From da5c6ab9aef9e5478fd2bd941101525a9e507a2f Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Mon, 15 Apr 2024 13:40:56 -0300 Subject: [PATCH] Refactor repository with pre-commit hooks (#9515) * Add Config * Add Cache and remove pre-commit action * [pre-commit.ci lite] apply automatic fixes * Remove freeze * Fix * Update action * Use latest stable Python 3 version * Improve caching * Improve cache tag * Improve bot message * fix(typos): Fix typos * fix(typos): Fix more typos * refactor(udp_server): Convert script from Python 2 to 3 * Fix whitespace * Clang-format fixes * Prettier fixes * Black formatting * Manual fixes * Line endings * Fix flake and make Vale manual * Fix flake and reformat --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Rodrigo Garcia --- CMakeLists.txt | 12 +- Kconfig.projbuild | 3 +- LICENSE.md | 4 +- README.md | 2 +- boards.txt | 6 +- cores/esp32/Arduino.h | 111 +- cores/esp32/Client.h | 34 +- cores/esp32/Esp.cpp | 623 ++- cores/esp32/Esp.h | 151 +- cores/esp32/FirmwareMSC.cpp | 175 +- cores/esp32/FirmwareMSC.h | 44 +- cores/esp32/FunctionalInterrupt.cpp | 38 +- cores/esp32/FunctionalInterrupt.h | 4 +- cores/esp32/HEXBuilder.cpp | 73 +- cores/esp32/HEXBuilder.h | 8 +- cores/esp32/HWCDC.cpp | 801 ++-- cores/esp32/HWCDC.h | 139 +- cores/esp32/HardwareI2C.h | 35 +- cores/esp32/HardwareSerial.cpp | 772 ++-- cores/esp32/HardwareSerial.h | 477 ++- cores/esp32/HashBuilder.h | 48 +- cores/esp32/IPAddress.cpp | 631 ++- cores/esp32/IPAddress.h | 160 +- cores/esp32/MD5Builder.cpp | 126 +- cores/esp32/MD5Builder.h | 27 +- cores/esp32/MacAddress.cpp | 292 +- cores/esp32/MacAddress.h | 94 +- cores/esp32/Print.cpp | 478 ++- cores/esp32/Print.h | 147 +- cores/esp32/Printable.h | 8 +- cores/esp32/SHA1Builder.cpp | 527 ++- cores/esp32/SHA1Builder.h | 33 +- cores/esp32/Server.h | 5 +- cores/esp32/Stream.cpp | 314 +- cores/esp32/Stream.h | 173 +- cores/esp32/StreamString.cpp | 46 +- cores/esp32/StreamString.h | 15 +- cores/esp32/Tone.cpp | 74 +- cores/esp32/USB.cpp | 412 +- cores/esp32/USB.h | 164 +- cores/esp32/USBCDC.cpp | 690 ++-- cores/esp32/USBCDC.h | 201 +- cores/esp32/USBMSC.cpp | 323 +- cores/esp32/USBMSC.h | 27 +- cores/esp32/Udp.h | 86 +- cores/esp32/WCharacter.h | 84 +- cores/esp32/WMath.cpp | 62 +- cores/esp32/WString.cpp | 1066 ++--- cores/esp32/WString.h | 684 ++-- cores/esp32/base64.cpp | 33 +- cores/esp32/base64.h | 7 +- cores/esp32/binary.h | 520 +-- cores/esp32/cbuf.cpp | 407 +- cores/esp32/cbuf.h | 46 +- cores/esp32/chip-debug-report.cpp | 117 +- cores/esp32/esp32-hal-adc.c | 1108 +++--- cores/esp32/esp32-hal-adc.h | 70 +- cores/esp32/esp32-hal-bt.c | 160 +- cores/esp32/esp32-hal-bt.h | 15 +- cores/esp32/esp32-hal-cpu.c | 347 +- cores/esp32/esp32-hal-cpu.h | 27 +- cores/esp32/esp32-hal-dac.c | 108 +- cores/esp32/esp32-hal-dac.h | 4 +- cores/esp32/esp32-hal-gpio.c | 369 +- cores/esp32/esp32-hal-gpio.h | 79 +- cores/esp32/esp32-hal-i2c-slave.c | 1273 +++--- cores/esp32/esp32-hal-i2c-slave.h | 12 +- cores/esp32/esp32-hal-i2c.c | 578 +-- cores/esp32/esp32-hal-i2c.h | 16 +- cores/esp32/esp32-hal-ledc.c | 622 ++- cores/esp32/esp32-hal-ledc.h | 112 +- cores/esp32/esp32-hal-log.h | 253 +- cores/esp32/esp32-hal-matrix.c | 29 +- cores/esp32/esp32-hal-matrix.h | 8 +- cores/esp32/esp32-hal-misc.c | 450 ++- cores/esp32/esp32-hal-periman.c | 342 +- cores/esp32/esp32-hal-periman.h | 167 +- cores/esp32/esp32-hal-psram.c | 147 +- cores/esp32/esp32-hal-psram.h | 10 +- cores/esp32/esp32-hal-rgb-led.c | 24 +- cores/esp32/esp32-hal-rgb-led.h | 6 +- cores/esp32/esp32-hal-rmt.c | 146 +- cores/esp32/esp32-hal-rmt.h | 164 +- cores/esp32/esp32-hal-sigmadelta.c | 134 +- cores/esp32/esp32-hal-sigmadelta.h | 8 +- cores/esp32/esp32-hal-spi.c | 2302 +++++------ cores/esp32/esp32-hal-spi.h | 156 +- cores/esp32/esp32-hal-time.c | 113 +- cores/esp32/esp32-hal-timer.c | 288 +- cores/esp32/esp32-hal-timer.h | 34 +- cores/esp32/esp32-hal-tinyusb.c | 1074 ++--- cores/esp32/esp32-hal-tinyusb.h | 105 +- cores/esp32/esp32-hal-touch.c | 466 ++- cores/esp32/esp32-hal-touch.h | 46 +- cores/esp32/esp32-hal-uart.c | 1569 ++++---- cores/esp32/esp32-hal-uart.h | 116 +- cores/esp32/esp32-hal.h | 108 +- cores/esp32/esp8266-compat.h | 2 +- cores/esp32/esp_arduino_version.h | 12 +- cores/esp32/firmware_msc_fat.c | 134 +- cores/esp32/firmware_msc_fat.h | 216 +- cores/esp32/io_pin_remap.h | 142 +- cores/esp32/libb64/LICENSE | 4 +- cores/esp32/libb64/cdecode.c | 48 +- cores/esp32/libb64/cdecode.h | 25 +- cores/esp32/libb64/cencode.c | 149 +- cores/esp32/libb64/cencode.h | 24 +- cores/esp32/main.cpp | 76 +- cores/esp32/pgmspace.h | 68 +- cores/esp32/stdlib_noniso.c | 294 +- cores/esp32/stdlib_noniso.h | 24 +- cores/esp32/wiring_private.h | 6 +- cores/esp32/wiring_pulse.c | 40 +- cores/esp32/wiring_shift.c | 42 +- docs/conf_common.py | 13 +- docs/en/api/adc.rst | 42 +- docs/en/api/ble.rst | 4 +- docs/en/api/bluetooth.rst | 4 +- docs/en/api/dac.rst | 4 +- docs/en/api/espnow.rst | 4 +- docs/en/api/ethernet.rst | 4 +- docs/en/api/gpio.rst | 18 +- docs/en/api/i2c.rst | 22 +- docs/en/api/insights.rst | 2 +- docs/en/api/ledc.rst | 40 +- docs/en/api/preferences.rst | 112 +- docs/en/api/rainmaker.rst | 10 +- docs/en/api/rmt.rst | 2 +- docs/en/api/sdmmc.rst | 2 +- docs/en/api/sigmadelta.rst | 4 +- docs/en/api/timer.rst | 16 +- docs/en/api/touch.rst | 20 +- docs/en/api/usb.rst | 8 +- docs/en/api/usb_cdc.rst | 2 +- docs/en/api/wifi.rst | 4 +- docs/en/boards/ESP32-C3-DevKitM-1.rst | 2 +- docs/en/boards/ESP32-DevKitC-1.rst | 14 +- docs/en/boards/ESP32-S2-Saola-1.rst | 2 +- docs/en/boards/boards.rst | 14 +- docs/en/conf.py | 14 +- docs/en/contributing.rst | 2 +- docs/en/esp-idf_component.rst | 2 +- docs/en/external_libraries_test.rst | 10 +- docs/en/faq.rst | 2 +- docs/en/getting_started.rst | 18 +- docs/en/guides/core_debug.rst | 1 - docs/en/guides/docs_contributing.rst | 8 +- docs/en/guides/tools_menu.rst | 4 +- docs/en/index.rst | 2 +- docs/en/installing.rst | 8 +- docs/en/libraries.rst | 4 +- docs/en/make.rst | 2 +- docs/en/migration_guides/2.x_to_3.0.rst | 4 +- docs/en/ota_web_update.rst | 2 +- docs/en/tutorials/blink.rst | 4 +- docs/en/tutorials/io_mux.rst | 10 +- docs/en/tutorials/partition_table.rst | 26 +- docs/en/tutorials/preferences.rst | 144 +- docs/utils.sh | 2 +- idf_component.yml | 1 - idf_component_examples/Hello_world/README.md | 6 +- .../Hello_world/main/idf_component.yml | 4 +- .../Hello_world/main/main.cpp | 8 +- .../ArduinoOTA/examples/BasicOTA/BasicOTA.ino | 4 +- libraries/ArduinoOTA/keywords.txt | 1 - libraries/ArduinoOTA/src/ArduinoOTA.cpp | 595 ++- libraries/ArduinoOTA/src/ArduinoOTA.h | 173 +- .../AsyncUDPClient/AsyncUDPClient.ino | 81 +- .../AsyncUDPMulticastServer.ino | 83 +- .../AsyncUDPServer/AsyncUDPServer.ino | 79 +- libraries/AsyncUDP/src/AsyncUDP.cpp | 1244 +++--- libraries/AsyncUDP/src/AsyncUDP.h | 210 +- libraries/BLE/README.md | 2 +- .../BLE5_extended_scan/BLE5_extended_scan.ino | 30 +- .../BLE5_multi_advertising.ino | 162 +- .../BLE5_periodic_advertising.ino | 60 +- .../BLE5_periodic_sync/BLE5_periodic_sync.ino | 55 +- .../Beacon_Scanner/Beacon_Scanner.ino | 137 +- .../examples/Beacon_Scanner/Beacon_Scanner.md | 4 +- libraries/BLE/examples/Client/Client.ino | 126 +- .../EddystoneTLM_Beacon.ino | 25 +- .../EddystoneURL_Beacon.ino | 49 +- libraries/BLE/examples/Notify/Notify.ino | 70 +- libraries/BLE/examples/Scan/Scan.ino | 20 +- libraries/BLE/examples/Server/Server.ino | 10 +- .../Server_multiconnect.ino | 70 +- libraries/BLE/examples/UART/UART.ino | 62 +- libraries/BLE/examples/Write/Write.ino | 32 +- libraries/BLE/examples/iBeacon/iBeacon.ino | 272 +- libraries/BLE/library.properties | 2 +- libraries/BLE/src/BLE2902.cpp | 37 +- libraries/BLE/src/BLE2902.h | 14 +- libraries/BLE/src/BLE2904.cpp | 45 +- libraries/BLE/src/BLE2904.h | 82 +- libraries/BLE/src/BLEAddress.cpp | 52 +- libraries/BLE/src/BLEAddress.h | 24 +- libraries/BLE/src/BLEAdvertisedDevice.cpp | 581 +-- libraries/BLE/src/BLEAdvertisedDevice.h | 174 +- libraries/BLE/src/BLEAdvertising.cpp | 854 ++-- libraries/BLE/src/BLEAdvertising.h | 134 +- libraries/BLE/src/BLEBeacon.cpp | 66 +- libraries/BLE/src/BLEBeacon.h | 46 +- libraries/BLE/src/BLECharacteristic.cpp | 1068 ++--- libraries/BLE/src/BLECharacteristic.h | 216 +- libraries/BLE/src/BLECharacteristicMap.cpp | 24 +- libraries/BLE/src/BLEClient.cpp | 301 +- libraries/BLE/src/BLEClient.h | 82 +- libraries/BLE/src/BLEDescriptor.cpp | 129 +- libraries/BLE/src/BLEDescriptor.h | 32 +- libraries/BLE/src/BLEDescriptorMap.cpp | 104 +- libraries/BLE/src/BLEDevice.cpp | 782 ++-- libraries/BLE/src/BLEDevice.h | 122 +- libraries/BLE/src/BLEEddystoneTLM.cpp | 56 +- .../BLE/src/BLEEddystoneTLM.cppwithheadder | 4 +- libraries/BLE/src/BLEEddystoneTLM.h | 38 +- libraries/BLE/src/BLEEddystoneURL.cpp | 216 +- libraries/BLE/src/BLEEddystoneURL.h | 36 +- libraries/BLE/src/BLEExceptions.cpp | 1 - libraries/BLE/src/BLEExceptions.h | 12 +- libraries/BLE/src/BLEHIDDevice.cpp | 155 +- libraries/BLE/src/BLEHIDDevice.h | 86 +- libraries/BLE/src/BLERemoteCharacteristic.cpp | 694 ++-- libraries/BLE/src/BLERemoteCharacteristic.h | 96 +- libraries/BLE/src/BLERemoteDescriptor.cpp | 61 +- libraries/BLE/src/BLERemoteDescriptor.h | 43 +- libraries/BLE/src/BLERemoteService.cpp | 133 +- libraries/BLE/src/BLERemoteService.h | 104 +- libraries/BLE/src/BLEScan.cpp | 654 ++- libraries/BLE/src/BLEScan.h | 120 +- libraries/BLE/src/BLESecurity.cpp | 112 +- libraries/BLE/src/BLESecurity.h | 58 +- libraries/BLE/src/BLEServer.cpp | 503 +-- libraries/BLE/src/BLEServer.h | 146 +- libraries/BLE/src/BLEService.cpp | 452 +-- libraries/BLE/src/BLEService.h | 108 +- libraries/BLE/src/BLEServiceMap.cpp | 96 +- libraries/BLE/src/BLEUUID.cpp | 422 +- libraries/BLE/src/BLEUUID.h | 14 +- libraries/BLE/src/BLEUtils.cpp | 3492 +++++++++-------- libraries/BLE/src/BLEUtils.h | 80 +- libraries/BLE/src/BLEValue.cpp | 68 +- libraries/BLE/src/BLEValue.h | 29 +- libraries/BLE/src/FreeRTOS.cpp | 270 +- libraries/BLE/src/GeneralUtils.cpp | 632 +-- libraries/BLE/src/GeneralUtils.h | 23 +- libraries/BLE/src/HIDKeyboardTypes.h | 688 ++-- libraries/BLE/src/HIDTypes.h | 80 +- libraries/BLE/src/RTOS.h | 73 +- libraries/BluetoothSerial/README.md | 2 +- .../DiscoverConnect/DiscoverConnect.ino | 65 +- .../examples/GetLocalMAC/GetLocalMAC.ino | 40 +- .../SerialToSerialBT/SerialToSerialBT.ino | 6 +- .../SerialToSerialBTM/SerialToSerialBTM.ino | 49 +- .../SerialToSerialBT_Legacy.ino | 32 +- .../SerialToSerialBT_SSP.ino | 67 +- .../bt_classic_device_discovery.ino | 10 +- .../bt_remove_paired_devices.ino | 36 +- libraries/BluetoothSerial/src/BTAddress.cpp | 72 +- libraries/BluetoothSerial/src/BTAddress.h | 18 +- .../BluetoothSerial/src/BTAdvertisedDevice.h | 62 +- .../src/BTAdvertisedDeviceSet.cpp | 86 +- libraries/BluetoothSerial/src/BTScan.h | 20 +- .../BluetoothSerial/src/BTScanResultsSet.cpp | 90 +- .../BluetoothSerial/src/BluetoothSerial.cpp | 1905 +++++---- .../BluetoothSerial/src/BluetoothSerial.h | 146 +- .../examples/CaptivePortal/CaptivePortal.ino | 10 +- libraries/DNSServer/src/DNSServer.cpp | 173 +- libraries/DNSServer/src/DNSServer.h | 209 +- .../examples/eeprom_class/eeprom_class.ino | 43 +- .../examples/eeprom_extra/eeprom_extra.ino | 37 +- .../examples/eeprom_write/eeprom_write.ino | 33 +- libraries/EEPROM/keywords.txt | 1 - libraries/EEPROM/src/EEPROM.cpp | 339 +- libraries/EEPROM/src/EEPROM.h | 150 +- .../examples/AnalogOut/LEDCFade/LEDCFade.ino | 36 +- .../LEDCSoftwareFade/LEDCSoftwareFade.ino | 14 +- .../AnalogOut/SigmaDelta/SigmaDelta.ino | 24 +- .../AnalogOut/ledcFrequency/ledcFrequency.ino | 55 +- .../AnalogOut/ledcWrite_RGB/ledcWrite_RGB.ino | 159 +- .../ESP32/examples/AnalogRead/AnalogRead.ino | 10 +- .../AnalogReadContinuous.ino | 69 +- .../ArduinoStackSize/ArduinoStackSize.ino | 2 +- .../examples/CI/CIBoardsTest/CIBoardsTest.ino | 16 +- .../CameraWebServer/CameraWebServer.ino | 22 +- .../Camera/CameraWebServer/app_httpd.cpp | 1996 +++++----- .../Camera/CameraWebServer/camera_index.h | 3105 ++++++++------- .../Camera/CameraWebServer/camera_pins.h | 496 +-- .../examples/ChipID/GetChipID/GetChipID.ino | 32 +- .../ExternalWakeUp/ExternalWakeUp.ino | 29 +- .../SmoothBlink_ULP_Code.ino | 79 +- .../DeepSleep/TimerWakeUp/TimerWakeUp.ino | 32 +- .../DeepSleep/TouchWakeUp/TouchWakeUp.ino | 97 +- .../BasicMultiThreading.ino | 85 +- .../ESP32/examples/FreeRTOS/Mutex/Mutex.ino | 100 +- .../ESP32/examples/FreeRTOS/Queue/Queue.ino | 92 +- .../examples/FreeRTOS/Semaphore/Semaphore.ino | 68 +- .../ESP32/examples/GPIO/BlinkRGB/BlinkRGB.ino | 16 +- .../FunctionalInterrupt.ino | 49 +- .../FunctionalInterruptStruct.ino | 8 +- .../GPIO/GPIOInterrupt/GPIOInterrupt.ino | 56 +- .../ESP32/examples/HWCDC_Events/.skip.esp32 | 1 - .../ESP32/examples/HWCDC_Events/.skip.esp32s2 | 1 - .../examples/HWCDC_Events/HWCDC_Events.ino | 14 +- .../GetMacAddress/GetMacAddress.ino | 175 +- .../examples/RMT/RMTCallback/RMTCallback.ino | 103 +- .../examples/RMT/RMTLoopback/RMTLoopback.ino | 103 +- .../examples/RMT/RMTReadXJT/RMTReadXJT.ino | 27 +- .../RMT/RMTWriteNeoPixel/RMTWriteNeoPixel.ino | 76 +- .../RMT/RMT_CPUFreq_Test/RMT_CPUFreq_Test.ino | 34 +- .../RMT_EndOfTransmissionState.ino | 132 +- .../RMT/RMT_LED_Blink/RMT_LED_Blink.ino | 234 +- .../ResetReason/ResetReason/ResetReason.ino | 89 +- .../ResetReason/ResetReason2/ResetReason2.ino | 34 +- .../BaudRateDetect_Demo.ino | 16 +- .../OnReceiveError_BREAK_Demo.ino | 47 +- .../Serial/OnReceive_Demo/OnReceive_Demo.ino | 38 +- .../RS485_Echo_Demo/RS485_Echo_Demo.ino | 14 +- .../RxFIFOFull_Demo/RxFIFOFull_Demo.ino | 52 +- .../Serial/RxTimeout_Demo/RxTimeout_Demo.ino | 35 +- .../Serial_All_CPU_Freqs.ino | 2 +- .../Serial_STD_Func_OnReceive.ino | 44 +- .../onReceiveExample/onReceiveExample.ino | 12 +- .../examples/TWAI/TWAIreceive/TWAIreceive.ino | 2 +- .../TWAI/TWAItransmit/TWAItransmit.ino | 2 +- .../ExampleTemplate/ExampleTemplate.ino | 2 - .../examples/Time/SimpleTime/SimpleTime.ino | 48 +- .../Timer/RepeatTimer/RepeatTimer.ino | 8 +- .../Timer/WatchdogTimer/WatchdogTimer.ino | 18 +- .../Touch/TouchButton/TouchButton.ino | 8 +- .../Touch/TouchButtonV2/TouchButtonV2.ino | 14 +- .../Touch/TouchInterrupt/TouchInterrupt.ino | 16 +- .../examples/Touch/TouchRead/TouchRead.ino | 8 +- .../Utilities/HEXBuilder/HEXBuilder.ino | 8 +- .../Utilities/MD5Builder/MD5Builder.ino | 10 +- .../Utilities/SHA1Builder/SHA1Builder.ino | 12 +- .../Zigbee/Zigbee_Light_Bulb/README.md | 2 +- .../Zigbee_Light_Bulb/Zigbee_Light_Bulb.ino | 249 +- .../Zigbee/Zigbee_Light_Switch/README.md | 2 +- .../Zigbee_Light_Switch.ino | 401 +- libraries/ESP32/keywords.txt | 2 +- .../examples/ES8388_loopback/ES8388.cpp | 407 +- .../ESP_I2S/examples/ES8388_loopback/ES8388.h | 1428 ++++--- .../ES8388_loopback/ES8388_loopback.ino | 12 +- .../examples/Record_to_WAV/Record_to_WAV.ino | 2 +- .../examples/Simple_tone/Simple_tone.ino | 29 +- libraries/ESP_I2S/library.properties | 2 +- libraries/ESP_I2S/src/ESP_I2S.cpp | 1291 +++--- libraries/ESP_I2S/src/ESP_I2S.h | 154 +- libraries/ESP_I2S/src/wav_header.h | 98 +- .../ESP_NOW_Broadcast_Master.ino | 106 +- .../ESP_NOW_Broadcast_Slave.ino | 131 +- .../ESP_NOW_Network/ESP_NOW_Network.ino | 417 +- .../ESP_NOW_Serial/ESP_NOW_Serial.ino | 65 +- libraries/ESP_NOW/library.properties | 2 +- libraries/ESP_NOW/src/ESP32_NOW.cpp | 633 ++- libraries/ESP_NOW/src/ESP32_NOW.h | 22 +- libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp | 428 +- libraries/ESP_NOW/src/ESP32_NOW_Serial.h | 62 +- libraries/ESP_SR/examples/Basic/Basic.ino | 67 +- libraries/ESP_SR/library.properties | 2 +- libraries/ESP_SR/src/ESP_SR.cpp | 69 +- libraries/ESP_SR/src/ESP_SR.h | 34 +- libraries/ESP_SR/src/esp32-hal-sr.c | 681 ++-- libraries/ESP_SR/src/esp32-hal-sr.h | 74 +- libraries/ESP_SR/tools/gen_sr_commands.py | 89 +- .../mDNS-SD_Extended/mDNS-SD_Extended.ino | 110 +- .../mDNS_Web_Server/mDNS_Web_Server.ino | 164 +- libraries/ESPmDNS/keywords.txt | 1 - libraries/ESPmDNS/src/ESPmDNS.cpp | 501 +-- libraries/ESPmDNS/src/ESPmDNS.h | 54 +- .../examples/ETH_LAN8720/ETH_LAN8720.ino | 27 +- .../examples/ETH_TLK110/ETH_TLK110.ino | 27 +- .../ETH_W5500_Arduino_SPI.ino | 41 +- .../ETH_W5500_IDF_SPI/ETH_W5500_IDF_SPI.ino | 43 +- libraries/Ethernet/src/ETH.cpp | 1355 ++++--- libraries/Ethernet/src/ETH.h | 142 +- .../FFat/examples/FFat_Test/FFat_Test.ino | 307 +- .../FFat/examples/FFat_time/FFat_time.ino | 293 +- libraries/FFat/src/FFat.cpp | 256 +- libraries/FFat/src/FFat.h | 26 +- libraries/FS/src/FS.cpp | 368 +- libraries/FS/src/FS.h | 133 +- libraries/FS/src/FSImpl.h | 74 +- libraries/FS/src/vfs_api.cpp | 858 ++-- libraries/FS/src/vfs_api.h | 76 +- .../examples/Authorization/Authorization.ino | 72 +- .../BasicHttpClient/BasicHttpClient.ino | 135 +- .../BasicHttpsClient/BasicHttpsClient.ino | 98 +- .../HTTPClientEnterprise.ino | 128 +- .../ReuseConnection/ReuseConnection.ino | 67 +- .../StreamHttpClient/StreamHttpClient.ino | 109 +- libraries/HTTPClient/src/HTTPClient.cpp | 2368 ++++++----- libraries/HTTPClient/src/HTTPClient.h | 400 +- .../examples/httpUpdate/httpUpdate.ino | 3 - .../httpUpdateSPIFFS/httpUpdateSPIFFS.ino | 2 - .../httpUpdateSecure/httpUpdateSecure.ino | 60 +- libraries/HTTPUpdate/src/HTTPUpdate.cpp | 560 ++- libraries/HTTPUpdate/src/HTTPUpdate.h | 199 +- .../examples/WebUpdater/WebUpdater.ino | 4 +- libraries/HTTPUpdateServer/keywords.txt | 2 +- libraries/HTTPUpdateServer/library.properties | 2 +- .../HTTPUpdateServer/src/HTTPUpdateServer.h | 243 +- .../DiagnosticsSmokeTest.ino | 147 +- .../examples/DiagnosticsSmokeTest/README.md | 2 +- .../MinimalDiagnostics/MinimalDiagnostics.ino | 40 +- libraries/Insights/library.properties | 2 +- libraries/Insights/src/Insights.cpp | 359 +- libraries/Insights/src/Insights.h | 179 +- .../examples/LITTLEFS_PlatformIO/.gitignore | 2 +- .../examples/LITTLEFS_PlatformIO/README.md | 6 +- .../LITTLEFS_PlatformIO/data/file1.txt | 2 +- .../data/testfolder/test2.txt | 2 +- .../examples/LITTLEFS_PlatformIO/src/main.cpp | 445 ++- .../examples/LITTLEFS_test/LITTLEFS_test.ino | 447 ++- .../examples/LITTLEFS_test/partitions.csv | 2 +- .../examples/LITTLEFS_time/LITTLEFS_time.ino | 350 +- libraries/LittleFS/src/LittleFS.cpp | 167 +- libraries/LittleFS/src/LittleFS.h | 22 +- .../NetBIOS/examples/ESP_NBNST/ESP_NBNST.ino | 1 - libraries/NetBIOS/src/NetBIOS.cpp | 264 +- libraries/NetBIOS/src/NetBIOS.h | 51 +- libraries/Network/library.properties | 2 +- libraries/Network/src/Network.h | 2 +- libraries/Network/src/NetworkClient.cpp | 1014 +++-- libraries/Network/src/NetworkClient.h | 149 +- libraries/Network/src/NetworkEvents.cpp | 586 ++- libraries/Network/src/NetworkEvents.h | 202 +- libraries/Network/src/NetworkInterface.cpp | 1367 ++++--- libraries/Network/src/NetworkInterface.h | 168 +- libraries/Network/src/NetworkManager.cpp | 291 +- libraries/Network/src/NetworkManager.h | 24 +- libraries/Network/src/NetworkServer.cpp | 81 +- libraries/Network/src/NetworkServer.h | 71 +- libraries/Network/src/NetworkUdp.cpp | 162 +- libraries/Network/src/NetworkUdp.h | 12 +- libraries/NetworkClientSecure/README.md | 16 +- .../WiFiClientInsecure/WiFiClientInsecure.ino | 12 +- .../examples/WiFiClientPSK/WiFiClientPSK.ino | 10 +- .../WiFiClientSecure/WiFiClientSecure.ino | 50 +- .../WiFiClientSecureEnterprise.ino | 106 +- .../WiFiClientSecureProtocolUpgrade.ino | 21 +- .../WiFiClientShowPeerCredentials.ino | 12 +- .../WiFiClientTrustOnFirstUse.ino | 36 +- .../src/NetworkClientSecure.cpp | 547 ++- .../src/NetworkClientSecure.h | 178 +- .../NetworkClientSecure/src/ssl_client.cpp | 949 +++-- .../NetworkClientSecure/src/ssl_client.h | 26 +- .../examples/Prefs2Struct/Prefs2Struct.ino | 30 +- libraries/Preferences/src/Preferences.cpp | 887 ++--- libraries/Preferences/src/Preferences.h | 106 +- libraries/RainMaker/README.md | 8 +- libraries/RainMaker/examples/README.md | 1 - .../RainMaker/examples/RMakerCustom/README.md | 4 +- .../examples/RMakerCustom/RMakerCustom.ino | 202 +- .../examples/RMakerCustomAirCooler/README.md | 2 +- .../RMakerCustomAirCooler.ino | 298 +- .../RMakerSonoffDualR3/RMakerSonoffDualR3.ino | 301 +- .../RainMaker/examples/RMakerSwitch/README.md | 2 +- .../examples/RMakerSwitch/RMakerSwitch.ino | 192 +- libraries/RainMaker/src/AppInsights.cpp | 98 +- libraries/RainMaker/src/RMaker.cpp | 260 +- libraries/RainMaker/src/RMaker.h | 33 +- libraries/RainMaker/src/RMakerDevice.cpp | 323 +- libraries/RainMaker/src/RMakerDevice.h | 292 +- libraries/RainMaker/src/RMakerNode.cpp | 51 +- libraries/RainMaker/src/RMakerNode.h | 46 +- libraries/RainMaker/src/RMakerParam.cpp | 49 +- libraries/RainMaker/src/RMakerParam.h | 58 +- libraries/RainMaker/src/RMakerQR.cpp | 39 +- libraries/RainMaker/src/RMakerQR.h | 4 +- libraries/RainMaker/src/RMakerType.cpp | 27 +- libraries/RainMaker/src/RMakerType.h | 4 +- libraries/RainMaker/src/RMakerUtils.cpp | 12 +- libraries/RainMaker/src/RMakerUtils.h | 2 +- libraries/SD/examples/SD_Test/SD_Test.ino | 339 +- libraries/SD/examples/SD_time/SD_time.ino | 337 +- libraries/SD/src/SD.cpp | 149 +- libraries/SD/src/SD.h | 36 +- libraries/SD/src/sd_defines.h | 10 +- libraries/SD/src/sd_diskio.cpp | 1341 +++---- libraries/SD/src/sd_diskio.h | 2 +- libraries/SD/src/sd_diskio_crc.c | 154 +- .../SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino | 339 +- .../SD_MMC/examples/SDMMC_time/SDMMC_time.ino | 389 +- libraries/SD_MMC/src/SD_MMC.cpp | 357 +- libraries/SD_MMC/src/SD_MMC.h | 48 +- libraries/SD_MMC/src/sd_defines.h | 10 +- .../SPI_Multiple_Buses/SPI_Multiple_Buses.ino | 79 +- libraries/SPI/keywords.txt | 2 +- libraries/SPI/library.properties | 2 +- libraries/SPI/src/SPI.cpp | 447 +-- libraries/SPI/src/SPI.h | 114 +- .../examples/SPIFFS_Test/SPIFFS_Test.ino | 297 +- .../examples/SPIFFS_time/SPIFFS_time.ino | 293 +- libraries/SPIFFS/src/SPIFFS.cpp | 161 +- libraries/SPIFFS/src/SPIFFS.h | 22 +- .../SimpleBleDevice/SimpleBleDevice.ino | 38 +- libraries/SimpleBLE/src/SimpleBLE.cpp | 151 +- libraries/SimpleBLE/src/SimpleBLE.h | 21 +- .../examples/hello_world/hello_world.ino | 10 +- .../examples/hello_world/model.cpp | 417 +- .../examples/micro_speech/audio_provider.cpp | 58 +- .../micro_speech/feature_provider.cpp | 16 +- .../examples/micro_speech/feature_provider.h | 4 +- .../micro_speech/micro_features_generator.cpp | 5 +- .../micro_speech/micro_model_settings.cpp | 8 +- .../examples/micro_speech/micro_speech.ino | 18 +- .../examples/micro_speech/model.cpp | 3121 +++++++-------- .../micro_speech/recognize_commands.cpp | 56 +- .../micro_speech/recognize_commands.h | 29 +- .../examples/micro_speech/ringbuf.c | 11 +- .../examples/micro_speech/ringbuf.h | 66 +- libraries/TFLiteMicro/src/TFLIteMicro.h | 2 +- libraries/Ticker/examples/Blinker/Blinker.ino | 8 +- .../examples/TickerBasic/TickerBasic.ino | 32 +- .../TickerParameter/TickerParameter.ino | 24 +- libraries/Ticker/src/Ticker.cpp | 12 +- libraries/Ticker/src/Ticker.h | 47 +- .../CompositeDevice/CompositeDevice.ino | 90 +- .../ConsumerControl/ConsumerControl.ino | 4 +- .../CustomHIDDevice/CustomHIDDevice.ino | 71 +- .../USB/examples/FirmwareMSC/FirmwareMSC.ino | 22 +- libraries/USB/examples/Gamepad/Gamepad.ino | 22 +- .../USB/examples/HIDVendor/HIDVendor.ino | 20 +- .../KeyboardLogout/KeyboardLogout.ino | 6 +- .../KeyboardMessage/KeyboardMessage.ino | 10 +- .../KeyboardReprogram/KeyboardReprogram.ino | 8 +- .../KeyboardSerial/KeyboardSerial.ino | 4 +- .../KeyboardAndMouseControl.ino | 6 +- .../MIDI/MidiController/MidiController.ino | 104 +- .../MIDI/MidiInterface/MidiInterface.ino | 50 +- .../MIDI/MidiMusicBox/MidiMusicBox.ino | 40 +- .../examples/MIDI/ReceiveMidi/ReceiveMidi.ino | 136 +- .../ButtonMouseControl/ButtonMouseControl.ino | 12 +- .../examples/SystemControl/SystemControl.ino | 4 +- libraries/USB/examples/USBMSC/USBMSC.ino | 144 +- .../USB/examples/USBSerial/USBSerial.ino | 36 +- .../USB/examples/USBVendor/USBVendor.ino | 62 +- libraries/USB/keywords.txt | 1 - libraries/USB/src/USBHID.cpp | 530 ++- libraries/USB/src/USBHID.h | 74 +- libraries/USB/src/USBHIDConsumerControl.cpp | 39 +- libraries/USB/src/USBHIDConsumerControl.h | 92 +- libraries/USB/src/USBHIDGamepad.cpp | 142 +- libraries/USB/src/USBHIDGamepad.h | 102 +- libraries/USB/src/USBHIDKeyboard.cpp | 558 ++- libraries/USB/src/USBHIDKeyboard.h | 183 +- libraries/USB/src/USBHIDMouse.cpp | 143 +- libraries/USB/src/USBHIDMouse.h | 76 +- libraries/USB/src/USBHIDSystemControl.cpp | 45 +- libraries/USB/src/USBHIDSystemControl.h | 28 +- libraries/USB/src/USBHIDVendor.cpp | 315 +- libraries/USB/src/USBHIDVendor.h | 68 +- libraries/USB/src/USBMIDI.cpp | 124 +- libraries/USB/src/USBMIDI.h | 80 +- libraries/USB/src/USBVendor.cpp | 292 +- libraries/USB/src/USBVendor.h | 108 +- libraries/USB/src/tusb_hid_mouse.h | 153 +- .../AWS_S3_OTA_Update/AWS_S3_OTA_Update.ino | 39 +- .../HTTPS_OTA_Update/HTTPS_OTA_Update.ino | 161 +- .../examples/HTTPS_OTA_Update/Readme.md | 12 +- .../HTTP_Client_AES_OTA_Update.ino | 666 ++-- .../HTTP_Client_AES_OTA_Update/updater.php | 4 +- .../HTTP_Server_AES_OTA_Update.ino | 472 +-- .../examples/OTAWebUpdater/OTAWebUpdater.ino | 34 +- .../Update/examples/OTAWebUpdater/html.h | 6 +- .../Update/examples/SD_Update/SD_Update.ino | 132 +- libraries/Update/keywords.txt | 1 - libraries/Update/src/HttpsOTAUpdate.cpp | 131 +- libraries/Update/src/HttpsOTAUpdate.h | 23 +- libraries/Update/src/Update.h | 304 +- libraries/Update/src/Updater.cpp | 947 +++-- .../AdvancedWebServer/AdvancedWebServer.ino | 5 +- .../examples/FSBrowser/FSBrowser.ino | 63 +- .../examples/FSBrowser/data/index.htm | 16 +- .../examples/HelloServer/HelloServer.ino | 2 +- .../HttpAdvancedAuth/HttpAdvancedAuth.ino | 16 +- .../HttpAuthCallback/HttpAuthCallback.ino | 15 +- .../HttpAuthCallbackInline.ino | 41 +- .../examples/HttpBasicAuth/HttpBasicAuth.ino | 2 +- .../HttpBasicAuthSHA1/HttpBasicAuthSHA1.ino | 4 +- .../HttpBasicAuthSHA1orBearerToken.ino | 8 +- .../MultiHomedServers/MultiHomedServers.ino | 28 +- .../examples/PathArgServer/PathArgServer.ino | 4 +- .../examples/SDWebServer/SDWebServer.ino | 33 +- .../SDWebServer/SdRoot/edit/index.htm | 68 +- .../SimpleAuthentification.ino | 16 +- .../UploadHugeFile/UploadHugeFile.ino | 13 +- .../examples/WebServer/.skip.esp32h2 | 1 - .../WebServer/examples/WebServer/README.md | 4 +- .../examples/WebServer/WebServer.ino | 4 +- .../examples/WebServer/builtinfiles.h | 12 +- .../examples/WebServer/data/files.htm | 2 +- .../examples/WebServer/data/index.htm | 2 +- .../examples/WebServer/data/style.css | 1 - .../WebServer/examples/WebServer/secrets.h | 2 +- .../examples/WebUpdate/WebUpdate.ino | 54 +- libraries/WebServer/src/Parsing.cpp | 257 +- libraries/WebServer/src/Uri.h | 39 +- libraries/WebServer/src/WebServer.cpp | 375 +- libraries/WebServer/src/WebServer.h | 195 +- .../WebServer/src/detail/RequestHandler.h | 59 +- .../src/detail/RequestHandlersImpl.h | 314 +- libraries/WebServer/src/detail/mimetable.cpp | 52 +- libraries/WebServer/src/detail/mimetable.h | 11 +- libraries/WebServer/src/uri/UriBraces.h | 98 +- libraries/WebServer/src/uri/UriGlob.h | 20 +- libraries/WebServer/src/uri/UriRegex.h | 68 +- .../FTM/FTM_Initiator/FTM_Initiator.ino | 19 +- .../WiFi/examples/FTM/FTM_Initiator/README.md | 2 +- .../FTM/FTM_Responder/FTM_Responder.ino | 4 +- .../WiFi/examples/FTM/FTM_Responder/README.md | 2 +- .../SimpleWiFiServer/SimpleWiFiServer.ino | 72 +- libraries/WiFi/examples/WPS/README.md | 8 +- libraries/WiFi/examples/WPS/WPS.ino | 46 +- .../WiFiAccessPoint/WiFiAccessPoint.ino | 29 +- .../WiFiBlueToothSwitch.ino | 143 +- .../WiFi/examples/WiFiClient/WiFiClient.ino | 69 +- .../WiFiClientBasic/WiFiClientBasic.ino | 96 +- .../WiFiClientConnect/WiFiClientConnect.ino | 158 +- .../examples/WiFiClientEnterprise/README.md | 8 +- .../WiFiClientEnterprise.ino | 54 +- .../WiFiClientEvents/WiFiClientEvents.ino | 236 +- .../WiFiClientStaticIP/WiFiClientStaticIP.ino | 21 +- libraries/WiFi/examples/WiFiIPv6/WiFiIPv6.ino | 146 +- .../WiFi/examples/WiFiMulti/WiFiMulti.ino | 42 +- .../WiFiMultiAdvanced/WiFiMultiAdvanced.ino | 76 +- libraries/WiFi/examples/WiFiScan/README.md | 2 +- libraries/WiFi/examples/WiFiScan/WiFiScan.ino | 137 +- .../WiFi/examples/WiFiScanAsync/.skip.esp32h2 | 1 - .../WiFi/examples/WiFiScanAsync/README.md | 2 +- .../examples/WiFiScanAsync/WiFiScanAsync.ino | 13 +- .../examples/WiFiScanDualAntenna/README.md | 2 +- .../WiFiScanDualAntenna.ino | 92 +- .../WiFiSmartConfig/WiFiSmartConfig.ino | 1 - .../WiFiTelnetToSerial/WiFiTelnetToSerial.ino | 36 +- .../examples/WiFiUDPClient/WiFiUDPClient.ino | 60 +- .../WiFi/examples/WiFiUDPClient/udp_server.py | 12 +- .../WiFi/examples/WiFiUDPClient/udp_server.rb | 6 +- libraries/WiFi/src/AP.cpp | 568 +-- libraries/WiFi/src/STA.cpp | 1254 +++--- libraries/WiFi/src/WiFi.cpp | 63 +- libraries/WiFi/src/WiFi.h | 48 +- libraries/WiFi/src/WiFiAP.cpp | 94 +- libraries/WiFi/src/WiFiAP.h | 88 +- libraries/WiFi/src/WiFiGeneric.cpp | 1062 +++-- libraries/WiFi/src/WiFiGeneric.h | 143 +- libraries/WiFi/src/WiFiMulti.cpp | 554 ++- libraries/WiFi/src/WiFiMulti.h | 61 +- libraries/WiFi/src/WiFiSTA.cpp | 353 +- libraries/WiFi/src/WiFiSTA.h | 202 +- libraries/WiFi/src/WiFiScan.cpp | 270 +- libraries/WiFi/src/WiFiScan.h | 46 +- libraries/WiFi/src/WiFiType.h | 34 +- .../WiFiProv/examples/WiFiProv/README.md | 2 +- .../WiFiProv/examples/WiFiProv/WiFiProv.ino | 83 +- libraries/WiFiProv/src/WiFiProv.cpp | 243 +- libraries/WiFiProv/src/WiFiProv.h | 39 +- .../Wire/examples/WireMaster/WireMaster.ino | 4 +- libraries/Wire/examples/WireScan/WireScan.ino | 8 +- .../Wire/examples/WireSlave/WireSlave.ino | 7 +- libraries/Wire/keywords.txt | 1 - libraries/Wire/library.properties | 2 +- libraries/Wire/src/Wire.cpp | 921 +++-- libraries/Wire/src/Wire.h | 141 +- tests/democfg/democfg.ino | 4 +- tests/democfg/test_democfg.py | 2 +- tests/hello_world/hello_world.ino | 4 +- tests/hello_world/test_hello_world.py | 2 +- tests/nvs/nvs.ino | 4 +- tests/nvs/test_nvs.py | 12 +- tests/periman/periman.ino | 22 +- tests/periman/test_periman.py | 19 +- tests/timer/timer.ino | 52 +- tests/touch/touch.ino | 123 +- tests/uart/uart.ino | 237 +- tests/unity/unity.ino | 8 +- tools/espota.py | 140 +- tools/gen_crt_bundle.py | 111 +- tools/gen_esp32part.py | 408 +- tools/gen_insights_package.py | 39 +- tools/get.py | 144 +- tools/ide-debug/svd/esp32.svd | 114 +- tools/ide-debug/svd/esp32c2.svd | 8 +- tools/ide-debug/svd/esp32c3.svd | 2 +- tools/ide-debug/svd/esp32c6.svd | 58 +- tools/ide-debug/svd/esp32h2.svd | 16 +- tools/ide-debug/svd/esp32s2.svd | 104 +- tools/ide-debug/svd/esp32s3.svd | 10 +- tools/partitions/app3M_fat9M_16MB.csv | 2 +- tools/partitions/bare_minimum_2MB.csv | 2 +- tools/partitions/default.csv | 2 +- tools/partitions/default_16MB.csv | 2 +- tools/partitions/default_8MB.csv | 2 +- tools/partitions/default_ffat.csv | 2 +- tools/partitions/huge_app.csv | 2 +- tools/partitions/large_spiffs_16MB.csv | 2 +- ...m5stack_partitions_16MB_factory_6_apps.csv | 1 - tools/partitions/max_app_8MB.csv | 2 +- tools/partitions/min_spiffs.csv | 2 +- tools/partitions/minimal.csv | 2 +- tools/partitions/no_ota.csv | 2 +- tools/partitions/noota_3g.csv | 2 +- tools/partitions/rainmaker.csv | 2 +- tools/partitions/zigbee.csv | 2 +- tools/partitions/zigbee_zczr.csv | 2 +- tools/platformio-build.py | 65 +- variants/AirM2M_CORE_ESP32C3/pins_arduino.h | 12 +- variants/AirM2M_CORE_ESP32C3/variant.cpp | 12 +- variants/Aventen_S3_Sync/pins_arduino.h | 16 +- variants/Bee_Data_Logger/pins_arduino.h | 16 +- variants/Bee_Motion/pins_arduino.h | 12 +- variants/Bee_Motion_Mini/pins_arduino.h | 9 +- variants/Bee_Motion_S3/pins_arduino.h | 16 +- variants/Bee_S3/pins_arduino.h | 16 +- variants/ET-Board/pins_arduino.h | 50 +- variants/Edgebox-ESP-100/pins_arduino.h | 4 +- variants/Geekble_ESP32C3/pins_arduino.h | 10 +- variants/Microduino-esp32/pins_arduino.h | 28 +- variants/Nebula_S3/pins_arduino.h | 10 +- variants/S_ODI_Ultra_v1/pins_arduino.h | 14 +- .../VALTRACK_V4_MFW_ESP32_C3/pins_arduino.h | 22 +- .../VALTRACK_V4_VTS_ESP32_C3/pins_arduino.h | 22 +- variants/XIAO_ESP32C3/pins_arduino.h | 8 +- variants/XIAO_ESP32C6/pins_arduino.h | 6 +- variants/XIAO_ESP32S3/pins_arduino.h | 6 +- .../adafruit_camera_esp32s3/pins_arduino.h | 70 +- variants/adafruit_camera_esp32s3/variant.cpp | 29 +- .../adafruit_feather_esp32_v2/pins_arduino.h | 16 +- .../adafruit_feather_esp32_v2/variant.cpp | 18 +- .../adafruit_feather_esp32s2/pins_arduino.h | 34 +- variants/adafruit_feather_esp32s2/variant.cpp | 29 +- .../pins_arduino.h | 40 +- .../variant.cpp | 22 +- .../pins_arduino.h | 40 +- .../adafruit_feather_esp32s2_tft/variant.cpp | 22 +- .../adafruit_feather_esp32s3/pins_arduino.h | 34 +- variants/adafruit_feather_esp32s3/variant.cpp | 23 +- .../pins_arduino.h | 34 +- .../variant.cpp | 23 +- .../pins_arduino.h | 40 +- .../variant.cpp | 22 +- .../pins_arduino.h | 40 +- .../adafruit_feather_esp32s3_tft/variant.cpp | 22 +- .../adafruit_funhouse_esp32s2/pins_arduino.h | 48 +- .../adafruit_funhouse_esp32s2/variant.cpp | 11 +- .../adafruit_itsybitsy_esp32/pins_arduino.h | 16 +- variants/adafruit_itsybitsy_esp32/variant.cpp | 18 +- .../adafruit_magtag29_esp32s2/pins_arduino.h | 48 +- .../adafruit_magtag29_esp32s2/variant.cpp | 11 +- .../pins_arduino.h | 40 +- .../adafruit_metro_esp32s2/pins_arduino.h | 30 +- variants/adafruit_metro_esp32s2/variant.cpp | 11 +- .../adafruit_metro_esp32s3/pins_arduino.h | 26 +- variants/adafruit_metro_esp32s3/variant.cpp | 15 +- variants/adafruit_qtpy_esp32/pins_arduino.h | 18 +- variants/adafruit_qtpy_esp32/variant.cpp | 18 +- variants/adafruit_qtpy_esp32c3/pins_arduino.h | 12 +- variants/adafruit_qtpy_esp32s2/pins_arduino.h | 34 +- variants/adafruit_qtpy_esp32s2/variant.cpp | 18 +- .../adafruit_qtpy_esp32s3_n4r2/pins_arduino.h | 38 +- .../adafruit_qtpy_esp32s3_n4r2/variant.cpp | 17 +- .../pins_arduino.h | 38 +- .../adafruit_qtpy_esp32s3_nopsram/variant.cpp | 17 +- .../adafruit_qualia_s3_rgb666/pins_arduino.h | 60 +- .../adafruit_qualia_s3_rgb666/variant.cpp | 13 +- variants/alksesp32/pins_arduino.h | 12 +- variants/arduino_nano_nora/dfu_callbacks.cpp | 112 +- variants/arduino_nano_nora/double_tap.c | 56 +- variants/arduino_nano_nora/double_tap.h | 8 +- .../extra/nora_recovery/nora_recovery.ino | 136 +- variants/arduino_nano_nora/io_pin_remap.cpp | 80 +- variants/arduino_nano_nora/pins_arduino.h | 134 +- variants/arduino_nano_nora/variant.cpp | 139 +- variants/atd147_s3/pins_arduino.h | 8 +- variants/atmegazero_esp32s2/pins_arduino.h | 10 +- variants/bpi-bit/pins_arduino.h | 4 +- variants/bpi_leaf_s3/pins_arduino.h | 12 +- variants/ch_denky/pins_arduino.h | 28 +- variants/cnrs_aw2eth/pins_arduino.h | 8 +- variants/connaxio_espoir/pins_arduino.h | 26 +- variants/crabik_slot_esp32_s3/pins_arduino.h | 58 +- .../pins_arduino.h | 52 +- .../cytron_maker_feather_aiot_s3/variant.cpp | 15 +- variants/d-duino-32/pins_arduino.h | 8 +- variants/d1_mini32/pins_arduino.h | 42 +- variants/d1_uno32/pins_arduino.h | 58 +- variants/d32/d32_core.h | 10 +- variants/d32/pins_arduino.h | 6 +- variants/d32_pro/pins_arduino.h | 18 +- variants/deneyapkart/pins_arduino.h | 32 +- variants/deneyapkart1A/pins_arduino.h | 36 +- variants/deneyapkart1Av2/pins_arduino.h | 50 +- variants/deneyapkartg/pins_arduino.h | 24 +- variants/deneyapmini/pins_arduino.h | 38 +- variants/deneyapminiv2/pins_arduino.h | 44 +- .../pins_arduino.h | 36 +- .../variant.cpp | 17 +- .../dfrobot_beetle_esp32c3/pins_arduino.h | 46 +- .../dfrobot_beetle_esp32c6/pins_arduino.h | 6 +- .../pins_arduino.h | 48 +- .../dfrobot_firebeetle2_esp32e/pins_arduino.h | 140 +- .../pins_arduino.h | 58 +- variants/dfrobot_romeo_esp32s3/pins_arduino.h | 86 +- variants/doitESP32devkitV1/pins_arduino.h | 10 +- variants/doitESPduino32/pins_arduino.h | 56 +- variants/dpu_esp32/pins_arduino.h | 24 +- variants/esp32-devkit-lipo/pins_arduino.h | 16 +- variants/esp32-evb/pins_arduino.h | 8 +- variants/esp32-gateway/pins_arduino.h | 30 +- variants/esp32-poe-iso/pins_arduino.h | 30 +- variants/esp32-poe/pins_arduino.h | 30 +- variants/esp32-sbc-fabgl/pins_arduino.h | 8 +- .../pins_arduino.h | 2 +- .../pins_arduino.h | 2 +- .../esp32-trueverit-iot-driver/pins_arduino.h | 2 +- variants/esp32/pins_arduino.h | 8 +- variants/esp320/pins_arduino.h | 10 +- variants/esp32_s3r8n16/pins_arduino.h | 12 +- variants/esp32c2/pins_arduino.h | 12 +- variants/esp32c3-devkit-lipo/pins_arduino.h | 18 +- variants/esp32c3/pins_arduino.h | 14 +- variants/esp32c6-evb/pins_arduino.h | 32 +- variants/esp32c6/pins_arduino.h | 14 +- variants/esp32da/pins_arduino.h | 8 +- variants/esp32h2-devkit-lipo/pins_arduino.h | 14 +- variants/esp32h2/pins_arduino.h | 14 +- variants/esp32micromod/pins_arduino.h | 16 +- .../esp32s2-devkit-lipo-usb/pins_arduino.h | 14 +- variants/esp32s2-devkit-lipo/pins_arduino.h | 16 +- variants/esp32s2/pins_arduino.h | 14 +- variants/esp32s2thing_plus/pins_arduino.h | 10 +- variants/esp32s2usb/pins_arduino.h | 32 +- variants/esp32s3-devkit-lipo/pins_arduino.h | 16 +- variants/esp32s3/pins_arduino.h | 14 +- variants/esp32s3_powerfeather/pins_arduino.h | 76 +- variants/esp32s3box/pins_arduino.h | 58 +- variants/esp32s3camlcd/pins_arduino.h | 90 +- variants/esp32s3usbotg/pins_arduino.h | 82 +- variants/esp32s3usbotg/variant.cpp | 82 +- variants/esp32thing/pins_arduino.h | 10 +- variants/esp32thing_plus/pins_arduino.h | 12 +- variants/esp32thing_plus_c/pins_arduino.h | 14 +- variants/esp32vn-iot-uno/pins_arduino.h | 8 +- variants/esp_c3_m1_i_kit/pins_arduino.h | 14 +- variants/espea32/pins_arduino.h | 10 +- variants/espectro32/pins_arduino.h | 12 +- variants/espino32/pins_arduino.h | 10 +- variants/feather_esp32/pins_arduino.h | 12 +- variants/firebeetle32/pins_arduino.h | 10 +- variants/fm-devkit/pins_arduino.h | 94 +- .../franzininho_wifi_esp32s2/pins_arduino.h | 22 +- .../pins_arduino.h | 32 +- variants/frog32/pins_arduino.h | 8 +- variants/gpy/pins_arduino.h | 28 +- variants/healthypi4/pins_arduino.h | 28 +- .../heltec_capsule_sensor_v3/pins_arduino.h | 12 +- variants/heltec_ht_de01/pins_arduino.h | 6 +- variants/heltec_wifi_kit_32/pins_arduino.h | 16 +- variants/heltec_wifi_kit_32_V3/pins_arduino.h | 8 +- variants/heltec_wifi_lora_32/pins_arduino.h | 16 +- .../heltec_wifi_lora_32_V2/pins_arduino.h | 14 +- .../heltec_wifi_lora_32_V3/pins_arduino.h | 14 +- .../heltec_wireless_bridge/pins_arduino.h | 20 +- .../heltec_wireless_mini_shell/pins_arduino.h | 12 +- variants/heltec_wireless_paper/pins_arduino.h | 8 +- .../heltec_wireless_shell_v3/pins_arduino.h | 14 +- variants/heltec_wireless_stick/pins_arduino.h | 14 +- .../heltec_wireless_stick_V1/pins_arduino.h | 14 +- .../heltec_wireless_stick_lite/pins_arduino.h | 14 +- .../pins_arduino.h | 14 +- .../heltec_wireless_stick_v3/pins_arduino.h | 16 +- .../heltec_wireless_tracker/pins_arduino.h | 14 +- variants/honeylemon/pins_arduino.h | 10 +- variants/hornbill32dev/pins_arduino.h | 48 +- variants/hornbill32minima/pins_arduino.h | 30 +- variants/imbrios-logsens-v1p1/pins_arduino.h | 46 +- variants/intorobot-fig/pins_arduino.h | 10 +- variants/ioxesp32/pins_arduino.h | 10 +- variants/lilygo_t_display/pins_arduino.h | 10 +- variants/lilygo_t_display_s3/pins_arduino.h | 28 +- variants/lionbit/pins_arduino.h | 94 +- variants/lionbits3/pins_arduino.h | 126 +- variants/lolin32-lite/pins_arduino.h | 10 +- variants/lolin32/pins_arduino.h | 10 +- variants/lolin_c3_mini/pins_arduino.h | 10 +- variants/lolin_c3_pico/pins_arduino.h | 12 +- variants/lolin_s2_mini/pins_arduino.h | 30 +- variants/lolin_s2_pico/pins_arduino.h | 32 +- variants/lolin_s3/pins_arduino.h | 12 +- variants/lolin_s3_mini/pins_arduino.h | 12 +- variants/lolin_s3_pro/pins_arduino.h | 20 +- variants/lopy/pins_arduino.h | 30 +- variants/lopy4/pins_arduino.h | 32 +- variants/m5stack_atom/pins_arduino.h | 8 +- variants/m5stack_atoms3/pins_arduino.h | 30 +- variants/m5stack_capsule/pins_arduino.h | 30 +- variants/m5stack_cardputer/pins_arduino.h | 30 +- variants/m5stack_core/pins_arduino.h | 8 +- variants/m5stack_core2/pins_arduino.h | 8 +- variants/m5stack_coreink/pins_arduino.h | 8 +- variants/m5stack_cores3/pins_arduino.h | 32 +- variants/m5stack_dial/pins_arduino.h | 30 +- variants/m5stack_fire/pins_arduino.h | 8 +- variants/m5stack_paper/pins_arduino.h | 8 +- variants/m5stack_poe_cam/pins_arduino.h | 8 +- variants/m5stack_stamp_c3/pins_arduino.h | 8 +- variants/m5stack_stamp_pico/pins_arduino.h | 8 +- variants/m5stack_stamp_s3/pins_arduino.h | 30 +- variants/m5stack_station/pins_arduino.h | 12 +- variants/m5stack_stickc/pins_arduino.h | 8 +- variants/m5stack_stickc_plus/pins_arduino.h | 8 +- variants/m5stack_stickc_plus2/pins_arduino.h | 8 +- variants/m5stack_timer_cam/pins_arduino.h | 6 +- variants/m5stack_tough/pins_arduino.h | 8 +- variants/m5stack_unit_cam/pins_arduino.h | 6 +- variants/m5stack_unit_cams3/pins_arduino.h | 30 +- variants/magicbit/pins_arduino.h | 12 +- variants/makergo_c3_supermini/pins_arduino.h | 13 +- variants/metro_esp-32/pins_arduino.h | 10 +- variants/mgbot-iotik32a/pins_arduino.h | 10 +- variants/mgbot-iotik32b/pins_arduino.h | 10 +- variants/mhetesp32devkit/pins_arduino.h | 10 +- variants/mhetesp32minikit/pins_arduino.h | 10 +- variants/micro_s2/pins_arduino.h | 18 +- variants/mpython/pins_arduino.h | 8 +- variants/namino_arancio/pins_arduino.h | 328 +- variants/namino_bianco/pins_arduino.h | 328 +- variants/namino_rosso/pins_arduino.h | 328 +- variants/nano32/pins_arduino.h | 10 +- variants/nina_w10/pins_arduino.h | 8 +- variants/node32s/pins_arduino.h | 10 +- variants/nodemcu-32s/pins_arduino.h | 10 +- .../nologo_esp32c3_super_mini/pins_arduino.h | 10 +- variants/nologo_esp32s3_pico/pins_arduino.h | 2 +- variants/nora_w10/pins_arduino.h | 122 +- variants/odroid_esp32/pins_arduino.h | 10 +- variants/onehorse32dev/pins_arduino.h | 10 +- variants/openkb/pins_arduino.h | 14 +- variants/oroca_edubot/pins_arduino.h | 14 +- variants/pico32/pins_arduino.h | 8 +- variants/piranha_esp-32/pins_arduino.h | 10 +- variants/pocket_32/pins_arduino.h | 10 +- variants/quantum/pins_arduino.h | 8 +- variants/redpill_esp32s3/pins_arduino.h | 10 +- variants/roboheart_hercules/pins_arduino.h | 20 +- .../partitions-4MB-tinyuf2.csv | 1 - variants/sensebox_mcu_esp32s2/pins_arduino.h | 124 +- variants/sensebox_mcu_esp32s2/variant.cpp | 16 +- .../pins_arduino.h | 14 +- .../pins_arduino.h | 6 +- .../pins_arduino.h | 10 +- .../pins_arduino.h | 104 +- .../sparkfun_pro_micro_esp32c3/pins_arduino.h | 34 +- variants/tamc_termod_s3/pins_arduino.h | 28 +- variants/tamc_termod_s3/variant.cpp | 14 +- variants/tbeam/pins_arduino.h | 28 +- .../thingpulse_epulse_feather/pins_arduino.h | 18 +- .../pins_arduino.h | 14 +- variants/ttgo-lora32-v1/pins_arduino.h | 140 +- variants/ttgo-lora32-v2/pins_arduino.h | 96 +- variants/ttgo-lora32-v21new/pins_arduino.h | 98 +- variants/ttgo-t-oi-plus/pins_arduino.h | 2 +- variants/ttgo-t1/pins_arduino.h | 10 +- variants/ttgo-t7-v13-mini32/pins_arduino.h | 10 +- variants/ttgo-t7-v14-mini32/pins_arduino.h | 10 +- variants/turta_iot_node/pins_arduino.h | 12 +- variants/twatch/pins_arduino.h | 24 +- variants/uPesy_edu_esp32/pins_arduino.h | 58 +- .../uPesy_esp32_wroom_devkit/pins_arduino.h | 10 +- .../uPesy_esp32_wrover_devkit/pins_arduino.h | 10 +- variants/uPesy_esp32c3_basic/pins_arduino.h | 8 +- variants/uPesy_esp32c3_mini/pins_arduino.h | 8 +- variants/uPesy_esp32s3_basic/pins_arduino.h | 20 +- variants/um_bling/pins_arduino.h | 6 +- variants/um_feathers2/pins_arduino.h | 12 +- variants/um_feathers2neo/pins_arduino.h | 16 +- variants/um_feathers3/pins_arduino.h | 18 +- variants/um_nanos3/pins_arduino.h | 16 +- variants/um_pros3/pins_arduino.h | 16 +- variants/um_rmp/pins_arduino.h | 16 +- variants/um_tinyc6/pins_arduino.h | 16 +- variants/um_tinypico/pins_arduino.h | 12 +- variants/um_tinys2/pins_arduino.h | 16 +- variants/um_tinys3/pins_arduino.h | 16 +- variants/unphone8/pins_arduino.h | 16 +- variants/unphone9/pins_arduino.h | 16 +- variants/vintlabsdevkitv1/pins_arduino.h | 12 +- variants/watchy/pins_arduino.h | 62 +- .../pins_arduino.h | 26 +- variants/wesp32/pins_arduino.h | 26 +- variants/widora-air/pins_arduino.h | 10 +- variants/wifiduino32/pins_arduino.h | 120 +- variants/wifiduino32s3/pins_arduino.h | 8 +- variants/wifiduinov2/pins_arduino.h | 10 +- variants/wipy3/pins_arduino.h | 14 +- variants/wt32-eth01/pins_arduino.h | 20 +- variants/wt32-sc01-plus/pins_arduino.h | 24 +- variants/xinabox/pins_arduino.h | 10 +- 999 files changed, 60033 insertions(+), 61179 deletions(-) mode change 100755 => 100644 libraries/BluetoothSerial/examples/bt_remove_paired_devices/bt_remove_paired_devices.ino mode change 100755 => 100644 libraries/NetBIOS/examples/ESP_NBNST/ESP_NBNST.ino mode change 100755 => 100644 libraries/NetBIOS/src/NetBIOS.cpp mode change 100755 => 100644 libraries/NetBIOS/src/NetBIOS.h mode change 100755 => 100644 variants/esp32micromod/pins_arduino.h mode change 100755 => 100644 variants/lolin32-lite/pins_arduino.h mode change 100755 => 100644 variants/sparkfun_lora_gateway_1-channel/pins_arduino.h mode change 100755 => 100644 variants/ttgo-t7-v13-mini32/pins_arduino.h mode change 100755 => 100644 variants/ttgo-t7-v14-mini32/pins_arduino.h diff --git a/CMakeLists.txt b/CMakeLists.txt index cc294494f43..aaa59b0fbb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,16 +129,16 @@ set(ARDUINO_LIBRARY_EEPROM_SRCS libraries/EEPROM/src/EEPROM.cpp) set(ARDUINO_LIBRARY_ESP_I2S_SRCS libraries/ESP_I2S/src/ESP_I2S.cpp) -set(ARDUINO_LIBRARY_ESP_NOW_SRCS +set(ARDUINO_LIBRARY_ESP_NOW_SRCS libraries/ESP_NOW/src/ESP32_NOW.cpp libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp) - -set(ARDUINO_LIBRARY_ESP_SR_SRCS + +set(ARDUINO_LIBRARY_ESP_SR_SRCS libraries/ESP_SR/src/ESP_SR.cpp libraries/ESP_SR/src/esp32-hal-sr.c) - + set(ARDUINO_LIBRARY_ESPmDNS_SRCS libraries/ESPmDNS/src/ESPmDNS.cpp) - + set(ARDUINO_LIBRARY_Ethernet_SRCS libraries/Ethernet/src/ETH.cpp) set(ARDUINO_LIBRARY_FFat_SRCS libraries/FFat/src/FFat.cpp) @@ -187,7 +187,7 @@ set(ARDUINO_LIBRARY_Ticker_SRCS libraries/Ticker/src/Ticker.cpp) set(ARDUINO_LIBRARY_Update_SRCS libraries/Update/src/Updater.cpp libraries/Update/src/HttpsOTAUpdate.cpp) - + set(ARDUINO_LIBRARY_USB_SRCS libraries/USB/src/USBHID.cpp libraries/USB/src/USBMIDI.cpp diff --git a/Kconfig.projbuild b/Kconfig.projbuild index af772bd4618..d753f436f70 100644 --- a/Kconfig.projbuild +++ b/Kconfig.projbuild @@ -209,7 +209,7 @@ config ARDUHAL_ESP_LOG default "n" help This option will redefine the ESP_LOGx macros to Arduino's log_x macros. - To enable for your application, add the follwing after your includes: + To enable for your application, add the following after your includes: #ifdef ARDUINO_ARCH_ESP32 #include "esp32-hal-log.h" #endif @@ -390,4 +390,3 @@ config ARDUINO_SELECTIVE_SimpleBLE default y endmenu - diff --git a/LICENSE.md b/LICENSE.md index d55f6088e5e..b14d908353d 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -4,7 +4,7 @@ Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - + Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -500,4 +500,4 @@ if necessary. Here is a sample; alter the names: signature of Ty Coon, 1 April 1990 Ty Coon, President of Vice -That's all there is to it! \ No newline at end of file +That's all there is to it! diff --git a/README.md b/README.md index 15866cfe7e4..940a9b7102b 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ You can use [EspExceptionDecoder](https://github.com/me-no-dev/EspExceptionDecod ### Issue/Bug report template -Before reporting an issue, make sure you've searched for similar one that was already created. Also make sure to go through all the issues labelled as [Type: For reference](https://github.com/espressif/arduino-esp32/issues?q=is%3Aissue+label%3A%22Type%3A+For+reference%22+). +Before reporting an issue, make sure you've searched for similar one that was already created. Also make sure to go through all the issues labeled as [Type: For reference](https://github.com/espressif/arduino-esp32/issues?q=is%3Aissue+label%3A%22Type%3A+For+reference%22+). Finally, if you are sure no one else had the issue, follow the **Issue template** or **Feature request template** while reporting any [new Issue](https://github.com/espressif/arduino-esp32/issues/new/choose). diff --git a/boards.txt b/boards.txt index e5b09978053..ec96b8ad34c 100644 --- a/boards.txt +++ b/boards.txt @@ -16309,7 +16309,7 @@ esp32s3-devkitlipo.menu.EraseFlash.none=Disabled esp32s3-devkitlipo.menu.EraseFlash.none.upload.erase_cmd= esp32s3-devkitlipo.menu.EraseFlash.all=Enabled esp32s3-devkitlipo.menu.EraseFlash.all.upload.erase_cmd=-e - + ############################################################## esp32c3-devkitlipo.name=OLIMEX ESP32-C3-DevKit-Lipo @@ -22487,7 +22487,7 @@ heltec_capsule_sensor_V3.menu.LORAWAN_PREAMBLE_LENGTH.1.build.LORAWAN_PREAMBLE_L heltec_capsule_sensor_V3.menu.SLOW_CLK_TPYE.0=External 32K (default) heltec_capsule_sensor_V3.menu.SLOW_CLK_TPYE.0.build.SLOW_CLK_TPYE=1 -heltec_capsule_sensor_V3.menu.SLOW_CLK_TPYE.1=Internal +heltec_capsule_sensor_V3.menu.SLOW_CLK_TPYE.1=Internal heltec_capsule_sensor_V3.menu.SLOW_CLK_TPYE.1.build.SLOW_CLK_TPYE=0 heltec_capsule_sensor_V3.menu.NetworkLogLevel.0=NONE @@ -22499,7 +22499,7 @@ heltec_capsule_sensor_V3.menu.NetworkLogLevel.2.build.NetworkLogLevel=2 heltec_capsule_sensor_V3.menu.NetworkLogLevel.3=INFO heltec_capsule_sensor_V3.menu.NetworkLogLevel.3.build.NetworkLogLevel=3 -heltec_capsule_sensor_V3.build.defines=-D{build.band} -DMCU_ESP32_S3 -DHELTEC_BOARD=50 -DCAPSULE_SENSOR_V3 -DSLOW_CLK_TPYE={build.SLOW_CLK_TPYE} -DRADIO_CHIP_SX1262 -DLoRaWAN_DEBUG_LEVEL={build.LoRaWanDebugLevel} -DACTIVE_REGION=LORAMAC_{build.band} -DLORAWAN_PREAMBLE_LENGTH={build.LORAWAN_PREAMBLE_LENGTH} -DLORAWAN_DEVEUI_AUTO={build.LORAWAN_DEVEUI_AUTO} -D{build.board} -DNLOG_LOCAL_LEVEL={build.NetworkLogLevel} +heltec_capsule_sensor_V3.build.defines=-D{build.band} -DMCU_ESP32_S3 -DHELTEC_BOARD=50 -DCAPSULE_SENSOR_V3 -DSLOW_CLK_TPYE={build.SLOW_CLK_TPYE} -DRADIO_CHIP_SX1262 -DLoRaWAN_DEBUG_LEVEL={build.LoRaWanDebugLevel} -DACTIVE_REGION=LORAMAC_{build.band} -DLORAWAN_PREAMBLE_LENGTH={build.LORAWAN_PREAMBLE_LENGTH} -DLORAWAN_DEVEUI_AUTO={build.LORAWAN_DEVEUI_AUTO} -D{build.board} -DNLOG_LOCAL_LEVEL={build.NetworkLogLevel} heltec_capsule_sensor_V3.menu.EraseFlash.none=Disabled heltec_capsule_sensor_V3.menu.EraseFlash.none.upload.erase_cmd= diff --git a/cores/esp32/Arduino.h b/cores/esp32/Arduino.h index b03c34f297f..88c84047e84 100644 --- a/cores/esp32/Arduino.h +++ b/cores/esp32/Arduino.h @@ -48,19 +48,19 @@ #define RAD_TO_DEG 57.295779513082320876798154814105 #define EULER 2.718281828459045235360287471352 -#define SERIAL 0x0 +#define SERIAL 0x0 #define DISPLAY 0x1 #define LSBFIRST 0 #define MSBFIRST 1 //Interrupt Modes -#define RISING 0x01 -#define FALLING 0x02 -#define CHANGE 0x03 -#define ONLOW 0x04 -#define ONHIGH 0x05 -#define ONLOW_WE 0x0C +#define RISING 0x01 +#define FALLING 0x02 +#define CHANGE 0x03 +#define ONLOW 0x04 +#define ONHIGH 0x05 +#define ONLOW_WE 0x0C #define ONHIGH_WE 0x0D #define DEFAULT 1 @@ -71,14 +71,14 @@ #endif // can't define max() / min() because of conflicts with C++ -#define _min(a,b) ((a)<(b)?(a):(b)) -#define _max(a,b) ((a)>(b)?(a):(b)) -#define _abs(x) ((x)>0?(x):-(x)) // abs() comes from STL -#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) -#define _round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) // round() comes from STL +#define _min(a, b) ((a) < (b) ? (a) : (b)) +#define _max(a, b) ((a) > (b) ? (a) : (b)) +#define _abs(x) ((x) > 0 ? (x) : -(x)) // abs() comes from STL +#define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt))) +#define _round(x) ((x) >= 0 ? (long)((x) + 0.5) : (long)((x)-0.5)) // round() comes from STL #define radians(deg) ((deg)*DEG_TO_RAD) #define degrees(rad) ((rad)*RAD_TO_DEG) -#define sq(x) ((x)*(x)) +#define sq(x) ((x) * (x)) // ESP32xx runs FreeRTOS... disabling interrupts can lead to issues, such as Watchdog Timeout #define sei() portENABLE_INTERRUPTS() @@ -86,12 +86,12 @@ #define interrupts() sei() #define noInterrupts() cli() -#define clockCyclesPerMicrosecond() ( (long int)getCpuFrequencyMhz() ) -#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) -#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) +#define clockCyclesPerMicrosecond() ((long int)getCpuFrequencyMhz()) +#define clockCyclesToMicroseconds(a) ((a) / clockCyclesPerMicrosecond()) +#define microsecondsToClockCycles(a) ((a)*clockCyclesPerMicrosecond()) -#define lowByte(w) ((uint8_t) ((w) & 0xff)) -#define highByte(w) ((uint8_t) ((w) >> 8)) +#define lowByte(w) ((uint8_t)((w)&0xff)) +#define highByte(w) ((uint8_t)((w) >> 8)) #define bitRead(value, bit) (((value) >> (bit)) & 0x01) #define bitSet(value, bit) ((value) |= (1UL << (bit))) @@ -101,26 +101,27 @@ // avr-libc defines _NOP() since 1.6.2 #ifndef _NOP -#define _NOP() do { __asm__ volatile ("nop"); } while (0) +#define _NOP() \ + do { __asm__ volatile("nop"); } while (0) #endif #define bit(b) (1UL << (b)) #define _BV(b) (1UL << (b)) -#define digitalPinToTimer(pin) (0) -#define analogInPinToBit(P) (P) +#define digitalPinToTimer(pin) (0) +#define analogInPinToBit(P) (P) #if SOC_GPIO_PIN_COUNT <= 32 -#define digitalPinToPort(pin) (0) -#define digitalPinToBitMask(pin) (1UL << digitalPinToGPIONumber(pin)) -#define portOutputRegister(port) ((volatile uint32_t*)GPIO_OUT_REG) -#define portInputRegister(port) ((volatile uint32_t*)GPIO_IN_REG) -#define portModeRegister(port) ((volatile uint32_t*)GPIO_ENABLE_REG) +#define digitalPinToPort(pin) (0) +#define digitalPinToBitMask(pin) (1UL << digitalPinToGPIONumber(pin)) +#define portOutputRegister(port) ((volatile uint32_t*)GPIO_OUT_REG) +#define portInputRegister(port) ((volatile uint32_t*)GPIO_IN_REG) +#define portModeRegister(port) ((volatile uint32_t*)GPIO_ENABLE_REG) #elif SOC_GPIO_PIN_COUNT <= 64 -#define digitalPinToPort(pin) ((digitalPinToGPIONumber(pin)>31)?1:0) -#define digitalPinToBitMask(pin) (1UL << (digitalPinToGPIONumber(pin)&31)) -#define portOutputRegister(port) ((volatile uint32_t*)((port)?GPIO_OUT1_REG:GPIO_OUT_REG)) -#define portInputRegister(port) ((volatile uint32_t*)((port)?GPIO_IN1_REG:GPIO_IN_REG)) -#define portModeRegister(port) ((volatile uint32_t*)((port)?GPIO_ENABLE1_REG:GPIO_ENABLE_REG)) +#define digitalPinToPort(pin) ((digitalPinToGPIONumber(pin) > 31) ? 1 : 0) +#define digitalPinToBitMask(pin) (1UL << (digitalPinToGPIONumber(pin) & 31)) +#define portOutputRegister(port) ((volatile uint32_t*)((port) ? GPIO_OUT1_REG : GPIO_OUT_REG)) +#define portInputRegister(port) ((volatile uint32_t*)((port) ? GPIO_IN1_REG : GPIO_IN_REG)) +#define portModeRegister(port) ((volatile uint32_t*)((port) ? GPIO_ENABLE1_REG : GPIO_ENABLE_REG)) #else #error SOC_GPIO_PIN_COUNT > 64 not implemented #endif @@ -131,16 +132,16 @@ #define NOT_ON_TIMER 0 // some defines generic for all SoC moved from variants/board_name/pins_arduino.h -#define NUM_DIGITAL_PINS SOC_GPIO_PIN_COUNT // All GPIOs +#define NUM_DIGITAL_PINS SOC_GPIO_PIN_COUNT // All GPIOs #if SOC_ADC_PERIPH_NUM == 1 -#define NUM_ANALOG_INPUTS (SOC_ADC_CHANNEL_NUM(0)) // Depends on the SoC (ESP32C6, ESP32H2, ESP32C2, ESP32P4) +#define NUM_ANALOG_INPUTS (SOC_ADC_CHANNEL_NUM(0)) // Depends on the SoC (ESP32C6, ESP32H2, ESP32C2, ESP32P4) #elif SOC_ADC_PERIPH_NUM == 2 -#define NUM_ANALOG_INPUTS (SOC_ADC_CHANNEL_NUM(0)+SOC_ADC_CHANNEL_NUM(1)) // Depends on the SoC (ESP32, ESP32S2, ESP32S3, ESP32C3) +#define NUM_ANALOG_INPUTS (SOC_ADC_CHANNEL_NUM(0) + SOC_ADC_CHANNEL_NUM(1)) // Depends on the SoC (ESP32, ESP32S2, ESP32S3, ESP32C3) #endif -#define EXTERNAL_NUM_INTERRUPTS NUM_DIGITAL_PINS // All GPIOs -#define analogInputToDigitalPin(p) (((p)1) ? (((i)* 0x1000) + 0x20000) : (((~(i)) & 1)* 0x1000 ))) - #endif // REG_SPI_BASE -#endif // TARGET +#ifndef REG_SPI_BASE +#define REG_SPI_BASE(i) (DR_REG_SPI1_BASE + (((i) > 1) ? (((i)*0x1000) + 0x20000) : (((~(i)) & 1) * 0x1000))) +#endif // REG_SPI_BASE +#endif // TARGET /** * User-defined Literals @@ -83,230 +83,208 @@ extern "C" { * uint32_t = test = 10_MHz; // --> 10000000 */ -unsigned long long operator"" _kHz(unsigned long long x) -{ - return x * 1000; +unsigned long long operator"" _kHz(unsigned long long x) { + return x * 1000; } -unsigned long long operator"" _MHz(unsigned long long x) -{ - return x * 1000 * 1000; +unsigned long long operator"" _MHz(unsigned long long x) { + return x * 1000 * 1000; } -unsigned long long operator"" _GHz(unsigned long long x) -{ - return x * 1000 * 1000 * 1000; +unsigned long long operator"" _GHz(unsigned long long x) { + return x * 1000 * 1000 * 1000; } -unsigned long long operator"" _kBit(unsigned long long x) -{ - return x * 1024; +unsigned long long operator"" _kBit(unsigned long long x) { + return x * 1024; } -unsigned long long operator"" _MBit(unsigned long long x) -{ - return x * 1024 * 1024; +unsigned long long operator"" _MBit(unsigned long long x) { + return x * 1024 * 1024; } -unsigned long long operator"" _GBit(unsigned long long x) -{ - return x * 1024 * 1024 * 1024; +unsigned long long operator"" _GBit(unsigned long long x) { + return x * 1024 * 1024 * 1024; } -unsigned long long operator"" _kB(unsigned long long x) -{ - return x * 1024; +unsigned long long operator"" _kB(unsigned long long x) { + return x * 1024; } -unsigned long long operator"" _MB(unsigned long long x) -{ - return x * 1024 * 1024; +unsigned long long operator"" _MB(unsigned long long x) { + return x * 1024 * 1024; } -unsigned long long operator"" _GB(unsigned long long x) -{ - return x * 1024 * 1024 * 1024; +unsigned long long operator"" _GB(unsigned long long x) { + return x * 1024 * 1024 * 1024; } EspClass ESP; -void EspClass::deepSleep(uint64_t time_us) -{ - esp_deep_sleep(time_us); +void EspClass::deepSleep(uint64_t time_us) { + esp_deep_sleep(time_us); } -void EspClass::restart(void) -{ - esp_restart(); +void EspClass::restart(void) { + esp_restart(); } -uint32_t EspClass::getHeapSize(void) -{ - return heap_caps_get_total_size(MALLOC_CAP_INTERNAL); +uint32_t EspClass::getHeapSize(void) { + return heap_caps_get_total_size(MALLOC_CAP_INTERNAL); } -uint32_t EspClass::getFreeHeap(void) -{ - return heap_caps_get_free_size(MALLOC_CAP_INTERNAL); +uint32_t EspClass::getFreeHeap(void) { + return heap_caps_get_free_size(MALLOC_CAP_INTERNAL); } -uint32_t EspClass::getMinFreeHeap(void) -{ - return heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL); +uint32_t EspClass::getMinFreeHeap(void) { + return heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL); } -uint32_t EspClass::getMaxAllocHeap(void) -{ - return heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL); +uint32_t EspClass::getMaxAllocHeap(void) { + return heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL); } -uint32_t EspClass::getPsramSize(void) -{ - if(psramFound()){ - return heap_caps_get_total_size(MALLOC_CAP_SPIRAM); - } - return 0; +uint32_t EspClass::getPsramSize(void) { + if (psramFound()) { + return heap_caps_get_total_size(MALLOC_CAP_SPIRAM); + } + return 0; } -uint32_t EspClass::getFreePsram(void) -{ - if(psramFound()){ - return heap_caps_get_free_size(MALLOC_CAP_SPIRAM); - } - return 0; +uint32_t EspClass::getFreePsram(void) { + if (psramFound()) { + return heap_caps_get_free_size(MALLOC_CAP_SPIRAM); + } + return 0; } -uint32_t EspClass::getMinFreePsram(void) -{ - if(psramFound()){ - return heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM); - } - return 0; +uint32_t EspClass::getMinFreePsram(void) { + if (psramFound()) { + return heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM); + } + return 0; } -uint32_t EspClass::getMaxAllocPsram(void) -{ - if(psramFound()){ - return heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM); - } - return 0; +uint32_t EspClass::getMaxAllocPsram(void) { + if (psramFound()) { + return heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM); + } + return 0; } static uint32_t sketchSize(sketchSize_t response) { - esp_image_metadata_t data; - const esp_partition_t *running = esp_ota_get_running_partition(); - if (!running) return 0; - const esp_partition_pos_t running_pos = { - .offset = running->address, - .size = running->size, - }; - data.start_addr = running_pos.offset; - esp_image_verify(ESP_IMAGE_VERIFY, &running_pos, &data); - if (response) { - return running_pos.size - data.image_len; - } else { - return data.image_len; - } -} - -uint32_t EspClass::getSketchSize () { - return sketchSize(SKETCH_SIZE_TOTAL); -} - -String EspClass::getSketchMD5() -{ - static String result; - if (result.length()) { - return result; - } - uint32_t lengthLeft = getSketchSize(); - - const esp_partition_t *running = esp_ota_get_running_partition(); - if (!running) { - log_e("Partition could not be found"); - return String(); + esp_image_metadata_t data; + const esp_partition_t *running = esp_ota_get_running_partition(); + if (!running) return 0; + const esp_partition_pos_t running_pos = { + .offset = running->address, + .size = running->size, + }; + data.start_addr = running_pos.offset; + esp_image_verify(ESP_IMAGE_VERIFY, &running_pos, &data); + if (response) { + return running_pos.size - data.image_len; + } else { + return data.image_len; + } +} + +uint32_t EspClass::getSketchSize() { + return sketchSize(SKETCH_SIZE_TOTAL); +} + +String EspClass::getSketchMD5() { + static String result; + if (result.length()) { + return result; + } + uint32_t lengthLeft = getSketchSize(); + + const esp_partition_t *running = esp_ota_get_running_partition(); + if (!running) { + log_e("Partition could not be found"); + return String(); + } + + const size_t bufSize = SPI_FLASH_SEC_SIZE; + uint8_t *pb = (uint8_t *)malloc(bufSize); + if (!pb) { + log_e("Not enough memory to allocate buffer"); + return String(); + } + uint32_t offset = 0; + + MD5Builder md5; + md5.begin(); + while (lengthLeft > 0) { + size_t readBytes = (lengthLeft < bufSize) ? lengthLeft : bufSize; + if (!ESP.flashRead(running->address + offset, (uint32_t *)pb, (readBytes + 3) & ~3)) { + free(pb); + log_e("Could not read buffer from flash"); + return String(); } + md5.add(pb, readBytes); + lengthLeft -= readBytes; + offset += readBytes; - const size_t bufSize = SPI_FLASH_SEC_SIZE; - uint8_t *pb = (uint8_t *)malloc(bufSize); - if(!pb) { - log_e("Not enough memory to allocate buffer"); - return String(); - } - uint32_t offset = 0; - - MD5Builder md5; - md5.begin(); - while(lengthLeft > 0) { - size_t readBytes = (lengthLeft < bufSize) ? lengthLeft : bufSize; - if (!ESP.flashRead(running->address + offset, (uint32_t *)pb, (readBytes + 3) & ~3)) { - free(pb); - log_e("Could not read buffer from flash"); - return String(); - } - md5.add(pb, readBytes); - lengthLeft -= readBytes; - offset += readBytes; - - #if CONFIG_FREERTOS_UNICORE - delay(1); // Fix solo WDT - #endif - } - free(pb); - md5.calculate(); - result = md5.toString(); - return result; +#if CONFIG_FREERTOS_UNICORE + delay(1); // Fix solo WDT +#endif + } + free(pb); + md5.calculate(); + result = md5.toString(); + return result; } -uint32_t EspClass::getFreeSketchSpace () { - const esp_partition_t* _partition = esp_ota_get_next_update_partition(NULL); - if(!_partition){ - return 0; - } +uint32_t EspClass::getFreeSketchSpace() { + const esp_partition_t *_partition = esp_ota_get_next_update_partition(NULL); + if (!_partition) { + return 0; + } - return _partition->size; + return _partition->size; } -uint16_t EspClass::getChipRevision(void) -{ - esp_chip_info_t chip_info; - esp_chip_info(&chip_info); - return chip_info.revision; +uint16_t EspClass::getChipRevision(void) { + esp_chip_info_t chip_info; + esp_chip_info(&chip_info); + return chip_info.revision; } -const char * EspClass::getChipModel(void) -{ +const char *EspClass::getChipModel(void) { #if CONFIG_IDF_TARGET_ESP32 - uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_PACKAGE); - uint32_t pkg_ver = chip_ver & 0x7; - switch (pkg_ver) { - case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6 : - if (getChipRevision() == 3) - return "ESP32-D0WDQ6-V3"; - else - return "ESP32-D0WDQ6"; - case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ5 : - if (getChipRevision() == 3) - return "ESP32-D0WD-V3"; - else - return "ESP32-D0WD"; - case EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 : - return "ESP32-D2WD"; - case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2 : - return "ESP32-PICO-D2"; - case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4 : - return "ESP32-PICO-D4"; - case EFUSE_RD_CHIP_VER_PKG_ESP32PICOV302 : - return "ESP32-PICO-V3-02"; - case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDR2V3 : - return "ESP32-D0WDR2-V3"; - default: - return "Unknown"; - } + uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_PACKAGE); + uint32_t pkg_ver = chip_ver & 0x7; + switch (pkg_ver) { + case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6: + if (getChipRevision() == 3) + return "ESP32-D0WDQ6-V3"; + else + return "ESP32-D0WDQ6"; + case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ5: + if (getChipRevision() == 3) + return "ESP32-D0WD-V3"; + else + return "ESP32-D0WD"; + case EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5: + return "ESP32-D2WD"; + case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2: + return "ESP32-PICO-D2"; + case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4: + return "ESP32-PICO-D4"; + case EFUSE_RD_CHIP_VER_PKG_ESP32PICOV302: + return "ESP32-PICO-V3-02"; + case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDR2V3: + return "ESP32-D0WDR2-V3"; + default: + return "Unknown"; + } #elif CONFIG_IDF_TARGET_ESP32S2 - uint32_t pkg_ver = REG_GET_FIELD(EFUSE_RD_MAC_SPI_SYS_3_REG, EFUSE_PKG_VERSION); - switch (pkg_ver) { + uint32_t pkg_ver = REG_GET_FIELD(EFUSE_RD_MAC_SPI_SYS_3_REG, EFUSE_PKG_VERSION); + switch (pkg_ver) { case 0: return "ESP32-S2"; case 1: @@ -315,91 +293,83 @@ const char * EspClass::getChipModel(void) return "ESP32-S2FH32"; default: return "ESP32-S2 (Unknown)"; - } + } #else - esp_chip_info_t chip_info; - esp_chip_info(&chip_info); - switch(chip_info.model){ - case CHIP_ESP32S3: return "ESP32-S3"; - case CHIP_ESP32C3: return "ESP32-C3"; - case CHIP_ESP32C2: return "ESP32-C2"; - case CHIP_ESP32C6: return "ESP32-C6"; - case CHIP_ESP32H2: return "ESP32-H2"; - default: return "UNKNOWN"; - } + esp_chip_info_t chip_info; + esp_chip_info(&chip_info); + switch (chip_info.model) { + case CHIP_ESP32S3: return "ESP32-S3"; + case CHIP_ESP32C3: return "ESP32-C3"; + case CHIP_ESP32C2: return "ESP32-C2"; + case CHIP_ESP32C6: return "ESP32-C6"; + case CHIP_ESP32H2: return "ESP32-H2"; + default: return "UNKNOWN"; + } #endif } -uint8_t EspClass::getChipCores(void) -{ - esp_chip_info_t chip_info; - esp_chip_info(&chip_info); - return chip_info.cores; +uint8_t EspClass::getChipCores(void) { + esp_chip_info_t chip_info; + esp_chip_info(&chip_info); + return chip_info.cores; } -const char * EspClass::getSdkVersion(void) -{ - return esp_get_idf_version(); +const char *EspClass::getSdkVersion(void) { + return esp_get_idf_version(); } -const char * EspClass::getCoreVersion(void) -{ - return ESP_ARDUINO_VERSION_STR; +const char *EspClass::getCoreVersion(void) { + return ESP_ARDUINO_VERSION_STR; } -uint32_t ESP_getFlashChipId(void) -{ +uint32_t ESP_getFlashChipId(void) { uint32_t id = g_rom_flashchip.device_id; id = ((id & 0xff) << 16) | ((id >> 16) & 0xff) | (id & 0xff00); return id; } -uint32_t EspClass::getFlashChipSize(void) -{ +uint32_t EspClass::getFlashChipSize(void) { uint32_t id = (ESP_getFlashChipId() >> 16) & 0xFF; return 2 << (id - 1); } -uint32_t EspClass::getFlashChipSpeed(void) -{ - esp_image_header_t fhdr; - if(esp_flash_read(esp_flash_default_chip, (void*)&fhdr, ESP_FLASH_IMAGE_BASE, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) { - return 0; - } - return magicFlashChipSpeed(fhdr.spi_speed); -} - -FlashMode_t EspClass::getFlashChipMode(void) -{ - #if CONFIG_IDF_TARGET_ESP32S2 - uint32_t spi_ctrl = REG_READ(PERIPHS_SPI_FLASH_CTRL); - #else - #if CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C6 - uint32_t spi_ctrl = REG_READ(DR_REG_SPI0_BASE + 0x8); - #else - uint32_t spi_ctrl = REG_READ(SPI_CTRL_REG(0)); - #endif - #endif - /* Not all of the following constants are already defined in older versions of spi_reg.h, so do it manually for now*/ - if (spi_ctrl & BIT(24)) { //SPI_FREAD_QIO - return (FM_QIO); - } else if (spi_ctrl & BIT(20)) { //SPI_FREAD_QUAD - return (FM_QOUT); - } else if (spi_ctrl & BIT(23)) { //SPI_FREAD_DIO - return (FM_DIO); - } else if (spi_ctrl & BIT(14)) { // SPI_FREAD_DUAL - return (FM_DOUT); - } else if (spi_ctrl & BIT(13)) { //SPI_FASTRD_MODE - return (FM_FAST_READ); - } else { - return (FM_SLOW_READ); - } - return (FM_DOUT); -} - -uint32_t EspClass::magicFlashChipSize(uint8_t byte) -{ -/* +uint32_t EspClass::getFlashChipSpeed(void) { + esp_image_header_t fhdr; + if (esp_flash_read(esp_flash_default_chip, (void *)&fhdr, ESP_FLASH_IMAGE_BASE, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) { + return 0; + } + return magicFlashChipSpeed(fhdr.spi_speed); +} + +FlashMode_t EspClass::getFlashChipMode(void) { +#if CONFIG_IDF_TARGET_ESP32S2 + uint32_t spi_ctrl = REG_READ(PERIPHS_SPI_FLASH_CTRL); +#else +#if CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C6 + uint32_t spi_ctrl = REG_READ(DR_REG_SPI0_BASE + 0x8); +#else + uint32_t spi_ctrl = REG_READ(SPI_CTRL_REG(0)); +#endif +#endif + /* Not all of the following constants are already defined in older versions of spi_reg.h, so do it manually for now*/ + if (spi_ctrl & BIT(24)) { //SPI_FREAD_QIO + return (FM_QIO); + } else if (spi_ctrl & BIT(20)) { //SPI_FREAD_QUAD + return (FM_QOUT); + } else if (spi_ctrl & BIT(23)) { //SPI_FREAD_DIO + return (FM_DIO); + } else if (spi_ctrl & BIT(14)) { // SPI_FREAD_DUAL + return (FM_DOUT); + } else if (spi_ctrl & BIT(13)) { //SPI_FASTRD_MODE + return (FM_FAST_READ); + } else { + return (FM_SLOW_READ); + } + return (FM_DOUT); +} + +uint32_t EspClass::magicFlashChipSize(uint8_t byte) { + /* FLASH_SIZES = { "1MB": 0x00, "2MB": 0x10, @@ -411,24 +381,23 @@ uint32_t EspClass::magicFlashChipSize(uint8_t byte) "128MB": 0x70, } */ - switch(byte & 0x0F) { - case 0x0: return (1_MB); // 8 MBit (1MB) - case 0x1: return (2_MB); // 16 MBit (2MB) - case 0x2: return (4_MB); // 32 MBit (4MB) - case 0x3: return (8_MB); // 64 MBit (8MB) - case 0x4: return (16_MB); // 128 MBit (16MB) - case 0x5: return (32_MB); // 256 MBit (32MB) - case 0x6: return (64_MB); // 512 MBit (64MB) - case 0x7: return (128_MB); // 1 GBit (128MB) - default: // fail? - return 0; - } -} - -uint32_t EspClass::magicFlashChipSpeed(uint8_t byte) -{ + switch (byte & 0x0F) { + case 0x0: return (1_MB); // 8 MBit (1MB) + case 0x1: return (2_MB); // 16 MBit (2MB) + case 0x2: return (4_MB); // 32 MBit (4MB) + case 0x3: return (8_MB); // 64 MBit (8MB) + case 0x4: return (16_MB); // 128 MBit (16MB) + case 0x5: return (32_MB); // 256 MBit (32MB) + case 0x6: return (64_MB); // 512 MBit (64MB) + case 0x7: return (128_MB); // 1 GBit (128MB) + default: // fail? + return 0; + } +} + +uint32_t EspClass::magicFlashChipSpeed(uint8_t byte) { #if CONFIG_IDF_TARGET_ESP32C2 -/* + /* FLASH_FREQUENCY = { "60m": 0xF, "30m": 0x0, @@ -436,34 +405,34 @@ uint32_t EspClass::magicFlashChipSpeed(uint8_t byte) "15m": 0x2, } */ - switch(byte & 0x0F) { - case 0xF: return (60_MHz); - case 0x0: return (30_MHz); - case 0x1: return (20_MHz); - case 0x2: return (15_MHz); - default: // fail? - return 0; - } + switch (byte & 0x0F) { + case 0xF: return (60_MHz); + case 0x0: return (30_MHz); + case 0x1: return (20_MHz); + case 0x2: return (15_MHz); + default: // fail? + return 0; + } #elif CONFIG_IDF_TARGET_ESP32C6 -/* + /* FLASH_FREQUENCY = { "80m": 0x0, # workaround for wrong mspi HS div value in ROM "40m": 0x0, "20m": 0x2, } */ - switch(byte & 0x0F) { - case 0x0: return (80_MHz); - case 0x2: return (20_MHz); - default: // fail? - return 0; - } + switch (byte & 0x0F) { + case 0x0: return (80_MHz); + case 0x2: return (20_MHz); + default: // fail? + return 0; + } #elif CONFIG_IDF_TARGET_ESP32H2 -/* + /* FLASH_FREQUENCY = { "48m": 0xF, "24m": 0x0, @@ -471,18 +440,18 @@ uint32_t EspClass::magicFlashChipSpeed(uint8_t byte) "12m": 0x2, } */ - switch(byte & 0x0F) { - case 0xF: return (48_MHz); - case 0x0: return (24_MHz); - case 0x1: return (16_MHz); - case 0x2: return (12_MHz); - default: // fail? - return 0; - } + switch (byte & 0x0F) { + case 0xF: return (48_MHz); + case 0x0: return (24_MHz); + case 0x1: return (16_MHz); + case 0x2: return (12_MHz); + default: // fail? + return 0; + } #else -/* + /* FLASH_FREQUENCY = { "80m": 0xF, "40m": 0x0, @@ -490,61 +459,53 @@ uint32_t EspClass::magicFlashChipSpeed(uint8_t byte) "20m": 0x2, } */ - switch(byte & 0x0F) { - case 0xF: return (80_MHz); - case 0x0: return (40_MHz); - case 0x1: return (26_MHz); - case 0x2: return (20_MHz); - default: // fail? - return 0; - } + switch (byte & 0x0F) { + case 0xF: return (80_MHz); + case 0x0: return (40_MHz); + case 0x1: return (26_MHz); + case 0x2: return (20_MHz); + default: // fail? + return 0; + } #endif } -FlashMode_t EspClass::magicFlashChipMode(uint8_t byte) -{ - FlashMode_t mode = (FlashMode_t) byte; - if(mode > FM_SLOW_READ) { - mode = FM_UNKNOWN; - } - return mode; +FlashMode_t EspClass::magicFlashChipMode(uint8_t byte) { + FlashMode_t mode = (FlashMode_t)byte; + if (mode > FM_SLOW_READ) { + mode = FM_UNKNOWN; + } + return mode; } -bool EspClass::flashEraseSector(uint32_t sector) -{ - return esp_flash_erase_region(esp_flash_default_chip, sector * SPI_FLASH_SEC_SIZE, SPI_FLASH_SEC_SIZE) == ESP_OK; +bool EspClass::flashEraseSector(uint32_t sector) { + return esp_flash_erase_region(esp_flash_default_chip, sector * SPI_FLASH_SEC_SIZE, SPI_FLASH_SEC_SIZE) == ESP_OK; } // Warning: These functions do not work with encrypted flash -bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size) -{ - return esp_flash_write(esp_flash_default_chip, (const void*) data, offset, size) == ESP_OK; +bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size) { + return esp_flash_write(esp_flash_default_chip, (const void *)data, offset, size) == ESP_OK; } -bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size) -{ - return esp_flash_read(esp_flash_default_chip, (void*) data, offset, size) == ESP_OK; +bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size) { + return esp_flash_read(esp_flash_default_chip, (void *)data, offset, size) == ESP_OK; } -bool EspClass::partitionEraseRange(const esp_partition_t *partition, uint32_t offset, size_t size) -{ - return esp_partition_erase_range(partition, offset, size) == ESP_OK; +bool EspClass::partitionEraseRange(const esp_partition_t *partition, uint32_t offset, size_t size) { + return esp_partition_erase_range(partition, offset, size) == ESP_OK; } -bool EspClass::partitionWrite(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size) -{ - return esp_partition_write(partition, offset, data, size) == ESP_OK; +bool EspClass::partitionWrite(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size) { + return esp_partition_write(partition, offset, data, size) == ESP_OK; } -bool EspClass::partitionRead(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size) -{ - return esp_partition_read(partition, offset, data, size) == ESP_OK; +bool EspClass::partitionRead(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size) { + return esp_partition_read(partition, offset, data, size) == ESP_OK; } -uint64_t EspClass::getEfuseMac(void) -{ - uint64_t _chipmacid = 0LL; - esp_efuse_mac_get_default((uint8_t*) (&_chipmacid)); - return _chipmacid; +uint64_t EspClass::getEfuseMac(void) { + uint64_t _chipmacid = 0LL; + esp_efuse_mac_get_default((uint8_t *)(&_chipmacid)); + return _chipmacid; } diff --git a/cores/esp32/Esp.h b/cores/esp32/Esp.h index 82dd25e3c25..58e428c918d 100644 --- a/cores/esp32/Esp.h +++ b/cores/esp32/Esp.h @@ -26,97 +26,96 @@ #include "esp_cpu.h" /** - * AVR macros for WDT managment + * AVR macros for WDT management */ typedef enum { - WDTO_0MS = 0, //!< WDTO_0MS - WDTO_15MS = 15, //!< WDTO_15MS - WDTO_30MS = 30, //!< WDTO_30MS - WDTO_60MS = 60, //!< WDTO_60MS - WDTO_120MS = 120, //!< WDTO_120MS - WDTO_250MS = 250, //!< WDTO_250MS - WDTO_500MS = 500, //!< WDTO_500MS - WDTO_1S = 1000,//!< WDTO_1S - WDTO_2S = 2000,//!< WDTO_2S - WDTO_4S = 4000,//!< WDTO_4S - WDTO_8S = 8000 //!< WDTO_8S + WDTO_0MS = 0, //!< WDTO_0MS + WDTO_15MS = 15, //!< WDTO_15MS + WDTO_30MS = 30, //!< WDTO_30MS + WDTO_60MS = 60, //!< WDTO_60MS + WDTO_120MS = 120, //!< WDTO_120MS + WDTO_250MS = 250, //!< WDTO_250MS + WDTO_500MS = 500, //!< WDTO_500MS + WDTO_1S = 1000, //!< WDTO_1S + WDTO_2S = 2000, //!< WDTO_2S + WDTO_4S = 4000, //!< WDTO_4S + WDTO_8S = 8000 //!< WDTO_8S } WDTO_t; typedef enum { - FM_QIO = 0x00, - FM_QOUT = 0x01, - FM_DIO = 0x02, - FM_DOUT = 0x03, - FM_FAST_READ = 0x04, - FM_SLOW_READ = 0x05, - FM_UNKNOWN = 0xff + FM_QIO = 0x00, + FM_QOUT = 0x01, + FM_DIO = 0x02, + FM_DOUT = 0x03, + FM_FAST_READ = 0x04, + FM_SLOW_READ = 0x05, + FM_UNKNOWN = 0xff } FlashMode_t; typedef enum { - SKETCH_SIZE_TOTAL = 0, - SKETCH_SIZE_FREE = 1 + SKETCH_SIZE_TOTAL = 0, + SKETCH_SIZE_FREE = 1 } sketchSize_t; -class EspClass -{ +class EspClass { public: - EspClass() {} - ~EspClass() {} - void restart(); - - //Internal RAM - uint32_t getHeapSize(); //total heap size - uint32_t getFreeHeap(); //available heap - uint32_t getMinFreeHeap(); //lowest level of free heap since boot - uint32_t getMaxAllocHeap(); //largest block of heap that can be allocated at once - - //SPI RAM - uint32_t getPsramSize(); - uint32_t getFreePsram(); - uint32_t getMinFreePsram(); - uint32_t getMaxAllocPsram(); - - uint16_t getChipRevision(); - const char * getChipModel(); - uint8_t getChipCores(); - uint32_t getCpuFreqMHz(){ return getCpuFrequencyMhz(); } - inline uint32_t getCycleCount() __attribute__((always_inline)); - - const char * getSdkVersion(); //version of ESP-IDF - const char * getCoreVersion();//version of this core - - void deepSleep(uint64_t time_us); - - uint32_t getFlashChipSize(); - uint32_t getFlashChipSpeed(); - FlashMode_t getFlashChipMode(); - - uint32_t magicFlashChipSize(uint8_t byte); - uint32_t magicFlashChipSpeed(uint8_t byte); - FlashMode_t magicFlashChipMode(uint8_t byte); - - uint32_t getSketchSize(); - String getSketchMD5(); - uint32_t getFreeSketchSpace(); - - bool flashEraseSector(uint32_t sector); - bool flashWrite(uint32_t offset, uint32_t *data, size_t size); - bool flashRead(uint32_t offset, uint32_t *data, size_t size); - - bool partitionEraseRange(const esp_partition_t *partition, uint32_t offset, size_t size); - bool partitionWrite(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size); - bool partitionRead(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size); - - uint64_t getEfuseMac(); - + EspClass() {} + ~EspClass() {} + void restart(); + + //Internal RAM + uint32_t getHeapSize(); //total heap size + uint32_t getFreeHeap(); //available heap + uint32_t getMinFreeHeap(); //lowest level of free heap since boot + uint32_t getMaxAllocHeap(); //largest block of heap that can be allocated at once + + //SPI RAM + uint32_t getPsramSize(); + uint32_t getFreePsram(); + uint32_t getMinFreePsram(); + uint32_t getMaxAllocPsram(); + + uint16_t getChipRevision(); + const char *getChipModel(); + uint8_t getChipCores(); + uint32_t getCpuFreqMHz() { + return getCpuFrequencyMhz(); + } + inline uint32_t getCycleCount() __attribute__((always_inline)); + + const char *getSdkVersion(); //version of ESP-IDF + const char *getCoreVersion(); //version of this core + + void deepSleep(uint64_t time_us); + + uint32_t getFlashChipSize(); + uint32_t getFlashChipSpeed(); + FlashMode_t getFlashChipMode(); + + uint32_t magicFlashChipSize(uint8_t byte); + uint32_t magicFlashChipSpeed(uint8_t byte); + FlashMode_t magicFlashChipMode(uint8_t byte); + + uint32_t getSketchSize(); + String getSketchMD5(); + uint32_t getFreeSketchSpace(); + + bool flashEraseSector(uint32_t sector); + bool flashWrite(uint32_t offset, uint32_t *data, size_t size); + bool flashRead(uint32_t offset, uint32_t *data, size_t size); + + bool partitionEraseRange(const esp_partition_t *partition, uint32_t offset, size_t size); + bool partitionWrite(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size); + bool partitionRead(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size); + + uint64_t getEfuseMac(); }; -uint32_t ARDUINO_ISR_ATTR EspClass::getCycleCount() -{ - return (uint32_t)esp_cpu_get_cycle_count(); +uint32_t ARDUINO_ISR_ATTR EspClass::getCycleCount() { + return (uint32_t)esp_cpu_get_cycle_count(); } extern EspClass ESP; -#endif //ESP_H +#endif //ESP_H diff --git a/cores/esp32/FirmwareMSC.cpp b/cores/esp32/FirmwareMSC.cpp index 638f1823499..5ba683a84cf 100644 --- a/cores/esp32/FirmwareMSC.cpp +++ b/cores/esp32/FirmwareMSC.cpp @@ -25,16 +25,16 @@ #include "spi_flash_mmap.h" #ifndef USB_FW_MSC_VENDOR_ID -#define USB_FW_MSC_VENDOR_ID "ESP32" //max 8 chars +#define USB_FW_MSC_VENDOR_ID "ESP32" //max 8 chars #endif #ifndef USB_FW_MSC_PRODUCT_ID -#define USB_FW_MSC_PRODUCT_ID "Firmware MSC"//max 16 chars +#define USB_FW_MSC_PRODUCT_ID "Firmware MSC" //max 16 chars #endif #ifndef USB_FW_MSC_PRODUCT_REVISION -#define USB_FW_MSC_PRODUCT_REVISION "1.0" //max 4 chars +#define USB_FW_MSC_PRODUCT_REVISION "1.0" //max 4 chars #endif #ifndef USB_FW_MSC_VOLUME_NAME -#define USB_FW_MSC_VOLUME_NAME "ESP32-FWMSC" //max 11 chars +#define USB_FW_MSC_VOLUME_NAME "ESP32-FWMSC" //max 11 chars #endif #ifndef USB_FW_MSC_SERIAL_NUMBER #define USB_FW_MSC_SERIAL_NUMBER 0x00000000 @@ -45,19 +45,19 @@ esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg); //General Variables -static uint8_t * msc_ram_disk = NULL; -static fat_boot_sector_t * msc_boot = NULL; -static uint8_t * msc_table = NULL; +static uint8_t *msc_ram_disk = NULL; +static fat_boot_sector_t *msc_boot = NULL; +static uint8_t *msc_table = NULL; static uint16_t msc_table_sectors = 0; static uint16_t msc_total_sectors = 0; static bool mcs_is_fat16 = false; //Firmware Read -static const esp_partition_t* msc_run_partition = NULL; +static const esp_partition_t *msc_run_partition = NULL; static uint16_t fw_start_sector = 0; static uint16_t fw_end_sector = 0; static size_t fw_size = 0; -static fat_dir_entry_t * fw_entry = NULL; +static fat_dir_entry_t *fw_entry = NULL; //Firmware Write typedef enum { @@ -67,17 +67,17 @@ typedef enum { MSC_UPDATE_END } msc_update_state_t; -static const esp_partition_t* msc_ota_partition = NULL; +static const esp_partition_t *msc_ota_partition = NULL; static msc_update_state_t msc_update_state = MSC_UPDATE_IDLE; static uint16_t msc_update_start_sector = 0; static uint32_t msc_update_bytes_written = 0; -static fat_dir_entry_t * msc_update_entry = NULL; +static fat_dir_entry_t *msc_update_entry = NULL; -static uint32_t get_firmware_size(const esp_partition_t* partition){ +static uint32_t get_firmware_size(const esp_partition_t *partition) { esp_image_metadata_t data; - const esp_partition_pos_t running_pos = { - .offset = partition->address, - .size = partition->size, + const esp_partition_pos_t running_pos = { + .offset = partition->address, + .size = partition->size, }; data.start_addr = running_pos.offset; esp_image_verify(ESP_IMAGE_VERIFY, &running_pos, &data); @@ -85,19 +85,19 @@ static uint32_t get_firmware_size(const esp_partition_t* partition){ } //Get number of sectors required based on the size of the firmware and OTA partition -static size_t msc_update_get_required_disk_sectors(){ +static size_t msc_update_get_required_disk_sectors() { size_t data_sectors = 16; size_t total_sectors = 0; msc_run_partition = esp_ota_get_running_partition(); msc_ota_partition = esp_ota_get_next_update_partition(NULL); - if(msc_run_partition){ + if (msc_run_partition) { fw_size = get_firmware_size(msc_run_partition); data_sectors += FAT_SIZE_TO_SECTORS(fw_size); log_d("APP size: %u (%u sectors)", fw_size, FAT_SIZE_TO_SECTORS(fw_size)); } else { log_w("APP partition not found. Reading disabled"); } - if(msc_ota_partition){ + if (msc_ota_partition) { data_sectors += FAT_SIZE_TO_SECTORS(msc_ota_partition->size); log_d("OTA size: %u (%u sectors)", msc_ota_partition->size, FAT_SIZE_TO_SECTORS(msc_ota_partition->size)); } else { @@ -105,7 +105,7 @@ static size_t msc_update_get_required_disk_sectors(){ } msc_table_sectors = fat_sectors_per_alloc_table(data_sectors, false); total_sectors = data_sectors + msc_table_sectors + 2; - if(total_sectors > 0xFF4){ + if (total_sectors > 0xFF4) { log_d("USING FAT16"); mcs_is_fat16 = true; total_sectors -= msc_table_sectors; @@ -123,11 +123,11 @@ static size_t msc_update_get_required_disk_sectors(){ } //setup the ramdisk and add the firmware download file -static bool msc_update_setup_disk(const char * volume_label, uint32_t serial_number){ +static bool msc_update_setup_disk(const char *volume_label, uint32_t serial_number) { msc_total_sectors = msc_update_get_required_disk_sectors(); uint8_t ram_sectors = msc_table_sectors + 2; - msc_ram_disk = (uint8_t*)calloc(ram_sectors, DISK_SECTOR_SIZE); - if(!msc_ram_disk){ + msc_ram_disk = (uint8_t *)calloc(ram_sectors, DISK_SECTOR_SIZE); + if (!msc_ram_disk) { log_e("Failed to allocate RAM Disk: %u bytes", ram_sectors * DISK_SECTOR_SIZE); return false; } @@ -136,14 +136,14 @@ static bool msc_update_setup_disk(const char * volume_label, uint32_t serial_num msc_boot = fat_add_boot_sector(msc_ram_disk, msc_total_sectors, msc_table_sectors, fat_file_system_type(mcs_is_fat16), volume_label, serial_number); msc_table = fat_add_table(msc_ram_disk, msc_boot, mcs_is_fat16); //fat_dir_entry_t * label = fat_add_label(msc_ram_disk, volume_label); - if(msc_run_partition){ + if (msc_run_partition) { fw_entry = fat_add_root_file(msc_ram_disk, 0, "FIRMWARE", "BIN", fw_size, 2, mcs_is_fat16); fw_end_sector = FAT_SIZE_TO_SECTORS(fw_size) + fw_start_sector; } return true; } -static void msc_update_delete_disk(){ +static void msc_update_delete_disk() { fw_entry = NULL; fw_size = 0; fw_end_sector = 0; @@ -163,39 +163,39 @@ static void msc_update_delete_disk(){ } //filter out entries to only include BINs in the root folder -static fat_dir_entry_t * msc_update_get_root_bin_entry(uint8_t index){ - fat_dir_entry_t * entry = (fat_dir_entry_t *)(msc_ram_disk + ((msc_boot->sectors_per_alloc_table+1) * DISK_SECTOR_SIZE) + (index * sizeof(fat_dir_entry_t))); - fat_lfn_entry_t * lfn = (fat_lfn_entry_t*)entry; +static fat_dir_entry_t *msc_update_get_root_bin_entry(uint8_t index) { + fat_dir_entry_t *entry = (fat_dir_entry_t *)(msc_ram_disk + ((msc_boot->sectors_per_alloc_table + 1) * DISK_SECTOR_SIZE) + (index * sizeof(fat_dir_entry_t))); + fat_lfn_entry_t *lfn = (fat_lfn_entry_t *)entry; //empty entry - if(entry->file_magic == 0){ + if (entry->file_magic == 0) { return NULL; } //long file name - if(lfn->attr == 0x0F && lfn->type == 0x00 && lfn->first_cluster == 0x0000){ + if (lfn->attr == 0x0F && lfn->type == 0x00 && lfn->first_cluster == 0x0000) { return NULL; } //only files marked as archives - if(entry->file_attr != FAT_FILE_ATTR_ARCHIVE){ + if (entry->file_attr != FAT_FILE_ATTR_ARCHIVE) { return NULL; } //deleted - if(entry->file_magic == 0xE5 || entry->file_magic == 0x05){ + if (entry->file_magic == 0xE5 || entry->file_magic == 0x05) { return NULL; } //not bins - if(memcmp("BIN", entry->file_extension, 3)){ + if (memcmp("BIN", entry->file_extension, 3)) { return NULL; } return entry; } //get an empty bin (the host will add an entry for file about to be written with size of zero) -static fat_dir_entry_t * msc_update_find_new_bin(){ - for(uint8_t i=16; i;){ +static fat_dir_entry_t *msc_update_find_new_bin() { + for (uint8_t i = 16; i;) { i--; - fat_dir_entry_t * entry = msc_update_get_root_bin_entry(i); - if(entry && entry->file_size == 0){ + fat_dir_entry_t *entry = msc_update_get_root_bin_entry(i); + if (entry && entry->file_size == 0) { return entry; } } @@ -203,11 +203,11 @@ static fat_dir_entry_t * msc_update_find_new_bin(){ } //get a bin starting from particular sector -static fat_dir_entry_t * msc_update_find_bin(uint16_t sector){ - for(uint8_t i=16; i; ){ +static fat_dir_entry_t *msc_update_find_bin(uint16_t sector) { + for (uint8_t i = 16; i;) { i--; - fat_dir_entry_t * entry = msc_update_get_root_bin_entry(i); - if(entry && entry->data_start_sector == (sector - msc_boot->sectors_per_alloc_table)){ + fat_dir_entry_t *entry = msc_update_get_root_bin_entry(i); + if (entry && entry->data_start_sector == (sector - msc_boot->sectors_per_alloc_table)) { return entry; } } @@ -215,12 +215,12 @@ static fat_dir_entry_t * msc_update_find_bin(uint16_t sector){ } //write the new data and erase the flash blocks when necessary -static esp_err_t msc_update_write(const esp_partition_t *partition, uint32_t offset, void *data, size_t size){ +static esp_err_t msc_update_write(const esp_partition_t *partition, uint32_t offset, void *data, size_t size) { esp_err_t err = ESP_OK; - if((offset & (SPI_FLASH_SEC_SIZE-1)) == 0){ + if ((offset & (SPI_FLASH_SEC_SIZE - 1)) == 0) { err = esp_partition_erase_range(partition, offset, SPI_FLASH_SEC_SIZE); - log_v("ERASE[0x%08X]: %s", offset, (err != ESP_OK)?"FAIL":"OK"); - if(err != ESP_OK){ + log_v("ERASE[0x%08X]: %s", offset, (err != ESP_OK) ? "FAIL" : "OK"); + if (err != ESP_OK) { return err; } } @@ -228,7 +228,7 @@ static esp_err_t msc_update_write(const esp_partition_t *partition, uint32_t off } //called when error was encountered while updating -static void msc_update_error(){ +static void msc_update_error() { log_e("UPDATE_ERROR: %u", msc_update_bytes_written); arduino_firmware_msc_event_data_t p; p.error.size = msc_update_bytes_written; @@ -240,16 +240,16 @@ static void msc_update_error(){ } //called when all firmware bytes have been received -static void msc_update_end(){ +static void msc_update_end() { log_d("UPDATE_END: %u", msc_update_entry->file_size); msc_update_state = MSC_UPDATE_END; size_t ota_size = get_firmware_size(msc_ota_partition); - if(ota_size != msc_update_entry->file_size){ + if (ota_size != msc_update_entry->file_size) { log_e("OTA SIZE MISMATCH %u != %u", ota_size, msc_update_entry->file_size); msc_update_error(); return; } - if(!ota_size || esp_ota_set_boot_partition(msc_ota_partition) != ESP_OK){ + if (!ota_size || esp_ota_set_boot_partition(msc_ota_partition) != ESP_OK) { log_e("ENABLING OTA PARTITION FAILED"); msc_update_error(); return; @@ -259,47 +259,47 @@ static void msc_update_end(){ arduino_usb_event_post(ARDUINO_FIRMWARE_MSC_EVENTS, ARDUINO_FIRMWARE_MSC_END_EVENT, &p, sizeof(arduino_firmware_msc_event_data_t), portMAX_DELAY); } -static int32_t msc_write(uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize){ +static int32_t msc_write(uint32_t lba, uint32_t offset, uint8_t *buffer, uint32_t bufsize) { //log_d("lba: %u, offset: %u, bufsize: %u", lba, offset, bufsize); - if(lba < fw_start_sector){ + if (lba < fw_start_sector) { //write to sectors that are in RAM memcpy(msc_ram_disk + (lba * DISK_SECTOR_SIZE) + offset, buffer, bufsize); - if(msc_ota_partition && lba == (fw_start_sector - 1)){ + if (msc_ota_partition && lba == (fw_start_sector - 1)) { //monitor the root folder table - if(msc_update_state <= MSC_UPDATE_RUNNING){ - fat_dir_entry_t * update_entry = msc_update_find_new_bin(); - if(update_entry) { - if(msc_update_entry) { + if (msc_update_state <= MSC_UPDATE_RUNNING) { + fat_dir_entry_t *update_entry = msc_update_find_new_bin(); + if (update_entry) { + if (msc_update_entry) { log_v("REPLACING ENTRY"); } else { log_v("ASSIGNING ENTRY"); } - if(msc_update_state <= MSC_UPDATE_STARTING){ + if (msc_update_state <= MSC_UPDATE_STARTING) { msc_update_state = MSC_UPDATE_STARTING; msc_update_bytes_written = 0; msc_update_start_sector = 0; } msc_update_entry = update_entry; - } else if(msc_update_state == MSC_UPDATE_RUNNING){ - if(!msc_update_entry && msc_update_start_sector){ + } else if (msc_update_state == MSC_UPDATE_RUNNING) { + if (!msc_update_entry && msc_update_start_sector) { msc_update_entry = msc_update_find_bin(msc_update_start_sector); } - if(msc_update_entry && msc_update_bytes_written >= msc_update_entry->file_size){ + if (msc_update_entry && msc_update_bytes_written >= msc_update_entry->file_size) { msc_update_end(); } } } } - } else if(msc_ota_partition && lba >= msc_update_start_sector){ + } else if (msc_ota_partition && lba >= msc_update_start_sector) { //handle writes to the region where the new firmware will be uploaded arduino_firmware_msc_event_data_t p; - if(msc_update_state <= MSC_UPDATE_STARTING && buffer[0] == 0xE9){ + if (msc_update_state <= MSC_UPDATE_STARTING && buffer[0] == 0xE9) { msc_update_state = MSC_UPDATE_RUNNING; msc_update_start_sector = lba; msc_update_bytes_written = 0; log_d("UPDATE_START: %u (0x%02X)", lba, lba - msc_boot->sectors_per_alloc_table); arduino_usb_event_post(ARDUINO_FIRMWARE_MSC_EVENTS, ARDUINO_FIRMWARE_MSC_START_EVENT, &p, sizeof(arduino_firmware_msc_event_data_t), portMAX_DELAY); - if(msc_update_write(msc_ota_partition, ((lba - msc_update_start_sector) * DISK_SECTOR_SIZE) + offset, buffer, bufsize) == ESP_OK){ + if (msc_update_write(msc_ota_partition, ((lba - msc_update_start_sector) * DISK_SECTOR_SIZE) + offset, buffer, bufsize) == ESP_OK) { log_v("UPDATE_WRITE: %u %u", ((lba - msc_update_start_sector) * DISK_SECTOR_SIZE) + offset, bufsize); msc_update_bytes_written = ((lba - msc_update_start_sector) * DISK_SECTOR_SIZE) + offset + bufsize; p.write.offset = ((lba - msc_update_start_sector) * DISK_SECTOR_SIZE) + offset; @@ -309,17 +309,17 @@ static int32_t msc_write(uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_ msc_update_error(); return 0; } - } else if(msc_update_state == MSC_UPDATE_RUNNING){ - if(msc_update_entry && msc_update_entry->file_size && msc_update_bytes_written < msc_update_entry->file_size && (msc_update_bytes_written + bufsize) >= msc_update_entry->file_size){ + } else if (msc_update_state == MSC_UPDATE_RUNNING) { + if (msc_update_entry && msc_update_entry->file_size && msc_update_bytes_written < msc_update_entry->file_size && (msc_update_bytes_written + bufsize) >= msc_update_entry->file_size) { bufsize = msc_update_entry->file_size - msc_update_bytes_written; } - if(msc_update_write(msc_ota_partition, ((lba - msc_update_start_sector) * DISK_SECTOR_SIZE) + offset, buffer, bufsize) == ESP_OK){ + if (msc_update_write(msc_ota_partition, ((lba - msc_update_start_sector) * DISK_SECTOR_SIZE) + offset, buffer, bufsize) == ESP_OK) { log_v("UPDATE_WRITE: %u %u", ((lba - msc_update_start_sector) * DISK_SECTOR_SIZE) + offset, bufsize); msc_update_bytes_written = ((lba - msc_update_start_sector) * DISK_SECTOR_SIZE) + offset + bufsize; p.write.offset = ((lba - msc_update_start_sector) * DISK_SECTOR_SIZE) + offset; p.write.size = bufsize; arduino_usb_event_post(ARDUINO_FIRMWARE_MSC_EVENTS, ARDUINO_FIRMWARE_MSC_WRITE_EVENT, &p, sizeof(arduino_firmware_msc_event_data_t), portMAX_DELAY); - if(msc_update_entry && msc_update_entry->file_size && msc_update_bytes_written >= msc_update_entry->file_size){ + if (msc_update_entry && msc_update_entry->file_size && msc_update_bytes_written >= msc_update_entry->file_size) { msc_update_end(); } } else { @@ -331,13 +331,13 @@ static int32_t msc_write(uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_ return bufsize; } -static int32_t msc_read(uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize){ +static int32_t msc_read(uint32_t lba, uint32_t offset, void *buffer, uint32_t bufsize) { //log_d("lba: %u, offset: %u, bufsize: %u", lba, offset, bufsize); - if(lba < fw_start_sector){ + if (lba < fw_start_sector) { memcpy(buffer, msc_ram_disk + (lba * DISK_SECTOR_SIZE) + offset, bufsize); - } else if(msc_run_partition && lba < fw_end_sector){ + } else if (msc_run_partition && lba < fw_end_sector) { //read the currently running firmware - if(esp_partition_read(msc_run_partition, ((lba - fw_start_sector) * DISK_SECTOR_SIZE) + offset, buffer, bufsize) != ESP_OK){ + if (esp_partition_read(msc_run_partition, ((lba - fw_start_sector) * DISK_SECTOR_SIZE) + offset, buffer, bufsize) != ESP_OK) { return 0; } } else { @@ -346,7 +346,7 @@ static int32_t msc_read(uint32_t lba, uint32_t offset, void* buffer, uint32_t bu return bufsize; } -static bool msc_start_stop(uint8_t power_condition, bool start, bool load_eject){ +static bool msc_start_stop(uint8_t power_condition, bool start, bool load_eject) { //log_d("power: %u, start: %u, eject: %u", power_condition, start, load_eject); arduino_firmware_msc_event_data_t p; p.power.power_condition = power_condition; @@ -357,9 +357,9 @@ static bool msc_start_stop(uint8_t power_condition, bool start, bool load_eject) } static volatile TaskHandle_t msc_task_handle = NULL; -static void msc_task(void *pvParameters){ +static void msc_task(void *pvParameters) { for (;;) { - if(msc_update_state == MSC_UPDATE_END){ + if (msc_update_state == MSC_UPDATE_END) { delay(100); esp_restart(); } @@ -369,24 +369,25 @@ static void msc_task(void *pvParameters){ vTaskDelete(NULL); } -FirmwareMSC::FirmwareMSC():msc(){} +FirmwareMSC::FirmwareMSC() + : msc() {} -FirmwareMSC::~FirmwareMSC(){ +FirmwareMSC::~FirmwareMSC() { end(); } -bool FirmwareMSC::begin(){ - if(msc_ram_disk){ +bool FirmwareMSC::begin() { + if (msc_ram_disk) { return true; } - if(!msc_update_setup_disk(USB_FW_MSC_VOLUME_NAME, USB_FW_MSC_SERIAL_NUMBER)){ + if (!msc_update_setup_disk(USB_FW_MSC_VOLUME_NAME, USB_FW_MSC_SERIAL_NUMBER)) { return false; } - if(!msc_task_handle){ - xTaskCreateUniversal(msc_task, "msc_disk", 1024, NULL, 2, (TaskHandle_t*)&msc_task_handle, 0); - if(!msc_task_handle){ + if (!msc_task_handle) { + xTaskCreateUniversal(msc_task, "msc_disk", 1024, NULL, 2, (TaskHandle_t *)&msc_task_handle, 0); + if (!msc_task_handle) { msc_update_delete_disk(); return false; } @@ -403,20 +404,20 @@ bool FirmwareMSC::begin(){ return true; } -void FirmwareMSC::end(){ +void FirmwareMSC::end() { msc.end(); - if(msc_task_handle){ + if (msc_task_handle) { vTaskDelete(msc_task_handle); msc_task_handle = NULL; } msc_update_delete_disk(); } -void FirmwareMSC::onEvent(esp_event_handler_t callback){ - onEvent(ARDUINO_FIRMWARE_MSC_ANY_EVENT, callback); +void FirmwareMSC::onEvent(esp_event_handler_t callback) { + onEvent(ARDUINO_FIRMWARE_MSC_ANY_EVENT, callback); } -void FirmwareMSC::onEvent(arduino_firmware_msc_event_t event, esp_event_handler_t callback){ - arduino_usb_event_handler_register_with(ARDUINO_FIRMWARE_MSC_EVENTS, event, callback, this); +void FirmwareMSC::onEvent(arduino_firmware_msc_event_t event, esp_event_handler_t callback) { + arduino_usb_event_handler_register_with(ARDUINO_FIRMWARE_MSC_EVENTS, event, callback, this); } #if ARDUINO_USB_MSC_ON_BOOT diff --git a/cores/esp32/FirmwareMSC.h b/cores/esp32/FirmwareMSC.h index 570feac8e2f..3eaa184bcd6 100644 --- a/cores/esp32/FirmwareMSC.h +++ b/cores/esp32/FirmwareMSC.h @@ -23,31 +23,31 @@ ESP_EVENT_DECLARE_BASE(ARDUINO_FIRMWARE_MSC_EVENTS); typedef enum { - ARDUINO_FIRMWARE_MSC_ANY_EVENT = ESP_EVENT_ANY_ID, - ARDUINO_FIRMWARE_MSC_START_EVENT = 0, - ARDUINO_FIRMWARE_MSC_WRITE_EVENT, - ARDUINO_FIRMWARE_MSC_END_EVENT, - ARDUINO_FIRMWARE_MSC_ERROR_EVENT, - ARDUINO_FIRMWARE_MSC_POWER_EVENT, - ARDUINO_FIRMWARE_MSC_MAX_EVENT, + ARDUINO_FIRMWARE_MSC_ANY_EVENT = ESP_EVENT_ANY_ID, + ARDUINO_FIRMWARE_MSC_START_EVENT = 0, + ARDUINO_FIRMWARE_MSC_WRITE_EVENT, + ARDUINO_FIRMWARE_MSC_END_EVENT, + ARDUINO_FIRMWARE_MSC_ERROR_EVENT, + ARDUINO_FIRMWARE_MSC_POWER_EVENT, + ARDUINO_FIRMWARE_MSC_MAX_EVENT, } arduino_firmware_msc_event_t; typedef union { - struct { - size_t offset; - size_t size; - } write; - struct { - uint8_t power_condition; - bool start; - bool load_eject; - } power; - struct { - size_t size; - } end; - struct { - size_t size; - } error; + struct { + size_t offset; + size_t size; + } write; + struct { + uint8_t power_condition; + bool start; + bool load_eject; + } power; + struct { + size_t size; + } end; + struct { + size_t size; + } error; } arduino_firmware_msc_event_data_t; class FirmwareMSC { diff --git a/cores/esp32/FunctionalInterrupt.cpp b/cores/esp32/FunctionalInterrupt.cpp index c5a8d37fed4..76d93e11602 100644 --- a/cores/esp32/FunctionalInterrupt.cpp +++ b/cores/esp32/FunctionalInterrupt.cpp @@ -11,34 +11,24 @@ typedef void (*voidFuncPtr)(void); typedef void (*voidFuncPtrArg)(void*); -extern "C" -{ - extern void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtrArg userFunc, void * arg, int intr_type, bool functional); +extern "C" { + extern void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtrArg userFunc, void* arg, int intr_type, bool functional); } -void ARDUINO_ISR_ATTR interruptFunctional(void* arg) -{ - InterruptArgStructure* localArg = (InterruptArgStructure*)arg; - if (localArg->interruptFunction) - { - localArg->interruptFunction(); - } +void ARDUINO_ISR_ATTR interruptFunctional(void* arg) { + InterruptArgStructure* localArg = (InterruptArgStructure*)arg; + if (localArg->interruptFunction) { + localArg->interruptFunction(); + } } -void attachInterrupt(uint8_t pin, std::function intRoutine, int mode) -{ - // use the local interrupt routine which takes the ArgStructure as argument - __attachInterruptFunctionalArg (pin, (voidFuncPtrArg)interruptFunctional, new InterruptArgStructure{intRoutine}, mode, true); +void attachInterrupt(uint8_t pin, std::function intRoutine, int mode) { + // use the local interrupt routine which takes the ArgStructure as argument + __attachInterruptFunctionalArg(pin, (voidFuncPtrArg)interruptFunctional, new InterruptArgStructure{ intRoutine }, mode, true); } -extern "C" -{ - void cleanupFunctional(void* arg) - { - delete (InterruptArgStructure*)arg; - } +extern "C" { + void cleanupFunctional(void* arg) { + delete (InterruptArgStructure*)arg; + } } - - - - diff --git a/cores/esp32/FunctionalInterrupt.h b/cores/esp32/FunctionalInterrupt.h index a6d083b9594..4b31d328663 100644 --- a/cores/esp32/FunctionalInterrupt.h +++ b/cores/esp32/FunctionalInterrupt.h @@ -12,11 +12,11 @@ #include struct InterruptArgStructure { - std::function interruptFunction; + std::function interruptFunction; }; // The extra set of parentheses here prevents macros defined // in io_pin_remap.h from applying to this declaration. -void (attachInterrupt)(uint8_t pin, std::function intRoutine, int mode); +void(attachInterrupt)(uint8_t pin, std::function intRoutine, int mode); #endif /* CORE_CORE_FUNCTIONALINTERRUPT_H_ */ diff --git a/cores/esp32/HEXBuilder.cpp b/cores/esp32/HEXBuilder.cpp index f3b0f7a9b3e..7befe1673c3 100644 --- a/cores/esp32/HEXBuilder.cpp +++ b/cores/esp32/HEXBuilder.cpp @@ -20,52 +20,51 @@ #include #include -static uint8_t hex_char_to_byte(uint8_t c) -{ - return (c >= 'a' && c <= 'f') ? (c - ((uint8_t)'a' - 0xa)) : - (c >= 'A' && c <= 'F') ? (c - ((uint8_t)'A' - 0xA)) : - (c >= '0' && c<= '9') ? (c - (uint8_t)'0') : 0x10; // unknown char is 16 +static uint8_t hex_char_to_byte(uint8_t c) { + return (c >= 'a' && c <= 'f') ? (c - ((uint8_t)'a' - 0xa)) : (c >= 'A' && c <= 'F') ? (c - ((uint8_t)'A' - 0xA)) + : (c >= '0' && c <= '9') ? (c - (uint8_t)'0') + : 0x10; // unknown char is 16 } -size_t HEXBuilder::hex2bytes(unsigned char * out, size_t maxlen, String &in) { - return hex2bytes(out, maxlen, in.c_str()); +size_t HEXBuilder::hex2bytes(unsigned char *out, size_t maxlen, String &in) { + return hex2bytes(out, maxlen, in.c_str()); } -size_t HEXBuilder::hex2bytes(unsigned char * out, size_t maxlen, const char * in) { - size_t len = 0; - for(;*in;in++) { - uint8_t c = hex_char_to_byte(*in); - // Silently skip anything unknown. - if (c > 15) - continue; +size_t HEXBuilder::hex2bytes(unsigned char *out, size_t maxlen, const char *in) { + size_t len = 0; + for (; *in; in++) { + uint8_t c = hex_char_to_byte(*in); + // Silently skip anything unknown. + if (c > 15) + continue; - if (len & 1) { - if (len/2 < maxlen) - out[len/2] |= c; - } else { - if (len/2 < maxlen) - out[len/2] = c<<4; - } - len++; + if (len & 1) { + if (len / 2 < maxlen) + out[len / 2] |= c; + } else { + if (len / 2 < maxlen) + out[len / 2] = c << 4; } - return (len + 1)/2; + len++; + } + return (len + 1) / 2; } -size_t HEXBuilder::bytes2hex(char * out, size_t maxlen, const unsigned char * in, size_t len) { - for(size_t i = 0; i < len; i++) { - if (i*2 + 1 < maxlen) { - sprintf(out + (i * 2), "%02x", in[i]); - } +size_t HEXBuilder::bytes2hex(char *out, size_t maxlen, const unsigned char *in, size_t len) { + for (size_t i = 0; i < len; i++) { + if (i * 2 + 1 < maxlen) { + sprintf(out + (i * 2), "%02x", in[i]); } - return len * 2 + 1; + } + return len * 2 + 1; } -String HEXBuilder::bytes2hex(const unsigned char * in, size_t len) { - size_t maxlen = len * 2 + 1; - char * out = (char *) malloc(maxlen); - if (!out) return String(); - bytes2hex(out, maxlen, in, len); - String ret = String(out); - free(out); - return ret; +String HEXBuilder::bytes2hex(const unsigned char *in, size_t len) { + size_t maxlen = len * 2 + 1; + char *out = (char *)malloc(maxlen); + if (!out) return String(); + bytes2hex(out, maxlen, in, len); + String ret = String(out); + free(out); + return ret; } diff --git a/cores/esp32/HEXBuilder.h b/cores/esp32/HEXBuilder.h index b3ec02ae267..99335a60d96 100644 --- a/cores/esp32/HEXBuilder.h +++ b/cores/esp32/HEXBuilder.h @@ -25,10 +25,10 @@ class HEXBuilder { public: - static size_t hex2bytes(unsigned char * out, size_t maxlen, String & in); - static size_t hex2bytes(unsigned char * out, size_t maxlen, const char * in); + static size_t hex2bytes(unsigned char* out, size_t maxlen, String& in); + static size_t hex2bytes(unsigned char* out, size_t maxlen, const char* in); - static String bytes2hex(const unsigned char * in, size_t len); - static size_t bytes2hex(char * out, size_t maxlen, const unsigned char * in, size_t len); + static String bytes2hex(const unsigned char* in, size_t len); + static size_t bytes2hex(char* out, size_t maxlen, const unsigned char* in, size_t len); }; #endif diff --git a/cores/esp32/HWCDC.cpp b/cores/esp32/HWCDC.cpp index c5dd27891d8..f49867e95cc 100644 --- a/cores/esp32/HWCDC.cpp +++ b/cores/esp32/HWCDC.cpp @@ -35,7 +35,7 @@ ESP_EVENT_DEFINE_BASE(ARDUINO_HW_CDC_EVENTS); static RingbufHandle_t tx_ring_buf = NULL; static QueueHandle_t rx_queue = NULL; -static uint8_t rx_data_buf[64] = {0}; +static uint8_t rx_data_buf[64] = { 0 }; static intr_handle_t intr_handle = NULL; static SemaphoreHandle_t tx_lock = NULL; static volatile bool connected = false; @@ -45,486 +45,471 @@ static uint32_t requested_tx_timeout_ms = 100; static esp_event_loop_handle_t arduino_hw_cdc_event_loop_handle = NULL; -static esp_err_t arduino_hw_cdc_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, BaseType_t *task_unblocked){ - if(arduino_hw_cdc_event_loop_handle == NULL){ - return ESP_FAIL; - } - return esp_event_isr_post_to(arduino_hw_cdc_event_loop_handle, event_base, event_id, event_data, event_data_size, task_unblocked); +static esp_err_t arduino_hw_cdc_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, BaseType_t *task_unblocked) { + if (arduino_hw_cdc_event_loop_handle == NULL) { + return ESP_FAIL; + } + return esp_event_isr_post_to(arduino_hw_cdc_event_loop_handle, event_base, event_id, event_data, event_data_size, task_unblocked); } -static esp_err_t arduino_hw_cdc_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg){ - if (!arduino_hw_cdc_event_loop_handle) { - esp_event_loop_args_t event_task_args = { - .queue_size = 5, - .task_name = "arduino_hw_cdc_events", - .task_priority = 5, - .task_stack_size = 2048, - .task_core_id = tskNO_AFFINITY - }; - if (esp_event_loop_create(&event_task_args, &arduino_hw_cdc_event_loop_handle) != ESP_OK) { - log_e("esp_event_loop_create failed"); - } - } - if(arduino_hw_cdc_event_loop_handle == NULL){ - return ESP_FAIL; - } - return esp_event_handler_register_with(arduino_hw_cdc_event_loop_handle, event_base, event_id, event_handler, event_handler_arg); +static esp_err_t arduino_hw_cdc_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg) { + if (!arduino_hw_cdc_event_loop_handle) { + esp_event_loop_args_t event_task_args = { + .queue_size = 5, + .task_name = "arduino_hw_cdc_events", + .task_priority = 5, + .task_stack_size = 2048, + .task_core_id = tskNO_AFFINITY + }; + if (esp_event_loop_create(&event_task_args, &arduino_hw_cdc_event_loop_handle) != ESP_OK) { + log_e("esp_event_loop_create failed"); + } + } + if (arduino_hw_cdc_event_loop_handle == NULL) { + return ESP_FAIL; + } + return esp_event_handler_register_with(arduino_hw_cdc_event_loop_handle, event_base, event_id, event_handler, event_handler_arg); } static void hw_cdc_isr_handler(void *arg) { - portBASE_TYPE xTaskWoken = 0; - uint32_t usbjtag_intr_status = 0; - arduino_hw_cdc_event_data_t event = {0}; - usbjtag_intr_status = usb_serial_jtag_ll_get_intsts_mask(); - - if (usbjtag_intr_status & USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY) { - // Interrupt tells us the host picked up the data we sent. - if(!usb_serial_jtag_is_connected()) { - connected = false; - usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); - // USB is unplugged, nothing to be done here - return; - } else { - connected = true; - } - if (tx_ring_buf != NULL && usb_serial_jtag_ll_txfifo_writable() == 1) { - // We disable the interrupt here so that the interrupt won't be triggered if there is no data to send. - usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); - size_t queued_size; - uint8_t *queued_buff = (uint8_t *)xRingbufferReceiveUpToFromISR(tx_ring_buf, &queued_size, 64); - // If the hardware fifo is avaliable, write in it. Otherwise, do nothing. - if (queued_buff != NULL) { //Although tx_queued_bytes may be larger than 0. We may have interrupt before xRingbufferSend() was called. - //Copy the queued buffer into the TX FIFO - usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); - usb_serial_jtag_ll_write_txfifo(queued_buff, queued_size); - usb_serial_jtag_ll_txfifo_flush(); - vRingbufferReturnItemFromISR(tx_ring_buf, queued_buff, &xTaskWoken); - if(connected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); - //send event? - //ets_printf("TX:%u\n", queued_size); - event.tx.len = queued_size; - arduino_hw_cdc_event_post(ARDUINO_HW_CDC_EVENTS, ARDUINO_HW_CDC_TX_EVENT, &event, sizeof(arduino_hw_cdc_event_data_t), &xTaskWoken); - } - } else { - usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); - } - } - - if (usbjtag_intr_status & USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT) { - // read rx buffer(max length is 64), and send avaliable data to ringbuffer. - // Ensure the rx buffer size is larger than RX_MAX_SIZE. - usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT); - uint32_t rx_fifo_len = usb_serial_jtag_ll_read_rxfifo(rx_data_buf, 64); - uint32_t i=0; - for(i=0; i just when USB is plugged and CDC is connected. -HWCDC::operator bool() const -{ - return HWCDC::isCDC_Connected(); +HWCDC::operator bool() const { + return HWCDC::isCDC_Connected(); } -void HWCDC::onEvent(esp_event_handler_t callback){ - onEvent(ARDUINO_HW_CDC_ANY_EVENT, callback); +void HWCDC::onEvent(esp_event_handler_t callback) { + onEvent(ARDUINO_HW_CDC_ANY_EVENT, callback); } -void HWCDC::onEvent(arduino_hw_cdc_event_t event, esp_event_handler_t callback){ - arduino_hw_cdc_event_handler_register_with(ARDUINO_HW_CDC_EVENTS, event, callback, this); +void HWCDC::onEvent(arduino_hw_cdc_event_t event, esp_event_handler_t callback) { + arduino_hw_cdc_event_handler_register_with(ARDUINO_HW_CDC_EVENTS, event, callback, this); } -bool HWCDC::deinit(void * busptr) -{ - // avoid any recursion issue with Peripheral Manager perimanSetPinBus() call - static bool running = false; - if (running) return true; - running = true; - // Setting USB D+ D- pins - bool retCode = true; - retCode &= perimanClearPinBus(USB_DM_GPIO_NUM); - retCode &= perimanClearPinBus(USB_DP_GPIO_NUM); - if (retCode) { - // Force the host to re-enumerate (BUS_RESET) - pinMode(USB_DM_GPIO_NUM, OUTPUT_OPEN_DRAIN); - pinMode(USB_DP_GPIO_NUM, OUTPUT_OPEN_DRAIN); - digitalWrite(USB_DM_GPIO_NUM, LOW); - digitalWrite(USB_DP_GPIO_NUM, LOW); - } - // release the flag - running = false; - return retCode; +bool HWCDC::deinit(void *busptr) { + // avoid any recursion issue with Peripheral Manager perimanSetPinBus() call + static bool running = false; + if (running) return true; + running = true; + // Setting USB D+ D- pins + bool retCode = true; + retCode &= perimanClearPinBus(USB_DM_GPIO_NUM); + retCode &= perimanClearPinBus(USB_DP_GPIO_NUM); + if (retCode) { + // Force the host to re-enumerate (BUS_RESET) + pinMode(USB_DM_GPIO_NUM, OUTPUT_OPEN_DRAIN); + pinMode(USB_DP_GPIO_NUM, OUTPUT_OPEN_DRAIN); + digitalWrite(USB_DM_GPIO_NUM, LOW); + digitalWrite(USB_DP_GPIO_NUM, LOW); + } + // release the flag + running = false; + return retCode; } -void HWCDC::begin(unsigned long baud) -{ - if(tx_lock == NULL) { - tx_lock = xSemaphoreCreateMutex(); - } - //RX Buffer default has 256 bytes if not preset - if(rx_queue == NULL) { - if (!setRxBufferSize(256)) { - log_e("HW CDC RX Buffer error"); - } - } - //TX Buffer default has 16 bytes if not preset - if (tx_ring_buf == NULL) { - if (!setTxBufferSize(16)) { - log_e("HW CDC TX Buffer error"); - } - } - - // the HW Serial pins needs to be first deinited in order to allow `if(Serial)` to work :-( - deinit(NULL); - delay(10); // USB Host has to enumerate it again - - // Peripheral Manager setting for USB D+ D- pins - uint8_t pin = USB_DM_GPIO_NUM; - if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DM, (void *) this, -1, -1)) goto err; - pin = USB_DP_GPIO_NUM; - if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DP, (void *) this, -1, -1)) goto err; - - // Configure PHY - // USB_Serial_JTAG use internal PHY - USB_SERIAL_JTAG.conf0.phy_sel = 0; - // Disable software control USB D+ D- pullup pulldown (Device FS: dp_pullup = 1) - USB_SERIAL_JTAG.conf0.pad_pull_override = 0; - // Enable USB D+ pullup - USB_SERIAL_JTAG.conf0.dp_pullup = 1; - // Enable USB pad function - USB_SERIAL_JTAG.conf0.usb_pad_enable = 1; - usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK); - usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET); - if(!intr_handle && esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, 0, hw_cdc_isr_handler, NULL, &intr_handle) != ESP_OK){ - isr_log_e("HW USB CDC failed to init interrupts"); - end(); - return; - } - return; - - err: - log_e("Serial JTAG Pin %u can't be set into Peripheral Manager.", pin); +void HWCDC::begin(unsigned long baud) { + if (tx_lock == NULL) { + tx_lock = xSemaphoreCreateMutex(); + } + //RX Buffer default has 256 bytes if not preset + if (rx_queue == NULL) { + if (!setRxBufferSize(256)) { + log_e("HW CDC RX Buffer error"); + } + } + //TX Buffer default has 16 bytes if not preset + if (tx_ring_buf == NULL) { + if (!setTxBufferSize(16)) { + log_e("HW CDC TX Buffer error"); + } + } + + // the HW Serial pins needs to be first deinited in order to allow `if(Serial)` to work :-( + deinit(NULL); + delay(10); // USB Host has to enumerate it again + + // Peripheral Manager setting for USB D+ D- pins + uint8_t pin = USB_DM_GPIO_NUM; + if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DM, (void *)this, -1, -1)) goto err; + pin = USB_DP_GPIO_NUM; + if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DP, (void *)this, -1, -1)) goto err; + + // Configure PHY + // USB_Serial_JTAG use internal PHY + USB_SERIAL_JTAG.conf0.phy_sel = 0; + // Disable software control USB D+ D- pullup pulldown (Device FS: dp_pullup = 1) + USB_SERIAL_JTAG.conf0.pad_pull_override = 0; + // Enable USB D+ pullup + USB_SERIAL_JTAG.conf0.dp_pullup = 1; + // Enable USB pad function + USB_SERIAL_JTAG.conf0.usb_pad_enable = 1; + usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK); + usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET); + if (!intr_handle && esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, 0, hw_cdc_isr_handler, NULL, &intr_handle) != ESP_OK) { + isr_log_e("HW USB CDC failed to init interrupts"); end(); + return; + } + return; + +err: + log_e("Serial JTAG Pin %u can't be set into Peripheral Manager.", pin); + end(); } -void HWCDC::end() -{ - //Disable/clear/free tx/rx interrupt. - 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); - esp_intr_free(intr_handle); - intr_handle = NULL; - if(tx_lock != NULL) { - vSemaphoreDelete(tx_lock); - tx_lock = NULL; - } - setRxBufferSize(0); - setTxBufferSize(0); - if (arduino_hw_cdc_event_loop_handle) { - esp_event_loop_delete(arduino_hw_cdc_event_loop_handle); - arduino_hw_cdc_event_loop_handle = NULL; - } - HWCDC::deinit(this); - setDebugOutput(false); - connected = false; +void HWCDC::end() { + //Disable/clear/free tx/rx interrupt. + 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); + esp_intr_free(intr_handle); + intr_handle = NULL; + if (tx_lock != NULL) { + vSemaphoreDelete(tx_lock); + tx_lock = NULL; + } + setRxBufferSize(0); + setTxBufferSize(0); + if (arduino_hw_cdc_event_loop_handle) { + esp_event_loop_delete(arduino_hw_cdc_event_loop_handle); + arduino_hw_cdc_event_loop_handle = NULL; + } + HWCDC::deinit(this); + setDebugOutput(false); + connected = false; } -void HWCDC::setTxTimeoutMs(uint32_t timeout){ - requested_tx_timeout_ms = timeout; +void HWCDC::setTxTimeoutMs(uint32_t timeout) { + requested_tx_timeout_ms = timeout; } /* * WRITING */ -size_t HWCDC::setTxBufferSize(size_t tx_queue_len){ - if(tx_ring_buf){ - vRingbufferDelete(tx_ring_buf); - tx_ring_buf = NULL; - } - if(!tx_queue_len){ - return 0; - } - tx_ring_buf = xRingbufferCreate(tx_queue_len, RINGBUF_TYPE_BYTEBUF); - if(!tx_ring_buf){ - return 0; - } - return tx_queue_len; +size_t HWCDC::setTxBufferSize(size_t tx_queue_len) { + if (tx_ring_buf) { + vRingbufferDelete(tx_ring_buf); + tx_ring_buf = NULL; + } + if (!tx_queue_len) { + return 0; + } + tx_ring_buf = xRingbufferCreate(tx_queue_len, RINGBUF_TYPE_BYTEBUF); + if (!tx_ring_buf) { + return 0; + } + return tx_queue_len; } -int HWCDC::availableForWrite(void) -{ - uint32_t tx_timeout_ms = 0; - if(tx_ring_buf == NULL || tx_lock == NULL){ - return 0; - } - if(HWCDC::isCDC_Connected()) { - tx_timeout_ms = requested_tx_timeout_ms; - } - if(xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS){ - return 0; - } - size_t a = xRingbufferGetCurFreeSize(tx_ring_buf); - xSemaphoreGive(tx_lock); - return a; +int HWCDC::availableForWrite(void) { + uint32_t tx_timeout_ms = 0; + if (tx_ring_buf == NULL || tx_lock == NULL) { + return 0; + } + if (HWCDC::isCDC_Connected()) { + tx_timeout_ms = requested_tx_timeout_ms; + } + if (xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS) { + return 0; + } + size_t a = xRingbufferGetCurFreeSize(tx_ring_buf); + xSemaphoreGive(tx_lock); + return a; } -static void flushTXBuffer() -{ - if (!tx_ring_buf) return; - UBaseType_t uxItemsWaiting = 0; - vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting); - - size_t queued_size = 0; - uint8_t *queued_buff = (uint8_t *)xRingbufferReceiveUpTo(tx_ring_buf, &queued_size, 0, uxItemsWaiting); - if (queued_size && queued_buff != NULL) { - vRingbufferReturnItem(tx_ring_buf, (void *)queued_buff); - } - // flushes CDC FIFO - usb_serial_jtag_ll_txfifo_flush(); +static void flushTXBuffer() { + if (!tx_ring_buf) return; + UBaseType_t uxItemsWaiting = 0; + vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting); + + size_t queued_size = 0; + uint8_t *queued_buff = (uint8_t *)xRingbufferReceiveUpTo(tx_ring_buf, &queued_size, 0, uxItemsWaiting); + if (queued_size && queued_buff != NULL) { + vRingbufferReturnItem(tx_ring_buf, (void *)queued_buff); + } + // flushes CDC FIFO + usb_serial_jtag_ll_txfifo_flush(); } -size_t HWCDC::write(const uint8_t *buffer, size_t size) -{ - uint32_t tx_timeout_ms = 0; - if(buffer == NULL || size == 0 || tx_ring_buf == NULL || tx_lock == NULL){ - return 0; - } - if(HWCDC::isCDC_Connected()) { - tx_timeout_ms = requested_tx_timeout_ms; - } else { - connected = false; - } - if(xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS){ - return 0; - } - size_t space = xRingbufferGetCurFreeSize(tx_ring_buf); - size_t to_send = size, so_far = 0; - - if(space > size){ - space = size; - } - // Non-Blocking method, Sending data to ringbuffer, and handle the data in ISR. - if(space > 0 && xRingbufferSend(tx_ring_buf, (void*) (buffer), space, 0) != pdTRUE){ - size = 0; - } else { - to_send -= space; - so_far += space; - // Now trigger the ISR to read data from the ring buffer. - usb_serial_jtag_ll_txfifo_flush(); - if(connected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); - - while(to_send){ - space = xRingbufferGetCurFreeSize(tx_ring_buf); - if(space > to_send){ - space = to_send; - } - // Blocking method, Sending data to ringbuffer, and handle the data in ISR. - if(xRingbufferSend(tx_ring_buf, (void*) (buffer+so_far), space, tx_timeout_ms / portTICK_PERIOD_MS) != pdTRUE){ - size = so_far; - break; - } - so_far += space; - to_send -= space; - // Now trigger the ISR to read data from the ring buffer. - usb_serial_jtag_ll_txfifo_flush(); - if(connected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); - } - } - // CDC is diconnected ==> flush all data from TX buffer - if(to_send && !usb_serial_jtag_ll_txfifo_writable()) { - connected = false; - flushTXBuffer(); - } - xSemaphoreGive(tx_lock); - return size; +size_t HWCDC::write(const uint8_t *buffer, size_t size) { + uint32_t tx_timeout_ms = 0; + if (buffer == NULL || size == 0 || tx_ring_buf == NULL || tx_lock == NULL) { + return 0; + } + if (HWCDC::isCDC_Connected()) { + tx_timeout_ms = requested_tx_timeout_ms; + } else { + connected = false; + } + if (xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS) { + return 0; + } + size_t space = xRingbufferGetCurFreeSize(tx_ring_buf); + size_t to_send = size, so_far = 0; + + if (space > size) { + space = size; + } + // Non-Blocking method, Sending data to ringbuffer, and handle the data in ISR. + if (space > 0 && xRingbufferSend(tx_ring_buf, (void *)(buffer), space, 0) != pdTRUE) { + size = 0; + } else { + to_send -= space; + so_far += space; + // Now trigger the ISR to read data from the ring buffer. + usb_serial_jtag_ll_txfifo_flush(); + if (connected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); + + while (to_send) { + space = xRingbufferGetCurFreeSize(tx_ring_buf); + if (space > to_send) { + space = to_send; + } + // Blocking method, Sending data to ringbuffer, and handle the data in ISR. + if (xRingbufferSend(tx_ring_buf, (void *)(buffer + so_far), space, tx_timeout_ms / portTICK_PERIOD_MS) != pdTRUE) { + size = so_far; + break; + } + so_far += space; + to_send -= space; + // Now trigger the ISR to read data from the ring buffer. + usb_serial_jtag_ll_txfifo_flush(); + if (connected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); + } + } + // CDC is disconnected ==> flush all data from TX buffer + if (to_send && !usb_serial_jtag_ll_txfifo_writable()) { + connected = false; + flushTXBuffer(); + } + xSemaphoreGive(tx_lock); + return size; } -size_t HWCDC::write(uint8_t c) -{ - return write(&c, 1); +size_t HWCDC::write(uint8_t c) { + return write(&c, 1); } -void HWCDC::flush(void) -{ - uint32_t tx_timeout_ms = 0; - if(tx_ring_buf == NULL || tx_lock == NULL){ - return; - } - if(HWCDC::isCDC_Connected()) { - tx_timeout_ms = requested_tx_timeout_ms; - } else { - connected = false; - } - if(xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS){ - return; - } - UBaseType_t uxItemsWaiting = 0; +void HWCDC::flush(void) { + uint32_t tx_timeout_ms = 0; + if (tx_ring_buf == NULL || tx_lock == NULL) { + return; + } + if (HWCDC::isCDC_Connected()) { + tx_timeout_ms = requested_tx_timeout_ms; + } else { + connected = false; + } + if (xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS) { + return; + } + UBaseType_t uxItemsWaiting = 0; + vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting); + if (uxItemsWaiting) { + // Now trigger the ISR to read data from the ring buffer. + usb_serial_jtag_ll_txfifo_flush(); + if (connected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); + } + uint8_t tries = 3; + while (tries && uxItemsWaiting) { + delay(5); + UBaseType_t lastUxItemsWaiting = uxItemsWaiting; vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting); - if(uxItemsWaiting){ - // Now trigger the ISR to read data from the ring buffer. - usb_serial_jtag_ll_txfifo_flush(); - if(connected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); - } - uint8_t tries = 3; - while(tries && uxItemsWaiting){ - delay(5); - UBaseType_t lastUxItemsWaiting = uxItemsWaiting; - vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting); - if (lastUxItemsWaiting == uxItemsWaiting) tries--; - } - if (tries == 0) { // CDC isn't connected anymore... - connected = false; - flushTXBuffer(); - } - xSemaphoreGive(tx_lock); + if (lastUxItemsWaiting == uxItemsWaiting) tries--; + } + if (tries == 0) { // CDC isn't connected anymore... + connected = false; + flushTXBuffer(); + } + xSemaphoreGive(tx_lock); } /* * READING */ -size_t HWCDC::setRxBufferSize(size_t rx_queue_len){ - if(rx_queue){ - vQueueDelete(rx_queue); - rx_queue = NULL; - } - if(!rx_queue_len){ - return 0; - } - rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t)); - if(!rx_queue){ - return 0; - } - return rx_queue_len; +size_t HWCDC::setRxBufferSize(size_t rx_queue_len) { + if (rx_queue) { + vQueueDelete(rx_queue); + rx_queue = NULL; + } + if (!rx_queue_len) { + return 0; + } + rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t)); + if (!rx_queue) { + return 0; + } + return rx_queue_len; } -int HWCDC::available(void) -{ - if(rx_queue == NULL){ - return -1; - } - return uxQueueMessagesWaiting(rx_queue); +int HWCDC::available(void) { + if (rx_queue == NULL) { + return -1; + } + return uxQueueMessagesWaiting(rx_queue); } -int HWCDC::peek(void) -{ - if(rx_queue == NULL){ - return -1; - } - uint8_t c; - if(xQueuePeek(rx_queue, &c, 0)) { - return c; - } +int HWCDC::peek(void) { + if (rx_queue == NULL) { return -1; + } + uint8_t c; + if (xQueuePeek(rx_queue, &c, 0)) { + return c; + } + return -1; } -int HWCDC::read(void) -{ - if(rx_queue == NULL){ - return -1; - } - uint8_t c = 0; - if(xQueueReceive(rx_queue, &c, 0)) { - return c; - } +int HWCDC::read(void) { + if (rx_queue == NULL) { return -1; + } + uint8_t c = 0; + if (xQueueReceive(rx_queue, &c, 0)) { + return c; + } + return -1; } -size_t HWCDC::read(uint8_t *buffer, size_t size) -{ - if(rx_queue == NULL){ - return -1; - } - uint8_t c = 0; - size_t count = 0; - while(count < size && xQueueReceive(rx_queue, &c, 0)){ - buffer[count++] = c; - } - return count; +size_t HWCDC::read(uint8_t *buffer, size_t size) { + if (rx_queue == NULL) { + return -1; + } + uint8_t c = 0; + size_t count = 0; + while (count < size && xQueueReceive(rx_queue, &c, 0)) { + buffer[count++] = c; + } + return count; } /* * DEBUG */ -void HWCDC::setDebugOutput(bool en) -{ - if(en) { - uartSetDebug(NULL); - ets_install_putc1((void (*)(char)) &cdc0_write_char); - } else { - ets_install_putc1(NULL); - } +void HWCDC::setDebugOutput(bool en) { + if (en) { + uartSetDebug(NULL); + ets_install_putc1((void (*)(char)) & cdc0_write_char); + } else { + ets_install_putc1(NULL); + } } #if ARDUINO_USB_MODE && ARDUINO_USB_CDC_ON_BOOT // Hardware JTAG CDC selected diff --git a/cores/esp32/HWCDC.h b/cores/esp32/HWCDC.h index 91e99d2774d..d2c73c832f1 100644 --- a/cores/esp32/HWCDC.h +++ b/cores/esp32/HWCDC.h @@ -26,93 +26,84 @@ ESP_EVENT_DECLARE_BASE(ARDUINO_HW_CDC_EVENTS); typedef enum { - ARDUINO_HW_CDC_ANY_EVENT = ESP_EVENT_ANY_ID, - ARDUINO_HW_CDC_CONNECTED_EVENT = 0, - ARDUINO_HW_CDC_BUS_RESET_EVENT, - ARDUINO_HW_CDC_RX_EVENT, - ARDUINO_HW_CDC_TX_EVENT, - ARDUINO_HW_CDC_MAX_EVENT, + ARDUINO_HW_CDC_ANY_EVENT = ESP_EVENT_ANY_ID, + ARDUINO_HW_CDC_CONNECTED_EVENT = 0, + ARDUINO_HW_CDC_BUS_RESET_EVENT, + ARDUINO_HW_CDC_RX_EVENT, + ARDUINO_HW_CDC_TX_EVENT, + ARDUINO_HW_CDC_MAX_EVENT, } arduino_hw_cdc_event_t; typedef union { - struct { - size_t len; - } rx; - struct { - size_t len; - } tx; + struct { + size_t len; + } rx; + struct { + size_t len; + } tx; } arduino_hw_cdc_event_data_t; -class HWCDC: public Stream -{ +class HWCDC : public Stream { private: - static bool deinit(void * busptr); - static bool isCDC_Connected(); - + static bool deinit(void *busptr); + static bool isCDC_Connected(); + public: - HWCDC(); - ~HWCDC(); + HWCDC(); + ~HWCDC(); - void onEvent(esp_event_handler_t callback); - void onEvent(arduino_hw_cdc_event_t event, esp_event_handler_t callback); + void onEvent(esp_event_handler_t callback); + void onEvent(arduino_hw_cdc_event_t event, esp_event_handler_t callback); - size_t setRxBufferSize(size_t); - size_t setTxBufferSize(size_t); - void setTxTimeoutMs(uint32_t timeout); - void begin(unsigned long baud=0); - void end(); - - int available(void); - int availableForWrite(void); - int peek(void); - int read(void); - size_t read(uint8_t *buffer, size_t size); - size_t write(uint8_t); - size_t write(const uint8_t *buffer, size_t size); - void flush(void); + size_t setRxBufferSize(size_t); + size_t setTxBufferSize(size_t); + void setTxTimeoutMs(uint32_t timeout); + void begin(unsigned long baud = 0); + void end(); - inline static bool isPlugged(void) - { - return usb_serial_jtag_is_connected(); - } + int available(void); + int availableForWrite(void); + int peek(void); + int read(void); + size_t read(uint8_t *buffer, size_t size); + size_t write(uint8_t); + size_t write(const uint8_t *buffer, size_t size); + void flush(void); - inline static bool isConnected(void) - { - return isCDC_Connected(); - } + inline static bool isPlugged(void) { + return usb_serial_jtag_is_connected(); + } - inline size_t read(char * buffer, size_t size) - { - return read((uint8_t*) buffer, size); - } - inline size_t write(const char * buffer, size_t size) - { - return write((uint8_t*) buffer, size); - } - inline size_t write(const char * s) - { - return write((uint8_t*) s, strlen(s)); - } - inline size_t write(unsigned long n) - { - return write((uint8_t) n); - } - inline size_t write(long n) - { - return write((uint8_t) n); - } - inline size_t write(unsigned int n) - { - return write((uint8_t) n); - } - inline size_t write(int n) - { - return write((uint8_t) n); - } - operator bool() const; - void setDebugOutput(bool); - uint32_t baudRate(){return 115200;} + inline static bool isConnected(void) { + return isCDC_Connected(); + } + inline size_t read(char *buffer, size_t size) { + return read((uint8_t *)buffer, size); + } + inline size_t write(const char *buffer, size_t size) { + return write((uint8_t *)buffer, size); + } + inline size_t write(const char *s) { + return write((uint8_t *)s, strlen(s)); + } + inline size_t write(unsigned long n) { + return write((uint8_t)n); + } + inline size_t write(long n) { + return write((uint8_t)n); + } + inline size_t write(unsigned int n) { + return write((uint8_t)n); + } + inline size_t write(int n) { + return write((uint8_t)n); + } + operator bool() const; + void setDebugOutput(bool); + uint32_t baudRate() { + return 115200; + } }; #if ARDUINO_USB_MODE && ARDUINO_USB_CDC_ON_BOOT // Hardware JTAG CDC selected #ifndef HWCDC_SERIAL_IS_DEFINED diff --git a/cores/esp32/HardwareI2C.h b/cores/esp32/HardwareI2C.h index 830c24a80d6..65b7e2036b2 100644 --- a/cores/esp32/HardwareI2C.h +++ b/cores/esp32/HardwareI2C.h @@ -21,22 +21,21 @@ #include #include "Stream.h" -class HardwareI2C : public Stream -{ - public: - virtual bool begin() = 0; - virtual bool begin(uint8_t address) = 0; - virtual bool end() = 0; - - virtual bool setClock(uint32_t freq) = 0; - - virtual void beginTransmission(uint8_t address) = 0; - virtual uint8_t endTransmission(bool stopBit) = 0; - virtual uint8_t endTransmission(void) = 0; - - virtual size_t requestFrom(uint8_t address, size_t len, bool stopBit) = 0; - virtual size_t requestFrom(uint8_t address, size_t len) = 0; - - virtual void onReceive(void(*)(int)) = 0; - virtual void onRequest(void(*)(void)) = 0; +class HardwareI2C : public Stream { +public: + virtual bool begin() = 0; + virtual bool begin(uint8_t address) = 0; + virtual bool end() = 0; + + virtual bool setClock(uint32_t freq) = 0; + + virtual void beginTransmission(uint8_t address) = 0; + virtual uint8_t endTransmission(bool stopBit) = 0; + virtual uint8_t endTransmission(void) = 0; + + virtual size_t requestFrom(uint8_t address, size_t len, bool stopBit) = 0; + virtual size_t requestFrom(uint8_t address, size_t len) = 0; + + virtual void onReceive(void (*)(int)) = 0; + virtual void onRequest(void (*)(void)) = 0; }; diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 3f3714d3573..1e4e3dfd19f 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -16,7 +16,7 @@ #endif #ifndef ARDUINO_SERIAL_EVENT_TASK_PRIORITY -#define ARDUINO_SERIAL_EVENT_TASK_PRIORITY (configMAX_PRIORITIES-1) +#define ARDUINO_SERIAL_EVENT_TASK_PRIORITY (configMAX_PRIORITIES - 1) #endif #ifndef ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE @@ -46,136 +46,133 @@ HardwareSerial Serial1(1); HardwareSerial Serial2(2); #endif -#if HWCDC_SERIAL_IS_DEFINED == 1 // Hardware JTAG CDC Event -extern void HWCDCSerialEvent (void)__attribute__((weak)); -void HWCDCSerialEvent(void) {} -#endif +#if HWCDC_SERIAL_IS_DEFINED == 1 // Hardware JTAG CDC Event +extern void HWCDCSerialEvent(void) __attribute__((weak)); +void HWCDCSerialEvent(void) {} +#endif -#if USB_SERIAL_IS_DEFINED == 1 // Native USB CDC Event +#if USB_SERIAL_IS_DEFINED == 1 // Native USB CDC Event // Used by Hardware Serial for USB CDC events -extern void USBSerialEvent (void)__attribute__((weak)); -void USBSerialEvent(void) {} -#endif +extern void USBSerialEvent(void) __attribute__((weak)); +void USBSerialEvent(void) {} +#endif -void serialEventRun(void) -{ -#if HWCDC_SERIAL_IS_DEFINED == 1 // Hardware JTAG CDC Event - if(HWCDCSerial.available()) HWCDCSerialEvent(); -#endif -#if USB_SERIAL_IS_DEFINED == 1 // Native USB CDC Event - if(USBSerial.available()) USBSerialEvent(); -#endif - // UART0 is default serialEvent() - if(Serial0.available()) serialEvent(); +void serialEventRun(void) { +#if HWCDC_SERIAL_IS_DEFINED == 1 // Hardware JTAG CDC Event + if (HWCDCSerial.available()) HWCDCSerialEvent(); +#endif +#if USB_SERIAL_IS_DEFINED == 1 // Native USB CDC Event + if (USBSerial.available()) USBSerialEvent(); +#endif + // UART0 is default serialEvent() + if (Serial0.available()) serialEvent(); #if SOC_UART_NUM > 1 - if(Serial1.available()) serialEvent1(); + if (Serial1.available()) serialEvent1(); #endif #if SOC_UART_NUM > 2 - if(Serial2.available()) serialEvent2(); + if (Serial2.available()) serialEvent2(); #endif } #endif #if !CONFIG_DISABLE_HAL_LOCKS -#define HSERIAL_MUTEX_LOCK() do {} while (xSemaphoreTake(_lock, portMAX_DELAY) != pdPASS) -#define HSERIAL_MUTEX_UNLOCK() xSemaphoreGive(_lock) +#define HSERIAL_MUTEX_LOCK() \ + do { \ + } while (xSemaphoreTake(_lock, portMAX_DELAY) != pdPASS) +#define HSERIAL_MUTEX_UNLOCK() xSemaphoreGive(_lock) #else #define HSERIAL_MUTEX_LOCK() #define HSERIAL_MUTEX_UNLOCK() #endif -HardwareSerial::HardwareSerial(uint8_t uart_nr) : -_uart_nr(uart_nr), -_uart(NULL), -_rxBufferSize(256), -_txBufferSize(0), -_onReceiveCB(NULL), -_onReceiveErrorCB(NULL), -_onReceiveTimeout(false), -_rxTimeout(2), -_rxFIFOFull(0), -_eventTask(NULL) +HardwareSerial::HardwareSerial(uint8_t uart_nr) + : _uart_nr(uart_nr), + _uart(NULL), + _rxBufferSize(256), + _txBufferSize(0), + _onReceiveCB(NULL), + _onReceiveErrorCB(NULL), + _onReceiveTimeout(false), + _rxTimeout(2), + _rxFIFOFull(0), + _eventTask(NULL) #if !CONFIG_DISABLE_HAL_LOCKS - ,_lock(NULL) + , + _lock(NULL) #endif { #if !CONFIG_DISABLE_HAL_LOCKS - if(_lock == NULL){ - _lock = xSemaphoreCreateMutex(); - if(_lock == NULL){ - log_e("xSemaphoreCreateMutex failed"); - return; - } + if (_lock == NULL) { + _lock = xSemaphoreCreateMutex(); + if (_lock == NULL) { + log_e("xSemaphoreCreateMutex failed"); + return; } + } #endif - // set deinit function in the Peripheral Manager - uart_init_PeriMan(); + // set deinit function in the Peripheral Manager + uart_init_PeriMan(); } -HardwareSerial::~HardwareSerial() -{ - end(); // explicit Full UART termination +HardwareSerial::~HardwareSerial() { + end(); // explicit Full UART termination #if !CONFIG_DISABLE_HAL_LOCKS - if(_lock != NULL){ - vSemaphoreDelete(_lock); - } + if (_lock != NULL) { + vSemaphoreDelete(_lock); + } #endif } -void HardwareSerial::_createEventTask(void *args) -{ - // Creating UART event Task - xTaskCreateUniversal(_uartEventTask, "uart_event_task", ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE, this, ARDUINO_SERIAL_EVENT_TASK_PRIORITY, &_eventTask, ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE); - if (_eventTask == NULL) { - log_e(" -- UART%d Event Task not Created!", _uart_nr); - } +void HardwareSerial::_createEventTask(void *args) { + // Creating UART event Task + xTaskCreateUniversal(_uartEventTask, "uart_event_task", ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE, this, ARDUINO_SERIAL_EVENT_TASK_PRIORITY, &_eventTask, ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE); + if (_eventTask == NULL) { + log_e(" -- UART%d Event Task not Created!", _uart_nr); + } } -void HardwareSerial::_destroyEventTask(void) -{ - if (_eventTask != NULL) { - vTaskDelete(_eventTask); - _eventTask = NULL; - } +void HardwareSerial::_destroyEventTask(void) { + if (_eventTask != NULL) { + vTaskDelete(_eventTask); + _eventTask = NULL; + } } -void HardwareSerial::onReceiveError(OnReceiveErrorCb function) -{ - HSERIAL_MUTEX_LOCK(); - // function may be NULL to cancel onReceive() from its respective task - _onReceiveErrorCB = function; - // this can be called after Serial.begin(), therefore it shall create the event task - if (function != NULL && _uart != NULL && _eventTask == NULL) { - _createEventTask(this); - } - HSERIAL_MUTEX_UNLOCK(); +void HardwareSerial::onReceiveError(OnReceiveErrorCb function) { + HSERIAL_MUTEX_LOCK(); + // function may be NULL to cancel onReceive() from its respective task + _onReceiveErrorCB = function; + // this can be called after Serial.begin(), therefore it shall create the event task + if (function != NULL && _uart != NULL && _eventTask == NULL) { + _createEventTask(this); + } + HSERIAL_MUTEX_UNLOCK(); } -void HardwareSerial::onReceive(OnReceiveCb function, bool onlyOnTimeout) -{ - HSERIAL_MUTEX_LOCK(); - // function may be NULL to cancel onReceive() from its respective task - _onReceiveCB = function; - - // setting the callback to NULL will just disable it - if (_onReceiveCB != NULL) { - // When Rx timeout is Zero (disabled), there is only one possible option that is callback when FIFO reaches 120 bytes - _onReceiveTimeout = _rxTimeout > 0 ? onlyOnTimeout : false; - - // in case that onReceive() shall work only with RX Timeout, FIFO shall be high - // this is a work around for an IDF issue with events and low FIFO Full value (< 3) - if (_onReceiveTimeout) { - uartSetRxFIFOFull(_uart, 120); - log_w("OnReceive is set to Timeout only, thus FIFO Full is now 120 bytes."); - } +void HardwareSerial::onReceive(OnReceiveCb function, bool onlyOnTimeout) { + HSERIAL_MUTEX_LOCK(); + // function may be NULL to cancel onReceive() from its respective task + _onReceiveCB = function; - // this method can be called after Serial.begin(), therefore it shall create the event task - if (_uart != NULL && _eventTask == NULL) { - _createEventTask(this); // Create event task - } + // setting the callback to NULL will just disable it + if (_onReceiveCB != NULL) { + // When Rx timeout is Zero (disabled), there is only one possible option that is callback when FIFO reaches 120 bytes + _onReceiveTimeout = _rxTimeout > 0 ? onlyOnTimeout : false; + + // in case that onReceive() shall work only with RX Timeout, FIFO shall be high + // this is a work around for an IDF issue with events and low FIFO Full value (< 3) + if (_onReceiveTimeout) { + uartSetRxFIFOFull(_uart, 120); + log_w("OnReceive is set to Timeout only, thus FIFO Full is now 120 bytes."); } - HSERIAL_MUTEX_UNLOCK(); + + // this method can be called after Serial.begin(), therefore it shall create the event task + if (_uart != NULL && _eventTask == NULL) { + _createEventTask(this); // Create event task + } + } + HSERIAL_MUTEX_UNLOCK(); } // This function allow the user to define how many bytes will trigger an Interrupt that will copy RX FIFO to the internal RX Ringbuffer @@ -183,391 +180,366 @@ void HardwareSerial::onReceive(OnReceiveCb function, bool onlyOnTimeout) // A low value of FIFO Full bytes will consume more CPU time within the ISR // A high value of FIFO Full bytes will make the application wait longer to have byte available for the Stkech in a streaming scenario // Both RX FIFO Full and RX Timeout may affect when onReceive() will be called -bool HardwareSerial::setRxFIFOFull(uint8_t fifoBytes) -{ - HSERIAL_MUTEX_LOCK(); - // in case that onReceive() shall work only with RX Timeout, FIFO shall be high - // this is a work around for an IDF issue with events and low FIFO Full value (< 3) - if (_onReceiveCB != NULL && _onReceiveTimeout) { - fifoBytes = 120; - log_w("OnReceive is set to Timeout only, thus FIFO Full is now 120 bytes."); - } - bool retCode = uartSetRxFIFOFull(_uart, fifoBytes); // Set new timeout - if (fifoBytes > 0 && fifoBytes < SOC_UART_FIFO_LEN - 1) _rxFIFOFull = fifoBytes; - HSERIAL_MUTEX_UNLOCK(); - return retCode; -} - -// timout is calculates in time to receive UART symbols at the UART baudrate. +bool HardwareSerial::setRxFIFOFull(uint8_t fifoBytes) { + HSERIAL_MUTEX_LOCK(); + // in case that onReceive() shall work only with RX Timeout, FIFO shall be high + // this is a work around for an IDF issue with events and low FIFO Full value (< 3) + if (_onReceiveCB != NULL && _onReceiveTimeout) { + fifoBytes = 120; + log_w("OnReceive is set to Timeout only, thus FIFO Full is now 120 bytes."); + } + bool retCode = uartSetRxFIFOFull(_uart, fifoBytes); // Set new timeout + if (fifoBytes > 0 && fifoBytes < SOC_UART_FIFO_LEN - 1) _rxFIFOFull = fifoBytes; + HSERIAL_MUTEX_UNLOCK(); + return retCode; +} + +// timeout is calculates in time to receive UART symbols at the UART baudrate. // the estimation is about 11 bits per symbol (SERIAL_8N1) -bool HardwareSerial::setRxTimeout(uint8_t symbols_timeout) -{ - HSERIAL_MUTEX_LOCK(); - - // Zero disables timeout, thus, onReceive callback will only be called when RX FIFO reaches 120 bytes - // Any non-zero value will activate onReceive callback based on UART baudrate with about 11 bits per symbol - _rxTimeout = symbols_timeout; - if (!symbols_timeout) _onReceiveTimeout = false; // only when RX timeout is disabled, we also must disable this flag - - bool retCode = uartSetRxTimeout(_uart, _rxTimeout); // Set new timeout - - HSERIAL_MUTEX_UNLOCK(); - return retCode; -} - -void HardwareSerial::eventQueueReset() -{ - QueueHandle_t uartEventQueue = NULL; - if (_uart == NULL) { - return; - } - uartGetEventQueue(_uart, &uartEventQueue); - if (uartEventQueue != NULL) { - xQueueReset(uartEventQueue); - } -} - -void HardwareSerial::_uartEventTask(void *args) -{ - HardwareSerial *uart = (HardwareSerial *)args; - uart_event_t event; - QueueHandle_t uartEventQueue = NULL; - uartGetEventQueue(uart->_uart, &uartEventQueue); - if (uartEventQueue != NULL) { - for(;;) { - //Waiting for UART event. - if(xQueueReceive(uartEventQueue, (void * )&event, (TickType_t)portMAX_DELAY)) { - hardwareSerial_error_t currentErr = UART_NO_ERROR; - switch(event.type) { - case UART_DATA: - if(uart->_onReceiveCB && uart->available() > 0 && - ((uart->_onReceiveTimeout && event.timeout_flag) || !uart->_onReceiveTimeout) ) - uart->_onReceiveCB(); - break; - case UART_FIFO_OVF: - log_w("UART%d FIFO Overflow. Consider adding Hardware Flow Control to your Application.", uart->_uart_nr); - currentErr = UART_FIFO_OVF_ERROR; - break; - case UART_BUFFER_FULL: - log_w("UART%d Buffer Full. Consider increasing your buffer size of your Application.", uart->_uart_nr); - currentErr = UART_BUFFER_FULL_ERROR; - break; - case UART_BREAK: - log_w("UART%d RX break.", uart->_uart_nr); - currentErr = UART_BREAK_ERROR; - break; - case UART_PARITY_ERR: - log_w("UART%d parity error.", uart->_uart_nr); - currentErr = UART_PARITY_ERROR; - break; - case UART_FRAME_ERR: - log_w("UART%d frame error.", uart->_uart_nr); - currentErr = UART_FRAME_ERROR; - break; - default: - log_w("UART%d unknown event type %d.", uart->_uart_nr, event.type); - break; - } - if (currentErr != UART_NO_ERROR) { - if(uart->_onReceiveErrorCB) uart->_onReceiveErrorCB(currentErr); - } - } +bool HardwareSerial::setRxTimeout(uint8_t symbols_timeout) { + HSERIAL_MUTEX_LOCK(); + + // Zero disables timeout, thus, onReceive callback will only be called when RX FIFO reaches 120 bytes + // Any non-zero value will activate onReceive callback based on UART baudrate with about 11 bits per symbol + _rxTimeout = symbols_timeout; + if (!symbols_timeout) _onReceiveTimeout = false; // only when RX timeout is disabled, we also must disable this flag + + bool retCode = uartSetRxTimeout(_uart, _rxTimeout); // Set new timeout + + HSERIAL_MUTEX_UNLOCK(); + return retCode; +} + +void HardwareSerial::eventQueueReset() { + QueueHandle_t uartEventQueue = NULL; + if (_uart == NULL) { + return; + } + uartGetEventQueue(_uart, &uartEventQueue); + if (uartEventQueue != NULL) { + xQueueReset(uartEventQueue); + } +} + +void HardwareSerial::_uartEventTask(void *args) { + HardwareSerial *uart = (HardwareSerial *)args; + uart_event_t event; + QueueHandle_t uartEventQueue = NULL; + uartGetEventQueue(uart->_uart, &uartEventQueue); + if (uartEventQueue != NULL) { + for (;;) { + //Waiting for UART event. + if (xQueueReceive(uartEventQueue, (void *)&event, (TickType_t)portMAX_DELAY)) { + hardwareSerial_error_t currentErr = UART_NO_ERROR; + switch (event.type) { + case UART_DATA: + if (uart->_onReceiveCB && uart->available() > 0 && ((uart->_onReceiveTimeout && event.timeout_flag) || !uart->_onReceiveTimeout)) + uart->_onReceiveCB(); + break; + case UART_FIFO_OVF: + log_w("UART%d FIFO Overflow. Consider adding Hardware Flow Control to your Application.", uart->_uart_nr); + currentErr = UART_FIFO_OVF_ERROR; + break; + case UART_BUFFER_FULL: + log_w("UART%d Buffer Full. Consider increasing your buffer size of your Application.", uart->_uart_nr); + currentErr = UART_BUFFER_FULL_ERROR; + break; + case UART_BREAK: + log_w("UART%d RX break.", uart->_uart_nr); + currentErr = UART_BREAK_ERROR; + break; + case UART_PARITY_ERR: + log_w("UART%d parity error.", uart->_uart_nr); + currentErr = UART_PARITY_ERROR; + break; + case UART_FRAME_ERR: + log_w("UART%d frame error.", uart->_uart_nr); + currentErr = UART_FRAME_ERROR; + break; + default: + log_w("UART%d unknown event type %d.", uart->_uart_nr, event.type); + break; } + if (currentErr != UART_NO_ERROR) { + if (uart->_onReceiveErrorCB) uart->_onReceiveErrorCB(currentErr); + } + } } - vTaskDelete(NULL); + } + vTaskDelete(NULL); } -void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert, unsigned long timeout_ms, uint8_t rxfifo_full_thrhd) -{ - if(_uart_nr >= SOC_UART_NUM) { - log_e("Serial number is invalid, please use a number from 0 to %u", SOC_UART_NUM - 1); - return; - } +void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert, unsigned long timeout_ms, uint8_t rxfifo_full_thrhd) { + if (_uart_nr >= SOC_UART_NUM) { + log_e("Serial number is invalid, please use a number from 0 to %u", SOC_UART_NUM - 1); + return; + } #if !CONFIG_DISABLE_HAL_LOCKS - if(_lock == NULL){ - log_e("MUTEX Lock failed. Can't begin."); - return; - } + if (_lock == NULL) { + log_e("MUTEX Lock failed. Can't begin."); + return; + } #endif - HSERIAL_MUTEX_LOCK(); - // First Time or after end() --> set default Pins - if (!uartIsDriverInstalled(_uart)) { - // get previously used RX/TX pins, if any. - int8_t _rxPin = uart_get_RxPin(_uart_nr); - int8_t _txPin = uart_get_TxPin(_uart_nr); - switch (_uart_nr) { - case UART_NUM_0: - if (rxPin < 0 && txPin < 0) { - // do not change RX0/TX0 if it has already been set before - rxPin = _rxPin < 0 ? (int8_t)SOC_RX0 : _rxPin; - txPin = _txPin < 0 ? (int8_t)SOC_TX0 : _txPin; - } - break; -#if SOC_UART_NUM > 1 // may save some flash bytes... - case UART_NUM_1: - if (rxPin < 0 && txPin < 0) { - // do not change RX1/TX1 if it has already been set before - rxPin = _rxPin < 0 ? (int8_t)RX1 : _rxPin; - txPin = _txPin < 0 ? (int8_t)TX1 : _txPin; - } - break; -#endif -#if SOC_UART_NUM > 2 // may save some flash bytes... - case UART_NUM_2: - if (rxPin < 0 && txPin < 0) { - // do not change RX2/TX2 if it has already been set before - rxPin = _rxPin < 0 ? (int8_t)RX2 : _rxPin; - txPin = _txPin < 0 ? (int8_t)TX2 : _txPin; - } - break; + HSERIAL_MUTEX_LOCK(); + // First Time or after end() --> set default Pins + if (!uartIsDriverInstalled(_uart)) { + // get previously used RX/TX pins, if any. + int8_t _rxPin = uart_get_RxPin(_uart_nr); + int8_t _txPin = uart_get_TxPin(_uart_nr); + switch (_uart_nr) { + case UART_NUM_0: + if (rxPin < 0 && txPin < 0) { + // do not change RX0/TX0 if it has already been set before + rxPin = _rxPin < 0 ? (int8_t)SOC_RX0 : _rxPin; + txPin = _txPin < 0 ? (int8_t)SOC_TX0 : _txPin; + } + break; +#if SOC_UART_NUM > 1 // may save some flash bytes... + case UART_NUM_1: + if (rxPin < 0 && txPin < 0) { + // do not change RX1/TX1 if it has already been set before + rxPin = _rxPin < 0 ? (int8_t)RX1 : _rxPin; + txPin = _txPin < 0 ? (int8_t)TX1 : _txPin; + } + break; #endif +#if SOC_UART_NUM > 2 // may save some flash bytes... + case UART_NUM_2: + if (rxPin < 0 && txPin < 0) { + // do not change RX2/TX2 if it has already been set before + rxPin = _rxPin < 0 ? (int8_t)RX2 : _rxPin; + txPin = _txPin < 0 ? (int8_t)TX2 : _txPin; } + break; +#endif } - - // map logical pins to GPIO numbers - rxPin = digitalPinToGPIONumber(rxPin); - txPin = digitalPinToGPIONumber(txPin); - // IDF UART driver keeps Pin setting on restarting. Negative Pin number will keep it unmodified. - // it will detach previous UART attached pins - - // indicates that uartbegin() has to initilize a new IDF driver - if (_testUartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, _rxBufferSize, _txBufferSize, invert, rxfifo_full_thrhd)) { - _destroyEventTask(); // when IDF uart driver must be restarted, _eventTask must finish too + } + + // map logical pins to GPIO numbers + rxPin = digitalPinToGPIONumber(rxPin); + txPin = digitalPinToGPIONumber(txPin); + // IDF UART driver keeps Pin setting on restarting. Negative Pin number will keep it unmodified. + // it will detach previous UART attached pins + + // indicates that uartbegin() has to initialize a new IDF driver + if (_testUartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, _rxBufferSize, _txBufferSize, invert, rxfifo_full_thrhd)) { + _destroyEventTask(); // when IDF uart driver must be restarted, _eventTask must finish too + } + + // IDF UART driver keeps Pin setting on restarting. Negative Pin number will keep it unmodified. + // it will detach previous UART attached pins + _uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, _rxBufferSize, _txBufferSize, invert, rxfifo_full_thrhd); + if (_uart == NULL) { + log_e("UART driver failed to start. Please check the logs."); + HSERIAL_MUTEX_UNLOCK(); + return; + } + if (!baud) { + // using baud rate as zero, forces it to try to detect the current baud rate in place + uartStartDetectBaudrate(_uart); + time_t startMillis = millis(); + unsigned long detectedBaudRate = 0; + while (millis() - startMillis < timeout_ms && !(detectedBaudRate = uartDetectBaudrate(_uart))) { + yield(); } - // IDF UART driver keeps Pin setting on restarting. Negative Pin number will keep it unmodified. - // it will detach previous UART attached pins - _uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, _rxBufferSize, _txBufferSize, invert, rxfifo_full_thrhd); - if (_uart == NULL) { + if (detectedBaudRate) { + delay(100); // Give some time... + _uart = uartBegin(_uart_nr, detectedBaudRate, config, rxPin, txPin, _rxBufferSize, _txBufferSize, invert, rxfifo_full_thrhd); + if (_uart == NULL) { log_e("UART driver failed to start. Please check the logs."); HSERIAL_MUTEX_UNLOCK(); return; - } - if (!baud) { - // using baud rate as zero, forces it to try to detect the current baud rate in place - uartStartDetectBaudrate(_uart); - time_t startMillis = millis(); - unsigned long detectedBaudRate = 0; - while(millis() - startMillis < timeout_ms && !(detectedBaudRate = uartDetectBaudrate(_uart))) { - yield(); - } - - if(detectedBaudRate) { - delay(100); // Give some time... - _uart = uartBegin(_uart_nr, detectedBaudRate, config, rxPin, txPin, _rxBufferSize, _txBufferSize, invert, rxfifo_full_thrhd); - if (_uart == NULL) { - log_e("UART driver failed to start. Please check the logs."); - HSERIAL_MUTEX_UNLOCK(); - return; - } - } else { - log_e("Could not detect baudrate. Serial data at the port must be present within the timeout for detection to be possible"); - _uart = NULL; - } - } - // create a task to deal with Serial Events when, for example, calling begin() twice to change the baudrate, - // or when setting the callback before calling begin() - if (_uart != NULL && (_onReceiveCB != NULL || _onReceiveErrorCB != NULL) && _eventTask == NULL) { - _createEventTask(this); - } - - // Set UART RX timeout - uartSetRxTimeout(_uart, _rxTimeout); - - // Set UART FIFO Full depending on the baud rate. - // Lower baud rates will force to emulate byte-by-byte reading - // Higher baud rates will keep IDF default of 120 bytes for FIFO FULL Interrupt - // It can also be changed by the application at any time - if (!_rxFIFOFull) { // it has not being changed before calling begin() - // set a default FIFO Full value for the IDF driver - uint8_t fifoFull = 1; - if (baud > 57600 || (_onReceiveCB != NULL && _onReceiveTimeout)) { - fifoFull = 120; } - uartSetRxFIFOFull(_uart, fifoFull); - _rxFIFOFull = fifoFull; + } else { + log_e("Could not detect baudrate. Serial data at the port must be present within the timeout for detection to be possible"); + _uart = NULL; + } + } + // create a task to deal with Serial Events when, for example, calling begin() twice to change the baudrate, + // or when setting the callback before calling begin() + if (_uart != NULL && (_onReceiveCB != NULL || _onReceiveErrorCB != NULL) && _eventTask == NULL) { + _createEventTask(this); + } + + // Set UART RX timeout + uartSetRxTimeout(_uart, _rxTimeout); + + // Set UART FIFO Full depending on the baud rate. + // Lower baud rates will force to emulate byte-by-byte reading + // Higher baud rates will keep IDF default of 120 bytes for FIFO FULL Interrupt + // It can also be changed by the application at any time + if (!_rxFIFOFull) { // it has not being changed before calling begin() + // set a default FIFO Full value for the IDF driver + uint8_t fifoFull = 1; + if (baud > 57600 || (_onReceiveCB != NULL && _onReceiveTimeout)) { + fifoFull = 120; } + uartSetRxFIFOFull(_uart, fifoFull); + _rxFIFOFull = fifoFull; + } - HSERIAL_MUTEX_UNLOCK(); + HSERIAL_MUTEX_UNLOCK(); } -void HardwareSerial::updateBaudRate(unsigned long baud) -{ +void HardwareSerial::updateBaudRate(unsigned long baud) { uartSetBaudRate(_uart, baud); } -void HardwareSerial::end() -{ - // default Serial.end() will completely disable HardwareSerial, - // including any tasks or debug message channel (log_x()) - but not for IDF log messages! - _onReceiveCB = NULL; - _onReceiveErrorCB = NULL; +void HardwareSerial::end() { + // default Serial.end() will completely disable HardwareSerial, + // including any tasks or debug message channel (log_x()) - but not for IDF log messages! + _onReceiveCB = NULL; + _onReceiveErrorCB = NULL; + if (uartGetDebug() == _uart_nr) { + uartSetDebug(0); + } + _rxFIFOFull = 0; + uartEnd(_uart_nr); // fully detach all pins and delete the UART driver + _destroyEventTask(); // when IDF uart driver is deleted, _eventTask must finish too + _uart = NULL; +} + +void HardwareSerial::setDebugOutput(bool en) { + if (_uart == 0) { + return; + } + if (en) { + uartSetDebug(_uart); + } else { if (uartGetDebug() == _uart_nr) { - uartSetDebug(0); - } - _rxFIFOFull = 0; - uartEnd(_uart_nr); // fully detach all pins and delete the UART driver - _destroyEventTask(); // when IDF uart driver is deleted, _eventTask must finish too - _uart = NULL; -} - -void HardwareSerial::setDebugOutput(bool en) -{ - if(_uart == 0) { - return; - } - if(en) { - uartSetDebug(_uart); - } else { - if(uartGetDebug() == _uart_nr) { - uartSetDebug(NULL); - } + uartSetDebug(NULL); } + } } -int HardwareSerial::available(void) -{ - return uartAvailable(_uart); +int HardwareSerial::available(void) { + return uartAvailable(_uart); } -int HardwareSerial::availableForWrite(void) -{ - return uartAvailableForWrite(_uart); +int HardwareSerial::availableForWrite(void) { + return uartAvailableForWrite(_uart); } -int HardwareSerial::peek(void) -{ - if (available()) { - return uartPeek(_uart); - } - return -1; +int HardwareSerial::peek(void) { + if (available()) { + return uartPeek(_uart); + } + return -1; } -int HardwareSerial::read(void) -{ - uint8_t c = 0; - if (uartReadBytes(_uart, &c, 1, 0) == 1) { - return c; - } else { - return -1; - } +int HardwareSerial::read(void) { + uint8_t c = 0; + if (uartReadBytes(_uart, &c, 1, 0) == 1) { + return c; + } else { + return -1; + } } // read characters into buffer // terminates if size characters have been read, or no further are pending // returns the number of characters placed in the buffer // the buffer is NOT null terminated. -size_t HardwareSerial::read(uint8_t *buffer, size_t size) -{ - return uartReadBytes(_uart, buffer, size, 0); +size_t HardwareSerial::read(uint8_t *buffer, size_t size) { + return uartReadBytes(_uart, buffer, size, 0); } // Overrides Stream::readBytes() to be faster using IDF -size_t HardwareSerial::readBytes(uint8_t *buffer, size_t length) -{ - return uartReadBytes(_uart, buffer, length, (uint32_t)getTimeout()); +size_t HardwareSerial::readBytes(uint8_t *buffer, size_t length) { + return uartReadBytes(_uart, buffer, length, (uint32_t)getTimeout()); } -void HardwareSerial::flush(void) -{ - uartFlush(_uart); +void HardwareSerial::flush(void) { + uartFlush(_uart); } -void HardwareSerial::flush(bool txOnly) -{ - uartFlushTxOnly(_uart, txOnly); +void HardwareSerial::flush(bool txOnly) { + uartFlushTxOnly(_uart, txOnly); } -size_t HardwareSerial::write(uint8_t c) -{ - uartWrite(_uart, c); - return 1; +size_t HardwareSerial::write(uint8_t c) { + uartWrite(_uart, c); + return 1; } -size_t HardwareSerial::write(const uint8_t *buffer, size_t size) -{ - uartWriteBuf(_uart, buffer, size); - return size; +size_t HardwareSerial::write(const uint8_t *buffer, size_t size) { + uartWriteBuf(_uart, buffer, size); + return size; } -uint32_t HardwareSerial::baudRate() -{ +uint32_t HardwareSerial::baudRate() { return uartGetBaudRate(_uart); } -HardwareSerial::operator bool() const -{ - return uartIsDriverInstalled(_uart); +HardwareSerial::operator bool() const { + return uartIsDriverInstalled(_uart); } -void HardwareSerial::setRxInvert(bool invert) -{ - uartSetRxInvert(_uart, invert); +void HardwareSerial::setRxInvert(bool invert) { + uartSetRxInvert(_uart, invert); } // negative Pin value will keep it unmodified // can be called after or before begin() -bool HardwareSerial::setPins(int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) -{ - // map logical pins to GPIO numbers - rxPin = digitalPinToGPIONumber(rxPin); - txPin = digitalPinToGPIONumber(txPin); - ctsPin = digitalPinToGPIONumber(ctsPin); - rtsPin = digitalPinToGPIONumber(rtsPin); +bool HardwareSerial::setPins(int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) { + // map logical pins to GPIO numbers + rxPin = digitalPinToGPIONumber(rxPin); + txPin = digitalPinToGPIONumber(txPin); + ctsPin = digitalPinToGPIONumber(ctsPin); + rtsPin = digitalPinToGPIONumber(rtsPin); - // uartSetPins() checks if pins are valid and, if necessary, detaches the previous ones - return uartSetPins(_uart_nr, rxPin, txPin, ctsPin, rtsPin); + // uartSetPins() checks if pins are valid and, if necessary, detaches the previous ones + return uartSetPins(_uart_nr, rxPin, txPin, ctsPin, rtsPin); } -// Enables or disables Hardware Flow Control using RTS and/or CTS pins +// Enables or disables Hardware Flow Control using RTS and/or CTS pins // must use setAllPins() in order to set RTS/CTS pins -// SerialHwFlowCtrl = UART_HW_FLOWCTRL_DISABLE, UART_HW_FLOWCTRL_RTS, +// SerialHwFlowCtrl = UART_HW_FLOWCTRL_DISABLE, UART_HW_FLOWCTRL_RTS, // UART_HW_FLOWCTRL_CTS, UART_HW_FLOWCTRL_CTS_RTS -bool HardwareSerial::setHwFlowCtrlMode(SerialHwFlowCtrl mode, uint8_t threshold) -{ - return uartSetHwFlowCtrlMode(_uart, mode, threshold); +bool HardwareSerial::setHwFlowCtrlMode(SerialHwFlowCtrl mode, uint8_t threshold) { + return uartSetHwFlowCtrlMode(_uart, mode, threshold); } -// Sets the uart mode in the esp32 uart for use with RS485 modes +// Sets the uart mode in the esp32 uart for use with RS485 modes // HwFlowCtrl must be disabled and RTS pin set -// SerialMode = UART_MODE_UART, UART_MODE_RS485_HALF_DUPLEX, UART_MODE_IRDA, -// or testing mode: UART_MODE_RS485_COLLISION_DETECT, UART_MODE_RS485_APP_CTRL -bool HardwareSerial::setMode(SerialMode mode) -{ - return uartSetMode(_uart, mode); +// SerialMode = UART_MODE_UART, UART_MODE_RS485_HALF_DUPLEX, UART_MODE_IRDA, +// or testing mode: UART_MODE_RS485_COLLISION_DETECT, UART_MODE_RS485_APP_CTRL +bool HardwareSerial::setMode(SerialMode mode) { + return uartSetMode(_uart, mode); } // minimum total RX Buffer size is the UART FIFO space (128 bytes for most SoC) + 1. IDF imposition. size_t HardwareSerial::setRxBufferSize(size_t new_size) { - if (_uart) { - log_e("RX Buffer can't be resized when Serial is already running. Set it before calling begin()."); - return 0; - } + if (_uart) { + log_e("RX Buffer can't be resized when Serial is already running. Set it before calling begin()."); + return 0; + } - if (new_size <= SOC_UART_FIFO_LEN) { - log_w("RX Buffer set to minimum value: %d.", SOC_UART_FIFO_LEN + 1); // ESP32, S2, S3 and C3 means higher than 128 - new_size = SOC_UART_FIFO_LEN + 1; - } + if (new_size <= SOC_UART_FIFO_LEN) { + log_w("RX Buffer set to minimum value: %d.", SOC_UART_FIFO_LEN + 1); // ESP32, S2, S3 and C3 means higher than 128 + new_size = SOC_UART_FIFO_LEN + 1; + } - _rxBufferSize = new_size; - return _rxBufferSize; + _rxBufferSize = new_size; + return _rxBufferSize; } // minimum total TX Buffer size is the UART FIFO space (128 bytes for most SoC). size_t HardwareSerial::setTxBufferSize(size_t new_size) { - if (_uart) { - log_e("TX Buffer can't be resized when Serial is already running. Set it before calling begin()."); - return 0; - } - - if (new_size <= SOC_UART_FIFO_LEN) { - log_w("TX Buffer set to minimum value: %d.", SOC_UART_FIFO_LEN); // ESP32, S2, S3 and C3 means higher than 128 - _txBufferSize = 0; // it will use just UART FIFO with SOC_UART_FIFO_LEN bytes (128 for most SoC) - return SOC_UART_FIFO_LEN; - } - // if new_size is higher than SOC_UART_FIFO_LEN, TX Ringbuffer will be active and it will be used to report back "availableToWrite()" - _txBufferSize = new_size; - return new_size; + if (_uart) { + log_e("TX Buffer can't be resized when Serial is already running. Set it before calling begin()."); + return 0; + } + + if (new_size <= SOC_UART_FIFO_LEN) { + log_w("TX Buffer set to minimum value: %d.", SOC_UART_FIFO_LEN); // ESP32, S2, S3 and C3 means higher than 128 + _txBufferSize = 0; // it will use just UART FIFO with SOC_UART_FIFO_LEN bytes (128 for most SoC) + return SOC_UART_FIFO_LEN; + } + // if new_size is higher than SOC_UART_FIFO_LEN, TX Ringbuffer will be active and it will be used to report back "availableToWrite()" + _txBufferSize = new_size; + return new_size; } diff --git a/cores/esp32/HardwareSerial.h b/cores/esp32/HardwareSerial.h index 0bf72d2aff2..766d0cf2be3 100644 --- a/cores/esp32/HardwareSerial.h +++ b/cores/esp32/HardwareSerial.h @@ -58,55 +58,55 @@ #include "freertos/semphr.h" enum SerialConfig { - SERIAL_5N1 = 0x8000010, - SERIAL_6N1 = 0x8000014, - SERIAL_7N1 = 0x8000018, - SERIAL_8N1 = 0x800001c, - SERIAL_5N2 = 0x8000030, - SERIAL_6N2 = 0x8000034, - SERIAL_7N2 = 0x8000038, - SERIAL_8N2 = 0x800003c, - SERIAL_5E1 = 0x8000012, - SERIAL_6E1 = 0x8000016, - SERIAL_7E1 = 0x800001a, - SERIAL_8E1 = 0x800001e, - SERIAL_5E2 = 0x8000032, - SERIAL_6E2 = 0x8000036, - SERIAL_7E2 = 0x800003a, - SERIAL_8E2 = 0x800003e, - SERIAL_5O1 = 0x8000013, - SERIAL_6O1 = 0x8000017, - SERIAL_7O1 = 0x800001b, - SERIAL_8O1 = 0x800001f, - SERIAL_5O2 = 0x8000033, - SERIAL_6O2 = 0x8000037, - SERIAL_7O2 = 0x800003b, - SERIAL_8O2 = 0x800003f + SERIAL_5N1 = 0x8000010, + SERIAL_6N1 = 0x8000014, + SERIAL_7N1 = 0x8000018, + SERIAL_8N1 = 0x800001c, + SERIAL_5N2 = 0x8000030, + SERIAL_6N2 = 0x8000034, + SERIAL_7N2 = 0x8000038, + SERIAL_8N2 = 0x800003c, + SERIAL_5E1 = 0x8000012, + SERIAL_6E1 = 0x8000016, + SERIAL_7E1 = 0x800001a, + SERIAL_8E1 = 0x800001e, + SERIAL_5E2 = 0x8000032, + SERIAL_6E2 = 0x8000036, + SERIAL_7E2 = 0x800003a, + SERIAL_8E2 = 0x800003e, + SERIAL_5O1 = 0x8000013, + SERIAL_6O1 = 0x8000017, + SERIAL_7O1 = 0x800001b, + SERIAL_8O1 = 0x800001f, + SERIAL_5O2 = 0x8000033, + SERIAL_6O2 = 0x8000037, + SERIAL_7O2 = 0x800003b, + SERIAL_8O2 = 0x800003f }; typedef uart_mode_t SerialMode; typedef uart_hw_flowcontrol_t SerialHwFlowCtrl; typedef enum { - UART_NO_ERROR, - UART_BREAK_ERROR, - UART_BUFFER_FULL_ERROR, - UART_FIFO_OVF_ERROR, - UART_FRAME_ERROR, - UART_PARITY_ERROR + UART_NO_ERROR, + UART_BREAK_ERROR, + UART_BUFFER_FULL_ERROR, + UART_FIFO_OVF_ERROR, + UART_FRAME_ERROR, + UART_PARITY_ERROR } hardwareSerial_error_t; #ifndef ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE - #define ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE 2048 +#define ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE 2048 #endif #ifndef ARDUINO_SERIAL_EVENT_TASK_PRIORITY - #define ARDUINO_SERIAL_EVENT_TASK_PRIORITY (configMAX_PRIORITIES-1) +#define ARDUINO_SERIAL_EVENT_TASK_PRIORITY (configMAX_PRIORITIES - 1) #endif #ifndef ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE - #define ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE -1 +#define ARDUINO_SERIAL_EVENT_TASK_RUNNING_CORE -1 #endif // UART0 pins are defined by default by the bootloader. @@ -114,234 +114,225 @@ typedef enum { // have changed and you know what you are doing. #ifndef SOC_RX0 - #if CONFIG_IDF_TARGET_ESP32 - #define SOC_RX0 (gpio_num_t)3 - #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 - #define SOC_RX0 (gpio_num_t)44 - #elif CONFIG_IDF_TARGET_ESP32C2 - #define SOC_RX0 (gpio_num_t)19 - #elif CONFIG_IDF_TARGET_ESP32C3 - #define SOC_RX0 (gpio_num_t)20 - #elif CONFIG_IDF_TARGET_ESP32C6 - #define SOC_RX0 (gpio_num_t)17 - #elif CONFIG_IDF_TARGET_ESP32H2 - #define SOC_RX0 (gpio_num_t)23 - #endif +#if CONFIG_IDF_TARGET_ESP32 +#define SOC_RX0 (gpio_num_t)3 +#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +#define SOC_RX0 (gpio_num_t)44 +#elif CONFIG_IDF_TARGET_ESP32C2 +#define SOC_RX0 (gpio_num_t)19 +#elif CONFIG_IDF_TARGET_ESP32C3 +#define SOC_RX0 (gpio_num_t)20 +#elif CONFIG_IDF_TARGET_ESP32C6 +#define SOC_RX0 (gpio_num_t)17 +#elif CONFIG_IDF_TARGET_ESP32H2 +#define SOC_RX0 (gpio_num_t)23 +#endif #endif #ifndef SOC_TX0 - #if CONFIG_IDF_TARGET_ESP32 - #define SOC_TX0 (gpio_num_t)1 - #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 - #define SOC_TX0 (gpio_num_t)43 - #elif CONFIG_IDF_TARGET_ESP32C2 - #define SOC_TX0 (gpio_num_t)20 - #elif CONFIG_IDF_TARGET_ESP32C3 - #define SOC_TX0 (gpio_num_t)21 - #elif CONFIG_IDF_TARGET_ESP32C6 - #define SOC_TX0 (gpio_num_t)16 - #elif CONFIG_IDF_TARGET_ESP32H2 - #define SOC_TX0 (gpio_num_t)24 - #endif +#if CONFIG_IDF_TARGET_ESP32 +#define SOC_TX0 (gpio_num_t)1 +#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +#define SOC_TX0 (gpio_num_t)43 +#elif CONFIG_IDF_TARGET_ESP32C2 +#define SOC_TX0 (gpio_num_t)20 +#elif CONFIG_IDF_TARGET_ESP32C3 +#define SOC_TX0 (gpio_num_t)21 +#elif CONFIG_IDF_TARGET_ESP32C6 +#define SOC_TX0 (gpio_num_t)16 +#elif CONFIG_IDF_TARGET_ESP32H2 +#define SOC_TX0 (gpio_num_t)24 +#endif #endif // Default pins for UART1 are arbitrary, and defined here for convenience. #if SOC_UART_NUM > 1 - #ifndef RX1 - #if CONFIG_IDF_TARGET_ESP32 - #define RX1 (gpio_num_t)26 - #elif CONFIG_IDF_TARGET_ESP32S2 - #define RX1 (gpio_num_t)4 - #elif CONFIG_IDF_TARGET_ESP32C2 - #define RX1 (gpio_num_t)10 - #elif CONFIG_IDF_TARGET_ESP32C3 - #define RX1 (gpio_num_t)18 - #elif CONFIG_IDF_TARGET_ESP32S3 - #define RX1 (gpio_num_t)15 - #elif CONFIG_IDF_TARGET_ESP32C6 - #define RX1 (gpio_num_t)4 - #elif CONFIG_IDF_TARGET_ESP32H2 - #define RX1 (gpio_num_t)0 - #endif - #endif - - #ifndef TX1 - #if CONFIG_IDF_TARGET_ESP32 - #define TX1 (gpio_num_t)27 - #elif CONFIG_IDF_TARGET_ESP32S2 - #define TX1 (gpio_num_t)5 - #elif CONFIG_IDF_TARGET_ESP32C2 - #define TX1 (gpio_num_t)18 - #elif CONFIG_IDF_TARGET_ESP32C3 - #define TX1 (gpio_num_t)19 - #elif CONFIG_IDF_TARGET_ESP32S3 - #define TX1 (gpio_num_t)16 - #elif CONFIG_IDF_TARGET_ESP32C6 - #define TX1 (gpio_num_t)5 - #elif CONFIG_IDF_TARGET_ESP32H2 - #define TX1 (gpio_num_t)1 - #endif - #endif +#ifndef RX1 +#if CONFIG_IDF_TARGET_ESP32 +#define RX1 (gpio_num_t)26 +#elif CONFIG_IDF_TARGET_ESP32S2 +#define RX1 (gpio_num_t)4 +#elif CONFIG_IDF_TARGET_ESP32C2 +#define RX1 (gpio_num_t)10 +#elif CONFIG_IDF_TARGET_ESP32C3 +#define RX1 (gpio_num_t)18 +#elif CONFIG_IDF_TARGET_ESP32S3 +#define RX1 (gpio_num_t)15 +#elif CONFIG_IDF_TARGET_ESP32C6 +#define RX1 (gpio_num_t)4 +#elif CONFIG_IDF_TARGET_ESP32H2 +#define RX1 (gpio_num_t)0 +#endif +#endif + +#ifndef TX1 +#if CONFIG_IDF_TARGET_ESP32 +#define TX1 (gpio_num_t)27 +#elif CONFIG_IDF_TARGET_ESP32S2 +#define TX1 (gpio_num_t)5 +#elif CONFIG_IDF_TARGET_ESP32C2 +#define TX1 (gpio_num_t)18 +#elif CONFIG_IDF_TARGET_ESP32C3 +#define TX1 (gpio_num_t)19 +#elif CONFIG_IDF_TARGET_ESP32S3 +#define TX1 (gpio_num_t)16 +#elif CONFIG_IDF_TARGET_ESP32C6 +#define TX1 (gpio_num_t)5 +#elif CONFIG_IDF_TARGET_ESP32H2 +#define TX1 (gpio_num_t)1 +#endif +#endif #endif /* SOC_UART_NUM > 1 */ // Default pins for UART2 are arbitrary, and defined here for convenience. #if SOC_UART_NUM > 2 - #ifndef RX2 - #if CONFIG_IDF_TARGET_ESP32 - #define RX2 (gpio_num_t)4 - #elif CONFIG_IDF_TARGET_ESP32S3 - #define RX2 (gpio_num_t)19 - #endif - #endif - - #ifndef TX2 - #if CONFIG_IDF_TARGET_ESP32 - #define TX2 (gpio_num_t)25 - #elif CONFIG_IDF_TARGET_ESP32S3 - #define TX2 (gpio_num_t)20 - #endif - #endif +#ifndef RX2 +#if CONFIG_IDF_TARGET_ESP32 +#define RX2 (gpio_num_t)4 +#elif CONFIG_IDF_TARGET_ESP32S3 +#define RX2 (gpio_num_t)19 +#endif +#endif + +#ifndef TX2 +#if CONFIG_IDF_TARGET_ESP32 +#define TX2 (gpio_num_t)25 +#elif CONFIG_IDF_TARGET_ESP32S3 +#define TX2 (gpio_num_t)20 +#endif +#endif #endif /* SOC_UART_NUM > 2 */ typedef std::function OnReceiveCb; typedef std::function OnReceiveErrorCb; -class HardwareSerial: public Stream -{ +class HardwareSerial : public Stream { public: - HardwareSerial(uint8_t uart_nr); - ~HardwareSerial(); - - // setRxTimeout sets the timeout after which onReceive callback will be called (after receiving data, it waits for this time of UART rx inactivity to call the callback fnc) - // param symbols_timeout defines a timeout threshold in uart symbol periods. Setting 0 symbol timeout disables the callback call by timeout. - // Maximum timeout setting is calculacted automatically by IDF. If set above the maximum, it is ignored and an error is printed on Serial0 (check console). - // Examples: Maximum for 11 bits symbol is 92 (SERIAL_8N2, SERIAL_8E1, SERIAL_8O1, etc), Maximum for 10 bits symbol is 101 (SERIAL_8N1). - // For example symbols_timeout=1 defines a timeout equal to transmission time of one symbol (~11 bit) on current baudrate. - // For a baudrate of 9600, SERIAL_8N1 (10 bit symbol) and symbols_timeout = 3, the timeout would be 3 / (9600 / 10) = 3.125 ms - bool setRxTimeout(uint8_t symbols_timeout); - - // setRxFIFOFull(uint8_t fifoBytes) will set the number of bytes that will trigger UART_INTR_RXFIFO_FULL interrupt and fill up RxRingBuffer - // This affects some functions such as Serial::available() and Serial.read() because, in a UART flow of receiving data, Serial internal - // RxRingBuffer will be filled only after these number of bytes arrive or a RX Timeout happens. - // This parameter can be set to 1 in order to receive byte by byte, but it will also consume more CPU time as the ISR will be activates often. - bool setRxFIFOFull(uint8_t fifoBytes); - - // onReceive will setup a callback that will be called whenever an UART interruption occurs (UART_INTR_RXFIFO_FULL or UART_INTR_RXFIFO_TOUT) - // UART_INTR_RXFIFO_FULL interrupt triggers at UART_FULL_THRESH_DEFAULT bytes received (defined as 120 bytes by default in IDF) - // UART_INTR_RXFIFO_TOUT interrupt triggers at UART_TOUT_THRESH_DEFAULT symbols passed without any reception (defined as 10 symbos by default in IDF) - // onlyOnTimeout parameter will define how onReceive will behave: - // Default: true -- The callback will only be called when RX Timeout happens. - // Whole stream of bytes will be ready for being read on the callback function at once. - // This option may lead to Rx Overflow depending on the Rx Buffer Size and number of bytes received in the streaming - // false -- The callback will be called when FIFO reaches 120 bytes and also on RX Timeout. - // The stream of incommig bytes will be "split" into blocks of 120 bytes on each callback. - // This option avoid any sort of Rx Overflow, but leaves the UART packet reassembling work to the Application. - void onReceive(OnReceiveCb function, bool onlyOnTimeout = false); - - // onReceive will be called on error events (see hardwareSerial_error_t) - void onReceiveError(OnReceiveErrorCb function); - - // eventQueueReset clears all events in the queue (the events that trigger onReceive and onReceiveError) - maybe usefull in some use cases - void eventQueueReset(); - - // When pins are changed, it will detach the previous ones - // if pin is negative, it won't be set/changed and will be kept as is - // timeout_ms is used in baudrate detection (ESP32, ESP32S2 only) - // invert will invert RX/TX polarity - // rxfifo_full_thrhd if the UART Flow Control Threshold in the UART FIFO (max 127) - void begin(unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1, bool invert=false, unsigned long timeout_ms = 20000UL, uint8_t rxfifo_full_thrhd = 112); - void end(void); - void updateBaudRate(unsigned long baud); - int available(void); - int availableForWrite(void); - int peek(void); - int read(void); - size_t read(uint8_t *buffer, size_t size); - inline size_t read(char * buffer, size_t size) - { - return read((uint8_t*) buffer, size); - } - // Overrides Stream::readBytes() to be faster using IDF - size_t readBytes(uint8_t *buffer, size_t length); - size_t readBytes(char *buffer, size_t length) - { - return readBytes((uint8_t *) buffer, length); - } - void flush(void); - void flush( bool txOnly); - size_t write(uint8_t); - size_t write(const uint8_t *buffer, size_t size); - inline size_t write(const char * buffer, size_t size) - { - return write((uint8_t*) buffer, size); - } - inline size_t write(const char * s) - { - return write((uint8_t*) s, strlen(s)); - } - inline size_t write(unsigned long n) - { - return write((uint8_t) n); - } - inline size_t write(long n) - { - return write((uint8_t) n); - } - inline size_t write(unsigned int n) - { - return write((uint8_t) n); - } - inline size_t write(int n) - { - return write((uint8_t) n); - } - uint32_t baudRate(); - operator bool() const; - - void setDebugOutput(bool); - - void setRxInvert(bool); - - // Negative Pin Number will keep it unmodified, thus this function can set individual pins - // setPins() can be called after or before begin() - // When pins are changed, it will detach the previous ones - bool setPins(int8_t rxPin, int8_t txPin, int8_t ctsPin = -1, int8_t rtsPin = -1); - // Enables or disables Hardware Flow Control using RTS and/or CTS pins (must use setAllPins() before) - // UART_HW_FLOWCTRL_DISABLE = 0x0 disable hardware flow control - // UART_HW_FLOWCTRL_RTS = 0x1 enable RX hardware flow control (rts) - // UART_HW_FLOWCTRL_CTS = 0x2 enable TX hardware flow control (cts) - // UART_HW_FLOWCTRL_CTS_RTS = 0x3 enable hardware flow control - bool setHwFlowCtrlMode(SerialHwFlowCtrl mode = UART_HW_FLOWCTRL_CTS_RTS, uint8_t threshold = 64); // 64 is half FIFO Length - // Used to set RS485 modes such as UART_MODE_RS485_HALF_DUPLEX for Auto RTS function on ESP32 - // UART_MODE_UART = 0x00 mode: regular UART mode - // UART_MODE_RS485_HALF_DUPLEX = 0x01 mode: half duplex RS485 UART mode control by RTS pin - // UART_MODE_IRDA = 0x02 mode: IRDA UART mode - // UART_MODE_RS485_COLLISION_DETECT = 0x03 mode: RS485 collision detection UART mode (used for test purposes) - // UART_MODE_RS485_APP_CTRL = 0x04 mode: application control RS485 UART mode (used for test purposes) - bool setMode(SerialMode mode); - size_t setRxBufferSize(size_t new_size); - size_t setTxBufferSize(size_t new_size); + HardwareSerial(uint8_t uart_nr); + ~HardwareSerial(); + + // setRxTimeout sets the timeout after which onReceive callback will be called (after receiving data, it waits for this time of UART rx inactivity to call the callback fnc) + // param symbols_timeout defines a timeout threshold in uart symbol periods. Setting 0 symbol timeout disables the callback call by timeout. + // Maximum timeout setting is calculacted automatically by IDF. If set above the maximum, it is ignored and an error is printed on Serial0 (check console). + // Examples: Maximum for 11 bits symbol is 92 (SERIAL_8N2, SERIAL_8E1, SERIAL_8O1, etc), Maximum for 10 bits symbol is 101 (SERIAL_8N1). + // For example symbols_timeout=1 defines a timeout equal to transmission time of one symbol (~11 bit) on current baudrate. + // For a baudrate of 9600, SERIAL_8N1 (10 bit symbol) and symbols_timeout = 3, the timeout would be 3 / (9600 / 10) = 3.125 ms + bool setRxTimeout(uint8_t symbols_timeout); + + // setRxFIFOFull(uint8_t fifoBytes) will set the number of bytes that will trigger UART_INTR_RXFIFO_FULL interrupt and fill up RxRingBuffer + // This affects some functions such as Serial::available() and Serial.read() because, in a UART flow of receiving data, Serial internal + // RxRingBuffer will be filled only after these number of bytes arrive or a RX Timeout happens. + // This parameter can be set to 1 in order to receive byte by byte, but it will also consume more CPU time as the ISR will be activates often. + bool setRxFIFOFull(uint8_t fifoBytes); + + // onReceive will setup a callback that will be called whenever an UART interruption occurs (UART_INTR_RXFIFO_FULL or UART_INTR_RXFIFO_TOUT) + // UART_INTR_RXFIFO_FULL interrupt triggers at UART_FULL_THRESH_DEFAULT bytes received (defined as 120 bytes by default in IDF) + // UART_INTR_RXFIFO_TOUT interrupt triggers at UART_TOUT_THRESH_DEFAULT symbols passed without any reception (defined as 10 symbos by default in IDF) + // onlyOnTimeout parameter will define how onReceive will behave: + // Default: true -- The callback will only be called when RX Timeout happens. + // Whole stream of bytes will be ready for being read on the callback function at once. + // This option may lead to Rx Overflow depending on the Rx Buffer Size and number of bytes received in the streaming + // false -- The callback will be called when FIFO reaches 120 bytes and also on RX Timeout. + // The stream of incommig bytes will be "split" into blocks of 120 bytes on each callback. + // This option avoid any sort of Rx Overflow, but leaves the UART packet reassembling work to the Application. + void onReceive(OnReceiveCb function, bool onlyOnTimeout = false); + + // onReceive will be called on error events (see hardwareSerial_error_t) + void onReceiveError(OnReceiveErrorCb function); + + // eventQueueReset clears all events in the queue (the events that trigger onReceive and onReceiveError) - maybe useful in some use cases + void eventQueueReset(); + + // When pins are changed, it will detach the previous ones + // if pin is negative, it won't be set/changed and will be kept as is + // timeout_ms is used in baudrate detection (ESP32, ESP32S2 only) + // invert will invert RX/TX polarity + // rxfifo_full_thrhd if the UART Flow Control Threshold in the UART FIFO (max 127) + void begin(unsigned long baud, uint32_t config = SERIAL_8N1, int8_t rxPin = -1, int8_t txPin = -1, bool invert = false, unsigned long timeout_ms = 20000UL, uint8_t rxfifo_full_thrhd = 112); + void end(void); + void updateBaudRate(unsigned long baud); + int available(void); + int availableForWrite(void); + int peek(void); + int read(void); + size_t read(uint8_t *buffer, size_t size); + inline size_t read(char *buffer, size_t size) { + return read((uint8_t *)buffer, size); + } + // Overrides Stream::readBytes() to be faster using IDF + size_t readBytes(uint8_t *buffer, size_t length); + size_t readBytes(char *buffer, size_t length) { + return readBytes((uint8_t *)buffer, length); + } + void flush(void); + void flush(bool txOnly); + size_t write(uint8_t); + size_t write(const uint8_t *buffer, size_t size); + inline size_t write(const char *buffer, size_t size) { + return write((uint8_t *)buffer, size); + } + inline size_t write(const char *s) { + return write((uint8_t *)s, strlen(s)); + } + inline size_t write(unsigned long n) { + return write((uint8_t)n); + } + inline size_t write(long n) { + return write((uint8_t)n); + } + inline size_t write(unsigned int n) { + return write((uint8_t)n); + } + inline size_t write(int n) { + return write((uint8_t)n); + } + uint32_t baudRate(); + operator bool() const; + + void setDebugOutput(bool); + + void setRxInvert(bool); + + // Negative Pin Number will keep it unmodified, thus this function can set individual pins + // setPins() can be called after or before begin() + // When pins are changed, it will detach the previous ones + bool setPins(int8_t rxPin, int8_t txPin, int8_t ctsPin = -1, int8_t rtsPin = -1); + // Enables or disables Hardware Flow Control using RTS and/or CTS pins (must use setAllPins() before) + // UART_HW_FLOWCTRL_DISABLE = 0x0 disable hardware flow control + // UART_HW_FLOWCTRL_RTS = 0x1 enable RX hardware flow control (rts) + // UART_HW_FLOWCTRL_CTS = 0x2 enable TX hardware flow control (cts) + // UART_HW_FLOWCTRL_CTS_RTS = 0x3 enable hardware flow control + bool setHwFlowCtrlMode(SerialHwFlowCtrl mode = UART_HW_FLOWCTRL_CTS_RTS, uint8_t threshold = 64); // 64 is half FIFO Length + // Used to set RS485 modes such as UART_MODE_RS485_HALF_DUPLEX for Auto RTS function on ESP32 + // UART_MODE_UART = 0x00 mode: regular UART mode + // UART_MODE_RS485_HALF_DUPLEX = 0x01 mode: half duplex RS485 UART mode control by RTS pin + // UART_MODE_IRDA = 0x02 mode: IRDA UART mode + // UART_MODE_RS485_COLLISION_DETECT = 0x03 mode: RS485 collision detection UART mode (used for test purposes) + // UART_MODE_RS485_APP_CTRL = 0x04 mode: application control RS485 UART mode (used for test purposes) + bool setMode(SerialMode mode); + size_t setRxBufferSize(size_t new_size); + size_t setTxBufferSize(size_t new_size); protected: - uint8_t _uart_nr; - uart_t* _uart; - size_t _rxBufferSize; - size_t _txBufferSize; - OnReceiveCb _onReceiveCB; - OnReceiveErrorCb _onReceiveErrorCB; - // _onReceive and _rxTimeout have be consistent when timeout is disabled - bool _onReceiveTimeout; - uint8_t _rxTimeout, _rxFIFOFull; - TaskHandle_t _eventTask; + uint8_t _uart_nr; + uart_t *_uart; + size_t _rxBufferSize; + size_t _txBufferSize; + OnReceiveCb _onReceiveCB; + OnReceiveErrorCb _onReceiveErrorCB; + // _onReceive and _rxTimeout have be consistent when timeout is disabled + bool _onReceiveTimeout; + uint8_t _rxTimeout, _rxFIFOFull; + TaskHandle_t _eventTask; #if !CONFIG_DISABLE_HAL_LOCKS - SemaphoreHandle_t _lock; + SemaphoreHandle_t _lock; #endif - void _createEventTask(void *args); - void _destroyEventTask(void); - static void _uartEventTask(void *args); + void _createEventTask(void *args); + void _destroyEventTask(void); + static void _uartEventTask(void *args); }; extern void serialEventRun(void) __attribute__((weak)); @@ -350,17 +341,17 @@ extern void serialEventRun(void) __attribute__((weak)); #ifndef ARDUINO_USB_CDC_ON_BOOT #define ARDUINO_USB_CDC_ON_BOOT 0 #endif -#if ARDUINO_USB_CDC_ON_BOOT //Serial used from Native_USB_CDC | HW_CDC_JTAG -#if ARDUINO_USB_MODE // Hardware CDC mode +#if ARDUINO_USB_CDC_ON_BOOT //Serial used from Native_USB_CDC | HW_CDC_JTAG +#if ARDUINO_USB_MODE // Hardware CDC mode // Arduino Serial is the HW JTAG CDC device #define Serial HWCDCSerial -#else // !ARDUINO_USB_MODE -- Native USB Mode +#else // !ARDUINO_USB_MODE -- Native USB Mode // Arduino Serial is the Native USB CDC device #define Serial USBSerial #endif // ARDUINO_USB_MODE #else // !ARDUINO_USB_CDC_ON_BOOT -- Serial is used from UART0 // if not using CDC on Boot, Arduino Serial is the UART0 device -#define Serial Serial0 +#define Serial Serial0 #endif // ARDUINO_USB_CDC_ON_BOOT // There is always Seria0 for UART0 extern HardwareSerial Serial0; @@ -370,6 +361,6 @@ extern HardwareSerial Serial1; #if SOC_UART_NUM > 2 extern HardwareSerial Serial2; #endif -#endif //!defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL) +#endif //!defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL) -#endif // HardwareSerial_h +#endif // HardwareSerial_h diff --git a/cores/esp32/HashBuilder.h b/cores/esp32/HashBuilder.h index 86013bd65a2..12b3cfb887a 100644 --- a/cores/esp32/HashBuilder.h +++ b/cores/esp32/HashBuilder.h @@ -20,33 +20,29 @@ #include "HEXBuilder.h" -class HashBuilder : public HEXBuilder -{ +class HashBuilder : public HEXBuilder { public: - virtual ~HashBuilder() {} - virtual void begin() = 0; - - virtual void add(const uint8_t* data, size_t len) = 0; - virtual void add(const char* data) - { - add((const uint8_t*)data, strlen(data)); - } - virtual void add(String data) - { - add(data.c_str()); - } - - virtual void addHexString(const char* data) = 0; - virtual void addHexString(String data) - { - addHexString(data.c_str()); - } - - virtual bool addStream(Stream& stream, const size_t maxLen) = 0; - virtual void calculate() = 0; - virtual void getBytes(uint8_t* output) = 0; - virtual void getChars(char* output) = 0; - virtual String toString() = 0; + virtual ~HashBuilder() {} + virtual void begin() = 0; + + virtual void add(const uint8_t* data, size_t len) = 0; + virtual void add(const char* data) { + add((const uint8_t*)data, strlen(data)); + } + virtual void add(String data) { + add(data.c_str()); + } + + virtual void addHexString(const char* data) = 0; + virtual void addHexString(String data) { + addHexString(data.c_str()); + } + + virtual bool addStream(Stream& stream, const size_t maxLen) = 0; + virtual void calculate() = 0; + virtual void getBytes(uint8_t* output) = 0; + virtual void getChars(char* output) = 0; + virtual String toString() = 0; }; #endif diff --git a/cores/esp32/IPAddress.cpp b/cores/esp32/IPAddress.cpp index 0fa5affdea7..f0342f2fbbf 100644 --- a/cores/esp32/IPAddress.cpp +++ b/cores/esp32/IPAddress.cpp @@ -22,409 +22,386 @@ #include "lwip/netif.h" #include "StreamString.h" -IPAddress::IPAddress() : IPAddress(IPv4) {} +IPAddress::IPAddress() + : IPAddress(IPv4) {} -IPAddress::IPAddress(IPType ip_type) -{ - _type = ip_type; - _zone = IP6_NO_ZONE; - memset(_address.bytes, 0, sizeof(_address.bytes)); +IPAddress::IPAddress(IPType ip_type) { + _type = ip_type; + _zone = IP6_NO_ZONE; + memset(_address.bytes, 0, sizeof(_address.bytes)); } -IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) -{ - _type = IPv4; - _zone = IP6_NO_ZONE; - memset(_address.bytes, 0, sizeof(_address.bytes)); - _address.bytes[IPADDRESS_V4_BYTES_INDEX] = first_octet; - _address.bytes[IPADDRESS_V4_BYTES_INDEX + 1] = second_octet; - _address.bytes[IPADDRESS_V4_BYTES_INDEX + 2] = third_octet; - _address.bytes[IPADDRESS_V4_BYTES_INDEX + 3] = fourth_octet; +IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) { + _type = IPv4; + _zone = IP6_NO_ZONE; + memset(_address.bytes, 0, sizeof(_address.bytes)); + _address.bytes[IPADDRESS_V4_BYTES_INDEX] = first_octet; + _address.bytes[IPADDRESS_V4_BYTES_INDEX + 1] = second_octet; + _address.bytes[IPADDRESS_V4_BYTES_INDEX + 2] = third_octet; + _address.bytes[IPADDRESS_V4_BYTES_INDEX + 3] = fourth_octet; } IPAddress::IPAddress(uint8_t o1, uint8_t o2, uint8_t o3, uint8_t o4, uint8_t o5, uint8_t o6, uint8_t o7, uint8_t o8, uint8_t o9, uint8_t o10, uint8_t o11, uint8_t o12, uint8_t o13, uint8_t o14, uint8_t o15, uint8_t o16, uint8_t z) { - _type = IPv6; - _address.bytes[0] = o1; - _address.bytes[1] = o2; - _address.bytes[2] = o3; - _address.bytes[3] = o4; - _address.bytes[4] = o5; - _address.bytes[5] = o6; - _address.bytes[6] = o7; - _address.bytes[7] = o8; - _address.bytes[8] = o9; - _address.bytes[9] = o10; - _address.bytes[10] = o11; - _address.bytes[11] = o12; - _address.bytes[12] = o13; - _address.bytes[13] = o14; - _address.bytes[14] = o15; - _address.bytes[15] = o16; - _zone = z; + _type = IPv6; + _address.bytes[0] = o1; + _address.bytes[1] = o2; + _address.bytes[2] = o3; + _address.bytes[3] = o4; + _address.bytes[4] = o5; + _address.bytes[5] = o6; + _address.bytes[6] = o7; + _address.bytes[7] = o8; + _address.bytes[8] = o9; + _address.bytes[9] = o10; + _address.bytes[10] = o11; + _address.bytes[11] = o12; + _address.bytes[12] = o13; + _address.bytes[13] = o14; + _address.bytes[14] = o15; + _address.bytes[15] = o16; + _zone = z; } -IPAddress::IPAddress(uint32_t address) -{ - // IPv4 only - _type = IPv4; - _zone = IP6_NO_ZONE; - memset(_address.bytes, 0, sizeof(_address.bytes)); - _address.dword[IPADDRESS_V4_DWORD_INDEX] = address; - - // NOTE on conversion/comparison and uint32_t: - // These conversions are host platform dependent. - // There is a defined integer representation of IPv4 addresses, - // based on network byte order (will be the value on big endian systems), - // e.g. http://2398766798 is the same as http://142.250.70.206, - // However on little endian systems the octets 0x83, 0xFA, 0x46, 0xCE, - // in that order, will form the integer (uint32_t) 3460758158 . +IPAddress::IPAddress(uint32_t address) { + // IPv4 only + _type = IPv4; + _zone = IP6_NO_ZONE; + memset(_address.bytes, 0, sizeof(_address.bytes)); + _address.dword[IPADDRESS_V4_DWORD_INDEX] = address; + + // NOTE on conversion/comparison and uint32_t: + // These conversions are host platform dependent. + // There is a defined integer representation of IPv4 addresses, + // based on network byte order (will be the value on big endian systems), + // e.g. http://2398766798 is the same as http://142.250.70.206, + // However on little endian systems the octets 0x83, 0xFA, 0x46, 0xCE, + // in that order, will form the integer (uint32_t) 3460758158 . } -IPAddress::IPAddress(const uint8_t *address) : IPAddress(IPv4, address) {} +IPAddress::IPAddress(const uint8_t* address) + : IPAddress(IPv4, address) {} -IPAddress::IPAddress(IPType ip_type, const uint8_t *address, uint8_t z) -{ - _type = ip_type; - if (ip_type == IPv4) { - memset(_address.bytes, 0, sizeof(_address.bytes)); - memcpy(&_address.bytes[IPADDRESS_V4_BYTES_INDEX], address, sizeof(uint32_t)); - _zone = 0; - } else { - memcpy(_address.bytes, address, sizeof(_address.bytes)); - _zone = z; - } +IPAddress::IPAddress(IPType ip_type, const uint8_t* address, uint8_t z) { + _type = ip_type; + if (ip_type == IPv4) { + memset(_address.bytes, 0, sizeof(_address.bytes)); + memcpy(&_address.bytes[IPADDRESS_V4_BYTES_INDEX], address, sizeof(uint32_t)); + _zone = 0; + } else { + memcpy(_address.bytes, address, sizeof(_address.bytes)); + _zone = z; + } } -IPAddress::IPAddress(const char *address) -{ - fromString(address); +IPAddress::IPAddress(const char* address) { + fromString(address); } -IPAddress::IPAddress(const IPAddress& address) -{ - *this = address; +IPAddress::IPAddress(const IPAddress& address) { + *this = address; } -String IPAddress::toString(bool includeZone) const -{ - StreamString s; - printTo(s, includeZone); - return String(s); +String IPAddress::toString(bool includeZone) const { + StreamString s; + printTo(s, includeZone); + return String(s); } -bool IPAddress::fromString(const char *address) { - if (!fromString4(address)) { - return fromString6(address); - } - return true; +bool IPAddress::fromString(const char* address) { + if (!fromString4(address)) { + return fromString6(address); + } + return true; } -bool IPAddress::fromString4(const char *address) -{ - // TODO: add support for "a", "a.b", "a.b.c" formats +bool IPAddress::fromString4(const char* address) { + // TODO: add support for "a", "a.b", "a.b.c" formats - int16_t acc = -1; // Accumulator - uint8_t dots = 0; + int16_t acc = -1; // Accumulator + uint8_t dots = 0; - memset(_address.bytes, 0, sizeof(_address.bytes)); - while (*address) - { - char c = *address++; - if (c >= '0' && c <= '9') - { - acc = (acc < 0) ? (c - '0') : acc * 10 + (c - '0'); - if (acc > 255) { - // Value out of [0..255] range - return false; - } - } - else if (c == '.') - { - if (dots == 3) { - // Too many dots (there must be 3 dots) - return false; - } - if (acc < 0) { - /* No value between dots, e.g. '1..' */ - return false; - } - _address.bytes[IPADDRESS_V4_BYTES_INDEX + dots++] = acc; - acc = -1; - } - else - { - // Invalid char - return false; - } - } - - if (dots != 3) { - // Too few dots (there must be 3 dots) + memset(_address.bytes, 0, sizeof(_address.bytes)); + while (*address) { + char c = *address++; + if (c >= '0' && c <= '9') { + acc = (acc < 0) ? (c - '0') : acc * 10 + (c - '0'); + if (acc > 255) { + // Value out of [0..255] range return false; - } - if (acc < 0) { + } + } else if (c == '.') { + if (dots == 3) { + // Too many dots (there must be 3 dots) + return false; + } + if (acc < 0) { /* No value between dots, e.g. '1..' */ return false; + } + _address.bytes[IPADDRESS_V4_BYTES_INDEX + dots++] = acc; + acc = -1; + } else { + // Invalid char + return false; } - _address.bytes[IPADDRESS_V4_BYTES_INDEX + 3] = acc; - _type = IPv4; - return true; + } + + if (dots != 3) { + // Too few dots (there must be 3 dots) + return false; + } + if (acc < 0) { + /* No value between dots, e.g. '1..' */ + return false; + } + _address.bytes[IPADDRESS_V4_BYTES_INDEX + 3] = acc; + _type = IPv4; + return true; } -bool IPAddress::fromString6(const char *address) { - uint32_t acc = 0; // Accumulator - int colons = 0, double_colons = -1; - - while (*address) - { - char c = tolower(*address++); - if (isalnum(c) && c <= 'f') { - if (c >= 'a') - c -= 'a' - '0' - 10; - acc = acc * 16 + (c - '0'); - if (acc > 0xffff) - // Value out of range - return false; - } - else if (c == ':') { - if (*address == ':') { - if (double_colons >= 0) { - // :: allowed once - return false; - } - if (*address != '\0' && *(address + 1) == ':') { - // ::: not allowed - return false; - } - // remember location - double_colons = colons + !!acc; - address++; - } else if (*address == '\0') { - // can't end with a single colon - return false; - } - if (colons == 7) - // too many separators - return false; - _address.bytes[colons * 2] = acc >> 8; - _address.bytes[colons * 2 + 1] = acc & 0xff; - colons++; - acc = 0; +bool IPAddress::fromString6(const char* address) { + uint32_t acc = 0; // Accumulator + int colons = 0, double_colons = -1; + + while (*address) { + char c = tolower(*address++); + if (isalnum(c) && c <= 'f') { + if (c >= 'a') + c -= 'a' - '0' - 10; + acc = acc * 16 + (c - '0'); + if (acc > 0xffff) + // Value out of range + return false; + } else if (c == ':') { + if (*address == ':') { + if (double_colons >= 0) { + // :: allowed once + return false; } - else if (c == '%') { - _zone = netif_name_to_index(address); - while(*address != '\0'){ - address++; - } + if (*address != '\0' && *(address + 1) == ':') { + // ::: not allowed + return false; } - else - // Invalid char - return false; - } - - if (double_colons == -1 && colons != 7) { - // Too few separators + // remember location + double_colons = colons + !!acc; + address++; + } else if (*address == '\0') { + // can't end with a single colon return false; - } - if (double_colons > -1 && colons > 6) { - // Too many segments (double colon must be at least one zero field) + } + if (colons == 7) + // too many separators return false; - } - _address.bytes[colons * 2] = acc >> 8; - _address.bytes[colons * 2 + 1] = acc & 0xff; - colons++; - - if (double_colons != -1) { - for (int i = colons * 2 - double_colons * 2 - 1; i >= 0; i--) - _address.bytes[16 - colons * 2 + double_colons * 2 + i] = _address.bytes[double_colons * 2 + i]; - for (int i = double_colons * 2; i < 16 - colons * 2 + double_colons * 2; i++) - _address.bytes[i] = 0; - } - - _type = IPv6; - return true; + _address.bytes[colons * 2] = acc >> 8; + _address.bytes[colons * 2 + 1] = acc & 0xff; + colons++; + acc = 0; + } else if (c == '%') { + _zone = netif_name_to_index(address); + while (*address != '\0') { + address++; + } + } else + // Invalid char + return false; + } + + if (double_colons == -1 && colons != 7) { + // Too few separators + return false; + } + if (double_colons > -1 && colons > 6) { + // Too many segments (double colon must be at least one zero field) + return false; + } + _address.bytes[colons * 2] = acc >> 8; + _address.bytes[colons * 2 + 1] = acc & 0xff; + colons++; + + if (double_colons != -1) { + for (int i = colons * 2 - double_colons * 2 - 1; i >= 0; i--) + _address.bytes[16 - colons * 2 + double_colons * 2 + i] = _address.bytes[double_colons * 2 + i]; + for (int i = double_colons * 2; i < 16 - colons * 2 + double_colons * 2; i++) + _address.bytes[i] = 0; + } + + _type = IPv6; + return true; } -IPAddress& IPAddress::operator=(const uint8_t *address) -{ - // IPv4 only conversion from byte pointer - _type = IPv4; - memset(_address.bytes, 0, sizeof(_address.bytes)); - memcpy(&_address.bytes[IPADDRESS_V4_BYTES_INDEX], address, sizeof(uint32_t)); - return *this; +IPAddress& IPAddress::operator=(const uint8_t* address) { + // IPv4 only conversion from byte pointer + _type = IPv4; + memset(_address.bytes, 0, sizeof(_address.bytes)); + memcpy(&_address.bytes[IPADDRESS_V4_BYTES_INDEX], address, sizeof(uint32_t)); + return *this; } -IPAddress& IPAddress::operator=(const char *address) -{ - fromString(address); - return *this; +IPAddress& IPAddress::operator=(const char* address) { + fromString(address); + return *this; } -IPAddress& IPAddress::operator=(uint32_t address) -{ - // IPv4 conversion - // See note on conversion/comparison and uint32_t - _type = IPv4; - memset(_address.bytes, 0, sizeof(_address.bytes)); - _address.dword[IPADDRESS_V4_DWORD_INDEX] = address; - return *this; +IPAddress& IPAddress::operator=(uint32_t address) { + // IPv4 conversion + // See note on conversion/comparison and uint32_t + _type = IPv4; + memset(_address.bytes, 0, sizeof(_address.bytes)); + _address.dword[IPADDRESS_V4_DWORD_INDEX] = address; + return *this; } -IPAddress& IPAddress::operator=(const IPAddress& address){ - _type = address.type(); - _zone = address.zone(); - memcpy(_address.bytes, address._address.bytes, sizeof(_address.bytes)); - return *this; +IPAddress& IPAddress::operator=(const IPAddress& address) { + _type = address.type(); + _zone = address.zone(); + memcpy(_address.bytes, address._address.bytes, sizeof(_address.bytes)); + return *this; } bool IPAddress::operator==(const IPAddress& addr) const { - return (addr._type == _type) - && (memcmp(addr._address.bytes, _address.bytes, sizeof(_address.bytes)) == 0); + return (addr._type == _type) + && (memcmp(addr._address.bytes, _address.bytes, sizeof(_address.bytes)) == 0); } -bool IPAddress::operator==(const uint8_t* addr) const -{ - // IPv4 only comparison to byte pointer - // Can't support IPv6 as we know our type, but not the length of the pointer - return _type == IPv4 && memcmp(addr, &_address.bytes[IPADDRESS_V4_BYTES_INDEX], sizeof(uint32_t)) == 0; +bool IPAddress::operator==(const uint8_t* addr) const { + // IPv4 only comparison to byte pointer + // Can't support IPv6 as we know our type, but not the length of the pointer + return _type == IPv4 && memcmp(addr, &_address.bytes[IPADDRESS_V4_BYTES_INDEX], sizeof(uint32_t)) == 0; } uint8_t IPAddress::operator[](int index) const { - if (_type == IPv4) { - return _address.bytes[IPADDRESS_V4_BYTES_INDEX + index]; - } - return _address.bytes[index]; + if (_type == IPv4) { + return _address.bytes[IPADDRESS_V4_BYTES_INDEX + index]; + } + return _address.bytes[index]; } uint8_t& IPAddress::operator[](int index) { - if (_type == IPv4) { - return _address.bytes[IPADDRESS_V4_BYTES_INDEX + index]; - } - return _address.bytes[index]; + if (_type == IPv4) { + return _address.bytes[IPADDRESS_V4_BYTES_INDEX + index]; + } + return _address.bytes[index]; } -size_t IPAddress::printTo(Print& p) const -{ - return printTo(p, false); +size_t IPAddress::printTo(Print& p) const { + return printTo(p, false); } -size_t IPAddress::printTo(Print& p, bool includeZone) const -{ - size_t n = 0; - - if (_type == IPv6) { - // IPv6 IETF canonical format: compress left-most longest run of two or more zero fields, lower case - int8_t longest_start = -1; - int8_t longest_length = 1; - int8_t current_start = -1; - int8_t current_length = 0; - for (int8_t f = 0; f < 8; f++) { - if (_address.bytes[f * 2] == 0 && _address.bytes[f * 2 + 1] == 0) { - if (current_start == -1) { - current_start = f; - current_length = 1; - } else { - current_length++; - } - if (current_length > longest_length) { - longest_start = current_start; - longest_length = current_length; - } - } else { - current_start = -1; - } +size_t IPAddress::printTo(Print& p, bool includeZone) const { + size_t n = 0; + + if (_type == IPv6) { + // IPv6 IETF canonical format: compress left-most longest run of two or more zero fields, lower case + int8_t longest_start = -1; + int8_t longest_length = 1; + int8_t current_start = -1; + int8_t current_length = 0; + for (int8_t f = 0; f < 8; f++) { + if (_address.bytes[f * 2] == 0 && _address.bytes[f * 2 + 1] == 0) { + if (current_start == -1) { + current_start = f; + current_length = 1; + } else { + current_length++; } - for (int f = 0; f < 8; f++) { - if (f < longest_start || f >= longest_start + longest_length) { - uint8_t c1 = _address.bytes[f * 2] >> 4; - uint8_t c2 = _address.bytes[f * 2] & 0xf; - uint8_t c3 = _address.bytes[f * 2 + 1] >> 4; - uint8_t c4 = _address.bytes[f * 2 + 1] & 0xf; - if (c1 > 0) { - n += p.print((char)(c1 < 10 ? '0' + c1 : 'a' + c1 - 10)); - } - if (c1 > 0 || c2 > 0) { - n += p.print((char)(c2 < 10 ? '0' + c2 : 'a' + c2 - 10)); - } - if (c1 > 0 || c2 > 0 || c3 > 0) { - n += p.print((char)(c3 < 10 ? '0' + c3 : 'a' + c3 - 10)); - } - n += p.print((char)(c4 < 10 ? '0' + c4 : 'a' + c4 - 10)); - if (f < 7) { - n += p.print(':'); - } - } else if (f == longest_start) { - if (longest_start == 0) { - n += p.print(':'); - } - n += p.print(':'); - } + if (current_length > longest_length) { + longest_start = current_start; + longest_length = current_length; } - // add a zone if zone-id is non-zero - if(_zone > 0 && includeZone){ - n += p.print('%'); - char if_name[NETIF_NAMESIZE]; - netif_index_to_name(_zone, if_name); - n += p.print(if_name); + } else { + current_start = -1; + } + } + for (int f = 0; f < 8; f++) { + if (f < longest_start || f >= longest_start + longest_length) { + uint8_t c1 = _address.bytes[f * 2] >> 4; + uint8_t c2 = _address.bytes[f * 2] & 0xf; + uint8_t c3 = _address.bytes[f * 2 + 1] >> 4; + uint8_t c4 = _address.bytes[f * 2 + 1] & 0xf; + if (c1 > 0) { + n += p.print((char)(c1 < 10 ? '0' + c1 : 'a' + c1 - 10)); + } + if (c1 > 0 || c2 > 0) { + n += p.print((char)(c2 < 10 ? '0' + c2 : 'a' + c2 - 10)); + } + if (c1 > 0 || c2 > 0 || c3 > 0) { + n += p.print((char)(c3 < 10 ? '0' + c3 : 'a' + c3 - 10)); + } + n += p.print((char)(c4 < 10 ? '0' + c4 : 'a' + c4 - 10)); + if (f < 7) { + n += p.print(':'); } - return n; + } else if (f == longest_start) { + if (longest_start == 0) { + n += p.print(':'); + } + n += p.print(':'); + } } - - // IPv4 - for (int i =0; i < 3; i++) - { - n += p.print(_address.bytes[IPADDRESS_V4_BYTES_INDEX + i], DEC); - n += p.print('.'); + // add a zone if zone-id is non-zero + if (_zone > 0 && includeZone) { + n += p.print('%'); + char if_name[NETIF_NAMESIZE]; + netif_index_to_name(_zone, if_name); + n += p.print(if_name); } - n += p.print(_address.bytes[IPADDRESS_V4_BYTES_INDEX + 3], DEC); return n; + } + + // IPv4 + for (int i = 0; i < 3; i++) { + n += p.print(_address.bytes[IPADDRESS_V4_BYTES_INDEX + i], DEC); + n += p.print('.'); + } + n += p.print(_address.bytes[IPADDRESS_V4_BYTES_INDEX + 3], DEC); + return n; } -IPAddress::IPAddress(const ip_addr_t *addr){ - from_ip_addr_t(addr); +IPAddress::IPAddress(const ip_addr_t* addr) { + from_ip_addr_t(addr); } void IPAddress::to_ip_addr_t(ip_addr_t* addr) const { - if(_type == IPv6){ - addr->type = IPADDR_TYPE_V6; - addr->u_addr.ip6.addr[0] = _address.dword[0]; - addr->u_addr.ip6.addr[1] = _address.dword[1]; - addr->u_addr.ip6.addr[2] = _address.dword[2]; - addr->u_addr.ip6.addr[3] = _address.dword[3]; + if (_type == IPv6) { + addr->type = IPADDR_TYPE_V6; + addr->u_addr.ip6.addr[0] = _address.dword[0]; + addr->u_addr.ip6.addr[1] = _address.dword[1]; + addr->u_addr.ip6.addr[2] = _address.dword[2]; + addr->u_addr.ip6.addr[3] = _address.dword[3]; #if LWIP_IPV6_SCOPES - addr->u_addr.ip6.zone = _zone; + addr->u_addr.ip6.zone = _zone; #endif /* LWIP_IPV6_SCOPES */ - } else { - addr->type = IPADDR_TYPE_V4; - addr->u_addr.ip4.addr = _address.dword[IPADDRESS_V4_DWORD_INDEX]; - } + } else { + addr->type = IPADDR_TYPE_V4; + addr->u_addr.ip4.addr = _address.dword[IPADDRESS_V4_DWORD_INDEX]; + } } -IPAddress& IPAddress::from_ip_addr_t(const ip_addr_t* addr){ - if(addr->type == IPADDR_TYPE_V6){ - _type = IPv6; - _address.dword[0] = addr->u_addr.ip6.addr[0]; - _address.dword[1] = addr->u_addr.ip6.addr[1]; - _address.dword[2] = addr->u_addr.ip6.addr[2]; - _address.dword[3] = addr->u_addr.ip6.addr[3]; +IPAddress& IPAddress::from_ip_addr_t(const ip_addr_t* addr) { + if (addr->type == IPADDR_TYPE_V6) { + _type = IPv6; + _address.dword[0] = addr->u_addr.ip6.addr[0]; + _address.dword[1] = addr->u_addr.ip6.addr[1]; + _address.dword[2] = addr->u_addr.ip6.addr[2]; + _address.dword[3] = addr->u_addr.ip6.addr[3]; #if LWIP_IPV6_SCOPES - _zone = addr->u_addr.ip6.zone; + _zone = addr->u_addr.ip6.zone; #endif /* LWIP_IPV6_SCOPES */ - } else { - _type = IPv4; - _address.dword[IPADDRESS_V4_DWORD_INDEX] = addr->u_addr.ip4.addr; - } - return *this; + } else { + _type = IPv4; + _address.dword[IPADDRESS_V4_DWORD_INDEX] = addr->u_addr.ip4.addr; + } + return *this; } esp_ip6_addr_type_t IPAddress::addr_type() const { - if(_type != IPv6){ - return ESP_IP6_ADDR_IS_UNKNOWN; - } - ip_addr_t addr; - to_ip_addr_t(&addr); - return esp_netif_ip6_get_addr_type((esp_ip6_addr_t*)(&(addr.u_addr.ip6))); + if (_type != IPv6) { + return ESP_IP6_ADDR_IS_UNKNOWN; + } + ip_addr_t addr; + to_ip_addr_t(&addr); + return esp_netif_ip6_get_addr_type((esp_ip6_addr_t*)(&(addr.u_addr.ip6))); } const IPAddress IN6ADDR_ANY(IPv6); -const IPAddress INADDR_NONE(0,0,0,0); +const IPAddress INADDR_NONE(0, 0, 0, 0); diff --git a/cores/esp32/IPAddress.h b/cores/esp32/IPAddress.h index 0a3efd01c8d..0a5a15fbaad 100644 --- a/cores/esp32/IPAddress.h +++ b/cores/esp32/IPAddress.h @@ -31,88 +31,100 @@ // A class to make it easier to handle and pass around IP addresses enum IPType { - IPv4, - IPv6 + IPv4, + IPv6 }; class IPAddress : public Printable { private: - union { - uint8_t bytes[16]; - uint32_t dword[4]; - } _address; - IPType _type; - uint8_t _zone; - - // Access the raw byte array containing the address. Because this returns a pointer - // to the internal structure rather than a copy of the address this function should only - // be used when you know that the usage of the returned uint8_t* will be transient and not - // stored. - uint8_t* raw_address() { return _type == IPv4 ? &_address.bytes[IPADDRESS_V4_BYTES_INDEX] : _address.bytes; } + union { + uint8_t bytes[16]; + uint32_t dword[4]; + } _address; + IPType _type; + uint8_t _zone; + + // Access the raw byte array containing the address. Because this returns a pointer + // to the internal structure rather than a copy of the address this function should only + // be used when you know that the usage of the returned uint8_t* will be transient and not + // stored. + uint8_t* raw_address() { + return _type == IPv4 ? &_address.bytes[IPADDRESS_V4_BYTES_INDEX] : _address.bytes; + } public: - // Constructors - - // Default IPv4 - IPAddress(); - IPAddress(IPType ip_type); - IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); - IPAddress(uint8_t o1, uint8_t o2, uint8_t o3, uint8_t o4, uint8_t o5, uint8_t o6, uint8_t o7, uint8_t o8, uint8_t o9, uint8_t o10, uint8_t o11, uint8_t o12, uint8_t o13, uint8_t o14, uint8_t o15, uint8_t o16, uint8_t z=0); - // IPv4; see implementation note - IPAddress(uint32_t address); - // Default IPv4 - IPAddress(const uint8_t *address); - IPAddress(IPType ip_type, const uint8_t *address, uint8_t z=0); - // If IPv4 fails tries IPv6 see fromString function - IPAddress(const char *address); - IPAddress(const IPAddress& address); - - bool fromString(const char *address); - bool fromString(const String &address) { return fromString(address.c_str()); } - - // Overloaded cast operator to allow IPAddress objects to be used where a uint32_t is expected - // NOTE: IPv4 only; see implementation note - operator uint32_t() const { return _type == IPv4 ? _address.dword[IPADDRESS_V4_DWORD_INDEX] : 0; }; - - bool operator==(const IPAddress& addr) const; - bool operator!=(const IPAddress& addr) const { return !(*this == addr); }; - - // NOTE: IPv4 only; we don't know the length of the pointer - bool operator==(const uint8_t* addr) const; - - // Overloaded index operator to allow getting and setting individual octets of the address - uint8_t operator[](int index) const; - uint8_t& operator[](int index); - - // Overloaded copy operators to allow initialisation of IPAddress objects from other types - // NOTE: IPv4 only - IPAddress& operator=(const uint8_t *address); - // NOTE: IPv4 only; see implementation note - IPAddress& operator=(uint32_t address); - // If IPv4 fails tries IPv6 see fromString function - IPAddress& operator=(const char *address); - IPAddress& operator=(const IPAddress& address); - - virtual size_t printTo(Print& p) const; - String toString(bool includeZone = false) const; - - IPType type() const { return _type; } - - // Espresif LwIP conversions - IPAddress(const ip_addr_t *addr); - void to_ip_addr_t(ip_addr_t* addr) const; - IPAddress& from_ip_addr_t(const ip_addr_t* addr); - esp_ip6_addr_type_t addr_type() const; - uint8_t zone() const { return (type() == IPv6)?_zone:0; } - size_t printTo(Print& p, bool includeZone) const; - - friend class UDP; - friend class Client; - friend class Server; + // Constructors + + // Default IPv4 + IPAddress(); + IPAddress(IPType ip_type); + IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); + IPAddress(uint8_t o1, uint8_t o2, uint8_t o3, uint8_t o4, uint8_t o5, uint8_t o6, uint8_t o7, uint8_t o8, uint8_t o9, uint8_t o10, uint8_t o11, uint8_t o12, uint8_t o13, uint8_t o14, uint8_t o15, uint8_t o16, uint8_t z = 0); + // IPv4; see implementation note + IPAddress(uint32_t address); + // Default IPv4 + IPAddress(const uint8_t* address); + IPAddress(IPType ip_type, const uint8_t* address, uint8_t z = 0); + // If IPv4 fails tries IPv6 see fromString function + IPAddress(const char* address); + IPAddress(const IPAddress& address); + + bool fromString(const char* address); + bool fromString(const String& address) { + return fromString(address.c_str()); + } + + // Overloaded cast operator to allow IPAddress objects to be used where a uint32_t is expected + // NOTE: IPv4 only; see implementation note + operator uint32_t() const { + return _type == IPv4 ? _address.dword[IPADDRESS_V4_DWORD_INDEX] : 0; + }; + + bool operator==(const IPAddress& addr) const; + bool operator!=(const IPAddress& addr) const { + return !(*this == addr); + }; + + // NOTE: IPv4 only; we don't know the length of the pointer + bool operator==(const uint8_t* addr) const; + + // Overloaded index operator to allow getting and setting individual octets of the address + uint8_t operator[](int index) const; + uint8_t& operator[](int index); + + // Overloaded copy operators to allow initialization of IPAddress objects from other types + // NOTE: IPv4 only + IPAddress& operator=(const uint8_t* address); + // NOTE: IPv4 only; see implementation note + IPAddress& operator=(uint32_t address); + // If IPv4 fails tries IPv6 see fromString function + IPAddress& operator=(const char* address); + IPAddress& operator=(const IPAddress& address); + + virtual size_t printTo(Print& p) const; + String toString(bool includeZone = false) const; + + IPType type() const { + return _type; + } + + // Espresif LwIP conversions + IPAddress(const ip_addr_t* addr); + void to_ip_addr_t(ip_addr_t* addr) const; + IPAddress& from_ip_addr_t(const ip_addr_t* addr); + esp_ip6_addr_type_t addr_type() const; + uint8_t zone() const { + return (type() == IPv6) ? _zone : 0; + } + size_t printTo(Print& p, bool includeZone) const; + + friend class UDP; + friend class Client; + friend class Server; protected: - bool fromString4(const char *address); - bool fromString6(const char *address); + bool fromString4(const char* address); + bool fromString6(const char* address); }; extern const IPAddress IN6ADDR_ANY; diff --git a/cores/esp32/MD5Builder.cpp b/cores/esp32/MD5Builder.cpp index f27b2dc7846..601565bfd5a 100644 --- a/cores/esp32/MD5Builder.cpp +++ b/cores/esp32/MD5Builder.cpp @@ -1,7 +1,7 @@ -/* +/* Copyright (c) 2015 Hristo Gochkov. All rights reserved. This file is part of the esp8266 core for Arduino environment. - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either @@ -21,87 +21,79 @@ #include #include -void MD5Builder::begin(void) -{ - memset(_buf, 0x00, ESP_ROM_MD5_DIGEST_LEN); - esp_rom_md5_init(&_ctx); +void MD5Builder::begin(void) { + memset(_buf, 0x00, ESP_ROM_MD5_DIGEST_LEN); + esp_rom_md5_init(&_ctx); } -void MD5Builder::add(const uint8_t * data, size_t len) -{ - esp_rom_md5_update(&_ctx, data, len); +void MD5Builder::add(const uint8_t* data, size_t len) { + esp_rom_md5_update(&_ctx, data, len); } -void MD5Builder::addHexString(const char * data) -{ - size_t len = strlen(data); - uint8_t * tmp = (uint8_t*)malloc(len/2); - if(tmp == NULL) { - return; - } - hex2bytes(tmp, len/2, data); - add(tmp, len/2); - free(tmp); +void MD5Builder::addHexString(const char* data) { + size_t len = strlen(data); + uint8_t* tmp = (uint8_t*)malloc(len / 2); + if (tmp == NULL) { + return; + } + hex2bytes(tmp, len / 2, data); + add(tmp, len / 2); + free(tmp); } -bool MD5Builder::addStream(Stream & stream, const size_t maxLen) -{ - const int buf_size = 512; - int maxLengthLeft = maxLen; - uint8_t * buf = (uint8_t*) malloc(buf_size); +bool MD5Builder::addStream(Stream& stream, const size_t maxLen) { + const int buf_size = 512; + int maxLengthLeft = maxLen; + uint8_t* buf = (uint8_t*)malloc(buf_size); + + if (!buf) { + return false; + } + + int bytesAvailable = stream.available(); + while ((bytesAvailable > 0) && (maxLengthLeft > 0)) { - if(!buf) { - return false; + // determine number of bytes to read + int readBytes = bytesAvailable; + if (readBytes > maxLengthLeft) { + readBytes = maxLengthLeft; // read only until max_len + } + if (readBytes > buf_size) { + readBytes = buf_size; // not read more the buffer can handle } - int bytesAvailable = stream.available(); - while((bytesAvailable > 0) && (maxLengthLeft > 0)) { - - // determine number of bytes to read - int readBytes = bytesAvailable; - if(readBytes > maxLengthLeft) { - readBytes = maxLengthLeft ; // read only until max_len - } - if(readBytes > buf_size) { - readBytes = buf_size; // not read more the buffer can handle - } - - // read data and check if we got something - int numBytesRead = stream.readBytes(buf, readBytes); - if(numBytesRead< 1) { - free(buf); - return false; - } - - // Update MD5 with buffer payload - esp_rom_md5_update(&_ctx, buf, numBytesRead); - - // update available number of bytes - maxLengthLeft -= numBytesRead; - bytesAvailable = stream.available(); + // read data and check if we got something + int numBytesRead = stream.readBytes(buf, readBytes); + if (numBytesRead < 1) { + free(buf); + return false; } - free(buf); - return true; + + // Update MD5 with buffer payload + esp_rom_md5_update(&_ctx, buf, numBytesRead); + + // update available number of bytes + maxLengthLeft -= numBytesRead; + bytesAvailable = stream.available(); + } + free(buf); + return true; } -void MD5Builder::calculate(void) -{ - esp_rom_md5_final(_buf, &_ctx); +void MD5Builder::calculate(void) { + esp_rom_md5_final(_buf, &_ctx); } -void MD5Builder::getBytes(uint8_t * output) -{ - memcpy(output, _buf, ESP_ROM_MD5_DIGEST_LEN); +void MD5Builder::getBytes(uint8_t* output) { + memcpy(output, _buf, ESP_ROM_MD5_DIGEST_LEN); } -void MD5Builder::getChars(char * output) -{ - bytes2hex(output, ESP_ROM_MD5_DIGEST_LEN*2+1, _buf, ESP_ROM_MD5_DIGEST_LEN); +void MD5Builder::getChars(char* output) { + bytes2hex(output, ESP_ROM_MD5_DIGEST_LEN * 2 + 1, _buf, ESP_ROM_MD5_DIGEST_LEN); } -String MD5Builder::toString(void) -{ - char out[(ESP_ROM_MD5_DIGEST_LEN * 2) + 1]; - getChars(out); - return String(out); +String MD5Builder::toString(void) { + char out[(ESP_ROM_MD5_DIGEST_LEN * 2) + 1]; + getChars(out); + return String(out); } diff --git a/cores/esp32/MD5Builder.h b/cores/esp32/MD5Builder.h index 70f23cebb05..8950eba9461 100644 --- a/cores/esp32/MD5Builder.h +++ b/cores/esp32/MD5Builder.h @@ -29,25 +29,24 @@ #include "HashBuilder.h" -class MD5Builder : public HashBuilder -{ +class MD5Builder : public HashBuilder { private: - md5_context_t _ctx; - uint8_t _buf[ESP_ROM_MD5_DIGEST_LEN]; + md5_context_t _ctx; + uint8_t _buf[ESP_ROM_MD5_DIGEST_LEN]; public: - void begin(void) override; + void begin(void) override; - using HashBuilder::add; - void add(const uint8_t * data, size_t len) override; + using HashBuilder::add; + void add(const uint8_t* data, size_t len) override; - using HashBuilder::addHexString; - void addHexString(const char * data) override; + using HashBuilder::addHexString; + void addHexString(const char* data) override; - bool addStream(Stream & stream, const size_t maxLen) override; - void calculate(void) override; - void getBytes(uint8_t * output) override; - void getChars(char * output) override; - String toString(void) override; + bool addStream(Stream& stream, const size_t maxLen) override; + void calculate(void) override; + void getBytes(uint8_t* output) override; + void getChars(char* output) override; + String toString(void) override; }; #endif diff --git a/cores/esp32/MacAddress.cpp b/cores/esp32/MacAddress.cpp index e1a23f5822f..393f636d471 100644 --- a/cores/esp32/MacAddress.cpp +++ b/cores/esp32/MacAddress.cpp @@ -3,231 +3,231 @@ #include //Default constructor, blank mac address. -MacAddress::MacAddress() : MacAddress(MAC6){} +MacAddress::MacAddress() + : MacAddress(MAC6) {} -MacAddress::MacAddress(MACType mac_type){ - _type = mac_type; - memset(_mac.bytes, 0, sizeof(_mac.bytes)); +MacAddress::MacAddress(MACType mac_type) { + _type = mac_type; + memset(_mac.bytes, 0, sizeof(_mac.bytes)); } MacAddress::MacAddress(MACType mac_type, uint64_t mac) { - _type = mac_type; - _mac.val = mac; + _type = mac_type; + _mac.val = mac; } MacAddress::MacAddress(MACType mac_type, const uint8_t *macbytearray) { - _type = mac_type; - memset(_mac.bytes, 0, sizeof(_mac.bytes)); - if(_type == MAC6) { - memcpy(_mac.bytes, macbytearray, 6); - } else { - memcpy(_mac.bytes, macbytearray, 8); - } + _type = mac_type; + memset(_mac.bytes, 0, sizeof(_mac.bytes)); + if (_type == MAC6) { + memcpy(_mac.bytes, macbytearray, 6); + } else { + memcpy(_mac.bytes, macbytearray, 8); + } } -MacAddress::MacAddress(const char *macstr){ - fromString(macstr); +MacAddress::MacAddress(const char *macstr) { + fromString(macstr); } -MacAddress::MacAddress(const String &macstr){ - fromString(macstr.c_str()); +MacAddress::MacAddress(const String &macstr) { + fromString(macstr.c_str()); } MacAddress::MacAddress(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6) { - _type = MAC6; - memset(_mac.bytes, 0, sizeof(_mac.bytes)); - _mac.bytes[0] = b1; - _mac.bytes[1] = b2; - _mac.bytes[2] = b3; - _mac.bytes[3] = b4; - _mac.bytes[4] = b5; - _mac.bytes[5] = b6; + _type = MAC6; + memset(_mac.bytes, 0, sizeof(_mac.bytes)); + _mac.bytes[0] = b1; + _mac.bytes[1] = b2; + _mac.bytes[2] = b3; + _mac.bytes[3] = b4; + _mac.bytes[4] = b5; + _mac.bytes[5] = b6; } MacAddress::MacAddress(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6, uint8_t b7, uint8_t b8) { - _type = MAC8; - _mac.bytes[0] = b1; - _mac.bytes[1] = b2; - _mac.bytes[2] = b3; - _mac.bytes[3] = b4; - _mac.bytes[4] = b5; - _mac.bytes[5] = b6; - _mac.bytes[6] = b7; - _mac.bytes[7] = b8; + _type = MAC8; + _mac.bytes[0] = b1; + _mac.bytes[1] = b2; + _mac.bytes[2] = b3; + _mac.bytes[3] = b4; + _mac.bytes[4] = b5; + _mac.bytes[5] = b6; + _mac.bytes[6] = b7; + _mac.bytes[7] = b8; } //Parse user entered string into MAC address bool MacAddress::fromString(const char *buf) { - if(strlen(buf) == 17) { - return fromString6(buf); - } else if(strlen(buf) == 23) { - return fromString8(buf); - } - return false; + if (strlen(buf) == 17) { + return fromString6(buf); + } else if (strlen(buf) == 23) { + return fromString8(buf); + } + return false; } //Parse user entered string into MAC address bool MacAddress::fromString6(const char *buf) { - char cs[18]; - char *token; - char *next; //Unused but required - int i; - - strncpy(cs, buf, sizeof(cs)); //strtok modifies the buffer: copy to working buffer. - - for(i = 0; i < 6; i++) { - token = strtok((i==0) ? cs : NULL, ":"); //Find first or next token - if(!token) { //No more tokens found - return false; - } - _mac.bytes[i] = strtol(token, &next, 16); + char cs[18]; + char *token; + char *next; //Unused but required + int i; + + strncpy(cs, buf, sizeof(cs)); //strtok modifies the buffer: copy to working buffer. + + for (i = 0; i < 6; i++) { + token = strtok((i == 0) ? cs : NULL, ":"); //Find first or next token + if (!token) { //No more tokens found + return false; } - _type = MAC6; - return true; + _mac.bytes[i] = strtol(token, &next, 16); + } + _type = MAC6; + return true; } bool MacAddress::fromString8(const char *buf) { - char cs[24]; - char *token; - char *next; //Unused but required - int i; - - strncpy(cs, buf, sizeof(cs)); //strtok modifies the buffer: copy to working buffer. - - for(i = 0; i < 8; i++) { - token = strtok((i==0) ? cs : NULL, ":"); //Find first or next token - if(!token) { //No more tokens found - return false; - } - _mac.bytes[i] = strtol(token, &next, 16); + char cs[24]; + char *token; + char *next; //Unused but required + int i; + + strncpy(cs, buf, sizeof(cs)); //strtok modifies the buffer: copy to working buffer. + + for (i = 0; i < 8; i++) { + token = strtok((i == 0) ? cs : NULL, ":"); //Find first or next token + if (!token) { //No more tokens found + return false; } - _type = MAC8; - return true; + _mac.bytes[i] = strtol(token, &next, 16); + } + _type = MAC8; + return true; } //Copy MAC into byte array void MacAddress::toBytes(uint8_t *buf) { - if(_type == MAC6) { - memcpy(buf, _mac.bytes, 6); - } else { - memcpy(buf, _mac.bytes, sizeof(_mac.bytes)); - } + if (_type == MAC6) { + memcpy(buf, _mac.bytes, 6); + } else { + memcpy(buf, _mac.bytes, sizeof(_mac.bytes)); + } } //Print MAC address into a C string. //MAC: Buffer must be at least 18 chars int MacAddress::toString(char *buf) { - if(_type == MAC6) { - return sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", - _mac.bytes[0], _mac.bytes[1], _mac.bytes[2], - _mac.bytes[3], _mac.bytes[4], _mac.bytes[5]); - } else { - return sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", - _mac.bytes[0], _mac.bytes[1], _mac.bytes[2], - _mac.bytes[3], _mac.bytes[4], _mac.bytes[5], - _mac.bytes[6], _mac.bytes[7]); - } + if (_type == MAC6) { + return sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", + _mac.bytes[0], _mac.bytes[1], _mac.bytes[2], + _mac.bytes[3], _mac.bytes[4], _mac.bytes[5]); + } else { + return sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", + _mac.bytes[0], _mac.bytes[1], _mac.bytes[2], + _mac.bytes[3], _mac.bytes[4], _mac.bytes[5], + _mac.bytes[6], _mac.bytes[7]); + } } String MacAddress::toString() const { - uint8_t bytes = (_type == MAC6) ? 18 : 24; - char buf[bytes]; - if(_type == MAC6) { - snprintf(buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X", - _mac.bytes[0], _mac.bytes[1], _mac.bytes[2], - _mac.bytes[3], _mac.bytes[4], _mac.bytes[5]); - } else { - snprintf(buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", - _mac.bytes[0], _mac.bytes[1], _mac.bytes[2], - _mac.bytes[3], _mac.bytes[4], _mac.bytes[5], - _mac.bytes[6], _mac.bytes[7]); - } - return String(buf); + uint8_t bytes = (_type == MAC6) ? 18 : 24; + char buf[bytes]; + if (_type == MAC6) { + snprintf(buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X", + _mac.bytes[0], _mac.bytes[1], _mac.bytes[2], + _mac.bytes[3], _mac.bytes[4], _mac.bytes[5]); + } else { + snprintf(buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", + _mac.bytes[0], _mac.bytes[1], _mac.bytes[2], + _mac.bytes[3], _mac.bytes[4], _mac.bytes[5], + _mac.bytes[6], _mac.bytes[7]); + } + return String(buf); } uint64_t MacAddress::Value() { - return _mac.val; + return _mac.val; } //Allow getting individual octets of the address. e.g. uint8_t b0 = ma[0]; uint8_t MacAddress::operator[](int index) const { - index = EnforceIndexBounds(index); - return _mac.bytes[index]; + index = EnforceIndexBounds(index); + return _mac.bytes[index]; } //Allow setting individual octets of the address. e.g. ma[2] = 255; -uint8_t& MacAddress::operator[](int index) { - index = EnforceIndexBounds(index); - return _mac.bytes[index]; +uint8_t &MacAddress::operator[](int index) { + index = EnforceIndexBounds(index); + return _mac.bytes[index]; } //Overloaded copy operator: init MacAddress object from byte array -MacAddress& MacAddress::operator=(const uint8_t *macbytearray) { - // 6-bytes MacAddress only - _type = MAC6; - memset(_mac.bytes, 0, sizeof(_mac.bytes)); - memcpy(_mac.bytes, macbytearray, 6); - return *this; +MacAddress &MacAddress::operator=(const uint8_t *macbytearray) { + // 6-bytes MacAddress only + _type = MAC6; + memset(_mac.bytes, 0, sizeof(_mac.bytes)); + memcpy(_mac.bytes, macbytearray, 6); + return *this; } //Overloaded copy operator: init MacAddress object from uint64_t -MacAddress& MacAddress::operator=(uint64_t macval) { - // 6-bytes MacAddress only - _type = MAC6; - _mac.val = macval; - return *this; +MacAddress &MacAddress::operator=(uint64_t macval) { + // 6-bytes MacAddress only + _type = MAC6; + _mac.val = macval; + return *this; } //Compare class to byte array bool MacAddress::operator==(const uint8_t *macbytearray) const { - return !memcmp(_mac.bytes, macbytearray, 6); + return !memcmp(_mac.bytes, macbytearray, 6); } //Allow comparing value of two classes -bool MacAddress::operator==(const MacAddress& mac2) const { - return _mac.val == mac2._mac.val; +bool MacAddress::operator==(const MacAddress &mac2) const { + return _mac.val == mac2._mac.val; } //Type converter object to uint64_t [same as .Value()] MacAddress::operator uint64_t() const { - return _mac.val; + return _mac.val; } //Type converter object to read only pointer to mac bytes. e.g. const uint8_t *ip_8 = ma; -MacAddress::operator const uint8_t*() const { - return _mac.bytes; +MacAddress::operator const uint8_t *() const { + return _mac.bytes; } //Type converter object to read only pointer to mac value. e.g. const uint32_t *ip_64 = ma; -MacAddress::operator const uint64_t*() const { - return &_mac.val; -} - -size_t MacAddress::printTo(Print& p) const -{ - uint8_t bytes = (_type == MAC6) ? 6 : 8; - size_t n = 0; - for(int i = 0; i < bytes; i++) { - if(i){ - n += p.print(':'); - } - n += p.printf("%02X", _mac.bytes[i]); +MacAddress::operator const uint64_t *() const { + return &_mac.val; +} + +size_t MacAddress::printTo(Print &p) const { + uint8_t bytes = (_type == MAC6) ? 6 : 8; + size_t n = 0; + for (int i = 0; i < bytes; i++) { + if (i) { + n += p.print(':'); } - return n; + n += p.printf("%02X", _mac.bytes[i]); + } + return n; } //Bounds checking int MacAddress::EnforceIndexBounds(int i) const { - if(i < 0) { - return 0; + if (i < 0) { + return 0; + } + if (_type == MAC6) { + if (i >= 6) { + return 5; } - if(_type == MAC6) { - if(i >= 6) { - return 5; - } - } else { - if(i >= 8) { - return 7; - } + } else { + if (i >= 8) { + return 7; } - return i; + } + return i; } diff --git a/cores/esp32/MacAddress.h b/cores/esp32/MacAddress.h index 1463bc487c5..1b4aa97920c 100644 --- a/cores/esp32/MacAddress.h +++ b/cores/esp32/MacAddress.h @@ -1,15 +1,15 @@ //----------------------------------------------------------------------------- // MacAddress.h - class to make it easier to handle BSSID and MAC addresses. -// +// // Copyright 2022 David McCurley // Modified by Espressif Systems 2024 // // Licensed under the Apache License, Version 2.0 (the "License"). // You may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -25,64 +25,68 @@ #include enum MACType { - MAC6, - MAC8 + MAC6, + MAC8 }; // A class to make it easier to handle and pass around MAC addresses, supporting both 6-byte and 8-byte MAC addresses. class MacAddress : public Printable { private: - union { - uint8_t bytes[8]; - uint64_t val; - } _mac; - MACType _type; + union { + uint8_t bytes[8]; + uint64_t val; + } _mac; + MACType _type; public: - //Default MAC6 - MacAddress(); + //Default MAC6 + MacAddress(); - MacAddress(MACType mac_type); - MacAddress(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6); - MacAddress(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6, uint8_t b7, uint8_t b8); + MacAddress(MACType mac_type); + MacAddress(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6); + MacAddress(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6, uint8_t b7, uint8_t b8); - MacAddress(MACType mac_type, uint64_t mac); - MacAddress(MACType mac_type, const uint8_t *macbytearray); + MacAddress(MACType mac_type, uint64_t mac); + MacAddress(MACType mac_type, const uint8_t *macbytearray); - //Default MAC6 - MacAddress(uint64_t mac) : MacAddress(MAC6, mac) {} - MacAddress(const uint8_t *macbytearray) : MacAddress(MAC6, macbytearray) {} + //Default MAC6 + MacAddress(uint64_t mac) + : MacAddress(MAC6, mac) {} + MacAddress(const uint8_t *macbytearray) + : MacAddress(MAC6, macbytearray) {} - MacAddress(const char *macstr); - MacAddress(const String &macstr); + MacAddress(const char *macstr); + MacAddress(const String &macstr); - virtual ~MacAddress() {} + virtual ~MacAddress() {} - bool fromString(const char *buf); - bool fromString(const String &macstr) { return fromString(macstr.c_str()); } + bool fromString(const char *buf); + bool fromString(const String &macstr) { + return fromString(macstr.c_str()); + } - void toBytes(uint8_t *buf); - int toString(char *buf); - String toString() const; - uint64_t Value(); + void toBytes(uint8_t *buf); + int toString(char *buf); + String toString() const; + uint64_t Value(); - uint8_t operator[](int index) const; - uint8_t& operator[](int index); + uint8_t operator[](int index) const; + uint8_t &operator[](int index); - //MAC6 only - MacAddress& operator=(const uint8_t *macbytearray); - MacAddress& operator=(uint64_t macval); + //MAC6 only + MacAddress &operator=(const uint8_t *macbytearray); + MacAddress &operator=(uint64_t macval); - bool operator==(const uint8_t *macbytearray) const; - bool operator==(const MacAddress& mac2) const; - operator uint64_t() const; - operator const uint8_t*() const; - operator const uint64_t*() const; + bool operator==(const uint8_t *macbytearray) const; + bool operator==(const MacAddress &mac2) const; + operator uint64_t() const; + operator const uint8_t *() const; + operator const uint64_t *() const; - virtual size_t printTo(Print& p) const; + virtual size_t printTo(Print &p) const; - // future use in Arduino Networking - /* + // future use in Arduino Networking + /* friend class EthernetClass; friend class UDP; friend class Client; @@ -92,11 +96,11 @@ class MacAddress : public Printable { */ protected: - bool fromString6(const char *buf); - bool fromString8(const char *buf); + bool fromString6(const char *buf); + bool fromString8(const char *buf); private: - int EnforceIndexBounds(int i) const; + int EnforceIndexBounds(int i) const; }; #endif diff --git a/cores/esp32/Print.cpp b/cores/esp32/Print.cpp index b1b9c0a1e88..53780d55abd 100644 --- a/cores/esp32/Print.cpp +++ b/cores/esp32/Print.cpp @@ -29,351 +29,317 @@ #include "Print.h" extern "C" { - #include "time.h" +#include "time.h" } // Public Methods ////////////////////////////////////////////////////////////// /* default implementation: may be overridden */ -size_t Print::write(const uint8_t *buffer, size_t size) -{ - size_t n = 0; - while(size--) { - n += write(*buffer++); - } - return n; -} - -size_t Print::vprintf(const char *format, va_list arg) -{ - char loc_buf[64]; - char * temp = loc_buf; - va_list copy; - va_copy(copy, arg); - int len = vsnprintf(temp, sizeof(loc_buf), format, copy); - va_end(copy); - if(len < 0) { - va_end(arg); - return 0; - } - if(len >= (int)sizeof(loc_buf)){ // comparation of same sign type for the compiler - temp = (char*) malloc(len+1); - if(temp == NULL) { - va_end(arg); - return 0; - } - len = vsnprintf(temp, len+1, format, arg); - } +size_t Print::write(const uint8_t *buffer, size_t size) { + size_t n = 0; + while (size--) { + n += write(*buffer++); + } + return n; +} + +size_t Print::vprintf(const char *format, va_list arg) { + char loc_buf[64]; + char *temp = loc_buf; + va_list copy; + va_copy(copy, arg); + int len = vsnprintf(temp, sizeof(loc_buf), format, copy); + va_end(copy); + if (len < 0) { va_end(arg); - len = write((uint8_t*)temp, len); - if(temp != loc_buf){ - free(temp); + return 0; + } + if (len >= (int)sizeof(loc_buf)) { // comparison of same sign type for the compiler + temp = (char *)malloc(len + 1); + if (temp == NULL) { + va_end(arg); + return 0; } - return len; + len = vsnprintf(temp, len + 1, format, arg); + } + va_end(arg); + len = write((uint8_t *)temp, len); + if (temp != loc_buf) { + free(temp); + } + return len; } -size_t Print::printf(const __FlashStringHelper *ifsh, ...) -{ - va_list arg; - va_start(arg, ifsh); - const char * format = (reinterpret_cast(ifsh)); - size_t ret = vprintf(format, arg); - va_end(arg); - return ret; +size_t Print::printf(const __FlashStringHelper *ifsh, ...) { + va_list arg; + va_start(arg, ifsh); + const char *format = (reinterpret_cast(ifsh)); + size_t ret = vprintf(format, arg); + va_end(arg); + return ret; } -size_t Print::printf(const char *format, ...) -{ - va_list arg; - va_start(arg, format); - size_t ret = vprintf(format, arg); - va_end(arg); - return ret; +size_t Print::printf(const char *format, ...) { + va_list arg; + va_start(arg, format); + size_t ret = vprintf(format, arg); + va_end(arg); + return ret; } -size_t Print::print(const String &s) -{ - return write(s.c_str(), s.length()); +size_t Print::print(const String &s) { + return write(s.c_str(), s.length()); } -size_t Print::print(const char str[]) -{ - return write(str); +size_t Print::print(const char str[]) { + return write(str); } -size_t Print::print(char c) -{ - return write(c); +size_t Print::print(char c) { + return write(c); } -size_t Print::print(unsigned char b, int base) -{ - return print((unsigned long) b, base); +size_t Print::print(unsigned char b, int base) { + return print((unsigned long)b, base); } -size_t Print::print(int n, int base) -{ - return print((long) n, base); +size_t Print::print(int n, int base) { + return print((long)n, base); } -size_t Print::print(unsigned int n, int base) -{ - return print((unsigned long) n, base); +size_t Print::print(unsigned int n, int base) { + return print((unsigned long)n, base); } -size_t Print::print(long n, int base) -{ - int t = 0; - if (base == 10 && n < 0) { - t = print('-'); - n = -n; - } - return printNumber(static_cast(n), base) + t; +size_t Print::print(long n, int base) { + int t = 0; + if (base == 10 && n < 0) { + t = print('-'); + n = -n; + } + return printNumber(static_cast(n), base) + t; } -size_t Print::print(unsigned long n, int base) -{ - if(base == 0) { - return write(n); - } else { - return printNumber(n, base); - } +size_t Print::print(unsigned long n, int base) { + if (base == 0) { + return write(n); + } else { + return printNumber(n, base); + } } -size_t Print::print(long long n, int base) -{ - int t = 0; - if (base == 10 && n < 0) { - t = print('-'); - n = -n; - } - return printNumber(static_cast(n), base) + t; +size_t Print::print(long long n, int base) { + int t = 0; + if (base == 10 && n < 0) { + t = print('-'); + n = -n; + } + return printNumber(static_cast(n), base) + t; } -size_t Print::print(unsigned long long n, int base) -{ - if (base == 0) { - return write(n); - } else { - return printNumber(n, base); - } +size_t Print::print(unsigned long long n, int base) { + if (base == 0) { + return write(n); + } else { + return printNumber(n, base); + } } -size_t Print::print(double n, int digits) -{ - return printFloat(n, digits); +size_t Print::print(double n, int digits) { + return printFloat(n, digits); } -size_t Print::print(const Printable& x) -{ - return x.printTo(*this); +size_t Print::print(const Printable &x) { + return x.printTo(*this); } -size_t Print::print(struct tm * timeinfo, const char * format) -{ - const char * f = format; - if(!f){ - f = "%c"; - } - char buf[64]; - size_t written = strftime(buf, 64, f, timeinfo); - if(written == 0){ - return written; - } - return print(buf); +size_t Print::print(struct tm *timeinfo, const char *format) { + const char *f = format; + if (!f) { + f = "%c"; + } + char buf[64]; + size_t written = strftime(buf, 64, f, timeinfo); + if (written == 0) { + return written; + } + return print(buf); } -size_t Print::println(void) -{ - return print("\r\n"); +size_t Print::println(void) { + return print("\r\n"); } -size_t Print::println(const String &s) -{ - size_t n = print(s); - n += println(); - return n; +size_t Print::println(const String &s) { + size_t n = print(s); + n += println(); + return n; } -size_t Print::println(const char c[]) -{ - size_t n = print(c); - n += println(); - return n; +size_t Print::println(const char c[]) { + size_t n = print(c); + n += println(); + return n; } -size_t Print::println(char c) -{ - size_t n = print(c); - n += println(); - return n; +size_t Print::println(char c) { + size_t n = print(c); + n += println(); + return n; } -size_t Print::println(unsigned char b, int base) -{ - size_t n = print(b, base); - n += println(); - return n; +size_t Print::println(unsigned char b, int base) { + size_t n = print(b, base); + n += println(); + return n; } -size_t Print::println(int num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; +size_t Print::println(int num, int base) { + size_t n = print(num, base); + n += println(); + return n; } -size_t Print::println(unsigned int num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; +size_t Print::println(unsigned int num, int base) { + size_t n = print(num, base); + n += println(); + return n; } -size_t Print::println(long num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; +size_t Print::println(long num, int base) { + size_t n = print(num, base); + n += println(); + return n; } -size_t Print::println(unsigned long num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; +size_t Print::println(unsigned long num, int base) { + size_t n = print(num, base); + n += println(); + return n; } -size_t Print::println(long long num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; +size_t Print::println(long long num, int base) { + size_t n = print(num, base); + n += println(); + return n; } -size_t Print::println(unsigned long long num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; +size_t Print::println(unsigned long long num, int base) { + size_t n = print(num, base); + n += println(); + return n; } -size_t Print::println(double num, int digits) -{ - size_t n = print(num, digits); - n += println(); - return n; +size_t Print::println(double num, int digits) { + size_t n = print(num, digits); + n += println(); + return n; } -size_t Print::println(const Printable& x) -{ - size_t n = print(x); - n += println(); - return n; +size_t Print::println(const Printable &x) { + size_t n = print(x); + n += println(); + return n; } -size_t Print::println(struct tm * timeinfo, const char * format) -{ - size_t n = print(timeinfo, format); - n += println(); - return n; +size_t Print::println(struct tm *timeinfo, const char *format) { + size_t n = print(timeinfo, format); + n += println(); + return n; } // Private Methods ///////////////////////////////////////////////////////////// -size_t Print::printNumber(unsigned long n, uint8_t base) -{ - char buf[8 * sizeof(n) + 1]; // Assumes 8-bit chars plus zero byte. - char *str = &buf[sizeof(buf) - 1]; +size_t Print::printNumber(unsigned long n, uint8_t base) { + char buf[8 * sizeof(n) + 1]; // Assumes 8-bit chars plus zero byte. + char *str = &buf[sizeof(buf) - 1]; - *str = '\0'; + *str = '\0'; - // prevent crash if called with base == 1 - if(base < 2) { - base = 10; - } + // prevent crash if called with base == 1 + if (base < 2) { + base = 10; + } - do { - char c = n % base; - n /= base; + do { + char c = n % base; + n /= base; - *--str = c < 10 ? c + '0' : c + 'A' - 10; - } while (n); + *--str = c < 10 ? c + '0' : c + 'A' - 10; + } while (n); - return write(str); + return write(str); } -size_t Print::printNumber(unsigned long long n, uint8_t base) -{ - char buf[8 * sizeof(n) + 1]; // Assumes 8-bit chars plus zero byte. - char* str = &buf[sizeof(buf) - 1]; +size_t Print::printNumber(unsigned long long n, uint8_t base) { + char buf[8 * sizeof(n) + 1]; // Assumes 8-bit chars plus zero byte. + char *str = &buf[sizeof(buf) - 1]; - *str = '\0'; + *str = '\0'; - // prevent crash if called with base == 1 - if (base < 2) { - base = 10; - } + // prevent crash if called with base == 1 + if (base < 2) { + base = 10; + } - do { - auto m = n; - n /= base; - char c = m - base * n; + do { + auto m = n; + n /= base; + char c = m - base * n; - *--str = c < 10 ? c + '0' : c + 'A' - 10; - } while (n); + *--str = c < 10 ? c + '0' : c + 'A' - 10; + } while (n); - return write(str); + return write(str); } -size_t Print::printFloat(double number, uint8_t digits) -{ - size_t n = 0; +size_t Print::printFloat(double number, uint8_t digits) { + size_t n = 0; - if(isnan(number)) { - return print("nan"); - } - if(isinf(number)) { - return print("inf"); - } - if(number > 4294967040.0) { - return print("ovf"); // constant determined empirically - } - if(number < -4294967040.0) { - return print("ovf"); // constant determined empirically - } + if (isnan(number)) { + return print("nan"); + } + if (isinf(number)) { + return print("inf"); + } + if (number > 4294967040.0) { + return print("ovf"); // constant determined empirically + } + if (number < -4294967040.0) { + return print("ovf"); // constant determined empirically + } - // Handle negative numbers - if(number < 0.0) { - n += print('-'); - number = -number; - } + // Handle negative numbers + if (number < 0.0) { + n += print('-'); + number = -number; + } - // Round correctly so that print(1.999, 2) prints as "2.00" - double rounding = 0.5; - for(uint8_t i = 0; i < digits; ++i) { - rounding /= 10.0; - } + // Round correctly so that print(1.999, 2) prints as "2.00" + double rounding = 0.5; + for (uint8_t i = 0; i < digits; ++i) { + rounding /= 10.0; + } - number += rounding; + number += rounding; - // Extract the integer part of the number and print it - unsigned long int_part = (unsigned long) number; - double remainder = number - (double) int_part; - n += print(int_part); + // Extract the integer part of the number and print it + unsigned long int_part = (unsigned long)number; + double remainder = number - (double)int_part; + n += print(int_part); - // Print the decimal point, but only if there are digits beyond - if(digits > 0) { - n += print("."); - } + // Print the decimal point, but only if there are digits beyond + if (digits > 0) { + n += print("."); + } - // Extract digits from the remainder one at a time - while(digits-- > 0) { - remainder *= 10.0; - int toPrint = int(remainder); - n += print(toPrint); - remainder -= toPrint; - } + // Extract digits from the remainder one at a time + while (digits-- > 0) { + remainder *= 10.0; + int toPrint = int(remainder); + n += print(toPrint); + remainder -= toPrint; + } - return n; + return n; } diff --git a/cores/esp32/Print.h b/cores/esp32/Print.h index a543e8c1d0f..056cbb6b4b4 100644 --- a/cores/esp32/Print.h +++ b/cores/esp32/Print.h @@ -32,89 +32,88 @@ #define OCT 8 #define BIN 2 -class Print -{ +class Print { private: - int write_error; - size_t printNumber(unsigned long, uint8_t); - size_t printNumber(unsigned long long, uint8_t); - size_t printFloat(double, uint8_t); + int write_error; + size_t printNumber(unsigned long, uint8_t); + size_t printNumber(unsigned long long, uint8_t); + size_t printFloat(double, uint8_t); protected: - void setWriteError(int err = 1) - { - write_error = err; - } + void setWriteError(int err = 1) { + write_error = err; + } public: - Print() : - write_error(0) - { - } - virtual ~Print() {} - int getWriteError() - { - return write_error; - } - void clearWriteError() - { - setWriteError(0); - } + Print() + : write_error(0) { + } + virtual ~Print() {} + int getWriteError() { + return write_error; + } + void clearWriteError() { + setWriteError(0); + } - virtual size_t write(uint8_t) = 0; - size_t write(const char *str) - { - if(str == NULL) { - return 0; - } - return write((const uint8_t *) str, strlen(str)); - } - virtual size_t write(const uint8_t *buffer, size_t size); - size_t write(const char *buffer, size_t size) - { - return write((const uint8_t *) buffer, size); + virtual size_t write(uint8_t) = 0; + size_t write(const char *str) { + if (str == NULL) { + return 0; } + return write((const uint8_t *)str, strlen(str)); + } + virtual size_t write(const uint8_t *buffer, size_t size); + size_t write(const char *buffer, size_t size) { + return write((const uint8_t *)buffer, size); + } + + size_t vprintf(const char *format, va_list arg); - size_t vprintf(const char *format, va_list arg); + size_t printf(const char *format, ...) __attribute__((format(printf, 2, 3))); + size_t printf(const __FlashStringHelper *ifsh, ...); - size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3))); - size_t printf(const __FlashStringHelper *ifsh, ...); + // add availableForWrite to make compatible with Arduino Print.h + // default to zero, meaning "a single write may block" + // should be overridden by subclasses with buffering + virtual int availableForWrite() { + return 0; + } + size_t print(const __FlashStringHelper *ifsh) { + return print(reinterpret_cast(ifsh)); + } + size_t print(const String &); + size_t print(const char[]); + size_t print(char); + size_t print(unsigned char, int = DEC); + size_t print(int, int = DEC); + size_t print(unsigned int, int = DEC); + size_t print(long, int = DEC); + size_t print(unsigned long, int = DEC); + size_t print(long long, int = DEC); + size_t print(unsigned long long, int = DEC); + size_t print(double, int = 2); + size_t print(const Printable &); + size_t print(struct tm *timeinfo, const char *format = NULL); - // add availableForWrite to make compatible with Arduino Print.h - // default to zero, meaning "a single write may block" - // should be overriden by subclasses with buffering - virtual int availableForWrite() { return 0; } - size_t print(const __FlashStringHelper *ifsh) { return print(reinterpret_cast(ifsh)); } - size_t print(const String &); - size_t print(const char[]); - size_t print(char); - size_t print(unsigned char, int = DEC); - size_t print(int, int = DEC); - size_t print(unsigned int, int = DEC); - size_t print(long, int = DEC); - size_t print(unsigned long, int = DEC); - size_t print(long long, int = DEC); - size_t print(unsigned long long, int = DEC); - size_t print(double, int = 2); - size_t print(const Printable&); - size_t print(struct tm * timeinfo, const char * format = NULL); + size_t println(const __FlashStringHelper *ifsh) { + return println(reinterpret_cast(ifsh)); + } + size_t println(const String &s); + size_t println(const char[]); + size_t println(char); + size_t println(unsigned char, int = DEC); + size_t println(int, int = DEC); + size_t println(unsigned int, int = DEC); + size_t println(long, int = DEC); + size_t println(unsigned long, int = DEC); + size_t println(long long, int = DEC); + size_t println(unsigned long long, int = DEC); + size_t println(double, int = 2); + size_t println(const Printable &); + size_t println(struct tm *timeinfo, const char *format = NULL); + size_t println(void); - size_t println(const __FlashStringHelper *ifsh) { return println(reinterpret_cast(ifsh)); } - size_t println(const String &s); - size_t println(const char[]); - size_t println(char); - size_t println(unsigned char, int = DEC); - size_t println(int, int = DEC); - size_t println(unsigned int, int = DEC); - size_t println(long, int = DEC); - size_t println(unsigned long, int = DEC); - size_t println(long long, int = DEC); - size_t println(unsigned long long, int = DEC); - size_t println(double, int = 2); - size_t println(const Printable&); - size_t println(struct tm * timeinfo, const char * format = NULL); - size_t println(void); - - virtual void flush() { /* Empty implementation for backward compatibility */ } - + virtual void flush() { /* Empty implementation for backward compatibility */ + } }; #endif diff --git a/cores/esp32/Printable.h b/cores/esp32/Printable.h index aa4e62f8f11..ae1bde9fb54 100644 --- a/cores/esp32/Printable.h +++ b/cores/esp32/Printable.h @@ -30,12 +30,10 @@ class Print; Print::print and Print::println methods. */ -class Printable -{ +class Printable { public: - virtual ~Printable() {} - virtual size_t printTo(Print& p) const = 0; + virtual ~Printable() {} + virtual size_t printTo(Print& p) const = 0; }; #endif - diff --git a/cores/esp32/SHA1Builder.cpp b/cores/esp32/SHA1Builder.cpp index 0f67d1086fd..84e28bdb23e 100644 --- a/cores/esp32/SHA1Builder.cpp +++ b/cores/esp32/SHA1Builder.cpp @@ -26,342 +26,327 @@ // 32-bit integer manipulation macros (big endian) #ifndef GET_UINT32_BE -#define GET_UINT32_BE(n,b,i) \ -{ \ - (n) = ((uint32_t) (b)[(i) ] << 24) \ - | ((uint32_t) (b)[(i) + 1] << 16) \ - | ((uint32_t) (b)[(i) + 2] << 8) \ - | ((uint32_t) (b)[(i) + 3] ); \ -} +#define GET_UINT32_BE(n, b, i) \ + { \ + (n) = ((uint32_t)(b)[(i)] << 24) \ + | ((uint32_t)(b)[(i) + 1] << 16) \ + | ((uint32_t)(b)[(i) + 2] << 8) \ + | ((uint32_t)(b)[(i) + 3]); \ + } #endif #ifndef PUT_UINT32_BE -#define PUT_UINT32_BE(n,b,i) \ -{ \ - (b)[(i) ] = (uint8_t) ((n) >> 24); \ - (b)[(i) + 1] = (uint8_t) ((n) >> 16); \ - (b)[(i) + 2] = (uint8_t) ((n) >> 8); \ - (b)[(i) + 3] = (uint8_t) ((n) ); \ -} +#define PUT_UINT32_BE(n, b, i) \ + { \ + (b)[(i)] = (uint8_t)((n) >> 24); \ + (b)[(i) + 1] = (uint8_t)((n) >> 16); \ + (b)[(i) + 2] = (uint8_t)((n) >> 8); \ + (b)[(i) + 3] = (uint8_t)((n)); \ + } #endif // Constants -static const uint8_t sha1_padding[64] = -{ - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +static const uint8_t sha1_padding[64] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Private methods -void SHA1Builder::process(const uint8_t* data) -{ - uint32_t temp, W[16], A, B, C, D, E; - - GET_UINT32_BE(W[ 0], data, 0); - GET_UINT32_BE(W[ 1], data, 4); - GET_UINT32_BE(W[ 2], data, 8); - GET_UINT32_BE(W[ 3], data, 12); - GET_UINT32_BE(W[ 4], data, 16); - GET_UINT32_BE(W[ 5], data, 20); - GET_UINT32_BE(W[ 6], data, 24); - GET_UINT32_BE(W[ 7], data, 28); - GET_UINT32_BE(W[ 8], data, 32); - GET_UINT32_BE(W[ 9], data, 36); - GET_UINT32_BE(W[10], data, 40); - GET_UINT32_BE(W[11], data, 44); - GET_UINT32_BE(W[12], data, 48); - GET_UINT32_BE(W[13], data, 52); - GET_UINT32_BE(W[14], data, 56); - GET_UINT32_BE(W[15], data, 60); - -#define sha1_S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) - -#define sha1_R(t) \ -( \ - temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ \ - W[(t - 14) & 0x0F] ^ W[ t & 0x0F], \ - (W[t & 0x0F] = sha1_S(temp,1)) \ -) - -#define sha1_P(a,b,c,d,e,x) \ -{ \ - e += sha1_S(a,5) + sha1_F(b,c,d) + sha1_K + x; b = sha1_S(b,30); \ -} - - A = state[0]; - B = state[1]; - C = state[2]; - D = state[3]; - E = state[4]; - -#define sha1_F(x,y,z) (z ^ (x & (y ^ z))) +void SHA1Builder::process(const uint8_t* data) { + uint32_t temp, W[16], A, B, C, D, E; + + GET_UINT32_BE(W[0], data, 0); + GET_UINT32_BE(W[1], data, 4); + GET_UINT32_BE(W[2], data, 8); + GET_UINT32_BE(W[3], data, 12); + GET_UINT32_BE(W[4], data, 16); + GET_UINT32_BE(W[5], data, 20); + GET_UINT32_BE(W[6], data, 24); + GET_UINT32_BE(W[7], data, 28); + GET_UINT32_BE(W[8], data, 32); + GET_UINT32_BE(W[9], data, 36); + GET_UINT32_BE(W[10], data, 40); + GET_UINT32_BE(W[11], data, 44); + GET_UINT32_BE(W[12], data, 48); + GET_UINT32_BE(W[13], data, 52); + GET_UINT32_BE(W[14], data, 56); + GET_UINT32_BE(W[15], data, 60); + +#define sha1_S(x, n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) + +#define sha1_R(t) \ + ( \ + temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ W[(t - 14) & 0x0F] ^ W[t & 0x0F], \ + (W[t & 0x0F] = sha1_S(temp, 1))) + +#define sha1_P(a, b, c, d, e, x) \ + { \ + e += sha1_S(a, 5) + sha1_F(b, c, d) + sha1_K + x; \ + b = sha1_S(b, 30); \ + } + + A = state[0]; + B = state[1]; + C = state[2]; + D = state[3]; + E = state[4]; + +#define sha1_F(x, y, z) (z ^ (x & (y ^ z))) #define sha1_K 0x5A827999 - sha1_P(A, B, C, D, E, W[0]); - sha1_P(E, A, B, C, D, W[1]); - sha1_P(D, E, A, B, C, W[2]); - sha1_P(C, D, E, A, B, W[3]); - sha1_P(B, C, D, E, A, W[4]); - sha1_P(A, B, C, D, E, W[5]); - sha1_P(E, A, B, C, D, W[6]); - sha1_P(D, E, A, B, C, W[7]); - sha1_P(C, D, E, A, B, W[8]); - sha1_P(B, C, D, E, A, W[9]); - sha1_P(A, B, C, D, E, W[10]); - sha1_P(E, A, B, C, D, W[11]); - sha1_P(D, E, A, B, C, W[12]); - sha1_P(C, D, E, A, B, W[13]); - sha1_P(B, C, D, E, A, W[14]); - sha1_P(A, B, C, D, E, W[15]); - sha1_P(E, A, B, C, D, sha1_R(16)); - sha1_P(D, E, A, B, C, sha1_R(17)); - sha1_P(C, D, E, A, B, sha1_R(18)); - sha1_P(B, C, D, E, A, sha1_R(19)); + sha1_P(A, B, C, D, E, W[0]); + sha1_P(E, A, B, C, D, W[1]); + sha1_P(D, E, A, B, C, W[2]); + sha1_P(C, D, E, A, B, W[3]); + sha1_P(B, C, D, E, A, W[4]); + sha1_P(A, B, C, D, E, W[5]); + sha1_P(E, A, B, C, D, W[6]); + sha1_P(D, E, A, B, C, W[7]); + sha1_P(C, D, E, A, B, W[8]); + sha1_P(B, C, D, E, A, W[9]); + sha1_P(A, B, C, D, E, W[10]); + sha1_P(E, A, B, C, D, W[11]); + sha1_P(D, E, A, B, C, W[12]); + sha1_P(C, D, E, A, B, W[13]); + sha1_P(B, C, D, E, A, W[14]); + sha1_P(A, B, C, D, E, W[15]); + sha1_P(E, A, B, C, D, sha1_R(16)); + sha1_P(D, E, A, B, C, sha1_R(17)); + sha1_P(C, D, E, A, B, sha1_R(18)); + sha1_P(B, C, D, E, A, sha1_R(19)); #undef sha1_K #undef sha1_F -#define sha1_F(x,y,z) (x ^ y ^ z) +#define sha1_F(x, y, z) (x ^ y ^ z) #define sha1_K 0x6ED9EBA1 - sha1_P(A, B, C, D, E, sha1_R(20)); - sha1_P(E, A, B, C, D, sha1_R(21)); - sha1_P(D, E, A, B, C, sha1_R(22)); - sha1_P(C, D, E, A, B, sha1_R(23)); - sha1_P(B, C, D, E, A, sha1_R(24)); - sha1_P(A, B, C, D, E, sha1_R(25)); - sha1_P(E, A, B, C, D, sha1_R(26)); - sha1_P(D, E, A, B, C, sha1_R(27)); - sha1_P(C, D, E, A, B, sha1_R(28)); - sha1_P(B, C, D, E, A, sha1_R(29)); - sha1_P(A, B, C, D, E, sha1_R(30)); - sha1_P(E, A, B, C, D, sha1_R(31)); - sha1_P(D, E, A, B, C, sha1_R(32)); - sha1_P(C, D, E, A, B, sha1_R(33)); - sha1_P(B, C, D, E, A, sha1_R(34)); - sha1_P(A, B, C, D, E, sha1_R(35)); - sha1_P(E, A, B, C, D, sha1_R(36)); - sha1_P(D, E, A, B, C, sha1_R(37)); - sha1_P(C, D, E, A, B, sha1_R(38)); - sha1_P(B, C, D, E, A, sha1_R(39)); + sha1_P(A, B, C, D, E, sha1_R(20)); + sha1_P(E, A, B, C, D, sha1_R(21)); + sha1_P(D, E, A, B, C, sha1_R(22)); + sha1_P(C, D, E, A, B, sha1_R(23)); + sha1_P(B, C, D, E, A, sha1_R(24)); + sha1_P(A, B, C, D, E, sha1_R(25)); + sha1_P(E, A, B, C, D, sha1_R(26)); + sha1_P(D, E, A, B, C, sha1_R(27)); + sha1_P(C, D, E, A, B, sha1_R(28)); + sha1_P(B, C, D, E, A, sha1_R(29)); + sha1_P(A, B, C, D, E, sha1_R(30)); + sha1_P(E, A, B, C, D, sha1_R(31)); + sha1_P(D, E, A, B, C, sha1_R(32)); + sha1_P(C, D, E, A, B, sha1_R(33)); + sha1_P(B, C, D, E, A, sha1_R(34)); + sha1_P(A, B, C, D, E, sha1_R(35)); + sha1_P(E, A, B, C, D, sha1_R(36)); + sha1_P(D, E, A, B, C, sha1_R(37)); + sha1_P(C, D, E, A, B, sha1_R(38)); + sha1_P(B, C, D, E, A, sha1_R(39)); #undef sha1_K #undef sha1_F -#define sha1_F(x,y,z) ((x & y) | (z & (x | y))) +#define sha1_F(x, y, z) ((x & y) | (z & (x | y))) #define sha1_K 0x8F1BBCDC - sha1_P(A, B, C, D, E, sha1_R(40)); - sha1_P(E, A, B, C, D, sha1_R(41)); - sha1_P(D, E, A, B, C, sha1_R(42)); - sha1_P(C, D, E, A, B, sha1_R(43)); - sha1_P(B, C, D, E, A, sha1_R(44)); - sha1_P(A, B, C, D, E, sha1_R(45)); - sha1_P(E, A, B, C, D, sha1_R(46)); - sha1_P(D, E, A, B, C, sha1_R(47)); - sha1_P(C, D, E, A, B, sha1_R(48)); - sha1_P(B, C, D, E, A, sha1_R(49)); - sha1_P(A, B, C, D, E, sha1_R(50)); - sha1_P(E, A, B, C, D, sha1_R(51)); - sha1_P(D, E, A, B, C, sha1_R(52)); - sha1_P(C, D, E, A, B, sha1_R(53)); - sha1_P(B, C, D, E, A, sha1_R(54)); - sha1_P(A, B, C, D, E, sha1_R(55)); - sha1_P(E, A, B, C, D, sha1_R(56)); - sha1_P(D, E, A, B, C, sha1_R(57)); - sha1_P(C, D, E, A, B, sha1_R(58)); - sha1_P(B, C, D, E, A, sha1_R(59)); + sha1_P(A, B, C, D, E, sha1_R(40)); + sha1_P(E, A, B, C, D, sha1_R(41)); + sha1_P(D, E, A, B, C, sha1_R(42)); + sha1_P(C, D, E, A, B, sha1_R(43)); + sha1_P(B, C, D, E, A, sha1_R(44)); + sha1_P(A, B, C, D, E, sha1_R(45)); + sha1_P(E, A, B, C, D, sha1_R(46)); + sha1_P(D, E, A, B, C, sha1_R(47)); + sha1_P(C, D, E, A, B, sha1_R(48)); + sha1_P(B, C, D, E, A, sha1_R(49)); + sha1_P(A, B, C, D, E, sha1_R(50)); + sha1_P(E, A, B, C, D, sha1_R(51)); + sha1_P(D, E, A, B, C, sha1_R(52)); + sha1_P(C, D, E, A, B, sha1_R(53)); + sha1_P(B, C, D, E, A, sha1_R(54)); + sha1_P(A, B, C, D, E, sha1_R(55)); + sha1_P(E, A, B, C, D, sha1_R(56)); + sha1_P(D, E, A, B, C, sha1_R(57)); + sha1_P(C, D, E, A, B, sha1_R(58)); + sha1_P(B, C, D, E, A, sha1_R(59)); #undef sha1_K #undef sha1_F -#define sha1_F(x,y,z) (x ^ y ^ z) +#define sha1_F(x, y, z) (x ^ y ^ z) #define sha1_K 0xCA62C1D6 - sha1_P(A, B, C, D, E, sha1_R(60)); - sha1_P(E, A, B, C, D, sha1_R(61)); - sha1_P(D, E, A, B, C, sha1_R(62)); - sha1_P(C, D, E, A, B, sha1_R(63)); - sha1_P(B, C, D, E, A, sha1_R(64)); - sha1_P(A, B, C, D, E, sha1_R(65)); - sha1_P(E, A, B, C, D, sha1_R(66)); - sha1_P(D, E, A, B, C, sha1_R(67)); - sha1_P(C, D, E, A, B, sha1_R(68)); - sha1_P(B, C, D, E, A, sha1_R(69)); - sha1_P(A, B, C, D, E, sha1_R(70)); - sha1_P(E, A, B, C, D, sha1_R(71)); - sha1_P(D, E, A, B, C, sha1_R(72)); - sha1_P(C, D, E, A, B, sha1_R(73)); - sha1_P(B, C, D, E, A, sha1_R(74)); - sha1_P(A, B, C, D, E, sha1_R(75)); - sha1_P(E, A, B, C, D, sha1_R(76)); - sha1_P(D, E, A, B, C, sha1_R(77)); - sha1_P(C, D, E, A, B, sha1_R(78)); - sha1_P(B, C, D, E, A, sha1_R(79)); + sha1_P(A, B, C, D, E, sha1_R(60)); + sha1_P(E, A, B, C, D, sha1_R(61)); + sha1_P(D, E, A, B, C, sha1_R(62)); + sha1_P(C, D, E, A, B, sha1_R(63)); + sha1_P(B, C, D, E, A, sha1_R(64)); + sha1_P(A, B, C, D, E, sha1_R(65)); + sha1_P(E, A, B, C, D, sha1_R(66)); + sha1_P(D, E, A, B, C, sha1_R(67)); + sha1_P(C, D, E, A, B, sha1_R(68)); + sha1_P(B, C, D, E, A, sha1_R(69)); + sha1_P(A, B, C, D, E, sha1_R(70)); + sha1_P(E, A, B, C, D, sha1_R(71)); + sha1_P(D, E, A, B, C, sha1_R(72)); + sha1_P(C, D, E, A, B, sha1_R(73)); + sha1_P(B, C, D, E, A, sha1_R(74)); + sha1_P(A, B, C, D, E, sha1_R(75)); + sha1_P(E, A, B, C, D, sha1_R(76)); + sha1_P(D, E, A, B, C, sha1_R(77)); + sha1_P(C, D, E, A, B, sha1_R(78)); + sha1_P(B, C, D, E, A, sha1_R(79)); #undef sha1_K #undef sha1_F - state[0] += A; - state[1] += B; - state[2] += C; - state[3] += D; - state[4] += E; + state[0] += A; + state[1] += B; + state[2] += C; + state[3] += D; + state[4] += E; } // Public methods -void SHA1Builder::begin(void) -{ - total[0] = 0; - total[1] = 0; +void SHA1Builder::begin(void) { + total[0] = 0; + total[1] = 0; - state[0] = 0x67452301; - state[1] = 0xEFCDAB89; - state[2] = 0x98BADCFE; - state[3] = 0x10325476; - state[4] = 0xC3D2E1F0; + state[0] = 0x67452301; + state[1] = 0xEFCDAB89; + state[2] = 0x98BADCFE; + state[3] = 0x10325476; + state[4] = 0xC3D2E1F0; - memset(buffer, 0x00, sizeof(buffer)); - memset(hash, 0x00, sizeof(hash)); + memset(buffer, 0x00, sizeof(buffer)); + memset(hash, 0x00, sizeof(hash)); } -void SHA1Builder::add(const uint8_t* data, size_t len) -{ - size_t fill; - uint32_t left; +void SHA1Builder::add(const uint8_t* data, size_t len) { + size_t fill; + uint32_t left; + + if (len == 0) { + return; + } + + left = total[0] & 0x3F; + fill = 64 - left; + + total[0] += (uint32_t)len; + total[0] &= 0xFFFFFFFF; + + if (total[0] < (uint32_t)len) { + total[1]++; + } + + if (left && len >= fill) { + memcpy((void*)(buffer + left), data, fill); + process(buffer); + data += fill; + len -= fill; + left = 0; + } + + while (len >= 64) { + process(data); + data += 64; + len -= 64; + } + + if (len > 0) { + memcpy((void*)(buffer + left), data, len); + } +} - if(len == 0) - { - return; - } +void SHA1Builder::addHexString(const char* data) { + uint16_t len = strlen(data); + uint8_t* tmp = (uint8_t*)malloc(len / 2); + if (tmp == NULL) { + return; + } + hex2bytes(tmp, len / 2, data); + add(tmp, len / 2); + free(tmp); +} - left = total[0] & 0x3F; - fill = 64 - left; +bool SHA1Builder::addStream(Stream& stream, const size_t maxLen) { + const int buf_size = 512; + int maxLengthLeft = maxLen; + uint8_t* buf = (uint8_t*)malloc(buf_size); - total[0] += (uint32_t) len; - total[0] &= 0xFFFFFFFF; + if (!buf) { + return false; + } - if(total[0] < (uint32_t) len) - { - total[1]++; - } + int bytesAvailable = stream.available(); + while ((bytesAvailable > 0) && (maxLengthLeft > 0)) { - if(left && len >= fill) - { - memcpy((void *) (buffer + left), data, fill); - process(buffer); - data += fill; - len -= fill; - left = 0; + // determine number of bytes to read + int readBytes = bytesAvailable; + if (readBytes > maxLengthLeft) { + readBytes = maxLengthLeft; // read only until max_len } - - while(len >= 64) - { - process(data); - data += 64; - len -= 64; - } - - if(len > 0) { - memcpy((void *) (buffer + left), data, len); + if (readBytes > buf_size) { + readBytes = buf_size; // not read more the buffer can handle } -} -void SHA1Builder::addHexString(const char * data) -{ - uint16_t len = strlen(data); - uint8_t * tmp = (uint8_t*)malloc(len/2); - if(tmp == NULL) { - return; + // read data and check if we got something + int numBytesRead = stream.readBytes(buf, readBytes); + if (numBytesRead < 1) { + free(buf); + return false; } - hex2bytes(tmp, len/2, data); - add(tmp, len/2); - free(tmp); -} - -bool SHA1Builder::addStream(Stream & stream, const size_t maxLen) -{ - const int buf_size = 512; - int maxLengthLeft = maxLen; - uint8_t * buf = (uint8_t*) malloc(buf_size); - if(!buf) { - return false; - } + // Update SHA1 with buffer payload + add(buf, numBytesRead); - int bytesAvailable = stream.available(); - while((bytesAvailable > 0) && (maxLengthLeft > 0)) { - - // determine number of bytes to read - int readBytes = bytesAvailable; - if(readBytes > maxLengthLeft) { - readBytes = maxLengthLeft ; // read only until max_len - } - if(readBytes > buf_size) { - readBytes = buf_size; // not read more the buffer can handle - } - - // read data and check if we got something - int numBytesRead = stream.readBytes(buf, readBytes); - if(numBytesRead< 1) { - free(buf); - return false; - } - - // Update SHA1 with buffer payload - add(buf, numBytesRead); - - // update available number of bytes - maxLengthLeft -= numBytesRead; - bytesAvailable = stream.available(); - } - free(buf); - return true; + // update available number of bytes + maxLengthLeft -= numBytesRead; + bytesAvailable = stream.available(); + } + free(buf); + return true; } -void SHA1Builder::calculate(void) -{ - uint32_t last, padn; - uint32_t high, low; - uint8_t msglen[8]; +void SHA1Builder::calculate(void) { + uint32_t last, padn; + uint32_t high, low; + uint8_t msglen[8]; - high = (total[0] >> 29) | (total[1] << 3); - low = (total[0] << 3); + high = (total[0] >> 29) | (total[1] << 3); + low = (total[0] << 3); - PUT_UINT32_BE(high, msglen, 0); - PUT_UINT32_BE(low, msglen, 4); + PUT_UINT32_BE(high, msglen, 0); + PUT_UINT32_BE(low, msglen, 4); - last = total[0] & 0x3F; - padn = (last < 56) ? (56 - last) : (120 - last); + last = total[0] & 0x3F; + padn = (last < 56) ? (56 - last) : (120 - last); - add((uint8_t*)sha1_padding, padn); - add(msglen, 8); + add((uint8_t*)sha1_padding, padn); + add(msglen, 8); - PUT_UINT32_BE(state[0], hash, 0); - PUT_UINT32_BE(state[1], hash, 4); - PUT_UINT32_BE(state[2], hash, 8); - PUT_UINT32_BE(state[3], hash, 12); - PUT_UINT32_BE(state[4], hash, 16); + PUT_UINT32_BE(state[0], hash, 0); + PUT_UINT32_BE(state[1], hash, 4); + PUT_UINT32_BE(state[2], hash, 8); + PUT_UINT32_BE(state[3], hash, 12); + PUT_UINT32_BE(state[4], hash, 16); } -void SHA1Builder::getBytes(uint8_t * output) -{ - memcpy(output, hash, SHA1_HASH_SIZE); +void SHA1Builder::getBytes(uint8_t* output) { + memcpy(output, hash, SHA1_HASH_SIZE); } -void SHA1Builder::getChars(char * output) -{ - bytes2hex(output, SHA1_HASH_SIZE*2+1, hash, SHA1_HASH_SIZE); +void SHA1Builder::getChars(char* output) { + bytes2hex(output, SHA1_HASH_SIZE * 2 + 1, hash, SHA1_HASH_SIZE); } -String SHA1Builder::toString(void) -{ - char out[(SHA1_HASH_SIZE * 2) + 1]; - getChars(out); - return String(out); +String SHA1Builder::toString(void) { + char out[(SHA1_HASH_SIZE * 2) + 1]; + getChars(out); + return String(out); } diff --git a/cores/esp32/SHA1Builder.h b/cores/esp32/SHA1Builder.h index 2ab876f6411..3b83f48e55a 100644 --- a/cores/esp32/SHA1Builder.h +++ b/cores/esp32/SHA1Builder.h @@ -22,30 +22,29 @@ #define SHA1_HASH_SIZE 20 -class SHA1Builder : public HashBuilder -{ +class SHA1Builder : public HashBuilder { private: - uint32_t total[2]; /* number of bytes processed */ - uint32_t state[5]; /* intermediate digest state */ - unsigned char buffer[64]; /* data block being processed */ - uint8_t hash[SHA1_HASH_SIZE]; /* SHA-1 result */ + uint32_t total[2]; /* number of bytes processed */ + uint32_t state[5]; /* intermediate digest state */ + unsigned char buffer[64]; /* data block being processed */ + uint8_t hash[SHA1_HASH_SIZE]; /* SHA-1 result */ - void process(const uint8_t* data); + void process(const uint8_t* data); public: - void begin() override; + void begin() override; - using HashBuilder::add; - void add(const uint8_t* data, size_t len) override; + using HashBuilder::add; + void add(const uint8_t* data, size_t len) override; - using HashBuilder::addHexString; - void addHexString(const char* data) override; + using HashBuilder::addHexString; + void addHexString(const char* data) override; - bool addStream(Stream& stream, const size_t maxLen) override; - void calculate() override; - void getBytes(uint8_t* output) override; - void getChars(char* output) override; - String toString() override; + bool addStream(Stream& stream, const size_t maxLen) override; + void calculate() override; + void getBytes(uint8_t* output) override; + void getChars(char* output) override; + String toString() override; }; #endif diff --git a/cores/esp32/Server.h b/cores/esp32/Server.h index 1be91873082..f4825d3dd09 100644 --- a/cores/esp32/Server.h +++ b/cores/esp32/Server.h @@ -22,10 +22,9 @@ #include "Print.h" -class Server: public Print -{ +class Server : public Print { public: - virtual void begin() =0; + virtual void begin() = 0; }; #endif diff --git a/cores/esp32/Stream.cpp b/cores/esp32/Stream.cpp index f412e461195..18ffd05ef1c 100644 --- a/cores/esp32/Stream.cpp +++ b/cores/esp32/Stream.cpp @@ -25,54 +25,51 @@ #include "esp32-hal.h" #define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait -#define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field +#define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field // private method to read stream with timeout -int Stream::timedRead() -{ - int c; - _startMillis = millis(); - do { - c = read(); - if(c >= 0) { - return c; - } - } while(millis() - _startMillis < _timeout); - return -1; // -1 indicates timeout +int Stream::timedRead() { + int c; + _startMillis = millis(); + do { + c = read(); + if (c >= 0) { + return c; + } + } while (millis() - _startMillis < _timeout); + return -1; // -1 indicates timeout } // private method to peek stream with timeout -int Stream::timedPeek() -{ - int c; - _startMillis = millis(); - do { - c = peek(); - if(c >= 0) { - return c; - } - } while(millis() - _startMillis < _timeout); - return -1; // -1 indicates timeout +int Stream::timedPeek() { + int c; + _startMillis = millis(); + do { + c = peek(); + if (c >= 0) { + return c; + } + } while (millis() - _startMillis < _timeout); + return -1; // -1 indicates timeout } // returns peek of the next digit in the stream or -1 if timeout // discards non-numeric characters -int Stream::peekNextDigit() -{ - int c; - while(1) { - c = timedPeek(); - if(c < 0) { - return c; // timeout - } - if(c == '-') { - return c; - } - if(c >= '0' && c <= '9') { - return c; - } - read(); // discard non-numeric +int Stream::peekNextDigit() { + int c; + while (1) { + c = timedPeek(); + if (c < 0) { + return c; // timeout + } + if (c == '-') { + return c; } + if (c >= '0' && c <= '9') { + return c; + } + read(); // discard non-numeric + } } // Public Methods @@ -80,49 +77,45 @@ int Stream::peekNextDigit() void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait { - _timeout = timeout; + _timeout = timeout; } unsigned long Stream::getTimeout(void) { return _timeout; } // find returns true if the target string is found -bool Stream::find(const char *target) -{ +bool Stream::find(const char *target) { return findUntil(target, strlen(target), NULL, 0); } // reads data from the stream until the target string of given length is found // returns true if target string is found, false if timed out -bool Stream::find(const char *target, size_t length) -{ +bool Stream::find(const char *target, size_t length) { return findUntil(target, length, NULL, 0); } // as find but search ends if the terminator string is found -bool Stream::findUntil(const char *target, const char *terminator) -{ +bool Stream::findUntil(const char *target, const char *terminator) { return findUntil(target, strlen(target), terminator, strlen(terminator)); } // reads data from the stream until the target string of the given length is found // search terminated if the terminator string is found // returns true if target string is found, false if terminated or timed out -bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen) -{ +bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen) { if (terminator == NULL) { - MultiTarget t[1] = {{target, targetLen, 0}}; + MultiTarget t[1] = { { target, targetLen, 0 } }; return findMulti(t, 1) == 0 ? true : false; } else { - MultiTarget t[2] = {{target, targetLen, 0}, {terminator, termLen, 0}}; + MultiTarget t[2] = { { target, targetLen, 0 }, { terminator, termLen, 0 } }; return findMulti(t, 2) == 0 ? true : false; } } -int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) { +int Stream::findMulti(struct Stream::MultiTarget *targets, int tCount) { // any zero length target string automatically matches and would make // a mess of the rest of the algorithm. - for (struct MultiTarget *t = targets; t < targets+tCount; ++t) { + for (struct MultiTarget *t = targets; t < targets + tCount; ++t) { if (t->len <= 0) return t - targets; } @@ -132,7 +125,7 @@ int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) { if (c < 0) return -1; - for (struct MultiTarget *t = targets; t < targets+tCount; ++t) { + for (struct MultiTarget *t = targets; t < targets + tCount; ++t) { // the simple case is if we match, deal with that first. if (c == t->str[t->index]) { if (++t->index == t->len) @@ -187,90 +180,86 @@ int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) { // returns the first valid (long) integer value from the current position. // initial characters that are not digits (or the minus sign) are skipped // function is terminated by the first character that is not a digit. -long Stream::parseInt() -{ - return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout) +long Stream::parseInt() { + return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout) } // as above but a given skipChar is ignored // this allows format characters (typically commas) in values to be ignored -long Stream::parseInt(char skipChar) -{ - boolean isNegative = false; - long value = 0; - int c; - - c = peekNextDigit(); - // ignore non numeric leading characters - if(c < 0) { - return 0; // zero returned if timeout - } - - do { - if(c == skipChar) { - } // ignore this charactor - else if(c == '-') { - isNegative = true; - } else if(c >= '0' && c <= '9') { // is c a digit? - value = value * 10 + c - '0'; - } - read(); // consume the character we got with peek - c = timedPeek(); - } while((c >= '0' && c <= '9') || c == skipChar); +long Stream::parseInt(char skipChar) { + boolean isNegative = false; + long value = 0; + int c; + + c = peekNextDigit(); + // ignore non numeric leading characters + if (c < 0) { + return 0; // zero returned if timeout + } - if(isNegative) { - value = -value; + do { + if (c == skipChar) { + } // ignore this character + else if (c == '-') { + isNegative = true; + } else if (c >= '0' && c <= '9') { // is c a digit? + value = value * 10 + c - '0'; } - return value; + read(); // consume the character we got with peek + c = timedPeek(); + } while ((c >= '0' && c <= '9') || c == skipChar); + + if (isNegative) { + value = -value; + } + return value; } // as parseInt but returns a floating point value -float Stream::parseFloat() -{ - return parseFloat(NO_SKIP_CHAR); +float Stream::parseFloat() { + return parseFloat(NO_SKIP_CHAR); } // as above but the given skipChar is ignored // this allows format characters (typically commas) in values to be ignored -float Stream::parseFloat(char skipChar) -{ - boolean isNegative = false; - boolean isFraction = false; - long value = 0; - int c; - float fraction = 1.0; - - c = peekNextDigit(); - // ignore non numeric leading characters - if(c < 0) { - return 0; // zero returned if timeout - } - - do { - if(c == skipChar) { - } // ignore - else if(c == '-') { - isNegative = true; - } else if(c == '.') { - isFraction = true; - } else if(c >= '0' && c <= '9') { // is c a digit? - value = value * 10 + c - '0'; - if(isFraction) { - fraction *= 0.1f; - } - } - read(); // consume the character we got with peek - c = timedPeek(); - } while((c >= '0' && c <= '9') || c == '.' || c == skipChar); +float Stream::parseFloat(char skipChar) { + boolean isNegative = false; + boolean isFraction = false; + long value = 0; + int c; + float fraction = 1.0; + + c = peekNextDigit(); + // ignore non numeric leading characters + if (c < 0) { + return 0; // zero returned if timeout + } - if(isNegative) { - value = -value; - } - if(isFraction) { - return value * fraction; - } else { - return value; + do { + if (c == skipChar) { + } // ignore + else if (c == '-') { + isNegative = true; + } else if (c == '.') { + isFraction = true; + } else if (c >= '0' && c <= '9') { // is c a digit? + value = value * 10 + c - '0'; + if (isFraction) { + fraction *= 0.1f; + } } + read(); // consume the character we got with peek + c = timedPeek(); + } while ((c >= '0' && c <= '9') || c == '.' || c == skipChar); + + if (isNegative) { + value = -value; + } + if (isFraction) { + return value * fraction; + } else { + return value; + } } // read characters from stream into buffer @@ -278,60 +267,55 @@ float Stream::parseFloat(char skipChar) // returns the number of characters placed in the buffer // the buffer is NOT null terminated. // -size_t Stream::readBytes(char *buffer, size_t length) -{ - size_t count = 0; - while(count < length) { - int c = timedRead(); - if(c < 0) { - break; - } - *buffer++ = (char) c; - count++; +size_t Stream::readBytes(char *buffer, size_t length) { + size_t count = 0; + while (count < length) { + int c = timedRead(); + if (c < 0) { + break; } - return count; + *buffer++ = (char)c; + count++; + } + return count; } // as readBytes with terminator character // terminates if length characters have been read, timeout, or if the terminator character detected // returns the number of characters placed in the buffer (0 means no valid data found) -size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length) -{ - if(length < 1) { - return 0; - } - size_t index = 0; - while(index < length) { - int c = timedRead(); - if(c < 0 || c == terminator) { - break; - } - *buffer++ = (char) c; - index++; - } - return index; // return number of characters, not including null terminator -} - -String Stream::readString() -{ - String ret; +size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length) { + if (length < 1) { + return 0; + } + size_t index = 0; + while (index < length) { int c = timedRead(); - while(c >= 0) { - ret += (char) c; - c = timedRead(); + if (c < 0 || c == terminator) { + break; } - return ret; + *buffer++ = (char)c; + index++; + } + return index; // return number of characters, not including null terminator } -String Stream::readStringUntil(char terminator) -{ - String ret; - int c = timedRead(); - while(c >= 0 && c != terminator) { - ret += (char) c; - c = timedRead(); - } - return ret; +String Stream::readString() { + String ret; + int c = timedRead(); + while (c >= 0) { + ret += (char)c; + c = timedRead(); + } + return ret; } +String Stream::readStringUntil(char terminator) { + String ret; + int c = timedRead(); + while (c >= 0 && c != terminator) { + ret += (char)c; + c = timedRead(); + } + return ret; +} diff --git a/cores/esp32/Stream.h b/cores/esp32/Stream.h index 8df8226d730..576a9018193 100644 --- a/cores/esp32/Stream.h +++ b/cores/esp32/Stream.h @@ -25,7 +25,7 @@ #include #include "Print.h" -// compatability macros for testing +// compatibility macros for testing /* #define getInt() parseInt() #define getInt(skipChar) parseInt(skipchar) @@ -35,105 +35,96 @@ readBytesBetween( pre_string, terminator, buffer, length) */ -class Stream: public Print -{ +class Stream : public Print { protected: - unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read - unsigned long _startMillis; // used for timeout measurement - int timedRead(); // private method to read stream with timeout - int timedPeek(); // private method to peek stream with timeout - int peekNextDigit(); // returns the next numeric digit in the stream or -1 if timeout + unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read + unsigned long _startMillis; // used for timeout measurement + int timedRead(); // private method to read stream with timeout + int timedPeek(); // private method to peek stream with timeout + int peekNextDigit(); // returns the next numeric digit in the stream or -1 if timeout public: - virtual int available() = 0; - virtual int read() = 0; - virtual int peek() = 0; - - Stream():_startMillis(0) - { - _timeout = 1000; - } - virtual ~Stream() {} - -// parsing methods - - void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second - unsigned long getTimeout(void); - - bool find(const char *target); // reads data from the stream until the target string is found - bool find(uint8_t *target) - { - return find((char *) target); - } - // returns true if target string is found, false if timed out (see setTimeout) - - bool find(const char *target, size_t length); // reads data from the stream until the target string of given length is found - bool find(const uint8_t *target, size_t length) - { - return find((char *) target, length); - } - // returns true if target string is found, false if timed out - - bool find(char target) - { - return find (&target, 1); - } - - bool findUntil(const char *target, const char *terminator); // as find but search ends if the terminator string is found - bool findUntil(const uint8_t *target, const char *terminator) - { - return findUntil((char *) target, terminator); - } - - bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen); // as above but search ends if the terminate string is found - bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) - { - return findUntil((char *) target, targetLen, terminate, termLen); - } - - long parseInt(); // returns the first valid (long) integer value from the current position. - // initial characters that are not digits (or the minus sign) are skipped - // integer is terminated by the first character that is not a digit. - - float parseFloat(); // float version of parseInt - - virtual size_t readBytes(char *buffer, size_t length); // read chars from stream into buffer - virtual size_t readBytes(uint8_t *buffer, size_t length) - { - return readBytes((char *) buffer, length); - } - // terminates if length characters have been read or timeout (see setTimeout) - // returns the number of characters placed in the buffer (0 means no valid data found) - - size_t readBytesUntil(char terminator, char *buffer, size_t length); // as readBytes with terminator character - size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) - { - return readBytesUntil(terminator, (char *) buffer, length); - } - // terminates if length characters have been read, timeout, or if the terminator character detected - // returns the number of characters placed in the buffer (0 means no valid data found) - - // Arduino String functions to be added here - virtual String readString(); - String readStringUntil(char terminator); + virtual int available() = 0; + virtual int read() = 0; + virtual int peek() = 0; + + Stream() + : _startMillis(0) { + _timeout = 1000; + } + virtual ~Stream() {} + + // parsing methods + + void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second + unsigned long getTimeout(void); + + bool find(const char *target); // reads data from the stream until the target string is found + bool find(uint8_t *target) { + return find((char *)target); + } + // returns true if target string is found, false if timed out (see setTimeout) + + bool find(const char *target, size_t length); // reads data from the stream until the target string of given length is found + bool find(const uint8_t *target, size_t length) { + return find((char *)target, length); + } + // returns true if target string is found, false if timed out + + bool find(char target) { + return find(&target, 1); + } + + bool findUntil(const char *target, const char *terminator); // as find but search ends if the terminator string is found + bool findUntil(const uint8_t *target, const char *terminator) { + return findUntil((char *)target, terminator); + } + + bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen); // as above but search ends if the terminate string is found + bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) { + return findUntil((char *)target, targetLen, terminate, termLen); + } + + long parseInt(); // returns the first valid (long) integer value from the current position. + // initial characters that are not digits (or the minus sign) are skipped + // integer is terminated by the first character that is not a digit. + + float parseFloat(); // float version of parseInt + + virtual size_t readBytes(char *buffer, size_t length); // read chars from stream into buffer + virtual size_t readBytes(uint8_t *buffer, size_t length) { + return readBytes((char *)buffer, length); + } + // terminates if length characters have been read or timeout (see setTimeout) + // returns the number of characters placed in the buffer (0 means no valid data found) + + size_t readBytesUntil(char terminator, char *buffer, size_t length); // as readBytes with terminator character + size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) { + return readBytesUntil(terminator, (char *)buffer, length); + } + // terminates if length characters have been read, timeout, or if the terminator character detected + // returns the number of characters placed in the buffer (0 means no valid data found) + + // Arduino String functions to be added here + virtual String readString(); + String readStringUntil(char terminator); protected: - long parseInt(char skipChar); // as above but the given skipChar is ignored - // as above but the given skipChar is ignored - // this allows format characters (typically commas) in values to be ignored - - float parseFloat(char skipChar); // as above but the given skipChar is ignored - - struct MultiTarget { - const char *str; // string you're searching for - size_t len; // length of string you're searching for - size_t index; // index used by the search routine. - }; + long parseInt(char skipChar); // as above but the given skipChar is ignored + // as above but the given skipChar is ignored + // this allows format characters (typically commas) in values to be ignored + + float parseFloat(char skipChar); // as above but the given skipChar is ignored + + struct MultiTarget { + const char *str; // string you're searching for + size_t len; // length of string you're searching for + size_t index; // index used by the search routine. + }; // This allows you to search for an arbitrary number of strings. // Returns index of the target that is found first or -1 if timeout occurs. int findMulti(struct MultiTarget *targets, int tCount); - }; #endif diff --git a/cores/esp32/StreamString.cpp b/cores/esp32/StreamString.cpp index f50b6825b55..022353359b2 100644 --- a/cores/esp32/StreamString.cpp +++ b/cores/esp32/StreamString.cpp @@ -24,44 +24,42 @@ #include "StreamString.h" size_t StreamString::write(const uint8_t *data, size_t size) { - if(size && data) { - const unsigned int newlen = length() + size; - if(reserve(newlen + 1)) { - memcpy((void *) (wbuffer() + len()), (const void *) data, size); - setLen(newlen); - *(wbuffer() + newlen) = 0x00; // add null for string end - return size; - } + if (size && data) { + const unsigned int newlen = length() + size; + if (reserve(newlen + 1)) { + memcpy((void *)(wbuffer() + len()), (const void *)data, size); + setLen(newlen); + *(wbuffer() + newlen) = 0x00; // add null for string end + return size; } - return 0; + } + return 0; } size_t StreamString::write(uint8_t data) { - return concat((char) data); + return concat((char)data); } int StreamString::available() { - return length(); + return length(); } int StreamString::read() { - if(length()) { - char c = charAt(0); - remove(0, 1); - return c; - - } - return -1; + if (length()) { + char c = charAt(0); + remove(0, 1); + return c; + } + return -1; } int StreamString::peek() { - if(length()) { - char c = charAt(0); - return c; - } - return -1; + if (length()) { + char c = charAt(0); + return c; + } + return -1; } void StreamString::flush() { } - diff --git a/cores/esp32/StreamString.h b/cores/esp32/StreamString.h index fa983786c70..e31e177e64b 100644 --- a/cores/esp32/StreamString.h +++ b/cores/esp32/StreamString.h @@ -24,16 +24,15 @@ #include "Stream.h" #include "WString.h" -class StreamString: public Stream, public String -{ +class StreamString : public Stream, public String { public: - size_t write(const uint8_t *buffer, size_t size) override; - size_t write(uint8_t data) override; + size_t write(const uint8_t *buffer, size_t size) override; + size_t write(uint8_t data) override; - int available() override; - int read() override; - int peek() override; - void flush() override; + int available() override; + int read() override; + int peek() override; + void flush() override; }; diff --git a/cores/esp32/Tone.cpp b/cores/esp32/Tone.cpp index 772b2b6bba1..03a41c6d51b 100644 --- a/cores/esp32/Tone.cpp +++ b/cores/esp32/Tone.cpp @@ -8,36 +8,36 @@ static TaskHandle_t _tone_task = NULL; static QueueHandle_t _tone_queue = NULL; static int8_t _pin = -1; -typedef enum{ +typedef enum { TONE_START, TONE_END } tone_cmd_t; -typedef struct{ +typedef struct { tone_cmd_t tone_cmd; uint8_t pin; unsigned int frequency; unsigned long duration; } tone_msg_t; -static void tone_task(void*){ +static void tone_task(void*) { tone_msg_t tone_msg; - while(1){ + while (1) { xQueueReceive(_tone_queue, &tone_msg, portMAX_DELAY); - switch(tone_msg.tone_cmd){ + switch (tone_msg.tone_cmd) { case TONE_START: log_d("Task received from queue TONE_START: pin=%d, frequency=%u Hz, duration=%lu ms", tone_msg.pin, tone_msg.frequency, tone_msg.duration); if (_pin == -1) { if (ledcAttach(tone_msg.pin, tone_msg.frequency, 10) == 0) { - log_e("Tone start failed"); - break; + log_e("Tone start failed"); + break; } _pin = tone_msg.pin; } ledcWriteTone(tone_msg.pin, tone_msg.frequency); - if(tone_msg.duration){ + if (tone_msg.duration) { delay(tone_msg.duration); ledcWriteTone(tone_msg.pin, 0); } @@ -50,56 +50,55 @@ static void tone_task(void*){ _pin = -1; break; - default: ; // do nothing - } // switch - } // infinite loop + default:; // do nothing + } // switch + } // infinite loop } -static int tone_init(){ - if(_tone_queue == NULL){ +static int tone_init() { + if (_tone_queue == NULL) { log_v("Creating tone queue"); _tone_queue = xQueueCreate(128, sizeof(tone_msg_t)); - if(_tone_queue == NULL){ + if (_tone_queue == NULL) { log_e("Could not create tone queue"); - return 0; // ERR + return 0; // ERR } log_v("Tone queue created"); } - if(_tone_task == NULL){ + if (_tone_task == NULL) { log_v("Creating tone task"); xTaskCreate( - tone_task, // Function to implement the task - "toneTask", // Name of the task - 3500, // Stack size in words - NULL, // Task input parameter - 1, // Priority of the task + tone_task, // Function to implement the task + "toneTask", // Name of the task + 3500, // Stack size in words + NULL, // Task input parameter + 1, // Priority of the task &_tone_task // Task handle. - ); - if(_tone_task == NULL){ + ); + if (_tone_task == NULL) { log_e("Could not create tone task"); - return 0; // ERR + return 0; // ERR } log_v("Tone task created"); } - return 1; // OK + return 1; // OK } -void noTone(uint8_t pin){ +void noTone(uint8_t pin) { log_d("noTone was called"); - if(_pin == pin) { - if(tone_init()){ + if (_pin == pin) { + if (tone_init()) { tone_msg_t tone_msg = { .tone_cmd = TONE_END, .pin = pin, - .frequency = 0, // Ignored - .duration = 0, // Ignored + .frequency = 0, // Ignored + .duration = 0, // Ignored }; - xQueueReset(_tone_queue); // clear queue + xQueueReset(_tone_queue); // clear queue xQueueSend(_tone_queue, &tone_msg, portMAX_DELAY); } - } - else { + } else { log_e("Tone is not running on given pin %d", pin); } } @@ -109,10 +108,10 @@ void noTone(uint8_t pin){ // frequency - PWM frequency in Hz // duration - time in ms - how long will the signal be outputted. // If not provided, or 0 you must manually call noTone to end output -void tone(uint8_t pin, unsigned int frequency, unsigned long duration){ +void tone(uint8_t pin, unsigned int frequency, unsigned long duration) { log_d("pin=%d, frequency=%u Hz, duration=%lu ms", pin, frequency, duration); - if(_pin == -1 || _pin == pin) { - if(tone_init()){ + if (_pin == -1 || _pin == pin) { + if (tone_init()) { tone_msg_t tone_msg = { .tone_cmd = TONE_START, .pin = pin, @@ -122,8 +121,7 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration){ xQueueSend(_tone_queue, &tone_msg, portMAX_DELAY); return; } - } - else { + } else { log_e("Tone is still running on pin %d, call noTone(%d) first!", _pin, _pin); return; } diff --git a/cores/esp32/USB.cpp b/cores/esp32/USB.cpp index 8740bb71763..48f9c8c8533 100644 --- a/cores/esp32/USB.cpp +++ b/cores/esp32/USB.cpp @@ -52,30 +52,28 @@ #endif #if CFG_TUD_DFU -__attribute__((weak)) uint16_t load_dfu_ota_descriptor(uint8_t * dst, uint8_t * itf) { - return 0; +__attribute__((weak)) uint16_t load_dfu_ota_descriptor(uint8_t *dst, uint8_t *itf) { + return 0; } #elif CFG_TUD_DFU_RUNTIME -static uint16_t load_dfu_descriptor(uint8_t * dst, uint8_t * itf) -{ +static uint16_t load_dfu_descriptor(uint8_t *dst, uint8_t *itf) { #define DFU_ATTRS (DFU_ATTR_CAN_DOWNLOAD | DFU_ATTR_CAN_UPLOAD | DFU_ATTR_MANIFESTATION_TOLERANT) - uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB DFU_RT"); - uint8_t descriptor[TUD_DFU_RT_DESC_LEN] = { - // Interface number, string index, attributes, detach timeout, transfer size */ - TUD_DFU_RT_DESCRIPTOR(*itf, str_index, DFU_ATTRS, 700, 64) - }; - *itf+=1; - memcpy(dst, descriptor, TUD_DFU_RT_DESC_LEN); - return TUD_DFU_RT_DESC_LEN; + uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB DFU_RT"); + uint8_t descriptor[TUD_DFU_RT_DESC_LEN] = { + // Interface number, string index, attributes, detach timeout, transfer size */ + TUD_DFU_RT_DESCRIPTOR(*itf, str_index, DFU_ATTRS, 700, 64) + }; + *itf += 1; + memcpy(dst, descriptor, TUD_DFU_RT_DESC_LEN); + return TUD_DFU_RT_DESC_LEN; } #endif /* CFG_TUD_DFU_RUNTIME */ #if CFG_TUD_DFU_RUNTIME // Invoked on DFU_DETACH request to reboot to the bootloader -void tud_dfu_runtime_reboot_to_dfu_cb(void) -{ - usb_persist_restart(RESTART_BOOTLOADER_DFU); +void tud_dfu_runtime_reboot_to_dfu_cb(void) { + usb_persist_restart(RESTART_BOOTLOADER_DFU); } #endif /* CFG_TUD_DFU_RUNTIME */ @@ -83,286 +81,270 @@ ESP_EVENT_DEFINE_BASE(ARDUINO_USB_EVENTS); static esp_event_loop_handle_t arduino_usb_event_loop_handle = NULL; -esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, TickType_t ticks_to_wait){ - if(arduino_usb_event_loop_handle == NULL){ - return ESP_FAIL; - } - return esp_event_post_to(arduino_usb_event_loop_handle, event_base, event_id, event_data, event_data_size, ticks_to_wait); +esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, TickType_t ticks_to_wait) { + if (arduino_usb_event_loop_handle == NULL) { + return ESP_FAIL; + } + return esp_event_post_to(arduino_usb_event_loop_handle, event_base, event_id, event_data, event_data_size, ticks_to_wait); } -esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg){ - if(arduino_usb_event_loop_handle == NULL){ - return ESP_FAIL; - } - return esp_event_handler_register_with(arduino_usb_event_loop_handle, event_base, event_id, event_handler, event_handler_arg); +esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg) { + if (arduino_usb_event_loop_handle == NULL) { + return ESP_FAIL; + } + return esp_event_handler_register_with(arduino_usb_event_loop_handle, event_base, event_id, event_handler, event_handler_arg); } static bool tinyusb_device_mounted = false; static bool tinyusb_device_suspended = false; // Invoked when device is mounted (configured) -void tud_mount_cb(void){ - tinyusb_device_mounted = true; - arduino_usb_event_data_t p; - arduino_usb_event_post(ARDUINO_USB_EVENTS, ARDUINO_USB_STARTED_EVENT, &p, sizeof(arduino_usb_event_data_t), portMAX_DELAY); +void tud_mount_cb(void) { + tinyusb_device_mounted = true; + arduino_usb_event_data_t p; + arduino_usb_event_post(ARDUINO_USB_EVENTS, ARDUINO_USB_STARTED_EVENT, &p, sizeof(arduino_usb_event_data_t), portMAX_DELAY); } // Invoked when device is unmounted -void tud_umount_cb(void){ - tinyusb_device_mounted = false; - arduino_usb_event_data_t p; - arduino_usb_event_post(ARDUINO_USB_EVENTS, ARDUINO_USB_STOPPED_EVENT, &p, sizeof(arduino_usb_event_data_t), portMAX_DELAY); +void tud_umount_cb(void) { + tinyusb_device_mounted = false; + arduino_usb_event_data_t p; + arduino_usb_event_post(ARDUINO_USB_EVENTS, ARDUINO_USB_STOPPED_EVENT, &p, sizeof(arduino_usb_event_data_t), portMAX_DELAY); } // Invoked when usb bus is suspended // Within 7ms, device must draw an average of current less than 2.5 mA from bus -void tud_suspend_cb(bool remote_wakeup_en){ - tinyusb_device_suspended = true; - arduino_usb_event_data_t p; - p.suspend.remote_wakeup_en = remote_wakeup_en; - arduino_usb_event_post(ARDUINO_USB_EVENTS, ARDUINO_USB_SUSPEND_EVENT, &p, sizeof(arduino_usb_event_data_t), portMAX_DELAY); +void tud_suspend_cb(bool remote_wakeup_en) { + tinyusb_device_suspended = true; + arduino_usb_event_data_t p; + p.suspend.remote_wakeup_en = remote_wakeup_en; + arduino_usb_event_post(ARDUINO_USB_EVENTS, ARDUINO_USB_SUSPEND_EVENT, &p, sizeof(arduino_usb_event_data_t), portMAX_DELAY); } // Invoked when usb bus is resumed -void tud_resume_cb(void){ - tinyusb_device_suspended = false; - arduino_usb_event_data_t p; - arduino_usb_event_post(ARDUINO_USB_EVENTS, ARDUINO_USB_RESUME_EVENT, &p, sizeof(arduino_usb_event_data_t), portMAX_DELAY); +void tud_resume_cb(void) { + tinyusb_device_suspended = false; + arduino_usb_event_data_t p; + arduino_usb_event_post(ARDUINO_USB_EVENTS, ARDUINO_USB_RESUME_EVENT, &p, sizeof(arduino_usb_event_data_t), portMAX_DELAY); } ESPUSB::ESPUSB(size_t task_stack_size, uint8_t event_task_priority) -:vid(USB_VID) -,pid(USB_PID) -,product_name(USB_PRODUCT) -,manufacturer_name(USB_MANUFACTURER) -,serial_number(USB_SERIAL) -,fw_version(0x0100) -,usb_version(0x0200)// at least 2.1 or 3.x for BOS & webUSB -,usb_class(TUSB_CLASS_MISC) -,usb_subclass(MISC_SUBCLASS_COMMON) -,usb_protocol(MISC_PROTOCOL_IAD) -,usb_attributes(TUSB_DESC_CONFIG_ATT_SELF_POWERED) -,usb_power_ma(500) -,webusb_enabled(USB_WEBUSB_ENABLED) -,webusb_url(USB_WEBUSB_URL) -,_started(false) -,_task_stack_size(task_stack_size) -,_event_task_priority(event_task_priority) -{ - if (!arduino_usb_event_loop_handle) { - esp_event_loop_args_t event_task_args = { - .queue_size = 5, - .task_name = "arduino_usb_events", - .task_priority = _event_task_priority, - .task_stack_size = _task_stack_size, - .task_core_id = tskNO_AFFINITY - }; - if (esp_event_loop_create(&event_task_args, &arduino_usb_event_loop_handle) != ESP_OK) { - log_e("esp_event_loop_create failed"); - } + : vid(USB_VID), pid(USB_PID), product_name(USB_PRODUCT), manufacturer_name(USB_MANUFACTURER), serial_number(USB_SERIAL), fw_version(0x0100), usb_version(0x0200) // at least 2.1 or 3.x for BOS & webUSB + , + usb_class(TUSB_CLASS_MISC), usb_subclass(MISC_SUBCLASS_COMMON), usb_protocol(MISC_PROTOCOL_IAD), usb_attributes(TUSB_DESC_CONFIG_ATT_SELF_POWERED), usb_power_ma(500), webusb_enabled(USB_WEBUSB_ENABLED), webusb_url(USB_WEBUSB_URL), _started(false), _task_stack_size(task_stack_size), _event_task_priority(event_task_priority) { + if (!arduino_usb_event_loop_handle) { + esp_event_loop_args_t event_task_args = { + .queue_size = 5, + .task_name = "arduino_usb_events", + .task_priority = _event_task_priority, + .task_stack_size = _task_stack_size, + .task_core_id = tskNO_AFFINITY + }; + if (esp_event_loop_create(&event_task_args, &arduino_usb_event_loop_handle) != ESP_OK) { + log_e("esp_event_loop_create failed"); } + } } -ESPUSB::~ESPUSB(){ - if (arduino_usb_event_loop_handle) { - esp_event_loop_delete(arduino_usb_event_loop_handle); - arduino_usb_event_loop_handle = NULL; - } +ESPUSB::~ESPUSB() { + if (arduino_usb_event_loop_handle) { + esp_event_loop_delete(arduino_usb_event_loop_handle); + arduino_usb_event_loop_handle = NULL; + } } -bool ESPUSB::begin(){ - if(!_started){ +bool ESPUSB::begin() { + if (!_started) { #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 - if(serial_number == "__MAC__"){ - StreamString s; - uint8_t m[6]; - esp_efuse_mac_get_default(m); - s.printf("%02X%02X%02X%02X%02X%02X", m[0], m[1], m[2], m[3], m[4], m[5]); - serial_number = s; - } -#endif - tinyusb_device_config_t tinyusb_device_config = { - .vid = vid, - .pid = pid, - .product_name = product_name.c_str(), - .manufacturer_name = manufacturer_name.c_str(), - .serial_number = serial_number.c_str(), - .fw_version = fw_version, - .usb_version = usb_version, - .usb_class = usb_class, - .usb_subclass = usb_subclass, - .usb_protocol = usb_protocol, - .usb_attributes = usb_attributes, - .usb_power_ma = usb_power_ma, - .webusb_enabled = webusb_enabled, - .webusb_url = webusb_url.c_str() - }; - _started = tinyusb_init(&tinyusb_device_config) == ESP_OK; + if (serial_number == "__MAC__") { + StreamString s; + uint8_t m[6]; + esp_efuse_mac_get_default(m); + s.printf("%02X%02X%02X%02X%02X%02X", m[0], m[1], m[2], m[3], m[4], m[5]); + serial_number = s; } - return _started; +#endif + tinyusb_device_config_t tinyusb_device_config = { + .vid = vid, + .pid = pid, + .product_name = product_name.c_str(), + .manufacturer_name = manufacturer_name.c_str(), + .serial_number = serial_number.c_str(), + .fw_version = fw_version, + .usb_version = usb_version, + .usb_class = usb_class, + .usb_subclass = usb_subclass, + .usb_protocol = usb_protocol, + .usb_attributes = usb_attributes, + .usb_power_ma = usb_power_ma, + .webusb_enabled = webusb_enabled, + .webusb_url = webusb_url.c_str() + }; + _started = tinyusb_init(&tinyusb_device_config) == ESP_OK; + } + return _started; } -void ESPUSB::onEvent(esp_event_handler_t callback){ - onEvent(ARDUINO_USB_ANY_EVENT, callback); +void ESPUSB::onEvent(esp_event_handler_t callback) { + onEvent(ARDUINO_USB_ANY_EVENT, callback); } -void ESPUSB::onEvent(arduino_usb_event_t event, esp_event_handler_t callback){ - arduino_usb_event_handler_register_with(ARDUINO_USB_EVENTS, event, callback, this); +void ESPUSB::onEvent(arduino_usb_event_t event, esp_event_handler_t callback) { + arduino_usb_event_handler_register_with(ARDUINO_USB_EVENTS, event, callback, this); } -ESPUSB::operator bool() const -{ - return _started && tinyusb_device_mounted; +ESPUSB::operator bool() const { + return _started && tinyusb_device_mounted; } -bool ESPUSB::enableDFU(){ +bool ESPUSB::enableDFU() { #if CFG_TUD_DFU - return tinyusb_enable_interface(USB_INTERFACE_DFU, TUD_DFU_DESC_LEN(1), load_dfu_ota_descriptor) == ESP_OK; + return tinyusb_enable_interface(USB_INTERFACE_DFU, TUD_DFU_DESC_LEN(1), load_dfu_ota_descriptor) == ESP_OK; #elif CFG_TUD_DFU_RUNTIME - return tinyusb_enable_interface(USB_INTERFACE_DFU, TUD_DFU_RT_DESC_LEN, load_dfu_descriptor) == ESP_OK; + return tinyusb_enable_interface(USB_INTERFACE_DFU, TUD_DFU_RT_DESC_LEN, load_dfu_descriptor) == ESP_OK; #endif /* CFG_TUD_DFU_RUNTIME */ - return false; + return false; } -bool ESPUSB::VID(uint16_t v){ - if(!_started){ - vid = v; - } - return !_started; +bool ESPUSB::VID(uint16_t v) { + if (!_started) { + vid = v; + } + return !_started; } -uint16_t ESPUSB::VID(void){ - return vid; +uint16_t ESPUSB::VID(void) { + return vid; } -bool ESPUSB::PID(uint16_t p){ - if(!_started){ - pid = p; - } - return !_started; +bool ESPUSB::PID(uint16_t p) { + if (!_started) { + pid = p; + } + return !_started; } -uint16_t ESPUSB::PID(void){ - return pid; +uint16_t ESPUSB::PID(void) { + return pid; } -bool ESPUSB::firmwareVersion(uint16_t version){ - if(!_started){ - fw_version = version; - } - return !_started; +bool ESPUSB::firmwareVersion(uint16_t version) { + if (!_started) { + fw_version = version; + } + return !_started; } -uint16_t ESPUSB::firmwareVersion(void){ - return fw_version; +uint16_t ESPUSB::firmwareVersion(void) { + return fw_version; } -bool ESPUSB::usbVersion(uint16_t version){ - if(!_started){ - usb_version = version; - } - return !_started; +bool ESPUSB::usbVersion(uint16_t version) { + if (!_started) { + usb_version = version; + } + return !_started; } -uint16_t ESPUSB::usbVersion(void){ - return usb_version; +uint16_t ESPUSB::usbVersion(void) { + return usb_version; } -bool ESPUSB::usbPower(uint16_t mA){ - if(!_started){ - usb_power_ma = mA; - } - return !_started; +bool ESPUSB::usbPower(uint16_t mA) { + if (!_started) { + usb_power_ma = mA; + } + return !_started; } -uint16_t ESPUSB::usbPower(void){ - return usb_power_ma; +uint16_t ESPUSB::usbPower(void) { + return usb_power_ma; } -bool ESPUSB::usbClass(uint8_t _class){ - if(!_started){ - usb_class = _class; - } - return !_started; +bool ESPUSB::usbClass(uint8_t _class) { + if (!_started) { + usb_class = _class; + } + return !_started; } -uint8_t ESPUSB::usbClass(void){ - return usb_class; +uint8_t ESPUSB::usbClass(void) { + return usb_class; } -bool ESPUSB::usbSubClass(uint8_t subClass){ - if(!_started){ - usb_subclass = subClass; - } - return !_started; +bool ESPUSB::usbSubClass(uint8_t subClass) { + if (!_started) { + usb_subclass = subClass; + } + return !_started; } -uint8_t ESPUSB::usbSubClass(void){ - return usb_subclass; +uint8_t ESPUSB::usbSubClass(void) { + return usb_subclass; } -bool ESPUSB::usbProtocol(uint8_t protocol){ - if(!_started){ - usb_protocol = protocol; - } - return !_started; +bool ESPUSB::usbProtocol(uint8_t protocol) { + if (!_started) { + usb_protocol = protocol; + } + return !_started; } -uint8_t ESPUSB::usbProtocol(void){ - return usb_protocol; +uint8_t ESPUSB::usbProtocol(void) { + return usb_protocol; } -bool ESPUSB::usbAttributes(uint8_t attr){ - if(!_started){ - usb_attributes = attr; - } - return !_started; +bool ESPUSB::usbAttributes(uint8_t attr) { + if (!_started) { + usb_attributes = attr; + } + return !_started; } -uint8_t ESPUSB::usbAttributes(void){ - return usb_attributes; +uint8_t ESPUSB::usbAttributes(void) { + return usb_attributes; } -bool ESPUSB::webUSB(bool enabled){ - if(!_started){ - webusb_enabled = enabled; - if(enabled && usb_version < 0x0210){ - usb_version = 0x0210; - } +bool ESPUSB::webUSB(bool enabled) { + if (!_started) { + webusb_enabled = enabled; + if (enabled && usb_version < 0x0210) { + usb_version = 0x0210; } - return !_started; + } + return !_started; } -bool ESPUSB::webUSB(void){ - return webusb_enabled; +bool ESPUSB::webUSB(void) { + return webusb_enabled; } -bool ESPUSB::productName(const char * name){ - if(!_started){ - product_name = name; - } - return !_started; +bool ESPUSB::productName(const char *name) { + if (!_started) { + product_name = name; + } + return !_started; } -const char * ESPUSB::productName(void){ - return product_name.c_str(); +const char *ESPUSB::productName(void) { + return product_name.c_str(); } -bool ESPUSB::manufacturerName(const char * name){ - if(!_started){ - manufacturer_name = name; - } - return !_started; +bool ESPUSB::manufacturerName(const char *name) { + if (!_started) { + manufacturer_name = name; + } + return !_started; } -const char * ESPUSB::manufacturerName(void){ - return manufacturer_name.c_str(); +const char *ESPUSB::manufacturerName(void) { + return manufacturer_name.c_str(); } -bool ESPUSB::serialNumber(const char * name){ - if(!_started){ - serial_number = name; - } - return !_started; +bool ESPUSB::serialNumber(const char *name) { + if (!_started) { + serial_number = name; + } + return !_started; } -const char * ESPUSB::serialNumber(void){ - return serial_number.c_str(); +const char *ESPUSB::serialNumber(void) { + return serial_number.c_str(); } -bool ESPUSB::webUSBURL(const char * name){ - if(!_started){ - webusb_url = name; - } - return !_started; +bool ESPUSB::webUSBURL(const char *name) { + if (!_started) { + webusb_url = name; + } + return !_started; } -const char * ESPUSB::webUSBURL(void){ - return webusb_url.c_str(); +const char *ESPUSB::webUSBURL(void) { + return webusb_url.c_str(); } ESPUSB USB; diff --git a/cores/esp32/USB.h b/cores/esp32/USB.h index 762ad172b7f..5023cea69af 100644 --- a/cores/esp32/USB.h +++ b/cores/esp32/USB.h @@ -22,98 +22,98 @@ #include "esp_event.h" #include "USBCDC.h" -#define ARDUINO_USB_ON_BOOT (ARDUINO_USB_CDC_ON_BOOT|ARDUINO_USB_MSC_ON_BOOT|ARDUINO_USB_DFU_ON_BOOT) +#define ARDUINO_USB_ON_BOOT (ARDUINO_USB_CDC_ON_BOOT | ARDUINO_USB_MSC_ON_BOOT | ARDUINO_USB_DFU_ON_BOOT) ESP_EVENT_DECLARE_BASE(ARDUINO_USB_EVENTS); typedef enum { - ARDUINO_USB_ANY_EVENT = ESP_EVENT_ANY_ID, - ARDUINO_USB_STARTED_EVENT = 0, - ARDUINO_USB_STOPPED_EVENT, - ARDUINO_USB_SUSPEND_EVENT, - ARDUINO_USB_RESUME_EVENT, - ARDUINO_USB_MAX_EVENT, + ARDUINO_USB_ANY_EVENT = ESP_EVENT_ANY_ID, + ARDUINO_USB_STARTED_EVENT = 0, + ARDUINO_USB_STOPPED_EVENT, + ARDUINO_USB_SUSPEND_EVENT, + ARDUINO_USB_RESUME_EVENT, + ARDUINO_USB_MAX_EVENT, } arduino_usb_event_t; typedef union { - struct { - bool remote_wakeup_en; - } suspend; + struct { + bool remote_wakeup_en; + } suspend; } arduino_usb_event_data_t; class ESPUSB { - public: - ESPUSB(size_t event_task_stack_size=2048, uint8_t event_task_priority=5); - ~ESPUSB(); - - void onEvent(esp_event_handler_t callback); - void onEvent(arduino_usb_event_t event, esp_event_handler_t callback); - - bool VID(uint16_t v); - uint16_t VID(void); - - bool PID(uint16_t p); - uint16_t PID(void); - - bool firmwareVersion(uint16_t version); - uint16_t firmwareVersion(void); - - bool usbVersion(uint16_t version); - uint16_t usbVersion(void); - - bool usbPower(uint16_t mA); - uint16_t usbPower(void); - - bool usbClass(uint8_t _class); - uint8_t usbClass(void); - - bool usbSubClass(uint8_t subClass); - uint8_t usbSubClass(void); - - bool usbProtocol(uint8_t protocol); - uint8_t usbProtocol(void); - - bool usbAttributes(uint8_t attr); - uint8_t usbAttributes(void); - - bool webUSB(bool enabled); - bool webUSB(void); - - bool productName(const char * name); - const char * productName(void); - - bool manufacturerName(const char * name); - const char * manufacturerName(void); - - bool serialNumber(const char * name); - const char * serialNumber(void); - - bool webUSBURL(const char * name); - const char * webUSBURL(void); - - bool enableDFU(); - bool begin(); - operator bool() const; - - private: - uint16_t vid; - uint16_t pid; - String product_name; - String manufacturer_name; - String serial_number; - uint16_t fw_version; - uint16_t usb_version; - uint8_t usb_class; - uint8_t usb_subclass; - uint8_t usb_protocol; - uint8_t usb_attributes; - uint16_t usb_power_ma; - bool webusb_enabled; - String webusb_url; - - bool _started; - size_t _task_stack_size; - uint8_t _event_task_priority; +public: + ESPUSB(size_t event_task_stack_size = 2048, uint8_t event_task_priority = 5); + ~ESPUSB(); + + void onEvent(esp_event_handler_t callback); + void onEvent(arduino_usb_event_t event, esp_event_handler_t callback); + + bool VID(uint16_t v); + uint16_t VID(void); + + bool PID(uint16_t p); + uint16_t PID(void); + + bool firmwareVersion(uint16_t version); + uint16_t firmwareVersion(void); + + bool usbVersion(uint16_t version); + uint16_t usbVersion(void); + + bool usbPower(uint16_t mA); + uint16_t usbPower(void); + + bool usbClass(uint8_t _class); + uint8_t usbClass(void); + + bool usbSubClass(uint8_t subClass); + uint8_t usbSubClass(void); + + bool usbProtocol(uint8_t protocol); + uint8_t usbProtocol(void); + + bool usbAttributes(uint8_t attr); + uint8_t usbAttributes(void); + + bool webUSB(bool enabled); + bool webUSB(void); + + bool productName(const char* name); + const char* productName(void); + + bool manufacturerName(const char* name); + const char* manufacturerName(void); + + bool serialNumber(const char* name); + const char* serialNumber(void); + + bool webUSBURL(const char* name); + const char* webUSBURL(void); + + bool enableDFU(); + bool begin(); + operator bool() const; + +private: + uint16_t vid; + uint16_t pid; + String product_name; + String manufacturer_name; + String serial_number; + uint16_t fw_version; + uint16_t usb_version; + uint8_t usb_class; + uint8_t usb_subclass; + uint8_t usb_protocol; + uint8_t usb_attributes; + uint16_t usb_power_ma; + bool webusb_enabled; + String webusb_url; + + bool _started; + size_t _task_stack_size; + uint8_t _event_task_priority; }; extern ESPUSB USB; diff --git a/cores/esp32/USBCDC.cpp b/cores/esp32/USBCDC.cpp index 85eb5f77855..ed96ce67d9d 100644 --- a/cores/esp32/USBCDC.cpp +++ b/cores/esp32/USBCDC.cpp @@ -27,435 +27,407 @@ esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg); #define MAX_USB_CDC_DEVICES 2 -USBCDC * devices[MAX_USB_CDC_DEVICES] = {NULL, NULL}; +USBCDC *devices[MAX_USB_CDC_DEVICES] = { NULL, NULL }; -static uint16_t load_cdc_descriptor(uint8_t * dst, uint8_t * itf) -{ - uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB CDC"); - uint8_t descriptor[TUD_CDC_DESC_LEN] = { - // Interface number, string index, EP notification address and size, EP data address (out, in) and size. - TUD_CDC_DESCRIPTOR(*itf, str_index, 0x85, 64, 0x03, 0x84, 64) - }; - *itf+=2; - memcpy(dst, descriptor, TUD_CDC_DESC_LEN); - return TUD_CDC_DESC_LEN; +static uint16_t load_cdc_descriptor(uint8_t *dst, uint8_t *itf) { + uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB CDC"); + uint8_t descriptor[TUD_CDC_DESC_LEN] = { + // Interface number, string index, EP notification address and size, EP data address (out, in) and size. + TUD_CDC_DESCRIPTOR(*itf, str_index, 0x85, 64, 0x03, 0x84, 64) + }; + *itf += 2; + memcpy(dst, descriptor, TUD_CDC_DESC_LEN); + return TUD_CDC_DESC_LEN; } // Invoked when line state DTR & RTS are changed via SET_CONTROL_LINE_STATE -void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) -{ - if(itf < MAX_USB_CDC_DEVICES && devices[itf] != NULL){ - devices[itf]->_onLineState(dtr, rts); - } +void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) { + if (itf < MAX_USB_CDC_DEVICES && devices[itf] != NULL) { + devices[itf]->_onLineState(dtr, rts); + } } // Invoked when line coding is change via SET_LINE_CODING -void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding) -{ - if(itf < MAX_USB_CDC_DEVICES && devices[itf] != NULL){ - devices[itf]->_onLineCoding(p_line_coding->bit_rate, p_line_coding->stop_bits, p_line_coding->parity, p_line_coding->data_bits); - } +void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const *p_line_coding) { + if (itf < MAX_USB_CDC_DEVICES && devices[itf] != NULL) { + devices[itf]->_onLineCoding(p_line_coding->bit_rate, p_line_coding->stop_bits, p_line_coding->parity, p_line_coding->data_bits); + } } // Invoked when received new data -void tud_cdc_rx_cb(uint8_t itf) -{ - if(itf < MAX_USB_CDC_DEVICES && devices[itf] != NULL){ - devices[itf]->_onRX(); - } +void tud_cdc_rx_cb(uint8_t itf) { + if (itf < MAX_USB_CDC_DEVICES && devices[itf] != NULL) { + devices[itf]->_onRX(); + } } // Invoked when received send break -void tud_cdc_send_break_cb(uint8_t itf, uint16_t duration_ms){ - //log_v("itf: %u, duration_ms: %u", itf, duration_ms); +void tud_cdc_send_break_cb(uint8_t itf, uint16_t duration_ms) { + //log_v("itf: %u, duration_ms: %u", itf, duration_ms); } // Invoked when space becomes available in TX buffer -void tud_cdc_tx_complete_cb(uint8_t itf){ - if(itf < MAX_USB_CDC_DEVICES && devices[itf] != NULL){ - devices[itf]->_onTX(); - } +void tud_cdc_tx_complete_cb(uint8_t itf) { + if (itf < MAX_USB_CDC_DEVICES && devices[itf] != NULL) { + devices[itf]->_onTX(); + } } -static void ARDUINO_ISR_ATTR cdc0_write_char(char c){ - if(devices[0] != NULL){ - tud_cdc_n_write_char(0, c); - } +static void ARDUINO_ISR_ATTR cdc0_write_char(char c) { + if (devices[0] != NULL) { + tud_cdc_n_write_char(0, c); + } } -static void usb_unplugged_cb(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data){ - ((USBCDC*)arg)->_onUnplugged(); -} - -USBCDC::USBCDC(uint8_t itfn) -: itf(itfn) -, bit_rate(0) -, stop_bits(0) -, parity(0) -, data_bits(0) -, dtr(false) -, rts(false) -, connected(false) -, reboot_enable(true) -, rx_queue(NULL) -, tx_lock(NULL) -, tx_timeout_ms(250) -{ - tinyusb_enable_interface(USB_INTERFACE_CDC, TUD_CDC_DESC_LEN, load_cdc_descriptor); - if(itf < MAX_USB_CDC_DEVICES){ - arduino_usb_event_handler_register_with(ARDUINO_USB_EVENTS, ARDUINO_USB_STOPPED_EVENT, usb_unplugged_cb, this); - } +static void usb_unplugged_cb(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { + ((USBCDC *)arg)->_onUnplugged(); +} + +USBCDC::USBCDC(uint8_t itfn) + : itf(itfn), bit_rate(0), stop_bits(0), parity(0), data_bits(0), dtr(false), rts(false), connected(false), reboot_enable(true), rx_queue(NULL), tx_lock(NULL), tx_timeout_ms(250) { + tinyusb_enable_interface(USB_INTERFACE_CDC, TUD_CDC_DESC_LEN, load_cdc_descriptor); + if (itf < MAX_USB_CDC_DEVICES) { + arduino_usb_event_handler_register_with(ARDUINO_USB_EVENTS, ARDUINO_USB_STOPPED_EVENT, usb_unplugged_cb, this); + } } -USBCDC::~USBCDC(){ - end(); +USBCDC::~USBCDC() { + end(); } -void USBCDC::onEvent(esp_event_handler_t callback){ - onEvent(ARDUINO_USB_CDC_ANY_EVENT, callback); +void USBCDC::onEvent(esp_event_handler_t callback) { + onEvent(ARDUINO_USB_CDC_ANY_EVENT, callback); } -void USBCDC::onEvent(arduino_usb_cdc_event_t event, esp_event_handler_t callback){ - arduino_usb_event_handler_register_with(ARDUINO_USB_CDC_EVENTS, event, callback, this); +void USBCDC::onEvent(arduino_usb_cdc_event_t event, esp_event_handler_t callback) { + arduino_usb_event_handler_register_with(ARDUINO_USB_CDC_EVENTS, event, callback, this); } -size_t USBCDC::setRxBufferSize(size_t rx_queue_len){ - size_t currentQueueSize = rx_queue ? - uxQueueSpacesAvailable(rx_queue) + uxQueueMessagesWaiting(rx_queue) : 0; +size_t USBCDC::setRxBufferSize(size_t rx_queue_len) { + size_t currentQueueSize = rx_queue ? uxQueueSpacesAvailable(rx_queue) + uxQueueMessagesWaiting(rx_queue) : 0; - if (rx_queue_len != currentQueueSize) { - QueueHandle_t new_rx_queue = NULL; - if (rx_queue_len) { - new_rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t)); - if(!new_rx_queue){ - log_e("CDC Queue creation failed."); - return 0; - } - if (rx_queue) { - size_t copySize = uxQueueMessagesWaiting(rx_queue); - if (copySize > 0) { - for(size_t i = 0; i < copySize; i++) { - uint8_t ch = 0; - xQueueReceive(rx_queue, &ch, 0); - if (!xQueueSend(new_rx_queue, &ch, 0)) { - arduino_usb_cdc_event_data_t p; - p.rx_overflow.dropped_bytes = copySize - i; - arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_RX_OVERFLOW_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY); - log_e("CDC RX Overflow."); - break; - } - } - } - vQueueDelete(rx_queue); - } - rx_queue = new_rx_queue; - return rx_queue_len; - } else { - if (rx_queue) { - vQueueDelete(rx_queue); - rx_queue = NULL; + if (rx_queue_len != currentQueueSize) { + QueueHandle_t new_rx_queue = NULL; + if (rx_queue_len) { + new_rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t)); + if (!new_rx_queue) { + log_e("CDC Queue creation failed."); + return 0; + } + if (rx_queue) { + size_t copySize = uxQueueMessagesWaiting(rx_queue); + if (copySize > 0) { + for (size_t i = 0; i < copySize; i++) { + uint8_t ch = 0; + xQueueReceive(rx_queue, &ch, 0); + if (!xQueueSend(new_rx_queue, &ch, 0)) { + arduino_usb_cdc_event_data_t p; + p.rx_overflow.dropped_bytes = copySize - i; + arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_RX_OVERFLOW_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY); + log_e("CDC RX Overflow."); + break; } + } } + vQueueDelete(rx_queue); + } + rx_queue = new_rx_queue; + return rx_queue_len; + } else { + if (rx_queue) { + vQueueDelete(rx_queue); + rx_queue = NULL; + } } - return rx_queue_len; -} - -void USBCDC::begin(unsigned long baud) -{ - if(tx_lock == NULL) { - tx_lock = xSemaphoreCreateMutex(); - } - // if rx_queue was set before begin(), keep it - if (!rx_queue) setRxBufferSize(256); //default if not preset - devices[itf] = this; + } + return rx_queue_len; } -void USBCDC::end() -{ - connected = false; - devices[itf] = NULL; - setRxBufferSize(0); - if(tx_lock != NULL) { - vSemaphoreDelete(tx_lock); - tx_lock = NULL; - } +void USBCDC::begin(unsigned long baud) { + if (tx_lock == NULL) { + tx_lock = xSemaphoreCreateMutex(); + } + // if rx_queue was set before begin(), keep it + if (!rx_queue) setRxBufferSize(256); //default if not preset + devices[itf] = this; } -void USBCDC::setTxTimeoutMs(uint32_t timeout){ - tx_timeout_ms = timeout; +void USBCDC::end() { + connected = false; + devices[itf] = NULL; + setRxBufferSize(0); + if (tx_lock != NULL) { + vSemaphoreDelete(tx_lock); + tx_lock = NULL; + } } -void USBCDC::_onUnplugged(void){ - if(connected){ - connected = false; - dtr = false; - rts = false; - arduino_usb_cdc_event_data_t p; - arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_DISCONNECTED_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY); - } +void USBCDC::setTxTimeoutMs(uint32_t timeout) { + tx_timeout_ms = timeout; } -enum { CDC_LINE_IDLE, CDC_LINE_1, CDC_LINE_2, CDC_LINE_3 }; -void USBCDC::_onLineState(bool _dtr, bool _rts){ - static uint8_t lineState = CDC_LINE_IDLE; - - if(dtr == _dtr && rts == _rts){ - return; // Skip duplicate events - } - - dtr = _dtr; - rts = _rts; - - if(reboot_enable){ - if(!dtr && rts){ - if(lineState == CDC_LINE_IDLE){ - lineState++; - if(connected){ - connected = false; - arduino_usb_cdc_event_data_t p; - arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_DISCONNECTED_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY); - } - // } else if(lineState == CDC_LINE_2){//esptool.js - // lineState++; - } else { - lineState = CDC_LINE_IDLE; - } - } else if(dtr && rts){ - if(lineState == CDC_LINE_1){ - lineState++; - } else { - lineState = CDC_LINE_IDLE; - } - } else if(dtr && !rts){ - if(lineState == CDC_LINE_2){ - lineState++; - // } else if(lineState == CDC_LINE_IDLE){//esptool.js - // lineState++; - } else { - lineState = CDC_LINE_IDLE; - } - } else if(!dtr && !rts){ - if(lineState == CDC_LINE_3){ - usb_persist_restart(RESTART_BOOTLOADER); - } else { - lineState = CDC_LINE_IDLE; - } - } - } - - if(lineState == CDC_LINE_IDLE){ - if(dtr && rts && !connected){ - connected = true; - arduino_usb_cdc_event_data_t p; - arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_CONNECTED_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY); - } else if(!dtr && connected){ - connected = false; - arduino_usb_cdc_event_data_t p; - arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_DISCONNECTED_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY); - } - arduino_usb_cdc_event_data_t l; - l.line_state.dtr = dtr; - l.line_state.rts = rts; - arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_LINE_STATE_EVENT, &l, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY); - } - -} - -void USBCDC::_onLineCoding(uint32_t _bit_rate, uint8_t _stop_bits, uint8_t _parity, uint8_t _data_bits){ - if(bit_rate != _bit_rate || data_bits != _data_bits || stop_bits != _stop_bits || parity != _parity){ - // ArduinoIDE sends LineCoding with 1200bps baud to reset the device - if(reboot_enable && _bit_rate == 1200){ - usb_persist_restart(RESTART_BOOTLOADER); - } else { - bit_rate = _bit_rate; - data_bits = _data_bits; - stop_bits = _stop_bits; - parity = _parity; - arduino_usb_cdc_event_data_t p; - p.line_coding.bit_rate = bit_rate; - p.line_coding.data_bits = data_bits; - p.line_coding.stop_bits = stop_bits; - p.line_coding.parity = parity; - arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_LINE_CODING_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY); +void USBCDC::_onUnplugged(void) { + if (connected) { + connected = false; + dtr = false; + rts = false; + arduino_usb_cdc_event_data_t p; + arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_DISCONNECTED_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY); + } +} + +enum { CDC_LINE_IDLE, + CDC_LINE_1, + CDC_LINE_2, + CDC_LINE_3 }; +void USBCDC::_onLineState(bool _dtr, bool _rts) { + static uint8_t lineState = CDC_LINE_IDLE; + + if (dtr == _dtr && rts == _rts) { + return; // Skip duplicate events + } + + dtr = _dtr; + rts = _rts; + + if (reboot_enable) { + if (!dtr && rts) { + if (lineState == CDC_LINE_IDLE) { + lineState++; + if (connected) { + connected = false; + arduino_usb_cdc_event_data_t p; + arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_DISCONNECTED_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY); } + // } else if(lineState == CDC_LINE_2){//esptool.js + // lineState++; + } else { + lineState = CDC_LINE_IDLE; + } + } else if (dtr && rts) { + if (lineState == CDC_LINE_1) { + lineState++; + } else { + lineState = CDC_LINE_IDLE; + } + } else if (dtr && !rts) { + if (lineState == CDC_LINE_2) { + lineState++; + // } else if(lineState == CDC_LINE_IDLE){//esptool.js + // lineState++; + } else { + lineState = CDC_LINE_IDLE; + } + } else if (!dtr && !rts) { + if (lineState == CDC_LINE_3) { + usb_persist_restart(RESTART_BOOTLOADER); + } else { + lineState = CDC_LINE_IDLE; + } + } + } + + if (lineState == CDC_LINE_IDLE) { + if (dtr && rts && !connected) { + connected = true; + arduino_usb_cdc_event_data_t p; + arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_CONNECTED_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY); + } else if (!dtr && connected) { + connected = false; + arduino_usb_cdc_event_data_t p; + arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_DISCONNECTED_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY); + } + arduino_usb_cdc_event_data_t l; + l.line_state.dtr = dtr; + l.line_state.rts = rts; + arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_LINE_STATE_EVENT, &l, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY); + } +} + +void USBCDC::_onLineCoding(uint32_t _bit_rate, uint8_t _stop_bits, uint8_t _parity, uint8_t _data_bits) { + if (bit_rate != _bit_rate || data_bits != _data_bits || stop_bits != _stop_bits || parity != _parity) { + // ArduinoIDE sends LineCoding with 1200bps baud to reset the device + if (reboot_enable && _bit_rate == 1200) { + usb_persist_restart(RESTART_BOOTLOADER); + } else { + bit_rate = _bit_rate; + data_bits = _data_bits; + stop_bits = _stop_bits; + parity = _parity; + arduino_usb_cdc_event_data_t p; + p.line_coding.bit_rate = bit_rate; + p.line_coding.data_bits = data_bits; + p.line_coding.stop_bits = stop_bits; + p.line_coding.parity = parity; + arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_LINE_CODING_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY); } + } } -void USBCDC::_onRX(){ - arduino_usb_cdc_event_data_t p; - uint8_t buf[CONFIG_TINYUSB_CDC_RX_BUFSIZE+1]; - uint32_t count = tud_cdc_n_read(itf, buf, CONFIG_TINYUSB_CDC_RX_BUFSIZE); - for(uint32_t i=0; i= MAX_USB_CDC_DEVICES || rx_queue == NULL){ - return -1; - } - return uxQueueMessagesWaiting(rx_queue); -} - -int USBCDC::peek(void) -{ - if(itf >= MAX_USB_CDC_DEVICES || rx_queue == NULL){ - return -1; - } - uint8_t c; - if(xQueuePeek(rx_queue, &c, 0)) { - return c; - } +int USBCDC::available(void) { + if (itf >= MAX_USB_CDC_DEVICES || rx_queue == NULL) { return -1; + } + return uxQueueMessagesWaiting(rx_queue); } -int USBCDC::read(void) -{ - if(itf >= MAX_USB_CDC_DEVICES || rx_queue == NULL){ - return -1; - } - uint8_t c = 0; - if(xQueueReceive(rx_queue, &c, 0)) { - return c; - } +int USBCDC::peek(void) { + if (itf >= MAX_USB_CDC_DEVICES || rx_queue == NULL) { return -1; + } + uint8_t c; + if (xQueuePeek(rx_queue, &c, 0)) { + return c; + } + return -1; } -size_t USBCDC::read(uint8_t *buffer, size_t size) -{ - if(itf >= MAX_USB_CDC_DEVICES || rx_queue == NULL){ - return -1; - } - uint8_t c = 0; - size_t count = 0; - while(count < size && xQueueReceive(rx_queue, &c, 0)){ - buffer[count++] = c; - } - return count; -} - -void USBCDC::flush(void) -{ - if(itf >= MAX_USB_CDC_DEVICES || tx_lock == NULL || !tud_cdc_n_connected(itf)){ - return; - } - if(xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS){ - return; - } - tud_cdc_n_write_flush(itf); - xSemaphoreGive(tx_lock); -} - -int USBCDC::availableForWrite(void) -{ - if(itf >= MAX_USB_CDC_DEVICES || tx_lock == NULL || !tud_cdc_n_connected(itf)){ - return 0; - } - if(xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS){ - return 0; - } - size_t a = tud_cdc_n_write_available(itf); - xSemaphoreGive(tx_lock); - return a; +int USBCDC::read(void) { + if (itf >= MAX_USB_CDC_DEVICES || rx_queue == NULL) { + return -1; + } + uint8_t c = 0; + if (xQueueReceive(rx_queue, &c, 0)) { + return c; + } + return -1; } -size_t USBCDC::write(const uint8_t *buffer, size_t size) -{ - if(itf >= MAX_USB_CDC_DEVICES || tx_lock == NULL || buffer == NULL || size == 0 || !tud_cdc_n_connected(itf)){ - return 0; - } - if(xPortInIsrContext()){ - BaseType_t taskWoken = false; - if(xSemaphoreTakeFromISR(tx_lock, &taskWoken) != pdPASS){ - return 0; - } - } else if(xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS){ - return 0; - } - size_t to_send = size, so_far = 0; - while(to_send){ - if(!tud_cdc_n_connected(itf)){ - size = so_far; - break; - } - size_t space = tud_cdc_n_write_available(itf); - if(!space){ - tud_cdc_n_write_flush(itf); - continue; - } - if(space > to_send){ - space = to_send; - } - size_t sent = tud_cdc_n_write(itf, buffer+so_far, space); - if(sent){ - so_far += sent; - to_send -= sent; - tud_cdc_n_write_flush(itf); - } else { - size = so_far; - break; - } - } - if(xPortInIsrContext()){ - BaseType_t taskWoken = false; - xSemaphoreGiveFromISR(tx_lock, &taskWoken); +size_t USBCDC::read(uint8_t *buffer, size_t size) { + if (itf >= MAX_USB_CDC_DEVICES || rx_queue == NULL) { + return -1; + } + uint8_t c = 0; + size_t count = 0; + while (count < size && xQueueReceive(rx_queue, &c, 0)) { + buffer[count++] = c; + } + return count; +} + +void USBCDC::flush(void) { + if (itf >= MAX_USB_CDC_DEVICES || tx_lock == NULL || !tud_cdc_n_connected(itf)) { + return; + } + if (xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS) { + return; + } + tud_cdc_n_write_flush(itf); + xSemaphoreGive(tx_lock); +} + +int USBCDC::availableForWrite(void) { + if (itf >= MAX_USB_CDC_DEVICES || tx_lock == NULL || !tud_cdc_n_connected(itf)) { + return 0; + } + if (xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS) { + return 0; + } + size_t a = tud_cdc_n_write_available(itf); + xSemaphoreGive(tx_lock); + return a; +} + +size_t USBCDC::write(const uint8_t *buffer, size_t size) { + if (itf >= MAX_USB_CDC_DEVICES || tx_lock == NULL || buffer == NULL || size == 0 || !tud_cdc_n_connected(itf)) { + return 0; + } + if (xPortInIsrContext()) { + BaseType_t taskWoken = false; + if (xSemaphoreTakeFromISR(tx_lock, &taskWoken) != pdPASS) { + return 0; + } + } else if (xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS) { + return 0; + } + size_t to_send = size, so_far = 0; + while (to_send) { + if (!tud_cdc_n_connected(itf)) { + size = so_far; + break; + } + size_t space = tud_cdc_n_write_available(itf); + if (!space) { + tud_cdc_n_write_flush(itf); + continue; + } + if (space > to_send) { + space = to_send; + } + size_t sent = tud_cdc_n_write(itf, buffer + so_far, space); + if (sent) { + so_far += sent; + to_send -= sent; + tud_cdc_n_write_flush(itf); } else { - xSemaphoreGive(tx_lock); - } - return size; + size = so_far; + break; + } + } + if (xPortInIsrContext()) { + BaseType_t taskWoken = false; + xSemaphoreGiveFromISR(tx_lock, &taskWoken); + } else { + xSemaphoreGive(tx_lock); + } + return size; } -size_t USBCDC::write(uint8_t c) -{ - return write(&c, 1); +size_t USBCDC::write(uint8_t c) { + return write(&c, 1); } -uint32_t USBCDC::baudRate() -{ - return bit_rate; +uint32_t USBCDC::baudRate() { + return bit_rate; } -void USBCDC::setDebugOutput(bool en) -{ - if(en) { - uartSetDebug(NULL); - ets_install_putc1((void (*)(char)) &cdc0_write_char); - } else { - ets_install_putc1(NULL); - } +void USBCDC::setDebugOutput(bool en) { + if (en) { + uartSetDebug(NULL); + ets_install_putc1((void (*)(char)) & cdc0_write_char); + } else { + ets_install_putc1(NULL); + } } -USBCDC::operator bool() const -{ - if(itf >= MAX_USB_CDC_DEVICES){ - return false; - } - return connected; +USBCDC::operator bool() const { + if (itf >= MAX_USB_CDC_DEVICES) { + return false; + } + return connected; } -#if !ARDUINO_USB_MODE && ARDUINO_USB_CDC_ON_BOOT // Native USB CDC selected +#if !ARDUINO_USB_MODE && ARDUINO_USB_CDC_ON_BOOT // Native USB CDC selected // USBSerial is always available to be used USBCDC USBSerial(0); #endif diff --git a/cores/esp32/USBCDC.h b/cores/esp32/USBCDC.h index 17c782671b2..17fd0cf6be1 100644 --- a/cores/esp32/USBCDC.h +++ b/cores/esp32/USBCDC.h @@ -29,122 +29,113 @@ ESP_EVENT_DECLARE_BASE(ARDUINO_USB_CDC_EVENTS); typedef enum { - ARDUINO_USB_CDC_ANY_EVENT = ESP_EVENT_ANY_ID, - ARDUINO_USB_CDC_CONNECTED_EVENT = 0, - ARDUINO_USB_CDC_DISCONNECTED_EVENT, - ARDUINO_USB_CDC_LINE_STATE_EVENT, - ARDUINO_USB_CDC_LINE_CODING_EVENT, - ARDUINO_USB_CDC_RX_EVENT, - ARDUINO_USB_CDC_TX_EVENT, - ARDUINO_USB_CDC_RX_OVERFLOW_EVENT, - ARDUINO_USB_CDC_MAX_EVENT, + ARDUINO_USB_CDC_ANY_EVENT = ESP_EVENT_ANY_ID, + ARDUINO_USB_CDC_CONNECTED_EVENT = 0, + ARDUINO_USB_CDC_DISCONNECTED_EVENT, + ARDUINO_USB_CDC_LINE_STATE_EVENT, + ARDUINO_USB_CDC_LINE_CODING_EVENT, + ARDUINO_USB_CDC_RX_EVENT, + ARDUINO_USB_CDC_TX_EVENT, + ARDUINO_USB_CDC_RX_OVERFLOW_EVENT, + ARDUINO_USB_CDC_MAX_EVENT, } arduino_usb_cdc_event_t; typedef union { - struct { - bool dtr; - bool rts; - } line_state; - struct { - uint32_t bit_rate; - uint8_t stop_bits; ///< 0: 1 stop bit - 1: 1.5 stop bits - 2: 2 stop bits - uint8_t parity; ///< 0: None - 1: Odd - 2: Even - 3: Mark - 4: Space - uint8_t data_bits; ///< can be 5, 6, 7, 8 or 16 - } line_coding; - struct { - size_t len; - } rx; - struct { - size_t dropped_bytes; - } rx_overflow; + struct { + bool dtr; + bool rts; + } line_state; + struct { + uint32_t bit_rate; + uint8_t stop_bits; ///< 0: 1 stop bit - 1: 1.5 stop bits - 2: 2 stop bits + uint8_t parity; ///< 0: None - 1: Odd - 2: Even - 3: Mark - 4: Space + uint8_t data_bits; ///< can be 5, 6, 7, 8 or 16 + } line_coding; + struct { + size_t len; + } rx; + struct { + size_t dropped_bytes; + } rx_overflow; } arduino_usb_cdc_event_data_t; -class USBCDC: public Stream -{ +class USBCDC : public Stream { public: - USBCDC(uint8_t itf=0); - ~USBCDC(); - - void onEvent(esp_event_handler_t callback); - void onEvent(arduino_usb_cdc_event_t event, esp_event_handler_t callback); - - size_t setRxBufferSize(size_t size); - void setTxTimeoutMs(uint32_t timeout); - void begin(unsigned long baud=0); - void end(); - - int available(void); - int availableForWrite(void); - int peek(void); - int read(void); - size_t read(uint8_t *buffer, size_t size); - size_t write(uint8_t); - size_t write(const uint8_t *buffer, size_t size); - void flush(void); - - inline size_t read(char * buffer, size_t size) - { - return read((uint8_t*) buffer, size); - } - inline size_t write(const char * buffer, size_t size) - { - return write((uint8_t*) buffer, size); - } - inline size_t write(const char * s) - { - return write((uint8_t*) s, strlen(s)); - } - inline size_t write(unsigned long n) - { - return write((uint8_t) n); - } - inline size_t write(long n) - { - return write((uint8_t) n); - } - inline size_t write(unsigned int n) - { - return write((uint8_t) n); - } - inline size_t write(int n) - { - return write((uint8_t) n); - } - uint32_t baudRate(); - void setDebugOutput(bool); - operator bool() const; - - void enableReboot(bool enable); - bool rebootEnabled(void); - - //internal methods - void _onDFU(void); - void _onLineState(bool _dtr, bool _rts); - void _onLineCoding(uint32_t _bit_rate, uint8_t _stop_bits, uint8_t _parity, uint8_t _data_bits); - void _onRX(void); - void _onTX(void); - void _onUnplugged(void); - + USBCDC(uint8_t itf = 0); + ~USBCDC(); + + void onEvent(esp_event_handler_t callback); + void onEvent(arduino_usb_cdc_event_t event, esp_event_handler_t callback); + + size_t setRxBufferSize(size_t size); + void setTxTimeoutMs(uint32_t timeout); + void begin(unsigned long baud = 0); + void end(); + + int available(void); + int availableForWrite(void); + int peek(void); + int read(void); + size_t read(uint8_t *buffer, size_t size); + size_t write(uint8_t); + size_t write(const uint8_t *buffer, size_t size); + void flush(void); + + inline size_t read(char *buffer, size_t size) { + return read((uint8_t *)buffer, size); + } + inline size_t write(const char *buffer, size_t size) { + return write((uint8_t *)buffer, size); + } + inline size_t write(const char *s) { + return write((uint8_t *)s, strlen(s)); + } + inline size_t write(unsigned long n) { + return write((uint8_t)n); + } + inline size_t write(long n) { + return write((uint8_t)n); + } + inline size_t write(unsigned int n) { + return write((uint8_t)n); + } + inline size_t write(int n) { + return write((uint8_t)n); + } + uint32_t baudRate(); + void setDebugOutput(bool); + operator bool() const; + + void enableReboot(bool enable); + bool rebootEnabled(void); + + //internal methods + void _onDFU(void); + void _onLineState(bool _dtr, bool _rts); + void _onLineCoding(uint32_t _bit_rate, uint8_t _stop_bits, uint8_t _parity, uint8_t _data_bits); + void _onRX(void); + void _onTX(void); + void _onUnplugged(void); + protected: - uint8_t itf; - uint32_t bit_rate; - uint8_t stop_bits; ///< 0: 1 stop bit - 1: 1.5 stop bits - 2: 2 stop bits - uint8_t parity; ///< 0: None - 1: Odd - 2: Even - 3: Mark - 4: Space - uint8_t data_bits; ///< can be 5, 6, 7, 8 or 16 - bool dtr; - bool rts; - bool connected; - bool reboot_enable; - QueueHandle_t rx_queue; - SemaphoreHandle_t tx_lock; - uint32_t tx_timeout_ms; - + uint8_t itf; + uint32_t bit_rate; + uint8_t stop_bits; ///< 0: 1 stop bit - 1: 1.5 stop bits - 2: 2 stop bits + uint8_t parity; ///< 0: None - 1: Odd - 2: Even - 3: Mark - 4: Space + uint8_t data_bits; ///< can be 5, 6, 7, 8 or 16 + bool dtr; + bool rts; + bool connected; + bool reboot_enable; + QueueHandle_t rx_queue; + SemaphoreHandle_t tx_lock; + uint32_t tx_timeout_ms; }; -#if !ARDUINO_USB_MODE && ARDUINO_USB_CDC_ON_BOOT // Native USB CDC selected +#if !ARDUINO_USB_MODE && ARDUINO_USB_CDC_ON_BOOT // Native USB CDC selected #ifndef USB_SERIAL_IS_DEFINED #define USB_SERIAL_IS_DEFINED 1 -#endif +#endif // USBSerial is always available to be used extern USBCDC USBSerial; #endif diff --git a/cores/esp32/USBMSC.cpp b/cores/esp32/USBMSC.cpp index 8b615d94c70..ab348585e1d 100644 --- a/cores/esp32/USBMSC.cpp +++ b/cores/esp32/USBMSC.cpp @@ -19,207 +19,169 @@ #include "esp32-hal-tinyusb.h" -extern "C" uint16_t tusb_msc_load_descriptor(uint8_t * dst, uint8_t * itf) -{ - uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB MSC"); - uint8_t ep_num = tinyusb_get_free_duplex_endpoint(); - TU_VERIFY (ep_num != 0); - uint8_t descriptor[TUD_MSC_DESC_LEN] = { - // Interface number, string index, EP Out & EP In address, EP size - TUD_MSC_DESCRIPTOR(*itf, str_index, ep_num, (uint8_t)(0x80 | ep_num), 64) - }; - *itf+=1; - memcpy(dst, descriptor, TUD_MSC_DESC_LEN); - return TUD_MSC_DESC_LEN; +extern "C" uint16_t tusb_msc_load_descriptor(uint8_t* dst, uint8_t* itf) { + uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB MSC"); + uint8_t ep_num = tinyusb_get_free_duplex_endpoint(); + TU_VERIFY(ep_num != 0); + uint8_t descriptor[TUD_MSC_DESC_LEN] = { + // Interface number, string index, EP Out & EP In address, EP size + TUD_MSC_DESCRIPTOR(*itf, str_index, ep_num, (uint8_t)(0x80 | ep_num), 64) + }; + *itf += 1; + memcpy(dst, descriptor, TUD_MSC_DESC_LEN); + return TUD_MSC_DESC_LEN; } typedef struct { - bool media_present; - uint8_t vendor_id[8]; - uint8_t product_id[16]; - uint8_t product_rev[4]; - uint16_t block_size; - uint32_t block_count; - bool (*start_stop)(uint8_t power_condition, bool start, bool load_eject); - int32_t (*read)(uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize); - int32_t (*write)(uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize); + bool media_present; + uint8_t vendor_id[8]; + uint8_t product_id[16]; + uint8_t product_rev[4]; + uint16_t block_size; + uint32_t block_count; + bool (*start_stop)(uint8_t power_condition, bool start, bool load_eject); + int32_t (*read)(uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize); + int32_t (*write)(uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize); } msc_lun_t; static const uint8_t MSC_MAX_LUN = 3; static uint8_t MSC_ACTIVE_LUN = 0; static msc_lun_t msc_luns[MSC_MAX_LUN]; -static void cplstr(void *dst, const void * src, size_t max_len){ - if(!src || !dst || !max_len){ - return; - } - size_t l = strlen((const char *)src); - if(l > max_len){ - l = max_len; - } - memcpy(dst, src, l); +static void cplstr(void* dst, const void* src, size_t max_len) { + if (!src || !dst || !max_len) { + return; + } + size_t l = strlen((const char*)src); + if (l > max_len) { + l = max_len; + } + memcpy(dst, src, l); } // Invoked when received GET_MAX_LUN request, required for multiple LUNs implementation -uint8_t tud_msc_get_maxlun_cb(void) -{ - log_v("%u", MSC_ACTIVE_LUN); - return MSC_ACTIVE_LUN; +uint8_t tud_msc_get_maxlun_cb(void) { + log_v("%u", MSC_ACTIVE_LUN); + return MSC_ACTIVE_LUN; } // Invoked when received SCSI_CMD_INQUIRY // Application fill vendor id, product id and revision with string up to 8, 16, 4 characters respectively -void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]) -{ - log_v("[%u]", lun); - cplstr(vendor_id , msc_luns[lun].vendor_id, 8); - cplstr(product_id , msc_luns[lun].product_id, 16); - cplstr(product_rev, msc_luns[lun].product_rev, 4); +void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]) { + log_v("[%u]", lun); + cplstr(vendor_id, msc_luns[lun].vendor_id, 8); + cplstr(product_id, msc_luns[lun].product_id, 16); + cplstr(product_rev, msc_luns[lun].product_rev, 4); } // Invoked when received Test Unit Ready command. // return true allowing host to read/write this LUN e.g SD card inserted -bool tud_msc_test_unit_ready_cb(uint8_t lun) -{ - log_v("[%u]: %u", lun, msc_luns[lun].media_present); - return msc_luns[lun].media_present; // RAM disk is always ready +bool tud_msc_test_unit_ready_cb(uint8_t lun) { + log_v("[%u]: %u", lun, msc_luns[lun].media_present); + return msc_luns[lun].media_present; // RAM disk is always ready } // Invoked when received SCSI_CMD_READ_CAPACITY_10 and SCSI_CMD_READ_FORMAT_CAPACITY to determine the disk size // Application update block count and block size -void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size) -{ - log_v("[%u]", lun); - if(!msc_luns[lun].media_present){ - *block_count = 0; - *block_size = 0; - return; - } +void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size) { + log_v("[%u]", lun); + if (!msc_luns[lun].media_present) { + *block_count = 0; + *block_size = 0; + return; + } - *block_count = msc_luns[lun].block_count; - *block_size = msc_luns[lun].block_size; + *block_count = msc_luns[lun].block_count; + *block_size = msc_luns[lun].block_size; } // Invoked when received Start Stop Unit command // - Start = 0 : stopped power mode, if load_eject = 1 : unload disk storage // - Start = 1 : active mode, if load_eject = 1 : load disk storage -bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject) -{ - log_v("[%u] power: %u, start: %u, eject: %u", lun, power_condition, start, load_eject); - if(msc_luns[lun].start_stop){ - return msc_luns[lun].start_stop(power_condition, start, load_eject); - } - return true; +bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject) { + log_v("[%u] power: %u, start: %u, eject: %u", lun, power_condition, start, load_eject); + if (msc_luns[lun].start_stop) { + return msc_luns[lun].start_stop(power_condition, start, load_eject); + } + return true; } // Callback invoked when received READ10 command. // Copy disk's data to buffer (up to bufsize) and return number of copied bytes. -int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize) -{ - log_v("[%u], lba: %u, offset: %u, bufsize: %u", lun, lba, offset, bufsize); - if(!msc_luns[lun].media_present){ - return 0; - } - if(msc_luns[lun].read){ - return msc_luns[lun].read(lba, offset, buffer, bufsize); - } +int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize) { + log_v("[%u], lba: %u, offset: %u, bufsize: %u", lun, lba, offset, bufsize); + if (!msc_luns[lun].media_present) { return 0; + } + if (msc_luns[lun].read) { + return msc_luns[lun].read(lba, offset, buffer, bufsize); + } + return 0; } // Callback invoked when received WRITE10 command. // Process data in buffer to disk's storage and return number of written bytes -int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize) -{ - log_v("[%u], lba: %u, offset: %u, bufsize: %u", lun, lba, offset, bufsize); - if(!msc_luns[lun].media_present){ - return 0; - } - if(msc_luns[lun].write){ - return msc_luns[lun].write(lba, offset, buffer, bufsize); - } +int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize) { + log_v("[%u], lba: %u, offset: %u, bufsize: %u", lun, lba, offset, bufsize); + if (!msc_luns[lun].media_present) { return 0; + } + if (msc_luns[lun].write) { + return msc_luns[lun].write(lba, offset, buffer, bufsize); + } + return 0; } // Callback invoked when received an SCSI command not in built-in list below // - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE // - READ10 and WRITE10 has their own callbacks -int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize) -{ - // read10 & write10 has their own callback and MUST not be handled here - log_v("[%u] cmd: %u, bufsize: %u", lun, scsi_cmd[0], bufsize); - - void const* response = NULL; - uint16_t resplen = 0; - - // most scsi handled is input - bool in_xfer = true; - - if(!msc_luns[lun].media_present){ - return -1; - } - - switch (scsi_cmd[0]) { - case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL: - // Host is about to read/write etc ... better not to disconnect disk - resplen = 0; - break; - - default: - // Set Sense = Invalid Command Operation - tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00); - - // negative means error -> tinyusb could stall and/or response with failed status - resplen = -1; - break; - } - - // return resplen must not larger than bufsize - if (resplen > bufsize) resplen = bufsize; - - if (response && (resplen > 0)) { - if (in_xfer) { - memcpy(buffer, response, resplen); - } else { - // SCSI output - } - } - - return resplen; -} - -USBMSC::USBMSC(){ - if(MSC_ACTIVE_LUN < MSC_MAX_LUN){ - _lun = MSC_ACTIVE_LUN; - MSC_ACTIVE_LUN++; - msc_luns[_lun].media_present = false; - msc_luns[_lun].vendor_id[0] = 0; - msc_luns[_lun].product_id[0] = 0; - msc_luns[_lun].product_rev[0] = 0; - msc_luns[_lun].block_size = 0; - msc_luns[_lun].block_count = 0; - msc_luns[_lun].start_stop = NULL; - msc_luns[_lun].read = NULL; - msc_luns[_lun].write = NULL; - } - if(_lun == 0){ - tinyusb_enable_interface(USB_INTERFACE_MSC, TUD_MSC_DESC_LEN, tusb_msc_load_descriptor); +int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize) { + // read10 & write10 has their own callback and MUST not be handled here + log_v("[%u] cmd: %u, bufsize: %u", lun, scsi_cmd[0], bufsize); + + void const* response = NULL; + uint16_t resplen = 0; + + // most scsi handled is input + bool in_xfer = true; + + if (!msc_luns[lun].media_present) { + return -1; + } + + switch (scsi_cmd[0]) { + case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL: + // Host is about to read/write etc ... better not to disconnect disk + resplen = 0; + break; + + default: + // Set Sense = Invalid Command Operation + tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00); + + // negative means error -> tinyusb could stall and/or response with failed status + resplen = -1; + break; + } + + // return resplen must not larger than bufsize + if (resplen > bufsize) resplen = bufsize; + + if (response && (resplen > 0)) { + if (in_xfer) { + memcpy(buffer, response, resplen); + } else { + // SCSI output } -} - -USBMSC::~USBMSC(){ - end(); -} + } -bool USBMSC::begin(uint32_t block_count, uint16_t block_size){ - msc_luns[_lun].block_size = block_size; - msc_luns[_lun].block_count = block_count; - if(!msc_luns[_lun].block_size || !msc_luns[_lun].block_count || !msc_luns[_lun].read || !msc_luns[_lun].write){ - return false; - } - return true; + return resplen; } -void USBMSC::end(){ +USBMSC::USBMSC() { + if (MSC_ACTIVE_LUN < MSC_MAX_LUN) { + _lun = MSC_ACTIVE_LUN; + MSC_ACTIVE_LUN++; msc_luns[_lun].media_present = false; msc_luns[_lun].vendor_id[0] = 0; msc_luns[_lun].product_id[0] = 0; @@ -229,34 +191,63 @@ void USBMSC::end(){ msc_luns[_lun].start_stop = NULL; msc_luns[_lun].read = NULL; msc_luns[_lun].write = NULL; + } + if (_lun == 0) { + tinyusb_enable_interface(USB_INTERFACE_MSC, TUD_MSC_DESC_LEN, tusb_msc_load_descriptor); + } +} + +USBMSC::~USBMSC() { + end(); +} + +bool USBMSC::begin(uint32_t block_count, uint16_t block_size) { + msc_luns[_lun].block_size = block_size; + msc_luns[_lun].block_count = block_count; + if (!msc_luns[_lun].block_size || !msc_luns[_lun].block_count || !msc_luns[_lun].read || !msc_luns[_lun].write) { + return false; + } + return true; +} + +void USBMSC::end() { + msc_luns[_lun].media_present = false; + msc_luns[_lun].vendor_id[0] = 0; + msc_luns[_lun].product_id[0] = 0; + msc_luns[_lun].product_rev[0] = 0; + msc_luns[_lun].block_size = 0; + msc_luns[_lun].block_count = 0; + msc_luns[_lun].start_stop = NULL; + msc_luns[_lun].read = NULL; + msc_luns[_lun].write = NULL; } -void USBMSC::vendorID(const char * vid){ - cplstr(msc_luns[_lun].vendor_id, vid, 8); +void USBMSC::vendorID(const char* vid) { + cplstr(msc_luns[_lun].vendor_id, vid, 8); } -void USBMSC::productID(const char * pid){ - cplstr(msc_luns[_lun].product_id, pid, 16); +void USBMSC::productID(const char* pid) { + cplstr(msc_luns[_lun].product_id, pid, 16); } -void USBMSC::productRevision(const char * rev){ - cplstr(msc_luns[_lun].product_rev, rev, 4); +void USBMSC::productRevision(const char* rev) { + cplstr(msc_luns[_lun].product_rev, rev, 4); } -void USBMSC::onStartStop(msc_start_stop_cb cb){ - msc_luns[_lun].start_stop = cb; +void USBMSC::onStartStop(msc_start_stop_cb cb) { + msc_luns[_lun].start_stop = cb; } -void USBMSC::onRead(msc_read_cb cb){ - msc_luns[_lun].read = cb; +void USBMSC::onRead(msc_read_cb cb) { + msc_luns[_lun].read = cb; } -void USBMSC::onWrite(msc_write_cb cb){ - msc_luns[_lun].write = cb; +void USBMSC::onWrite(msc_write_cb cb) { + msc_luns[_lun].write = cb; } -void USBMSC::mediaPresent(bool media_present){ - msc_luns[_lun].media_present = media_present; +void USBMSC::mediaPresent(bool media_present) { + msc_luns[_lun].media_present = media_present; } #endif /* CONFIG_TINYUSB_MSC_ENABLED */ diff --git a/cores/esp32/USBMSC.h b/cores/esp32/USBMSC.h index b21a95543f6..55f37867fc0 100644 --- a/cores/esp32/USBMSC.h +++ b/cores/esp32/USBMSC.h @@ -34,22 +34,21 @@ typedef int32_t (*msc_read_cb)(uint32_t lba, uint32_t offset, void* buffer, uint // Process data in buffer to disk's storage and return number of written bytes typedef int32_t (*msc_write_cb)(uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize); -class USBMSC -{ +class USBMSC { public: - USBMSC(); - ~USBMSC(); - bool begin(uint32_t block_count, uint16_t block_size); - void end(); - void vendorID(const char * vid);//max 8 chars - void productID(const char * pid);//max 16 chars - void productRevision(const char * ver);//max 4 chars - void mediaPresent(bool media_present); - void onStartStop(msc_start_stop_cb cb); - void onRead(msc_read_cb cb); - void onWrite(msc_write_cb cb); + USBMSC(); + ~USBMSC(); + bool begin(uint32_t block_count, uint16_t block_size); + void end(); + void vendorID(const char* vid); //max 8 chars + void productID(const char* pid); //max 16 chars + void productRevision(const char* ver); //max 4 chars + void mediaPresent(bool media_present); + void onStartStop(msc_start_stop_cb cb); + void onRead(msc_read_cb cb); + void onWrite(msc_write_cb cb); private: - uint8_t _lun; + uint8_t _lun; }; #endif /* CONFIG_TINYUSB_MSC_ENABLED */ diff --git a/cores/esp32/Udp.h b/cores/esp32/Udp.h index fd79975eb0a..c806289197b 100644 --- a/cores/esp32/Udp.h +++ b/cores/esp32/Udp.h @@ -38,56 +38,56 @@ #include #include -class UDP: public Stream -{ +class UDP : public Stream { public: - virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use - virtual uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure - virtual void stop() =0; // Finish with the UDP socket + virtual uint8_t begin(uint16_t) = 0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use + virtual uint8_t beginMulticast(IPAddress, uint16_t) { + return 0; + } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure + virtual void stop() = 0; // Finish with the UDP socket - // Sending UDP packets + // Sending UDP packets - // Start building up a packet to send to the remote host specific in ip and port - // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port - virtual int beginPacket(IPAddress ip, uint16_t port) =0; - // Start building up a packet to send to the remote host specific in host and port - // Returns 1 if successful, 0 if there was a problem resolving the hostname or port - virtual int beginPacket(const char *host, uint16_t port) =0; - // Finish off this packet and send it - // Returns 1 if the packet was sent successfully, 0 if there was an error - virtual int endPacket() =0; - // Write a single byte into the packet - virtual size_t write(uint8_t) =0; - // Write size bytes from buffer into the packet - virtual size_t write(const uint8_t *buffer, size_t size) =0; + // Start building up a packet to send to the remote host specific in ip and port + // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port + virtual int beginPacket(IPAddress ip, uint16_t port) = 0; + // Start building up a packet to send to the remote host specific in host and port + // Returns 1 if successful, 0 if there was a problem resolving the hostname or port + virtual int beginPacket(const char* host, uint16_t port) = 0; + // Finish off this packet and send it + // Returns 1 if the packet was sent successfully, 0 if there was an error + virtual int endPacket() = 0; + // Write a single byte into the packet + virtual size_t write(uint8_t) = 0; + // Write size bytes from buffer into the packet + virtual size_t write(const uint8_t* buffer, size_t size) = 0; - // Start processing the next available incoming packet - // Returns the size of the packet in bytes, or 0 if no packets are available - virtual int parsePacket() =0; - // Number of bytes remaining in the current packet - virtual int available() =0; - // Read a single byte from the current packet - virtual int read() =0; - // Read up to len bytes from the current packet and place them into buffer - // Returns the number of bytes read, or 0 if none are available - virtual int read(unsigned char* buffer, size_t len) =0; - // Read up to len characters from the current packet and place them into buffer - // Returns the number of characters read, or 0 if none are available - virtual int read(char* buffer, size_t len) =0; - // Return the next byte from the current packet without moving on to the next byte - virtual int peek() =0; - virtual void flush() =0; // Finish reading the current packet + // Start processing the next available incoming packet + // Returns the size of the packet in bytes, or 0 if no packets are available + virtual int parsePacket() = 0; + // Number of bytes remaining in the current packet + virtual int available() = 0; + // Read a single byte from the current packet + virtual int read() = 0; + // Read up to len bytes from the current packet and place them into buffer + // Returns the number of bytes read, or 0 if none are available + virtual int read(unsigned char* buffer, size_t len) = 0; + // Read up to len characters from the current packet and place them into buffer + // Returns the number of characters read, or 0 if none are available + virtual int read(char* buffer, size_t len) = 0; + // Return the next byte from the current packet without moving on to the next byte + virtual int peek() = 0; + virtual void flush() = 0; // Finish reading the current packet - // Return the IP address of the host who sent the current incoming packet - virtual IPAddress remoteIP() =0; - // Return the port of the host who sent the current incoming packet - virtual uint16_t remotePort() =0; + // Return the IP address of the host who sent the current incoming packet + virtual IPAddress remoteIP() = 0; + // Return the port of the host who sent the current incoming packet + virtual uint16_t remotePort() = 0; protected: - uint8_t* rawIPAddress(IPAddress& addr) - { - return addr.raw_address(); - } + uint8_t* rawIPAddress(IPAddress& addr) { + return addr.raw_address(); + } }; #endif diff --git a/cores/esp32/WCharacter.h b/cores/esp32/WCharacter.h index 53428873421..e75e1f0a670 100644 --- a/cores/esp32/WCharacter.h +++ b/cores/esp32/WCharacter.h @@ -21,8 +21,8 @@ #define Character_h #include -#define isascii(__c) ((unsigned)(__c)<=0177) -#define toascii(__c) ((__c)&0177) +#define isascii(__c) ((unsigned)(__c) <= 0177) +#define toascii(__c) ((__c)&0177) // WCharacter.h prototypes inline boolean isAlphaNumeric(int c) __attribute__((always_inline)); @@ -44,94 +44,80 @@ inline int toUpperCase(int c) __attribute__((always_inline)); // Checks for an alphanumeric character. // It is equivalent to (isalpha(c) || isdigit(c)). -inline boolean isAlphaNumeric(int c) -{ - return (isalnum(c) == 0 ? false : true); +inline boolean isAlphaNumeric(int c) { + return (isalnum(c) == 0 ? false : true); } // Checks for an alphabetic character. // It is equivalent to (isupper(c) || islower(c)). -inline boolean isAlpha(int c) -{ - return (isalpha(c) == 0 ? false : true); +inline boolean isAlpha(int c) { + return (isalpha(c) == 0 ? false : true); } // Checks whether c is a 7-bit unsigned char value // that fits into the ASCII character set. -inline boolean isAscii(int c) -{ - return ( isascii (c) == 0 ? false : true); +inline boolean isAscii(int c) { + return (isascii(c) == 0 ? false : true); } // Checks for a blank character, that is, a space or a tab. -inline boolean isWhitespace(int c) -{ - return (isblank(c) == 0 ? false : true); +inline boolean isWhitespace(int c) { + return (isblank(c) == 0 ? false : true); } // Checks for a control character. -inline boolean isControl(int c) -{ - return (iscntrl(c) == 0 ? false : true); +inline boolean isControl(int c) { + return (iscntrl(c) == 0 ? false : true); } // Checks for a digit (0 through 9). -inline boolean isDigit(int c) -{ - return (isdigit(c) == 0 ? false : true); +inline boolean isDigit(int c) { + return (isdigit(c) == 0 ? false : true); } // Checks for any printable character except space. -inline boolean isGraph(int c) -{ - return (isgraph(c) == 0 ? false : true); +inline boolean isGraph(int c) { + return (isgraph(c) == 0 ? false : true); } // Checks for a lower-case character. -inline boolean isLowerCase(int c) -{ - return (islower(c) == 0 ? false : true); +inline boolean isLowerCase(int c) { + return (islower(c) == 0 ? false : true); } // Checks for any printable character including space. -inline boolean isPrintable(int c) -{ - return (isprint(c) == 0 ? false : true); +inline boolean isPrintable(int c) { + return (isprint(c) == 0 ? false : true); } // Checks for any printable character which is not a space // or an alphanumeric character. -inline boolean isPunct(int c) -{ - return (ispunct(c) == 0 ? false : true); +inline boolean isPunct(int c) { + return (ispunct(c) == 0 ? false : true); } // Checks for white-space characters. For the avr-libc library, // these are: space, formfeed ('\f'), newline ('\n'), carriage // return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). -inline boolean isSpace(int c) -{ - return (isspace(c) == 0 ? false : true); +inline boolean isSpace(int c) { + return (isspace(c) == 0 ? false : true); } // Checks for an uppercase letter. -inline boolean isUpperCase(int c) -{ - return (isupper(c) == 0 ? false : true); +inline boolean isUpperCase(int c) { + return (isupper(c) == 0 ? false : true); } // Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7 // 8 9 a b c d e f A B C D E F. -inline boolean isHexadecimalDigit(int c) -{ - return (isxdigit(c) == 0 ? false : true); +inline boolean isHexadecimalDigit(int c) { + return (isxdigit(c) == 0 ? false : true); } // Converts c to a 7-bit unsigned char value that fits into the // ASCII character set, by clearing the high-order bits. -inline int toAscii(int c) -{ - return toascii(c); +inline int toAscii(int c) { + return toascii(c); } // Warning: @@ -140,15 +126,13 @@ inline int toAscii(int c) // characters. // Converts the letter c to lower case, if possible. -inline int toLowerCase(int c) -{ - return tolower(c); +inline int toLowerCase(int c) { + return tolower(c); } // Converts the letter c to upper case, if possible. -inline int toUpperCase(int c) -{ - return toupper(c); +inline int toUpperCase(int c) { + return toupper(c); } #endif diff --git a/cores/esp32/WMath.cpp b/cores/esp32/WMath.cpp index eb51cb49152..13b736a17e5 100644 --- a/cores/esp32/WMath.cpp +++ b/cores/esp32/WMath.cpp @@ -39,22 +39,19 @@ void useRealRandomGenerator(bool useRandomHW) { } // Calling randomSeed() will force the -// Pseudo Random generator like in +// Pseudo Random generator like in // Arduino mainstream API -void randomSeed(unsigned long seed) -{ - if(seed != 0) { - srand(seed); - s_useRandomHW = false; - } +void randomSeed(unsigned long seed) { + if (seed != 0) { + srand(seed); + s_useRandomHW = false; + } } -long random( long howsmall, long howbig ); -long random( long howbig ) -{ - if ( howbig == 0 ) - { - return 0 ; +long random(long howsmall, long howbig); +long random(long howbig) { + if (howbig == 0) { + return 0; } if (howbig < 0) { return (random(0, -howbig)); @@ -64,32 +61,29 @@ long random( long howbig ) return val % howbig; } -long random(long howsmall, long howbig) -{ - if(howsmall >= howbig) { - return howsmall; - } - long diff = howbig - howsmall; - return random(diff) + howsmall; +long random(long howsmall, long howbig) { + if (howsmall >= howbig) { + return howsmall; + } + long diff = howbig - howsmall; + return random(diff) + howsmall; } long map(long x, long in_min, long in_max, long out_min, long out_max) { - const long run = in_max - in_min; - if(run == 0){ - log_e("map(): Invalid input range, min == max"); - return -1; // AVR returns -1, SAM returns 0 - } - const long rise = out_max - out_min; - const long delta = x - in_min; - return (delta * rise) / run + out_min; + const long run = in_max - in_min; + if (run == 0) { + log_e("map(): Invalid input range, min == max"); + return -1; // AVR returns -1, SAM returns 0 + } + const long rise = out_max - out_min; + const long delta = x - in_min; + return (delta * rise) / run + out_min; } -uint16_t makeWord(uint16_t w) -{ - return w; +uint16_t makeWord(uint16_t w) { + return w; } -uint16_t makeWord(uint8_t h, uint8_t l) -{ - return (h << 8) | l; +uint16_t makeWord(uint8_t h, uint8_t l) { + return (h << 8) | l; } diff --git a/cores/esp32/WString.cpp b/cores/esp32/WString.cpp index 990a2824a51..a236a5f73b9 100644 --- a/cores/esp32/WString.cpp +++ b/cores/esp32/WString.cpp @@ -31,115 +31,115 @@ /*********************************************/ String::String(const char *cstr) { - init(); - if (cstr) - copy(cstr, strlen(cstr)); + init(); + if (cstr) + copy(cstr, strlen(cstr)); } String::String(const char *cstr, unsigned int length) { - init(); - if (cstr) - copy(cstr, length); + init(); + if (cstr) + copy(cstr, length); } String::String(const String &value) { - init(); - *this = value; + init(); + *this = value; } #ifdef __GXX_EXPERIMENTAL_CXX0X__ String::String(String &&rval) { - init(); - move(rval); + init(); + move(rval); } String::String(StringSumHelper &&rval) { - init(); - move(rval); + init(); + move(rval); } #endif String::String(char c) { - init(); - char buf[] = { c, '\0' }; - *this = buf; + init(); + char buf[] = { c, '\0' }; + *this = buf; } String::String(unsigned char value, unsigned char base) { - init(); - char buf[1 + 8 * sizeof(unsigned char)]; - utoa(value, buf, base); - *this = buf; + init(); + char buf[1 + 8 * sizeof(unsigned char)]; + utoa(value, buf, base); + *this = buf; } String::String(int value, unsigned char base) { - init(); - char buf[2 + 8 * sizeof(int)]; - itoa(value, buf, base); - *this = buf; + init(); + char buf[2 + 8 * sizeof(int)]; + itoa(value, buf, base); + *this = buf; } String::String(unsigned int value, unsigned char base) { - init(); - char buf[1 + 8 * sizeof(unsigned int)]; - utoa(value, buf, base); - *this = buf; + init(); + char buf[1 + 8 * sizeof(unsigned int)]; + utoa(value, buf, base); + *this = buf; } String::String(long value, unsigned char base) { - init(); - char buf[2 + 8 * sizeof(long)]; - ltoa(value, buf, base); - *this = buf; + init(); + char buf[2 + 8 * sizeof(long)]; + ltoa(value, buf, base); + *this = buf; } String::String(unsigned long value, unsigned char base) { - init(); - char buf[1 + 8 * sizeof(unsigned long)]; - ultoa(value, buf, base); - *this = buf; + init(); + char buf[1 + 8 * sizeof(unsigned long)]; + ultoa(value, buf, base); + *this = buf; } String::String(float value, unsigned int decimalPlaces) { - init(); - char *buf = (char*)malloc(decimalPlaces + 42); - if (buf) { - *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); - free(buf); - } else { - *this = "nan"; - log_e("No enought memory for the operation."); - } + init(); + char *buf = (char *)malloc(decimalPlaces + 42); + if (buf) { + *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); + free(buf); + } else { + *this = "nan"; + log_e("No enough memory for the operation."); + } } String::String(double value, unsigned int decimalPlaces) { - init(); - char *buf = (char*)malloc(decimalPlaces + 312); - if (buf) { - *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); - free(buf); - } else { - *this = "nan"; - log_e("No enought memory for the operation."); - } + init(); + char *buf = (char *)malloc(decimalPlaces + 312); + if (buf) { + *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); + free(buf); + } else { + *this = "nan"; + log_e("No enough memory for the operation."); + } } String::String(long long value, unsigned char base) { - init(); - char buf[2 + 8 * sizeof(long long)]; - lltoa(value, buf, base); - *this = buf; + init(); + char buf[2 + 8 * sizeof(long long)]; + lltoa(value, buf, base); + *this = buf; } String::String(unsigned long long value, unsigned char base) { - init(); - char buf[1 + 8 * sizeof(unsigned long long)]; - ulltoa(value, buf, base); - *this = buf; + init(); + char buf[1 + 8 * sizeof(unsigned long long)]; + ulltoa(value, buf, base); + *this = buf; } String::~String() { - invalidate(); + invalidate(); } /*********************************************/ @@ -147,150 +147,150 @@ String::~String() { /*********************************************/ inline void String::init(void) { - setSSO(false); - setBuffer(nullptr); - setCapacity(0); - setLen(0); + setSSO(false); + setBuffer(nullptr); + setCapacity(0); + setLen(0); } void String::invalidate(void) { - if(!isSSO() && wbuffer()) - free(wbuffer()); - init(); + if (!isSSO() && wbuffer()) + free(wbuffer()); + init(); } bool String::reserve(unsigned int size) { - if(buffer() && capacity() >= size) - return true; - if(changeBuffer(size)) { - if(len() == 0) - wbuffer()[0] = 0; - return true; - } - return false; + if (buffer() && capacity() >= size) + return true; + if (changeBuffer(size)) { + if (len() == 0) + wbuffer()[0] = 0; + return true; + } + return false; } bool String::changeBuffer(unsigned int maxStrLen) { - // Can we use SSO here to avoid allocation? - if (maxStrLen < sizeof(sso.buff) - 1) { - if (isSSO() || !buffer()) { - // Already using SSO, nothing to do - uint16_t oldLen = len(); - setSSO(true); - setLen(oldLen); - } else { // if bufptr && !isSSO() - // Using bufptr, need to shrink into sso.buff - char temp[sizeof(sso.buff)]; - memcpy(temp, buffer(), maxStrLen); - free(wbuffer()); - uint16_t oldLen = len(); - setSSO(true); - memcpy(wbuffer(), temp, maxStrLen); - setLen(oldLen); - } - return true; + // Can we use SSO here to avoid allocation? + if (maxStrLen < sizeof(sso.buff) - 1) { + if (isSSO() || !buffer()) { + // Already using SSO, nothing to do + uint16_t oldLen = len(); + setSSO(true); + setLen(oldLen); + } else { // if bufptr && !isSSO() + // Using bufptr, need to shrink into sso.buff + char temp[sizeof(sso.buff)]; + memcpy(temp, buffer(), maxStrLen); + free(wbuffer()); + uint16_t oldLen = len(); + setSSO(true); + memcpy(wbuffer(), temp, maxStrLen); + setLen(oldLen); } - // Fallthrough to normal allocator - size_t newSize = (maxStrLen + 16) & (~0xf); - // Make sure we can fit newsize in the buffer - if (newSize > CAPACITY_MAX) { - return false; + return true; + } + // Fallthrough to normal allocator + size_t newSize = (maxStrLen + 16) & (~0xf); + // Make sure we can fit newsize in the buffer + if (newSize > CAPACITY_MAX) { + return false; + } + uint16_t oldLen = len(); + char *newbuffer = (char *)realloc(isSSO() ? nullptr : wbuffer(), newSize); + if (newbuffer) { + size_t oldSize = capacity() + 1; // include NULL. + if (isSSO()) { + // Copy the SSO buffer into allocated space + memmove(newbuffer, sso.buff, sizeof(sso.buff)); } - uint16_t oldLen = len(); - char *newbuffer = (char *) realloc(isSSO() ? nullptr : wbuffer(), newSize); - if (newbuffer) { - size_t oldSize = capacity() + 1; // include NULL. - if (isSSO()) { - // Copy the SSO buffer into allocated space - memmove(newbuffer, sso.buff, sizeof(sso.buff)); - } - if (newSize > oldSize) { - memset(newbuffer + oldSize, 0, newSize - oldSize); - } - setSSO(false); - setCapacity(newSize - 1); - setBuffer(newbuffer); - setLen(oldLen); // Needed in case of SSO where len() never existed - return true; + if (newSize > oldSize) { + memset(newbuffer + oldSize, 0, newSize - oldSize); } - return false; + setSSO(false); + setCapacity(newSize - 1); + setBuffer(newbuffer); + setLen(oldLen); // Needed in case of SSO where len() never existed + return true; + } + return false; } /*********************************************/ /* Copy and Move */ /*********************************************/ -String & String::copy(const char *cstr, unsigned int length) { - if(!reserve(length)) { - invalidate(); - return *this; - } - memmove(wbuffer(), cstr, length + 1); - setLen(length); +String &String::copy(const char *cstr, unsigned int length) { + if (!reserve(length)) { + invalidate(); return *this; + } + memmove(wbuffer(), cstr, length + 1); + setLen(length); + return *this; } #ifdef __GXX_EXPERIMENTAL_CXX0X__ void String::move(String &rhs) { - if(buffer()) { - if(capacity() >= rhs.len()) { - memmove(wbuffer(), rhs.buffer(), rhs.length() + 1); - setLen(rhs.len()); - rhs.invalidate(); - return; - } else { - if (!isSSO()) { - free(wbuffer()); - setBuffer(nullptr); - } - } - } - if (rhs.isSSO()) { - setSSO(true); - memmove(sso.buff, rhs.sso.buff, sizeof(sso.buff)); + if (buffer()) { + if (capacity() >= rhs.len()) { + memmove(wbuffer(), rhs.buffer(), rhs.length() + 1); + setLen(rhs.len()); + rhs.invalidate(); + return; } else { - setSSO(false); - setBuffer(rhs.wbuffer()); + if (!isSSO()) { + free(wbuffer()); + setBuffer(nullptr); + } } - setCapacity(rhs.capacity()); - setLen(rhs.len()); - rhs.setSSO(false); - rhs.setCapacity(0); - rhs.setBuffer(nullptr); - rhs.setLen(0); + } + if (rhs.isSSO()) { + setSSO(true); + memmove(sso.buff, rhs.sso.buff, sizeof(sso.buff)); + } else { + setSSO(false); + setBuffer(rhs.wbuffer()); + } + setCapacity(rhs.capacity()); + setLen(rhs.len()); + rhs.setSSO(false); + rhs.setCapacity(0); + rhs.setBuffer(nullptr); + rhs.setLen(0); } #endif -String & String::operator =(const String &rhs) { - if(this == &rhs) - return *this; - if(rhs.buffer()) - copy(rhs.buffer(), rhs.len()); - else - invalidate(); +String &String::operator=(const String &rhs) { + if (this == &rhs) return *this; + if (rhs.buffer()) + copy(rhs.buffer(), rhs.len()); + else + invalidate(); + return *this; } #ifdef __GXX_EXPERIMENTAL_CXX0X__ -String & String::operator =(String &&rval) { - if(this != &rval) - move(rval); - return *this; +String &String::operator=(String &&rval) { + if (this != &rval) + move(rval); + return *this; } -String & String::operator =(StringSumHelper &&rval) { - if(this != &rval) - move(rval); - return *this; +String &String::operator=(StringSumHelper &&rval) { + if (this != &rval) + move(rval); + return *this; } #endif -String & String::operator =(const char *cstr) { - if(cstr) - copy(cstr, strlen(cstr)); - else - invalidate(); - return *this; +String &String::operator=(const char *cstr) { + if (cstr) + copy(cstr, strlen(cstr)); + else + invalidate(); + return *this; } /*********************************************/ @@ -298,194 +298,194 @@ String & String::operator =(const char *cstr) { /*********************************************/ bool String::concat(const String &s) { - // Special case if we're concatting ourself (s += s;) since we may end up - // realloc'ing the buffer and moving s.buffer in the method called - if (&s == this) { - unsigned int newlen = 2 * len(); - if (!s.buffer()) - return false; - if (s.len() == 0) - return true; - if (!reserve(newlen)) - return false; - memmove(wbuffer() + len(), buffer(), len()); - setLen(newlen); - wbuffer()[len()] = 0; - return true; - } else { - return concat(s.buffer(), s.len()); - } + // Special case if we're concatting ourself (s += s;) since we may end up + // realloc'ing the buffer and moving s.buffer in the method called + if (&s == this) { + unsigned int newlen = 2 * len(); + if (!s.buffer()) + return false; + if (s.len() == 0) + return true; + if (!reserve(newlen)) + return false; + memmove(wbuffer() + len(), buffer(), len()); + setLen(newlen); + wbuffer()[len()] = 0; + return true; + } else { + return concat(s.buffer(), s.len()); + } } bool String::concat(const char *cstr, unsigned int length) { - unsigned int newlen = len() + length; - if(!cstr) - return false; - if(length == 0) - return true; - if(!reserve(newlen)) - return false; - if (cstr >= wbuffer() && cstr < wbuffer() + len()) - // compatible with SSO in ram #6155 (case "x += x.c_str()") - memmove(wbuffer() + len(), cstr, length + 1); - else - // compatible with source in flash #6367 - memcpy_P(wbuffer() + len(), cstr, length + 1); - setLen(newlen); + unsigned int newlen = len() + length; + if (!cstr) + return false; + if (length == 0) return true; + if (!reserve(newlen)) + return false; + if (cstr >= wbuffer() && cstr < wbuffer() + len()) + // compatible with SSO in ram #6155 (case "x += x.c_str()") + memmove(wbuffer() + len(), cstr, length + 1); + else + // compatible with source in flash #6367 + memcpy_P(wbuffer() + len(), cstr, length + 1); + setLen(newlen); + return true; } bool String::concat(const char *cstr) { - if(!cstr) - return false; - return concat(cstr, strlen(cstr)); + if (!cstr) + return false; + return concat(cstr, strlen(cstr)); } bool String::concat(char c) { - char buf[] = { c, '\0' }; - return concat(buf, 1); + char buf[] = { c, '\0' }; + return concat(buf, 1); } bool String::concat(unsigned char num) { - char buf[1 + 3 * sizeof(unsigned char)]; - utoa(num, buf, 10); - return concat(buf, strlen(buf)); + char buf[1 + 3 * sizeof(unsigned char)]; + utoa(num, buf, 10); + return concat(buf, strlen(buf)); } bool String::concat(int num) { - char buf[2 + 3 * sizeof(int)]; - itoa(num, buf, 10); - return concat(buf, strlen(buf)); + char buf[2 + 3 * sizeof(int)]; + itoa(num, buf, 10); + return concat(buf, strlen(buf)); } bool String::concat(unsigned int num) { - char buf[1 + 3 * sizeof(unsigned int)]; - utoa(num, buf, 10); - return concat(buf, strlen(buf)); + char buf[1 + 3 * sizeof(unsigned int)]; + utoa(num, buf, 10); + return concat(buf, strlen(buf)); } bool String::concat(long num) { - char buf[2 + 3 * sizeof(long)]; - ltoa(num, buf, 10); - return concat(buf, strlen(buf)); + char buf[2 + 3 * sizeof(long)]; + ltoa(num, buf, 10); + return concat(buf, strlen(buf)); } bool String::concat(unsigned long num) { - char buf[1 + 3 * sizeof(unsigned long)]; - ultoa(num, buf, 10); - return concat(buf, strlen(buf)); + char buf[1 + 3 * sizeof(unsigned long)]; + ultoa(num, buf, 10); + return concat(buf, strlen(buf)); } bool String::concat(long long num) { - char buf[2 + 3 * sizeof(long long)]; - lltoa(num, buf, 10); - return concat(buf, strlen(buf)); + char buf[2 + 3 * sizeof(long long)]; + lltoa(num, buf, 10); + return concat(buf, strlen(buf)); } bool String::concat(unsigned long long num) { - char buf[1 + 3 * sizeof(unsigned long long)]; - ulltoa(num, buf, 10); - return concat(buf, strlen(buf)); + char buf[1 + 3 * sizeof(unsigned long long)]; + ulltoa(num, buf, 10); + return concat(buf, strlen(buf)); } bool String::concat(float num) { - char buf[20]; - char* string = dtostrf(num, 4, 2, buf); - return concat(string, strlen(string)); + char buf[20]; + char *string = dtostrf(num, 4, 2, buf); + return concat(string, strlen(string)); } bool String::concat(double num) { - char buf[20]; - char* string = dtostrf(num, 4, 2, buf); - return concat(string, strlen(string)); + char buf[20]; + char *string = dtostrf(num, 4, 2, buf); + return concat(string, strlen(string)); } /*********************************************/ /* Concatenate */ /*********************************************/ -StringSumHelper & operator +(const StringSumHelper &lhs, const String &rhs) { - StringSumHelper &a = const_cast(lhs); - if(!a.concat(rhs.buffer(), rhs.len())) - a.invalidate(); - return a; +StringSumHelper &operator+(const StringSumHelper &lhs, const String &rhs) { + StringSumHelper &a = const_cast(lhs); + if (!a.concat(rhs.buffer(), rhs.len())) + a.invalidate(); + return a; } -StringSumHelper & operator +(const StringSumHelper &lhs, const char *cstr) { - StringSumHelper &a = const_cast(lhs); - if(!cstr || !a.concat(cstr, strlen(cstr))) - a.invalidate(); - return a; +StringSumHelper &operator+(const StringSumHelper &lhs, const char *cstr) { + StringSumHelper &a = const_cast(lhs); + if (!cstr || !a.concat(cstr, strlen(cstr))) + a.invalidate(); + return a; } -StringSumHelper & operator +(const StringSumHelper &lhs, char c) { - StringSumHelper &a = const_cast(lhs); - if(!a.concat(c)) - a.invalidate(); - return a; +StringSumHelper &operator+(const StringSumHelper &lhs, char c) { + StringSumHelper &a = const_cast(lhs); + if (!a.concat(c)) + a.invalidate(); + return a; } -StringSumHelper & operator +(const StringSumHelper &lhs, unsigned char num) { - StringSumHelper &a = const_cast(lhs); - if(!a.concat(num)) - a.invalidate(); - return a; +StringSumHelper &operator+(const StringSumHelper &lhs, unsigned char num) { + StringSumHelper &a = const_cast(lhs); + if (!a.concat(num)) + a.invalidate(); + return a; } -StringSumHelper & operator +(const StringSumHelper &lhs, int num) { - StringSumHelper &a = const_cast(lhs); - if(!a.concat(num)) - a.invalidate(); - return a; +StringSumHelper &operator+(const StringSumHelper &lhs, int num) { + StringSumHelper &a = const_cast(lhs); + if (!a.concat(num)) + a.invalidate(); + return a; } -StringSumHelper & operator +(const StringSumHelper &lhs, unsigned int num) { - StringSumHelper &a = const_cast(lhs); - if(!a.concat(num)) - a.invalidate(); - return a; +StringSumHelper &operator+(const StringSumHelper &lhs, unsigned int num) { + StringSumHelper &a = const_cast(lhs); + if (!a.concat(num)) + a.invalidate(); + return a; } -StringSumHelper & operator +(const StringSumHelper &lhs, long num) { - StringSumHelper &a = const_cast(lhs); - if(!a.concat(num)) - a.invalidate(); - return a; +StringSumHelper &operator+(const StringSumHelper &lhs, long num) { + StringSumHelper &a = const_cast(lhs); + if (!a.concat(num)) + a.invalidate(); + return a; } -StringSumHelper & operator +(const StringSumHelper &lhs, unsigned long num) { - StringSumHelper &a = const_cast(lhs); - if(!a.concat(num)) - a.invalidate(); - return a; +StringSumHelper &operator+(const StringSumHelper &lhs, unsigned long num) { + StringSumHelper &a = const_cast(lhs); + if (!a.concat(num)) + a.invalidate(); + return a; } -StringSumHelper & operator +(const StringSumHelper &lhs, float num) { - StringSumHelper &a = const_cast(lhs); - if(!a.concat(num)) - a.invalidate(); - return a; +StringSumHelper &operator+(const StringSumHelper &lhs, float num) { + StringSumHelper &a = const_cast(lhs); + if (!a.concat(num)) + a.invalidate(); + return a; } -StringSumHelper & operator +(const StringSumHelper &lhs, double num) { - StringSumHelper &a = const_cast(lhs); - if(!a.concat(num)) - a.invalidate(); - return a; +StringSumHelper &operator+(const StringSumHelper &lhs, double num) { + StringSumHelper &a = const_cast(lhs); + if (!a.concat(num)) + a.invalidate(); + return a; } -StringSumHelper & operator +(const StringSumHelper &lhs, long long num) { - StringSumHelper &a = const_cast(lhs); - if(!a.concat(num)) - a.invalidate(); - return a; +StringSumHelper &operator+(const StringSumHelper &lhs, long long num) { + StringSumHelper &a = const_cast(lhs); + if (!a.concat(num)) + a.invalidate(); + return a; } -StringSumHelper & operator +(const StringSumHelper &lhs, unsigned long long num) { - StringSumHelper &a = const_cast(lhs); - if(!a.concat(num)) - a.invalidate(); - return a; +StringSumHelper &operator+(const StringSumHelper &lhs, unsigned long long num) { + StringSumHelper &a = const_cast(lhs); + if (!a.concat(num)) + a.invalidate(); + return a; } /*********************************************/ @@ -493,103 +493,103 @@ StringSumHelper & operator +(const StringSumHelper &lhs, unsigned long long num) /*********************************************/ int String::compareTo(const String &s) const { - if(!buffer() || !s.buffer()) { - if(s.buffer() && s.len() > 0) - return 0 - *(unsigned char *) s.buffer(); - if(buffer() && len() > 0) - return *(unsigned char *) buffer(); - return 0; - } - return strcmp(buffer(), s.buffer()); + if (!buffer() || !s.buffer()) { + if (s.buffer() && s.len() > 0) + return 0 - *(unsigned char *)s.buffer(); + if (buffer() && len() > 0) + return *(unsigned char *)buffer(); + return 0; + } + return strcmp(buffer(), s.buffer()); } bool String::equals(const String &s2) const { - return (len() == s2.len() && compareTo(s2) == 0); + return (len() == s2.len() && compareTo(s2) == 0); } bool String::equals(const char *cstr) const { - if(len() == 0) - return (cstr == NULL || *cstr == 0); - if(cstr == NULL) - return buffer()[0] == 0; - return strcmp(buffer(), cstr) == 0; + if (len() == 0) + return (cstr == NULL || *cstr == 0); + if (cstr == NULL) + return buffer()[0] == 0; + return strcmp(buffer(), cstr) == 0; } bool String::operator<(const String &rhs) const { - return compareTo(rhs) < 0; + return compareTo(rhs) < 0; } bool String::operator>(const String &rhs) const { - return compareTo(rhs) > 0; + return compareTo(rhs) > 0; } bool String::operator<=(const String &rhs) const { - return compareTo(rhs) <= 0; + return compareTo(rhs) <= 0; } bool String::operator>=(const String &rhs) const { - return compareTo(rhs) >= 0; + return compareTo(rhs) >= 0; } bool String::equalsIgnoreCase(const String &s2) const { - if(this == &s2) - return true; - if(len() != s2.len()) - return false; - if(len() == 0) - return true; - const char *p1 = buffer(); - const char *p2 = s2.buffer(); - while(*p1) { - if(tolower(*p1++) != tolower(*p2++)) - return false; - } + if (this == &s2) + return true; + if (len() != s2.len()) + return false; + if (len() == 0) return true; + const char *p1 = buffer(); + const char *p2 = s2.buffer(); + while (*p1) { + if (tolower(*p1++) != tolower(*p2++)) + return false; + } + return true; } unsigned char String::equalsConstantTime(const String &s2) const { - // To avoid possible time-based attacks present function - // compares given strings in a constant time. - if(len() != s2.len()) - return 0; - //at this point lengths are the same - if(len() == 0) - return 1; - //at this point lengths are the same and non-zero - const char *p1 = buffer(); - const char *p2 = s2.buffer(); - unsigned int equalchars = 0; - unsigned int diffchars = 0; - while(*p1) { - if(*p1 == *p2) - ++equalchars; - else - ++diffchars; - ++p1; - ++p2; - } - //the following should force a constant time eval of the condition without a compiler "logical shortcut" - unsigned char equalcond = (equalchars == len()); - unsigned char diffcond = (diffchars == 0); - return (equalcond & diffcond); //bitwise AND + // To avoid possible time-based attacks present function + // compares given strings in a constant time. + if (len() != s2.len()) + return 0; + //at this point lengths are the same + if (len() == 0) + return 1; + //at this point lengths are the same and non-zero + const char *p1 = buffer(); + const char *p2 = s2.buffer(); + unsigned int equalchars = 0; + unsigned int diffchars = 0; + while (*p1) { + if (*p1 == *p2) + ++equalchars; + else + ++diffchars; + ++p1; + ++p2; + } + //the following should force a constant time eval of the condition without a compiler "logical shortcut" + unsigned char equalcond = (equalchars == len()); + unsigned char diffcond = (diffchars == 0); + return (equalcond & diffcond); //bitwise AND } bool String::startsWith(const String &s2) const { - if(len() < s2.len()) - return false; - return startsWith(s2, 0); + if (len() < s2.len()) + return false; + return startsWith(s2, 0); } bool String::startsWith(const String &s2, unsigned int offset) const { - if(offset > (unsigned)(len() - s2.len()) || !buffer() || !s2.buffer()) - return false; - return strncmp(&buffer()[offset], s2.buffer(), s2.len()) == 0; + if (offset > (unsigned)(len() - s2.len()) || !buffer() || !s2.buffer()) + return false; + return strncmp(&buffer()[offset], s2.buffer(), s2.len()) == 0; } bool String::endsWith(const String &s2) const { - if(len() < s2.len() || !buffer() || !s2.buffer()) - return false; - return strcmp(&buffer()[len() - s2.len()], s2.buffer()) == 0; + if (len() < s2.len() || !buffer() || !s2.buffer()) + return false; + return strcmp(&buffer()[len() - s2.len()], s2.buffer()) == 0; } /*********************************************/ @@ -597,41 +597,41 @@ bool String::endsWith(const String &s2) const { /*********************************************/ char String::charAt(unsigned int loc) const { - return operator[](loc); + return operator[](loc); } void String::setCharAt(unsigned int loc, char c) { - if(loc < len()) - wbuffer()[loc] = c; + if (loc < len()) + wbuffer()[loc] = c; } -char & String::operator[](unsigned int index) { - static char dummy_writable_char; - if(index >= len() || !buffer()) { - dummy_writable_char = 0; - return dummy_writable_char; - } - return wbuffer()[index]; +char &String::operator[](unsigned int index) { + static char dummy_writable_char; + if (index >= len() || !buffer()) { + dummy_writable_char = 0; + return dummy_writable_char; + } + return wbuffer()[index]; } char String::operator[](unsigned int index) const { - if(index >= len() || !buffer()) - return 0; - return buffer()[index]; + if (index >= len() || !buffer()) + return 0; + return buffer()[index]; } void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index) const { - if(!bufsize || !buf) - return; - if(index >= len()) { - buf[0] = 0; - return; - } - unsigned int n = bufsize - 1; - if(n > len() - index) - n = len() - index; - strncpy((char *) buf, buffer() + index, n); - buf[n] = 0; + if (!bufsize || !buf) + return; + if (index >= len()) { + buf[0] = 0; + return; + } + unsigned int n = bufsize - 1; + if (n > len() - index) + n = len() - index; + strncpy((char *)buf, buffer() + index, n); + buf[n] = 0; } /*********************************************/ @@ -639,83 +639,83 @@ void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int ind /*********************************************/ int String::indexOf(char c) const { - return indexOf(c, 0); + return indexOf(c, 0); } int String::indexOf(char ch, unsigned int fromIndex) const { - if(fromIndex >= len()) - return -1; - const char *temp = strchr(buffer() + fromIndex, ch); - if(temp == NULL) - return -1; - return temp - buffer(); + if (fromIndex >= len()) + return -1; + const char *temp = strchr(buffer() + fromIndex, ch); + if (temp == NULL) + return -1; + return temp - buffer(); } int String::indexOf(const String &s2) const { - return indexOf(s2, 0); + return indexOf(s2, 0); } int String::indexOf(const String &s2, unsigned int fromIndex) const { - if(fromIndex >= len()) - return -1; - const char *found = strstr(buffer() + fromIndex, s2.buffer()); - if(found == NULL) - return -1; - return found - buffer(); + if (fromIndex >= len()) + return -1; + const char *found = strstr(buffer() + fromIndex, s2.buffer()); + if (found == NULL) + return -1; + return found - buffer(); } int String::lastIndexOf(char theChar) const { - return lastIndexOf(theChar, len() - 1); + return lastIndexOf(theChar, len() - 1); } int String::lastIndexOf(char ch, unsigned int fromIndex) const { - if(fromIndex >= len()) - return -1; - char tempchar = buffer()[fromIndex + 1]; - wbuffer()[fromIndex + 1] = '\0'; - char* temp = strrchr(wbuffer(), ch); - wbuffer()[fromIndex + 1] = tempchar; - if(temp == NULL) - return -1; - const int rv = temp - buffer(); - if(rv >= len()) - return -1; - return rv; + if (fromIndex >= len()) + return -1; + char tempchar = buffer()[fromIndex + 1]; + wbuffer()[fromIndex + 1] = '\0'; + char *temp = strrchr(wbuffer(), ch); + wbuffer()[fromIndex + 1] = tempchar; + if (temp == NULL) + return -1; + const int rv = temp - buffer(); + if (rv >= len()) + return -1; + return rv; } int String::lastIndexOf(const String &s2) const { - return lastIndexOf(s2, len() - s2.len()); + return lastIndexOf(s2, len() - s2.len()); } int String::lastIndexOf(const String &s2, unsigned int fromIndex) const { - if(s2.len() == 0 || len() == 0 || s2.len() > len()) - return -1; - if(fromIndex >= len()) - fromIndex = len() - 1; - int found = -1; - for(char *p = wbuffer(); p <= wbuffer() + fromIndex; p++) { - p = strstr(p, s2.buffer()); - if(!p) - break; - if((unsigned int) (p - wbuffer()) <= fromIndex) - found = p - buffer(); - } - return found; + if (s2.len() == 0 || len() == 0 || s2.len() > len()) + return -1; + if (fromIndex >= len()) + fromIndex = len() - 1; + int found = -1; + for (char *p = wbuffer(); p <= wbuffer() + fromIndex; p++) { + p = strstr(p, s2.buffer()); + if (!p) + break; + if ((unsigned int)(p - wbuffer()) <= fromIndex) + found = p - buffer(); + } + return found; } String String::substring(unsigned int left, unsigned int right) const { - if(left > right) { - unsigned int temp = right; - right = left; - left = temp; - } - String out; - if(left >= len()) - return out; - if(right > len()) - right = len(); - out.copy(buffer() + left, right - left); + if (left > right) { + unsigned int temp = right; + right = left; + left = temp; + } + String out; + if (left >= len()) return out; + if (right > len()) + right = len(); + out.copy(buffer() + left, right - left); + return out; } /*********************************************/ @@ -723,118 +723,118 @@ String String::substring(unsigned int left, unsigned int right) const { /*********************************************/ void String::replace(char find, char replace) { - if(!buffer()) - return; - for(char *p = wbuffer(); *p; p++) { - if(*p == find) - *p = replace; - } + if (!buffer()) + return; + for (char *p = wbuffer(); *p; p++) { + if (*p == find) + *p = replace; + } } void String::replace(const String &find, const String &replace) { - if(len() == 0 || find.len() == 0) - return; - int diff = replace.len() - find.len(); - char *readFrom = wbuffer(); - char *foundAt; - if(diff == 0) { - while((foundAt = strstr(readFrom, find.buffer())) != NULL) { - memmove(foundAt, replace.buffer(), replace.len()); - readFrom = foundAt + replace.len(); - } - } else if(diff < 0) { - char *writeTo = wbuffer(); - unsigned int l = len(); - while((foundAt = strstr(readFrom, find.buffer())) != NULL) { - unsigned int n = foundAt - readFrom; - memmove(writeTo, readFrom, n); - writeTo += n; - memmove(writeTo, replace.buffer(), replace.len()); - writeTo += replace.len(); - readFrom = foundAt + find.len(); - l += diff; - } - memmove(writeTo, readFrom, strlen(readFrom)+1); - setLen(l); - } else { - unsigned int size = len(); // compute size needed for result - while((foundAt = strstr(readFrom, find.buffer())) != NULL) { - readFrom = foundAt + find.len(); - size += diff; - } - if(size == len()) - return; - if(size > capacity() && !changeBuffer(size)) { - log_w("String.Replace() Insufficient space to replace string"); - return; - } - int index = len() - 1; - while(index >= 0 && (index = lastIndexOf(find, index)) >= 0) { - readFrom = wbuffer() + index + find.len(); - memmove(readFrom + diff, readFrom, len() - (readFrom - buffer())); - int newLen = len() + diff; - memmove(wbuffer() + index, replace.buffer(), replace.len()); - setLen(newLen); - wbuffer()[newLen] = 0; - index--; - } + if (len() == 0 || find.len() == 0) + return; + int diff = replace.len() - find.len(); + char *readFrom = wbuffer(); + char *foundAt; + if (diff == 0) { + while ((foundAt = strstr(readFrom, find.buffer())) != NULL) { + memmove(foundAt, replace.buffer(), replace.len()); + readFrom = foundAt + replace.len(); + } + } else if (diff < 0) { + char *writeTo = wbuffer(); + unsigned int l = len(); + while ((foundAt = strstr(readFrom, find.buffer())) != NULL) { + unsigned int n = foundAt - readFrom; + memmove(writeTo, readFrom, n); + writeTo += n; + memmove(writeTo, replace.buffer(), replace.len()); + writeTo += replace.len(); + readFrom = foundAt + find.len(); + l += diff; + } + memmove(writeTo, readFrom, strlen(readFrom) + 1); + setLen(l); + } else { + unsigned int size = len(); // compute size needed for result + while ((foundAt = strstr(readFrom, find.buffer())) != NULL) { + readFrom = foundAt + find.len(); + size += diff; + } + if (size == len()) + return; + if (size > capacity() && !changeBuffer(size)) { + log_w("String.Replace() Insufficient space to replace string"); + return; + } + int index = len() - 1; + while (index >= 0 && (index = lastIndexOf(find, index)) >= 0) { + readFrom = wbuffer() + index + find.len(); + memmove(readFrom + diff, readFrom, len() - (readFrom - buffer())); + int newLen = len() + diff; + memmove(wbuffer() + index, replace.buffer(), replace.len()); + setLen(newLen); + wbuffer()[newLen] = 0; + index--; } + } } void String::remove(unsigned int index) { - // Pass the biggest integer as the count. The remove method - // below will take care of truncating it at the end of the - // string. - remove(index, (unsigned int) -1); + // Pass the biggest integer as the count. The remove method + // below will take care of truncating it at the end of the + // string. + remove(index, (unsigned int)-1); } void String::remove(unsigned int index, unsigned int count) { - if(index >= len()) { - return; - } - if(count <= 0) { - return; - } - if(count > len() - index) { - count = len() - index; - } - char *writeTo = wbuffer() + index; - unsigned int newlen = len() - count; - memmove(writeTo, wbuffer() + index + count, newlen - index); - setLen(newlen); - wbuffer()[newlen] = 0; + if (index >= len()) { + return; + } + if (count <= 0) { + return; + } + if (count > len() - index) { + count = len() - index; + } + char *writeTo = wbuffer() + index; + unsigned int newlen = len() - count; + memmove(writeTo, wbuffer() + index + count, newlen - index); + setLen(newlen); + wbuffer()[newlen] = 0; } void String::toLowerCase(void) { - if(!buffer()) - return; - for(char *p = wbuffer(); *p; p++) { - *p = tolower(*p); - } + if (!buffer()) + return; + for (char *p = wbuffer(); *p; p++) { + *p = tolower(*p); + } } void String::toUpperCase(void) { - if(!buffer()) - return; - for(char *p = wbuffer(); *p; p++) { - *p = toupper(*p); - } + if (!buffer()) + return; + for (char *p = wbuffer(); *p; p++) { + *p = toupper(*p); + } } void String::trim(void) { - if(!buffer() || len() == 0) - return; - char *begin = wbuffer(); - while(isspace(*begin)) - begin++; - char *end = wbuffer() + len() - 1; - while(isspace(*end) && end >= begin) - end--; - unsigned int newlen = end + 1 - begin; - if(begin > buffer()) - memmove(wbuffer(), begin, newlen); - setLen(newlen); - wbuffer()[newlen] = 0; + if (!buffer() || len() == 0) + return; + char *begin = wbuffer(); + while (isspace(*begin)) + begin++; + char *end = wbuffer() + len() - 1; + while (isspace(*end) && end >= begin) + end--; + unsigned int newlen = end + 1 - begin; + if (begin > buffer()) + memmove(wbuffer(), begin, newlen); + setLen(newlen); + wbuffer()[newlen] = 0; } /*********************************************/ @@ -842,21 +842,21 @@ void String::trim(void) { /*********************************************/ long String::toInt(void) const { - if (buffer()) - return atol(buffer()); - return 0; + if (buffer()) + return atol(buffer()); + return 0; } float String::toFloat(void) const { - if (buffer()) - return atof(buffer()); - return 0; + if (buffer()) + return atof(buffer()); + return 0; } double String::toDouble(void) const { - if (buffer()) - return atof(buffer()); - return 0.0; + if (buffer()) + return atof(buffer()); + return 0.0; } // global empty string to allow returning const String& with nothing diff --git a/cores/esp32/WString.h b/cores/esp32/WString.h index 6517109f29b..d379bc46080 100644 --- a/cores/esp32/WString.h +++ b/cores/esp32/WString.h @@ -43,359 +43,395 @@ class StringSumHelper; // The string class class String { - // use a function pointer to allow for "if (s)" without the - // complications of an operator bool(). for more information, see: - // http://www.artima.com/cppsource/safebool.html - typedef void (String::*StringIfHelperType)() const; - void StringIfHelper() const { - } + // use a function pointer to allow for "if (s)" without the + // complications of an operator bool(). for more information, see: + // http://www.artima.com/cppsource/safebool.html + typedef void (String::*StringIfHelperType)() const; + void StringIfHelper() const { + } - public: - // constructors - // creates a copy of the initial value. - // if the initial value is null or invalid, or if memory allocation - // fails, the string will be marked as invalid (i.e. "if (s)" will - // be false). - String(const char *cstr = ""); - String(const char *cstr, unsigned int length); +public: + // constructors + // creates a copy of the initial value. + // if the initial value is null or invalid, or if memory allocation + // fails, the string will be marked as invalid (i.e. "if (s)" will + // be false). + String(const char *cstr = ""); + String(const char *cstr, unsigned int length); #ifdef __GXX_EXPERIMENTAL_CXX0X__ - String(const uint8_t *cstr, unsigned int length) : String(reinterpret_cast(cstr), length) {} + String(const uint8_t *cstr, unsigned int length) + : String(reinterpret_cast(cstr), length) {} #endif - String(const String &str); - String(const __FlashStringHelper *str) : String(reinterpret_cast(str)) {} + String(const String &str); + String(const __FlashStringHelper *str) + : String(reinterpret_cast(str)) {} #ifdef __GXX_EXPERIMENTAL_CXX0X__ - String(String &&rval); - String(StringSumHelper &&rval); + String(String &&rval); + String(StringSumHelper &&rval); #endif - explicit String(char c); - explicit String(unsigned char, unsigned char base = 10); - explicit String(int, unsigned char base = 10); - explicit String(unsigned int, unsigned char base = 10); - explicit String(long, unsigned char base = 10); - explicit String(unsigned long, unsigned char base = 10); - explicit String(float, unsigned int decimalPlaces = 2); - explicit String(double, unsigned int decimalPlaces = 2); - explicit String(long long, unsigned char base = 10); - explicit String(unsigned long long, unsigned char base = 10); - ~String(void); + explicit String(char c); + explicit String(unsigned char, unsigned char base = 10); + explicit String(int, unsigned char base = 10); + explicit String(unsigned int, unsigned char base = 10); + explicit String(long, unsigned char base = 10); + explicit String(unsigned long, unsigned char base = 10); + explicit String(float, unsigned int decimalPlaces = 2); + explicit String(double, unsigned int decimalPlaces = 2); + explicit String(long long, unsigned char base = 10); + explicit String(unsigned long long, unsigned char base = 10); + ~String(void); - // memory management - // return true on success, false on failure (in which case, the string - // is left unchanged). reserve(0), if successful, will validate an - // invalid string (i.e., "if (s)" will be true afterwards) - bool reserve(unsigned int size); - inline unsigned int length(void) const { - if(buffer()) { - return len(); - } else { - return 0; - } - } - inline void clear(void) { - setLen(0); - } - inline bool isEmpty(void) const { - return length() == 0; - } + // memory management + // return true on success, false on failure (in which case, the string + // is left unchanged). reserve(0), if successful, will validate an + // invalid string (i.e., "if (s)" will be true afterwards) + bool reserve(unsigned int size); + inline unsigned int length(void) const { + if (buffer()) { + return len(); + } else { + return 0; + } + } + inline void clear(void) { + setLen(0); + } + inline bool isEmpty(void) const { + return length() == 0; + } - // creates a copy of the assigned value. if the value is null or - // invalid, or if the memory allocation fails, the string will be - // marked as invalid ("if (s)" will be false). - String & operator =(const String &rhs); - String & operator =(const char *cstr); - String & operator = (const __FlashStringHelper *str) {return *this = reinterpret_cast(str);} + // creates a copy of the assigned value. if the value is null or + // invalid, or if the memory allocation fails, the string will be + // marked as invalid ("if (s)" will be false). + String &operator=(const String &rhs); + String &operator=(const char *cstr); + String &operator=(const __FlashStringHelper *str) { + return *this = reinterpret_cast(str); + } #ifdef __GXX_EXPERIMENTAL_CXX0X__ - String & operator =(String &&rval); - String & operator =(StringSumHelper &&rval); + String &operator=(String &&rval); + String &operator=(StringSumHelper &&rval); #endif - // concatenate (works w/ built-in types, same as assignment) + // concatenate (works w/ built-in types, same as assignment) - // returns true on success, false on failure (in which case, the string - // is left unchanged). if the argument is null or invalid, the - // concatenation is considered unsuccessful. - bool concat(const String &str); - bool concat(const char *cstr); - bool concat(const char *cstr, unsigned int length); - bool concat(const uint8_t *cstr, unsigned int length) {return concat(reinterpret_cast(cstr), length);} - bool concat(char c); - bool concat(unsigned char c); - bool concat(int num); - bool concat(unsigned int num); - bool concat(long num); - bool concat(unsigned long num); - bool concat(float num); - bool concat(double num); - bool concat(long long num); - bool concat(unsigned long long num); - bool concat(const __FlashStringHelper * str) {return concat(reinterpret_cast(str));} + // returns true on success, false on failure (in which case, the string + // is left unchanged). if the argument is null or invalid, the + // concatenation is considered unsuccessful. + bool concat(const String &str); + bool concat(const char *cstr); + bool concat(const char *cstr, unsigned int length); + bool concat(const uint8_t *cstr, unsigned int length) { + return concat(reinterpret_cast(cstr), length); + } + bool concat(char c); + bool concat(unsigned char c); + bool concat(int num); + bool concat(unsigned int num); + bool concat(long num); + bool concat(unsigned long num); + bool concat(float num); + bool concat(double num); + bool concat(long long num); + bool concat(unsigned long long num); + bool concat(const __FlashStringHelper *str) { + return concat(reinterpret_cast(str)); + } - // if there's not enough memory for the concatenated value, the string - // will be left unchanged (but this isn't signalled in any way) - String & operator +=(const String &rhs) { - concat(rhs); - return (*this); - } - String & operator +=(const char *cstr) { - concat(cstr); - return (*this); - } - String & operator +=(char c) { - concat(c); - return (*this); - } - String & operator +=(unsigned char num) { - concat(num); - return (*this); - } - String & operator +=(int num) { - concat(num); - return (*this); - } - String & operator +=(unsigned int num) { - concat(num); - return (*this); - } - String & operator +=(long num) { - concat(num); - return (*this); - } - String & operator +=(unsigned long num) { - concat(num); - return (*this); - } - String & operator +=(float num) { - concat(num); - return (*this); - } - String & operator +=(double num) { - concat(num); - return (*this); - } - String & operator +=(long long num) { - concat(num); - return (*this); - } - String & operator +=(unsigned long long num) { - concat(num); - return (*this); - } - String & operator += (const __FlashStringHelper *str) {return *this += reinterpret_cast(str);} + // if there's not enough memory for the concatenated value, the string + // will be left unchanged (but this isn't signaled in any way) + String &operator+=(const String &rhs) { + concat(rhs); + return (*this); + } + String &operator+=(const char *cstr) { + concat(cstr); + return (*this); + } + String &operator+=(char c) { + concat(c); + return (*this); + } + String &operator+=(unsigned char num) { + concat(num); + return (*this); + } + String &operator+=(int num) { + concat(num); + return (*this); + } + String &operator+=(unsigned int num) { + concat(num); + return (*this); + } + String &operator+=(long num) { + concat(num); + return (*this); + } + String &operator+=(unsigned long num) { + concat(num); + return (*this); + } + String &operator+=(float num) { + concat(num); + return (*this); + } + String &operator+=(double num) { + concat(num); + return (*this); + } + String &operator+=(long long num) { + concat(num); + return (*this); + } + String &operator+=(unsigned long long num) { + concat(num); + return (*this); + } + String &operator+=(const __FlashStringHelper *str) { + return *this += reinterpret_cast(str); + } - friend StringSumHelper & operator +(const StringSumHelper &lhs, const String &rhs); - friend StringSumHelper & operator +(const StringSumHelper &lhs, const char *cstr); - friend StringSumHelper & operator +(const StringSumHelper &lhs, char c); - friend StringSumHelper & operator +(const StringSumHelper &lhs, unsigned char num); - friend StringSumHelper & operator +(const StringSumHelper &lhs, int num); - friend StringSumHelper & operator +(const StringSumHelper &lhs, unsigned int num); - friend StringSumHelper & operator +(const StringSumHelper &lhs, long num); - friend StringSumHelper & operator +(const StringSumHelper &lhs, unsigned long num); - friend StringSumHelper & operator +(const StringSumHelper &lhs, float num); - friend StringSumHelper & operator +(const StringSumHelper &lhs, double num); - friend StringSumHelper & operator +(const StringSumHelper &lhs, long long num); - friend StringSumHelper & operator +(const StringSumHelper &lhs, unsigned long long num); + friend StringSumHelper &operator+(const StringSumHelper &lhs, const String &rhs); + friend StringSumHelper &operator+(const StringSumHelper &lhs, const char *cstr); + friend StringSumHelper &operator+(const StringSumHelper &lhs, char c); + friend StringSumHelper &operator+(const StringSumHelper &lhs, unsigned char num); + friend StringSumHelper &operator+(const StringSumHelper &lhs, int num); + friend StringSumHelper &operator+(const StringSumHelper &lhs, unsigned int num); + friend StringSumHelper &operator+(const StringSumHelper &lhs, long num); + friend StringSumHelper &operator+(const StringSumHelper &lhs, unsigned long num); + friend StringSumHelper &operator+(const StringSumHelper &lhs, float num); + friend StringSumHelper &operator+(const StringSumHelper &lhs, double num); + friend StringSumHelper &operator+(const StringSumHelper &lhs, long long num); + friend StringSumHelper &operator+(const StringSumHelper &lhs, unsigned long long num); - // comparison (only works w/ Strings and "strings") - operator StringIfHelperType() const { - return buffer() ? &String::StringIfHelper : 0; - } - int compareTo(const String &s) const; - bool equals(const String &s) const; - bool equals(const char *cstr) const; - bool operator ==(const String &rhs) const { - return equals(rhs); - } - bool operator ==(const char *cstr) const { - return equals(cstr); - } - bool operator !=(const String &rhs) const { - return !equals(rhs); - } - bool operator !=(const char *cstr) const { - return !equals(cstr); - } - bool operator <(const String &rhs) const; - bool operator >(const String &rhs) const; - bool operator <=(const String &rhs) const; - bool operator >=(const String &rhs) const; - bool equalsIgnoreCase(const String &s) const; - unsigned char equalsConstantTime(const String &s) const; - bool startsWith(const String &prefix) const; - bool startsWith(const char *prefix) const { - return this->startsWith(String(prefix)); - } - bool startsWith(const __FlashStringHelper *prefix) const { - return this->startsWith(reinterpret_cast(prefix)); - } - bool startsWith(const String &prefix, unsigned int offset) const; - bool endsWith(const String &suffix) const; - bool endsWith(const char *suffix) const { - return this->endsWith(String(suffix)); - } - bool endsWith(const __FlashStringHelper * suffix) const { - return this->endsWith(reinterpret_cast(suffix)); - } + // comparison (only works w/ Strings and "strings") + operator StringIfHelperType() const { + return buffer() ? &String::StringIfHelper : 0; + } + int compareTo(const String &s) const; + bool equals(const String &s) const; + bool equals(const char *cstr) const; + bool operator==(const String &rhs) const { + return equals(rhs); + } + bool operator==(const char *cstr) const { + return equals(cstr); + } + bool operator!=(const String &rhs) const { + return !equals(rhs); + } + bool operator!=(const char *cstr) const { + return !equals(cstr); + } + bool operator<(const String &rhs) const; + bool operator>(const String &rhs) const; + bool operator<=(const String &rhs) const; + bool operator>=(const String &rhs) const; + bool equalsIgnoreCase(const String &s) const; + unsigned char equalsConstantTime(const String &s) const; + bool startsWith(const String &prefix) const; + bool startsWith(const char *prefix) const { + return this->startsWith(String(prefix)); + } + bool startsWith(const __FlashStringHelper *prefix) const { + return this->startsWith(reinterpret_cast(prefix)); + } + bool startsWith(const String &prefix, unsigned int offset) const; + bool endsWith(const String &suffix) const; + bool endsWith(const char *suffix) const { + return this->endsWith(String(suffix)); + } + bool endsWith(const __FlashStringHelper *suffix) const { + return this->endsWith(reinterpret_cast(suffix)); + } - // character access - char charAt(unsigned int index) const; - void setCharAt(unsigned int index, char c); - char operator [](unsigned int index) const; - char& operator [](unsigned int index); - void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index = 0) const; - void toCharArray(char *buf, unsigned int bufsize, unsigned int index = 0) const { - getBytes((unsigned char *) buf, bufsize, index); - } - const char* c_str() const { return buffer(); } - char* begin() { return wbuffer(); } - char* end() { return wbuffer() + length(); } - const char* begin() const { return c_str(); } - const char* end() const { return c_str() + length(); } + // character access + char charAt(unsigned int index) const; + void setCharAt(unsigned int index, char c); + char operator[](unsigned int index) const; + char &operator[](unsigned int index); + void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index = 0) const; + void toCharArray(char *buf, unsigned int bufsize, unsigned int index = 0) const { + getBytes((unsigned char *)buf, bufsize, index); + } + const char *c_str() const { + return buffer(); + } + char *begin() { + return wbuffer(); + } + char *end() { + return wbuffer() + length(); + } + const char *begin() const { + return c_str(); + } + const char *end() const { + return c_str() + length(); + } - // search - int indexOf(char ch) const; - int indexOf(char ch, unsigned int fromIndex) const; - int indexOf(const String &str) const; - int indexOf(const String &str, unsigned int fromIndex) const; - int lastIndexOf(char ch) const; - int lastIndexOf(char ch, unsigned int fromIndex) const; - int lastIndexOf(const String &str) const; - int lastIndexOf(const String &str, unsigned int fromIndex) const; - String substring(unsigned int beginIndex) const { - return substring(beginIndex, len()); - } - String substring(unsigned int beginIndex, unsigned int endIndex) const; + // search + int indexOf(char ch) const; + int indexOf(char ch, unsigned int fromIndex) const; + int indexOf(const String &str) const; + int indexOf(const String &str, unsigned int fromIndex) const; + int lastIndexOf(char ch) const; + int lastIndexOf(char ch, unsigned int fromIndex) const; + int lastIndexOf(const String &str) const; + int lastIndexOf(const String &str, unsigned int fromIndex) const; + String substring(unsigned int beginIndex) const { + return substring(beginIndex, len()); + } + String substring(unsigned int beginIndex, unsigned int endIndex) const; - // modification - void replace(char find, char replace); - void replace(const String &find, const String &replace); - void replace(const char *find, const String &replace) { - this->replace(String(find), replace); - } - void replace(const __FlashStringHelper *find, const String &replace) { - this->replace(reinterpret_cast(find), replace); - } - void replace(const char *find, const char *replace) { - this->replace(String(find), String(replace)); - } - void replace(const __FlashStringHelper *find, const char *replace) { - this->replace(reinterpret_cast(find), String(replace)); - } - void replace(const __FlashStringHelper *find, const __FlashStringHelper *replace) { - this->replace(reinterpret_cast(find), reinterpret_cast(replace)); - } - void remove(unsigned int index); - void remove(unsigned int index, unsigned int count); - void toLowerCase(void); - void toUpperCase(void); - void trim(void); + // modification + void replace(char find, char replace); + void replace(const String &find, const String &replace); + void replace(const char *find, const String &replace) { + this->replace(String(find), replace); + } + void replace(const __FlashStringHelper *find, const String &replace) { + this->replace(reinterpret_cast(find), replace); + } + void replace(const char *find, const char *replace) { + this->replace(String(find), String(replace)); + } + void replace(const __FlashStringHelper *find, const char *replace) { + this->replace(reinterpret_cast(find), String(replace)); + } + void replace(const __FlashStringHelper *find, const __FlashStringHelper *replace) { + this->replace(reinterpret_cast(find), reinterpret_cast(replace)); + } + void remove(unsigned int index); + void remove(unsigned int index, unsigned int count); + void toLowerCase(void); + void toUpperCase(void); + void trim(void); - // parsing/conversion - long toInt(void) const; - float toFloat(void) const; - double toDouble(void) const; + // parsing/conversion + long toInt(void) const; + float toFloat(void) const; + double toDouble(void) const; - protected: - // Contains the string info when we're not in SSO mode - struct _ptr { - char * buff; - uint32_t cap; - uint32_t len; - }; - // This allows strings up up to 11 (10 + \0 termination) without any extra space. - enum { SSOSIZE = sizeof(struct _ptr) + 4 - 1 }; // Characters to allocate space for SSO, must be 12 or more - struct _sso { - char buff[SSOSIZE]; - unsigned char len : 7; // Ensure only one byte is allocated by GCC for the bitfields - unsigned char isSSO : 1; - } __attribute__((packed)); // Ensure that GCC doesn't expand the flag byte to a 32-bit word for alignment issues +protected: + // Contains the string info when we're not in SSO mode + struct _ptr { + char *buff; + uint32_t cap; + uint32_t len; + }; + // This allows strings up up to 11 (10 + \0 termination) without any extra space. + enum { SSOSIZE = sizeof(struct _ptr) + 4 - 1 }; // Characters to allocate space for SSO, must be 12 or more + struct _sso { + char buff[SSOSIZE]; + unsigned char len : 7; // Ensure only one byte is allocated by GCC for the bitfields + unsigned char isSSO : 1; + } __attribute__((packed)); // Ensure that GCC doesn't expand the flag byte to a 32-bit word for alignment issues #ifdef BOARD_HAS_PSRAM - enum { CAPACITY_MAX = 3145728 }; + enum { CAPACITY_MAX = 3145728 }; #else - enum { CAPACITY_MAX = 65535 }; + enum { CAPACITY_MAX = 65535 }; #endif - union { - struct _ptr ptr; - struct _sso sso; - }; - // Accessor functions - inline bool isSSO() const { return sso.isSSO; } - inline unsigned int len() const { return isSSO() ? sso.len : ptr.len; } - inline unsigned int capacity() const { return isSSO() ? (unsigned int)SSOSIZE - 1 : ptr.cap; } // Size of max string not including terminal NUL - inline void setSSO(bool set) { sso.isSSO = set; } - inline void setLen(int len) { - if (isSSO()) { - sso.len = len; - sso.buff[len] = 0; - } else { - ptr.len = len; - if (ptr.buff) { - ptr.buff[len] = 0; - } - } - } - inline void setCapacity(int cap) { if (!isSSO()) ptr.cap = cap; } - inline void setBuffer(char *buff) { if (!isSSO()) ptr.buff = buff; } - // Buffer accessor functions - inline const char *buffer() const { return reinterpret_cast(isSSO() ? sso.buff : ptr.buff); } - inline char *wbuffer() const { return isSSO() ? const_cast(sso.buff) : ptr.buff; } // Writable version of buffer + union { + struct _ptr ptr; + struct _sso sso; + }; + // Accessor functions + inline bool isSSO() const { + return sso.isSSO; + } + inline unsigned int len() const { + return isSSO() ? sso.len : ptr.len; + } + inline unsigned int capacity() const { + return isSSO() ? (unsigned int)SSOSIZE - 1 : ptr.cap; + } // Size of max string not including terminal NUL + inline void setSSO(bool set) { + sso.isSSO = set; + } + inline void setLen(int len) { + if (isSSO()) { + sso.len = len; + sso.buff[len] = 0; + } else { + ptr.len = len; + if (ptr.buff) { + ptr.buff[len] = 0; + } + } + } + inline void setCapacity(int cap) { + if (!isSSO()) ptr.cap = cap; + } + inline void setBuffer(char *buff) { + if (!isSSO()) ptr.buff = buff; + } + // Buffer accessor functions + inline const char *buffer() const { + return reinterpret_cast(isSSO() ? sso.buff : ptr.buff); + } + inline char *wbuffer() const { + return isSSO() ? const_cast(sso.buff) : ptr.buff; + } // Writable version of buffer - protected: - void init(void); - void invalidate(void); - bool changeBuffer(unsigned int maxStrLen); +protected: + void init(void); + void invalidate(void); + bool changeBuffer(unsigned int maxStrLen); - // copy and move - String & copy(const char *cstr, unsigned int length); - String & copy(const __FlashStringHelper *pstr, unsigned int length) { - return copy(reinterpret_cast(pstr), length); - } + // copy and move + String ©(const char *cstr, unsigned int length); + String ©(const __FlashStringHelper *pstr, unsigned int length) { + return copy(reinterpret_cast(pstr), length); + } #ifdef __GXX_EXPERIMENTAL_CXX0X__ - void move(String &rhs); + void move(String &rhs); #endif }; -class StringSumHelper: public String { - public: - StringSumHelper(const String &s) : - String(s) { - } - StringSumHelper(const char *p) : - String(p) { - } - StringSumHelper(char c) : - String(c) { - } - StringSumHelper(unsigned char num) : - String(num) { - } - StringSumHelper(int num) : - String(num) { - } - StringSumHelper(unsigned int num) : - String(num) { - } - StringSumHelper(long num) : - String(num) { - } - StringSumHelper(unsigned long num) : - String(num) { - } - StringSumHelper(float num) : - String(num) { - } - StringSumHelper(double num) : - String(num) { - } - StringSumHelper(long long num) : - String(num) { - } - StringSumHelper(unsigned long long num) : - String(num) { - } +class StringSumHelper : public String { +public: + StringSumHelper(const String &s) + : String(s) { + } + StringSumHelper(const char *p) + : String(p) { + } + StringSumHelper(char c) + : String(c) { + } + StringSumHelper(unsigned char num) + : String(num) { + } + StringSumHelper(int num) + : String(num) { + } + StringSumHelper(unsigned int num) + : String(num) { + } + StringSumHelper(long num) + : String(num) { + } + StringSumHelper(unsigned long num) + : String(num) { + } + StringSumHelper(float num) + : String(num) { + } + StringSumHelper(double num) + : String(num) { + } + StringSumHelper(long long num) + : String(num) { + } + StringSumHelper(unsigned long long num) + : String(num) { + } }; - -inline StringSumHelper & operator +(const StringSumHelper &lhs, const __FlashStringHelper *rhs) { - return lhs + reinterpret_cast(rhs); + +inline StringSumHelper &operator+(const StringSumHelper &lhs, const __FlashStringHelper *rhs) { + return lhs + reinterpret_cast(rhs); } extern const String emptyString; diff --git a/cores/esp32/base64.cpp b/cores/esp32/base64.cpp index 1fc144e2659..8fa9617668c 100644 --- a/cores/esp32/base64.cpp +++ b/cores/esp32/base64.cpp @@ -35,21 +35,20 @@ extern "C" { * @param length size_t * @return String */ -String base64::encode(const uint8_t * data, size_t length) -{ - size_t size = base64_encode_expected_len(length) + 1; - char * buffer = (char *) malloc(size); - if(buffer) { - base64_encodestate _state; - base64_init_encodestate(&_state); - int len = base64_encode_block((const char *) &data[0], length, &buffer[0], &_state); - len = base64_encode_blockend((buffer + len), &_state); +String base64::encode(const uint8_t *data, size_t length) { + size_t size = base64_encode_expected_len(length) + 1; + char *buffer = (char *)malloc(size); + if (buffer) { + base64_encodestate _state; + base64_init_encodestate(&_state); + int len = base64_encode_block((const char *)&data[0], length, &buffer[0], &_state); + len = base64_encode_blockend((buffer + len), &_state); - String base64 = String(buffer); - free(buffer); - return base64; - } - return String("-FAIL-"); + String base64 = String(buffer); + free(buffer); + return base64; + } + return String("-FAIL-"); } /** @@ -57,8 +56,6 @@ String base64::encode(const uint8_t * data, size_t length) * @param text const String& * @return String */ -String base64::encode(const String& text) -{ - return base64::encode((uint8_t *) text.c_str(), text.length()); +String base64::encode(const String &text) { + return base64::encode((uint8_t *)text.c_str(), text.length()); } - diff --git a/cores/esp32/base64.h b/cores/esp32/base64.h index 97095817b8f..2bdd3cc8da4 100644 --- a/cores/esp32/base64.h +++ b/cores/esp32/base64.h @@ -1,11 +1,10 @@ #ifndef CORE_BASE64_H_ #define CORE_BASE64_H_ -class base64 -{ +class base64 { public: - static String encode(const uint8_t * data, size_t length); - static String encode(const String& text); + static String encode(const uint8_t* data, size_t length); + static String encode(const String& text); private: }; diff --git a/cores/esp32/binary.h b/cores/esp32/binary.h index 947542e389d..4a8e4e70819 100644 --- a/cores/esp32/binary.h +++ b/cores/esp32/binary.h @@ -24,398 +24,398 @@ /* If supported, 0b binary literals are preferable to these constants. * In that case, warn the user about these being deprecated (if possible). */ #if __cplusplus >= 201402L - /* C++14 introduces binary literals; C++11 introduces [[deprecated()]] */ - #define DEPRECATED(x) [[deprecated("use " #x " instead")]] +/* C++14 introduces binary literals; C++11 introduces [[deprecated()]] */ +#define DEPRECATED(x) [[deprecated("use " #x " instead")]] #elif __GNUC__ >= 6 - /* GCC 4.3 supports binary literals; GCC 6 supports __deprecated__ on enums*/ - #define DEPRECATED(x) __attribute__ ((__deprecated__ ("use " #x " instead"))) +/* GCC 4.3 supports binary literals; GCC 6 supports __deprecated__ on enums*/ +#define DEPRECATED(x) __attribute__((__deprecated__("use " #x " instead"))) #else - /* binary literals not supported, or "deprecated" warning not displayable */ - #define DEPRECATED(x) +/* binary literals not supported, or "deprecated" warning not displayable */ +#define DEPRECATED(x) #endif enum { - B0 DEPRECATED(0b0 ) = 0, - B00 DEPRECATED(0b00 ) = 0, - B000 DEPRECATED(0b000 ) = 0, - B0000 DEPRECATED(0b0000 ) = 0, - B00000 DEPRECATED(0b00000 ) = 0, - B000000 DEPRECATED(0b000000 ) = 0, - B0000000 DEPRECATED(0b0000000 ) = 0, + B0 DEPRECATED(0b0) = 0, + B00 DEPRECATED(0b00) = 0, + B000 DEPRECATED(0b000) = 0, + B0000 DEPRECATED(0b0000) = 0, + B00000 DEPRECATED(0b00000) = 0, + B000000 DEPRECATED(0b000000) = 0, + B0000000 DEPRECATED(0b0000000) = 0, B00000000 DEPRECATED(0b00000000) = 0, - B1 DEPRECATED(0b1 ) = 1, - B01 DEPRECATED(0b01 ) = 1, - B001 DEPRECATED(0b001 ) = 1, - B0001 DEPRECATED(0b0001 ) = 1, - B00001 DEPRECATED(0b00001 ) = 1, - B000001 DEPRECATED(0b000001 ) = 1, - B0000001 DEPRECATED(0b0000001 ) = 1, + B1 DEPRECATED(0b1) = 1, + B01 DEPRECATED(0b01) = 1, + B001 DEPRECATED(0b001) = 1, + B0001 DEPRECATED(0b0001) = 1, + B00001 DEPRECATED(0b00001) = 1, + B000001 DEPRECATED(0b000001) = 1, + B0000001 DEPRECATED(0b0000001) = 1, B00000001 DEPRECATED(0b00000001) = 1, - B10 DEPRECATED(0b10 ) = 2, - B010 DEPRECATED(0b010 ) = 2, - B0010 DEPRECATED(0b0010 ) = 2, - B00010 DEPRECATED(0b00010 ) = 2, - B000010 DEPRECATED(0b000010 ) = 2, - B0000010 DEPRECATED(0b0000010 ) = 2, + B10 DEPRECATED(0b10) = 2, + B010 DEPRECATED(0b010) = 2, + B0010 DEPRECATED(0b0010) = 2, + B00010 DEPRECATED(0b00010) = 2, + B000010 DEPRECATED(0b000010) = 2, + B0000010 DEPRECATED(0b0000010) = 2, B00000010 DEPRECATED(0b00000010) = 2, - B11 DEPRECATED(0b11 ) = 3, - B011 DEPRECATED(0b011 ) = 3, - B0011 DEPRECATED(0b0011 ) = 3, - B00011 DEPRECATED(0b00011 ) = 3, - B000011 DEPRECATED(0b000011 ) = 3, - B0000011 DEPRECATED(0b0000011 ) = 3, + B11 DEPRECATED(0b11) = 3, + B011 DEPRECATED(0b011) = 3, + B0011 DEPRECATED(0b0011) = 3, + B00011 DEPRECATED(0b00011) = 3, + B000011 DEPRECATED(0b000011) = 3, + B0000011 DEPRECATED(0b0000011) = 3, B00000011 DEPRECATED(0b00000011) = 3, - B100 DEPRECATED(0b100 ) = 4, - B0100 DEPRECATED(0b0100 ) = 4, - B00100 DEPRECATED(0b00100 ) = 4, - B000100 DEPRECATED(0b000100 ) = 4, - B0000100 DEPRECATED(0b0000100 ) = 4, + B100 DEPRECATED(0b100) = 4, + B0100 DEPRECATED(0b0100) = 4, + B00100 DEPRECATED(0b00100) = 4, + B000100 DEPRECATED(0b000100) = 4, + B0000100 DEPRECATED(0b0000100) = 4, B00000100 DEPRECATED(0b00000100) = 4, - B101 DEPRECATED(0b101 ) = 5, - B0101 DEPRECATED(0b0101 ) = 5, - B00101 DEPRECATED(0b00101 ) = 5, - B000101 DEPRECATED(0b000101 ) = 5, - B0000101 DEPRECATED(0b0000101 ) = 5, + B101 DEPRECATED(0b101) = 5, + B0101 DEPRECATED(0b0101) = 5, + B00101 DEPRECATED(0b00101) = 5, + B000101 DEPRECATED(0b000101) = 5, + B0000101 DEPRECATED(0b0000101) = 5, B00000101 DEPRECATED(0b00000101) = 5, - B110 DEPRECATED(0b110 ) = 6, - B0110 DEPRECATED(0b0110 ) = 6, - B00110 DEPRECATED(0b00110 ) = 6, - B000110 DEPRECATED(0b000110 ) = 6, - B0000110 DEPRECATED(0b0000110 ) = 6, + B110 DEPRECATED(0b110) = 6, + B0110 DEPRECATED(0b0110) = 6, + B00110 DEPRECATED(0b00110) = 6, + B000110 DEPRECATED(0b000110) = 6, + B0000110 DEPRECATED(0b0000110) = 6, B00000110 DEPRECATED(0b00000110) = 6, - B111 DEPRECATED(0b111 ) = 7, - B0111 DEPRECATED(0b0111 ) = 7, - B00111 DEPRECATED(0b00111 ) = 7, - B000111 DEPRECATED(0b000111 ) = 7, - B0000111 DEPRECATED(0b0000111 ) = 7, + B111 DEPRECATED(0b111) = 7, + B0111 DEPRECATED(0b0111) = 7, + B00111 DEPRECATED(0b00111) = 7, + B000111 DEPRECATED(0b000111) = 7, + B0000111 DEPRECATED(0b0000111) = 7, B00000111 DEPRECATED(0b00000111) = 7, - B1000 DEPRECATED(0b1000 ) = 8, - B01000 DEPRECATED(0b01000 ) = 8, - B001000 DEPRECATED(0b001000 ) = 8, - B0001000 DEPRECATED(0b0001000 ) = 8, + B1000 DEPRECATED(0b1000) = 8, + B01000 DEPRECATED(0b01000) = 8, + B001000 DEPRECATED(0b001000) = 8, + B0001000 DEPRECATED(0b0001000) = 8, B00001000 DEPRECATED(0b00001000) = 8, - B1001 DEPRECATED(0b1001 ) = 9, - B01001 DEPRECATED(0b01001 ) = 9, - B001001 DEPRECATED(0b001001 ) = 9, - B0001001 DEPRECATED(0b0001001 ) = 9, + B1001 DEPRECATED(0b1001) = 9, + B01001 DEPRECATED(0b01001) = 9, + B001001 DEPRECATED(0b001001) = 9, + B0001001 DEPRECATED(0b0001001) = 9, B00001001 DEPRECATED(0b00001001) = 9, - B1010 DEPRECATED(0b1010 ) = 10, - B01010 DEPRECATED(0b01010 ) = 10, - B001010 DEPRECATED(0b001010 ) = 10, - B0001010 DEPRECATED(0b0001010 ) = 10, + B1010 DEPRECATED(0b1010) = 10, + B01010 DEPRECATED(0b01010) = 10, + B001010 DEPRECATED(0b001010) = 10, + B0001010 DEPRECATED(0b0001010) = 10, B00001010 DEPRECATED(0b00001010) = 10, - B1011 DEPRECATED(0b1011 ) = 11, - B01011 DEPRECATED(0b01011 ) = 11, - B001011 DEPRECATED(0b001011 ) = 11, - B0001011 DEPRECATED(0b0001011 ) = 11, + B1011 DEPRECATED(0b1011) = 11, + B01011 DEPRECATED(0b01011) = 11, + B001011 DEPRECATED(0b001011) = 11, + B0001011 DEPRECATED(0b0001011) = 11, B00001011 DEPRECATED(0b00001011) = 11, - B1100 DEPRECATED(0b1100 ) = 12, - B01100 DEPRECATED(0b01100 ) = 12, - B001100 DEPRECATED(0b001100 ) = 12, - B0001100 DEPRECATED(0b0001100 ) = 12, + B1100 DEPRECATED(0b1100) = 12, + B01100 DEPRECATED(0b01100) = 12, + B001100 DEPRECATED(0b001100) = 12, + B0001100 DEPRECATED(0b0001100) = 12, B00001100 DEPRECATED(0b00001100) = 12, - B1101 DEPRECATED(0b1101 ) = 13, - B01101 DEPRECATED(0b01101 ) = 13, - B001101 DEPRECATED(0b001101 ) = 13, - B0001101 DEPRECATED(0b0001101 ) = 13, + B1101 DEPRECATED(0b1101) = 13, + B01101 DEPRECATED(0b01101) = 13, + B001101 DEPRECATED(0b001101) = 13, + B0001101 DEPRECATED(0b0001101) = 13, B00001101 DEPRECATED(0b00001101) = 13, - B1110 DEPRECATED(0b1110 ) = 14, - B01110 DEPRECATED(0b01110 ) = 14, - B001110 DEPRECATED(0b001110 ) = 14, - B0001110 DEPRECATED(0b0001110 ) = 14, + B1110 DEPRECATED(0b1110) = 14, + B01110 DEPRECATED(0b01110) = 14, + B001110 DEPRECATED(0b001110) = 14, + B0001110 DEPRECATED(0b0001110) = 14, B00001110 DEPRECATED(0b00001110) = 14, - B1111 DEPRECATED(0b1111 ) = 15, - B01111 DEPRECATED(0b01111 ) = 15, - B001111 DEPRECATED(0b001111 ) = 15, - B0001111 DEPRECATED(0b0001111 ) = 15, + B1111 DEPRECATED(0b1111) = 15, + B01111 DEPRECATED(0b01111) = 15, + B001111 DEPRECATED(0b001111) = 15, + B0001111 DEPRECATED(0b0001111) = 15, B00001111 DEPRECATED(0b00001111) = 15, - B10000 DEPRECATED(0b10000 ) = 16, - B010000 DEPRECATED(0b010000 ) = 16, - B0010000 DEPRECATED(0b0010000 ) = 16, + B10000 DEPRECATED(0b10000) = 16, + B010000 DEPRECATED(0b010000) = 16, + B0010000 DEPRECATED(0b0010000) = 16, B00010000 DEPRECATED(0b00010000) = 16, - B10001 DEPRECATED(0b10001 ) = 17, - B010001 DEPRECATED(0b010001 ) = 17, - B0010001 DEPRECATED(0b0010001 ) = 17, + B10001 DEPRECATED(0b10001) = 17, + B010001 DEPRECATED(0b010001) = 17, + B0010001 DEPRECATED(0b0010001) = 17, B00010001 DEPRECATED(0b00010001) = 17, - B10010 DEPRECATED(0b10010 ) = 18, - B010010 DEPRECATED(0b010010 ) = 18, - B0010010 DEPRECATED(0b0010010 ) = 18, + B10010 DEPRECATED(0b10010) = 18, + B010010 DEPRECATED(0b010010) = 18, + B0010010 DEPRECATED(0b0010010) = 18, B00010010 DEPRECATED(0b00010010) = 18, - B10011 DEPRECATED(0b10011 ) = 19, - B010011 DEPRECATED(0b010011 ) = 19, - B0010011 DEPRECATED(0b0010011 ) = 19, + B10011 DEPRECATED(0b10011) = 19, + B010011 DEPRECATED(0b010011) = 19, + B0010011 DEPRECATED(0b0010011) = 19, B00010011 DEPRECATED(0b00010011) = 19, - B10100 DEPRECATED(0b10100 ) = 20, - B010100 DEPRECATED(0b010100 ) = 20, - B0010100 DEPRECATED(0b0010100 ) = 20, + B10100 DEPRECATED(0b10100) = 20, + B010100 DEPRECATED(0b010100) = 20, + B0010100 DEPRECATED(0b0010100) = 20, B00010100 DEPRECATED(0b00010100) = 20, - B10101 DEPRECATED(0b10101 ) = 21, - B010101 DEPRECATED(0b010101 ) = 21, - B0010101 DEPRECATED(0b0010101 ) = 21, + B10101 DEPRECATED(0b10101) = 21, + B010101 DEPRECATED(0b010101) = 21, + B0010101 DEPRECATED(0b0010101) = 21, B00010101 DEPRECATED(0b00010101) = 21, - B10110 DEPRECATED(0b10110 ) = 22, - B010110 DEPRECATED(0b010110 ) = 22, - B0010110 DEPRECATED(0b0010110 ) = 22, + B10110 DEPRECATED(0b10110) = 22, + B010110 DEPRECATED(0b010110) = 22, + B0010110 DEPRECATED(0b0010110) = 22, B00010110 DEPRECATED(0b00010110) = 22, - B10111 DEPRECATED(0b10111 ) = 23, - B010111 DEPRECATED(0b010111 ) = 23, - B0010111 DEPRECATED(0b0010111 ) = 23, + B10111 DEPRECATED(0b10111) = 23, + B010111 DEPRECATED(0b010111) = 23, + B0010111 DEPRECATED(0b0010111) = 23, B00010111 DEPRECATED(0b00010111) = 23, - B11000 DEPRECATED(0b11000 ) = 24, - B011000 DEPRECATED(0b011000 ) = 24, - B0011000 DEPRECATED(0b0011000 ) = 24, + B11000 DEPRECATED(0b11000) = 24, + B011000 DEPRECATED(0b011000) = 24, + B0011000 DEPRECATED(0b0011000) = 24, B00011000 DEPRECATED(0b00011000) = 24, - B11001 DEPRECATED(0b11001 ) = 25, - B011001 DEPRECATED(0b011001 ) = 25, - B0011001 DEPRECATED(0b0011001 ) = 25, + B11001 DEPRECATED(0b11001) = 25, + B011001 DEPRECATED(0b011001) = 25, + B0011001 DEPRECATED(0b0011001) = 25, B00011001 DEPRECATED(0b00011001) = 25, - B11010 DEPRECATED(0b11010 ) = 26, - B011010 DEPRECATED(0b011010 ) = 26, - B0011010 DEPRECATED(0b0011010 ) = 26, + B11010 DEPRECATED(0b11010) = 26, + B011010 DEPRECATED(0b011010) = 26, + B0011010 DEPRECATED(0b0011010) = 26, B00011010 DEPRECATED(0b00011010) = 26, - B11011 DEPRECATED(0b11011 ) = 27, - B011011 DEPRECATED(0b011011 ) = 27, - B0011011 DEPRECATED(0b0011011 ) = 27, + B11011 DEPRECATED(0b11011) = 27, + B011011 DEPRECATED(0b011011) = 27, + B0011011 DEPRECATED(0b0011011) = 27, B00011011 DEPRECATED(0b00011011) = 27, - B11100 DEPRECATED(0b11100 ) = 28, - B011100 DEPRECATED(0b011100 ) = 28, - B0011100 DEPRECATED(0b0011100 ) = 28, + B11100 DEPRECATED(0b11100) = 28, + B011100 DEPRECATED(0b011100) = 28, + B0011100 DEPRECATED(0b0011100) = 28, B00011100 DEPRECATED(0b00011100) = 28, - B11101 DEPRECATED(0b11101 ) = 29, - B011101 DEPRECATED(0b011101 ) = 29, - B0011101 DEPRECATED(0b0011101 ) = 29, + B11101 DEPRECATED(0b11101) = 29, + B011101 DEPRECATED(0b011101) = 29, + B0011101 DEPRECATED(0b0011101) = 29, B00011101 DEPRECATED(0b00011101) = 29, - B11110 DEPRECATED(0b11110 ) = 30, - B011110 DEPRECATED(0b011110 ) = 30, - B0011110 DEPRECATED(0b0011110 ) = 30, + B11110 DEPRECATED(0b11110) = 30, + B011110 DEPRECATED(0b011110) = 30, + B0011110 DEPRECATED(0b0011110) = 30, B00011110 DEPRECATED(0b00011110) = 30, - B11111 DEPRECATED(0b11111 ) = 31, - B011111 DEPRECATED(0b011111 ) = 31, - B0011111 DEPRECATED(0b0011111 ) = 31, + B11111 DEPRECATED(0b11111) = 31, + B011111 DEPRECATED(0b011111) = 31, + B0011111 DEPRECATED(0b0011111) = 31, B00011111 DEPRECATED(0b00011111) = 31, - B100000 DEPRECATED(0b100000 ) = 32, - B0100000 DEPRECATED(0b0100000 ) = 32, + B100000 DEPRECATED(0b100000) = 32, + B0100000 DEPRECATED(0b0100000) = 32, B00100000 DEPRECATED(0b00100000) = 32, - B100001 DEPRECATED(0b100001 ) = 33, - B0100001 DEPRECATED(0b0100001 ) = 33, + B100001 DEPRECATED(0b100001) = 33, + B0100001 DEPRECATED(0b0100001) = 33, B00100001 DEPRECATED(0b00100001) = 33, - B100010 DEPRECATED(0b100010 ) = 34, - B0100010 DEPRECATED(0b0100010 ) = 34, + B100010 DEPRECATED(0b100010) = 34, + B0100010 DEPRECATED(0b0100010) = 34, B00100010 DEPRECATED(0b00100010) = 34, - B100011 DEPRECATED(0b100011 ) = 35, - B0100011 DEPRECATED(0b0100011 ) = 35, + B100011 DEPRECATED(0b100011) = 35, + B0100011 DEPRECATED(0b0100011) = 35, B00100011 DEPRECATED(0b00100011) = 35, - B100100 DEPRECATED(0b100100 ) = 36, - B0100100 DEPRECATED(0b0100100 ) = 36, + B100100 DEPRECATED(0b100100) = 36, + B0100100 DEPRECATED(0b0100100) = 36, B00100100 DEPRECATED(0b00100100) = 36, - B100101 DEPRECATED(0b100101 ) = 37, - B0100101 DEPRECATED(0b0100101 ) = 37, + B100101 DEPRECATED(0b100101) = 37, + B0100101 DEPRECATED(0b0100101) = 37, B00100101 DEPRECATED(0b00100101) = 37, - B100110 DEPRECATED(0b100110 ) = 38, - B0100110 DEPRECATED(0b0100110 ) = 38, + B100110 DEPRECATED(0b100110) = 38, + B0100110 DEPRECATED(0b0100110) = 38, B00100110 DEPRECATED(0b00100110) = 38, - B100111 DEPRECATED(0b100111 ) = 39, - B0100111 DEPRECATED(0b0100111 ) = 39, + B100111 DEPRECATED(0b100111) = 39, + B0100111 DEPRECATED(0b0100111) = 39, B00100111 DEPRECATED(0b00100111) = 39, - B101000 DEPRECATED(0b101000 ) = 40, - B0101000 DEPRECATED(0b0101000 ) = 40, + B101000 DEPRECATED(0b101000) = 40, + B0101000 DEPRECATED(0b0101000) = 40, B00101000 DEPRECATED(0b00101000) = 40, - B101001 DEPRECATED(0b101001 ) = 41, - B0101001 DEPRECATED(0b0101001 ) = 41, + B101001 DEPRECATED(0b101001) = 41, + B0101001 DEPRECATED(0b0101001) = 41, B00101001 DEPRECATED(0b00101001) = 41, - B101010 DEPRECATED(0b101010 ) = 42, - B0101010 DEPRECATED(0b0101010 ) = 42, + B101010 DEPRECATED(0b101010) = 42, + B0101010 DEPRECATED(0b0101010) = 42, B00101010 DEPRECATED(0b00101010) = 42, - B101011 DEPRECATED(0b101011 ) = 43, - B0101011 DEPRECATED(0b0101011 ) = 43, + B101011 DEPRECATED(0b101011) = 43, + B0101011 DEPRECATED(0b0101011) = 43, B00101011 DEPRECATED(0b00101011) = 43, - B101100 DEPRECATED(0b101100 ) = 44, - B0101100 DEPRECATED(0b0101100 ) = 44, + B101100 DEPRECATED(0b101100) = 44, + B0101100 DEPRECATED(0b0101100) = 44, B00101100 DEPRECATED(0b00101100) = 44, - B101101 DEPRECATED(0b101101 ) = 45, - B0101101 DEPRECATED(0b0101101 ) = 45, + B101101 DEPRECATED(0b101101) = 45, + B0101101 DEPRECATED(0b0101101) = 45, B00101101 DEPRECATED(0b00101101) = 45, - B101110 DEPRECATED(0b101110 ) = 46, - B0101110 DEPRECATED(0b0101110 ) = 46, + B101110 DEPRECATED(0b101110) = 46, + B0101110 DEPRECATED(0b0101110) = 46, B00101110 DEPRECATED(0b00101110) = 46, - B101111 DEPRECATED(0b101111 ) = 47, - B0101111 DEPRECATED(0b0101111 ) = 47, + B101111 DEPRECATED(0b101111) = 47, + B0101111 DEPRECATED(0b0101111) = 47, B00101111 DEPRECATED(0b00101111) = 47, - B110000 DEPRECATED(0b110000 ) = 48, - B0110000 DEPRECATED(0b0110000 ) = 48, + B110000 DEPRECATED(0b110000) = 48, + B0110000 DEPRECATED(0b0110000) = 48, B00110000 DEPRECATED(0b00110000) = 48, - B110001 DEPRECATED(0b110001 ) = 49, - B0110001 DEPRECATED(0b0110001 ) = 49, + B110001 DEPRECATED(0b110001) = 49, + B0110001 DEPRECATED(0b0110001) = 49, B00110001 DEPRECATED(0b00110001) = 49, - B110010 DEPRECATED(0b110010 ) = 50, - B0110010 DEPRECATED(0b0110010 ) = 50, + B110010 DEPRECATED(0b110010) = 50, + B0110010 DEPRECATED(0b0110010) = 50, B00110010 DEPRECATED(0b00110010) = 50, - B110011 DEPRECATED(0b110011 ) = 51, - B0110011 DEPRECATED(0b0110011 ) = 51, + B110011 DEPRECATED(0b110011) = 51, + B0110011 DEPRECATED(0b0110011) = 51, B00110011 DEPRECATED(0b00110011) = 51, - B110100 DEPRECATED(0b110100 ) = 52, - B0110100 DEPRECATED(0b0110100 ) = 52, + B110100 DEPRECATED(0b110100) = 52, + B0110100 DEPRECATED(0b0110100) = 52, B00110100 DEPRECATED(0b00110100) = 52, - B110101 DEPRECATED(0b110101 ) = 53, - B0110101 DEPRECATED(0b0110101 ) = 53, + B110101 DEPRECATED(0b110101) = 53, + B0110101 DEPRECATED(0b0110101) = 53, B00110101 DEPRECATED(0b00110101) = 53, - B110110 DEPRECATED(0b110110 ) = 54, - B0110110 DEPRECATED(0b0110110 ) = 54, + B110110 DEPRECATED(0b110110) = 54, + B0110110 DEPRECATED(0b0110110) = 54, B00110110 DEPRECATED(0b00110110) = 54, - B110111 DEPRECATED(0b110111 ) = 55, - B0110111 DEPRECATED(0b0110111 ) = 55, + B110111 DEPRECATED(0b110111) = 55, + B0110111 DEPRECATED(0b0110111) = 55, B00110111 DEPRECATED(0b00110111) = 55, - B111000 DEPRECATED(0b111000 ) = 56, - B0111000 DEPRECATED(0b0111000 ) = 56, + B111000 DEPRECATED(0b111000) = 56, + B0111000 DEPRECATED(0b0111000) = 56, B00111000 DEPRECATED(0b00111000) = 56, - B111001 DEPRECATED(0b111001 ) = 57, - B0111001 DEPRECATED(0b0111001 ) = 57, + B111001 DEPRECATED(0b111001) = 57, + B0111001 DEPRECATED(0b0111001) = 57, B00111001 DEPRECATED(0b00111001) = 57, - B111010 DEPRECATED(0b111010 ) = 58, - B0111010 DEPRECATED(0b0111010 ) = 58, + B111010 DEPRECATED(0b111010) = 58, + B0111010 DEPRECATED(0b0111010) = 58, B00111010 DEPRECATED(0b00111010) = 58, - B111011 DEPRECATED(0b111011 ) = 59, - B0111011 DEPRECATED(0b0111011 ) = 59, + B111011 DEPRECATED(0b111011) = 59, + B0111011 DEPRECATED(0b0111011) = 59, B00111011 DEPRECATED(0b00111011) = 59, - B111100 DEPRECATED(0b111100 ) = 60, - B0111100 DEPRECATED(0b0111100 ) = 60, + B111100 DEPRECATED(0b111100) = 60, + B0111100 DEPRECATED(0b0111100) = 60, B00111100 DEPRECATED(0b00111100) = 60, - B111101 DEPRECATED(0b111101 ) = 61, - B0111101 DEPRECATED(0b0111101 ) = 61, + B111101 DEPRECATED(0b111101) = 61, + B0111101 DEPRECATED(0b0111101) = 61, B00111101 DEPRECATED(0b00111101) = 61, - B111110 DEPRECATED(0b111110 ) = 62, - B0111110 DEPRECATED(0b0111110 ) = 62, + B111110 DEPRECATED(0b111110) = 62, + B0111110 DEPRECATED(0b0111110) = 62, B00111110 DEPRECATED(0b00111110) = 62, - B111111 DEPRECATED(0b111111 ) = 63, - B0111111 DEPRECATED(0b0111111 ) = 63, + B111111 DEPRECATED(0b111111) = 63, + B0111111 DEPRECATED(0b0111111) = 63, B00111111 DEPRECATED(0b00111111) = 63, - B1000000 DEPRECATED(0b1000000 ) = 64, + B1000000 DEPRECATED(0b1000000) = 64, B01000000 DEPRECATED(0b01000000) = 64, - B1000001 DEPRECATED(0b1000001 ) = 65, + B1000001 DEPRECATED(0b1000001) = 65, B01000001 DEPRECATED(0b01000001) = 65, - B1000010 DEPRECATED(0b1000010 ) = 66, + B1000010 DEPRECATED(0b1000010) = 66, B01000010 DEPRECATED(0b01000010) = 66, - B1000011 DEPRECATED(0b1000011 ) = 67, + B1000011 DEPRECATED(0b1000011) = 67, B01000011 DEPRECATED(0b01000011) = 67, - B1000100 DEPRECATED(0b1000100 ) = 68, + B1000100 DEPRECATED(0b1000100) = 68, B01000100 DEPRECATED(0b01000100) = 68, - B1000101 DEPRECATED(0b1000101 ) = 69, + B1000101 DEPRECATED(0b1000101) = 69, B01000101 DEPRECATED(0b01000101) = 69, - B1000110 DEPRECATED(0b1000110 ) = 70, + B1000110 DEPRECATED(0b1000110) = 70, B01000110 DEPRECATED(0b01000110) = 70, - B1000111 DEPRECATED(0b1000111 ) = 71, + B1000111 DEPRECATED(0b1000111) = 71, B01000111 DEPRECATED(0b01000111) = 71, - B1001000 DEPRECATED(0b1001000 ) = 72, + B1001000 DEPRECATED(0b1001000) = 72, B01001000 DEPRECATED(0b01001000) = 72, - B1001001 DEPRECATED(0b1001001 ) = 73, + B1001001 DEPRECATED(0b1001001) = 73, B01001001 DEPRECATED(0b01001001) = 73, - B1001010 DEPRECATED(0b1001010 ) = 74, + B1001010 DEPRECATED(0b1001010) = 74, B01001010 DEPRECATED(0b01001010) = 74, - B1001011 DEPRECATED(0b1001011 ) = 75, + B1001011 DEPRECATED(0b1001011) = 75, B01001011 DEPRECATED(0b01001011) = 75, - B1001100 DEPRECATED(0b1001100 ) = 76, + B1001100 DEPRECATED(0b1001100) = 76, B01001100 DEPRECATED(0b01001100) = 76, - B1001101 DEPRECATED(0b1001101 ) = 77, + B1001101 DEPRECATED(0b1001101) = 77, B01001101 DEPRECATED(0b01001101) = 77, - B1001110 DEPRECATED(0b1001110 ) = 78, + B1001110 DEPRECATED(0b1001110) = 78, B01001110 DEPRECATED(0b01001110) = 78, - B1001111 DEPRECATED(0b1001111 ) = 79, + B1001111 DEPRECATED(0b1001111) = 79, B01001111 DEPRECATED(0b01001111) = 79, - B1010000 DEPRECATED(0b1010000 ) = 80, + B1010000 DEPRECATED(0b1010000) = 80, B01010000 DEPRECATED(0b01010000) = 80, - B1010001 DEPRECATED(0b1010001 ) = 81, + B1010001 DEPRECATED(0b1010001) = 81, B01010001 DEPRECATED(0b01010001) = 81, - B1010010 DEPRECATED(0b1010010 ) = 82, + B1010010 DEPRECATED(0b1010010) = 82, B01010010 DEPRECATED(0b01010010) = 82, - B1010011 DEPRECATED(0b1010011 ) = 83, + B1010011 DEPRECATED(0b1010011) = 83, B01010011 DEPRECATED(0b01010011) = 83, - B1010100 DEPRECATED(0b1010100 ) = 84, + B1010100 DEPRECATED(0b1010100) = 84, B01010100 DEPRECATED(0b01010100) = 84, - B1010101 DEPRECATED(0b1010101 ) = 85, + B1010101 DEPRECATED(0b1010101) = 85, B01010101 DEPRECATED(0b01010101) = 85, - B1010110 DEPRECATED(0b1010110 ) = 86, + B1010110 DEPRECATED(0b1010110) = 86, B01010110 DEPRECATED(0b01010110) = 86, - B1010111 DEPRECATED(0b1010111 ) = 87, + B1010111 DEPRECATED(0b1010111) = 87, B01010111 DEPRECATED(0b01010111) = 87, - B1011000 DEPRECATED(0b1011000 ) = 88, + B1011000 DEPRECATED(0b1011000) = 88, B01011000 DEPRECATED(0b01011000) = 88, - B1011001 DEPRECATED(0b1011001 ) = 89, + B1011001 DEPRECATED(0b1011001) = 89, B01011001 DEPRECATED(0b01011001) = 89, - B1011010 DEPRECATED(0b1011010 ) = 90, + B1011010 DEPRECATED(0b1011010) = 90, B01011010 DEPRECATED(0b01011010) = 90, - B1011011 DEPRECATED(0b1011011 ) = 91, + B1011011 DEPRECATED(0b1011011) = 91, B01011011 DEPRECATED(0b01011011) = 91, - B1011100 DEPRECATED(0b1011100 ) = 92, + B1011100 DEPRECATED(0b1011100) = 92, B01011100 DEPRECATED(0b01011100) = 92, - B1011101 DEPRECATED(0b1011101 ) = 93, + B1011101 DEPRECATED(0b1011101) = 93, B01011101 DEPRECATED(0b01011101) = 93, - B1011110 DEPRECATED(0b1011110 ) = 94, + B1011110 DEPRECATED(0b1011110) = 94, B01011110 DEPRECATED(0b01011110) = 94, - B1011111 DEPRECATED(0b1011111 ) = 95, + B1011111 DEPRECATED(0b1011111) = 95, B01011111 DEPRECATED(0b01011111) = 95, - B1100000 DEPRECATED(0b1100000 ) = 96, + B1100000 DEPRECATED(0b1100000) = 96, B01100000 DEPRECATED(0b01100000) = 96, - B1100001 DEPRECATED(0b1100001 ) = 97, + B1100001 DEPRECATED(0b1100001) = 97, B01100001 DEPRECATED(0b01100001) = 97, - B1100010 DEPRECATED(0b1100010 ) = 98, + B1100010 DEPRECATED(0b1100010) = 98, B01100010 DEPRECATED(0b01100010) = 98, - B1100011 DEPRECATED(0b1100011 ) = 99, + B1100011 DEPRECATED(0b1100011) = 99, B01100011 DEPRECATED(0b01100011) = 99, - B1100100 DEPRECATED(0b1100100 ) = 100, + B1100100 DEPRECATED(0b1100100) = 100, B01100100 DEPRECATED(0b01100100) = 100, - B1100101 DEPRECATED(0b1100101 ) = 101, + B1100101 DEPRECATED(0b1100101) = 101, B01100101 DEPRECATED(0b01100101) = 101, - B1100110 DEPRECATED(0b1100110 ) = 102, + B1100110 DEPRECATED(0b1100110) = 102, B01100110 DEPRECATED(0b01100110) = 102, - B1100111 DEPRECATED(0b1100111 ) = 103, + B1100111 DEPRECATED(0b1100111) = 103, B01100111 DEPRECATED(0b01100111) = 103, - B1101000 DEPRECATED(0b1101000 ) = 104, + B1101000 DEPRECATED(0b1101000) = 104, B01101000 DEPRECATED(0b01101000) = 104, - B1101001 DEPRECATED(0b1101001 ) = 105, + B1101001 DEPRECATED(0b1101001) = 105, B01101001 DEPRECATED(0b01101001) = 105, - B1101010 DEPRECATED(0b1101010 ) = 106, + B1101010 DEPRECATED(0b1101010) = 106, B01101010 DEPRECATED(0b01101010) = 106, - B1101011 DEPRECATED(0b1101011 ) = 107, + B1101011 DEPRECATED(0b1101011) = 107, B01101011 DEPRECATED(0b01101011) = 107, - B1101100 DEPRECATED(0b1101100 ) = 108, + B1101100 DEPRECATED(0b1101100) = 108, B01101100 DEPRECATED(0b01101100) = 108, - B1101101 DEPRECATED(0b1101101 ) = 109, + B1101101 DEPRECATED(0b1101101) = 109, B01101101 DEPRECATED(0b01101101) = 109, - B1101110 DEPRECATED(0b1101110 ) = 110, + B1101110 DEPRECATED(0b1101110) = 110, B01101110 DEPRECATED(0b01101110) = 110, - B1101111 DEPRECATED(0b1101111 ) = 111, + B1101111 DEPRECATED(0b1101111) = 111, B01101111 DEPRECATED(0b01101111) = 111, - B1110000 DEPRECATED(0b1110000 ) = 112, + B1110000 DEPRECATED(0b1110000) = 112, B01110000 DEPRECATED(0b01110000) = 112, - B1110001 DEPRECATED(0b1110001 ) = 113, + B1110001 DEPRECATED(0b1110001) = 113, B01110001 DEPRECATED(0b01110001) = 113, - B1110010 DEPRECATED(0b1110010 ) = 114, + B1110010 DEPRECATED(0b1110010) = 114, B01110010 DEPRECATED(0b01110010) = 114, - B1110011 DEPRECATED(0b1110011 ) = 115, + B1110011 DEPRECATED(0b1110011) = 115, B01110011 DEPRECATED(0b01110011) = 115, - B1110100 DEPRECATED(0b1110100 ) = 116, + B1110100 DEPRECATED(0b1110100) = 116, B01110100 DEPRECATED(0b01110100) = 116, - B1110101 DEPRECATED(0b1110101 ) = 117, + B1110101 DEPRECATED(0b1110101) = 117, B01110101 DEPRECATED(0b01110101) = 117, - B1110110 DEPRECATED(0b1110110 ) = 118, + B1110110 DEPRECATED(0b1110110) = 118, B01110110 DEPRECATED(0b01110110) = 118, - B1110111 DEPRECATED(0b1110111 ) = 119, + B1110111 DEPRECATED(0b1110111) = 119, B01110111 DEPRECATED(0b01110111) = 119, - B1111000 DEPRECATED(0b1111000 ) = 120, + B1111000 DEPRECATED(0b1111000) = 120, B01111000 DEPRECATED(0b01111000) = 120, - B1111001 DEPRECATED(0b1111001 ) = 121, + B1111001 DEPRECATED(0b1111001) = 121, B01111001 DEPRECATED(0b01111001) = 121, - B1111010 DEPRECATED(0b1111010 ) = 122, + B1111010 DEPRECATED(0b1111010) = 122, B01111010 DEPRECATED(0b01111010) = 122, - B1111011 DEPRECATED(0b1111011 ) = 123, + B1111011 DEPRECATED(0b1111011) = 123, B01111011 DEPRECATED(0b01111011) = 123, - B1111100 DEPRECATED(0b1111100 ) = 124, + B1111100 DEPRECATED(0b1111100) = 124, B01111100 DEPRECATED(0b01111100) = 124, - B1111101 DEPRECATED(0b1111101 ) = 125, + B1111101 DEPRECATED(0b1111101) = 125, B01111101 DEPRECATED(0b01111101) = 125, - B1111110 DEPRECATED(0b1111110 ) = 126, + B1111110 DEPRECATED(0b1111110) = 126, B01111110 DEPRECATED(0b01111110) = 126, - B1111111 DEPRECATED(0b1111111 ) = 127, + B1111111 DEPRECATED(0b1111111) = 127, B01111111 DEPRECATED(0b01111111) = 127, B10000000 DEPRECATED(0b10000000) = 128, B10000001 DEPRECATED(0b10000001) = 129, diff --git a/cores/esp32/cbuf.cpp b/cores/esp32/cbuf.cpp index 4a110fd732a..26b26d081f3 100644 --- a/cores/esp32/cbuf.cpp +++ b/cores/esp32/cbuf.cpp @@ -27,264 +27,259 @@ #define CBUF_MUTEX_UNLOCK() #define CBUF_MUTEX_DELETE() #else -#define CBUF_MUTEX_CREATE() if(_lock == NULL){_lock = xSemaphoreCreateMutex(); if(_lock == NULL){log_e("failed to create mutex");}} -#define CBUF_MUTEX_LOCK() if(_lock != NULL){xSemaphoreTakeRecursive(_lock, portMAX_DELAY);} -#define CBUF_MUTEX_UNLOCK() if(_lock != NULL){xSemaphoreGiveRecursive(_lock);} -#define CBUF_MUTEX_DELETE() if(_lock != NULL){SemaphoreHandle_t l = _lock; _lock = NULL; vSemaphoreDelete(l);} +#define CBUF_MUTEX_CREATE() \ + if (_lock == NULL) { \ + _lock = xSemaphoreCreateMutex(); \ + if (_lock == NULL) { log_e("failed to create mutex"); } \ + } +#define CBUF_MUTEX_LOCK() \ + if (_lock != NULL) { xSemaphoreTakeRecursive(_lock, portMAX_DELAY); } +#define CBUF_MUTEX_UNLOCK() \ + if (_lock != NULL) { xSemaphoreGiveRecursive(_lock); } +#define CBUF_MUTEX_DELETE() \ + if (_lock != NULL) { \ + SemaphoreHandle_t l = _lock; \ + _lock = NULL; \ + vSemaphoreDelete(l); \ + } #endif -cbuf::cbuf(size_t size) : - next(NULL), +cbuf::cbuf(size_t size) + : next(NULL), has_peek(false), peek_byte(0), - _buf(xRingbufferCreate(size, RINGBUF_TYPE_BYTEBUF)) -{ - if(_buf == NULL) { - log_e("failed to allocate ring buffer"); - } - CBUF_MUTEX_CREATE(); + _buf(xRingbufferCreate(size, RINGBUF_TYPE_BYTEBUF)) { + if (_buf == NULL) { + log_e("failed to allocate ring buffer"); + } + CBUF_MUTEX_CREATE(); } -cbuf::~cbuf() -{ - CBUF_MUTEX_LOCK(); - if(_buf != NULL){ - RingbufHandle_t b = _buf; - _buf = NULL; - vRingbufferDelete(b); - } - CBUF_MUTEX_UNLOCK(); - CBUF_MUTEX_DELETE(); +cbuf::~cbuf() { + CBUF_MUTEX_LOCK(); + if (_buf != NULL) { + RingbufHandle_t b = _buf; + _buf = NULL; + vRingbufferDelete(b); + } + CBUF_MUTEX_UNLOCK(); + CBUF_MUTEX_DELETE(); } -size_t cbuf::resizeAdd(size_t addSize) -{ - return resize(size() + addSize); +size_t cbuf::resizeAdd(size_t addSize) { + return resize(size() + addSize); } -size_t cbuf::resize(size_t newSize) -{ - CBUF_MUTEX_LOCK(); - size_t _size = size(); - if(newSize == _size) { - return _size; - } +size_t cbuf::resize(size_t newSize) { + CBUF_MUTEX_LOCK(); + size_t _size = size(); + if (newSize == _size) { + return _size; + } + + // not lose any data + // if data can be lost use remove or flush before resize + size_t bytes_available = available(); + if (newSize < bytes_available) { + CBUF_MUTEX_UNLOCK(); + log_e("new size is less than the currently available data size"); + return _size; + } + + RingbufHandle_t newbuf = xRingbufferCreate(newSize, RINGBUF_TYPE_BYTEBUF); + if (newbuf == NULL) { + CBUF_MUTEX_UNLOCK(); + log_e("failed to allocate new ring buffer"); + return _size; + } - // not lose any data - // if data can be lost use remove or flush before resize - size_t bytes_available = available(); - if(newSize < bytes_available) { + if (_buf != NULL) { + if (bytes_available) { + char *old_data = (char *)malloc(bytes_available); + if (old_data == NULL) { + vRingbufferDelete(newbuf); CBUF_MUTEX_UNLOCK(); - log_e("new size is less than the currently available data size"); + log_e("failed to allocate temporary buffer"); return _size; - } - - RingbufHandle_t newbuf = xRingbufferCreate(newSize, RINGBUF_TYPE_BYTEBUF); - if(newbuf == NULL) { + } + bytes_available = read(old_data, bytes_available); + if (!bytes_available) { + free(old_data); + vRingbufferDelete(newbuf); CBUF_MUTEX_UNLOCK(); - log_e("failed to allocate new ring buffer"); + log_e("failed to read previous data"); return _size; + } + if (xRingbufferSend(newbuf, (void *)old_data, bytes_available, 0) != pdTRUE) { + write(old_data, bytes_available); + free(old_data); + vRingbufferDelete(newbuf); + CBUF_MUTEX_UNLOCK(); + log_e("failed to restore previous data"); + return _size; + } + free(old_data); } - if(_buf != NULL) { - if(bytes_available){ - char * old_data = (char *)malloc(bytes_available); - if(old_data == NULL){ - vRingbufferDelete(newbuf); - CBUF_MUTEX_UNLOCK(); - log_e("failed to allocate temporary buffer"); - return _size; - } - bytes_available = read(old_data, bytes_available); - if(!bytes_available){ - free(old_data); - vRingbufferDelete(newbuf); - CBUF_MUTEX_UNLOCK(); - log_e("failed to read previous data"); - return _size; - } - if(xRingbufferSend(newbuf, (void*)old_data, bytes_available, 0) != pdTRUE){ - write(old_data, bytes_available); - free(old_data); - vRingbufferDelete(newbuf); - CBUF_MUTEX_UNLOCK(); - log_e("failed to restore previous data"); - return _size; - } - free(old_data); - } - - RingbufHandle_t b = _buf; - _buf = newbuf; - vRingbufferDelete(b); - } else { - _buf = newbuf; - } - CBUF_MUTEX_UNLOCK(); - return newSize; + RingbufHandle_t b = _buf; + _buf = newbuf; + vRingbufferDelete(b); + } else { + _buf = newbuf; + } + CBUF_MUTEX_UNLOCK(); + return newSize; } -size_t cbuf::available() const -{ - size_t available = 0; - if(_buf != NULL){ - vRingbufferGetInfo(_buf, NULL, NULL, NULL, NULL, (UBaseType_t *)&available); - } - if (has_peek) available++; - return available; +size_t cbuf::available() const { + size_t available = 0; + if (_buf != NULL) { + vRingbufferGetInfo(_buf, NULL, NULL, NULL, NULL, (UBaseType_t *)&available); + } + if (has_peek) available++; + return available; } -size_t cbuf::size() -{ - size_t _size = 0; - if(_buf != NULL){ - _size = xRingbufferGetMaxItemSize(_buf); - } - return _size; +size_t cbuf::size() { + size_t _size = 0; + if (_buf != NULL) { + _size = xRingbufferGetMaxItemSize(_buf); + } + return _size; } -size_t cbuf::room() const -{ - size_t _room = 0; - if(_buf != NULL){ - _room = xRingbufferGetCurFreeSize(_buf); - } - return _room; +size_t cbuf::room() const { + size_t _room = 0; + if (_buf != NULL) { + _room = xRingbufferGetCurFreeSize(_buf); + } + return _room; } -bool cbuf::empty() const -{ - return available() == 0; +bool cbuf::empty() const { + return available() == 0; } -bool cbuf::full() const -{ - return room() == 0; +bool cbuf::full() const { + return room() == 0; } -int cbuf::peek() -{ - if (!available()) { - return -1; - } +int cbuf::peek() { + if (!available()) { + return -1; + } - int c; + int c; - CBUF_MUTEX_LOCK(); - if (has_peek) { - c = peek_byte; - } else { - c = read(); - if (c >= 0) { - has_peek = true; - peek_byte = c; - } + CBUF_MUTEX_LOCK(); + if (has_peek) { + c = peek_byte; + } else { + c = read(); + if (c >= 0) { + has_peek = true; + peek_byte = c; } - CBUF_MUTEX_UNLOCK(); - return c; + } + CBUF_MUTEX_UNLOCK(); + return c; } -int cbuf::read() -{ - char result = 0; - if(!read(&result, 1)){ - return -1; - } - return static_cast(result); +int cbuf::read() { + char result = 0; + if (!read(&result, 1)) { + return -1; + } + return static_cast(result); } -size_t cbuf::read(char* dst, size_t size) -{ - CBUF_MUTEX_LOCK(); - size_t bytes_available = available(); - if(!bytes_available || !size){ - CBUF_MUTEX_UNLOCK(); - return 0; - } +size_t cbuf::read(char *dst, size_t size) { + CBUF_MUTEX_LOCK(); + size_t bytes_available = available(); + if (!bytes_available || !size) { + CBUF_MUTEX_UNLOCK(); + return 0; + } - if (has_peek) { - if (dst != NULL) { - *dst++ = peek_byte; - } - size--; + if (has_peek) { + if (dst != NULL) { + *dst++ = peek_byte; } + size--; + } - size_t size_read = 0; - if (size) { - size_t received_size = 0; - size_t size_to_read = (size < bytes_available) ? size : bytes_available; - uint8_t *received_buff = (uint8_t *)xRingbufferReceiveUpTo(_buf, &received_size, 0, size_to_read); + size_t size_read = 0; + if (size) { + size_t received_size = 0; + size_t size_to_read = (size < bytes_available) ? size : bytes_available; + uint8_t *received_buff = (uint8_t *)xRingbufferReceiveUpTo(_buf, &received_size, 0, size_to_read); + if (received_buff != NULL) { + if (dst != NULL) { + memcpy(dst, received_buff, received_size); + } + vRingbufferReturnItem(_buf, received_buff); + size_read = received_size; + size_to_read -= received_size; + // wrap around data + if (size_to_read) { + received_size = 0; + received_buff = (uint8_t *)xRingbufferReceiveUpTo(_buf, &received_size, 0, size_to_read); if (received_buff != NULL) { - if(dst != NULL){ - memcpy(dst, received_buff, received_size); - } - vRingbufferReturnItem(_buf, received_buff); - size_read = received_size; - size_to_read -= received_size; - // wrap around data - if(size_to_read){ - received_size = 0; - received_buff = (uint8_t *)xRingbufferReceiveUpTo(_buf, &received_size, 0, size_to_read); - if (received_buff != NULL) { - if(dst != NULL){ - memcpy(dst+size_read, received_buff, received_size); - } - vRingbufferReturnItem(_buf, received_buff); - size_read += received_size; - } else { - log_e("failed to read wrap around data from ring buffer"); - } - } + if (dst != NULL) { + memcpy(dst + size_read, received_buff, received_size); + } + vRingbufferReturnItem(_buf, received_buff); + size_read += received_size; } else { - log_e("failed to read from ring buffer"); + log_e("failed to read wrap around data from ring buffer"); } + } + } else { + log_e("failed to read from ring buffer"); } + } - if (has_peek) { - has_peek = false; - size_read++; - } + if (has_peek) { + has_peek = false; + size_read++; + } - CBUF_MUTEX_UNLOCK(); - return size_read; + CBUF_MUTEX_UNLOCK(); + return size_read; } -size_t cbuf::write(char c) -{ - return write(&c, 1); +size_t cbuf::write(char c) { + return write(&c, 1); } -size_t cbuf::write(const char* src, size_t size) -{ - CBUF_MUTEX_LOCK(); - size_t bytes_available = room(); - if(!bytes_available || !size){ - CBUF_MUTEX_UNLOCK(); - return 0; - } - size_t size_to_write = (size < bytes_available) ? size : bytes_available; - if(xRingbufferSend(_buf, (void*)src, size_to_write, 0) != pdTRUE){ - CBUF_MUTEX_UNLOCK(); - log_e("failed to write to ring buffer"); - return 0; - } +size_t cbuf::write(const char *src, size_t size) { + CBUF_MUTEX_LOCK(); + size_t bytes_available = room(); + if (!bytes_available || !size) { + CBUF_MUTEX_UNLOCK(); + return 0; + } + size_t size_to_write = (size < bytes_available) ? size : bytes_available; + if (xRingbufferSend(_buf, (void *)src, size_to_write, 0) != pdTRUE) { CBUF_MUTEX_UNLOCK(); - return size_to_write; + log_e("failed to write to ring buffer"); + return 0; + } + CBUF_MUTEX_UNLOCK(); + return size_to_write; } -void cbuf::flush() -{ - read(NULL, available()); +void cbuf::flush() { + read(NULL, available()); } -size_t cbuf::remove(size_t size) -{ - CBUF_MUTEX_LOCK(); - size_t bytes_available = available(); - if(bytes_available && size){ - size_t size_to_remove = (size < bytes_available) ? size : bytes_available; - bytes_available -= read(NULL, size_to_remove); - } - CBUF_MUTEX_UNLOCK(); - return bytes_available; +size_t cbuf::remove(size_t size) { + CBUF_MUTEX_LOCK(); + size_t bytes_available = available(); + if (bytes_available && size) { + size_t size_to_remove = (size < bytes_available) ? size : bytes_available; + bytes_available -= read(NULL, size_to_remove); + } + CBUF_MUTEX_UNLOCK(); + return bytes_available; } diff --git a/cores/esp32/cbuf.h b/cores/esp32/cbuf.h index 29e11efb83e..a14af35c675 100644 --- a/cores/esp32/cbuf.h +++ b/cores/esp32/cbuf.h @@ -28,40 +28,38 @@ #include "freertos/ringbuf.h" #include "freertos/semphr.h" -class cbuf -{ +class cbuf { public: - cbuf(size_t size); - ~cbuf(); + cbuf(size_t size); + ~cbuf(); - size_t resizeAdd(size_t addSize); - size_t resize(size_t newSize); + size_t resizeAdd(size_t addSize); + size_t resize(size_t newSize); - size_t available() const; - size_t size(); - size_t room() const; - bool empty() const; - bool full() const; + size_t available() const; + size_t size(); + size_t room() const; + bool empty() const; + bool full() const; - int peek(); + int peek(); - int read(); - size_t read(char* dst, size_t size); + int read(); + size_t read(char* dst, size_t size); - size_t write(char c); - size_t write(const char* src, size_t size); + size_t write(char c); + size_t write(const char* src, size_t size); - void flush(); - size_t remove(size_t size); + void flush(); + size_t remove(size_t size); - cbuf *next; - bool has_peek; - uint8_t peek_byte; + cbuf* next; + bool has_peek; + uint8_t peek_byte; protected: - RingbufHandle_t _buf = NULL; + RingbufHandle_t _buf = NULL; #if !CONFIG_DISABLE_HAL_LOCKS - SemaphoreHandle_t _lock = NULL; + SemaphoreHandle_t _lock = NULL; #endif - }; diff --git a/cores/esp32/chip-debug-report.cpp b/cores/esp32/chip-debug-report.cpp index aeb0e907dfb..bfedc617494 100644 --- a/cores/esp32/chip-debug-report.cpp +++ b/cores/esp32/chip-debug-report.cpp @@ -20,9 +20,9 @@ #define chip_report_printf log_printf #define printMemCapsInfo(caps) _printMemCapsInfo(MALLOC_CAP_##caps, #caps) -#define b2kb(b) ((float)b/1024.0) -#define b2mb(b) ((float)b/(1024.0*1024.0)) -static void _printMemCapsInfo(uint32_t caps, const char * caps_str){ +#define b2kb(b) ((float)b / 1024.0) +#define b2mb(b) ((float)b / (1024.0 * 1024.0)) +static void _printMemCapsInfo(uint32_t caps, const char* caps_str) { multi_heap_info_t info; size_t total = heap_caps_get_total_size(caps); heap_caps_get_info(&info, caps); @@ -35,17 +35,17 @@ static void _printMemCapsInfo(uint32_t caps, const char * caps_str){ chip_report_printf(" Largest Free Block: %8u B (%6.1f KB)\n", info.largest_free_block, b2kb(info.largest_free_block)); } -static void printPkgVersion(void){ +static void printPkgVersion(void) { chip_report_printf(" Package : "); #if CONFIG_IDF_TARGET_ESP32 uint32_t pkg_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_PACKAGE); - switch(pkg_ver){ + switch (pkg_ver) { case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDR2V3: chip_report_printf("D0WD-R2-V3"); break; - case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6 : chip_report_printf("D0WD-Q6"); break; - case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ5 : chip_report_printf("D0WD-Q5"); break; - case EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 : chip_report_printf("D2WD-Q5"); break; - case EFUSE_RD_CHIP_VER_PKG_ESP32U4WDH : chip_report_printf("U4WD-H"); break; - case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4 : chip_report_printf("PICO-D4"); break; + case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6: chip_report_printf("D0WD-Q6"); break; + case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ5: chip_report_printf("D0WD-Q5"); break; + case EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5: chip_report_printf("D2WD-Q5"); break; + case EFUSE_RD_CHIP_VER_PKG_ESP32U4WDH: chip_report_printf("U4WD-H"); break; + case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4: chip_report_printf("PICO-D4"); break; case EFUSE_RD_CHIP_VER_PKG_ESP32PICOV302: chip_report_printf("PICO-V3-02"); break; } #elif CONFIG_IDF_TARGET_ESP32S2 @@ -70,13 +70,13 @@ static void printPkgVersion(void){ chip_report_printf("\n"); } -static void printChipInfo(void){ +static void printChipInfo(void) { esp_chip_info_t info; esp_chip_info(&info); chip_report_printf("Chip Info:\n"); chip_report_printf("------------------------------------------\n"); chip_report_printf(" Model : "); - switch(info.model){ + switch (info.model) { case CHIP_ESP32: chip_report_printf("ESP32\n"); break; case CHIP_ESP32S2: chip_report_printf("ESP32-S2\n"); break; case CHIP_ESP32S3: chip_report_printf("ESP32-S3\n"); break; @@ -88,7 +88,7 @@ static void printChipInfo(void){ } printPkgVersion(); chip_report_printf(" Revision : "); - if(info.revision > 0xFF){ + if (info.revision > 0xFF) { chip_report_printf("%d.%d\n", info.revision >> 8, info.revision & 0xFF); } else { chip_report_printf("%d\n", info.revision); @@ -97,26 +97,26 @@ static void printChipInfo(void){ rtc_cpu_freq_config_t conf; rtc_clk_cpu_freq_get_config(&conf); chip_report_printf(" Frequency : %lu MHz\n", conf.freq_mhz); - chip_report_printf(" Embedded Flash : %s\n", (info.features & CHIP_FEATURE_EMB_FLASH)?"Yes":"No"); - chip_report_printf(" Embedded PSRAM : %s\n", (info.features & CHIP_FEATURE_EMB_PSRAM)?"Yes":"No"); - chip_report_printf(" 2.4GHz WiFi : %s\n", (info.features & CHIP_FEATURE_WIFI_BGN)?"Yes":"No"); - chip_report_printf(" Classic BT : %s\n", (info.features & CHIP_FEATURE_BT)?"Yes":"No"); - chip_report_printf(" BT Low Energy : %s\n", (info.features & CHIP_FEATURE_BLE)?"Yes":"No"); - chip_report_printf(" IEEE 802.15.4 : %s\n", (info.features & CHIP_FEATURE_IEEE802154)?"Yes":"No"); + chip_report_printf(" Embedded Flash : %s\n", (info.features & CHIP_FEATURE_EMB_FLASH) ? "Yes" : "No"); + chip_report_printf(" Embedded PSRAM : %s\n", (info.features & CHIP_FEATURE_EMB_PSRAM) ? "Yes" : "No"); + chip_report_printf(" 2.4GHz WiFi : %s\n", (info.features & CHIP_FEATURE_WIFI_BGN) ? "Yes" : "No"); + chip_report_printf(" Classic BT : %s\n", (info.features & CHIP_FEATURE_BT) ? "Yes" : "No"); + chip_report_printf(" BT Low Energy : %s\n", (info.features & CHIP_FEATURE_BLE) ? "Yes" : "No"); + chip_report_printf(" IEEE 802.15.4 : %s\n", (info.features & CHIP_FEATURE_IEEE802154) ? "Yes" : "No"); } -static void printFlashInfo(void){ +static void printFlashInfo(void) { #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 - #define ESP_FLASH_IMAGE_BASE 0x1000 +#define ESP_FLASH_IMAGE_BASE 0x1000 #else - #define ESP_FLASH_IMAGE_BASE 0x0000 +#define ESP_FLASH_IMAGE_BASE 0x0000 #endif // REG_SPI_BASE is not defined for S3/C3 ?? #if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 - #ifndef REG_SPI_BASE - #define REG_SPI_BASE(i) (DR_REG_SPI1_BASE + (((i)>1) ? (((i)* 0x1000) + 0x20000) : (((~(i)) & 1)* 0x1000 ))) - #endif // REG_SPI_BASE -#endif // TARGET +#ifndef REG_SPI_BASE +#define REG_SPI_BASE(i) (DR_REG_SPI1_BASE + (((i) > 1) ? (((i)*0x1000) + 0x20000) : (((~(i)) & 1) * 0x1000))) +#endif // REG_SPI_BASE +#endif // TARGET chip_report_printf("Flash Info:\n"); chip_report_printf("------------------------------------------\n"); @@ -127,9 +127,9 @@ static void printFlashInfo(void){ chip_report_printf(" Page Size : %8lu B (%6.1f KB)\n", g_rom_flashchip.page_size, b2kb(g_rom_flashchip.page_size)); esp_image_header_t fhdr; esp_flash_read(esp_flash_default_chip, (void*)&fhdr, ESP_FLASH_IMAGE_BASE, sizeof(esp_image_header_t)); - if(fhdr.magic == ESP_IMAGE_HEADER_MAGIC) { + if (fhdr.magic == ESP_IMAGE_HEADER_MAGIC) { uint32_t f_freq = 0; - switch(fhdr.spi_speed) { + switch (fhdr.spi_speed) { #if CONFIG_IDF_TARGET_ESP32H2 case 0x0: f_freq = 32; break; case 0x2: f_freq = 16; break; @@ -155,26 +155,26 @@ static void printFlashInfo(void){ chip_report_printf("DIO\n"); #elif CONFIG_ESPTOOLPY_FLASHMODE_DOUT chip_report_printf("DOUT\n"); -#endif +#endif } -static void printPartitionsInfo(void){ +static void printPartitionsInfo(void) { chip_report_printf("Partitions Info:\n"); chip_report_printf("------------------------------------------\n"); esp_partition_iterator_t iterator = esp_partition_find(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, NULL); - if(iterator != NULL){ + if (iterator != NULL) { esp_partition_iterator_t it = iterator; - while(it != NULL){ + while (it != NULL) { const esp_partition_t* partition = esp_partition_get(it); - if(partition){ + if (partition) { chip_report_printf(" %17s : addr: 0x%08X, size: %7.1f KB", partition->label, partition->address, b2kb(partition->size)); - if(partition->type == ESP_PARTITION_TYPE_APP){ + if (partition->type == ESP_PARTITION_TYPE_APP) { chip_report_printf(", type: APP"); - if(partition->subtype == 0){ + if (partition->subtype == 0) { chip_report_printf(", subtype: FACTORY"); - } else if(partition->subtype >= 0x10 && partition->subtype < 0x20){ + } else if (partition->subtype >= 0x10 && partition->subtype < 0x20) { chip_report_printf(", subtype: OTA_%lu", partition->subtype - 0x10); - } else if(partition->subtype == 0x20){ + } else if (partition->subtype == 0x20) { chip_report_printf(", subtype: TEST"); } else { chip_report_printf(", subtype: 0x%02X", partition->subtype); @@ -182,7 +182,7 @@ static void printPartitionsInfo(void){ } else { chip_report_printf(", type: DATA"); chip_report_printf(", subtype: "); - switch(partition->subtype){ + switch (partition->subtype) { case ESP_PARTITION_SUBTYPE_DATA_OTA: chip_report_printf("OTA"); break; case ESP_PARTITION_SUBTYPE_DATA_PHY: chip_report_printf("PHY"); break; case ESP_PARTITION_SUBTYPE_DATA_NVS: chip_report_printf("NVS"); break; @@ -204,7 +204,7 @@ static void printPartitionsInfo(void){ } } -static void printSoftwareInfo(void){ +static void printSoftwareInfo(void) { chip_report_printf("Software Info:\n"); chip_report_printf("------------------------------------------\n"); chip_report_printf(" Compile Date/Time : %s %s\n", __DATE__, __TIME__); @@ -215,7 +215,7 @@ static void printSoftwareInfo(void){ chip_report_printf(" Arduino Version : %s\n", ESP_ARDUINO_VERSION_STR); } -static void printBoardInfo(void){ +static void printBoardInfo(void) { chip_report_printf("Board Info:\n"); chip_report_printf("------------------------------------------\n"); chip_report_printf(" Arduino Board : %s\n", ARDUINO_BOARD); @@ -239,7 +239,7 @@ static void printBoardInfo(void){ #endif /* ARDUINO_FQBN */ } -static void printPerimanInfo(void){ +static void printPerimanInfo(void) { chip_report_printf("GPIO Info:\n"); chip_report_printf("------------------------------------------\n"); #if defined(BOARD_HAS_PIN_REMAP) @@ -248,18 +248,18 @@ static void printPerimanInfo(void){ chip_report_printf(" GPIO : BUS_TYPE[bus/unit][chan]\n"); #endif chip_report_printf(" -------------------------------------- \n"); - for(uint8_t i = 0; i < SOC_GPIO_PIN_COUNT; i++){ - if(!perimanPinIsValid(i)){ - continue;//invalid pin + for (uint8_t i = 0; i < SOC_GPIO_PIN_COUNT; i++) { + if (!perimanPinIsValid(i)) { + continue; //invalid pin } peripheral_bus_type_t type = perimanGetPinBusType(i); - if(type == ESP32_BUS_TYPE_INIT){ - continue;//unused pin + if (type == ESP32_BUS_TYPE_INIT) { + continue; //unused pin } #if defined(BOARD_HAS_PIN_REMAP) int dpin = gpioNumberToDigitalPin(i); if (dpin < 0) { - continue;//pin is not exported + continue; //pin is not exported } else { chip_report_printf(" D%-3d|%4u : ", dpin, i); } @@ -267,37 +267,36 @@ static void printPerimanInfo(void){ chip_report_printf(" %4u : ", i); #endif const char* extra_type = perimanGetPinBusExtraType(i); - if(extra_type){ + if (extra_type) { chip_report_printf("%s", extra_type); - } - else { + } else { chip_report_printf("%s", perimanGetTypeName(type)); } int8_t bus_number = perimanGetPinBusNum(i); - if (bus_number != -1){ + if (bus_number != -1) { chip_report_printf("[%u]", bus_number); } int8_t bus_channel = perimanGetPinBusChannel(i); - if (bus_channel != -1){ + if (bus_channel != -1) { chip_report_printf("[%u]", bus_channel); } chip_report_printf("\n"); } } -void printBeforeSetupInfo(void){ +void printBeforeSetupInfo(void) { #if ARDUINO_USB_CDC_ON_BOOT Serial.begin(0); Serial.setDebugOutput(true); uint8_t t = 0; - while(!Serial && (t++ < 200)) delay(10); //wait up to 2 seconds for the IDE to connect + while (!Serial && (t++ < 200)) delay(10); //wait up to 2 seconds for the IDE to connect #endif chip_report_printf("=========== Before Setup Start ===========\n"); printChipInfo(); chip_report_printf("------------------------------------------\n"); printMemCapsInfo(INTERNAL); chip_report_printf("------------------------------------------\n"); - if(psramFound()){ + if (psramFound()) { printMemCapsInfo(SPIRAM); chip_report_printf(" Bus Mode : "); #if CONFIG_SPIRAM_MODE_OCT @@ -315,18 +314,18 @@ void printBeforeSetupInfo(void){ chip_report_printf("------------------------------------------\n"); printBoardInfo(); chip_report_printf("============ Before Setup End ============\n"); - delay(100); //allow the print to finish + delay(100); //allow the print to finish } -void printAfterSetupInfo(void){ +void printAfterSetupInfo(void) { chip_report_printf("=========== After Setup Start ============\n"); printMemCapsInfo(INTERNAL); chip_report_printf("------------------------------------------\n"); - if(psramFound()){ + if (psramFound()) { printMemCapsInfo(SPIRAM); chip_report_printf("------------------------------------------\n"); } printPerimanInfo(); chip_report_printf("============ After Setup End =============\n"); - delay(20); //allow the print to finish + delay(20); //allow the print to finish } diff --git a/cores/esp32/esp32-hal-adc.c b/cores/esp32/esp32-hal-adc.c index 80c7bb1f88c..94d2e226104 100644 --- a/cores/esp32/esp32-hal-adc.c +++ b/cores/esp32/esp32-hal-adc.c @@ -23,327 +23,323 @@ // ESP32-C2 does not define those two for some reason #ifndef SOC_ADC_DIGI_RESULT_BYTES -#define SOC_ADC_DIGI_RESULT_BYTES (4) +#define SOC_ADC_DIGI_RESULT_BYTES (4) #endif #ifndef SOC_ADC_DIGI_DATA_BYTES_PER_CONV -#define SOC_ADC_DIGI_DATA_BYTES_PER_CONV (4) +#define SOC_ADC_DIGI_DATA_BYTES_PER_CONV (4) #endif static uint8_t __analogAttenuation = ADC_11db; -static uint8_t __analogWidth = SOC_ADC_RTC_MAX_BITWIDTH; +static uint8_t __analogWidth = SOC_ADC_RTC_MAX_BITWIDTH; static uint8_t __analogReturnedWidth = SOC_ADC_RTC_MAX_BITWIDTH; typedef struct { - voidFuncPtr fn; - void* arg; + voidFuncPtr fn; + void *arg; } interrupt_config_t; typedef struct { - adc_oneshot_unit_handle_t adc_oneshot_handle; - adc_continuous_handle_t adc_continuous_handle; - interrupt_config_t adc_interrupt_handle; - adc_cali_handle_t adc_cali_handle; - uint32_t buffer_size; - uint32_t conversion_frame_size; + adc_oneshot_unit_handle_t adc_oneshot_handle; + adc_continuous_handle_t adc_continuous_handle; + interrupt_config_t adc_interrupt_handle; + adc_cali_handle_t adc_cali_handle; + uint32_t buffer_size; + uint32_t conversion_frame_size; } adc_handle_t; adc_handle_t adc_handle[SOC_ADC_PERIPH_NUM]; -static bool adcDetachBus(void * pin){ - adc_channel_t adc_channel; - adc_unit_t adc_unit; - uint8_t used_channels = 0; - - adc_oneshot_io_to_channel((int)(pin-1), &adc_unit, &adc_channel); - for (uint8_t channel = 0; channel < SOC_ADC_CHANNEL_NUM(adc_unit); channel++){ - int io_pin; - adc_oneshot_channel_to_io(adc_unit, channel, &io_pin); - if(perimanGetPinBusType(io_pin) == ESP32_BUS_TYPE_ADC_ONESHOT){ - used_channels++; - } - } - - if(used_channels == 1){ //only 1 channel is used - esp_err_t err = adc_oneshot_del_unit(adc_handle[adc_unit].adc_oneshot_handle); - if(err != ESP_OK){ - return false; - } - adc_handle[adc_unit].adc_oneshot_handle = NULL; - if(adc_handle[adc_unit].adc_cali_handle != NULL){ - #if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED - err = adc_cali_delete_scheme_curve_fitting(adc_handle[adc_unit].adc_cali_handle); - if(err != ESP_OK){ - return false; - } - #elif !defined(CONFIG_IDF_TARGET_ESP32H2) - err = adc_cali_delete_scheme_line_fitting(adc_handle[adc_unit].adc_cali_handle); - if(err != ESP_OK){ - return false; - } - #endif - } - adc_handle[adc_unit].adc_cali_handle = NULL; +static bool adcDetachBus(void *pin) { + adc_channel_t adc_channel; + adc_unit_t adc_unit; + uint8_t used_channels = 0; + + adc_oneshot_io_to_channel((int)(pin - 1), &adc_unit, &adc_channel); + for (uint8_t channel = 0; channel < SOC_ADC_CHANNEL_NUM(adc_unit); channel++) { + int io_pin; + adc_oneshot_channel_to_io(adc_unit, channel, &io_pin); + if (perimanGetPinBusType(io_pin) == ESP32_BUS_TYPE_ADC_ONESHOT) { + used_channels++; + } + } + + if (used_channels == 1) { //only 1 channel is used + esp_err_t err = adc_oneshot_del_unit(adc_handle[adc_unit].adc_oneshot_handle); + if (err != ESP_OK) { + return false; + } + adc_handle[adc_unit].adc_oneshot_handle = NULL; + if (adc_handle[adc_unit].adc_cali_handle != NULL) { +#if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED + err = adc_cali_delete_scheme_curve_fitting(adc_handle[adc_unit].adc_cali_handle); + if (err != ESP_OK) { + return false; + } +#elif !defined(CONFIG_IDF_TARGET_ESP32H2) + err = adc_cali_delete_scheme_line_fitting(adc_handle[adc_unit].adc_cali_handle); + if (err != ESP_OK) { + return false; + } +#endif } - return true; + adc_handle[adc_unit].adc_cali_handle = NULL; + } + return true; } -esp_err_t __analogChannelConfig(adc_bitwidth_t width, adc_attenuation_t atten, int8_t pin){ - esp_err_t err = ESP_OK; - adc_oneshot_chan_cfg_t config = { - .bitwidth = width, - .atten = (atten & 3), - }; - if(pin == -1){ //Reconfigure all used analog pins/channels - for(int adc_unit = 0 ; adc_unit < SOC_ADC_PERIPH_NUM; adc_unit++){ - if(adc_handle[adc_unit].adc_oneshot_handle != NULL){ - for (uint8_t channel = 0; channel < SOC_ADC_CHANNEL_NUM(adc_unit); channel++){ - int io_pin; - adc_oneshot_channel_to_io( adc_unit, channel, &io_pin); - if(perimanGetPinBusType(io_pin) == ESP32_BUS_TYPE_ADC_ONESHOT){ - err = adc_oneshot_config_channel(adc_handle[adc_unit].adc_oneshot_handle, channel, &config); - if(err != ESP_OK){ - log_e("adc_oneshot_config_channel failed with error: %d", err); - return err; - } - } - } - //ADC calibration reconfig only if all channels are updated - if(adc_handle[adc_unit].adc_cali_handle != NULL){ - #if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED - log_d("Deleting ADC_UNIT_%d cali handle",adc_unit); - err = adc_cali_delete_scheme_curve_fitting(adc_handle[adc_unit].adc_cali_handle); - if(err != ESP_OK){ - log_e("adc_cali_delete_scheme_curve_fitting failed with error: %d", err); - return err; - } - adc_cali_curve_fitting_config_t cali_config = { - .unit_id = adc_unit, - .atten = atten, - .bitwidth = width, - }; - log_d("Creating ADC_UNIT_%d curve cali handle",adc_unit); - err = adc_cali_create_scheme_curve_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle); - if(err != ESP_OK){ - log_e("adc_cali_create_scheme_curve_fitting failed with error: %d", err); - return err; - } - #elif !defined(CONFIG_IDF_TARGET_ESP32H2) //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED - log_d("Deleting ADC_UNIT_%d line cali handle",adc_unit); - err = adc_cali_delete_scheme_line_fitting(adc_handle[adc_unit].adc_cali_handle); - if(err != ESP_OK){ - log_e("adc_cali_delete_scheme_line_fitting failed with error: %d", err); - return err; - } - adc_cali_line_fitting_config_t cali_config = { - .unit_id = adc_unit, - .atten = atten, - .bitwidth = width, - }; - log_d("Creating ADC_UNIT_%d line cali handle",adc_unit); - err = adc_cali_create_scheme_line_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle); - if(err != ESP_OK){ - log_e("adc_cali_create_scheme_line_fitting failed with error: %d", err); - return err; - } - #endif - } - } - } - - //make it default for next channels - __analogWidth = width; - __analogAttenuation = atten; - } - else{ //Reconfigure single channel - if(perimanGetPinBusType(pin) == ESP32_BUS_TYPE_ADC_ONESHOT){ - adc_channel_t channel; - adc_unit_t adc_unit; - - adc_oneshot_io_to_channel(pin, &adc_unit, &channel); - if(err != ESP_OK){ - log_e("Pin %u is not ADC pin!", pin); - return err; - } +esp_err_t __analogChannelConfig(adc_bitwidth_t width, adc_attenuation_t atten, int8_t pin) { + esp_err_t err = ESP_OK; + adc_oneshot_chan_cfg_t config = { + .bitwidth = width, + .atten = (atten & 3), + }; + if (pin == -1) { //Reconfigure all used analog pins/channels + for (int adc_unit = 0; adc_unit < SOC_ADC_PERIPH_NUM; adc_unit++) { + if (adc_handle[adc_unit].adc_oneshot_handle != NULL) { + for (uint8_t channel = 0; channel < SOC_ADC_CHANNEL_NUM(adc_unit); channel++) { + int io_pin; + adc_oneshot_channel_to_io(adc_unit, channel, &io_pin); + if (perimanGetPinBusType(io_pin) == ESP32_BUS_TYPE_ADC_ONESHOT) { err = adc_oneshot_config_channel(adc_handle[adc_unit].adc_oneshot_handle, channel, &config); - if(err != ESP_OK){ - log_e("adc_oneshot_config_channel failed with error: %d", err); - return err; + if (err != ESP_OK) { + log_e("adc_oneshot_config_channel failed with error: %d", err); + return err; } + } } - else { - log_e("Pin is not configured as analog channel"); + //ADC calibration reconfig only if all channels are updated + if (adc_handle[adc_unit].adc_cali_handle != NULL) { +#if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED + log_d("Deleting ADC_UNIT_%d cali handle", adc_unit); + err = adc_cali_delete_scheme_curve_fitting(adc_handle[adc_unit].adc_cali_handle); + if (err != ESP_OK) { + log_e("adc_cali_delete_scheme_curve_fitting failed with error: %d", err); + return err; + } + adc_cali_curve_fitting_config_t cali_config = { + .unit_id = adc_unit, + .atten = atten, + .bitwidth = width, + }; + log_d("Creating ADC_UNIT_%d curve cali handle", adc_unit); + err = adc_cali_create_scheme_curve_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle); + if (err != ESP_OK) { + log_e("adc_cali_create_scheme_curve_fitting failed with error: %d", err); + return err; + } +#elif !defined(CONFIG_IDF_TARGET_ESP32H2) //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED + log_d("Deleting ADC_UNIT_%d line cali handle", adc_unit); + err = adc_cali_delete_scheme_line_fitting(adc_handle[adc_unit].adc_cali_handle); + if (err != ESP_OK) { + log_e("adc_cali_delete_scheme_line_fitting failed with error: %d", err); + return err; + } + adc_cali_line_fitting_config_t cali_config = { + .unit_id = adc_unit, + .atten = atten, + .bitwidth = width, + }; + log_d("Creating ADC_UNIT_%d line cali handle", adc_unit); + err = adc_cali_create_scheme_line_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle); + if (err != ESP_OK) { + log_e("adc_cali_create_scheme_line_fitting failed with error: %d", err); + return err; + } +#endif } + } } - return ESP_OK; -} -static inline uint16_t mapResolution(uint16_t value){ - uint8_t from = __analogWidth; - if (from == __analogReturnedWidth){ - return value; - } - if (from > __analogReturnedWidth){ - return value >> (from - __analogReturnedWidth); + //make it default for next channels + __analogWidth = width; + __analogAttenuation = atten; + } else { //Reconfigure single channel + if (perimanGetPinBusType(pin) == ESP32_BUS_TYPE_ADC_ONESHOT) { + adc_channel_t channel; + adc_unit_t adc_unit; + + adc_oneshot_io_to_channel(pin, &adc_unit, &channel); + if (err != ESP_OK) { + log_e("Pin %u is not ADC pin!", pin); + return err; + } + err = adc_oneshot_config_channel(adc_handle[adc_unit].adc_oneshot_handle, channel, &config); + if (err != ESP_OK) { + log_e("adc_oneshot_config_channel failed with error: %d", err); + return err; + } + } else { + log_e("Pin is not configured as analog channel"); } - return value << (__analogReturnedWidth - from); + } + return ESP_OK; } -void __analogSetAttenuation(adc_attenuation_t attenuation){ - if(__analogChannelConfig(__analogWidth, attenuation, -1) != ESP_OK){ - log_e("__analogChannelConfig failed!"); - } +static inline uint16_t mapResolution(uint16_t value) { + uint8_t from = __analogWidth; + if (from == __analogReturnedWidth) { + return value; + } + if (from > __analogReturnedWidth) { + return value >> (from - __analogReturnedWidth); + } + return value << (__analogReturnedWidth - from); +} + +void __analogSetAttenuation(adc_attenuation_t attenuation) { + if (__analogChannelConfig(__analogWidth, attenuation, -1) != ESP_OK) { + log_e("__analogChannelConfig failed!"); + } } #if CONFIG_IDF_TARGET_ESP32 -void __analogSetWidth(uint8_t bits){ - if(bits < SOC_ADC_RTC_MIN_BITWIDTH){ - bits = SOC_ADC_RTC_MIN_BITWIDTH; - } - else if(bits > SOC_ADC_RTC_MAX_BITWIDTH){ - bits = SOC_ADC_RTC_MAX_BITWIDTH; - } - if(__analogChannelConfig(bits, __analogAttenuation, -1) != ESP_OK){ - log_e("__analogChannelConfig failed!"); - } +void __analogSetWidth(uint8_t bits) { + if (bits < SOC_ADC_RTC_MIN_BITWIDTH) { + bits = SOC_ADC_RTC_MIN_BITWIDTH; + } else if (bits > SOC_ADC_RTC_MAX_BITWIDTH) { + bits = SOC_ADC_RTC_MAX_BITWIDTH; + } + if (__analogChannelConfig(bits, __analogAttenuation, -1) != ESP_OK) { + log_e("__analogChannelConfig failed!"); + } } #endif -esp_err_t __analogInit(uint8_t pin, adc_channel_t channel, adc_unit_t adc_unit){ - esp_err_t err = ESP_OK; - if(adc_handle[adc_unit].adc_oneshot_handle == NULL) { - adc_oneshot_unit_init_cfg_t init_config1 = { - .unit_id = adc_unit, - .ulp_mode = ADC_ULP_MODE_DISABLE, - }; - err = adc_oneshot_new_unit(&init_config1, &adc_handle[adc_unit].adc_oneshot_handle); - - if(err != ESP_OK){ - log_e("adc_oneshot_new_unit failed with error: %d", err); - return err; - } - } - perimanSetBusDeinit(ESP32_BUS_TYPE_ADC_ONESHOT, adcDetachBus); - - if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_ADC_ONESHOT, (void *)(pin+1), adc_unit, channel)){ - adcDetachBus((void *)(pin+1)); - return err; - } - - adc_oneshot_chan_cfg_t config = { - .bitwidth = __analogWidth, - .atten = __analogAttenuation, +esp_err_t __analogInit(uint8_t pin, adc_channel_t channel, adc_unit_t adc_unit) { + esp_err_t err = ESP_OK; + if (adc_handle[adc_unit].adc_oneshot_handle == NULL) { + adc_oneshot_unit_init_cfg_t init_config1 = { + .unit_id = adc_unit, + .ulp_mode = ADC_ULP_MODE_DISABLE, }; - - err = adc_oneshot_config_channel(adc_handle[adc_unit].adc_oneshot_handle, channel, &config); - if(err != ESP_OK){ - log_e("adc_oneshot_config_channel failed with error: %d", err); - return err; - } - return ESP_OK; + err = adc_oneshot_new_unit(&init_config1, &adc_handle[adc_unit].adc_oneshot_handle); + + if (err != ESP_OK) { + log_e("adc_oneshot_new_unit failed with error: %d", err); + return err; + } + } + perimanSetBusDeinit(ESP32_BUS_TYPE_ADC_ONESHOT, adcDetachBus); + + if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_ADC_ONESHOT, (void *)(pin + 1), adc_unit, channel)) { + adcDetachBus((void *)(pin + 1)); + return err; + } + + adc_oneshot_chan_cfg_t config = { + .bitwidth = __analogWidth, + .atten = __analogAttenuation, + }; + + err = adc_oneshot_config_channel(adc_handle[adc_unit].adc_oneshot_handle, channel, &config); + if (err != ESP_OK) { + log_e("adc_oneshot_config_channel failed with error: %d", err); + return err; + } + return ESP_OK; } -void __analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation){ - if(__analogChannelConfig(__analogWidth, attenuation, pin) != ESP_OK) - { - log_e("__analogChannelConfig failed!"); - } +void __analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation) { + if (__analogChannelConfig(__analogWidth, attenuation, pin) != ESP_OK) { + log_e("__analogChannelConfig failed!"); + } } -void __analogReadResolution(uint8_t bits){ - if(!bits || bits > 16){ - return; - } - __analogReturnedWidth = bits; - +void __analogReadResolution(uint8_t bits) { + if (!bits || bits > 16) { + return; + } + __analogReturnedWidth = bits; + #if CONFIG_IDF_TARGET_ESP32 - __analogSetWidth(bits); // hardware analog resolution from 9 to 12 + __analogSetWidth(bits); // hardware analog resolution from 9 to 12 #endif } -uint16_t __analogRead(uint8_t pin){ - int value = 0; - adc_channel_t channel; - adc_unit_t adc_unit; +uint16_t __analogRead(uint8_t pin) { + int value = 0; + adc_channel_t channel; + adc_unit_t adc_unit; - esp_err_t err = ESP_OK; - err = adc_oneshot_io_to_channel(pin, &adc_unit, &channel); - if(err != ESP_OK){ - log_e("Pin %u is not ADC pin!", pin); - return value; - } + esp_err_t err = ESP_OK; + err = adc_oneshot_io_to_channel(pin, &adc_unit, &channel); + if (err != ESP_OK) { + log_e("Pin %u is not ADC pin!", pin); + return value; + } - if(perimanGetPinBus(pin, ESP32_BUS_TYPE_ADC_ONESHOT) == NULL){ - log_d("Calling __analogInit! pin = %d", pin); - err = __analogInit(pin, channel, adc_unit); - if(err != ESP_OK){ - log_e("Analog initialization failed!"); - return value; - } + if (perimanGetPinBus(pin, ESP32_BUS_TYPE_ADC_ONESHOT) == NULL) { + log_d("Calling __analogInit! pin = %d", pin); + err = __analogInit(pin, channel, adc_unit); + if (err != ESP_OK) { + log_e("Analog initialization failed!"); + return value; } + } - adc_oneshot_read(adc_handle[adc_unit].adc_oneshot_handle, channel, &value); - return mapResolution(value); + adc_oneshot_read(adc_handle[adc_unit].adc_oneshot_handle, channel, &value); + return mapResolution(value); } -uint32_t __analogReadMilliVolts(uint8_t pin){ - int value = 0; - adc_channel_t channel; - adc_unit_t adc_unit; - esp_err_t err = ESP_OK; +uint32_t __analogReadMilliVolts(uint8_t pin) { + int value = 0; + adc_channel_t channel; + adc_unit_t adc_unit; + esp_err_t err = ESP_OK; - adc_oneshot_io_to_channel(pin, &adc_unit, &channel); - if(err != ESP_OK){ - log_e("Pin %u is not ADC pin!", pin); - return value; - } - - if(perimanGetPinBus(pin, ESP32_BUS_TYPE_ADC_ONESHOT) == NULL){ - err = __analogInit(pin, channel, adc_unit); - if(err != ESP_OK){ - log_e("Analog initialization failed!"); - return value; - } - } - - if(adc_handle[adc_unit].adc_cali_handle == NULL){ - log_d("Creating cali handle for ADC_%d", adc_unit); - #if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED - adc_cali_curve_fitting_config_t cali_config = { - .unit_id = adc_unit, - .atten = __analogAttenuation, - .bitwidth = __analogWidth, - }; - err = adc_cali_create_scheme_curve_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle); - #elif !defined(CONFIG_IDF_TARGET_ESP32H2) //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED - adc_cali_line_fitting_config_t cali_config = { - .unit_id = adc_unit, - .bitwidth = __analogWidth, - .atten = __analogAttenuation, - }; - err = adc_cali_create_scheme_line_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle); - #endif - if(err != ESP_OK){ - log_e("adc_cali_create_scheme_x failed!"); - return value; - } - } - - err = adc_oneshot_get_calibrated_result(adc_handle[adc_unit].adc_oneshot_handle, adc_handle[adc_unit].adc_cali_handle, channel, &value); - if(err != ESP_OK){ - log_e("adc_oneshot_get_calibrated_result failed!"); - return 0; - } + adc_oneshot_io_to_channel(pin, &adc_unit, &channel); + if (err != ESP_OK) { + log_e("Pin %u is not ADC pin!", pin); return value; + } + + if (perimanGetPinBus(pin, ESP32_BUS_TYPE_ADC_ONESHOT) == NULL) { + err = __analogInit(pin, channel, adc_unit); + if (err != ESP_OK) { + log_e("Analog initialization failed!"); + return value; + } + } + + if (adc_handle[adc_unit].adc_cali_handle == NULL) { + log_d("Creating cali handle for ADC_%d", adc_unit); +#if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED + adc_cali_curve_fitting_config_t cali_config = { + .unit_id = adc_unit, + .atten = __analogAttenuation, + .bitwidth = __analogWidth, + }; + err = adc_cali_create_scheme_curve_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle); +#elif !defined(CONFIG_IDF_TARGET_ESP32H2) //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED + adc_cali_line_fitting_config_t cali_config = { + .unit_id = adc_unit, + .bitwidth = __analogWidth, + .atten = __analogAttenuation, + }; + err = adc_cali_create_scheme_line_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle); +#endif + if (err != ESP_OK) { + log_e("adc_cali_create_scheme_x failed!"); + return value; + } + } + + err = adc_oneshot_get_calibrated_result(adc_handle[adc_unit].adc_oneshot_handle, adc_handle[adc_unit].adc_cali_handle, channel, &value); + if (err != ESP_OK) { + log_e("adc_oneshot_get_calibrated_result failed!"); + return 0; + } + return value; } -extern uint16_t analogRead(uint8_t pin) __attribute__ ((weak, alias("__analogRead"))); -extern uint32_t analogReadMilliVolts(uint8_t pin) __attribute__ ((weak, alias("__analogReadMilliVolts"))); -extern void analogReadResolution(uint8_t bits) __attribute__ ((weak, alias("__analogReadResolution"))); -extern void analogSetAttenuation(adc_attenuation_t attenuation) __attribute__ ((weak, alias("__analogSetAttenuation"))); -extern void analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation) __attribute__ ((weak, alias("__analogSetPinAttenuation"))); +extern uint16_t analogRead(uint8_t pin) __attribute__((weak, alias("__analogRead"))); +extern uint32_t analogReadMilliVolts(uint8_t pin) __attribute__((weak, alias("__analogReadMilliVolts"))); +extern void analogReadResolution(uint8_t bits) __attribute__((weak, alias("__analogReadResolution"))); +extern void analogSetAttenuation(adc_attenuation_t attenuation) __attribute__((weak, alias("__analogSetAttenuation"))); +extern void analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation) __attribute__((weak, alias("__analogSetPinAttenuation"))); #if CONFIG_IDF_TARGET_ESP32 -extern void analogSetWidth(uint8_t bits) __attribute__ ((weak, alias("__analogSetWidth"))); +extern void analogSetWidth(uint8_t bits) __attribute__((weak, alias("__analogSetWidth"))); #endif /* @@ -351,353 +347,347 @@ extern void analogSetWidth(uint8_t bits) __attribute__ ((weak, alias("__analogSe */ #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 - #define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE1 - #define ADC_GET_CHANNEL(p_data) ((p_data)->type1.channel) - #define ADC_GET_DATA(p_data) ((p_data)->type1.data) +#define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE1 +#define ADC_GET_CHANNEL(p_data) ((p_data)->type1.channel) +#define ADC_GET_DATA(p_data) ((p_data)->type1.data) #else - #define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2 - #define ADC_GET_CHANNEL(p_data) ((p_data)->type2.channel) - #define ADC_GET_DATA(p_data) ((p_data)->type2.data) +#define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2 +#define ADC_GET_CHANNEL(p_data) ((p_data)->type2.channel) +#define ADC_GET_DATA(p_data) ((p_data)->type2.data) #endif static uint8_t __adcContinuousAtten = ADC_11db; -static uint8_t __adcContinuousWidth = SOC_ADC_DIGI_MAX_BITWIDTH; +static uint8_t __adcContinuousWidth = SOC_ADC_DIGI_MAX_BITWIDTH; static uint8_t used_adc_channels = 0; -adc_continuos_data_t * adc_result = NULL; +adc_continuos_data_t *adc_result = NULL; -static bool adcContinuousDetachBus(void * adc_unit_number){ - adc_unit_t adc_unit = (adc_unit_t)adc_unit_number - 1; +static bool adcContinuousDetachBus(void *adc_unit_number) { + adc_unit_t adc_unit = (adc_unit_t)adc_unit_number - 1; - if(adc_handle[adc_unit].adc_continuous_handle == NULL){ - return true; - } - else - { - esp_err_t err = adc_continuous_deinit(adc_handle[adc_unit].adc_continuous_handle); - if(err != ESP_OK){ - return false; - } - adc_handle[adc_unit].adc_continuous_handle = NULL; - if(adc_handle[adc_unit].adc_cali_handle != NULL){ - #if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED - err = adc_cali_delete_scheme_curve_fitting(adc_handle[adc_unit].adc_cali_handle); - if(err != ESP_OK){ - return false; - } - #elif !defined(CONFIG_IDF_TARGET_ESP32H2) - err = adc_cali_delete_scheme_line_fitting(adc_handle[adc_unit].adc_cali_handle); - if(err != ESP_OK){ - return false; - } - #endif - } - adc_handle[adc_unit].adc_cali_handle = NULL; - - //set all used pins to INIT state - for (uint8_t channel = 0; channel < SOC_ADC_CHANNEL_NUM(adc_unit); channel++){ - int io_pin; - adc_oneshot_channel_to_io(adc_unit, channel, &io_pin); - if(perimanGetPinBusType(io_pin) == ESP32_BUS_TYPE_ADC_CONT){ - if(!perimanClearPinBus(io_pin)){ - return false; - } - } - } - } + if (adc_handle[adc_unit].adc_continuous_handle == NULL) { return true; -} + } else { + esp_err_t err = adc_continuous_deinit(adc_handle[adc_unit].adc_continuous_handle); + if (err != ESP_OK) { + return false; + } + adc_handle[adc_unit].adc_continuous_handle = NULL; + if (adc_handle[adc_unit].adc_cali_handle != NULL) { +#if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED + err = adc_cali_delete_scheme_curve_fitting(adc_handle[adc_unit].adc_cali_handle); + if (err != ESP_OK) { + return false; + } +#elif !defined(CONFIG_IDF_TARGET_ESP32H2) + err = adc_cali_delete_scheme_line_fitting(adc_handle[adc_unit].adc_cali_handle); + if (err != ESP_OK) { + return false; + } +#endif + } + adc_handle[adc_unit].adc_cali_handle = NULL; -bool IRAM_ATTR adcFnWrapper(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *args){ - interrupt_config_t * isr = (interrupt_config_t*)args; - //Check if edata->size matches conversion_frame_size, else just return from ISR - if(edata->size == adc_handle[0].conversion_frame_size){ - if(isr->fn) { - if(isr->arg){ - ((voidFuncPtrArg)isr->fn)(isr->arg); - } else { - isr->fn(); - } + //set all used pins to INIT state + for (uint8_t channel = 0; channel < SOC_ADC_CHANNEL_NUM(adc_unit); channel++) { + int io_pin; + adc_oneshot_channel_to_io(adc_unit, channel, &io_pin); + if (perimanGetPinBusType(io_pin) == ESP32_BUS_TYPE_ADC_CONT) { + if (!perimanClearPinBus(io_pin)) { + return false; } + } } - return false; + } + return true; } -esp_err_t __analogContinuousInit(adc_channel_t *channel, uint8_t channel_num, adc_unit_t adc_unit, uint32_t sampling_freq_hz){ - //Create new ADC continuous handle - adc_continuous_handle_cfg_t adc_config = { - .max_store_buf_size = adc_handle[adc_unit].buffer_size, - .conv_frame_size = adc_handle[adc_unit].conversion_frame_size, - }; - - esp_err_t err = adc_continuous_new_handle(&adc_config, &adc_handle[adc_unit].adc_continuous_handle); - if(err != ESP_OK){ - log_e("adc_continuous_new_handle failed with error: %d", err); - return ESP_FAIL; - } - - //Configure adc pins - adc_continuous_config_t dig_cfg = { - .sample_freq_hz = sampling_freq_hz, - .conv_mode = ADC_CONV_SINGLE_UNIT_1, - .format = ADC_OUTPUT_TYPE, - }; - adc_digi_pattern_config_t adc_pattern[SOC_ADC_PATT_LEN_MAX] = {0}; - dig_cfg.pattern_num = channel_num; - for (int i = 0; i < channel_num; i++) { - adc_pattern[i].atten = __adcContinuousAtten; - adc_pattern[i].channel = channel[i] & 0x7; - adc_pattern[i].unit = ADC_UNIT_1; - adc_pattern[i].bit_width = __adcContinuousWidth; - } - dig_cfg.adc_pattern = adc_pattern; - err = adc_continuous_config(adc_handle[adc_unit].adc_continuous_handle, &dig_cfg); - - if(err != ESP_OK){ - log_e("adc_continuous_config failed with error: %d", err); - return ESP_FAIL; - } +bool IRAM_ATTR adcFnWrapper(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *args) { + interrupt_config_t *isr = (interrupt_config_t *)args; + //Check if edata->size matches conversion_frame_size, else just return from ISR + if (edata->size == adc_handle[0].conversion_frame_size) { + if (isr->fn) { + if (isr->arg) { + ((voidFuncPtrArg)isr->fn)(isr->arg); + } else { + isr->fn(); + } + } + } + return false; +} - used_adc_channels = channel_num; - return ESP_OK; +esp_err_t __analogContinuousInit(adc_channel_t *channel, uint8_t channel_num, adc_unit_t adc_unit, uint32_t sampling_freq_hz) { + //Create new ADC continuous handle + adc_continuous_handle_cfg_t adc_config = { + .max_store_buf_size = adc_handle[adc_unit].buffer_size, + .conv_frame_size = adc_handle[adc_unit].conversion_frame_size, + }; + + esp_err_t err = adc_continuous_new_handle(&adc_config, &adc_handle[adc_unit].adc_continuous_handle); + if (err != ESP_OK) { + log_e("adc_continuous_new_handle failed with error: %d", err); + return ESP_FAIL; + } + + //Configure adc pins + adc_continuous_config_t dig_cfg = { + .sample_freq_hz = sampling_freq_hz, + .conv_mode = ADC_CONV_SINGLE_UNIT_1, + .format = ADC_OUTPUT_TYPE, + }; + adc_digi_pattern_config_t adc_pattern[SOC_ADC_PATT_LEN_MAX] = { 0 }; + dig_cfg.pattern_num = channel_num; + for (int i = 0; i < channel_num; i++) { + adc_pattern[i].atten = __adcContinuousAtten; + adc_pattern[i].channel = channel[i] & 0x7; + adc_pattern[i].unit = ADC_UNIT_1; + adc_pattern[i].bit_width = __adcContinuousWidth; + } + dig_cfg.adc_pattern = adc_pattern; + err = adc_continuous_config(adc_handle[adc_unit].adc_continuous_handle, &dig_cfg); + + if (err != ESP_OK) { + log_e("adc_continuous_config failed with error: %d", err); + return ESP_FAIL; + } + + used_adc_channels = channel_num; + return ESP_OK; } -bool analogContinuous(uint8_t pins[], size_t pins_count, uint32_t conversions_per_pin, uint32_t sampling_freq_hz, void (*userFunc)(void)){ - adc_channel_t channel[pins_count]; - adc_unit_t adc_unit; - esp_err_t err = ESP_OK; +bool analogContinuous(uint8_t pins[], size_t pins_count, uint32_t conversions_per_pin, uint32_t sampling_freq_hz, void (*userFunc)(void)) { + adc_channel_t channel[pins_count]; + adc_unit_t adc_unit; + esp_err_t err = ESP_OK; - //Convert pins to channels and check if all are ADC1s unit - for(int i = 0; i < pins_count; i++){ - err = adc_continuous_io_to_channel(pins[i], &adc_unit, &channel[i]); - if(err != ESP_OK){ - log_e("Pin %u is not ADC pin!", pins[i]); - return false; - } - if(adc_unit != 0){ - log_e("Only ADC1 pins are supported in continuous mode!"); - return false; - } + //Convert pins to channels and check if all are ADC1s unit + for (int i = 0; i < pins_count; i++) { + err = adc_continuous_io_to_channel(pins[i], &adc_unit, &channel[i]); + if (err != ESP_OK) { + log_e("Pin %u is not ADC pin!", pins[i]); + return false; } - - //Check if Oneshot and Continous handle exists - if(adc_handle[adc_unit].adc_oneshot_handle != NULL){ - log_e("ADC%d is running in oneshot mode. Aborting.", adc_unit+1); - return false; - } - if(adc_handle[adc_unit].adc_continuous_handle != NULL){ - log_e("ADC%d continuous is already initialized. To reconfigure call analogContinuousDeinit() first.", adc_unit+1); - return false; + if (adc_unit != 0) { + log_e("Only ADC1 pins are supported in continuous mode!"); + return false; } + } - //Check sampling frequency - if((sampling_freq_hz < SOC_ADC_SAMPLE_FREQ_THRES_LOW) || (sampling_freq_hz > SOC_ADC_SAMPLE_FREQ_THRES_HIGH)){ - log_e("Sampling frequency is out of range. Supported sampling frequencies are %d - %d", SOC_ADC_SAMPLE_FREQ_THRES_LOW, SOC_ADC_SAMPLE_FREQ_THRES_HIGH); - return false; - } + //Check if Oneshot and Continuous handle exists + if (adc_handle[adc_unit].adc_oneshot_handle != NULL) { + log_e("ADC%d is running in oneshot mode. Aborting.", adc_unit + 1); + return false; + } + if (adc_handle[adc_unit].adc_continuous_handle != NULL) { + log_e("ADC%d continuous is already initialized. To reconfigure call analogContinuousDeinit() first.", adc_unit + 1); + return false; + } - //Set periman deinit function and reset all pins to init state. - perimanSetBusDeinit(ESP32_BUS_TYPE_ADC_CONT, adcContinuousDetachBus); - for(int j = 0; j < pins_count; j++){ - if(!perimanClearPinBus(pins[j])){ - return false; - } + //Check sampling frequency + if ((sampling_freq_hz < SOC_ADC_SAMPLE_FREQ_THRES_LOW) || (sampling_freq_hz > SOC_ADC_SAMPLE_FREQ_THRES_HIGH)) { + log_e("Sampling frequency is out of range. Supported sampling frequencies are %d - %d", SOC_ADC_SAMPLE_FREQ_THRES_LOW, SOC_ADC_SAMPLE_FREQ_THRES_HIGH); + return false; + } + + //Set periman deinit function and reset all pins to init state. + perimanSetBusDeinit(ESP32_BUS_TYPE_ADC_CONT, adcContinuousDetachBus); + for (int j = 0; j < pins_count; j++) { + if (!perimanClearPinBus(pins[j])) { + return false; } + } - //Set conversion frame and buffer size (conversion frame must be in multiples of SOC_ADC_DIGI_DATA_BYTES_PER_CONV) - adc_handle[adc_unit].conversion_frame_size = conversions_per_pin * pins_count * SOC_ADC_DIGI_RESULT_BYTES; + //Set conversion frame and buffer size (conversion frame must be in multiples of SOC_ADC_DIGI_DATA_BYTES_PER_CONV) + adc_handle[adc_unit].conversion_frame_size = conversions_per_pin * pins_count * SOC_ADC_DIGI_RESULT_BYTES; #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 - uint8_t calc_multiple = adc_handle[adc_unit].conversion_frame_size % SOC_ADC_DIGI_DATA_BYTES_PER_CONV; - if(calc_multiple != 0){ - adc_handle[adc_unit].conversion_frame_size = (adc_handle[adc_unit].conversion_frame_size + calc_multiple); - } + uint8_t calc_multiple = adc_handle[adc_unit].conversion_frame_size % SOC_ADC_DIGI_DATA_BYTES_PER_CONV; + if (calc_multiple != 0) { + adc_handle[adc_unit].conversion_frame_size = (adc_handle[adc_unit].conversion_frame_size + calc_multiple); + } #endif - adc_handle[adc_unit].buffer_size = adc_handle[adc_unit].conversion_frame_size * 2; + adc_handle[adc_unit].buffer_size = adc_handle[adc_unit].conversion_frame_size * 2; - //Conversion frame size buffer cant be bigger than 4092 bytes - if(adc_handle[adc_unit].conversion_frame_size > 4092){ - log_e("Buffers are too big. Please set lower conversions per pin."); - return false; - } - - //Initialize continuous handle and pins - err = __analogContinuousInit(channel, sizeof(channel) / sizeof(adc_channel_t), adc_unit, sampling_freq_hz); - if(err != ESP_OK){ - log_e("Analog initialization failed!"); - return false; - } + //Conversion frame size buffer cant be bigger than 4092 bytes + if (adc_handle[adc_unit].conversion_frame_size > 4092) { + log_e("Buffers are too big. Please set lower conversions per pin."); + return false; + } - //Setup callbacks for complete event - adc_continuous_evt_cbs_t cbs = { - .on_conv_done = adcFnWrapper, - //.on_pool_ovf can be used in future + //Initialize continuous handle and pins + err = __analogContinuousInit(channel, sizeof(channel) / sizeof(adc_channel_t), adc_unit, sampling_freq_hz); + if (err != ESP_OK) { + log_e("Analog initialization failed!"); + return false; + } + + //Setup callbacks for complete event + adc_continuous_evt_cbs_t cbs = { + .on_conv_done = adcFnWrapper, + //.on_pool_ovf can be used in future + }; + adc_handle[adc_unit].adc_interrupt_handle.fn = (voidFuncPtr)userFunc; + err = adc_continuous_register_event_callbacks(adc_handle[adc_unit].adc_continuous_handle, &cbs, &adc_handle[adc_unit].adc_interrupt_handle); + if (err != ESP_OK) { + log_e("adc_continuous_register_event_callbacks failed!"); + return false; + } + + //Allocate and prepare result structure for adc readings + adc_result = malloc(pins_count * sizeof(adc_continuos_data_t)); + for (int k = 0; k < pins_count; k++) { + adc_result[k].pin = pins[k]; + adc_result[k].channel = channel[k]; + } + + //Initialize ADC calibration handle + if (adc_handle[adc_unit].adc_cali_handle == NULL) { + log_d("Creating cali handle for ADC_%d", adc_unit); +#if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED + adc_cali_curve_fitting_config_t cali_config = { + .unit_id = adc_unit, + .atten = __adcContinuousAtten, + .bitwidth = __adcContinuousWidth, }; - adc_handle[adc_unit].adc_interrupt_handle.fn = (voidFuncPtr)userFunc; - err = adc_continuous_register_event_callbacks(adc_handle[adc_unit].adc_continuous_handle, &cbs, &adc_handle[adc_unit].adc_interrupt_handle); - if(err != ESP_OK){ - log_e("adc_continuous_register_event_callbacks failed!"); - return false; + err = adc_cali_create_scheme_curve_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle); +#elif !defined(CONFIG_IDF_TARGET_ESP32H2) //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED + adc_cali_line_fitting_config_t cali_config = { + .unit_id = adc_unit, + .bitwidth = __adcContinuousWidth, + .atten = __adcContinuousAtten, + }; + err = adc_cali_create_scheme_line_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle); +#endif + if (err != ESP_OK) { + log_e("adc_cali_create_scheme_x failed!"); + return false; } + } - //Allocate and prepare result structure for adc readings - adc_result = malloc(pins_count * sizeof(adc_continuos_data_t)); - for(int k = 0; k < pins_count; k++){ - adc_result[k].pin = pins[k]; - adc_result[k].channel = channel[k]; + for (int k = 0; k < pins_count; k++) { + if (!perimanSetPinBus(pins[k], ESP32_BUS_TYPE_ADC_CONT, (void *)(adc_unit + 1), adc_unit, channel[k])) { + log_e("perimanSetPinBus to ADC Continuous failed!"); + adcContinuousDetachBus((void *)(adc_unit + 1)); + return false; } + } + + return true; +} - //Initialize ADC calibration handle - if(adc_handle[adc_unit].adc_cali_handle == NULL){ - log_d("Creating cali handle for ADC_%d", adc_unit); - #if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED - adc_cali_curve_fitting_config_t cali_config = { - .unit_id = adc_unit, - .atten = __adcContinuousAtten, - .bitwidth = __adcContinuousWidth, - }; - err = adc_cali_create_scheme_curve_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle); - #elif !defined(CONFIG_IDF_TARGET_ESP32H2) //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED - adc_cali_line_fitting_config_t cali_config = { - .unit_id = adc_unit, - .bitwidth = __adcContinuousWidth, - .atten = __adcContinuousAtten, - }; - err = adc_cali_create_scheme_line_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle); - #endif - if(err != ESP_OK){ - log_e("adc_cali_create_scheme_x failed!"); - return false; +bool analogContinuousRead(adc_continuos_data_t **buffer, uint32_t timeout_ms) { + if (adc_handle[ADC_UNIT_1].adc_continuous_handle != NULL) { + uint32_t bytes_read = 0; + uint32_t read_raw[used_adc_channels]; + uint32_t read_count[used_adc_channels]; + uint8_t adc_read[adc_handle[ADC_UNIT_1].conversion_frame_size]; + memset(adc_read, 0xcc, sizeof(adc_read)); + memset(read_raw, 0, sizeof(read_raw)); + memset(read_count, 0, sizeof(read_count)); + + esp_err_t err = adc_continuous_read(adc_handle[ADC_UNIT_1].adc_continuous_handle, adc_read, adc_handle[0].conversion_frame_size, &bytes_read, timeout_ms); + if (err != ESP_OK) { + if (err == ESP_ERR_TIMEOUT) { + log_e("Reading data failed: No data, increase timeout"); + } else { + log_e("Reading data failed with error: %X", err); + } + *buffer = NULL; + return false; + } + + for (int i = 0; i < bytes_read; i += SOC_ADC_DIGI_RESULT_BYTES) { + adc_digi_output_data_t *p = (adc_digi_output_data_t *)&adc_read[i]; + uint32_t chan_num = ADC_GET_CHANNEL(p); + uint32_t data = ADC_GET_DATA(p); + + /* Check the channel number validation, the data is invalid if the channel num exceed the maximum channel */ + if (chan_num >= SOC_ADC_CHANNEL_NUM(0)) { + log_e("Invalid data [%d_%d]", chan_num, data); + *buffer = NULL; + return false; + } + if (data >= (1 << SOC_ADC_DIGI_MAX_BITWIDTH)) { + data = 0; + log_e("Invalid data"); + } + + for (int j = 0; j < used_adc_channels; j++) { + if (adc_result[j].channel == chan_num) { + read_raw[j] += data; + read_count[j] += 1; + break; } + } } - for(int k = 0; k < pins_count; k++){ - if(!perimanSetPinBus(pins[k], ESP32_BUS_TYPE_ADC_CONT, (void *)(adc_unit+1), adc_unit, channel[k])){ - log_e("perimanSetPinBus to ADC Continuous failed!"); - adcContinuousDetachBus((void *)(adc_unit+1)); - return false; - } + for (int j = 0; j < used_adc_channels; j++) { + if (read_count[j] != 0) { + adc_result[j].avg_read_raw = read_raw[j] / read_count[j]; + adc_cali_raw_to_voltage(adc_handle[ADC_UNIT_1].adc_cali_handle, adc_result[j].avg_read_raw, &adc_result[j].avg_read_mvolts); + } else { + log_w("No data read for pin %d", adc_result[j].pin); + } } + *buffer = adc_result; return true; -} - -bool analogContinuousRead(adc_continuos_data_t ** buffer, uint32_t timeout_ms){ - if(adc_handle[ADC_UNIT_1].adc_continuous_handle != NULL){ - uint32_t bytes_read = 0; - uint32_t read_raw[used_adc_channels]; - uint32_t read_count[used_adc_channels]; - uint8_t adc_read[adc_handle[ADC_UNIT_1].conversion_frame_size]; - memset(adc_read, 0xcc, sizeof(adc_read)); - memset(read_raw, 0, sizeof(read_raw)); - memset(read_count, 0, sizeof(read_count)); - - esp_err_t err = adc_continuous_read(adc_handle[ADC_UNIT_1].adc_continuous_handle, adc_read, adc_handle[0].conversion_frame_size, &bytes_read, timeout_ms); - if(err != ESP_OK){ - if(err == ESP_ERR_TIMEOUT){ - log_e("Reading data failed: No data, increase timeout"); - } - else { - log_e("Reading data failed with error: %X", err); - } - *buffer = NULL; - return false; - } - - for (int i = 0; i < bytes_read; i += SOC_ADC_DIGI_RESULT_BYTES) { - adc_digi_output_data_t *p = (adc_digi_output_data_t*)&adc_read[i]; - uint32_t chan_num = ADC_GET_CHANNEL(p); - uint32_t data = ADC_GET_DATA(p); - - /* Check the channel number validation, the data is invalid if the channel num exceed the maximum channel */ - if(chan_num >= SOC_ADC_CHANNEL_NUM(0)){ - log_e("Invalid data [%d_%d]", chan_num, data); - *buffer = NULL; - return false; - } - if(data >= (1 << SOC_ADC_DIGI_MAX_BITWIDTH)) - { - data = 0; - log_e("Invalid data"); - } - - for(int j = 0; j < used_adc_channels; j++){ - if(adc_result[j].channel == chan_num){ - read_raw[j] += data; - read_count[j] += 1; - break; - } - } - } - - for (int j = 0; j < used_adc_channels; j++){ - if (read_count[j] != 0){ - adc_result[j].avg_read_raw = read_raw[j] / read_count[j]; - adc_cali_raw_to_voltage(adc_handle[ADC_UNIT_1].adc_cali_handle, adc_result[j].avg_read_raw, &adc_result[j].avg_read_mvolts); - } - else { - log_w("No data read for pin %d", adc_result[j].pin); - } - } - *buffer = adc_result; - return true; - - } - else { - log_e("ADC Continuous is not initialized!"); - return false; - } + } else { + log_e("ADC Continuous is not initialized!"); + return false; + } } -bool analogContinuousStart(){ - if(adc_handle[ADC_UNIT_1].adc_continuous_handle != NULL){ - if(adc_continuous_start(adc_handle[ADC_UNIT_1].adc_continuous_handle) == ESP_OK){ - return true; - } - } else { - log_e("ADC Continuous is not initialized!"); +bool analogContinuousStart() { + if (adc_handle[ADC_UNIT_1].adc_continuous_handle != NULL) { + if (adc_continuous_start(adc_handle[ADC_UNIT_1].adc_continuous_handle) == ESP_OK) { + return true; } - return false; + } else { + log_e("ADC Continuous is not initialized!"); + } + return false; } -bool analogContinuousStop(){ - if(adc_handle[ADC_UNIT_1].adc_continuous_handle != NULL){ - if(adc_continuous_stop(adc_handle[ADC_UNIT_1].adc_continuous_handle) == ESP_OK){ - return true; - } - } else { - log_e("ADC Continuous is not initialized!"); +bool analogContinuousStop() { + if (adc_handle[ADC_UNIT_1].adc_continuous_handle != NULL) { + if (adc_continuous_stop(adc_handle[ADC_UNIT_1].adc_continuous_handle) == ESP_OK) { + return true; } - return false; + } else { + log_e("ADC Continuous is not initialized!"); + } + return false; } -bool analogContinuousDeinit(){ - if(adc_handle[ADC_UNIT_1].adc_continuous_handle != NULL){ - esp_err_t err = adc_continuous_deinit(adc_handle[ADC_UNIT_1].adc_continuous_handle); - if (err != ESP_OK){ - return false; - } - free(adc_result); - adc_handle[ADC_UNIT_1].adc_continuous_handle = NULL; - } else { - log_i("ADC Continuous was not initialized"); - } - return true; +bool analogContinuousDeinit() { + if (adc_handle[ADC_UNIT_1].adc_continuous_handle != NULL) { + esp_err_t err = adc_continuous_deinit(adc_handle[ADC_UNIT_1].adc_continuous_handle); + if (err != ESP_OK) { + return false; + } + free(adc_result); + adc_handle[ADC_UNIT_1].adc_continuous_handle = NULL; + } else { + log_i("ADC Continuous was not initialized"); + } + return true; } -void analogContinuousSetAtten(adc_attenuation_t attenuation){ - __adcContinuousAtten = attenuation; +void analogContinuousSetAtten(adc_attenuation_t attenuation) { + __adcContinuousAtten = attenuation; } -void analogContinuousSetWidth(uint8_t bits){ - if ((bits < SOC_ADC_DIGI_MIN_BITWIDTH) && (bits > SOC_ADC_DIGI_MAX_BITWIDTH)){ - log_e("Selected width cannot be set. Range is from %d to %d", SOC_ADC_DIGI_MIN_BITWIDTH, SOC_ADC_DIGI_MAX_BITWIDTH); - return; - } - __adcContinuousWidth = bits; +void analogContinuousSetWidth(uint8_t bits) { + if ((bits < SOC_ADC_DIGI_MIN_BITWIDTH) && (bits > SOC_ADC_DIGI_MAX_BITWIDTH)) { + log_e("Selected width cannot be set. Range is from %d to %d", SOC_ADC_DIGI_MIN_BITWIDTH, SOC_ADC_DIGI_MAX_BITWIDTH); + return; + } + __adcContinuousWidth = bits; } #endif diff --git a/cores/esp32/esp32-hal-adc.h b/cores/esp32/esp32-hal-adc.h index 41122b2d4bb..1597824fda3 100644 --- a/cores/esp32/esp32-hal-adc.h +++ b/cores/esp32/esp32-hal-adc.h @@ -28,103 +28,103 @@ extern "C" { #include "esp32-hal.h" -typedef enum { + typedef enum { ADC_0db, ADC_2_5db, ADC_6db, ADC_11db, ADC_ATTENDB_MAX -} adc_attenuation_t; + } adc_attenuation_t; -/* + /* * Get ADC value for pin * */ -uint16_t analogRead(uint8_t pin); + uint16_t analogRead(uint8_t pin); -/* + /* * Get MilliVolts value for pin * */ -uint32_t analogReadMilliVolts(uint8_t pin); + uint32_t analogReadMilliVolts(uint8_t pin); -/* + /* * Set the resolution of analogRead return values. Default is 12 bits (range from 0 to 4096). * If between 9 and 12, it will equal the set hardware resolution, else value will be shifted. * Range is 1 - 16 * * Note: compatibility with Arduino SAM */ -void analogReadResolution(uint8_t bits); + void analogReadResolution(uint8_t bits); -/* + /* * Set the attenuation for all channels * Default is 11db * */ -void analogSetAttenuation(adc_attenuation_t attenuation); + void analogSetAttenuation(adc_attenuation_t attenuation); -/* + /* * Set the attenuation for particular pin * Default is 11db * */ -void analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation); + void analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation); #if CONFIG_IDF_TARGET_ESP32 -/* + /* * Sets the sample bits and read resolution * Default is 12bit (0 - 4095) * Range is 9 - 12 * */ -void analogSetWidth(uint8_t bits); + void analogSetWidth(uint8_t bits); #endif -/* + /* * Analog Continuous mode * */ -typedef struct { - uint8_t pin; /*!cb(r->arg, ev_type, old_apb, new_apb); - r=r->next; - } - else { // run backwards through chain - while(r->next != NULL) r = r->next; // find first added - while( r != NULL){ - r->cb(r->arg, ev_type, old_apb, new_apb); - r=r->prev; - } - } +static void triggerApbChangeCallback(apb_change_ev_t ev_type, uint32_t old_apb, uint32_t new_apb) { + initApbChangeCallback(); + xSemaphoreTake(apb_change_lock, portMAX_DELAY); + apb_change_t* r = apb_change_callbacks; + if (r != NULL) { + if (ev_type == APB_BEFORE_CHANGE) + while (r != NULL) { + r->cb(r->arg, ev_type, old_apb, new_apb); + r = r->next; + } + else { // run backwards through chain + while (r->next != NULL) r = r->next; // find first added + while (r != NULL) { + r->cb(r->arg, ev_type, old_apb, new_apb); + r = r->prev; + } } - xSemaphoreGive(apb_change_lock); + } + xSemaphoreGive(apb_change_lock); } -bool addApbChangeCallback(void * arg, apb_change_cb_t cb){ - initApbChangeCallback(); - apb_change_t * c = (apb_change_t*)malloc(sizeof(apb_change_t)); - if(!c){ - log_e("Callback Object Malloc Failed"); - return false; - } - c->next = NULL; - c->prev = NULL; - c->arg = arg; - c->cb = cb; - xSemaphoreTake(apb_change_lock, portMAX_DELAY); - if(apb_change_callbacks == NULL){ - apb_change_callbacks = c; +bool addApbChangeCallback(void* arg, apb_change_cb_t cb) { + initApbChangeCallback(); + apb_change_t* c = (apb_change_t*)malloc(sizeof(apb_change_t)); + if (!c) { + log_e("Callback Object Malloc Failed"); + return false; + } + c->next = NULL; + c->prev = NULL; + c->arg = arg; + c->cb = cb; + xSemaphoreTake(apb_change_lock, portMAX_DELAY); + if (apb_change_callbacks == NULL) { + apb_change_callbacks = c; + } else { + apb_change_t* r = apb_change_callbacks; + // look for duplicate callbacks + while ((r != NULL) && !((r->cb == cb) && (r->arg == arg))) r = r->next; + if (r) { + log_e("duplicate func=%8p arg=%8p", c->cb, c->arg); + free(c); + xSemaphoreGive(apb_change_lock); + return false; } else { - apb_change_t * r = apb_change_callbacks; - // look for duplicate callbacks - while( (r != NULL ) && !((r->cb == cb) && ( r->arg == arg))) r = r->next; - if (r) { - log_e("duplicate func=%8p arg=%8p",c->cb,c->arg); - free(c); - xSemaphoreGive(apb_change_lock); - return false; - } - else { - c->next = apb_change_callbacks; - apb_change_callbacks-> prev = c; - apb_change_callbacks = c; - } + c->next = apb_change_callbacks; + apb_change_callbacks->prev = c; + apb_change_callbacks = c; } - xSemaphoreGive(apb_change_lock); - return true; + } + xSemaphoreGive(apb_change_lock); + return true; } -bool removeApbChangeCallback(void * arg, apb_change_cb_t cb){ - initApbChangeCallback(); - xSemaphoreTake(apb_change_lock, portMAX_DELAY); - apb_change_t * r = apb_change_callbacks; - // look for matching callback - while( (r != NULL ) && !((r->cb == cb) && ( r->arg == arg))) r = r->next; - if ( r == NULL ) { - log_e("not found func=%8p arg=%8p",cb,arg); - xSemaphoreGive(apb_change_lock); - return false; - } - else { - // patch links - if(r->prev) r->prev->next = r->next; - else { // this is first link - apb_change_callbacks = r->next; - } - if(r->next) r->next->prev = r->prev; - free(r); - } +bool removeApbChangeCallback(void* arg, apb_change_cb_t cb) { + initApbChangeCallback(); + xSemaphoreTake(apb_change_lock, portMAX_DELAY); + apb_change_t* r = apb_change_callbacks; + // look for matching callback + while ((r != NULL) && !((r->cb == cb) && (r->arg == arg))) r = r->next; + if (r == NULL) { + log_e("not found func=%8p arg=%8p", cb, arg); xSemaphoreGive(apb_change_lock); - return true; + return false; + } else { + // patch links + if (r->prev) r->prev->next = r->next; + else { // this is first link + apb_change_callbacks = r->next; + } + if (r->next) r->next->prev = r->prev; + free(r); + } + xSemaphoreGive(apb_change_lock); + return true; } -static uint32_t calculateApb(rtc_cpu_freq_config_t * conf){ +static uint32_t calculateApb(rtc_cpu_freq_config_t* conf) { #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32H2 - return APB_CLK_FREQ; + return APB_CLK_FREQ; #else - if(conf->freq_mhz >= 80){ - return 80 * MHZ; - } - return (conf->source_freq_mhz * MHZ) / conf->div; + if (conf->freq_mhz >= 80) { + return 80 * MHZ; + } + return (conf->source_freq_mhz * MHZ) / conf->div; #endif } -void esp_timer_impl_update_apb_freq(uint32_t apb_ticks_per_us); //private in IDF +void esp_timer_impl_update_apb_freq(uint32_t apb_ticks_per_us); //private in IDF -bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz){ - rtc_cpu_freq_config_t conf, cconf; - uint32_t capb, apb; - //Get XTAL Frequency and calculate min CPU MHz +bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz) { + rtc_cpu_freq_config_t conf, cconf; + uint32_t capb, apb; + //Get XTAL Frequency and calculate min CPU MHz #ifndef CONFIG_IDF_TARGET_ESP32H2 - rtc_xtal_freq_t xtal = rtc_clk_xtal_freq_get(); + rtc_xtal_freq_t xtal = rtc_clk_xtal_freq_get(); #endif #if CONFIG_IDF_TARGET_ESP32 - if(xtal > RTC_XTAL_FREQ_AUTO){ - if(xtal < RTC_XTAL_FREQ_40M) { - if(cpu_freq_mhz <= xtal && cpu_freq_mhz != xtal && cpu_freq_mhz != (xtal/2)){ - log_e("Bad frequency: %u MHz! Options are: 240, 160, 80, %u and %u MHz", cpu_freq_mhz, xtal, xtal/2); - return false; - } - } else if(cpu_freq_mhz <= xtal && cpu_freq_mhz != xtal && cpu_freq_mhz != (xtal/2) && cpu_freq_mhz != (xtal/4)){ - log_e("Bad frequency: %u MHz! Options are: 240, 160, 80, %u, %u and %u MHz", cpu_freq_mhz, xtal, xtal/2, xtal/4); - return false; - } + if (xtal > RTC_XTAL_FREQ_AUTO) { + if (xtal < RTC_XTAL_FREQ_40M) { + if (cpu_freq_mhz <= xtal && cpu_freq_mhz != xtal && cpu_freq_mhz != (xtal / 2)) { + log_e("Bad frequency: %u MHz! Options are: 240, 160, 80, %u and %u MHz", cpu_freq_mhz, xtal, xtal / 2); + return false; + } + } else if (cpu_freq_mhz <= xtal && cpu_freq_mhz != xtal && cpu_freq_mhz != (xtal / 2) && cpu_freq_mhz != (xtal / 4)) { + log_e("Bad frequency: %u MHz! Options are: 240, 160, 80, %u, %u and %u MHz", cpu_freq_mhz, xtal, xtal / 2, xtal / 4); + return false; } + } #endif #ifndef CONFIG_IDF_TARGET_ESP32H2 - if(cpu_freq_mhz > xtal && cpu_freq_mhz != 240 && cpu_freq_mhz != 160 && cpu_freq_mhz != 120 && cpu_freq_mhz != 80){ - if(xtal >= RTC_XTAL_FREQ_40M){ - log_e("Bad frequency: %u MHz! Options are: 240, 160, 120, 80, %u, %u and %u MHz", cpu_freq_mhz, xtal, xtal/2, xtal/4); - } else { - log_e("Bad frequency: %u MHz! Options are: 240, 160, 120, 80, %u and %u MHz", cpu_freq_mhz, xtal, xtal/2); - } - return false; + if (cpu_freq_mhz > xtal && cpu_freq_mhz != 240 && cpu_freq_mhz != 160 && cpu_freq_mhz != 120 && cpu_freq_mhz != 80) { + if (xtal >= RTC_XTAL_FREQ_40M) { + log_e("Bad frequency: %u MHz! Options are: 240, 160, 120, 80, %u, %u and %u MHz", cpu_freq_mhz, xtal, xtal / 2, xtal / 4); + } else { + log_e("Bad frequency: %u MHz! Options are: 240, 160, 120, 80, %u and %u MHz", cpu_freq_mhz, xtal, xtal / 2); } + return false; + } #endif #if CONFIG_IDF_TARGET_ESP32 - //check if cpu supports the frequency - if(cpu_freq_mhz == 240){ - //Check if ESP32 is rated for a CPU frequency of 160MHz only - if (REG_GET_BIT(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_CPU_FREQ_RATED) && - REG_GET_BIT(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_CPU_FREQ_LOW)) { - log_e("Can not switch to 240 MHz! Chip CPU frequency rated for 160MHz."); - cpu_freq_mhz = 160; - } + //check if cpu supports the frequency + if (cpu_freq_mhz == 240) { + //Check if ESP32 is rated for a CPU frequency of 160MHz only + if (REG_GET_BIT(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_CPU_FREQ_RATED) && REG_GET_BIT(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_CPU_FREQ_LOW)) { + log_e("Can not switch to 240 MHz! Chip CPU frequency rated for 160MHz."); + cpu_freq_mhz = 160; } + } #endif - //Get current CPU clock configuration - rtc_clk_cpu_freq_get_config(&cconf); - //return if frequency has not changed - if(cconf.freq_mhz == cpu_freq_mhz){ - return true; - } - //Get configuration for the new CPU frequency - if(!rtc_clk_cpu_freq_mhz_to_config(cpu_freq_mhz, &conf)){ - log_e("CPU clock could not be set to %u MHz", cpu_freq_mhz); - return false; - } - //Current APB - capb = calculateApb(&cconf); - //New APB - apb = calculateApb(&conf); - - //Call peripheral functions before the APB change - if(apb_change_callbacks){ - triggerApbChangeCallback(APB_BEFORE_CHANGE, capb, apb); - } - //Make the frequency change - rtc_clk_cpu_freq_set_config_fast(&conf); + //Get current CPU clock configuration + rtc_clk_cpu_freq_get_config(&cconf); + //return if frequency has not changed + if (cconf.freq_mhz == cpu_freq_mhz) { + return true; + } + //Get configuration for the new CPU frequency + if (!rtc_clk_cpu_freq_mhz_to_config(cpu_freq_mhz, &conf)) { + log_e("CPU clock could not be set to %u MHz", cpu_freq_mhz); + return false; + } + //Current APB + capb = calculateApb(&cconf); + //New APB + apb = calculateApb(&conf); + + //Call peripheral functions before the APB change + if (apb_change_callbacks) { + triggerApbChangeCallback(APB_BEFORE_CHANGE, capb, apb); + } + //Make the frequency change + rtc_clk_cpu_freq_set_config_fast(&conf); #if !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32H2) - if(capb != apb){ - //Update REF_TICK (uncomment if REF_TICK is different than 1MHz) - //if(conf.freq_mhz < 80){ - // ESP_REG(APB_CTRL_XTAL_TICK_CONF_REG) = conf.freq_mhz / (REF_CLK_FREQ / MHZ) - 1; - // } - //Update APB Freq REG - rtc_clk_apb_freq_update(apb); - //Update esp_timer divisor - esp_timer_impl_update_apb_freq(apb / MHZ); - } + if (capb != apb) { + //Update REF_TICK (uncomment if REF_TICK is different than 1MHz) + //if(conf.freq_mhz < 80){ + // ESP_REG(APB_CTRL_XTAL_TICK_CONF_REG) = conf.freq_mhz / (REF_CLK_FREQ / MHZ) - 1; + // } + //Update APB Freq REG + rtc_clk_apb_freq_update(apb); + //Update esp_timer divisor + esp_timer_impl_update_apb_freq(apb / MHZ); + } #endif - //Update FreeRTOS Tick Divisor + //Update FreeRTOS Tick Divisor #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 #elif CONFIG_IDF_TARGET_ESP32S3 #else - uint32_t fcpu = (conf.freq_mhz >= 80)?(conf.freq_mhz * MHZ):(apb); - _xt_tick_divisor = fcpu / XT_TICK_PER_SEC; + uint32_t fcpu = (conf.freq_mhz >= 80) ? (conf.freq_mhz * MHZ) : (apb); + _xt_tick_divisor = fcpu / XT_TICK_PER_SEC; #endif - //Call peripheral functions after the APB change - if(apb_change_callbacks){ - triggerApbChangeCallback(APB_AFTER_CHANGE, capb, apb); - } + //Call peripheral functions after the APB change + if (apb_change_callbacks) { + triggerApbChangeCallback(APB_AFTER_CHANGE, capb, apb); + } #ifdef SOC_CLK_APLL_SUPPORTED - log_d("%s: %u / %u = %u Mhz, APB: %u Hz", (conf.source == RTC_CPU_FREQ_SRC_PLL)?"PLL":((conf.source == RTC_CPU_FREQ_SRC_APLL)?"APLL":((conf.source == RTC_CPU_FREQ_SRC_XTAL)?"XTAL":"8M")), conf.source_freq_mhz, conf.div, conf.freq_mhz, apb); + log_d("%s: %u / %u = %u Mhz, APB: %u Hz", (conf.source == RTC_CPU_FREQ_SRC_PLL) ? "PLL" : ((conf.source == RTC_CPU_FREQ_SRC_APLL) ? "APLL" : ((conf.source == RTC_CPU_FREQ_SRC_XTAL) ? "XTAL" : "8M")), conf.source_freq_mhz, conf.div, conf.freq_mhz, apb); #else - log_d("%s: %u / %u = %u Mhz, APB: %u Hz", (conf.source == RTC_CPU_FREQ_SRC_PLL)?"PLL":((conf.source == RTC_CPU_FREQ_SRC_XTAL)?"XTAL":"17.5M"), conf.source_freq_mhz, conf.div, conf.freq_mhz, apb); + log_d("%s: %u / %u = %u Mhz, APB: %u Hz", (conf.source == RTC_CPU_FREQ_SRC_PLL) ? "PLL" : ((conf.source == RTC_CPU_FREQ_SRC_XTAL) ? "XTAL" : "17.5M"), conf.source_freq_mhz, conf.div, conf.freq_mhz, apb); #endif - return true; + return true; } -uint32_t getCpuFrequencyMhz(){ - rtc_cpu_freq_config_t conf; - rtc_clk_cpu_freq_get_config(&conf); - return conf.freq_mhz; +uint32_t getCpuFrequencyMhz() { + rtc_cpu_freq_config_t conf; + rtc_clk_cpu_freq_get_config(&conf); + return conf.freq_mhz; } -uint32_t getXtalFrequencyMhz(){ - return rtc_clk_xtal_freq_get(); +uint32_t getXtalFrequencyMhz() { + return rtc_clk_xtal_freq_get(); } -uint32_t getApbFrequency(){ - rtc_cpu_freq_config_t conf; - rtc_clk_cpu_freq_get_config(&conf); - return calculateApb(&conf); +uint32_t getApbFrequency() { + rtc_cpu_freq_config_t conf; + rtc_clk_cpu_freq_get_config(&conf); + return calculateApb(&conf); } diff --git a/cores/esp32/esp32-hal-cpu.h b/cores/esp32/esp32-hal-cpu.h index 646b59858f5..ffb5524e421 100644 --- a/cores/esp32/esp32-hal-cpu.h +++ b/cores/esp32/esp32-hal-cpu.h @@ -23,23 +23,24 @@ extern "C" { #include #include -typedef enum { APB_BEFORE_CHANGE, APB_AFTER_CHANGE } apb_change_ev_t; + typedef enum { APB_BEFORE_CHANGE, + APB_AFTER_CHANGE } apb_change_ev_t; -typedef void (* apb_change_cb_t)(void * arg, apb_change_ev_t ev_type, uint32_t old_apb, uint32_t new_apb); + typedef void (*apb_change_cb_t)(void* arg, apb_change_ev_t ev_type, uint32_t old_apb, uint32_t new_apb); -bool addApbChangeCallback(void * arg, apb_change_cb_t cb); -bool removeApbChangeCallback(void * arg, apb_change_cb_t cb); + bool addApbChangeCallback(void* arg, apb_change_cb_t cb); + bool removeApbChangeCallback(void* arg, apb_change_cb_t cb); -//function takes the following frequencies as valid values: -// 240, 160, 80 <<< For all XTAL types -// 40, 20, 10 <<< For 40MHz XTAL -// 26, 13 <<< For 26MHz XTAL -// 24, 12 <<< For 24MHz XTAL -bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz); + //function takes the following frequencies as valid values: + // 240, 160, 80 <<< For all XTAL types + // 40, 20, 10 <<< For 40MHz XTAL + // 26, 13 <<< For 26MHz XTAL + // 24, 12 <<< For 24MHz XTAL + bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz); -uint32_t getCpuFrequencyMhz(); // In MHz -uint32_t getXtalFrequencyMhz(); // In MHz -uint32_t getApbFrequency(); // In Hz + uint32_t getCpuFrequencyMhz(); // In MHz + uint32_t getXtalFrequencyMhz(); // In MHz + uint32_t getApbFrequency(); // In Hz #ifdef __cplusplus } diff --git a/cores/esp32/esp32-hal-dac.c b/cores/esp32/esp32-hal-dac.c index 96154f0f087..b6dadd98a58 100644 --- a/cores/esp32/esp32-hal-dac.c +++ b/cores/esp32/esp32-hal-dac.c @@ -12,69 +12,67 @@ #include "soc/dac_channel.h" #include "driver/dac_oneshot.h" -static bool dacDetachBus(void * bus){ - esp_err_t err = dac_oneshot_del_channel((dac_oneshot_handle_t)bus); - if(err != ESP_OK){ - log_e("dac_oneshot_del_channel failed with error: %d", err); - return false; - } - return true; +static bool dacDetachBus(void *bus) { + esp_err_t err = dac_oneshot_del_channel((dac_oneshot_handle_t)bus); + if (err != ESP_OK) { + log_e("dac_oneshot_del_channel failed with error: %d", err); + return false; + } + return true; } -bool __dacWrite(uint8_t pin, uint8_t value) -{ - esp_err_t err = ESP_OK; - if(pin != DAC_CHAN0_GPIO_NUM && pin != DAC_CHAN1_GPIO_NUM){ - log_e("pin %u is not a DAC pin", pin); - return false;//not dac pin - } - - dac_oneshot_handle_t bus = (dac_oneshot_handle_t)perimanGetPinBus(pin, ESP32_BUS_TYPE_DAC_ONESHOT); - if(bus == NULL){ - perimanSetBusDeinit(ESP32_BUS_TYPE_DAC_ONESHOT, dacDetachBus); - if(!perimanClearPinBus(pin)){ - return false; - } - dac_channel_t channel = (pin == DAC_CHAN0_GPIO_NUM)?DAC_CHAN_0:DAC_CHAN_1; - dac_oneshot_config_t config = { - .chan_id = channel - }; - err = dac_oneshot_new_channel(&config, &bus); - if(err != ESP_OK){ - log_e("dac_oneshot_new_channel failed with error: %d", err); - return false; - } - if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_DAC_ONESHOT, (void *)bus, -1, channel)){ - dacDetachBus((void *)bus); - return false; - } - } +bool __dacWrite(uint8_t pin, uint8_t value) { + esp_err_t err = ESP_OK; + if (pin != DAC_CHAN0_GPIO_NUM && pin != DAC_CHAN1_GPIO_NUM) { + log_e("pin %u is not a DAC pin", pin); + return false; //not dac pin + } - err = dac_oneshot_output_voltage(bus, value); - if(err != ESP_OK){ - log_e("dac_oneshot_output_voltage failed with error: %d", err); - return false; + dac_oneshot_handle_t bus = (dac_oneshot_handle_t)perimanGetPinBus(pin, ESP32_BUS_TYPE_DAC_ONESHOT); + if (bus == NULL) { + perimanSetBusDeinit(ESP32_BUS_TYPE_DAC_ONESHOT, dacDetachBus); + if (!perimanClearPinBus(pin)) { + return false; } - return true; -} - -bool __dacDisable(uint8_t pin) -{ - if(pin != DAC_CHAN0_GPIO_NUM && pin != DAC_CHAN1_GPIO_NUM){ - log_e("pin %u is not a DAC pin", pin); - return false;//not dac pin + dac_channel_t channel = (pin == DAC_CHAN0_GPIO_NUM) ? DAC_CHAN_0 : DAC_CHAN_1; + dac_oneshot_config_t config = { + .chan_id = channel + }; + err = dac_oneshot_new_channel(&config, &bus); + if (err != ESP_OK) { + log_e("dac_oneshot_new_channel failed with error: %d", err); + return false; } - void * bus = perimanGetPinBus(pin, ESP32_BUS_TYPE_DAC_ONESHOT); - if(bus != NULL){ - // will call dacDetachBus - return perimanClearPinBus(pin); - } else { - log_e("pin %u is not attached to DAC", pin); + if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_DAC_ONESHOT, (void *)bus, -1, channel)) { + dacDetachBus((void *)bus); + return false; } + } + + err = dac_oneshot_output_voltage(bus, value); + if (err != ESP_OK) { + log_e("dac_oneshot_output_voltage failed with error: %d", err); return false; + } + return true; +} + +bool __dacDisable(uint8_t pin) { + if (pin != DAC_CHAN0_GPIO_NUM && pin != DAC_CHAN1_GPIO_NUM) { + log_e("pin %u is not a DAC pin", pin); + return false; //not dac pin + } + void *bus = perimanGetPinBus(pin, ESP32_BUS_TYPE_DAC_ONESHOT); + if (bus != NULL) { + // will call dacDetachBus + return perimanClearPinBus(pin); + } else { + log_e("pin %u is not attached to DAC", pin); + } + return false; } -extern bool dacWrite(uint8_t pin, uint8_t value) __attribute__ ((weak, alias("__dacWrite"))); -extern bool dacDisable(uint8_t pin) __attribute__ ((weak, alias("__dacDisable"))); +extern bool dacWrite(uint8_t pin, uint8_t value) __attribute__((weak, alias("__dacWrite"))); +extern bool dacDisable(uint8_t pin) __attribute__((weak, alias("__dacDisable"))); #endif diff --git a/cores/esp32/esp32-hal-dac.h b/cores/esp32/esp32-hal-dac.h index 113354ba830..1c6b5063a4e 100644 --- a/cores/esp32/esp32-hal-dac.h +++ b/cores/esp32/esp32-hal-dac.h @@ -16,8 +16,8 @@ extern "C" { #include #include -bool dacWrite(uint8_t pin, uint8_t value); -bool dacDisable(uint8_t pin); + bool dacWrite(uint8_t pin, uint8_t value); + bool dacDisable(uint8_t pin); #ifdef __cplusplus } diff --git a/cores/esp32/esp32-hal-gpio.c b/cores/esp32/esp32-hal-gpio.c index 2301302d62b..91cb47c67fd 100644 --- a/cores/esp32/esp32-hal-gpio.c +++ b/cores/esp32/esp32-hal-gpio.c @@ -19,266 +19,253 @@ // It fixes lack of pin definition for S3 and for any future SoC // this function works for ESP32, ESP32-S2 and ESP32-S3 - including the C3, it will return -1 for any pin -#if SOC_TOUCH_SENSOR_NUM > 0 +#if SOC_TOUCH_SENSOR_NUM > 0 #include "soc/touch_sensor_periph.h" -int8_t digitalPinToTouchChannel(uint8_t pin) -{ - int8_t ret = -1; - if (pin < SOC_GPIO_PIN_COUNT) { - for (uint8_t i = 0; i < SOC_TOUCH_SENSOR_NUM; i++) { - if (touch_sensor_channel_io_map[i] == pin) { - ret = i; - break; - } - } +int8_t digitalPinToTouchChannel(uint8_t pin) { + int8_t ret = -1; + if (pin < SOC_GPIO_PIN_COUNT) { + for (uint8_t i = 0; i < SOC_TOUCH_SENSOR_NUM; i++) { + if (touch_sensor_channel_io_map[i] == pin) { + ret = i; + break; + } } - return ret; + } + return ret; } #else // No Touch Sensor available -int8_t digitalPinToTouchChannel(uint8_t pin) -{ - return -1; +int8_t digitalPinToTouchChannel(uint8_t pin) { + return -1; } #endif #ifdef SOC_ADC_SUPPORTED #include "soc/adc_periph.h" -int8_t digitalPinToAnalogChannel(uint8_t pin) -{ - uint8_t channel = 0; - if (pin < SOC_GPIO_PIN_COUNT) { - for (uint8_t i = 0; i < SOC_ADC_PERIPH_NUM; i++) { - for (uint8_t j = 0; j < SOC_ADC_MAX_CHANNEL_NUM; j++) { - if (adc_channel_io_map[i][j] == pin) { - return channel; - } - channel++; - } +int8_t digitalPinToAnalogChannel(uint8_t pin) { + uint8_t channel = 0; + if (pin < SOC_GPIO_PIN_COUNT) { + for (uint8_t i = 0; i < SOC_ADC_PERIPH_NUM; i++) { + for (uint8_t j = 0; j < SOC_ADC_MAX_CHANNEL_NUM; j++) { + if (adc_channel_io_map[i][j] == pin) { + return channel; } + channel++; + } } - return -1; + } + return -1; } -int8_t analogChannelToDigitalPin(uint8_t channel) -{ - if (channel >= (SOC_ADC_PERIPH_NUM * SOC_ADC_MAX_CHANNEL_NUM)) { - return -1; - } - uint8_t adc_unit = (channel / SOC_ADC_MAX_CHANNEL_NUM); - uint8_t adc_chan = (channel % SOC_ADC_MAX_CHANNEL_NUM); - return adc_channel_io_map[adc_unit][adc_chan]; +int8_t analogChannelToDigitalPin(uint8_t channel) { + if (channel >= (SOC_ADC_PERIPH_NUM * SOC_ADC_MAX_CHANNEL_NUM)) { + return -1; + } + uint8_t adc_unit = (channel / SOC_ADC_MAX_CHANNEL_NUM); + uint8_t adc_chan = (channel % SOC_ADC_MAX_CHANNEL_NUM); + return adc_channel_io_map[adc_unit][adc_chan]; } #else -// No Analog channels availible -int8_t analogChannelToDigitalPin(uint8_t channel) -{ - return -1; +// No Analog channels available +int8_t analogChannelToDigitalPin(uint8_t channel) { + return -1; } #endif typedef void (*voidFuncPtr)(void); typedef void (*voidFuncPtrArg)(void*); typedef struct { - voidFuncPtr fn; - void* arg; - bool functional; + voidFuncPtr fn; + void* arg; + bool functional; } InterruptHandle_t; -static InterruptHandle_t __pinInterruptHandlers[SOC_GPIO_PIN_COUNT] = {0,}; +static InterruptHandle_t __pinInterruptHandlers[SOC_GPIO_PIN_COUNT] = { + 0, +}; #include "driver/rtc_io.h" -static bool gpioDetachBus(void * bus){ - return true; +static bool gpioDetachBus(void* bus) { + return true; } -extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode) -{ +extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode) { #ifdef RGB_BUILTIN - if (pin == RGB_BUILTIN){ - __pinMode(RGB_BUILTIN-SOC_GPIO_PIN_COUNT, mode); - return; - } + if (pin == RGB_BUILTIN) { + __pinMode(RGB_BUILTIN - SOC_GPIO_PIN_COUNT, mode); + return; + } #endif - if (pin >= SOC_GPIO_PIN_COUNT) { - log_e("Invalid IO %i selected", pin); - return; - } + if (pin >= SOC_GPIO_PIN_COUNT) { + log_e("Invalid IO %i selected", pin); + return; + } - if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL){ - perimanSetBusDeinit(ESP32_BUS_TYPE_GPIO, gpioDetachBus); - if(!perimanClearPinBus(pin)){ - log_e("Deinit of previous bus from IO %i failed", pin); - return; - } + if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL) { + perimanSetBusDeinit(ESP32_BUS_TYPE_GPIO, gpioDetachBus); + if (!perimanClearPinBus(pin)) { + log_e("Deinit of previous bus from IO %i failed", pin); + return; } - - gpio_hal_context_t gpiohal; - gpiohal.dev = GPIO_LL_GET_HW(GPIO_PORT_0); - - gpio_config_t conf = { - .pin_bit_mask = (1ULL<pin[pin].int_type /*!< GPIO interrupt type - previously set */ - }; - if (mode < 0x20) {//io - conf.mode = mode & (INPUT | OUTPUT); - if (mode & OPEN_DRAIN) { - conf.mode |= GPIO_MODE_DEF_OD; - } - if (mode & PULLUP) { - conf.pull_up_en = GPIO_PULLUP_ENABLE; - } - if (mode & PULLDOWN) { - conf.pull_down_en = GPIO_PULLDOWN_ENABLE; - } + } + + gpio_hal_context_t gpiohal; + gpiohal.dev = GPIO_LL_GET_HW(GPIO_PORT_0); + + gpio_config_t conf = { + .pin_bit_mask = (1ULL << pin), /*!< GPIO pin: set with bit mask, each bit maps to a GPIO */ + .mode = GPIO_MODE_DISABLE, /*!< GPIO mode: set input/output mode */ + .pull_up_en = GPIO_PULLUP_DISABLE, /*!< GPIO pull-up */ + .pull_down_en = GPIO_PULLDOWN_DISABLE, /*!< GPIO pull-down */ + .intr_type = gpiohal.dev->pin[pin].int_type /*!< GPIO interrupt type - previously set */ + }; + if (mode < 0x20) { //io + conf.mode = mode & (INPUT | OUTPUT); + if (mode & OPEN_DRAIN) { + conf.mode |= GPIO_MODE_DEF_OD; } - if(gpio_config(&conf) != ESP_OK) - { - log_e("IO %i config failed", pin); - return; + if (mode & PULLUP) { + conf.pull_up_en = GPIO_PULLUP_ENABLE; } - if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL){ - if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_GPIO, (void *)(pin+1), -1, -1)){ - //gpioDetachBus((void *)(pin+1)); - return; - } + if (mode & PULLDOWN) { + conf.pull_down_en = GPIO_PULLDOWN_ENABLE; + } + } + if (gpio_config(&conf) != ESP_OK) { + log_e("IO %i config failed", pin); + return; + } + if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL) { + if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_GPIO, (void*)(pin + 1), -1, -1)) { + //gpioDetachBus((void *)(pin+1)); + return; } + } } #ifdef RGB_BUILTIN uint8_t RGB_BUILTIN_storage = 0; #endif -extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val) -{ - #ifdef RGB_BUILTIN - if(pin == RGB_BUILTIN){ - //use RMT to set all channels on/off - RGB_BUILTIN_storage=val; - const uint8_t comm_val = val != 0 ? RGB_BRIGHTNESS : 0; - neopixelWrite(RGB_BUILTIN, comm_val, comm_val, comm_val); - return; - } - #endif - if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL){ - gpio_set_level((gpio_num_t)pin, val); - } else { - log_e("IO %i is not set as GPIO.", pin); - } +extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val) { +#ifdef RGB_BUILTIN + if (pin == RGB_BUILTIN) { + //use RMT to set all channels on/off + RGB_BUILTIN_storage = val; + const uint8_t comm_val = val != 0 ? RGB_BRIGHTNESS : 0; + neopixelWrite(RGB_BUILTIN, comm_val, comm_val, comm_val); + return; + } +#endif + if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL) { + gpio_set_level((gpio_num_t)pin, val); + } else { + log_e("IO %i is not set as GPIO.", pin); + } } -extern int ARDUINO_ISR_ATTR __digitalRead(uint8_t pin) -{ - #ifdef RGB_BUILTIN - if(pin == RGB_BUILTIN){ - return RGB_BUILTIN_storage; - } - #endif +extern int ARDUINO_ISR_ATTR __digitalRead(uint8_t pin) { +#ifdef RGB_BUILTIN + if (pin == RGB_BUILTIN) { + return RGB_BUILTIN_storage; + } +#endif - if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL){ - return gpio_get_level((gpio_num_t)pin); - } - else { - log_e("IO %i is not set as GPIO.", pin); - return 0; - } + if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL) { + return gpio_get_level((gpio_num_t)pin); + } else { + log_e("IO %i is not set as GPIO.", pin); + return 0; + } } -static void ARDUINO_ISR_ATTR __onPinInterrupt(void * arg) { - InterruptHandle_t * isr = (InterruptHandle_t*)arg; - if(isr->fn) { - if(isr->arg){ - ((voidFuncPtrArg)isr->fn)(isr->arg); - } else { - isr->fn(); - } +static void ARDUINO_ISR_ATTR __onPinInterrupt(void* arg) { + InterruptHandle_t* isr = (InterruptHandle_t*)arg; + if (isr->fn) { + if (isr->arg) { + ((voidFuncPtrArg)isr->fn)(isr->arg); + } else { + isr->fn(); } + } } extern void cleanupFunctional(void* arg); -extern void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtrArg userFunc, void * arg, int intr_type, bool functional) -{ - static bool interrupt_initialized = false; - - // makes sure that pin -1 (255) will never work -- this follows Arduino standard - if (pin >= SOC_GPIO_PIN_COUNT) return; - - if(!interrupt_initialized) { - esp_err_t err = gpio_install_isr_service((int)ARDUINO_ISR_FLAG); - interrupt_initialized = (err == ESP_OK) || (err == ESP_ERR_INVALID_STATE); - } - if(!interrupt_initialized) { - log_e("IO %i ISR Service Failed To Start", pin); - return; - } - - // if new attach without detach remove old info - if (__pinInterruptHandlers[pin].functional && __pinInterruptHandlers[pin].arg) - { - cleanupFunctional(__pinInterruptHandlers[pin].arg); - } - __pinInterruptHandlers[pin].fn = (voidFuncPtr)userFunc; - __pinInterruptHandlers[pin].arg = arg; - __pinInterruptHandlers[pin].functional = functional; - - gpio_set_intr_type((gpio_num_t)pin, (gpio_int_type_t)(intr_type & 0x7)); - if(intr_type & 0x8){ - gpio_wakeup_enable((gpio_num_t)pin, (gpio_int_type_t)(intr_type & 0x7)); - } - gpio_isr_handler_add((gpio_num_t)pin, __onPinInterrupt, &__pinInterruptHandlers[pin]); - - - //FIX interrupts on peripherals outputs (eg. LEDC,...) - //Enable input in GPIO register - gpio_hal_context_t gpiohal; - gpiohal.dev = GPIO_LL_GET_HW(GPIO_PORT_0); - gpio_hal_input_enable(&gpiohal, pin); +extern void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtrArg userFunc, void* arg, int intr_type, bool functional) { + static bool interrupt_initialized = false; + + // makes sure that pin -1 (255) will never work -- this follows Arduino standard + if (pin >= SOC_GPIO_PIN_COUNT) return; + + if (!interrupt_initialized) { + esp_err_t err = gpio_install_isr_service((int)ARDUINO_ISR_FLAG); + interrupt_initialized = (err == ESP_OK) || (err == ESP_ERR_INVALID_STATE); + } + if (!interrupt_initialized) { + log_e("IO %i ISR Service Failed To Start", pin); + return; + } + + // if new attach without detach remove old info + if (__pinInterruptHandlers[pin].functional && __pinInterruptHandlers[pin].arg) { + cleanupFunctional(__pinInterruptHandlers[pin].arg); + } + __pinInterruptHandlers[pin].fn = (voidFuncPtr)userFunc; + __pinInterruptHandlers[pin].arg = arg; + __pinInterruptHandlers[pin].functional = functional; + + gpio_set_intr_type((gpio_num_t)pin, (gpio_int_type_t)(intr_type & 0x7)); + if (intr_type & 0x8) { + gpio_wakeup_enable((gpio_num_t)pin, (gpio_int_type_t)(intr_type & 0x7)); + } + gpio_isr_handler_add((gpio_num_t)pin, __onPinInterrupt, &__pinInterruptHandlers[pin]); + + + //FIX interrupts on peripherals outputs (eg. LEDC,...) + //Enable input in GPIO register + gpio_hal_context_t gpiohal; + gpiohal.dev = GPIO_LL_GET_HW(GPIO_PORT_0); + gpio_hal_input_enable(&gpiohal, pin); } -extern void __attachInterruptArg(uint8_t pin, voidFuncPtrArg userFunc, void * arg, int intr_type) -{ - __attachInterruptFunctionalArg(pin, userFunc, arg, intr_type, false); +extern void __attachInterruptArg(uint8_t pin, voidFuncPtrArg userFunc, void* arg, int intr_type) { + __attachInterruptFunctionalArg(pin, userFunc, arg, intr_type, false); } extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int intr_type) { - __attachInterruptFunctionalArg(pin, (voidFuncPtrArg)userFunc, NULL, intr_type, false); + __attachInterruptFunctionalArg(pin, (voidFuncPtrArg)userFunc, NULL, intr_type, false); } -extern void __detachInterrupt(uint8_t pin) -{ - gpio_isr_handler_remove((gpio_num_t)pin); //remove handle and disable isr for pin - gpio_wakeup_disable((gpio_num_t)pin); +extern void __detachInterrupt(uint8_t pin) { + gpio_isr_handler_remove((gpio_num_t)pin); //remove handle and disable isr for pin + gpio_wakeup_disable((gpio_num_t)pin); - if (__pinInterruptHandlers[pin].functional && __pinInterruptHandlers[pin].arg) - { - cleanupFunctional(__pinInterruptHandlers[pin].arg); - } - __pinInterruptHandlers[pin].fn = NULL; - __pinInterruptHandlers[pin].arg = NULL; - __pinInterruptHandlers[pin].functional = false; + if (__pinInterruptHandlers[pin].functional && __pinInterruptHandlers[pin].arg) { + cleanupFunctional(__pinInterruptHandlers[pin].arg); + } + __pinInterruptHandlers[pin].fn = NULL; + __pinInterruptHandlers[pin].arg = NULL; + __pinInterruptHandlers[pin].functional = false; - gpio_set_intr_type((gpio_num_t)pin, GPIO_INTR_DISABLE); + gpio_set_intr_type((gpio_num_t)pin, GPIO_INTR_DISABLE); } extern void enableInterrupt(uint8_t pin) { - gpio_intr_enable((gpio_num_t)pin); + gpio_intr_enable((gpio_num_t)pin); } extern void disableInterrupt(uint8_t pin) { - gpio_intr_disable((gpio_num_t)pin); + gpio_intr_disable((gpio_num_t)pin); } -extern void pinMode(uint8_t pin, uint8_t mode) __attribute__ ((weak, alias("__pinMode"))); -extern void digitalWrite(uint8_t pin, uint8_t val) __attribute__ ((weak, alias("__digitalWrite"))); -extern int digitalRead(uint8_t pin) __attribute__ ((weak, alias("__digitalRead"))); -extern void attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode) __attribute__ ((weak, alias("__attachInterrupt"))); -extern void attachInterruptArg(uint8_t pin, voidFuncPtrArg handler, void * arg, int mode) __attribute__ ((weak, alias("__attachInterruptArg"))); -extern void detachInterrupt(uint8_t pin) __attribute__ ((weak, alias("__detachInterrupt"))); +extern void pinMode(uint8_t pin, uint8_t mode) __attribute__((weak, alias("__pinMode"))); +extern void digitalWrite(uint8_t pin, uint8_t val) __attribute__((weak, alias("__digitalWrite"))); +extern int digitalRead(uint8_t pin) __attribute__((weak, alias("__digitalRead"))); +extern void attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode) __attribute__((weak, alias("__attachInterrupt"))); +extern void attachInterruptArg(uint8_t pin, voidFuncPtrArg handler, void* arg, int mode) __attribute__((weak, alias("__attachInterruptArg"))); +extern void detachInterrupt(uint8_t pin) __attribute__((weak, alias("__detachInterrupt"))); diff --git a/cores/esp32/esp32-hal-gpio.h b/cores/esp32/esp32-hal-gpio.h index a45302d9e99..7c0905de524 100644 --- a/cores/esp32/esp32-hal-gpio.h +++ b/cores/esp32/esp32-hal-gpio.h @@ -29,61 +29,62 @@ extern "C" { #include "pins_arduino.h" #if (CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3) -#define NUM_OUPUT_PINS 46 -#define PIN_DAC1 17 -#define PIN_DAC2 18 +#define NUM_OUPUT_PINS 46 +#define PIN_DAC1 17 +#define PIN_DAC2 18 #else -#define NUM_OUPUT_PINS 34 -#define PIN_DAC1 25 -#define PIN_DAC2 26 +#define NUM_OUPUT_PINS 34 +#define PIN_DAC1 25 +#define PIN_DAC2 26 #endif -#define LOW 0x0 -#define HIGH 0x1 +#define LOW 0x0 +#define HIGH 0x1 //GPIO FUNCTIONS -#define INPUT 0x01 -// Changed OUTPUT from 0x02 to behave the same as Arduino pinMode(pin,OUTPUT) +#define INPUT 0x01 +// Changed OUTPUT from 0x02 to behave the same as Arduino pinMode(pin,OUTPUT) // where you can read the state of pin even when it is set as OUTPUT -#define OUTPUT 0x03 -#define PULLUP 0x04 -#define INPUT_PULLUP 0x05 -#define PULLDOWN 0x08 -#define INPUT_PULLDOWN 0x09 -#define OPEN_DRAIN 0x10 +#define OUTPUT 0x03 +#define PULLUP 0x04 +#define INPUT_PULLUP 0x05 +#define PULLDOWN 0x08 +#define INPUT_PULLDOWN 0x09 +#define OPEN_DRAIN 0x10 #define OUTPUT_OPEN_DRAIN 0x13 -#define ANALOG 0xC0 +#define ANALOG 0xC0 //Interrupt Modes -#define DISABLED 0x00 -#define RISING 0x01 -#define FALLING 0x02 -#define CHANGE 0x03 -#define ONLOW 0x04 -#define ONHIGH 0x05 -#define ONLOW_WE 0x0C +#define DISABLED 0x00 +#define RISING 0x01 +#define FALLING 0x02 +#define CHANGE 0x03 +#define ONLOW 0x04 +#define ONHIGH 0x05 +#define ONLOW_WE 0x0C #define ONHIGH_WE 0x0D -#define digitalPinIsValid(pin) GPIO_IS_VALID_GPIO(pin) -#define digitalPinCanOutput(pin) GPIO_IS_VALID_OUTPUT_GPIO(pin) +#define digitalPinIsValid(pin) GPIO_IS_VALID_GPIO(pin) +#define digitalPinCanOutput(pin) GPIO_IS_VALID_OUTPUT_GPIO(pin) -#define digitalPinToRtcPin(pin) ((RTC_GPIO_IS_VALID_GPIO(pin))?rtc_io_number_get(pin):-1) -#define digitalPinToDacChannel(pin) (((pin) == DAC_CHANNEL_1_GPIO_NUM)?0:((pin) == DAC_CHANNEL_2_GPIO_NUM)?1:-1) +#define digitalPinToRtcPin(pin) ((RTC_GPIO_IS_VALID_GPIO(pin)) ? rtc_io_number_get(pin) : -1) +#define digitalPinToDacChannel(pin) (((pin) == DAC_CHANNEL_1_GPIO_NUM) ? 0 : ((pin) == DAC_CHANNEL_2_GPIO_NUM) ? 1 \ + : -1) -void pinMode(uint8_t pin, uint8_t mode); -void digitalWrite(uint8_t pin, uint8_t val); -int digitalRead(uint8_t pin); + void pinMode(uint8_t pin, uint8_t mode); + void digitalWrite(uint8_t pin, uint8_t val); + int digitalRead(uint8_t pin); -void attachInterrupt(uint8_t pin, void (*)(void), int mode); -void attachInterruptArg(uint8_t pin, void (*)(void*), void * arg, int mode); -void detachInterrupt(uint8_t pin); -void enableInterrupt(uint8_t pin); -void disableInterrupt(uint8_t pin); + void attachInterrupt(uint8_t pin, void (*)(void), int mode); + void attachInterruptArg(uint8_t pin, void (*)(void*), void* arg, int mode); + void detachInterrupt(uint8_t pin); + void enableInterrupt(uint8_t pin); + void disableInterrupt(uint8_t pin); -int8_t digitalPinToTouchChannel(uint8_t pin); -int8_t digitalPinToAnalogChannel(uint8_t pin); -int8_t analogChannelToDigitalPin(uint8_t channel); + int8_t digitalPinToTouchChannel(uint8_t pin); + int8_t digitalPinToAnalogChannel(uint8_t pin); + int8_t analogChannelToDigitalPin(uint8_t channel); #ifdef __cplusplus } diff --git a/cores/esp32/esp32-hal-i2c-slave.c b/cores/esp32/esp32-hal-i2c-slave.c index 3589ecfc5a8..3a2f4e56f34 100644 --- a/cores/esp32/esp32-hal-i2c-slave.c +++ b/cores/esp32/esp32-hal-i2c-slave.c @@ -47,69 +47,72 @@ #include "esp32-hal-i2c-slave.h" #include "esp32-hal-periman.h" -#define I2C_SLAVE_USE_RX_QUEUE 0 // 1: Queue, 0: RingBuffer +#define I2C_SLAVE_USE_RX_QUEUE 0 // 1: Queue, 0: RingBuffer #if SOC_I2C_NUM > 1 -#define I2C_SCL_IDX(p) ((p==0)?I2CEXT0_SCL_OUT_IDX:((p==1)?I2CEXT1_SCL_OUT_IDX:0)) -#define I2C_SDA_IDX(p) ((p==0)?I2CEXT0_SDA_OUT_IDX:((p==1)?I2CEXT1_SDA_OUT_IDX:0)) +#define I2C_SCL_IDX(p) ((p == 0) ? I2CEXT0_SCL_OUT_IDX : ((p == 1) ? I2CEXT1_SCL_OUT_IDX : 0)) +#define I2C_SDA_IDX(p) ((p == 0) ? I2CEXT0_SDA_OUT_IDX : ((p == 1) ? I2CEXT1_SDA_OUT_IDX : 0)) #else -#define I2C_SCL_IDX(p) I2CEXT0_SCL_OUT_IDX +#define I2C_SCL_IDX(p) I2CEXT0_SCL_OUT_IDX #define I2C_SDA_IDX(p) I2CEXT0_SDA_OUT_IDX #endif #if CONFIG_IDF_TARGET_ESP32 - #define I2C_TXFIFO_WM_INT_ENA I2C_TXFIFO_EMPTY_INT_ENA - #define I2C_RXFIFO_WM_INT_ENA I2C_RXFIFO_FULL_INT_ENA +#define I2C_TXFIFO_WM_INT_ENA I2C_TXFIFO_EMPTY_INT_ENA +#define I2C_RXFIFO_WM_INT_ENA I2C_RXFIFO_FULL_INT_ENA #endif enum { - I2C_SLAVE_EVT_RX, I2C_SLAVE_EVT_TX + I2C_SLAVE_EVT_RX, + I2C_SLAVE_EVT_TX }; typedef struct i2c_slave_struct_t { - i2c_dev_t * dev; - uint8_t num; - int8_t sda; - int8_t scl; - i2c_slave_request_cb_t request_callback; - i2c_slave_receive_cb_t receive_callback; - void * arg; - intr_handle_t intr_handle; - TaskHandle_t task_handle; - QueueHandle_t event_queue; + i2c_dev_t *dev; + uint8_t num; + int8_t sda; + int8_t scl; + i2c_slave_request_cb_t request_callback; + i2c_slave_receive_cb_t receive_callback; + void *arg; + intr_handle_t intr_handle; + TaskHandle_t task_handle; + QueueHandle_t event_queue; #if I2C_SLAVE_USE_RX_QUEUE - QueueHandle_t rx_queue; + QueueHandle_t rx_queue; #else - RingbufHandle_t rx_ring_buf; + RingbufHandle_t rx_ring_buf; #endif - QueueHandle_t tx_queue; - uint32_t rx_data_count; + QueueHandle_t tx_queue; + uint32_t rx_data_count; #if !CONFIG_DISABLE_HAL_LOCKS - SemaphoreHandle_t lock; + SemaphoreHandle_t lock; #endif } i2c_slave_struct_t; typedef union { - struct { - uint32_t event : 2; - uint32_t stop : 1; - uint32_t param : 29; - }; - uint32_t val; + struct { + uint32_t event : 2; + uint32_t stop : 1; + uint32_t param : 29; + }; + uint32_t val; } i2c_slave_queue_event_t; static i2c_slave_struct_t _i2c_bus_array[SOC_I2C_NUM] = { - { &I2C0, 0, -1, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0 + { &I2C0, 0, -1, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0 #if !CONFIG_DISABLE_HAL_LOCKS - , NULL + , + NULL #endif - }, + }, #if SOC_I2C_NUM > 1 - { &I2C1, 1, -1, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0 + { &I2C1, 1, -1, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0 #if !CONFIG_DISABLE_HAL_LOCKS - , NULL + , + NULL #endif - } + } #endif }; @@ -117,767 +120,757 @@ static i2c_slave_struct_t _i2c_bus_array[SOC_I2C_NUM] = { #define I2C_SLAVE_MUTEX_LOCK() #define I2C_SLAVE_MUTEX_UNLOCK() #else -#define I2C_SLAVE_MUTEX_LOCK() if(i2c->lock){xSemaphoreTake(i2c->lock, portMAX_DELAY);} -#define I2C_SLAVE_MUTEX_UNLOCK() if(i2c->lock){xSemaphoreGive(i2c->lock);} +#define I2C_SLAVE_MUTEX_LOCK() \ + if (i2c->lock) { xSemaphoreTake(i2c->lock, portMAX_DELAY); } +#define I2C_SLAVE_MUTEX_UNLOCK() \ + if (i2c->lock) { xSemaphoreGive(i2c->lock); } #endif //-------------------------------------- HAL_LL (Missing Functions) ------------------------------------------------ typedef enum { - I2C_STRETCH_CAUSE_MASTER_READ, - I2C_STRETCH_CAUSE_TX_FIFO_EMPTY, - I2C_STRETCH_CAUSE_RX_FIFO_FULL, - I2C_STRETCH_CAUSE_MAX + I2C_STRETCH_CAUSE_MASTER_READ, + I2C_STRETCH_CAUSE_TX_FIFO_EMPTY, + I2C_STRETCH_CAUSE_RX_FIFO_FULL, + I2C_STRETCH_CAUSE_MAX } i2c_stretch_cause_t; -static inline i2c_stretch_cause_t i2c_ll_stretch_cause(i2c_dev_t *hw) -{ +static inline i2c_stretch_cause_t i2c_ll_stretch_cause(i2c_dev_t *hw) { #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 - return hw->sr.stretch_cause; + return hw->sr.stretch_cause; #elif CONFIG_IDF_TARGET_ESP32S2 - return hw->status_reg.stretch_cause; + return hw->status_reg.stretch_cause; #else - return I2C_STRETCH_CAUSE_MAX; + return I2C_STRETCH_CAUSE_MAX; #endif } -static inline void i2c_ll_set_stretch(i2c_dev_t *hw, uint16_t time) -{ +static inline void i2c_ll_set_stretch(i2c_dev_t *hw, uint16_t time) { #ifndef CONFIG_IDF_TARGET_ESP32 - typeof(hw->scl_stretch_conf) scl_stretch_conf; - scl_stretch_conf.val = 0; - scl_stretch_conf.slave_scl_stretch_en = (time > 0); - scl_stretch_conf.stretch_protect_num = time; - scl_stretch_conf.slave_scl_stretch_clr = 1; - hw->scl_stretch_conf.val = scl_stretch_conf.val; - if(time > 0){ - //enable interrupt - hw->int_ena.val |= I2C_SLAVE_STRETCH_INT_ENA; - } else { - //disable interrupt - hw->int_ena.val &= (~I2C_SLAVE_STRETCH_INT_ENA); - } + typeof(hw->scl_stretch_conf) scl_stretch_conf; + scl_stretch_conf.val = 0; + scl_stretch_conf.slave_scl_stretch_en = (time > 0); + scl_stretch_conf.stretch_protect_num = time; + scl_stretch_conf.slave_scl_stretch_clr = 1; + hw->scl_stretch_conf.val = scl_stretch_conf.val; + if (time > 0) { + //enable interrupt + hw->int_ena.val |= I2C_SLAVE_STRETCH_INT_ENA; + } else { + //disable interrupt + hw->int_ena.val &= (~I2C_SLAVE_STRETCH_INT_ENA); + } #endif } -static inline void i2c_ll_stretch_clr(i2c_dev_t *hw) -{ +static inline void i2c_ll_stretch_clr(i2c_dev_t *hw) { #ifndef CONFIG_IDF_TARGET_ESP32 - hw->scl_stretch_conf.slave_scl_stretch_clr = 1; + hw->scl_stretch_conf.slave_scl_stretch_clr = 1; #endif } -static inline bool i2c_ll_slave_addressed(i2c_dev_t *hw) -{ +static inline bool i2c_ll_slave_addressed(i2c_dev_t *hw) { #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32H2 - return hw->sr.slave_addressed; + return hw->sr.slave_addressed; #else - return hw->status_reg.slave_addressed; + return hw->status_reg.slave_addressed; #endif } -static inline bool i2c_ll_slave_rw(i2c_dev_t *hw)//not exposed by hal_ll +static inline bool i2c_ll_slave_rw(i2c_dev_t *hw) //not exposed by hal_ll { #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32H2 - return hw->sr.slave_rw; + return hw->sr.slave_rw; #else - return hw->status_reg.slave_rw; + return hw->status_reg.slave_rw; #endif } //-------------------------------------- PRIVATE (Function Prototypes) ------------------------------------------------ -static void i2c_slave_free_resources(i2c_slave_struct_t * i2c); +static void i2c_slave_free_resources(i2c_slave_struct_t *i2c); static void i2c_slave_delay_us(uint64_t us); static void i2c_slave_gpio_mode(int8_t pin, gpio_mode_t mode); static bool i2c_slave_check_line_state(int8_t sda, int8_t scl); -static bool i2c_slave_attach_gpio(i2c_slave_struct_t * i2c, int8_t sda, int8_t scl); -static bool i2c_slave_detach_gpio(i2c_slave_struct_t * i2c); -static bool i2c_slave_set_frequency(i2c_slave_struct_t * i2c, uint32_t clk_speed); -static bool i2c_slave_send_event(i2c_slave_struct_t * i2c, i2c_slave_queue_event_t* event); -static bool i2c_slave_handle_tx_fifo_empty(i2c_slave_struct_t * i2c); -static bool i2c_slave_handle_rx_fifo_full(i2c_slave_struct_t * i2c, uint32_t len); -static size_t i2c_slave_read_rx(i2c_slave_struct_t * i2c, uint8_t * data, size_t len); -static void i2c_slave_isr_handler(void* arg); +static bool i2c_slave_attach_gpio(i2c_slave_struct_t *i2c, int8_t sda, int8_t scl); +static bool i2c_slave_detach_gpio(i2c_slave_struct_t *i2c); +static bool i2c_slave_set_frequency(i2c_slave_struct_t *i2c, uint32_t clk_speed); +static bool i2c_slave_send_event(i2c_slave_struct_t *i2c, i2c_slave_queue_event_t *event); +static bool i2c_slave_handle_tx_fifo_empty(i2c_slave_struct_t *i2c); +static bool i2c_slave_handle_rx_fifo_full(i2c_slave_struct_t *i2c, uint32_t len); +static size_t i2c_slave_read_rx(i2c_slave_struct_t *i2c, uint8_t *data, size_t len); +static void i2c_slave_isr_handler(void *arg); static void i2c_slave_task(void *pv_args); -static bool i2cSlaveDetachBus(void * bus_i2c_num); +static bool i2cSlaveDetachBus(void *bus_i2c_num); //===================================================================================================================== //-------------------------------------- Public Functions ------------------------------------------------------------- //===================================================================================================================== -esp_err_t i2cSlaveAttachCallbacks(uint8_t num, i2c_slave_request_cb_t request_callback, i2c_slave_receive_cb_t receive_callback, void * arg){ - if(num >= SOC_I2C_NUM){ - log_e("Invalid port num: %u", num); - return ESP_ERR_INVALID_ARG; - } - i2c_slave_struct_t * i2c = &_i2c_bus_array[num]; - I2C_SLAVE_MUTEX_LOCK(); - i2c->request_callback = request_callback; - i2c->receive_callback = receive_callback; - i2c->arg = arg; - I2C_SLAVE_MUTEX_UNLOCK(); - return ESP_OK; +esp_err_t i2cSlaveAttachCallbacks(uint8_t num, i2c_slave_request_cb_t request_callback, i2c_slave_receive_cb_t receive_callback, void *arg) { + if (num >= SOC_I2C_NUM) { + log_e("Invalid port num: %u", num); + return ESP_ERR_INVALID_ARG; + } + i2c_slave_struct_t *i2c = &_i2c_bus_array[num]; + I2C_SLAVE_MUTEX_LOCK(); + i2c->request_callback = request_callback; + i2c->receive_callback = receive_callback; + i2c->arg = arg; + I2C_SLAVE_MUTEX_UNLOCK(); + return ESP_OK; } esp_err_t i2cSlaveInit(uint8_t num, int sda, int scl, uint16_t slaveID, uint32_t frequency, size_t rx_len, size_t tx_len) { - if(num >= SOC_I2C_NUM){ - log_e("Invalid port num: %u", num); - return ESP_ERR_INVALID_ARG; - } + if (num >= SOC_I2C_NUM) { + log_e("Invalid port num: %u", num); + return ESP_ERR_INVALID_ARG; + } - if (sda < 0 || scl < 0) { - log_e("invalid pins sda=%d, scl=%d", sda, scl); - return ESP_ERR_INVALID_ARG; - } + if (sda < 0 || scl < 0) { + log_e("invalid pins sda=%d, scl=%d", sda, scl); + return ESP_ERR_INVALID_ARG; + } - if(!frequency){ - frequency = 100000; - } else if(frequency > 1000000){ - frequency = 1000000; - } + if (!frequency) { + frequency = 100000; + } else if (frequency > 1000000) { + frequency = 1000000; + } - perimanSetBusDeinit(ESP32_BUS_TYPE_I2C_SLAVE_SDA, i2cSlaveDetachBus); - perimanSetBusDeinit(ESP32_BUS_TYPE_I2C_SLAVE_SCL, i2cSlaveDetachBus); + perimanSetBusDeinit(ESP32_BUS_TYPE_I2C_SLAVE_SDA, i2cSlaveDetachBus); + perimanSetBusDeinit(ESP32_BUS_TYPE_I2C_SLAVE_SCL, i2cSlaveDetachBus); - if(!perimanClearPinBus(sda) || !perimanClearPinBus(scl)){ - return false; - } + if (!perimanClearPinBus(sda) || !perimanClearPinBus(scl)) { + return false; + } - log_i("Initialising I2C Slave: sda=%d scl=%d freq=%d, addr=0x%x", sda, scl, frequency, slaveID); + log_i("Initializing I2C Slave: sda=%d scl=%d freq=%d, addr=0x%x", sda, scl, frequency, slaveID); - i2c_slave_struct_t * i2c = &_i2c_bus_array[num]; - esp_err_t ret = ESP_OK; + i2c_slave_struct_t *i2c = &_i2c_bus_array[num]; + esp_err_t ret = ESP_OK; #if !CONFIG_DISABLE_HAL_LOCKS - if(!i2c->lock){ - i2c->lock = xSemaphoreCreateMutex(); - if (i2c->lock == NULL) { - log_e("RX queue create failed"); - return ESP_ERR_NO_MEM; - } + if (!i2c->lock) { + i2c->lock = xSemaphoreCreateMutex(); + if (i2c->lock == NULL) { + log_e("RX queue create failed"); + return ESP_ERR_NO_MEM; } + } #endif - I2C_SLAVE_MUTEX_LOCK(); - i2c_slave_free_resources(i2c); + I2C_SLAVE_MUTEX_LOCK(); + i2c_slave_free_resources(i2c); #if I2C_SLAVE_USE_RX_QUEUE - i2c->rx_queue = xQueueCreate(rx_len, sizeof(uint8_t)); - if (i2c->rx_queue == NULL) { - log_e("RX queue create failed"); - ret = ESP_ERR_NO_MEM; - goto fail; - } + i2c->rx_queue = xQueueCreate(rx_len, sizeof(uint8_t)); + if (i2c->rx_queue == NULL) { + log_e("RX queue create failed"); + ret = ESP_ERR_NO_MEM; + goto fail; + } #else - i2c->rx_ring_buf = xRingbufferCreate(rx_len, RINGBUF_TYPE_BYTEBUF); - if (i2c->rx_ring_buf == NULL) { - log_e("RX RingBuf create failed"); - ret = ESP_ERR_NO_MEM; - goto fail; - } + i2c->rx_ring_buf = xRingbufferCreate(rx_len, RINGBUF_TYPE_BYTEBUF); + if (i2c->rx_ring_buf == NULL) { + log_e("RX RingBuf create failed"); + ret = ESP_ERR_NO_MEM; + goto fail; + } #endif - i2c->tx_queue = xQueueCreate(tx_len, sizeof(uint8_t)); - if (i2c->tx_queue == NULL) { - log_e("TX queue create failed"); - ret = ESP_ERR_NO_MEM; - goto fail; - } - - i2c->event_queue = xQueueCreate(16, sizeof(i2c_slave_queue_event_t)); - if (i2c->event_queue == NULL) { - log_e("Event queue create failed"); - ret = ESP_ERR_NO_MEM; - goto fail; - } - - xTaskCreate(i2c_slave_task, "i2c_slave_task", 4096, i2c, 20, &i2c->task_handle); - if(i2c->task_handle == NULL){ - log_e("Event thread create failed"); - ret = ESP_ERR_NO_MEM; - goto fail; - } - - if (frequency == 0) { - frequency = 100000L; - } - frequency = (frequency * 5) / 4; - + i2c->tx_queue = xQueueCreate(tx_len, sizeof(uint8_t)); + if (i2c->tx_queue == NULL) { + log_e("TX queue create failed"); + ret = ESP_ERR_NO_MEM; + goto fail; + } + + i2c->event_queue = xQueueCreate(16, sizeof(i2c_slave_queue_event_t)); + if (i2c->event_queue == NULL) { + log_e("Event queue create failed"); + ret = ESP_ERR_NO_MEM; + goto fail; + } + + xTaskCreate(i2c_slave_task, "i2c_slave_task", 4096, i2c, 20, &i2c->task_handle); + if (i2c->task_handle == NULL) { + log_e("Event thread create failed"); + ret = ESP_ERR_NO_MEM; + goto fail; + } + + if (frequency == 0) { + frequency = 100000L; + } + frequency = (frequency * 5) / 4; + + if (i2c->num == 0) { + periph_ll_enable_clk_clear_rst(PERIPH_I2C0_MODULE); +#if SOC_I2C_NUM > 1 + } else { + periph_ll_enable_clk_clear_rst(PERIPH_I2C1_MODULE); +#endif + } + + i2c_ll_slave_init(i2c->dev); + i2c_ll_set_fifo_mode(i2c->dev, true); + i2c_ll_set_slave_addr(i2c->dev, slaveID, false); + i2c_ll_set_tout(i2c->dev, I2C_LL_MAX_TIMEOUT); + i2c_slave_set_frequency(i2c, frequency); + + if (!i2c_slave_check_line_state(sda, scl)) { + log_e("bad pin state"); + ret = ESP_FAIL; + goto fail; + } + + i2c_slave_attach_gpio(i2c, sda, scl); + + if (i2c_ll_is_bus_busy(i2c->dev)) { + log_w("Bus busy, reinit"); + ret = ESP_FAIL; + goto fail; + } + + i2c_ll_disable_intr_mask(i2c->dev, I2C_LL_INTR_MASK); + i2c_ll_clear_intr_mask(i2c->dev, I2C_LL_INTR_MASK); + i2c_ll_set_fifo_mode(i2c->dev, true); + + if (!i2c->intr_handle) { + uint32_t flags = ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_SHARED; if (i2c->num == 0) { - periph_ll_enable_clk_clear_rst(PERIPH_I2C0_MODULE); + ret = esp_intr_alloc(ETS_I2C_EXT0_INTR_SOURCE, flags, &i2c_slave_isr_handler, i2c, &i2c->intr_handle); #if SOC_I2C_NUM > 1 } else { - periph_ll_enable_clk_clear_rst(PERIPH_I2C1_MODULE); + ret = esp_intr_alloc(ETS_I2C_EXT1_INTR_SOURCE, flags, &i2c_slave_isr_handler, i2c, &i2c->intr_handle); #endif } - - i2c_ll_slave_init(i2c->dev); - i2c_ll_set_fifo_mode(i2c->dev, true); - i2c_ll_set_slave_addr(i2c->dev, slaveID, false); - i2c_ll_set_tout(i2c->dev, I2C_LL_MAX_TIMEOUT); - i2c_slave_set_frequency(i2c, frequency); - - if (!i2c_slave_check_line_state(sda, scl)) { - log_e("bad pin state"); - ret = ESP_FAIL; - goto fail; - } - - i2c_slave_attach_gpio(i2c, sda, scl); - if (i2c_ll_is_bus_busy(i2c->dev)) { - log_w("Bus busy, reinit"); - ret = ESP_FAIL; - goto fail; + if (ret != ESP_OK) { + log_e("install interrupt handler Failed=%d", ret); + goto fail; } + } - i2c_ll_disable_intr_mask(i2c->dev, I2C_LL_INTR_MASK); - i2c_ll_clear_intr_mask(i2c->dev, I2C_LL_INTR_MASK); - i2c_ll_set_fifo_mode(i2c->dev, true); - - if (!i2c->intr_handle) { - uint32_t flags = ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_SHARED; - if(i2c->num == 0) { - ret = esp_intr_alloc(ETS_I2C_EXT0_INTR_SOURCE, flags, &i2c_slave_isr_handler, i2c, &i2c->intr_handle); -#if SOC_I2C_NUM > 1 - } else { - ret = esp_intr_alloc(ETS_I2C_EXT1_INTR_SOURCE, flags, &i2c_slave_isr_handler, i2c, &i2c->intr_handle); -#endif - } - - if (ret != ESP_OK) { - log_e("install interrupt handler Failed=%d", ret); - goto fail; - } - } - - i2c_ll_txfifo_rst(i2c->dev); - i2c_ll_rxfifo_rst(i2c->dev); - i2c_ll_slave_enable_rx_it(i2c->dev); - i2c_ll_set_stretch(i2c->dev, 0x3FF); - i2c_ll_update(i2c->dev); - if(!perimanSetPinBus(sda, ESP32_BUS_TYPE_I2C_SLAVE_SDA, (void *)(i2c->num+1), i2c->num, -1) || !perimanSetPinBus(scl, ESP32_BUS_TYPE_I2C_SLAVE_SCL, (void *)(i2c->num+1), i2c->num, -1)){ - i2cSlaveDetachBus((void *)(i2c->num+1)); - ret = ESP_FAIL; - } - I2C_SLAVE_MUTEX_UNLOCK(); - return ret; + i2c_ll_txfifo_rst(i2c->dev); + i2c_ll_rxfifo_rst(i2c->dev); + i2c_ll_slave_enable_rx_it(i2c->dev); + i2c_ll_set_stretch(i2c->dev, 0x3FF); + i2c_ll_update(i2c->dev); + if (!perimanSetPinBus(sda, ESP32_BUS_TYPE_I2C_SLAVE_SDA, (void *)(i2c->num + 1), i2c->num, -1) || !perimanSetPinBus(scl, ESP32_BUS_TYPE_I2C_SLAVE_SCL, (void *)(i2c->num + 1), i2c->num, -1)) { + i2cSlaveDetachBus((void *)(i2c->num + 1)); + ret = ESP_FAIL; + } + I2C_SLAVE_MUTEX_UNLOCK(); + return ret; fail: - i2c_slave_free_resources(i2c); - I2C_SLAVE_MUTEX_UNLOCK(); - return ret; + i2c_slave_free_resources(i2c); + I2C_SLAVE_MUTEX_UNLOCK(); + return ret; } -esp_err_t i2cSlaveDeinit(uint8_t num){ - if(num >= SOC_I2C_NUM){ - log_e("Invalid port num: %u", num); - return ESP_ERR_INVALID_ARG; - } +esp_err_t i2cSlaveDeinit(uint8_t num) { + if (num >= SOC_I2C_NUM) { + log_e("Invalid port num: %u", num); + return ESP_ERR_INVALID_ARG; + } - i2c_slave_struct_t * i2c = &_i2c_bus_array[num]; + i2c_slave_struct_t *i2c = &_i2c_bus_array[num]; #if !CONFIG_DISABLE_HAL_LOCKS - if(!i2c->lock){ - log_e("Lock is not initialized! Did you call i2c_slave_init()?"); - return ESP_ERR_NO_MEM; - } + if (!i2c->lock) { + log_e("Lock is not initialized! Did you call i2c_slave_init()?"); + return ESP_ERR_NO_MEM; + } #endif - I2C_SLAVE_MUTEX_LOCK(); - int scl = i2c->scl; - int sda = i2c->sda; - i2c_slave_free_resources(i2c); - perimanClearPinBus(scl); - perimanClearPinBus(sda); - I2C_SLAVE_MUTEX_UNLOCK(); - return ESP_OK; + I2C_SLAVE_MUTEX_LOCK(); + int scl = i2c->scl; + int sda = i2c->sda; + i2c_slave_free_resources(i2c); + perimanClearPinBus(scl); + perimanClearPinBus(sda); + I2C_SLAVE_MUTEX_UNLOCK(); + return ESP_OK; } size_t i2cSlaveWrite(uint8_t num, const uint8_t *buf, uint32_t len, uint32_t timeout_ms) { - if(num >= SOC_I2C_NUM){ - log_e("Invalid port num: %u", num); - return 0; - } - uint32_t to_queue = 0, to_fifo = 0; - i2c_slave_struct_t * i2c = &_i2c_bus_array[num]; + if (num >= SOC_I2C_NUM) { + log_e("Invalid port num: %u", num); + return 0; + } + uint32_t to_queue = 0, to_fifo = 0; + i2c_slave_struct_t *i2c = &_i2c_bus_array[num]; #if !CONFIG_DISABLE_HAL_LOCKS - if(!i2c->lock){ - log_e("Lock is not initialized! Did you call i2c_slave_init()?"); - return ESP_ERR_NO_MEM; - } + if (!i2c->lock) { + log_e("Lock is not initialized! Did you call i2c_slave_init()?"); + return ESP_ERR_NO_MEM; + } #endif - if(!i2c->tx_queue){ - return 0; - } - I2C_SLAVE_MUTEX_LOCK(); + if (!i2c->tx_queue) { + return 0; + } + I2C_SLAVE_MUTEX_LOCK(); #if CONFIG_IDF_TARGET_ESP32 - i2c_ll_slave_disable_tx_it(i2c->dev); - uint32_t txfifo_len = 0; - i2c_ll_get_txfifo_len(i2c->dev, &txfifo_len); - if (txfifo_len < SOC_I2C_FIFO_LEN) { - i2c_ll_txfifo_rst(i2c->dev); - } + i2c_ll_slave_disable_tx_it(i2c->dev); + uint32_t txfifo_len = 0; + i2c_ll_get_txfifo_len(i2c->dev, &txfifo_len); + if (txfifo_len < SOC_I2C_FIFO_LEN) { + i2c_ll_txfifo_rst(i2c->dev); + } #endif - i2c_ll_get_txfifo_len(i2c->dev, &to_fifo); - if(to_fifo){ - if(len < to_fifo){ - to_fifo = len; - } - i2c_ll_write_txfifo(i2c->dev, (uint8_t*)buf, to_fifo); - buf += to_fifo; - len -= to_fifo; - //reset tx_queue - xQueueReset(i2c->tx_queue); - //write the rest of the bytes to the queue - if(len){ - to_queue = uxQueueSpacesAvailable(i2c->tx_queue); - if(len < to_queue){ - to_queue = len; - } - for (size_t i = 0; i < to_queue; i++) { - if (xQueueSend(i2c->tx_queue, &buf[i], timeout_ms / portTICK_PERIOD_MS) != pdTRUE) { - xQueueReset(i2c->tx_queue); - to_queue = 0; - break; - } - } - //no need to enable TX_EMPTY if tx_queue is empty - if(to_queue){ - i2c_ll_slave_enable_tx_it(i2c->dev); - } + i2c_ll_get_txfifo_len(i2c->dev, &to_fifo); + if (to_fifo) { + if (len < to_fifo) { + to_fifo = len; + } + i2c_ll_write_txfifo(i2c->dev, (uint8_t *)buf, to_fifo); + buf += to_fifo; + len -= to_fifo; + //reset tx_queue + xQueueReset(i2c->tx_queue); + //write the rest of the bytes to the queue + if (len) { + to_queue = uxQueueSpacesAvailable(i2c->tx_queue); + if (len < to_queue) { + to_queue = len; + } + for (size_t i = 0; i < to_queue; i++) { + if (xQueueSend(i2c->tx_queue, &buf[i], timeout_ms / portTICK_PERIOD_MS) != pdTRUE) { + xQueueReset(i2c->tx_queue); + to_queue = 0; + break; } - } - I2C_SLAVE_MUTEX_UNLOCK(); - return to_queue + to_fifo; + } + //no need to enable TX_EMPTY if tx_queue is empty + if (to_queue) { + i2c_ll_slave_enable_tx_it(i2c->dev); + } + } + } + I2C_SLAVE_MUTEX_UNLOCK(); + return to_queue + to_fifo; } //===================================================================================================================== //-------------------------------------- Private Functions ------------------------------------------------------------ //===================================================================================================================== -static void i2c_slave_free_resources(i2c_slave_struct_t * i2c){ - i2c_slave_detach_gpio(i2c); - i2c_ll_set_slave_addr(i2c->dev, 0, false); - i2c_ll_disable_intr_mask(i2c->dev, I2C_LL_INTR_MASK); - i2c_ll_clear_intr_mask(i2c->dev, I2C_LL_INTR_MASK); +static void i2c_slave_free_resources(i2c_slave_struct_t *i2c) { + i2c_slave_detach_gpio(i2c); + i2c_ll_set_slave_addr(i2c->dev, 0, false); + i2c_ll_disable_intr_mask(i2c->dev, I2C_LL_INTR_MASK); + i2c_ll_clear_intr_mask(i2c->dev, I2C_LL_INTR_MASK); - if (i2c->intr_handle) { - esp_intr_free(i2c->intr_handle); - i2c->intr_handle = NULL; - } + if (i2c->intr_handle) { + esp_intr_free(i2c->intr_handle); + i2c->intr_handle = NULL; + } - if(i2c->task_handle){ - vTaskDelete(i2c->task_handle); - i2c->task_handle = NULL; - } + if (i2c->task_handle) { + vTaskDelete(i2c->task_handle); + i2c->task_handle = NULL; + } #if I2C_SLAVE_USE_RX_QUEUE - if (i2c->rx_queue) { - vQueueDelete(i2c->rx_queue); - i2c->rx_queue = NULL; - } + if (i2c->rx_queue) { + vQueueDelete(i2c->rx_queue); + i2c->rx_queue = NULL; + } #else - if (i2c->rx_ring_buf) { - vRingbufferDelete(i2c->rx_ring_buf); - i2c->rx_ring_buf = NULL; - } + if (i2c->rx_ring_buf) { + vRingbufferDelete(i2c->rx_ring_buf); + i2c->rx_ring_buf = NULL; + } #endif - if (i2c->tx_queue) { - vQueueDelete(i2c->tx_queue); - i2c->tx_queue = NULL; - } + if (i2c->tx_queue) { + vQueueDelete(i2c->tx_queue); + i2c->tx_queue = NULL; + } - if (i2c->event_queue) { - vQueueDelete(i2c->event_queue); - i2c->event_queue = NULL; - } + if (i2c->event_queue) { + vQueueDelete(i2c->event_queue); + i2c->event_queue = NULL; + } - i2c->rx_data_count = 0; + i2c->rx_data_count = 0; } -static bool i2c_slave_set_frequency(i2c_slave_struct_t * i2c, uint32_t clk_speed) -{ - if (i2c == NULL) { - log_e("no control buffer"); - return false; - } - if(clk_speed > 1100000UL){ - clk_speed = 1100000UL; - } +static bool i2c_slave_set_frequency(i2c_slave_struct_t *i2c, uint32_t clk_speed) { + if (i2c == NULL) { + log_e("no control buffer"); + return false; + } + if (clk_speed > 1100000UL) { + clk_speed = 1100000UL; + } - // Adjust Fifo thresholds based on frequency - uint32_t a = (clk_speed / 50000L) + 2; - log_d("Fifo thresholds: rx_fifo_full = %d, tx_fifo_empty = %d", SOC_I2C_FIFO_LEN - a, a); + // Adjust Fifo thresholds based on frequency + uint32_t a = (clk_speed / 50000L) + 2; + log_d("Fifo thresholds: rx_fifo_full = %d, tx_fifo_empty = %d", SOC_I2C_FIFO_LEN - a, a); - i2c_hal_clk_config_t clk_cal; + i2c_hal_clk_config_t clk_cal; #if SOC_I2C_SUPPORT_APB - i2c_ll_cal_bus_clk(APB_CLK_FREQ, clk_speed, &clk_cal); - i2c_ll_set_source_clk(i2c->dev, SOC_MOD_CLK_APB); /*!< I2C source clock from APB, 80M*/ + i2c_ll_cal_bus_clk(APB_CLK_FREQ, clk_speed, &clk_cal); + i2c_ll_set_source_clk(i2c->dev, SOC_MOD_CLK_APB); /*!< I2C source clock from APB, 80M*/ #elif SOC_I2C_SUPPORT_XTAL - i2c_ll_cal_bus_clk(XTAL_CLK_FREQ, clk_speed, &clk_cal); - i2c_ll_set_source_clk(i2c->dev, SOC_MOD_CLK_XTAL); /*!< I2C source clock from XTAL, 40M */ + i2c_ll_cal_bus_clk(XTAL_CLK_FREQ, clk_speed, &clk_cal); + i2c_ll_set_source_clk(i2c->dev, SOC_MOD_CLK_XTAL); /*!< I2C source clock from XTAL, 40M */ #endif - i2c_ll_set_txfifo_empty_thr(i2c->dev, a); - i2c_ll_set_rxfifo_full_thr(i2c->dev, SOC_I2C_FIFO_LEN - a); - i2c_ll_set_bus_timing(i2c->dev, &clk_cal); - i2c_ll_set_filter(i2c->dev, 3); - return true; + i2c_ll_set_txfifo_empty_thr(i2c->dev, a); + i2c_ll_set_rxfifo_full_thr(i2c->dev, SOC_I2C_FIFO_LEN - a); + i2c_ll_set_bus_timing(i2c->dev, &clk_cal); + i2c_ll_set_filter(i2c->dev, 3); + return true; } -static void i2c_slave_delay_us(uint64_t us) -{ - uint64_t m = esp_timer_get_time(); - if (us) { - uint64_t e = (m + us); - if (m > e) { //overflow - while ((uint64_t)esp_timer_get_time() > e); - } - while ((uint64_t)esp_timer_get_time() < e); - } +static void i2c_slave_delay_us(uint64_t us) { + uint64_t m = esp_timer_get_time(); + if (us) { + uint64_t e = (m + us); + if (m > e) { //overflow + while ((uint64_t)esp_timer_get_time() > e) + ; + } + while ((uint64_t)esp_timer_get_time() < e) + ; + } } -static void i2c_slave_gpio_mode(int8_t pin, gpio_mode_t mode) -{ - gpio_config_t conf = { - .pin_bit_mask = 1LL << pin, - .mode = mode, - .pull_up_en = GPIO_PULLUP_ENABLE, - .pull_down_en = GPIO_PULLDOWN_DISABLE, - .intr_type = GPIO_INTR_DISABLE - }; - gpio_config(&conf); +static void i2c_slave_gpio_mode(int8_t pin, gpio_mode_t mode) { + gpio_config_t conf = { + .pin_bit_mask = 1LL << pin, + .mode = mode, + .pull_up_en = GPIO_PULLUP_ENABLE, + .pull_down_en = GPIO_PULLDOWN_DISABLE, + .intr_type = GPIO_INTR_DISABLE + }; + gpio_config(&conf); } -static bool i2c_slave_check_line_state(int8_t sda, int8_t scl) -{ - if (sda < 0 || scl < 0) { - return false;//return false since there is nothing to do - } - // if the bus is not 'clear' try the cycling SCL until SDA goes High or 9 cycles - gpio_set_level(sda, 1); - gpio_set_level(scl, 1); - i2c_slave_gpio_mode(sda, GPIO_MODE_INPUT | GPIO_MODE_DEF_OD); - i2c_slave_gpio_mode(scl, GPIO_MODE_INPUT | GPIO_MODE_DEF_OD); - gpio_set_level(scl, 1); - - if (!gpio_get_level(sda) || !gpio_get_level(scl)) { // bus in busy state - log_w("invalid state sda(%d)=%d, scl(%d)=%d", sda, gpio_get_level(sda), scl, gpio_get_level(scl)); - for (uint8_t a=0; a<9; a++) { - i2c_slave_delay_us(5); - if (gpio_get_level(sda) && gpio_get_level(scl)) { // bus recovered - log_w("Recovered after %d Cycles",a); - gpio_set_level(sda,0); // start - i2c_slave_delay_us(5); - for (uint8_t a=0;a<9; a++) { - gpio_set_level(scl,1); - i2c_slave_delay_us(5); - gpio_set_level(scl,0); - i2c_slave_delay_us(5); - } - gpio_set_level(scl,1); - i2c_slave_delay_us(5); - gpio_set_level(sda,1); // stop - break; - } - gpio_set_level(scl, 0); - i2c_slave_delay_us(5); - gpio_set_level(scl, 1); +static bool i2c_slave_check_line_state(int8_t sda, int8_t scl) { + if (sda < 0 || scl < 0) { + return false; //return false since there is nothing to do + } + // if the bus is not 'clear' try the cycling SCL until SDA goes High or 9 cycles + gpio_set_level(sda, 1); + gpio_set_level(scl, 1); + i2c_slave_gpio_mode(sda, GPIO_MODE_INPUT | GPIO_MODE_DEF_OD); + i2c_slave_gpio_mode(scl, GPIO_MODE_INPUT | GPIO_MODE_DEF_OD); + gpio_set_level(scl, 1); + + if (!gpio_get_level(sda) || !gpio_get_level(scl)) { // bus in busy state + log_w("invalid state sda(%d)=%d, scl(%d)=%d", sda, gpio_get_level(sda), scl, gpio_get_level(scl)); + for (uint8_t a = 0; a < 9; a++) { + i2c_slave_delay_us(5); + if (gpio_get_level(sda) && gpio_get_level(scl)) { // bus recovered + log_w("Recovered after %d Cycles", a); + gpio_set_level(sda, 0); // start + i2c_slave_delay_us(5); + for (uint8_t a = 0; a < 9; a++) { + gpio_set_level(scl, 1); + i2c_slave_delay_us(5); + gpio_set_level(scl, 0); + i2c_slave_delay_us(5); } - } - - if (!gpio_get_level(sda) || !gpio_get_level(scl)) { // bus in busy state - log_e("Bus Invalid State, Can't init sda=%d, scl=%d",gpio_get_level(sda),gpio_get_level(scl)); - return false; // bus is busy - } - return true; + gpio_set_level(scl, 1); + i2c_slave_delay_us(5); + gpio_set_level(sda, 1); // stop + break; + } + gpio_set_level(scl, 0); + i2c_slave_delay_us(5); + gpio_set_level(scl, 1); + } + } + + if (!gpio_get_level(sda) || !gpio_get_level(scl)) { // bus in busy state + log_e("Bus Invalid State, Can't init sda=%d, scl=%d", gpio_get_level(sda), gpio_get_level(scl)); + return false; // bus is busy + } + return true; } -static bool i2c_slave_attach_gpio(i2c_slave_struct_t * i2c, int8_t sda, int8_t scl) -{ - if (i2c == NULL) { - log_e("no control block"); - return false; - } - - if ((sda < 0)||( scl < 0)) { - log_e("bad pins sda=%d, scl=%d",sda,scl); - return false; - } - - i2c->scl = scl; - gpio_set_level(scl, 1); - i2c_slave_gpio_mode(scl, GPIO_MODE_INPUT_OUTPUT_OD); - gpio_matrix_out(scl, I2C_SCL_IDX(i2c->num), false, false); - gpio_matrix_in(scl, I2C_SCL_IDX(i2c->num), false); - - i2c->sda = sda; - gpio_set_level(sda, 1); - i2c_slave_gpio_mode(sda, GPIO_MODE_INPUT_OUTPUT_OD); - gpio_matrix_out(sda, I2C_SDA_IDX(i2c->num), false, false); - gpio_matrix_in(sda, I2C_SDA_IDX(i2c->num), false); - - return true; +static bool i2c_slave_attach_gpio(i2c_slave_struct_t *i2c, int8_t sda, int8_t scl) { + if (i2c == NULL) { + log_e("no control block"); + return false; + } + + if ((sda < 0) || (scl < 0)) { + log_e("bad pins sda=%d, scl=%d", sda, scl); + return false; + } + + i2c->scl = scl; + gpio_set_level(scl, 1); + i2c_slave_gpio_mode(scl, GPIO_MODE_INPUT_OUTPUT_OD); + gpio_matrix_out(scl, I2C_SCL_IDX(i2c->num), false, false); + gpio_matrix_in(scl, I2C_SCL_IDX(i2c->num), false); + + i2c->sda = sda; + gpio_set_level(sda, 1); + i2c_slave_gpio_mode(sda, GPIO_MODE_INPUT_OUTPUT_OD); + gpio_matrix_out(sda, I2C_SDA_IDX(i2c->num), false, false); + gpio_matrix_in(sda, I2C_SDA_IDX(i2c->num), false); + + return true; } -static bool i2c_slave_detach_gpio(i2c_slave_struct_t * i2c) -{ - if (i2c == NULL) { - log_e("no control Block"); - return false; - } - if (i2c->scl >= 0) { - gpio_matrix_out(i2c->scl, 0x100, false, false); - gpio_matrix_in(0x30, I2C_SCL_IDX(i2c->num), false); - i2c_slave_gpio_mode(i2c->scl, GPIO_MODE_INPUT); - i2c->scl = -1; // un attached - } - if (i2c->sda >= 0) { - gpio_matrix_out(i2c->sda, 0x100, false, false); - gpio_matrix_in(0x30, I2C_SDA_IDX(i2c->num), false); - i2c_slave_gpio_mode(i2c->sda, GPIO_MODE_INPUT); - i2c->sda = -1; // un attached - } - return true; +static bool i2c_slave_detach_gpio(i2c_slave_struct_t *i2c) { + if (i2c == NULL) { + log_e("no control Block"); + return false; + } + if (i2c->scl >= 0) { + gpio_matrix_out(i2c->scl, 0x100, false, false); + gpio_matrix_in(0x30, I2C_SCL_IDX(i2c->num), false); + i2c_slave_gpio_mode(i2c->scl, GPIO_MODE_INPUT); + i2c->scl = -1; // un attached + } + if (i2c->sda >= 0) { + gpio_matrix_out(i2c->sda, 0x100, false, false); + gpio_matrix_in(0x30, I2C_SDA_IDX(i2c->num), false); + i2c_slave_gpio_mode(i2c->sda, GPIO_MODE_INPUT); + i2c->sda = -1; // un attached + } + return true; } -static bool i2c_slave_send_event(i2c_slave_struct_t * i2c, i2c_slave_queue_event_t* event) -{ - bool pxHigherPriorityTaskWoken = false; - if(i2c->event_queue) { - if(xQueueSendFromISR(i2c->event_queue, event, (BaseType_t * const)&pxHigherPriorityTaskWoken) != pdTRUE){ - //log_e("event_queue_full"); - } +static bool i2c_slave_send_event(i2c_slave_struct_t *i2c, i2c_slave_queue_event_t *event) { + bool pxHigherPriorityTaskWoken = false; + if (i2c->event_queue) { + if (xQueueSendFromISR(i2c->event_queue, event, (BaseType_t *const)&pxHigherPriorityTaskWoken) != pdTRUE) { + //log_e("event_queue_full"); } - return pxHigherPriorityTaskWoken; + } + return pxHigherPriorityTaskWoken; } -static bool i2c_slave_handle_tx_fifo_empty(i2c_slave_struct_t * i2c) -{ - bool pxHigherPriorityTaskWoken = false; - uint32_t d = 0, moveCnt = 0; - i2c_ll_get_txfifo_len(i2c->dev, &moveCnt); - while (moveCnt > 0) { // read tx queue until Fifo is full or queue is empty - if(xQueueReceiveFromISR(i2c->tx_queue, &d, (BaseType_t * const)&pxHigherPriorityTaskWoken) == pdTRUE){ - i2c_ll_write_txfifo(i2c->dev, (uint8_t*)&d, 1); - moveCnt--; - } else { - i2c_ll_slave_disable_tx_it(i2c->dev); - break; - } +static bool i2c_slave_handle_tx_fifo_empty(i2c_slave_struct_t *i2c) { + bool pxHigherPriorityTaskWoken = false; + uint32_t d = 0, moveCnt = 0; + i2c_ll_get_txfifo_len(i2c->dev, &moveCnt); + while (moveCnt > 0) { // read tx queue until Fifo is full or queue is empty + if (xQueueReceiveFromISR(i2c->tx_queue, &d, (BaseType_t *const)&pxHigherPriorityTaskWoken) == pdTRUE) { + i2c_ll_write_txfifo(i2c->dev, (uint8_t *)&d, 1); + moveCnt--; + } else { + i2c_ll_slave_disable_tx_it(i2c->dev); + break; } - return pxHigherPriorityTaskWoken; + } + return pxHigherPriorityTaskWoken; } -static bool i2c_slave_handle_rx_fifo_full(i2c_slave_struct_t * i2c, uint32_t len) -{ +static bool i2c_slave_handle_rx_fifo_full(i2c_slave_struct_t *i2c, uint32_t len) { #if I2C_SLAVE_USE_RX_QUEUE - uint32_t d = 0; + uint32_t d = 0; #else - uint8_t data[SOC_I2C_FIFO_LEN]; + uint8_t data[SOC_I2C_FIFO_LEN]; #endif - bool pxHigherPriorityTaskWoken = false; + bool pxHigherPriorityTaskWoken = false; #if I2C_SLAVE_USE_RX_QUEUE - while (len > 0) { - i2c_ll_read_rxfifo(i2c->dev, (uint8_t*)&d, 1); - if(xQueueSendFromISR(i2c->rx_queue, &d, (BaseType_t * const)&pxHigherPriorityTaskWoken) != pdTRUE){ - log_e("rx_queue_full"); - } else { - i2c->rx_data_count++; - } - if (--len == 0) { - len = i2c_ll_get_rxfifo_cnt(i2c->dev); - } + while (len > 0) { + i2c_ll_read_rxfifo(i2c->dev, (uint8_t *)&d, 1); + if (xQueueSendFromISR(i2c->rx_queue, &d, (BaseType_t *const)&pxHigherPriorityTaskWoken) != pdTRUE) { + log_e("rx_queue_full"); + } else { + i2c->rx_data_count++; + } + if (--len == 0) { + len = i2c_ll_get_rxfifo_cnt(i2c->dev); + } #else - if(len){ - i2c_ll_read_rxfifo(i2c->dev, data, len); - if(xRingbufferSendFromISR(i2c->rx_ring_buf, (void*) data, len, (BaseType_t * const)&pxHigherPriorityTaskWoken) != pdTRUE){ - log_e("rx_ring_buf_full"); - } else { - i2c->rx_data_count += len; - } -#endif + if (len) { + i2c_ll_read_rxfifo(i2c->dev, data, len); + if (xRingbufferSendFromISR(i2c->rx_ring_buf, (void *)data, len, (BaseType_t *const)&pxHigherPriorityTaskWoken) != pdTRUE) { + log_e("rx_ring_buf_full"); + } else { + i2c->rx_data_count += len; } - return pxHigherPriorityTaskWoken; +#endif + } + return pxHigherPriorityTaskWoken; } -static void i2c_slave_isr_handler(void* arg) -{ - bool pxHigherPriorityTaskWoken = false; - i2c_slave_struct_t * i2c = (i2c_slave_struct_t *) arg; // recover data - - uint32_t activeInt = 0; - i2c_ll_get_intr_mask(i2c->dev, &activeInt); - i2c_ll_clear_intr_mask(i2c->dev, activeInt); - uint32_t rx_fifo_len = 0; - i2c_ll_get_rxfifo_cnt(i2c->dev, &rx_fifo_len); - bool slave_rw = i2c_ll_slave_rw(i2c->dev); - - if(activeInt & I2C_RXFIFO_WM_INT_ENA){ // RX FiFo Full - pxHigherPriorityTaskWoken |= i2c_slave_handle_rx_fifo_full(i2c, rx_fifo_len); - i2c_ll_slave_enable_rx_it(i2c->dev);//is this necessary? - } - - if(activeInt & I2C_TRANS_COMPLETE_INT_ENA){ // STOP - if(rx_fifo_len){ //READ RX FIFO - pxHigherPriorityTaskWoken |= i2c_slave_handle_rx_fifo_full(i2c, rx_fifo_len); - } - if(i2c->rx_data_count){ //WRITE or RepeatedStart - //SEND RX Event - i2c_slave_queue_event_t event; - event.event = I2C_SLAVE_EVT_RX; - event.stop = !slave_rw; - event.param = i2c->rx_data_count; - pxHigherPriorityTaskWoken |= i2c_slave_send_event(i2c, &event); - //Zero RX count - i2c->rx_data_count = 0; - } - if(slave_rw){ // READ +static void i2c_slave_isr_handler(void *arg) { + bool pxHigherPriorityTaskWoken = false; + i2c_slave_struct_t *i2c = (i2c_slave_struct_t *)arg; // recover data + + uint32_t activeInt = 0; + i2c_ll_get_intr_mask(i2c->dev, &activeInt); + i2c_ll_clear_intr_mask(i2c->dev, activeInt); + uint32_t rx_fifo_len = 0; + i2c_ll_get_rxfifo_cnt(i2c->dev, &rx_fifo_len); + bool slave_rw = i2c_ll_slave_rw(i2c->dev); + + if (activeInt & I2C_RXFIFO_WM_INT_ENA) { // RX FiFo Full + pxHigherPriorityTaskWoken |= i2c_slave_handle_rx_fifo_full(i2c, rx_fifo_len); + i2c_ll_slave_enable_rx_it(i2c->dev); //is this necessary? + } + + if (activeInt & I2C_TRANS_COMPLETE_INT_ENA) { // STOP + if (rx_fifo_len) { //READ RX FIFO + pxHigherPriorityTaskWoken |= i2c_slave_handle_rx_fifo_full(i2c, rx_fifo_len); + } + if (i2c->rx_data_count) { //WRITE or RepeatedStart + //SEND RX Event + i2c_slave_queue_event_t event; + event.event = I2C_SLAVE_EVT_RX; + event.stop = !slave_rw; + event.param = i2c->rx_data_count; + pxHigherPriorityTaskWoken |= i2c_slave_send_event(i2c, &event); + //Zero RX count + i2c->rx_data_count = 0; + } + if (slave_rw) { // READ #if CONFIG_IDF_TARGET_ESP32 - if(i2c->dev->status_reg.scl_main_state_last == 6){ - //SEND TX Event - i2c_slave_queue_event_t event; - event.event = I2C_SLAVE_EVT_TX; - pxHigherPriorityTaskWoken |= i2c_slave_send_event(i2c, &event); - } + if (i2c->dev->status_reg.scl_main_state_last == 6) { + //SEND TX Event + i2c_slave_queue_event_t event; + event.event = I2C_SLAVE_EVT_TX; + pxHigherPriorityTaskWoken |= i2c_slave_send_event(i2c, &event); + } #else - //reset TX data - i2c_ll_txfifo_rst(i2c->dev); - uint8_t d; - while (xQueueReceiveFromISR(i2c->tx_queue, &d, (BaseType_t * const)&pxHigherPriorityTaskWoken) == pdTRUE) ;//flush partial write + //reset TX data + i2c_ll_txfifo_rst(i2c->dev); + uint8_t d; + while (xQueueReceiveFromISR(i2c->tx_queue, &d, (BaseType_t *const)&pxHigherPriorityTaskWoken) == pdTRUE) + ; //flush partial write #endif - } } + } #ifndef CONFIG_IDF_TARGET_ESP32 - if(activeInt & I2C_SLAVE_STRETCH_INT_ENA){ // STRETCH - i2c_stretch_cause_t cause = i2c_ll_stretch_cause(i2c->dev); - if(cause == I2C_STRETCH_CAUSE_MASTER_READ){ - //on C3 RX data dissapears with repeated start, so we need to get it here - if(rx_fifo_len){ - pxHigherPriorityTaskWoken |= i2c_slave_handle_rx_fifo_full(i2c, rx_fifo_len); - } - //SEND TX Event - i2c_slave_queue_event_t event; - event.event = I2C_SLAVE_EVT_TX; - pxHigherPriorityTaskWoken |= i2c_slave_send_event(i2c, &event); - //will clear after execution - } else if(cause == I2C_STRETCH_CAUSE_TX_FIFO_EMPTY){ - pxHigherPriorityTaskWoken |= i2c_slave_handle_tx_fifo_empty(i2c); - i2c_ll_stretch_clr(i2c->dev); - } else if(cause == I2C_STRETCH_CAUSE_RX_FIFO_FULL){ - pxHigherPriorityTaskWoken |= i2c_slave_handle_rx_fifo_full(i2c, rx_fifo_len); - i2c_ll_stretch_clr(i2c->dev); - } - } + if (activeInt & I2C_SLAVE_STRETCH_INT_ENA) { // STRETCH + i2c_stretch_cause_t cause = i2c_ll_stretch_cause(i2c->dev); + if (cause == I2C_STRETCH_CAUSE_MASTER_READ) { + //on C3 RX data disappears with repeated start, so we need to get it here + if (rx_fifo_len) { + pxHigherPriorityTaskWoken |= i2c_slave_handle_rx_fifo_full(i2c, rx_fifo_len); + } + //SEND TX Event + i2c_slave_queue_event_t event; + event.event = I2C_SLAVE_EVT_TX; + pxHigherPriorityTaskWoken |= i2c_slave_send_event(i2c, &event); + //will clear after execution + } else if (cause == I2C_STRETCH_CAUSE_TX_FIFO_EMPTY) { + pxHigherPriorityTaskWoken |= i2c_slave_handle_tx_fifo_empty(i2c); + i2c_ll_stretch_clr(i2c->dev); + } else if (cause == I2C_STRETCH_CAUSE_RX_FIFO_FULL) { + pxHigherPriorityTaskWoken |= i2c_slave_handle_rx_fifo_full(i2c, rx_fifo_len); + i2c_ll_stretch_clr(i2c->dev); + } + } #endif - if(activeInt & I2C_TXFIFO_WM_INT_ENA){ // TX FiFo Empty - pxHigherPriorityTaskWoken |= i2c_slave_handle_tx_fifo_empty(i2c); - } + if (activeInt & I2C_TXFIFO_WM_INT_ENA) { // TX FiFo Empty + pxHigherPriorityTaskWoken |= i2c_slave_handle_tx_fifo_empty(i2c); + } - if(pxHigherPriorityTaskWoken){ - portYIELD_FROM_ISR(); - } + if (pxHigherPriorityTaskWoken) { + portYIELD_FROM_ISR(); + } } -static size_t i2c_slave_read_rx(i2c_slave_struct_t * i2c, uint8_t * data, size_t len){ - if(!len){ - return 0; - } +static size_t i2c_slave_read_rx(i2c_slave_struct_t *i2c, uint8_t *data, size_t len) { + if (!len) { + return 0; + } #if I2C_SLAVE_USE_RX_QUEUE - uint8_t d = 0; - BaseType_t res = pdTRUE; - for(size_t i=0; irx_queue, &data[i], 0); - } else { - res = xQueueReceive(i2c->rx_queue, &d, 0); - } - if (res != pdTRUE) { - log_e("Read Queue(%u) Failed", i); - len = i; - break; - } + uint8_t d = 0; + BaseType_t res = pdTRUE; + for (size_t i = 0; i < len; i++) { + if (data) { + res = xQueueReceive(i2c->rx_queue, &data[i], 0); + } else { + res = xQueueReceive(i2c->rx_queue, &d, 0); } - return (data)?len:0; -#else - size_t dlen = 0, - to_read = len, - so_far = 0, - available = 0; - uint8_t * rx_data = NULL; - - vRingbufferGetInfo(i2c->rx_ring_buf, NULL, NULL, NULL, NULL, &available); - if(available < to_read){ - log_e("Less available than requested. %u < %u", available, len); - to_read = available; + if (res != pdTRUE) { + log_e("Read Queue(%u) Failed", i); + len = i; + break; } + } + return (data) ? len : 0; +#else + size_t dlen = 0, + to_read = len, + so_far = 0, + available = 0; + uint8_t *rx_data = NULL; + + vRingbufferGetInfo(i2c->rx_ring_buf, NULL, NULL, NULL, NULL, &available); + if (available < to_read) { + log_e("Less available than requested. %u < %u", available, len); + to_read = available; + } + + while (to_read) { + dlen = 0; + rx_data = (uint8_t *)xRingbufferReceiveUpTo(i2c->rx_ring_buf, &dlen, 0, to_read); + if (!rx_data) { + log_e("Receive %u Failed", to_read); + return so_far; + } + if (data) { + memcpy(data + so_far, rx_data, dlen); + } + vRingbufferReturnItem(i2c->rx_ring_buf, rx_data); + so_far += dlen; + to_read -= dlen; + } + return (data) ? so_far : 0; +#endif +} - while(to_read){ - dlen = 0; - rx_data = (uint8_t *)xRingbufferReceiveUpTo(i2c->rx_ring_buf, &dlen, 0, to_read); - if(!rx_data){ - log_e("Receive %u Failed", to_read); - return so_far; +static void i2c_slave_task(void *pv_args) { + i2c_slave_struct_t *i2c = (i2c_slave_struct_t *)pv_args; + i2c_slave_queue_event_t event; + size_t len = 0; + bool stop = false; + uint8_t *data = NULL; + for (;;) { + if (xQueueReceive(i2c->event_queue, &event, portMAX_DELAY) == pdTRUE) { + // Write + if (event.event == I2C_SLAVE_EVT_RX) { + len = event.param; + stop = event.stop; + data = (len > 0) ? (uint8_t *)malloc(len) : NULL; + + if (len && data == NULL) { + log_e("Malloc (%u) Failed", len); } - if(data){ - memcpy(data+so_far, rx_data, dlen); + len = i2c_slave_read_rx(i2c, data, len); + if (i2c->receive_callback) { + i2c->receive_callback(i2c->num, data, len, stop, i2c->arg); } - vRingbufferReturnItem(i2c->rx_ring_buf, rx_data); - so_far+=dlen; - to_read-=dlen; - } - return (data)?so_far:0; -#endif -} + free(data); -static void i2c_slave_task(void *pv_args) -{ - i2c_slave_struct_t * i2c = (i2c_slave_struct_t *)pv_args; - i2c_slave_queue_event_t event; - size_t len = 0; - bool stop = false; - uint8_t * data = NULL; - for(;;){ - if(xQueueReceive(i2c->event_queue, &event, portMAX_DELAY) == pdTRUE){ - // Write - if(event.event == I2C_SLAVE_EVT_RX){ - len = event.param; - stop = event.stop; - data = (len > 0)?(uint8_t*)malloc(len):NULL; - - if(len && data == NULL){ - log_e("Malloc (%u) Failed", len); - } - len = i2c_slave_read_rx(i2c, data, len); - if(i2c->receive_callback){ - i2c->receive_callback(i2c->num, data, len, stop, i2c->arg); - } - free(data); - - // Read - } else if(event.event == I2C_SLAVE_EVT_TX){ - if(i2c->request_callback){ - i2c->request_callback(i2c->num, i2c->arg); - } - i2c_ll_stretch_clr(i2c->dev); - } + // Read + } else if (event.event == I2C_SLAVE_EVT_TX) { + if (i2c->request_callback) { + i2c->request_callback(i2c->num, i2c->arg); } + i2c_ll_stretch_clr(i2c->dev); + } } - vTaskDelete(NULL); + } + vTaskDelete(NULL); } -static bool i2cSlaveDetachBus(void * bus_i2c_num){ - uint8_t num = (int)bus_i2c_num - 1; - i2c_slave_struct_t * i2c = &_i2c_bus_array[num]; - if (i2c->scl == -1 && i2c->sda == -1) { - return true; - } - esp_err_t err = i2cSlaveDeinit(num); - if(err != ESP_OK){ - log_e("i2cSlaveDeinit failed with error: %d", err); - return false; - } +static bool i2cSlaveDetachBus(void *bus_i2c_num) { + uint8_t num = (int)bus_i2c_num - 1; + i2c_slave_struct_t *i2c = &_i2c_bus_array[num]; + if (i2c->scl == -1 && i2c->sda == -1) { return true; + } + esp_err_t err = i2cSlaveDeinit(num); + if (err != ESP_OK) { + log_e("i2cSlaveDeinit failed with error: %d", err); + return false; + } + return true; } #endif /* SOC_I2C_SUPPORT_SLAVE */ diff --git a/cores/esp32/esp32-hal-i2c-slave.h b/cores/esp32/esp32-hal-i2c-slave.h index bc6893003c1..41e157ac916 100644 --- a/cores/esp32/esp32-hal-i2c-slave.h +++ b/cores/esp32/esp32-hal-i2c-slave.h @@ -25,13 +25,13 @@ extern "C" { #include "stddef.h" #include "esp_err.h" -typedef void (*i2c_slave_request_cb_t) (uint8_t num, void * arg); -typedef void (*i2c_slave_receive_cb_t) (uint8_t num, uint8_t * data, size_t len, bool stop, void * arg); -esp_err_t i2cSlaveAttachCallbacks(uint8_t num, i2c_slave_request_cb_t request_callback, i2c_slave_receive_cb_t receive_callback, void * arg); + typedef void (*i2c_slave_request_cb_t)(uint8_t num, void *arg); + typedef void (*i2c_slave_receive_cb_t)(uint8_t num, uint8_t *data, size_t len, bool stop, void *arg); + esp_err_t i2cSlaveAttachCallbacks(uint8_t num, i2c_slave_request_cb_t request_callback, i2c_slave_receive_cb_t receive_callback, void *arg); -esp_err_t i2cSlaveInit(uint8_t num, int sda, int scl, uint16_t slaveID, uint32_t frequency, size_t rx_len, size_t tx_len); -esp_err_t i2cSlaveDeinit(uint8_t num); -size_t i2cSlaveWrite(uint8_t num, const uint8_t *buf, uint32_t len, uint32_t timeout_ms); + esp_err_t i2cSlaveInit(uint8_t num, int sda, int scl, uint16_t slaveID, uint32_t frequency, size_t rx_len, size_t tx_len); + esp_err_t i2cSlaveDeinit(uint8_t num); + size_t i2cSlaveWrite(uint8_t num, const uint8_t *buf, uint32_t len, uint32_t timeout_ms); #ifdef __cplusplus } diff --git a/cores/esp32/esp32-hal-i2c.c b/cores/esp32/esp32-hal-i2c.c index b76fa963e81..32640242528 100644 --- a/cores/esp32/esp32-hal-i2c.c +++ b/cores/esp32/esp32-hal-i2c.c @@ -38,369 +38,369 @@ #endif typedef volatile struct { - bool initialized; - uint32_t frequency; + bool initialized; + uint32_t frequency; #if !CONFIG_DISABLE_HAL_LOCKS - SemaphoreHandle_t lock; + SemaphoreHandle_t lock; #endif - int8_t scl; - int8_t sda; + int8_t scl; + int8_t sda; } i2c_bus_t; static i2c_bus_t bus[SOC_I2C_NUM]; -static bool i2cDetachBus(void * bus_i2c_num){ - uint8_t i2c_num = (int)bus_i2c_num - 1; - if(!bus[i2c_num].initialized){ - return true; - } - esp_err_t err = i2cDeinit(i2c_num); - if(err != ESP_OK){ - log_e("i2cDeinit failed with error: %d", err); - return false; - } +static bool i2cDetachBus(void *bus_i2c_num) { + uint8_t i2c_num = (int)bus_i2c_num - 1; + if (!bus[i2c_num].initialized) { return true; + } + esp_err_t err = i2cDeinit(i2c_num); + if (err != ESP_OK) { + log_e("i2cDeinit failed with error: %d", err); + return false; + } + return true; } -bool i2cIsInit(uint8_t i2c_num){ - if(i2c_num >= SOC_I2C_NUM){ - return false; - } - return bus[i2c_num].initialized; +bool i2cIsInit(uint8_t i2c_num) { + if (i2c_num >= SOC_I2C_NUM) { + return false; + } + return bus[i2c_num].initialized; } -esp_err_t i2cInit(uint8_t i2c_num, int8_t sda, int8_t scl, uint32_t frequency){ - if(i2c_num >= SOC_I2C_NUM){ - return ESP_ERR_INVALID_ARG; - } +esp_err_t i2cInit(uint8_t i2c_num, int8_t sda, int8_t scl, uint32_t frequency) { + if (i2c_num >= SOC_I2C_NUM) { + return ESP_ERR_INVALID_ARG; + } #if !CONFIG_DISABLE_HAL_LOCKS - if(bus[i2c_num].lock == NULL){ - bus[i2c_num].lock = xSemaphoreCreateMutex(); - if(bus[i2c_num].lock == NULL){ - log_e("xSemaphoreCreateMutex failed"); - return ESP_ERR_NO_MEM; - } - } - //acquire lock - if(xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE){ - log_e("could not acquire lock"); - return ESP_FAIL; - } + if (bus[i2c_num].lock == NULL) { + bus[i2c_num].lock = xSemaphoreCreateMutex(); + if (bus[i2c_num].lock == NULL) { + log_e("xSemaphoreCreateMutex failed"); + return ESP_ERR_NO_MEM; + } + } + //acquire lock + if (xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE) { + log_e("could not acquire lock"); + return ESP_FAIL; + } #endif - if(bus[i2c_num].initialized){ - log_e("bus is already initialized"); - return ESP_FAIL; - } + if (bus[i2c_num].initialized) { + log_e("bus is already initialized"); + return ESP_FAIL; + } - if(!frequency){ - frequency = 100000UL; - } else if(frequency > 1000000UL){ - frequency = 1000000UL; - } + if (!frequency) { + frequency = 100000UL; + } else if (frequency > 1000000UL) { + frequency = 1000000UL; + } - perimanSetBusDeinit(ESP32_BUS_TYPE_I2C_MASTER_SDA, i2cDetachBus); - perimanSetBusDeinit(ESP32_BUS_TYPE_I2C_MASTER_SCL, i2cDetachBus); + perimanSetBusDeinit(ESP32_BUS_TYPE_I2C_MASTER_SDA, i2cDetachBus); + perimanSetBusDeinit(ESP32_BUS_TYPE_I2C_MASTER_SCL, i2cDetachBus); - if(!perimanClearPinBus(sda) || !perimanClearPinBus(scl)){ - return false; - } + if (!perimanClearPinBus(sda) || !perimanClearPinBus(scl)) { + return false; + } - log_i("Initialising I2C Master: sda=%d scl=%d freq=%d", sda, scl, frequency); + log_i("Initializing I2C Master: sda=%d scl=%d freq=%d", sda, scl, frequency); - i2c_config_t conf = { }; - conf.mode = I2C_MODE_MASTER; - conf.scl_io_num = (gpio_num_t)scl; - conf.sda_io_num = (gpio_num_t)sda; - conf.scl_pullup_en = GPIO_PULLUP_ENABLE; - conf.sda_pullup_en = GPIO_PULLUP_ENABLE; - conf.master.clk_speed = frequency; - conf.clk_flags = I2C_SCLK_SRC_FLAG_FOR_NOMAL; //Any one clock source that is available for the specified frequency may be choosen + i2c_config_t conf = {}; + conf.mode = I2C_MODE_MASTER; + conf.scl_io_num = (gpio_num_t)scl; + conf.sda_io_num = (gpio_num_t)sda; + conf.scl_pullup_en = GPIO_PULLUP_ENABLE; + conf.sda_pullup_en = GPIO_PULLUP_ENABLE; + conf.master.clk_speed = frequency; + conf.clk_flags = I2C_SCLK_SRC_FLAG_FOR_NOMAL; //Any one clock source that is available for the specified frequency may be chosen - esp_err_t ret = i2c_param_config((i2c_port_t)i2c_num, &conf); + esp_err_t ret = i2c_param_config((i2c_port_t)i2c_num, &conf); + if (ret != ESP_OK) { + log_e("i2c_param_config failed"); + } else { + ret = i2c_driver_install((i2c_port_t)i2c_num, conf.mode, 0, 0, 0); if (ret != ESP_OK) { - log_e("i2c_param_config failed"); + log_e("i2c_driver_install failed"); } else { - ret = i2c_driver_install((i2c_port_t)i2c_num, conf.mode, 0, 0, 0); - if (ret != ESP_OK) { - log_e("i2c_driver_install failed"); - } else { - bus[i2c_num].initialized = true; - bus[i2c_num].frequency = frequency; - bus[i2c_num].scl = scl; - bus[i2c_num].sda = sda; - //Clock Stretching Timeout: 20b:esp32, 5b:esp32-c3, 24b:esp32-s2 - i2c_set_timeout((i2c_port_t)i2c_num, I2C_LL_MAX_TIMEOUT); - if(!perimanSetPinBus(sda, ESP32_BUS_TYPE_I2C_MASTER_SDA, (void *)(i2c_num+1), i2c_num, -1) || !perimanSetPinBus(scl, ESP32_BUS_TYPE_I2C_MASTER_SCL, (void *)(i2c_num+1), i2c_num, -1)){ - i2cDetachBus((void *)(i2c_num+1)); - return false; - } - } + bus[i2c_num].initialized = true; + bus[i2c_num].frequency = frequency; + bus[i2c_num].scl = scl; + bus[i2c_num].sda = sda; + //Clock Stretching Timeout: 20b:esp32, 5b:esp32-c3, 24b:esp32-s2 + i2c_set_timeout((i2c_port_t)i2c_num, I2C_LL_MAX_TIMEOUT); + if (!perimanSetPinBus(sda, ESP32_BUS_TYPE_I2C_MASTER_SDA, (void *)(i2c_num + 1), i2c_num, -1) || !perimanSetPinBus(scl, ESP32_BUS_TYPE_I2C_MASTER_SCL, (void *)(i2c_num + 1), i2c_num, -1)) { + i2cDetachBus((void *)(i2c_num + 1)); + return false; + } } + } #if !CONFIG_DISABLE_HAL_LOCKS - //release lock - xSemaphoreGive(bus[i2c_num].lock); + //release lock + xSemaphoreGive(bus[i2c_num].lock); #endif - return ret; + return ret; } -esp_err_t i2cDeinit(uint8_t i2c_num){ - esp_err_t err = ESP_FAIL; - if(i2c_num >= SOC_I2C_NUM){ - return ESP_ERR_INVALID_ARG; - } +esp_err_t i2cDeinit(uint8_t i2c_num) { + esp_err_t err = ESP_FAIL; + if (i2c_num >= SOC_I2C_NUM) { + return ESP_ERR_INVALID_ARG; + } #if !CONFIG_DISABLE_HAL_LOCKS - //acquire lock - if(bus[i2c_num].lock == NULL || xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE){ - log_e("could not acquire lock"); - return err; - } + //acquire lock + if (bus[i2c_num].lock == NULL || xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE) { + log_e("could not acquire lock"); + return err; + } #endif - if(!bus[i2c_num].initialized){ - log_e("bus is not initialized"); - } else { - err = i2c_driver_delete((i2c_port_t)i2c_num); - if(err == ESP_OK){ - bus[i2c_num].initialized = false; - perimanClearPinBus(bus[i2c_num].scl); - perimanClearPinBus(bus[i2c_num].sda); - bus[i2c_num].scl = -1; - bus[i2c_num].sda = -1; - } - } + if (!bus[i2c_num].initialized) { + log_e("bus is not initialized"); + } else { + err = i2c_driver_delete((i2c_port_t)i2c_num); + if (err == ESP_OK) { + bus[i2c_num].initialized = false; + perimanClearPinBus(bus[i2c_num].scl); + perimanClearPinBus(bus[i2c_num].sda); + bus[i2c_num].scl = -1; + bus[i2c_num].sda = -1; + } + } #if !CONFIG_DISABLE_HAL_LOCKS - //release lock - xSemaphoreGive(bus[i2c_num].lock); + //release lock + xSemaphoreGive(bus[i2c_num].lock); #endif - return err; + return err; } -esp_err_t i2cWrite(uint8_t i2c_num, uint16_t address, const uint8_t* buff, size_t size, uint32_t timeOutMillis){ - esp_err_t ret = ESP_FAIL; - i2c_cmd_handle_t cmd = NULL; - if(i2c_num >= SOC_I2C_NUM){ - return ESP_ERR_INVALID_ARG; - } +esp_err_t i2cWrite(uint8_t i2c_num, uint16_t address, const uint8_t *buff, size_t size, uint32_t timeOutMillis) { + esp_err_t ret = ESP_FAIL; + i2c_cmd_handle_t cmd = NULL; + if (i2c_num >= SOC_I2C_NUM) { + return ESP_ERR_INVALID_ARG; + } #if !CONFIG_DISABLE_HAL_LOCKS - //acquire lock - if(bus[i2c_num].lock == NULL || xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE){ - log_e("could not acquire lock"); - return ret; - } + //acquire lock + if (bus[i2c_num].lock == NULL || xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE) { + log_e("could not acquire lock"); + return ret; + } #endif - if(!bus[i2c_num].initialized){ - log_e("bus is not initialized"); - goto end; - } - - //short implementation does not support zero size writes (example when scanning) PR in IDF? - //ret = i2c_master_write_to_device((i2c_port_t)i2c_num, address, buff, size, timeOutMillis / portTICK_PERIOD_MS); + if (!bus[i2c_num].initialized) { + log_e("bus is not initialized"); + goto end; + } - ret = ESP_OK; - uint8_t cmd_buff[I2C_LINK_RECOMMENDED_SIZE(1)] = { 0 }; - cmd = i2c_cmd_link_create_static(cmd_buff, I2C_LINK_RECOMMENDED_SIZE(1)); - ret = i2c_master_start(cmd); - if (ret != ESP_OK) { - goto end; - } - ret = i2c_master_write_byte(cmd, (address << 1) | I2C_MASTER_WRITE, true); - if (ret != ESP_OK) { - goto end; - } - if(size){ - ret = i2c_master_write(cmd, buff, size, true); - if (ret != ESP_OK) { - goto end; - } - } - ret = i2c_master_stop(cmd); + //short implementation does not support zero size writes (example when scanning) PR in IDF? + //ret = i2c_master_write_to_device((i2c_port_t)i2c_num, address, buff, size, timeOutMillis / portTICK_PERIOD_MS); + + ret = ESP_OK; + uint8_t cmd_buff[I2C_LINK_RECOMMENDED_SIZE(1)] = { 0 }; + cmd = i2c_cmd_link_create_static(cmd_buff, I2C_LINK_RECOMMENDED_SIZE(1)); + ret = i2c_master_start(cmd); + if (ret != ESP_OK) { + goto end; + } + ret = i2c_master_write_byte(cmd, (address << 1) | I2C_MASTER_WRITE, true); + if (ret != ESP_OK) { + goto end; + } + if (size) { + ret = i2c_master_write(cmd, buff, size, true); if (ret != ESP_OK) { - goto end; - } - ret = i2c_master_cmd_begin((i2c_port_t)i2c_num, cmd, timeOutMillis / portTICK_PERIOD_MS); + goto end; + } + } + ret = i2c_master_stop(cmd); + if (ret != ESP_OK) { + goto end; + } + ret = i2c_master_cmd_begin((i2c_port_t)i2c_num, cmd, timeOutMillis / portTICK_PERIOD_MS); end: - if(cmd != NULL){ - i2c_cmd_link_delete_static(cmd); - } + if (cmd != NULL) { + i2c_cmd_link_delete_static(cmd); + } #if !CONFIG_DISABLE_HAL_LOCKS - //release lock - xSemaphoreGive(bus[i2c_num].lock); + //release lock + xSemaphoreGive(bus[i2c_num].lock); #endif - return ret; + return ret; } -esp_err_t i2cRead(uint8_t i2c_num, uint16_t address, uint8_t* buff, size_t size, uint32_t timeOutMillis, size_t *readCount){ - esp_err_t ret = ESP_FAIL; - if(i2c_num >= SOC_I2C_NUM){ - return ESP_ERR_INVALID_ARG; - } +esp_err_t i2cRead(uint8_t i2c_num, uint16_t address, uint8_t *buff, size_t size, uint32_t timeOutMillis, size_t *readCount) { + esp_err_t ret = ESP_FAIL; + if (i2c_num >= SOC_I2C_NUM) { + return ESP_ERR_INVALID_ARG; + } #if !CONFIG_DISABLE_HAL_LOCKS - //acquire lock - if(bus[i2c_num].lock == NULL || xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE){ - log_e("could not acquire lock"); - return ret; - } + //acquire lock + if (bus[i2c_num].lock == NULL || xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE) { + log_e("could not acquire lock"); + return ret; + } #endif - if(!bus[i2c_num].initialized){ - log_e("bus is not initialized"); + if (!bus[i2c_num].initialized) { + log_e("bus is not initialized"); + } else { + ret = i2c_master_read_from_device((i2c_port_t)i2c_num, address, buff, size, timeOutMillis / portTICK_PERIOD_MS); + if (ret == ESP_OK) { + *readCount = size; } else { - ret = i2c_master_read_from_device((i2c_port_t)i2c_num, address, buff, size, timeOutMillis / portTICK_PERIOD_MS); - if(ret == ESP_OK){ - *readCount = size; - } else { - *readCount = 0; - } + *readCount = 0; } + } #if !CONFIG_DISABLE_HAL_LOCKS - //release lock - xSemaphoreGive(bus[i2c_num].lock); + //release lock + xSemaphoreGive(bus[i2c_num].lock); #endif - return ret; + return ret; } -esp_err_t i2cWriteReadNonStop(uint8_t i2c_num, uint16_t address, const uint8_t* wbuff, size_t wsize, uint8_t* rbuff, size_t rsize, uint32_t timeOutMillis, size_t *readCount){ - esp_err_t ret = ESP_FAIL; - if(i2c_num >= SOC_I2C_NUM){ - return ESP_ERR_INVALID_ARG; - } +esp_err_t i2cWriteReadNonStop(uint8_t i2c_num, uint16_t address, const uint8_t *wbuff, size_t wsize, uint8_t *rbuff, size_t rsize, uint32_t timeOutMillis, size_t *readCount) { + esp_err_t ret = ESP_FAIL; + if (i2c_num >= SOC_I2C_NUM) { + return ESP_ERR_INVALID_ARG; + } #if !CONFIG_DISABLE_HAL_LOCKS - //acquire lock - if(bus[i2c_num].lock == NULL || xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE){ - log_e("could not acquire lock"); - return ret; - } + //acquire lock + if (bus[i2c_num].lock == NULL || xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE) { + log_e("could not acquire lock"); + return ret; + } #endif - if(!bus[i2c_num].initialized){ - log_e("bus is not initialized"); + if (!bus[i2c_num].initialized) { + log_e("bus is not initialized"); + } else { + ret = i2c_master_write_read_device((i2c_port_t)i2c_num, address, wbuff, wsize, rbuff, rsize, timeOutMillis / portTICK_PERIOD_MS); + if (ret == ESP_OK) { + *readCount = rsize; } else { - ret = i2c_master_write_read_device((i2c_port_t)i2c_num, address, wbuff, wsize, rbuff, rsize, timeOutMillis / portTICK_PERIOD_MS); - if(ret == ESP_OK){ - *readCount = rsize; - } else { - *readCount = 0; - } + *readCount = 0; } + } #if !CONFIG_DISABLE_HAL_LOCKS - //release lock - xSemaphoreGive(bus[i2c_num].lock); + //release lock + xSemaphoreGive(bus[i2c_num].lock); #endif - return ret; + return ret; } -esp_err_t i2cSetClock(uint8_t i2c_num, uint32_t frequency){ - esp_err_t ret = ESP_FAIL; - if(i2c_num >= SOC_I2C_NUM){ - return ESP_ERR_INVALID_ARG; - } +esp_err_t i2cSetClock(uint8_t i2c_num, uint32_t frequency) { + esp_err_t ret = ESP_FAIL; + if (i2c_num >= SOC_I2C_NUM) { + return ESP_ERR_INVALID_ARG; + } #if !CONFIG_DISABLE_HAL_LOCKS - //acquire lock - if(bus[i2c_num].lock == NULL || xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE){ - log_e("could not acquire lock"); - return ret; - } + //acquire lock + if (bus[i2c_num].lock == NULL || xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE) { + log_e("could not acquire lock"); + return ret; + } #endif - if(!bus[i2c_num].initialized){ - log_e("bus is not initialized"); - goto end; - } - if(bus[i2c_num].frequency == frequency){ - ret = ESP_OK; - goto end; - } - if(!frequency){ - frequency = 100000UL; - } else if(frequency > 1000000UL){ - frequency = 1000000UL; - } + if (!bus[i2c_num].initialized) { + log_e("bus is not initialized"); + goto end; + } + if (bus[i2c_num].frequency == frequency) { + ret = ESP_OK; + goto end; + } + if (!frequency) { + frequency = 100000UL; + } else if (frequency > 1000000UL) { + frequency = 1000000UL; + } + + typedef struct { + soc_module_clk_t clk; /*!< I2C source clock */ + uint32_t clk_freq; /*!< I2C source clock frequency */ + } i2c_clk_alloc_t; - typedef struct { - soc_module_clk_t clk; /*!< I2C source clock */ - uint32_t clk_freq; /*!< I2C source clock frequency */ - } i2c_clk_alloc_t; + typedef enum { + I2C_SCLK_DEFAULT = 0, /*!< I2C source clock not selected*/ +#if SOC_I2C_SUPPORT_APB + I2C_SCLK_APB, /*!< I2C source clock from APB, 80M*/ +#endif +#if SOC_I2C_SUPPORT_XTAL + I2C_SCLK_XTAL, /*!< I2C source clock from XTAL, 40M */ +#endif +#if SOC_I2C_SUPPORT_RTC + I2C_SCLK_RTC, /*!< I2C source clock from 8M RTC, 8M */ +#endif +#if SOC_I2C_SUPPORT_REF_TICK + I2C_SCLK_REF_TICK, /*!< I2C source clock from REF_TICK, 1M */ +#endif + I2C_SCLK_MAX, + } i2c_sclk_t; - typedef enum { - I2C_SCLK_DEFAULT = 0, /*!< I2C source clock not selected*/ - #if SOC_I2C_SUPPORT_APB - I2C_SCLK_APB, /*!< I2C source clock from APB, 80M*/ - #endif - #if SOC_I2C_SUPPORT_XTAL - I2C_SCLK_XTAL, /*!< I2C source clock from XTAL, 40M */ - #endif - #if SOC_I2C_SUPPORT_RTC - I2C_SCLK_RTC, /*!< I2C source clock from 8M RTC, 8M */ - #endif - #if SOC_I2C_SUPPORT_REF_TICK - I2C_SCLK_REF_TICK, /*!< I2C source clock from REF_TICK, 1M */ - #endif - I2C_SCLK_MAX, - } i2c_sclk_t; + // i2c clock characteristic, The order is the same as i2c_sclk_t. + i2c_clk_alloc_t i2c_clk_alloc[I2C_SCLK_MAX] = { + { 0, 0 }, +#if SOC_I2C_SUPPORT_APB + { SOC_MOD_CLK_APB, esp_clk_apb_freq() }, /*!< I2C APB clock characteristic*/ +#endif +#if SOC_I2C_SUPPORT_XTAL + { SOC_MOD_CLK_XTAL, esp_clk_xtal_freq() }, /*!< I2C XTAL characteristic*/ +#endif +#if SOC_I2C_SUPPORT_RTC + { SOC_MOD_CLK_RC_FAST, periph_rtc_dig_clk8m_get_freq() }, /*!< I2C 20M RTC characteristic*/ +#endif +#if SOC_I2C_SUPPORT_REF_TICK + { SOC_MOD_CLK_REF_TICK, REF_CLK_FREQ }, /*!< I2C REF_TICK characteristic*/ +#endif + }; - // i2c clock characteristic, The order is the same as i2c_sclk_t. - i2c_clk_alloc_t i2c_clk_alloc[I2C_SCLK_MAX] = { - {0, 0}, - #if SOC_I2C_SUPPORT_APB - {SOC_MOD_CLK_APB, esp_clk_apb_freq()}, /*!< I2C APB clock characteristic*/ - #endif - #if SOC_I2C_SUPPORT_XTAL - {SOC_MOD_CLK_XTAL, esp_clk_xtal_freq()}, /*!< I2C XTAL characteristic*/ - #endif - #if SOC_I2C_SUPPORT_RTC - {SOC_MOD_CLK_RC_FAST, periph_rtc_dig_clk8m_get_freq()}, /*!< I2C 20M RTC characteristic*/ - #endif - #if SOC_I2C_SUPPORT_REF_TICK - {SOC_MOD_CLK_REF_TICK, REF_CLK_FREQ},/*!< I2C REF_TICK characteristic*/ - #endif - }; - - i2c_sclk_t src_clk = I2C_SCLK_DEFAULT; - ret = ESP_OK; - for (i2c_sclk_t clk = I2C_SCLK_DEFAULT + 1; clk < I2C_SCLK_MAX; clk++) { + i2c_sclk_t src_clk = I2C_SCLK_DEFAULT; + ret = ESP_OK; + for (i2c_sclk_t clk = I2C_SCLK_DEFAULT + 1; clk < I2C_SCLK_MAX; clk++) { #if CONFIG_IDF_TARGET_ESP32S3 - if (clk == I2C_SCLK_RTC) { // RTC clock for s3 is unaccessable now. - continue; - } -#endif - if (frequency <= i2c_clk_alloc[clk].clk_freq) { - src_clk = clk; - break; - } + if (clk == I2C_SCLK_RTC) { // RTC clock for s3 is inaccessible now. + continue; } - if(src_clk == I2C_SCLK_DEFAULT || src_clk == I2C_SCLK_MAX){ - log_e("clock source could not be selected"); - ret = ESP_FAIL; - } else { - i2c_hal_context_t hal; - hal.dev = I2C_LL_GET_HW(i2c_num); -#if SOC_I2C_SUPPORT_RTC - if(src_clk == I2C_SCLK_RTC){ - periph_rtc_dig_clk8m_enable(); - } #endif - i2c_hal_set_bus_timing(&(hal), frequency, i2c_clk_alloc[src_clk].clk, i2c_clk_alloc[src_clk].clk_freq); - bus[i2c_num].frequency = frequency; - //Clock Stretching Timeout: 20b:esp32, 5b:esp32-c3, 24b:esp32-s2 - i2c_set_timeout((i2c_port_t)i2c_num, I2C_LL_MAX_TIMEOUT); + if (frequency <= i2c_clk_alloc[clk].clk_freq) { + src_clk = clk; + break; + } + } + if (src_clk == I2C_SCLK_DEFAULT || src_clk == I2C_SCLK_MAX) { + log_e("clock source could not be selected"); + ret = ESP_FAIL; + } else { + i2c_hal_context_t hal; + hal.dev = I2C_LL_GET_HW(i2c_num); +#if SOC_I2C_SUPPORT_RTC + if (src_clk == I2C_SCLK_RTC) { + periph_rtc_dig_clk8m_enable(); } +#endif + i2c_hal_set_bus_timing(&(hal), frequency, i2c_clk_alloc[src_clk].clk, i2c_clk_alloc[src_clk].clk_freq); + bus[i2c_num].frequency = frequency; + //Clock Stretching Timeout: 20b:esp32, 5b:esp32-c3, 24b:esp32-s2 + i2c_set_timeout((i2c_port_t)i2c_num, I2C_LL_MAX_TIMEOUT); + } end: #if !CONFIG_DISABLE_HAL_LOCKS - //release lock - xSemaphoreGive(bus[i2c_num].lock); + //release lock + xSemaphoreGive(bus[i2c_num].lock); #endif - return ret; + return ret; } -esp_err_t i2cGetClock(uint8_t i2c_num, uint32_t * frequency){ - if(i2c_num >= SOC_I2C_NUM){ - return ESP_ERR_INVALID_ARG; - } - if(!bus[i2c_num].initialized){ - log_e("bus is not initialized"); - return ESP_FAIL; - } - *frequency = bus[i2c_num].frequency; - return ESP_OK; +esp_err_t i2cGetClock(uint8_t i2c_num, uint32_t *frequency) { + if (i2c_num >= SOC_I2C_NUM) { + return ESP_ERR_INVALID_ARG; + } + if (!bus[i2c_num].initialized) { + log_e("bus is not initialized"); + return ESP_FAIL; + } + *frequency = bus[i2c_num].frequency; + return ESP_OK; } #endif /* SOC_I2C_SUPPORTED */ diff --git a/cores/esp32/esp32-hal-i2c.h b/cores/esp32/esp32-hal-i2c.h index 2fa1e24a0a5..51f24a79ea9 100644 --- a/cores/esp32/esp32-hal-i2c.h +++ b/cores/esp32/esp32-hal-i2c.h @@ -28,14 +28,14 @@ extern "C" { #include #include -esp_err_t i2cInit(uint8_t i2c_num, int8_t sda, int8_t scl, uint32_t clk_speed); -esp_err_t i2cDeinit(uint8_t i2c_num); -esp_err_t i2cSetClock(uint8_t i2c_num, uint32_t frequency); -esp_err_t i2cGetClock(uint8_t i2c_num, uint32_t * frequency); -esp_err_t i2cWrite(uint8_t i2c_num, uint16_t address, const uint8_t* buff, size_t size, uint32_t timeOutMillis); -esp_err_t i2cRead(uint8_t i2c_num, uint16_t address, uint8_t* buff, size_t size, uint32_t timeOutMillis, size_t *readCount); -esp_err_t i2cWriteReadNonStop(uint8_t i2c_num, uint16_t address, const uint8_t* wbuff, size_t wsize, uint8_t* rbuff, size_t rsize, uint32_t timeOutMillis, size_t *readCount); -bool i2cIsInit(uint8_t i2c_num); + esp_err_t i2cInit(uint8_t i2c_num, int8_t sda, int8_t scl, uint32_t clk_speed); + esp_err_t i2cDeinit(uint8_t i2c_num); + esp_err_t i2cSetClock(uint8_t i2c_num, uint32_t frequency); + esp_err_t i2cGetClock(uint8_t i2c_num, uint32_t* frequency); + esp_err_t i2cWrite(uint8_t i2c_num, uint16_t address, const uint8_t* buff, size_t size, uint32_t timeOutMillis); + esp_err_t i2cRead(uint8_t i2c_num, uint16_t address, uint8_t* buff, size_t size, uint32_t timeOutMillis, size_t* readCount); + esp_err_t i2cWriteReadNonStop(uint8_t i2c_num, uint16_t address, const uint8_t* wbuff, size_t wsize, uint8_t* rbuff, size_t rsize, uint32_t timeOutMillis, size_t* readCount); + bool i2cIsInit(uint8_t i2c_num); #ifdef __cplusplus } diff --git a/cores/esp32/esp32-hal-ledc.c b/cores/esp32/esp32-hal-ledc.c index 2005777d7bd..121fc6ee376 100644 --- a/cores/esp32/esp32-hal-ledc.c +++ b/cores/esp32/esp32-hal-ledc.c @@ -23,380 +23,366 @@ #include "esp_rom_gpio.h" #ifdef SOC_LEDC_SUPPORT_HS_MODE -#define LEDC_CHANNELS (SOC_LEDC_CHANNEL_NUM<<1) +#define LEDC_CHANNELS (SOC_LEDC_CHANNEL_NUM << 1) #else -#define LEDC_CHANNELS (SOC_LEDC_CHANNEL_NUM) +#define LEDC_CHANNELS (SOC_LEDC_CHANNEL_NUM) #endif //Use XTAL clock if possible to avoid timer frequency error when setting APB clock < 80 Mhz //Need to be fixed in ESP-IDF #ifdef SOC_LEDC_SUPPORT_XTAL_CLOCK -#define LEDC_DEFAULT_CLK LEDC_USE_XTAL_CLK +#define LEDC_DEFAULT_CLK LEDC_USE_XTAL_CLK #else -#define LEDC_DEFAULT_CLK LEDC_AUTO_CLK +#define LEDC_DEFAULT_CLK LEDC_AUTO_CLK #endif -#define LEDC_MAX_BIT_WIDTH SOC_LEDC_TIMER_BIT_WIDTH +#define LEDC_MAX_BIT_WIDTH SOC_LEDC_TIMER_BIT_WIDTH typedef struct { - int used_channels : LEDC_CHANNELS; // Used channels as a bits + int used_channels : LEDC_CHANNELS; // Used channels as a bits } ledc_periph_t; -ledc_periph_t ledc_handle = {0}; +ledc_periph_t ledc_handle = { 0 }; static bool fade_initialized = false; -static bool ledcDetachBus(void * bus){ - ledc_channel_handle_t *handle = (ledc_channel_handle_t*)bus; - ledc_handle.used_channels &= ~(1UL << handle->channel); - pinMatrixOutDetach(handle->pin, false, false); - free(handle); - if(ledc_handle.used_channels == 0){ - ledc_fade_func_uninstall(); - fade_initialized = false; - } - return true; +static bool ledcDetachBus(void *bus) { + ledc_channel_handle_t *handle = (ledc_channel_handle_t *)bus; + ledc_handle.used_channels &= ~(1UL << handle->channel); + pinMatrixOutDetach(handle->pin, false, false); + free(handle); + if (ledc_handle.used_channels == 0) { + ledc_fade_func_uninstall(); + fade_initialized = false; + } + return true; } -bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t channel) -{ - if(channel >= LEDC_CHANNELS || ledc_handle.used_channels & (1UL << channel)){ - log_e("Channel %u is not available (maximum %u) or already used!", channel, LEDC_CHANNELS); - return false; - } - if (freq == 0) { - log_e("LEDC pin %u - frequency can't be zero.", pin); - return false; - } - if (resolution == 0 || resolution > LEDC_MAX_BIT_WIDTH){ - log_e("LEDC pin %u - resolution is zero or it is too big (maximum %u)", pin, LEDC_MAX_BIT_WIDTH); - return false; - } +bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t channel) { + if (channel >= LEDC_CHANNELS || ledc_handle.used_channels & (1UL << channel)) { + log_e("Channel %u is not available (maximum %u) or already used!", channel, LEDC_CHANNELS); + return false; + } + if (freq == 0) { + log_e("LEDC pin %u - frequency can't be zero.", pin); + return false; + } + if (resolution == 0 || resolution > LEDC_MAX_BIT_WIDTH) { + log_e("LEDC pin %u - resolution is zero or it is too big (maximum %u)", pin, LEDC_MAX_BIT_WIDTH); + return false; + } - perimanSetBusDeinit(ESP32_BUS_TYPE_LEDC, ledcDetachBus); - ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); - if(bus != NULL){ - log_e("Pin %u is already attached to LEDC (channel %u, resolution %u)", pin, bus->channel, bus->channel_resolution); - return false; - } + perimanSetBusDeinit(ESP32_BUS_TYPE_LEDC, ledcDetachBus); + ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); + if (bus != NULL) { + log_e("Pin %u is already attached to LEDC (channel %u, resolution %u)", pin, bus->channel, bus->channel_resolution); + return false; + } - if(!perimanClearPinBus(pin)){ - log_e("Pin %u is already attached to another bus and failed to detach", pin); - return false; - } + if (!perimanClearPinBus(pin)) { + log_e("Pin %u is already attached to another bus and failed to detach", pin); + return false; + } - uint8_t group=(channel/8), timer=((channel/2)%4); + uint8_t group = (channel / 8), timer = ((channel / 2) % 4); + + ledc_timer_config_t ledc_timer = { + .speed_mode = group, + .timer_num = timer, + .duty_resolution = resolution, + .freq_hz = freq, + .clk_cfg = LEDC_DEFAULT_CLK + }; + if (ledc_timer_config(&ledc_timer) != ESP_OK) { + log_e("ledc setup failed!"); + return false; + } - ledc_timer_config_t ledc_timer = { - .speed_mode = group, - .timer_num = timer, - .duty_resolution = resolution, - .freq_hz = freq, - .clk_cfg = LEDC_DEFAULT_CLK - }; - if(ledc_timer_config(&ledc_timer) != ESP_OK) - { - log_e("ledc setup failed!"); - return false; - } + uint32_t duty = ledc_get_duty(group, channel); + + ledc_channel_config_t ledc_channel = { + .speed_mode = group, + .channel = (channel % 8), + .timer_sel = timer, + .intr_type = LEDC_INTR_DISABLE, + .gpio_num = pin, + .duty = duty, + .hpoint = 0 + }; + ledc_channel_config(&ledc_channel); + + ledc_channel_handle_t *handle = (ledc_channel_handle_t *)malloc(sizeof(ledc_channel_handle_t)); + + handle->pin = pin; + handle->channel = channel; + handle->channel_resolution = resolution; +#ifndef SOC_LEDC_SUPPORT_FADE_STOP + handle->lock = NULL; +#endif + ledc_handle.used_channels |= 1UL << channel; - uint32_t duty = ledc_get_duty(group,channel); + if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_LEDC, (void *)handle, group, channel)) { + ledcDetachBus((void *)handle); + return false; + } - ledc_channel_config_t ledc_channel = { - .speed_mode = group, - .channel = (channel%8), - .timer_sel = timer, - .intr_type = LEDC_INTR_DISABLE, - .gpio_num = pin, - .duty = duty, - .hpoint = 0 - }; - ledc_channel_config(&ledc_channel); + log_i("LEDC attached to pin %u (channel %u, resolution %u)", pin, channel, resolution); + return true; +} - ledc_channel_handle_t *handle = (ledc_channel_handle_t *)malloc(sizeof(ledc_channel_handle_t)); +bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution) { + int free_channel = ~ledc_handle.used_channels & (ledc_handle.used_channels + 1); + if (free_channel == 0) { + log_e("No more LEDC channels available! (maximum is %u channels)", LEDC_CHANNELS); + return false; + } + uint8_t channel = __builtin_ctz(free_channel); // Convert the free_channel bit to channel number - handle->pin = pin; - handle->channel = channel; - handle->channel_resolution = resolution; - #ifndef SOC_LEDC_SUPPORT_FADE_STOP - handle->lock = NULL; - #endif - ledc_handle.used_channels |= 1UL << channel; + return ledcAttachChannel(pin, freq, resolution, channel); +} - if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_LEDC, (void *)handle, group, channel)){ - ledcDetachBus((void *)handle); - return false; +bool ledcWrite(uint8_t pin, uint32_t duty) { + ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); + if (bus != NULL) { + + uint8_t group = (bus->channel / 8), channel = (bus->channel % 8); + + //Fixing if all bits in resolution is set = LEDC FULL ON + uint32_t max_duty = (1 << bus->channel_resolution) - 1; + + if ((duty == max_duty) && (max_duty != 1)) { + duty = max_duty + 1; } - log_i("LEDC attached to pin %u (channel %u, resolution %u)", pin, channel, resolution); + ledc_set_duty(group, channel, duty); + ledc_update_duty(group, channel); + return true; + } + return false; } -bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution) -{ - int free_channel = ~ledc_handle.used_channels & (ledc_handle.used_channels+1); - if (free_channel == 0){ - log_e("No more LEDC channels available! (maximum is %u channels)", LEDC_CHANNELS); - return false; - } - uint8_t channel = __builtin_ctz(free_channel); // Convert the free_channel bit to channel number +uint32_t ledcRead(uint8_t pin) { + ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); + if (bus != NULL) { - return ledcAttachChannel(pin, freq, resolution, channel); + uint8_t group = (bus->channel / 8), channel = (bus->channel % 8); + return ledc_get_duty(group, channel); + } + return 0; +} + +uint32_t ledcReadFreq(uint8_t pin) { + ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); + if (bus != NULL) { + if (!ledcRead(pin)) { + return 0; + } + uint8_t group = (bus->channel / 8), timer = ((bus->channel / 2) % 4); + return ledc_get_freq(group, timer); + } + return 0; } -bool ledcWrite(uint8_t pin, uint32_t duty) -{ - ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); - if(bus != NULL){ - uint8_t group=(bus->channel/8), channel=(bus->channel%8); +uint32_t ledcWriteTone(uint8_t pin, uint32_t freq) { + ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); + if (bus != NULL) { - //Fixing if all bits in resolution is set = LEDC FULL ON - uint32_t max_duty = (1 << bus->channel_resolution) - 1; + if (!freq) { + ledcWrite(pin, 0); + return 0; + } - if((duty == max_duty) && (max_duty != 1)){ - duty = max_duty + 1; - } + uint8_t group = (bus->channel / 8), timer = ((bus->channel / 2) % 4); - ledc_set_duty(group, channel, duty); - ledc_update_duty(group, channel); + ledc_timer_config_t ledc_timer = { + .speed_mode = group, + .timer_num = timer, + .duty_resolution = 10, + .freq_hz = freq, + .clk_cfg = LEDC_DEFAULT_CLK + }; - return true; + if (ledc_timer_config(&ledc_timer) != ESP_OK) { + log_e("ledcWriteTone configuration failed!"); + return 0; } - return false; + bus->channel_resolution = 10; + + uint32_t res_freq = ledc_get_freq(group, timer); + ledcWrite(pin, 0x1FF); + return res_freq; + } + return 0; } -uint32_t ledcRead(uint8_t pin) -{ - ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); - if(bus != NULL){ +uint32_t ledcWriteNote(uint8_t pin, note_t note, uint8_t octave) { + const uint16_t noteFrequencyBase[12] = { + // C C# D Eb E F F# G G# A Bb B + 4186, 4435, 4699, 4978, 5274, 5588, 5920, 6272, 6645, 7040, 7459, 7902 + }; - uint8_t group=(bus->channel/8), channel=(bus->channel%8); - return ledc_get_duty(group,channel); - } - return 0; + if (octave > 8 || note >= NOTE_MAX) { + return 0; + } + uint32_t noteFreq = (uint32_t)noteFrequencyBase[note] / (uint32_t)(1 << (8 - octave)); + return ledcWriteTone(pin, noteFreq); } -uint32_t ledcReadFreq(uint8_t pin) -{ - ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); - if(bus != NULL){ - if(!ledcRead(pin)){ - return 0; - } - uint8_t group=(bus->channel/8), timer=((bus->channel/2)%4); - return ledc_get_freq(group,timer); - } - return 0; +bool ledcDetach(uint8_t pin) { + ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); + if (bus != NULL) { + // will call ledcDetachBus + return perimanClearPinBus(pin); + } else { + log_e("pin %u is not attached to LEDC", pin); + } + return false; } - -uint32_t ledcWriteTone(uint8_t pin, uint32_t freq) -{ - ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); - if(bus != NULL){ - - if(!freq){ - ledcWrite(pin, 0); - return 0; - } - - uint8_t group=(bus->channel/8), timer=((bus->channel/2)%4); - - ledc_timer_config_t ledc_timer = { - .speed_mode = group, - .timer_num = timer, - .duty_resolution = 10, - .freq_hz = freq, - .clk_cfg = LEDC_DEFAULT_CLK - }; - - if(ledc_timer_config(&ledc_timer) != ESP_OK) - { - log_e("ledcWriteTone configuration failed!"); - return 0; - } - bus->channel_resolution = 10; - - uint32_t res_freq = ledc_get_freq(group,timer); - ledcWrite(pin, 0x1FF); - return res_freq; +uint32_t ledcChangeFrequency(uint8_t pin, uint32_t freq, uint8_t resolution) { + ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); + if (bus != NULL) { + if (freq == 0) { + log_e("LEDC pin %u - frequency can't be zero.", pin); + return 0; } - return 0; -} + if (resolution == 0 || resolution > LEDC_MAX_BIT_WIDTH) { + log_e("LEDC pin %u - resolution is zero or it is too big (maximum %u)", pin, LEDC_MAX_BIT_WIDTH); + return 0; + } + uint8_t group = (bus->channel / 8), timer = ((bus->channel / 2) % 4); -uint32_t ledcWriteNote(uint8_t pin, note_t note, uint8_t octave){ - const uint16_t noteFrequencyBase[12] = { - // C C# D Eb E F F# G G# A Bb B - 4186, 4435, 4699, 4978, 5274, 5588, 5920, 6272, 6645, 7040, 7459, 7902 + ledc_timer_config_t ledc_timer = { + .speed_mode = group, + .timer_num = timer, + .duty_resolution = resolution, + .freq_hz = freq, + .clk_cfg = LEDC_DEFAULT_CLK }; - if(octave > 8 || note >= NOTE_MAX){ - return 0; + if (ledc_timer_config(&ledc_timer) != ESP_OK) { + log_e("ledcChangeFrequency failed!"); + return 0; } - uint32_t noteFreq = (uint32_t)noteFrequencyBase[note] / (uint32_t)(1 << (8-octave)); - return ledcWriteTone(pin, noteFreq); + bus->channel_resolution = resolution; + return ledc_get_freq(group, timer); + } + return 0; } -bool ledcDetach(uint8_t pin) -{ - ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); - if(bus != NULL){ - // will call ledcDetachBus - return perimanClearPinBus(pin); - } else { - log_e("pin %u is not attached to LEDC", pin); - } - return false; +bool ledcOutputInvert(uint8_t pin, bool out_invert) { + ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); + if (bus != NULL) { + gpio_set_level(pin, out_invert); +#ifdef SOC_LEDC_SUPPORT_HS_MODE + esp_rom_gpio_connect_out_signal(pin, ((bus->channel / 8 == 0) ? LEDC_HS_SIG_OUT0_IDX : LEDC_LS_SIG_OUT0_IDX) + ((bus->channel) % 8), out_invert, 0); +#else + esp_rom_gpio_connect_out_signal(pin, LEDC_LS_SIG_OUT0_IDX + ((bus->channel) % 8), out_invert, 0); +#endif + return true; + } + return false; } -uint32_t ledcChangeFrequency(uint8_t pin, uint32_t freq, uint8_t resolution) -{ - ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); - if(bus != NULL){ - if (freq == 0) { - log_e("LEDC pin %u - frequency can't be zero.", pin); - return 0; - } - if (resolution == 0 || resolution > LEDC_MAX_BIT_WIDTH){ - log_e("LEDC pin %u - resolution is zero or it is too big (maximum %u)", pin, LEDC_MAX_BIT_WIDTH); - return 0; - } - uint8_t group=(bus->channel/8), timer=((bus->channel/2)%4); - - ledc_timer_config_t ledc_timer = { - .speed_mode = group, - .timer_num = timer, - .duty_resolution = resolution, - .freq_hz = freq, - .clk_cfg = LEDC_DEFAULT_CLK - }; - - if(ledc_timer_config(&ledc_timer) != ESP_OK) - { - log_e("ledcChangeFrequency failed!"); - return 0; - } - bus->channel_resolution = resolution; - return ledc_get_freq(group,timer); +static IRAM_ATTR bool ledcFnWrapper(const ledc_cb_param_t *param, void *user_arg) { + if (param->event == LEDC_FADE_END_EVT) { + ledc_channel_handle_t *bus = (ledc_channel_handle_t *)user_arg; +#ifndef SOC_LEDC_SUPPORT_FADE_STOP + portBASE_TYPE xTaskWoken = 0; + xSemaphoreGiveFromISR(bus->lock, &xTaskWoken); +#endif + if (bus->fn) { + if (bus->arg) { + ((voidFuncPtrArg)bus->fn)(bus->arg); + } else { + bus->fn(); + } } - return 0; + } + return true; } -bool ledcOutputInvert(uint8_t pin, bool out_invert) -{ - ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); - if(bus != NULL){ - gpio_set_level(pin, out_invert); - #ifdef SOC_LEDC_SUPPORT_HS_MODE - esp_rom_gpio_connect_out_signal(pin, ((bus->channel/8 == 0) ? LEDC_HS_SIG_OUT0_IDX : LEDC_LS_SIG_OUT0_IDX) + ((bus->channel)%8), out_invert, 0); - #else - esp_rom_gpio_connect_out_signal(pin, LEDC_LS_SIG_OUT0_IDX + ((bus->channel)%8), out_invert, 0); - #endif - return true; +static bool ledcFadeConfig(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, void (*userFunc)(void *), void *arg) { + ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); + if (bus != NULL) { + +#ifndef SOC_LEDC_SUPPORT_FADE_STOP +#if !CONFIG_DISABLE_HAL_LOCKS + if (bus->lock == NULL) { + bus->lock = xSemaphoreCreateBinary(); + if (bus->lock == NULL) { + log_e("xSemaphoreCreateBinary failed"); + return false; + } + xSemaphoreGive(bus->lock); + } + //acquire lock + if (xSemaphoreTake(bus->lock, 0) != pdTRUE) { + log_e("LEDC Fade is still running on pin %u! SoC does not support stopping fade.", pin); + return false; + } +#endif +#endif + uint8_t group = (bus->channel / 8), channel = (bus->channel % 8); + + // Initialize fade service. + if (!fade_initialized) { + ledc_fade_func_install(0); + fade_initialized = true; } - return false; -} -static IRAM_ATTR bool ledcFnWrapper(const ledc_cb_param_t *param, void *user_arg) -{ - if (param->event == LEDC_FADE_END_EVT) { - ledc_channel_handle_t *bus = (ledc_channel_handle_t*)user_arg; - #ifndef SOC_LEDC_SUPPORT_FADE_STOP - portBASE_TYPE xTaskWoken = 0; - xSemaphoreGiveFromISR(bus->lock, &xTaskWoken); - #endif - if(bus->fn) { - if(bus->arg){ - ((voidFuncPtrArg)bus->fn)(bus->arg); - } else { - bus->fn(); - } - } + bus->fn = (voidFuncPtr)userFunc; + bus->arg = arg; + + ledc_cbs_t callbacks = { + .fade_cb = ledcFnWrapper + }; + ledc_cb_register(group, channel, &callbacks, (void *)bus); + + //Fixing if all bits in resolution is set = LEDC FULL ON + uint32_t max_duty = (1 << bus->channel_resolution) - 1; + + if ((target_duty == max_duty) && (max_duty != 1)) { + target_duty = max_duty + 1; + } else if ((start_duty == max_duty) && (max_duty != 1)) { + start_duty = max_duty + 1; } - return true; -} -static bool ledcFadeConfig(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, void (*userFunc)(void*), void * arg){ - ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); - if(bus != NULL){ - - #ifndef SOC_LEDC_SUPPORT_FADE_STOP - #if !CONFIG_DISABLE_HAL_LOCKS - if(bus->lock == NULL){ - bus->lock = xSemaphoreCreateBinary(); - if(bus->lock == NULL){ - log_e("xSemaphoreCreateBinary failed"); - return false; - } - xSemaphoreGive(bus->lock); - } - //acquire lock - if(xSemaphoreTake(bus->lock, 0) != pdTRUE){ - log_e("LEDC Fade is still running on pin %u! SoC does not support stopping fade.", pin); - return false; - } - #endif - #endif - uint8_t group=(bus->channel/8), channel=(bus->channel%8); - - // Initialize fade service. - if(!fade_initialized){ - ledc_fade_func_install(0); - fade_initialized = true; - } - - bus->fn = (voidFuncPtr)userFunc; - bus->arg = arg; - - ledc_cbs_t callbacks = { - .fade_cb = ledcFnWrapper - }; - ledc_cb_register(group, channel, &callbacks, (void *) bus); - - //Fixing if all bits in resolution is set = LEDC FULL ON - uint32_t max_duty = (1 << bus->channel_resolution) - 1; - - if((target_duty == max_duty) && (max_duty != 1)){ - target_duty = max_duty + 1; - } - else if((start_duty == max_duty) && (max_duty != 1)){ - start_duty = max_duty + 1; - } - - #if SOC_LEDC_SUPPORT_FADE_STOP - ledc_fade_stop(group, channel); - #endif - - if(ledc_set_duty_and_update(group, channel, start_duty, 0) != ESP_OK){ - log_e("ledc_set_duty_and_update failed"); - return false; - } - // Wait for LEDCs next PWM cycle to update duty (~ 1-2 ms) - while(ledc_get_duty(group,channel) != start_duty); - - if(ledc_set_fade_time_and_start(group, channel, target_duty, max_fade_time_ms, LEDC_FADE_NO_WAIT) != ESP_OK){ - log_e("ledc_set_fade_time_and_start failed"); - return false; - } +#if SOC_LEDC_SUPPORT_FADE_STOP + ledc_fade_stop(group, channel); +#endif + + if (ledc_set_duty_and_update(group, channel, start_duty, 0) != ESP_OK) { + log_e("ledc_set_duty_and_update failed"); + return false; } - else { - log_e("Pin %u is not attached to LEDC. Call ledcAttach first!", pin); - return false; + // Wait for LEDCs next PWM cycle to update duty (~ 1-2 ms) + while (ledc_get_duty(group, channel) != start_duty) + ; + + if (ledc_set_fade_time_and_start(group, channel, target_duty, max_fade_time_ms, LEDC_FADE_NO_WAIT) != ESP_OK) { + log_e("ledc_set_fade_time_and_start failed"); + return false; } - return true; + } else { + log_e("Pin %u is not attached to LEDC. Call ledcAttach first!", pin); + return false; + } + return true; } -bool ledcFade(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms){ - return ledcFadeConfig(pin, start_duty, target_duty, max_fade_time_ms, NULL, NULL); +bool ledcFade(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms) { + return ledcFadeConfig(pin, start_duty, target_duty, max_fade_time_ms, NULL, NULL); } -bool ledcFadeWithInterrupt(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, voidFuncPtr userFunc){ - return ledcFadeConfig(pin, start_duty, target_duty, max_fade_time_ms, (voidFuncPtrArg)userFunc, NULL); +bool ledcFadeWithInterrupt(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, voidFuncPtr userFunc) { + return ledcFadeConfig(pin, start_duty, target_duty, max_fade_time_ms, (voidFuncPtrArg)userFunc, NULL); } -bool ledcFadeWithInterruptArg(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, void (*userFunc)(void*), void * arg){ - return ledcFadeConfig(pin, start_duty, target_duty, max_fade_time_ms, userFunc, arg); +bool ledcFadeWithInterruptArg(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, void (*userFunc)(void *), void *arg) { + return ledcFadeConfig(pin, start_duty, target_duty, max_fade_time_ms, userFunc, arg); } static uint8_t analog_resolution = 8; @@ -404,31 +390,31 @@ static int analog_frequency = 1000; void analogWrite(uint8_t pin, int value) { // Use ledc hardware for internal pins if (pin < SOC_GPIO_PIN_COUNT) { - ledc_channel_handle_t *bus = (ledc_channel_handle_t*)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); - if(bus == NULL && perimanClearPinBus(pin)){ - if(ledcAttach(pin, analog_frequency, analog_resolution) == 0){ - log_e("analogWrite setup failed (freq = %u, resolution = %u). Try setting different resolution or frequency"); - return; - } + ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); + if (bus == NULL && perimanClearPinBus(pin)) { + if (ledcAttach(pin, analog_frequency, analog_resolution) == 0) { + log_e("analogWrite setup failed (freq = %u, resolution = %u). Try setting different resolution or frequency"); + return; + } } ledcWrite(pin, value); } } void analogWriteFrequency(uint8_t pin, uint32_t freq) { - if (ledcChangeFrequency(pin, freq, analog_resolution) == 0){ - log_e("analogWrite frequency cant be set due to selected resolution! Try to adjust resolution first"); - return; - } - analog_frequency = freq; + if (ledcChangeFrequency(pin, freq, analog_resolution) == 0) { + log_e("analogWrite frequency cant be set due to selected resolution! Try to adjust resolution first"); + return; + } + analog_frequency = freq; } void analogWriteResolution(uint8_t pin, uint8_t resolution) { - if (ledcChangeFrequency(pin, analog_frequency, resolution) == 0){ - log_e("analogWrite resolution cant be set due to selected frequency! Try to adjust frequency first"); - return; - } - analog_resolution = resolution; + if (ledcChangeFrequency(pin, analog_frequency, resolution) == 0) { + log_e("analogWrite resolution cant be set due to selected frequency! Try to adjust frequency first"); + return; + } + analog_resolution = resolution; } #endif /* SOC_LEDC_SUPPORTED */ diff --git a/cores/esp32/esp32-hal-ledc.h b/cores/esp32/esp32-hal-ledc.h index 94dcf7509d1..432764f86ed 100644 --- a/cores/esp32/esp32-hal-ledc.h +++ b/cores/esp32/esp32-hal-ledc.h @@ -27,25 +27,37 @@ extern "C" { #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" -typedef enum { - NOTE_C, NOTE_Cs, NOTE_D, NOTE_Eb, NOTE_E, NOTE_F, NOTE_Fs, NOTE_G, NOTE_Gs, NOTE_A, NOTE_Bb, NOTE_B, NOTE_MAX -} note_t; - -typedef void (*voidFuncPtr)(void); -typedef void (*voidFuncPtrArg)(void*); - -typedef struct { - uint8_t pin; // Pin assigned to channel - uint8_t channel; // Channel number - uint8_t channel_resolution; // Resolution of channel + typedef enum { + NOTE_C, + NOTE_Cs, + NOTE_D, + NOTE_Eb, + NOTE_E, + NOTE_F, + NOTE_Fs, + NOTE_G, + NOTE_Gs, + NOTE_A, + NOTE_Bb, + NOTE_B, + NOTE_MAX + } note_t; + + typedef void (*voidFuncPtr)(void); + typedef void (*voidFuncPtrArg)(void*); + + typedef struct { + uint8_t pin; // Pin assigned to channel + uint8_t channel; // Channel number + uint8_t channel_resolution; // Resolution of channel voidFuncPtr fn; void* arg; #ifndef SOC_LEDC_SUPPORT_FADE_STOP - SemaphoreHandle_t lock; //xSemaphoreCreateBinary + SemaphoreHandle_t lock; //xSemaphoreCreateBinary #endif -} ledc_channel_handle_t; + } ledc_channel_handle_t; -/** + /** * @brief Attach a pin to the LEDC driver, with a given frequency and resolution. * Channel is automatically assigned. * @@ -55,9 +67,9 @@ typedef struct { * * @return true if configuration is successful and pin was successfully attached, false otherwise. */ -bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution); + bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution); -/** + /** * @brief Attach a pin to the LEDC driver, with a given frequency, resolution and channel. * * @param pin GPIO pin @@ -67,9 +79,9 @@ bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution); * * @return true if configuration is successful and pin was successfully attached, false otherwise. */ -bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t channel); + bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t channel); -/** + /** * @brief Set the duty cycle of a given pin. * * @param pin GPIO pin @@ -77,9 +89,9 @@ bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t c * * @return true if duty cycle was successfully set, false otherwise. */ -bool ledcWrite(uint8_t pin, uint32_t duty); + bool ledcWrite(uint8_t pin, uint32_t duty); -/** + /** * @brief Sets the duty to 50 % PWM tone on selected frequency. * * @param pin GPIO pin @@ -88,9 +100,9 @@ bool ledcWrite(uint8_t pin, uint32_t duty); * @return frequency if tone was successfully set. * If ``0`` is returned, error occurs and LEDC pin was not configured. */ -uint32_t ledcWriteTone(uint8_t pin, uint32_t freq); + uint32_t ledcWriteTone(uint8_t pin, uint32_t freq); -/** + /** * @brief Sets the LEDC pin to specific note. * * @param pin GPIO pin @@ -100,96 +112,96 @@ uint32_t ledcWriteTone(uint8_t pin, uint32_t freq); * @return frequency if note was successfully set. * If ``0`` is returned, error occurs and LEDC pin was not configured. */ -uint32_t ledcWriteNote(uint8_t pin, note_t note, uint8_t octave); + uint32_t ledcWriteNote(uint8_t pin, note_t note, uint8_t octave); -/** + /** * @brief Read the duty cycle of a given LEDC pin. * * @param pin GPIO pin * * @return duty cycle of selected LEDC pin. */ -uint32_t ledcRead(uint8_t pin); + uint32_t ledcRead(uint8_t pin); -/** + /** * @brief Read the frequency of a given LEDC pin. * * @param pin GPIO pin * * @return frequency of selected LEDC pin. */ -uint32_t ledcReadFreq(uint8_t pin); + uint32_t ledcReadFreq(uint8_t pin); -/** + /** * @brief Detach a pin from the LEDC driver. * * @param pin GPIO pin * * @return true if pin was successfully detached, false otherwise. */ -bool ledcDetach(uint8_t pin); + bool ledcDetach(uint8_t pin); -/** + /** * @brief Change the frequency and resolution of a given LEDC pin. - * + * * @param pin GPIO pin * @param freq frequency of PWM signal * @param resolution resolution for LEDC pin - * + * * @return frequency configured for the LEDC channel. * If ``0`` is returned, error occurs and LEDC pin was not configured. */ -uint32_t ledcChangeFrequency(uint8_t pin, uint32_t freq, uint8_t resolution); + uint32_t ledcChangeFrequency(uint8_t pin, uint32_t freq, uint8_t resolution); -/** + /** * @brief Sets inverting of the output signal for a given LEDC pin. - * + * * @param pin GPIO pin * @param out_invert select, if output should be inverted (true = inverting output). - * + * * @return true if output inverting was successfully set, false otherwise. */ -bool ledcOutputInvert(uint8_t pin, bool out_invert); + bool ledcOutputInvert(uint8_t pin, bool out_invert); -//Fade functions -/** + //Fade functions + /** * @brief Setup and start a fade on a given LEDC pin. - * + * * @param pin GPIO pin * @param start_duty initial duty cycle of the fade * @param target_duty target duty cycle of the fade * @param max_fade_time_ms maximum fade time in milliseconds - * + * * @return true if fade was successfully set and started, false otherwise. */ -bool ledcFade(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms); + bool ledcFade(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms); -/** + /** * @brief Setup and start a fade on a given LEDC pin with a callback function. - * + * * @param pin GPIO pin * @param start_duty initial duty cycle of the fade * @param target_duty target duty cycle of the fade * @param max_fade_time_ms maximum fade time in milliseconds * @param userFunc callback function to be called after fade is finished - * + * * @return true if fade was successfully set and started, false otherwise. */ -bool ledcFadeWithInterrupt(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, void (*userFunc)(void)); + bool ledcFadeWithInterrupt(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, void (*userFunc)(void)); -/** + /** * @brief Setup and start a fade on a given LEDC pin with a callback function and argument. - * + * * @param pin GPIO pin * @param start_duty initial duty cycle of the fade * @param target_duty target duty cycle of the fade * @param max_fade_time_ms maximum fade time in milliseconds * @param userFunc callback function to be called after fade is finished * @param arg argument to be passed to the callback function - * + * * @return true if fade was successfully set and started, false otherwise. */ -bool ledcFadeWithInterruptArg(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, void (*userFunc)(void*), void * arg); + bool ledcFadeWithInterruptArg(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, void (*userFunc)(void*), void* arg); #ifdef __cplusplus } diff --git a/cores/esp32/esp32-hal-log.h b/cores/esp32/esp32-hal-log.h index 15f986400b4..b43a0747315 100644 --- a/cores/esp32/esp32-hal-log.h +++ b/cores/esp32/esp32-hal-log.h @@ -15,19 +15,18 @@ #define __ARDUHAL_LOG_H__ #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif #include "sdkconfig.h" #include "esp_timer.h" -#define ARDUHAL_LOG_LEVEL_NONE (0) -#define ARDUHAL_LOG_LEVEL_ERROR (1) -#define ARDUHAL_LOG_LEVEL_WARN (2) -#define ARDUHAL_LOG_LEVEL_INFO (3) -#define ARDUHAL_LOG_LEVEL_DEBUG (4) -#define ARDUHAL_LOG_LEVEL_VERBOSE (5) +#define ARDUHAL_LOG_LEVEL_NONE (0) +#define ARDUHAL_LOG_LEVEL_ERROR (1) +#define ARDUHAL_LOG_LEVEL_WARN (2) +#define ARDUHAL_LOG_LEVEL_INFO (3) +#define ARDUHAL_LOG_LEVEL_DEBUG (4) +#define ARDUHAL_LOG_LEVEL_VERBOSE (5) #ifndef CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL #define CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL ARDUHAL_LOG_LEVEL_NONE @@ -49,26 +48,26 @@ extern "C" #endif #if CONFIG_ARDUHAL_LOG_COLORS -#define ARDUHAL_LOG_COLOR_BLACK "30" -#define ARDUHAL_LOG_COLOR_RED "31" //ERROR -#define ARDUHAL_LOG_COLOR_GREEN "32" //INFO -#define ARDUHAL_LOG_COLOR_YELLOW "33" //WARNING -#define ARDUHAL_LOG_COLOR_BLUE "34" +#define ARDUHAL_LOG_COLOR_BLACK "30" +#define ARDUHAL_LOG_COLOR_RED "31" //ERROR +#define ARDUHAL_LOG_COLOR_GREEN "32" //INFO +#define ARDUHAL_LOG_COLOR_YELLOW "33" //WARNING +#define ARDUHAL_LOG_COLOR_BLUE "34" #define ARDUHAL_LOG_COLOR_MAGENTA "35" -#define ARDUHAL_LOG_COLOR_CYAN "36" //DEBUG -#define ARDUHAL_LOG_COLOR_GRAY "37" //VERBOSE -#define ARDUHAL_LOG_COLOR_WHITE "38" - -#define ARDUHAL_LOG_COLOR(COLOR) "\033[0;" COLOR "m" -#define ARDUHAL_LOG_BOLD(COLOR) "\033[1;" COLOR "m" -#define ARDUHAL_LOG_RESET_COLOR "\033[0m" - -#define ARDUHAL_LOG_COLOR_E ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_RED) -#define ARDUHAL_LOG_COLOR_W ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_YELLOW) -#define ARDUHAL_LOG_COLOR_I ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_GREEN) -#define ARDUHAL_LOG_COLOR_D ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_CYAN) -#define ARDUHAL_LOG_COLOR_V ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_GRAY) -#define ARDUHAL_LOG_COLOR_PRINT(letter) log_printf(ARDUHAL_LOG_COLOR_ ## letter) +#define ARDUHAL_LOG_COLOR_CYAN "36" //DEBUG +#define ARDUHAL_LOG_COLOR_GRAY "37" //VERBOSE +#define ARDUHAL_LOG_COLOR_WHITE "38" + +#define ARDUHAL_LOG_COLOR(COLOR) "\033[0;" COLOR "m" +#define ARDUHAL_LOG_BOLD(COLOR) "\033[1;" COLOR "m" +#define ARDUHAL_LOG_RESET_COLOR "\033[0m" + +#define ARDUHAL_LOG_COLOR_E ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_RED) +#define ARDUHAL_LOG_COLOR_W ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_YELLOW) +#define ARDUHAL_LOG_COLOR_I ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_GREEN) +#define ARDUHAL_LOG_COLOR_D ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_CYAN) +#define ARDUHAL_LOG_COLOR_V ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_GRAY) +#define ARDUHAL_LOG_COLOR_PRINT(letter) log_printf(ARDUHAL_LOG_COLOR_##letter) #define ARDUHAL_LOG_COLOR_PRINT_END log_printf(ARDUHAL_LOG_RESET_COLOR) #else #define ARDUHAL_LOG_COLOR_E @@ -83,109 +82,193 @@ extern "C" -const char * pathToFileName(const char * path); -int log_printf(const char *fmt, ...); -void log_print_buf(const uint8_t *b, size_t len); + const char *pathToFileName(const char *path); + int log_printf(const char *fmt, ...); + void log_print_buf(const uint8_t *b, size_t len); -#define ARDUHAL_SHORT_LOG_FORMAT(letter, format) ARDUHAL_LOG_COLOR_ ## letter format ARDUHAL_LOG_RESET_COLOR "\r\n" -#define ARDUHAL_LOG_FORMAT(letter, format) ARDUHAL_LOG_COLOR_ ## letter "[%6u][" #letter "][%s:%u] %s(): " format ARDUHAL_LOG_RESET_COLOR "\r\n", (unsigned long) (esp_timer_get_time() / 1000ULL), pathToFileName(__FILE__), __LINE__, __FUNCTION__ +#define ARDUHAL_SHORT_LOG_FORMAT(letter, format) ARDUHAL_LOG_COLOR_##letter format ARDUHAL_LOG_RESET_COLOR "\r\n" +#define ARDUHAL_LOG_FORMAT(letter, format) ARDUHAL_LOG_COLOR_##letter "[%6u][" #letter "][%s:%u] %s(): " format ARDUHAL_LOG_RESET_COLOR "\r\n", (unsigned long)(esp_timer_get_time() / 1000ULL), pathToFileName(__FILE__), __LINE__, __FUNCTION__ -//esp_rom_printf(DRAM_STR("ST:%d\n"), frame_pos); + //esp_rom_printf(DRAM_STR("ST:%d\n"), frame_pos); #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE #ifndef USE_ESP_IDF_LOG #define log_v(format, ...) log_printf(ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__) #define isr_log_v(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__) -#define log_buf_v(b,l) do{ARDUHAL_LOG_COLOR_PRINT(V);log_print_buf(b,l);ARDUHAL_LOG_COLOR_PRINT_END;}while(0) +#define log_buf_v(b, l) \ + do { \ + ARDUHAL_LOG_COLOR_PRINT(V); \ + log_print_buf(b, l); \ + ARDUHAL_LOG_COLOR_PRINT_END; \ + } while (0) #else -#define log_v(format, ...) do {ESP_LOG_LEVEL_LOCAL(ESP_LOG_VERBOSE, TAG, format, ##__VA_ARGS__);}while(0) -#define isr_log_v(format, ...) do {ets_printf(LOG_FORMAT(V, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0) -#define log_buf_v(b,l) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_VERBOSE);}while(0) +#define log_v(format, ...) \ + do { ESP_LOG_LEVEL_LOCAL(ESP_LOG_VERBOSE, TAG, format, ##__VA_ARGS__); } while (0) +#define isr_log_v(format, ...) \ + do { ets_printf(LOG_FORMAT(V, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); } while (0) +#define log_buf_v(b, l) \ + do { ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_VERBOSE); } while (0) #endif #else -#define log_v(format, ...) do {} while(0) -#define isr_log_v(format, ...) do {} while(0) -#define log_buf_v(b,l) do {} while(0) +#define log_v(format, ...) \ + do { \ + } while (0) +#define isr_log_v(format, ...) \ + do { \ + } while (0) +#define log_buf_v(b, l) \ + do { \ + } while (0) #endif #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG #ifndef USE_ESP_IDF_LOG #define log_d(format, ...) log_printf(ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__) #define isr_log_d(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__) -#define log_buf_d(b,l) do{ARDUHAL_LOG_COLOR_PRINT(D);log_print_buf(b,l);ARDUHAL_LOG_COLOR_PRINT_END;}while(0) +#define log_buf_d(b, l) \ + do { \ + ARDUHAL_LOG_COLOR_PRINT(D); \ + log_print_buf(b, l); \ + ARDUHAL_LOG_COLOR_PRINT_END; \ + } while (0) #else -#define log_d(format, ...) do {ESP_LOG_LEVEL_LOCAL(ESP_LOG_DEBUG, TAG, format, ##__VA_ARGS__);}while(0) -#define isr_log_d(format, ...) do {ets_printf(LOG_FORMAT(D, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0) -#define log_buf_d(b,l) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_DEBUG);}while(0) +#define log_d(format, ...) \ + do { ESP_LOG_LEVEL_LOCAL(ESP_LOG_DEBUG, TAG, format, ##__VA_ARGS__); } while (0) +#define isr_log_d(format, ...) \ + do { ets_printf(LOG_FORMAT(D, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); } while (0) +#define log_buf_d(b, l) \ + do { ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_DEBUG); } while (0) #endif #else -#define log_d(format, ...) do {} while(0) -#define isr_log_d(format, ...) do {} while(0) -#define log_buf_d(b,l) do {} while(0) +#define log_d(format, ...) \ + do { \ + } while (0) +#define isr_log_d(format, ...) \ + do { \ + } while (0) +#define log_buf_d(b, l) \ + do { \ + } while (0) #endif #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO #ifndef USE_ESP_IDF_LOG #define log_i(format, ...) log_printf(ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__) #define isr_log_i(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__) -#define log_buf_i(b,l) do{ARDUHAL_LOG_COLOR_PRINT(I);log_print_buf(b,l);ARDUHAL_LOG_COLOR_PRINT_END;}while(0) +#define log_buf_i(b, l) \ + do { \ + ARDUHAL_LOG_COLOR_PRINT(I); \ + log_print_buf(b, l); \ + ARDUHAL_LOG_COLOR_PRINT_END; \ + } while (0) #else -#define log_i(format, ...) do {ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, TAG, format, ##__VA_ARGS__);}while(0) -#define isr_log_i(format, ...) do {ets_printf(LOG_FORMAT(I, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0) -#define log_buf_i(b,l) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_INFO);}while(0) +#define log_i(format, ...) \ + do { ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, TAG, format, ##__VA_ARGS__); } while (0) +#define isr_log_i(format, ...) \ + do { ets_printf(LOG_FORMAT(I, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); } while (0) +#define log_buf_i(b, l) \ + do { ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_INFO); } while (0) #endif #else -#define log_i(format, ...) do {} while(0) -#define isr_log_i(format, ...) do {} while(0) -#define log_buf_i(b,l) do {} while(0) +#define log_i(format, ...) \ + do { \ + } while (0) +#define isr_log_i(format, ...) \ + do { \ + } while (0) +#define log_buf_i(b, l) \ + do { \ + } while (0) #endif #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_WARN #ifndef USE_ESP_IDF_LOG #define log_w(format, ...) log_printf(ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__) #define isr_log_w(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__) -#define log_buf_w(b,l) do{ARDUHAL_LOG_COLOR_PRINT(W);log_print_buf(b,l);ARDUHAL_LOG_COLOR_PRINT_END;}while(0) +#define log_buf_w(b, l) \ + do { \ + ARDUHAL_LOG_COLOR_PRINT(W); \ + log_print_buf(b, l); \ + ARDUHAL_LOG_COLOR_PRINT_END; \ + } while (0) #else -#define log_w(format, ...) do {ESP_LOG_LEVEL_LOCAL(ESP_LOG_WARN, TAG, format, ##__VA_ARGS__);}while(0) -#define isr_log_w(format, ...) do {ets_printf(LOG_FORMAT(W, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0) -#define log_buf_w(b,l) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_WARN);}while(0) +#define log_w(format, ...) \ + do { ESP_LOG_LEVEL_LOCAL(ESP_LOG_WARN, TAG, format, ##__VA_ARGS__); } while (0) +#define isr_log_w(format, ...) \ + do { ets_printf(LOG_FORMAT(W, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); } while (0) +#define log_buf_w(b, l) \ + do { ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_WARN); } while (0) #endif #else -#define log_w(format, ...) do {} while(0) -#define isr_log_w(format, ...) do {} while(0) -#define log_buf_w(b,l) do {} while(0) +#define log_w(format, ...) \ + do { \ + } while (0) +#define isr_log_w(format, ...) \ + do { \ + } while (0) +#define log_buf_w(b, l) \ + do { \ + } while (0) #endif #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR #ifndef USE_ESP_IDF_LOG #define log_e(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) #define isr_log_e(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) -#define log_buf_e(b,l) do{ARDUHAL_LOG_COLOR_PRINT(E);log_print_buf(b,l);ARDUHAL_LOG_COLOR_PRINT_END;}while(0) +#define log_buf_e(b, l) \ + do { \ + ARDUHAL_LOG_COLOR_PRINT(E); \ + log_print_buf(b, l); \ + ARDUHAL_LOG_COLOR_PRINT_END; \ + } while (0) #else -#define log_e(format, ...) do {ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, TAG, format, ##__VA_ARGS__);}while(0) -#define isr_log_e(format, ...) do {ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0) -#define log_buf_e(b,l) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR);}while(0) +#define log_e(format, ...) \ + do { ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, TAG, format, ##__VA_ARGS__); } while (0) +#define isr_log_e(format, ...) \ + do { ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); } while (0) +#define log_buf_e(b, l) \ + do { ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR); } while (0) #endif #else -#define log_e(format, ...) do {} while(0) -#define isr_log_e(format, ...) do {} while(0) -#define log_buf_e(b,l) do {} while(0) +#define log_e(format, ...) \ + do { \ + } while (0) +#define isr_log_e(format, ...) \ + do { \ + } while (0) +#define log_buf_e(b, l) \ + do { \ + } while (0) #endif #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_NONE #ifndef USE_ESP_IDF_LOG #define log_n(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) #define isr_log_n(format, ...) ets_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) -#define log_buf_n(b,l) do{ARDUHAL_LOG_COLOR_PRINT(E);log_print_buf(b,l);ARDUHAL_LOG_COLOR_PRINT_END;}while(0) +#define log_buf_n(b, l) \ + do { \ + ARDUHAL_LOG_COLOR_PRINT(E); \ + log_print_buf(b, l); \ + ARDUHAL_LOG_COLOR_PRINT_END; \ + } while (0) #else -#define log_n(format, ...) do {ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, TAG, format, ##__VA_ARGS__);}while(0) -#define isr_log_n(format, ...) do {ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0) -#define log_buf_n(b,l) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR);}while(0) +#define log_n(format, ...) \ + do { ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, TAG, format, ##__VA_ARGS__); } while (0) +#define isr_log_n(format, ...) \ + do { ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); } while (0) +#define log_buf_n(b, l) \ + do { ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR); } while (0) #endif #else -#define log_n(format, ...) do {} while(0) -#define isr_log_n(format, ...) do {} while(0) -#define log_buf_n(b,l) do {} while(0) +#define log_n(format, ...) \ + do { \ + } while (0) +#define isr_log_n(format, ...) \ + do { \ + } while (0) +#define log_buf_n(b, l) \ + do { \ + } while (0) #endif #include "esp_log.h" @@ -208,16 +291,16 @@ void log_print_buf(const uint8_t *b, size_t len); #undef ESP_EARLY_LOGD #undef ESP_EARLY_LOGV -#define ESP_LOGE(tag, format, ...) log_e("[%s] " format, tag, ##__VA_ARGS__) -#define ESP_LOGW(tag, format, ...) log_w("[%s] " format, tag, ##__VA_ARGS__) -#define ESP_LOGI(tag, format, ...) log_i("[%s] " format, tag, ##__VA_ARGS__) -#define ESP_LOGD(tag, format, ...) log_d("[%s] " format, tag, ##__VA_ARGS__) -#define ESP_LOGV(tag, format, ...) log_v("[%s] " format, tag, ##__VA_ARGS__) -#define ESP_EARLY_LOGE(tag, format, ...) isr_log_e("[%s] " format, tag, ##__VA_ARGS__) -#define ESP_EARLY_LOGW(tag, format, ...) isr_log_w("[%s] " format, tag, ##__VA_ARGS__) -#define ESP_EARLY_LOGI(tag, format, ...) isr_log_i("[%s] " format, tag, ##__VA_ARGS__) -#define ESP_EARLY_LOGD(tag, format, ...) isr_log_d("[%s] " format, tag, ##__VA_ARGS__) -#define ESP_EARLY_LOGV(tag, format, ...) isr_log_v("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_LOGE(tag, format, ...) log_e("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_LOGW(tag, format, ...) log_w("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_LOGI(tag, format, ...) log_i("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_LOGD(tag, format, ...) log_d("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_LOGV(tag, format, ...) log_v("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_EARLY_LOGE(tag, format, ...) isr_log_e("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_EARLY_LOGW(tag, format, ...) isr_log_w("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_EARLY_LOGI(tag, format, ...) isr_log_i("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_EARLY_LOGD(tag, format, ...) isr_log_d("[%s] " format, tag, ##__VA_ARGS__) +#define ESP_EARLY_LOGV(tag, format, ...) isr_log_v("[%s] " format, tag, ##__VA_ARGS__) #endif #endif diff --git a/cores/esp32/esp32-hal-matrix.c b/cores/esp32/esp32-hal-matrix.c index 9174ae373ca..b47d70cdc0a 100644 --- a/cores/esp32/esp32-hal-matrix.c +++ b/cores/esp32/esp32-hal-matrix.c @@ -16,9 +16,9 @@ #include "esp_attr.h" #include "esp_system.h" -#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ #include "soc/gpio_pins.h" -#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 #include "esp32/rom/gpio.h" #elif CONFIG_IDF_TARGET_ESP32S2 #include "esp32s2/rom/gpio.h" @@ -32,38 +32,33 @@ #include "esp32c6/rom/gpio.h" #elif CONFIG_IDF_TARGET_ESP32H2 #include "esp32h2/rom/gpio.h" -#else +#else #error Target CONFIG_IDF_TARGET is not supported #endif -#else // ESP32 Before IDF 4.0 +#else // ESP32 Before IDF 4.0 #include "rom/gpio.h" #define GPIO_MATRIX_CONST_ZERO_INPUT GPIO_FUNC_IN_LOW #define GPIO_MATRIX_CONST_ONE_INPUT GPIO_FUNC_IN_HIGH #endif -void ARDUINO_ISR_ATTR pinMatrixOutAttach(uint8_t pin, uint8_t function, bool invertOut, bool invertEnable) -{ - gpio_matrix_out(pin, function, invertOut, invertEnable); +void ARDUINO_ISR_ATTR pinMatrixOutAttach(uint8_t pin, uint8_t function, bool invertOut, bool invertEnable) { + gpio_matrix_out(pin, function, invertOut, invertEnable); } -void ARDUINO_ISR_ATTR pinMatrixOutDetach(uint8_t pin, bool invertOut, bool invertEnable) -{ - gpio_matrix_out(pin, SIG_GPIO_OUT_IDX, invertOut, invertEnable); +void ARDUINO_ISR_ATTR pinMatrixOutDetach(uint8_t pin, bool invertOut, bool invertEnable) { + gpio_matrix_out(pin, SIG_GPIO_OUT_IDX, invertOut, invertEnable); } -void ARDUINO_ISR_ATTR pinMatrixInAttach(uint8_t pin, uint8_t signal, bool inverted) -{ - gpio_matrix_in(pin, signal, inverted); +void ARDUINO_ISR_ATTR pinMatrixInAttach(uint8_t pin, uint8_t signal, bool inverted) { + gpio_matrix_in(pin, signal, inverted); } -void ARDUINO_ISR_ATTR pinMatrixInDetach(uint8_t signal, bool high, bool inverted) -{ - gpio_matrix_in(high?GPIO_MATRIX_CONST_ONE_INPUT:GPIO_MATRIX_CONST_ZERO_INPUT, signal, inverted); +void ARDUINO_ISR_ATTR pinMatrixInDetach(uint8_t signal, bool high, bool inverted) { + gpio_matrix_in(high ? GPIO_MATRIX_CONST_ONE_INPUT : GPIO_MATRIX_CONST_ZERO_INPUT, signal, inverted); } /* void ARDUINO_ISR_ATTR intrMatrixAttach(uint32_t source, uint32_t inum){ intr_matrix_set(PRO_CPU_NUM, source, inum); } */ - diff --git a/cores/esp32/esp32-hal-matrix.h b/cores/esp32/esp32-hal-matrix.h index 3bc90498d6b..32e99b782f0 100644 --- a/cores/esp32/esp32-hal-matrix.h +++ b/cores/esp32/esp32-hal-matrix.h @@ -23,10 +23,10 @@ extern "C" { #include "esp32-hal.h" #include "soc/gpio_sig_map.h" -void pinMatrixOutAttach(uint8_t pin, uint8_t function, bool invertOut, bool invertEnable); -void pinMatrixOutDetach(uint8_t pin, bool invertOut, bool invertEnable); -void pinMatrixInAttach(uint8_t pin, uint8_t signal, bool inverted); -void pinMatrixInDetach(uint8_t signal, bool high, bool inverted); + void pinMatrixOutAttach(uint8_t pin, uint8_t function, bool invertOut, bool invertEnable); + void pinMatrixOutDetach(uint8_t pin, bool invertOut, bool invertEnable); + void pinMatrixInAttach(uint8_t pin, uint8_t signal, bool inverted); + void pinMatrixInDetach(uint8_t signal, bool high, bool inverted); #ifdef __cplusplus } diff --git a/cores/esp32/esp32-hal-misc.c b/cores/esp32/esp32-hal-misc.c index c5973fbbba5..43c47bf1555 100644 --- a/cores/esp32/esp32-hal-misc.c +++ b/cores/esp32/esp32-hal-misc.c @@ -23,10 +23,10 @@ #include "esp_timer.h" #ifdef CONFIG_APP_ROLLBACK_ENABLE #include "esp_ota_ops.h" -#endif //CONFIG_APP_ROLLBACK_ENABLE +#endif //CONFIG_APP_ROLLBACK_ENABLE #ifdef CONFIG_BT_ENABLED #include "esp_bt.h" -#endif //CONFIG_BT_ENABLED +#endif //CONFIG_BT_ENABLED #include #include "soc/rtc.h" #if !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32H2) @@ -37,9 +37,9 @@ #include "esp32-hal.h" #include "esp_system.h" -#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ -#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 #include "esp32/rom/rtc.h" #elif CONFIG_IDF_TARGET_ESP32S2 #include "esp32s2/rom/rtc.h" @@ -54,7 +54,7 @@ #elif CONFIG_IDF_TARGET_ESP32H2 #include "esp32h2/rom/rtc.h" -#else +#else #error Target CONFIG_IDF_TARGET is not supported #endif @@ -62,172 +62,163 @@ #include "driver/temperature_sensor.h" #endif -#else // ESP32 Before IDF 4.0 +#else // ESP32 Before IDF 4.0 #include "rom/rtc.h" #endif -//Undocumented!!! Get chip temperature in Farenheit +//Undocumented!!! Get chip temperature in Fahrenheit //Source: https://github.com/pcbreflux/espressif/blob/master/esp32/arduino/sketchbook/ESP32_int_temp_sensor/ESP32_int_temp_sensor.ino #ifdef CONFIG_IDF_TARGET_ESP32 uint8_t temprature_sens_read(); -float temperatureRead() -{ - return (temprature_sens_read() - 32) / 1.8; +float temperatureRead() { + return (temprature_sens_read() - 32) / 1.8; } #elif SOC_TEMP_SENSOR_SUPPORTED static temperature_sensor_handle_t temp_sensor = NULL; -static bool temperatureReadInit() -{ - static volatile bool initialized = false; - if(!initialized){ - initialized = true; - //Install temperature sensor, expected temp ranger range: 10~50 ℃ - temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(10, 50); - if(temperature_sensor_install(&temp_sensor_config, &temp_sensor) != ESP_OK){ - initialized = false; - temp_sensor = NULL; - log_e("temperature_sensor_install failed"); - } - else if(temperature_sensor_enable(temp_sensor) != ESP_OK){ - temperature_sensor_uninstall(temp_sensor); - initialized = false; - temp_sensor = NULL; - log_e("temperature_sensor_enable failed"); - } +static bool temperatureReadInit() { + static volatile bool initialized = false; + if (!initialized) { + initialized = true; + //Install temperature sensor, expected temp ranger range: 10~50 ℃ + temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(10, 50); + if (temperature_sensor_install(&temp_sensor_config, &temp_sensor) != ESP_OK) { + initialized = false; + temp_sensor = NULL; + log_e("temperature_sensor_install failed"); + } else if (temperature_sensor_enable(temp_sensor) != ESP_OK) { + temperature_sensor_uninstall(temp_sensor); + initialized = false; + temp_sensor = NULL; + log_e("temperature_sensor_enable failed"); } - return initialized; + } + return initialized; } -float temperatureRead() -{ - float result = NAN; - if(temperatureReadInit()){ - if(temperature_sensor_get_celsius(temp_sensor, &result) != ESP_OK){ - log_e("temperature_sensor_get_celsius failed"); - } +float temperatureRead() { + float result = NAN; + if (temperatureReadInit()) { + if (temperature_sensor_get_celsius(temp_sensor, &result) != ESP_OK) { + log_e("temperature_sensor_get_celsius failed"); } - return result; + } + return result; } #endif -void __yield() -{ - vPortYield(); +void __yield() { + vPortYield(); } -void yield() __attribute__ ((weak, alias("__yield"))); +void yield() __attribute__((weak, alias("__yield"))); #if CONFIG_AUTOSTART_ARDUINO extern TaskHandle_t loopTaskHandle; extern bool loopTaskWDTEnabled; -void enableLoopWDT(){ - if(loopTaskHandle != NULL){ - if(esp_task_wdt_add(loopTaskHandle) != ESP_OK){ - log_e("Failed to add loop task to WDT"); - } else { - loopTaskWDTEnabled = true; - } +void enableLoopWDT() { + if (loopTaskHandle != NULL) { + if (esp_task_wdt_add(loopTaskHandle) != ESP_OK) { + log_e("Failed to add loop task to WDT"); + } else { + loopTaskWDTEnabled = true; } + } } -void disableLoopWDT(){ - if(loopTaskHandle != NULL && loopTaskWDTEnabled){ - loopTaskWDTEnabled = false; - if(esp_task_wdt_delete(loopTaskHandle) != ESP_OK){ - log_e("Failed to remove loop task from WDT"); - } +void disableLoopWDT() { + if (loopTaskHandle != NULL && loopTaskWDTEnabled) { + loopTaskWDTEnabled = false; + if (esp_task_wdt_delete(loopTaskHandle) != ESP_OK) { + log_e("Failed to remove loop task from WDT"); } + } } -void feedLoopWDT(){ - esp_err_t err = esp_task_wdt_reset(); - if(err != ESP_OK){ - log_e("Failed to feed WDT! Error: %d", err); - } +void feedLoopWDT() { + esp_err_t err = esp_task_wdt_reset(); + if (err != ESP_OK) { + log_e("Failed to feed WDT! Error: %d", err); + } } #endif -void enableCore0WDT(){ - TaskHandle_t idle_0 = xTaskGetIdleTaskHandleForCPU(0); - if(idle_0 == NULL || esp_task_wdt_add(idle_0) != ESP_OK){ - log_e("Failed to add Core 0 IDLE task to WDT"); - } +void enableCore0WDT() { + TaskHandle_t idle_0 = xTaskGetIdleTaskHandleForCPU(0); + if (idle_0 == NULL || esp_task_wdt_add(idle_0) != ESP_OK) { + log_e("Failed to add Core 0 IDLE task to WDT"); + } } -void disableCore0WDT(){ - TaskHandle_t idle_0 = xTaskGetIdleTaskHandleForCPU(0); - if(idle_0 == NULL || esp_task_wdt_delete(idle_0) != ESP_OK){ - log_e("Failed to remove Core 0 IDLE task from WDT"); - } +void disableCore0WDT() { + TaskHandle_t idle_0 = xTaskGetIdleTaskHandleForCPU(0); + if (idle_0 == NULL || esp_task_wdt_delete(idle_0) != ESP_OK) { + log_e("Failed to remove Core 0 IDLE task from WDT"); + } } #ifndef CONFIG_FREERTOS_UNICORE -void enableCore1WDT(){ - TaskHandle_t idle_1 = xTaskGetIdleTaskHandleForCPU(1); - if(idle_1 == NULL || esp_task_wdt_add(idle_1) != ESP_OK){ - log_e("Failed to add Core 1 IDLE task to WDT"); - } +void enableCore1WDT() { + TaskHandle_t idle_1 = xTaskGetIdleTaskHandleForCPU(1); + if (idle_1 == NULL || esp_task_wdt_add(idle_1) != ESP_OK) { + log_e("Failed to add Core 1 IDLE task to WDT"); + } } -void disableCore1WDT(){ - TaskHandle_t idle_1 = xTaskGetIdleTaskHandleForCPU(1); - if(idle_1 == NULL || esp_task_wdt_delete(idle_1) != ESP_OK){ - log_e("Failed to remove Core 1 IDLE task from WDT"); - } +void disableCore1WDT() { + TaskHandle_t idle_1 = xTaskGetIdleTaskHandleForCPU(1); + if (idle_1 == NULL || esp_task_wdt_delete(idle_1) != ESP_OK) { + log_e("Failed to remove Core 1 IDLE task from WDT"); + } } #endif -BaseType_t xTaskCreateUniversal( TaskFunction_t pxTaskCode, - const char * const pcName, - const uint32_t usStackDepth, - void * const pvParameters, - UBaseType_t uxPriority, - TaskHandle_t * const pxCreatedTask, - const BaseType_t xCoreID ){ +BaseType_t xTaskCreateUniversal(TaskFunction_t pxTaskCode, + const char *const pcName, + const uint32_t usStackDepth, + void *const pvParameters, + UBaseType_t uxPriority, + TaskHandle_t *const pxCreatedTask, + const BaseType_t xCoreID) { #ifndef CONFIG_FREERTOS_UNICORE - if(xCoreID >= 0 && xCoreID < 2) { - return xTaskCreatePinnedToCore(pxTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask, xCoreID); - } else { + if (xCoreID >= 0 && xCoreID < 2) { + return xTaskCreatePinnedToCore(pxTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask, xCoreID); + } else { #endif return xTaskCreate(pxTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask); #ifndef CONFIG_FREERTOS_UNICORE - } + } #endif } -unsigned long ARDUINO_ISR_ATTR micros() -{ - return (unsigned long) (esp_timer_get_time()); +unsigned long ARDUINO_ISR_ATTR micros() { + return (unsigned long)(esp_timer_get_time()); } -unsigned long ARDUINO_ISR_ATTR millis() -{ - return (unsigned long) (esp_timer_get_time() / 1000ULL); +unsigned long ARDUINO_ISR_ATTR millis() { + return (unsigned long)(esp_timer_get_time() / 1000ULL); } -void delay(uint32_t ms) -{ - vTaskDelay(ms / portTICK_PERIOD_MS); +void delay(uint32_t ms) { + vTaskDelay(ms / portTICK_PERIOD_MS); } -void ARDUINO_ISR_ATTR delayMicroseconds(uint32_t us) -{ - uint64_t m = (uint64_t)esp_timer_get_time(); - if(us){ - uint64_t e = (m + us); - if(m > e){ //overflow - while((uint64_t)esp_timer_get_time() > e){ - NOP(); - } - } - while((uint64_t)esp_timer_get_time() < e){ - NOP(); - } +void ARDUINO_ISR_ATTR delayMicroseconds(uint32_t us) { + uint64_t m = (uint64_t)esp_timer_get_time(); + if (us) { + uint64_t e = (m + us); + if (m > e) { //overflow + while ((uint64_t)esp_timer_get_time() > e) { + NOP(); + } } + while ((uint64_t)esp_timer_get_time() < e) { + NOP(); + } + } } void initVariant() __attribute__((weak)); @@ -238,90 +229,94 @@ void init() {} #ifdef CONFIG_APP_ROLLBACK_ENABLE bool verifyOta() __attribute__((weak)); -bool verifyOta() { return true; } +bool verifyOta() { + return true; +} bool verifyRollbackLater() __attribute__((weak)); -bool verifyRollbackLater() { return false; } +bool verifyRollbackLater() { + return false; +} #endif #ifdef CONFIG_BT_ENABLED #if CONFIG_IDF_TARGET_ESP32 //overwritten in esp32-hal-bt.c bool btInUse() __attribute__((weak)); -bool btInUse(){ return false; } +bool btInUse() { + return false; +} #else //from esp32-hal-bt.c extern bool btInUse(); #endif #endif -void initArduino() -{ - //init proper ref tick value for PLL (uncomment if REF_TICK is different than 1MHz) - //ESP_REG(APB_CTRL_PLL_TICK_CONF_REG) = APB_CLK_FREQ / REF_CLK_FREQ - 1; +void initArduino() { + //init proper ref tick value for PLL (uncomment if REF_TICK is different than 1MHz) + //ESP_REG(APB_CTRL_PLL_TICK_CONF_REG) = APB_CLK_FREQ / REF_CLK_FREQ - 1; #ifdef F_CPU - setCpuFrequencyMhz(F_CPU/1000000); + setCpuFrequencyMhz(F_CPU / 1000000); #endif #if CONFIG_SPIRAM_SUPPORT || CONFIG_SPIRAM - psramInit(); + psramInit(); #endif #ifdef CONFIG_APP_ROLLBACK_ENABLE - if(!verifyRollbackLater()){ - const esp_partition_t *running = esp_ota_get_running_partition(); - esp_ota_img_states_t ota_state; - if (esp_ota_get_state_partition(running, &ota_state) == ESP_OK) { - if (ota_state == ESP_OTA_IMG_PENDING_VERIFY) { - if (verifyOta()) { - esp_ota_mark_app_valid_cancel_rollback(); - } else { - log_e("OTA verification failed! Start rollback to the previous version ..."); - esp_ota_mark_app_invalid_rollback_and_reboot(); - } - } - } - } -#endif - esp_log_level_set("*", CONFIG_LOG_DEFAULT_LEVEL); - esp_err_t err = nvs_flash_init(); - if(err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND){ - const esp_partition_t* partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, NULL); - if (partition != NULL) { - err = esp_partition_erase_range(partition, 0, partition->size); - if(!err){ - err = nvs_flash_init(); - } else { - log_e("Failed to format the broken NVS partition!"); - } + if (!verifyRollbackLater()) { + const esp_partition_t *running = esp_ota_get_running_partition(); + esp_ota_img_states_t ota_state; + if (esp_ota_get_state_partition(running, &ota_state) == ESP_OK) { + if (ota_state == ESP_OTA_IMG_PENDING_VERIFY) { + if (verifyOta()) { + esp_ota_mark_app_valid_cancel_rollback(); } else { - log_e("Could not find NVS partition"); + log_e("OTA verification failed! Start rollback to the previous version ..."); + esp_ota_mark_app_invalid_rollback_and_reboot(); } + } } - if(err) { - log_e("Failed to initialize NVS! Error: %u", err); + } +#endif + esp_log_level_set("*", CONFIG_LOG_DEFAULT_LEVEL); + esp_err_t err = nvs_flash_init(); + if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) { + const esp_partition_t *partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, NULL); + if (partition != NULL) { + err = esp_partition_erase_range(partition, 0, partition->size); + if (!err) { + err = nvs_flash_init(); + } else { + log_e("Failed to format the broken NVS partition!"); + } + } else { + log_e("Could not find NVS partition"); } + } + if (err) { + log_e("Failed to initialize NVS! Error: %u", err); + } #ifdef CONFIG_BT_ENABLED - if(!btInUse()){ - esp_bt_controller_mem_release(ESP_BT_MODE_BTDM); - } + if (!btInUse()) { + esp_bt_controller_mem_release(ESP_BT_MODE_BTDM); + } #endif - init(); - initVariant(); + init(); + initVariant(); } //used by hal log -const char * ARDUINO_ISR_ATTR pathToFileName(const char * path) -{ - size_t i = 0; - size_t pos = 0; - char * p = (char *)path; - while(*p){ - i++; - if(*p == '/' || *p == '\\'){ - pos = i; - } - p++; +const char *ARDUINO_ISR_ATTR pathToFileName(const char *path) { + size_t i = 0; + size_t pos = 0; + char *p = (char *)path; + while (*p) { + i++; + if (*p == '/' || *p == '\\') { + pos = i; } - return path+pos; + p++; + } + return path + pos; } #include "esp_rom_sys.h" @@ -335,82 +330,81 @@ const char * ARDUINO_ISR_ATTR pathToFileName(const char * path) #include "esp_private/panic_internal.h" static arduino_panic_handler_t _panic_handler = NULL; -static void * _panic_handler_arg = NULL; +static void *_panic_handler_arg = NULL; -void set_arduino_panic_handler(arduino_panic_handler_t handler, void * arg){ - _panic_handler = handler; - _panic_handler_arg = arg; +void set_arduino_panic_handler(arduino_panic_handler_t handler, void *arg) { + _panic_handler = handler; + _panic_handler_arg = arg; } -arduino_panic_handler_t get_arduino_panic_handler(void){ - return _panic_handler; +arduino_panic_handler_t get_arduino_panic_handler(void) { + return _panic_handler; } -void * get_arduino_panic_handler_arg(void){ - return _panic_handler_arg; +void *get_arduino_panic_handler_arg(void) { + return _panic_handler_arg; } -static void handle_custom_backtrace(panic_info_t* info){ - arduino_panic_info_t p_info; - p_info.reason = info->reason; - p_info.core = info->core; - p_info.pc = info->addr; - p_info.backtrace_len = 0; - p_info.backtrace_corrupt = false; - p_info.backtrace_continues = false; +static void handle_custom_backtrace(panic_info_t *info) { + arduino_panic_info_t p_info; + p_info.reason = info->reason; + p_info.core = info->core; + p_info.pc = info->addr; + p_info.backtrace_len = 0; + p_info.backtrace_corrupt = false; + p_info.backtrace_continues = false; #if CONFIG_IDF_TARGET_ARCH_XTENSA - XtExcFrame *xt_frame = (XtExcFrame *) info->frame; - esp_backtrace_frame_t stk_frame = {.pc = xt_frame->pc, .sp = xt_frame->a1, .next_pc = xt_frame->a0, .exc_frame = xt_frame}; - uint32_t i = 100, pc_ptr = esp_cpu_process_stack_pc(stk_frame.pc); - p_info.backtrace[p_info.backtrace_len++] = pc_ptr; - - bool corrupted = !(esp_stack_ptr_is_sane(stk_frame.sp) && - (esp_ptr_executable((void *)esp_cpu_process_stack_pc(stk_frame.pc)) || - /* Ignore the first corrupted PC in case of InstrFetchProhibited */ - (stk_frame.exc_frame && ((XtExcFrame *)stk_frame.exc_frame)->exccause == EXCCAUSE_INSTR_PROHIBITED))); - - while (i-- > 0 && stk_frame.next_pc != 0 && !corrupted) { - if (!esp_backtrace_get_next_frame(&stk_frame)) { - corrupted = true; - } - pc_ptr = esp_cpu_process_stack_pc(stk_frame.pc); - if(esp_ptr_executable((void *)pc_ptr)){ - p_info.backtrace[p_info.backtrace_len++] = pc_ptr; - if(p_info.backtrace_len == 60){ - break; - } - } + XtExcFrame *xt_frame = (XtExcFrame *)info->frame; + esp_backtrace_frame_t stk_frame = { .pc = xt_frame->pc, .sp = xt_frame->a1, .next_pc = xt_frame->a0, .exc_frame = xt_frame }; + uint32_t i = 100, pc_ptr = esp_cpu_process_stack_pc(stk_frame.pc); + p_info.backtrace[p_info.backtrace_len++] = pc_ptr; + + bool corrupted = !(esp_stack_ptr_is_sane(stk_frame.sp) && (esp_ptr_executable((void *)esp_cpu_process_stack_pc(stk_frame.pc)) || + /* Ignore the first corrupted PC in case of InstrFetchProhibited */ + (stk_frame.exc_frame && ((XtExcFrame *)stk_frame.exc_frame)->exccause == EXCCAUSE_INSTR_PROHIBITED))); + + while (i-- > 0 && stk_frame.next_pc != 0 && !corrupted) { + if (!esp_backtrace_get_next_frame(&stk_frame)) { + corrupted = true; } - - if (corrupted) { - p_info.backtrace_corrupt = true; - } else if (stk_frame.next_pc != 0) { - p_info.backtrace_continues = true; + pc_ptr = esp_cpu_process_stack_pc(stk_frame.pc); + if (esp_ptr_executable((void *)pc_ptr)) { + p_info.backtrace[p_info.backtrace_len++] = pc_ptr; + if (p_info.backtrace_len == 60) { + break; + } } + } + + if (corrupted) { + p_info.backtrace_corrupt = true; + } else if (stk_frame.next_pc != 0) { + p_info.backtrace_continues = true; + } #elif CONFIG_IDF_TARGET_ARCH_RISCV - uint32_t sp = (uint32_t)((RvExcFrame *)info->frame)->sp; - p_info.backtrace[p_info.backtrace_len++] = sp; - uint32_t *spptr = (uint32_t *)(sp); - for (int i = 0; i < 256; i++){ - if(esp_ptr_executable((void *)spptr[i])){ - p_info.backtrace[p_info.backtrace_len++] = spptr[i]; - if(p_info.backtrace_len == 60){ - if(i < 255){ - p_info.backtrace_continues = true; - } - break; - } + uint32_t sp = (uint32_t)((RvExcFrame *)info->frame)->sp; + p_info.backtrace[p_info.backtrace_len++] = sp; + uint32_t *spptr = (uint32_t *)(sp); + for (int i = 0; i < 256; i++) { + if (esp_ptr_executable((void *)spptr[i])) { + p_info.backtrace[p_info.backtrace_len++] = spptr[i]; + if (p_info.backtrace_len == 60) { + if (i < 255) { + p_info.backtrace_continues = true; } + break; + } } + } #endif - _panic_handler(&p_info, _panic_handler_arg); + _panic_handler(&p_info, _panic_handler_arg); } -void __real_esp_panic_handler(panic_info_t*); -void __wrap_esp_panic_handler(panic_info_t* info) { - if(_panic_handler != NULL){ - handle_custom_backtrace(info); - } - __real_esp_panic_handler(info); +void __real_esp_panic_handler(panic_info_t *); +void __wrap_esp_panic_handler(panic_info_t *info) { + if (_panic_handler != NULL) { + handle_custom_backtrace(info); + } + __real_esp_panic_handler(info); } diff --git a/cores/esp32/esp32-hal-periman.c b/cores/esp32/esp32-hal-periman.c index dd3a2f32a21..e6fc3e66b71 100644 --- a/cores/esp32/esp32-hal-periman.c +++ b/cores/esp32/esp32-hal-periman.c @@ -9,11 +9,11 @@ #include "esp_bit_defs.h" typedef struct ATTR_PACKED { - peripheral_bus_type_t type; - const char* extra_type; - void * bus; - int8_t bus_num; - int8_t bus_channel; + peripheral_bus_type_t type; + const char* extra_type; + void* bus; + int8_t bus_num; + int8_t bus_channel; } peripheral_pin_item_t; static peripheral_bus_deinit_cb_t deinit_functions[ESP32_BUS_TYPE_MAX]; @@ -22,214 +22,214 @@ static peripheral_pin_item_t pins[SOC_GPIO_PIN_COUNT]; #define GPIO_NOT_VALID(p) ((p >= SOC_GPIO_PIN_COUNT) || ((SOC_GPIO_VALID_GPIO_MASK & (1ULL << p)) == 0)) const char* perimanGetTypeName(peripheral_bus_type_t type) { - switch(type) { - case ESP32_BUS_TYPE_INIT: return "INIT"; - case ESP32_BUS_TYPE_GPIO: return "GPIO"; - case ESP32_BUS_TYPE_UART_RX: return "UART_RX"; - case ESP32_BUS_TYPE_UART_TX: return "UART_TX"; - case ESP32_BUS_TYPE_UART_CTS: return "UART_CTS"; - case ESP32_BUS_TYPE_UART_RTS: return "UART_RTS"; + switch (type) { + case ESP32_BUS_TYPE_INIT: return "INIT"; + case ESP32_BUS_TYPE_GPIO: return "GPIO"; + case ESP32_BUS_TYPE_UART_RX: return "UART_RX"; + case ESP32_BUS_TYPE_UART_TX: return "UART_TX"; + case ESP32_BUS_TYPE_UART_CTS: return "UART_CTS"; + case ESP32_BUS_TYPE_UART_RTS: return "UART_RTS"; #if SOC_SDM_SUPPORTED - case ESP32_BUS_TYPE_SIGMADELTA: return "SIGMADELTA"; + case ESP32_BUS_TYPE_SIGMADELTA: return "SIGMADELTA"; #endif #if SOC_ADC_SUPPORTED - case ESP32_BUS_TYPE_ADC_ONESHOT: return "ADC_ONESHOT"; - case ESP32_BUS_TYPE_ADC_CONT: return "ADC_CONT"; + case ESP32_BUS_TYPE_ADC_ONESHOT: return "ADC_ONESHOT"; + case ESP32_BUS_TYPE_ADC_CONT: return "ADC_CONT"; #endif #if SOC_DAC_SUPPORTED - case ESP32_BUS_TYPE_DAC_ONESHOT: return "DAC_ONESHOT"; - case ESP32_BUS_TYPE_DAC_CONT: return "DAC_CONT"; - case ESP32_BUS_TYPE_DAC_COSINE: return "DAC_COSINE"; + case ESP32_BUS_TYPE_DAC_ONESHOT: return "DAC_ONESHOT"; + case ESP32_BUS_TYPE_DAC_CONT: return "DAC_CONT"; + case ESP32_BUS_TYPE_DAC_COSINE: return "DAC_COSINE"; #endif #if SOC_LEDC_SUPPORTED - case ESP32_BUS_TYPE_LEDC: return "LEDC"; + case ESP32_BUS_TYPE_LEDC: return "LEDC"; #endif #if SOC_RMT_SUPPORTED - case ESP32_BUS_TYPE_RMT_TX: return "RMT_TX"; - case ESP32_BUS_TYPE_RMT_RX: return "RMT_RX"; + case ESP32_BUS_TYPE_RMT_TX: return "RMT_TX"; + case ESP32_BUS_TYPE_RMT_RX: return "RMT_RX"; #endif #if SOC_I2S_SUPPORTED - case ESP32_BUS_TYPE_I2S_STD_MCLK: return "I2S_STD_MCLK"; - case ESP32_BUS_TYPE_I2S_STD_BCLK: return "I2S_STD_BCLK"; - case ESP32_BUS_TYPE_I2S_STD_WS: return "I2S_STD_WS"; - case ESP32_BUS_TYPE_I2S_STD_DOUT: return "I2S_STD_DOUT"; - case ESP32_BUS_TYPE_I2S_STD_DIN: return "I2S_STD_DIN"; - case ESP32_BUS_TYPE_I2S_TDM_MCLK: return "I2S_TDM_MCLK"; - case ESP32_BUS_TYPE_I2S_TDM_BCLK: return "I2S_TDM_BCLK"; - case ESP32_BUS_TYPE_I2S_TDM_WS: return "I2S_TDM_WS"; - case ESP32_BUS_TYPE_I2S_TDM_DOUT: return "I2S_TDM_DOUT"; - case ESP32_BUS_TYPE_I2S_TDM_DIN: return "I2S_TDM_DIN"; - case ESP32_BUS_TYPE_I2S_PDM_TX_CLK: return "I2S_PDM_TX_CLK"; - case ESP32_BUS_TYPE_I2S_PDM_TX_DOUT0: return "I2S_PDM_TX_DOUT0"; - case ESP32_BUS_TYPE_I2S_PDM_TX_DOUT1: return "I2S_PDM_TX_DOUT1"; - case ESP32_BUS_TYPE_I2S_PDM_RX_CLK: return "I2S_PDM_RX_CLK"; - case ESP32_BUS_TYPE_I2S_PDM_RX_DIN0: return "I2S_PDM_RX_DIN0"; - case ESP32_BUS_TYPE_I2S_PDM_RX_DIN1: return "I2S_PDM_RX_DIN1"; - case ESP32_BUS_TYPE_I2S_PDM_RX_DIN2: return "I2S_PDM_RX_DIN2"; - case ESP32_BUS_TYPE_I2S_PDM_RX_DIN3: return "I2S_PDM_RX_DIN3"; + case ESP32_BUS_TYPE_I2S_STD_MCLK: return "I2S_STD_MCLK"; + case ESP32_BUS_TYPE_I2S_STD_BCLK: return "I2S_STD_BCLK"; + case ESP32_BUS_TYPE_I2S_STD_WS: return "I2S_STD_WS"; + case ESP32_BUS_TYPE_I2S_STD_DOUT: return "I2S_STD_DOUT"; + case ESP32_BUS_TYPE_I2S_STD_DIN: return "I2S_STD_DIN"; + case ESP32_BUS_TYPE_I2S_TDM_MCLK: return "I2S_TDM_MCLK"; + case ESP32_BUS_TYPE_I2S_TDM_BCLK: return "I2S_TDM_BCLK"; + case ESP32_BUS_TYPE_I2S_TDM_WS: return "I2S_TDM_WS"; + case ESP32_BUS_TYPE_I2S_TDM_DOUT: return "I2S_TDM_DOUT"; + case ESP32_BUS_TYPE_I2S_TDM_DIN: return "I2S_TDM_DIN"; + case ESP32_BUS_TYPE_I2S_PDM_TX_CLK: return "I2S_PDM_TX_CLK"; + case ESP32_BUS_TYPE_I2S_PDM_TX_DOUT0: return "I2S_PDM_TX_DOUT0"; + case ESP32_BUS_TYPE_I2S_PDM_TX_DOUT1: return "I2S_PDM_TX_DOUT1"; + case ESP32_BUS_TYPE_I2S_PDM_RX_CLK: return "I2S_PDM_RX_CLK"; + case ESP32_BUS_TYPE_I2S_PDM_RX_DIN0: return "I2S_PDM_RX_DIN0"; + case ESP32_BUS_TYPE_I2S_PDM_RX_DIN1: return "I2S_PDM_RX_DIN1"; + case ESP32_BUS_TYPE_I2S_PDM_RX_DIN2: return "I2S_PDM_RX_DIN2"; + case ESP32_BUS_TYPE_I2S_PDM_RX_DIN3: return "I2S_PDM_RX_DIN3"; #endif #if SOC_I2C_SUPPORTED - case ESP32_BUS_TYPE_I2C_MASTER_SDA: return "I2C_MASTER_SDA"; - case ESP32_BUS_TYPE_I2C_MASTER_SCL: return "I2C_MASTER_SCL"; - case ESP32_BUS_TYPE_I2C_SLAVE_SDA: return "I2C_SLAVE_SDA"; - case ESP32_BUS_TYPE_I2C_SLAVE_SCL: return "I2C_SLAVE_SCL"; + case ESP32_BUS_TYPE_I2C_MASTER_SDA: return "I2C_MASTER_SDA"; + case ESP32_BUS_TYPE_I2C_MASTER_SCL: return "I2C_MASTER_SCL"; + case ESP32_BUS_TYPE_I2C_SLAVE_SDA: return "I2C_SLAVE_SDA"; + case ESP32_BUS_TYPE_I2C_SLAVE_SCL: return "I2C_SLAVE_SCL"; #endif #if SOC_GPSPI_SUPPORTED - case ESP32_BUS_TYPE_SPI_MASTER_SCK: return "SPI_MASTER_SCK"; - case ESP32_BUS_TYPE_SPI_MASTER_MISO: return "SPI_MASTER_MISO"; - case ESP32_BUS_TYPE_SPI_MASTER_MOSI: return "SPI_MASTER_MOSI"; - case ESP32_BUS_TYPE_SPI_MASTER_SS: return "SPI_MASTER_SS"; + case ESP32_BUS_TYPE_SPI_MASTER_SCK: return "SPI_MASTER_SCK"; + case ESP32_BUS_TYPE_SPI_MASTER_MISO: return "SPI_MASTER_MISO"; + case ESP32_BUS_TYPE_SPI_MASTER_MOSI: return "SPI_MASTER_MOSI"; + case ESP32_BUS_TYPE_SPI_MASTER_SS: return "SPI_MASTER_SS"; #endif #if SOC_SDMMC_HOST_SUPPORTED - case ESP32_BUS_TYPE_SDMMC_CLK: return "SDMMC_CLK"; - case ESP32_BUS_TYPE_SDMMC_CMD: return "SDMMC_CMD"; - case ESP32_BUS_TYPE_SDMMC_D0: return "SDMMC_D0"; - case ESP32_BUS_TYPE_SDMMC_D1: return "SDMMC_D1"; - case ESP32_BUS_TYPE_SDMMC_D2: return "SDMMC_D2"; - case ESP32_BUS_TYPE_SDMMC_D3: return "SDMMC_D3"; + case ESP32_BUS_TYPE_SDMMC_CLK: return "SDMMC_CLK"; + case ESP32_BUS_TYPE_SDMMC_CMD: return "SDMMC_CMD"; + case ESP32_BUS_TYPE_SDMMC_D0: return "SDMMC_D0"; + case ESP32_BUS_TYPE_SDMMC_D1: return "SDMMC_D1"; + case ESP32_BUS_TYPE_SDMMC_D2: return "SDMMC_D2"; + case ESP32_BUS_TYPE_SDMMC_D3: return "SDMMC_D3"; #endif #if SOC_TOUCH_SENSOR_SUPPORTED - case ESP32_BUS_TYPE_TOUCH: return "TOUCH"; + case ESP32_BUS_TYPE_TOUCH: return "TOUCH"; #endif #if SOC_USB_SERIAL_JTAG_SUPPORTED || SOC_USB_OTG_SUPPORTED - case ESP32_BUS_TYPE_USB_DM: return "USB_DM"; - case ESP32_BUS_TYPE_USB_DP: return "USB_DP"; + case ESP32_BUS_TYPE_USB_DM: return "USB_DM"; + case ESP32_BUS_TYPE_USB_DP: return "USB_DP"; #endif #if SOC_GPSPI_SUPPORTED - case ESP32_BUS_TYPE_ETHERNET_SPI: return "ETHERNET_SPI"; + case ESP32_BUS_TYPE_ETHERNET_SPI: return "ETHERNET_SPI"; #endif #if CONFIG_ETH_USE_ESP32_EMAC - case ESP32_BUS_TYPE_ETHERNET_RMII: return "ETHERNET_RMII"; - case ESP32_BUS_TYPE_ETHERNET_CLK: return "ETHERNET_CLK"; - case ESP32_BUS_TYPE_ETHERNET_MCD: return "ETHERNET_MCD"; - case ESP32_BUS_TYPE_ETHERNET_MDIO: return "ETHERNET_MDIO"; - case ESP32_BUS_TYPE_ETHERNET_PWR: return "ETHERNET_PWR"; + case ESP32_BUS_TYPE_ETHERNET_RMII: return "ETHERNET_RMII"; + case ESP32_BUS_TYPE_ETHERNET_CLK: return "ETHERNET_CLK"; + case ESP32_BUS_TYPE_ETHERNET_MCD: return "ETHERNET_MCD"; + case ESP32_BUS_TYPE_ETHERNET_MDIO: return "ETHERNET_MDIO"; + case ESP32_BUS_TYPE_ETHERNET_PWR: return "ETHERNET_PWR"; #endif - default: return "UNKNOWN"; - } + default: return "UNKNOWN"; + } } -bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus, int8_t bus_num, int8_t bus_channel){ - peripheral_bus_type_t otype = ESP32_BUS_TYPE_INIT; - void * obus = NULL; - if(GPIO_NOT_VALID(pin)){ - log_e("Invalid pin: %u", pin); - return false; - } - if(type >= ESP32_BUS_TYPE_MAX){ - log_e("Invalid type: %s (%u) when setting pin %u", perimanGetTypeName(type), (unsigned int)type, pin); - return false; - } - if(type > ESP32_BUS_TYPE_GPIO && bus == NULL){ - log_e("Bus is NULL for pin %u with type %s (%u)", pin, perimanGetTypeName(type), (unsigned int)type); - return false; - } - if (type == ESP32_BUS_TYPE_INIT && bus != NULL){ - log_e("Can't set a Bus to INIT Type (pin %u)", pin); - return false; - } - otype = pins[pin].type; - obus = pins[pin].bus; - if(type == otype && bus == obus){ - if (type != ESP32_BUS_TYPE_INIT) { - log_i("Pin %u already has type %s (%u) with bus %p", pin, perimanGetTypeName(type), (unsigned int)type, bus); - } - return true; - } - if(obus != NULL){ - if(deinit_functions[otype] == NULL){ - log_e("No deinit function for type %s (%u) (pin %u)", perimanGetTypeName(otype), (unsigned int)otype, pin); - return false; - } - if(!deinit_functions[otype](obus)){ - log_e("Deinit function for previous bus type %s (%u) failed (pin %u)", perimanGetTypeName(otype), (unsigned int)otype, pin); - return false; - } - } - pins[pin].type = type; - pins[pin].bus = bus; - pins[pin].bus_num = bus_num; - pins[pin].bus_channel = bus_channel; - pins[pin].extra_type = NULL; - log_v("Pin %u successfully set to type %s (%u) with bus %p", pin, perimanGetTypeName(type), (unsigned int)type, bus); - return true; +bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void* bus, int8_t bus_num, int8_t bus_channel) { + peripheral_bus_type_t otype = ESP32_BUS_TYPE_INIT; + void* obus = NULL; + if (GPIO_NOT_VALID(pin)) { + log_e("Invalid pin: %u", pin); + return false; + } + if (type >= ESP32_BUS_TYPE_MAX) { + log_e("Invalid type: %s (%u) when setting pin %u", perimanGetTypeName(type), (unsigned int)type, pin); + return false; + } + if (type > ESP32_BUS_TYPE_GPIO && bus == NULL) { + log_e("Bus is NULL for pin %u with type %s (%u)", pin, perimanGetTypeName(type), (unsigned int)type); + return false; + } + if (type == ESP32_BUS_TYPE_INIT && bus != NULL) { + log_e("Can't set a Bus to INIT Type (pin %u)", pin); + return false; + } + otype = pins[pin].type; + obus = pins[pin].bus; + if (type == otype && bus == obus) { + if (type != ESP32_BUS_TYPE_INIT) { + log_i("Pin %u already has type %s (%u) with bus %p", pin, perimanGetTypeName(type), (unsigned int)type, bus); + } + return true; + } + if (obus != NULL) { + if (deinit_functions[otype] == NULL) { + log_e("No deinit function for type %s (%u) (pin %u)", perimanGetTypeName(otype), (unsigned int)otype, pin); + return false; + } + if (!deinit_functions[otype](obus)) { + log_e("Deinit function for previous bus type %s (%u) failed (pin %u)", perimanGetTypeName(otype), (unsigned int)otype, pin); + return false; + } + } + pins[pin].type = type; + pins[pin].bus = bus; + pins[pin].bus_num = bus_num; + pins[pin].bus_channel = bus_channel; + pins[pin].extra_type = NULL; + log_v("Pin %u successfully set to type %s (%u) with bus %p", pin, perimanGetTypeName(type), (unsigned int)type, bus); + return true; } -bool perimanSetPinBusExtraType(uint8_t pin, const char* extra_type){ - if(GPIO_NOT_VALID(pin)){ - log_e("Invalid pin: %u", pin); - return false; - } - if (pins[pin].type == ESP32_BUS_TYPE_INIT) { - log_e("Can't set extra type for Bus INIT Type (pin %u)", pin); - return false; - } - pins[pin].extra_type = extra_type; - log_v("Successfully set extra_type %s for pin %u", extra_type, pin); - return true; +bool perimanSetPinBusExtraType(uint8_t pin, const char* extra_type) { + if (GPIO_NOT_VALID(pin)) { + log_e("Invalid pin: %u", pin); + return false; + } + if (pins[pin].type == ESP32_BUS_TYPE_INIT) { + log_e("Can't set extra type for Bus INIT Type (pin %u)", pin); + return false; + } + pins[pin].extra_type = extra_type; + log_v("Successfully set extra_type %s for pin %u", extra_type, pin); + return true; } -void * perimanGetPinBus(uint8_t pin, peripheral_bus_type_t type){ - if(GPIO_NOT_VALID(pin)){ - log_e("Invalid pin: %u", pin); - return NULL; - } - if(type >= ESP32_BUS_TYPE_MAX || type == ESP32_BUS_TYPE_INIT){ - log_e("Invalid type %s (%u) for pin %u", perimanGetTypeName(type), (unsigned int)type, pin); - return NULL; - } - if(pins[pin].type == type){ - return pins[pin].bus; - } - return NULL; +void* perimanGetPinBus(uint8_t pin, peripheral_bus_type_t type) { + if (GPIO_NOT_VALID(pin)) { + log_e("Invalid pin: %u", pin); + return NULL; + } + if (type >= ESP32_BUS_TYPE_MAX || type == ESP32_BUS_TYPE_INIT) { + log_e("Invalid type %s (%u) for pin %u", perimanGetTypeName(type), (unsigned int)type, pin); + return NULL; + } + if (pins[pin].type == type) { + return pins[pin].bus; + } + return NULL; } -peripheral_bus_type_t perimanGetPinBusType(uint8_t pin){ - if(GPIO_NOT_VALID(pin)){ - log_e("Invalid pin: %u", pin); - return ESP32_BUS_TYPE_MAX; - } - return pins[pin].type; +peripheral_bus_type_t perimanGetPinBusType(uint8_t pin) { + if (GPIO_NOT_VALID(pin)) { + log_e("Invalid pin: %u", pin); + return ESP32_BUS_TYPE_MAX; + } + return pins[pin].type; } -const char* perimanGetPinBusExtraType(uint8_t pin){ - if(GPIO_NOT_VALID(pin)){ - log_e("Invalid pin: %u", pin); - return NULL; - } - return pins[pin].extra_type; +const char* perimanGetPinBusExtraType(uint8_t pin) { + if (GPIO_NOT_VALID(pin)) { + log_e("Invalid pin: %u", pin); + return NULL; + } + return pins[pin].extra_type; } -int8_t perimanGetPinBusNum(uint8_t pin){ - if(GPIO_NOT_VALID(pin)){ - log_e("Invalid pin: %u", pin); - return -1; - } - return pins[pin].bus_num; +int8_t perimanGetPinBusNum(uint8_t pin) { + if (GPIO_NOT_VALID(pin)) { + log_e("Invalid pin: %u", pin); + return -1; + } + return pins[pin].bus_num; } -int8_t perimanGetPinBusChannel(uint8_t pin){ - if(GPIO_NOT_VALID(pin)){ - log_e("Invalid pin: %u", pin); - return -1; - } - return pins[pin].bus_channel; +int8_t perimanGetPinBusChannel(uint8_t pin) { + if (GPIO_NOT_VALID(pin)) { + log_e("Invalid pin: %u", pin); + return -1; + } + return pins[pin].bus_channel; } -bool perimanSetBusDeinit(peripheral_bus_type_t type, peripheral_bus_deinit_cb_t cb){ - if(type >= ESP32_BUS_TYPE_MAX || type == ESP32_BUS_TYPE_INIT){ - log_e("Invalid type: %s (%u)", perimanGetTypeName(type), (unsigned int)type); - return false; - } - if(cb == NULL){ - log_e("Callback is NULL when setting deinit function for type %s (%u)", perimanGetTypeName(type), (unsigned int)type); - return false; - } - deinit_functions[type] = cb; - log_v("Deinit function for type %s (%u) successfully set to %p", perimanGetTypeName(type), (unsigned int)type, cb); - return true; +bool perimanSetBusDeinit(peripheral_bus_type_t type, peripheral_bus_deinit_cb_t cb) { + if (type >= ESP32_BUS_TYPE_MAX || type == ESP32_BUS_TYPE_INIT) { + log_e("Invalid type: %s (%u)", perimanGetTypeName(type), (unsigned int)type); + return false; + } + if (cb == NULL) { + log_e("Callback is NULL when setting deinit function for type %s (%u)", perimanGetTypeName(type), (unsigned int)type); + return false; + } + deinit_functions[type] = cb; + log_v("Deinit function for type %s (%u) successfully set to %p", perimanGetTypeName(type), (unsigned int)type, cb); + return true; } -bool perimanPinIsValid(uint8_t pin){ - return !(GPIO_NOT_VALID(pin)); +bool perimanPinIsValid(uint8_t pin) { + return !(GPIO_NOT_VALID(pin)); } diff --git a/cores/esp32/esp32-hal-periman.h b/cores/esp32/esp32-hal-periman.h index aa3de699502..989795d8ade 100644 --- a/cores/esp32/esp32-hal-periman.h +++ b/cores/esp32/esp32-hal-periman.h @@ -7,8 +7,7 @@ #pragma once #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif #include "soc/soc_caps.h" @@ -18,125 +17,125 @@ extern "C" #define perimanClearPinBus(p) perimanSetPinBus(p, ESP32_BUS_TYPE_INIT, NULL, -1, -1) -typedef enum { - ESP32_BUS_TYPE_INIT, // IO has not been attached to a bus yet - ESP32_BUS_TYPE_GPIO, // IO is used as GPIO - ESP32_BUS_TYPE_UART_RX, // IO is used as UART RX pin - ESP32_BUS_TYPE_UART_TX, // IO is used as UART TX pin - ESP32_BUS_TYPE_UART_CTS, // IO is used as UART CTS pin - ESP32_BUS_TYPE_UART_RTS, // IO is used as UART RTS pin + typedef enum { + ESP32_BUS_TYPE_INIT, // IO has not been attached to a bus yet + ESP32_BUS_TYPE_GPIO, // IO is used as GPIO + ESP32_BUS_TYPE_UART_RX, // IO is used as UART RX pin + ESP32_BUS_TYPE_UART_TX, // IO is used as UART TX pin + ESP32_BUS_TYPE_UART_CTS, // IO is used as UART CTS pin + ESP32_BUS_TYPE_UART_RTS, // IO is used as UART RTS pin #if SOC_SDM_SUPPORTED - ESP32_BUS_TYPE_SIGMADELTA, // IO is used as SigmeDelta output + ESP32_BUS_TYPE_SIGMADELTA, // IO is used as SigmeDelta output #endif #if SOC_ADC_SUPPORTED - ESP32_BUS_TYPE_ADC_ONESHOT, // IO is used as ADC OneShot input - ESP32_BUS_TYPE_ADC_CONT, // IO is used as ADC continuous input + ESP32_BUS_TYPE_ADC_ONESHOT, // IO is used as ADC OneShot input + ESP32_BUS_TYPE_ADC_CONT, // IO is used as ADC continuous input #endif #if SOC_DAC_SUPPORTED - ESP32_BUS_TYPE_DAC_ONESHOT, // IO is used as DAC OneShot output - ESP32_BUS_TYPE_DAC_CONT, // IO is used as DAC continuous output - ESP32_BUS_TYPE_DAC_COSINE, // IO is used as DAC cosine output + ESP32_BUS_TYPE_DAC_ONESHOT, // IO is used as DAC OneShot output + ESP32_BUS_TYPE_DAC_CONT, // IO is used as DAC continuous output + ESP32_BUS_TYPE_DAC_COSINE, // IO is used as DAC cosine output #endif #if SOC_LEDC_SUPPORTED - ESP32_BUS_TYPE_LEDC, // IO is used as LEDC output + ESP32_BUS_TYPE_LEDC, // IO is used as LEDC output #endif #if SOC_RMT_SUPPORTED - ESP32_BUS_TYPE_RMT_TX, // IO is used as RMT output - ESP32_BUS_TYPE_RMT_RX, // IO is used as RMT input + ESP32_BUS_TYPE_RMT_TX, // IO is used as RMT output + ESP32_BUS_TYPE_RMT_RX, // IO is used as RMT input #endif #if SOC_I2S_SUPPORTED - ESP32_BUS_TYPE_I2S_STD_MCLK, // IO is used as I2S STD MCLK pin - ESP32_BUS_TYPE_I2S_STD_BCLK, // IO is used as I2S STD BCLK pin - ESP32_BUS_TYPE_I2S_STD_WS, // IO is used as I2S STD WS pin - ESP32_BUS_TYPE_I2S_STD_DOUT, // IO is used as I2S STD DOUT pin - ESP32_BUS_TYPE_I2S_STD_DIN, // IO is used as I2S STD DIN pin - - ESP32_BUS_TYPE_I2S_TDM_MCLK, // IO is used as I2S TDM MCLK pin - ESP32_BUS_TYPE_I2S_TDM_BCLK, // IO is used as I2S TDM BCLK pin - ESP32_BUS_TYPE_I2S_TDM_WS, // IO is used as I2S TDM WS pin - ESP32_BUS_TYPE_I2S_TDM_DOUT, // IO is used as I2S TDM DOUT pin - ESP32_BUS_TYPE_I2S_TDM_DIN, // IO is used as I2S TDM DIN pin - - ESP32_BUS_TYPE_I2S_PDM_TX_CLK, // IO is used as I2S PDM CLK pin - ESP32_BUS_TYPE_I2S_PDM_TX_DOUT0,// IO is used as I2S PDM DOUT0 pin - ESP32_BUS_TYPE_I2S_PDM_TX_DOUT1,// IO is used as I2S PDM DOUT1 pin - - ESP32_BUS_TYPE_I2S_PDM_RX_CLK, // IO is used as I2S PDM CLK pin - ESP32_BUS_TYPE_I2S_PDM_RX_DIN0, // IO is used as I2S PDM DIN0 pin - ESP32_BUS_TYPE_I2S_PDM_RX_DIN1, // IO is used as I2S PDM DIN1 pin - ESP32_BUS_TYPE_I2S_PDM_RX_DIN2, // IO is used as I2S PDM DIN2 pin - ESP32_BUS_TYPE_I2S_PDM_RX_DIN3, // IO is used as I2S PDM DIN3 pin + ESP32_BUS_TYPE_I2S_STD_MCLK, // IO is used as I2S STD MCLK pin + ESP32_BUS_TYPE_I2S_STD_BCLK, // IO is used as I2S STD BCLK pin + ESP32_BUS_TYPE_I2S_STD_WS, // IO is used as I2S STD WS pin + ESP32_BUS_TYPE_I2S_STD_DOUT, // IO is used as I2S STD DOUT pin + ESP32_BUS_TYPE_I2S_STD_DIN, // IO is used as I2S STD DIN pin + + ESP32_BUS_TYPE_I2S_TDM_MCLK, // IO is used as I2S TDM MCLK pin + ESP32_BUS_TYPE_I2S_TDM_BCLK, // IO is used as I2S TDM BCLK pin + ESP32_BUS_TYPE_I2S_TDM_WS, // IO is used as I2S TDM WS pin + ESP32_BUS_TYPE_I2S_TDM_DOUT, // IO is used as I2S TDM DOUT pin + ESP32_BUS_TYPE_I2S_TDM_DIN, // IO is used as I2S TDM DIN pin + + ESP32_BUS_TYPE_I2S_PDM_TX_CLK, // IO is used as I2S PDM CLK pin + ESP32_BUS_TYPE_I2S_PDM_TX_DOUT0, // IO is used as I2S PDM DOUT0 pin + ESP32_BUS_TYPE_I2S_PDM_TX_DOUT1, // IO is used as I2S PDM DOUT1 pin + + ESP32_BUS_TYPE_I2S_PDM_RX_CLK, // IO is used as I2S PDM CLK pin + ESP32_BUS_TYPE_I2S_PDM_RX_DIN0, // IO is used as I2S PDM DIN0 pin + ESP32_BUS_TYPE_I2S_PDM_RX_DIN1, // IO is used as I2S PDM DIN1 pin + ESP32_BUS_TYPE_I2S_PDM_RX_DIN2, // IO is used as I2S PDM DIN2 pin + ESP32_BUS_TYPE_I2S_PDM_RX_DIN3, // IO is used as I2S PDM DIN3 pin #endif #if SOC_I2C_SUPPORTED - ESP32_BUS_TYPE_I2C_MASTER_SDA, // IO is used as I2C master SDA pin - ESP32_BUS_TYPE_I2C_MASTER_SCL, // IO is used as I2C master SCL pin - ESP32_BUS_TYPE_I2C_SLAVE_SDA, // IO is used as I2C slave SDA pin - ESP32_BUS_TYPE_I2C_SLAVE_SCL, // IO is used as I2C slave SCL pin + ESP32_BUS_TYPE_I2C_MASTER_SDA, // IO is used as I2C master SDA pin + ESP32_BUS_TYPE_I2C_MASTER_SCL, // IO is used as I2C master SCL pin + ESP32_BUS_TYPE_I2C_SLAVE_SDA, // IO is used as I2C slave SDA pin + ESP32_BUS_TYPE_I2C_SLAVE_SCL, // IO is used as I2C slave SCL pin #endif #if SOC_GPSPI_SUPPORTED - ESP32_BUS_TYPE_SPI_MASTER_SCK, // IO is used as SPI master SCK pin - ESP32_BUS_TYPE_SPI_MASTER_MISO, // IO is used as SPI master MISO pin - ESP32_BUS_TYPE_SPI_MASTER_MOSI, // IO is used as SPI master MOSI pin - ESP32_BUS_TYPE_SPI_MASTER_SS, // IO is used as SPI master SS pin + ESP32_BUS_TYPE_SPI_MASTER_SCK, // IO is used as SPI master SCK pin + ESP32_BUS_TYPE_SPI_MASTER_MISO, // IO is used as SPI master MISO pin + ESP32_BUS_TYPE_SPI_MASTER_MOSI, // IO is used as SPI master MOSI pin + ESP32_BUS_TYPE_SPI_MASTER_SS, // IO is used as SPI master SS pin #endif #if SOC_SDMMC_HOST_SUPPORTED - ESP32_BUS_TYPE_SDMMC_CLK, // IO is used as SDMMC CLK pin - ESP32_BUS_TYPE_SDMMC_CMD, // IO is used as SDMMC CMD pin - ESP32_BUS_TYPE_SDMMC_D0, // IO is used as SDMMC D0 pin - ESP32_BUS_TYPE_SDMMC_D1, // IO is used as SDMMC D1 pin - ESP32_BUS_TYPE_SDMMC_D2, // IO is used as SDMMC D2 pin - ESP32_BUS_TYPE_SDMMC_D3, // IO is used as SDMMC D3 pin + ESP32_BUS_TYPE_SDMMC_CLK, // IO is used as SDMMC CLK pin + ESP32_BUS_TYPE_SDMMC_CMD, // IO is used as SDMMC CMD pin + ESP32_BUS_TYPE_SDMMC_D0, // IO is used as SDMMC D0 pin + ESP32_BUS_TYPE_SDMMC_D1, // IO is used as SDMMC D1 pin + ESP32_BUS_TYPE_SDMMC_D2, // IO is used as SDMMC D2 pin + ESP32_BUS_TYPE_SDMMC_D3, // IO is used as SDMMC D3 pin #endif #if SOC_TOUCH_SENSOR_SUPPORTED - ESP32_BUS_TYPE_TOUCH, // IO is used as TOUCH pin + ESP32_BUS_TYPE_TOUCH, // IO is used as TOUCH pin #endif #if SOC_USB_SERIAL_JTAG_SUPPORTED || SOC_USB_OTG_SUPPORTED - ESP32_BUS_TYPE_USB_DM, // IO is used as USB DM (+) pin - ESP32_BUS_TYPE_USB_DP, // IO is used as USB DP (-) pin + ESP32_BUS_TYPE_USB_DM, // IO is used as USB DM (+) pin + ESP32_BUS_TYPE_USB_DP, // IO is used as USB DP (-) pin #endif #if SOC_GPSPI_SUPPORTED - ESP32_BUS_TYPE_ETHERNET_SPI, // IO is used as ETHERNET SPI pin + ESP32_BUS_TYPE_ETHERNET_SPI, // IO is used as ETHERNET SPI pin #endif #if CONFIG_ETH_USE_ESP32_EMAC - ESP32_BUS_TYPE_ETHERNET_RMII, // IO is used as ETHERNET RMII pin - ESP32_BUS_TYPE_ETHERNET_CLK, // IO is used as ETHERNET CLK pin - ESP32_BUS_TYPE_ETHERNET_MCD, // IO is used as ETHERNET MCD pin - ESP32_BUS_TYPE_ETHERNET_MDIO, // IO is used as ETHERNET MDIO pin - ESP32_BUS_TYPE_ETHERNET_PWR, // IO is used as ETHERNET PWR pin + ESP32_BUS_TYPE_ETHERNET_RMII, // IO is used as ETHERNET RMII pin + ESP32_BUS_TYPE_ETHERNET_CLK, // IO is used as ETHERNET CLK pin + ESP32_BUS_TYPE_ETHERNET_MCD, // IO is used as ETHERNET MCD pin + ESP32_BUS_TYPE_ETHERNET_MDIO, // IO is used as ETHERNET MDIO pin + ESP32_BUS_TYPE_ETHERNET_PWR, // IO is used as ETHERNET PWR pin #endif - ESP32_BUS_TYPE_MAX -} peripheral_bus_type_t; + ESP32_BUS_TYPE_MAX + } peripheral_bus_type_t; -typedef bool (*peripheral_bus_deinit_cb_t)(void * bus); + typedef bool (*peripheral_bus_deinit_cb_t)(void* bus); -const char* perimanGetTypeName(peripheral_bus_type_t type); + const char* perimanGetTypeName(peripheral_bus_type_t type); -// Sets the bus type, bus handle, bus number and bus channel for given pin. -bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void * bus, int8_t bus_num, int8_t bus_channel); + // Sets the bus type, bus handle, bus number and bus channel for given pin. + bool perimanSetPinBus(uint8_t pin, peripheral_bus_type_t type, void* bus, int8_t bus_num, int8_t bus_channel); -// Returns handle of the bus for the given pin if type of bus matches. NULL otherwise -void * perimanGetPinBus(uint8_t pin, peripheral_bus_type_t type); + // Returns handle of the bus for the given pin if type of bus matches. NULL otherwise + void* perimanGetPinBus(uint8_t pin, peripheral_bus_type_t type); -// Returns the type of the bus for the given pin if attached. ESP32_BUS_TYPE_MAX otherwise -peripheral_bus_type_t perimanGetPinBusType(uint8_t pin); + // Returns the type of the bus for the given pin if attached. ESP32_BUS_TYPE_MAX otherwise + peripheral_bus_type_t perimanGetPinBusType(uint8_t pin); -// Returns the bus number or unit of the bus for the given pin if set. -1 otherwise -int8_t perimanGetPinBusNum(uint8_t pin); + // Returns the bus number or unit of the bus for the given pin if set. -1 otherwise + int8_t perimanGetPinBusNum(uint8_t pin); -// Returns the bus channel of the bus for the given pin if set. -1 otherwise -int8_t perimanGetPinBusChannel(uint8_t pin); + // Returns the bus channel of the bus for the given pin if set. -1 otherwise + int8_t perimanGetPinBusChannel(uint8_t pin); -// Sets the peripheral destructor callback. Used to destroy bus when pin is assigned another function -bool perimanSetBusDeinit(peripheral_bus_type_t type, peripheral_bus_deinit_cb_t cb); + // Sets the peripheral destructor callback. Used to destroy bus when pin is assigned another function + bool perimanSetBusDeinit(peripheral_bus_type_t type, peripheral_bus_deinit_cb_t cb); -// Check if given pin is a valid GPIO number -bool perimanPinIsValid(uint8_t pin); + // Check if given pin is a valid GPIO number + bool perimanPinIsValid(uint8_t pin); -// Sets the extra type for non Init bus. Used to customise pin bus name which can be printed by printPerimanInfo(). -bool perimanSetPinBusExtraType(uint8_t pin, const char* extra_type); + // Sets the extra type for non Init bus. Used to customize pin bus name which can be printed by printPerimanInfo(). + bool perimanSetPinBusExtraType(uint8_t pin, const char* extra_type); -// Returns the extra type of the bus for given pin if set. NULL otherwise -const char* perimanGetPinBusExtraType(uint8_t pin); + // Returns the extra type of the bus for given pin if set. NULL otherwise + const char* perimanGetPinBusExtraType(uint8_t pin); #ifdef __cplusplus } diff --git a/cores/esp32/esp32-hal-psram.c b/cores/esp32/esp32-hal-psram.c index 0fda6e0d74d..55acba2aa85 100644 --- a/cores/esp32/esp32-hal-psram.c +++ b/cores/esp32/esp32-hal-psram.c @@ -21,13 +21,13 @@ #include "esp_system.h" #include "esp_psram.h" #include "esp_private/esp_psram_extram.h" -#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 #include "esp32/rom/cache.h" #elif CONFIG_IDF_TARGET_ESP32S2 #include "esp32s2/rom/cache.h" #elif CONFIG_IDF_TARGET_ESP32S3 #include "esp32s3/rom/cache.h" -#else +#else #error Target CONFIG_IDF_TARGET is not supported #endif @@ -35,110 +35,109 @@ static volatile bool spiramDetected = false; static volatile bool spiramFailed = false; //allows user to bypass SPI RAM test routine -__attribute__((weak)) bool testSPIRAM(void) -{ - return esp_psram_extram_test(); +__attribute__((weak)) bool testSPIRAM(void) { + return esp_psram_extram_test(); } -bool psramInit(){ - if (spiramDetected) { - return true; - } +bool psramInit() { + if (spiramDetected) { + return true; + } #ifndef CONFIG_SPIRAM_BOOT_INIT - if (spiramFailed) { - return false; - } + if (spiramFailed) { + return false; + } #if CONFIG_IDF_TARGET_ESP32 - uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_PACKAGE); - uint32_t pkg_ver = chip_ver & 0x7; - if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 || pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2) { - spiramFailed = true; - log_w("PSRAM not supported!"); - return false; - } + uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_PACKAGE); + uint32_t pkg_ver = chip_ver & 0x7; + if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 || pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2) { + spiramFailed = true; + log_w("PSRAM not supported!"); + return false; + } #elif CONFIG_IDF_TARGET_ESP32S2 - extern void esp_config_data_cache_mode(void); - esp_config_data_cache_mode(); - Cache_Enable_DCache(0); + extern void esp_config_data_cache_mode(void); + esp_config_data_cache_mode(); + Cache_Enable_DCache(0); #endif - if (esp_psram_init() != ESP_OK) { - spiramFailed = true; - log_w("PSRAM init failed!"); + if (esp_psram_init() != ESP_OK) { + spiramFailed = true; + log_w("PSRAM init failed!"); #if CONFIG_IDF_TARGET_ESP32 - if (pkg_ver != EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4) { - pinMatrixOutDetach(16, false, false); - pinMatrixOutDetach(17, false, false); - } -#endif - return false; - } - - //testSPIRAM() allows user to bypass SPI RAM test routine - if (!testSPIRAM()) { - spiramFailed = true; - log_e("PSRAM test failed!"); - return false; - } - if (esp_psram_extram_add_to_heap_allocator() != ESP_OK) { - spiramFailed = true; - log_e("PSRAM could not be added to the heap!"); - return false; + if (pkg_ver != EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4) { + pinMatrixOutDetach(16, false, false); + pinMatrixOutDetach(17, false, false); } +#endif + return false; + } + + //testSPIRAM() allows user to bypass SPI RAM test routine + if (!testSPIRAM()) { + spiramFailed = true; + log_e("PSRAM test failed!"); + return false; + } + if (esp_psram_extram_add_to_heap_allocator() != ESP_OK) { + spiramFailed = true; + log_e("PSRAM could not be added to the heap!"); + return false; + } #if CONFIG_SPIRAM_USE_MALLOC && !CONFIG_ARDUINO_ISR_IRAM - heap_caps_malloc_extmem_enable(CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL); + heap_caps_malloc_extmem_enable(CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL); #endif #endif /* CONFIG_SPIRAM_BOOT_INIT */ - log_i("PSRAM enabled"); - spiramDetected = true; - return true; + log_i("PSRAM enabled"); + spiramDetected = true; + return true; } -bool ARDUINO_ISR_ATTR psramFound(){ - return spiramDetected; +bool ARDUINO_ISR_ATTR psramFound() { + return spiramDetected; } -void ARDUINO_ISR_ATTR *ps_malloc(size_t size){ - if(!spiramDetected){ - return NULL; - } - return heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); +void ARDUINO_ISR_ATTR *ps_malloc(size_t size) { + if (!spiramDetected) { + return NULL; + } + return heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); } -void ARDUINO_ISR_ATTR *ps_calloc(size_t n, size_t size){ - if(!spiramDetected){ - return NULL; - } - return heap_caps_calloc(n, size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); +void ARDUINO_ISR_ATTR *ps_calloc(size_t n, size_t size) { + if (!spiramDetected) { + return NULL; + } + return heap_caps_calloc(n, size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); } -void ARDUINO_ISR_ATTR *ps_realloc(void *ptr, size_t size){ - if(!spiramDetected){ - return NULL; - } - return heap_caps_realloc(ptr, size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); +void ARDUINO_ISR_ATTR *ps_realloc(void *ptr, size_t size) { + if (!spiramDetected) { + return NULL; + } + return heap_caps_realloc(ptr, size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); } #else -bool psramInit(){ - return false; +bool psramInit() { + return false; } -bool ARDUINO_ISR_ATTR psramFound(){ - return false; +bool ARDUINO_ISR_ATTR psramFound() { + return false; } -void ARDUINO_ISR_ATTR *ps_malloc(size_t size){ - return NULL; +void ARDUINO_ISR_ATTR *ps_malloc(size_t size) { + return NULL; } -void ARDUINO_ISR_ATTR *ps_calloc(size_t n, size_t size){ - return NULL; +void ARDUINO_ISR_ATTR *ps_calloc(size_t n, size_t size) { + return NULL; } -void ARDUINO_ISR_ATTR *ps_realloc(void *ptr, size_t size){ - return NULL; +void ARDUINO_ISR_ATTR *ps_realloc(void *ptr, size_t size) { + return NULL; } #endif diff --git a/cores/esp32/esp32-hal-psram.h b/cores/esp32/esp32-hal-psram.h index 0ba6763c69f..0d4fba22c39 100644 --- a/cores/esp32/esp32-hal-psram.h +++ b/cores/esp32/esp32-hal-psram.h @@ -30,12 +30,12 @@ extern "C" { #endif #endif -bool psramInit(); -bool psramFound(); + bool psramInit(); + bool psramFound(); -void *ps_malloc(size_t size); -void *ps_calloc(size_t n, size_t size); -void *ps_realloc(void *ptr, size_t size); + void *ps_malloc(size_t size); + void *ps_calloc(size_t n, size_t size); + void *ps_realloc(void *ptr, size_t size); #ifdef __cplusplus } diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index 5bd98612151..d221a944351 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -3,7 +3,7 @@ #include "esp32-hal-rgb-led.h" -void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val){ +void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val) { #if SOC_RMT_SUPPORTED rmt_data_t led_data[24]; @@ -16,28 +16,28 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue return; } - int color[] = {green_val, red_val, blue_val}; // Color coding is in order GREEN, RED, BLUE + int color[] = { green_val, red_val, blue_val }; // Color coding is in order GREEN, RED, BLUE int i = 0; - for (int col = 0; col < 3; col++ ) { + for (int col = 0; col < 3; col++) { for (int bit = 0; bit < 8; bit++) { if ((color[col] & (1 << (7 - bit)))) { // HIGH bit - led_data[i].level0 = 1; // T1H - led_data[i].duration0 = 8; // 0.8us - led_data[i].level1 = 0; // T1L - led_data[i].duration1 = 4; // 0.4us + led_data[i].level0 = 1; // T1H + led_data[i].duration0 = 8; // 0.8us + led_data[i].level1 = 0; // T1L + led_data[i].duration1 = 4; // 0.4us } else { // LOW bit - led_data[i].level0 = 1; // T0H - led_data[i].duration0 = 4; // 0.4us - led_data[i].level1 = 0; // T0L - led_data[i].duration1 = 8; // 0.8us + led_data[i].level0 = 1; // T0H + led_data[i].duration0 = 4; // 0.4us + led_data[i].level1 = 0; // T0L + led_data[i].duration1 = 8; // 0.8us } i++; } } rmtWrite(pin, led_data, RMT_SYMBOLS_OF(led_data), RMT_WAIT_FOR_EVER); #else - log_e("RMT is not supported on " CONFIG_IDF_TARGET); + log_e("RMT is not supported on " CONFIG_IDF_TARGET); #endif /* SOC_RMT_SUPPORTED */ } diff --git a/cores/esp32/esp32-hal-rgb-led.h b/cores/esp32/esp32-hal-rgb-led.h index f3539a22513..0c40f53a6d5 100644 --- a/cores/esp32/esp32-hal-rgb-led.h +++ b/cores/esp32/esp32-hal-rgb-led.h @@ -8,13 +8,13 @@ extern "C" { #include "esp32-hal.h" #ifndef RGB_BRIGHTNESS - #define RGB_BRIGHTNESS 64 +#define RGB_BRIGHTNESS 64 #endif -void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val); + void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val); #ifdef __cplusplus } #endif -#endif /* MAIN_ESP32_HAL_RGB_LED_H_ */ \ No newline at end of file +#endif /* MAIN_ESP32_HAL_RGB_LED_H_ */ diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 0755dc43ecd..7fd0d376312 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -37,35 +37,37 @@ extern TaskHandle_t loopTaskHandle; */ #if CONFIG_DISABLE_HAL_LOCKS -# define RMT_MUTEX_LOCK(busptr) -# define RMT_MUTEX_UNLOCK(busptr) +#define RMT_MUTEX_LOCK(busptr) +#define RMT_MUTEX_UNLOCK(busptr) #else -# define RMT_MUTEX_LOCK(busptr) do {} while (xSemaphoreTake(busptr->g_rmt_objlocks, portMAX_DELAY) != pdPASS) -# define RMT_MUTEX_UNLOCK(busptr) xSemaphoreGive(busptr->g_rmt_objlocks) +#define RMT_MUTEX_LOCK(busptr) \ + do { \ + } while (xSemaphoreTake(busptr->g_rmt_objlocks, portMAX_DELAY) != pdPASS) +#define RMT_MUTEX_UNLOCK(busptr) xSemaphoreGive(busptr->g_rmt_objlocks) #endif /* CONFIG_DISABLE_HAL_LOCKS */ /** - Typedefs for internal stuctures, enums + Typedefs for internal structures, enums */ struct rmt_obj_s { // general RMT information - rmt_channel_handle_t rmt_channel_h; // IDF RMT channel handler - rmt_encoder_handle_t rmt_copy_encoder_h; // RMT simple copy encoder handle + rmt_channel_handle_t rmt_channel_h; // IDF RMT channel handler + rmt_encoder_handle_t rmt_copy_encoder_h; // RMT simple copy encoder handle - uint32_t signal_range_min_ns; // RX Filter data - Low Pass pulse width - uint32_t signal_range_max_ns; // RX idle time that defines end of reading + uint32_t signal_range_min_ns; // RX Filter data - Low Pass pulse width + uint32_t signal_range_max_ns; // RX idle time that defines end of reading - EventGroupHandle_t rmt_events; // read/write done event RMT callback handle - bool rmt_ch_is_looping; // Is this RMT TX Channel in LOOPING MODE? - size_t *num_symbols_read; // Pointer to the number of RMT symbol read by IDF RMT RX Done - uint32_t frequency_Hz; // RMT Frequency - uint8_t rmt_EOT_Level; // RMT End of Transmission Level - default is LOW + EventGroupHandle_t rmt_events; // read/write done event RMT callback handle + bool rmt_ch_is_looping; // Is this RMT TX Channel in LOOPING MODE? + size_t *num_symbols_read; // Pointer to the number of RMT symbol read by IDF RMT RX Done + uint32_t frequency_Hz; // RMT Frequency + uint8_t rmt_EOT_Level; // RMT End of Transmission Level - default is LOW #if !CONFIG_DISABLE_HAL_LOCKS - SemaphoreHandle_t g_rmt_objlocks; // Channel Semaphore Lock -#endif /* CONFIG_DISABLE_HAL_LOCKS */ + SemaphoreHandle_t g_rmt_objlocks; // Channel Semaphore Lock +#endif /* CONFIG_DISABLE_HAL_LOCKS */ }; typedef struct rmt_obj_s *rmt_bus_handle_t; @@ -80,11 +82,10 @@ static SemaphoreHandle_t g_rmt_block_lock = NULL; */ // This is called from an IDF ISR code, therefore this code is part of an ISR -static bool _rmt_rx_done_callback(rmt_channel_handle_t channel, const rmt_rx_done_event_data_t *data, void *args) -{ +static bool _rmt_rx_done_callback(rmt_channel_handle_t channel, const rmt_rx_done_event_data_t *data, void *args) { BaseType_t high_task_wakeup = pdFALSE; - rmt_bus_handle_t bus = (rmt_bus_handle_t) args; - // sets the returning number of RMT symbols (32 bits) effectively read + rmt_bus_handle_t bus = (rmt_bus_handle_t)args; + // sets the returning number of RMT symbols (32 bits) effectively read *bus->num_symbols_read = data->num_symbols; // set RX event group and signal the received RMT symbols of that channel xEventGroupSetBitsFromISR(bus->rmt_events, RMT_FLAG_RX_DONE, &high_task_wakeup); @@ -93,10 +94,9 @@ static bool _rmt_rx_done_callback(rmt_channel_handle_t channel, const rmt_rx_don } // This is called from an IDF ISR code, therefore this code is part of an ISR -static bool _rmt_tx_done_callback(rmt_channel_handle_t channel, const rmt_tx_done_event_data_t *data, void *args) -{ +static bool _rmt_tx_done_callback(rmt_channel_handle_t channel, const rmt_tx_done_event_data_t *data, void *args) { BaseType_t high_task_wakeup = pdFALSE; - rmt_bus_handle_t bus = (rmt_bus_handle_t) args; + rmt_bus_handle_t bus = (rmt_bus_handle_t)args; // set RX event group and signal the received RMT symbols of that channel xEventGroupSetBitsFromISR(bus->rmt_events, RMT_FLAG_TX_DONE, &high_task_wakeup); // A "need to yield" is returned in order to execute portYIELD_FROM_ISR() in the main IDF RX ISR @@ -104,8 +104,7 @@ static bool _rmt_tx_done_callback(rmt_channel_handle_t channel, const rmt_tx_don } // This function must be called only after checking the pin and its bus with _rmtGetBus() -static bool _rmtCheckDirection(uint8_t gpio_num, rmt_ch_dir_t rmt_dir, const char* labelFunc) -{ +static bool _rmtCheckDirection(uint8_t gpio_num, rmt_ch_dir_t rmt_dir, const char *labelFunc) { // gets bus RMT direction from the Peripheral Manager information rmt_ch_dir_t bus_rmt_dir = perimanGetPinBusType(gpio_num) == ESP32_BUS_TYPE_RMT_TX ? RMT_TX_MODE : RMT_RX_MODE; @@ -119,11 +118,10 @@ static bool _rmtCheckDirection(uint8_t gpio_num, rmt_ch_dir_t rmt_dir, const cha } else { log_w("==>%s():Channel set as RX instead of TX.", labelFunc); } - return false; // mismatched + return false; // mismatched } -static rmt_bus_handle_t _rmtGetBus(int pin, const char* labelFunc) -{ +static rmt_bus_handle_t _rmtGetBus(int pin, const char *labelFunc) { // Is pin RX or TX? Let's find it out peripheral_bus_type_t rmt_bus_type = perimanGetPinBusType(pin); if (rmt_bus_type != ESP32_BUS_TYPE_RMT_TX && rmt_bus_type != ESP32_BUS_TYPE_RMT_RX) { @@ -135,19 +133,18 @@ static rmt_bus_handle_t _rmtGetBus(int pin, const char* labelFunc) } // Peripheral Manager detach callback -static bool _rmtDetachBus(void *busptr) -{ +static bool _rmtDetachBus(void *busptr) { // sanity check - it should never happen assert(busptr && "_rmtDetachBus bus NULL pointer."); bool retCode = true; - rmt_bus_handle_t bus = (rmt_bus_handle_t) busptr; + rmt_bus_handle_t bus = (rmt_bus_handle_t)busptr; log_v("Detaching RMT GPIO Bus"); // lock it while (xSemaphoreTake(g_rmt_block_lock, portMAX_DELAY) != pdPASS) {} - // free Event Group + // free Event Group if (bus->rmt_events != NULL) { vEventGroupDelete(bus->rmt_events); bus->rmt_events = NULL; @@ -186,8 +183,7 @@ static bool _rmtDetachBus(void *busptr) Public method definitions */ -bool rmtSetEOT(int pin, uint8_t EOT_Level) -{ +bool rmtSetEOT(int pin, uint8_t EOT_Level) { rmt_bus_handle_t bus = _rmtGetBus(pin, __FUNCTION__); if (bus == NULL) { return false; @@ -200,8 +196,7 @@ bool rmtSetEOT(int pin, uint8_t EOT_Level) return true; } -bool rmtSetCarrier(int pin, bool carrier_en, bool carrier_level, uint32_t frequency_Hz, float duty_percent) -{ +bool rmtSetCarrier(int pin, bool carrier_en, bool carrier_level, uint32_t frequency_Hz, float duty_percent) { rmt_bus_handle_t bus = _rmtGetBus(pin, __FUNCTION__); if (bus == NULL) { return false; @@ -211,7 +206,7 @@ bool rmtSetCarrier(int pin, bool carrier_en, bool carrier_level, uint32_t freque log_w("GPIO %d - RMT Carrier must be a float percentage from 0 to 1. Setting to 50%.", pin); duty_percent = 0.5; } - rmt_carrier_config_t carrier_cfg = {0}; + rmt_carrier_config_t carrier_cfg = { 0 }; carrier_cfg.duty_cycle = duty_percent; // duty cycle carrier_cfg.frequency_hz = carrier_en ? frequency_Hz : 0; // carrier frequency in Hz carrier_cfg.flags.polarity_active_low = carrier_level; // carrier modulation polarity level @@ -228,8 +223,7 @@ bool rmtSetCarrier(int pin, bool carrier_en, bool carrier_level, uint32_t freque return retCode; } -bool rmtSetRxMinThreshold(int pin, uint8_t filter_pulse_ticks) -{ +bool rmtSetRxMinThreshold(int pin, uint8_t filter_pulse_ticks) { rmt_bus_handle_t bus = _rmtGetBus(pin, __FUNCTION__); if (bus == NULL) { return false; @@ -242,7 +236,7 @@ bool rmtSetRxMinThreshold(int pin, uint8_t filter_pulse_ticks) uint32_t filter_pulse_ns = (1000000000 / bus->frequency_Hz) * filter_pulse_ticks; // RMT_LL_MAX_FILTER_VALUE is 255 for ESP32, S2, S3, C3, C6 and H2; // filter_pulse_ticks is 8 bits, thus it will not exceed 255 -#if 0 // for the future, in case some other SoC has different limit +#if 0 // for the future, in case some other SoC has different limit if (filter_pulse_ticks > RMT_LL_MAX_FILTER_VALUE) { log_e("filter_pulse_ticks is too big. Max = %d", RMT_LL_MAX_FILTER_VALUE); return false; @@ -250,13 +244,12 @@ bool rmtSetRxMinThreshold(int pin, uint8_t filter_pulse_ticks) #endif RMT_MUTEX_LOCK(bus); - bus->signal_range_min_ns = filter_pulse_ns; // set zero to disable it + bus->signal_range_min_ns = filter_pulse_ns; // set zero to disable it RMT_MUTEX_UNLOCK(bus); return true; } -bool rmtSetRxMaxThreshold(int pin, uint16_t idle_thres_ticks) -{ +bool rmtSetRxMaxThreshold(int pin, uint16_t idle_thres_ticks) { rmt_bus_handle_t bus = _rmtGetBus(pin, __FUNCTION__); if (bus == NULL) { return false; @@ -268,7 +261,7 @@ bool rmtSetRxMaxThreshold(int pin, uint16_t idle_thres_ticks) uint32_t idle_thres_ns = (1000000000 / bus->frequency_Hz) * idle_thres_ticks; // RMT_LL_MAX_IDLE_VALUE is 65535 for ESP32,S2 and 32767 for S3, C3, C6 and H2 -#if RMT_LL_MAX_IDLE_VALUE < 65535 // idle_thres_ticks is 16 bits anyway - save some bytes +#if RMT_LL_MAX_IDLE_VALUE < 65535 // idle_thres_ticks is 16 bits anyway - save some bytes if (idle_thres_ticks > RMT_LL_MAX_IDLE_VALUE) { log_e("idle_thres_ticks is too big. Max = %ld", RMT_LL_MAX_IDLE_VALUE); return false; @@ -281,8 +274,7 @@ bool rmtSetRxMaxThreshold(int pin, uint16_t idle_thres_ticks) return true; } -bool rmtDeinit(int pin) -{ +bool rmtDeinit(int pin) { log_v("Deiniting RMT GPIO %d", pin); if (_rmtGetBus(pin, __FUNCTION__) != NULL) { // release all allocated data @@ -292,8 +284,7 @@ bool rmtDeinit(int pin) return false; } -static bool _rmtWrite(int pin, rmt_data_t* data, size_t num_rmt_symbols, bool blocking, bool loop, uint32_t timeout_ms) -{ +static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool blocking, bool loop, uint32_t timeout_ms) { rmt_bus_handle_t bus = _rmtGetBus(pin, __FUNCTION__); if (bus == NULL) { return false; @@ -301,7 +292,7 @@ static bool _rmtWrite(int pin, rmt_data_t* data, size_t num_rmt_symbols, bool bl if (!_rmtCheckDirection(pin, RMT_TX_MODE, __FUNCTION__)) { return false; } - bool loopCancel = false; // user wants to cancel the writing loop mode + bool loopCancel = false; // user wants to cancel the writing loop mode if (data == NULL || num_rmt_symbols == 0) { if (!loop) { log_w("GPIO %d - RMT Write Data NULL pointer or size is zero.", pin); @@ -319,7 +310,7 @@ static bool _rmtWrite(int pin, rmt_data_t* data, size_t num_rmt_symbols, bool bl return false; } - rmt_transmit_config_t transmit_cfg = {0}; // loop mode disabled + rmt_transmit_config_t transmit_cfg = { 0 }; // loop mode disabled bool retCode = true; RMT_MUTEX_LOCK(bus); @@ -338,28 +329,29 @@ static bool _rmtWrite(int pin, rmt_data_t* data, size_t num_rmt_symbols, bool bl if (loopCancel) { // just resets and releases the channel, maybe, already done above, then exits bus->rmt_ch_is_looping = false; - } else { // new writing | looping request + } else { // new writing | looping request // looping | Writing over a previous looping state is valid if (loop) { transmit_cfg.loop_count = -1; // enable infinite loop mode - // keeps RMT_FLAG_TX_DONE set - it never changes + // keeps RMT_FLAG_TX_DONE set - it never changes } else { // looping mode never sets this flag (IDF 5.1) in the callback xEventGroupClearBits(bus->rmt_events, RMT_FLAG_TX_DONE); } // transmits just once or looping data - if (ESP_OK != rmt_transmit(bus->rmt_channel_h, bus->rmt_copy_encoder_h, - (const void *) data, num_rmt_symbols * sizeof(rmt_data_t), &transmit_cfg)) { + if (ESP_OK != rmt_transmit(bus->rmt_channel_h, bus->rmt_copy_encoder_h, (const void *)data, num_rmt_symbols * sizeof(rmt_data_t), &transmit_cfg)) { retCode = false; log_w("GPIO %d - RMT Transmission failed.", pin); - } else { // transmit OK + } else { // transmit OK if (loop) { - bus->rmt_ch_is_looping = true; // for ever... until a channel canceling or new writing + bus->rmt_ch_is_looping = true; // for ever... until a channel canceling or new writing } else { if (blocking) { // wait for transmission confirmation | timeout - retCode = (xEventGroupWaitBits(bus->rmt_events, RMT_FLAG_TX_DONE, pdFALSE /* do not clear on exit */, - pdFALSE /* wait for all bits */, timeout_ms) & RMT_FLAG_TX_DONE) != 0; + retCode = (xEventGroupWaitBits(bus->rmt_events, RMT_FLAG_TX_DONE, pdFALSE /* do not clear on exit */, + pdFALSE /* wait for all bits */, timeout_ms) + & RMT_FLAG_TX_DONE) + != 0; } } } @@ -368,8 +360,7 @@ static bool _rmtWrite(int pin, rmt_data_t* data, size_t num_rmt_symbols, bool bl return retCode; } -static bool _rmtRead(int pin, rmt_data_t* data, size_t *num_rmt_symbols, bool waitForData, uint32_t timeout_ms) -{ +static bool _rmtRead(int pin, rmt_data_t *data, size_t *num_rmt_symbols, bool waitForData, uint32_t timeout_ms) { rmt_bus_handle_t bus = _rmtGetBus(pin, __FUNCTION__); if (bus == NULL) { return false; @@ -396,10 +387,12 @@ static bool _rmtRead(int pin, rmt_data_t* data, size_t *num_rmt_symbols, bool wa rmt_receive(bus->rmt_channel_h, data, *num_rmt_symbols * sizeof(rmt_data_t), &receive_config); // wait for data if requested if (waitForData) { - retCode = (xEventGroupWaitBits(bus->rmt_events, RMT_FLAG_RX_DONE, pdFALSE /* do not clear on exit */, - pdFALSE /* wait for all bits */, timeout_ms) & RMT_FLAG_RX_DONE) != 0; + retCode = (xEventGroupWaitBits(bus->rmt_events, RMT_FLAG_RX_DONE, pdFALSE /* do not clear on exit */, + pdFALSE /* wait for all bits */, timeout_ms) + & RMT_FLAG_RX_DONE) + != 0; } - + RMT_MUTEX_UNLOCK(bus); return retCode; } @@ -413,7 +406,7 @@ bool rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols) { return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, false /*looping*/, 0 /*N/A*/); } -bool rmtWriteLooping(int pin, rmt_data_t* data, size_t num_rmt_symbols) { +bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols) { return _rmtWrite(pin, data, num_rmt_symbols, false /*blocks*/, true /*looping*/, 0 /*N/A*/); } @@ -433,11 +426,11 @@ bool rmtTransmitCompleted(int pin) { return retCode; } -bool rmtRead(int pin, rmt_data_t* data, size_t *num_rmt_symbols, uint32_t timeout_ms) { +bool rmtRead(int pin, rmt_data_t *data, size_t *num_rmt_symbols, uint32_t timeout_ms) { return _rmtRead(pin, data, num_rmt_symbols, true /* blocking */, timeout_ms); } -bool rmtReadAsync(int pin, rmt_data_t* data, size_t *num_rmt_symbols) { +bool rmtReadAsync(int pin, rmt_data_t *data, size_t *num_rmt_symbols) { return _rmtRead(pin, data, num_rmt_symbols, false /* non-blocking */, 0 /* N/A */); } @@ -457,8 +450,7 @@ bool rmtReceiveCompleted(int pin) { return retCode; } -bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_size, uint32_t frequency_Hz) -{ +bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_size, uint32_t frequency_Hz) { log_v("GPIO %d - %s - MemSize[%d] - Freq=%dHz", pin, channel_direction == RMT_RX_MODE ? "RX MODE" : "TX MODE", mem_size * RMT_SYMBOLS_PER_CHANNEL_BLOCK, frequency_Hz); // create common block mutex for protecting allocs from multiple threads allocating RMT channels @@ -487,7 +479,7 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_ return false; } - // Try to dettach any (Tx|Rx|Whatever) previous bus or just keep it as not attached + // Try to detach any (Tx|Rx|Whatever) previous bus or just keep it as not attached if (!perimanClearPinBus(pin)) { log_w("GPIO %d - Can't detach previous peripheral.", pin); return false; @@ -508,7 +500,7 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_ // pulses with width smaller than min_ns will be ignored (as a glitch) //bus->signal_range_min_ns = 0; // disabled --> not necessary CALLOC set all to ZERO. // RMT stops reading if the input stays idle for longer than max_ns - bus->signal_range_max_ns = (1000000000 / frequency_Hz) * RMT_LL_MAX_IDLE_VALUE; // maximum possible + bus->signal_range_max_ns = (1000000000 / frequency_Hz) * RMT_LL_MAX_IDLE_VALUE; // maximum possible // creates the event group to control read_done and write_done bus->rmt_events = xEventGroupCreate(); if (bus->rmt_events == NULL) { @@ -528,7 +520,7 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_ tx_cfg.clk_src = RMT_CLK_SRC_DEFAULT; tx_cfg.resolution_hz = frequency_Hz; tx_cfg.mem_block_symbols = SOC_RMT_MEM_WORDS_PER_CHANNEL * mem_size; - tx_cfg.trans_queue_depth = 10; // maximum allowed + tx_cfg.trans_queue_depth = 10; // maximum allowed tx_cfg.flags.invert_out = 0; tx_cfg.flags.with_dma = 0; tx_cfg.flags.io_loop_back = 0; @@ -568,7 +560,7 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_ log_e("GPIO %d RMT - RX Initialization error.", pin); goto Err; } - + // set RX Callback rmt_rx_event_callbacks_t cbs = { .on_recv_done = _rmt_rx_done_callback }; if (ESP_OK != rmt_rx_register_event_callbacks(bus->rmt_channel_h, &cbs, bus)) { @@ -593,23 +585,23 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_ } #endif - rmt_enable(bus->rmt_channel_h); // starts/enables the channel + rmt_enable(bus->rmt_channel_h); // starts/enables the channel // Finally, allocate Peripheral Manager RMT bus and associate it to its GPIO peripheral_bus_type_t pinBusType = channel_direction == RMT_TX_MODE ? ESP32_BUS_TYPE_RMT_TX : ESP32_BUS_TYPE_RMT_RX; - if (!perimanSetPinBus(pin, pinBusType, (void *) bus, -1, -1)) { + if (!perimanSetPinBus(pin, pinBusType, (void *)bus, -1, -1)) { log_e("Can't allocate the GPIO %d in the Peripheral Manager.", pin); goto Err; } - + // this delay is necessary when CPU frequency changes, but internal RMT setup is "old/wrong" // The use case is related to the RMT_CPUFreq_Test example. The very first RMT Write - // goes in the wrong pace (frequency). The delay allows other IDF tasks to run to fix it. + // goes in the wrong pace (frequency). The delay allows other IDF tasks to run to fix it. if (loopTaskHandle != NULL) { // it can only run when Arduino task has been already started. delay(1); - } // prevent panic when rmtInit() is executed within an C++ object constructor + } // prevent panic when rmtInit() is executed within an C++ object constructor // release the mutex xSemaphoreGive(g_rmt_block_lock); return true; diff --git a/cores/esp32/esp32-hal-rmt.h b/cores/esp32/esp32-hal-rmt.h index 1b08fdae00d..374483b4b3f 100644 --- a/cores/esp32/esp32-hal-rmt.h +++ b/cores/esp32/esp32-hal-rmt.h @@ -22,37 +22,37 @@ extern "C" { #endif -typedef enum { - RMT_RX_MODE = 0, // false - RMT_TX_MODE = 1, // true -} rmt_ch_dir_t; - -typedef enum { - RMT_MEM_NUM_BLOCKS_1 = 1, - RMT_MEM_NUM_BLOCKS_2 = 2, + typedef enum { + RMT_RX_MODE = 0, // false + RMT_TX_MODE = 1, // true + } rmt_ch_dir_t; + + typedef enum { + RMT_MEM_NUM_BLOCKS_1 = 1, + RMT_MEM_NUM_BLOCKS_2 = 2, #if SOC_RMT_TX_CANDIDATES_PER_GROUP > 2 - RMT_MEM_NUM_BLOCKS_3 = 3, - RMT_MEM_NUM_BLOCKS_4 = 4, + RMT_MEM_NUM_BLOCKS_3 = 3, + RMT_MEM_NUM_BLOCKS_4 = 4, #if SOC_RMT_TX_CANDIDATES_PER_GROUP > 4 - RMT_MEM_NUM_BLOCKS_5 = 5, - RMT_MEM_NUM_BLOCKS_6 = 6, - RMT_MEM_NUM_BLOCKS_7 = 7, - RMT_MEM_NUM_BLOCKS_8 = 8, + RMT_MEM_NUM_BLOCKS_5 = 5, + RMT_MEM_NUM_BLOCKS_6 = 6, + RMT_MEM_NUM_BLOCKS_7 = 7, + RMT_MEM_NUM_BLOCKS_8 = 8, #endif #endif -} rmt_reserve_memsize_t; - -// Each RMT Symbols has 4 bytes -// Total number of bytes per RMT_MEM_BLOCK is RMT_SYMBOLS_PER_CHANNEL_BLOCK * 4 bytes -typedef union { - struct { - uint32_t duration0 : 15; - uint32_t level0 : 1; - uint32_t duration1 : 15; - uint32_t level1 : 1; - }; - uint32_t val; -} rmt_data_t; + } rmt_reserve_memsize_t; + + // Each RMT Symbols has 4 bytes + // Total number of bytes per RMT_MEM_BLOCK is RMT_SYMBOLS_PER_CHANNEL_BLOCK * 4 bytes + typedef union { + struct { + uint32_t duration0 : 15; + uint32_t level0 : 1; + uint32_t duration1 : 15; + uint32_t level1 : 1; + }; + uint32_t val; + } rmt_data_t; // Reading and Writing shall use as rmt_symbols_size this unit // ESP32 has 8 MEM BLOCKS in total shared with Reading and/or Writing @@ -67,35 +67,35 @@ typedef union { // Helper macro to calculate the number of RTM symbols in a array or type #define RMT_SYMBOLS_OF(x) (sizeof(x) / sizeof(rmt_data_t)) -/** + /** Initialize the object - - New Parameters in Arduino Core 3: RMT tick is set in the rmtInit() function by the + + New Parameters in Arduino Core 3: RMT tick is set in the rmtInit() function by the frequency of the RMT channel. Example: 100ns tick => 10MHz, thus frequency will be 10,000,000 Hz Returns on execution success, otherwise */ -bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t memsize, uint32_t frequency_Hz); + bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t memsize, uint32_t frequency_Hz); -/** + /** Sets the End of Transmission level to be set for the when the RMT transmission ends. This function affects how rmtWrite(), rmtWriteAsync() or rmtWriteLooping() will set the pin after writing the data. The default EOT level is LOW, in case this function isn't used before RMT Writing. This level can be set for each RMT pin and can be changed between writings to the same pin. shall be Zero (LOW) or non-zero (HIGH) value. - It only affects the transmission process, therefore, it doesn't affect any IDLE LEVEL before starting the RMT transmission. + It only affects the transmission process, therefore, it doesn't affect any IDLE LEVEL before starting the RMT transmission. The pre-transmission idle level can be set manually calling, for instance, digitalWrite(pin, Level). Returns when EOT has been correctly set for , otherwise. */ -bool rmtSetEOT(int pin, uint8_t EOT_Level); + bool rmtSetEOT(int pin, uint8_t EOT_Level); -/** - Sending data in Blocking Mode. + /** + Sending data in Blocking Mode. is a 32 bits structure as defined by rmt_data_t type. It is possible to use the macro RMT_SYMBOLS_OF(data), if data is an array of . - - Blocking mode - only returns after sending all data or by timeout. + + Blocking mode - only returns after sending all data or by timeout. If the writing operation takes longer than in milliseconds, it will end its execution returning . Timeout can be set as undefined time by passing as parameter. @@ -105,128 +105,128 @@ bool rmtSetEOT(int pin, uint8_t EOT_Level); Returns when there is no error in the write operation, otherwise, including when it exits by timeout. */ -bool rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t timeout_ms); + bool rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, uint32_t timeout_ms); -/** + /** Sending data in Async Mode. is a 32 bits structure as defined by rmt_data_t type. It is possible to use the macro RMT_SYMBOLS_OF(data), if is an array of - If more than one rmtWriteAsync() is executed in sequence, it will wait for the first transmission - to finish, resulting in a return that indicates that the rmtWriteAsync() call has failed. + If more than one rmtWriteAsync() is executed in sequence, it will wait for the first transmission + to finish, resulting in a return that indicates that the rmtWriteAsync() call has failed. In such case, this channel will have to finish the previous transmission before starting a new one. - + Non-Blocking mode - returns right after execution. Returns on execution success, otherwise. will return when all data is sent. */ -bool rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols); + bool rmtWriteAsync(int pin, rmt_data_t *data, size_t num_rmt_symbols); -/** + /** Writing data up to the reserved memsize, looping continuously is a 32 bits structure as defined by rmt_data_t type. It is possible to use the macro RMT_SYMBOLS_OF(data), if data is an array of rmt_data_t - If *data or size_byte are NULL | Zero, it will disable the writing loop and stop transmission + If *data or size_byte are NULL | Zero, it will disable the writing loop and stop transmission Non-Blocking mode - returns right after execution Returns on execution success, otherwise will return always while it is looping. -*/ -bool rmtWriteLooping(int pin, rmt_data_t* data, size_t num_rmt_symbols); +*/ + bool rmtWriteLooping(int pin, rmt_data_t *data, size_t num_rmt_symbols); -/** - Checks if transmission is completed and the rmtChannel ready for transmiting new data. + /** + Checks if transmission is completed and the rmtChannel ready for transmitting new data. To be ready for a new transmission, means that the previous transmission is completed. Returns when all data has been sent, otherwise. - The data transmition information is reset when a new rmtWrite/Async function is called. - If rmtWrite() times out or rmtWriteAsync() is called, this function will return until - all data is sent out. - rmtTranmitCompleted() will always return when rmtWriteLooping() is called, - beacuse it has no effect in such case. + The data transmission information is reset when a new rmtWrite/Async function is called. + If rmtWrite() times out or rmtWriteAsync() is called, this function will return until + all data is sent out. + rmtTranmitCompleted() will always return when rmtWriteLooping() is called, + because it has no effect in such case. */ -bool rmtTransmitCompleted(int pin); + bool rmtTransmitCompleted(int pin); -/** + /** Initiates blocking receive. Read data will be stored in a user provided buffer <*data> - It will read up to RMT Symbols and the value of this variable will + It will read up to RMT Symbols and the value of this variable will change to the effective number of symbols read. is a 32 bits structure as defined by rmt_data_t type. If the reading operation takes longer than in milliseconds, it will end its - execution and the function will return . In a time out scenario, won't + execution and the function will return . In a time out scenario, won't change and rmtReceiveCompleted() can be used latter to check if there is data available. Timeout can be set as undefined time by passing RMT_WAIT_FOR_EVER as parameter Returns when there is no error in the read operation, otherwise, including when it exits by timeout. - Returns, by value, the number of RMT Symbols read in and the user buffer + Returns, by value, the number of RMT Symbols read in and the user buffer when the read operation has success within the defined . If the function times out, it will read RMT data latter asynchronously, affecting <*data> and <*num_rmt_symbols>. After timeout, the application can check if data is already available using */ -bool rmtRead(int pin, rmt_data_t* data, size_t *num_rmt_symbols, uint32_t timeout_ms); + bool rmtRead(int pin, rmt_data_t *data, size_t *num_rmt_symbols, uint32_t timeout_ms); -/** + /** Initiates async (non-blocking) receive. It will return immediately after execution. Read data will be stored in a user provided buffer <*data>. - It will read up to RMT Symbols and the value of this variable will + It will read up to RMT Symbols and the value of this variable will change to the effective number of symbols read, whenever the read is completed. is a 32 bits structure as defined by type. - Returns when there is no error in the read operation, otherwise. - Returns asynchronously, by value, the number of RMT Symbols read, and also, it will copy + Returns when there is no error in the read operation, otherwise. + Returns asynchronously, by value, the number of RMT Symbols read, and also, it will copy the RMT received data to the user buffer when the read operation happens. The application can check if data is already available using */ -bool rmtReadAsync(int pin, rmt_data_t* data, size_t *num_rmt_symbols); + bool rmtReadAsync(int pin, rmt_data_t *data, size_t *num_rmt_symbols); -/** + /** Checks if a data reception is completed and the rmtChannel has new data for processing. Returns when data has been received, otherwise. The data reception information is reset when a new rmtRead/Async function is called. */ -bool rmtReceiveCompleted(int pin); + bool rmtReceiveCompleted(int pin); -/** + /** Function used to set a threshold (in ticks) used to consider that a data reception has ended. - In receive mode, when no edge is detected on the input signal for longer than idle_thres_ticks - time, the receiving process is finished and the Data is made available by + In receive mode, when no edge is detected on the input signal for longer than idle_thres_ticks + time, the receiving process is finished and the Data is made available by the rmtRead/Async functions. Note that this time (in RMT channel frequency cycles) will also define how many low/high bits are read at the end of the received data. The function returns if it is correctly executed, otherwise. */ -bool rmtSetRxMaxThreshold(int pin, uint16_t idle_thres_ticks); + bool rmtSetRxMaxThreshold(int pin, uint16_t idle_thres_ticks); -/** + /** Parameters changed in Arduino Core 3: low and high (ticks) are now expressed in Carrier Freq in Hz and duty cycle in percentage float 0.0 to 1.0 - example: 38.5KHz 33% High => 38500, 0.33 - - Function to set a RX demodulation carrier or TX modulation carrier + + Function to set a RX demodulation carrier or TX modulation carrier is used to enable/disable the use of demodulation/modulation for RX/TX true means that the polarity level for the (de)modulation is positive is the carrier frequency used - is a float deom 0 to 1 (0.5 means a square wave) of the carrier frequency + is a float deom 0 to 1 (0.5 means a square wave) of the carrier frequency The function returns if it is correctly executed, otherwise. */ -bool rmtSetCarrier(int pin, bool carrier_en, bool carrier_level, uint32_t frequency_Hz, float duty_percent); + bool rmtSetCarrier(int pin, bool carrier_en, bool carrier_level, uint32_t frequency_Hz, float duty_percent); -/** + /** Function used to filter input noise in the RX channel. - In receiving mode, channel will ignore any input pulse which width (high or low) + In receiving mode, channel will ignore any input pulse which width (high or low) is smaller than If is Zero, it will to disable the filter. The function returns if it is correctly executed, otherwise. */ -bool rmtSetRxMinThreshold(int pin, uint8_t filter_pulse_ticks); + bool rmtSetRxMinThreshold(int pin, uint8_t filter_pulse_ticks); -/** + /** Deinitializes the driver and releases all allocated memory It also disables RMT for this gpio */ -bool rmtDeinit(int pin); + bool rmtDeinit(int pin); #ifdef __cplusplus } diff --git a/cores/esp32/esp32-hal-sigmadelta.c b/cores/esp32/esp32-hal-sigmadelta.c index 2377e35f067..9d21286e96a 100644 --- a/cores/esp32/esp32-hal-sigmadelta.c +++ b/cores/esp32/esp32-hal-sigmadelta.c @@ -11,82 +11,80 @@ #include "esp32-hal-periman.h" #include "driver/sdm.h" -static bool sigmaDeltaDetachBus(void * bus){ - esp_err_t err = sdm_channel_disable((sdm_channel_handle_t)bus); - if(err != ESP_OK){ - log_w("sdm_channel_disable failed with error: %d", err); - } - err = sdm_del_channel((sdm_channel_handle_t)bus); - if(err != ESP_OK){ - log_e("sdm_del_channel failed with error: %d", err); - return false; - } - return true; +static bool sigmaDeltaDetachBus(void *bus) { + esp_err_t err = sdm_channel_disable((sdm_channel_handle_t)bus); + if (err != ESP_OK) { + log_w("sdm_channel_disable failed with error: %d", err); + } + err = sdm_del_channel((sdm_channel_handle_t)bus); + if (err != ESP_OK) { + log_e("sdm_del_channel failed with error: %d", err); + return false; + } + return true; } -bool sigmaDeltaAttach(uint8_t pin, uint32_t freq) //freq 1220-312500 +bool sigmaDeltaAttach(uint8_t pin, uint32_t freq) //freq 1220-312500 { - perimanSetBusDeinit(ESP32_BUS_TYPE_SIGMADELTA, sigmaDeltaDetachBus); - sdm_channel_handle_t bus = NULL; - // pin may be previously attached to other peripheral -> detach it. - // if attached to sigmaDelta, detach it and set the new frequency - if(perimanGetPinBusType(pin) != ESP32_BUS_TYPE_INIT && !perimanClearPinBus(pin)){ - log_e("Pin %u could not be detached.", pin); - return false; - } - sdm_config_t config = { - .gpio_num = (int)pin, - .clk_src = SDM_CLK_SRC_DEFAULT, - .sample_rate_hz = freq, - .flags = { - .invert_out = 0, - .io_loop_back = 0 - } - }; - esp_err_t err = sdm_new_channel(&config, &bus); - if(err != ESP_OK){ - log_e("sdm_new_channel failed with error: %d", err); - return false; - } - err = sdm_channel_enable(bus); - if(err != ESP_OK){ - sigmaDeltaDetachBus((void *)bus); - log_e("sdm_channel_enable failed with error: %d", err); - return false; - } - if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_SIGMADELTA, (void *)bus, -1, -1)){ - sigmaDeltaDetachBus((void *)bus); - return false; - } - return true; + perimanSetBusDeinit(ESP32_BUS_TYPE_SIGMADELTA, sigmaDeltaDetachBus); + sdm_channel_handle_t bus = NULL; + // pin may be previously attached to other peripheral -> detach it. + // if attached to sigmaDelta, detach it and set the new frequency + if (perimanGetPinBusType(pin) != ESP32_BUS_TYPE_INIT && !perimanClearPinBus(pin)) { + log_e("Pin %u could not be detached.", pin); + return false; + } + sdm_config_t config = { + .gpio_num = (int)pin, + .clk_src = SDM_CLK_SRC_DEFAULT, + .sample_rate_hz = freq, + .flags = { + .invert_out = 0, + .io_loop_back = 0 } + }; + esp_err_t err = sdm_new_channel(&config, &bus); + if (err != ESP_OK) { + log_e("sdm_new_channel failed with error: %d", err); + return false; + } + err = sdm_channel_enable(bus); + if (err != ESP_OK) { + sigmaDeltaDetachBus((void *)bus); + log_e("sdm_channel_enable failed with error: %d", err); + return false; + } + if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_SIGMADELTA, (void *)bus, -1, -1)) { + sigmaDeltaDetachBus((void *)bus); + return false; + } + return true; } -bool sigmaDeltaWrite(uint8_t pin, uint8_t duty) //chan 0-x according to SOC duty 8 bit +bool sigmaDeltaWrite(uint8_t pin, uint8_t duty) //chan 0-x according to SOC duty 8 bit { - sdm_channel_handle_t bus = (sdm_channel_handle_t)perimanGetPinBus(pin, ESP32_BUS_TYPE_SIGMADELTA); - if(bus != NULL){ - int8_t d = duty - 128; - esp_err_t err = sdm_channel_set_duty(bus, d); - if(err != ESP_OK){ - log_e("sdm_channel_set_duty failed with error: %d", err); - return false; - } - return true; - } else { - log_e("pin %u is not attached to SigmaDelta", pin); + sdm_channel_handle_t bus = (sdm_channel_handle_t)perimanGetPinBus(pin, ESP32_BUS_TYPE_SIGMADELTA); + if (bus != NULL) { + int8_t d = duty - 128; + esp_err_t err = sdm_channel_set_duty(bus, d); + if (err != ESP_OK) { + log_e("sdm_channel_set_duty failed with error: %d", err); + return false; } - return false; + return true; + } else { + log_e("pin %u is not attached to SigmaDelta", pin); + } + return false; } -bool sigmaDeltaDetach(uint8_t pin) -{ - void * bus = perimanGetPinBus(pin, ESP32_BUS_TYPE_SIGMADELTA); - if(bus != NULL){ - // will call sigmaDeltaDetachBus - return perimanClearPinBus(pin); - } else { - log_e("pin %u is not attached to SigmaDelta", pin); - } - return false; +bool sigmaDeltaDetach(uint8_t pin) { + void *bus = perimanGetPinBus(pin, ESP32_BUS_TYPE_SIGMADELTA); + if (bus != NULL) { + // will call sigmaDeltaDetachBus + return perimanClearPinBus(pin); + } else { + log_e("pin %u is not attached to SigmaDelta", pin); + } + return false; } #endif diff --git a/cores/esp32/esp32-hal-sigmadelta.h b/cores/esp32/esp32-hal-sigmadelta.h index 41d2b3ac604..ea1f9c7a137 100644 --- a/cores/esp32/esp32-hal-sigmadelta.h +++ b/cores/esp32/esp32-hal-sigmadelta.h @@ -16,10 +16,10 @@ extern "C" { #include #include -//freq 1220-312500 duty 0-255 -bool sigmaDeltaAttach(uint8_t pin, uint32_t freq); -bool sigmaDeltaWrite(uint8_t pin, uint8_t duty); -bool sigmaDeltaDetach(uint8_t pin); + //freq 1220-312500 duty 0-255 + bool sigmaDeltaAttach(uint8_t pin, uint32_t freq); + bool sigmaDeltaWrite(uint8_t pin, uint8_t duty); + bool sigmaDeltaDetach(uint8_t pin); #ifdef __cplusplus } diff --git a/cores/esp32/esp32-hal-spi.c b/cores/esp32/esp32-hal-spi.c index 4fd0a3a928d..e0c9f4cf30b 100644 --- a/cores/esp32/esp32-hal-spi.c +++ b/cores/esp32/esp32-hal-spi.c @@ -31,7 +31,7 @@ #include "esp_system.h" #include "esp_intr_alloc.h" -#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 #include "soc/dport_reg.h" #include "esp32/rom/ets_sys.h" #include "esp32/rom/gpio.h" @@ -55,70 +55,70 @@ #elif CONFIG_IDF_TARGET_ESP32H2 #include "esp32h2/rom/ets_sys.h" #include "esp32h2/rom/gpio.h" -#else +#else #error Target CONFIG_IDF_TARGET is not supported #endif struct spi_struct_t { - spi_dev_t * dev; + spi_dev_t *dev; #if !CONFIG_DISABLE_HAL_LOCKS - SemaphoreHandle_t lock; + SemaphoreHandle_t lock; #endif - uint8_t num; - int8_t sck; - int8_t miso; - int8_t mosi; - int8_t ss; + uint8_t num; + int8_t sck; + int8_t miso; + int8_t mosi; + int8_t ss; }; #if CONFIG_IDF_TARGET_ESP32S2 // ESP32S2 -#define SPI_COUNT (3) +#define SPI_COUNT (3) -#define SPI_CLK_IDX(p) ((p==0)?SPICLK_OUT_MUX_IDX:((p==1)?FSPICLK_OUT_MUX_IDX:((p==2)?SPI3_CLK_OUT_MUX_IDX:0))) -#define SPI_MISO_IDX(p) ((p==0)?SPIQ_OUT_IDX:((p==1)?FSPIQ_OUT_IDX:((p==2)?SPI3_Q_OUT_IDX:0))) -#define SPI_MOSI_IDX(p) ((p==0)?SPID_IN_IDX:((p==1)?FSPID_IN_IDX:((p==2)?SPI3_D_IN_IDX:0))) +#define SPI_CLK_IDX(p) ((p == 0) ? SPICLK_OUT_MUX_IDX : ((p == 1) ? FSPICLK_OUT_MUX_IDX : ((p == 2) ? SPI3_CLK_OUT_MUX_IDX : 0))) +#define SPI_MISO_IDX(p) ((p == 0) ? SPIQ_OUT_IDX : ((p == 1) ? FSPIQ_OUT_IDX : ((p == 2) ? SPI3_Q_OUT_IDX : 0))) +#define SPI_MOSI_IDX(p) ((p == 0) ? SPID_IN_IDX : ((p == 1) ? FSPID_IN_IDX : ((p == 2) ? SPI3_D_IN_IDX : 0))) -#define SPI_SPI_SS_IDX(n) ((n==0)?SPICS0_OUT_IDX:((n==1)?SPICS1_OUT_IDX:0)) -#define SPI_HSPI_SS_IDX(n) ((n==0)?SPI3_CS0_OUT_IDX:((n==1)?SPI3_CS1_OUT_IDX:((n==2)?SPI3_CS2_OUT_IDX:SPI3_CS0_OUT_IDX))) -#define SPI_FSPI_SS_IDX(n) ((n==0)?FSPICS0_OUT_IDX:((n==1)?FSPICS1_OUT_IDX:((n==2)?FSPICS2_OUT_IDX:FSPICS0_OUT_IDX))) -#define SPI_SS_IDX(p, n) ((p==0)?SPI_SPI_SS_IDX(n):((p==1)?SPI_SPI_SS_IDX(n):((p==2)?SPI_HSPI_SS_IDX(n):0))) +#define SPI_SPI_SS_IDX(n) ((n == 0) ? SPICS0_OUT_IDX : ((n == 1) ? SPICS1_OUT_IDX : 0)) +#define SPI_HSPI_SS_IDX(n) ((n == 0) ? SPI3_CS0_OUT_IDX : ((n == 1) ? SPI3_CS1_OUT_IDX : ((n == 2) ? SPI3_CS2_OUT_IDX : SPI3_CS0_OUT_IDX))) +#define SPI_FSPI_SS_IDX(n) ((n == 0) ? FSPICS0_OUT_IDX : ((n == 1) ? FSPICS1_OUT_IDX : ((n == 2) ? FSPICS2_OUT_IDX : FSPICS0_OUT_IDX))) +#define SPI_SS_IDX(p, n) ((p == 0) ? SPI_SPI_SS_IDX(n) : ((p == 1) ? SPI_SPI_SS_IDX(n) : ((p == 2) ? SPI_HSPI_SS_IDX(n) : 0))) #elif CONFIG_IDF_TARGET_ESP32S3 // ESP32S3 -#define SPI_COUNT (2) +#define SPI_COUNT (2) -#define SPI_CLK_IDX(p) ((p==0)?FSPICLK_OUT_IDX:((p==1)?SPI3_CLK_OUT_IDX:0)) -#define SPI_MISO_IDX(p) ((p==0)?FSPIQ_OUT_IDX:((p==1)?SPI3_Q_OUT_IDX:0)) -#define SPI_MOSI_IDX(p) ((p==0)?FSPID_IN_IDX:((p==1)?SPI3_D_IN_IDX:0)) +#define SPI_CLK_IDX(p) ((p == 0) ? FSPICLK_OUT_IDX : ((p == 1) ? SPI3_CLK_OUT_IDX : 0)) +#define SPI_MISO_IDX(p) ((p == 0) ? FSPIQ_OUT_IDX : ((p == 1) ? SPI3_Q_OUT_IDX : 0)) +#define SPI_MOSI_IDX(p) ((p == 0) ? FSPID_IN_IDX : ((p == 1) ? SPI3_D_IN_IDX : 0)) -#define SPI_HSPI_SS_IDX(n) ((n==0)?SPI3_CS0_OUT_IDX:((n==1)?SPI3_CS1_OUT_IDX:0)) -#define SPI_FSPI_SS_IDX(n) ((n==0)?FSPICS0_OUT_IDX:((n==1)?FSPICS1_OUT_IDX:0)) -#define SPI_SS_IDX(p, n) ((p==0)?SPI_FSPI_SS_IDX(n):((p==1)?SPI_HSPI_SS_IDX(n):0)) +#define SPI_HSPI_SS_IDX(n) ((n == 0) ? SPI3_CS0_OUT_IDX : ((n == 1) ? SPI3_CS1_OUT_IDX : 0)) +#define SPI_FSPI_SS_IDX(n) ((n == 0) ? FSPICS0_OUT_IDX : ((n == 1) ? FSPICS1_OUT_IDX : 0)) +#define SPI_SS_IDX(p, n) ((p == 0) ? SPI_FSPI_SS_IDX(n) : ((p == 1) ? SPI_HSPI_SS_IDX(n) : 0)) #elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 // ESP32C3 -#define SPI_COUNT (1) +#define SPI_COUNT (1) -#define SPI_CLK_IDX(p) FSPICLK_OUT_IDX -#define SPI_MISO_IDX(p) FSPIQ_OUT_IDX -#define SPI_MOSI_IDX(p) FSPID_IN_IDX +#define SPI_CLK_IDX(p) FSPICLK_OUT_IDX +#define SPI_MISO_IDX(p) FSPIQ_OUT_IDX +#define SPI_MOSI_IDX(p) FSPID_IN_IDX -#define SPI_SPI_SS_IDX(n) ((n==0)?FSPICS0_OUT_IDX:((n==1)?FSPICS1_OUT_IDX:((n==2)?FSPICS2_OUT_IDX:FSPICS0_OUT_IDX))) -#define SPI_SS_IDX(p, n) SPI_SPI_SS_IDX(n) +#define SPI_SPI_SS_IDX(n) ((n == 0) ? FSPICS0_OUT_IDX : ((n == 1) ? FSPICS1_OUT_IDX : ((n == 2) ? FSPICS2_OUT_IDX : FSPICS0_OUT_IDX))) +#define SPI_SS_IDX(p, n) SPI_SPI_SS_IDX(n) #else // ESP32 -#define SPI_COUNT (4) +#define SPI_COUNT (4) -#define SPI_CLK_IDX(p) ((p==0)?SPICLK_OUT_IDX:((p==1)?SPICLK_OUT_IDX:((p==2)?HSPICLK_OUT_IDX:((p==3)?VSPICLK_OUT_IDX:0)))) -#define SPI_MISO_IDX(p) ((p==0)?SPIQ_OUT_IDX:((p==1)?SPIQ_OUT_IDX:((p==2)?HSPIQ_OUT_IDX:((p==3)?VSPIQ_OUT_IDX:0)))) -#define SPI_MOSI_IDX(p) ((p==0)?SPID_IN_IDX:((p==1)?SPID_IN_IDX:((p==2)?HSPID_IN_IDX:((p==3)?VSPID_IN_IDX:0)))) +#define SPI_CLK_IDX(p) ((p == 0) ? SPICLK_OUT_IDX : ((p == 1) ? SPICLK_OUT_IDX : ((p == 2) ? HSPICLK_OUT_IDX : ((p == 3) ? VSPICLK_OUT_IDX : 0)))) +#define SPI_MISO_IDX(p) ((p == 0) ? SPIQ_OUT_IDX : ((p == 1) ? SPIQ_OUT_IDX : ((p == 2) ? HSPIQ_OUT_IDX : ((p == 3) ? VSPIQ_OUT_IDX : 0)))) +#define SPI_MOSI_IDX(p) ((p == 0) ? SPID_IN_IDX : ((p == 1) ? SPID_IN_IDX : ((p == 2) ? HSPID_IN_IDX : ((p == 3) ? VSPID_IN_IDX : 0)))) -#define SPI_SPI_SS_IDX(n) ((n==0)?SPICS0_OUT_IDX:((n==1)?SPICS1_OUT_IDX:((n==2)?SPICS2_OUT_IDX:SPICS0_OUT_IDX))) -#define SPI_HSPI_SS_IDX(n) ((n==0)?HSPICS0_OUT_IDX:((n==1)?HSPICS1_OUT_IDX:((n==2)?HSPICS2_OUT_IDX:HSPICS0_OUT_IDX))) -#define SPI_VSPI_SS_IDX(n) ((n==0)?VSPICS0_OUT_IDX:((n==1)?VSPICS1_OUT_IDX:((n==2)?VSPICS2_OUT_IDX:VSPICS0_OUT_IDX))) -#define SPI_SS_IDX(p, n) ((p==0)?SPI_SPI_SS_IDX(n):((p==1)?SPI_SPI_SS_IDX(n):((p==2)?SPI_HSPI_SS_IDX(n):((p==3)?SPI_VSPI_SS_IDX(n):0)))) +#define SPI_SPI_SS_IDX(n) ((n == 0) ? SPICS0_OUT_IDX : ((n == 1) ? SPICS1_OUT_IDX : ((n == 2) ? SPICS2_OUT_IDX : SPICS0_OUT_IDX))) +#define SPI_HSPI_SS_IDX(n) ((n == 0) ? HSPICS0_OUT_IDX : ((n == 1) ? HSPICS1_OUT_IDX : ((n == 2) ? HSPICS2_OUT_IDX : HSPICS0_OUT_IDX))) +#define SPI_VSPI_SS_IDX(n) ((n == 0) ? VSPICS0_OUT_IDX : ((n == 1) ? VSPICS1_OUT_IDX : ((n == 2) ? VSPICS2_OUT_IDX : VSPICS0_OUT_IDX))) +#define SPI_SS_IDX(p, n) ((p == 0) ? SPI_SPI_SS_IDX(n) : ((p == 1) ? SPI_SPI_SS_IDX(n) : ((p == 2) ? SPI_HSPI_SS_IDX(n) : ((p == 3) ? SPI_VSPI_SS_IDX(n) : 0)))) #endif @@ -128,586 +128,564 @@ struct spi_struct_t { static spi_t _spi_bus_array[] = { #if CONFIG_IDF_TARGET_ESP32S2 - {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), 0, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 1, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 2, -1, -1, -1, -1} + { (volatile spi_dev_t *)(DR_REG_SPI1_BASE), 0, -1, -1, -1, -1 }, + { (volatile spi_dev_t *)(DR_REG_SPI2_BASE), 1, -1, -1, -1, -1 }, + { (volatile spi_dev_t *)(DR_REG_SPI3_BASE), 2, -1, -1, -1, -1 } #elif CONFIG_IDF_TARGET_ESP32S3 - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 1, -1, -1, -1, -1} + { (volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1 }, + { (volatile spi_dev_t *)(DR_REG_SPI3_BASE), 1, -1, -1, -1, -1 } #elif CONFIG_IDF_TARGET_ESP32C2 - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1} + { (volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1 } #elif CONFIG_IDF_TARGET_ESP32C3 - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1} + { (volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1 } #elif CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - {(spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1} + { (spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1 } #else - {(volatile spi_dev_t *)(DR_REG_SPI0_BASE), 0, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), 1, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 2, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 3, -1, -1, -1, -1} + { (volatile spi_dev_t *)(DR_REG_SPI0_BASE), 0, -1, -1, -1, -1 }, + { (volatile spi_dev_t *)(DR_REG_SPI1_BASE), 1, -1, -1, -1, -1 }, + { (volatile spi_dev_t *)(DR_REG_SPI2_BASE), 2, -1, -1, -1, -1 }, + { (volatile spi_dev_t *)(DR_REG_SPI3_BASE), 3, -1, -1, -1, -1 } #endif }; #else -#define SPI_MUTEX_LOCK() do {} while (xSemaphoreTake(spi->lock, portMAX_DELAY) != pdPASS) -#define SPI_MUTEX_UNLOCK() xSemaphoreGive(spi->lock) +#define SPI_MUTEX_LOCK() \ + do { \ + } while (xSemaphoreTake(spi->lock, portMAX_DELAY) != pdPASS) +#define SPI_MUTEX_UNLOCK() xSemaphoreGive(spi->lock) static spi_t _spi_bus_array[] = { #if CONFIG_IDF_TARGET_ESP32S2 - {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), NULL, 0, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 1, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 2, -1, -1, -1, -1} + { (volatile spi_dev_t *)(DR_REG_SPI1_BASE), NULL, 0, -1, -1, -1, -1 }, + { (volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 1, -1, -1, -1, -1 }, + { (volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 2, -1, -1, -1, -1 } #elif CONFIG_IDF_TARGET_ESP32S3 - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 1, -1, -1, -1, -1} + { (volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1 }, + { (volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 1, -1, -1, -1, -1 } #elif CONFIG_IDF_TARGET_ESP32C2 - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1} + { (volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1 } #elif CONFIG_IDF_TARGET_ESP32C3 - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1} + { (volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1 } #elif CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - {(spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1} + { (spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1 } #else - {(volatile spi_dev_t *)(DR_REG_SPI0_BASE), NULL, 0, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), NULL, 1, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 2, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 3, -1, -1, -1, -1} + { (volatile spi_dev_t *)(DR_REG_SPI0_BASE), NULL, 0, -1, -1, -1, -1 }, + { (volatile spi_dev_t *)(DR_REG_SPI1_BASE), NULL, 1, -1, -1, -1, -1 }, + { (volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 2, -1, -1, -1, -1 }, + { (volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 3, -1, -1, -1, -1 } #endif }; #endif -static bool spiDetachBus(void * bus){ - uint8_t spi_num = (int)bus - 1; - spi_t * spi = &_spi_bus_array[spi_num]; +static bool spiDetachBus(void *bus) { + uint8_t spi_num = (int)bus - 1; + spi_t *spi = &_spi_bus_array[spi_num]; - if(spi->dev->clock.val == 0){ - log_d("SPI bus already stopped"); - return true; - } - else if(spi->sck == -1 || (spi->miso == -1 && spi->mosi == -1)){ - log_d("Stopping SPI bus"); - spiStopBus(spi); - - spiDetachSCK(spi); - spiDetachMISO(spi); - spiDetachMOSI(spi); - spiDetachSS(spi); - spi = NULL; - return true; - } + if (spi->dev->clock.val == 0) { + log_d("SPI bus already stopped"); return true; + } else if (spi->sck == -1 || (spi->miso == -1 && spi->mosi == -1)) { + log_d("Stopping SPI bus"); + spiStopBus(spi); + + spiDetachSCK(spi); + spiDetachMISO(spi); + spiDetachMOSI(spi); + spiDetachSS(spi); + spi = NULL; + return true; + } + return true; } -static bool spiDetachBus_SCK(void * bus){ - uint8_t spi_num = (int)bus - 1; - spi_t * spi = &_spi_bus_array[spi_num]; - if(spi->sck != -1){ - spiDetachSCK(spi); - spiDetachBus(bus); - } - return true; +static bool spiDetachBus_SCK(void *bus) { + uint8_t spi_num = (int)bus - 1; + spi_t *spi = &_spi_bus_array[spi_num]; + if (spi->sck != -1) { + spiDetachSCK(spi); + spiDetachBus(bus); + } + return true; } -static bool spiDetachBus_MISO(void * bus){ - uint8_t spi_num = (int)bus - 1; - spi_t * spi = &_spi_bus_array[spi_num]; - if(spi->miso != -1){ - spiDetachMISO(spi); - spiDetachBus(bus); - } - return true; +static bool spiDetachBus_MISO(void *bus) { + uint8_t spi_num = (int)bus - 1; + spi_t *spi = &_spi_bus_array[spi_num]; + if (spi->miso != -1) { + spiDetachMISO(spi); + spiDetachBus(bus); + } + return true; } -static bool spiDetachBus_MOSI(void * bus){ - uint8_t spi_num = (int)bus - 1; - spi_t * spi = &_spi_bus_array[spi_num]; - if(spi->mosi != -1){ - spiDetachMOSI(spi); - spiDetachBus(bus); - } - return true; +static bool spiDetachBus_MOSI(void *bus) { + uint8_t spi_num = (int)bus - 1; + spi_t *spi = &_spi_bus_array[spi_num]; + if (spi->mosi != -1) { + spiDetachMOSI(spi); + spiDetachBus(bus); + } + return true; } -static bool spiDetachBus_SS(void * bus){ - uint8_t spi_num = (int)bus - 1; - spi_t * spi = &_spi_bus_array[spi_num]; - if(spi->ss != -1){ - spiDetachSS(spi); - spiDetachBus(bus); - } - return true; +static bool spiDetachBus_SS(void *bus) { + uint8_t spi_num = (int)bus - 1; + spi_t *spi = &_spi_bus_array[spi_num]; + if (spi->ss != -1) { + spiDetachSS(spi); + spiDetachBus(bus); + } + return true; } -bool spiAttachSCK(spi_t * spi, int8_t sck) -{ - if(!spi || sck < 0) { - return false; - } - void * bus = perimanGetPinBus(sck, ESP32_BUS_TYPE_SPI_MASTER_SCK); - if(bus != NULL && !perimanClearPinBus(sck)){ - return false; - } - pinMode(sck, OUTPUT); - pinMatrixOutAttach(sck, SPI_CLK_IDX(spi->num), false, false); - spi->sck = sck; - if(!perimanSetPinBus(sck, ESP32_BUS_TYPE_SPI_MASTER_SCK, (void *)(spi->num+1), spi->num, -1)){ - spiDetachBus_SCK((void *)(spi->num+1)); - log_e("Failed to set pin bus to SPI for pin %d", sck); - return false; - } - return true; +bool spiAttachSCK(spi_t *spi, int8_t sck) { + if (!spi || sck < 0) { + return false; + } + void *bus = perimanGetPinBus(sck, ESP32_BUS_TYPE_SPI_MASTER_SCK); + if (bus != NULL && !perimanClearPinBus(sck)) { + return false; + } + pinMode(sck, OUTPUT); + pinMatrixOutAttach(sck, SPI_CLK_IDX(spi->num), false, false); + spi->sck = sck; + if (!perimanSetPinBus(sck, ESP32_BUS_TYPE_SPI_MASTER_SCK, (void *)(spi->num + 1), spi->num, -1)) { + spiDetachBus_SCK((void *)(spi->num + 1)); + log_e("Failed to set pin bus to SPI for pin %d", sck); + return false; + } + return true; } -bool spiAttachMISO(spi_t * spi, int8_t miso) -{ - if(!spi || miso < 0) { - return false; - } - void * bus = perimanGetPinBus(miso, ESP32_BUS_TYPE_SPI_MASTER_MISO); - if(bus != NULL && !perimanClearPinBus(miso)){ - return false; - } - pinMode(miso, INPUT); - pinMatrixInAttach(miso, SPI_MISO_IDX(spi->num), false); - spi->miso = miso; - if(!perimanSetPinBus(miso, ESP32_BUS_TYPE_SPI_MASTER_MISO, (void *)(spi->num+1), spi->num, -1)){ - spiDetachBus_MISO((void *)(spi->num+1)); - log_e("Failed to set pin bus to SPI for pin %d", miso); - return false; - } - return true; +bool spiAttachMISO(spi_t *spi, int8_t miso) { + if (!spi || miso < 0) { + return false; + } + void *bus = perimanGetPinBus(miso, ESP32_BUS_TYPE_SPI_MASTER_MISO); + if (bus != NULL && !perimanClearPinBus(miso)) { + return false; + } + pinMode(miso, INPUT); + pinMatrixInAttach(miso, SPI_MISO_IDX(spi->num), false); + spi->miso = miso; + if (!perimanSetPinBus(miso, ESP32_BUS_TYPE_SPI_MASTER_MISO, (void *)(spi->num + 1), spi->num, -1)) { + spiDetachBus_MISO((void *)(spi->num + 1)); + log_e("Failed to set pin bus to SPI for pin %d", miso); + return false; + } + return true; } -bool spiAttachMOSI(spi_t * spi, int8_t mosi) -{ - if(!spi || mosi < 0) { - return false; - } - void * bus = perimanGetPinBus(mosi, ESP32_BUS_TYPE_SPI_MASTER_MOSI); - if(bus != NULL && !perimanClearPinBus(mosi)){ - return false; - } - pinMode(mosi, OUTPUT); - pinMatrixOutAttach(mosi, SPI_MOSI_IDX(spi->num), false, false); - spi->mosi = mosi; - if(!perimanSetPinBus(mosi, ESP32_BUS_TYPE_SPI_MASTER_MOSI, (void *)(spi->num+1), spi->num, -1)){ - spiDetachBus_MOSI((void *)(spi->num+1)); - log_e("Failed to set pin bus to SPI for pin %d", mosi); - return false; - } - return true; +bool spiAttachMOSI(spi_t *spi, int8_t mosi) { + if (!spi || mosi < 0) { + return false; + } + void *bus = perimanGetPinBus(mosi, ESP32_BUS_TYPE_SPI_MASTER_MOSI); + if (bus != NULL && !perimanClearPinBus(mosi)) { + return false; + } + pinMode(mosi, OUTPUT); + pinMatrixOutAttach(mosi, SPI_MOSI_IDX(spi->num), false, false); + spi->mosi = mosi; + if (!perimanSetPinBus(mosi, ESP32_BUS_TYPE_SPI_MASTER_MOSI, (void *)(spi->num + 1), spi->num, -1)) { + spiDetachBus_MOSI((void *)(spi->num + 1)); + log_e("Failed to set pin bus to SPI for pin %d", mosi); + return false; + } + return true; } -bool spiDetachSCK(spi_t * spi) -{ - if(!spi) { - return false; - } - int8_t sck = spi->sck; - if(sck != -1) { - pinMatrixOutDetach(sck, false, false); - spi->sck = -1; - perimanClearPinBus(sck); - } - return true; +bool spiDetachSCK(spi_t *spi) { + if (!spi) { + return false; + } + int8_t sck = spi->sck; + if (sck != -1) { + pinMatrixOutDetach(sck, false, false); + spi->sck = -1; + perimanClearPinBus(sck); + } + return true; } -bool spiDetachMISO(spi_t * spi) -{ - if(!spi) { - return false; - } - int8_t miso = spi->miso; - if(miso != -1) { - pinMatrixInDetach(SPI_MISO_IDX(spi->num), false, false); - spi->miso = -1; - perimanClearPinBus(miso); - } - return true; +bool spiDetachMISO(spi_t *spi) { + if (!spi) { + return false; + } + int8_t miso = spi->miso; + if (miso != -1) { + pinMatrixInDetach(SPI_MISO_IDX(spi->num), false, false); + spi->miso = -1; + perimanClearPinBus(miso); + } + return true; } -bool spiDetachMOSI(spi_t * spi) -{ - if(!spi) { - return false; - } - int8_t mosi = spi->mosi; - if(mosi != -1) { - pinMatrixOutDetach(mosi, false, false); - spi->mosi = -1; - perimanClearPinBus(mosi); - } - return true; +bool spiDetachMOSI(spi_t *spi) { + if (!spi) { + return false; + } + int8_t mosi = spi->mosi; + if (mosi != -1) { + pinMatrixOutDetach(mosi, false, false); + spi->mosi = -1; + perimanClearPinBus(mosi); + } + return true; } -bool spiAttachSS(spi_t * spi, uint8_t ss_num, int8_t ss) -{ - if(!spi || ss < 0 || ss_num > 2) { - return false; - } - void * bus = perimanGetPinBus(ss, ESP32_BUS_TYPE_SPI_MASTER_SS); - if(bus != NULL && !perimanClearPinBus(ss)){ - return false; - } - pinMode(ss, OUTPUT); - pinMatrixOutAttach(ss, SPI_SS_IDX(spi->num, ss_num), false, false); - spiEnableSSPins(spi, (1 << ss_num)); - spi->ss = ss; - if(!perimanSetPinBus(ss, ESP32_BUS_TYPE_SPI_MASTER_SS, (void *)(spi->num+1), spi->num, -1)){ - spiDetachBus_SS((void *)(spi->num+1)); - log_e("Failed to set pin bus to SPI for pin %d", ss); - return false; - } - return true; +bool spiAttachSS(spi_t *spi, uint8_t ss_num, int8_t ss) { + if (!spi || ss < 0 || ss_num > 2) { + return false; + } + void *bus = perimanGetPinBus(ss, ESP32_BUS_TYPE_SPI_MASTER_SS); + if (bus != NULL && !perimanClearPinBus(ss)) { + return false; + } + pinMode(ss, OUTPUT); + pinMatrixOutAttach(ss, SPI_SS_IDX(spi->num, ss_num), false, false); + spiEnableSSPins(spi, (1 << ss_num)); + spi->ss = ss; + if (!perimanSetPinBus(ss, ESP32_BUS_TYPE_SPI_MASTER_SS, (void *)(spi->num + 1), spi->num, -1)) { + spiDetachBus_SS((void *)(spi->num + 1)); + log_e("Failed to set pin bus to SPI for pin %d", ss); + return false; + } + return true; } -bool spiDetachSS(spi_t * spi) -{ - if(!spi) { - return false; - } - int8_t ss = spi->ss; - if(ss != -1) { - pinMatrixOutDetach(ss, false, false); - spi->ss = -1; - perimanClearPinBus(ss); - } - return true; +bool spiDetachSS(spi_t *spi) { + if (!spi) { + return false; + } + int8_t ss = spi->ss; + if (ss != -1) { + pinMatrixOutDetach(ss, false, false); + spi->ss = -1; + perimanClearPinBus(ss); + } + return true; } -void spiEnableSSPins(spi_t * spi, uint8_t ss_mask) -{ - if(!spi) { - return; - } - SPI_MUTEX_LOCK(); +void spiEnableSSPins(spi_t *spi, uint8_t ss_mask) { + if (!spi) { + return; + } + SPI_MUTEX_LOCK(); #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->misc.val &= ~(ss_mask & SPI_SS_MASK_ALL); + spi->dev->misc.val &= ~(ss_mask & SPI_SS_MASK_ALL); #else - spi->dev->pin.val &= ~(ss_mask & SPI_SS_MASK_ALL); + spi->dev->pin.val &= ~(ss_mask & SPI_SS_MASK_ALL); #endif - SPI_MUTEX_UNLOCK(); + SPI_MUTEX_UNLOCK(); } -void spiDisableSSPins(spi_t * spi, uint8_t ss_mask) -{ - if(!spi) { - return; - } - SPI_MUTEX_LOCK(); +void spiDisableSSPins(spi_t *spi, uint8_t ss_mask) { + if (!spi) { + return; + } + SPI_MUTEX_LOCK(); #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->misc.val |= (ss_mask & SPI_SS_MASK_ALL); + spi->dev->misc.val |= (ss_mask & SPI_SS_MASK_ALL); #else - spi->dev->pin.val |= (ss_mask & SPI_SS_MASK_ALL); + spi->dev->pin.val |= (ss_mask & SPI_SS_MASK_ALL); #endif - SPI_MUTEX_UNLOCK(); + SPI_MUTEX_UNLOCK(); } -void spiSSEnable(spi_t * spi) -{ - if(!spi) { - return; - } - SPI_MUTEX_LOCK(); - spi->dev->user.cs_setup = 1; - spi->dev->user.cs_hold = 1; - SPI_MUTEX_UNLOCK(); +void spiSSEnable(spi_t *spi) { + if (!spi) { + return; + } + SPI_MUTEX_LOCK(); + spi->dev->user.cs_setup = 1; + spi->dev->user.cs_hold = 1; + SPI_MUTEX_UNLOCK(); } -void spiSSDisable(spi_t * spi) -{ - if(!spi) { - return; - } - SPI_MUTEX_LOCK(); - spi->dev->user.cs_setup = 0; - spi->dev->user.cs_hold = 0; - SPI_MUTEX_UNLOCK(); +void spiSSDisable(spi_t *spi) { + if (!spi) { + return; + } + SPI_MUTEX_LOCK(); + spi->dev->user.cs_setup = 0; + spi->dev->user.cs_hold = 0; + SPI_MUTEX_UNLOCK(); } -void spiSSSet(spi_t * spi) -{ - if(!spi) { - return; - } - SPI_MUTEX_LOCK(); +void spiSSSet(spi_t *spi) { + if (!spi) { + return; + } + SPI_MUTEX_LOCK(); #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->misc.cs_keep_active = 1; + spi->dev->misc.cs_keep_active = 1; #else - spi->dev->pin.cs_keep_active = 1; + spi->dev->pin.cs_keep_active = 1; #endif - SPI_MUTEX_UNLOCK(); + SPI_MUTEX_UNLOCK(); } -void spiSSClear(spi_t * spi) -{ - if(!spi) { - return; - } - SPI_MUTEX_LOCK(); +void spiSSClear(spi_t *spi) { + if (!spi) { + return; + } + SPI_MUTEX_LOCK(); #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->misc.cs_keep_active = 0; + spi->dev->misc.cs_keep_active = 0; #else - spi->dev->pin.cs_keep_active = 0; + spi->dev->pin.cs_keep_active = 0; #endif - SPI_MUTEX_UNLOCK(); + SPI_MUTEX_UNLOCK(); } -uint32_t spiGetClockDiv(spi_t * spi) -{ - if(!spi) { - return 0; - } - return spi->dev->clock.val; +uint32_t spiGetClockDiv(spi_t *spi) { + if (!spi) { + return 0; + } + return spi->dev->clock.val; } -void spiSetClockDiv(spi_t * spi, uint32_t clockDiv) -{ - if(!spi) { - return; - } - SPI_MUTEX_LOCK(); - spi->dev->clock.val = clockDiv; - SPI_MUTEX_UNLOCK(); +void spiSetClockDiv(spi_t *spi, uint32_t clockDiv) { + if (!spi) { + return; + } + SPI_MUTEX_LOCK(); + spi->dev->clock.val = clockDiv; + SPI_MUTEX_UNLOCK(); } -uint8_t spiGetDataMode(spi_t * spi) -{ - if(!spi) { - return 0; - } +uint8_t spiGetDataMode(spi_t *spi) { + if (!spi) { + return 0; + } #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - bool idleEdge = spi->dev->misc.ck_idle_edge; + bool idleEdge = spi->dev->misc.ck_idle_edge; #else - bool idleEdge = spi->dev->pin.ck_idle_edge; -#endif - bool outEdge = spi->dev->user.ck_out_edge; - if(idleEdge) { - if(outEdge) { - return SPI_MODE2; - } - return SPI_MODE3; - } - if(outEdge) { - return SPI_MODE1; - } - return SPI_MODE0; + bool idleEdge = spi->dev->pin.ck_idle_edge; +#endif + bool outEdge = spi->dev->user.ck_out_edge; + if (idleEdge) { + if (outEdge) { + return SPI_MODE2; + } + return SPI_MODE3; + } + if (outEdge) { + return SPI_MODE1; + } + return SPI_MODE0; } -void spiSetDataMode(spi_t * spi, uint8_t dataMode) -{ - if(!spi) { - return; - } - SPI_MUTEX_LOCK(); - switch (dataMode) { +void spiSetDataMode(spi_t *spi, uint8_t dataMode) { + if (!spi) { + return; + } + SPI_MUTEX_LOCK(); + switch (dataMode) { case SPI_MODE1: #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->misc.ck_idle_edge = 0; + spi->dev->misc.ck_idle_edge = 0; #else - spi->dev->pin.ck_idle_edge = 0; + spi->dev->pin.ck_idle_edge = 0; #endif - spi->dev->user.ck_out_edge = 1; - break; + spi->dev->user.ck_out_edge = 1; + break; case SPI_MODE2: #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->misc.ck_idle_edge = 1; + spi->dev->misc.ck_idle_edge = 1; #else - spi->dev->pin.ck_idle_edge = 1; + spi->dev->pin.ck_idle_edge = 1; #endif - spi->dev->user.ck_out_edge = 1; - break; + spi->dev->user.ck_out_edge = 1; + break; case SPI_MODE3: #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->misc.ck_idle_edge = 1; + spi->dev->misc.ck_idle_edge = 1; #else - spi->dev->pin.ck_idle_edge = 1; + spi->dev->pin.ck_idle_edge = 1; #endif - spi->dev->user.ck_out_edge = 0; - break; + spi->dev->user.ck_out_edge = 0; + break; case SPI_MODE0: default: #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->misc.ck_idle_edge = 0; + spi->dev->misc.ck_idle_edge = 0; #else - spi->dev->pin.ck_idle_edge = 0; + spi->dev->pin.ck_idle_edge = 0; #endif - spi->dev->user.ck_out_edge = 0; - break; - } - SPI_MUTEX_UNLOCK(); + spi->dev->user.ck_out_edge = 0; + break; + } + SPI_MUTEX_UNLOCK(); } -uint8_t spiGetBitOrder(spi_t * spi) -{ - if(!spi) { - return 0; - } - return (spi->dev->ctrl.wr_bit_order | spi->dev->ctrl.rd_bit_order) == 0; +uint8_t spiGetBitOrder(spi_t *spi) { + if (!spi) { + return 0; + } + return (spi->dev->ctrl.wr_bit_order | spi->dev->ctrl.rd_bit_order) == 0; } -void spiSetBitOrder(spi_t * spi, uint8_t bitOrder) -{ - if(!spi) { - return; - } - SPI_MUTEX_LOCK(); - if (SPI_MSBFIRST == bitOrder) { - spi->dev->ctrl.wr_bit_order = 0; - spi->dev->ctrl.rd_bit_order = 0; - } else if (SPI_LSBFIRST == bitOrder) { - spi->dev->ctrl.wr_bit_order = 1; - spi->dev->ctrl.rd_bit_order = 1; - } - SPI_MUTEX_UNLOCK(); +void spiSetBitOrder(spi_t *spi, uint8_t bitOrder) { + if (!spi) { + return; + } + SPI_MUTEX_LOCK(); + if (SPI_MSBFIRST == bitOrder) { + spi->dev->ctrl.wr_bit_order = 0; + spi->dev->ctrl.rd_bit_order = 0; + } else if (SPI_LSBFIRST == bitOrder) { + spi->dev->ctrl.wr_bit_order = 1; + spi->dev->ctrl.rd_bit_order = 1; + } + SPI_MUTEX_UNLOCK(); } -static void _on_apb_change(void * arg, apb_change_ev_t ev_type, uint32_t old_apb, uint32_t new_apb) -{ - spi_t * spi = (spi_t *)arg; - if(ev_type == APB_BEFORE_CHANGE){ - SPI_MUTEX_LOCK(); - while(spi->dev->cmd.usr); - } else { - spi->dev->clock.val = spiFrequencyToClockDiv(old_apb / ((spi->dev->clock.clkdiv_pre + 1) * (spi->dev->clock.clkcnt_n + 1))); - SPI_MUTEX_UNLOCK(); - } +static void _on_apb_change(void *arg, apb_change_ev_t ev_type, uint32_t old_apb, uint32_t new_apb) { + spi_t *spi = (spi_t *)arg; + if (ev_type == APB_BEFORE_CHANGE) { + SPI_MUTEX_LOCK(); + while (spi->dev->cmd.usr) + ; + } else { + spi->dev->clock.val = spiFrequencyToClockDiv(old_apb / ((spi->dev->clock.clkdiv_pre + 1) * (spi->dev->clock.clkcnt_n + 1))); + SPI_MUTEX_UNLOCK(); + } } -static void spiInitBus(spi_t * spi) -{ +static void spiInitBus(spi_t *spi) { #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 - spi->dev->slave.trans_done = 0; + spi->dev->slave.trans_done = 0; #endif - spi->dev->slave.val = 0; + spi->dev->slave.val = 0; #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->misc.val = 0; + spi->dev->misc.val = 0; #else - spi->dev->pin.val = 0; + spi->dev->pin.val = 0; #endif - spi->dev->user.val = 0; - spi->dev->user1.val = 0; - spi->dev->ctrl.val = 0; + spi->dev->user.val = 0; + spi->dev->user1.val = 0; + spi->dev->ctrl.val = 0; #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 - spi->dev->ctrl1.val = 0; - spi->dev->ctrl2.val = 0; + spi->dev->ctrl1.val = 0; + spi->dev->ctrl2.val = 0; #else - spi->dev->clk_gate.val = 0; - spi->dev->dma_conf.val = 0; - spi->dev->dma_conf.rx_afifo_rst = 1; - spi->dev->dma_conf.buf_afifo_rst = 1; + spi->dev->clk_gate.val = 0; + spi->dev->dma_conf.val = 0; + spi->dev->dma_conf.rx_afifo_rst = 1; + spi->dev->dma_conf.buf_afifo_rst = 1; #endif - spi->dev->clock.val = 0; + spi->dev->clock.val = 0; } -void spiStopBus(spi_t * spi) -{ - if(!spi) { - return; - } +void spiStopBus(spi_t *spi) { + if (!spi) { + return; + } - removeApbChangeCallback(spi, _on_apb_change); + removeApbChangeCallback(spi, _on_apb_change); - SPI_MUTEX_LOCK(); - spiInitBus(spi); - SPI_MUTEX_UNLOCK(); + SPI_MUTEX_LOCK(); + spiInitBus(spi); + SPI_MUTEX_UNLOCK(); } -spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_t bitOrder) -{ - if(spi_num >= SPI_COUNT){ - return NULL; - } +spi_t *spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_t bitOrder) { + if (spi_num >= SPI_COUNT) { + return NULL; + } - perimanSetBusDeinit(ESP32_BUS_TYPE_SPI_MASTER_SCK, spiDetachBus_SCK); - perimanSetBusDeinit(ESP32_BUS_TYPE_SPI_MASTER_MISO, spiDetachBus_MISO); - perimanSetBusDeinit(ESP32_BUS_TYPE_SPI_MASTER_MOSI, spiDetachBus_MOSI); - perimanSetBusDeinit(ESP32_BUS_TYPE_SPI_MASTER_SS, spiDetachBus_SS); + perimanSetBusDeinit(ESP32_BUS_TYPE_SPI_MASTER_SCK, spiDetachBus_SCK); + perimanSetBusDeinit(ESP32_BUS_TYPE_SPI_MASTER_MISO, spiDetachBus_MISO); + perimanSetBusDeinit(ESP32_BUS_TYPE_SPI_MASTER_MOSI, spiDetachBus_MOSI); + perimanSetBusDeinit(ESP32_BUS_TYPE_SPI_MASTER_SS, spiDetachBus_SS); - spi_t * spi = &_spi_bus_array[spi_num]; + spi_t *spi = &_spi_bus_array[spi_num]; #if !CONFIG_DISABLE_HAL_LOCKS - if(spi->lock == NULL){ - spi->lock = xSemaphoreCreateMutex(); - if(spi->lock == NULL) { - return NULL; - } + if (spi->lock == NULL) { + spi->lock = xSemaphoreCreateMutex(); + if (spi->lock == NULL) { + return NULL; } + } #endif #if CONFIG_IDF_TARGET_ESP32S2 - if(spi_num == FSPI) { - DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI2_CLK_EN); - DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI2_RST); - } else if(spi_num == HSPI) { - DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI3_CLK_EN); - DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI3_RST); - } else { - DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI01_CLK_EN); - DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI01_RST); - } + if (spi_num == FSPI) { + DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI2_CLK_EN); + DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI2_RST); + } else if (spi_num == HSPI) { + DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI3_CLK_EN); + DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI3_RST); + } else { + DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI01_CLK_EN); + DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI01_RST); + } #elif CONFIG_IDF_TARGET_ESP32S3 - if(spi_num == FSPI) { - periph_ll_reset( PERIPH_SPI2_MODULE ); - periph_ll_enable_clk_clear_rst( PERIPH_SPI2_MODULE ); - } else if(spi_num == HSPI) { - periph_ll_reset( PERIPH_SPI3_MODULE ); - periph_ll_enable_clk_clear_rst( PERIPH_SPI3_MODULE ); - } + if (spi_num == FSPI) { + periph_ll_reset(PERIPH_SPI2_MODULE); + periph_ll_enable_clk_clear_rst(PERIPH_SPI2_MODULE); + } else if (spi_num == HSPI) { + periph_ll_reset(PERIPH_SPI3_MODULE); + periph_ll_enable_clk_clear_rst(PERIPH_SPI3_MODULE); + } #elif CONFIG_IDF_TARGET_ESP32 - if(spi_num == HSPI) { - DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI2_CLK_EN); - DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI2_RST); - } else if(spi_num == VSPI) { - DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI3_CLK_EN); - DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI3_RST); - } else { - DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI01_CLK_EN); - DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI01_RST); - } + if (spi_num == HSPI) { + DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI2_CLK_EN); + DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI2_RST); + } else if (spi_num == VSPI) { + DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI3_CLK_EN); + DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI3_RST); + } else { + DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI01_CLK_EN); + DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI01_RST); + } #elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - periph_ll_reset( PERIPH_SPI2_MODULE ); - periph_ll_enable_clk_clear_rst( PERIPH_SPI2_MODULE ); + periph_ll_reset(PERIPH_SPI2_MODULE); + periph_ll_enable_clk_clear_rst(PERIPH_SPI2_MODULE); #endif - SPI_MUTEX_LOCK(); - spiInitBus(spi); + SPI_MUTEX_LOCK(); + spiInitBus(spi); #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->clk_gate.clk_en = 1; - spi->dev->clk_gate.mst_clk_sel = 1; - spi->dev->clk_gate.mst_clk_active = 1; + spi->dev->clk_gate.clk_en = 1; + spi->dev->clk_gate.mst_clk_sel = 1; + spi->dev->clk_gate.mst_clk_active = 1; #if !CONFIG_IDF_TARGET_ESP32C6 && !CONFIG_IDF_TARGET_ESP32H2 - spi->dev->dma_conf.tx_seg_trans_clr_en = 1; - spi->dev->dma_conf.rx_seg_trans_clr_en = 1; - spi->dev->dma_conf.dma_seg_trans_en = 0; -#endif -#endif - spi->dev->user.usr_mosi = 1; - spi->dev->user.usr_miso = 1; - spi->dev->user.doutdin = 1; - int i; - for(i=0; i<16; i++) { - #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[i].val = 0x00000000; - #else - spi->dev->data_buf[i] = 0x00000000; - #endif - } - SPI_MUTEX_UNLOCK(); + spi->dev->dma_conf.tx_seg_trans_clr_en = 1; + spi->dev->dma_conf.rx_seg_trans_clr_en = 1; + spi->dev->dma_conf.dma_seg_trans_en = 0; +#endif +#endif + spi->dev->user.usr_mosi = 1; + spi->dev->user.usr_miso = 1; + spi->dev->user.doutdin = 1; + int i; + for (i = 0; i < 16; i++) { +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 + spi->dev->data_buf[i].val = 0x00000000; +#else + spi->dev->data_buf[i] = 0x00000000; +#endif + } + SPI_MUTEX_UNLOCK(); - spiSetDataMode(spi, dataMode); - spiSetBitOrder(spi, bitOrder); - spiSetClockDiv(spi, clockDiv); + spiSetDataMode(spi, dataMode); + spiSetBitOrder(spi, bitOrder); + spiSetClockDiv(spi, clockDiv); - addApbChangeCallback(spi, _on_apb_change); + addApbChangeCallback(spi, _on_apb_change); - return spi; + return spi; } -void spiWaitReady(spi_t * spi) -{ - if(!spi) { - return; - } - while(spi->dev->cmd.usr); +void spiWaitReady(spi_t *spi) { + if (!spi) { + return; + } + while (spi->dev->cmd.usr) + ; } #if CONFIG_IDF_TARGET_ESP32S2 @@ -720,820 +698,852 @@ void spiWaitReady(spi_t * spi) #define miso_dlen ms_dlen #endif -void spiWrite(spi_t * spi, const uint32_t *data, uint8_t len) -{ - if(!spi) { - return; - } - int i; - if(len > 16) { - len = 16; - } - SPI_MUTEX_LOCK(); - spi->dev->mosi_dlen.usr_mosi_dbitlen = (len * 32) - 1; +void spiWrite(spi_t *spi, const uint32_t *data, uint8_t len) { + if (!spi) { + return; + } + int i; + if (len > 16) { + len = 16; + } + SPI_MUTEX_LOCK(); + spi->dev->mosi_dlen.usr_mosi_dbitlen = (len * 32) - 1; #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 - spi->dev->miso_dlen.usr_miso_dbitlen = 0; + spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif - for(i=0; idev->data_buf[i].val = data[i]; + spi->dev->data_buf[i].val = data[i]; #else - spi->dev->data_buf[i] = data[i]; + spi->dev->data_buf[i] = data[i]; #endif - } + } #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); -#endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); - SPI_MUTEX_UNLOCK(); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; +#endif + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; + SPI_MUTEX_UNLOCK(); } -void spiTransfer(spi_t * spi, uint32_t *data, uint8_t len) -{ - if(!spi) { - return; - } - int i; - if(len > 16) { - len = 16; - } - SPI_MUTEX_LOCK(); - spi->dev->mosi_dlen.usr_mosi_dbitlen = (len * 32) - 1; - spi->dev->miso_dlen.usr_miso_dbitlen = (len * 32) - 1; - for(i=0; i 16) { + len = 16; + } + SPI_MUTEX_LOCK(); + spi->dev->mosi_dlen.usr_mosi_dbitlen = (len * 32) - 1; + spi->dev->miso_dlen.usr_miso_dbitlen = (len * 32) - 1; + for (i = 0; i < len; i++) { #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[i].val = data[i]; + spi->dev->data_buf[i].val = data[i]; #else - spi->dev->data_buf[i] = data[i]; + spi->dev->data_buf[i] = data[i]; #endif - } + } #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); -#endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); - for(i=0; idev->cmd.update = 1; + while (spi->dev->cmd.update) + ; +#endif + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; + for (i = 0; i < len; i++) { #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - data[i] = spi->dev->data_buf[i].val; + data[i] = spi->dev->data_buf[i].val; #else - data[i] = spi->dev->data_buf[i]; + data[i] = spi->dev->data_buf[i]; #endif - } - SPI_MUTEX_UNLOCK(); + } + SPI_MUTEX_UNLOCK(); } -void spiWriteByte(spi_t * spi, uint8_t data) -{ - if(!spi) { - return; - } - SPI_MUTEX_LOCK(); - spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; +void spiWriteByte(spi_t *spi, uint8_t data) { + if (!spi) { + return; + } + SPI_MUTEX_LOCK(); + spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 - spi->dev->miso_dlen.usr_miso_dbitlen = 0; + spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[0].val = data; + spi->dev->data_buf[0].val = data; #else - spi->dev->data_buf[0] = data; + spi->dev->data_buf[0] = data; #endif #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); -#endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); - SPI_MUTEX_UNLOCK(); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; +#endif + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; + SPI_MUTEX_UNLOCK(); } -uint8_t spiTransferByte(spi_t * spi, uint8_t data) -{ - if(!spi) { - return 0; - } - SPI_MUTEX_LOCK(); - spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; - spi->dev->miso_dlen.usr_miso_dbitlen = 7; +uint8_t spiTransferByte(spi_t *spi, uint8_t data) { + if (!spi) { + return 0; + } + SPI_MUTEX_LOCK(); + spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; + spi->dev->miso_dlen.usr_miso_dbitlen = 7; #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[0].val = data; + spi->dev->data_buf[0].val = data; #else - spi->dev->data_buf[0] = data; + spi->dev->data_buf[0] = data; #endif #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; #endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - data = spi->dev->data_buf[0].val & 0xFF; + data = spi->dev->data_buf[0].val & 0xFF; #else - data = spi->dev->data_buf[0] & 0xFF; + data = spi->dev->data_buf[0] & 0xFF; #endif - SPI_MUTEX_UNLOCK(); - return data; + SPI_MUTEX_UNLOCK(); + return data; } -static uint32_t __spiTranslate32(uint32_t data) -{ - union { - uint32_t l; - uint8_t b[4]; - } out; - out.l = data; - return out.b[3] | (out.b[2] << 8) | (out.b[1] << 16) | (out.b[0] << 24); +static uint32_t __spiTranslate32(uint32_t data) { + union { + uint32_t l; + uint8_t b[4]; + } out; + out.l = data; + return out.b[3] | (out.b[2] << 8) | (out.b[1] << 16) | (out.b[0] << 24); } -void spiWriteWord(spi_t * spi, uint16_t data) -{ - if(!spi) { - return; - } - if(!spi->dev->ctrl.wr_bit_order){ - data = (data >> 8) | (data << 8); - } - SPI_MUTEX_LOCK(); - spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; +void spiWriteWord(spi_t *spi, uint16_t data) { + if (!spi) { + return; + } + if (!spi->dev->ctrl.wr_bit_order) { + data = (data >> 8) | (data << 8); + } + SPI_MUTEX_LOCK(); + spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 - spi->dev->miso_dlen.usr_miso_dbitlen = 0; + spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[0].val = data; + spi->dev->data_buf[0].val = data; #else - spi->dev->data_buf[0] = data; + spi->dev->data_buf[0] = data; #endif #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); -#endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); - SPI_MUTEX_UNLOCK(); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; +#endif + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; + SPI_MUTEX_UNLOCK(); } -uint16_t spiTransferWord(spi_t * spi, uint16_t data) -{ - if(!spi) { - return 0; - } - if(!spi->dev->ctrl.wr_bit_order){ - data = (data >> 8) | (data << 8); - } - SPI_MUTEX_LOCK(); - spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; - spi->dev->miso_dlen.usr_miso_dbitlen = 15; +uint16_t spiTransferWord(spi_t *spi, uint16_t data) { + if (!spi) { + return 0; + } + if (!spi->dev->ctrl.wr_bit_order) { + data = (data >> 8) | (data << 8); + } + SPI_MUTEX_LOCK(); + spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; + spi->dev->miso_dlen.usr_miso_dbitlen = 15; #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[0].val = data; + spi->dev->data_buf[0].val = data; #else - spi->dev->data_buf[0] = data; + spi->dev->data_buf[0] = data; #endif #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; #endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - data = spi->dev->data_buf[0].val; + data = spi->dev->data_buf[0].val; #else - data = spi->dev->data_buf[0]; + data = spi->dev->data_buf[0]; #endif - SPI_MUTEX_UNLOCK(); - if(!spi->dev->ctrl.rd_bit_order){ - data = (data >> 8) | (data << 8); - } - return data; + SPI_MUTEX_UNLOCK(); + if (!spi->dev->ctrl.rd_bit_order) { + data = (data >> 8) | (data << 8); + } + return data; } -void spiWriteLong(spi_t * spi, uint32_t data) -{ - if(!spi) { - return; - } - if(!spi->dev->ctrl.wr_bit_order){ - data = __spiTranslate32(data); - } - SPI_MUTEX_LOCK(); - spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; +void spiWriteLong(spi_t *spi, uint32_t data) { + if (!spi) { + return; + } + if (!spi->dev->ctrl.wr_bit_order) { + data = __spiTranslate32(data); + } + SPI_MUTEX_LOCK(); + spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 - spi->dev->miso_dlen.usr_miso_dbitlen = 0; + spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[0].val = data; + spi->dev->data_buf[0].val = data; #else - spi->dev->data_buf[0] = data; + spi->dev->data_buf[0] = data; #endif #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); -#endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); - SPI_MUTEX_UNLOCK(); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; +#endif + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; + SPI_MUTEX_UNLOCK(); } -uint32_t spiTransferLong(spi_t * spi, uint32_t data) -{ - if(!spi) { - return 0; - } - if(!spi->dev->ctrl.wr_bit_order){ - data = __spiTranslate32(data); - } - SPI_MUTEX_LOCK(); - spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; - spi->dev->miso_dlen.usr_miso_dbitlen = 31; +uint32_t spiTransferLong(spi_t *spi, uint32_t data) { + if (!spi) { + return 0; + } + if (!spi->dev->ctrl.wr_bit_order) { + data = __spiTranslate32(data); + } + SPI_MUTEX_LOCK(); + spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; + spi->dev->miso_dlen.usr_miso_dbitlen = 31; #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[0].val = data; + spi->dev->data_buf[0].val = data; #else - spi->dev->data_buf[0] = data; + spi->dev->data_buf[0] = data; #endif #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; #endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - data = spi->dev->data_buf[0].val; + data = spi->dev->data_buf[0].val; #else - data = spi->dev->data_buf[0]; + data = spi->dev->data_buf[0]; #endif - SPI_MUTEX_UNLOCK(); - if(!spi->dev->ctrl.rd_bit_order){ - data = __spiTranslate32(data); - } - return data; + SPI_MUTEX_UNLOCK(); + if (!spi->dev->ctrl.rd_bit_order) { + data = __spiTranslate32(data); + } + return data; } -static void __spiTransferBytes(spi_t * spi, const uint8_t * data, uint8_t * out, uint32_t bytes) -{ - if(!spi) { - return; - } - uint32_t i; +static void __spiTransferBytes(spi_t *spi, const uint8_t *data, uint8_t *out, uint32_t bytes) { + if (!spi) { + return; + } + uint32_t i; - if(bytes > 64) { - bytes = 64; - } + if (bytes > 64) { + bytes = 64; + } - uint32_t words = (bytes + 3) / 4;//16 max + uint32_t words = (bytes + 3) / 4; //16 max - uint32_t wordsBuf[16] = {0,}; - uint8_t * bytesBuf = (uint8_t *) wordsBuf; + uint32_t wordsBuf[16] = { + 0, + }; + uint8_t *bytesBuf = (uint8_t *)wordsBuf; - if(data) { - memcpy(bytesBuf, data, bytes);//copy data to buffer - } else { - memset(bytesBuf, 0xFF, bytes); - } + if (data) { + memcpy(bytesBuf, data, bytes); //copy data to buffer + } else { + memset(bytesBuf, 0xFF, bytes); + } - spi->dev->mosi_dlen.usr_mosi_dbitlen = ((bytes * 8) - 1); - spi->dev->miso_dlen.usr_miso_dbitlen = ((bytes * 8) - 1); + spi->dev->mosi_dlen.usr_mosi_dbitlen = ((bytes * 8) - 1); + spi->dev->miso_dlen.usr_miso_dbitlen = ((bytes * 8) - 1); - for(i=0; idev->data_buf[i].val = wordsBuf[i]; //copy buffer to spi fifo - #else - spi->dev->data_buf[i] = wordsBuf[i]; //copy buffer to spi fifo - #endif - } + for (i = 0; i < words; i++) { +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 + spi->dev->data_buf[i].val = wordsBuf[i]; //copy buffer to spi fifo +#else + spi->dev->data_buf[i] = wordsBuf[i]; //copy buffer to spi fifo +#endif + } #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; #endif - spi->dev->cmd.usr = 1; + spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); + while (spi->dev->cmd.usr) + ; - if(out) { - for(i=0; idev->data_buf[i].val;//copy spi fifo to buffer - #else - wordsBuf[i] = spi->dev->data_buf[i];//copy spi fifo to buffer - #endif - } - memcpy(out, bytesBuf, bytes);//copy buffer to output + if (out) { + for (i = 0; i < words; i++) { +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 + wordsBuf[i] = spi->dev->data_buf[i].val; //copy spi fifo to buffer +#else + wordsBuf[i] = spi->dev->data_buf[i]; //copy spi fifo to buffer +#endif } + memcpy(out, bytesBuf, bytes); //copy buffer to output + } } -void spiTransferBytes(spi_t * spi, const uint8_t * data, uint8_t * out, uint32_t size) -{ - if(!spi) { - return; - } - SPI_MUTEX_LOCK(); - while(size) { - if(size > 64) { - __spiTransferBytes(spi, data, out, 64); - size -= 64; - if(data) { - data += 64; - } - if(out) { - out += 64; - } - } else { - __spiTransferBytes(spi, data, out, size); - size = 0; - } +void spiTransferBytes(spi_t *spi, const uint8_t *data, uint8_t *out, uint32_t size) { + if (!spi) { + return; + } + SPI_MUTEX_LOCK(); + while (size) { + if (size > 64) { + __spiTransferBytes(spi, data, out, 64); + size -= 64; + if (data) { + data += 64; + } + if (out) { + out += 64; + } + } else { + __spiTransferBytes(spi, data, out, size); + size = 0; } - SPI_MUTEX_UNLOCK(); + } + SPI_MUTEX_UNLOCK(); } -void spiTransferBits(spi_t * spi, uint32_t data, uint32_t * out, uint8_t bits) -{ - if(!spi) { - return; - } - SPI_MUTEX_LOCK(); - spiTransferBitsNL(spi, data, out, bits); - SPI_MUTEX_UNLOCK(); +void spiTransferBits(spi_t *spi, uint32_t data, uint32_t *out, uint8_t bits) { + if (!spi) { + return; + } + SPI_MUTEX_LOCK(); + spiTransferBitsNL(spi, data, out, bits); + SPI_MUTEX_UNLOCK(); } /* * Manual Lock Management * */ -#define MSB_32_SET(var, val) { uint8_t * d = (uint8_t *)&(val); (var) = d[3] | (d[2] << 8) | (d[1] << 16) | (d[0] << 24); } -#define MSB_24_SET(var, val) { uint8_t * d = (uint8_t *)&(val); (var) = d[2] | (d[1] << 8) | (d[0] << 16); } -#define MSB_16_SET(var, val) { (var) = (((val) & 0xFF00) >> 8) | (((val) & 0xFF) << 8); } -#define MSB_PIX_SET(var, val) { uint8_t * d = (uint8_t *)&(val); (var) = d[1] | (d[0] << 8) | (d[3] << 16) | (d[2] << 24); } - -void spiTransaction(spi_t * spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bitOrder) -{ - if(!spi) { - return; - } - SPI_MUTEX_LOCK(); - spi->dev->clock.val = clockDiv; - switch (dataMode) { +#define MSB_32_SET(var, val) \ + { \ + uint8_t *d = (uint8_t *)&(val); \ + (var) = d[3] | (d[2] << 8) | (d[1] << 16) | (d[0] << 24); \ + } +#define MSB_24_SET(var, val) \ + { \ + uint8_t *d = (uint8_t *)&(val); \ + (var) = d[2] | (d[1] << 8) | (d[0] << 16); \ + } +#define MSB_16_SET(var, val) \ + { (var) = (((val)&0xFF00) >> 8) | (((val)&0xFF) << 8); } +#define MSB_PIX_SET(var, val) \ + { \ + uint8_t *d = (uint8_t *)&(val); \ + (var) = d[1] | (d[0] << 8) | (d[3] << 16) | (d[2] << 24); \ + } + +void spiTransaction(spi_t *spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bitOrder) { + if (!spi) { + return; + } + SPI_MUTEX_LOCK(); + spi->dev->clock.val = clockDiv; + switch (dataMode) { case SPI_MODE1: #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->misc.ck_idle_edge = 0; + spi->dev->misc.ck_idle_edge = 0; #else - spi->dev->pin.ck_idle_edge = 0; + spi->dev->pin.ck_idle_edge = 0; #endif - spi->dev->user.ck_out_edge = 1; - break; + spi->dev->user.ck_out_edge = 1; + break; case SPI_MODE2: #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->misc.ck_idle_edge = 1; + spi->dev->misc.ck_idle_edge = 1; #else - spi->dev->pin.ck_idle_edge = 1; + spi->dev->pin.ck_idle_edge = 1; #endif - spi->dev->user.ck_out_edge = 1; - break; + spi->dev->user.ck_out_edge = 1; + break; case SPI_MODE3: #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->misc.ck_idle_edge = 1; + spi->dev->misc.ck_idle_edge = 1; #else - spi->dev->pin.ck_idle_edge = 1; + spi->dev->pin.ck_idle_edge = 1; #endif - spi->dev->user.ck_out_edge = 0; - break; + spi->dev->user.ck_out_edge = 0; + break; case SPI_MODE0: default: #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->misc.ck_idle_edge = 0; + spi->dev->misc.ck_idle_edge = 0; #else - spi->dev->pin.ck_idle_edge = 0; -#endif - spi->dev->user.ck_out_edge = 0; - break; - } - if (SPI_MSBFIRST == bitOrder) { - spi->dev->ctrl.wr_bit_order = 0; - spi->dev->ctrl.rd_bit_order = 0; - } else if (SPI_LSBFIRST == bitOrder) { - spi->dev->ctrl.wr_bit_order = 1; - spi->dev->ctrl.rd_bit_order = 1; - } -#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - // Sync new config with hardware, fixes https://github.com/espressif/arduino-esp32/issues/9221 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); + spi->dev->pin.ck_idle_edge = 0; +#endif + spi->dev->user.ck_out_edge = 0; + break; + } + if (SPI_MSBFIRST == bitOrder) { + spi->dev->ctrl.wr_bit_order = 0; + spi->dev->ctrl.rd_bit_order = 0; + } else if (SPI_LSBFIRST == bitOrder) { + spi->dev->ctrl.wr_bit_order = 1; + spi->dev->ctrl.rd_bit_order = 1; + } +#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 + // Sync new config with hardware, fixes https://github.com/espressif/arduino-esp32/issues/9221 + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; #endif } -void spiSimpleTransaction(spi_t * spi) -{ - if(!spi) { - return; - } - SPI_MUTEX_LOCK(); +void spiSimpleTransaction(spi_t *spi) { + if (!spi) { + return; + } + SPI_MUTEX_LOCK(); } -void spiEndTransaction(spi_t * spi) -{ - if(!spi) { - return; - } - SPI_MUTEX_UNLOCK(); +void spiEndTransaction(spi_t *spi) { + if (!spi) { + return; + } + SPI_MUTEX_UNLOCK(); } -void ARDUINO_ISR_ATTR spiWriteByteNL(spi_t * spi, uint8_t data) -{ - if(!spi) { - return; - } - spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; +void ARDUINO_ISR_ATTR spiWriteByteNL(spi_t *spi, uint8_t data) { + if (!spi) { + return; + } + spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 - spi->dev->miso_dlen.usr_miso_dbitlen = 0; + spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[0].val = data; + spi->dev->data_buf[0].val = data; #else - spi->dev->data_buf[0] = data; + spi->dev->data_buf[0] = data; #endif #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; #endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; } -uint8_t spiTransferByteNL(spi_t * spi, uint8_t data) -{ - if(!spi) { - return 0; - } - spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; - spi->dev->miso_dlen.usr_miso_dbitlen = 7; +uint8_t spiTransferByteNL(spi_t *spi, uint8_t data) { + if (!spi) { + return 0; + } + spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; + spi->dev->miso_dlen.usr_miso_dbitlen = 7; #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[0].val = data; + spi->dev->data_buf[0].val = data; #else - spi->dev->data_buf[0] = data; + spi->dev->data_buf[0] = data; #endif #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; #endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - data = spi->dev->data_buf[0].val & 0xFF; + data = spi->dev->data_buf[0].val & 0xFF; #else - data = spi->dev->data_buf[0] & 0xFF; + data = spi->dev->data_buf[0] & 0xFF; #endif - return data; + return data; } -void ARDUINO_ISR_ATTR spiWriteShortNL(spi_t * spi, uint16_t data) -{ - if(!spi) { - return; - } - if(!spi->dev->ctrl.wr_bit_order){ - MSB_16_SET(data, data); - } - spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; +void ARDUINO_ISR_ATTR spiWriteShortNL(spi_t *spi, uint16_t data) { + if (!spi) { + return; + } + if (!spi->dev->ctrl.wr_bit_order) { + MSB_16_SET(data, data); + } + spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 - spi->dev->miso_dlen.usr_miso_dbitlen = 0; + spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[0].val = data; + spi->dev->data_buf[0].val = data; #else - spi->dev->data_buf[0] = data; + spi->dev->data_buf[0] = data; #endif #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; #endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; } -uint16_t spiTransferShortNL(spi_t * spi, uint16_t data) -{ - if(!spi) { - return 0; - } - if(!spi->dev->ctrl.wr_bit_order){ - MSB_16_SET(data, data); - } - spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; - spi->dev->miso_dlen.usr_miso_dbitlen = 15; +uint16_t spiTransferShortNL(spi_t *spi, uint16_t data) { + if (!spi) { + return 0; + } + if (!spi->dev->ctrl.wr_bit_order) { + MSB_16_SET(data, data); + } + spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; + spi->dev->miso_dlen.usr_miso_dbitlen = 15; #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[0].val = data; + spi->dev->data_buf[0].val = data; #else - spi->dev->data_buf[0] = data; + spi->dev->data_buf[0] = data; #endif #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; #endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - data = spi->dev->data_buf[0].val & 0xFFFF; + data = spi->dev->data_buf[0].val & 0xFFFF; #else - data = spi->dev->data_buf[0] & 0xFFFF; + data = spi->dev->data_buf[0] & 0xFFFF; #endif - if(!spi->dev->ctrl.rd_bit_order){ - MSB_16_SET(data, data); - } - return data; + if (!spi->dev->ctrl.rd_bit_order) { + MSB_16_SET(data, data); + } + return data; } -void ARDUINO_ISR_ATTR spiWriteLongNL(spi_t * spi, uint32_t data) -{ - if(!spi) { - return; - } - if(!spi->dev->ctrl.wr_bit_order){ - MSB_32_SET(data, data); - } - spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; +void ARDUINO_ISR_ATTR spiWriteLongNL(spi_t *spi, uint32_t data) { + if (!spi) { + return; + } + if (!spi->dev->ctrl.wr_bit_order) { + MSB_32_SET(data, data); + } + spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 - spi->dev->miso_dlen.usr_miso_dbitlen = 0; + spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[0].val = data; + spi->dev->data_buf[0].val = data; #else - spi->dev->data_buf[0] = data; + spi->dev->data_buf[0] = data; #endif #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; #endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; } -uint32_t spiTransferLongNL(spi_t * spi, uint32_t data) -{ - if(!spi) { - return 0; - } - if(!spi->dev->ctrl.wr_bit_order){ - MSB_32_SET(data, data); - } - spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; - spi->dev->miso_dlen.usr_miso_dbitlen = 31; +uint32_t spiTransferLongNL(spi_t *spi, uint32_t data) { + if (!spi) { + return 0; + } + if (!spi->dev->ctrl.wr_bit_order) { + MSB_32_SET(data, data); + } + spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; + spi->dev->miso_dlen.usr_miso_dbitlen = 31; #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[0].val = data; + spi->dev->data_buf[0].val = data; #else - spi->dev->data_buf[0] = data; + spi->dev->data_buf[0] = data; #endif #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; #endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); - #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - data = spi->dev->data_buf[0].val; + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 + data = spi->dev->data_buf[0].val; #else - data = spi->dev->data_buf[0]; + data = spi->dev->data_buf[0]; #endif - if(!spi->dev->ctrl.rd_bit_order){ - MSB_32_SET(data, data); - } - return data; + if (!spi->dev->ctrl.rd_bit_order) { + MSB_32_SET(data, data); + } + return data; } -void spiWriteNL(spi_t * spi, const void * data_in, uint32_t len){ - if(!spi) { - return; - } - size_t longs = len >> 2; - if(len & 3){ - longs++; - } - uint32_t * data = (uint32_t*)data_in; - size_t c_len = 0, c_longs = 0; - - while(len){ - c_len = (len>64)?64:len; - c_longs = (longs > 16)?16:longs; - - spi->dev->mosi_dlen.usr_mosi_dbitlen = (c_len*8)-1; +void spiWriteNL(spi_t *spi, const void *data_in, uint32_t len) { + if (!spi) { + return; + } + size_t longs = len >> 2; + if (len & 3) { + longs++; + } + uint32_t *data = (uint32_t *)data_in; + size_t c_len = 0, c_longs = 0; + + while (len) { + c_len = (len > 64) ? 64 : len; + c_longs = (longs > 16) ? 16 : longs; + + spi->dev->mosi_dlen.usr_mosi_dbitlen = (c_len * 8) - 1; #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif - for (size_t i=0; idev->data_buf[i].val = data[i]; - #else - spi->dev->data_buf[i] = data[i]; - #endif - } + for (size_t i = 0; i < c_longs; i++) { +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 + spi->dev->data_buf[i].val = data[i]; +#else + spi->dev->data_buf[i] = data[i]; +#endif + } #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; #endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; - data += c_longs; - longs -= c_longs; - len -= c_len; - } + data += c_longs; + longs -= c_longs; + len -= c_len; + } } -void spiTransferBytesNL(spi_t * spi, const void * data_in, uint8_t * data_out, uint32_t len){ - if(!spi) { - return; - } - size_t longs = len >> 2; - if(len & 3){ - longs++; +void spiTransferBytesNL(spi_t *spi, const void *data_in, uint8_t *data_out, uint32_t len) { + if (!spi) { + return; + } + size_t longs = len >> 2; + if (len & 3) { + longs++; + } + uint32_t *data = (uint32_t *)data_in; + uint32_t *result = (uint32_t *)data_out; + size_t c_len = 0, c_longs = 0; + + while (len) { + c_len = (len > 64) ? 64 : len; + c_longs = (longs > 16) ? 16 : longs; + + spi->dev->mosi_dlen.usr_mosi_dbitlen = (c_len * 8) - 1; + spi->dev->miso_dlen.usr_miso_dbitlen = (c_len * 8) - 1; + if (data) { + for (size_t i = 0; i < c_longs; i++) { +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 + spi->dev->data_buf[i].val = data[i]; +#else + spi->dev->data_buf[i] = data[i]; +#endif + } + } else { + for (size_t i = 0; i < c_longs; i++) { +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 + spi->dev->data_buf[i].val = 0xFFFFFFFF; +#else + spi->dev->data_buf[i] = 0xFFFFFFFF; +#endif + } } - uint32_t * data = (uint32_t*)data_in; - uint32_t * result = (uint32_t*)data_out; - size_t c_len = 0, c_longs = 0; - - while(len){ - c_len = (len>64)?64:len; - c_longs = (longs > 16)?16:longs; - - spi->dev->mosi_dlen.usr_mosi_dbitlen = (c_len*8)-1; - spi->dev->miso_dlen.usr_miso_dbitlen = (c_len*8)-1; - if(data){ - for (size_t i=0; idev->data_buf[i].val = data[i]; - #else - spi->dev->data_buf[i] = data[i]; - #endif - } - } else { - for (size_t i=0; idev->data_buf[i].val = 0xFFFFFFFF; - #else - spi->dev->data_buf[i] = 0xFFFFFFFF; - #endif - } - } #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); -#endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); - if(result){ - if(c_len & 3){ - for (size_t i=0; i<(c_longs-1); i++) { - #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - result[i] = spi->dev->data_buf[i].val; - #else - result[i] = spi->dev->data_buf[i]; - #endif - } - #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - uint32_t last_data = spi->dev->data_buf[c_longs-1].val; - #else - uint32_t last_data = spi->dev->data_buf[c_longs-1]; - #endif - uint8_t * last_out8 = (uint8_t *)&result[c_longs-1]; - uint8_t * last_data8 = (uint8_t *)&last_data; - for (size_t i=0; i<(c_len & 3); i++) { - last_out8[i] = last_data8[i]; - } - } else { - for (size_t i=0; idev->data_buf[i].val; - #else - result[i] = spi->dev->data_buf[i]; - #endif - } - } + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; +#endif + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; + if (result) { + if (c_len & 3) { + for (size_t i = 0; i < (c_longs - 1); i++) { +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 + result[i] = spi->dev->data_buf[i].val; +#else + result[i] = spi->dev->data_buf[i]; +#endif } - if(data){ - data += c_longs; +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 + uint32_t last_data = spi->dev->data_buf[c_longs - 1].val; +#else + uint32_t last_data = spi->dev->data_buf[c_longs - 1]; +#endif + uint8_t *last_out8 = (uint8_t *)&result[c_longs - 1]; + uint8_t *last_data8 = (uint8_t *)&last_data; + for (size_t i = 0; i < (c_len & 3); i++) { + last_out8[i] = last_data8[i]; } - if(result){ - result += c_longs; + } else { + for (size_t i = 0; i < c_longs; i++) { +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 + result[i] = spi->dev->data_buf[i].val; +#else + result[i] = spi->dev->data_buf[i]; +#endif } - longs -= c_longs; - len -= c_len; + } } -} - -void spiTransferBitsNL(spi_t * spi, uint32_t data, uint32_t * out, uint8_t bits) -{ - if(!spi) { - return; + if (data) { + data += c_longs; } - - if(bits > 32) { - bits = 32; + if (result) { + result += c_longs; } - uint32_t bytes = (bits + 7) / 8;//64 max - uint32_t mask = (((uint64_t)1 << bits) - 1) & 0xFFFFFFFF; - data = data & mask; - if(!spi->dev->ctrl.wr_bit_order){ - if(bytes == 2) { - MSB_16_SET(data, data); - } else if(bytes == 3) { - MSB_24_SET(data, data); - } else { - MSB_32_SET(data, data); - } + longs -= c_longs; + len -= c_len; + } +} + +void spiTransferBitsNL(spi_t *spi, uint32_t data, uint32_t *out, uint8_t bits) { + if (!spi) { + return; + } + + if (bits > 32) { + bits = 32; + } + uint32_t bytes = (bits + 7) / 8; //64 max + uint32_t mask = (((uint64_t)1 << bits) - 1) & 0xFFFFFFFF; + data = data & mask; + if (!spi->dev->ctrl.wr_bit_order) { + if (bytes == 2) { + MSB_16_SET(data, data); + } else if (bytes == 3) { + MSB_24_SET(data, data); + } else { + MSB_32_SET(data, data); } + } - spi->dev->mosi_dlen.usr_mosi_dbitlen = (bits - 1); - spi->dev->miso_dlen.usr_miso_dbitlen = (bits - 1); + spi->dev->mosi_dlen.usr_mosi_dbitlen = (bits - 1); + spi->dev->miso_dlen.usr_miso_dbitlen = (bits - 1); #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[0].val = data; + spi->dev->data_buf[0].val = data; #else - spi->dev->data_buf[0] = data; + spi->dev->data_buf[0] = data; #endif #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; #endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); - #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - data = spi->dev->data_buf[0].val; + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 + data = spi->dev->data_buf[0].val; #else - data = spi->dev->data_buf[0]; -#endif - if(out) { - *out = data; - if(!spi->dev->ctrl.rd_bit_order){ - if(bytes == 2) { - MSB_16_SET(*out, data); - } else if(bytes == 3) { - MSB_24_SET(*out, data); - } else { - MSB_32_SET(*out, data); - } - } - } + data = spi->dev->data_buf[0]; +#endif + if (out) { + *out = data; + if (!spi->dev->ctrl.rd_bit_order) { + if (bytes == 2) { + MSB_16_SET(*out, data); + } else if (bytes == 3) { + MSB_24_SET(*out, data); + } else { + MSB_32_SET(*out, data); + } + } + } } -void ARDUINO_ISR_ATTR spiWritePixelsNL(spi_t * spi, const void * data_in, uint32_t len){ - size_t longs = len >> 2; - if(len & 3){ - longs++; - } - bool msb = !spi->dev->ctrl.wr_bit_order; - uint32_t * data = (uint32_t*)data_in; - size_t c_len = 0, c_longs = 0, l_bytes = 0; - - while(len){ - c_len = (len>64)?64:len; - c_longs = (longs > 16)?16:longs; - l_bytes = (c_len & 3); - - spi->dev->mosi_dlen.usr_mosi_dbitlen = (c_len*8)-1; +void ARDUINO_ISR_ATTR spiWritePixelsNL(spi_t *spi, const void *data_in, uint32_t len) { + size_t longs = len >> 2; + if (len & 3) { + longs++; + } + bool msb = !spi->dev->ctrl.wr_bit_order; + uint32_t *data = (uint32_t *)data_in; + size_t c_len = 0, c_longs = 0, l_bytes = 0; + + while (len) { + c_len = (len > 64) ? 64 : len; + c_longs = (longs > 16) ? 16 : longs; + l_bytes = (c_len & 3); + + spi->dev->mosi_dlen.usr_mosi_dbitlen = (c_len * 8) - 1; #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif - for (size_t i=0; idev->data_buf[i].val, data[i]); - #else - MSB_16_SET(spi->dev->data_buf[i], data[i]); - #endif - } else { - #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[i].val = data[i] & 0xFF; - #else - spi->dev->data_buf[i] = data[i] & 0xFF; - #endif - } - } else { - #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - MSB_PIX_SET(spi->dev->data_buf[i].val, data[i]); - #else - MSB_PIX_SET(spi->dev->data_buf[i], data[i]); - #endif - } - } else { - #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->data_buf[i].val = data[i]; - #else - spi->dev->data_buf[i] = data[i]; - #endif - } + for (size_t i = 0; i < c_longs; i++) { + if (msb) { + if (l_bytes && i == (c_longs - 1)) { + if (l_bytes == 2) { +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 + MSB_16_SET(spi->dev->data_buf[i].val, data[i]); +#else + MSB_16_SET(spi->dev->data_buf[i], data[i]); +#endif + } else { +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 + spi->dev->data_buf[i].val = data[i] & 0xFF; +#else + spi->dev->data_buf[i] = data[i] & 0xFF; +#endif + } + } else { +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 + MSB_PIX_SET(spi->dev->data_buf[i].val, data[i]); +#else + MSB_PIX_SET(spi->dev->data_buf[i], data[i]); +#endif } + } else { +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 + spi->dev->data_buf[i].val = data[i]; +#else + spi->dev->data_buf[i] = data[i]; +#endif + } + } #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - spi->dev->cmd.update = 1; - while (spi->dev->cmd.update); + spi->dev->cmd.update = 1; + while (spi->dev->cmd.update) + ; #endif - spi->dev->cmd.usr = 1; - while(spi->dev->cmd.usr); + spi->dev->cmd.usr = 1; + while (spi->dev->cmd.usr) + ; - data += c_longs; - longs -= c_longs; - len -= c_len; - } + data += c_longs; + longs -= c_longs; + len -= c_len; + } } @@ -1544,88 +1554,86 @@ void ARDUINO_ISR_ATTR spiWritePixelsNL(spi_t * spi, const void * data_in, uint32 * */ typedef union { - uint32_t value; - struct { - uint32_t clkcnt_l: 6; /*it must be equal to spi_clkcnt_N.*/ - uint32_t clkcnt_h: 6; /*it must be floor((spi_clkcnt_N+1)/2-1).*/ - uint32_t clkcnt_n: 6; /*it is the divider of spi_clk. So spi_clk frequency is system/(spi_clkdiv_pre+1)/(spi_clkcnt_N+1)*/ + uint32_t value; + struct { + uint32_t clkcnt_l : 6; /*it must be equal to spi_clkcnt_N.*/ + uint32_t clkcnt_h : 6; /*it must be floor((spi_clkcnt_N+1)/2-1).*/ + uint32_t clkcnt_n : 6; /*it is the divider of spi_clk. So spi_clk frequency is system/(spi_clkdiv_pre+1)/(spi_clkcnt_N+1)*/ #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - uint32_t clkdiv_pre: 4; /*it is pre-divider of spi_clk.*/ - uint32_t reserved: 9; /*reserved*/ + uint32_t clkdiv_pre : 4; /*it is pre-divider of spi_clk.*/ + uint32_t reserved : 9; /*reserved*/ #else - uint32_t clkdiv_pre: 13; /*it is pre-divider of spi_clk.*/ + uint32_t clkdiv_pre : 13; /*it is pre-divider of spi_clk.*/ #endif - uint32_t clk_equ_sysclk: 1; /*1: spi_clk is eqaul to system 0: spi_clk is divided from system clock.*/ - }; + uint32_t clk_equ_sysclk : 1; /*1: spi_clk is equal to system 0: spi_clk is divided from system clock.*/ + }; } spiClk_t; #define ClkRegToFreq(reg) (apb_freq / (((reg)->clkdiv_pre + 1) * ((reg)->clkcnt_n + 1))) -uint32_t spiClockDivToFrequency(uint32_t clockDiv) -{ - uint32_t apb_freq = getApbFrequency(); - spiClk_t reg = { clockDiv }; - return ClkRegToFreq(®); +uint32_t spiClockDivToFrequency(uint32_t clockDiv) { + uint32_t apb_freq = getApbFrequency(); + spiClk_t reg = { clockDiv }; + return ClkRegToFreq(®); } -uint32_t spiFrequencyToClockDiv(uint32_t freq) -{ - uint32_t apb_freq = getApbFrequency(); +uint32_t spiFrequencyToClockDiv(uint32_t freq) { + uint32_t apb_freq = getApbFrequency(); - if(freq >= apb_freq) { - return SPI_CLK_EQU_SYSCLK; - } + if (freq >= apb_freq) { + return SPI_CLK_EQU_SYSCLK; + } - const spiClk_t minFreqReg = { 0x7FFFF000 }; - uint32_t minFreq = ClkRegToFreq((spiClk_t*) &minFreqReg); - if(freq < minFreq) { - return minFreqReg.value; - } + const spiClk_t minFreqReg = { 0x7FFFF000 }; + uint32_t minFreq = ClkRegToFreq((spiClk_t *)&minFreqReg); + if (freq < minFreq) { + return minFreqReg.value; + } - uint8_t calN = 1; - spiClk_t bestReg = { 0 }; - uint32_t bestFreq = 0; + uint8_t calN = 1; + spiClk_t bestReg = { 0 }; + uint32_t bestFreq = 0; - while(calN <= 0x3F) { - spiClk_t reg = { 0 }; - uint32_t calFreq; - int32_t calPre; - int8_t calPreVari = -2; + while (calN <= 0x3F) { + spiClk_t reg = { 0 }; + uint32_t calFreq; + int32_t calPre; + int8_t calPreVari = -2; - reg.clkcnt_n = calN; + reg.clkcnt_n = calN; - while(calPreVari++ <= 1) { - calPre = (((apb_freq / (reg.clkcnt_n + 1)) / freq) - 1) + calPreVari; + while (calPreVari++ <= 1) { + calPre = (((apb_freq / (reg.clkcnt_n + 1)) / freq) - 1) + calPreVari; #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - if(calPre > 0xF) { - reg.clkdiv_pre = 0xF; + if (calPre > 0xF) { + reg.clkdiv_pre = 0xF; #else - if(calPre > 0x1FFF) { - reg.clkdiv_pre = 0x1FFF; -#endif - } else if(calPre <= 0) { - reg.clkdiv_pre = 0; - } else { - reg.clkdiv_pre = calPre; - } - reg.clkcnt_l = ((reg.clkcnt_n + 1) / 2); - calFreq = ClkRegToFreq(®); - if(calFreq == freq) { - memcpy(&bestReg, ®, sizeof(bestReg)); - break; - } else if(calFreq < freq) { - if((freq - calFreq) < (freq - bestFreq)) { - bestFreq = calFreq; - memcpy(&bestReg, ®, sizeof(bestReg)); - } - } - } - if(calFreq == (int32_t) freq) { - break; + if (calPre > 0x1FFF) { + reg.clkdiv_pre = 0x1FFF; +#endif + } else if (calPre <= 0) { + reg.clkdiv_pre = 0; + } else { + reg.clkdiv_pre = calPre; + } + reg.clkcnt_l = ((reg.clkcnt_n + 1) / 2); + calFreq = ClkRegToFreq(®); + if (calFreq == freq) { + memcpy(&bestReg, ®, sizeof(bestReg)); + break; + } else if (calFreq < freq) { + if ((freq - calFreq) < (freq - bestFreq)) { + bestFreq = calFreq; + memcpy(&bestReg, ®, sizeof(bestReg)); } - calN++; + } + } + if (calFreq == (int32_t)freq) { + break; } - return bestReg.value; + calN++; + } + return bestReg.value; } #endif /* SOC_GPSPI_SUPPORTED */ diff --git a/cores/esp32/esp32-hal-spi.h b/cores/esp32/esp32-hal-spi.h index 5c8eb58d059..2eba5ae6a01 100644 --- a/cores/esp32/esp32-hal-spi.h +++ b/cores/esp32/esp32-hal-spi.h @@ -29,28 +29,28 @@ extern "C" { #define SPI_HAS_TRANSACTION #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32S3 -#define FSPI 0 -#define HSPI 1 +#define FSPI 0 +#define HSPI 1 #elif CONFIG_IDF_TARGET_ESP32S2 -#define FSPI 1 //SPI 1 bus. ESP32S2: for external memory only (can use the same data lines but different SS) -#define HSPI 2 //SPI 2 bus. ESP32S2: external memory or device - it can be matrixed to any pins -#define SPI2 2 // Another name for ESP32S2 SPI 2 -#define SPI3 3 //SPI 3 bus. ESP32S2: device only - it can be matrixed to any pins +#define FSPI 1 //SPI 1 bus. ESP32S2: for external memory only (can use the same data lines but different SS) +#define HSPI 2 //SPI 2 bus. ESP32S2: external memory or device - it can be matrixed to any pins +#define SPI2 2 // Another name for ESP32S2 SPI 2 +#define SPI3 3 //SPI 3 bus. ESP32S2: device only - it can be matrixed to any pins #elif CONFIG_IDF_TARGET_ESP32 -#define FSPI 1 //SPI 1 bus attached to the flash (can use the same data lines but different SS) -#define HSPI 2 //SPI 2 bus normally mapped to pins 12 - 15, but can be matrixed to any pins -#define VSPI 3 //SPI 3 bus normally attached to pins 5, 18, 19 and 23, but can be matrixed to any pins +#define FSPI 1 //SPI 1 bus attached to the flash (can use the same data lines but different SS) +#define HSPI 2 //SPI 2 bus normally mapped to pins 12 - 15, but can be matrixed to any pins +#define VSPI 3 //SPI 3 bus normally attached to pins 5, 18, 19 and 23, but can be matrixed to any pins #endif // This defines are not representing the real Divider of the ESP32 // the Defines match to an AVR Arduino on 16MHz for better compatibility -#define SPI_CLOCK_DIV2 0x00101001 //8 MHz -#define SPI_CLOCK_DIV4 0x00241001 //4 MHz -#define SPI_CLOCK_DIV8 0x004c1001 //2 MHz -#define SPI_CLOCK_DIV16 0x009c1001 //1 MHz -#define SPI_CLOCK_DIV32 0x013c1001 //500 KHz -#define SPI_CLOCK_DIV64 0x027c1001 //250 KHz -#define SPI_CLOCK_DIV128 0x04fc1001 //125 KHz +#define SPI_CLOCK_DIV2 0x00101001 //8 MHz +#define SPI_CLOCK_DIV4 0x00241001 //4 MHz +#define SPI_CLOCK_DIV8 0x004c1001 //2 MHz +#define SPI_CLOCK_DIV16 0x009c1001 //1 MHz +#define SPI_CLOCK_DIV32 0x013c1001 //500 KHz +#define SPI_CLOCK_DIV64 0x027c1001 //250 KHz +#define SPI_CLOCK_DIV128 0x04fc1001 //125 KHz #define SPI_MODE0 0 #define SPI_MODE1 1 @@ -65,88 +65,88 @@ extern "C" { #define SPI_LSBFIRST 0 #define SPI_MSBFIRST 1 -struct spi_struct_t; -typedef struct spi_struct_t spi_t; + struct spi_struct_t; + typedef struct spi_struct_t spi_t; -spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_t bitOrder); -void spiStopBus(spi_t * spi); + spi_t *spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_t bitOrder); + void spiStopBus(spi_t *spi); -//Attach/Detach Signal Pins -bool spiAttachSCK(spi_t * spi, int8_t sck); -bool spiAttachMISO(spi_t * spi, int8_t miso); -bool spiAttachMOSI(spi_t * spi, int8_t mosi); -bool spiDetachSCK(spi_t * spi); -bool spiDetachMISO(spi_t * spi); -bool spiDetachMOSI(spi_t * spi); + //Attach/Detach Signal Pins + bool spiAttachSCK(spi_t *spi, int8_t sck); + bool spiAttachMISO(spi_t *spi, int8_t miso); + bool spiAttachMOSI(spi_t *spi, int8_t mosi); + bool spiDetachSCK(spi_t *spi); + bool spiDetachMISO(spi_t *spi); + bool spiDetachMOSI(spi_t *spi); -//Attach/Detach SS pin to SPI_SSx signal -bool spiAttachSS(spi_t * spi, uint8_t ss_num, int8_t ss); -bool spiDetachSS(spi_t * spi); + //Attach/Detach SS pin to SPI_SSx signal + bool spiAttachSS(spi_t *spi, uint8_t ss_num, int8_t ss); + bool spiDetachSS(spi_t *spi); -//Enable/Disable SPI_SSx pins -void spiEnableSSPins(spi_t * spi, uint8_t ss_mask); -void spiDisableSSPins(spi_t * spi, uint8_t ss_mask); + //Enable/Disable SPI_SSx pins + void spiEnableSSPins(spi_t *spi, uint8_t ss_mask); + void spiDisableSSPins(spi_t *spi, uint8_t ss_mask); -//Enable/Disable hardware control of SPI_SSx pins -void spiSSEnable(spi_t * spi); -void spiSSDisable(spi_t * spi); + //Enable/Disable hardware control of SPI_SSx pins + void spiSSEnable(spi_t *spi); + void spiSSDisable(spi_t *spi); -//Activate enabled SPI_SSx pins -void spiSSSet(spi_t * spi); -//Deactivate enabled SPI_SSx pins -void spiSSClear(spi_t * spi); + //Activate enabled SPI_SSx pins + void spiSSSet(spi_t *spi); + //Deactivate enabled SPI_SSx pins + void spiSSClear(spi_t *spi); -void spiWaitReady(spi_t * spi); + void spiWaitReady(spi_t *spi); -uint32_t spiGetClockDiv(spi_t * spi); -uint8_t spiGetDataMode(spi_t * spi); -uint8_t spiGetBitOrder(spi_t * spi); + uint32_t spiGetClockDiv(spi_t *spi); + uint8_t spiGetDataMode(spi_t *spi); + uint8_t spiGetBitOrder(spi_t *spi); -/* + /* * Non transaction based lock methods (each locks and unlocks when called) * */ -void spiSetClockDiv(spi_t * spi, uint32_t clockDiv); -void spiSetDataMode(spi_t * spi, uint8_t dataMode); -void spiSetBitOrder(spi_t * spi, uint8_t bitOrder); - -void spiWrite(spi_t * spi, const uint32_t *data, uint8_t len); -void spiWriteByte(spi_t * spi, uint8_t data); -void spiWriteWord(spi_t * spi, uint16_t data); -void spiWriteLong(spi_t * spi, uint32_t data); - -void spiTransfer(spi_t * spi, uint32_t *out, uint8_t len); -uint8_t spiTransferByte(spi_t * spi, uint8_t data); -uint16_t spiTransferWord(spi_t * spi, uint16_t data); -uint32_t spiTransferLong(spi_t * spi, uint32_t data); -void spiTransferBytes(spi_t * spi, const uint8_t * data, uint8_t * out, uint32_t size); -void spiTransferBits(spi_t * spi, uint32_t data, uint32_t * out, uint8_t bits); - -/* + void spiSetClockDiv(spi_t *spi, uint32_t clockDiv); + void spiSetDataMode(spi_t *spi, uint8_t dataMode); + void spiSetBitOrder(spi_t *spi, uint8_t bitOrder); + + void spiWrite(spi_t *spi, const uint32_t *data, uint8_t len); + void spiWriteByte(spi_t *spi, uint8_t data); + void spiWriteWord(spi_t *spi, uint16_t data); + void spiWriteLong(spi_t *spi, uint32_t data); + + void spiTransfer(spi_t *spi, uint32_t *out, uint8_t len); + uint8_t spiTransferByte(spi_t *spi, uint8_t data); + uint16_t spiTransferWord(spi_t *spi, uint16_t data); + uint32_t spiTransferLong(spi_t *spi, uint32_t data); + void spiTransferBytes(spi_t *spi, const uint8_t *data, uint8_t *out, uint32_t size); + void spiTransferBits(spi_t *spi, uint32_t data, uint32_t *out, uint8_t bits); + + /* * New (EXPERIMENTAL) Transaction lock based API (lock once until endTransaction) * */ -void spiTransaction(spi_t * spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bitOrder); -void spiSimpleTransaction(spi_t * spi); -void spiEndTransaction(spi_t * spi); + void spiTransaction(spi_t *spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bitOrder); + void spiSimpleTransaction(spi_t *spi); + void spiEndTransaction(spi_t *spi); -void spiWriteNL(spi_t * spi, const void * data_in, uint32_t len); -void spiWriteByteNL(spi_t * spi, uint8_t data); -void spiWriteShortNL(spi_t * spi, uint16_t data); -void spiWriteLongNL(spi_t * spi, uint32_t data); -void spiWritePixelsNL(spi_t * spi, const void * data_in, uint32_t len); + void spiWriteNL(spi_t *spi, const void *data_in, uint32_t len); + void spiWriteByteNL(spi_t *spi, uint8_t data); + void spiWriteShortNL(spi_t *spi, uint16_t data); + void spiWriteLongNL(spi_t *spi, uint32_t data); + void spiWritePixelsNL(spi_t *spi, const void *data_in, uint32_t len); #define spiTransferNL(spi, data, len) spiTransferBytesNL(spi, data, data, len) -uint8_t spiTransferByteNL(spi_t * spi, uint8_t data); -uint16_t spiTransferShortNL(spi_t * spi, uint16_t data); -uint32_t spiTransferLongNL(spi_t * spi, uint32_t data); -void spiTransferBytesNL(spi_t * spi, const void * data_in, uint8_t * data_out, uint32_t len); -void spiTransferBitsNL(spi_t * spi, uint32_t data_in, uint32_t * data_out, uint8_t bits); + uint8_t spiTransferByteNL(spi_t *spi, uint8_t data); + uint16_t spiTransferShortNL(spi_t *spi, uint16_t data); + uint32_t spiTransferLongNL(spi_t *spi, uint32_t data); + void spiTransferBytesNL(spi_t *spi, const void *data_in, uint8_t *data_out, uint32_t len); + void spiTransferBitsNL(spi_t *spi, uint32_t data_in, uint32_t *data_out, uint8_t bits); -/* + /* * Helper functions to translate frequency to clock divider and back * */ -uint32_t spiFrequencyToClockDiv(uint32_t freq); -uint32_t spiClockDivToFrequency(uint32_t freq); + uint32_t spiFrequencyToClockDiv(uint32_t freq); + uint32_t spiClockDivToFrequency(uint32_t freq); #ifdef __cplusplus } diff --git a/cores/esp32/esp32-hal-time.c b/cores/esp32/esp32-hal-time.c index e7048307284..6f8f93224f6 100644 --- a/cores/esp32/esp32-hal-time.c +++ b/cores/esp32/esp32-hal-time.c @@ -17,81 +17,76 @@ //#include "tcpip_adapter.h" #include "esp_netif.h" -static void setTimeZone(long offset, int daylight) -{ - char cst[17] = {0}; - char cdt[17] = "DST"; - char tz[33] = {0}; +static void setTimeZone(long offset, int daylight) { + char cst[17] = { 0 }; + char cdt[17] = "DST"; + char tz[33] = { 0 }; - if(offset % 3600){ - sprintf(cst, "UTC%ld:%02u:%02u", offset / 3600, abs((offset % 3600) / 60), abs(offset % 60)); + if (offset % 3600) { + sprintf(cst, "UTC%ld:%02u:%02u", offset / 3600, abs((offset % 3600) / 60), abs(offset % 60)); + } else { + sprintf(cst, "UTC%ld", offset / 3600); + } + if (daylight != 3600) { + long tz_dst = offset - daylight; + if (tz_dst % 3600) { + sprintf(cdt, "DST%ld:%02u:%02u", tz_dst / 3600, abs((tz_dst % 3600) / 60), abs(tz_dst % 60)); } else { - sprintf(cst, "UTC%ld", offset / 3600); + sprintf(cdt, "DST%ld", tz_dst / 3600); } - if(daylight != 3600){ - long tz_dst = offset - daylight; - if(tz_dst % 3600){ - sprintf(cdt, "DST%ld:%02u:%02u", tz_dst / 3600, abs((tz_dst % 3600) / 60), abs(tz_dst % 60)); - } else { - sprintf(cdt, "DST%ld", tz_dst / 3600); - } - } - sprintf(tz, "%s%s", cst, cdt); - setenv("TZ", tz, 1); - tzset(); + } + sprintf(tz, "%s%s", cst, cdt); + setenv("TZ", tz, 1); + tzset(); } /* * configTime * Source: https://github.com/esp8266/Arduino/blob/master/cores/esp8266/time.c * */ -void configTime(long gmtOffset_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3) -{ - //tcpip_adapter_init(); // Should not hurt anything if already inited - esp_netif_init(); - if(sntp_enabled()){ - sntp_stop(); - } - sntp_setoperatingmode(SNTP_OPMODE_POLL); - sntp_setservername(0, (char*)server1); - sntp_setservername(1, (char*)server2); - sntp_setservername(2, (char*)server3); - sntp_init(); - setTimeZone(-gmtOffset_sec, daylightOffset_sec); +void configTime(long gmtOffset_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3) { + //tcpip_adapter_init(); // Should not hurt anything if already inited + esp_netif_init(); + if (sntp_enabled()) { + sntp_stop(); + } + sntp_setoperatingmode(SNTP_OPMODE_POLL); + sntp_setservername(0, (char*)server1); + sntp_setservername(1, (char*)server2); + sntp_setservername(2, (char*)server3); + sntp_init(); + setTimeZone(-gmtOffset_sec, daylightOffset_sec); } /* * configTzTime * sntp setup using TZ environment variable * */ -void configTzTime(const char* tz, const char* server1, const char* server2, const char* server3) -{ - //tcpip_adapter_init(); // Should not hurt anything if already inited - esp_netif_init(); - if(sntp_enabled()){ - sntp_stop(); - } - sntp_setoperatingmode(SNTP_OPMODE_POLL); - sntp_setservername(0, (char*)server1); - sntp_setservername(1, (char*)server2); - sntp_setservername(2, (char*)server3); - sntp_init(); - setenv("TZ", tz, 1); - tzset(); +void configTzTime(const char* tz, const char* server1, const char* server2, const char* server3) { + //tcpip_adapter_init(); // Should not hurt anything if already inited + esp_netif_init(); + if (sntp_enabled()) { + sntp_stop(); + } + sntp_setoperatingmode(SNTP_OPMODE_POLL); + sntp_setservername(0, (char*)server1); + sntp_setservername(1, (char*)server2); + sntp_setservername(2, (char*)server3); + sntp_init(); + setenv("TZ", tz, 1); + tzset(); } -bool getLocalTime(struct tm * info, uint32_t ms) -{ - uint32_t start = millis(); - time_t now; - while((millis()-start) <= ms) { - time(&now); - localtime_r(&now, info); - if(info->tm_year > (2016 - 1900)){ - return true; - } - delay(10); +bool getLocalTime(struct tm* info, uint32_t ms) { + uint32_t start = millis(); + time_t now; + while ((millis() - start) <= ms) { + time(&now); + localtime_r(&now, info); + if (info->tm_year > (2016 - 1900)) { + return true; } - return false; + delay(10); + } + return false; } - diff --git a/cores/esp32/esp32-hal-timer.c b/cores/esp32/esp32-hal-timer.c index b8ab8548d76..b2ea5f8c06d 100644 --- a/cores/esp32/esp32-hal-timer.c +++ b/cores/esp32/esp32-hal-timer.c @@ -16,202 +16,200 @@ #if SOC_GPTIMER_SUPPORTED #include "driver/gptimer.h" -#if defined __has_include && __has_include ("clk_tree.h") +#if defined __has_include && __has_include("clk_tree.h") #include "clk_tree.h" #else #include "esp_clk_tree.h" #endif typedef void (*voidFuncPtr)(void); -typedef void (*voidFuncPtrArg)(void*); +typedef void (*voidFuncPtrArg)(void *); typedef struct { - voidFuncPtr fn; - void* arg; + voidFuncPtr fn; + void *arg; } interrupt_config_t; struct timer_struct_t { - gptimer_handle_t timer_handle; - interrupt_config_t interrupt_handle; - bool timer_started; + gptimer_handle_t timer_handle; + interrupt_config_t interrupt_handle; + bool timer_started; }; -inline uint64_t timerRead(hw_timer_t * timer){ +inline uint64_t timerRead(hw_timer_t *timer) { - uint64_t value; - gptimer_get_raw_count(timer->timer_handle, &value); - return value; + uint64_t value; + gptimer_get_raw_count(timer->timer_handle, &value); + return value; } -void timerWrite(hw_timer_t * timer, uint64_t val){ - gptimer_set_raw_count(timer->timer_handle, val); +void timerWrite(hw_timer_t *timer, uint64_t val) { + gptimer_set_raw_count(timer->timer_handle, val); } -void timerAlarm(hw_timer_t * timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count){ - esp_err_t err = ESP_OK; - gptimer_alarm_config_t alarm_cfg = { - .alarm_count = alarm_value, - .reload_count = reload_count, - .flags.auto_reload_on_alarm = autoreload, - }; - err = gptimer_set_alarm_action(timer->timer_handle, &alarm_cfg); - if (err != ESP_OK){ - log_e("Timer Alarm Write failed, error num=%d", err); - } +void timerAlarm(hw_timer_t *timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count) { + esp_err_t err = ESP_OK; + gptimer_alarm_config_t alarm_cfg = { + .alarm_count = alarm_value, + .reload_count = reload_count, + .flags.auto_reload_on_alarm = autoreload, + }; + err = gptimer_set_alarm_action(timer->timer_handle, &alarm_cfg); + if (err != ESP_OK) { + log_e("Timer Alarm Write failed, error num=%d", err); + } } -uint32_t timerGetFrequency(hw_timer_t * timer){ - uint32_t frequency; - gptimer_get_resolution(timer->timer_handle, &frequency); - return frequency; +uint32_t timerGetFrequency(hw_timer_t *timer) { + uint32_t frequency; + gptimer_get_resolution(timer->timer_handle, &frequency); + return frequency; } -void timerStart(hw_timer_t * timer){ - gptimer_start(timer->timer_handle); - timer->timer_started = true; +void timerStart(hw_timer_t *timer) { + gptimer_start(timer->timer_handle); + timer->timer_started = true; } -void timerStop(hw_timer_t * timer){ - gptimer_stop(timer->timer_handle); - timer->timer_started = false; +void timerStop(hw_timer_t *timer) { + gptimer_stop(timer->timer_handle); + timer->timer_started = false; } -void timerRestart(hw_timer_t * timer){ - gptimer_set_raw_count(timer->timer_handle,0); +void timerRestart(hw_timer_t *timer) { + gptimer_set_raw_count(timer->timer_handle, 0); } -hw_timer_t * timerBegin(uint32_t frequency){ - esp_err_t err = ESP_OK; - uint32_t counter_src_hz = 0; - uint32_t divider = 0; - soc_periph_gptimer_clk_src_t clk; +hw_timer_t *timerBegin(uint32_t frequency) { + esp_err_t err = ESP_OK; + uint32_t counter_src_hz = 0; + uint32_t divider = 0; + soc_periph_gptimer_clk_src_t clk; - soc_periph_gptimer_clk_src_t gptimer_clks[] = SOC_GPTIMER_CLKS; - for (size_t i = 0; i < sizeof(gptimer_clks) / sizeof(gptimer_clks[0]); i++){ - clk = gptimer_clks[i]; -#if defined __has_include && __has_include ("clk_tree.h") - clk_tree_src_get_freq_hz(clk, CLK_TREE_SRC_FREQ_PRECISION_CACHED, &counter_src_hz); + soc_periph_gptimer_clk_src_t gptimer_clks[] = SOC_GPTIMER_CLKS; + for (size_t i = 0; i < sizeof(gptimer_clks) / sizeof(gptimer_clks[0]); i++) { + clk = gptimer_clks[i]; +#if defined __has_include && __has_include("clk_tree.h") + clk_tree_src_get_freq_hz(clk, CLK_TREE_SRC_FREQ_PRECISION_CACHED, &counter_src_hz); #else - esp_clk_tree_src_get_freq_hz(clk, ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED, &counter_src_hz); + esp_clk_tree_src_get_freq_hz(clk, ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED, &counter_src_hz); #endif - divider = counter_src_hz / frequency; - if((divider >= 2) && (divider <= 65536)){ - break; - } - else divider = 0; - } - - if(divider == 0){ - log_e("Resolution cannot be reached with any clock source, aborting!"); - return NULL; - } - - gptimer_config_t config = { - .clk_src = clk, - .direction = GPTIMER_COUNT_UP, - .resolution_hz = frequency, - .flags.intr_shared = true, - }; - - hw_timer_t *timer = malloc(sizeof(hw_timer_t)); - - err = gptimer_new_timer(&config, &timer->timer_handle); - if (err != ESP_OK){ - log_e("Failed to create a new GPTimer, error num=%d", err); - free(timer); - return NULL; - } - gptimer_enable(timer->timer_handle); - gptimer_start(timer->timer_handle); - timer->timer_started = true; - return timer; -} - -void timerEnd(hw_timer_t * timer){ - esp_err_t err = ESP_OK; - if(timer->timer_started == true){ - gptimer_stop(timer->timer_handle); - } - gptimer_disable(timer->timer_handle); - err = gptimer_del_timer(timer->timer_handle); - if (err != ESP_OK){ - log_e("Failed to destroy GPTimer, error num=%d", err); - return; - } + divider = counter_src_hz / frequency; + if ((divider >= 2) && (divider <= 65536)) { + break; + } else divider = 0; + } + + if (divider == 0) { + log_e("Resolution cannot be reached with any clock source, aborting!"); + return NULL; + } + + gptimer_config_t config = { + .clk_src = clk, + .direction = GPTIMER_COUNT_UP, + .resolution_hz = frequency, + .flags.intr_shared = true, + }; + + hw_timer_t *timer = malloc(sizeof(hw_timer_t)); + + err = gptimer_new_timer(&config, &timer->timer_handle); + if (err != ESP_OK) { + log_e("Failed to create a new GPTimer, error num=%d", err); free(timer); + return NULL; + } + gptimer_enable(timer->timer_handle); + gptimer_start(timer->timer_handle); + timer->timer_started = true; + return timer; } -bool IRAM_ATTR timerFnWrapper(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void * args){ - interrupt_config_t * isr = (interrupt_config_t*)args; - if(isr->fn) { - if(isr->arg){ - ((voidFuncPtrArg)isr->fn)(isr->arg); - } else { - isr->fn(); - } +void timerEnd(hw_timer_t *timer) { + esp_err_t err = ESP_OK; + if (timer->timer_started == true) { + gptimer_stop(timer->timer_handle); + } + gptimer_disable(timer->timer_handle); + err = gptimer_del_timer(timer->timer_handle); + if (err != ESP_OK) { + log_e("Failed to destroy GPTimer, error num=%d", err); + return; + } + free(timer); +} + +bool IRAM_ATTR timerFnWrapper(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *args) { + interrupt_config_t *isr = (interrupt_config_t *)args; + if (isr->fn) { + if (isr->arg) { + ((voidFuncPtrArg)isr->fn)(isr->arg); + } else { + isr->fn(); } - // some additional logic or handling may be required here to approriately yield or not - return false; + } + // some additional logic or handling may be required here to appropriately yield or not + return false; } -void timerAttachInterruptFunctionalArg(hw_timer_t * timer, void (*userFunc)(void*), void * arg){ - esp_err_t err = ESP_OK; - gptimer_event_callbacks_t cbs = { - .on_alarm = timerFnWrapper, - }; - - timer->interrupt_handle.fn = (voidFuncPtr)userFunc; - timer->interrupt_handle.arg = arg; +void timerAttachInterruptFunctionalArg(hw_timer_t *timer, void (*userFunc)(void *), void *arg) { + esp_err_t err = ESP_OK; + gptimer_event_callbacks_t cbs = { + .on_alarm = timerFnWrapper, + }; - if(timer->timer_started == true){ - gptimer_stop(timer->timer_handle); - } - gptimer_disable(timer->timer_handle); - err = gptimer_register_event_callbacks(timer->timer_handle, &cbs, &timer->interrupt_handle); - if (err != ESP_OK){ - log_e("Timer Attach Interrupt failed, error num=%d", err); - } - gptimer_enable(timer->timer_handle); - if(timer->timer_started == true){ - gptimer_start(timer->timer_handle); - } + timer->interrupt_handle.fn = (voidFuncPtr)userFunc; + timer->interrupt_handle.arg = arg; + if (timer->timer_started == true) { + gptimer_stop(timer->timer_handle); + } + gptimer_disable(timer->timer_handle); + err = gptimer_register_event_callbacks(timer->timer_handle, &cbs, &timer->interrupt_handle); + if (err != ESP_OK) { + log_e("Timer Attach Interrupt failed, error num=%d", err); + } + gptimer_enable(timer->timer_handle); + if (timer->timer_started == true) { + gptimer_start(timer->timer_handle); + } } -void timerAttachInterruptArg(hw_timer_t * timer, void (*userFunc)(void*), void * arg){ - timerAttachInterruptFunctionalArg(timer, userFunc, arg); +void timerAttachInterruptArg(hw_timer_t *timer, void (*userFunc)(void *), void *arg) { + timerAttachInterruptFunctionalArg(timer, userFunc, arg); } -void timerAttachInterrupt(hw_timer_t * timer, voidFuncPtr userFunc){ - timerAttachInterruptFunctionalArg(timer, (voidFuncPtrArg)userFunc, NULL); +void timerAttachInterrupt(hw_timer_t *timer, voidFuncPtr userFunc) { + timerAttachInterruptFunctionalArg(timer, (voidFuncPtrArg)userFunc, NULL); } -void timerDetachInterrupt(hw_timer_t * timer){ - esp_err_t err = ESP_OK; - err = gptimer_set_alarm_action(timer->timer_handle, NULL); - timer->interrupt_handle.fn = NULL; - timer->interrupt_handle.arg = NULL; - if (err != ESP_OK){ - log_e("Timer Detach Interrupt failed, error num=%d", err); - } +void timerDetachInterrupt(hw_timer_t *timer) { + esp_err_t err = ESP_OK; + err = gptimer_set_alarm_action(timer->timer_handle, NULL); + timer->interrupt_handle.fn = NULL; + timer->interrupt_handle.arg = NULL; + if (err != ESP_OK) { + log_e("Timer Detach Interrupt failed, error num=%d", err); + } } -uint64_t timerReadMicros(hw_timer_t * timer){ - uint64_t timer_val = timerRead(timer); - uint32_t frequency = timerGetFrequency(timer); - return timer_val * 1000000 / frequency; +uint64_t timerReadMicros(hw_timer_t *timer) { + uint64_t timer_val = timerRead(timer); + uint32_t frequency = timerGetFrequency(timer); + return timer_val * 1000000 / frequency; } -uint64_t timerReadMilis(hw_timer_t * timer){ - uint64_t timer_val = timerRead(timer); - uint32_t frequency = timerGetFrequency(timer); - return timer_val * 1000 / frequency; +uint64_t timerReadMilis(hw_timer_t *timer) { + uint64_t timer_val = timerRead(timer); + uint32_t frequency = timerGetFrequency(timer); + return timer_val * 1000 / frequency; } -double timerReadSeconds(hw_timer_t * timer){ - uint64_t timer_val = timerRead(timer); - uint32_t frequency = timerGetFrequency(timer); - return (double)timer_val / frequency; +double timerReadSeconds(hw_timer_t *timer) { + uint64_t timer_val = timerRead(timer); + uint32_t frequency = timerGetFrequency(timer); + return (double)timer_val / frequency; } #endif /* SOC_GPTIMER_SUPPORTED */ diff --git a/cores/esp32/esp32-hal-timer.h b/cores/esp32/esp32-hal-timer.h index 9b71e1801f7..01571685332 100644 --- a/cores/esp32/esp32-hal-timer.h +++ b/cores/esp32/esp32-hal-timer.h @@ -29,29 +29,29 @@ extern "C" { #endif -struct timer_struct_t; -typedef struct timer_struct_t hw_timer_t; + struct timer_struct_t; + typedef struct timer_struct_t hw_timer_t; -hw_timer_t * timerBegin(uint32_t frequency); -void timerEnd(hw_timer_t * timer); + hw_timer_t* timerBegin(uint32_t frequency); + void timerEnd(hw_timer_t* timer); -void timerStart(hw_timer_t * timer); -void timerStop(hw_timer_t * timer); -void timerRestart(hw_timer_t * timer); -void timerWrite(hw_timer_t * timer, uint64_t val); + void timerStart(hw_timer_t* timer); + void timerStop(hw_timer_t* timer); + void timerRestart(hw_timer_t* timer); + void timerWrite(hw_timer_t* timer, uint64_t val); -uint64_t timerRead(hw_timer_t * timer); -uint64_t timerReadMicros(hw_timer_t * timer); -uint64_t timerReadMilis(hw_timer_t * timer); -double timerReadSeconds(hw_timer_t * timer); + uint64_t timerRead(hw_timer_t* timer); + uint64_t timerReadMicros(hw_timer_t* timer); + uint64_t timerReadMilis(hw_timer_t* timer); + double timerReadSeconds(hw_timer_t* timer); -uint32_t timerGetFrequency(hw_timer_t * timer); + uint32_t timerGetFrequency(hw_timer_t* timer); -void timerAttachInterrupt(hw_timer_t * timer, void (*userFunc)(void)); -void timerAttachInterruptArg(hw_timer_t * timer, void (*userFunc)(void*), void * arg); -void timerDetachInterrupt(hw_timer_t * timer); + void timerAttachInterrupt(hw_timer_t* timer, void (*userFunc)(void)); + void timerAttachInterruptArg(hw_timer_t* timer, void (*userFunc)(void*), void* arg); + void timerDetachInterrupt(hw_timer_t* timer); -void timerAlarm(hw_timer_t * timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count); + void timerAlarm(hw_timer_t* timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count); #ifdef __cplusplus } diff --git a/cores/esp32/esp32-hal-tinyusb.c b/cores/esp32/esp32-hal-tinyusb.c index fd0db206678..f0e9644daaf 100644 --- a/cores/esp32/esp32-hal-tinyusb.c +++ b/cores/esp32/esp32-hal-tinyusb.c @@ -42,7 +42,7 @@ #include "esp32s2/rom/usb/usb_dc.h" #include "esp32s2/rom/usb/chip_usb_dw_wrapper.h" #elif CONFIG_IDF_TARGET_ESP32S3 -#if defined __has_include && __has_include ("hal/usb_phy_ll.h") +#if defined __has_include && __has_include("hal/usb_phy_ll.h") #include "hal/usb_phy_ll.h" #else #include "hal/usb_fsls_phy_ll.h" @@ -53,67 +53,65 @@ #include "esp32s3/rom/usb/chip_usb_dw_wrapper.h" #endif -typedef enum{ - TINYUSB_USBDEV_0, +typedef enum { + TINYUSB_USBDEV_0, } tinyusb_usbdev_t; typedef char *tusb_desc_strarray_device_t[USB_STRING_DESCRIPTOR_ARRAY_SIZE]; typedef struct { - bool external_phy; + bool external_phy; } tinyusb_config_t; -static bool usb_otg_deinit(void * busptr) { - // Once USB OTG is initialized, its GPIOs are assigned and it shall never be deinited - // except when S3 swithicng usb from cdc to jtag while resetting to bootrom +static bool usb_otg_deinit(void *busptr) { + // Once USB OTG is initialized, its GPIOs are assigned and it shall never be deinited + // except when S3 swithicng usb from cdc to jtag while resetting to bootrom #if CONFIG_IDF_TARGET_ESP32S3 - return true; + return true; #else - return false; + return false; #endif } -static void configure_pins(usb_hal_context_t *usb) -{ - for (const usb_iopin_dsc_t *iopin = usb_periph_iopins; iopin->pin != -1; ++iopin) { - if ((usb->use_external_phy) || (iopin->ext_phy_only == 0)) { - esp_rom_gpio_pad_select_gpio(iopin->pin); - if (iopin->is_output) { - esp_rom_gpio_connect_out_signal(iopin->pin, iopin->func, false, false); - } else { - esp_rom_gpio_connect_in_signal(iopin->pin, iopin->func, false); - if ((iopin->pin != GPIO_FUNC_IN_LOW) && (iopin->pin != GPIO_FUNC_IN_HIGH)) { - gpio_ll_input_enable(&GPIO, iopin->pin); - } - } - esp_rom_gpio_pad_unhold(iopin->pin); - } - } - if (!usb->use_external_phy) { - gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3); - gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3); - if (perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DM, usb_otg_deinit) && perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DP, usb_otg_deinit)){ - // Bus Pointer is not used anyway - once the USB GPIOs are assigned, they can't be detached - perimanSetPinBus(USBPHY_DM_NUM, ESP32_BUS_TYPE_USB_DM, (void *) usb, -1, -1); - perimanSetPinBus(USBPHY_DP_NUM, ESP32_BUS_TYPE_USB_DP, (void *) usb, -1, -1); - } else { - log_e("USB OTG Pins can't be set into Peripheral Manager."); +static void configure_pins(usb_hal_context_t *usb) { + for (const usb_iopin_dsc_t *iopin = usb_periph_iopins; iopin->pin != -1; ++iopin) { + if ((usb->use_external_phy) || (iopin->ext_phy_only == 0)) { + esp_rom_gpio_pad_select_gpio(iopin->pin); + if (iopin->is_output) { + esp_rom_gpio_connect_out_signal(iopin->pin, iopin->func, false, false); + } else { + esp_rom_gpio_connect_in_signal(iopin->pin, iopin->func, false); + if ((iopin->pin != GPIO_FUNC_IN_LOW) && (iopin->pin != GPIO_FUNC_IN_HIGH)) { + gpio_ll_input_enable(&GPIO, iopin->pin); } + } + esp_rom_gpio_pad_unhold(iopin->pin); + } + } + if (!usb->use_external_phy) { + gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3); + gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3); + if (perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DM, usb_otg_deinit) && perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DP, usb_otg_deinit)) { + // Bus Pointer is not used anyway - once the USB GPIOs are assigned, they can't be detached + perimanSetPinBus(USBPHY_DM_NUM, ESP32_BUS_TYPE_USB_DM, (void *)usb, -1, -1); + perimanSetPinBus(USBPHY_DP_NUM, ESP32_BUS_TYPE_USB_DP, (void *)usb, -1, -1); + } else { + log_e("USB OTG Pins can't be set into Peripheral Manager."); } + } } -esp_err_t tinyusb_driver_install(const tinyusb_config_t *config) -{ - usb_hal_context_t hal = { - .use_external_phy = config->external_phy - }; - usb_hal_init(&hal); - configure_pins(&hal); - if (!tusb_init()) { - log_e("Can't initialize the TinyUSB stack."); - return ESP_FAIL; - } - return ESP_OK; +esp_err_t tinyusb_driver_install(const tinyusb_config_t *config) { + usb_hal_context_t hal = { + .use_external_phy = config->external_phy + }; + usb_hal_init(&hal); + configure_pins(&hal); + if (!tusb_init()) { + log_e("Can't initialize the TinyUSB stack."); + return ESP_FAIL; + } + return ESP_OK; } @@ -127,38 +125,38 @@ esp_err_t tinyusb_driver_install(const tinyusb_config_t *config) typedef char tusb_str_t[127]; -static bool WEBUSB_ENABLED = false; +static bool WEBUSB_ENABLED = false; -static tusb_str_t WEBUSB_URL = ""; -static tusb_str_t USB_DEVICE_PRODUCT = ""; +static tusb_str_t WEBUSB_URL = ""; +static tusb_str_t USB_DEVICE_PRODUCT = ""; static tusb_str_t USB_DEVICE_MANUFACTURER = ""; -static tusb_str_t USB_DEVICE_SERIAL = ""; -static tusb_str_t USB_DEVICE_LANGUAGE = "\x09\x04";//English (0x0409) +static tusb_str_t USB_DEVICE_SERIAL = ""; +static tusb_str_t USB_DEVICE_LANGUAGE = "\x09\x04"; //English (0x0409) -static uint8_t USB_DEVICE_ATTRIBUTES = 0; -static uint16_t USB_DEVICE_POWER = 0; +static uint8_t USB_DEVICE_ATTRIBUTES = 0; +static uint16_t USB_DEVICE_POWER = 0; /* * Device Descriptor * */ static tusb_desc_device_t tinyusb_device_descriptor = { - .bLength = sizeof(tusb_desc_device_t), - .bDescriptorType = TUSB_DESC_DEVICE, - .bcdUSB = 0, - .bDeviceClass = 0, - .bDeviceSubClass = 0, - .bDeviceProtocol = 0, - .bMaxPacketSize0 = CFG_TUD_ENDOINT0_SIZE, - - .idVendor = 0, - .idProduct = 0, - .bcdDevice = 0, - - .iManufacturer = 0x01, - .iProduct = 0x02, - .iSerialNumber = 0x03, - - .bNumConfigurations = 0x01 + .bLength = sizeof(tusb_desc_device_t), + .bDescriptorType = TUSB_DESC_DEVICE, + .bcdUSB = 0, + .bDeviceClass = 0, + .bDeviceSubClass = 0, + .bDeviceProtocol = 0, + .bMaxPacketSize0 = CFG_TUD_ENDOINT0_SIZE, + + .idVendor = 0, + .idProduct = 0, + .bcdDevice = 0, + + .iManufacturer = 0x01, + .iProduct = 0x02, + .iSerialNumber = 0x03, + + .bNumConfigurations = 0x01 }; /* @@ -166,12 +164,12 @@ static tusb_desc_device_t tinyusb_device_descriptor = { * */ #define MAX_STRING_DESCRIPTORS 20 static uint32_t tinyusb_string_descriptor_len = 4; -static char * tinyusb_string_descriptor[MAX_STRING_DESCRIPTORS] = { - // array of pointer to string descriptors - USB_DEVICE_LANGUAGE, // 0: is supported language - USB_DEVICE_MANUFACTURER,// 1: Manufacturer - USB_DEVICE_PRODUCT, // 2: Product - USB_DEVICE_SERIAL, // 3: Serials, should use chip ID +static char *tinyusb_string_descriptor[MAX_STRING_DESCRIPTORS] = { + // array of pointer to string descriptors + USB_DEVICE_LANGUAGE, // 0: is supported language + USB_DEVICE_MANUFACTURER, // 1: Manufacturer + USB_DEVICE_PRODUCT, // 2: Product + USB_DEVICE_SERIAL, // 3: Serials, should use chip ID }; @@ -189,34 +187,33 @@ GUID is freshly generated and should be OK to use. (Section Microsoft OS compatibility descriptors) */ -#define MS_OS_20_DESC_LEN 0xB2 - -static uint8_t const tinyusb_ms_os_20_descriptor[] = -{ - // Set header: length, type, windows version, total length - U16_TO_U8S_LE(0x000A), U16_TO_U8S_LE(MS_OS_20_SET_HEADER_DESCRIPTOR), U32_TO_U8S_LE(0x06030000), U16_TO_U8S_LE(MS_OS_20_DESC_LEN), - - // Configuration subset header: length, type, configuration index, reserved, configuration total length - U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_CONFIGURATION), 0, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A), - - // Function Subset header: length, type, first interface, reserved, subset length - U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), 0, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A-0x08), - - // MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID - U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible - - // MS OS 2.0 Registry property descriptor: length, type - U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A-0x08-0x08-0x14), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY), - U16_TO_U8S_LE(0x0007), U16_TO_U8S_LE(0x002A), // wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUIDs\0" in UTF-16 - 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, - 'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00, 0x00, 0x00, - U16_TO_U8S_LE(0x0050), // wPropertyDataLength - //bPropertyData: “{975F44D9-0D08-43FD-8B3E-127CA8AFFF9D}”. - '{', 0x00, '9', 0x00, '7', 0x00, '5', 0x00, 'F', 0x00, '4', 0x00, '4', 0x00, 'D', 0x00, '9', 0x00, '-', 0x00, - '0', 0x00, 'D', 0x00, '0', 0x00, '8', 0x00, '-', 0x00, '4', 0x00, '3', 0x00, 'F', 0x00, 'D', 0x00, '-', 0x00, - '8', 0x00, 'B', 0x00, '3', 0x00, 'E', 0x00, '-', 0x00, '1', 0x00, '2', 0x00, '7', 0x00, 'C', 0x00, 'A', 0x00, - '8', 0x00, 'A', 0x00, 'F', 0x00, 'F', 0x00, 'F', 0x00, '9', 0x00, 'D', 0x00, '}', 0x00, 0x00, 0x00, 0x00, 0x00 +#define MS_OS_20_DESC_LEN 0xB2 + +static uint8_t const tinyusb_ms_os_20_descriptor[] = { + // Set header: length, type, windows version, total length + U16_TO_U8S_LE(0x000A), U16_TO_U8S_LE(MS_OS_20_SET_HEADER_DESCRIPTOR), U32_TO_U8S_LE(0x06030000), U16_TO_U8S_LE(MS_OS_20_DESC_LEN), + + // Configuration subset header: length, type, configuration index, reserved, configuration total length + U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_CONFIGURATION), 0, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN - 0x0A), + + // Function Subset header: length, type, first interface, reserved, subset length + U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), 0, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN - 0x0A - 0x08), + + // MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID + U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible + + // MS OS 2.0 Registry property descriptor: length, type + U16_TO_U8S_LE(MS_OS_20_DESC_LEN - 0x0A - 0x08 - 0x08 - 0x14), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY), + U16_TO_U8S_LE(0x0007), U16_TO_U8S_LE(0x002A), // wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUIDs\0" in UTF-16 + 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, + 'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00, 0x00, 0x00, + U16_TO_U8S_LE(0x0050), // wPropertyDataLength + //bPropertyData: “{975F44D9-0D08-43FD-8B3E-127CA8AFFF9D}”. + '{', 0x00, '9', 0x00, '7', 0x00, '5', 0x00, 'F', 0x00, '4', 0x00, '4', 0x00, 'D', 0x00, '9', 0x00, '-', 0x00, + '0', 0x00, 'D', 0x00, '0', 0x00, '8', 0x00, '-', 0x00, '4', 0x00, '3', 0x00, 'F', 0x00, 'D', 0x00, '-', 0x00, + '8', 0x00, 'B', 0x00, '3', 0x00, 'E', 0x00, '-', 0x00, '1', 0x00, '2', 0x00, '7', 0x00, 'C', 0x00, 'A', 0x00, + '8', 0x00, 'A', 0x00, 'F', 0x00, 'F', 0x00, 'F', 0x00, '9', 0x00, 'D', 0x00, '}', 0x00, 0x00, 0x00, 0x00, 0x00 }; TU_VERIFY_STATIC(sizeof(tinyusb_ms_os_20_descriptor) == MS_OS_20_DESC_LEN, "Incorrect size"); @@ -225,22 +222,22 @@ TU_VERIFY_STATIC(sizeof(tinyusb_ms_os_20_descriptor) == MS_OS_20_DESC_LEN, "Inco /* * BOS Descriptor (required for webUSB) * */ -#define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_WEBUSB_DESC_LEN + TUD_BOS_MICROSOFT_OS_DESC_LEN) +#define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_WEBUSB_DESC_LEN + TUD_BOS_MICROSOFT_OS_DESC_LEN) enum { - VENDOR_REQUEST_WEBUSB = 1, - VENDOR_REQUEST_MICROSOFT = 2 + VENDOR_REQUEST_WEBUSB = 1, + VENDOR_REQUEST_MICROSOFT = 2 }; static uint8_t const tinyusb_bos_descriptor[] = { - // total length, number of device caps - TUD_BOS_DESCRIPTOR(BOS_TOTAL_LEN, 2), + // total length, number of device caps + TUD_BOS_DESCRIPTOR(BOS_TOTAL_LEN, 2), - // Vendor Code, iLandingPage - TUD_BOS_WEBUSB_DESCRIPTOR(VENDOR_REQUEST_WEBUSB, 1), + // Vendor Code, iLandingPage + TUD_BOS_WEBUSB_DESCRIPTOR(VENDOR_REQUEST_WEBUSB, 1), - // Microsoft OS 2.0 descriptor - TUD_BOS_MS_OS_20_DESCRIPTOR(MS_OS_20_DESC_LEN, VENDOR_REQUEST_MICROSOFT) + // Microsoft OS 2.0 descriptor + TUD_BOS_MS_OS_20_DESCRIPTOR(MS_OS_20_DESC_LEN, VENDOR_REQUEST_MICROSOFT) }; /* @@ -250,14 +247,14 @@ typedef struct TU_ATTR_PACKED { uint8_t bLength; uint8_t bDescriptorType; uint8_t bScheme; - char url[127]; + char url[127]; } tinyusb_desc_webusb_url_t; static tinyusb_desc_webusb_url_t tinyusb_url_descriptor = { - .bLength = 3, - .bDescriptorType = 3, // WEBUSB URL type - .bScheme = 255, // URL Scheme Prefix: 0: "http://", 1: "https://", 255: "" - .url = "" + .bLength = 3, + .bDescriptorType = 3, // WEBUSB URL type + .bScheme = 255, // URL Scheme Prefix: 0: "http://", 1: "https://", 255: "" + .url = "" }; /* @@ -268,17 +265,17 @@ static tinyusb_descriptor_cb_t tinyusb_loaded_interfaces_callbacks[USB_INTERFACE static uint32_t tinyusb_loaded_interfaces_mask = 0; static uint8_t tinyusb_loaded_interfaces_num = 0; static uint16_t tinyusb_config_descriptor_len = 0; -static uint8_t * tinyusb_config_descriptor = NULL; +static uint8_t *tinyusb_config_descriptor = NULL; /* * Endpoint Usage Tracking * */ typedef union { - struct { - uint32_t in:16; - uint32_t out:16; - }; - uint32_t val; + struct { + uint32_t in : 16; + uint32_t out : 16; + }; + uint32_t val; } tinyusb_endpoints_usage_t; static tinyusb_endpoints_usage_t tinyusb_endpoints; @@ -291,113 +288,123 @@ static tinyusb_endpoints_usage_t tinyusb_endpoints; /** * @brief Invoked when received GET CONFIGURATION DESCRIPTOR. */ -__attribute__ ((weak)) uint8_t const *tud_descriptor_configuration_cb(uint8_t index) -{ - //log_d("%u", index); - return tinyusb_config_descriptor; +__attribute__((weak)) uint8_t const *tud_descriptor_configuration_cb(uint8_t index) { + //log_d("%u", index); + return tinyusb_config_descriptor; } /** * @brief Invoked when received GET DEVICE DESCRIPTOR. */ -__attribute__ ((weak)) uint8_t const *tud_descriptor_device_cb(void) -{ - //log_d(""); - return (uint8_t const *)&tinyusb_device_descriptor; +__attribute__((weak)) uint8_t const *tud_descriptor_device_cb(void) { + //log_d(""); + return (uint8_t const *)&tinyusb_device_descriptor; } /** * @brief Invoked when received GET STRING DESCRIPTOR request. */ -__attribute__ ((weak)) uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) -{ - //log_d("%u (0x%x)", index, langid); - static uint16_t _desc_str[127]; - uint8_t chr_count; - - if (index == 0) { - memcpy(&_desc_str[1], tinyusb_string_descriptor[0], 2); - chr_count = 1; - } else { - // Convert ASCII string into UTF-16 - if (index >= tinyusb_string_descriptor_len) { - return NULL; - } - const char *str = tinyusb_string_descriptor[index]; - // Cap at max char - chr_count = strlen(str); - if (chr_count > 126) { - chr_count = 126; - } - for (uint8_t i = 0; i < chr_count; i++) { - _desc_str[1 + i] = str[i]; - } - } - - // first byte is len, second byte is string type - _desc_str[0] = (TUSB_DESC_STRING << 8 ) | (2*chr_count + 2); - - return _desc_str; +__attribute__((weak)) uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) { + //log_d("%u (0x%x)", index, langid); + static uint16_t _desc_str[127]; + uint8_t chr_count; + + if (index == 0) { + memcpy(&_desc_str[1], tinyusb_string_descriptor[0], 2); + chr_count = 1; + } else { + // Convert ASCII string into UTF-16 + if (index >= tinyusb_string_descriptor_len) { + return NULL; + } + const char *str = tinyusb_string_descriptor[index]; + // Cap at max char + chr_count = strlen(str); + if (chr_count > 126) { + chr_count = 126; + } + for (uint8_t i = 0; i < chr_count; i++) { + _desc_str[1 + i] = str[i]; + } + } + + // first byte is len, second byte is string type + _desc_str[0] = (TUSB_DESC_STRING << 8) | (2 * chr_count + 2); + + return _desc_str; } /** * @brief Invoked when received GET BOS DESCRIPTOR request. */ -uint8_t const * tud_descriptor_bos_cb(void) -{ - //log_v(""); - return tinyusb_bos_descriptor; +uint8_t const *tud_descriptor_bos_cb(void) { + //log_v(""); + return tinyusb_bos_descriptor; } -__attribute__ ((weak)) bool tinyusb_vendor_control_request_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request){ return false; } +__attribute__((weak)) bool tinyusb_vendor_control_request_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request) { + return false; +} /** * @brief Handle WebUSB and Vendor requests. */ -bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request) -{ - if(WEBUSB_ENABLED && (request->bRequest == VENDOR_REQUEST_WEBUSB - || (request->bRequest == VENDOR_REQUEST_MICROSOFT && request->wIndex == 7))){ - // we only care for SETUP stage - if (stage == CONTROL_STAGE_SETUP) { - if(request->bRequest == VENDOR_REQUEST_WEBUSB){ - // match vendor request in BOS descriptor - // Get landing page url - tinyusb_url_descriptor.bLength = 3 + strlen(WEBUSB_URL); - snprintf(tinyusb_url_descriptor.url, 127, "%s", WEBUSB_URL); - return tud_control_xfer(rhport, request, (void*) &tinyusb_url_descriptor, tinyusb_url_descriptor.bLength); - } - // Get Microsoft OS 2.0 compatible descriptor - uint16_t total_len; - memcpy(&total_len, tinyusb_ms_os_20_descriptor + 8, 2); - return tud_control_xfer(rhport, request, (void*) tinyusb_ms_os_20_descriptor, total_len); - } - return true; +bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request) { + if (WEBUSB_ENABLED && (request->bRequest == VENDOR_REQUEST_WEBUSB || (request->bRequest == VENDOR_REQUEST_MICROSOFT && request->wIndex == 7))) { + // we only care for SETUP stage + if (stage == CONTROL_STAGE_SETUP) { + if (request->bRequest == VENDOR_REQUEST_WEBUSB) { + // match vendor request in BOS descriptor + // Get landing page url + tinyusb_url_descriptor.bLength = 3 + strlen(WEBUSB_URL); + snprintf(tinyusb_url_descriptor.url, 127, "%s", WEBUSB_URL); + return tud_control_xfer(rhport, request, (void *)&tinyusb_url_descriptor, tinyusb_url_descriptor.bLength); + } + // Get Microsoft OS 2.0 compatible descriptor + uint16_t total_len; + memcpy(&total_len, tinyusb_ms_os_20_descriptor + 8, 2); + return tud_control_xfer(rhport, request, (void *)tinyusb_ms_os_20_descriptor, total_len); } - log_v("rhport: %u, stage: %u, type: 0x%x, request: 0x%x", rhport, stage, request->bmRequestType_bit.type, request->bRequest); - return tinyusb_vendor_control_request_cb(rhport, stage, request); + return true; + } + log_v("rhport: %u, stage: %u, type: 0x%x, request: 0x%x", rhport, stage, request->bmRequestType_bit.type, request->bRequest); + return tinyusb_vendor_control_request_cb(rhport, stage, request); } /* * Required Callbacks * */ #if CFG_TUD_DFU -__attribute__ ((weak)) uint32_t tud_dfu_get_timeout_cb(uint8_t alt, uint8_t state){return 0;} -__attribute__ ((weak)) void tud_dfu_download_cb (uint8_t alt, uint16_t block_num, uint8_t const *data, uint16_t length){} -__attribute__ ((weak)) void tud_dfu_manifest_cb(uint8_t alt){} +__attribute__((weak)) uint32_t tud_dfu_get_timeout_cb(uint8_t alt, uint8_t state) { + return 0; +} +__attribute__((weak)) void tud_dfu_download_cb(uint8_t alt, uint16_t block_num, uint8_t const *data, uint16_t length) {} +__attribute__((weak)) void tud_dfu_manifest_cb(uint8_t alt) {} #endif #if CFG_TUD_HID -__attribute__ ((weak)) const uint8_t * tud_hid_descriptor_report_cb(uint8_t itf){return NULL;} -__attribute__ ((weak)) uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen){return 0;} -__attribute__ ((weak)) void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, const uint8_t * buffer, uint16_t bufsize){} +__attribute__((weak)) const uint8_t *tud_hid_descriptor_report_cb(uint8_t itf) { + return NULL; +} +__attribute__((weak)) uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen) { + return 0; +} +__attribute__((weak)) void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, const uint8_t *buffer, uint16_t bufsize) {} #endif #if CFG_TUD_MSC -__attribute__ ((weak)) bool tud_msc_test_unit_ready_cb(uint8_t lun){return false;} -__attribute__ ((weak)) void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]){} -__attribute__ ((weak)) void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size){} -__attribute__ ((weak)) int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize){return -1;} -__attribute__ ((weak)) int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize){return -1;} -__attribute__ ((weak)) int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize){return -1;} +__attribute__((weak)) bool tud_msc_test_unit_ready_cb(uint8_t lun) { + return false; +} +__attribute__((weak)) void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]) {} +__attribute__((weak)) void tud_msc_capacity_cb(uint8_t lun, uint32_t *block_count, uint16_t *block_size) {} +__attribute__((weak)) int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void *buffer, uint32_t bufsize) { + return -1; +} +__attribute__((weak)) int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t *buffer, uint32_t bufsize) { + return -1; +} +__attribute__((weak)) int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void *buffer, uint16_t bufsize) { + return -1; +} #endif @@ -410,413 +417,406 @@ static restart_type_t usb_persist_mode = RESTART_NO_PERSIST; #if CONFIG_IDF_TARGET_ESP32S3 static void hw_cdc_reset_handler(void *arg) { - portBASE_TYPE xTaskWoken = 0; - uint32_t usbjtag_intr_status = usb_serial_jtag_ll_get_intsts_mask(); - usb_serial_jtag_ll_clr_intsts_mask(usbjtag_intr_status); - - if (usbjtag_intr_status & USB_SERIAL_JTAG_INTR_BUS_RESET) { - xSemaphoreGiveFromISR((SemaphoreHandle_t)arg, &xTaskWoken); - } + portBASE_TYPE xTaskWoken = 0; + uint32_t usbjtag_intr_status = usb_serial_jtag_ll_get_intsts_mask(); + usb_serial_jtag_ll_clr_intsts_mask(usbjtag_intr_status); - if (xTaskWoken == pdTRUE) { - portYIELD_FROM_ISR(); - } + if (usbjtag_intr_status & USB_SERIAL_JTAG_INTR_BUS_RESET) { + xSemaphoreGiveFromISR((SemaphoreHandle_t)arg, &xTaskWoken); + } + + if (xTaskWoken == pdTRUE) { + portYIELD_FROM_ISR(); + } } -static void usb_switch_to_cdc_jtag(){ - // Disable USB-OTG - periph_ll_reset(PERIPH_USB_MODULE); - //periph_ll_enable_clk_clear_rst(PERIPH_USB_MODULE); - periph_ll_disable_clk_set_rst(PERIPH_USB_MODULE); - - // Switch to hardware CDC+JTAG - CLEAR_PERI_REG_MASK(RTC_CNTL_USB_CONF_REG, (RTC_CNTL_SW_HW_USB_PHY_SEL|RTC_CNTL_SW_USB_PHY_SEL|RTC_CNTL_USB_PAD_ENABLE)); - - // Do not use external PHY - CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_PHY_SEL); - - // Release GPIO pins from CDC+JTAG - CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE); - - // Force the host to re-enumerate (BUS_RESET) - pinMode(USBPHY_DM_NUM, OUTPUT_OPEN_DRAIN); - pinMode(USBPHY_DP_NUM, OUTPUT_OPEN_DRAIN); - digitalWrite(USBPHY_DM_NUM, LOW); - digitalWrite(USBPHY_DP_NUM, LOW); - - // Initialize CDC+JTAG ISR to listen for BUS_RESET - #if defined __has_include && __has_include ("hal/usb_phy_ll.h") - usb_phy_ll_int_jtag_enable(&USB_SERIAL_JTAG); - #else - usb_fsls_phy_ll_int_jtag_enable(&USB_SERIAL_JTAG); - #endif - 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); - intr_handle_t intr_handle = NULL; - SemaphoreHandle_t reset_sem = xSemaphoreCreateBinary(); - if(reset_sem){ - if(esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, 0, hw_cdc_reset_handler, reset_sem, &intr_handle) != ESP_OK){ - vSemaphoreDelete(reset_sem); - reset_sem = NULL; - log_e("HW USB CDC failed to init interrupts"); - } - } else { - log_e("reset_sem init failed"); - } +static void usb_switch_to_cdc_jtag() { + // Disable USB-OTG + periph_ll_reset(PERIPH_USB_MODULE); + //periph_ll_enable_clk_clear_rst(PERIPH_USB_MODULE); + periph_ll_disable_clk_set_rst(PERIPH_USB_MODULE); - // Connect GPIOs to integrated CDC+JTAG - SET_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE); + // Switch to hardware CDC+JTAG + CLEAR_PERI_REG_MASK(RTC_CNTL_USB_CONF_REG, (RTC_CNTL_SW_HW_USB_PHY_SEL | RTC_CNTL_SW_USB_PHY_SEL | RTC_CNTL_USB_PAD_ENABLE)); - // Wait for BUS_RESET to give us back the semaphore - if(reset_sem){ - if(xSemaphoreTake(reset_sem, 1000 / portTICK_PERIOD_MS) != pdPASS){ - log_e("reset_sem timeout"); - } - usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK); - esp_intr_free(intr_handle); - vSemaphoreDelete(reset_sem); + // Do not use external PHY + CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_PHY_SEL); + + // Release GPIO pins from CDC+JTAG + CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE); + + // Force the host to re-enumerate (BUS_RESET) + pinMode(USBPHY_DM_NUM, OUTPUT_OPEN_DRAIN); + pinMode(USBPHY_DP_NUM, OUTPUT_OPEN_DRAIN); + digitalWrite(USBPHY_DM_NUM, LOW); + digitalWrite(USBPHY_DP_NUM, LOW); + +// Initialize CDC+JTAG ISR to listen for BUS_RESET +#if defined __has_include && __has_include("hal/usb_phy_ll.h") + usb_phy_ll_int_jtag_enable(&USB_SERIAL_JTAG); +#else + usb_fsls_phy_ll_int_jtag_enable(&USB_SERIAL_JTAG); +#endif + 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); + intr_handle_t intr_handle = NULL; + SemaphoreHandle_t reset_sem = xSemaphoreCreateBinary(); + if (reset_sem) { + if (esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, 0, hw_cdc_reset_handler, reset_sem, &intr_handle) != ESP_OK) { + vSemaphoreDelete(reset_sem); + reset_sem = NULL; + log_e("HW USB CDC failed to init interrupts"); + } + } else { + log_e("reset_sem init failed"); + } + + // Connect GPIOs to integrated CDC+JTAG + SET_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE); + + // Wait for BUS_RESET to give us back the semaphore + if (reset_sem) { + if (xSemaphoreTake(reset_sem, 1000 / portTICK_PERIOD_MS) != pdPASS) { + log_e("reset_sem timeout"); } + usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK); + esp_intr_free(intr_handle); + vSemaphoreDelete(reset_sem); + } } #endif -static void IRAM_ATTR usb_persist_shutdown_handler(void) -{ - if(usb_persist_mode != RESTART_NO_PERSIST){ - if (usb_persist_enabled) { - usb_dc_prepare_persist(); - } - if (usb_persist_mode == RESTART_BOOTLOADER) { - //USB CDC Download - if (usb_persist_enabled) { - chip_usb_set_persist_flags(USBDC_PERSIST_ENA); +static void IRAM_ATTR usb_persist_shutdown_handler(void) { + if (usb_persist_mode != RESTART_NO_PERSIST) { + if (usb_persist_enabled) { + usb_dc_prepare_persist(); + } + if (usb_persist_mode == RESTART_BOOTLOADER) { + //USB CDC Download + if (usb_persist_enabled) { + chip_usb_set_persist_flags(USBDC_PERSIST_ENA); #if CONFIG_IDF_TARGET_ESP32S2 - } else { - periph_ll_reset(PERIPH_USB_MODULE); - periph_ll_enable_clk_clear_rst(PERIPH_USB_MODULE); + } else { + periph_ll_reset(PERIPH_USB_MODULE); + periph_ll_enable_clk_clear_rst(PERIPH_USB_MODULE); #endif - } - REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT); - } else if (usb_persist_mode == RESTART_BOOTLOADER_DFU) { - //DFU Download + } + REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT); + } else if (usb_persist_mode == RESTART_BOOTLOADER_DFU) { + //DFU Download #if CONFIG_IDF_TARGET_ESP32S2 - // Reset USB Core - USB0.grstctl |= USB_CSFTRST; - while ((USB0.grstctl & USB_CSFTRST) == USB_CSFTRST){} + // Reset USB Core + USB0.grstctl |= USB_CSFTRST; + while ((USB0.grstctl & USB_CSFTRST) == USB_CSFTRST) {} #endif - chip_usb_set_persist_flags(USBDC_BOOT_DFU); - REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT); - } else if (usb_persist_enabled) { - //USB Persist reboot - chip_usb_set_persist_flags(USBDC_PERSIST_ENA); - } + chip_usb_set_persist_flags(USBDC_BOOT_DFU); + REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT); + } else if (usb_persist_enabled) { + //USB Persist reboot + chip_usb_set_persist_flags(USBDC_PERSIST_ENA); } + } } -void usb_persist_restart(restart_type_t mode) -{ - if (mode < RESTART_TYPE_MAX && esp_register_shutdown_handler(usb_persist_shutdown_handler) == ESP_OK) { - usb_persist_mode = mode; +void usb_persist_restart(restart_type_t mode) { + if (mode < RESTART_TYPE_MAX && esp_register_shutdown_handler(usb_persist_shutdown_handler) == ESP_OK) { + usb_persist_mode = mode; #if CONFIG_IDF_TARGET_ESP32S3 - if (mode == RESTART_BOOTLOADER) { - usb_switch_to_cdc_jtag(); - } -#endif - esp_restart(); + if (mode == RESTART_BOOTLOADER) { + usb_switch_to_cdc_jtag(); } +#endif + esp_restart(); + } } -static bool tinyusb_reserve_in_endpoint(uint8_t endpoint){ - if(endpoint > 6 || (tinyusb_endpoints.in & BIT(endpoint)) != 0){ - return false; - } - tinyusb_endpoints.in |= BIT(endpoint); - return true; +static bool tinyusb_reserve_in_endpoint(uint8_t endpoint) { + if (endpoint > 6 || (tinyusb_endpoints.in & BIT(endpoint)) != 0) { + return false; + } + tinyusb_endpoints.in |= BIT(endpoint); + return true; } -static bool tinyusb_reserve_out_endpoint(uint8_t endpoint){ - if(endpoint > 6 || (tinyusb_endpoints.out & BIT(endpoint)) != 0){ - return false; - } - tinyusb_endpoints.out |= BIT(endpoint); - return true; +static bool tinyusb_reserve_out_endpoint(uint8_t endpoint) { + if (endpoint > 6 || (tinyusb_endpoints.out & BIT(endpoint)) != 0) { + return false; + } + tinyusb_endpoints.out |= BIT(endpoint); + return true; } -static bool tinyusb_has_available_fifos(void){ - uint8_t max_endpoints = 4, active_endpoints = 0; - if (tinyusb_loaded_interfaces_mask & BIT(USB_INTERFACE_CDC)) { - max_endpoints = 5; //CDC endpoint 0x85 is actually not linked to FIFO and not used - } - for(uint8_t i=1; i<7; i++){ - if((tinyusb_endpoints.in & BIT(i)) != 0){ - active_endpoints++; - } +static bool tinyusb_has_available_fifos(void) { + uint8_t max_endpoints = 4, active_endpoints = 0; + if (tinyusb_loaded_interfaces_mask & BIT(USB_INTERFACE_CDC)) { + max_endpoints = 5; //CDC endpoint 0x85 is actually not linked to FIFO and not used + } + for (uint8_t i = 1; i < 7; i++) { + if ((tinyusb_endpoints.in & BIT(i)) != 0) { + active_endpoints++; } + } - return active_endpoints < max_endpoints; + return active_endpoints < max_endpoints; } -static uint16_t tinyusb_load_descriptor(tinyusb_interface_t interface, uint8_t * dst, uint8_t * itf) -{ - if(tinyusb_loaded_interfaces_callbacks[interface]){ - return tinyusb_loaded_interfaces_callbacks[interface](dst, itf); - } - return 0; +static uint16_t tinyusb_load_descriptor(tinyusb_interface_t interface, uint8_t *dst, uint8_t *itf) { + if (tinyusb_loaded_interfaces_callbacks[interface]) { + return tinyusb_loaded_interfaces_callbacks[interface](dst, itf); + } + return 0; } -static bool tinyusb_load_enabled_interfaces(){ - tinyusb_config_descriptor_len += TUD_CONFIG_DESC_LEN; - tinyusb_config_descriptor = (uint8_t *)malloc(tinyusb_config_descriptor_len); - if (tinyusb_config_descriptor == NULL) { - log_e("Descriptor Malloc Failed"); +static bool tinyusb_load_enabled_interfaces() { + tinyusb_config_descriptor_len += TUD_CONFIG_DESC_LEN; + tinyusb_config_descriptor = (uint8_t *)malloc(tinyusb_config_descriptor_len); + if (tinyusb_config_descriptor == NULL) { + log_e("Descriptor Malloc Failed"); + return false; + } + uint8_t *dst = tinyusb_config_descriptor + TUD_CONFIG_DESC_LEN; + + for (int i = 0; i < USB_INTERFACE_MAX; i++) { + if (tinyusb_loaded_interfaces_mask & (1U << i)) { + uint16_t len = tinyusb_load_descriptor((tinyusb_interface_t)i, dst, &tinyusb_loaded_interfaces_num); + if (!len) { + log_e("Descriptor Load Failed"); return false; - } - uint8_t * dst = tinyusb_config_descriptor + TUD_CONFIG_DESC_LEN; - - for(int i=0; i> 4); - *srl++ = nibble_to_hex_char(b & 0xf); - } - *srl++ = '\0'; +static void set_usb_serial_num(void) { + /* Get the MAC address */ + const uint32_t mac0 = REG_GET_FIELD(EFUSE_RD_MAC_SPI_SYS_0_REG, EFUSE_MAC_0); + const uint32_t mac1 = REG_GET_FIELD(EFUSE_RD_MAC_SPI_SYS_1_REG, EFUSE_MAC_1); + uint8_t mac_bytes[6]; + memcpy(mac_bytes, &mac0, 4); + memcpy(mac_bytes + 4, &mac1, 2); + + /* Convert to UTF16 string */ + uint8_t *srl = (uint8_t *)USB_DEVICE_SERIAL; + for (int i = 0; i < 6; ++i) { + uint8_t b = mac_bytes[5 - i]; /* printing from the MSB */ + if (i) { + *srl++ = ':'; + } + *srl++ = nibble_to_hex_char(b >> 4); + *srl++ = nibble_to_hex_char(b & 0xf); + } + *srl++ = '\0'; } -static void tinyusb_apply_device_config(tinyusb_device_config_t *config){ - if(config->product_name){ - snprintf(USB_DEVICE_PRODUCT, 126, "%s", config->product_name); - } - - if(config->manufacturer_name){ - snprintf(USB_DEVICE_MANUFACTURER, 126, "%s", config->manufacturer_name); - } - - if(config->serial_number && config->serial_number[0]){ - snprintf(USB_DEVICE_SERIAL, 126, "%s", config->serial_number); - } else { - set_usb_serial_num(); - } - - if(config->webusb_url){ - snprintf(WEBUSB_URL, 126, "%s", config->webusb_url); - } - - // Windows 10 will not recognize the CDC device if WebUSB is enabled and USB Class is not 2 (CDC) - if( - (tinyusb_loaded_interfaces_mask & BIT(USB_INTERFACE_CDC)) - && config->webusb_enabled - && (config->usb_class != TUSB_CLASS_CDC) - ){ - config->usb_class = TUSB_CLASS_CDC; - config->usb_protocol = 0x00; - } - - WEBUSB_ENABLED = config->webusb_enabled; - USB_DEVICE_ATTRIBUTES = config->usb_attributes; - USB_DEVICE_POWER = config->usb_power_ma; - - tinyusb_device_descriptor.bcdUSB = config->usb_version; - tinyusb_device_descriptor.idVendor = config->vid; - tinyusb_device_descriptor.idProduct = config->pid; - tinyusb_device_descriptor.bcdDevice = config->fw_version; - tinyusb_device_descriptor.bDeviceClass = config->usb_class; - tinyusb_device_descriptor.bDeviceSubClass = config->usb_subclass; - tinyusb_device_descriptor.bDeviceProtocol = config->usb_protocol; +static void tinyusb_apply_device_config(tinyusb_device_config_t *config) { + if (config->product_name) { + snprintf(USB_DEVICE_PRODUCT, 126, "%s", config->product_name); + } + + if (config->manufacturer_name) { + snprintf(USB_DEVICE_MANUFACTURER, 126, "%s", config->manufacturer_name); + } + + if (config->serial_number && config->serial_number[0]) { + snprintf(USB_DEVICE_SERIAL, 126, "%s", config->serial_number); + } else { + set_usb_serial_num(); + } + + if (config->webusb_url) { + snprintf(WEBUSB_URL, 126, "%s", config->webusb_url); + } + + // Windows 10 will not recognize the CDC device if WebUSB is enabled and USB Class is not 2 (CDC) + if ( + (tinyusb_loaded_interfaces_mask & BIT(USB_INTERFACE_CDC)) + && config->webusb_enabled + && (config->usb_class != TUSB_CLASS_CDC)) { + config->usb_class = TUSB_CLASS_CDC; + config->usb_protocol = 0x00; + } + + WEBUSB_ENABLED = config->webusb_enabled; + USB_DEVICE_ATTRIBUTES = config->usb_attributes; + USB_DEVICE_POWER = config->usb_power_ma; + + tinyusb_device_descriptor.bcdUSB = config->usb_version; + tinyusb_device_descriptor.idVendor = config->vid; + tinyusb_device_descriptor.idProduct = config->pid; + tinyusb_device_descriptor.bcdDevice = config->fw_version; + tinyusb_device_descriptor.bDeviceClass = config->usb_class; + tinyusb_device_descriptor.bDeviceSubClass = config->usb_subclass; + tinyusb_device_descriptor.bDeviceProtocol = config->usb_protocol; } // USB Device Driver task // This top level thread processes all usb events and invokes callbacks static void usb_device_task(void *param) { - (void)param; - while(1) tud_task(); // RTOS forever loop + (void)param; + while (1) tud_task(); // RTOS forever loop } /* * PUBLIC API * */ #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR - const char *tinyusb_interface_names[USB_INTERFACE_MAX] = {"MSC", "DFU", "HID", "VENDOR", "CDC", "MIDI", "CUSTOM"}; +const char *tinyusb_interface_names[USB_INTERFACE_MAX] = { "MSC", "DFU", "HID", "VENDOR", "CDC", "MIDI", "CUSTOM" }; #endif static bool tinyusb_is_initialized = false; -esp_err_t tinyusb_enable_interface(tinyusb_interface_t interface, uint16_t descriptor_len, tinyusb_descriptor_cb_t cb){ - return tinyusb_enable_interface2(interface, descriptor_len, cb, false); +esp_err_t tinyusb_enable_interface(tinyusb_interface_t interface, uint16_t descriptor_len, tinyusb_descriptor_cb_t cb) { + return tinyusb_enable_interface2(interface, descriptor_len, cb, false); } -esp_err_t tinyusb_enable_interface2(tinyusb_interface_t interface, uint16_t descriptor_len, tinyusb_descriptor_cb_t cb, bool reserve_endpoints) -{ - if(tinyusb_is_initialized){ - log_e("TinyUSB has already started! Interface %s not enabled", (interface >= USB_INTERFACE_MAX)?"":tinyusb_interface_names[interface]); - return ESP_FAIL; - } - if((interface >= USB_INTERFACE_MAX) || (tinyusb_loaded_interfaces_mask & (1U << interface))){ - log_e("Interface %s invalid or already enabled", (interface >= USB_INTERFACE_MAX)?"":tinyusb_interface_names[interface]); - return ESP_FAIL; - } - if(interface == USB_INTERFACE_HID && reserve_endpoints){ - // Some simple PC BIOS requires specific endpoint addresses for keyboard at boot - if(!tinyusb_reserve_out_endpoint(1) ||!tinyusb_reserve_in_endpoint(1)){ - log_e("HID Reserve Endpoints Failed"); - return ESP_FAIL; - } - } - if(interface == USB_INTERFACE_CDC){ - if(!tinyusb_reserve_out_endpoint(3) ||!tinyusb_reserve_in_endpoint(4) || !tinyusb_reserve_in_endpoint(5)){ - log_e("CDC Reserve Endpoints Failed"); - return ESP_FAIL; - } - } - tinyusb_loaded_interfaces_mask |= (1U << interface); - tinyusb_config_descriptor_len += descriptor_len; - tinyusb_loaded_interfaces_callbacks[interface] = cb; - log_d("Interface %s enabled", tinyusb_interface_names[interface]); - return ESP_OK; +esp_err_t tinyusb_enable_interface2(tinyusb_interface_t interface, uint16_t descriptor_len, tinyusb_descriptor_cb_t cb, bool reserve_endpoints) { + if (tinyusb_is_initialized) { + log_e("TinyUSB has already started! Interface %s not enabled", (interface >= USB_INTERFACE_MAX) ? "" : tinyusb_interface_names[interface]); + return ESP_FAIL; + } + if ((interface >= USB_INTERFACE_MAX) || (tinyusb_loaded_interfaces_mask & (1U << interface))) { + log_e("Interface %s invalid or already enabled", (interface >= USB_INTERFACE_MAX) ? "" : tinyusb_interface_names[interface]); + return ESP_FAIL; + } + if (interface == USB_INTERFACE_HID && reserve_endpoints) { + // Some simple PC BIOS requires specific endpoint addresses for keyboard at boot + if (!tinyusb_reserve_out_endpoint(1) || !tinyusb_reserve_in_endpoint(1)) { + log_e("HID Reserve Endpoints Failed"); + return ESP_FAIL; + } + } + if (interface == USB_INTERFACE_CDC) { + if (!tinyusb_reserve_out_endpoint(3) || !tinyusb_reserve_in_endpoint(4) || !tinyusb_reserve_in_endpoint(5)) { + log_e("CDC Reserve Endpoints Failed"); + return ESP_FAIL; + } + } + tinyusb_loaded_interfaces_mask |= (1U << interface); + tinyusb_config_descriptor_len += descriptor_len; + tinyusb_loaded_interfaces_callbacks[interface] = cb; + log_d("Interface %s enabled", tinyusb_interface_names[interface]); + return ESP_OK; } esp_err_t tinyusb_init(tinyusb_device_config_t *config) { - if(tinyusb_is_initialized){ - return ESP_OK; - } - tinyusb_is_initialized = true; - - //tinyusb_endpoints.val = 0; - tinyusb_apply_device_config(config); - if (!tinyusb_load_enabled_interfaces()) { - tinyusb_is_initialized = false; - return ESP_FAIL; - } - - bool usb_did_persist = (USB_WRAP.date.val == USBDC_PERSIST_ENA); - - //if(usb_did_persist && usb_persist_enabled){ - // Enable USB/IO_MUX peripheral reset, if coming from persistent reboot - REG_CLR_BIT(RTC_CNTL_USB_CONF_REG, RTC_CNTL_IO_MUX_RESET_DISABLE); - REG_CLR_BIT(RTC_CNTL_USB_CONF_REG, RTC_CNTL_USB_RESET_DISABLE); - //} else - if(!usb_did_persist || !usb_persist_enabled){ - // Reset USB module - periph_ll_reset(PERIPH_USB_MODULE); - periph_ll_enable_clk_clear_rst(PERIPH_USB_MODULE); - } - - tinyusb_config_t tusb_cfg = { - .external_phy = false // In the most cases you need to use a `false` value - }; - esp_err_t err = tinyusb_driver_install(&tusb_cfg); - if (err != ESP_OK) { - tinyusb_is_initialized = false; - return err; - } - xTaskCreate(usb_device_task, "usbd", 4096, NULL, configMAX_PRIORITIES - 1, NULL); + if (tinyusb_is_initialized) { + return ESP_OK; + } + tinyusb_is_initialized = true; + + //tinyusb_endpoints.val = 0; + tinyusb_apply_device_config(config); + if (!tinyusb_load_enabled_interfaces()) { + tinyusb_is_initialized = false; + return ESP_FAIL; + } + + bool usb_did_persist = (USB_WRAP.date.val == USBDC_PERSIST_ENA); + + //if(usb_did_persist && usb_persist_enabled){ + // Enable USB/IO_MUX peripheral reset, if coming from persistent reboot + REG_CLR_BIT(RTC_CNTL_USB_CONF_REG, RTC_CNTL_IO_MUX_RESET_DISABLE); + REG_CLR_BIT(RTC_CNTL_USB_CONF_REG, RTC_CNTL_USB_RESET_DISABLE); + //} else + if (!usb_did_persist || !usb_persist_enabled) { + // Reset USB module + periph_ll_reset(PERIPH_USB_MODULE); + periph_ll_enable_clk_clear_rst(PERIPH_USB_MODULE); + } + + tinyusb_config_t tusb_cfg = { + .external_phy = false // In the most cases you need to use a `false` value + }; + esp_err_t err = tinyusb_driver_install(&tusb_cfg); + if (err != ESP_OK) { + tinyusb_is_initialized = false; return err; + } + xTaskCreate(usb_device_task, "usbd", 4096, NULL, configMAX_PRIORITIES - 1, NULL); + return err; } -uint8_t tinyusb_add_string_descriptor(const char * str){ - if(str == NULL || tinyusb_string_descriptor_len >= MAX_STRING_DESCRIPTORS){ - return 0; - } - uint8_t index = tinyusb_string_descriptor_len; - tinyusb_string_descriptor[tinyusb_string_descriptor_len++] = (char*)str; - return index; +uint8_t tinyusb_add_string_descriptor(const char *str) { + if (str == NULL || tinyusb_string_descriptor_len >= MAX_STRING_DESCRIPTORS) { + return 0; + } + uint8_t index = tinyusb_string_descriptor_len; + tinyusb_string_descriptor[tinyusb_string_descriptor_len++] = (char *)str; + return index; } -uint8_t tinyusb_get_free_duplex_endpoint(void){ - if(!tinyusb_has_available_fifos()){ - log_e("No available IN endpoints"); - return 0; - } - for(uint8_t i=1; i<7; i++){ - if((tinyusb_endpoints.in & BIT(i)) == 0 && (tinyusb_endpoints.out & BIT(i)) == 0){ - tinyusb_endpoints.in |= BIT(i); - tinyusb_endpoints.out |= BIT(i); - return i; - } - } - log_e("No available duplex endpoints"); +uint8_t tinyusb_get_free_duplex_endpoint(void) { + if (!tinyusb_has_available_fifos()) { + log_e("No available IN endpoints"); return 0; + } + for (uint8_t i = 1; i < 7; i++) { + if ((tinyusb_endpoints.in & BIT(i)) == 0 && (tinyusb_endpoints.out & BIT(i)) == 0) { + tinyusb_endpoints.in |= BIT(i); + tinyusb_endpoints.out |= BIT(i); + return i; + } + } + log_e("No available duplex endpoints"); + return 0; } -uint8_t tinyusb_get_free_in_endpoint(void){ - if(!tinyusb_has_available_fifos()){ - log_e("No available IN endpoints"); - return 0; - } - for(uint8_t i=1; i<7; i++){ - if((tinyusb_endpoints.in & BIT(i)) == 0 && (tinyusb_endpoints.out & BIT(i)) != 0){ - tinyusb_endpoints.in |= BIT(i); - return i; - } - } - for(uint8_t i=1; i<7; i++){ - if((tinyusb_endpoints.in & BIT(i)) == 0){ - tinyusb_endpoints.in |= BIT(i); - return i; - } - } +uint8_t tinyusb_get_free_in_endpoint(void) { + if (!tinyusb_has_available_fifos()) { + log_e("No available IN endpoints"); return 0; + } + for (uint8_t i = 1; i < 7; i++) { + if ((tinyusb_endpoints.in & BIT(i)) == 0 && (tinyusb_endpoints.out & BIT(i)) != 0) { + tinyusb_endpoints.in |= BIT(i); + return i; + } + } + for (uint8_t i = 1; i < 7; i++) { + if ((tinyusb_endpoints.in & BIT(i)) == 0) { + tinyusb_endpoints.in |= BIT(i); + return i; + } + } + return 0; } -uint8_t tinyusb_get_free_out_endpoint(void){ - for(uint8_t i=1; i<7; i++){ - if((tinyusb_endpoints.out & BIT(i)) == 0 && (tinyusb_endpoints.in & BIT(i)) != 0){ - tinyusb_endpoints.out |= BIT(i); - return i; - } +uint8_t tinyusb_get_free_out_endpoint(void) { + for (uint8_t i = 1; i < 7; i++) { + if ((tinyusb_endpoints.out & BIT(i)) == 0 && (tinyusb_endpoints.in & BIT(i)) != 0) { + tinyusb_endpoints.out |= BIT(i); + return i; } - for(uint8_t i=1; i<7; i++){ - if((tinyusb_endpoints.out & BIT(i)) == 0){ - tinyusb_endpoints.out |= BIT(i); - return i; - } + } + for (uint8_t i = 1; i < 7; i++) { + if ((tinyusb_endpoints.out & BIT(i)) == 0) { + tinyusb_endpoints.out |= BIT(i); + return i; } - return 0; + } + return 0; } #endif /* CONFIG_TINYUSB_ENABLED */ diff --git a/cores/esp32/esp32-hal-tinyusb.h b/cores/esp32/esp32-hal-tinyusb.h index 84b635b85d6..de86642e70f 100644 --- a/cores/esp32/esp32-hal-tinyusb.h +++ b/cores/esp32/esp32-hal-tinyusb.h @@ -31,59 +31,60 @@ extern "C" { #define USB_ESPRESSIF_VID 0x303A #define USB_STRING_DESCRIPTOR_ARRAY_SIZE 10 -typedef struct { - uint16_t vid; - uint16_t pid; - const char * product_name; - const char * manufacturer_name; - const char * serial_number; - uint16_t fw_version; - - uint16_t usb_version; - uint8_t usb_class; - uint8_t usb_subclass; - uint8_t usb_protocol; - uint8_t usb_attributes; - uint16_t usb_power_ma; - - bool webusb_enabled; - const char * webusb_url; -} tinyusb_device_config_t; - -#define TINYUSB_CONFIG_DEFAULT() { \ - .vid = USB_ESPRESSIF_VID, \ - .pid = 0x0002, \ - .product_name = CONFIG_TINYUSB_DESC_PRODUCT_STRING, \ - .manufacturer_name = CONFIG_TINYUSB_DESC_MANUFACTURER_STRING, \ - .serial_number = CONFIG_TINYUSB_DESC_SERIAL_STRING, \ - .fw_version = CONFIG_TINYUSB_DESC_BCDDEVICE, \ - .usb_version = 0x0200, \ - .usb_class = TUSB_CLASS_MISC, \ - .usb_subclass = MISC_SUBCLASS_COMMON, \ - .usb_protocol = MISC_PROTOCOL_IAD, \ - .usb_attributes = TUSB_DESC_CONFIG_ATT_SELF_POWERED, \ - .usb_power_ma = 500, \ - .webusb_enabled = false, \ - .webusb_url = "espressif.github.io/arduino-esp32/webusb.html" \ -} - -esp_err_t tinyusb_init(tinyusb_device_config_t *config); - -/* + typedef struct { + uint16_t vid; + uint16_t pid; + const char *product_name; + const char *manufacturer_name; + const char *serial_number; + uint16_t fw_version; + + uint16_t usb_version; + uint8_t usb_class; + uint8_t usb_subclass; + uint8_t usb_protocol; + uint8_t usb_attributes; + uint16_t usb_power_ma; + + bool webusb_enabled; + const char *webusb_url; + } tinyusb_device_config_t; + +#define TINYUSB_CONFIG_DEFAULT() \ + { \ + .vid = USB_ESPRESSIF_VID, \ + .pid = 0x0002, \ + .product_name = CONFIG_TINYUSB_DESC_PRODUCT_STRING, \ + .manufacturer_name = CONFIG_TINYUSB_DESC_MANUFACTURER_STRING, \ + .serial_number = CONFIG_TINYUSB_DESC_SERIAL_STRING, \ + .fw_version = CONFIG_TINYUSB_DESC_BCDDEVICE, \ + .usb_version = 0x0200, \ + .usb_class = TUSB_CLASS_MISC, \ + .usb_subclass = MISC_SUBCLASS_COMMON, \ + .usb_protocol = MISC_PROTOCOL_IAD, \ + .usb_attributes = TUSB_DESC_CONFIG_ATT_SELF_POWERED, \ + .usb_power_ma = 500, \ + .webusb_enabled = false, \ + .webusb_url = "espressif.github.io/arduino-esp32/webusb.html" \ + } + + esp_err_t tinyusb_init(tinyusb_device_config_t *config); + + /* * USB Persistence API * */ -typedef enum { + typedef enum { RESTART_NO_PERSIST, RESTART_PERSIST, RESTART_BOOTLOADER, RESTART_BOOTLOADER_DFU, RESTART_TYPE_MAX -} restart_type_t; + } restart_type_t; -void usb_persist_restart(restart_type_t mode); + void usb_persist_restart(restart_type_t mode); -// The following definitions and functions are to be used only by the drivers -typedef enum { + // The following definitions and functions are to be used only by the drivers + typedef enum { USB_INTERFACE_MSC, USB_INTERFACE_DFU, USB_INTERFACE_HID, @@ -92,16 +93,16 @@ typedef enum { USB_INTERFACE_MIDI, USB_INTERFACE_CUSTOM, USB_INTERFACE_MAX -} tinyusb_interface_t; + } tinyusb_interface_t; -typedef uint16_t (*tinyusb_descriptor_cb_t)(uint8_t * dst, uint8_t * itf); + typedef uint16_t (*tinyusb_descriptor_cb_t)(uint8_t *dst, uint8_t *itf); -esp_err_t tinyusb_enable_interface(tinyusb_interface_t interface, uint16_t descriptor_len, tinyusb_descriptor_cb_t cb); -esp_err_t tinyusb_enable_interface2(tinyusb_interface_t interface, uint16_t descriptor_len, tinyusb_descriptor_cb_t cb, bool reserve_endpoints); -uint8_t tinyusb_add_string_descriptor(const char * str); -uint8_t tinyusb_get_free_duplex_endpoint(void); -uint8_t tinyusb_get_free_in_endpoint(void); -uint8_t tinyusb_get_free_out_endpoint(void); + esp_err_t tinyusb_enable_interface(tinyusb_interface_t interface, uint16_t descriptor_len, tinyusb_descriptor_cb_t cb); + esp_err_t tinyusb_enable_interface2(tinyusb_interface_t interface, uint16_t descriptor_len, tinyusb_descriptor_cb_t cb, bool reserve_endpoints); + uint8_t tinyusb_add_string_descriptor(const char *str); + uint8_t tinyusb_get_free_duplex_endpoint(void); + uint8_t tinyusb_get_free_in_endpoint(void); + uint8_t tinyusb_get_free_out_endpoint(void); #ifdef __cplusplus } diff --git a/cores/esp32/esp32-hal-touch.c b/cores/esp32/esp32-hal-touch.c index f64c07ce015..1052ae6d7a6 100644 --- a/cores/esp32/esp32-hal-touch.c +++ b/cores/esp32/esp32-hal-touch.c @@ -22,10 +22,10 @@ Internal Private Touch Data Structure and Functions */ -#if SOC_TOUCH_VERSION_1 // ESP32 +#if SOC_TOUCH_VERSION_1 // ESP32 static uint16_t __touchSleepCycles = 0x1000; static uint16_t __touchMeasureCycles = 0x1000; -#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 +#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 static uint16_t __touchSleepCycles = TOUCH_PAD_SLEEP_CYCLE_DEFAULT; static uint16_t __touchMeasureCycles = TOUCH_PAD_MEASURE_CYCLE_DEFAULT; #endif @@ -34,245 +34,238 @@ typedef void (*voidFuncPtr)(void); typedef void (*voidArgFuncPtr)(void *); typedef struct { - voidFuncPtr fn; - bool callWithArgs; - void* arg; -#if SOC_TOUCH_VERSION_2 // Only for ESP32S2 and ESP32S3 - bool lastStatusIsPressed; + voidFuncPtr fn; + bool callWithArgs; + void *arg; +#if SOC_TOUCH_VERSION_2 // Only for ESP32S2 and ESP32S3 + bool lastStatusIsPressed; #endif } TouchInterruptHandle_t; -static TouchInterruptHandle_t __touchInterruptHandlers[SOC_TOUCH_SENSOR_NUM] = {0,}; +static TouchInterruptHandle_t __touchInterruptHandlers[SOC_TOUCH_SENSOR_NUM] = { + 0, +}; static uint8_t used_pads = 0; static bool initialized = false; static bool channels_initialized[SOC_TOUCH_SENSOR_NUM] = { false }; -static void ARDUINO_ISR_ATTR __touchISR(void * arg) -{ -#if SOC_TOUCH_VERSION_1 // ESP32 - uint32_t pad_intr = touch_pad_get_status(); - //clear interrupt - touch_pad_clear_status(); - // call Pad ISR User callback - for (int i = 0; i < SOC_TOUCH_SENSOR_NUM; i++) { - if ((pad_intr >> i) & 0x01) { - if(__touchInterruptHandlers[i].fn){ - // keeping backward compatibility with "void cb(void)" and with new "void cb(vooid *)" - if (__touchInterruptHandlers[i].callWithArgs) { - ((voidArgFuncPtr)__touchInterruptHandlers[i].fn)(__touchInterruptHandlers[i].arg); - } else { - __touchInterruptHandlers[i].fn(); - } - } - } - } -#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 - touch_pad_intr_mask_t evt = touch_pad_read_intr_status_mask(); - uint8_t pad_num = touch_pad_get_current_meas_channel(); - if (evt & TOUCH_PAD_INTR_MASK_ACTIVE) { - // touch has been pressed / touched - __touchInterruptHandlers[pad_num].lastStatusIsPressed = true; - } - if (evt & TOUCH_PAD_INTR_MASK_INACTIVE) { - // touch has been released / untouched - __touchInterruptHandlers[pad_num].lastStatusIsPressed = false; - } - if(__touchInterruptHandlers[pad_num].fn){ +static void ARDUINO_ISR_ATTR __touchISR(void *arg) { +#if SOC_TOUCH_VERSION_1 // ESP32 + uint32_t pad_intr = touch_pad_get_status(); + //clear interrupt + touch_pad_clear_status(); + // call Pad ISR User callback + for (int i = 0; i < SOC_TOUCH_SENSOR_NUM; i++) { + if ((pad_intr >> i) & 0x01) { + if (__touchInterruptHandlers[i].fn) { // keeping backward compatibility with "void cb(void)" and with new "void cb(vooid *)" - if (__touchInterruptHandlers[pad_num].callWithArgs) { - ((voidArgFuncPtr)__touchInterruptHandlers[pad_num].fn)(__touchInterruptHandlers[pad_num].arg); + if (__touchInterruptHandlers[i].callWithArgs) { + ((voidArgFuncPtr)__touchInterruptHandlers[i].fn)(__touchInterruptHandlers[i].arg); } else { - __touchInterruptHandlers[pad_num].fn(); + __touchInterruptHandlers[i].fn(); } + } + } + } +#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 + touch_pad_intr_mask_t evt = touch_pad_read_intr_status_mask(); + uint8_t pad_num = touch_pad_get_current_meas_channel(); + if (evt & TOUCH_PAD_INTR_MASK_ACTIVE) { + // touch has been pressed / touched + __touchInterruptHandlers[pad_num].lastStatusIsPressed = true; + } + if (evt & TOUCH_PAD_INTR_MASK_INACTIVE) { + // touch has been released / untouched + __touchInterruptHandlers[pad_num].lastStatusIsPressed = false; + } + if (__touchInterruptHandlers[pad_num].fn) { + // keeping backward compatibility with "void cb(void)" and with new "void cb(vooid *)" + if (__touchInterruptHandlers[pad_num].callWithArgs) { + ((voidArgFuncPtr)__touchInterruptHandlers[pad_num].fn)(__touchInterruptHandlers[pad_num].arg); + } else { + __touchInterruptHandlers[pad_num].fn(); } + } #endif } -static void __touchSetCycles(uint16_t measure, uint16_t sleep) -{ - __touchSleepCycles = sleep; - __touchMeasureCycles = measure; -#if SOC_TOUCH_VERSION_1 // ESP32 - touch_pad_set_measurement_clock_cycles(measure); -#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 - touch_pad_set_charge_discharge_times(measure); +static void __touchSetCycles(uint16_t measure, uint16_t sleep) { + __touchSleepCycles = sleep; + __touchMeasureCycles = measure; +#if SOC_TOUCH_VERSION_1 // ESP32 + touch_pad_set_measurement_clock_cycles(measure); +#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 + touch_pad_set_charge_discharge_times(measure); #endif - touch_pad_set_measurement_interval(sleep); + touch_pad_set_measurement_interval(sleep); } -static bool touchDetachBus(void * pin){ - int8_t pad = digitalPinToTouchChannel((int)(pin-1)); - channels_initialized[pad] = false; - used_pads--; - if (used_pads == 0) { - if (touch_pad_deinit() != ESP_OK) //deinit touch module, as no pads are used - { - log_e("Touch module deinit failed!"); - return false; - } - initialized = false; +static bool touchDetachBus(void *pin) { + int8_t pad = digitalPinToTouchChannel((int)(pin - 1)); + channels_initialized[pad] = false; + used_pads--; + if (used_pads == 0) { + if (touch_pad_deinit() != ESP_OK) //deinit touch module, as no pads are used + { + log_e("Touch module deinit failed!"); + return false; } - return true; + initialized = false; + } + return true; } -static void __touchInit() -{ - if(initialized){ - return; - } - - esp_err_t err = ESP_OK; - -#if SOC_TOUCH_VERSION_1 // ESP32 - err = touch_pad_init(); - if (err != ESP_OK) { - goto err; - } - // the next two lines will drive the touch reading values -- both will return ESP_OK - touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V); - touch_pad_set_measurement_clock_cycles(__touchMeasureCycles); - touch_pad_set_measurement_interval(__touchSleepCycles); - // Touch Sensor Timer initiated - touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); // returns ESP_OK - err = touch_pad_filter_start(10); - if (err != ESP_OK) { - goto err; - } - // keep ISR activated - it can run all together (ISR + touchRead()) - err = touch_pad_isr_register(__touchISR, NULL); - if (err != ESP_OK) { - goto err; - } - touch_pad_intr_enable(); // returns ESP_OK -#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 - err = touch_pad_init(); - if (err != ESP_OK) { - goto err; - } - // the next lines will drive the touch reading values -- all os them return ESP_OK - touch_pad_set_charge_discharge_times(__touchMeasureCycles); - touch_pad_set_measurement_interval(__touchSleepCycles); - touch_pad_set_voltage(TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD); - touch_pad_set_idle_channel_connect(TOUCH_PAD_IDLE_CH_CONNECT_DEFAULT); - touch_pad_denoise_t denoise = { - .grade = TOUCH_PAD_DENOISE_BIT4, - .cap_level = TOUCH_PAD_DENOISE_CAP_L4, - }; - touch_pad_denoise_set_config(&denoise); - touch_pad_denoise_enable(); - // Touch Sensor Timer initiated - touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); // returns ESP_OK - touch_pad_fsm_start(); // returns ESP_OK - //ISR setup moved to __touchChannelInit +static void __touchInit() { + if (initialized) { + return; + } + + esp_err_t err = ESP_OK; + +#if SOC_TOUCH_VERSION_1 // ESP32 + err = touch_pad_init(); + if (err != ESP_OK) { + goto err; + } + // the next two lines will drive the touch reading values -- both will return ESP_OK + touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V); + touch_pad_set_measurement_clock_cycles(__touchMeasureCycles); + touch_pad_set_measurement_interval(__touchSleepCycles); + // Touch Sensor Timer initiated + touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); // returns ESP_OK + err = touch_pad_filter_start(10); + if (err != ESP_OK) { + goto err; + } + // keep ISR activated - it can run all together (ISR + touchRead()) + err = touch_pad_isr_register(__touchISR, NULL); + if (err != ESP_OK) { + goto err; + } + touch_pad_intr_enable(); // returns ESP_OK +#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 + err = touch_pad_init(); + if (err != ESP_OK) { + goto err; + } + // the next lines will drive the touch reading values -- all os them return ESP_OK + touch_pad_set_charge_discharge_times(__touchMeasureCycles); + touch_pad_set_measurement_interval(__touchSleepCycles); + touch_pad_set_voltage(TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD); + touch_pad_set_idle_channel_connect(TOUCH_PAD_IDLE_CH_CONNECT_DEFAULT); + touch_pad_denoise_t denoise = { + .grade = TOUCH_PAD_DENOISE_BIT4, + .cap_level = TOUCH_PAD_DENOISE_CAP_L4, + }; + touch_pad_denoise_set_config(&denoise); + touch_pad_denoise_enable(); + // Touch Sensor Timer initiated + touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); // returns ESP_OK + touch_pad_fsm_start(); // returns ESP_OK + //ISR setup moved to __touchChannelInit #endif - initialized = true; - return; + initialized = true; + return; err: - log_e(" Touch sensor initialization error."); - initialized = false; - return; + log_e(" Touch sensor initialization error."); + initialized = false; + return; } -static void __touchChannelInit(int pad) -{ - if(channels_initialized[pad]){ - return; - } - -#if SOC_TOUCH_VERSION_1 // ESP32 - // Initial no Threshold and setup - __touchInterruptHandlers[pad].fn = NULL; - touch_pad_config(pad, SOC_TOUCH_PAD_THRESHOLD_MAX); // returns ESP_OK -#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 - // Initial no Threshold and setup - __touchInterruptHandlers[pad].fn = NULL; - touch_pad_config(pad); // returns ESP_OK - // keep ISR activated - it can run all together (ISR + touchRead()) - esp_err_t err = touch_pad_isr_register(__touchISR, NULL, TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); - if (err != ESP_OK) { - log_e(" Touch sensor initialization error."); - return; - } - touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); // returns ESP_OK +static void __touchChannelInit(int pad) { + if (channels_initialized[pad]) { + return; + } + +#if SOC_TOUCH_VERSION_1 // ESP32 + // Initial no Threshold and setup + __touchInterruptHandlers[pad].fn = NULL; + touch_pad_config(pad, SOC_TOUCH_PAD_THRESHOLD_MAX); // returns ESP_OK +#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 + // Initial no Threshold and setup + __touchInterruptHandlers[pad].fn = NULL; + touch_pad_config(pad); // returns ESP_OK + // keep ISR activated - it can run all together (ISR + touchRead()) + esp_err_t err = touch_pad_isr_register(__touchISR, NULL, TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); + if (err != ESP_OK) { + log_e(" Touch sensor initialization error."); + return; + } + touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); // returns ESP_OK #endif - channels_initialized[pad] = true; - used_pads++; - delay(20); //delay needed before reading from touch channel after config + channels_initialized[pad] = true; + used_pads++; + delay(20); //delay needed before reading from touch channel after config } -static touch_value_t __touchRead(uint8_t pin) -{ - int8_t pad = digitalPinToTouchChannel(pin); - if(pad < 0){ - log_e(" No touch pad on selected pin!"); - return 0; +static touch_value_t __touchRead(uint8_t pin) { + int8_t pad = digitalPinToTouchChannel(pin); + if (pad < 0) { + log_e(" No touch pad on selected pin!"); + return 0; + } + + if (perimanGetPinBus(pin, ESP32_BUS_TYPE_TOUCH) == NULL) { + perimanSetBusDeinit(ESP32_BUS_TYPE_TOUCH, touchDetachBus); + if (!perimanClearPinBus(pin)) { + return 0; } + __touchInit(); + __touchChannelInit(pad); - if(perimanGetPinBus(pin, ESP32_BUS_TYPE_TOUCH) == NULL){ - perimanSetBusDeinit(ESP32_BUS_TYPE_TOUCH, touchDetachBus); - if(!perimanClearPinBus(pin)){ - return 0; - } - __touchInit(); - __touchChannelInit(pad); - - if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_TOUCH, (void *)(pin+1), -1, pad)){ - touchDetachBus((void *)(pin+1)); - return 0; - } + if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_TOUCH, (void *)(pin + 1), -1, pad)) { + touchDetachBus((void *)(pin + 1)); + return 0; } + } - touch_value_t touch_value; - touch_pad_read_raw_data(pad, &touch_value); + touch_value_t touch_value; + touch_pad_read_raw_data(pad, &touch_value); - return touch_value; + return touch_value; } -static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Args, touch_value_t threshold, bool callWithArgs) -{ - int8_t pad = digitalPinToTouchChannel(pin); - if(pad < 0){ - log_e(" No touch pad on selected pin!"); - return; - } - - if (userFunc == NULL) { - // dettach ISR User Call - __touchInterruptHandlers[pad].fn = NULL; - threshold = SOC_TOUCH_PAD_THRESHOLD_MAX; // deactivate the ISR with SOC_TOUCH_PAD_THRESHOLD_MAX - } else { - // attach ISR User Call - __touchInit(); - __touchChannelInit(pad); - __touchInterruptHandlers[pad].fn = userFunc; - __touchInterruptHandlers[pad].callWithArgs = callWithArgs; - __touchInterruptHandlers[pad].arg = Args; - } - - touch_pad_set_thresh(pad, threshold); +static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Args, touch_value_t threshold, bool callWithArgs) { + int8_t pad = digitalPinToTouchChannel(pin); + if (pad < 0) { + log_e(" No touch pad on selected pin!"); + return; + } + + if (userFunc == NULL) { + // detach ISR User Call + __touchInterruptHandlers[pad].fn = NULL; + threshold = SOC_TOUCH_PAD_THRESHOLD_MAX; // deactivate the ISR with SOC_TOUCH_PAD_THRESHOLD_MAX + } else { + // attach ISR User Call + __touchInit(); + __touchChannelInit(pad); + __touchInterruptHandlers[pad].fn = userFunc; + __touchInterruptHandlers[pad].callWithArgs = callWithArgs; + __touchInterruptHandlers[pad].arg = Args; + } + + touch_pad_set_thresh(pad, threshold); } // it keeps backwards compatibility -static void __touchAttachInterrupt(uint8_t pin, void (*userFunc)(void), touch_value_t threshold) -{ - __touchConfigInterrupt(pin, userFunc, NULL, threshold, false); +static void __touchAttachInterrupt(uint8_t pin, void (*userFunc)(void), touch_value_t threshold) { + __touchConfigInterrupt(pin, userFunc, NULL, threshold, false); } // new additional version of the API with User Args -static void __touchAttachArgsInterrupt(uint8_t pin, void (*userFunc)(void), void *args, touch_value_t threshold) -{ - __touchConfigInterrupt(pin, userFunc, args, threshold, true); +static void __touchAttachArgsInterrupt(uint8_t pin, void (*userFunc)(void), void *args, touch_value_t threshold) { + __touchConfigInterrupt(pin, userFunc, args, threshold, true); } -// new additional API to dettach touch ISR -static void __touchDettachInterrupt(uint8_t pin) -{ - __touchConfigInterrupt(pin, NULL, NULL, 0, false); // userFunc as NULL acts as dettaching +// new additional API to detach touch ISR +static void __touchDettachInterrupt(uint8_t pin) { + __touchConfigInterrupt(pin, NULL, NULL, 0, false); // userFunc as NULL acts as detaching } @@ -280,59 +273,58 @@ static void __touchDettachInterrupt(uint8_t pin) External Public Touch API Functions */ -#if SOC_TOUCH_VERSION_1 // Only for ESP32 SoC +#if SOC_TOUCH_VERSION_1 // Only for ESP32 SoC void touchInterruptSetThresholdDirection(bool mustbeLower) { - if (mustbeLower) { - touch_pad_set_trigger_mode(TOUCH_TRIGGER_BELOW); - } else { - touch_pad_set_trigger_mode(TOUCH_TRIGGER_ABOVE); - } + if (mustbeLower) { + touch_pad_set_trigger_mode(TOUCH_TRIGGER_BELOW); + } else { + touch_pad_set_trigger_mode(TOUCH_TRIGGER_ABOVE); + } } -#elif SOC_TOUCH_VERSION_2 // Only for ESP32S2 and ESP32S3 -// returns true if touch pad has been and continues pressed and false otherwise +#elif SOC_TOUCH_VERSION_2 // Only for ESP32S2 and ESP32S3 +// returns true if touch pad has been and continues pressed and false otherwise bool touchInterruptGetLastStatus(uint8_t pin) { - int8_t pad = digitalPinToTouchChannel(pin); - if(pad < 0){ - return false; - } + int8_t pad = digitalPinToTouchChannel(pin); + if (pad < 0) { + return false; + } - return __touchInterruptHandlers[pad].lastStatusIsPressed; + return __touchInterruptHandlers[pad].lastStatusIsPressed; } #endif -void touchSleepWakeUpEnable(uint8_t pin, touch_value_t threshold) -{ - int8_t pad = digitalPinToTouchChannel(pin); - if(pad < 0){ - log_e(" No touch pad on selected pin!"); - return; +void touchSleepWakeUpEnable(uint8_t pin, touch_value_t threshold) { + int8_t pad = digitalPinToTouchChannel(pin); + if (pad < 0) { + log_e(" No touch pad on selected pin!"); + return; + } + + if (perimanGetPinBus(pin, ESP32_BUS_TYPE_TOUCH) == NULL) { + perimanSetBusDeinit(ESP32_BUS_TYPE_TOUCH, touchDetachBus); + __touchInit(); + __touchChannelInit(pad); + if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_TOUCH, (void *)(pin + 1), -1, pad)) { + log_e("Failed to set bus to Peripheral manager"); + touchDetachBus((void *)(pin + 1)); + return; } + } +#if SOC_TOUCH_VERSION_1 // Only for ESP32 SoC + touch_pad_set_thresh(pad, threshold); - if(perimanGetPinBus(pin, ESP32_BUS_TYPE_TOUCH) == NULL){ - perimanSetBusDeinit(ESP32_BUS_TYPE_TOUCH, touchDetachBus); - __touchInit(); - __touchChannelInit(pad); - if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_TOUCH, (void *)(pin+1), -1, pad)){ - log_e("Failed to set bus to Peripheral manager"); - touchDetachBus((void *)(pin+1)); - return; - } - } - #if SOC_TOUCH_VERSION_1 // Only for ESP32 SoC - touch_pad_set_thresh(pad, threshold); - - #elif SOC_TOUCH_VERSION_2 - touch_pad_sleep_channel_enable(pad, true); - touch_pad_sleep_set_threshold(pad, threshold); - - #endif - esp_sleep_enable_touchpad_wakeup(); +#elif SOC_TOUCH_VERSION_2 + touch_pad_sleep_channel_enable(pad, true); + touch_pad_sleep_set_threshold(pad, threshold); + +#endif + esp_sleep_enable_touchpad_wakeup(); } -extern touch_value_t touchRead(uint8_t) __attribute__ ((weak, alias("__touchRead"))); -extern void touchAttachInterrupt(uint8_t, voidFuncPtr, touch_value_t) __attribute__ ((weak, alias("__touchAttachInterrupt"))); -extern void touchAttachInterruptArg(uint8_t, voidArgFuncPtr, void *, touch_value_t) __attribute__ ((weak, alias("__touchAttachArgsInterrupt"))); -extern void touchDetachInterrupt(uint8_t) __attribute__ ((weak, alias("__touchDettachInterrupt"))); -extern void touchSetCycles(uint16_t, uint16_t) __attribute__ ((weak, alias("__touchSetCycles"))); +extern touch_value_t touchRead(uint8_t) __attribute__((weak, alias("__touchRead"))); +extern void touchAttachInterrupt(uint8_t, voidFuncPtr, touch_value_t) __attribute__((weak, alias("__touchAttachInterrupt"))); +extern void touchAttachInterruptArg(uint8_t, voidArgFuncPtr, void *, touch_value_t) __attribute__((weak, alias("__touchAttachArgsInterrupt"))); +extern void touchDetachInterrupt(uint8_t) __attribute__((weak, alias("__touchDettachInterrupt"))); +extern void touchSetCycles(uint16_t, uint16_t) __attribute__((weak, alias("__touchSetCycles"))); #endif /* SOC_TOUCH_SENSOR_SUPPORTED */ diff --git a/cores/esp32/esp32-hal-touch.h b/cores/esp32/esp32-hal-touch.h index 780b5abf3bb..627e74b57ea 100644 --- a/cores/esp32/esp32-hal-touch.h +++ b/cores/esp32/esp32-hal-touch.h @@ -33,66 +33,66 @@ extern "C" { #error Touch IDF driver Not supported! #endif -#if SOC_TOUCH_VERSION_1 // ESP32 -typedef uint16_t touch_value_t; -#elif SOC_TOUCH_VERSION_2 // ESP32S2 ESP32S3 +#if SOC_TOUCH_VERSION_1 // ESP32 + typedef uint16_t touch_value_t; +#elif SOC_TOUCH_VERSION_2 // ESP32S2 ESP32S3 typedef uint32_t touch_value_t; #endif -/* + /* * Set cycles that measurement operation takes * The result from touchRead, threshold and detection * accuracy depend on these values. Defaults are * 0x1000 for measure and 0x1000 for sleep. * With default values touchRead takes 0.5ms * */ -void touchSetCycles(uint16_t measure, uint16_t sleep); + void touchSetCycles(uint16_t measure, uint16_t sleep); -/* + /* * Read touch pad (for ESP32 values close to 0 mean touch detected / * for ESP32-S2/S3 higher values mean touch detected) * You can use this method to chose a good threshold value * to use as value for touchAttachInterrupt * */ -touch_value_t touchRead(uint8_t pin); + touch_value_t touchRead(uint8_t pin); -/* + /* * Set function to be called if touch pad value falls (ESP32) - * below the given threshold / rises (ESP32-S2/S3) by given increment (threshold). + * below the given threshold / rises (ESP32-S2/S3) by given increment (threshold). * Use touchRead to determine a proper threshold between touched and untouched state * */ -void touchAttachInterrupt(uint8_t pin, void (*userFunc)(void), touch_value_t threshold); -void touchAttachInterruptArg(uint8_t pin, void (*userFunc)(void*), void *arg, touch_value_t threshold); -void touchDetachInterrupt(uint8_t pin); + void touchAttachInterrupt(uint8_t pin, void (*userFunc)(void), touch_value_t threshold); + void touchAttachInterruptArg(uint8_t pin, void (*userFunc)(void *), void *arg, touch_value_t threshold); + void touchDetachInterrupt(uint8_t pin); -/* - * Specific functions to ESP32 + /* + * Specific functions to ESP32 * Tells the driver if it shall activate the ISR if the sensor is Lower or Higher than the Threshold * Default if Lower. **/ -#if SOC_TOUCH_VERSION_1 // Only for ESP32 SoC -void touchInterruptSetThresholdDirection(bool mustbeLower); +#if SOC_TOUCH_VERSION_1 // Only for ESP32 SoC + void touchInterruptSetThresholdDirection(bool mustbeLower); #endif -/* + /* * Specific functions to ESP32-S2 and ESP32-S3 * Returns true when the latest ISR status for the Touchpad is that it is touched (Active) * and false when the Touchpad is untoouched (Inactive) - * This function can be used in conjunction with ISR User callback in order to take action + * This function can be used in conjunction with ISR User callback in order to take action * as soon as the touchpad is touched and/or released **/ -#if SOC_TOUCH_VERSION_2 // Only for ESP32S2 and ESP32S3 -// returns true if touch pad has been and continues pressed and false otherwise -bool touchInterruptGetLastStatus(uint8_t pin); +#if SOC_TOUCH_VERSION_2 // Only for ESP32S2 and ESP32S3 + // returns true if touch pad has been and continues pressed and false otherwise + bool touchInterruptGetLastStatus(uint8_t pin); #endif -/* + /* * Setup touch pad wake up from deep sleep with given threshold. **/ -void touchSleepWakeUpEnable(uint8_t pin, touch_value_t threshold); + void touchSleepWakeUpEnable(uint8_t pin, touch_value_t threshold); #ifdef __cplusplus } diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index cbb454645d5..39522fea5fb 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -33,25 +33,25 @@ #include "hal/gpio_hal.h" #include "esp_rom_gpio.h" -static int s_uart_debug_nr = 0; // UART number for debug output +static int s_uart_debug_nr = 0; // UART number for debug output struct uart_struct_t { #if !CONFIG_DISABLE_HAL_LOCKS - SemaphoreHandle_t lock; // UART lock + SemaphoreHandle_t lock; // UART lock #endif - uint8_t num; // UART number for IDF driver API - bool has_peek; // flag to indicate that there is a peek byte pending to be read - uint8_t peek_byte; // peek byte that has been read but not consumed - QueueHandle_t uart_event_queue; // export it by some uartGetEventQueue() function - // configuration data:: Arduino API tipical data - int8_t _rxPin, _txPin, _ctsPin, _rtsPin; // UART GPIOs - uint32_t _baudrate, _config; // UART baudrate and config - // UART ESP32 specific data - uint16_t _rx_buffer_size, _tx_buffer_size; // UART RX and TX buffer sizes - bool _inverted; // UART inverted signal - uint8_t _rxfifo_full_thrhd; // UART RX FIFO full threshold + uint8_t num; // UART number for IDF driver API + bool has_peek; // flag to indicate that there is a peek byte pending to be read + uint8_t peek_byte; // peek byte that has been read but not consumed + QueueHandle_t uart_event_queue; // export it by some uartGetEventQueue() function + // configuration data:: Arduino API tipical data + int8_t _rxPin, _txPin, _ctsPin, _rtsPin; // UART GPIOs + uint32_t _baudrate, _config; // UART baudrate and config + // UART ESP32 specific data + uint16_t _rx_buffer_size, _tx_buffer_size; // UART RX and TX buffer sizes + bool _inverted; // UART inverted signal + uint8_t _rxfifo_full_thrhd; // UART RX FIFO full threshold }; #if CONFIG_DISABLE_HAL_LOCKS @@ -60,27 +60,30 @@ struct uart_struct_t { #define UART_MUTEX_UNLOCK() static uart_t _uart_bus_array[] = { - {0, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + { 0, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0 }, #if SOC_UART_NUM > 1 - {1, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + { 1, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0 }, #endif #if SOC_UART_NUM > 2 - {2, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + { 2, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0 }, #endif }; #else -#define UART_MUTEX_LOCK() if(uart->lock != NULL) do {} while (xSemaphoreTake(uart->lock, portMAX_DELAY) != pdPASS) -#define UART_MUTEX_UNLOCK() if(uart->lock != NULL) xSemaphoreGive(uart->lock) +#define UART_MUTEX_LOCK() \ + if (uart->lock != NULL) do { \ + } while (xSemaphoreTake(uart->lock, portMAX_DELAY) != pdPASS) +#define UART_MUTEX_UNLOCK() \ + if (uart->lock != NULL) xSemaphoreGive(uart->lock) static uart_t _uart_bus_array[] = { - {NULL, 0, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + { NULL, 0, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0 }, #if SOC_UART_NUM > 1 - {NULL, 1, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + { NULL, 1, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0 }, #endif #if SOC_UART_NUM > 2 - {NULL, 2, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + { NULL, 2, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0 }, #endif }; @@ -88,803 +91,769 @@ static uart_t _uart_bus_array[] = { // Negative Pin Number will keep it unmodified, thus this function can detach individual pins // This function will also unset the pins in the Peripheral Manager and set the pin to -1 after detaching -static bool _uartDetachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) -{ - if(uart_num >= SOC_UART_NUM) { - log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1); - return false; - } - // get UART information - uart_t* uart = &_uart_bus_array[uart_num]; - bool retCode = true; - //log_v("detaching UART%d pins: prev,pin RX(%d,%d) TX(%d,%d) CTS(%d,%d) RTS(%d,%d)", uart_num, - // uart->_rxPin, rxPin, uart->_txPin, txPin, uart->_ctsPin, ctsPin, uart->_rtsPin, rtsPin); vTaskDelay(10); - - // detaches pins and sets Peripheral Manager and UART information - if (rxPin >= 0 && uart->_rxPin == rxPin && perimanGetPinBusType(rxPin) == ESP32_BUS_TYPE_UART_RX) { - gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[rxPin], PIN_FUNC_GPIO); - // avoids causing BREAK in the UART line - if (uart->_inverted) { - esp_rom_gpio_connect_in_signal(GPIO_FUNC_IN_LOW, UART_PERIPH_SIGNAL(uart_num, SOC_UART_RX_PIN_IDX), false); - } else { - esp_rom_gpio_connect_in_signal(GPIO_FUNC_IN_HIGH, UART_PERIPH_SIGNAL(uart_num, SOC_UART_RX_PIN_IDX), false); - } - uart->_rxPin = -1; // -1 means unassigned/detached - if (!perimanClearPinBus(rxPin)) { - retCode = false; - log_e("UART%d failed to detach RX pin %d", uart_num, rxPin); - } - } - if (txPin >= 0 && uart->_txPin == txPin && perimanGetPinBusType(txPin) == ESP32_BUS_TYPE_UART_TX) { - gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[txPin], PIN_FUNC_GPIO); - esp_rom_gpio_connect_out_signal(txPin, SIG_GPIO_OUT_IDX, false, false); - uart->_txPin = -1; // -1 means unassigned/detached - if (!perimanClearPinBus(txPin)) { - retCode = false; - log_e("UART%d failed to detach TX pin %d", uart_num, txPin); - } - } - if (ctsPin >= 0 && uart->_ctsPin == ctsPin && perimanGetPinBusType(ctsPin) == ESP32_BUS_TYPE_UART_CTS) { - gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[ctsPin], PIN_FUNC_GPIO); - esp_rom_gpio_connect_in_signal(GPIO_FUNC_IN_LOW, UART_PERIPH_SIGNAL(uart_num, SOC_UART_CTS_PIN_IDX), false); - uart->_ctsPin = -1; // -1 means unassigned/detached - if (!perimanClearPinBus(ctsPin)) { - retCode = false; - log_e("UART%d failed to detach CTS pin %d", uart_num, ctsPin); - } - } - if (rtsPin >= 0 && uart->_rtsPin == rtsPin && perimanGetPinBusType(rtsPin) == ESP32_BUS_TYPE_UART_RTS) { - gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[rtsPin], PIN_FUNC_GPIO); - esp_rom_gpio_connect_out_signal(rtsPin, SIG_GPIO_OUT_IDX, false, false); - uart->_rtsPin = -1; // -1 means unassigned/detached - if (!perimanClearPinBus(rtsPin)) { - retCode = false; - log_e("UART%d failed to detach RTS pin %d", uart_num, rtsPin); - } - } - return retCode; +static bool _uartDetachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) { + if (uart_num >= SOC_UART_NUM) { + log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1); + return false; + } + // get UART information + uart_t* uart = &_uart_bus_array[uart_num]; + bool retCode = true; + //log_v("detaching UART%d pins: prev,pin RX(%d,%d) TX(%d,%d) CTS(%d,%d) RTS(%d,%d)", uart_num, + // uart->_rxPin, rxPin, uart->_txPin, txPin, uart->_ctsPin, ctsPin, uart->_rtsPin, rtsPin); vTaskDelay(10); + + // detaches pins and sets Peripheral Manager and UART information + if (rxPin >= 0 && uart->_rxPin == rxPin && perimanGetPinBusType(rxPin) == ESP32_BUS_TYPE_UART_RX) { + gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[rxPin], PIN_FUNC_GPIO); + // avoids causing BREAK in the UART line + if (uart->_inverted) { + esp_rom_gpio_connect_in_signal(GPIO_FUNC_IN_LOW, UART_PERIPH_SIGNAL(uart_num, SOC_UART_RX_PIN_IDX), false); + } else { + esp_rom_gpio_connect_in_signal(GPIO_FUNC_IN_HIGH, UART_PERIPH_SIGNAL(uart_num, SOC_UART_RX_PIN_IDX), false); + } + uart->_rxPin = -1; // -1 means unassigned/detached + if (!perimanClearPinBus(rxPin)) { + retCode = false; + log_e("UART%d failed to detach RX pin %d", uart_num, rxPin); + } + } + if (txPin >= 0 && uart->_txPin == txPin && perimanGetPinBusType(txPin) == ESP32_BUS_TYPE_UART_TX) { + gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[txPin], PIN_FUNC_GPIO); + esp_rom_gpio_connect_out_signal(txPin, SIG_GPIO_OUT_IDX, false, false); + uart->_txPin = -1; // -1 means unassigned/detached + if (!perimanClearPinBus(txPin)) { + retCode = false; + log_e("UART%d failed to detach TX pin %d", uart_num, txPin); + } + } + if (ctsPin >= 0 && uart->_ctsPin == ctsPin && perimanGetPinBusType(ctsPin) == ESP32_BUS_TYPE_UART_CTS) { + gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[ctsPin], PIN_FUNC_GPIO); + esp_rom_gpio_connect_in_signal(GPIO_FUNC_IN_LOW, UART_PERIPH_SIGNAL(uart_num, SOC_UART_CTS_PIN_IDX), false); + uart->_ctsPin = -1; // -1 means unassigned/detached + if (!perimanClearPinBus(ctsPin)) { + retCode = false; + log_e("UART%d failed to detach CTS pin %d", uart_num, ctsPin); + } + } + if (rtsPin >= 0 && uart->_rtsPin == rtsPin && perimanGetPinBusType(rtsPin) == ESP32_BUS_TYPE_UART_RTS) { + gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[rtsPin], PIN_FUNC_GPIO); + esp_rom_gpio_connect_out_signal(rtsPin, SIG_GPIO_OUT_IDX, false, false); + uart->_rtsPin = -1; // -1 means unassigned/detached + if (!perimanClearPinBus(rtsPin)) { + retCode = false; + log_e("UART%d failed to detach RTS pin %d", uart_num, rtsPin); + } + } + return retCode; } // Peripheral Manager detach callback for each specific UART PIN -static bool _uartDetachBus_RX(void *busptr) -{ +static bool _uartDetachBus_RX(void* busptr) { // sanity check - it should never happen assert(busptr && "_uartDetachBus_RX bus NULL pointer."); - uart_t* bus = (uart_t*) busptr; + uart_t* bus = (uart_t*)busptr; return _uartDetachPins(bus->num, bus->_rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); } -static bool _uartDetachBus_TX(void *busptr) -{ +static bool _uartDetachBus_TX(void* busptr) { // sanity check - it should never happen assert(busptr && "_uartDetachBus_TX bus NULL pointer."); - uart_t* bus = (uart_t*) busptr; + uart_t* bus = (uart_t*)busptr; return _uartDetachPins(bus->num, UART_PIN_NO_CHANGE, bus->_txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); } -static bool _uartDetachBus_CTS(void *busptr) -{ +static bool _uartDetachBus_CTS(void* busptr) { // sanity check - it should never happen assert(busptr && "_uartDetachBus_CTS bus NULL pointer."); - uart_t* bus = (uart_t*) busptr; + uart_t* bus = (uart_t*)busptr; return _uartDetachPins(bus->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, bus->_ctsPin, UART_PIN_NO_CHANGE); } -static bool _uartDetachBus_RTS(void *busptr) -{ +static bool _uartDetachBus_RTS(void* busptr) { // sanity check - it should never happen assert(busptr && "_uartDetachBus_RTS bus NULL pointer."); - uart_t* bus = (uart_t*) busptr; + uart_t* bus = (uart_t*)busptr; return _uartDetachPins(bus->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, bus->_rtsPin); } -// Attach function for UART +// Attach function for UART // connects the IO Pad, set Paripheral Manager and internal UART structure data -static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) -{ - if(uart_num >= SOC_UART_NUM) { - log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1); - return false; - } - // get UART information - uart_t* uart = &_uart_bus_array[uart_num]; - //log_v("attaching UART%d pins: prev,new RX(%d,%d) TX(%d,%d) CTS(%d,%d) RTS(%d,%d)", uart_num, - // uart->_rxPin, rxPin, uart->_txPin, txPin, uart->_ctsPin, ctsPin, uart->_rtsPin, rtsPin); vTaskDelay(10); - - - bool retCode = true; - if (rxPin >= 0) { - // forces a clean detaching from a previous peripheral - if (perimanGetPinBusType(rxPin) != ESP32_BUS_TYPE_INIT) perimanClearPinBus(rxPin); - // connect RX Pad - bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - if (ret) { - ret &= perimanSetPinBus(rxPin, ESP32_BUS_TYPE_UART_RX, (void *)uart, uart_num, -1); - if (ret) uart->_rxPin = rxPin; - } - if (!ret) { - log_e("UART%d failed to attach RX pin %d", uart_num, rxPin); - } - retCode &= ret; - } - if (txPin >= 0) { - // forces a clean detaching from a previous peripheral - if (perimanGetPinBusType(txPin) != ESP32_BUS_TYPE_INIT) perimanClearPinBus(txPin); - // connect TX Pad - bool ret = ESP_OK == uart_set_pin(uart->num, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - if (ret) { - ret &= perimanSetPinBus(txPin, ESP32_BUS_TYPE_UART_TX, (void *)uart, uart_num, -1); - if (ret) uart->_txPin = txPin; - } - if (!ret) { - log_e("UART%d failed to attach TX pin %d", uart_num, txPin); - } - retCode &= ret; - } - if (ctsPin >= 0) { - // forces a clean detaching from a previous peripheral - if (perimanGetPinBusType(ctsPin) != ESP32_BUS_TYPE_INIT) perimanClearPinBus(ctsPin); - // connect CTS Pad - bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, ctsPin); - if (ret) { - ret &= perimanSetPinBus(ctsPin, ESP32_BUS_TYPE_UART_CTS, (void *)uart, uart_num, -1); - if (ret) uart->_ctsPin = ctsPin; - } - if (!ret) { - log_e("UART%d failed to attach CTS pin %d", uart_num, ctsPin); - } - retCode &= ret; - } - if (rtsPin >= 0) { - // forces a clean detaching from a previous peripheral - if (perimanGetPinBusType(rtsPin) != ESP32_BUS_TYPE_INIT) perimanClearPinBus(rtsPin); - // connect RTS Pad - bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, rtsPin, UART_PIN_NO_CHANGE); - if (ret) { - ret &= perimanSetPinBus(rtsPin, ESP32_BUS_TYPE_UART_RTS, (void *)uart, uart_num, -1); - if (ret) uart->_rtsPin = rtsPin; - } - if (!ret) { - log_e("UART%d failed to attach RTS pin %d", uart_num, rtsPin); - } - retCode &= ret; - } - return retCode; +static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) { + if (uart_num >= SOC_UART_NUM) { + log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1); + return false; + } + // get UART information + uart_t* uart = &_uart_bus_array[uart_num]; + //log_v("attaching UART%d pins: prev,new RX(%d,%d) TX(%d,%d) CTS(%d,%d) RTS(%d,%d)", uart_num, + // uart->_rxPin, rxPin, uart->_txPin, txPin, uart->_ctsPin, ctsPin, uart->_rtsPin, rtsPin); vTaskDelay(10); + + + bool retCode = true; + if (rxPin >= 0) { + // forces a clean detaching from a previous peripheral + if (perimanGetPinBusType(rxPin) != ESP32_BUS_TYPE_INIT) perimanClearPinBus(rxPin); + // connect RX Pad + bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + if (ret) { + ret &= perimanSetPinBus(rxPin, ESP32_BUS_TYPE_UART_RX, (void*)uart, uart_num, -1); + if (ret) uart->_rxPin = rxPin; + } + if (!ret) { + log_e("UART%d failed to attach RX pin %d", uart_num, rxPin); + } + retCode &= ret; + } + if (txPin >= 0) { + // forces a clean detaching from a previous peripheral + if (perimanGetPinBusType(txPin) != ESP32_BUS_TYPE_INIT) perimanClearPinBus(txPin); + // connect TX Pad + bool ret = ESP_OK == uart_set_pin(uart->num, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + if (ret) { + ret &= perimanSetPinBus(txPin, ESP32_BUS_TYPE_UART_TX, (void*)uart, uart_num, -1); + if (ret) uart->_txPin = txPin; + } + if (!ret) { + log_e("UART%d failed to attach TX pin %d", uart_num, txPin); + } + retCode &= ret; + } + if (ctsPin >= 0) { + // forces a clean detaching from a previous peripheral + if (perimanGetPinBusType(ctsPin) != ESP32_BUS_TYPE_INIT) perimanClearPinBus(ctsPin); + // connect CTS Pad + bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, ctsPin); + if (ret) { + ret &= perimanSetPinBus(ctsPin, ESP32_BUS_TYPE_UART_CTS, (void*)uart, uart_num, -1); + if (ret) uart->_ctsPin = ctsPin; + } + if (!ret) { + log_e("UART%d failed to attach CTS pin %d", uart_num, ctsPin); + } + retCode &= ret; + } + if (rtsPin >= 0) { + // forces a clean detaching from a previous peripheral + if (perimanGetPinBusType(rtsPin) != ESP32_BUS_TYPE_INIT) perimanClearPinBus(rtsPin); + // connect RTS Pad + bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, rtsPin, UART_PIN_NO_CHANGE); + if (ret) { + ret &= perimanSetPinBus(rtsPin, ESP32_BUS_TYPE_UART_RTS, (void*)uart, uart_num, -1); + if (ret) uart->_rtsPin = rtsPin; + } + if (!ret) { + log_e("UART%d failed to attach RTS pin %d", uart_num, rtsPin); + } + retCode &= ret; + } + return retCode; } // just helper functions -int8_t uart_get_RxPin(uint8_t uart_num) -{ - return _uart_bus_array[uart_num]._rxPin; +int8_t uart_get_RxPin(uint8_t uart_num) { + return _uart_bus_array[uart_num]._rxPin; } -int8_t uart_get_TxPin(uint8_t uart_num) -{ - return _uart_bus_array[uart_num]._txPin; +int8_t uart_get_TxPin(uint8_t uart_num) { + return _uart_bus_array[uart_num]._txPin; } -void uart_init_PeriMan(void) -{ - // set Peripheral Manager deInit Callback for each UART pin - perimanSetBusDeinit(ESP32_BUS_TYPE_UART_RX, _uartDetachBus_RX); - perimanSetBusDeinit(ESP32_BUS_TYPE_UART_TX, _uartDetachBus_TX); - perimanSetBusDeinit(ESP32_BUS_TYPE_UART_CTS, _uartDetachBus_CTS); - perimanSetBusDeinit(ESP32_BUS_TYPE_UART_RTS, _uartDetachBus_RTS); +void uart_init_PeriMan(void) { + // set Peripheral Manager deInit Callback for each UART pin + perimanSetBusDeinit(ESP32_BUS_TYPE_UART_RX, _uartDetachBus_RX); + perimanSetBusDeinit(ESP32_BUS_TYPE_UART_TX, _uartDetachBus_TX); + perimanSetBusDeinit(ESP32_BUS_TYPE_UART_CTS, _uartDetachBus_CTS); + perimanSetBusDeinit(ESP32_BUS_TYPE_UART_RTS, _uartDetachBus_RTS); } // Routines that take care of UART events will be in the HardwareSerial Class code -void uartGetEventQueue(uart_t* uart, QueueHandle_t *q) -{ - // passing back NULL for the Queue pointer when UART is not initialized yet - *q = NULL; - if(uart == NULL) { - return; - } - *q = uart->uart_event_queue; +void uartGetEventQueue(uart_t* uart, QueueHandle_t* q) { + // passing back NULL for the Queue pointer when UART is not initialized yet + *q = NULL; + if (uart == NULL) { return; + } + *q = uart->uart_event_queue; + return; } -bool uartIsDriverInstalled(uart_t* uart) -{ - if(uart == NULL) { - return false; - } - - if (uart_is_driver_installed(uart->num)) { - return true; - } +bool uartIsDriverInstalled(uart_t* uart) { + if (uart == NULL) { return false; + } + + if (uart_is_driver_installed(uart->num)) { + return true; + } + return false; } // Negative Pin Number will keep it unmodified, thus this function can set individual pins // When pins are changed, it will detach the previous one -bool uartSetPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) -{ - if(uart_num >= SOC_UART_NUM) { - log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1); - return false; - } - // get UART information - uart_t* uart = &_uart_bus_array[uart_num]; - - bool retCode = true; - UART_MUTEX_LOCK(); - - //log_v("setting UART%d pins: prev->new RX(%d->%d) TX(%d->%d) CTS(%d->%d) RTS(%d->%d)", uart_num, - // uart->_rxPin, rxPin, uart->_txPin, txPin, uart->_ctsPin, ctsPin, uart->_rtsPin, rtsPin); vTaskDelay(10); - - // First step: detachs all previous UART pins - bool rxPinChanged = rxPin >= 0 && rxPin != uart->_rxPin; - if (rxPinChanged) { - retCode &= _uartDetachPins(uart_num, uart->_rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - } - bool txPinChanged = txPin >= 0 && txPin != uart->_txPin; - if (txPinChanged) { - retCode &= _uartDetachPins(uart_num, UART_PIN_NO_CHANGE, uart->_txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - } - bool ctsPinChanged = ctsPin >= 0 && ctsPin != uart->_ctsPin; - if (ctsPinChanged) { - retCode &= _uartDetachPins(uart_num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, uart->_ctsPin, UART_PIN_NO_CHANGE); - } - bool rtsPinChanged = rtsPin >= 0 && rtsPin != uart->_rtsPin; - if (rtsPinChanged) { - retCode &= _uartDetachPins(uart_num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, uart->_rtsPin); - } - - // Second step: attach all UART new pins - if (rxPinChanged) { - retCode &= _uartAttachPins(uart_num, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - } - if (txPinChanged) { - retCode &= _uartAttachPins(uart_num, UART_PIN_NO_CHANGE, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - } - if (ctsPinChanged) { - retCode &= _uartAttachPins(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, ctsPin, UART_PIN_NO_CHANGE); - } - if (rtsPinChanged) { - retCode &= _uartAttachPins(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, rtsPin); - } - UART_MUTEX_UNLOCK(); - - if (!retCode) { - log_e("UART%d set pins failed.", uart_num); - } - return retCode; +bool uartSetPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) { + if (uart_num >= SOC_UART_NUM) { + log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1); + return false; + } + // get UART information + uart_t* uart = &_uart_bus_array[uart_num]; + + bool retCode = true; + UART_MUTEX_LOCK(); + + //log_v("setting UART%d pins: prev->new RX(%d->%d) TX(%d->%d) CTS(%d->%d) RTS(%d->%d)", uart_num, + // uart->_rxPin, rxPin, uart->_txPin, txPin, uart->_ctsPin, ctsPin, uart->_rtsPin, rtsPin); vTaskDelay(10); + + // First step: detaches all previous UART pins + bool rxPinChanged = rxPin >= 0 && rxPin != uart->_rxPin; + if (rxPinChanged) { + retCode &= _uartDetachPins(uart_num, uart->_rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + } + bool txPinChanged = txPin >= 0 && txPin != uart->_txPin; + if (txPinChanged) { + retCode &= _uartDetachPins(uart_num, UART_PIN_NO_CHANGE, uart->_txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + } + bool ctsPinChanged = ctsPin >= 0 && ctsPin != uart->_ctsPin; + if (ctsPinChanged) { + retCode &= _uartDetachPins(uart_num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, uart->_ctsPin, UART_PIN_NO_CHANGE); + } + bool rtsPinChanged = rtsPin >= 0 && rtsPin != uart->_rtsPin; + if (rtsPinChanged) { + retCode &= _uartDetachPins(uart_num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, uart->_rtsPin); + } + + // Second step: attach all UART new pins + if (rxPinChanged) { + retCode &= _uartAttachPins(uart_num, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + } + if (txPinChanged) { + retCode &= _uartAttachPins(uart_num, UART_PIN_NO_CHANGE, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + } + if (ctsPinChanged) { + retCode &= _uartAttachPins(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, ctsPin, UART_PIN_NO_CHANGE); + } + if (rtsPinChanged) { + retCode &= _uartAttachPins(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, rtsPin); + } + UART_MUTEX_UNLOCK(); + + if (!retCode) { + log_e("UART%d set pins failed.", uart_num); + } + return retCode; } -// -bool uartSetHwFlowCtrlMode(uart_t *uart, uart_hw_flowcontrol_t mode, uint8_t threshold) { - if(uart == NULL) { - return false; - } - // IDF will issue corresponding error message when mode or threshold are wrong and prevent crashing - // IDF will check (mode > HW_FLOWCTRL_CTS_RTS || threshold >= SOC_UART_FIFO_LEN) - UART_MUTEX_LOCK(); - bool retCode = (ESP_OK == uart_set_hw_flow_ctrl(uart->num, mode, threshold)); - UART_MUTEX_UNLOCK(); - return retCode; +// +bool uartSetHwFlowCtrlMode(uart_t* uart, uart_hw_flowcontrol_t mode, uint8_t threshold) { + if (uart == NULL) { + return false; + } + // IDF will issue corresponding error message when mode or threshold are wrong and prevent crashing + // IDF will check (mode > HW_FLOWCTRL_CTS_RTS || threshold >= SOC_UART_FIFO_LEN) + UART_MUTEX_LOCK(); + bool retCode = (ESP_OK == uart_set_hw_flow_ctrl(uart->num, mode, threshold)); + UART_MUTEX_UNLOCK(); + return retCode; } // This helper function will return true if a new IDF UART driver needs to be restarted and false if the current one can continue its execution -bool _testUartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd) -{ - if(uart_nr >= SOC_UART_NUM) { - return false; // no new driver has to be installed - } - uart_t* uart = &_uart_bus_array[uart_nr]; - // verify if is necessary to restart the UART driver - if (uart_is_driver_installed(uart_nr)) { - // some parameters can't be changed unless we end the UART driver - if ( uart->_rx_buffer_size != rx_buffer_size || uart->_tx_buffer_size != tx_buffer_size || uart->_inverted != inverted || uart->_rxfifo_full_thrhd != rxfifo_full_thrhd) { - return true; // the current IDF UART driver must be terminated and a new driver shall be installed - } else { - return false; // The current IDF UART driver can continue its execution - } +bool _testUartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd) { + if (uart_nr >= SOC_UART_NUM) { + return false; // no new driver has to be installed + } + uart_t* uart = &_uart_bus_array[uart_nr]; + // verify if is necessary to restart the UART driver + if (uart_is_driver_installed(uart_nr)) { + // some parameters can't be changed unless we end the UART driver + if (uart->_rx_buffer_size != rx_buffer_size || uart->_tx_buffer_size != tx_buffer_size || uart->_inverted != inverted || uart->_rxfifo_full_thrhd != rxfifo_full_thrhd) { + return true; // the current IDF UART driver must be terminated and a new driver shall be installed } else { - return true; // no IDF UART driver is running and a new driver shall be installed + return false; // The current IDF UART driver can continue its execution } + } else { + return true; // no IDF UART driver is running and a new driver shall be installed + } } -uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd) -{ - if(uart_nr >= SOC_UART_NUM) { - log_e("UART number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1); - return NULL; // no new driver was installed - } - uart_t* uart = &_uart_bus_array[uart_nr]; - log_v("UART%d baud(%ld) Mode(%x) rxPin(%d) txPin(%d)", uart_nr, baudrate, config, rxPin, txPin); +uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd) { + if (uart_nr >= SOC_UART_NUM) { + log_e("UART number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1); + return NULL; // no new driver was installed + } + uart_t* uart = &_uart_bus_array[uart_nr]; + log_v("UART%d baud(%ld) Mode(%x) rxPin(%d) txPin(%d)", uart_nr, baudrate, config, rxPin, txPin); #if !CONFIG_DISABLE_HAL_LOCKS - if(uart->lock == NULL) { - uart->lock = xSemaphoreCreateMutex(); - if(uart->lock == NULL) { - log_e("HAL LOCK error."); - return NULL; // no new driver was installed - } + if (uart->lock == NULL) { + uart->lock = xSemaphoreCreateMutex(); + if (uart->lock == NULL) { + log_e("HAL LOCK error."); + return NULL; // no new driver was installed } + } #endif - if (uart_is_driver_installed(uart_nr)) { - log_v("UART%d Driver already installed.", uart_nr); - // some parameters can't be changed unless we end the UART driver - if ( uart->_rx_buffer_size != rx_buffer_size || uart->_tx_buffer_size != tx_buffer_size || uart->_inverted != inverted || uart->_rxfifo_full_thrhd != rxfifo_full_thrhd) { - log_v("UART%d changing buffer sizes or inverted signal or rxfifo_full_thrhd. IDF driver will be restarted", uart_nr); - uartEnd(uart_nr); + if (uart_is_driver_installed(uart_nr)) { + log_v("UART%d Driver already installed.", uart_nr); + // some parameters can't be changed unless we end the UART driver + if (uart->_rx_buffer_size != rx_buffer_size || uart->_tx_buffer_size != tx_buffer_size || uart->_inverted != inverted || uart->_rxfifo_full_thrhd != rxfifo_full_thrhd) { + log_v("UART%d changing buffer sizes or inverted signal or rxfifo_full_thrhd. IDF driver will be restarted", uart_nr); + uartEnd(uart_nr); + } else { + bool retCode = true; + UART_MUTEX_LOCK(); + //User may just want to change some parameters, such as baudrate, data length, parity, stop bits or pins + if (uart->_baudrate != baudrate) { + if (ESP_OK != uart_set_baudrate(uart_nr, baudrate)) { + log_e("UART%d changing baudrate failed.", uart_nr); + retCode = false; } else { - bool retCode = true; - UART_MUTEX_LOCK(); - //User may just want to change some parameters, such as baudrate, data length, parity, stop bits or pins - if (uart->_baudrate != baudrate) { - if (ESP_OK != uart_set_baudrate(uart_nr, baudrate)) { - log_e("UART%d changing baudrate failed.", uart_nr); - retCode = false; - } else { - log_v("UART%d changed baudrate to %d", uart_nr, baudrate); - uart->_baudrate = baudrate; - } - } - uart_word_length_t data_bits = (config & 0xc) >> 2; - uart_parity_t parity = config & 0x3; - uart_stop_bits_t stop_bits = (config & 0x30) >> 4; - if (retCode && (uart->_config & 0xc) >> 2 != data_bits) { - if (ESP_OK != uart_set_word_length(uart_nr, data_bits)) { - log_e("UART%d changing data length failed.", uart_nr); - retCode = false; - } else { - log_v("UART%d changed data length to %d", uart_nr, data_bits + 5); - } - } - if (retCode && (uart->_config & 0x3) != parity) { - if (ESP_OK != uart_set_parity(uart_nr, parity)) { - log_e("UART%d changing parity failed.", uart_nr); - retCode = false; - } else { - log_v("UART%d changed parity to %s", uart_nr, parity == 0 ? "NONE" : parity == 2 ? "EVEN" : "ODD"); - } - } - if (retCode && (uart->_config & 0xc30) >> 4 != stop_bits) { - if (ESP_OK != uart_set_stop_bits(uart_nr, stop_bits)) { - log_e("UART%d changing stop bits failed.", uart_nr); - retCode = false; - } else { - log_v("UART%d changed stop bits to %d", uart_nr, stop_bits == 3 ? 2 : 1); - } - } - if (retCode) uart->_config = config; - if (retCode && rxPin > 0 && uart->_rxPin != rxPin) { - retCode &= _uartDetachPins(uart_nr, uart->_rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - retCode &= _uartAttachPins(uart_nr, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - if (!retCode) { - log_e("UART%d changing RX pin failed.", uart_nr); - } else { - log_v("UART%d changed RX pin to %d", uart_nr, rxPin); - } - } - if (retCode && txPin > 0 && uart->_txPin != txPin) { - retCode &= _uartDetachPins(uart_nr, UART_PIN_NO_CHANGE, uart->_txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - retCode &= _uartAttachPins(uart_nr, UART_PIN_NO_CHANGE, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - if (!retCode) { - log_e("UART%d changing TX pin failed.", uart_nr); - } else { - log_v("UART%d changed TX pin to %d", uart_nr, txPin); - } - } - UART_MUTEX_UNLOCK(); - if (retCode) { - // UART driver was already working, just return the uart_t structure, syaing that no new driver was installed - return uart; - } - // if we reach this point, it means that we need to restart the UART driver - uartEnd(uart_nr); + log_v("UART%d changed baudrate to %d", uart_nr, baudrate); + uart->_baudrate = baudrate; } - } else { - log_v("UART%d not installed. Starting installation", uart_nr); - } - uart_config_t uart_config; - uart_config.data_bits = (config & 0xc) >> 2; - uart_config.parity = (config & 0x3); - uart_config.stop_bits = (config & 0x30) >> 4; - uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE; - uart_config.rx_flow_ctrl_thresh = rxfifo_full_thrhd; - uart_config.baud_rate = baudrate; - // CLK_APB for ESP32|S2|S3|C3 -- CLK_PLL_F40M for C2 -- CLK_PLL_F48M for H2 -- CLK_PLL_F80M for C6 - uart_config.source_clk = UART_SCLK_DEFAULT; - - UART_MUTEX_LOCK(); - bool retCode = ESP_OK == uart_driver_install(uart_nr, rx_buffer_size, tx_buffer_size, 20, &(uart->uart_event_queue), 0); - - if (retCode) retCode &= ESP_OK == uart_param_config(uart_nr, &uart_config); - - // Is it right or the idea is to swap rx and tx pins? - if (retCode && inverted) { - // invert signal for both Rx and Tx - retCode &= ESP_OK == uart_set_line_inverse(uart_nr, UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV); - } - - if (retCode) { - uart->_baudrate = baudrate; - uart->_config = config; - uart->_inverted = inverted; - uart->_rxfifo_full_thrhd = rxfifo_full_thrhd; - uart->_rx_buffer_size = rx_buffer_size; - uart->_tx_buffer_size = tx_buffer_size; - uart->has_peek = false; - uart->peek_byte = 0; - } - UART_MUTEX_UNLOCK(); - - // uartSetPins detaches previous pins if new ones are used over a previous begin() - if (retCode) retCode &= uartSetPins(uart_nr, rxPin, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - if (!retCode) { - uartEnd(uart_nr); - uart = NULL; - log_e("UART%d initialization error.", uart->num); - } else { - uartFlush(uart); - log_v("UART%d initialization done.", uart->num); - } - return uart; // a new driver was installed + } + uart_word_length_t data_bits = (config & 0xc) >> 2; + uart_parity_t parity = config & 0x3; + uart_stop_bits_t stop_bits = (config & 0x30) >> 4; + if (retCode && (uart->_config & 0xc) >> 2 != data_bits) { + if (ESP_OK != uart_set_word_length(uart_nr, data_bits)) { + log_e("UART%d changing data length failed.", uart_nr); + retCode = false; + } else { + log_v("UART%d changed data length to %d", uart_nr, data_bits + 5); + } + } + if (retCode && (uart->_config & 0x3) != parity) { + if (ESP_OK != uart_set_parity(uart_nr, parity)) { + log_e("UART%d changing parity failed.", uart_nr); + retCode = false; + } else { + log_v("UART%d changed parity to %s", uart_nr, parity == 0 ? "NONE" : parity == 2 ? "EVEN" + : "ODD"); + } + } + if (retCode && (uart->_config & 0xc30) >> 4 != stop_bits) { + if (ESP_OK != uart_set_stop_bits(uart_nr, stop_bits)) { + log_e("UART%d changing stop bits failed.", uart_nr); + retCode = false; + } else { + log_v("UART%d changed stop bits to %d", uart_nr, stop_bits == 3 ? 2 : 1); + } + } + if (retCode) uart->_config = config; + if (retCode && rxPin > 0 && uart->_rxPin != rxPin) { + retCode &= _uartDetachPins(uart_nr, uart->_rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + retCode &= _uartAttachPins(uart_nr, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + if (!retCode) { + log_e("UART%d changing RX pin failed.", uart_nr); + } else { + log_v("UART%d changed RX pin to %d", uart_nr, rxPin); + } + } + if (retCode && txPin > 0 && uart->_txPin != txPin) { + retCode &= _uartDetachPins(uart_nr, UART_PIN_NO_CHANGE, uart->_txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + retCode &= _uartAttachPins(uart_nr, UART_PIN_NO_CHANGE, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + if (!retCode) { + log_e("UART%d changing TX pin failed.", uart_nr); + } else { + log_v("UART%d changed TX pin to %d", uart_nr, txPin); + } + } + UART_MUTEX_UNLOCK(); + if (retCode) { + // UART driver was already working, just return the uart_t structure, syaing that no new driver was installed + return uart; + } + // if we reach this point, it means that we need to restart the UART driver + uartEnd(uart_nr); + } + } else { + log_v("UART%d not installed. Starting installation", uart_nr); + } + uart_config_t uart_config; + uart_config.data_bits = (config & 0xc) >> 2; + uart_config.parity = (config & 0x3); + uart_config.stop_bits = (config & 0x30) >> 4; + uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE; + uart_config.rx_flow_ctrl_thresh = rxfifo_full_thrhd; + uart_config.baud_rate = baudrate; + // CLK_APB for ESP32|S2|S3|C3 -- CLK_PLL_F40M for C2 -- CLK_PLL_F48M for H2 -- CLK_PLL_F80M for C6 + uart_config.source_clk = UART_SCLK_DEFAULT; + + UART_MUTEX_LOCK(); + bool retCode = ESP_OK == uart_driver_install(uart_nr, rx_buffer_size, tx_buffer_size, 20, &(uart->uart_event_queue), 0); + + if (retCode) retCode &= ESP_OK == uart_param_config(uart_nr, &uart_config); + + // Is it right or the idea is to swap rx and tx pins? + if (retCode && inverted) { + // invert signal for both Rx and Tx + retCode &= ESP_OK == uart_set_line_inverse(uart_nr, UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV); + } + + if (retCode) { + uart->_baudrate = baudrate; + uart->_config = config; + uart->_inverted = inverted; + uart->_rxfifo_full_thrhd = rxfifo_full_thrhd; + uart->_rx_buffer_size = rx_buffer_size; + uart->_tx_buffer_size = tx_buffer_size; + uart->has_peek = false; + uart->peek_byte = 0; + } + UART_MUTEX_UNLOCK(); + + // uartSetPins detaches previous pins if new ones are used over a previous begin() + if (retCode) retCode &= uartSetPins(uart_nr, rxPin, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + if (!retCode) { + uartEnd(uart_nr); + uart = NULL; + log_e("UART%d initialization error.", uart->num); + } else { + uartFlush(uart); + log_v("UART%d initialization done.", uart->num); + } + return uart; // a new driver was installed } // This function code is under testing - for now just keep it here -void uartSetFastReading(uart_t* uart) -{ - if(uart == NULL) { - return; - } - - UART_MUTEX_LOCK(); - // override default RX IDF Driver Interrupt - no BREAK, PARITY or OVERFLOW - uart_intr_config_t uart_intr = { - .intr_enable_mask = UART_INTR_RXFIFO_FULL | UART_INTR_RXFIFO_TOUT, // only these IRQs - no BREAK, PARITY or OVERFLOW - .rx_timeout_thresh = 1, - .txfifo_empty_intr_thresh = 10, - .rxfifo_full_thresh = 2, - }; - - ESP_ERROR_CHECK(uart_intr_config(uart->num, &uart_intr)); - UART_MUTEX_UNLOCK(); +void uartSetFastReading(uart_t* uart) { + if (uart == NULL) { + return; + } + + UART_MUTEX_LOCK(); + // override default RX IDF Driver Interrupt - no BREAK, PARITY or OVERFLOW + uart_intr_config_t uart_intr = { + .intr_enable_mask = UART_INTR_RXFIFO_FULL | UART_INTR_RXFIFO_TOUT, // only these IRQs - no BREAK, PARITY or OVERFLOW + .rx_timeout_thresh = 1, + .txfifo_empty_intr_thresh = 10, + .rxfifo_full_thresh = 2, + }; + + ESP_ERROR_CHECK(uart_intr_config(uart->num, &uart_intr)); + UART_MUTEX_UNLOCK(); } -bool uartSetRxTimeout(uart_t* uart, uint8_t numSymbTimeout) -{ - if(uart == NULL) { - return false; - } +bool uartSetRxTimeout(uart_t* uart, uint8_t numSymbTimeout) { + if (uart == NULL) { + return false; + } - UART_MUTEX_LOCK(); - bool retCode = (ESP_OK == uart_set_rx_timeout(uart->num, numSymbTimeout)); - UART_MUTEX_UNLOCK(); - return retCode; + UART_MUTEX_LOCK(); + bool retCode = (ESP_OK == uart_set_rx_timeout(uart->num, numSymbTimeout)); + UART_MUTEX_UNLOCK(); + return retCode; } -bool uartSetRxFIFOFull(uart_t* uart, uint8_t numBytesFIFOFull) -{ - if(uart == NULL) { - return false; - } +bool uartSetRxFIFOFull(uart_t* uart, uint8_t numBytesFIFOFull) { + if (uart == NULL) { + return false; + } - UART_MUTEX_LOCK(); - bool retCode = (ESP_OK == uart_set_rx_full_threshold(uart->num, numBytesFIFOFull)); - UART_MUTEX_UNLOCK(); - return retCode; + UART_MUTEX_LOCK(); + bool retCode = (ESP_OK == uart_set_rx_full_threshold(uart->num, numBytesFIFOFull)); + UART_MUTEX_UNLOCK(); + return retCode; } -void uartEnd(uint8_t uart_num) -{ - if(uart_num >= SOC_UART_NUM) { - log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1); - return; - } - // get UART information - uart_t* uart = &_uart_bus_array[uart_num]; - - UART_MUTEX_LOCK(); - _uartDetachPins(uart_num, uart->_rxPin, uart->_txPin, uart->_ctsPin, uart->_rtsPin); - if(uart_is_driver_installed(uart_num)) { - uart_driver_delete(uart_num); - } - UART_MUTEX_UNLOCK(); +void uartEnd(uint8_t uart_num) { + if (uart_num >= SOC_UART_NUM) { + log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1); + return; + } + // get UART information + uart_t* uart = &_uart_bus_array[uart_num]; + + UART_MUTEX_LOCK(); + _uartDetachPins(uart_num, uart->_rxPin, uart->_txPin, uart->_ctsPin, uart->_rtsPin); + if (uart_is_driver_installed(uart_num)) { + uart_driver_delete(uart_num); + } + UART_MUTEX_UNLOCK(); } -void uartSetRxInvert(uart_t* uart, bool invert) -{ - if (uart == NULL) - return; +void uartSetRxInvert(uart_t* uart, bool invert) { + if (uart == NULL) + return; #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - // POTENTIAL ISSUE :: original code only set/reset rxd_inv bit + // POTENTIAL ISSUE :: original code only set/reset rxd_inv bit // IDF or LL set/reset the whole inv_mask! // if (invert) // ESP_ERROR_CHECK(uart_set_line_inverse(uart->num, UART_SIGNAL_RXD_INV)); // else // ESP_ERROR_CHECK(uart_set_line_inverse(uart->num, UART_SIGNAL_INV_DISABLE)); - + #else - // this implementation is better over IDF API because it only affects RXD - // this is supported in ESP32, ESP32-S2 and ESP32-C3 - uart_dev_t *hw = UART_LL_GET_HW(uart->num); - if (invert) - hw->conf0.rxd_inv = 1; - else - hw->conf0.rxd_inv = 0; -#endif + // this implementation is better over IDF API because it only affects RXD + // this is supported in ESP32, ESP32-S2 and ESP32-C3 + uart_dev_t* hw = UART_LL_GET_HW(uart->num); + if (invert) + hw->conf0.rxd_inv = 1; + else + hw->conf0.rxd_inv = 0; +#endif } -uint32_t uartAvailable(uart_t* uart) -{ +uint32_t uartAvailable(uart_t* uart) { - if(uart == NULL) { - return 0; - } - - UART_MUTEX_LOCK(); - size_t available; - uart_get_buffered_data_len(uart->num, &available); - if (uart->has_peek) available++; - UART_MUTEX_UNLOCK(); - return available; + if (uart == NULL) { + return 0; + } + + UART_MUTEX_LOCK(); + size_t available; + uart_get_buffered_data_len(uart->num, &available); + if (uart->has_peek) available++; + UART_MUTEX_UNLOCK(); + return available; } -uint32_t uartAvailableForWrite(uart_t* uart) -{ - if(uart == NULL) { - return 0; - } - UART_MUTEX_LOCK(); - uint32_t available = uart_ll_get_txfifo_len(UART_LL_GET_HW(uart->num)); - size_t txRingBufferAvailable = 0; - if (ESP_OK == uart_get_tx_buffer_free_size(uart->num, &txRingBufferAvailable)) { - available = txRingBufferAvailable == 0 ? available : txRingBufferAvailable; - } - UART_MUTEX_UNLOCK(); - return available; +uint32_t uartAvailableForWrite(uart_t* uart) { + if (uart == NULL) { + return 0; + } + UART_MUTEX_LOCK(); + uint32_t available = uart_ll_get_txfifo_len(UART_LL_GET_HW(uart->num)); + size_t txRingBufferAvailable = 0; + if (ESP_OK == uart_get_tx_buffer_free_size(uart->num, &txRingBufferAvailable)) { + available = txRingBufferAvailable == 0 ? available : txRingBufferAvailable; + } + UART_MUTEX_UNLOCK(); + return available; } -size_t uartReadBytes(uart_t* uart, uint8_t *buffer, size_t size, uint32_t timeout_ms) -{ - if(uart == NULL || size == 0 || buffer == NULL) { - return 0; - } +size_t uartReadBytes(uart_t* uart, uint8_t* buffer, size_t size, uint32_t timeout_ms) { + if (uart == NULL || size == 0 || buffer == NULL) { + return 0; + } - size_t bytes_read = 0; + size_t bytes_read = 0; - UART_MUTEX_LOCK(); + UART_MUTEX_LOCK(); - if (uart->has_peek) { - uart->has_peek = false; - *buffer++ = uart->peek_byte; - size--; - bytes_read = 1; - } + if (uart->has_peek) { + uart->has_peek = false; + *buffer++ = uart->peek_byte; + size--; + bytes_read = 1; + } + + if (size > 0) { + int len = uart_read_bytes(uart->num, buffer, size, pdMS_TO_TICKS(timeout_ms)); + if (len < 0) len = 0; // error reading UART + bytes_read += len; + } - if (size > 0) { - int len = uart_read_bytes(uart->num, buffer, size, pdMS_TO_TICKS(timeout_ms)); - if (len < 0) len = 0; // error reading UART - bytes_read += len; - } - - UART_MUTEX_UNLOCK(); - return bytes_read; + UART_MUTEX_UNLOCK(); + return bytes_read; } -// DEPRICATED but the original code will be kepts here as future reference when a final solution +// DEPRECATED but the original code will be kepts here as future reference when a final solution // to the UART driver is defined in the use case of reading byte by byte from UART. -uint8_t uartRead(uart_t* uart) -{ - if(uart == NULL) { - return 0; - } - uint8_t c = 0; +uint8_t uartRead(uart_t* uart) { + if (uart == NULL) { + return 0; + } + uint8_t c = 0; - UART_MUTEX_LOCK(); + UART_MUTEX_LOCK(); - if (uart->has_peek) { - uart->has_peek = false; - c = uart->peek_byte; - } else { + if (uart->has_peek) { + uart->has_peek = false; + c = uart->peek_byte; + } else { - int len = uart_read_bytes(uart->num, &c, 1, 20 / portTICK_PERIOD_MS); - if (len <= 0) { // includes negative return from IDF in case of error - c = 0; - } + int len = uart_read_bytes(uart->num, &c, 1, 20 / portTICK_PERIOD_MS); + if (len <= 0) { // includes negative return from IDF in case of error + c = 0; } - UART_MUTEX_UNLOCK(); - return c; + } + UART_MUTEX_UNLOCK(); + return c; } -uint8_t uartPeek(uart_t* uart) -{ - if(uart == NULL) { - return 0; - } - uint8_t c = 0; +uint8_t uartPeek(uart_t* uart) { + if (uart == NULL) { + return 0; + } + uint8_t c = 0; - UART_MUTEX_LOCK(); + UART_MUTEX_LOCK(); - if (uart->has_peek) { - c = uart->peek_byte; + if (uart->has_peek) { + c = uart->peek_byte; + } else { + int len = uart_read_bytes(uart->num, &c, 1, 20 / portTICK_PERIOD_MS); + if (len <= 0) { // includes negative return from IDF in case of error + c = 0; } else { - int len = uart_read_bytes(uart->num, &c, 1, 20 / portTICK_PERIOD_MS); - if (len <= 0) { // includes negative return from IDF in case of error - c = 0; - } else { - uart->has_peek = true; - uart->peek_byte = c; - } + uart->has_peek = true; + uart->peek_byte = c; } - UART_MUTEX_UNLOCK(); - return c; + } + UART_MUTEX_UNLOCK(); + return c; } -void uartWrite(uart_t* uart, uint8_t c) -{ - if(uart == NULL) { - return; - } - UART_MUTEX_LOCK(); - uart_write_bytes(uart->num, &c, 1); - UART_MUTEX_UNLOCK(); +void uartWrite(uart_t* uart, uint8_t c) { + if (uart == NULL) { + return; + } + UART_MUTEX_LOCK(); + uart_write_bytes(uart->num, &c, 1); + UART_MUTEX_UNLOCK(); } -void uartWriteBuf(uart_t* uart, const uint8_t * data, size_t len) -{ - if(uart == NULL || data == NULL || !len) { - return; - } +void uartWriteBuf(uart_t* uart, const uint8_t* data, size_t len) { + if (uart == NULL || data == NULL || !len) { + return; + } - UART_MUTEX_LOCK(); - uart_write_bytes(uart->num, data, len); - UART_MUTEX_UNLOCK(); + UART_MUTEX_LOCK(); + uart_write_bytes(uart->num, data, len); + UART_MUTEX_UNLOCK(); } -void uartFlush(uart_t* uart) -{ - uartFlushTxOnly(uart, true); +void uartFlush(uart_t* uart) { + uartFlushTxOnly(uart, true); } -void uartFlushTxOnly(uart_t* uart, bool txOnly) -{ - if(uart == NULL) { - return; - } - - UART_MUTEX_LOCK(); - while(!uart_ll_is_tx_idle(UART_LL_GET_HW(uart->num))); +void uartFlushTxOnly(uart_t* uart, bool txOnly) { + if (uart == NULL) { + return; + } - if ( !txOnly ) { - ESP_ERROR_CHECK(uart_flush_input(uart->num)); - } - UART_MUTEX_UNLOCK(); -} + UART_MUTEX_LOCK(); + while (!uart_ll_is_tx_idle(UART_LL_GET_HW(uart->num))) + ; -void uartSetBaudRate(uart_t* uart, uint32_t baud_rate) -{ - if(uart == NULL) { - return; - } - UART_MUTEX_LOCK(); - uint32_t sclk_freq; - if(uart_get_sclk_freq(UART_SCLK_DEFAULT, &sclk_freq) == ESP_OK){ - uart_ll_set_baudrate(UART_LL_GET_HW(uart->num), baud_rate, sclk_freq); - } - uart->_baudrate = baud_rate; - UART_MUTEX_UNLOCK(); + if (!txOnly) { + ESP_ERROR_CHECK(uart_flush_input(uart->num)); + } + UART_MUTEX_UNLOCK(); } -uint32_t uartGetBaudRate(uart_t* uart) -{ - uint32_t baud_rate = 0; - uint32_t sclk_freq; +void uartSetBaudRate(uart_t* uart, uint32_t baud_rate) { + if (uart == NULL) { + return; + } + UART_MUTEX_LOCK(); + uint32_t sclk_freq; + if (uart_get_sclk_freq(UART_SCLK_DEFAULT, &sclk_freq) == ESP_OK) { + uart_ll_set_baudrate(UART_LL_GET_HW(uart->num), baud_rate, sclk_freq); + } + uart->_baudrate = baud_rate; + UART_MUTEX_UNLOCK(); +} - if(uart == NULL) { - return 0; - } +uint32_t uartGetBaudRate(uart_t* uart) { + uint32_t baud_rate = 0; + uint32_t sclk_freq; - UART_MUTEX_LOCK(); - if(uart_get_sclk_freq(UART_SCLK_DEFAULT, &sclk_freq) == ESP_OK){ - baud_rate = uart_ll_get_baudrate(UART_LL_GET_HW(uart->num), sclk_freq); - } - UART_MUTEX_UNLOCK(); - return baud_rate; + if (uart == NULL) { + return 0; + } + + UART_MUTEX_LOCK(); + if (uart_get_sclk_freq(UART_SCLK_DEFAULT, &sclk_freq) == ESP_OK) { + baud_rate = uart_ll_get_baudrate(UART_LL_GET_HW(uart->num), sclk_freq); + } + UART_MUTEX_UNLOCK(); + return baud_rate; } -static void ARDUINO_ISR_ATTR uart0_write_char(char c) -{ - while (uart_ll_get_txfifo_len(&UART0) == 0); - uart_ll_write_txfifo(&UART0, (const uint8_t *) &c, 1); +static void ARDUINO_ISR_ATTR uart0_write_char(char c) { + while (uart_ll_get_txfifo_len(&UART0) == 0) + ; + uart_ll_write_txfifo(&UART0, (const uint8_t*)&c, 1); } #if SOC_UART_NUM > 1 -static void ARDUINO_ISR_ATTR uart1_write_char(char c) -{ - while (uart_ll_get_txfifo_len(&UART1) == 0); - uart_ll_write_txfifo(&UART1, (const uint8_t *) &c, 1); +static void ARDUINO_ISR_ATTR uart1_write_char(char c) { + while (uart_ll_get_txfifo_len(&UART1) == 0) + ; + uart_ll_write_txfifo(&UART1, (const uint8_t*)&c, 1); } #endif #if SOC_UART_NUM > 2 -static void ARDUINO_ISR_ATTR uart2_write_char(char c) -{ - while (uart_ll_get_txfifo_len(&UART2) == 0); - uart_ll_write_txfifo(&UART2, (const uint8_t *) &c, 1); +static void ARDUINO_ISR_ATTR uart2_write_char(char c) { + while (uart_ll_get_txfifo_len(&UART2) == 0) + ; + uart_ll_write_txfifo(&UART2, (const uint8_t*)&c, 1); } #endif -void uart_install_putc() -{ - switch(s_uart_debug_nr) { +void uart_install_putc() { + switch (s_uart_debug_nr) { case 0: - ets_install_putc1((void (*)(char)) &uart0_write_char); - break; + ets_install_putc1((void (*)(char)) & uart0_write_char); + break; #if SOC_UART_NUM > 1 case 1: - ets_install_putc1((void (*)(char)) &uart1_write_char); - break; + ets_install_putc1((void (*)(char)) & uart1_write_char); + break; #endif #if SOC_UART_NUM > 2 case 2: - ets_install_putc1((void (*)(char)) &uart2_write_char); - break; + ets_install_putc1((void (*)(char)) & uart2_write_char); + break; #endif default: - ets_install_putc1(NULL); - break; - } + ets_install_putc1(NULL); + break; + } } // Routines that take care of UART mode in the HardwareSerial Class code // used to set UART_MODE_RS485_HALF_DUPLEX auto RTS for TXD for ESP32 chips -bool uartSetMode(uart_t *uart, uart_mode_t mode) -{ - if (uart == NULL || uart->num >= SOC_UART_NUM) - { - return false; - } - - UART_MUTEX_LOCK(); - bool retCode = (ESP_OK == uart_set_mode(uart->num, mode)); - UART_MUTEX_UNLOCK(); - return retCode; +bool uartSetMode(uart_t* uart, uart_mode_t mode) { + if (uart == NULL || uart->num >= SOC_UART_NUM) { + return false; + } + + UART_MUTEX_LOCK(); + bool retCode = (ESP_OK == uart_set_mode(uart->num, mode)); + UART_MUTEX_UNLOCK(); + return retCode; } -void uartSetDebug(uart_t* uart) -{ - if(uart == NULL || uart->num >= SOC_UART_NUM) { - s_uart_debug_nr = -1; - } else { - s_uart_debug_nr = uart->num; - } - uart_install_putc(); +void uartSetDebug(uart_t* uart) { + if (uart == NULL || uart->num >= SOC_UART_NUM) { + s_uart_debug_nr = -1; + } else { + s_uart_debug_nr = uart->num; + } + uart_install_putc(); } -int uartGetDebug() -{ - return s_uart_debug_nr; +int uartGetDebug() { + return s_uart_debug_nr; } -int log_printfv(const char *format, va_list arg) -{ - static char loc_buf[64]; - char * temp = loc_buf; - uint32_t len; - va_list copy; - va_copy(copy, arg); - len = vsnprintf(NULL, 0, format, copy); - va_end(copy); - if(len >= sizeof(loc_buf)){ - temp = (char*)malloc(len+1); - if(temp == NULL) { - return 0; - } - } +int log_printfv(const char* format, va_list arg) { + static char loc_buf[64]; + char* temp = loc_buf; + uint32_t len; + va_list copy; + va_copy(copy, arg); + len = vsnprintf(NULL, 0, format, copy); + va_end(copy); + if (len >= sizeof(loc_buf)) { + temp = (char*)malloc(len + 1); + if (temp == NULL) { + return 0; + } + } /* // This causes dead locks with logging in specific cases and also with C++ constructors that may send logs #if !CONFIG_DISABLE_HAL_LOCKS @@ -894,15 +863,15 @@ int log_printfv(const char *format, va_list arg) #endif */ #if CONFIG_IDF_TARGET_ESP32C3 - vsnprintf(temp, len+1, format, arg); - ets_printf("%s", temp); + vsnprintf(temp, len + 1, format, arg); + ets_printf("%s", temp); #else - int wlen = vsnprintf(temp, len+1, format, arg); - for (int i = 0; i < wlen; i++) { - ets_write_char_uart(temp[i]); - } + int wlen = vsnprintf(temp, len + 1, format, arg); + for (int i = 0; i < wlen; i++) { + ets_write_char_uart(temp[i]); + } #endif -/* + /* // This causes dead locks with logging and also with constructors that may send logs #if !CONFIG_DISABLE_HAL_LOCKS if(s_uart_debug_nr != -1 && _uart_bus_array[s_uart_debug_nr].lock){ @@ -910,182 +879,180 @@ int log_printfv(const char *format, va_list arg) } #endif */ - if(len >= sizeof(loc_buf)){ - free(temp); - } - // flushes TX - make sure that the log message is completely sent. - if(s_uart_debug_nr != -1) while(!uart_ll_is_tx_idle(UART_LL_GET_HW(s_uart_debug_nr))); - return len; + if (len >= sizeof(loc_buf)) { + free(temp); + } + // flushes TX - make sure that the log message is completely sent. + if (s_uart_debug_nr != -1) + while (!uart_ll_is_tx_idle(UART_LL_GET_HW(s_uart_debug_nr))) + ; + return len; } -int log_printf(const char *format, ...) -{ - int len; - va_list arg; - va_start(arg, format); - len = log_printfv(format, arg); - va_end(arg); - return len; +int log_printf(const char* format, ...) { + int len; + va_list arg; + va_start(arg, format); + len = log_printfv(format, arg); + va_end(arg); + return len; } -static void log_print_buf_line(const uint8_t *b, size_t len, size_t total_len){ - for(size_t i = 0; i 16){ - for(size_t i = len; i<16; i++){ - log_printf(" "); - } - log_printf(" // "); - } else { - log_printf(" // "); - } - for(size_t i = 0; i= 0x20) && (b[i] < 0x80))?b[i]:'.'); - } - log_printf("\n"); +static void log_print_buf_line(const uint8_t* b, size_t len, size_t total_len) { + for (size_t i = 0; i < len; i++) { + log_printf("%s0x%02x,", i ? " " : "", b[i]); + } + if (total_len > 16) { + for (size_t i = len; i < 16; i++) { + log_printf(" "); + } + log_printf(" // "); + } else { + log_printf(" // "); + } + for (size_t i = 0; i < len; i++) { + log_printf("%c", ((b[i] >= 0x20) && (b[i] < 0x80)) ? b[i] : '.'); + } + log_printf("\n"); } -void log_print_buf(const uint8_t *b, size_t len){ - if(!len || !b){ - return; - } - for(size_t i = 0; i 16){ - log_printf("/* 0x%04X */ ", i); - } - log_print_buf_line(b+i, ((len-i)<16)?(len - i):16, len); +void log_print_buf(const uint8_t* b, size_t len) { + if (!len || !b) { + return; + } + for (size_t i = 0; i < len; i += 16) { + if (len > 16) { + log_printf("/* 0x%04X */ ", i); } + log_print_buf_line(b + i, ((len - i) < 16) ? (len - i) : 16, len); + } } /* - * if enough pulses are detected return the minimum high pulse duration + minimum low pulse duration divided by two. - * This equals one bit period. If flag is true the function return inmediately, otherwise it waits for enough pulses. + * if enough pulses are detected return the minimum high pulse duration + minimum low pulse duration divided by two. + * This equals one bit period. If flag is true the function return immediately, otherwise it waits for enough pulses. */ -unsigned long uartBaudrateDetect(uart_t *uart, bool flg) -{ +unsigned long uartBaudrateDetect(uart_t* uart, bool flg) { // Baud rate detection only works for ESP32 and ESP32S2 #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 - if(uart == NULL) { - return 0; - } + if (uart == NULL) { + return 0; + } - uart_dev_t *hw = UART_LL_GET_HW(uart->num); + uart_dev_t* hw = UART_LL_GET_HW(uart->num); - while(hw->rxd_cnt.edge_cnt < 30) { // UART_PULSE_NUM(uart_num) - if(flg) return 0; - ets_delay_us(1000); - } + while (hw->rxd_cnt.edge_cnt < 30) { // UART_PULSE_NUM(uart_num) + if (flg) return 0; + ets_delay_us(1000); + } - UART_MUTEX_LOCK(); - //log_i("lowpulse_min_cnt = %d hightpulse_min_cnt = %d", hw->lowpulse.min_cnt, hw->highpulse.min_cnt); - unsigned long ret = ((hw->lowpulse.min_cnt + hw->highpulse.min_cnt) >> 1); - UART_MUTEX_UNLOCK(); + UART_MUTEX_LOCK(); + //log_i("lowpulse_min_cnt = %d hightpulse_min_cnt = %d", hw->lowpulse.min_cnt, hw->highpulse.min_cnt); + unsigned long ret = ((hw->lowpulse.min_cnt + hw->highpulse.min_cnt) >> 1); + UART_MUTEX_UNLOCK(); - return ret; + return ret; #else - return 0; + return 0; #endif } /* - * To start detection of baud rate with the uart the auto_baud.en bit needs to be cleared and set. The bit period is - * detected calling uartBadrateDetect(). The raw baudrate is computed using the UART_CLK_FREQ. The raw baudrate is + * To start detection of baud rate with the uart the auto_baud.en bit needs to be cleared and set. The bit period is + * detected calling uartBadrateDetect(). The raw baudrate is computed using the UART_CLK_FREQ. The raw baudrate is * rounded to the closed real baudrate. - * + * * ESP32-C3 reports wrong baud rate detection as shown below: - * + * * This will help in a future recall for the C3. * Baud Sent: Baud Read: * 300 --> 19536 * 2400 --> 19536 - * 4800 --> 19536 - * 9600 --> 28818 + * 4800 --> 19536 + * 9600 --> 28818 * 19200 --> 57678 * 38400 --> 115440 * 57600 --> 173535 * 115200 --> 347826 * 230400 --> 701754 - * - * + * + * */ -void uartStartDetectBaudrate(uart_t *uart) { - if(uart == NULL) { - return; - } +void uartStartDetectBaudrate(uart_t* uart) { + if (uart == NULL) { + return; + } // Baud rate detection only works for ESP32 and ESP32S2 #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 - uart_dev_t *hw = UART_LL_GET_HW(uart->num); - hw->auto_baud.glitch_filt = 0x08; - hw->auto_baud.en = 0; - hw->auto_baud.en = 1; + uart_dev_t* hw = UART_LL_GET_HW(uart->num); + hw->auto_baud.glitch_filt = 0x08; + hw->auto_baud.en = 0; + hw->auto_baud.en = 1; #else - - // ESP32-C3 requires further testing - // Baud rate detection returns wrong values - - log_e("baud rate detection for this SoC is not supported."); - return; - // Code bellow for C3 kept for future recall - //hw->rx_filt.glitch_filt = 0x08; - //hw->rx_filt.glitch_filt_en = 1; - //hw->conf0.autobaud_en = 0; - //hw->conf0.autobaud_en = 1; + // ESP32-C3 requires further testing + // Baud rate detection returns wrong values + + log_e("baud rate detection for this SoC is not supported."); + return; + + // Code bellow for C3 kept for future recall + //hw->rx_filt.glitch_filt = 0x08; + //hw->rx_filt.glitch_filt_en = 1; + //hw->conf0.autobaud_en = 0; + //hw->conf0.autobaud_en = 1; #endif } - -unsigned long uartDetectBaudrate(uart_t *uart) -{ - if(uart == NULL) { - return 0; - } + +unsigned long uartDetectBaudrate(uart_t* uart) { + if (uart == NULL) { + return 0; + } // Baud rate detection only works for ESP32 and ESP32S2 #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 - static bool uartStateDetectingBaudrate = false; + static bool uartStateDetectingBaudrate = false; - if(!uartStateDetectingBaudrate) { - uartStartDetectBaudrate(uart); - uartStateDetectingBaudrate = true; - } + if (!uartStateDetectingBaudrate) { + uartStartDetectBaudrate(uart); + uartStateDetectingBaudrate = true; + } - unsigned long divisor = uartBaudrateDetect(uart, true); - if (!divisor) { - return 0; - } + unsigned long divisor = uartBaudrateDetect(uart, true); + if (!divisor) { + return 0; + } - uart_dev_t *hw = UART_LL_GET_HW(uart->num); - hw->auto_baud.en = 0; + uart_dev_t* hw = UART_LL_GET_HW(uart->num); + hw->auto_baud.en = 0; - uartStateDetectingBaudrate = false; // Initialize for the next round + uartStateDetectingBaudrate = false; // Initialize for the next round - unsigned long baudrate = getApbFrequency() / divisor; - - //log_i("APB_FREQ = %d\nraw baudrate detected = %d", getApbFrequency(), baudrate); + unsigned long baudrate = getApbFrequency() / divisor; - static const unsigned long default_rates[] = {300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 74880, 115200, 230400, 256000, 460800, 921600, 1843200, 3686400}; + //log_i("APB_FREQ = %d\nraw baudrate detected = %d", getApbFrequency(), baudrate); - size_t i; - for (i = 1; i < sizeof(default_rates) / sizeof(default_rates[0]) - 1; i++) // find the nearest real baudrate - { - if (baudrate <= default_rates[i]) - { - if (baudrate - default_rates[i - 1] < default_rates[i] - baudrate) { - i--; - } - break; - } + static const unsigned long default_rates[] = { 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 74880, 115200, 230400, 256000, 460800, 921600, 1843200, 3686400 }; + + size_t i; + for (i = 1; i < sizeof(default_rates) / sizeof(default_rates[0]) - 1; i++) // find the nearest real baudrate + { + if (baudrate <= default_rates[i]) { + if (baudrate - default_rates[i - 1] < default_rates[i] - baudrate) { + i--; + } + break; } + } - return default_rates[i]; + return default_rates[i]; #else - log_e("baud rate detection this SoC is not supported."); - return 0; + log_e("baud rate detection this SoC is not supported."); + return 0; #endif } @@ -1102,18 +1069,17 @@ unsigned long uartDetectBaudrate(uart_t *uart) // gets the right TX or RX SIGNAL, based on the UART number from gpio_sig_map.h #if SOC_UART_NUM > 2 - #define UART_TX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0TXD_OUT_IDX : (uartNumber == UART_NUM_1 ? U1TXD_OUT_IDX : U2TXD_OUT_IDX)) - #define UART_RX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0RXD_IN_IDX : (uartNumber == UART_NUM_1 ? U1RXD_IN_IDX : U2RXD_IN_IDX)) +#define UART_TX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0TXD_OUT_IDX : (uartNumber == UART_NUM_1 ? U1TXD_OUT_IDX : U2TXD_OUT_IDX)) +#define UART_RX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0RXD_IN_IDX : (uartNumber == UART_NUM_1 ? U1RXD_IN_IDX : U2RXD_IN_IDX)) #else - #define UART_TX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0TXD_OUT_IDX : U1TXD_OUT_IDX) - #define UART_RX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0RXD_IN_IDX : U1RXD_IN_IDX) +#define UART_TX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0TXD_OUT_IDX : U1TXD_OUT_IDX) +#define UART_RX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0RXD_IN_IDX : U1RXD_IN_IDX) #endif /* This function internally binds defined UARTs TX signal with defined RX pin of any UART (same or different). This creates a loop that lets us receive anything we send on the UART without external wires. */ -void uart_internal_loopback(uint8_t uartNum, int8_t rxPin) -{ +void uart_internal_loopback(uint8_t uartNum, int8_t rxPin) { if (uartNum > SOC_UART_NUM - 1 || !GPIO_IS_VALID_GPIO(rxPin)) return; esp_rom_gpio_connect_out_signal(rxPin, UART_TX_SIGNAL(uartNum), false, false); } @@ -1123,24 +1089,21 @@ void uart_internal_loopback(uint8_t uartNum, int8_t rxPin) */ // Forces a BREAK in the line based on SERIAL_8N1 configuration at any baud rate -void uart_send_break(uint8_t uartNum) -{ +void uart_send_break(uint8_t uartNum) { uint32_t currentBaudrate = 0; uart_get_baudrate(uartNum, ¤tBaudrate); // calculates 10 bits of breaks in microseconds for baudrates up to 500mbps - // This is very sensetive timing... it works fine for SERIAL_8N1 - uint32_t breakTime = (uint32_t) (10.0 * (1000000.0 / currentBaudrate)); + // This is very sensitive timing... it works fine for SERIAL_8N1 + uint32_t breakTime = (uint32_t)(10.0 * (1000000.0 / currentBaudrate)); uart_set_line_inverse(uartNum, UART_SIGNAL_TXD_INV); esp_rom_delay_us(breakTime); uart_set_line_inverse(uartNum, UART_SIGNAL_INV_DISABLE); } // Sends a buffer and at the end of the stream, it generates BREAK in the line -int uart_send_msg_with_break(uint8_t uartNum, uint8_t *msg, size_t msgSize) -{ +int uart_send_msg_with_break(uint8_t uartNum, uint8_t* msg, size_t msgSize) { // 12 bits long BREAK for 8N1 - return uart_write_bytes_with_break(uartNum, (const void *)msg, msgSize, 12); + return uart_write_bytes_with_break(uartNum, (const void*)msg, msgSize, 12); } #endif /* SOC_UART_SUPPORTED */ - diff --git a/cores/esp32/esp32-hal-uart.h b/cores/esp32/esp32-hal-uart.h index b33c7bc75fe..abc99294abb 100644 --- a/cores/esp32/esp32-hal-uart.h +++ b/cores/esp32/esp32-hal-uart.h @@ -29,86 +29,86 @@ extern "C" { #include "freertos/queue.h" #include "hal/uart_types.h" -struct uart_struct_t; -typedef struct uart_struct_t uart_t; + struct uart_struct_t; + typedef struct uart_struct_t uart_t; -bool _testUartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd); -uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd); -void uartEnd(uint8_t uart_num); + bool _testUartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd); + uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd); + void uartEnd(uint8_t uart_num); -// This is used to retrieve the Event Queue pointer from a UART IDF Driver in order to allow user to deal with its events -void uartGetEventQueue(uart_t* uart, QueueHandle_t *q); + // This is used to retrieve the Event Queue pointer from a UART IDF Driver in order to allow user to deal with its events + void uartGetEventQueue(uart_t* uart, QueueHandle_t* q); -uint32_t uartAvailable(uart_t* uart); -uint32_t uartAvailableForWrite(uart_t* uart); -size_t uartReadBytes(uart_t* uart, uint8_t *buffer, size_t size, uint32_t timeout_ms); -uint8_t uartRead(uart_t* uart); -uint8_t uartPeek(uart_t* uart); + uint32_t uartAvailable(uart_t* uart); + uint32_t uartAvailableForWrite(uart_t* uart); + size_t uartReadBytes(uart_t* uart, uint8_t* buffer, size_t size, uint32_t timeout_ms); + uint8_t uartRead(uart_t* uart); + uint8_t uartPeek(uart_t* uart); -void uartWrite(uart_t* uart, uint8_t c); -void uartWriteBuf(uart_t* uart, const uint8_t * data, size_t len); + void uartWrite(uart_t* uart, uint8_t c); + void uartWriteBuf(uart_t* uart, const uint8_t* data, size_t len); -void uartFlush(uart_t* uart); -void uartFlushTxOnly(uart_t* uart, bool txOnly ); + void uartFlush(uart_t* uart); + void uartFlushTxOnly(uart_t* uart, bool txOnly); -void uartSetBaudRate(uart_t* uart, uint32_t baud_rate); -uint32_t uartGetBaudRate(uart_t* uart); + void uartSetBaudRate(uart_t* uart, uint32_t baud_rate); + uint32_t uartGetBaudRate(uart_t* uart); -void uartSetRxInvert(uart_t* uart, bool invert); -bool uartSetRxTimeout(uart_t* uart, uint8_t numSymbTimeout); -bool uartSetRxFIFOFull(uart_t* uart, uint8_t numBytesFIFOFull); -void uartSetFastReading(uart_t* uart); + void uartSetRxInvert(uart_t* uart, bool invert); + bool uartSetRxTimeout(uart_t* uart, uint8_t numSymbTimeout); + bool uartSetRxFIFOFull(uart_t* uart, uint8_t numBytesFIFOFull); + void uartSetFastReading(uart_t* uart); -void uartSetDebug(uart_t* uart); -int uartGetDebug(); + void uartSetDebug(uart_t* uart); + int uartGetDebug(); -bool uartIsDriverInstalled(uart_t* uart); + bool uartIsDriverInstalled(uart_t* uart); -// Negative Pin Number will keep it unmodified, thus this function can set individual pins -// When pins are changed, it will detach the previous ones -// Can be called before or after begin() -bool uartSetPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin); + // Negative Pin Number will keep it unmodified, thus this function can set individual pins + // When pins are changed, it will detach the previous ones + // Can be called before or after begin() + bool uartSetPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin); -// helper functions -int8_t uart_get_RxPin(uint8_t uart_num); -int8_t uart_get_TxPin(uint8_t uart_num); -void uart_init_PeriMan(void); + // helper functions + int8_t uart_get_RxPin(uint8_t uart_num); + int8_t uart_get_TxPin(uint8_t uart_num); + void uart_init_PeriMan(void); -// Enables or disables HW Flow Control function -- needs also to set CTS and/or RTS pins -// UART_HW_FLOWCTRL_DISABLE = 0x0 disable hardware flow control -// UART_HW_FLOWCTRL_RTS = 0x1 enable RX hardware flow control (rts) -// UART_HW_FLOWCTRL_CTS = 0x2 enable TX hardware flow control (cts) -// UART_HW_FLOWCTRL_CTS_RTS = 0x3 enable hardware flow control -bool uartSetHwFlowCtrlMode(uart_t *uart, uart_hw_flowcontrol_t mode, uint8_t threshold); + // Enables or disables HW Flow Control function -- needs also to set CTS and/or RTS pins + // UART_HW_FLOWCTRL_DISABLE = 0x0 disable hardware flow control + // UART_HW_FLOWCTRL_RTS = 0x1 enable RX hardware flow control (rts) + // UART_HW_FLOWCTRL_CTS = 0x2 enable TX hardware flow control (cts) + // UART_HW_FLOWCTRL_CTS_RTS = 0x3 enable hardware flow control + bool uartSetHwFlowCtrlMode(uart_t* uart, uart_hw_flowcontrol_t mode, uint8_t threshold); -// Used to set RS485 function -- needs to disable HW Flow Control and set RTS pin to use -// RTS pin becomes RS485 half duplex RE/DE -// UART_MODE_UART = 0x00 mode: regular UART mode -// UART_MODE_RS485_HALF_DUPLEX = 0x01 mode: half duplex RS485 UART mode control by RTS pin -// UART_MODE_IRDA = 0x02 mode: IRDA UART mode -// UART_MODE_RS485_COLLISION_DETECT = 0x03 mode: RS485 collision detection UART mode (used for test purposes) -// UART_MODE_RS485_APP_CTRL = 0x04 mode: application control RS485 UART mode (used for test purposes) -bool uartSetMode(uart_t *uart, uart_mode_t mode); + // Used to set RS485 function -- needs to disable HW Flow Control and set RTS pin to use + // RTS pin becomes RS485 half duplex RE/DE + // UART_MODE_UART = 0x00 mode: regular UART mode + // UART_MODE_RS485_HALF_DUPLEX = 0x01 mode: half duplex RS485 UART mode control by RTS pin + // UART_MODE_IRDA = 0x02 mode: IRDA UART mode + // UART_MODE_RS485_COLLISION_DETECT = 0x03 mode: RS485 collision detection UART mode (used for test purposes) + // UART_MODE_RS485_APP_CTRL = 0x04 mode: application control RS485 UART mode (used for test purposes) + bool uartSetMode(uart_t* uart, uart_mode_t mode); -void uartStartDetectBaudrate(uart_t *uart); -unsigned long uartDetectBaudrate(uart_t *uart); + void uartStartDetectBaudrate(uart_t* uart); + unsigned long uartDetectBaudrate(uart_t* uart); -/* + /* These functions are for testing puspose only and can be used in Arduino Sketches Those are used in the UART examples */ -// Make sure UART's RX signal is connected to TX pin -// This creates a loop that lets us receive anything we send on the UART -void uart_internal_loopback(uint8_t uartNum, int8_t rxPin); + // Make sure UART's RX signal is connected to TX pin + // This creates a loop that lets us receive anything we send on the UART + void uart_internal_loopback(uint8_t uartNum, int8_t rxPin); -// Routines that generate BREAK in the UART for testing purpose + // Routines that generate BREAK in the UART for testing purpose -// Forces a BREAK in the line based on SERIAL_8N1 configuration at any baud rate -void uart_send_break(uint8_t uartNum); -// Sends a buffer and at the end of the stream, it generates BREAK in the line -int uart_send_msg_with_break(uint8_t uartNum, uint8_t *msg, size_t msgSize); + // Forces a BREAK in the line based on SERIAL_8N1 configuration at any baud rate + void uart_send_break(uint8_t uartNum); + // Sends a buffer and at the end of the stream, it generates BREAK in the line + int uart_send_msg_with_break(uint8_t uartNum, uint8_t* msg, size_t msgSize); #ifdef __cplusplus diff --git a/cores/esp32/esp32-hal.h b/cores/esp32/esp32-hal.h index 2f53bb2ff66..8aa123a6f99 100644 --- a/cores/esp32/esp32-hal.h +++ b/cores/esp32/esp32-hal.h @@ -61,13 +61,13 @@ extern "C" { #define ARDUINO_EVENT_RUNNING_CORE CONFIG_ARDUINO_EVENT_RUNNING_CORE #endif -//forward declaration from freertos/portmacro.h -void vPortYield(void); -void yield(void); + //forward declaration from freertos/portmacro.h + void vPortYield(void); + void yield(void); #define optimistic_yield(u) -#define ESP_REG(addr) *((volatile uint32_t *)(addr)) -#define NOP() asm volatile ("nop") +#define ESP_REG(addr) *((volatile uint32_t*)(addr)) +#define NOP() asm volatile("nop") #include "esp32-hal-log.h" #include "esp32-hal-matrix.h" @@ -87,71 +87,71 @@ void yield(void); #include "esp32-hal-rgb-led.h" #include "esp32-hal-cpu.h" -void analogWrite(uint8_t pin, int value); -void analogWriteFrequency(uint8_t pin, uint32_t freq); -void analogWriteResolution(uint8_t pin, uint8_t bits); + void analogWrite(uint8_t pin, int value); + void analogWriteFrequency(uint8_t pin, uint32_t freq); + void analogWriteResolution(uint8_t pin, uint8_t bits); -//returns chip temperature in Celsius -float temperatureRead(); + //returns chip temperature in Celsius + float temperatureRead(); -//allows user to bypass SPI RAM test routine -bool testSPIRAM(void); + //allows user to bypass SPI RAM test routine + bool testSPIRAM(void); #if CONFIG_AUTOSTART_ARDUINO -//enable/disable WDT for Arduino's setup and loop functions -void enableLoopWDT(); -void disableLoopWDT(); -//feed WDT for the loop task -void feedLoopWDT(); + //enable/disable WDT for Arduino's setup and loop functions + void enableLoopWDT(); + void disableLoopWDT(); + //feed WDT for the loop task + void feedLoopWDT(); #endif -//enable/disable WDT for the IDLE task on Core 0 (SYSTEM) -void enableCore0WDT(); -void disableCore0WDT(); + //enable/disable WDT for the IDLE task on Core 0 (SYSTEM) + void enableCore0WDT(); + void disableCore0WDT(); #ifndef CONFIG_FREERTOS_UNICORE -//enable/disable WDT for the IDLE task on Core 1 (Arduino) -void enableCore1WDT(); -void disableCore1WDT(); + //enable/disable WDT for the IDLE task on Core 1 (Arduino) + void enableCore1WDT(); + void disableCore1WDT(); #endif -//if xCoreID < 0 or CPU is unicore, it will use xTaskCreate, else xTaskCreatePinnedToCore -//allows to easily handle all possible situations without repetitive code -BaseType_t xTaskCreateUniversal( TaskFunction_t pxTaskCode, - const char * const pcName, - const uint32_t usStackDepth, - void * const pvParameters, - UBaseType_t uxPriority, - TaskHandle_t * const pxCreatedTask, - const BaseType_t xCoreID ); - -unsigned long micros(); -unsigned long millis(); -void delay(uint32_t); -void delayMicroseconds(uint32_t us); + //if xCoreID < 0 or CPU is unicore, it will use xTaskCreate, else xTaskCreatePinnedToCore + //allows to easily handle all possible situations without repetitive code + BaseType_t xTaskCreateUniversal(TaskFunction_t pxTaskCode, + const char* const pcName, + const uint32_t usStackDepth, + void* const pvParameters, + UBaseType_t uxPriority, + TaskHandle_t* const pxCreatedTask, + const BaseType_t xCoreID); + + unsigned long micros(); + unsigned long millis(); + void delay(uint32_t); + void delayMicroseconds(uint32_t us); #if !CONFIG_ESP32_PHY_AUTO_INIT -void arduino_phy_init(); + void arduino_phy_init(); #endif #if !CONFIG_AUTOSTART_ARDUINO -void initArduino(); + void initArduino(); #endif -typedef struct { - int core; // core which triggered panic - const char* reason; // exception string - const void* pc; // instruction address that triggered the exception - bool backtrace_corrupt; // if backtrace is corrupt - bool backtrace_continues; // if backtrace continues, but did not fit - unsigned int backtrace_len; // number of backtrace addresses - unsigned int backtrace[60]; // backtrace addresses array -} arduino_panic_info_t; - -typedef void (*arduino_panic_handler_t)(arduino_panic_info_t * info, void * arg); - -void set_arduino_panic_handler(arduino_panic_handler_t handler, void * arg); -arduino_panic_handler_t get_arduino_panic_handler(void); -void * get_arduino_panic_handler_arg(void); + typedef struct { + int core; // core which triggered panic + const char* reason; // exception string + const void* pc; // instruction address that triggered the exception + bool backtrace_corrupt; // if backtrace is corrupt + bool backtrace_continues; // if backtrace continues, but did not fit + unsigned int backtrace_len; // number of backtrace addresses + unsigned int backtrace[60]; // backtrace addresses array + } arduino_panic_info_t; + + typedef void (*arduino_panic_handler_t)(arduino_panic_info_t* info, void* arg); + + void set_arduino_panic_handler(arduino_panic_handler_t handler, void* arg); + arduino_panic_handler_t get_arduino_panic_handler(void); + void* get_arduino_panic_handler_arg(void); #ifdef __cplusplus } diff --git a/cores/esp32/esp8266-compat.h b/cores/esp32/esp8266-compat.h index 9f9dd632bf7..7c21481bd72 100644 --- a/cores/esp32/esp8266-compat.h +++ b/cores/esp32/esp8266-compat.h @@ -21,4 +21,4 @@ #define ICACHE_RAM_ATTR ARDUINO_ISR_ATTR -#endif /* _ESP8266_COMPAT_H_ */ \ No newline at end of file +#endif /* _ESP8266_COMPAT_H_ */ diff --git a/cores/esp32/esp_arduino_version.h b/cores/esp32/esp_arduino_version.h index e319d97cad3..0f60d88d0ce 100644 --- a/cores/esp32/esp_arduino_version.h +++ b/cores/esp32/esp_arduino_version.h @@ -19,11 +19,11 @@ extern "C" { #endif /** Major version number (X.x.x) */ -#define ESP_ARDUINO_VERSION_MAJOR 3 +#define ESP_ARDUINO_VERSION_MAJOR 3 /** Minor version number (x.X.x) */ -#define ESP_ARDUINO_VERSION_MINOR 0 +#define ESP_ARDUINO_VERSION_MINOR 0 /** Patch version number (x.x.X) */ -#define ESP_ARDUINO_VERSION_PATCH 0 +#define ESP_ARDUINO_VERSION_PATCH 0 /** * Macro to convert ARDUINO version number into an integer @@ -37,9 +37,9 @@ extern "C" { * * To be used in comparisons, such as ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0) */ -#define ESP_ARDUINO_VERSION ESP_ARDUINO_VERSION_VAL(ESP_ARDUINO_VERSION_MAJOR, \ - ESP_ARDUINO_VERSION_MINOR, \ - ESP_ARDUINO_VERSION_PATCH) +#define ESP_ARDUINO_VERSION ESP_ARDUINO_VERSION_VAL(ESP_ARDUINO_VERSION_MAJOR, \ + ESP_ARDUINO_VERSION_MINOR, \ + ESP_ARDUINO_VERSION_PATCH) /** * Current ARDUINO version, as string diff --git a/cores/esp32/firmware_msc_fat.c b/cores/esp32/firmware_msc_fat.c index 30a1a64ea21..7dfe6c8c096 100644 --- a/cores/esp32/firmware_msc_fat.c +++ b/cores/esp32/firmware_msc_fat.c @@ -14,47 +14,47 @@ #include "firmware_msc_fat.h" //copy up to max_len chars from src to dst and do not terminate -static size_t cplstr(void *dst, const void * src, size_t max_len){ - if(!src || !dst || !max_len){ - return 0; - } - size_t l = strlen((const char *)src); - if(l > max_len){ - l = max_len; - } - memcpy(dst, src, l); - return l; +static size_t cplstr(void *dst, const void *src, size_t max_len) { + if (!src || !dst || !max_len) { + return 0; + } + size_t l = strlen((const char *)src); + if (l > max_len) { + l = max_len; + } + memcpy(dst, src, l); + return l; } //copy up to max_len chars from src to dst, adding spaces up to max_len. do not terminate -static void cplstrsp(void *dst, const void * src, size_t max_len){ - size_t l = cplstr(dst, src, max_len); - for(; l < max_len; l++){ - ((uint8_t*)dst)[l] = 0x20; - } +static void cplstrsp(void *dst, const void *src, size_t max_len) { + size_t l = cplstr(dst, src, max_len); + for (; l < max_len; l++) { + ((uint8_t *)dst)[l] = 0x20; + } } // FAT12 -static const char * FAT12_FILE_SYSTEM_TYPE = "FAT12"; +static const char *FAT12_FILE_SYSTEM_TYPE = "FAT12"; -static uint16_t fat12_sectors_per_alloc_table(uint32_t sector_num){ - uint32_t required_bytes = (((sector_num * 3)+1)/2); - return (required_bytes / DISK_SECTOR_SIZE) + ((required_bytes & (DISK_SECTOR_SIZE - 1))?1:0); +static uint16_t fat12_sectors_per_alloc_table(uint32_t sector_num) { + uint32_t required_bytes = (((sector_num * 3) + 1) / 2); + return (required_bytes / DISK_SECTOR_SIZE) + ((required_bytes & (DISK_SECTOR_SIZE - 1)) ? 1 : 0); } -static uint8_t * fat12_add_table(uint8_t * dst, fat_boot_sector_t * boot){ - memset(dst+DISK_SECTOR_SIZE, 0, boot->sectors_per_alloc_table * DISK_SECTOR_SIZE); - uint8_t * d = dst + DISK_SECTOR_SIZE; +static uint8_t *fat12_add_table(uint8_t *dst, fat_boot_sector_t *boot) { + memset(dst + DISK_SECTOR_SIZE, 0, boot->sectors_per_alloc_table * DISK_SECTOR_SIZE); + uint8_t *d = dst + DISK_SECTOR_SIZE; d[0] = 0xF8; d[1] = 0xFF; d[2] = 0xFF; return d; } -static void fat12_set_table_index(uint8_t * table, uint16_t index, uint16_t value){ +static void fat12_set_table_index(uint8_t *table, uint16_t index, uint16_t value) { uint16_t offset = (index >> 1) * 3; - uint8_t * data = table + offset; - if(index & 1){ + uint8_t *data = table + offset; + if (index & 1) { data[2] = (value >> 4) & 0xFF; data[1] = (data[1] & 0xF) | ((value & 0xF) << 4); } else { @@ -64,55 +64,55 @@ static void fat12_set_table_index(uint8_t * table, uint16_t index, uint16_t valu } //FAT16 -static const char * FAT16_FILE_SYSTEM_TYPE = "FAT16"; +static const char *FAT16_FILE_SYSTEM_TYPE = "FAT16"; -static uint16_t fat16_sectors_per_alloc_table(uint32_t sector_num){ +static uint16_t fat16_sectors_per_alloc_table(uint32_t sector_num) { uint32_t required_bytes = sector_num * 2; - return (required_bytes / DISK_SECTOR_SIZE) + ((required_bytes & (DISK_SECTOR_SIZE - 1))?1:0); + return (required_bytes / DISK_SECTOR_SIZE) + ((required_bytes & (DISK_SECTOR_SIZE - 1)) ? 1 : 0); } -static uint8_t * fat16_add_table(uint8_t * dst, fat_boot_sector_t * boot){ - memset(dst+DISK_SECTOR_SIZE, 0, boot->sectors_per_alloc_table * DISK_SECTOR_SIZE); - uint16_t * d = (uint16_t *)(dst + DISK_SECTOR_SIZE); +static uint8_t *fat16_add_table(uint8_t *dst, fat_boot_sector_t *boot) { + memset(dst + DISK_SECTOR_SIZE, 0, boot->sectors_per_alloc_table * DISK_SECTOR_SIZE); + uint16_t *d = (uint16_t *)(dst + DISK_SECTOR_SIZE); d[0] = 0xFFF8; d[1] = 0xFFFF; return (uint8_t *)d; } -static void fat16_set_table_index(uint8_t * table, uint16_t index, uint16_t value){ +static void fat16_set_table_index(uint8_t *table, uint16_t index, uint16_t value) { uint16_t offset = index * 2; *(uint16_t *)(table + offset) = value; } //Interface -const char * fat_file_system_type(bool fat16) { - return ((fat16)?FAT16_FILE_SYSTEM_TYPE:FAT12_FILE_SYSTEM_TYPE); +const char *fat_file_system_type(bool fat16) { + return ((fat16) ? FAT16_FILE_SYSTEM_TYPE : FAT12_FILE_SYSTEM_TYPE); } -uint16_t fat_sectors_per_alloc_table(uint32_t sector_num, bool fat16){ - if(fat16){ +uint16_t fat_sectors_per_alloc_table(uint32_t sector_num, bool fat16) { + if (fat16) { return fat16_sectors_per_alloc_table(sector_num); } return fat12_sectors_per_alloc_table(sector_num); } -uint8_t * fat_add_table(uint8_t * dst, fat_boot_sector_t * boot, bool fat16){ - if(fat16){ +uint8_t *fat_add_table(uint8_t *dst, fat_boot_sector_t *boot, bool fat16) { + if (fat16) { return fat16_add_table(dst, boot); } return fat12_add_table(dst, boot); } -void fat_set_table_index(uint8_t * table, uint16_t index, uint16_t value, bool fat16){ - if(fat16){ +void fat_set_table_index(uint8_t *table, uint16_t index, uint16_t value, bool fat16) { + if (fat16) { fat16_set_table_index(table, index, value); } else { fat12_set_table_index(table, index, value); } } -fat_boot_sector_t * fat_add_boot_sector(uint8_t * dst, uint16_t sector_num, uint16_t table_sectors, const char * file_system_type, const char * volume_label, uint32_t serial_number){ - fat_boot_sector_t *boot = (fat_boot_sector_t*)dst; +fat_boot_sector_t *fat_add_boot_sector(uint8_t *dst, uint16_t sector_num, uint16_t table_sectors, const char *file_system_type, const char *volume_label, uint32_t serial_number) { + fat_boot_sector_t *boot = (fat_boot_sector_t *)dst; boot->jump_instruction[0] = 0xEB; boot->jump_instruction[1] = 0x3C; boot->jump_instruction[2] = 0x90; @@ -140,19 +140,19 @@ fat_boot_sector_t * fat_add_boot_sector(uint8_t * dst, uint16_t sector_num, uint return boot; } -fat_dir_entry_t * fat_add_label(uint8_t * dst, const char * volume_label){ - fat_boot_sector_t * boot = (fat_boot_sector_t *)dst; - fat_dir_entry_t * entry = (fat_dir_entry_t *)(dst + ((boot->sectors_per_alloc_table+1) * DISK_SECTOR_SIZE)); +fat_dir_entry_t *fat_add_label(uint8_t *dst, const char *volume_label) { + fat_boot_sector_t *boot = (fat_boot_sector_t *)dst; + fat_dir_entry_t *entry = (fat_dir_entry_t *)(dst + ((boot->sectors_per_alloc_table + 1) * DISK_SECTOR_SIZE)); memset(entry, 0, sizeof(fat_dir_entry_t)); cplstrsp(entry->volume_label, volume_label, 11); entry->file_attr = FAT_FILE_ATTR_VOLUME_LABEL; return entry; } -fat_dir_entry_t * fat_add_root_file(uint8_t * dst, uint8_t index, const char * file_name, const char * file_extension, size_t file_size, uint16_t data_start_sector, bool is_fat16){ - fat_boot_sector_t * boot = (fat_boot_sector_t *)dst; - uint8_t * table = dst + DISK_SECTOR_SIZE; - fat_dir_entry_t * entry = (fat_dir_entry_t *)(dst + ((boot->sectors_per_alloc_table+1) * DISK_SECTOR_SIZE) + (index * sizeof(fat_dir_entry_t))); +fat_dir_entry_t *fat_add_root_file(uint8_t *dst, uint8_t index, const char *file_name, const char *file_extension, size_t file_size, uint16_t data_start_sector, bool is_fat16) { + fat_boot_sector_t *boot = (fat_boot_sector_t *)dst; + uint8_t *table = dst + DISK_SECTOR_SIZE; + fat_dir_entry_t *entry = (fat_dir_entry_t *)(dst + ((boot->sectors_per_alloc_table + 1) * DISK_SECTOR_SIZE) + (index * sizeof(fat_dir_entry_t))); memset(entry, 0, sizeof(fat_dir_entry_t)); cplstrsp(entry->file_name, file_name, 8); cplstrsp(entry->file_extension, file_extension, 3); @@ -162,25 +162,27 @@ fat_dir_entry_t * fat_add_root_file(uint8_t * dst, uint8_t index, const char * f entry->extended_attr = 0; uint16_t file_sectors = file_size / DISK_SECTOR_SIZE; - if(file_size % DISK_SECTOR_SIZE){ + if (file_size % DISK_SECTOR_SIZE) { file_sectors++; } uint16_t data_end_sector = data_start_sector + file_sectors; - for(uint16_t i=data_start_sector; i<(data_end_sector-1); i++){ - fat_set_table_index(table, i, i+1, is_fat16); + for (uint16_t i = data_start_sector; i < (data_end_sector - 1); i++) { + fat_set_table_index(table, i, i + 1, is_fat16); } - fat_set_table_index(table, data_end_sector-1, 0xFFFF, is_fat16); + fat_set_table_index(table, data_end_sector - 1, 0xFFFF, is_fat16); //Set Firmware Date based on the build time - static const char * month_names_short[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - char mstr[8] = {'\0',}; + static const char *month_names_short[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; + char mstr[8] = { + '\0', + }; const char *str = __DATE__ " " __TIME__; - int ms=0, seconds=0, minutes=0, hours=0, year=0, date=0, month=0; - int r = sscanf(str,"%s %d %d %d:%d:%d", mstr, &date, &year, &hours, &minutes, &seconds); - if(r >= 0){ - for(int i=0; i<12; i++){ - if(!strcmp(mstr, month_names_short[i])){ + int ms = 0, seconds = 0, minutes = 0, hours = 0, year = 0, date = 0, month = 0; + int r = sscanf(str, "%s %d %d %d:%d:%d", mstr, &date, &year, &hours, &minutes, &seconds); + if (r >= 0) { + for (int i = 0; i < 12; i++) { + if (!strcmp(mstr, month_names_short[i])) { month = i; break; } @@ -195,10 +197,10 @@ fat_dir_entry_t * fat_add_root_file(uint8_t * dst, uint8_t index, const char * f return entry; } -uint8_t fat_lfn_checksum(const uint8_t *short_filename){ - uint8_t sum = 0; - for (uint8_t i = 11; i; i--) { - sum = ((sum & 1) << 7) + (sum >> 1) + *short_filename++; - } - return sum; +uint8_t fat_lfn_checksum(const uint8_t *short_filename) { + uint8_t sum = 0; + for (uint8_t i = 11; i; i--) { + sum = ((sum & 1) << 7) + (sum >> 1) + *short_filename++; + } + return sum; } diff --git a/cores/esp32/firmware_msc_fat.h b/cores/esp32/firmware_msc_fat.h index dd88cdc7a0d..3b26465bf08 100644 --- a/cores/esp32/firmware_msc_fat.h +++ b/cores/esp32/firmware_msc_fat.h @@ -21,121 +21,121 @@ #include #ifdef __cplusplus - extern "C" { +extern "C" { #endif -#define FAT_U8(v) ((v) & 0xFF) +#define FAT_U8(v) ((v)&0xFF) #define FAT_U16(v) FAT_U8(v), FAT_U8((v) >> 8) #define FAT_U32(v) FAT_U8(v), FAT_U8((v) >> 8), FAT_U8((v) >> 16), FAT_U8((v) >> 24) -#define FAT12_TBL2B(l,h) FAT_U8(l), FAT_U8(((l >> 8) & 0xF) | ((h << 4) & 0xF0)), FAT_U8(h >> 4) - -#define FAT_MS2B(s,ms) FAT_U8(((((s) & 0x1) * 1000) + (ms)) / 10) -#define FAT_HMS2B(h,m,s) FAT_U8(((s) >> 1)|(((m) & 0x7) << 5)), FAT_U8((((m) >> 3) & 0x7)|((h) << 3)) -#define FAT_YMD2B(y,m,d) FAT_U8(((d) & 0x1F)|(((m) & 0x7) << 5)), FAT_U8((((m) >> 3) & 0x1)|((((y) - 1980) & 0x7F) << 1)) - -#define FAT_MS2V(s,ms) FAT_U8(((((s) & 0x1) * 1000) + (ms)) / 10) -#define FAT_HMS2V(h,m,s) (FAT_U8(((s) >> 1)|(((m) & 0x7) << 5)) | (FAT_U8((((m) >> 3) & 0x7)|((h) << 3)) << 8)) -#define FAT_YMD2V(y,m,d) (FAT_U8(((d) & 0x1F)|(((m) & 0x7) << 5)) | (FAT_U8((((m) >> 3) & 0x1)|((((y) - 1980) & 0x7F) << 1)) << 8)) - -#define FAT_B2HMS(hms) ((hms >> 11) & 0x1F), ((hms >> 5) & 0x3F), ((hms & 0x1F) << 1) -#define FAT_B2YMD(ymd) (((ymd >> 9) & 0x7F) + 1980), ((ymd >> 5) & 0x0F), (ymd & 0x1F) - -#define FAT_FILE_ATTR_READ_ONLY 0x01 -#define FAT_FILE_ATTR_HIDDEN 0x02 -#define FAT_FILE_ATTR_SYSTEM 0x04 -#define FAT_FILE_ATTR_VOLUME_LABEL 0x08 -#define FAT_FILE_ATTR_SUBDIRECTORY 0x10 -#define FAT_FILE_ATTR_ARCHIVE 0x20 -#define FAT_FILE_ATTR_DEVICE 0x40 - -static const uint16_t DISK_SECTOR_SIZE = 512; - -#define FAT_SIZE_TO_SECTORS(bytes) ((bytes) / DISK_SECTOR_SIZE) + (((bytes) % DISK_SECTOR_SIZE)?1:0) - -typedef struct __attribute__ ((packed)) { - uint8_t jump_instruction[3]; - char oem_name[8];//padded with spaces (0x20) - uint16_t bytes_per_sector;//DISK_SECTOR_SIZE usually 512 - uint8_t sectors_per_cluster;//Allowed values are 1, 2, 4, 8, 16, 32, 64, and 128 - uint16_t reserved_sectors_count;//At least 1 for this sector, usually 32 for FAT32 - uint8_t file_alloc_tables_num;//Almost always 2; RAM disks might use 1 - uint16_t max_root_dir_entries;//FAT12 and FAT16 - uint16_t fat12_sector_num;//DISK_SECTOR_NUM FAT12 and FAT16 - uint8_t media_descriptor; - uint16_t sectors_per_alloc_table;//FAT12 and FAT16 - uint16_t sectors_per_track;//A value of 0 may indicate LBA-only access - uint16_t num_heads; - uint32_t hidden_sectors_count; - uint32_t total_sectors_32; - uint8_t physical_drive_number;//0x00 for (first) removable media, 0x80 for (first) fixed disk - uint8_t reserved0; - uint8_t extended_boot_signature;//should be 0x29 - uint32_t serial_number;//0x1234 => 1234 - char volume_label[11];//padded with spaces (0x20) - char file_system_type[8];//padded with spaces (0x20) - uint8_t reserved[448]; - uint16_t signature;//should be 0xAA55 -} fat_boot_sector_t; - -typedef struct __attribute__ ((packed)) { - union { - struct { - char file_name[8];//padded with spaces (0x20) - char file_extension[3];//padded with spaces (0x20) +#define FAT12_TBL2B(l, h) FAT_U8(l), FAT_U8(((l >> 8) & 0xF) | ((h << 4) & 0xF0)), FAT_U8(h >> 4) + +#define FAT_MS2B(s, ms) FAT_U8(((((s)&0x1) * 1000) + (ms)) / 10) +#define FAT_HMS2B(h, m, s) FAT_U8(((s) >> 1) | (((m)&0x7) << 5)), FAT_U8((((m) >> 3) & 0x7) | ((h) << 3)) +#define FAT_YMD2B(y, m, d) FAT_U8(((d)&0x1F) | (((m)&0x7) << 5)), FAT_U8((((m) >> 3) & 0x1) | ((((y)-1980) & 0x7F) << 1)) + +#define FAT_MS2V(s, ms) FAT_U8(((((s)&0x1) * 1000) + (ms)) / 10) +#define FAT_HMS2V(h, m, s) (FAT_U8(((s) >> 1) | (((m)&0x7) << 5)) | (FAT_U8((((m) >> 3) & 0x7) | ((h) << 3)) << 8)) +#define FAT_YMD2V(y, m, d) (FAT_U8(((d)&0x1F) | (((m)&0x7) << 5)) | (FAT_U8((((m) >> 3) & 0x1) | ((((y)-1980) & 0x7F) << 1)) << 8)) + +#define FAT_B2HMS(hms) ((hms >> 11) & 0x1F), ((hms >> 5) & 0x3F), ((hms & 0x1F) << 1) +#define FAT_B2YMD(ymd) (((ymd >> 9) & 0x7F) + 1980), ((ymd >> 5) & 0x0F), (ymd & 0x1F) + +#define FAT_FILE_ATTR_READ_ONLY 0x01 +#define FAT_FILE_ATTR_HIDDEN 0x02 +#define FAT_FILE_ATTR_SYSTEM 0x04 +#define FAT_FILE_ATTR_VOLUME_LABEL 0x08 +#define FAT_FILE_ATTR_SUBDIRECTORY 0x10 +#define FAT_FILE_ATTR_ARCHIVE 0x20 +#define FAT_FILE_ATTR_DEVICE 0x40 + + static const uint16_t DISK_SECTOR_SIZE = 512; + +#define FAT_SIZE_TO_SECTORS(bytes) ((bytes) / DISK_SECTOR_SIZE) + (((bytes) % DISK_SECTOR_SIZE) ? 1 : 0) + + typedef struct __attribute__((packed)) { + uint8_t jump_instruction[3]; + char oem_name[8]; //padded with spaces (0x20) + uint16_t bytes_per_sector; //DISK_SECTOR_SIZE usually 512 + uint8_t sectors_per_cluster; //Allowed values are 1, 2, 4, 8, 16, 32, 64, and 128 + uint16_t reserved_sectors_count; //At least 1 for this sector, usually 32 for FAT32 + uint8_t file_alloc_tables_num; //Almost always 2; RAM disks might use 1 + uint16_t max_root_dir_entries; //FAT12 and FAT16 + uint16_t fat12_sector_num; //DISK_SECTOR_NUM FAT12 and FAT16 + uint8_t media_descriptor; + uint16_t sectors_per_alloc_table; //FAT12 and FAT16 + uint16_t sectors_per_track; //A value of 0 may indicate LBA-only access + uint16_t num_heads; + uint32_t hidden_sectors_count; + uint32_t total_sectors_32; + uint8_t physical_drive_number; //0x00 for (first) removable media, 0x80 for (first) fixed disk + uint8_t reserved0; + uint8_t extended_boot_signature; //should be 0x29 + uint32_t serial_number; //0x1234 => 1234 + char volume_label[11]; //padded with spaces (0x20) + char file_system_type[8]; //padded with spaces (0x20) + uint8_t reserved[448]; + uint16_t signature; //should be 0xAA55 + } fat_boot_sector_t; + + typedef struct __attribute__((packed)) { + union { + struct { + char file_name[8]; //padded with spaces (0x20) + char file_extension[3]; //padded with spaces (0x20) + }; + struct { + uint8_t file_magic; // 0xE5:deleted, 0x05:will_be_deleted, 0x00:end_marker, 0x2E:dot_marker(. or ..) + char file_magic_data[10]; + }; + char volume_label[11]; //padded with spaces (0x20) }; - struct { - uint8_t file_magic;// 0xE5:deleted, 0x05:will_be_deleted, 0x00:end_marker, 0x2E:dot_marker(. or ..) - char file_magic_data[10]; + uint8_t file_attr; //mask of FAT_FILE_ATTR_* + uint8_t reserved; //always 0 + uint8_t creation_time_ms; //ms * 10; max 1990 (1s 990ms) + uint16_t creation_time_hms; // [5:6:5] => h:m:(s/2) + uint16_t creation_time_ymd; // [7:4:5] => (y+1980):m:d + uint16_t last_access_ymd; + uint16_t extended_attr; + uint16_t last_modified_hms; + uint16_t last_modified_ymd; + uint16_t data_start_sector; + uint32_t file_size; + } fat_dir_entry_t; + + typedef struct __attribute__((packed)) { + union { + struct { + uint8_t number : 5; + uint8_t reserved0 : 1; + uint8_t llfp : 1; + uint8_t reserved1 : 1; + } seq; + uint8_t seq_num; //0xE5: Deleted Entry }; - char volume_label[11];//padded with spaces (0x20) - }; - uint8_t file_attr;//mask of FAT_FILE_ATTR_* - uint8_t reserved;//always 0 - uint8_t creation_time_ms;//ms * 10; max 1990 (1s 990ms) - uint16_t creation_time_hms; // [5:6:5] => h:m:(s/2) - uint16_t creation_time_ymd; // [7:4:5] => (y+1980):m:d - uint16_t last_access_ymd; - uint16_t extended_attr; - uint16_t last_modified_hms; - uint16_t last_modified_ymd; - uint16_t data_start_sector; - uint32_t file_size; -} fat_dir_entry_t; - -typedef struct __attribute__ ((packed)) { - union { - struct { - uint8_t number:5; - uint8_t reserved0:1; - uint8_t llfp:1; - uint8_t reserved1:1; - } seq; - uint8_t seq_num; //0xE5: Deleted Entry - }; - uint16_t name0[5]; - uint8_t attr; //ALWAYS 0x0F - uint8_t type; //ALWAYS 0x00 - uint8_t dos_checksum; - uint16_t name1[6]; - uint16_t first_cluster; //ALWAYS 0x0000 - uint16_t name2[2]; -} fat_lfn_entry_t; - -typedef union { - fat_dir_entry_t dir; - fat_lfn_entry_t lfn; -} fat_entry_t; - -const char * fat_file_system_type(bool fat16); -uint16_t fat_sectors_per_alloc_table(uint32_t sector_num, bool fat16); -uint8_t * fat_add_table(uint8_t * dst, fat_boot_sector_t * boot, bool fat16); -void fat_set_table_index(uint8_t * table, uint16_t index, uint16_t value, bool fat16); -fat_boot_sector_t * fat_add_boot_sector(uint8_t * dst, uint16_t sector_num, uint16_t table_sectors, const char * file_system_type, const char * volume_label, uint32_t serial_number); -fat_dir_entry_t * fat_add_label(uint8_t * dst, const char * volume_label); -fat_dir_entry_t * fat_add_root_file(uint8_t * dst, uint8_t index, const char * file_name, const char * file_extension, size_t file_size, uint16_t data_start_sector, bool is_fat16); -uint8_t fat_lfn_checksum(const uint8_t *short_filename); + uint16_t name0[5]; + uint8_t attr; //ALWAYS 0x0F + uint8_t type; //ALWAYS 0x00 + uint8_t dos_checksum; + uint16_t name1[6]; + uint16_t first_cluster; //ALWAYS 0x0000 + uint16_t name2[2]; + } fat_lfn_entry_t; + + typedef union { + fat_dir_entry_t dir; + fat_lfn_entry_t lfn; + } fat_entry_t; + + const char *fat_file_system_type(bool fat16); + uint16_t fat_sectors_per_alloc_table(uint32_t sector_num, bool fat16); + uint8_t *fat_add_table(uint8_t *dst, fat_boot_sector_t *boot, bool fat16); + void fat_set_table_index(uint8_t *table, uint16_t index, uint16_t value, bool fat16); + fat_boot_sector_t *fat_add_boot_sector(uint8_t *dst, uint16_t sector_num, uint16_t table_sectors, const char *file_system_type, const char *volume_label, uint32_t serial_number); + fat_dir_entry_t *fat_add_label(uint8_t *dst, const char *volume_label); + fat_dir_entry_t *fat_add_root_file(uint8_t *dst, uint8_t index, const char *file_name, const char *file_extension, size_t file_size, uint16_t data_start_sector, bool is_fat16); + uint8_t fat_lfn_checksum(const uint8_t *short_filename); #ifdef __cplusplus - } +} #endif diff --git a/cores/esp32/io_pin_remap.h b/cores/esp32/io_pin_remap.h index c50d4207d31..b2f70627d2a 100644 --- a/cores/esp32/io_pin_remap.h +++ b/cores/esp32/io_pin_remap.h @@ -15,110 +15,110 @@ int8_t gpioNumberToDigitalPin(int8_t gpioNumber); // Override APIs requiring pin remapping // cores/esp32/Arduino.h -#define pulseInLong(pin, args...) pulseInLong(digitalPinToGPIONumber(pin), args) -#define pulseIn(pin, args...) pulseIn(digitalPinToGPIONumber(pin), args) -#define noTone(_pin) noTone(digitalPinToGPIONumber(_pin)) -#define tone(_pin, args...) tone(digitalPinToGPIONumber(_pin), args) +#define pulseInLong(pin, args...) pulseInLong(digitalPinToGPIONumber(pin), args) +#define pulseIn(pin, args...) pulseIn(digitalPinToGPIONumber(pin), args) +#define noTone(_pin) noTone(digitalPinToGPIONumber(_pin)) +#define tone(_pin, args...) tone(digitalPinToGPIONumber(_pin), args) // cores/esp32/esp32-hal.h -#define analogGetChannel(pin) analogGetChannel(digitalPinToGPIONumber(pin)) -#define analogWrite(pin, value) analogWrite(digitalPinToGPIONumber(pin), value) -#define analogWriteFrequency(pin, freq) analogWriteFrequency(digitalPinToGPIONumber(pin), freq) -#define analogWriteResolution(pin, bits) analogWriteResolution(digitalPinToGPIONumber(pin), bits) +#define analogGetChannel(pin) analogGetChannel(digitalPinToGPIONumber(pin)) +#define analogWrite(pin, value) analogWrite(digitalPinToGPIONumber(pin), value) +#define analogWriteFrequency(pin, freq) analogWriteFrequency(digitalPinToGPIONumber(pin), freq) +#define analogWriteResolution(pin, bits) analogWriteResolution(digitalPinToGPIONumber(pin), bits) // cores/esp32/esp32-hal-adc.h -#define analogRead(pin) analogRead(digitalPinToGPIONumber(pin)) -#define analogReadMilliVolts(pin) analogReadMilliVolts(digitalPinToGPIONumber(pin)) -#define analogSetPinAttenuation(pin, attenuation) analogSetPinAttenuation(digitalPinToGPIONumber(pin), attenuation) +#define analogRead(pin) analogRead(digitalPinToGPIONumber(pin)) +#define analogReadMilliVolts(pin) analogReadMilliVolts(digitalPinToGPIONumber(pin)) +#define analogSetPinAttenuation(pin, attenuation) analogSetPinAttenuation(digitalPinToGPIONumber(pin), attenuation) // cores/esp32/esp32-hal-dac.h -#define dacDisable(pin) dacDisable(digitalPinToGPIONumber(pin)) -#define dacWrite(pin, value) dacWrite(digitalPinToGPIONumber(pin), value) +#define dacDisable(pin) dacDisable(digitalPinToGPIONumber(pin)) +#define dacWrite(pin, value) dacWrite(digitalPinToGPIONumber(pin), value) // cores/esp32/esp32-hal-gpio.h -#define analogChannelToDigitalPin(channel) gpioNumberToDigitalPin(analogChannelToDigitalPin(channel)) -#define digitalPinToAnalogChannel(pin) digitalPinToAnalogChannel(digitalPinToGPIONumber(pin)) -#define digitalPinToTouchChannel(pin) digitalPinToTouchChannel(digitalPinToGPIONumber(pin)) -#define digitalRead(pin) digitalRead(digitalPinToGPIONumber(pin)) -#define attachInterruptArg(pin, fcn, arg, mode) attachInterruptArg(digitalPinToGPIONumber(pin), fcn, arg, mode) -#define attachInterrupt(pin, fcn, mode) attachInterrupt(digitalPinToGPIONumber(pin), fcn, mode) -#define detachInterrupt(pin) detachInterrupt(digitalPinToGPIONumber(pin)) -#define digitalWrite(pin, val) digitalWrite(digitalPinToGPIONumber(pin), val) -#define pinMode(pin, mode) pinMode(digitalPinToGPIONumber(pin), mode) +#define analogChannelToDigitalPin(channel) gpioNumberToDigitalPin(analogChannelToDigitalPin(channel)) +#define digitalPinToAnalogChannel(pin) digitalPinToAnalogChannel(digitalPinToGPIONumber(pin)) +#define digitalPinToTouchChannel(pin) digitalPinToTouchChannel(digitalPinToGPIONumber(pin)) +#define digitalRead(pin) digitalRead(digitalPinToGPIONumber(pin)) +#define attachInterruptArg(pin, fcn, arg, mode) attachInterruptArg(digitalPinToGPIONumber(pin), fcn, arg, mode) +#define attachInterrupt(pin, fcn, mode) attachInterrupt(digitalPinToGPIONumber(pin), fcn, mode) +#define detachInterrupt(pin) detachInterrupt(digitalPinToGPIONumber(pin)) +#define digitalWrite(pin, val) digitalWrite(digitalPinToGPIONumber(pin), val) +#define pinMode(pin, mode) pinMode(digitalPinToGPIONumber(pin), mode) // cores/esp32/esp32-hal-i2c.h -#define i2cInit(i2c_num, sda, scl, clk_speed) i2cInit(i2c_num, digitalPinToGPIONumber(sda), digitalPinToGPIONumber(scl), clk_speed) +#define i2cInit(i2c_num, sda, scl, clk_speed) i2cInit(i2c_num, digitalPinToGPIONumber(sda), digitalPinToGPIONumber(scl), clk_speed) // cores/esp32/esp32-hal-i2c-slave.h -#define i2cSlaveInit(num, sda, scl, slaveID, frequency, rx_len, tx_len) i2cSlaveInit(num, digitalPinToGPIONumber(sda), digitalPinToGPIONumber(scl), slaveID, frequency, rx_len, tx_len) +#define i2cSlaveInit(num, sda, scl, slaveID, frequency, rx_len, tx_len) i2cSlaveInit(num, digitalPinToGPIONumber(sda), digitalPinToGPIONumber(scl), slaveID, frequency, rx_len, tx_len) // cores/esp32/esp32-hal-ledc.h -#define ledcAttach(pin, freq, resolution) ledcAttach(digitalPinToGPIONumber(pin), freq, resolution) -#define ledcAttachChannel(pin, freq, resolution, channel) ledcAttachChannel(digitalPinToGPIONumber(pin), freq, resolution, channel) -#define ledcWrite(pin, duty) ledcWrite(digitalPinToGPIONumber(pin), duty) -#define ledcWriteTone(pin, freq) ledcWriteTone(digitalPinToGPIONumber(pin), freq) -#define ledcWriteNote(pin, note, octave) ledcWriteNote(digitalPinToGPIONumber(pin), note, octave) -#define ledcRead(pin) ledcRead(digitalPinToGPIONumber(pin)) -#define ledcReadFreq(pin) ledcReadFreq(digitalPinToGPIONumber(pin)) -#define ledcDetach(pin) ledcDetach(digitalPinToGPIONumber(pin)) -#define ledcChangeFrequency(pin, freq, resolution) ledcChangeFrequency(digitalPinToGPIONumber(pin), freq, resolution) -#define ledcOutputInvert(pin, out_invert) ledcOutputInvert(digitalPinToGPIONumber(pin), out_invert) - -#define ledcFade(pin, start_duty, target_duty, max_fade_time_ms) ledcFade(digitalPinToGPIONumber(pin), start_duty, target_duty, max_fade_time_ms) -#define ledcFadeWithInterrupt(pin, start_duty, target_duty, max_fade_time_ms, userFunc) ledcFadeWithInterrupt(digitalPinToGPIONumber(pin), start_duty, target_duty, max_fade_time_ms, userFunc) +#define ledcAttach(pin, freq, resolution) ledcAttach(digitalPinToGPIONumber(pin), freq, resolution) +#define ledcAttachChannel(pin, freq, resolution, channel) ledcAttachChannel(digitalPinToGPIONumber(pin), freq, resolution, channel) +#define ledcWrite(pin, duty) ledcWrite(digitalPinToGPIONumber(pin), duty) +#define ledcWriteTone(pin, freq) ledcWriteTone(digitalPinToGPIONumber(pin), freq) +#define ledcWriteNote(pin, note, octave) ledcWriteNote(digitalPinToGPIONumber(pin), note, octave) +#define ledcRead(pin) ledcRead(digitalPinToGPIONumber(pin)) +#define ledcReadFreq(pin) ledcReadFreq(digitalPinToGPIONumber(pin)) +#define ledcDetach(pin) ledcDetach(digitalPinToGPIONumber(pin)) +#define ledcChangeFrequency(pin, freq, resolution) ledcChangeFrequency(digitalPinToGPIONumber(pin), freq, resolution) +#define ledcOutputInvert(pin, out_invert) ledcOutputInvert(digitalPinToGPIONumber(pin), out_invert) + +#define ledcFade(pin, start_duty, target_duty, max_fade_time_ms) ledcFade(digitalPinToGPIONumber(pin), start_duty, target_duty, max_fade_time_ms) +#define ledcFadeWithInterrupt(pin, start_duty, target_duty, max_fade_time_ms, userFunc) ledcFadeWithInterrupt(digitalPinToGPIONumber(pin), start_duty, target_duty, max_fade_time_ms, userFunc) #define ledcFadeWithInterruptArg(pin, start_duty, target_duty, max_fade_time_ms, userFunc, arg) ledcFadeWithInterruptArg(digitalPinToGPIONumber(pin), start_duty, target_duty, max_fade_time_ms, userFunc, arg) // cores/esp32/esp32-hal-matrix.h -#define pinMatrixInAttach(pin, signal, inverted) pinMatrixInAttach(digitalPinToGPIONumber(pin), signal, inverted) -#define pinMatrixOutAttach(pin, function, invertOut, invertEnable) pinMatrixOutAttach(digitalPinToGPIONumber(pin), function, invertOut, invertEnable) -#define pinMatrixOutDetach(pin, invertOut, invertEnable) pinMatrixOutDetach(digitalPinToGPIONumber(pin), invertOut, invertEnable) +#define pinMatrixInAttach(pin, signal, inverted) pinMatrixInAttach(digitalPinToGPIONumber(pin), signal, inverted) +#define pinMatrixOutAttach(pin, function, invertOut, invertEnable) pinMatrixOutAttach(digitalPinToGPIONumber(pin), function, invertOut, invertEnable) +#define pinMatrixOutDetach(pin, invertOut, invertEnable) pinMatrixOutDetach(digitalPinToGPIONumber(pin), invertOut, invertEnable) // cores/esp32/esp32-hal-rgb-led.h -#define neopixelWrite(pin, red_val, green_val, blue_val) neopixelWrite(digitalPinToGPIONumber(pin), red_val, green_val, blue_val) +#define neopixelWrite(pin, red_val, green_val, blue_val) neopixelWrite(digitalPinToGPIONumber(pin), red_val, green_val, blue_val) // cores/esp32/esp32-hal-rmt.h -#define rmtInit(pin, channel_direction, memsize, frequency_Hz) rmtInit(digitalPinToGPIONumber(pin), channel_direction, memsize, frequency_Hz) -#define rmtSetEOT(pin, EOT_Level) rmtSetEOT(digitalPinToGPIONumber(pin), EOT_Level) -#define rmtWrite(pin, data, num_rmt_symbols, timeout_ms) rmtWrite(digitalPinToGPIONumber(pin), data, num_rmt_symbols, timeout_ms) -#define rmtWriteAsync(pin, data, num_rmt_symbols) rmtWriteAsync(digitalPinToGPIONumber(pin), data, num_rmt_symbols) -#define rmtWriteLooping(pin, data, num_rmt_symbols) rmtWriteLooping(digitalPinToGPIONumber(pin), data, num_rmt_symbols) -#define rmtTransmitCompleted(pin) rmtTransmitCompleted(digitalPinToGPIONumber(pin)) -#define rmtRead(pin, data, num_rmt_symbols, timeout_ms) rmtRead(digitalPinToGPIONumber(pin), data, num_rmt_symbols, timeout_ms) -#define rmtReadAsync(pin, data, num_rmt_symbols) rmtReadAsync(digitalPinToGPIONumber(pin), data, num_rmt_symbols) -#define rmtReceiveCompleted(pin) rmtReceiveCompleted(digitalPinToGPIONumber(pin)) -#define rmtSetRxMaxThreshold(pin, idle_thres_ticks) rmtSetRxMaxThreshold(digitalPinToGPIONumber(pin), idle_thres_ticks) -#define rmtSetCarrier(pin, carrier_en, carrier_level, frequency_Hz, duty_percent) rmtSetCarrier(digitalPinToGPIONumber(pin), carrier_en, carrier_level, frequency_Hz, duty_percent) -#define rmtSetRxMinThreshold(pin, filter_pulse_ticks) rmtSetRxMinThreshold(digitalPinToGPIONumber(pin), filter_pulse_ticks) -#define rmtDeinit(pin) rmtDeinit(digitalPinToGPIONumber(pin)) +#define rmtInit(pin, channel_direction, memsize, frequency_Hz) rmtInit(digitalPinToGPIONumber(pin), channel_direction, memsize, frequency_Hz) +#define rmtSetEOT(pin, EOT_Level) rmtSetEOT(digitalPinToGPIONumber(pin), EOT_Level) +#define rmtWrite(pin, data, num_rmt_symbols, timeout_ms) rmtWrite(digitalPinToGPIONumber(pin), data, num_rmt_symbols, timeout_ms) +#define rmtWriteAsync(pin, data, num_rmt_symbols) rmtWriteAsync(digitalPinToGPIONumber(pin), data, num_rmt_symbols) +#define rmtWriteLooping(pin, data, num_rmt_symbols) rmtWriteLooping(digitalPinToGPIONumber(pin), data, num_rmt_symbols) +#define rmtTransmitCompleted(pin) rmtTransmitCompleted(digitalPinToGPIONumber(pin)) +#define rmtRead(pin, data, num_rmt_symbols, timeout_ms) rmtRead(digitalPinToGPIONumber(pin), data, num_rmt_symbols, timeout_ms) +#define rmtReadAsync(pin, data, num_rmt_symbols) rmtReadAsync(digitalPinToGPIONumber(pin), data, num_rmt_symbols) +#define rmtReceiveCompleted(pin) rmtReceiveCompleted(digitalPinToGPIONumber(pin)) +#define rmtSetRxMaxThreshold(pin, idle_thres_ticks) rmtSetRxMaxThreshold(digitalPinToGPIONumber(pin), idle_thres_ticks) +#define rmtSetCarrier(pin, carrier_en, carrier_level, frequency_Hz, duty_percent) rmtSetCarrier(digitalPinToGPIONumber(pin), carrier_en, carrier_level, frequency_Hz, duty_percent) +#define rmtSetRxMinThreshold(pin, filter_pulse_ticks) rmtSetRxMinThreshold(digitalPinToGPIONumber(pin), filter_pulse_ticks) +#define rmtDeinit(pin) rmtDeinit(digitalPinToGPIONumber(pin)) // cores/esp32/esp32-hal-sigmadelta.h -#define sigmaDeltaAttach(pin, freq) sigmaDeltaAttach(digitalPinToGPIONumber(pin), freq) -#define sigmaDeltaWrite(pin, duty) sigmaDeltaWrite(digitalPinToGPIONumber(pin), duty) -#define sigmaDeltaDetach(pin) sigmaDeltaDetach(digitalPinToGPIONumber(pin)) +#define sigmaDeltaAttach(pin, freq) sigmaDeltaAttach(digitalPinToGPIONumber(pin), freq) +#define sigmaDeltaWrite(pin, duty) sigmaDeltaWrite(digitalPinToGPIONumber(pin), duty) +#define sigmaDeltaDetach(pin) sigmaDeltaDetach(digitalPinToGPIONumber(pin)) // cores/esp32/esp32-hal-spi.h -#define spiAttachSCK(spi, sck) spiAttachSCK(spi, digitalPinToGPIONumber(sck)) -#define spiAttachMISO(spi, miso) spiAttachMISO(spi, digitalPinToGPIONumber(miso)) -#define spiAttachMOSI(spi, mosi) spiAttachMOSI(spi, digitalPinToGPIONumber(mosi)) -#define spiAttachSS(spi, cs_num, ss) spiAttachSS(spi, cs_num, digitalPinToGPIONumber(ss)) +#define spiAttachSCK(spi, sck) spiAttachSCK(spi, digitalPinToGPIONumber(sck)) +#define spiAttachMISO(spi, miso) spiAttachMISO(spi, digitalPinToGPIONumber(miso)) +#define spiAttachMOSI(spi, mosi) spiAttachMOSI(spi, digitalPinToGPIONumber(mosi)) +#define spiAttachSS(spi, cs_num, ss) spiAttachSS(spi, cs_num, digitalPinToGPIONumber(ss)) // cores/esp32/esp32-hal-touch.h -#define touchInterruptGetLastStatus(pin) touchInterruptGetLastStatus(digitalPinToGPIONumber(pin)) -#define touchRead(pin) touchRead(digitalPinToGPIONumber(pin)) -#define touchAttachInterruptArg(pin, userFunc, arg, threshold) touchAttachInterruptArg(digitalPinToGPIONumber(pin), userFunc, arg, threshold) -#define touchAttachInterrupt(pin, userFunc, threshold) touchAttachInterrupt(digitalPinToGPIONumber(pin), userFunc, threshold) -#define touchDetachInterrupt(pin) touchDetachInterrupt(digitalPinToGPIONumber(pin)) -#define touchSleepWakeUpEnable(pin, threshold) touchSleepWakeUpEnable(digitalPinToGPIONumber(pin), threshold) +#define touchInterruptGetLastStatus(pin) touchInterruptGetLastStatus(digitalPinToGPIONumber(pin)) +#define touchRead(pin) touchRead(digitalPinToGPIONumber(pin)) +#define touchAttachInterruptArg(pin, userFunc, arg, threshold) touchAttachInterruptArg(digitalPinToGPIONumber(pin), userFunc, arg, threshold) +#define touchAttachInterrupt(pin, userFunc, threshold) touchAttachInterrupt(digitalPinToGPIONumber(pin), userFunc, threshold) +#define touchDetachInterrupt(pin) touchDetachInterrupt(digitalPinToGPIONumber(pin)) +#define touchSleepWakeUpEnable(pin, threshold) touchSleepWakeUpEnable(digitalPinToGPIONumber(pin), threshold) // cores/esp32/esp32-hal-uart.h #define uartBegin(uart_nr, baudrate, config, rxPin, txPin, rx_buffer_size, tx_buffer_size, inverted, rxfifo_full_thrhd) \ - uartBegin(uart_nr, baudrate, config, digitalPinToGPIONumber(rxPin), digitalPinToGPIONumber(txPin), rx_buffer_size, tx_buffer_size, inverted, rxfifo_full_thrhd) + uartBegin(uart_nr, baudrate, config, digitalPinToGPIONumber(rxPin), digitalPinToGPIONumber(txPin), rx_buffer_size, tx_buffer_size, inverted, rxfifo_full_thrhd) #define uartSetPins(uart, rxPin, txPin, ctsPin, rtsPin) \ - uartSetPins(uart, digitalPinToGPIONumber(rxPin), digitalPinToGPIONumber(txPin), digitalPinToGPIONumber(ctsPin), digitalPinToGPIONumber(rtsPin)) + uartSetPins(uart, digitalPinToGPIONumber(rxPin), digitalPinToGPIONumber(txPin), digitalPinToGPIONumber(ctsPin), digitalPinToGPIONumber(rtsPin)) #define uartDetachPins(uart, rxPin, txPin, ctsPin, rtsPin) \ - uartDetachPins(uart, digitalPinToGPIONumber(rxPin), digitalPinToGPIONumber(txPin), digitalPinToGPIONumber(ctsPin), digitalPinToGPIONumber(rtsPin)) + uartDetachPins(uart, digitalPinToGPIONumber(rxPin), digitalPinToGPIONumber(txPin), digitalPinToGPIONumber(ctsPin), digitalPinToGPIONumber(rtsPin)) -#endif // ARDUINO_CORE_BUILD +#endif // ARDUINO_CORE_BUILD #else diff --git a/cores/esp32/libb64/LICENSE b/cores/esp32/libb64/LICENSE index a6b56069e7f..ae8a7b9d181 100644 --- a/cores/esp32/libb64/LICENSE +++ b/cores/esp32/libb64/LICENSE @@ -1,4 +1,4 @@ -Copyright-Only Dedication (based on United States law) +Copyright-Only Dedication (based on United States law) or Public Domain Certification The person or persons who have associated work with this document (the @@ -26,4 +26,4 @@ Dedicator recognizes that, once placed in the public domain, the Work may be freely reproduced, distributed, transmitted, used, modified, built upon, or otherwise exploited by anyone for any purpose, commercial or non-commercial, and in any way, including by methods that have not yet been invented or -conceived. \ No newline at end of file +conceived. diff --git a/cores/esp32/libb64/cdecode.c b/cores/esp32/libb64/cdecode.c index c4712b79762..a4ba209b0cb 100644 --- a/cores/esp32/libb64/cdecode.c +++ b/cores/esp32/libb64/cdecode.c @@ -8,42 +8,42 @@ For details, see http://sourceforge.net/projects/libb64 #include "cdecode.h" #include -static int base64_decode_value_signed(int8_t value_in){ - static const int8_t decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51}; +static int base64_decode_value_signed(int8_t value_in) { + static const int8_t decoding[] = { 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -2, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 }; static const int8_t decoding_size = sizeof(decoding); value_in -= 43; if (value_in < 0 || value_in >= decoding_size) return -1; return decoding[(int)value_in]; } -void base64_init_decodestate(base64_decodestate* state_in){ +void base64_init_decodestate(base64_decodestate* state_in) { state_in->step = step_a; state_in->plainchar = 0; } -static int base64_decode_block_signed(const int8_t* code_in, const int length_in, int8_t* plaintext_out, base64_decodestate* state_in){ +static int base64_decode_block_signed(const int8_t* code_in, const int length_in, int8_t* plaintext_out, base64_decodestate* state_in) { const int8_t* codechar = code_in; int8_t* plainchar = plaintext_out; int8_t fragment; - + *plainchar = state_in->plainchar; - - switch (state_in->step){ - while (1){ + + switch (state_in->step) { + while (1) { case step_a: do { - if (codechar == code_in+length_in){ + if (codechar == code_in + length_in) { state_in->step = step_a; state_in->plainchar = *plainchar; return plainchar - plaintext_out; } fragment = (int8_t)base64_decode_value_signed(*codechar++); } while (fragment < 0); - *plainchar = (fragment & 0x03f) << 2; + *plainchar = (fragment & 0x03f) << 2; // fall through case step_b: do { - if (codechar == code_in+length_in){ + if (codechar == code_in + length_in) { state_in->step = step_b; state_in->plainchar = *plainchar; return plainchar - plaintext_out; @@ -51,11 +51,11 @@ static int base64_decode_block_signed(const int8_t* code_in, const int length_in fragment = (int8_t)base64_decode_value_signed(*codechar++); } while (fragment < 0); *plainchar++ |= (fragment & 0x030) >> 4; - *plainchar = (fragment & 0x00f) << 4; + *plainchar = (fragment & 0x00f) << 4; // fall through case step_c: do { - if (codechar == code_in+length_in){ + if (codechar == code_in + length_in) { state_in->step = step_c; state_in->plainchar = *plainchar; return plainchar - plaintext_out; @@ -63,40 +63,40 @@ static int base64_decode_block_signed(const int8_t* code_in, const int length_in fragment = (int8_t)base64_decode_value_signed(*codechar++); } while (fragment < 0); *plainchar++ |= (fragment & 0x03c) >> 2; - *plainchar = (fragment & 0x003) << 6; + *plainchar = (fragment & 0x003) << 6; // fall through case step_d: do { - if (codechar == code_in+length_in){ + if (codechar == code_in + length_in) { state_in->step = step_d; state_in->plainchar = *plainchar; return plainchar - plaintext_out; } fragment = (int8_t)base64_decode_value_signed(*codechar++); } while (fragment < 0); - *plainchar++ |= (fragment & 0x03f); + *plainchar++ |= (fragment & 0x03f); } } /* control should not reach here */ return plainchar - plaintext_out; } -static int base64_decode_chars_signed(const int8_t* code_in, const int length_in, int8_t* plaintext_out){ +static int base64_decode_chars_signed(const int8_t* code_in, const int length_in, int8_t* plaintext_out) { base64_decodestate _state; base64_init_decodestate(&_state); int len = base64_decode_block_signed(code_in, length_in, plaintext_out, &_state); - if(len > 0) plaintext_out[len] = 0; + if (len > 0) plaintext_out[len] = 0; return len; } -int base64_decode_value(char value_in){ - return base64_decode_value_signed(*((int8_t *) &value_in)); +int base64_decode_value(char value_in) { + return base64_decode_value_signed(*((int8_t*)&value_in)); } -int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in){ - return base64_decode_block_signed((int8_t *) code_in, length_in, (int8_t *) plaintext_out, state_in); +int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in) { + return base64_decode_block_signed((int8_t*)code_in, length_in, (int8_t*)plaintext_out, state_in); } -int base64_decode_chars(const char* code_in, const int length_in, char* plaintext_out){ - return base64_decode_chars_signed((int8_t *) code_in, length_in, (int8_t *) plaintext_out); +int base64_decode_chars(const char* code_in, const int length_in, char* plaintext_out) { + return base64_decode_chars_signed((int8_t*)code_in, length_in, (int8_t*)plaintext_out); } diff --git a/cores/esp32/libb64/cdecode.h b/cores/esp32/libb64/cdecode.h index 44f114f691c..c8b8ef4e94e 100644 --- a/cores/esp32/libb64/cdecode.h +++ b/cores/esp32/libb64/cdecode.h @@ -14,25 +14,28 @@ For details, see http://sourceforge.net/projects/libb64 extern "C" { #endif -typedef enum { - step_a, step_b, step_c, step_d -} base64_decodestep; - -typedef struct { + typedef enum { + step_a, + step_b, + step_c, + step_d + } base64_decodestep; + + typedef struct { base64_decodestep step; char plainchar; -} base64_decodestate; + } base64_decodestate; -void base64_init_decodestate(base64_decodestate* state_in); + void base64_init_decodestate(base64_decodestate* state_in); -int base64_decode_value(char value_in); + int base64_decode_value(char value_in); -int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in); + int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in); -int base64_decode_chars(const char* code_in, const int length_in, char* plaintext_out); + int base64_decode_chars(const char* code_in, const int length_in, char* plaintext_out); #ifdef __cplusplus -} // extern "C" +} // extern "C" #endif #endif /* BASE64_CDECODE_H */ diff --git a/cores/esp32/libb64/cencode.c b/cores/esp32/libb64/cencode.c index f5388e5270e..2954d2f0f44 100644 --- a/cores/esp32/libb64/cencode.c +++ b/cores/esp32/libb64/cencode.c @@ -7,98 +7,93 @@ For details, see http://sourceforge.net/projects/libb64 #include "cencode.h" -void base64_init_encodestate(base64_encodestate* state_in) -{ - state_in->step = step_A; - state_in->result = 0; +void base64_init_encodestate(base64_encodestate* state_in) { + state_in->step = step_A; + state_in->result = 0; } -char base64_encode_value(char value_in) -{ - static const char* encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - if (value_in > 63) { - return '='; - } - return encoding[(int)value_in]; +char base64_encode_value(char value_in) { + static const char* encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + if (value_in > 63) { + return '='; + } + return encoding[(int)value_in]; } -int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in) -{ - const char* plainchar = plaintext_in; - const char* const plaintextend = plaintext_in + length_in; - char* codechar = code_out; - char result; - char fragment; +int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in) { + const char* plainchar = plaintext_in; + const char* const plaintextend = plaintext_in + length_in; + char* codechar = code_out; + char result; + char fragment; - result = state_in->result; + result = state_in->result; - switch (state_in->step) { - while (1) { - case step_A: - if (plainchar == plaintextend) { - state_in->result = result; - state_in->step = step_A; - return codechar - code_out; - } - fragment = *plainchar++; - result = (fragment & 0x0fc) >> 2; - *codechar++ = base64_encode_value(result); - result = (fragment & 0x003) << 4; - // fall through - case step_B: - if (plainchar == plaintextend) { - state_in->result = result; - state_in->step = step_B; - return codechar - code_out; - } - fragment = *plainchar++; - result |= (fragment & 0x0f0) >> 4; - *codechar++ = base64_encode_value(result); - result = (fragment & 0x00f) << 2; - // fall through - case step_C: - if (plainchar == plaintextend) { - state_in->result = result; - state_in->step = step_C; - return codechar - code_out; - } - fragment = *plainchar++; - result |= (fragment & 0x0c0) >> 6; - *codechar++ = base64_encode_value(result); - result = (fragment & 0x03f) >> 0; - *codechar++ = base64_encode_value(result); + switch (state_in->step) { + while (1) { + case step_A: + if (plainchar == plaintextend) { + state_in->result = result; + state_in->step = step_A; + return codechar - code_out; + } + fragment = *plainchar++; + result = (fragment & 0x0fc) >> 2; + *codechar++ = base64_encode_value(result); + result = (fragment & 0x003) << 4; + // fall through + case step_B: + if (plainchar == plaintextend) { + state_in->result = result; + state_in->step = step_B; + return codechar - code_out; } + fragment = *plainchar++; + result |= (fragment & 0x0f0) >> 4; + *codechar++ = base64_encode_value(result); + result = (fragment & 0x00f) << 2; + // fall through + case step_C: + if (plainchar == plaintextend) { + state_in->result = result; + state_in->step = step_C; + return codechar - code_out; + } + fragment = *plainchar++; + result |= (fragment & 0x0c0) >> 6; + *codechar++ = base64_encode_value(result); + result = (fragment & 0x03f) >> 0; + *codechar++ = base64_encode_value(result); } - /* control should not reach here */ - return codechar - code_out; + } + /* control should not reach here */ + return codechar - code_out; } -int base64_encode_blockend(char* code_out, base64_encodestate* state_in) -{ - char* codechar = code_out; +int base64_encode_blockend(char* code_out, base64_encodestate* state_in) { + char* codechar = code_out; - switch (state_in->step) { + switch (state_in->step) { case step_B: - *codechar++ = base64_encode_value(state_in->result); - *codechar++ = '='; - *codechar++ = '='; - break; + *codechar++ = base64_encode_value(state_in->result); + *codechar++ = '='; + *codechar++ = '='; + break; case step_C: - *codechar++ = base64_encode_value(state_in->result); - *codechar++ = '='; - break; + *codechar++ = base64_encode_value(state_in->result); + *codechar++ = '='; + break; case step_A: - break; - } - *codechar = 0x00; + break; + } + *codechar = 0x00; - return codechar - code_out; + return codechar - code_out; } -int base64_encode_chars(const char* plaintext_in, int length_in, char* code_out) -{ - base64_encodestate _state; - base64_init_encodestate(&_state); - int len = base64_encode_block(plaintext_in, length_in, code_out, &_state); - return len + base64_encode_blockend((code_out + len), &_state); +int base64_encode_chars(const char* plaintext_in, int length_in, char* code_out) { + base64_encodestate _state; + base64_init_encodestate(&_state); + int len = base64_encode_block(plaintext_in, length_in, code_out, &_state); + return len + base64_encode_blockend((code_out + len), &_state); } diff --git a/cores/esp32/libb64/cencode.h b/cores/esp32/libb64/cencode.h index 51bb3f3dd75..e81e804f6e4 100644 --- a/cores/esp32/libb64/cencode.h +++ b/cores/esp32/libb64/cencode.h @@ -14,28 +14,30 @@ For details, see http://sourceforge.net/projects/libb64 extern "C" { #endif -typedef enum { - step_A, step_B, step_C -} base64_encodestep; + typedef enum { + step_A, + step_B, + step_C + } base64_encodestep; -typedef struct { + typedef struct { base64_encodestep step; char result; int stepcount; -} base64_encodestate; + } base64_encodestate; -void base64_init_encodestate(base64_encodestate* state_in); + void base64_init_encodestate(base64_encodestate* state_in); -char base64_encode_value(char value_in); + char base64_encode_value(char value_in); -int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in); + int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in); -int base64_encode_blockend(char* code_out, base64_encodestate* state_in); + int base64_encode_blockend(char* code_out, base64_encodestate* state_in); -int base64_encode_chars(const char* plaintext_in, int length_in, char* code_out); + int base64_encode_chars(const char* plaintext_in, int length_in, char* code_out); #ifdef __cplusplus -} // extern "C" +} // extern "C" #endif #endif /* BASE64_CENCODE_H */ diff --git a/cores/esp32/main.cpp b/cores/esp32/main.cpp index fd51c4123bd..d613b58da1f 100644 --- a/cores/esp32/main.cpp +++ b/cores/esp32/main.cpp @@ -2,7 +2,7 @@ #include "freertos/task.h" #include "esp_task_wdt.h" #include "Arduino.h" -#if (ARDUINO_USB_CDC_ON_BOOT|ARDUINO_USB_MSC_ON_BOOT|ARDUINO_USB_DFU_ON_BOOT) && !ARDUINO_USB_MODE +#if (ARDUINO_USB_CDC_ON_BOOT | ARDUINO_USB_MSC_ON_BOOT | ARDUINO_USB_DFU_ON_BOOT) && !ARDUINO_USB_MODE #include "USB.h" #if ARDUINO_USB_MSC_ON_BOOT #include "FirmwareMSC.h" @@ -23,76 +23,74 @@ TaskHandle_t loopTaskHandle = NULL; #if CONFIG_AUTOSTART_ARDUINO #if CONFIG_FREERTOS_UNICORE -void yieldIfNecessary(void){ - static uint64_t lastYield = 0; - uint64_t now = millis(); - if((now - lastYield) > 2000) { - lastYield = now; - vTaskDelay(5); //delay 1 RTOS tick - } +void yieldIfNecessary(void) { + static uint64_t lastYield = 0; + uint64_t now = millis(); + if ((now - lastYield) > 2000) { + lastYield = now; + vTaskDelay(5); //delay 1 RTOS tick + } } #endif bool loopTaskWDTEnabled; __attribute__((weak)) size_t getArduinoLoopTaskStackSize(void) { - return ARDUINO_LOOP_STACK_SIZE; + return ARDUINO_LOOP_STACK_SIZE; } __attribute__((weak)) bool shouldPrintChipDebugReport(void) { - return false; + return false; } -void loopTask(void *pvParameters) -{ +void loopTask(void *pvParameters) { #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL) - // sets UART0 (default console) RX/TX pins as already configured in boot or as defined in variants/pins_arduino.h - Serial0.setPins(gpioNumberToDigitalPin(SOC_RX0), gpioNumberToDigitalPin(SOC_TX0)); + // sets UART0 (default console) RX/TX pins as already configured in boot or as defined in variants/pins_arduino.h + Serial0.setPins(gpioNumberToDigitalPin(SOC_RX0), gpioNumberToDigitalPin(SOC_TX0)); #endif #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - printBeforeSetupInfo(); + printBeforeSetupInfo(); #else - if(shouldPrintChipDebugReport()){ - printBeforeSetupInfo(); - } + if (shouldPrintChipDebugReport()) { + printBeforeSetupInfo(); + } #endif - setup(); + setup(); #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - printAfterSetupInfo(); + printAfterSetupInfo(); #else - if(shouldPrintChipDebugReport()){ - printAfterSetupInfo(); - } + if (shouldPrintChipDebugReport()) { + printAfterSetupInfo(); + } #endif - for(;;) { + for (;;) { #if CONFIG_FREERTOS_UNICORE - yieldIfNecessary(); + yieldIfNecessary(); #endif - if(loopTaskWDTEnabled){ - esp_task_wdt_reset(); - } - loop(); - if (serialEventRun) serialEventRun(); + if (loopTaskWDTEnabled) { + esp_task_wdt_reset(); } + loop(); + if (serialEventRun) serialEventRun(); + } } -extern "C" void app_main() -{ +extern "C" void app_main() { #if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE - Serial.begin(); + Serial.begin(); #endif #if ARDUINO_USB_MSC_ON_BOOT && !ARDUINO_USB_MODE - MSC_Update.begin(); + MSC_Update.begin(); #endif #if ARDUINO_USB_DFU_ON_BOOT && !ARDUINO_USB_MODE - USB.enableDFU(); + USB.enableDFU(); #endif #if ARDUINO_USB_ON_BOOT && !ARDUINO_USB_MODE - USB.begin(); + USB.begin(); #endif - loopTaskWDTEnabled = false; - initArduino(); - xTaskCreateUniversal(loopTask, "loopTask", getArduinoLoopTaskStackSize(), NULL, 1, &loopTaskHandle, ARDUINO_RUNNING_CORE); + loopTaskWDTEnabled = false; + initArduino(); + xTaskCreateUniversal(loopTask, "loopTask", getArduinoLoopTaskStackSize(), NULL, 1, &loopTaskHandle, ARDUINO_RUNNING_CORE); } #endif diff --git a/cores/esp32/pgmspace.h b/cores/esp32/pgmspace.h index 75f7e801b95..2b0f0270be6 100644 --- a/cores/esp32/pgmspace.h +++ b/cores/esp32/pgmspace.h @@ -1,7 +1,7 @@ -/* +/* Copyright (c) 2015 Hristo Gochkov. All rights reserved. This file is part of the RaspberryPi core for Arduino environment. - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either @@ -30,12 +30,12 @@ typedef long prog_int32_t; typedef unsigned long prog_uint32_t; #define PROGMEM -#define PGM_P const char * -#define PGM_VOID_P const void * -#define PSTR(s) (s) -#define _SFR_BYTE(n) (n) +#define PGM_P const char * +#define PGM_VOID_P const void * +#define PSTR(s) (s) +#define _SFR_BYTE(n) (n) -#define pgm_read_byte(addr) (*(const unsigned char *)(addr)) +#define pgm_read_byte(addr) (*(const unsigned char *)(addr)) #define pgm_read_word(addr) ({ \ typeof(addr) _addr = (addr); \ *(const unsigned short *)(_addr); \ @@ -50,40 +50,40 @@ typedef unsigned long prog_uint32_t; }) #define pgm_read_ptr(addr) ({ \ typeof(addr) _addr = (addr); \ - *(void * const *)(_addr); \ + *(void *const *)(_addr); \ }) #define pgm_get_far_address(x) ((uint32_t)(&(x))) -#define pgm_read_byte_near(addr) pgm_read_byte(addr) -#define pgm_read_word_near(addr) pgm_read_word(addr) +#define pgm_read_byte_near(addr) pgm_read_byte(addr) +#define pgm_read_word_near(addr) pgm_read_word(addr) #define pgm_read_dword_near(addr) pgm_read_dword(addr) #define pgm_read_float_near(addr) pgm_read_float(addr) -#define pgm_read_ptr_near(addr) pgm_read_ptr(addr) -#define pgm_read_byte_far(addr) pgm_read_byte(addr) -#define pgm_read_word_far(addr) pgm_read_word(addr) -#define pgm_read_dword_far(addr) pgm_read_dword(addr) -#define pgm_read_float_far(addr) pgm_read_float(addr) -#define pgm_read_ptr_far(addr) pgm_read_ptr(addr) +#define pgm_read_ptr_near(addr) pgm_read_ptr(addr) +#define pgm_read_byte_far(addr) pgm_read_byte(addr) +#define pgm_read_word_far(addr) pgm_read_word(addr) +#define pgm_read_dword_far(addr) pgm_read_dword(addr) +#define pgm_read_float_far(addr) pgm_read_float(addr) +#define pgm_read_ptr_far(addr) pgm_read_ptr(addr) -#define memcmp_P memcmp -#define memccpy_P memccpy -#define memmem_P memmem -#define memcpy_P memcpy -#define strcpy_P strcpy -#define strncpy_P strncpy -#define strcat_P strcat -#define strncat_P strncat -#define strcmp_P strcmp -#define strncmp_P strncmp -#define strcasecmp_P strcasecmp +#define memcmp_P memcmp +#define memccpy_P memccpy +#define memmem_P memmem +#define memcpy_P memcpy +#define strcpy_P strcpy +#define strncpy_P strncpy +#define strcat_P strcat +#define strncat_P strncat +#define strcmp_P strcmp +#define strncmp_P strncmp +#define strcasecmp_P strcasecmp #define strncasecmp_P strncasecmp -#define strlen_P strlen -#define strnlen_P strnlen -#define strstr_P strstr -#define printf_P printf -#define sprintf_P sprintf -#define snprintf_P snprintf -#define vsnprintf_P vsnprintf +#define strlen_P strlen +#define strnlen_P strnlen +#define strstr_P strstr +#define printf_P printf +#define sprintf_P sprintf +#define snprintf_P snprintf +#define vsnprintf_P vsnprintf #endif diff --git a/cores/esp32/stdlib_noniso.c b/cores/esp32/stdlib_noniso.c index e1e9eed6d41..aac17971b07 100644 --- a/cores/esp32/stdlib_noniso.c +++ b/cores/esp32/stdlib_noniso.c @@ -1,5 +1,5 @@ /* - core_esp8266_noniso.c - nonstandard (but usefull) conversion functions + core_esp8266_noniso.c - nonstandard (but useful) conversion functions Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. This file is part of the esp8266 core for Arduino environment. @@ -31,180 +31,178 @@ #include "esp_system.h" static void reverse(char* begin, char* end) { - char *is = begin; - char *ie = end - 1; - while(is < ie) { - char tmp = *ie; - *ie = *is; - *is = tmp; - ++is; - --ie; - } + char* is = begin; + char* ie = end - 1; + while (is < ie) { + char tmp = *ie; + *ie = *is; + *is = tmp; + ++is; + --ie; + } } char* ltoa(long value, char* result, int base) { - if(base < 2 || base > 16) { - *result = 0; - return result; - } + if (base < 2 || base > 16) { + *result = 0; + return result; + } - char* out = result; - long quotient = abs(value); + char* out = result; + long quotient = abs(value); - do { - const long tmp = quotient / base; - *out = "0123456789abcdef"[quotient - (tmp * base)]; - ++out; - quotient = tmp; - } while(quotient); + do { + const long tmp = quotient / base; + *out = "0123456789abcdef"[quotient - (tmp * base)]; + ++out; + quotient = tmp; + } while (quotient); - // Apply negative sign - if(value < 0) - *out++ = '-'; + // Apply negative sign + if (value < 0) + *out++ = '-'; - reverse(result, out); - *out = 0; - return result; + reverse(result, out); + *out = 0; + return result; } -char* lltoa (long long val, char* result, int base) { - if(base < 2 || base > 16) { - *result = 0; - return result; - } +char* lltoa(long long val, char* result, int base) { + if (base < 2 || base > 16) { + *result = 0; + return result; + } - char* out = result; - long long quotient = val > 0 ? val : -val; + char* out = result; + long long quotient = val > 0 ? val : -val; - do { - const long long tmp = quotient / base; - *out = "0123456789abcdef"[quotient - (tmp * base)]; - ++out; - quotient = tmp; - } while(quotient); + do { + const long long tmp = quotient / base; + *out = "0123456789abcdef"[quotient - (tmp * base)]; + ++out; + quotient = tmp; + } while (quotient); - // Apply negative sign - if(val < 0) - *out++ = '-'; + // Apply negative sign + if (val < 0) + *out++ = '-'; - reverse(result, out); - *out = 0; - return result; + reverse(result, out); + *out = 0; + return result; } char* ultoa(unsigned long value, char* result, int base) { - if(base < 2 || base > 16) { - *result = 0; - return result; - } - - char* out = result; - unsigned long quotient = value; - - do { - const unsigned long tmp = quotient / base; - *out = "0123456789abcdef"[quotient - (tmp * base)]; - ++out; - quotient = tmp; - } while(quotient); - - reverse(result, out); - *out = 0; + if (base < 2 || base > 16) { + *result = 0; return result; -} + } -char* ulltoa (unsigned long long val, char* result, int base) { - if(base < 2 || base > 16) { - *result = 0; - return result; - } - - char* out = result; - unsigned long long quotient = val; + char* out = result; + unsigned long quotient = value; - do { - const unsigned long long tmp = quotient / base; - *out = "0123456789abcdef"[quotient - (tmp * base)]; - ++out; - quotient = tmp; - } while(quotient); + do { + const unsigned long tmp = quotient / base; + *out = "0123456789abcdef"[quotient - (tmp * base)]; + ++out; + quotient = tmp; + } while (quotient); - reverse(result, out); - *out = 0; - return result; + reverse(result, out); + *out = 0; + return result; } -char * dtostrf(double number, signed int width, unsigned int prec, char *s) { - bool negative = false; - - if (isnan(number)) { - strcpy(s, "nan"); - return s; - } - if (isinf(number)) { - strcpy(s, "inf"); - return s; - } - - char* out = s; - - int fillme = width; // how many cells to fill for the integer part - if (prec > 0) { - fillme -= (prec+1); - } +char* ulltoa(unsigned long long val, char* result, int base) { + if (base < 2 || base > 16) { + *result = 0; + return result; + } - // Handle negative numbers - if (number < 0.0) { - negative = true; - fillme--; - number = -number; - } + char* out = result; + unsigned long long quotient = val; - // Round correctly so that print(1.999, 2) prints as "2.00" - // I optimized out most of the divisions - double rounding = 2.0; - for (unsigned int i = 0; i < prec; ++i) - rounding *= 10.0; - rounding = 1.0 / rounding; - - number += rounding; - - // Figure out how big our number really is - double tenpow = 1.0; - unsigned int digitcount = 1; - while (number >= 10.0 * tenpow) { - tenpow *= 10.0; - digitcount++; - } + do { + const unsigned long long tmp = quotient / base; + *out = "0123456789abcdef"[quotient - (tmp * base)]; + ++out; + quotient = tmp; + } while (quotient); - number /= tenpow; - fillme -= digitcount; + reverse(result, out); + *out = 0; + return result; +} - // Pad unused cells with spaces - while (fillme-- > 0) { - *out++ = ' '; - } +char* dtostrf(double number, signed int width, unsigned int prec, char* s) { + bool negative = false; - // Handle negative sign - if (negative) *out++ = '-'; - - // Print the digits, and if necessary, the decimal point - digitcount += prec; - int8_t digit = 0; - while (digitcount-- > 0) { - digit = (int8_t)number; - if (digit > 9) digit = 9; // insurance - *out++ = (char)('0' | digit); - if ((digitcount == prec) && (prec > 0)) { - *out++ = '.'; - } - number -= digit; - number *= 10.0; + if (isnan(number)) { + strcpy(s, "nan"); + return s; + } + if (isinf(number)) { + strcpy(s, "inf"); + return s; + } + + char* out = s; + + int fillme = width; // how many cells to fill for the integer part + if (prec > 0) { + fillme -= (prec + 1); + } + + // Handle negative numbers + if (number < 0.0) { + negative = true; + fillme--; + number = -number; + } + + // Round correctly so that print(1.999, 2) prints as "2.00" + // I optimized out most of the divisions + double rounding = 2.0; + for (unsigned int i = 0; i < prec; ++i) + rounding *= 10.0; + rounding = 1.0 / rounding; + + number += rounding; + + // Figure out how big our number really is + double tenpow = 1.0; + unsigned int digitcount = 1; + while (number >= 10.0 * tenpow) { + tenpow *= 10.0; + digitcount++; + } + + number /= tenpow; + fillme -= digitcount; + + // Pad unused cells with spaces + while (fillme-- > 0) { + *out++ = ' '; + } + + // Handle negative sign + if (negative) *out++ = '-'; + + // Print the digits, and if necessary, the decimal point + digitcount += prec; + int8_t digit = 0; + while (digitcount-- > 0) { + digit = (int8_t)number; + if (digit > 9) digit = 9; // insurance + *out++ = (char)('0' | digit); + if ((digitcount == prec) && (prec > 0)) { + *out++ = '.'; } + number -= digit; + number *= 10.0; + } - // make sure the string is terminated - *out = 0; - return s; + // make sure the string is terminated + *out = 0; + return s; } - - diff --git a/cores/esp32/stdlib_noniso.h b/cores/esp32/stdlib_noniso.h index 8356c1199aa..33fbe71430d 100644 --- a/cores/esp32/stdlib_noniso.h +++ b/cores/esp32/stdlib_noniso.h @@ -1,5 +1,5 @@ /* - stdlib_noniso.h - nonstandard (but usefull) conversion functions + stdlib_noniso.h - nonstandard (but useful) conversion functions Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. @@ -25,28 +25,28 @@ extern "C" { #endif -int atoi(const char *s); + int atoi(const char* s); -long atol(const char* s); + long atol(const char* s); -double atof(const char* s); + double atof(const char* s); -char* itoa (int val, char *s, int radix); + char* itoa(int val, char* s, int radix); -char* ltoa (long val, char *s, int radix); + char* ltoa(long val, char* s, int radix); -char* lltoa (long long val, char* s, int radix); + char* lltoa(long long val, char* s, int radix); -char* utoa (unsigned int val, char *s, int radix); + char* utoa(unsigned int val, char* s, int radix); -char* ultoa (unsigned long val, char *s, int radix); + char* ultoa(unsigned long val, char* s, int radix); -char* ulltoa (unsigned long long val, char* s, int radix); + char* ulltoa(unsigned long long val, char* s, int radix); -char* dtostrf (double val, signed int width, unsigned int prec, char *s); + char* dtostrf(double val, signed int width, unsigned int prec, char* s); #ifdef __cplusplus -} // extern "C" +} // extern "C" #endif diff --git a/cores/esp32/wiring_private.h b/cores/esp32/wiring_private.h index 2c53565a674..37a21556dc1 100644 --- a/cores/esp32/wiring_private.h +++ b/cores/esp32/wiring_private.h @@ -34,12 +34,12 @@ extern "C" { #endif -typedef void (*voidFuncPtr)(void); + typedef void (*voidFuncPtr)(void); -void initPins(); + void initPins(); #ifdef __cplusplus -} // extern "C" +} // extern "C" #endif #endif diff --git a/cores/esp32/wiring_pulse.c b/cores/esp32/wiring_pulse.c index 8c55e7258ef..9dabb3d4e7c 100644 --- a/cores/esp32/wiring_pulse.c +++ b/cores/esp32/wiring_pulse.c @@ -20,29 +20,27 @@ #include "esp_cpu.h" #define WAIT_FOR_PIN_STATE(state) \ - while (digitalRead(pin) != (state)) { \ - if (esp_cpu_get_cycle_count() - start_cycle_count > timeout_cycles) { \ - return 0; \ - } \ - } + while (digitalRead(pin) != (state)) { \ + if (esp_cpu_get_cycle_count() - start_cycle_count > timeout_cycles) { \ + return 0; \ + } \ + } // max timeout is 27 seconds at 160MHz clock and 54 seconds at 80MHz clock -unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) -{ - const uint32_t max_timeout_us = clockCyclesToMicroseconds(UINT_MAX); - if (timeout > max_timeout_us) { - timeout = max_timeout_us; - } - const uint32_t timeout_cycles = microsecondsToClockCycles(timeout); - const uint32_t start_cycle_count = esp_cpu_get_cycle_count(); - WAIT_FOR_PIN_STATE(!state); - WAIT_FOR_PIN_STATE(state); - const uint32_t pulse_start_cycle_count = esp_cpu_get_cycle_count(); - WAIT_FOR_PIN_STATE(!state); - return clockCyclesToMicroseconds(esp_cpu_get_cycle_count() - pulse_start_cycle_count); +unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) { + const uint32_t max_timeout_us = clockCyclesToMicroseconds(UINT_MAX); + if (timeout > max_timeout_us) { + timeout = max_timeout_us; + } + const uint32_t timeout_cycles = microsecondsToClockCycles(timeout); + const uint32_t start_cycle_count = esp_cpu_get_cycle_count(); + WAIT_FOR_PIN_STATE(!state); + WAIT_FOR_PIN_STATE(state); + const uint32_t pulse_start_cycle_count = esp_cpu_get_cycle_count(); + WAIT_FOR_PIN_STATE(!state); + return clockCyclesToMicroseconds(esp_cpu_get_cycle_count() - pulse_start_cycle_count); } -unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout) -{ - return pulseIn(pin, state, timeout); +unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout) { + return pulseIn(pin, state, timeout); } diff --git a/cores/esp32/wiring_shift.c b/cores/esp32/wiring_shift.c index 41cf8a0fa5b..67360a58670 100644 --- a/cores/esp32/wiring_shift.c +++ b/cores/esp32/wiring_shift.c @@ -21,31 +21,31 @@ #include "wiring_private.h" uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) { - uint8_t value = 0; - uint8_t i; + uint8_t value = 0; + uint8_t i; - for(i = 0; i < 8; ++i) { - //digitalWrite(clockPin, HIGH); - if(bitOrder == LSBFIRST) - value |= digitalRead(dataPin) << i; - else - value |= digitalRead(dataPin) << (7 - i); - digitalWrite(clockPin, HIGH); - digitalWrite(clockPin, LOW); - } - return value; + for (i = 0; i < 8; ++i) { + //digitalWrite(clockPin, HIGH); + if (bitOrder == LSBFIRST) + value |= digitalRead(dataPin) << i; + else + value |= digitalRead(dataPin) << (7 - i); + digitalWrite(clockPin, HIGH); + digitalWrite(clockPin, LOW); + } + return value; } void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) { - uint8_t i; + uint8_t i; - for(i = 0; i < 8; i++) { - if(bitOrder == LSBFIRST) - digitalWrite(dataPin, !!(val & (1 << i))); - else - digitalWrite(dataPin, !!(val & (1 << (7 - i)))); + for (i = 0; i < 8; i++) { + if (bitOrder == LSBFIRST) + digitalWrite(dataPin, !!(val & (1 << i))); + else + digitalWrite(dataPin, !!(val & (1 << (7 - i)))); - digitalWrite(clockPin, HIGH); - digitalWrite(clockPin, LOW); - } + digitalWrite(clockPin, HIGH); + digitalWrite(clockPin, LOW); + } } diff --git a/docs/conf_common.py b/docs/conf_common.py index dd37c809849..676cca899d5 100644 --- a/docs/conf_common.py +++ b/docs/conf_common.py @@ -17,17 +17,18 @@ github_repo = "espressif/arduino-esp32" # context used by sphinx_idf_theme -html_context["github_user"] = "espressif" -html_context["github_repo"] = "arduino-esp32" +html_context["github_user"] = "espressif" # noqa: F405 +html_context["github_repo"] = "arduino-esp32" # noqa: F405 html_static_path = ["../_static"] # Conditional content -extensions += ['sphinx_copybutton', - 'sphinx_tabs.tabs', - 'esp_docs.esp_extensions.dummy_build_system', - ] +extensions += [ # noqa: F405 + "sphinx_copybutton", + "sphinx_tabs.tabs", + "esp_docs.esp_extensions.dummy_build_system", +] # ESP32_DOCS = [ # "index.rst", diff --git a/docs/en/api/adc.rst b/docs/en/api/adc.rst index 8ab252e181b..cc9ad86180b 100644 --- a/docs/en/api/adc.rst +++ b/docs/en/api/adc.rst @@ -5,11 +5,11 @@ ADC About ----- -ADC (analog to digital converter) is a very common peripheral used to convert an analog signal such as voltage -to a digital form so that it can be read and processed by a microcontroller. +ADC (analog to digital converter) is a very common peripheral used to convert an analog signal such as voltage +to a digital form so that it can be read and processed by a microcontroller. -ADCs are very useful in control and monitoring applications since most sensors -(e.g., temperature, pressure, force) produce analogue output voltages. +ADCs are very useful in control and monitoring applications since most sensors +(e.g., temperature, pressure, force) produce analog output voltages. .. note:: Each SoC or module has a different number of ADC's with a different number of channels and pins available. Refer to datasheet of each board for more info. @@ -20,7 +20,7 @@ ADC OneShot mode **************** -The ADC OneShot mode API is fully compatible with Arduino's ``analogRead`` function. +The ADC OneShot mode API is fully compatible with Arduino's ``analogRead`` function. When you call the ``analogRead`` or ``analogReadMillivolts`` function, it returns the result of a single conversion on the requested pin. analogRead @@ -33,7 +33,7 @@ This function is used to get the ADC raw value for a given pin/ADC channel. uint16_t analogRead(uint8_t pin); * ``pin`` GPIO pin to read analog value - + This function will return analog raw value (non-calibrated). analogReadMillivolts @@ -52,8 +52,8 @@ This function will return analog value in millivolts (calibrated). analogReadResolution ^^^^^^^^^^^^^^^^^^^^ -This function is used to set the resolution of ``analogRead`` return value. Default is 12 bits (range from 0 to 4095) -for all chips except ESP32S3 where default is 13 bits (range from 0 to 8191). +This function is used to set the resolution of ``analogRead`` return value. Default is 12 bits (range from 0 to 4095) +for all chips except ESP32S3 where default is 13 bits (range from 0 to 8191). When different resolution is set, the values read will be shifted to match the given resolution. Range is 1 - 16 .The default value will be used, if this function is not used. @@ -156,11 +156,11 @@ Range is 9 - 12. ADC Continuous mode ******************* -ADC Continuous mode is an API designed for performing analog conversions on multiple pins in the background, +ADC Continuous mode is an API designed for performing analog conversions on multiple pins in the background, with the feature of receiving a callback upon completion of these conversions to access the results. -This API allows you to specify the desired number of conversions per pin within a single cycle, along with its corresponding sampling rate. -The outcome of the ``analogContinuousRead`` function is an array of ``adc_continuous_data_t`` structures. +This API allows you to specify the desired number of conversions per pin within a single cycle, along with its corresponding sampling rate. +The outcome of the ``analogContinuousRead`` function is an array of ``adc_continuous_data_t`` structures. These structures hold both the raw average value and the average value in millivolts for each pin. analogContinuous @@ -177,7 +177,7 @@ This function is used to configure ADC continuous peripheral on selected pins. * ``conversions_per_pin`` sets how many conversions per pin will run each ADC cycle * ``sampling_freq_hz`` sets sampling frequency of ADC in Hz * ``userFunc`` sets callback function to be called after adc conversion is done (can be set to ``NULL``) - + This function will return ``true`` if configuration is successful. If ``false`` is returned, error occurs and ADC continuous was not configured. @@ -199,9 +199,9 @@ This function is used to read ADC continuous data to the result buffer. The resu bool analogContinuousRead(adc_continuos_data_t ** buffer, uint32_t timeout_ms); -* ``buffer`` conversion result buffer to read from ADC in adc_continuos_data_t format. +* ``buffer`` conversion result buffer to read from ADC in adc_continuos_data_t format. * ``timeout_ms`` time to wait for data in milliseconds. - + This function will return ``true`` if reading is successful and ``buffer`` is filled with data. If ``false`` is returned, reading has failed and ``buffer`` is set to NULL. @@ -213,8 +213,8 @@ This function is used to start ADC continuous conversions. .. code-block:: arduino bool analogContinuousStart(); - -This function will return ``true`` if ADC continuous is succesfully started. + +This function will return ``true`` if ADC continuous is successfully started. If ``false`` is returned, starting ADC continuous has failed. analogContinuousStop @@ -225,8 +225,8 @@ This function is used to stop ADC continuous conversions. .. code-block:: arduino bool analogContinuousStop(); - -This function will return ``true`` if ADC continuous is succesfully stopped. + +This function will return ``true`` if ADC continuous is successfully stopped. If ``false`` is returned, stopping ADC continuous has failed. analogContinuousDeinit @@ -237,14 +237,14 @@ This function is used to deinitialize ADC continuous peripheral. .. code-block:: arduino bool analogContinuousDeinit(); - -This function will return ``true`` if ADC continuous is succesfully deinitialized. + +This function will return ``true`` if ADC continuous is successfully deinitialized. If ``false`` is returned, deinitilization of ADC continuous has failed. analogContinuousSetAtten ^^^^^^^^^^^^^^^^^^^^^^^^ -This function is used to set the attenuation for ADC continuous peripheral. For more informations refer to `analogSetAttenuation`_. +This function is used to set the attenuation for ADC continuous peripheral. For more information refer to `analogSetAttenuation`_. .. code-block:: arduino diff --git a/docs/en/api/ble.rst b/docs/en/api/ble.rst index 05e765f8feb..8a994605312 100644 --- a/docs/en/api/ble.rst +++ b/docs/en/api/ble.rst @@ -10,7 +10,7 @@ About Examples -------- -To get started with BLE, you can try: +To get started with BLE, you can try: BLE Scan ******** @@ -24,4 +24,4 @@ BLE UART .. literalinclude:: ../../../libraries/BLE/examples/UART/UART.ino :language: arduino -Complete list of `BLE examples `_. +Complete list of `BLE examples `_. diff --git a/docs/en/api/bluetooth.rst b/docs/en/api/bluetooth.rst index b652d200a51..ebabfca5a9e 100644 --- a/docs/en/api/bluetooth.rst +++ b/docs/en/api/bluetooth.rst @@ -10,7 +10,7 @@ About Examples -------- -To get started with Bluetooth, you can try: +To get started with Bluetooth, you can try: Serial To Serial BT ******************* @@ -24,4 +24,4 @@ BT Classic Device Discovery .. literalinclude:: ../../../libraries/BluetoothSerial/examples/bt_classic_device_discovery/bt_classic_device_discovery.ino :language: arduino -Complete list of `Bluetooth examples `_. +Complete list of `Bluetooth examples `_. diff --git a/docs/en/api/dac.rst b/docs/en/api/dac.rst index 9fd91feeefd..d66c6878c17 100644 --- a/docs/en/api/dac.rst +++ b/docs/en/api/dac.rst @@ -6,7 +6,7 @@ About ----- DAC (digital to analog converter) is a very common peripheral used to convert a digital signal to an -analog form. +analog form. ESP32 and ESP32-S2 have two 8-bit DAC channels. The DAC driver allows these channels to be set to arbitrary voltages. @@ -44,4 +44,4 @@ This function is used to disable DAC output on a given pin/DAC channel. void dacDisable(uint8_t pin); -* ``pin`` GPIO pin. \ No newline at end of file +* ``pin`` GPIO pin. diff --git a/docs/en/api/espnow.rst b/docs/en/api/espnow.rst index 48472881599..d9f27ee711a 100644 --- a/docs/en/api/espnow.rst +++ b/docs/en/api/espnow.rst @@ -5,9 +5,9 @@ ESP-NOW About ----- -ESP-NOW is a communication protocol designed for low-power, low-latency, and high-throughput communication between ESP32 devices without the need for an access point (AP). +ESP-NOW is a communication protocol designed for low-power, low-latency, and high-throughput communication between ESP32 devices without the need for an access point (AP). It is ideal for scenarios where devices need to communicate directly with each other in a local network. -ESP-NOW can be used for smart lights, remote control devices, sensors and many other applications. +ESP-NOW can be used for smart lights, remote control devices, sensors and many other applications. This library provides an easy-to-use interface for setting up ESP-NOW communication, adding and removing peers, and sending and receiving data packets. diff --git a/docs/en/api/ethernet.rst b/docs/en/api/ethernet.rst index 9a7bd5687cb..ad4297e6668 100644 --- a/docs/en/api/ethernet.rst +++ b/docs/en/api/ethernet.rst @@ -10,7 +10,7 @@ About Examples -------- -To get started with Ethernet, you can try: +To get started with Ethernet, you can try: LAN8720 ******* @@ -24,4 +24,4 @@ TLK110 .. literalinclude:: ../../../libraries/Ethernet/examples/ETH_TLK110/ETH_TLK110.ino :language: arduino -Complete list of `Ethernet examples `_. +Complete list of `Ethernet examples `_. diff --git a/docs/en/api/gpio.rst b/docs/en/api/gpio.rst index b60c3798e4f..e74f90bff92 100644 --- a/docs/en/api/gpio.rst +++ b/docs/en/api/gpio.rst @@ -15,13 +15,13 @@ GPIOs Modes *********** There are two different modes in the GPIO configuration: - + - **Input Mode** In this mode, the GPIO will receive the digital state from a specific device. This device could be a button or a switch. - **Output Mode** - + For the output mode, the GPIO will change the GPIO digital state to a specific device. You can drive an LED for example. GPIO API @@ -37,11 +37,11 @@ The ``pinMode`` function is used to define the GPIO operation mode for a specifi .. code-block:: arduino void pinMode(uint8_t pin, uint8_t mode); - + * ``pin`` defines the GPIO pin number. * ``mode`` sets operation mode. - -The following modes are supported for the basic `input` and `output`: + +The following modes are supported for the basic `input` and `output`: * **INPUT** sets the GPIO as input without pullup or pulldown (high impedance). * **OUTPUT** sets the GPIO as output/read mode. @@ -51,7 +51,7 @@ The following modes are supported for the basic `input` and `output`: Internal Pullup and Pulldown ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -The ESP32 SoC families supports the internal pullup and pulldown throught a 45kR resistor, that can be enabled when configuring the GPIO mode as ``INPUT`` mode. +The ESP32 SoC families supports the internal pullup and pulldown through a 45kR resistor, that can be enabled when configuring the GPIO mode as ``INPUT`` mode. If the pullup or pulldown mode is not defined, the pin will stay in the high impedance mode. digitalWrite @@ -64,7 +64,7 @@ The function ``digitalWrite`` sets the state of the selected GPIO to ``HIGH`` or void digitalWrite(uint8_t pin, uint8_t val); * ``pin`` defines the GPIO pin number. -* ``val`` set the output digital state to ``HIGH`` or ``LOW``. +* ``val`` set the output digital state to ``HIGH`` or ``LOW``. digitalRead *********** @@ -155,9 +155,9 @@ GPIO Input and Output Modes void loop() { - if(!digitalRead(BUTTON)){ + if(!digitalRead(BUTTON)){ stateLED = stateLED^1; - digitalWrite(LED,stateLED); + digitalWrite(LED,stateLED); } } diff --git a/docs/en/api/i2c.rst b/docs/en/api/i2c.rst index 31a07f88046..3723b5e3947 100644 --- a/docs/en/api/i2c.rst +++ b/docs/en/api/i2c.rst @@ -56,7 +56,7 @@ This function will return ``true`` if the peripheral was initialized correctly. setPins ^^^^^^^ -This function is used to define the ``SDA`` and ``SCL`` pins. +This function is used to define the ``SDA`` and ``SCL`` pins. .. note:: Call this function before ``begin`` to change the pins from the default ones. @@ -110,7 +110,7 @@ Set the bus timeout given in milliseconds. The default value is 50ms. void setTimeOut(uint16_t timeOutMillis); * ``timeOutMillis`` sets the timeout in ms. - + getTimeOut ^^^^^^^^^^ @@ -132,8 +132,8 @@ This function writes data to the buffer. .. code-block:: arduino size_t write(uint8_t); - -or + +or .. code-block:: arduino @@ -219,7 +219,7 @@ Here are the I2C master APIs. These function are intended to be used only for ma begin ^^^^^ -In master mode, the ``begin`` function can be used by passing the **pins** and **bus frequency**. Use this function only for the master mode. +In master mode, the ``begin`` function can be used by passing the **pins** and **bus frequency**. Use this function only for the master mode. .. code-block:: arduino @@ -252,7 +252,7 @@ After writing to the buffer using `i2c write`_, use the function ``endTransmissi Calling the this function without ``sendStop`` is equivalent to ``sendStop = true``. .. code-block:: arduino - + uint8_t endTransmission(void); This function will return the error code. @@ -291,7 +291,7 @@ This mode is used to accept communication from the master. Basic Usage ^^^^^^^^^^^ -To start using I2C as slave mode on the Arduino, the first step is to include the ``Wire.h`` header to the scketch. +To start using I2C as slave mode on the Arduino, the first step is to include the ``Wire.h`` header to the sketch. .. code-block:: arduino @@ -309,7 +309,7 @@ and Wire.onRequest(onRequest); -The ``onReceive`` will handle the request from the master device uppon a slave read request and the ``onRequest`` will handle the answer to the master. +The ``onReceive`` will handle the request from the master device upon a slave read request and the ``onRequest`` will handle the answer to the master. Now, we can start the peripheral configuration by calling ``begin`` function with the device address. @@ -322,7 +322,7 @@ By using ``begin`` without any arguments, all the settings will be done by using **For ESP32 only!** -Use the function ``slaveWrite`` in order to pre-write to the slave response buffer. This is used only for the ESP32 in order to add the slave capability on the chip and keep compatability with Arduino. +Use the function ``slaveWrite`` in order to pre-write to the slave response buffer. This is used only for the ESP32 in order to add the slave capability on the chip and keep compatibility with Arduino. .. code-block:: arduino @@ -336,7 +336,7 @@ Here are the I2C slave APIs. These function are intended to be used only for sla begin ^^^^^ -In slave mode, the ``begin`` function must be used by passing the **slave address**. You can also define the **pins** and the **bus frequency**. +In slave mode, the ``begin`` function must be used by passing the **slave address**. You can also define the **pins** and the **bus frequency**. .. code-block:: arduino @@ -365,7 +365,7 @@ The ``onRequest`` function is used to define the callback for the data to be sen slaveWrite ^^^^^^^^^^ -The ``slaveWrite`` function writes on the slave response buffer before receiving the response message. This function is only used for adding the slave compatability for the ESP32. +The ``slaveWrite`` function writes on the slave response buffer before receiving the response message. This function is only used for adding the slave compatibility for the ESP32. .. warning:: This function is only required for the ESP32. You **don't** need to use for ESP32-S2 and ESP32-C3. diff --git a/docs/en/api/insights.rst b/docs/en/api/insights.rst index 5818a326f3d..1350c7bcee3 100644 --- a/docs/en/api/insights.rst +++ b/docs/en/api/insights.rst @@ -7,7 +7,7 @@ About ESP Insights is a remote diagnostics solution that allows users to remotely monitor the health of ESP devices in the field. -Developers normally prefer debugging issues by physically probing them using gdb or observing the logs. This surely helps debug issues, but there are often cases wherein issues are seen only in specific environments under specific conditions. Even things like casings and placement of the product can affect the behaviour. A few examples are +Developers normally prefer debugging issues by physically probing them using gdb or observing the logs. This surely helps debug issues, but there are often cases wherein issues are seen only in specific environments under specific conditions. Even things like casings and placement of the product can affect the behavior. A few examples are - Wi-Fi disconnections for a smart switch concealed in a wall. - Smart speakers crashing during some specific usage pattern. diff --git a/docs/en/api/ledc.rst b/docs/en/api/ledc.rst index 200e19f81e5..e2a18779571 100644 --- a/docs/en/api/ledc.rst +++ b/docs/en/api/ledc.rst @@ -4,8 +4,8 @@ LED Control (LEDC) About ----- -The LED control (LEDC) peripheral is primarly designed to control the intensity of LEDs, -although it can also be used to generate PWM signals for other purposes. +The LED control (LEDC) peripheral is primarily designed to control the intensity of LEDs, +although it can also be used to generate PWM signals for other purposes. ESP32 SoCs has from 6 to 16 channels (variates on socs, see table below) which can generate independent waveforms, that can be used for example to drive RGB LED devices. @@ -128,7 +128,7 @@ This function is used to setup the LEDC pin to specific note. * ``pin`` select LEDC pin. * ``note`` select note to be set. - + ======= ======= ======= ======= ======= ====== NOTE_C NOTE_Cs NOTE_D NOTE_Eb NOTE_E NOTE_F NOTE_Fs NOTE_G NOTE_Gs NOTE_A NOTE_Bb NOTE_B @@ -164,10 +164,10 @@ This function is used to set frequency for the LEDC pin. * ``pin`` select LEDC pin. * ``freq`` select frequency of pwm. -* ``resolution`` select resolution for LEDC channel. - +* ``resolution`` select resolution for LEDC channel. + * range is 1-14 bits (1-20 bits for ESP32). - + This function will return ``frequency`` configured for the LEDC channel. If ``0`` is returned, error occurs and the LEDC channel frequency was not set. @@ -182,7 +182,7 @@ This function is used to set inverting output for the LEDC pin. * ``pin`` select LEDC pin. * ``out_invert`` select, if output should be inverted (true = inverting output). - + This function returns ``true`` if setting inverting output was successful. If ``false`` is returned, an error occurred and the inverting output was not set. @@ -197,9 +197,9 @@ This function is used to setup and start fade for the LEDC pin. * ``pin`` select LEDC pin. * ``start_duty`` select starting duty of fade. -* ``target_duty`` select target duty of fade. -* ``max_fade_time_ms`` select maximum time for fade. - +* ``target_duty`` select target duty of fade. +* ``max_fade_time_ms`` select maximum time for fade. + This function will return ``true`` if configuration is successful. If ``false`` is returned, error occurs and LEDC fade was not configured / started. @@ -214,10 +214,10 @@ This function is used to setup and start fade for the LEDC pin with interrupt. * ``pin`` select LEDC pin. * ``start_duty`` select starting duty of fade. -* ``target_duty`` select target duty of fade. -* ``max_fade_time_ms`` select maximum time for fade. -* ``userFunc`` funtion to be called when interrupt is triggered. - +* ``target_duty`` select target duty of fade. +* ``max_fade_time_ms`` select maximum time for fade. +* ``userFunc`` function to be called when interrupt is triggered. + This function will return ``true`` if configuration is successful and fade start. If ``false`` is returned, error occurs and LEDC fade was not configured / started. @@ -232,11 +232,11 @@ This function is used to setup and start fade for the LEDC pin with interrupt us * ``pin`` select LEDC pin. * ``start_duty`` select starting duty of fade. -* ``target_duty`` select target duty of fade. -* ``max_fade_time_ms`` select maximum time for fade. -* ``userFunc`` funtion to be called when interrupt is triggered. +* ``target_duty`` select target duty of fade. +* ``max_fade_time_ms`` select maximum time for fade. +* ``userFunc`` function to be called when interrupt is triggered. * ``arg`` pointer to the interrupt arguments. - + This function will return ``true`` if configuration is successful and fade start. If ``false`` is returned, error occurs and LEDC fade was not configured / started. @@ -262,9 +262,9 @@ This function is used to set resolution for selected analogWrite pin. .. code-block:: arduino void analogWriteResolution(uint8_t pin, uint8_t resolution); - + * ``pin`` select the GPIO pin. -* ``resolution`` select resolution for analog channel. +* ``resolution`` select resolution for analog channel. analogWriteFrequency ******************** diff --git a/docs/en/api/preferences.rst b/docs/en/api/preferences.rst index 83ca6d820e9..2b06b78df07 100644 --- a/docs/en/api/preferences.rst +++ b/docs/en/api/preferences.rst @@ -7,7 +7,7 @@ About The Preferences library is unique to arduino-esp32. It should be considered as the replacement for the Arduino EEPROM library. -It uses a portion of the on-board non-volatile memory (NVS) of the ESP32 to store data. This data is retained across restarts and loss of power events to the system. +It uses a portion of the on-board non-volatile memory (NVS) of the ESP32 to store data. This data is retained across restarts and loss of power events to the system. Preferences works best for storing many small values, rather than a few large values. If large amounts of data are to be stored, consider using a file system library such as LitteFS. @@ -40,7 +40,7 @@ Preferences directly supports the following data types: .. table:: **Table 1 — Preferences Data Types** :align: center - + +-------------------+-------------------+---------------+ | Preferences Type | Data Type | Size (bytes) | +===================+===================+===============+ @@ -113,7 +113,7 @@ Arduino-esp32 Preferences API **Notes** * If the namespace does not exist within the partition, it is first created. - * Attempting to write a key value to a namespace open in read-only mode will fail. + * Attempting to write a key value to a namespace open in read-only mode will fail. * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. @@ -123,8 +123,8 @@ Arduino-esp32 Preferences API Close the currently opened namespace. .. code-block:: arduino - - void end() + + void end() .. **Parameters** @@ -134,7 +134,7 @@ Arduino-esp32 Preferences API * Nothing **Note** - * After closing a namespace, methods used to access it will fail. + * After closing a namespace, methods used to access it will fail. ``clear`` @@ -142,61 +142,61 @@ Arduino-esp32 Preferences API Delete all keys and values from the currently opened namespace. - .. code-block:: arduino - - bool clear() + .. code-block:: arduino + + bool clear() .. **Parameters** * None - + **Returns** * ``true`` if all keys and values were deleted; ``false`` otherwise. - + **Note** - * the namespace name still exists afterward. + * the namespace name still exists afterward. * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. - - + + ``remove`` ************* Delete a key-value pair from the currently open namespace. - + .. code-block:: arduino - + bool remove(const char * key) .. **Parameters** * ``key`` (Required) - - the name of the key to be deleted. - + - the name of the key to be deleted. + **Returns** * ``true`` if key-value pair was deleted; ``false`` otherwise. - - **Note** + + **Note** * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. - - + + ``isKey`` ************* Check if a key-value pair from the currently open namespace exists. - + .. code-block:: arduino - + bool isKey(const char * key) .. **Parameters** * ``key`` (Required) - - the name of the key to be checked. - + - the name of the key to be checked. + **Returns** * ``true`` if key-value pair exists; ``false`` otherwise. - - **Note** + + **Note** * Attempting to check a key without a namespace being open will return false. @@ -218,7 +218,7 @@ Arduino-esp32 Preferences API * ``value`` (Required) - must match the data type of the method. - + **Returns** * ``1`` (the number of bytes stored for these data types) if the call is successful; ``0`` otherwise. @@ -245,7 +245,7 @@ Arduino-esp32 Preferences API * ``value`` (Required) - must match the data type of the method. - + **Returns** * ``2`` (the number of bytes stored for these data types) if the call is successful; ``0`` otherwise. @@ -261,7 +261,7 @@ Arduino-esp32 Preferences API ********************** Store a value against a given key in the currently open namespace. - + .. code-block:: arduino size_t putInt(const char* key, int32_t value) @@ -277,7 +277,7 @@ Arduino-esp32 Preferences API * ``value`` (Required) - must match the data type of the method. - + **Returns** * ``4`` (the number of bytes stored for these data types) if the call is successful; ``0`` otherwise. @@ -308,7 +308,7 @@ Arduino-esp32 Preferences API * ``value`` (Required) - must match the data type of the method. - + **Returns** * ``8`` (the number of bytes stored for these data types) if the call is successful; ``0`` otherwise. @@ -334,7 +334,7 @@ Arduino-esp32 Preferences API * ``value`` (Required) - must match the data type of the method. - + **Returns** * ``true`` if successful; ``false`` otherwise. @@ -360,9 +360,9 @@ Arduino-esp32 Preferences API - if the key does not exist in the currently opened namespace it is first created. * ``value`` (Required) - - if ``const char*``, a null-terminated (c-string) character array. + - if ``const char*``, a null-terminated (c-string) character array. - if ``String``, a valid Arduino String type. - + **Returns** * if successful: the number of bytes stored; ``0`` otherwise. @@ -391,13 +391,13 @@ Arduino-esp32 Preferences API * ``len`` (Required) - the number of bytes from ``value`` to be stored. - + **Returns** * if successful: the number of bytes stored; ``0`` otherwise. **Notes** * Attempting to store a value without a namespace being open in read-write mode will fail. - * This method operates on the bytes used by the underlying data type, not the number of elements of a given data type. The data type of ``value`` is not retained by the Preferences library afterward. + * This method operates on the bytes used by the underlying data type, not the number of elements of a given data type. The data type of ``value`` is not retained by the Preferences library afterward. * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. @@ -418,14 +418,14 @@ Arduino-esp32 Preferences API * ``defaultValue`` (Optional) - must match the data type of the method if provided. - + **Returns** * the value stored against ``key`` if the call is successful. * ``defaultValue``, if it is provided; ``0`` otherwise. **Notes** * Attempting to retrieve a key without a namespace being available will fail. - * Attempting to retrieve value from a non existant key will fail. + * Attempting to retrieve value from a non existent key will fail. * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. @@ -439,7 +439,7 @@ Arduino-esp32 Preferences API int16_t getShort(const char* key, int16_t defaultValue = 0) uint16_t getUShort(const char* key, uint16_t defaultValue = 0) .. - + Except for the data type returned, behaves exactly like ``getChar``. @@ -455,7 +455,7 @@ Arduino-esp32 Preferences API uint32_t getUInt(const char* key, uint32_t defaultValue = 0) .. - + Except for the data type returned, behaves exactly like ``getChar``. @@ -470,7 +470,7 @@ Arduino-esp32 Preferences API uint32_t getULong(const char* key, uint32_t defaultValue = 0) .. - + Except for the data type returned, behaves exactly like ``getChar``. @@ -485,7 +485,7 @@ Arduino-esp32 Preferences API uint64_t getULong64(const char* key, uint64_t defaultValue = 0) .. - + Except for the data type returned, behaves exactly like ``getChar``. @@ -499,7 +499,7 @@ Arduino-esp32 Preferences API float_t getFloat(const char* key, float_t defaultValue = NAN) .. - + Except for the data type returned and the value of ``defaultValue``, behaves exactly like ``getChar``. @@ -513,7 +513,7 @@ Arduino-esp32 Preferences API double_t getDouble(const char* key, double_t defaultValue = NAN) .. - + Except for the data type returned and the value of ``defaultValue``, behaves exactly like ``getChar``. @@ -527,7 +527,7 @@ Arduino-esp32 Preferences API uint8_t getUChar(const char* key, uint8_t defaultValue = 0); .. - + Except for the data type returned, behaves exactly like ``getChar``. @@ -571,7 +571,7 @@ Arduino-esp32 Preferences API **Parameters** * ``key`` (Required) * ``defaultValue`` (Optional) - + **Returns** * the value stored against ``key`` if the call if successful * if the method fails: it returns ``defaultValue``, if provided; ``""`` (an empty String) otherwise. @@ -623,7 +623,7 @@ Get the number of bytes stored in the value against a key of type ``Bytes`` in t **Returns** * if successful: the number of bytes in the value stored against ``key``; ``0`` otherwise. - + **Notes** * This method will fail if ``key`` is not of type ``Bytes``. * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. @@ -646,7 +646,7 @@ Get the Preferences data type of a given key within the currently open namespace **Returns** * an ``int`` value as per Table 2 below. * a value of ``10`` (PT_INVALID) if the call fails. - + **Notes** * The return values are enumerated in ``Preferences.h``. Table 2 includes the enumerated values for information. * A return value can map to more than one Prefs Type. @@ -654,7 +654,7 @@ Get the Preferences data type of a given key within the currently open namespace .. table:: **Table 2 — getType Return Values** :align: center - + +---------------+---------------+-------------------+-----------------------+ | Return value | Prefs Type | Data Type | Enumerated Value | +===============+===============+===================+=======================+ @@ -687,7 +687,7 @@ Get the Preferences data type of a given key within the currently open namespace | 9 | Double | double_t | PT_BLOB | | +---------------+-------------------+ | | | Float | float_t | | - | +---------------+-------------------+ | + | +---------------+-------------------+ | | | Bytes | uint8_t | | +---------------+---------------+-------------------+-----------------------+ | 10 | \- | \- | PT_INVALID | @@ -710,13 +710,13 @@ Get the number of free entries available in the key table of the currently open **Returns** * if successful: the number of free entries available in the key table of the currently open namespace; ``0`` otherwise. - + **Notes** * keys storing values of type ``Bool``, ``Char``, ``UChar``, ``Short``, ``UShort``, ``Int``, ``UInt``, ``Long``, ``ULong``, ``Long64``, ``ULong64`` use one entry in the key table. * keys storing values of type ``Float`` and ``Double`` use three entries in the key table. - * Arduino or c-string ``String`` types use a minimum of two key table entries with the number of entries increasing with the length of the string. - * keys storing values of type ``Bytes`` use a minimum of three key table entries with the number of entries increasing with the number of bytes stored. + * Arduino or c-string ``String`` types use a minimum of two key table entries with the number of entries increasing with the length of the string. + * keys storing values of type ``Bytes`` use a minimum of three key table entries with the number of entries increasing with the number of bytes stored. * A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility. - + .. --- EOF ---- diff --git a/docs/en/api/rainmaker.rst b/docs/en/api/rainmaker.rst index baa7ec1d15c..3c8a7958ba9 100644 --- a/docs/en/api/rainmaker.rst +++ b/docs/en/api/rainmaker.rst @@ -149,7 +149,7 @@ For more information, check `here `_. +Complete list of `RMT examples `_. diff --git a/docs/en/api/sdmmc.rst b/docs/en/api/sdmmc.rst index 69b612b4876..f6c9db77101 100644 --- a/docs/en/api/sdmmc.rst +++ b/docs/en/api/sdmmc.rst @@ -19,4 +19,4 @@ SDMMC Test :language: arduino -Complete list of `SD MMC examples `_. +Complete list of `SD MMC examples `_. diff --git a/docs/en/api/sigmadelta.rst b/docs/en/api/sigmadelta.rst index 4505c553cf2..d3035af2938 100644 --- a/docs/en/api/sigmadelta.rst +++ b/docs/en/api/sigmadelta.rst @@ -6,7 +6,7 @@ About ----- ESP32 provides a second-order sigma delta modulation module and 8 (4 for ESP32-C3) -independent modulation channels. The channels are capable to output 1-bit +independent modulation channels. The channels are capable to output 1-bit signals (output index: 100 ~ 107) with sigma delta modulation. ========= ============================= @@ -36,7 +36,7 @@ This function is used to set up the SigmaDelta channel with the selected frequen * ``freq`` select frequency. * range is 1-14 bits (1-20 bits for ESP32). - + This function returns ``true`` if the configuration was successful. If ``false`` is returned, an error occurred and the SigmaDelta channel was not configured. diff --git a/docs/en/api/timer.rst b/docs/en/api/timer.rst index 07acd4d502a..58706d8e453 100644 --- a/docs/en/api/timer.rst +++ b/docs/en/api/timer.rst @@ -5,8 +5,8 @@ Timer About ----- -The ESP32 SoCs contains from 2 to 4 hardware timers. -They are all 64-bit (54-bit for ESP32-C3) generic timers based on 16-bit pre-scalers and 64-bit (54-bit for ESP32-C3) +The ESP32 SoCs contains from 2 to 4 hardware timers. +They are all 64-bit (54-bit for ESP32-C3) generic timers based on 16-bit pre-scalers and 64-bit (54-bit for ESP32-C3) up / down counters which are capable of being auto-reloaded. ========= ================ @@ -122,7 +122,7 @@ This function will return ``counter value`` of the timer in microseconds. timerReadMilis ************** -This function is used to read counter value in miliseconds of the timer. +This function is used to read counter value in milliseconds of the timer. .. code-block:: arduino @@ -130,7 +130,7 @@ This function is used to read counter value in miliseconds of the timer. * ``timer`` timer struct. -This function will return ``counter value`` of the timer in miliseconds. +This function will return ``counter value`` of the timer in milliseconds. timerReadSeconds **************** @@ -157,7 +157,7 @@ This function is used to get resolution in Hz of the timer. * ``timer`` timer struct. This function will return ``frequency`` in Hz of the timer. - + timerAttachInterrupt ******************** @@ -168,7 +168,7 @@ This function is used to attach interrupt to timer. void timerAttachInterrupt(hw_timer_t * timer, void (*userFunc)(void)); * ``timer`` timer struct. -* ``userFunc`` funtion to be called when interrupt is triggered. +* ``userFunc`` function to be called when interrupt is triggered. timerAttachInterruptArg *********************** @@ -180,7 +180,7 @@ This function is used to attach interrupt to timer using arguments. void timerAttachInterruptArg(hw_timer_t * timer, void (*userFunc)(void*), void * arg); * ``timer`` timer struct. -* ``userFunc`` funtion to be called when interrupt is triggered. +* ``userFunc`` function to be called when interrupt is triggered. * ``arg`` pointer to the interrupt arguments. timerDetachInterrupt @@ -197,7 +197,7 @@ This function is used to detach interrupt from timer. timerAlarm ********** -This function is used to configure alarm value and autoreload of the timer. Alarm is automaticaly enabled. +This function is used to configure alarm value and autoreload of the timer. Alarm is automatically enabled. .. code-block:: arduino diff --git a/docs/en/api/touch.rst b/docs/en/api/touch.rst index 9dd23a8d017..7b9775b2c80 100644 --- a/docs/en/api/touch.rst +++ b/docs/en/api/touch.rst @@ -5,9 +5,9 @@ TOUCH About ----- -Touch sensor is a peripheral, that has an internal oscilator circuit and it measures charge/discharge frequency over a fixed period of time on respective GPIO pins. -Therefore these touch sensors are also known as capacitive sensors. For example, if you touch any of these pins, finger electrical charge will change this number of cycles, -by changing the RC circuit attached to the touch sensor. The TouchRead() will return the number of cycles (charges/discharges) in a certain time (meas). +Touch sensor is a peripheral, that has an internal oscillator circuit and it measures charge/discharge frequency over a fixed period of time on respective GPIO pins. +Therefore these touch sensors are also known as capacitive sensors. For example, if you touch any of these pins, finger electrical charge will change this number of cycles, +by changing the RC circuit attached to the touch sensor. The TouchRead() will return the number of cycles (charges/discharges) in a certain time (meas). The change of this count will be used to validate if a touch has happened or not. These pins can be easily integrated into capacitive pads, and replace mechanical buttons. .. note:: Touch peripheral is not present in every SoC. Refer to datasheet of each chip for more info. @@ -21,7 +21,7 @@ TOUCH common API touchRead ^^^^^^^^^ -This function gets the touch sensor data. Each touch sensor has a counter to count the number of charge/discharge cycles. When the pad is ‘touched’, +This function gets the touch sensor data. Each touch sensor has a counter to count the number of charge/discharge cycles. When the pad is ‘touched’, the value in the counter will change because of the larger equivalent capacitance. The change of the data determines if the pad has been touched or not. .. code-block:: arduino @@ -29,7 +29,7 @@ the value in the counter will change because of the larger equivalent capacitanc touch_value_t touchRead(uint8_t pin); * ``pin`` GPIO pin to read TOUCH value - + This function will return touch pad value as uint16_t (ESP32) or uint32_t (ESP32-S2/S3). touchSetCycles @@ -48,8 +48,8 @@ The defaults are setting touchRead to take ~0.5ms. touchAttachInterrupt ^^^^^^^^^^^^^^^^^^^^ -This function is used to attach interrupt to the touch pad. The function will be called if a touch sensor value falls below the given -threshold for ESP32 or rises above the given threshold for ESP32-S2/S3. To determine a proper threshold value between touched and untouched state, +This function is used to attach interrupt to the touch pad. The function will be called if a touch sensor value falls below the given +threshold for ESP32 or rises above the given threshold for ESP32-S2/S3. To determine a proper threshold value between touched and untouched state, use touchRead() function. .. code-block:: arduino @@ -118,13 +118,13 @@ TOUCH API specific for ESP32S2 and ESP32S3 chip (TOUCH_V2) touchInterruptGetLastStatus ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -This function is used get the lastest ISR status for the touch pad. +This function is used get the latest ISR status for the touch pad. .. code-block:: arduino bool touchInterruptGetLastStatus(uint8_t pin); -This function returns true if the touch pad has been and continues pressed or false otherwise. +This function returns true if the touch pad has been and continues pressed or false otherwise. Example Applications ******************** @@ -139,4 +139,4 @@ A usage example for the touch interrupts. .. literalinclude:: ../../../libraries/ESP32/examples/Touch/TouchInterrupt/TouchInterrupt.ino :language: arduino -More examples can be found in our repository -> `Touch examples `_. \ No newline at end of file +More examples can be found in our repository -> `Touch examples `_. diff --git a/docs/en/api/usb.rst b/docs/en/api/usb.rst index 056e3fcc1ae..b7d77b9d5d5 100644 --- a/docs/en/api/usb.rst +++ b/docs/en/api/usb.rst @@ -109,7 +109,7 @@ firmwareVersion Set the firmware version. This is a 16 bits unsigned value. .. code-block:: arduino - + bool firmwareVersion(uint16_t version); Get the firmware version. @@ -219,7 +219,7 @@ Set the USB attributes. Get the USB attributes. .. code-block:: arduino - + uint8_t usbAttributes(void); Return the USB attributes. The default value is: ``TUSB_DESC_CONFIG_ATT_SELF_POWERED`` @@ -236,7 +236,7 @@ This function is used to enable the ``webUSB`` functionality. This function is used to get the ``webUSB`` setting. .. code-block:: arduino - + bool webUSB(void); Return the ``webUSB`` setting (`Enabled` or `Disabled`) @@ -268,7 +268,7 @@ This function is used to define the manufacturer name. This function is used to get the manufacturer's name. .. code-block:: arduino - + const char * manufacturerName(void); serialNumber diff --git a/docs/en/api/usb_cdc.rst b/docs/en/api/usb_cdc.rst index 7d700b955a8..61e9fcdf928 100644 --- a/docs/en/api/usb_cdc.rst +++ b/docs/en/api/usb_cdc.rst @@ -83,7 +83,7 @@ available This function will return if there are messages in the queue. .. code-block:: arduino - + int available(void); The return is the number of bytes available to read. diff --git a/docs/en/api/wifi.rst b/docs/en/api/wifi.rst index d18ac273686..5bdd050ac5b 100644 --- a/docs/en/api/wifi.rst +++ b/docs/en/api/wifi.rst @@ -166,7 +166,7 @@ By default, the memory allocation will be set to **dynamic** if this function is setDualAntennaConfig ******************** -Configures the Dual antenna functionallity. This function should be used only on the **ESP32-WROOM-DA** module or any other ESP32 with RF switch. +Configures the Dual antenna functionality. This function should be used only on the **ESP32-WROOM-DA** module or any other ESP32 with RF switch. .. code-block:: arduino @@ -223,7 +223,7 @@ Use the function ``softAP`` to configure the Wi-Fi AP characteristics: Where: * ``ssid`` sets the Wi-Fi network SSID. -* ``passphrase`` sets the Wi-Fi network password. If the network is open, set as ``NULL``. +* ``passphrase`` sets the Wi-Fi network password. If the network is open, set as ``NULL``. * ``channel`` configures the Wi-Fi channel. * ``ssid_hidden`` sets the network as hidden. * ``max_connection`` sets the maximum number of simultaneous connections. The default is 4. diff --git a/docs/en/boards/ESP32-C3-DevKitM-1.rst b/docs/en/boards/ESP32-C3-DevKitM-1.rst index 11e6e45d55f..763e5e5d630 100644 --- a/docs/en/boards/ESP32-C3-DevKitM-1.rst +++ b/docs/en/boards/ESP32-C3-DevKitM-1.rst @@ -83,7 +83,7 @@ No. Name Type [1]_ Function === ==== ========== ==================================== .. [1] P: Power supply; I: Input; O: Output; T: High impedance. -.. [2] GPIO2, GPIO8, and GPIO9 are strapping pins of the ESP32-C3FN4 chip. During the chip's system reset, the latches of the strapping pins sample the voltage level as strapping bits, and hold these bits until the chip is powered down or shut down. +.. [2] GPIO2, GPIO8, and GPIO9 are strapping pins of the ESP32-C3FN4 chip. During the chip's system reset, the latches of the strapping pins sample the voltage level as strapping bits, and hold these bits until the chip is powered down or shut down. Pin Layout ---------- diff --git a/docs/en/boards/ESP32-DevKitC-1.rst b/docs/en/boards/ESP32-DevKitC-1.rst index 4bb86696227..f7aa63da61c 100644 --- a/docs/en/boards/ESP32-DevKitC-1.rst +++ b/docs/en/boards/ESP32-DevKitC-1.rst @@ -125,14 +125,14 @@ Restricted Usage GPIO's Some of the GPIO's are used for the external flash and PSRAM. These GPIO's cannot be used: ==== =================== -GPIO Shared Function +GPIO Shared Function ==== =================== -IO6 External SPI Flash -IO7 External SPI Flash -IO8 External SPI Flash -IO9 External SPI Flash -IO10 External SPI Flash -IO11 External SPI Flash +IO6 External SPI Flash +IO7 External SPI Flash +IO8 External SPI Flash +IO9 External SPI Flash +IO10 External SPI Flash +IO11 External SPI Flash ==== =================== Other GPIO's are `INPUT ONLY` and cannot be used as output pin: diff --git a/docs/en/boards/ESP32-S2-Saola-1.rst b/docs/en/boards/ESP32-S2-Saola-1.rst index 1a06a6d87bb..99b4890247b 100644 --- a/docs/en/boards/ESP32-S2-Saola-1.rst +++ b/docs/en/boards/ESP32-S2-Saola-1.rst @@ -128,7 +128,7 @@ Restricted Usage GPIOS Some of the GPIO's are used for the external flash and PSRAM. These GPIO's cannot be used: ==== =================== -GPIO Shared Function +GPIO Shared Function ==== =================== IO26 Connected to PSRAM ==== =================== diff --git a/docs/en/boards/boards.rst b/docs/en/boards/boards.rst index 7115d5bcb4e..cd0b310a66a 100644 --- a/docs/en/boards/boards.rst +++ b/docs/en/boards/boards.rst @@ -23,7 +23,7 @@ The ESP32 is divided by family: * ESP32-C * Wi-Fi and BLE 5 * ESP32-H - * BLE and IEEE 802.15.4 + * BLE and IEEE 802.15.4 For each family, we have SoC variants with some differentiation. The differences are more about the embedded flash and its size and the number of the cores (dual or single). @@ -48,7 +48,7 @@ Now that you know that the module can be different but the heart is the same, yo Before buying: Keep in mind that for some "must have" features when choosing the best board for your needs: - Embedded USB-to-Serial - - This is very convenient for programming and monitoring the logs with the terminal via USB. + - This is very convenient for programming and monitoring the logs with the terminal via USB. - Breadboard friendly - If you are prototyping, this will be very useful to connect your board directly on the breadboard. - open-source/open-hardware @@ -73,7 +73,7 @@ Espressif ESP32-S2-Saola-1 ESP32-C3-DevKitM-1 -.. note:: +.. note:: Only a few development boards are described on this documentation page. For more information about other Espressif development boards please refer to the `Espressif website `_. Third Party @@ -94,12 +94,12 @@ LOLIN Generic Vendor ************** - + .. toctree:: :maxdepth: 1 - + Generic Board Name - + .. note:: Create one file per board or one file with multiple boards. Do not add board information/description on this file. @@ -108,7 +108,7 @@ Generic Vendor Resources --------- -.. _Espressif Systems: https://www.espressif.com +.. _Espressif Systems: https://www.espressif.com .. _Espressif Product Selector: https://products.espressif.com/ .. |board_lolin_d32| raw:: html diff --git a/docs/en/conf.py b/docs/en/conf.py index 9979662dae0..c4291af80e8 100644 --- a/docs/en/conf.py +++ b/docs/en/conf.py @@ -12,20 +12,22 @@ except ImportError: import os import sys - sys.path.insert(0, os.path.abspath('../')) + + sys.path.insert(0, os.path.abspath("../")) from conf_common import * # noqa: F403,F401 import datetime + current_year = datetime.datetime.now().year # General information about the project. -project = u'Arduino ESP32' -copyright = u'2016 - {}, Espressif Systems (Shanghai) Co., Ltd'.format(current_year) -pdf_title = u'Arduino ESP32 Documentation Guide' +project = "Arduino ESP32" +copyright = "2016 - {}, Espressif Systems (Shanghai) Co., Ltd".format(current_year) +pdf_title = "Arduino ESP32 Documentation Guide" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -language = 'en' +language = "en" # Tracking ID for Google Analytics -google_analytics_id = 'G-F58JM78930' \ No newline at end of file +google_analytics_id = "G-F58JM78930" diff --git a/docs/en/contributing.rst b/docs/en/contributing.rst index f259d9a96c8..1c2b27c98bf 100644 --- a/docs/en/contributing.rst +++ b/docs/en/contributing.rst @@ -24,7 +24,7 @@ Before sending us a Pull Request, please consider this: * Are comments and documentation written in clear English, with no spelling or grammar errors? * Example contributions are also welcome. - + * If you are contributing by adding a new example, please use the `Arduino style guide`_ and the example guideline below. * If the contribution contains multiple commits, are they grouped together into logical changes (one major change per pull request)? Are any commits with names like "fixed typo" `squashed into previous commits `_? diff --git a/docs/en/esp-idf_component.rst b/docs/en/esp-idf_component.rst index c6dbe68e662..f3c7c7ce9af 100644 --- a/docs/en/esp-idf_component.rst +++ b/docs/en/esp-idf_component.rst @@ -28,7 +28,7 @@ Installation #. In the project folder, create a new folder called ``components`` and clone this repository inside the newly created folder. .. code-block:: bash - + mkdir -p components && \ cd components && \ git clone https://github.com/espressif/arduino-esp32.git arduino && \ diff --git a/docs/en/external_libraries_test.rst b/docs/en/external_libraries_test.rst index 0d7da671cd2..4dda53cda0b 100644 --- a/docs/en/external_libraries_test.rst +++ b/docs/en/external_libraries_test.rst @@ -9,7 +9,7 @@ External libraries testing is a compilation test for listed libraries on arduino External libraries test is running periodically (once a week) against master branch and can also run on PR by adding a label ``lib_test``. The test is running on all supported ESP32 chips. -.. note:: +.. note:: As the test is just a compilation of example, that does not guarantee that the library/sketch will run without any problems after flashing it on your device. How to Add Library to Test @@ -17,7 +17,7 @@ How to Add Library to Test To add a library to the CI test you need to add your library to the `lib.json`_. file located in ``./github/workflows/``. -.. note:: +.. note:: Please add the libraries to the `lib.json`_ in alphabetical order, thanks. List of parameters: @@ -32,7 +32,7 @@ Required: * ``exclude_targets`` - List of targets to be excluded from testing. Use only when the SoC dont support used peripheral. * ``sketch_path`` - Path / paths to the sketch / sketches to be tested. - + Optional: * ``version`` - Version of the library. @@ -80,7 +80,7 @@ Submit a PR * Open a PR with the changes and someone from Espressif team will add a label ``lib_test`` to the PR and CI will run the test to check, if the addition is fine and the library/example is compiling. * After merging your PR, the next scheduled test will test your library and add the results to the `LIBRARIES_TEST.md`_. - + Test Results ------------ @@ -129,4 +129,4 @@ In the table the results are in order ``BEFORE -> AFTER``. :class: no-scaled-link .. _LIBRARIES_TEST.md: https://github.com/espressif/arduino-esp32/blob/gh-pages/LIBRARIES_TEST.md -.. _lib.json: https://github.com/espressif/arduino-esp32/.github/workflow/lib.json \ No newline at end of file +.. _lib.json: https://github.com/espressif/arduino-esp32/.github/workflow/lib.json diff --git a/docs/en/faq.rst b/docs/en/faq.rst index af26ec96927..97520b35673 100644 --- a/docs/en/faq.rst +++ b/docs/en/faq.rst @@ -14,4 +14,4 @@ Note that modifying ``sdkconfig`` or ``sdkconfig.h`` files found in the arduino- How to compile libs with different debug level? ----------------------------------------------- -The short answer is ``esp32-arduino-lib-builder/configs/defconfig.common:44``. A guide explaining the process can be found here \ No newline at end of file +The short answer is ``esp32-arduino-lib-builder/configs/defconfig.common:44``. A guide explaining the process can be found here diff --git a/docs/en/getting_started.rst b/docs/en/getting_started.rst index 9267f1b427f..a4b69696787 100644 --- a/docs/en/getting_started.rst +++ b/docs/en/getting_started.rst @@ -16,12 +16,12 @@ First Things First ESP32 is a single 2.4 GHz Wi-Fi-and-Bluetooth SoC (System On a Chip) designed by `Espressif Systems`_. -ESP32 is designed for mobile, wearable electronics, and Internet-of-Things (IoT) applications. It features all the state-of-the-art characteristics -of low-power chips, including fine-grained clock gating, multiple power modes,and dynamic power scaling. For instance, in a low-power IoT sensor -hub application scenario, ESP32 is woken-up periodically and only when a specified condition is detected. Low-duty cycle is used to minimize the -amount of energy that the chip expends. +ESP32 is designed for mobile, wearable electronics, and Internet-of-Things (IoT) applications. It features all the state-of-the-art characteristics +of low-power chips, including fine-grained clock gating, multiple power modes,and dynamic power scaling. For instance, in a low-power IoT sensor +hub application scenario, ESP32 is woken-up periodically and only when a specified condition is detected. Low-duty cycle is used to minimize the +amount of energy that the chip expends. -The output of the power amplifier is also adjustable, thus contributing to an optimal trade-off between communication range, data rate and +The output of the power amplifier is also adjustable, thus contributing to an optimal trade-off between communication range, data rate and power consumption. The ESP32 series is available as a chip or module. @@ -50,7 +50,7 @@ See `Boards `_ for more details about ESP32 development boar Arduino Core Reference ---------------------- -This documentation is built on the ESP32 and we are not going to cover the common Arduino API. To see the Arduino reference documentation, +This documentation is built on the ESP32 and we are not going to cover the common Arduino API. To see the Arduino reference documentation, please consider reading the official documentation. Arduino Official Documentation: `Arduino Reference`_. @@ -105,7 +105,7 @@ Here are some community channels where you may find information and ask for some Issues Reporting ---------------- -Before opening a new issue, please read this: +Before opening a new issue, please read this: Be sure to search for a similar reported issue. This avoids duplicating or creating noise in the GitHub Issues reporting. We also have the troubleshooting guide to save your time on the most common issues reported by users. @@ -123,7 +123,7 @@ To install Arduino-ESP32, please see the dedicated section on the Installation g .. toctree:: :maxdepth: 2 - + How to Install Development Boards @@ -142,7 +142,7 @@ There is also a `list of examples `_ Resources --------- -.. _Espressif Systems: https://www.espressif.com +.. _Espressif Systems: https://www.espressif.com .. _Espressif Product Selector: https://products.espressif.com/ .. _Arduino.cc: https://www.arduino.cc/en/Main/Software .. _Arduino Reference: https://www.arduino.cc/reference/en/ diff --git a/docs/en/guides/core_debug.rst b/docs/en/guides/core_debug.rst index 1f39567e2f5..c2a0158e225 100644 --- a/docs/en/guides/core_debug.rst +++ b/docs/en/guides/core_debug.rst @@ -35,4 +35,3 @@ Then simply build the libs for all SoCs or one specific SoC. Note that building - ``esp32s3`` - Example: ``./build.sh -t esp32`` - A wrong format or non-existing SoC will result in the error sed: can't read sdkconfig: No such file or directory - diff --git a/docs/en/guides/docs_contributing.rst b/docs/en/guides/docs_contributing.rst index fd7e097cdf2..c167c6176d2 100644 --- a/docs/en/guides/docs_contributing.rst +++ b/docs/en/guides/docs_contributing.rst @@ -89,15 +89,15 @@ If everything is ok, you will see some output logs similar to this one: building [mo]: targets for 0 po files that are out of date building [html]: targets for 35 source files that are out of date updating environment: [extensions changed ('sphinx_tabs.tabs')] 41 added, 3 changed, 0 removed - reading sources... [100%] tutorials/tutorials + reading sources... [100%] tutorials/tutorials looking for now-outdated files... none found pickling environment... done checking consistency... done preparing documents... done - writing output... [100%] tutorials/tutorials + writing output... [100%] tutorials/tutorials generating indices... genindexdone writing additional pages... searchdone - copying images... [100%] tutorials/../../_static/tutorials/peripherals/tutorial_peripheral_diagram.png + copying images... [100%] tutorials/../../_static/tutorials/peripherals/tutorial_peripheral_diagram.png copying static files... ... done copying extra files... done dumping search index in English (code: en)... done @@ -180,7 +180,7 @@ Here is an example of how to add the function description from `I2C API "Preferences" > "Sketchbook location" (in the IDE once started). Adjust the command above accordingly. diff --git a/docs/en/libraries.rst b/docs/en/libraries.rst index a3c32b4d6dd..6d0bfeabc0f 100644 --- a/docs/en/libraries.rst +++ b/docs/en/libraries.rst @@ -71,7 +71,7 @@ APIs The Arduino ESP32 offers some unique APIs, described in this section: -.. note:: +.. note:: Please be advised that we cannot ensure continuous compatibility between the Arduino Core ESP32 APIs and ESP8266 APIs, as well as Arduino-Core APIs (Arduino.cc). While our aim is to maintain harmony, the addition of new features may result in occasional divergence. We strive to achieve the best possible integration but acknowledge that perfect compatibility might not always be feasible. Please refer to the documentation for any specific considerations. @@ -79,5 +79,5 @@ The Arduino ESP32 offers some unique APIs, described in this section: .. toctree:: :maxdepth: 1 :glob: - + api/* diff --git a/docs/en/make.rst b/docs/en/make.rst index c10ee0d140f..fce7f94a7a7 100644 --- a/docs/en/make.rst +++ b/docs/en/make.rst @@ -2,5 +2,5 @@ makeEspArduino ============== -The `makeEspArduino `_ is a generic makefile for any ESP8266/ESP32 Arduino project. +The `makeEspArduino `_ is a generic makefile for any ESP8266/ESP32 Arduino project. Using it instead of the Arduino IDE makes it easier to do automated and production builds. diff --git a/docs/en/migration_guides/2.x_to_3.0.rst b/docs/en/migration_guides/2.x_to_3.0.rst index 730cde690e8..e1ace29c662 100644 --- a/docs/en/migration_guides/2.x_to_3.0.rst +++ b/docs/en/migration_guides/2.x_to_3.0.rst @@ -44,7 +44,7 @@ Removed APIs I2S --- -The I2S driver has been completely redesigned and refactored to use the new ESP-IDF driver. +The I2S driver has been completely redesigned and refactored to use the new ESP-IDF driver. For more information about the new API, check :doc:`/api/i2s`. LEDC @@ -206,4 +206,4 @@ Functional changes * In Arduino (and other frameworks) the method named ``flush()`` is intended to send out the transmit buffer content. ``WiFiClient`` and ``WiFiUDP`` method ``flush()`` won't clear the receive buffer anymore. A new method called ``clear()`` is now used for that. Currently ``flush()`` does nothing in ``WiFiClient``, ``WiFiClientSecure`` and ``WiFiUDP``. * ``WiFiServer`` has functions ``accept()`` and ``available()`` with the same functionality. In Arduino, ``available()`` should work differently so it is now deprecated. -* ``WiFiServer`` had unimplemented write functions inherited from ``Print`` class. These are now removed. Also unimplemented method ``stopAll()`` is removed. The methods were unimplemented because WiFiServer doesn't manage connected WiFiClient objects for print-to-all-clients functionality. \ No newline at end of file +* ``WiFiServer`` had unimplemented write functions inherited from ``Print`` class. These are now removed. Also unimplemented method ``stopAll()`` is removed. The methods were unimplemented because WiFiServer doesn't manage connected WiFiClient objects for print-to-all-clients functionality. diff --git a/docs/en/ota_web_update.rst b/docs/en/ota_web_update.rst index 179101770a0..2d5c4e529c0 100644 --- a/docs/en/ota_web_update.rst +++ b/docs/en/ota_web_update.rst @@ -55,7 +55,7 @@ Prepare the sketch and configuration for initial upload with a serial port * password = admin .. note:: - *If entering “http://ESP32.local” does not work, try replacing “ESP32” with module’s IP address. This workaround is useful in case the host software installed does not work*. + *If entering “http://ESP32.local” does not work, try replacing “ESP32” with module’s IP address. This workaround is useful in case the host software installed does not work*. Now click on the Login button and browser will display an upload form diff --git a/docs/en/tutorials/blink.rst b/docs/en/tutorials/blink.rst index f65af1b3bae..b5f6a767f8d 100644 --- a/docs/en/tutorials/blink.rst +++ b/docs/en/tutorials/blink.rst @@ -25,7 +25,7 @@ In order to make this simple blink tutorial, you'll need to do the following ste #define LED 2 -This ``#define LED 2`` will be used to set the GPIO2 as the ``LED`` output pin. +This ``#define LED 2`` will be used to set the GPIO2 as the ``LED`` output pin. 2. **Setup.** @@ -110,4 +110,4 @@ Resources .. _ESP32 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf .. _Wokwi: https://wokwi.com/ .. _PlatformIO: https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html#platformio -.. _Arduino IDE: https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html#installing-using-boards-manager \ No newline at end of file +.. _Arduino IDE: https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html#installing-using-boards-manager diff --git a/docs/en/tutorials/io_mux.rst b/docs/en/tutorials/io_mux.rst index 03b10449013..3cff49812b1 100644 --- a/docs/en/tutorials/io_mux.rst +++ b/docs/en/tutorials/io_mux.rst @@ -41,7 +41,7 @@ To use this functionality, we must be aware of some precautions: Before assigning the peripheral pins in your design, double check if the pins you're using are appropriate. The input-only pins cannot be used for peripherals that require output or input/output signals. -The greatest advantage of this functionality is the fact that we don't need to be fully dependent on the physical pin, since we can change according to our needs. +The greatest advantage of this functionality is the fact that we don't need to be fully dependent on the physical pin, since we can change according to our needs. This can facilitate the hardware design routing or in some cases, fix some pin swap mistake during the hardware design phase. Peripherals @@ -83,7 +83,7 @@ This table is present on each datasheet provided by Espressif. Usage Examples -------------- -In the Arduino Uno, we have the I2C pins defined by hardware, A4 is the SDA and A5 the SCL. In this case, we do not need to set +In the Arduino Uno, we have the I2C pins defined by hardware, A4 is the SDA and A5 the SCL. In this case, we do not need to set these pins in the ``Wire.begin();`` function, because they are already into the Wire library. .. code-block:: arduino @@ -93,7 +93,7 @@ these pins in the ``Wire.begin();`` function, because they are already into the Wire.begin(); // join i2c bus (address optional for master) } -Now, for the ESP32, the default pins for the I2C are SDA (GPIO21) and SCL (GPIO22). We can use a different pin as alternative for the +Now, for the ESP32, the default pins for the I2C are SDA (GPIO21) and SCL (GPIO22). We can use a different pin as alternative for the default ones if you need to change the pins. To change the pins, we must call the ``Wire.setPins(int sda, int scl);`` function before calling ``Wire.begin();``. @@ -101,7 +101,7 @@ To change the pins, we must call the ``Wire.setPins(int sda, int scl);`` functio int sda_pin = 16; // GPIO16 as I2C SDA int scl_pin = 17; // GPIO17 as I2C SCL - + void setup() { Wire.setPins(sda_pin, scl_pin); // Set the I2C pins before begin @@ -115,6 +115,6 @@ A similar approach also applies for the other peripherals. Resources --------- -.. _Espressif Systems: https://www.espressif.com +.. _Espressif Systems: https://www.espressif.com .. _Espressif Product Selector: https://products.espressif.com/ .. _IO MUX GPIO: https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf#iomuxgpio diff --git a/docs/en/tutorials/partition_table.rst b/docs/en/tutorials/partition_table.rst index 933ff22d77f..b267461bd1c 100644 --- a/docs/en/tutorials/partition_table.rst +++ b/docs/en/tutorials/partition_table.rst @@ -9,7 +9,7 @@ Partition table is used to define the flash memory organization and the differen You can use one of the available partition table scheme or create your own. You can see all the different schemes on the `tools/partitions `_ folder or by the Arduino IDE tools menu `Tools -> Partition Scheme`. -The partition table is created by a .CSV (Comma-separeted Values) file with the following structure: +The partition table is created by a .CSV (Comma-separated Values) file with the following structure: .. code-block:: @@ -35,35 +35,35 @@ Where: The SubType defines the usage of the ``app`` and ``data`` partitions. **data** - + ``ota`` The ota subtype is used to store the OTA information. This partition is used only when the OTA is used to select the initialization partition, otherwise no need to add it to your custom partition table. The size of this partition should be a fixed size of 8kB (0x2000 bytes). - + ``nvs`` The nvs partition subtype is used to define the partition to store general data, like the WiFi data, device PHY calibration data and any other data to be stored on the non-volatile memory. This kind of partition is suitable for small custom configuration data, cloud certificates, etc. Another usage for the NVS is to store sensitive data, since the NVS supports encryption. It is highly recommended to add at least one nvs partition, labeled with the name nvs, in your custom partition tables with size of at least 12kB (0x3000 bytes). If needed, you can increase the size of the nvs partition. The recommended size for this partition is from 12kb to 64kb. Although larger NVS partitions can be defined, we recommend using FAT or SPIFFS filesystem for storage of larger amounts of data. - + ``coredump`` The coredump partition subtype is used to store the core dump on the flash. The core dump is used to analyze critical errors like crash and panic. This function must be enabled in the project configuration menu and set the data destination to flash. The recommended size for this partition is 64kB (0x10000). - + ``nvs_keys`` The nvs_keys partition subtype is used to store the keys when the NVS encryption is used. The size for this partition is 4kB (0x1000). - + ``fat`` The fat partition subtype defines the FAT filesystem usage, and it is suitable for larger data and if this data is often updated and changed. The FAT FS can be used with wear leveling feature to increase the erase/modification cycles per memory sector and encryption for sensitive data storage, like cloud certificates or any other data that may be protected. To use FAT FS with wear leveling see the example. - + ``spiffs`` The spiffs partition subtype defines the SPI flash filesystem usage, and it is also suitable for larger files and it also performs the wear leveling and file system consistency check. @@ -72,24 +72,24 @@ Where: **app** ``factory`` - + The factory partition subtype is the default application. The bootloader will set this partition as the default application initialization if no OTA partition is found, or the OTA partitions are empty. If the OTA partition is used, the ota_0 can be used as the default application and the factory can be removed from the partition table to save memory space. - + ``ota_0`` to ``ota_15`` - + The ota_x partition subtype is used for the Over-the air update. The OTA feature requires at least two ota_x partition (usually ota_0 and ota_1) and it also requires the ota partition to keep the OTA information data. Up to 16 OTA partitions can be defined but only two are needed for basic OTA feature. - + ``test`` - + The test partition subtype is used for factory test procedures. 4. **Offset** The offset defines the partition start address. The offset is defined by the sum of the offset and the size of the earlier partition. -.. note:: +.. note:: Offset must be multiple of 4kB (0x1000) and for app partitions it must be aligned by 64kB (0x10000). If left blank, the offset will be automatically calculated based on the end of the previous partition, including any necessary alignment, however, the offset for the first partition must be always set as **0x9000** and for the first application partition **0x10000**. diff --git a/docs/en/tutorials/preferences.rst b/docs/en/tutorials/preferences.rst index 3cb54f1928c..dd27913c38f 100644 --- a/docs/en/tutorials/preferences.rst +++ b/docs/en/tutorials/preferences.rst @@ -8,7 +8,7 @@ Introduction The Preferences library is unique to arduino-esp32. It should be considered as the replacement for the Arduino EEPROM library. -It uses a portion of the on-board non-volatile memory (NVS) of the ESP32 to store data. This data is retained across restarts and loss of power events to the system. +It uses a portion of the on-board non-volatile memory (NVS) of the ESP32 to store data. This data is retained across restarts and loss of power events to the system. Preferences works best for storing many small values, rather than a few large values. If you need to store large amounts of data, consider using a file system library such as LitteFS. @@ -44,11 +44,11 @@ Library methods are provided to: - determine data types stored against a key; - determine the number of key entries available in the namespace. -Preferences directly suports the following data types: +Preferences directly supports the following data types: .. table:: **Table 1 — Preferences Types** :align: center - + +-------------------+-------------------+---------------+ | Preferences Type | Data Type | Size (bytes) | +===================+===================+===============+ @@ -107,7 +107,7 @@ To retrieve a value: *(Technically, you can retrieve a value if the namespace is open in either read-only or read-write mode but it's good practice to open the namespace in read-only mode if you are only retrieving values.)* -When storing information, a "``put[PreferencesType]``" method referenced to its key is used. +When storing information, a "``put[PreferencesType]``" method referenced to its key is used. When retrieving information a "``get[PreferencesType]``" method referenced to its key is used. @@ -130,7 +130,7 @@ Each step is discussed below. .. - + Create or Open the Namespace ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -140,7 +140,7 @@ In your sketch, first insert a declaration of a ``Preferences`` object by includ Preferences mySketchPrefs; // "mySketchPrefs" is the name of the Preferences object. // Can be whatever you want. - + This object is used with the Preferences methods to access the namespace and the key-value pairs it contains. A namespace is made available for use with the ``.begin`` method: @@ -178,25 +178,25 @@ By example, consider this code segment: Preferences mySketchPrefs; String doesExist; - mySketchPrefs.begin("myPrefs", false); // open (or create and then open if it does not + mySketchPrefs.begin("myPrefs", false); // open (or create and then open if it does not // yet exist) the namespace "myPrefs" in RW mode. - + bool doesExist = mySketchPrefs.isKey("myTestKey"); - + if (doesExist == false) { - /* + /* If doesExist is false, we will need to create our namespace key(s) and store a value into them. - */ - + */ + // Insert your "first time run" code to create your keys & assign their values below here. } else { - /* + /* If doesExist is true, the key(s) we need have been created before and so we can access their values as needed during startup. */ - + // Insert your "we've been here before" startup code below here. } @@ -217,7 +217,7 @@ An example is: .. code-block:: arduino - myPreferences.putFloat("pi", 3.14159265359); // stores an float_t data type + myPreferences.putFloat("pi", 3.14159265359); // stores an float_t data type // against the key "pi". Reading Values From a Namespace @@ -244,13 +244,13 @@ Summary So the basics of using Preferences are: #. You cannot store into or retrieve from a ``key-value`` pair until a namespace is created and opened and the key exists in that namespace. - + #. If the key already exists, it was created the first time the sketch was run. #. A key value can be retrieved regardless of the mode in which the namespace was opened, but a value can only be stored if the namespace is open in read-write mode. - + #. Data types of the “``get``'s” and “``put``'s” must match. - + #. Remember the 15 character limit for namespace and key names. @@ -264,65 +264,65 @@ Its purpose is to set either a factory default configuration if the system has n When started, the system has no way of knowing which of the above conditions is true. So the first thing it does after opening the namespace is check for the existence of a key that we have predetermined can only exist if we have previously run the sketch. Based on its existence we decide if a factory default set of operating parameters should be used (and in so doing create the namespace keys and populate the values with defaults) or if we should use operating parameters from the last time the system was running. .. code-block:: arduino - + #include - + #define RW_MODE false #define RO_MODE true - + Preferences stcPrefs; void setup() { - + // not the complete setup(), but in setup(), include this... - + stcPrefs.begin("STCPrefs", RO_MODE); // Open our namespace (or create it // if it doesn't exist) in RO mode. - + bool tpInit = stcPrefs.isKey("nvsInit"); // Test for the existence // of the "already initialized" key. if (tpInit == false) { - // If tpInit is 'false', the key "nvsInit" does not yet exist therefore this + // If tpInit is 'false', the key "nvsInit" does not yet exist therefore this // must be our first-time run. We need to set up our Preferences namespace keys. So... stcPrefs.end(); // close the namespace in RO mode and... stcPrefs.begin("STCPrefs", RW_MODE); // reopen it in RW mode. - - // The .begin() method created the "STCPrefs" namespace and since this is our + + // The .begin() method created the "STCPrefs" namespace and since this is our // first-time run we will create // our keys and store the initial "factory default" values. stcPrefs.putUChar("curBright", 10); stcPrefs.putString("talChan", "one"); stcPrefs.putLong("talMax", -220226); stcPrefs.putBool("ctMde", true); - + stcPrefs.putBool("nvsInit", true); // Create the "already initialized" // key and store a value. - + // The "factory defaults" are created and stored so... stcPrefs.end(); // Close the namespace in RW mode and... stcPrefs.begin("STCPrefs", RO_MODE); // reopen it in RO mode so the setup code // outside this first-time run 'if' block // can retrieve the run-time values - // from the "STCPrefs" namespace. + // from the "STCPrefs" namespace. } // Retrieve the operational parameters from the namespace // and save them into their run-time variables. - currentBrightness = stcPrefs.getUChar("curBright"); // + currentBrightness = stcPrefs.getUChar("curBright"); // tChannel = stcPrefs.getString("talChan"); // The LHS variables were defined tChanMax = stcPrefs.getLong("talMax"); // earlier in the sketch. ctMode = stcPrefs.getBool("ctMde"); // - + // All done. Last run state (or the factory default) is now restored. stcPrefs.end(); // Close our preferences namespace. - + // Carry on with the rest of your setup code... - - // When the sketch is running, it updates any changes to an operational parameter + + // When the sketch is running, it updates any changes to an operational parameter // to the appropriate key-value pair in the namespace. - + } @@ -337,23 +337,23 @@ Deleting key-value Pairs .. code-block:: arduino preferences.clear(); - -.. + +.. - Deletes *all* the key-value pairs in the currently opened namespace. - + - The namespace still exists. - + - The namespace must be open in read-write mode for this to work. .. code-block:: arduino preferences.remove("keyname"); - -.. + +.. - Deletes the "keyname" and value associated with it from the currently opened namespace. - + - The namespace must be open in read-write mode for this to work. - Tip: use this to remove the "test key" to force a "factory reset" during the next reboot (see the *Real World Example* above). @@ -363,13 +363,13 @@ If either of the above are used, the ``key-value`` pair will need to be recreate Determining the Number of Available Keys ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -For each namespace, Preferences keeps track of the keys in a key table. There must be an open entry in the table before a key can be created. This method will return the number of entires available in the table. +For each namespace, Preferences keeps track of the keys in a key table. There must be an open entry in the table before a key can be created. This method will return the number of entries available in the table. .. code-block:: arduino freeEntries() - -.. + +.. To send to the serial monitor the number of available entries the following could be used. @@ -405,7 +405,7 @@ As in: .. code-block:: arduino PreferenceType whatType = getType("myKey"); - + .. The value returned is a ``PreferenceType`` value that maps to a Preferences Type. Refer to the description in the `Preferences API Reference`_ for details. @@ -424,7 +424,7 @@ The library provides the following methods to facilitate this. putBytes("myBytesKey", value, valueLen) getBytes("myBytesKey", buffer, valueLen) getBytesLength("myBytesKey") - + .. The ``put`` and ``get`` ``Bytes`` methods store and retrieve the data. The ``getBytesLength`` method is used to find the size of the data stored against the key (which is needed to retrieve ``Bytes`` data). @@ -458,21 +458,21 @@ This is best explained with an example. Here the ``Bytes`` methods are used to s Serial.begin(115200); delay(250); - + mySketchPrefs.begin("myPrefs", RW_MODE); // open (or create) the namespace // "myPrefs" in RW mode mySketchPrefs.clear(); // delete any previous keys in this namespace - + // Create an array of test values. We're using hex numbers // throughout to better show how the bytes move around. int16_t myArray[] = { 0x1112, 0x2122, 0x3132, 0x4142, 0x5152, 0x6162, 0x7172 }; - + Serial.println("Printing myArray..."); for (int i = 0; i < sizeof(myArray) / sizeof(int16_t); i++) { Serial.print(myArray[i], HEX); Serial.print(", "); } Serial.println("\r\n"); - + // In the next statement, the second sizeof() needs // to match the data type of the elements of myArray Serial.print("The number of elements in myArray is: "); @@ -480,22 +480,22 @@ This is best explained with an example. Here the ``Bytes`` methods are used to s Serial.print("But the size of myArray in bytes is: "); Serial.println( sizeof(myArray) ); Serial.println(""); - + Serial.println( "Storing myArray into the Preferences namespace \"myPrefs\" against the key \"myPrefsBytes\"."); - // Note: in the next statement, to store the entire array, we must use the - // size of the arrray in bytes, not the number of elements in the array. + // Note: in the next statement, to store the entire array, we must use the + // size of the array in bytes, not the number of elements in the array. mySketchPrefs.putBytes( "myPrefsBytes", myArray, sizeof(myArray) ); Serial.print("The size of \"myPrefsBytes\" is (in bytes): "); Serial.println( mySketchPrefs.getBytesLength("myPrefsBytes") ); Serial.println(""); - + int16_t myIntBuffer[20] = {}; // No magic about 20. Just making a buffer (array) big enough. Serial.println("Retrieving the value of myPrefsBytes into myIntBuffer."); Serial.println(" - Note the data type of myIntBuffer matches that of myArray"); mySketchPrefs.getBytes("myPrefsBytes", myIntBuffer, mySketchPrefs.getBytesLength("myPrefsBytes")); - + Serial.println("Printing myIntBuffer..."); // In the next statement, sizeof() needs to match the data type of the elements of myArray for (int i = 0; i < mySketchPrefs.getBytesLength("myPrefsBytes") / sizeof(int16_t); i++) { @@ -508,7 +508,7 @@ This is best explained with an example. Here the ``Bytes`` methods are used to s uint8_t myByteBuffer[40] = {}; // No magic about 40. Just making a buffer (array) big enough. mySketchPrefs.getBytes("myPrefsBytes", myByteBuffer, mySketchPrefs.getBytesLength("myPrefsBytes")); - + Serial.println("Printing myByteBuffer..."); for (int i = 0; i < mySketchPrefs.getBytesLength("myPrefsBytes"); i++) { Serial.print(myByteBuffer[i], HEX); Serial.print(", "); @@ -527,7 +527,7 @@ The resulting output is: :: Printing myArray... - 1112, 2122, 3132, 4142, 5152, 6162, 7172, + 1112, 2122, 3132, 4142, 5152, 6162, 7172, The number of elements in myArray is: 7 But the size of myArray in bytes is: 14 @@ -538,11 +538,11 @@ The resulting output is: Retrieving the value of myPrefsBytes into myIntBuffer. - Note the data type of myIntBuffer matches that of myArray Printing myIntBuffer... - 1112, 2122, 3132, 4142, 5152, 6162, 7172, + 1112, 2122, 3132, 4142, 5152, 6162, 7172, We can see how the data from myArray is actually stored in the namespace as follows. Printing myByteBuffer... - 12, 11, 22, 21, 32, 31, 42, 41, 52, 51, 62, 61, 72, 71, + 12, 11, 22, 21, 32, 31, 42, 41, 52, 51, 62, 61, 72, 71, You can copy the sketch and change the data type and values in ``myArray`` and follow along with the code and output to see how the ``Bytes`` methods work. The data type of ``myIntBuffer`` should be changed to match that of ``myArray`` (and check the "``sizeof()``'s" where indicated in the comments). @@ -563,32 +563,32 @@ If you need to access a different namespace, close the one before opening the ot currentNamespace.begin("myNamespace", false); // do stuff... - currentNamespace.end(); // closes 'myNamespace' - + currentNamespace.end(); // closes 'myNamespace' + currentNamespace.begin("myOtherNamespace", false); // opens a different Preferences namesspace. // do other stuff... - + currentNamespace.end(); // closes 'myOtherNamespace' Here the "``currentNamespace``" object is reused, but different Preferences objects can be declared and used. Just remember to keep it all straight as all "``putX``'s" and "``getX``'s", etc. will only operate on the single currently opened namespace. -A Closer Look at ``getX`` +A Closer Look at ``getX`` -------------------------- Methods in the Preferences library return a status code that can be used to determine if the method completed successfully. This is described in the `Preferences API Reference`_. -Assume we have a key named "``favourites``" that contains a value of a ``String`` data type. +Assume we have a key named ``favorites`` that contains a value of a ``String`` data type. After executing the statement: .. code-block:: arduino - dessert = mySketchPrefs.getString("favourites"); - + dessert = mySketchPrefs.getString("favorites"); + .. -the variable ``dessert`` will contain the value of the string stored against the key ``"favourites"``. +the variable ``dessert`` will contain the value of the string stored against the key ``"favorites"``. But what if something went wrong and the ``getString`` call failed to retrieve the key value? How would we be able to detect the error? @@ -640,7 +640,7 @@ Returning to the example above: .. code-block:: arduino - dessert = mySketchPrefs.getString("favourites", "gravel"); + dessert = mySketchPrefs.getString("favorites", "gravel"); .. @@ -676,9 +676,9 @@ To completely erase and reformat the NVS memory used by Preferences, create and ; } -.. +.. -.. warning:: +.. warning:: **You should download a new sketch to your board immediately after running the above or else it will reformat the NVS partition every time it is powered up or restarted!** diff --git a/docs/utils.sh b/docs/utils.sh index 0f9574e57a5..84f37489975 100644 --- a/docs/utils.sh +++ b/docs/utils.sh @@ -15,4 +15,4 @@ function add_doc_server_ssh_keys() { local server_user="${3}" add_ssh_keys "${key_string}" echo -e "Host ${server_url}\n\tStrictHostKeyChecking no\n\tUser ${server_user}\n" >>~/.ssh/config -} \ No newline at end of file +} diff --git a/idf_component.yml b/idf_component.yml index 634d364ba3a..c9c0342647b 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -83,4 +83,3 @@ dependencies: - if: "target in [esp32s3]" examples: - path: ./idf_component_examples/Hello_world - diff --git a/idf_component_examples/Hello_world/README.md b/idf_component_examples/Hello_world/README.md index e4fcc16ff34..f666805dd8a 100644 --- a/idf_component_examples/Hello_world/README.md +++ b/idf_component_examples/Hello_world/README.md @@ -8,7 +8,7 @@ See [Arduino-esp32](https://components.espressif.com/components/espressif/arduin ## How to use example -To create a ESP-IDF project from this example with the latest relase of Arduino-esp32, you can simply run command: `idf.py create-project-from-example "espressif/arduino-esp32:hello_world"`. +To create a ESP-IDF project from this example with the latest release of Arduino-esp32, you can simply run command: `idf.py create-project-from-example "espressif/arduino-esp32:hello_world"`. ESP-IDF will download all dependencies needed from the component registry and setup the project for you. If you want to use cloned Arduino-esp32 repository, you can build this example directly. @@ -22,7 +22,7 @@ The project **Hello_world** contains one source file in C++ language [main.cpp]( ESP-IDF projects are built using CMake. The project build configuration is contained in `CMakeLists.txt` files that provide set of directives and instructions describing the project's source files and targets -(executable, library, or both). +(executable, library, or both). Below is short explanation of remaining files in the project folder. @@ -60,4 +60,4 @@ Below is structure of the project folder with the Arduino libraries. │ ├── idf_component.yml │   └── main.cpp └── README.md This is the file you are currently reading -``` \ No newline at end of file +``` diff --git a/idf_component_examples/Hello_world/main/idf_component.yml b/idf_component_examples/Hello_world/main/idf_component.yml index 42e1b06e52d..f955824767c 100644 --- a/idf_component_examples/Hello_world/main/idf_component.yml +++ b/idf_component_examples/Hello_world/main/idf_component.yml @@ -1,6 +1,6 @@ ## IDF Component Manager Manifest File dependencies: espressif/arduino-esp32: - version: '*' - override_path: '../../../' + version: "*" + override_path: "../../../" pre_release: true diff --git a/idf_component_examples/Hello_world/main/main.cpp b/idf_component_examples/Hello_world/main/main.cpp index 450fa4078f5..7068f5f15cf 100644 --- a/idf_component_examples/Hello_world/main/main.cpp +++ b/idf_component_examples/Hello_world/main/main.cpp @@ -1,10 +1,10 @@ #include "Arduino.h" -void setup(){ +void setup() { Serial.begin(115200); } -void loop(){ - Serial.println("Hello world!"); - delay(1000); +void loop() { + Serial.println("Hello world!"); + delay(1000); } diff --git a/libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino b/libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino index 9492c8383f2..2c7380f10b0 100644 --- a/libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino +++ b/libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino @@ -35,7 +35,7 @@ void setup() { String type; if (ArduinoOTA.getCommand() == U_FLASH) type = "sketch"; - else // U_SPIFFS + else // U_SPIFFS type = "filesystem"; // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end() @@ -65,4 +65,4 @@ void setup() { void loop() { ArduinoOTA.handle(); -} \ No newline at end of file +} diff --git a/libraries/ArduinoOTA/keywords.txt b/libraries/ArduinoOTA/keywords.txt index 1c14d9e8989..0f3921b73fc 100644 --- a/libraries/ArduinoOTA/keywords.txt +++ b/libraries/ArduinoOTA/keywords.txt @@ -23,4 +23,3 @@ onProgress KEYWORD2 ####################################### # Constants (LITERAL1) ####################################### - diff --git a/libraries/ArduinoOTA/src/ArduinoOTA.cpp b/libraries/ArduinoOTA/src/ArduinoOTA.cpp index a0ca6075a17..d8a00433b1f 100644 --- a/libraries/ArduinoOTA/src/ArduinoOTA.cpp +++ b/libraries/ArduinoOTA/src/ArduinoOTA.cpp @@ -12,386 +12,373 @@ // #define OTA_DEBUG Serial ArduinoOTAClass::ArduinoOTAClass() -: _port(0) -, _initialized(false) -, _rebootOnSuccess(true) -, _mdnsEnabled(true) -, _state(OTA_IDLE) -, _size(0) -, _cmd(0) -, _ota_port(0) -, _ota_timeout(1000) -, _start_callback(NULL) -, _end_callback(NULL) -, _error_callback(NULL) -, _progress_callback(NULL) -{ + : _port(0), _initialized(false), _rebootOnSuccess(true), _mdnsEnabled(true), _state(OTA_IDLE), _size(0), _cmd(0), _ota_port(0), _ota_timeout(1000), _start_callback(NULL), _end_callback(NULL), _error_callback(NULL), _progress_callback(NULL) { } -ArduinoOTAClass::~ArduinoOTAClass(){ - _udp_ota.stop(); +ArduinoOTAClass::~ArduinoOTAClass() { + _udp_ota.stop(); } ArduinoOTAClass& ArduinoOTAClass::onStart(THandlerFunction fn) { - _start_callback = fn; - return *this; + _start_callback = fn; + return *this; } ArduinoOTAClass& ArduinoOTAClass::onEnd(THandlerFunction fn) { - _end_callback = fn; - return *this; + _end_callback = fn; + return *this; } ArduinoOTAClass& ArduinoOTAClass::onProgress(THandlerFunction_Progress fn) { - _progress_callback = fn; - return *this; + _progress_callback = fn; + return *this; } ArduinoOTAClass& ArduinoOTAClass::onError(THandlerFunction_Error fn) { - _error_callback = fn; - return *this; + _error_callback = fn; + return *this; } ArduinoOTAClass& ArduinoOTAClass::setPort(uint16_t port) { - if (!_initialized && !_port && port) { - _port = port; - } - return *this; + if (!_initialized && !_port && port) { + _port = port; + } + return *this; } -ArduinoOTAClass& ArduinoOTAClass::setHostname(const char * hostname) { - if (!_initialized && !_hostname.length() && hostname) { - _hostname = hostname; - } - return *this; +ArduinoOTAClass& ArduinoOTAClass::setHostname(const char* hostname) { + if (!_initialized && !_hostname.length() && hostname) { + _hostname = hostname; + } + return *this; } String ArduinoOTAClass::getHostname() { - return _hostname; + return _hostname; } -ArduinoOTAClass& ArduinoOTAClass::setPassword(const char * password) { - if (!_initialized && !_password.length() && password) { - MD5Builder passmd5; - passmd5.begin(); - passmd5.add(password); - passmd5.calculate(); - _password = passmd5.toString(); - } - return *this; +ArduinoOTAClass& ArduinoOTAClass::setPassword(const char* password) { + if (!_initialized && !_password.length() && password) { + MD5Builder passmd5; + passmd5.begin(); + passmd5.add(password); + passmd5.calculate(); + _password = passmd5.toString(); + } + return *this; } -ArduinoOTAClass& ArduinoOTAClass::setPasswordHash(const char * password) { - if (!_initialized && !_password.length() && password) { - _password = password; - } - return *this; +ArduinoOTAClass& ArduinoOTAClass::setPasswordHash(const char* password) { + if (!_initialized && !_password.length() && password) { + _password = password; + } + return *this; } -ArduinoOTAClass& ArduinoOTAClass::setPartitionLabel(const char * partition_label) { - if (!_initialized && !_partition_label.length() && partition_label) { - _partition_label = partition_label; - } - return *this; +ArduinoOTAClass& ArduinoOTAClass::setPartitionLabel(const char* partition_label) { + if (!_initialized && !_partition_label.length() && partition_label) { + _partition_label = partition_label; + } + return *this; } String ArduinoOTAClass::getPartitionLabel() { - return _partition_label; + return _partition_label; } -ArduinoOTAClass& ArduinoOTAClass::setRebootOnSuccess(bool reboot){ - _rebootOnSuccess = reboot; - return *this; +ArduinoOTAClass& ArduinoOTAClass::setRebootOnSuccess(bool reboot) { + _rebootOnSuccess = reboot; + return *this; } -ArduinoOTAClass& ArduinoOTAClass::setMdnsEnabled(bool enabled){ - _mdnsEnabled = enabled; - return *this; +ArduinoOTAClass& ArduinoOTAClass::setMdnsEnabled(bool enabled) { + _mdnsEnabled = enabled; + return *this; } void ArduinoOTAClass::begin() { - if (_initialized){ - log_w("already initialized"); - return; - } + if (_initialized) { + log_w("already initialized"); + return; + } + + if (!_port) { + _port = 3232; + } + + if (!_udp_ota.begin(_port)) { + log_e("udp bind failed"); + return; + } + + + if (!_hostname.length()) { + char tmp[20]; + uint8_t mac[6]; + Network.macAddress(mac); + sprintf(tmp, "esp32-%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + _hostname = tmp; + } + if (_mdnsEnabled) { + MDNS.begin(_hostname.c_str()); + MDNS.enableArduino(_port, (_password.length() > 0)); + } + _initialized = true; + _state = OTA_IDLE; + log_i("OTA server at: %s.local:%u", _hostname.c_str(), _port); +} - if (!_port) { - _port = 3232; +int ArduinoOTAClass::parseInt() { + char data[INT_BUFFER_SIZE]; + uint8_t index = 0; + char value; + while (_udp_ota.peek() == ' ') _udp_ota.read(); + while (index < INT_BUFFER_SIZE - 1) { + value = _udp_ota.peek(); + if (value < '0' || value > '9') { + data[index++] = '\0'; + return atoi(data); } + data[index++] = _udp_ota.read(); + } + return 0; +} - if(!_udp_ota.begin(_port)){ - log_e("udp bind failed"); - return; +String ArduinoOTAClass::readStringUntil(char end) { + String res = ""; + int value; + while (true) { + value = _udp_ota.read(); + if (value <= 0 || value == end) { + return res; } + res += (char)value; + } + return res; +} +void ArduinoOTAClass::_onRx() { + if (_state == OTA_IDLE) { + int cmd = parseInt(); + if (cmd != U_FLASH && cmd != U_SPIFFS) + return; + _cmd = cmd; + _ota_port = parseInt(); + _size = parseInt(); + _udp_ota.read(); + _md5 = readStringUntil('\n'); + _md5.trim(); + if (_md5.length() != 32) { + log_e("bad md5 length"); + return; + } - if (!_hostname.length()) { - char tmp[20]; - uint8_t mac[6]; - Network.macAddress(mac); - sprintf(tmp, "esp32-%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - _hostname = tmp; + if (_password.length()) { + MD5Builder nonce_md5; + nonce_md5.begin(); + nonce_md5.add(String(micros())); + nonce_md5.calculate(); + _nonce = nonce_md5.toString(); + + _udp_ota.beginPacket(_udp_ota.remoteIP(), _udp_ota.remotePort()); + _udp_ota.printf("AUTH %s", _nonce.c_str()); + _udp_ota.endPacket(); + _state = OTA_WAITAUTH; + return; + } else { + _udp_ota.beginPacket(_udp_ota.remoteIP(), _udp_ota.remotePort()); + _udp_ota.print("OK"); + _udp_ota.endPacket(); + _ota_ip = _udp_ota.remoteIP(); + _state = OTA_RUNUPDATE; } - if(_mdnsEnabled){ - MDNS.begin(_hostname.c_str()); - MDNS.enableArduino(_port, (_password.length() > 0)); + } else if (_state == OTA_WAITAUTH) { + int cmd = parseInt(); + if (cmd != U_AUTH) { + log_e("%d was expected. got %d instead", U_AUTH, cmd); + _state = OTA_IDLE; + return; } - _initialized = true; - _state = OTA_IDLE; - log_i("OTA server at: %s.local:%u", _hostname.c_str(), _port); -} - -int ArduinoOTAClass::parseInt(){ - char data[INT_BUFFER_SIZE]; - uint8_t index = 0; - char value; - while(_udp_ota.peek() == ' ') _udp_ota.read(); - while(index < INT_BUFFER_SIZE - 1){ - value = _udp_ota.peek(); - if(value < '0' || value > '9'){ - data[index++] = '\0'; - return atoi(data); - } - data[index++] = _udp_ota.read(); + _udp_ota.read(); + String cnonce = readStringUntil(' '); + String response = readStringUntil('\n'); + if (cnonce.length() != 32 || response.length() != 32) { + log_e("auth param fail"); + _state = OTA_IDLE; + return; } - return 0; -} -String ArduinoOTAClass::readStringUntil(char end){ - String res = ""; - int value; - while(true){ - value = _udp_ota.read(); - if(value <= 0 || value == end){ - return res; - } - res += (char)value; + String challenge = _password + ":" + String(_nonce) + ":" + cnonce; + MD5Builder _challengemd5; + _challengemd5.begin(); + _challengemd5.add(challenge); + _challengemd5.calculate(); + String result = _challengemd5.toString(); + + if (result.equals(response)) { + _udp_ota.beginPacket(_udp_ota.remoteIP(), _udp_ota.remotePort()); + _udp_ota.print("OK"); + _udp_ota.endPacket(); + _ota_ip = _udp_ota.remoteIP(); + _state = OTA_RUNUPDATE; + } else { + _udp_ota.beginPacket(_udp_ota.remoteIP(), _udp_ota.remotePort()); + _udp_ota.print("Authentication Failed"); + log_w("Authentication Failed"); + _udp_ota.endPacket(); + if (_error_callback) _error_callback(OTA_AUTH_ERROR); + _state = OTA_IDLE; } - return res; + } } -void ArduinoOTAClass::_onRx(){ - if (_state == OTA_IDLE) { - int cmd = parseInt(); - if (cmd != U_FLASH && cmd != U_SPIFFS) - return; - _cmd = cmd; - _ota_port = parseInt(); - _size = parseInt(); - _udp_ota.read(); - _md5 = readStringUntil('\n'); - _md5.trim(); - if(_md5.length() != 32){ - log_e("bad md5 length"); - return; - } +void ArduinoOTAClass::_runUpdate() { + const char* partition_label = _partition_label.length() ? _partition_label.c_str() : NULL; + if (!Update.begin(_size, _cmd, -1, LOW, partition_label)) { - if (_password.length()){ - MD5Builder nonce_md5; - nonce_md5.begin(); - nonce_md5.add(String(micros())); - nonce_md5.calculate(); - _nonce = nonce_md5.toString(); - - _udp_ota.beginPacket(_udp_ota.remoteIP(), _udp_ota.remotePort()); - _udp_ota.printf("AUTH %s", _nonce.c_str()); - _udp_ota.endPacket(); - _state = OTA_WAITAUTH; - return; - } else { - _udp_ota.beginPacket(_udp_ota.remoteIP(), _udp_ota.remotePort()); - _udp_ota.print("OK"); - _udp_ota.endPacket(); - _ota_ip = _udp_ota.remoteIP(); - _state = OTA_RUNUPDATE; - } - } else if (_state == OTA_WAITAUTH) { - int cmd = parseInt(); - if (cmd != U_AUTH) { - log_e("%d was expected. got %d instead", U_AUTH, cmd); - _state = OTA_IDLE; - return; - } - _udp_ota.read(); - String cnonce = readStringUntil(' '); - String response = readStringUntil('\n'); - if (cnonce.length() != 32 || response.length() != 32) { - log_e("auth param fail"); - _state = OTA_IDLE; - return; - } + log_e("Begin ERROR: %s", Update.errorString()); - String challenge = _password + ":" + String(_nonce) + ":" + cnonce; - MD5Builder _challengemd5; - _challengemd5.begin(); - _challengemd5.add(challenge); - _challengemd5.calculate(); - String result = _challengemd5.toString(); - - if(result.equals(response)){ - _udp_ota.beginPacket(_udp_ota.remoteIP(), _udp_ota.remotePort()); - _udp_ota.print("OK"); - _udp_ota.endPacket(); - _ota_ip = _udp_ota.remoteIP(); - _state = OTA_RUNUPDATE; - } else { - _udp_ota.beginPacket(_udp_ota.remoteIP(), _udp_ota.remotePort()); - _udp_ota.print("Authentication Failed"); - log_w("Authentication Failed"); - _udp_ota.endPacket(); - if (_error_callback) _error_callback(OTA_AUTH_ERROR); - _state = OTA_IDLE; - } + if (_error_callback) { + _error_callback(OTA_BEGIN_ERROR); } -} - -void ArduinoOTAClass::_runUpdate() { - const char *partition_label = _partition_label.length() ? _partition_label.c_str() : NULL; - if (!Update.begin(_size, _cmd, -1, LOW, partition_label)) { + _state = OTA_IDLE; + return; + } + Update.setMD5(_md5.c_str()); + + if (_start_callback) { + _start_callback(); + } + if (_progress_callback) { + _progress_callback(0, _size); + } + + NetworkClient client; + if (!client.connect(_ota_ip, _ota_port)) { + if (_error_callback) { + _error_callback(OTA_CONNECT_ERROR); + } + _state = OTA_IDLE; + } - log_e("Begin ERROR: %s", Update.errorString()); + uint32_t written = 0, total = 0, tried = 0; - if (_error_callback) { - _error_callback(OTA_BEGIN_ERROR); + while (!Update.isFinished() && client.connected()) { + size_t waited = _ota_timeout; + size_t available = client.available(); + while (!available && waited) { + delay(1); + waited -= 1; + available = client.available(); + } + if (!waited) { + if (written && tried++ < 3) { + log_i("Try[%u]: %u", tried, written); + if (!client.printf("%lu", written)) { + log_e("failed to respond"); + _state = OTA_IDLE; + break; } - _state = OTA_IDLE; - return; + continue; + } + log_e("Receive Failed"); + if (_error_callback) { + _error_callback(OTA_RECEIVE_ERROR); + } + _state = OTA_IDLE; + Update.abort(); + return; } - Update.setMD5(_md5.c_str()); - - if (_start_callback) { - _start_callback(); + if (!available) { + log_e("No Data: %u", waited); + _state = OTA_IDLE; + break; } - if (_progress_callback) { - _progress_callback(0, _size); + tried = 0; + static uint8_t buf[1460]; + if (available > 1460) { + available = 1460; } - - NetworkClient client; - if (!client.connect(_ota_ip, _ota_port)) { - if (_error_callback) { - _error_callback(OTA_CONNECT_ERROR); - } - _state = OTA_IDLE; - } - - uint32_t written = 0, total = 0, tried = 0; - - while (!Update.isFinished() && client.connected()) { - size_t waited = _ota_timeout; - size_t available = client.available(); - while (!available && waited){ - delay(1); - waited -=1 ; - available = client.available(); - } - if (!waited){ - if(written && tried++ < 3){ - log_i("Try[%u]: %u", tried, written); - if(!client.printf("%lu", written)){ - log_e("failed to respond"); - _state = OTA_IDLE; - break; - } - continue; - } - log_e("Receive Failed"); - if (_error_callback) { - _error_callback(OTA_RECEIVE_ERROR); - } - _state = OTA_IDLE; - Update.abort(); - return; - } - if(!available){ - log_e("No Data: %u", waited); - _state = OTA_IDLE; - break; - } - tried = 0; - static uint8_t buf[1460]; - if(available > 1460){ - available = 1460; - } - size_t r = client.read(buf, available); - if(r != available){ - log_w("didn't read enough! %u != %u", r, available); - if((int32_t) r<0) { - delay(1); - continue; //let's not try to write 4 gigabytes when client.read returns -1 - } - } - - written = Update.write(buf, r); - if (written > 0) { - if(written != r){ - log_w("didn't write enough! %u != %u", written, r); - } - if(!client.printf("%lu", written)){ - log_w("failed to respond"); - } - total += written; - if(_progress_callback) { - _progress_callback(total, _size); - } - } else { - log_e("Write ERROR: %s", Update.errorString()); - } + size_t r = client.read(buf, available); + if (r != available) { + log_w("didn't read enough! %u != %u", r, available); + if ((int32_t)r < 0) { + delay(1); + continue; //let's not try to write 4 gigabytes when client.read returns -1 + } } - if (Update.end()) { - client.print("OK"); - client.stop(); - delay(10); - if (_end_callback) { - _end_callback(); - } - if(_rebootOnSuccess){ - //let serial/network finish tasks that might be given in _end_callback - delay(100); - ESP.restart(); - } + written = Update.write(buf, r); + if (written > 0) { + if (written != r) { + log_w("didn't write enough! %u != %u", written, r); + } + if (!client.printf("%lu", written)) { + log_w("failed to respond"); + } + total += written; + if (_progress_callback) { + _progress_callback(total, _size); + } } else { - if (_error_callback) { - _error_callback(OTA_END_ERROR); - } - Update.printError(client); - client.stop(); - delay(10); - log_e("Update ERROR: %s", Update.errorString()); - _state = OTA_IDLE; + log_e("Write ERROR: %s", Update.errorString()); + } + } + + if (Update.end()) { + client.print("OK"); + client.stop(); + delay(10); + if (_end_callback) { + _end_callback(); + } + if (_rebootOnSuccess) { + //let serial/network finish tasks that might be given in _end_callback + delay(100); + ESP.restart(); + } + } else { + if (_error_callback) { + _error_callback(OTA_END_ERROR); } + Update.printError(client); + client.stop(); + delay(10); + log_e("Update ERROR: %s", Update.errorString()); + _state = OTA_IDLE; + } } void ArduinoOTAClass::end() { - _initialized = false; - _udp_ota.stop(); - if(_mdnsEnabled){ - MDNS.end(); - } - _state = OTA_IDLE; - log_i("OTA server stopped."); + _initialized = false; + _udp_ota.stop(); + if (_mdnsEnabled) { + MDNS.end(); + } + _state = OTA_IDLE; + log_i("OTA server stopped."); } void ArduinoOTAClass::handle() { - if (!_initialized) { - return; - } - if (_state == OTA_RUNUPDATE) { - _runUpdate(); - _state = OTA_IDLE; - } - if(_udp_ota.parsePacket()){ - _onRx(); - } - _udp_ota.flush(); // always flush, even zero length packets must be flushed. + if (!_initialized) { + return; + } + if (_state == OTA_RUNUPDATE) { + _runUpdate(); + _state = OTA_IDLE; + } + if (_udp_ota.parsePacket()) { + _onRx(); + } + _udp_ota.flush(); // always flush, even zero length packets must be flushed. } int ArduinoOTAClass::getCommand() { - return _cmd; + return _cmd; } void ArduinoOTAClass::setTimeout(int timeoutInMillis) { - _ota_timeout = timeoutInMillis; + _ota_timeout = timeoutInMillis; } #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_ARDUINOOTA) diff --git a/libraries/ArduinoOTA/src/ArduinoOTA.h b/libraries/ArduinoOTA/src/ArduinoOTA.h index 726722897f9..9b751b75258 100644 --- a/libraries/ArduinoOTA/src/ArduinoOTA.h +++ b/libraries/ArduinoOTA/src/ArduinoOTA.h @@ -21,96 +21,95 @@ typedef enum { OTA_END_ERROR } ota_error_t; -class ArduinoOTAClass -{ - public: - typedef std::function THandlerFunction; - typedef std::function THandlerFunction_Error; - typedef std::function THandlerFunction_Progress; - - ArduinoOTAClass(); - ~ArduinoOTAClass(); - - //Sets the service port. Default 3232 - ArduinoOTAClass& setPort(uint16_t port); - - //Sets the device hostname. Default esp32-xxxxxx - ArduinoOTAClass& setHostname(const char *hostname); - String getHostname(); - - //Sets the password that will be required for OTA. Default NULL - ArduinoOTAClass& setPassword(const char *password); - - //Sets the password as above but in the form MD5(password). Default NULL - ArduinoOTAClass& setPasswordHash(const char *password); - - //Sets the partition label to write to when updating SPIFFS. Default NULL - ArduinoOTAClass &setPartitionLabel(const char *partition_label); - String getPartitionLabel(); - - //Sets if the device should be rebooted after successful update. Default true - ArduinoOTAClass& setRebootOnSuccess(bool reboot); - - //Sets if the device should advertise itself to Arduino IDE. Default true - ArduinoOTAClass& setMdnsEnabled(bool enabled); - - //This callback will be called when OTA connection has begun - ArduinoOTAClass& onStart(THandlerFunction fn); - - //This callback will be called when OTA has finished - ArduinoOTAClass& onEnd(THandlerFunction fn); - - //This callback will be called when OTA encountered Error - ArduinoOTAClass& onError(THandlerFunction_Error fn); - - //This callback will be called when OTA is receiving data - ArduinoOTAClass& onProgress(THandlerFunction_Progress fn); - - //Starts the ArduinoOTA service - void begin(); - - //Ends the ArduinoOTA service - void end(); - - //Call this in loop() to run the service - void handle(); - - //Gets update command type after OTA has started. Either U_FLASH or U_SPIFFS - int getCommand(); - - void setTimeout(int timeoutInMillis); - - private: - int _port; - String _password; - String _hostname; - String _partition_label; - String _nonce; - NetworkUDP _udp_ota; - bool _initialized; - bool _rebootOnSuccess; - bool _mdnsEnabled; - ota_state_t _state; - int _size; - int _cmd; - int _ota_port; - int _ota_timeout; - IPAddress _ota_ip; - String _md5; - - THandlerFunction _start_callback; - THandlerFunction _end_callback; - THandlerFunction_Error _error_callback; - THandlerFunction_Progress _progress_callback; - - void _runUpdate(void); - void _onRx(void); - int parseInt(void); - String readStringUntil(char end); +class ArduinoOTAClass { +public: + typedef std::function THandlerFunction; + typedef std::function THandlerFunction_Error; + typedef std::function THandlerFunction_Progress; + + ArduinoOTAClass(); + ~ArduinoOTAClass(); + + //Sets the service port. Default 3232 + ArduinoOTAClass& setPort(uint16_t port); + + //Sets the device hostname. Default esp32-xxxxxx + ArduinoOTAClass& setHostname(const char* hostname); + String getHostname(); + + //Sets the password that will be required for OTA. Default NULL + ArduinoOTAClass& setPassword(const char* password); + + //Sets the password as above but in the form MD5(password). Default NULL + ArduinoOTAClass& setPasswordHash(const char* password); + + //Sets the partition label to write to when updating SPIFFS. Default NULL + ArduinoOTAClass& setPartitionLabel(const char* partition_label); + String getPartitionLabel(); + + //Sets if the device should be rebooted after successful update. Default true + ArduinoOTAClass& setRebootOnSuccess(bool reboot); + + //Sets if the device should advertise itself to Arduino IDE. Default true + ArduinoOTAClass& setMdnsEnabled(bool enabled); + + //This callback will be called when OTA connection has begun + ArduinoOTAClass& onStart(THandlerFunction fn); + + //This callback will be called when OTA has finished + ArduinoOTAClass& onEnd(THandlerFunction fn); + + //This callback will be called when OTA encountered Error + ArduinoOTAClass& onError(THandlerFunction_Error fn); + + //This callback will be called when OTA is receiving data + ArduinoOTAClass& onProgress(THandlerFunction_Progress fn); + + //Starts the ArduinoOTA service + void begin(); + + //Ends the ArduinoOTA service + void end(); + + //Call this in loop() to run the service + void handle(); + + //Gets update command type after OTA has started. Either U_FLASH or U_SPIFFS + int getCommand(); + + void setTimeout(int timeoutInMillis); + +private: + int _port; + String _password; + String _hostname; + String _partition_label; + String _nonce; + NetworkUDP _udp_ota; + bool _initialized; + bool _rebootOnSuccess; + bool _mdnsEnabled; + ota_state_t _state; + int _size; + int _cmd; + int _ota_port; + int _ota_timeout; + IPAddress _ota_ip; + String _md5; + + THandlerFunction _start_callback; + THandlerFunction _end_callback; + THandlerFunction_Error _error_callback; + THandlerFunction_Progress _progress_callback; + + void _runUpdate(void); + void _onRx(void); + int parseInt(void); + String readStringUntil(char end); }; #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_ARDUINOOTA) extern ArduinoOTAClass ArduinoOTA; #endif -#endif /* __ARDUINO_OTA_H */ \ No newline at end of file +#endif /* __ARDUINO_OTA_H */ diff --git a/libraries/AsyncUDP/examples/AsyncUDPClient/AsyncUDPClient.ino b/libraries/AsyncUDP/examples/AsyncUDPClient/AsyncUDPClient.ino index 3348f8a76a4..23b24a303c9 100644 --- a/libraries/AsyncUDP/examples/AsyncUDPClient/AsyncUDPClient.ino +++ b/libraries/AsyncUDP/examples/AsyncUDPClient/AsyncUDPClient.ino @@ -1,51 +1,50 @@ #include "WiFi.h" #include "AsyncUDP.h" -const char * ssid = "***********"; -const char * password = "***********"; +const char* ssid = "***********"; +const char* password = "***********"; AsyncUDP udp; -void setup() -{ - Serial.begin(115200); - WiFi.mode(WIFI_STA); - WiFi.begin(ssid, password); - if (WiFi.waitForConnectResult() != WL_CONNECTED) { - Serial.println("WiFi Failed"); - while(1) { - delay(1000); - } - } - if(udp.connect(IPAddress(192,168,1,100), 1234)) { - Serial.println("UDP connected"); - udp.onPacket([](AsyncUDPPacket packet) { - Serial.print("UDP Packet Type: "); - Serial.print(packet.isBroadcast()?"Broadcast":packet.isMulticast()?"Multicast":"Unicast"); - Serial.print(", From: "); - Serial.print(packet.remoteIP()); - Serial.print(":"); - Serial.print(packet.remotePort()); - Serial.print(", To: "); - Serial.print(packet.localIP()); - Serial.print(":"); - Serial.print(packet.localPort()); - Serial.print(", Length: "); - Serial.print(packet.length()); - Serial.print(", Data: "); - Serial.write(packet.data(), packet.length()); - Serial.println(); - //reply to the client - packet.printf("Got %u bytes of data", packet.length()); - }); - //Send unicast - udp.print("Hello Server!"); +void setup() { + Serial.begin(115200); + WiFi.mode(WIFI_STA); + WiFi.begin(ssid, password); + if (WiFi.waitForConnectResult() != WL_CONNECTED) { + Serial.println("WiFi Failed"); + while (1) { + delay(1000); } + } + if (udp.connect(IPAddress(192, 168, 1, 100), 1234)) { + Serial.println("UDP connected"); + udp.onPacket([](AsyncUDPPacket packet) { + Serial.print("UDP Packet Type: "); + Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" + : "Unicast"); + Serial.print(", From: "); + Serial.print(packet.remoteIP()); + Serial.print(":"); + Serial.print(packet.remotePort()); + Serial.print(", To: "); + Serial.print(packet.localIP()); + Serial.print(":"); + Serial.print(packet.localPort()); + Serial.print(", Length: "); + Serial.print(packet.length()); + Serial.print(", Data: "); + Serial.write(packet.data(), packet.length()); + Serial.println(); + //reply to the client + packet.printf("Got %u bytes of data", packet.length()); + }); + //Send unicast + udp.print("Hello Server!"); + } } -void loop() -{ - delay(1000); - //Send broadcast on port 1234 - udp.broadcastTo("Anyone here?", 1234); +void loop() { + delay(1000); + //Send broadcast on port 1234 + udp.broadcastTo("Anyone here?", 1234); } diff --git a/libraries/AsyncUDP/examples/AsyncUDPMulticastServer/AsyncUDPMulticastServer.ino b/libraries/AsyncUDP/examples/AsyncUDPMulticastServer/AsyncUDPMulticastServer.ino index 2bbbac51c4d..375cda23d32 100644 --- a/libraries/AsyncUDP/examples/AsyncUDPMulticastServer/AsyncUDPMulticastServer.ino +++ b/libraries/AsyncUDP/examples/AsyncUDPMulticastServer/AsyncUDPMulticastServer.ino @@ -1,52 +1,51 @@ #include "WiFi.h" #include "AsyncUDP.h" -const char * ssid = "***********"; -const char * password = "***********"; +const char* ssid = "***********"; +const char* password = "***********"; AsyncUDP udp; -void setup() -{ - Serial.begin(115200); - WiFi.mode(WIFI_STA); - WiFi.begin(ssid, password); - if (WiFi.waitForConnectResult() != WL_CONNECTED) { - Serial.println("WiFi Failed"); - while(1) { - delay(1000); - } - } - if(udp.listenMulticast(IPAddress(239,1,2,3), 1234)) { - Serial.print("UDP Listening on IP: "); - Serial.println(WiFi.localIP()); - udp.onPacket([](AsyncUDPPacket packet) { - Serial.print("UDP Packet Type: "); - Serial.print(packet.isBroadcast()?"Broadcast":packet.isMulticast()?"Multicast":"Unicast"); - Serial.print(", From: "); - Serial.print(packet.remoteIP()); - Serial.print(":"); - Serial.print(packet.remotePort()); - Serial.print(", To: "); - Serial.print(packet.localIP()); - Serial.print(":"); - Serial.print(packet.localPort()); - Serial.print(", Length: "); - Serial.print(packet.length()); - Serial.print(", Data: "); - Serial.write(packet.data(), packet.length()); - Serial.println(); - //reply to the client - packet.printf("Got %u bytes of data", packet.length()); - }); - //Send multicast - udp.print("Hello!"); +void setup() { + Serial.begin(115200); + WiFi.mode(WIFI_STA); + WiFi.begin(ssid, password); + if (WiFi.waitForConnectResult() != WL_CONNECTED) { + Serial.println("WiFi Failed"); + while (1) { + delay(1000); } + } + if (udp.listenMulticast(IPAddress(239, 1, 2, 3), 1234)) { + Serial.print("UDP Listening on IP: "); + Serial.println(WiFi.localIP()); + udp.onPacket([](AsyncUDPPacket packet) { + Serial.print("UDP Packet Type: "); + Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" + : "Unicast"); + Serial.print(", From: "); + Serial.print(packet.remoteIP()); + Serial.print(":"); + Serial.print(packet.remotePort()); + Serial.print(", To: "); + Serial.print(packet.localIP()); + Serial.print(":"); + Serial.print(packet.localPort()); + Serial.print(", Length: "); + Serial.print(packet.length()); + Serial.print(", Data: "); + Serial.write(packet.data(), packet.length()); + Serial.println(); + //reply to the client + packet.printf("Got %u bytes of data", packet.length()); + }); + //Send multicast + udp.print("Hello!"); + } } -void loop() -{ - delay(1000); - //Send multicast - udp.print("Anyone here?"); +void loop() { + delay(1000); + //Send multicast + udp.print("Anyone here?"); } diff --git a/libraries/AsyncUDP/examples/AsyncUDPServer/AsyncUDPServer.ino b/libraries/AsyncUDP/examples/AsyncUDPServer/AsyncUDPServer.ino index 1f8529bd51d..c4f4a6c24b7 100644 --- a/libraries/AsyncUDP/examples/AsyncUDPServer/AsyncUDPServer.ino +++ b/libraries/AsyncUDP/examples/AsyncUDPServer/AsyncUDPServer.ino @@ -1,50 +1,49 @@ #include "WiFi.h" #include "AsyncUDP.h" -const char * ssid = "***********"; -const char * password = "***********"; +const char* ssid = "***********"; +const char* password = "***********"; AsyncUDP udp; -void setup() -{ - Serial.begin(115200); - WiFi.mode(WIFI_STA); - WiFi.begin(ssid, password); - if (WiFi.waitForConnectResult() != WL_CONNECTED) { - Serial.println("WiFi Failed"); - while(1) { - delay(1000); - } - } - if(udp.listen(1234)) { - Serial.print("UDP Listening on IP: "); - Serial.println(WiFi.localIP()); - udp.onPacket([](AsyncUDPPacket packet) { - Serial.print("UDP Packet Type: "); - Serial.print(packet.isBroadcast()?"Broadcast":packet.isMulticast()?"Multicast":"Unicast"); - Serial.print(", From: "); - Serial.print(packet.remoteIP()); - Serial.print(":"); - Serial.print(packet.remotePort()); - Serial.print(", To: "); - Serial.print(packet.localIP()); - Serial.print(":"); - Serial.print(packet.localPort()); - Serial.print(", Length: "); - Serial.print(packet.length()); - Serial.print(", Data: "); - Serial.write(packet.data(), packet.length()); - Serial.println(); - //reply to the client - packet.printf("Got %u bytes of data", packet.length()); - }); +void setup() { + Serial.begin(115200); + WiFi.mode(WIFI_STA); + WiFi.begin(ssid, password); + if (WiFi.waitForConnectResult() != WL_CONNECTED) { + Serial.println("WiFi Failed"); + while (1) { + delay(1000); } + } + if (udp.listen(1234)) { + Serial.print("UDP Listening on IP: "); + Serial.println(WiFi.localIP()); + udp.onPacket([](AsyncUDPPacket packet) { + Serial.print("UDP Packet Type: "); + Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" + : "Unicast"); + Serial.print(", From: "); + Serial.print(packet.remoteIP()); + Serial.print(":"); + Serial.print(packet.remotePort()); + Serial.print(", To: "); + Serial.print(packet.localIP()); + Serial.print(":"); + Serial.print(packet.localPort()); + Serial.print(", Length: "); + Serial.print(packet.length()); + Serial.print(", Data: "); + Serial.write(packet.data(), packet.length()); + Serial.println(); + //reply to the client + packet.printf("Got %u bytes of data", packet.length()); + }); + } } -void loop() -{ - delay(1000); - //Send broadcast - udp.broadcast("Anyone here?"); +void loop() { + delay(1000); + //Send broadcast + udp.broadcast("Anyone here?"); } diff --git a/libraries/AsyncUDP/src/AsyncUDP.cpp b/libraries/AsyncUDP/src/AsyncUDP.cpp index 1c650f1a721..3ebef6abdbb 100644 --- a/libraries/AsyncUDP/src/AsyncUDP.cpp +++ b/libraries/AsyncUDP/src/AsyncUDP.cpp @@ -15,203 +15,201 @@ extern "C" { #include "lwip/priv/tcpip_priv.h" -static const char * netif_ifkeys[TCPIP_ADAPTER_IF_MAX] = { - "WIFI_STA_DEF", "WIFI_AP_DEF", "ETH_DEF", "PPP_DEF" +static const char *netif_ifkeys[TCPIP_ADAPTER_IF_MAX] = { + "WIFI_STA_DEF", "WIFI_AP_DEF", "ETH_DEF", "PPP_DEF" }; -static esp_err_t tcpip_adapter_get_netif(tcpip_adapter_if_t tcpip_if, void ** netif){ - *netif = NULL; - if(tcpip_if < TCPIP_ADAPTER_IF_MAX){ - esp_netif_t *esp_netif = esp_netif_get_handle_from_ifkey(netif_ifkeys[tcpip_if]); - if(esp_netif == NULL){ - return ESP_FAIL; - } - int netif_index = esp_netif_get_netif_impl_index(esp_netif); - if(netif_index < 0){ - return ESP_FAIL; - } - *netif = (void*)netif_get_by_index(netif_index); - } else { - *netif = netif_default; +static esp_err_t tcpip_adapter_get_netif(tcpip_adapter_if_t tcpip_if, void **netif) { + *netif = NULL; + if (tcpip_if < TCPIP_ADAPTER_IF_MAX) { + esp_netif_t *esp_netif = esp_netif_get_handle_from_ifkey(netif_ifkeys[tcpip_if]); + if (esp_netif == NULL) { + return ESP_FAIL; } - return (*netif != NULL)?ESP_OK:ESP_FAIL; + int netif_index = esp_netif_get_netif_impl_index(esp_netif); + if (netif_index < 0) { + return ESP_FAIL; + } + *netif = (void *)netif_get_by_index(netif_index); + } else { + *netif = netif_default; + } + return (*netif != NULL) ? ESP_OK : ESP_FAIL; } typedef struct { - struct tcpip_api_call_data call; - udp_pcb * pcb; - const ip_addr_t *addr; - uint16_t port; - struct pbuf *pb; - struct netif *netif; - err_t err; + struct tcpip_api_call_data call; + udp_pcb *pcb; + const ip_addr_t *addr; + uint16_t port; + struct pbuf *pb; + struct netif *netif; + err_t err; } udp_api_call_t; -static err_t _udp_connect_api(struct tcpip_api_call_data *api_call_msg){ - udp_api_call_t * msg = (udp_api_call_t *)api_call_msg; - msg->err = udp_connect(msg->pcb, msg->addr, msg->port); - return msg->err; +static err_t _udp_connect_api(struct tcpip_api_call_data *api_call_msg) { + udp_api_call_t *msg = (udp_api_call_t *)api_call_msg; + msg->err = udp_connect(msg->pcb, msg->addr, msg->port); + return msg->err; } -static err_t _udp_connect(struct udp_pcb *pcb, const ip_addr_t *addr, u16_t port){ - udp_api_call_t msg; - msg.pcb = pcb; - msg.addr = addr; - msg.port = port; - tcpip_api_call(_udp_connect_api, (struct tcpip_api_call_data*)&msg); - return msg.err; +static err_t _udp_connect(struct udp_pcb *pcb, const ip_addr_t *addr, u16_t port) { + udp_api_call_t msg; + msg.pcb = pcb; + msg.addr = addr; + msg.port = port; + tcpip_api_call(_udp_connect_api, (struct tcpip_api_call_data *)&msg); + return msg.err; } -static err_t _udp_disconnect_api(struct tcpip_api_call_data *api_call_msg){ - udp_api_call_t * msg = (udp_api_call_t *)api_call_msg; - msg->err = 0; - udp_disconnect(msg->pcb); - return msg->err; +static err_t _udp_disconnect_api(struct tcpip_api_call_data *api_call_msg) { + udp_api_call_t *msg = (udp_api_call_t *)api_call_msg; + msg->err = 0; + udp_disconnect(msg->pcb); + return msg->err; } -static void _udp_disconnect(struct udp_pcb *pcb){ - udp_api_call_t msg; - msg.pcb = pcb; - tcpip_api_call(_udp_disconnect_api, (struct tcpip_api_call_data*)&msg); +static void _udp_disconnect(struct udp_pcb *pcb) { + udp_api_call_t msg; + msg.pcb = pcb; + tcpip_api_call(_udp_disconnect_api, (struct tcpip_api_call_data *)&msg); } -static err_t _udp_remove_api(struct tcpip_api_call_data *api_call_msg){ - udp_api_call_t * msg = (udp_api_call_t *)api_call_msg; - msg->err = 0; - udp_remove(msg->pcb); - return msg->err; +static err_t _udp_remove_api(struct tcpip_api_call_data *api_call_msg) { + udp_api_call_t *msg = (udp_api_call_t *)api_call_msg; + msg->err = 0; + udp_remove(msg->pcb); + return msg->err; } -static void _udp_remove(struct udp_pcb *pcb){ - udp_api_call_t msg; - msg.pcb = pcb; - tcpip_api_call(_udp_remove_api, (struct tcpip_api_call_data*)&msg); +static void _udp_remove(struct udp_pcb *pcb) { + udp_api_call_t msg; + msg.pcb = pcb; + tcpip_api_call(_udp_remove_api, (struct tcpip_api_call_data *)&msg); } -static err_t _udp_bind_api(struct tcpip_api_call_data *api_call_msg){ - udp_api_call_t * msg = (udp_api_call_t *)api_call_msg; - msg->err = udp_bind(msg->pcb, msg->addr, msg->port); - return msg->err; +static err_t _udp_bind_api(struct tcpip_api_call_data *api_call_msg) { + udp_api_call_t *msg = (udp_api_call_t *)api_call_msg; + msg->err = udp_bind(msg->pcb, msg->addr, msg->port); + return msg->err; } -static err_t _udp_bind(struct udp_pcb *pcb, const ip_addr_t *addr, u16_t port){ - udp_api_call_t msg; - msg.pcb = pcb; - msg.addr = addr; - msg.port = port; - tcpip_api_call(_udp_bind_api, (struct tcpip_api_call_data*)&msg); - return msg.err; +static err_t _udp_bind(struct udp_pcb *pcb, const ip_addr_t *addr, u16_t port) { + udp_api_call_t msg; + msg.pcb = pcb; + msg.addr = addr; + msg.port = port; + tcpip_api_call(_udp_bind_api, (struct tcpip_api_call_data *)&msg); + return msg.err; } -static err_t _udp_sendto_api(struct tcpip_api_call_data *api_call_msg){ - udp_api_call_t * msg = (udp_api_call_t *)api_call_msg; - msg->err = udp_sendto(msg->pcb, msg->pb, msg->addr, msg->port); - return msg->err; +static err_t _udp_sendto_api(struct tcpip_api_call_data *api_call_msg) { + udp_api_call_t *msg = (udp_api_call_t *)api_call_msg; + msg->err = udp_sendto(msg->pcb, msg->pb, msg->addr, msg->port); + return msg->err; } -static err_t _udp_sendto(struct udp_pcb *pcb, struct pbuf *pb, const ip_addr_t *addr, u16_t port){ - udp_api_call_t msg; - msg.pcb = pcb; - msg.addr = addr; - msg.port = port; - msg.pb = pb; - tcpip_api_call(_udp_sendto_api, (struct tcpip_api_call_data*)&msg); - return msg.err; +static err_t _udp_sendto(struct udp_pcb *pcb, struct pbuf *pb, const ip_addr_t *addr, u16_t port) { + udp_api_call_t msg; + msg.pcb = pcb; + msg.addr = addr; + msg.port = port; + msg.pb = pb; + tcpip_api_call(_udp_sendto_api, (struct tcpip_api_call_data *)&msg); + return msg.err; } -static err_t _udp_sendto_if_api(struct tcpip_api_call_data *api_call_msg){ - udp_api_call_t * msg = (udp_api_call_t *)api_call_msg; - msg->err = udp_sendto_if(msg->pcb, msg->pb, msg->addr, msg->port, msg->netif); - return msg->err; +static err_t _udp_sendto_if_api(struct tcpip_api_call_data *api_call_msg) { + udp_api_call_t *msg = (udp_api_call_t *)api_call_msg; + msg->err = udp_sendto_if(msg->pcb, msg->pb, msg->addr, msg->port, msg->netif); + return msg->err; } -static err_t _udp_sendto_if(struct udp_pcb *pcb, struct pbuf *pb, const ip_addr_t *addr, u16_t port, struct netif *netif){ - udp_api_call_t msg; - msg.pcb = pcb; - msg.addr = addr; - msg.port = port; - msg.pb = pb; - msg.netif = netif; - tcpip_api_call(_udp_sendto_if_api, (struct tcpip_api_call_data*)&msg); - return msg.err; +static err_t _udp_sendto_if(struct udp_pcb *pcb, struct pbuf *pb, const ip_addr_t *addr, u16_t port, struct netif *netif) { + udp_api_call_t msg; + msg.pcb = pcb; + msg.addr = addr; + msg.port = port; + msg.pb = pb; + msg.netif = netif; + tcpip_api_call(_udp_sendto_if_api, (struct tcpip_api_call_data *)&msg); + return msg.err; } typedef struct { - void *arg; - udp_pcb *pcb; - pbuf *pb; - const ip_addr_t *addr; - uint16_t port; - struct netif * netif; + void *arg; + udp_pcb *pcb; + pbuf *pb; + const ip_addr_t *addr; + uint16_t port; + struct netif *netif; } lwip_event_packet_t; static QueueHandle_t _udp_queue; static volatile TaskHandle_t _udp_task_handle = NULL; -static void _udp_task(void *pvParameters){ - lwip_event_packet_t * e = NULL; - for (;;) { - if(xQueueReceive(_udp_queue, &e, portMAX_DELAY) == pdTRUE){ - if(!e->pb){ - free((void*)(e)); - continue; - } - AsyncUDP::_s_recv(e->arg, e->pcb, e->pb, e->addr, e->port, e->netif); - free((void*)(e)); - } - } - _udp_task_handle = NULL; - vTaskDelete(NULL); -} - -static bool _udp_task_start(){ - if(!_udp_queue){ - _udp_queue = xQueueCreate(32, sizeof(lwip_event_packet_t *)); - if(!_udp_queue){ - return false; - } - } - if(!_udp_task_handle){ - xTaskCreateUniversal(_udp_task, "async_udp", 4096, NULL, CONFIG_ARDUINO_UDP_TASK_PRIORITY, (TaskHandle_t*)&_udp_task_handle, CONFIG_ARDUINO_UDP_RUNNING_CORE); - if(!_udp_task_handle){ - return false; - } - } - return true; -} - -static bool _udp_task_post(void *arg, udp_pcb *pcb, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif *netif) -{ - if(!_udp_task_handle || !_udp_queue){ - return false; - } - lwip_event_packet_t * e = (lwip_event_packet_t *)malloc(sizeof(lwip_event_packet_t)); - if(!e){ - return false; - } - e->arg = arg; - e->pcb = pcb; - e->pb = pb; - e->addr = addr; - e->port = port; - e->netif = netif; - if (xQueueSend(_udp_queue, &e, portMAX_DELAY) != pdPASS) { - free((void*)(e)); - return false; - } - return true; -} - -static void _udp_recv(void *arg, udp_pcb *pcb, pbuf *pb, const ip_addr_t *addr, uint16_t port) -{ - while(pb != NULL) { - pbuf * this_pb = pb; - pb = pb->next; - this_pb->next = NULL; - if(!_udp_task_post(arg, pcb, this_pb, addr, port, ip_current_input_netif())){ - pbuf_free(this_pb); - } - } +static void _udp_task(void *pvParameters) { + lwip_event_packet_t *e = NULL; + for (;;) { + if (xQueueReceive(_udp_queue, &e, portMAX_DELAY) == pdTRUE) { + if (!e->pb) { + free((void *)(e)); + continue; + } + AsyncUDP::_s_recv(e->arg, e->pcb, e->pb, e->addr, e->port, e->netif); + free((void *)(e)); + } + } + _udp_task_handle = NULL; + vTaskDelete(NULL); +} + +static bool _udp_task_start() { + if (!_udp_queue) { + _udp_queue = xQueueCreate(32, sizeof(lwip_event_packet_t *)); + if (!_udp_queue) { + return false; + } + } + if (!_udp_task_handle) { + xTaskCreateUniversal(_udp_task, "async_udp", 4096, NULL, CONFIG_ARDUINO_UDP_TASK_PRIORITY, (TaskHandle_t *)&_udp_task_handle, CONFIG_ARDUINO_UDP_RUNNING_CORE); + if (!_udp_task_handle) { + return false; + } + } + return true; +} + +static bool _udp_task_post(void *arg, udp_pcb *pcb, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif *netif) { + if (!_udp_task_handle || !_udp_queue) { + return false; + } + lwip_event_packet_t *e = (lwip_event_packet_t *)malloc(sizeof(lwip_event_packet_t)); + if (!e) { + return false; + } + e->arg = arg; + e->pcb = pcb; + e->pb = pb; + e->addr = addr; + e->port = port; + e->netif = netif; + if (xQueueSend(_udp_queue, &e, portMAX_DELAY) != pdPASS) { + free((void *)(e)); + return false; + } + return true; +} + +static void _udp_recv(void *arg, udp_pcb *pcb, pbuf *pb, const ip_addr_t *addr, uint16_t port) { + while (pb != NULL) { + pbuf *this_pb = pb; + pb = pb->next; + this_pb->next = NULL; + if (!_udp_task_post(arg, pcb, this_pb, addr, port, ip_current_input_netif())) { + pbuf_free(this_pb); + } + } } /* static bool _udp_task_stop(){ @@ -240,640 +238,582 @@ static bool _udp_task_stop(){ #define UDP_MUTEX_UNLOCK() //xSemaphoreGive(_lock) -AsyncUDPMessage::AsyncUDPMessage(size_t size) -{ - _index = 0; - if(size > CONFIG_TCP_MSS) { - size = CONFIG_TCP_MSS; - } - _size = size; - _buffer = (uint8_t *)malloc(size); +AsyncUDPMessage::AsyncUDPMessage(size_t size) { + _index = 0; + if (size > CONFIG_TCP_MSS) { + size = CONFIG_TCP_MSS; + } + _size = size; + _buffer = (uint8_t *)malloc(size); } -AsyncUDPMessage::~AsyncUDPMessage() -{ - if(_buffer) { - free(_buffer); - } +AsyncUDPMessage::~AsyncUDPMessage() { + if (_buffer) { + free(_buffer); + } } -size_t AsyncUDPMessage::write(const uint8_t *data, size_t len) -{ - if(_buffer == NULL) { - return 0; - } - size_t s = space(); - if(len > s) { - len = s; - } - memcpy(_buffer + _index, data, len); - _index += len; - return len; +size_t AsyncUDPMessage::write(const uint8_t *data, size_t len) { + if (_buffer == NULL) { + return 0; + } + size_t s = space(); + if (len > s) { + len = s; + } + memcpy(_buffer + _index, data, len); + _index += len; + return len; } -size_t AsyncUDPMessage::write(uint8_t data) -{ - return write(&data, 1); +size_t AsyncUDPMessage::write(uint8_t data) { + return write(&data, 1); } -size_t AsyncUDPMessage::space() -{ - if(_buffer == NULL) { - return 0; - } - return _size - _index; +size_t AsyncUDPMessage::space() { + if (_buffer == NULL) { + return 0; + } + return _size - _index; } -uint8_t * AsyncUDPMessage::data() -{ - return _buffer; +uint8_t *AsyncUDPMessage::data() { + return _buffer; } -size_t AsyncUDPMessage::length() -{ - return _index; +size_t AsyncUDPMessage::length() { + return _index; } -void AsyncUDPMessage::flush() -{ - _index = 0; +void AsyncUDPMessage::flush() { + _index = 0; } -AsyncUDPPacket::AsyncUDPPacket(AsyncUDPPacket &packet){ - _udp = packet._udp; - _pb = packet._pb; - _if = packet._if; - _data = packet._data; - _len = packet._len; - _index = 0; +AsyncUDPPacket::AsyncUDPPacket(AsyncUDPPacket &packet) { + _udp = packet._udp; + _pb = packet._pb; + _if = packet._if; + _data = packet._data; + _len = packet._len; + _index = 0; - memcpy(&_remoteIp, &packet._remoteIp, sizeof(ip_addr_t)); - memcpy(&_localIp, &packet._localIp, sizeof(ip_addr_t)); - _localPort = packet._localPort; - _remotePort = packet._remotePort; - memcpy(_remoteMac, packet._remoteMac, 6); + memcpy(&_remoteIp, &packet._remoteIp, sizeof(ip_addr_t)); + memcpy(&_localIp, &packet._localIp, sizeof(ip_addr_t)); + _localPort = packet._localPort; + _remotePort = packet._remotePort; + memcpy(_remoteMac, packet._remoteMac, 6); - pbuf_ref(_pb); + pbuf_ref(_pb); } -AsyncUDPPacket::AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *raddr, uint16_t rport, struct netif * ntif) -{ - _udp = udp; - _pb = pb; - _if = TCPIP_ADAPTER_IF_MAX; - _data = (uint8_t*)(pb->payload); - _len = pb->len; - _index = 0; +AsyncUDPPacket::AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *raddr, uint16_t rport, struct netif *ntif) { + _udp = udp; + _pb = pb; + _if = TCPIP_ADAPTER_IF_MAX; + _data = (uint8_t *)(pb->payload); + _len = pb->len; + _index = 0; - pbuf_ref(_pb); + pbuf_ref(_pb); - //memcpy(&_remoteIp, raddr, sizeof(ip_addr_t)); - _remoteIp.type = raddr->type; - _localIp.type = _remoteIp.type; + //memcpy(&_remoteIp, raddr, sizeof(ip_addr_t)); + _remoteIp.type = raddr->type; + _localIp.type = _remoteIp.type; - eth_hdr* eth = NULL; - udp_hdr* udphdr = (udp_hdr *)(_data - UDP_HLEN); - _localPort = ntohs(udphdr->dest); - _remotePort = ntohs(udphdr->src); + eth_hdr *eth = NULL; + udp_hdr *udphdr = (udp_hdr *)(_data - UDP_HLEN); + _localPort = ntohs(udphdr->dest); + _remotePort = ntohs(udphdr->src); - if (_remoteIp.type == IPADDR_TYPE_V4) { - eth = (eth_hdr *)(_data - UDP_HLEN - IP_HLEN - SIZEOF_ETH_HDR); - struct ip_hdr * iphdr = (struct ip_hdr *)(_data - UDP_HLEN - IP_HLEN); - _localIp.u_addr.ip4.addr = iphdr->dest.addr; - _remoteIp.u_addr.ip4.addr = iphdr->src.addr; - } else { - eth = (eth_hdr *)(_data - UDP_HLEN - IP6_HLEN - SIZEOF_ETH_HDR); - struct ip6_hdr * ip6hdr = (struct ip6_hdr *)(_data - UDP_HLEN - IP6_HLEN); - memcpy(&_localIp.u_addr.ip6.addr, (uint8_t *)ip6hdr->dest.addr, 16); - memcpy(&_remoteIp.u_addr.ip6.addr, (uint8_t *)ip6hdr->src.addr, 16); - } - memcpy(_remoteMac, eth->src.addr, 6); - - struct netif * netif = NULL; - void * nif = NULL; - int i; - for (i=0; idest.addr; + _remoteIp.u_addr.ip4.addr = iphdr->src.addr; + } else { + eth = (eth_hdr *)(_data - UDP_HLEN - IP6_HLEN - SIZEOF_ETH_HDR); + struct ip6_hdr *ip6hdr = (struct ip6_hdr *)(_data - UDP_HLEN - IP6_HLEN); + memcpy(&_localIp.u_addr.ip6.addr, (uint8_t *)ip6hdr->dest.addr, 16); + memcpy(&_remoteIp.u_addr.ip6.addr, (uint8_t *)ip6hdr->src.addr, 16); + } + memcpy(_remoteMac, eth->src.addr, 6); + + struct netif *netif = NULL; + void *nif = NULL; + int i; + for (i = 0; i < TCPIP_ADAPTER_IF_MAX; i++) { + tcpip_adapter_get_netif((tcpip_adapter_if_t)i, &nif); + netif = (struct netif *)nif; + if (netif && netif == ntif) { + _if = (tcpip_adapter_if_t)i; + break; } + } } -AsyncUDPPacket::~AsyncUDPPacket() -{ - pbuf_free(_pb); +AsyncUDPPacket::~AsyncUDPPacket() { + pbuf_free(_pb); } -uint8_t * AsyncUDPPacket::data() -{ - return _data; +uint8_t *AsyncUDPPacket::data() { + return _data; } -size_t AsyncUDPPacket::length() -{ - return _len; +size_t AsyncUDPPacket::length() { + return _len; } -int AsyncUDPPacket::available(){ - return _len - _index; +int AsyncUDPPacket::available() { + return _len - _index; } -size_t AsyncUDPPacket::read(uint8_t *data, size_t len){ - size_t i; - size_t a = _len - _index; - if(len > a){ - len = a; - } - for(i=0;i a) { + len = a; + } + for (i = 0; i < len; i++) { + data[i] = read(); + } + return len; } -int AsyncUDPPacket::read(){ - if(_index < _len){ - return _data[_index++]; - } - return -1; +int AsyncUDPPacket::read() { + if (_index < _len) { + return _data[_index++]; + } + return -1; } -int AsyncUDPPacket::peek(){ - if(_index < _len){ - return _data[_index]; - } - return -1; +int AsyncUDPPacket::peek() { + if (_index < _len) { + return _data[_index]; + } + return -1; } -void AsyncUDPPacket::flush(){ - _index = _len; +void AsyncUDPPacket::flush() { + _index = _len; } -tcpip_adapter_if_t AsyncUDPPacket::interface() -{ - return _if; +tcpip_adapter_if_t AsyncUDPPacket::interface() { + return _if; } -IPAddress AsyncUDPPacket::localIP() -{ - if(_localIp.type != IPADDR_TYPE_V4){ - return IPAddress(); - } - return IPAddress(_localIp.u_addr.ip4.addr); +IPAddress AsyncUDPPacket::localIP() { + if (_localIp.type != IPADDR_TYPE_V4) { + return IPAddress(); + } + return IPAddress(_localIp.u_addr.ip4.addr); } -IPAddress AsyncUDPPacket::localIPv6() -{ - if(_localIp.type != IPADDR_TYPE_V6){ - return IPAddress(IPv6); - } - return IPAddress(IPv6, (const uint8_t *)_localIp.u_addr.ip6.addr, _localIp.u_addr.ip6.zone); +IPAddress AsyncUDPPacket::localIPv6() { + if (_localIp.type != IPADDR_TYPE_V6) { + return IPAddress(IPv6); + } + return IPAddress(IPv6, (const uint8_t *)_localIp.u_addr.ip6.addr, _localIp.u_addr.ip6.zone); } -uint16_t AsyncUDPPacket::localPort() -{ - return _localPort; +uint16_t AsyncUDPPacket::localPort() { + return _localPort; } -IPAddress AsyncUDPPacket::remoteIP() -{ - if(_remoteIp.type != IPADDR_TYPE_V4){ - return IPAddress(); - } - return IPAddress(_remoteIp.u_addr.ip4.addr); +IPAddress AsyncUDPPacket::remoteIP() { + if (_remoteIp.type != IPADDR_TYPE_V4) { + return IPAddress(); + } + return IPAddress(_remoteIp.u_addr.ip4.addr); } -IPAddress AsyncUDPPacket::remoteIPv6() -{ - if(_remoteIp.type != IPADDR_TYPE_V6){ - return IPAddress(IPv6); - } - return IPAddress(IPv6, (const uint8_t *)_remoteIp.u_addr.ip6.addr, _remoteIp.u_addr.ip6.zone); +IPAddress AsyncUDPPacket::remoteIPv6() { + if (_remoteIp.type != IPADDR_TYPE_V6) { + return IPAddress(IPv6); + } + return IPAddress(IPv6, (const uint8_t *)_remoteIp.u_addr.ip6.addr, _remoteIp.u_addr.ip6.zone); } -uint16_t AsyncUDPPacket::remotePort() -{ - return _remotePort; +uint16_t AsyncUDPPacket::remotePort() { + return _remotePort; } -void AsyncUDPPacket::remoteMac(uint8_t * mac) -{ - memcpy(mac, _remoteMac, 6); +void AsyncUDPPacket::remoteMac(uint8_t *mac) { + memcpy(mac, _remoteMac, 6); } -bool AsyncUDPPacket::isIPv6() -{ - return _localIp.type == IPADDR_TYPE_V6; +bool AsyncUDPPacket::isIPv6() { + return _localIp.type == IPADDR_TYPE_V6; } -bool AsyncUDPPacket::isBroadcast() -{ - if(_localIp.type == IPADDR_TYPE_V6){ - return false; - } - uint32_t ip = _localIp.u_addr.ip4.addr; - return ip == 0xFFFFFFFF || ip == 0 || (ip & 0xFF000000) == 0xFF000000; +bool AsyncUDPPacket::isBroadcast() { + if (_localIp.type == IPADDR_TYPE_V6) { + return false; + } + uint32_t ip = _localIp.u_addr.ip4.addr; + return ip == 0xFFFFFFFF || ip == 0 || (ip & 0xFF000000) == 0xFF000000; } -bool AsyncUDPPacket::isMulticast() -{ - return ip_addr_ismulticast(&(_localIp)); +bool AsyncUDPPacket::isMulticast() { + return ip_addr_ismulticast(&(_localIp)); } -size_t AsyncUDPPacket::write(const uint8_t *data, size_t len) -{ - if(!data){ - return 0; - } - return _udp->writeTo(data, len, &_remoteIp, _remotePort, _if); +size_t AsyncUDPPacket::write(const uint8_t *data, size_t len) { + if (!data) { + return 0; + } + return _udp->writeTo(data, len, &_remoteIp, _remotePort, _if); } -size_t AsyncUDPPacket::write(uint8_t data) -{ - return write(&data, 1); +size_t AsyncUDPPacket::write(uint8_t data) { + return write(&data, 1); } -size_t AsyncUDPPacket::send(AsyncUDPMessage &message) -{ - return write(message.data(), message.length()); +size_t AsyncUDPPacket::send(AsyncUDPMessage &message) { + return write(message.data(), message.length()); } -bool AsyncUDP::_init(){ - if(_pcb){ - return true; - } - _pcb = udp_new(); - if(!_pcb){ - return false; - } - //_lock = xSemaphoreCreateMutex(); - udp_recv(_pcb, &_udp_recv, (void *) this); +bool AsyncUDP::_init() { + if (_pcb) { return true; -} - -AsyncUDP::AsyncUDP() -{ - _pcb = NULL; - _connected = false; - _lastErr = ERR_OK; - _handler = NULL; -} - -AsyncUDP::~AsyncUDP() -{ - close(); - UDP_MUTEX_LOCK(); - udp_recv(_pcb, NULL, NULL); - _udp_remove(_pcb); - _pcb = NULL; - UDP_MUTEX_UNLOCK(); - //vSemaphoreDelete(_lock); -} - -void AsyncUDP::close() -{ - UDP_MUTEX_LOCK(); - if(_pcb != NULL) { - if(_connected) { - _udp_disconnect(_pcb); - } - _connected = false; - //todo: unjoin multicast group + } + _pcb = udp_new(); + if (!_pcb) { + return false; + } + //_lock = xSemaphoreCreateMutex(); + udp_recv(_pcb, &_udp_recv, (void *)this); + return true; +} + +AsyncUDP::AsyncUDP() { + _pcb = NULL; + _connected = false; + _lastErr = ERR_OK; + _handler = NULL; +} + +AsyncUDP::~AsyncUDP() { + close(); + UDP_MUTEX_LOCK(); + udp_recv(_pcb, NULL, NULL); + _udp_remove(_pcb); + _pcb = NULL; + UDP_MUTEX_UNLOCK(); + //vSemaphoreDelete(_lock); +} + +void AsyncUDP::close() { + UDP_MUTEX_LOCK(); + if (_pcb != NULL) { + if (_connected) { + _udp_disconnect(_pcb); } + _connected = false; + //todo: unjoin multicast group + } + UDP_MUTEX_UNLOCK(); +} + +bool AsyncUDP::connect(const ip_addr_t *addr, uint16_t port) { + if (!_udp_task_start()) { + log_e("failed to start task"); + return false; + } + if (!_init()) { + return false; + } + close(); + UDP_MUTEX_LOCK(); + _lastErr = _udp_connect(_pcb, addr, port); + if (_lastErr != ERR_OK) { UDP_MUTEX_UNLOCK(); -} - -bool AsyncUDP::connect(const ip_addr_t *addr, uint16_t port) -{ - if(!_udp_task_start()){ - log_e("failed to start task"); - return false; - } - if(!_init()) { - return false; - } - close(); - UDP_MUTEX_LOCK(); - _lastErr = _udp_connect(_pcb, addr, port); - if(_lastErr != ERR_OK) { - UDP_MUTEX_UNLOCK(); - return false; - } - _connected = true; + return false; + } + _connected = true; + UDP_MUTEX_UNLOCK(); + return true; +} + +bool AsyncUDP::listen(const ip_addr_t *addr, uint16_t port) { + if (!_udp_task_start()) { + log_e("failed to start task"); + return false; + } + if (!_init()) { + return false; + } + close(); + if (addr) { + IP_SET_TYPE_VAL(_pcb->local_ip, addr->type); + IP_SET_TYPE_VAL(_pcb->remote_ip, addr->type); + } + UDP_MUTEX_LOCK(); + if (_udp_bind(_pcb, addr, port) != ERR_OK) { UDP_MUTEX_UNLOCK(); - return true; -} - -bool AsyncUDP::listen(const ip_addr_t *addr, uint16_t port) -{ - if(!_udp_task_start()){ - log_e("failed to start task"); - return false; - } - if(!_init()) { - return false; - } - close(); - if(addr){ - IP_SET_TYPE_VAL(_pcb->local_ip, addr->type); - IP_SET_TYPE_VAL(_pcb->remote_ip, addr->type); - } - UDP_MUTEX_LOCK(); - if(_udp_bind(_pcb, addr, port) != ERR_OK) { - UDP_MUTEX_UNLOCK(); - return false; + return false; + } + _connected = true; + UDP_MUTEX_UNLOCK(); + return true; +} + +static esp_err_t joinMulticastGroup(const ip_addr_t *addr, bool join, tcpip_adapter_if_t tcpip_if = TCPIP_ADAPTER_IF_MAX) { + struct netif *netif = NULL; + if (tcpip_if < TCPIP_ADAPTER_IF_MAX) { + void *nif = NULL; + esp_err_t err = tcpip_adapter_get_netif(tcpip_if, &nif); + if (err) { + return ESP_ERR_INVALID_ARG; + } + netif = (struct netif *)nif; + + if (addr->type == IPADDR_TYPE_V4) { + if (join) { + if (igmp_joingroup_netif(netif, (const ip4_addr *)&(addr->u_addr.ip4))) { + return ESP_ERR_INVALID_STATE; + } + } else { + if (igmp_leavegroup_netif(netif, (const ip4_addr *)&(addr->u_addr.ip4))) { + return ESP_ERR_INVALID_STATE; + } + } + } else { + if (join) { + if (mld6_joingroup_netif(netif, &(addr->u_addr.ip6))) { + return ESP_ERR_INVALID_STATE; + } + } else { + if (mld6_leavegroup_netif(netif, &(addr->u_addr.ip6))) { + return ESP_ERR_INVALID_STATE; + } + } } - _connected = true; - UDP_MUTEX_UNLOCK(); - return true; -} - -static esp_err_t joinMulticastGroup(const ip_addr_t *addr, bool join, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX) -{ - struct netif * netif = NULL; - if(tcpip_if < TCPIP_ADAPTER_IF_MAX){ - void * nif = NULL; - esp_err_t err = tcpip_adapter_get_netif(tcpip_if, &nif); - if (err) { - return ESP_ERR_INVALID_ARG; + } else { + if (addr->type == IPADDR_TYPE_V4) { + if (join) { + if (igmp_joingroup((const ip4_addr *)IP4_ADDR_ANY, (const ip4_addr *)&(addr->u_addr.ip4))) { + return ESP_ERR_INVALID_STATE; + } + } else { + if (igmp_leavegroup((const ip4_addr *)IP4_ADDR_ANY, (const ip4_addr *)&(addr->u_addr.ip4))) { + return ESP_ERR_INVALID_STATE; } - netif = (struct netif *)nif; - - if (addr->type == IPADDR_TYPE_V4) { - if(join){ - if (igmp_joingroup_netif(netif, (const ip4_addr *)&(addr->u_addr.ip4))) { - return ESP_ERR_INVALID_STATE; - } - } else { - if (igmp_leavegroup_netif(netif, (const ip4_addr *)&(addr->u_addr.ip4))) { - return ESP_ERR_INVALID_STATE; - } - } - } else { - if(join){ - if (mld6_joingroup_netif(netif, &(addr->u_addr.ip6))) { - return ESP_ERR_INVALID_STATE; - } - } else { - if (mld6_leavegroup_netif(netif, &(addr->u_addr.ip6))) { - return ESP_ERR_INVALID_STATE; - } - } + } + } else { + if (join) { + if (mld6_joingroup((const ip6_addr *)IP6_ADDR_ANY, &(addr->u_addr.ip6))) { + return ESP_ERR_INVALID_STATE; } - } else { - if (addr->type == IPADDR_TYPE_V4) { - if(join){ - if (igmp_joingroup((const ip4_addr *)IP4_ADDR_ANY, (const ip4_addr *)&(addr->u_addr.ip4))) { - return ESP_ERR_INVALID_STATE; - } - } else { - if (igmp_leavegroup((const ip4_addr *)IP4_ADDR_ANY, (const ip4_addr *)&(addr->u_addr.ip4))) { - return ESP_ERR_INVALID_STATE; - } - } - } else { - if(join){ - if (mld6_joingroup((const ip6_addr *)IP6_ADDR_ANY, &(addr->u_addr.ip6))) { - return ESP_ERR_INVALID_STATE; - } - } else { - if (mld6_leavegroup((const ip6_addr *)IP6_ADDR_ANY, &(addr->u_addr.ip6))) { - return ESP_ERR_INVALID_STATE; - } - } + } else { + if (mld6_leavegroup((const ip6_addr *)IP6_ADDR_ANY, &(addr->u_addr.ip6))) { + return ESP_ERR_INVALID_STATE; } + } } - return ESP_OK; + } + return ESP_OK; } -bool AsyncUDP::listenMulticast(const ip_addr_t *addr, uint16_t port, uint8_t ttl, tcpip_adapter_if_t tcpip_if) -{ - if(!ip_addr_ismulticast(addr)) { - return false; - } +bool AsyncUDP::listenMulticast(const ip_addr_t *addr, uint16_t port, uint8_t ttl, tcpip_adapter_if_t tcpip_if) { + if (!ip_addr_ismulticast(addr)) { + return false; + } - if (joinMulticastGroup(addr, true, tcpip_if)!= ERR_OK) { - return false; - } + if (joinMulticastGroup(addr, true, tcpip_if) != ERR_OK) { + return false; + } - if(!listen(NULL, port)) { - return false; - } + if (!listen(NULL, port)) { + return false; + } - UDP_MUTEX_LOCK(); - _pcb->mcast_ttl = ttl; - _pcb->remote_port = port; - ip_addr_copy(_pcb->remote_ip, *addr); - //ip_addr_copy(_pcb->remote_ip, ip_addr_any_type); - UDP_MUTEX_UNLOCK(); + UDP_MUTEX_LOCK(); + _pcb->mcast_ttl = ttl; + _pcb->remote_port = port; + ip_addr_copy(_pcb->remote_ip, *addr); + //ip_addr_copy(_pcb->remote_ip, ip_addr_any_type); + UDP_MUTEX_UNLOCK(); - return true; + return true; } -size_t AsyncUDP::writeTo(const uint8_t * data, size_t len, const ip_addr_t * addr, uint16_t port, tcpip_adapter_if_t tcpip_if) -{ - if(!_pcb) { - UDP_MUTEX_LOCK(); - _pcb = udp_new(); - UDP_MUTEX_UNLOCK(); - if(_pcb == NULL) { - return 0; - } - } - if(len > CONFIG_TCP_MSS) { - len = CONFIG_TCP_MSS; +size_t AsyncUDP::writeTo(const uint8_t *data, size_t len, const ip_addr_t *addr, uint16_t port, tcpip_adapter_if_t tcpip_if) { + if (!_pcb) { + UDP_MUTEX_LOCK(); + _pcb = udp_new(); + UDP_MUTEX_UNLOCK(); + if (_pcb == NULL) { + return 0; + } + } + if (len > CONFIG_TCP_MSS) { + len = CONFIG_TCP_MSS; + } + _lastErr = ERR_OK; + pbuf *pbt = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); + if (pbt != NULL) { + uint8_t *dst = reinterpret_cast(pbt->payload); + memcpy(dst, data, len); + UDP_MUTEX_LOCK(); + if (tcpip_if < TCPIP_ADAPTER_IF_MAX) { + void *nif = NULL; + tcpip_adapter_get_netif((tcpip_adapter_if_t)tcpip_if, &nif); + if (!nif) { + _lastErr = _udp_sendto(_pcb, pbt, addr, port); + } else { + _lastErr = _udp_sendto_if(_pcb, pbt, addr, port, (struct netif *)nif); + } + } else { + _lastErr = _udp_sendto(_pcb, pbt, addr, port); } - _lastErr = ERR_OK; - pbuf* pbt = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); - if(pbt != NULL) { - uint8_t* dst = reinterpret_cast(pbt->payload); - memcpy(dst, data, len); - UDP_MUTEX_LOCK(); - if(tcpip_if < TCPIP_ADAPTER_IF_MAX){ - void * nif = NULL; - tcpip_adapter_get_netif((tcpip_adapter_if_t)tcpip_if, &nif); - if(!nif){ - _lastErr = _udp_sendto(_pcb, pbt, addr, port); - } else { - _lastErr = _udp_sendto_if(_pcb, pbt, addr, port, (struct netif *)nif); - } - } else { - _lastErr = _udp_sendto(_pcb, pbt, addr, port); - } - UDP_MUTEX_UNLOCK(); - pbuf_free(pbt); - if(_lastErr < ERR_OK) { - return 0; - } - return len; + UDP_MUTEX_UNLOCK(); + pbuf_free(pbt); + if (_lastErr < ERR_OK) { + return 0; } - return 0; + return len; + } + return 0; } -void AsyncUDP::_recv(udp_pcb *upcb, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif * netif) -{ - while(pb != NULL) { - pbuf * this_pb = pb; - pb = pb->next; - this_pb->next = NULL; - if(_handler) { - AsyncUDPPacket packet(this, this_pb, addr, port, netif); - _handler(packet); - } - pbuf_free(this_pb); +void AsyncUDP::_recv(udp_pcb *upcb, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif *netif) { + while (pb != NULL) { + pbuf *this_pb = pb; + pb = pb->next; + this_pb->next = NULL; + if (_handler) { + AsyncUDPPacket packet(this, this_pb, addr, port, netif); + _handler(packet); } + pbuf_free(this_pb); + } } -void AsyncUDP::_s_recv(void *arg, udp_pcb *upcb, pbuf *p, const ip_addr_t *addr, uint16_t port, struct netif * netif) -{ - reinterpret_cast(arg)->_recv(upcb, p, addr, port, netif); +void AsyncUDP::_s_recv(void *arg, udp_pcb *upcb, pbuf *p, const ip_addr_t *addr, uint16_t port, struct netif *netif) { + reinterpret_cast(arg)->_recv(upcb, p, addr, port, netif); } -bool AsyncUDP::listen(uint16_t port) -{ - return listen(IP_ANY_TYPE, port); +bool AsyncUDP::listen(uint16_t port) { + return listen(IP_ANY_TYPE, port); } -bool AsyncUDP::listen(const IPAddress addr, uint16_t port) -{ - ip_addr_t laddr; - addr.to_ip_addr_t(&laddr); - return listen(&laddr, port); +bool AsyncUDP::listen(const IPAddress addr, uint16_t port) { + ip_addr_t laddr; + addr.to_ip_addr_t(&laddr); + return listen(&laddr, port); } -bool AsyncUDP::listenMulticast(const IPAddress addr, uint16_t port, uint8_t ttl, tcpip_adapter_if_t tcpip_if) -{ - ip_addr_t laddr; - addr.to_ip_addr_t(&laddr); - return listenMulticast(&laddr, port, ttl, tcpip_if); +bool AsyncUDP::listenMulticast(const IPAddress addr, uint16_t port, uint8_t ttl, tcpip_adapter_if_t tcpip_if) { + ip_addr_t laddr; + addr.to_ip_addr_t(&laddr); + return listenMulticast(&laddr, port, ttl, tcpip_if); } -bool AsyncUDP::connect(const IPAddress addr, uint16_t port) -{ - ip_addr_t daddr; - addr.to_ip_addr_t(&daddr); - return connect(&daddr, port); +bool AsyncUDP::connect(const IPAddress addr, uint16_t port) { + ip_addr_t daddr; + addr.to_ip_addr_t(&daddr); + return connect(&daddr, port); } -size_t AsyncUDP::writeTo(const uint8_t *data, size_t len, const IPAddress addr, uint16_t port, tcpip_adapter_if_t tcpip_if) -{ - ip_addr_t daddr; - addr.to_ip_addr_t(&daddr); - return writeTo(data, len, &daddr, port, tcpip_if); +size_t AsyncUDP::writeTo(const uint8_t *data, size_t len, const IPAddress addr, uint16_t port, tcpip_adapter_if_t tcpip_if) { + ip_addr_t daddr; + addr.to_ip_addr_t(&daddr); + return writeTo(data, len, &daddr, port, tcpip_if); } -IPAddress AsyncUDP::listenIP() -{ - if(!_pcb || _pcb->remote_ip.type != IPADDR_TYPE_V4){ - return IPAddress(); - } - return IPAddress(_pcb->remote_ip.u_addr.ip4.addr); +IPAddress AsyncUDP::listenIP() { + if (!_pcb || _pcb->remote_ip.type != IPADDR_TYPE_V4) { + return IPAddress(); + } + return IPAddress(_pcb->remote_ip.u_addr.ip4.addr); } -IPAddress AsyncUDP::listenIPv6() -{ - if(!_pcb || _pcb->remote_ip.type != IPADDR_TYPE_V6){ - return IPAddress(IPv6); - } - return IPAddress(IPv6, (const uint8_t *)_pcb->remote_ip.u_addr.ip6.addr, _pcb->remote_ip.u_addr.ip6.zone); +IPAddress AsyncUDP::listenIPv6() { + if (!_pcb || _pcb->remote_ip.type != IPADDR_TYPE_V6) { + return IPAddress(IPv6); + } + return IPAddress(IPv6, (const uint8_t *)_pcb->remote_ip.u_addr.ip6.addr, _pcb->remote_ip.u_addr.ip6.zone); } -size_t AsyncUDP::write(const uint8_t *data, size_t len) -{ - return writeTo(data, len, &(_pcb->remote_ip), _pcb->remote_port); +size_t AsyncUDP::write(const uint8_t *data, size_t len) { + return writeTo(data, len, &(_pcb->remote_ip), _pcb->remote_port); } -size_t AsyncUDP::write(uint8_t data) -{ - return write(&data, 1); +size_t AsyncUDP::write(uint8_t data) { + return write(&data, 1); } -size_t AsyncUDP::broadcastTo(uint8_t *data, size_t len, uint16_t port, tcpip_adapter_if_t tcpip_if) -{ - return writeTo(data, len, IP_ADDR_BROADCAST, port, tcpip_if); +size_t AsyncUDP::broadcastTo(uint8_t *data, size_t len, uint16_t port, tcpip_adapter_if_t tcpip_if) { + return writeTo(data, len, IP_ADDR_BROADCAST, port, tcpip_if); } -size_t AsyncUDP::broadcastTo(const char * data, uint16_t port, tcpip_adapter_if_t tcpip_if) -{ - return broadcastTo((uint8_t *)data, strlen(data), port, tcpip_if); +size_t AsyncUDP::broadcastTo(const char *data, uint16_t port, tcpip_adapter_if_t tcpip_if) { + return broadcastTo((uint8_t *)data, strlen(data), port, tcpip_if); } -size_t AsyncUDP::broadcast(uint8_t *data, size_t len) -{ - if(_pcb->local_port != 0) { - return broadcastTo(data, len, _pcb->local_port); - } - return 0; +size_t AsyncUDP::broadcast(uint8_t *data, size_t len) { + if (_pcb->local_port != 0) { + return broadcastTo(data, len, _pcb->local_port); + } + return 0; } -size_t AsyncUDP::broadcast(const char * data) -{ - return broadcast((uint8_t *)data, strlen(data)); +size_t AsyncUDP::broadcast(const char *data) { + return broadcast((uint8_t *)data, strlen(data)); } -size_t AsyncUDP::sendTo(AsyncUDPMessage &message, const ip_addr_t *addr, uint16_t port, tcpip_adapter_if_t tcpip_if) -{ - if(!message) { - return 0; - } - return writeTo(message.data(), message.length(), addr, port, tcpip_if); +size_t AsyncUDP::sendTo(AsyncUDPMessage &message, const ip_addr_t *addr, uint16_t port, tcpip_adapter_if_t tcpip_if) { + if (!message) { + return 0; + } + return writeTo(message.data(), message.length(), addr, port, tcpip_if); } -size_t AsyncUDP::sendTo(AsyncUDPMessage &message, const IPAddress addr, uint16_t port, tcpip_adapter_if_t tcpip_if) -{ - if(!message) { - return 0; - } - return writeTo(message.data(), message.length(), addr, port, tcpip_if); +size_t AsyncUDP::sendTo(AsyncUDPMessage &message, const IPAddress addr, uint16_t port, tcpip_adapter_if_t tcpip_if) { + if (!message) { + return 0; + } + return writeTo(message.data(), message.length(), addr, port, tcpip_if); } -size_t AsyncUDP::send(AsyncUDPMessage &message) -{ - if(!message) { - return 0; - } - return writeTo(message.data(), message.length(), &(_pcb->remote_ip), _pcb->remote_port); +size_t AsyncUDP::send(AsyncUDPMessage &message) { + if (!message) { + return 0; + } + return writeTo(message.data(), message.length(), &(_pcb->remote_ip), _pcb->remote_port); } -size_t AsyncUDP::broadcastTo(AsyncUDPMessage &message, uint16_t port, tcpip_adapter_if_t tcpip_if) -{ - if(!message) { - return 0; - } - return broadcastTo(message.data(), message.length(), port, tcpip_if); +size_t AsyncUDP::broadcastTo(AsyncUDPMessage &message, uint16_t port, tcpip_adapter_if_t tcpip_if) { + if (!message) { + return 0; + } + return broadcastTo(message.data(), message.length(), port, tcpip_if); } -size_t AsyncUDP::broadcast(AsyncUDPMessage &message) -{ - if(!message) { - return 0; - } - return broadcast(message.data(), message.length()); +size_t AsyncUDP::broadcast(AsyncUDPMessage &message) { + if (!message) { + return 0; + } + return broadcast(message.data(), message.length()); } -AsyncUDP::operator bool() -{ - return _connected; +AsyncUDP::operator bool() { + return _connected; } -bool AsyncUDP::connected() -{ - return _connected; +bool AsyncUDP::connected() { + return _connected; } esp_err_t AsyncUDP::lastErr() { - return _lastErr; + return _lastErr; } -void AsyncUDP::onPacket(AuPacketHandlerFunctionWithArg cb, void * arg) -{ - onPacket(std::bind(cb, arg, std::placeholders::_1)); +void AsyncUDP::onPacket(AuPacketHandlerFunctionWithArg cb, void *arg) { + onPacket(std::bind(cb, arg, std::placeholders::_1)); } -void AsyncUDP::onPacket(AuPacketHandlerFunction cb) -{ - _handler = cb; +void AsyncUDP::onPacket(AuPacketHandlerFunction cb) { + _handler = cb; } diff --git a/libraries/AsyncUDP/src/AsyncUDP.h b/libraries/AsyncUDP/src/AsyncUDP.h index 31d075191df..b9cb6319a1d 100644 --- a/libraries/AsyncUDP/src/AsyncUDP.h +++ b/libraries/AsyncUDP/src/AsyncUDP.h @@ -14,11 +14,11 @@ extern "C" { // This enum and it's uses are copied and adapted for compatibility from ESP-IDF 4- typedef enum { - TCPIP_ADAPTER_IF_STA = 0, /**< Wi-Fi STA (station) interface */ - TCPIP_ADAPTER_IF_AP, /**< Wi-Fi soft-AP interface */ - TCPIP_ADAPTER_IF_ETH, /**< Ethernet interface */ - TCPIP_ADAPTER_IF_PPP, /**< PPP interface */ - TCPIP_ADAPTER_IF_MAX + TCPIP_ADAPTER_IF_STA = 0, /**< Wi-Fi STA (station) interface */ + TCPIP_ADAPTER_IF_AP, /**< Wi-Fi soft-AP interface */ + TCPIP_ADAPTER_IF_ETH, /**< Ethernet interface */ + TCPIP_ADAPTER_IF_PPP, /**< PPP interface */ + TCPIP_ADAPTER_IF_MAX } tcpip_adapter_if_t; class AsyncUDP; @@ -28,132 +28,128 @@ struct udp_pcb; struct pbuf; struct netif; -typedef std::function AuPacketHandlerFunction; -typedef std::function AuPacketHandlerFunctionWithArg; +typedef std::function AuPacketHandlerFunction; +typedef std::function AuPacketHandlerFunctionWithArg; -class AsyncUDPMessage : public Print -{ +class AsyncUDPMessage : public Print { protected: - uint8_t *_buffer; - size_t _index; - size_t _size; + uint8_t *_buffer; + size_t _index; + size_t _size; public: - AsyncUDPMessage(size_t size=CONFIG_TCP_MSS); - virtual ~AsyncUDPMessage(); - size_t write(const uint8_t *data, size_t len); - size_t write(uint8_t data); - size_t space(); - uint8_t * data(); - size_t length(); - void flush(); - operator bool() - { - return _buffer != NULL; - } + AsyncUDPMessage(size_t size = CONFIG_TCP_MSS); + virtual ~AsyncUDPMessage(); + size_t write(const uint8_t *data, size_t len); + size_t write(uint8_t data); + size_t space(); + uint8_t *data(); + size_t length(); + void flush(); + operator bool() { + return _buffer != NULL; + } }; -class AsyncUDPPacket : public Stream -{ +class AsyncUDPPacket : public Stream { protected: - AsyncUDP *_udp; - pbuf *_pb; - tcpip_adapter_if_t _if; - ip_addr_t _localIp; - uint16_t _localPort; - ip_addr_t _remoteIp; - uint16_t _remotePort; - uint8_t _remoteMac[6]; - uint8_t *_data; - size_t _len; - size_t _index; + AsyncUDP *_udp; + pbuf *_pb; + tcpip_adapter_if_t _if; + ip_addr_t _localIp; + uint16_t _localPort; + ip_addr_t _remoteIp; + uint16_t _remotePort; + uint8_t _remoteMac[6]; + uint8_t *_data; + size_t _len; + size_t _index; public: - AsyncUDPPacket(AsyncUDPPacket &packet); - AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif * netif); - virtual ~AsyncUDPPacket(); - - uint8_t * data(); - size_t length(); - bool isBroadcast(); - bool isMulticast(); - bool isIPv6(); - - tcpip_adapter_if_t interface(); - - IPAddress localIP(); - IPAddress localIPv6(); - uint16_t localPort(); - IPAddress remoteIP(); - IPAddress remoteIPv6(); - uint16_t remotePort(); - void remoteMac(uint8_t * mac); - - size_t send(AsyncUDPMessage &message); - - int available(); - size_t read(uint8_t *data, size_t len); - int read(); - int peek(); - void flush(); - - size_t write(const uint8_t *data, size_t len); - size_t write(uint8_t data); + AsyncUDPPacket(AsyncUDPPacket &packet); + AsyncUDPPacket(AsyncUDP *udp, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif *netif); + virtual ~AsyncUDPPacket(); + + uint8_t *data(); + size_t length(); + bool isBroadcast(); + bool isMulticast(); + bool isIPv6(); + + tcpip_adapter_if_t interface(); + + IPAddress localIP(); + IPAddress localIPv6(); + uint16_t localPort(); + IPAddress remoteIP(); + IPAddress remoteIPv6(); + uint16_t remotePort(); + void remoteMac(uint8_t *mac); + + size_t send(AsyncUDPMessage &message); + + int available(); + size_t read(uint8_t *data, size_t len); + int read(); + int peek(); + void flush(); + + size_t write(const uint8_t *data, size_t len); + size_t write(uint8_t data); }; -class AsyncUDP : public Print -{ +class AsyncUDP : public Print { protected: - udp_pcb *_pcb; - //SemaphoreHandle_t _lock; - bool _connected; - esp_err_t _lastErr; - AuPacketHandlerFunction _handler; + udp_pcb *_pcb; + //SemaphoreHandle_t _lock; + bool _connected; + esp_err_t _lastErr; + AuPacketHandlerFunction _handler; - bool _init(); - void _recv(udp_pcb *upcb, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif * netif); + bool _init(); + void _recv(udp_pcb *upcb, pbuf *pb, const ip_addr_t *addr, uint16_t port, struct netif *netif); public: - AsyncUDP(); - virtual ~AsyncUDP(); + AsyncUDP(); + virtual ~AsyncUDP(); - void onPacket(AuPacketHandlerFunctionWithArg cb, void * arg=NULL); - void onPacket(AuPacketHandlerFunction cb); + void onPacket(AuPacketHandlerFunctionWithArg cb, void *arg = NULL); + void onPacket(AuPacketHandlerFunction cb); - bool listen(const ip_addr_t *addr, uint16_t port); - bool listen(const IPAddress addr, uint16_t port); - bool listen(uint16_t port); + bool listen(const ip_addr_t *addr, uint16_t port); + bool listen(const IPAddress addr, uint16_t port); + bool listen(uint16_t port); - bool listenMulticast(const ip_addr_t *addr, uint16_t port, uint8_t ttl=1, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX); - bool listenMulticast(const IPAddress addr, uint16_t port, uint8_t ttl=1, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX); + bool listenMulticast(const ip_addr_t *addr, uint16_t port, uint8_t ttl = 1, tcpip_adapter_if_t tcpip_if = TCPIP_ADAPTER_IF_MAX); + bool listenMulticast(const IPAddress addr, uint16_t port, uint8_t ttl = 1, tcpip_adapter_if_t tcpip_if = TCPIP_ADAPTER_IF_MAX); - bool connect(const ip_addr_t *addr, uint16_t port); - bool connect(const IPAddress addr, uint16_t port); + bool connect(const ip_addr_t *addr, uint16_t port); + bool connect(const IPAddress addr, uint16_t port); - void close(); + void close(); - size_t writeTo(const uint8_t *data, size_t len, const ip_addr_t *addr, uint16_t port, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX); - size_t writeTo(const uint8_t *data, size_t len, const IPAddress addr, uint16_t port, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX); - size_t write(const uint8_t *data, size_t len); - size_t write(uint8_t data); + size_t writeTo(const uint8_t *data, size_t len, const ip_addr_t *addr, uint16_t port, tcpip_adapter_if_t tcpip_if = TCPIP_ADAPTER_IF_MAX); + size_t writeTo(const uint8_t *data, size_t len, const IPAddress addr, uint16_t port, tcpip_adapter_if_t tcpip_if = TCPIP_ADAPTER_IF_MAX); + size_t write(const uint8_t *data, size_t len); + size_t write(uint8_t data); - size_t broadcastTo(uint8_t *data, size_t len, uint16_t port, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX); - size_t broadcastTo(const char * data, uint16_t port, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX); - size_t broadcast(uint8_t *data, size_t len); - size_t broadcast(const char * data); + size_t broadcastTo(uint8_t *data, size_t len, uint16_t port, tcpip_adapter_if_t tcpip_if = TCPIP_ADAPTER_IF_MAX); + size_t broadcastTo(const char *data, uint16_t port, tcpip_adapter_if_t tcpip_if = TCPIP_ADAPTER_IF_MAX); + size_t broadcast(uint8_t *data, size_t len); + size_t broadcast(const char *data); - size_t sendTo(AsyncUDPMessage &message, const ip_addr_t *addr, uint16_t port, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX); - size_t sendTo(AsyncUDPMessage &message, const IPAddress addr, uint16_t port, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX); - size_t send(AsyncUDPMessage &message); + size_t sendTo(AsyncUDPMessage &message, const ip_addr_t *addr, uint16_t port, tcpip_adapter_if_t tcpip_if = TCPIP_ADAPTER_IF_MAX); + size_t sendTo(AsyncUDPMessage &message, const IPAddress addr, uint16_t port, tcpip_adapter_if_t tcpip_if = TCPIP_ADAPTER_IF_MAX); + size_t send(AsyncUDPMessage &message); - size_t broadcastTo(AsyncUDPMessage &message, uint16_t port, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_MAX); - size_t broadcast(AsyncUDPMessage &message); + size_t broadcastTo(AsyncUDPMessage &message, uint16_t port, tcpip_adapter_if_t tcpip_if = TCPIP_ADAPTER_IF_MAX); + size_t broadcast(AsyncUDPMessage &message); - IPAddress listenIP(); - IPAddress listenIPv6(); - bool connected(); - esp_err_t lastErr(); - operator bool(); + IPAddress listenIP(); + IPAddress listenIPv6(); + bool connected(); + esp_err_t lastErr(); + operator bool(); - static void _s_recv(void *arg, udp_pcb *upcb, pbuf *p, const ip_addr_t *addr, uint16_t port, struct netif * netif); + static void _s_recv(void *arg, udp_pcb *upcb, pbuf *p, const ip_addr_t *addr, uint16_t port, struct netif *netif); }; #endif diff --git a/libraries/BLE/README.md b/libraries/BLE/README.md index e80fbe0c52b..05cc8bf68e2 100644 --- a/libraries/BLE/README.md +++ b/libraries/BLE/README.md @@ -12,4 +12,4 @@ https://github.com/nkolban/esp32-snippets/issues Documentation for using the library can be found here: -https://github.com/nkolban/esp32-snippets/tree/master/Documentation \ No newline at end of file +https://github.com/nkolban/esp32-snippets/tree/master/Documentation diff --git a/libraries/BLE/examples/BLE5_extended_scan/BLE5_extended_scan.ino b/libraries/BLE/examples/BLE5_extended_scan/BLE5_extended_scan.ino index ec0f3965175..b052694150a 100644 --- a/libraries/BLE/examples/BLE5_extended_scan/BLE5_extended_scan.ino +++ b/libraries/BLE/examples/BLE5_extended_scan/BLE5_extended_scan.ino @@ -16,19 +16,19 @@ #include #include -uint32_t scanTime = 100; //In 10ms (1000ms) +uint32_t scanTime = 100; //In 10ms (1000ms) BLEScan* pBLEScan; -class MyBLEExtAdvertisingCallbacks: public BLEExtAdvertisingCallbacks { - void onResult(esp_ble_gap_ext_adv_report_t report) { - if(report.event_type & ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY){ - // here we can receive regular advertising data from BLE4.x devices - Serial.println("BLE4.2"); - } else { - // here we will get extended advertising data that are advertised over data channel by BLE5 divices - Serial.printf("Ext advertise: data_le: %d, data_status: %d \n", report.adv_data_len, report.data_status); - } +class MyBLEExtAdvertisingCallbacks : public BLEExtAdvertisingCallbacks { + void onResult(esp_ble_gap_ext_adv_report_t report) { + if (report.event_type & ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY) { + // here we can receive regular advertising data from BLE4.x devices + Serial.println("BLE4.2"); + } else { + // here we will get extended advertising data that are advertised over data channel by BLE5 divices + Serial.printf("Ext advertise: data_le: %d, data_status: %d \n", report.adv_data_len, report.data_status); } + } }; void setup() { @@ -36,15 +36,15 @@ void setup() { Serial.println("Scanning..."); BLEDevice::init(""); - pBLEScan = BLEDevice::getScan(); //create new scan + pBLEScan = BLEDevice::getScan(); //create new scan pBLEScan->setExtendedScanCallback(new MyBLEExtAdvertisingCallbacks()); - pBLEScan->setExtScanParams(); // use with pre-defined/default values, overloaded function allows to pass parameters - delay(1000); // it is just for simplicity this example, to let ble stack to set extended scan params - pBLEScan->startExtScan(scanTime, 3); // scan duration in n * 10ms, period - repeat after n seconds (period >= duration) + pBLEScan->setExtScanParams(); // use with pre-defined/default values, overloaded function allows to pass parameters + delay(1000); // it is just for simplicity this example, to let ble stack to set extended scan params + pBLEScan->startExtScan(scanTime, 3); // scan duration in n * 10ms, period - repeat after n seconds (period >= duration) } void loop() { // put your main code here, to run repeatedly: delay(2000); } -#endif // SOC_BLE_50_SUPPORTED +#endif // SOC_BLE_50_SUPPORTED diff --git a/libraries/BLE/examples/BLE5_multi_advertising/BLE5_multi_advertising.ino b/libraries/BLE/examples/BLE5_multi_advertising/BLE5_multi_advertising.ino index 51935041fef..6a69d706ad3 100644 --- a/libraries/BLE/examples/BLE5_multi_advertising/BLE5_multi_advertising.ino +++ b/libraries/BLE/examples/BLE5_multi_advertising/BLE5_multi_advertising.ino @@ -7,120 +7,120 @@ */ #ifndef CONFIG_BT_BLE_50_FEATURES_SUPPORTED - #error "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3" +#error "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3" #else #include #include esp_ble_gap_ext_adv_params_t ext_adv_params_1M = { - .type = ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE, - .interval_min = 0x30, - .interval_max = 0x30, - .channel_map = ADV_CHNL_ALL, - .own_addr_type = BLE_ADDR_TYPE_RANDOM, - .peer_addr_type = BLE_ADDR_TYPE_RANDOM, - .peer_addr = {0,0,0,0,0,0}, - .filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, - .tx_power = EXT_ADV_TX_PWR_NO_PREFERENCE, - .primary_phy = ESP_BLE_GAP_PHY_CODED, - .max_skip = 0, - .secondary_phy = ESP_BLE_GAP_PHY_1M, - .sid = 0, - .scan_req_notif = false, + .type = ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE, + .interval_min = 0x30, + .interval_max = 0x30, + .channel_map = ADV_CHNL_ALL, + .own_addr_type = BLE_ADDR_TYPE_RANDOM, + .peer_addr_type = BLE_ADDR_TYPE_RANDOM, + .peer_addr = { 0, 0, 0, 0, 0, 0 }, + .filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, + .tx_power = EXT_ADV_TX_PWR_NO_PREFERENCE, + .primary_phy = ESP_BLE_GAP_PHY_CODED, + .max_skip = 0, + .secondary_phy = ESP_BLE_GAP_PHY_1M, + .sid = 0, + .scan_req_notif = false, }; esp_ble_gap_ext_adv_params_t ext_adv_params_2M = { - .type = ESP_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE, - .interval_min = 0x40, - .interval_max = 0x40, - .channel_map = ADV_CHNL_ALL, - .own_addr_type = BLE_ADDR_TYPE_RANDOM, - .peer_addr_type = BLE_ADDR_TYPE_RANDOM, - .peer_addr = {0,0,0,0,0,0}, - .filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, - .tx_power = EXT_ADV_TX_PWR_NO_PREFERENCE, - .primary_phy = ESP_BLE_GAP_PHY_1M, - .max_skip = 0, - .secondary_phy = ESP_BLE_GAP_PHY_2M, - .sid = 1, - .scan_req_notif = false, + .type = ESP_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE, + .interval_min = 0x40, + .interval_max = 0x40, + .channel_map = ADV_CHNL_ALL, + .own_addr_type = BLE_ADDR_TYPE_RANDOM, + .peer_addr_type = BLE_ADDR_TYPE_RANDOM, + .peer_addr = { 0, 0, 0, 0, 0, 0 }, + .filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, + .tx_power = EXT_ADV_TX_PWR_NO_PREFERENCE, + .primary_phy = ESP_BLE_GAP_PHY_1M, + .max_skip = 0, + .secondary_phy = ESP_BLE_GAP_PHY_2M, + .sid = 1, + .scan_req_notif = false, }; esp_ble_gap_ext_adv_params_t legacy_adv_params = { - .type = ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_IND, - .interval_min = 0x45, - .interval_max = 0x45, - .channel_map = ADV_CHNL_ALL, - .own_addr_type = BLE_ADDR_TYPE_RANDOM, - .peer_addr_type = BLE_ADDR_TYPE_RANDOM, - .peer_addr = {0,0,0,0,0,0}, - .filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, - .tx_power = EXT_ADV_TX_PWR_NO_PREFERENCE, - .primary_phy = ESP_BLE_GAP_PHY_1M, - .max_skip = 0, - .secondary_phy = ESP_BLE_GAP_PHY_1M, - .sid = 2, - .scan_req_notif = false, + .type = ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_IND, + .interval_min = 0x45, + .interval_max = 0x45, + .channel_map = ADV_CHNL_ALL, + .own_addr_type = BLE_ADDR_TYPE_RANDOM, + .peer_addr_type = BLE_ADDR_TYPE_RANDOM, + .peer_addr = { 0, 0, 0, 0, 0, 0 }, + .filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, + .tx_power = EXT_ADV_TX_PWR_NO_PREFERENCE, + .primary_phy = ESP_BLE_GAP_PHY_1M, + .max_skip = 0, + .secondary_phy = ESP_BLE_GAP_PHY_1M, + .sid = 2, + .scan_req_notif = false, }; esp_ble_gap_ext_adv_params_t ext_adv_params_coded = { - .type = ESP_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE, - .interval_min = 0x50, - .interval_max = 0x50, - .channel_map = ADV_CHNL_ALL, - .own_addr_type = BLE_ADDR_TYPE_RANDOM, - .peer_addr_type = BLE_ADDR_TYPE_RANDOM, - .peer_addr = {0,0,0,0,0,0}, - .filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, - .tx_power = EXT_ADV_TX_PWR_NO_PREFERENCE, - .primary_phy = ESP_BLE_GAP_PHY_1M, - .max_skip = 0, - .secondary_phy = ESP_BLE_GAP_PHY_CODED, - .sid = 3, - .scan_req_notif = false, + .type = ESP_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE, + .interval_min = 0x50, + .interval_max = 0x50, + .channel_map = ADV_CHNL_ALL, + .own_addr_type = BLE_ADDR_TYPE_RANDOM, + .peer_addr_type = BLE_ADDR_TYPE_RANDOM, + .peer_addr = { 0, 0, 0, 0, 0, 0 }, + .filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, + .tx_power = EXT_ADV_TX_PWR_NO_PREFERENCE, + .primary_phy = ESP_BLE_GAP_PHY_1M, + .max_skip = 0, + .secondary_phy = ESP_BLE_GAP_PHY_CODED, + .sid = 3, + .scan_req_notif = false, }; static uint8_t raw_adv_data_1m[] = { - 0x02, 0x01, 0x06, - 0x02, 0x0a, 0xeb, - 0x12, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A', - 'D', 'V', '_', '1', 'M', 0X0 + 0x02, 0x01, 0x06, + 0x02, 0x0a, 0xeb, + 0x12, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A', + 'D', 'V', '_', '1', 'M', 0X0 }; static uint8_t raw_scan_rsp_data_2m[] = { - 0x02, 0x01, 0x06, - 0x02, 0x0a, 0xeb, - 0x12, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A', - 'D', 'V', '_', '2', 'M', 0X0 + 0x02, 0x01, 0x06, + 0x02, 0x0a, 0xeb, + 0x12, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A', + 'D', 'V', '_', '2', 'M', 0X0 }; static uint8_t legacy_adv_data[] = { - 0x02, 0x01, 0x06, - 0x02, 0x0a, 0xeb, - 0x15, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A', - 'D', 'V', '_', 'C', 'O', 'D', 'E', 'D', 0X0 + 0x02, 0x01, 0x06, + 0x02, 0x0a, 0xeb, + 0x15, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A', + 'D', 'V', '_', 'C', 'O', 'D', 'E', 'D', 0X0 }; static uint8_t legacy_scan_rsp_data[] = { - 0x02, 0x01, 0x06, - 0x02, 0x0a, 0xeb, - 0x16, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A', - 'D', 'V', '_', 'L', 'E', 'G', 'A', 'C', 'Y', 0X0 + 0x02, 0x01, 0x06, + 0x02, 0x0a, 0xeb, + 0x16, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A', + 'D', 'V', '_', 'L', 'E', 'G', 'A', 'C', 'Y', 0X0 }; static uint8_t raw_scan_rsp_data_coded[] = { - 0x37, 0x09, 'V', 'E', 'R', 'Y', '_', 'L', 'O', 'N', 'G', '_', 'D', 'E', 'V', 'I', 'C', 'E', '_', 'N', 'A', 'M', 'E', '_', - 'S', 'E', 'N', 'T', '_', 'U', 'S', 'I', 'N', 'G', '_', 'E', 'X', 'T', 'E', 'N', 'D', 'E', 'D', '_', 'A', 'D', 'V', 'E', 'R', 'T', 'I', 'S', 'I', 'N', 'G', 0X0 + 0x37, 0x09, 'V', 'E', 'R', 'Y', '_', 'L', 'O', 'N', 'G', '_', 'D', 'E', 'V', 'I', 'C', 'E', '_', 'N', 'A', 'M', 'E', '_', + 'S', 'E', 'N', 'T', '_', 'U', 'S', 'I', 'N', 'G', '_', 'E', 'X', 'T', 'E', 'N', 'D', 'E', 'D', '_', 'A', 'D', 'V', 'E', 'R', 'T', 'I', 'S', 'I', 'N', 'G', 0X0 }; -uint8_t addr_1m[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x01}; -uint8_t addr_2m[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x02}; -uint8_t addr_legacy[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x03}; -uint8_t addr_coded[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x04}; +uint8_t addr_1m[6] = { 0xc0, 0xde, 0x52, 0x00, 0x00, 0x01 }; +uint8_t addr_2m[6] = { 0xc0, 0xde, 0x52, 0x00, 0x00, 0x02 }; +uint8_t addr_legacy[6] = { 0xc0, 0xde, 0x52, 0x00, 0x00, 0x03 }; +uint8_t addr_coded[6] = { 0xc0, 0xde, 0x52, 0x00, 0x00, 0x04 }; -BLEMultiAdvertising advert(4); // max number of advertisement data +BLEMultiAdvertising advert(4); // max number of advertisement data void setup() { Serial.begin(115200); @@ -156,4 +156,4 @@ void setup() { void loop() { delay(2000); } -#endif \ No newline at end of file +#endif diff --git a/libraries/BLE/examples/BLE5_periodic_advertising/BLE5_periodic_advertising.ino b/libraries/BLE/examples/BLE5_periodic_advertising/BLE5_periodic_advertising.ino index 123a5d13ffe..8587a928ccb 100644 --- a/libraries/BLE/examples/BLE5_periodic_advertising/BLE5_periodic_advertising.ino +++ b/libraries/BLE/examples/BLE5_periodic_advertising/BLE5_periodic_advertising.ino @@ -6,54 +6,54 @@ */ #ifndef CONFIG_BT_BLE_50_FEATURES_SUPPORTED - #error "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3" +#error "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3" #else #include #include esp_ble_gap_ext_adv_params_t ext_adv_params_2M = { - .type = ESP_BLE_GAP_SET_EXT_ADV_PROP_NONCONN_NONSCANNABLE_UNDIRECTED, - .interval_min = 0x40, - .interval_max = 0x40, - .channel_map = ADV_CHNL_ALL, - .own_addr_type = BLE_ADDR_TYPE_RANDOM, - .peer_addr_type = BLE_ADDR_TYPE_RANDOM, - .peer_addr = {0,0,0,0,0,0}, - .filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, - .tx_power = EXT_ADV_TX_PWR_NO_PREFERENCE, - .primary_phy = ESP_BLE_GAP_PHY_1M, - .max_skip = 0, - .secondary_phy = ESP_BLE_GAP_PHY_2M, - .sid = 1, - .scan_req_notif = false, + .type = ESP_BLE_GAP_SET_EXT_ADV_PROP_NONCONN_NONSCANNABLE_UNDIRECTED, + .interval_min = 0x40, + .interval_max = 0x40, + .channel_map = ADV_CHNL_ALL, + .own_addr_type = BLE_ADDR_TYPE_RANDOM, + .peer_addr_type = BLE_ADDR_TYPE_RANDOM, + .peer_addr = { 0, 0, 0, 0, 0, 0 }, + .filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, + .tx_power = EXT_ADV_TX_PWR_NO_PREFERENCE, + .primary_phy = ESP_BLE_GAP_PHY_1M, + .max_skip = 0, + .secondary_phy = ESP_BLE_GAP_PHY_2M, + .sid = 1, + .scan_req_notif = false, }; static uint8_t raw_scan_rsp_data_2m[] = { - 0x02, 0x01, 0x06, - 0x02, 0x0a, 0xeb, - 0x12, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A', - 'D', 'V', '_', '2', 'M', 0X0 + 0x02, 0x01, 0x06, + 0x02, 0x0a, 0xeb, + 0x12, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A', + 'D', 'V', '_', '2', 'M', 0X0 }; static esp_ble_gap_periodic_adv_params_t periodic_adv_params = { - .interval_min = 0x320, // 1000 ms interval - .interval_max = 0x640, - .properties = 0, // Do not include TX power + .interval_min = 0x320, // 1000 ms interval + .interval_max = 0x640, + .properties = 0, // Do not include TX power }; static uint8_t periodic_adv_raw_data[] = { - 0x02, 0x01, 0x06, - 0x02, 0x0a, 0xeb, - 0x03, 0x03, 0xab, 0xcd, - 0x11, 0x09, 'E', 'S', 'P', '_', 'P', 'E', 'R', 'I', 'O', 'D', 'I', - 'C', '_', 'A', 'D', 'V' + 0x02, 0x01, 0x06, + 0x02, 0x0a, 0xeb, + 0x03, 0x03, 0xab, 0xcd, + 0x11, 0x09, 'E', 'S', 'P', '_', 'P', 'E', 'R', 'I', 'O', 'D', 'I', + 'C', '_', 'A', 'D', 'V' }; -uint8_t addr_2m[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x02}; +uint8_t addr_2m[6] = { 0xc0, 0xde, 0x52, 0x00, 0x00, 0x02 }; -BLEMultiAdvertising advert(1); // max number of advertisement data +BLEMultiAdvertising advert(1); // max number of advertisement data void setup() { Serial.begin(115200); @@ -76,4 +76,4 @@ void setup() { void loop() { delay(2000); } -#endif \ No newline at end of file +#endif diff --git a/libraries/BLE/examples/BLE5_periodic_sync/BLE5_periodic_sync.ino b/libraries/BLE/examples/BLE5_periodic_sync/BLE5_periodic_sync.ino index 6be284e2480..795049364d6 100644 --- a/libraries/BLE/examples/BLE5_periodic_sync/BLE5_periodic_sync.ino +++ b/libraries/BLE/examples/BLE5_periodic_sync/BLE5_periodic_sync.ino @@ -18,25 +18,22 @@ BLEScan *pBLEScan; static bool periodic_sync = false; static esp_ble_gap_periodic_adv_sync_params_t periodic_adv_sync_params = { - .filter_policy = 0, - .sid = 0, - .addr_type = BLE_ADDR_TYPE_RANDOM, - .addr = {0,0,0,0,0,0}, - .skip = 10, - .sync_timeout = 1000, // timeout: 1000 * 10ms + .filter_policy = 0, + .sid = 0, + .addr_type = BLE_ADDR_TYPE_RANDOM, + .addr = { 0, 0, 0, 0, 0, 0 }, + .skip = 10, + .sync_timeout = 1000, // timeout: 1000 * 10ms }; -class MyBLEExtAdvertisingCallbacks : public BLEExtAdvertisingCallbacks -{ - void onResult(esp_ble_gap_ext_adv_report_t params) - { +class MyBLEExtAdvertisingCallbacks : public BLEExtAdvertisingCallbacks { + void onResult(esp_ble_gap_ext_adv_report_t params) { uint8_t *adv_name = NULL; uint8_t adv_name_len = 0; adv_name = esp_ble_resolve_adv_data(params.adv_data, ESP_BLE_AD_TYPE_NAME_CMPL, &adv_name_len); - if ((adv_name != NULL) && (memcmp(adv_name, "ESP_MULTI_ADV_2M", adv_name_len) == 0) && !periodic_sync) - { + if ((adv_name != NULL) && (memcmp(adv_name, "ESP_MULTI_ADV_2M", adv_name_len) == 0) && !periodic_sync) { periodic_sync = true; - char adv_temp_name[60] = {'0'}; + char adv_temp_name[60] = { '0' }; memcpy(adv_temp_name, adv_name, adv_name_len); log_i("Start create sync with the peer device %s", adv_temp_name); periodic_adv_sync_params.sid = params.sid; @@ -47,27 +44,23 @@ class MyBLEExtAdvertisingCallbacks : public BLEExtAdvertisingCallbacks } }; -class MyPeriodicScan : public BLEPeriodicScanCallbacks -{ +class MyPeriodicScan : public BLEPeriodicScanCallbacks { // void onCreateSync(esp_bt_status_t status){} // void onCancelSync(esp_bt_status_t status){} // void onTerminateSync(esp_bt_status_t status){} - void onStop(esp_bt_status_t status) - { + void onStop(esp_bt_status_t status) { log_i("ESP_GAP_BLE_EXT_SCAN_STOP_COMPLETE_EVT"); periodic_sync = false; - pBLEScan->startExtScan(0, 0); // scan duration in n * 10ms, period - repeat after n seconds (period >= duration) + pBLEScan->startExtScan(0, 0); // scan duration in n * 10ms, period - repeat after n seconds (period >= duration) } - void onLostSync(uint16_t sync_handle) - { + void onLostSync(uint16_t sync_handle) { log_i("ESP_GAP_BLE_PERIODIC_ADV_SYNC_LOST_EVT"); esp_ble_gap_stop_ext_scan(); } - void onSync(esp_ble_periodic_adv_sync_estab_param_t params) - { + void onSync(esp_ble_periodic_adv_sync_estab_param_t params) { log_i("ESP_GAP_BLE_PERIODIC_ADV_SYNC_ESTAB_EVT, status %d", params.status); // esp_log_buffer_hex("sync addr", param->periodic_adv_sync_estab.adv_addr, 6); log_i("sync handle %d sid %d perioic adv interval %d adv phy %d", params.sync_handle, @@ -76,8 +69,7 @@ class MyPeriodicScan : public BLEPeriodicScanCallbacks params.adv_phy); } - void onReport(esp_ble_gap_periodic_adv_report_t params) - { + void onReport(esp_ble_gap_periodic_adv_report_t params) { log_i("periodic adv report, sync handle %d data status %d data len %d rssi %d", params.sync_handle, params.data_status, params.data_length, @@ -85,24 +77,21 @@ class MyPeriodicScan : public BLEPeriodicScanCallbacks } }; -void setup() -{ +void setup() { Serial.begin(115200); Serial.println("Periodic scan..."); BLEDevice::init(""); - pBLEScan = BLEDevice::getScan(); //create new scan + pBLEScan = BLEDevice::getScan(); //create new scan pBLEScan->setExtendedScanCallback(new MyBLEExtAdvertisingCallbacks()); - pBLEScan->setExtScanParams(); // use with pre-defined/default values, overloaded function allows to pass parameters + pBLEScan->setExtScanParams(); // use with pre-defined/default values, overloaded function allows to pass parameters pBLEScan->setPeriodicScanCallback(new MyPeriodicScan()); - delay(100); // it is just for simplicity this example, to let ble stack to set extended scan params + delay(100); // it is just for simplicity this example, to let ble stack to set extended scan params pBLEScan->startExtScan(0, 0); - } -void loop() -{ +void loop() { delay(2000); } -#endif // SOC_BLE_50_SUPPORTED +#endif // SOC_BLE_50_SUPPORTED diff --git a/libraries/BLE/examples/Beacon_Scanner/Beacon_Scanner.ino b/libraries/BLE/examples/Beacon_Scanner/Beacon_Scanner.ino index 71864fb845c..54cd5a20ee5 100644 --- a/libraries/BLE/examples/Beacon_Scanner/Beacon_Scanner.ino +++ b/libraries/BLE/examples/Beacon_Scanner/Beacon_Scanner.ino @@ -15,106 +15,93 @@ #include #include -int scanTime = 5; //In seconds +int scanTime = 5; //In seconds BLEScan *pBLEScan; -class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks -{ - void onResult(BLEAdvertisedDevice advertisedDevice) - { - if (advertisedDevice.haveName()) - { - Serial.print("Device name: "); - Serial.println(advertisedDevice.getName().c_str()); - Serial.println(""); - } +class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks { + void onResult(BLEAdvertisedDevice advertisedDevice) { + if (advertisedDevice.haveName()) { + Serial.print("Device name: "); + Serial.println(advertisedDevice.getName().c_str()); + Serial.println(""); + } - if (advertisedDevice.haveServiceUUID()) - { - BLEUUID devUUID = advertisedDevice.getServiceUUID(); - Serial.print("Found ServiceUUID: "); - Serial.println(devUUID.toString().c_str()); - Serial.println(""); - } - - if (advertisedDevice.haveManufacturerData() == true) - { - String strManufacturerData = advertisedDevice.getManufacturerData(); + if (advertisedDevice.haveServiceUUID()) { + BLEUUID devUUID = advertisedDevice.getServiceUUID(); + Serial.print("Found ServiceUUID: "); + Serial.println(devUUID.toString().c_str()); + Serial.println(""); + } - uint8_t cManufacturerData[100]; - memcpy(cManufacturerData, strManufacturerData.c_str(), strManufacturerData.length()); + if (advertisedDevice.haveManufacturerData() == true) { + String strManufacturerData = advertisedDevice.getManufacturerData(); - if (strManufacturerData.length() == 25 && cManufacturerData[0] == 0x4C && cManufacturerData[1] == 0x00) - { - Serial.println("Found an iBeacon!"); - BLEBeacon oBeacon = BLEBeacon(); - oBeacon.setData(strManufacturerData); - Serial.printf("iBeacon Frame\n"); - Serial.printf("ID: %04X Major: %d Minor: %d UUID: %s Power: %d\n", oBeacon.getManufacturerId(), ENDIAN_CHANGE_U16(oBeacon.getMajor()), ENDIAN_CHANGE_U16(oBeacon.getMinor()), oBeacon.getProximityUUID().toString().c_str(), oBeacon.getSignalPower()); - } - else - { - Serial.println("Found another manufacturers beacon!"); - Serial.printf("strManufacturerData: %d ", strManufacturerData.length()); - for (int i = 0; i < strManufacturerData.length(); i++) - { - Serial.printf("[%X]", cManufacturerData[i]); - } - Serial.printf("\n"); - } - } + uint8_t cManufacturerData[100]; + memcpy(cManufacturerData, strManufacturerData.c_str(), strManufacturerData.length()); - if (advertisedDevice.getFrameType() == BLE_EDDYSTONE_URL_FRAME) - { - Serial.println("Found an EddystoneURL beacon!"); - BLEEddystoneURL EddystoneURL = BLEEddystoneURL(&advertisedDevice); - Serial.printf("URL bytes: 0x"); - String url = EddystoneURL.getURL(); - for(auto byte : url){ - Serial.printf("%02X", byte); + if (strManufacturerData.length() == 25 && cManufacturerData[0] == 0x4C && cManufacturerData[1] == 0x00) { + Serial.println("Found an iBeacon!"); + BLEBeacon oBeacon = BLEBeacon(); + oBeacon.setData(strManufacturerData); + Serial.printf("iBeacon Frame\n"); + Serial.printf("ID: %04X Major: %d Minor: %d UUID: %s Power: %d\n", oBeacon.getManufacturerId(), ENDIAN_CHANGE_U16(oBeacon.getMajor()), ENDIAN_CHANGE_U16(oBeacon.getMinor()), oBeacon.getProximityUUID().toString().c_str(), oBeacon.getSignalPower()); + } else { + Serial.println("Found another manufacturers beacon!"); + Serial.printf("strManufacturerData: %d ", strManufacturerData.length()); + for (int i = 0; i < strManufacturerData.length(); i++) { + Serial.printf("[%X]", cManufacturerData[i]); } Serial.printf("\n"); - Serial.printf("Decoded URL: %s\n", EddystoneURL.getDecodedURL().c_str()); - Serial.printf("EddystoneURL.getDecodedURL(): %s\n", EddystoneURL.getDecodedURL().c_str()); - Serial.printf("TX power %d (Raw 0x%02X)\n", EddystoneURL.getPower(), EddystoneURL.getPower()); - Serial.println("\n"); } + } - if (advertisedDevice.getFrameType() == BLE_EDDYSTONE_TLM_FRAME) - { - Serial.println("Found an EddystoneTLM beacon!"); - BLEEddystoneTLM EddystoneTLM(&advertisedDevice); - Serial.printf("Reported battery voltage: %dmV\n", EddystoneTLM.getVolt()); - Serial.printf("Reported temperature: %.2f°C (raw data=0x%04X)\n", EddystoneTLM.getTemp(), EddystoneTLM.getRawTemp()); - Serial.printf("Reported advertise count: %lu\n", EddystoneTLM.getCount()); - Serial.printf("Reported time since last reboot: %lus\n", EddystoneTLM.getTime()); - Serial.println("\n"); - Serial.print(EddystoneTLM.toString().c_str()); - Serial.println("\n"); - } + if (advertisedDevice.getFrameType() == BLE_EDDYSTONE_URL_FRAME) { + Serial.println("Found an EddystoneURL beacon!"); + BLEEddystoneURL EddystoneURL = BLEEddystoneURL(&advertisedDevice); + Serial.printf("URL bytes: 0x"); + String url = EddystoneURL.getURL(); + for (auto byte : url) { + Serial.printf("%02X", byte); + } + Serial.printf("\n"); + Serial.printf("Decoded URL: %s\n", EddystoneURL.getDecodedURL().c_str()); + Serial.printf("EddystoneURL.getDecodedURL(): %s\n", EddystoneURL.getDecodedURL().c_str()); + Serial.printf("TX power %d (Raw 0x%02X)\n", EddystoneURL.getPower(), EddystoneURL.getPower()); + Serial.println("\n"); + } + + if (advertisedDevice.getFrameType() == BLE_EDDYSTONE_TLM_FRAME) { + Serial.println("Found an EddystoneTLM beacon!"); + BLEEddystoneTLM EddystoneTLM(&advertisedDevice); + Serial.printf("Reported battery voltage: %dmV\n", EddystoneTLM.getVolt()); + Serial.printf("Reported temperature: %.2f°C (raw data=0x%04X)\n", EddystoneTLM.getTemp(), EddystoneTLM.getRawTemp()); + Serial.printf("Reported advertise count: %lu\n", EddystoneTLM.getCount()); + Serial.printf("Reported time since last reboot: %lus\n", EddystoneTLM.getTime()); + Serial.println("\n"); + Serial.print(EddystoneTLM.toString().c_str()); + Serial.println("\n"); } + } }; -void setup() -{ +void setup() { Serial.begin(115200); Serial.println("Scanning..."); BLEDevice::init(""); - pBLEScan = BLEDevice::getScan(); //create new scan + pBLEScan = BLEDevice::getScan(); //create new scan pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); - pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster + pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster pBLEScan->setInterval(100); - pBLEScan->setWindow(99); // less or equal setInterval value + pBLEScan->setWindow(99); // less or equal setInterval value } -void loop() -{ +void loop() { // put your main code here, to run repeatedly: BLEScanResults *foundDevices = pBLEScan->start(scanTime, false); Serial.print("Devices found: "); Serial.println(foundDevices->getCount()); Serial.println("Scan done!"); - pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory + pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory delay(2000); } diff --git a/libraries/BLE/examples/Beacon_Scanner/Beacon_Scanner.md b/libraries/BLE/examples/Beacon_Scanner/Beacon_Scanner.md index 558c3e7aec0..34101fe82b7 100644 --- a/libraries/BLE/examples/Beacon_Scanner/Beacon_Scanner.md +++ b/libraries/BLE/examples/Beacon_Scanner/Beacon_Scanner.md @@ -1,9 +1,9 @@ ## BLE Beacon Scanner Initiates a BLE device scan. -Checks if the discovered devices are +Checks if the discovered devices are - an iBeacon - an Eddystone TLM beacon - an Eddystone URL beacon -and sends the decoded beacon information over Serial log \ No newline at end of file +and sends the decoded beacon information over Serial log diff --git a/libraries/BLE/examples/Client/Client.ino b/libraries/BLE/examples/Client/Client.ino index 5d7f5d5c57a..ff6852d14ac 100644 --- a/libraries/BLE/examples/Client/Client.ino +++ b/libraries/BLE/examples/Client/Client.ino @@ -11,7 +11,7 @@ // The remote service we wish to connect to. static BLEUUID serviceUUID("4fafc201-1fb5-459e-8fcc-c5c9c331914b"); // The characteristic of the remote service we are interested in. -static BLEUUID charUUID("beb5483e-36e1-4688-b7f5-ea07361b26a8"); +static BLEUUID charUUID("beb5483e-36e1-4688-b7f5-ea07361b26a8"); static boolean doConnect = false; static boolean connected = false; @@ -24,13 +24,13 @@ static void notifyCallback( uint8_t* pData, size_t length, bool isNotify) { - Serial.print("Notify callback for characteristic "); - Serial.print(pBLERemoteCharacteristic->getUUID().toString().c_str()); - Serial.print(" of data length "); - Serial.println(length); - Serial.print("data: "); - Serial.write(pData, length); - Serial.println(); + Serial.print("Notify callback for characteristic "); + Serial.print(pBLERemoteCharacteristic->getUUID().toString().c_str()); + Serial.print(" of data length "); + Serial.println(length); + Serial.print("data: "); + Serial.write(pData, length); + Serial.println(); } class MyClientCallback : public BLEClientCallbacks { @@ -44,58 +44,58 @@ class MyClientCallback : public BLEClientCallbacks { }; bool connectToServer() { - Serial.print("Forming a connection to "); - Serial.println(myDevice->getAddress().toString().c_str()); - - BLEClient* pClient = BLEDevice::createClient(); - Serial.println(" - Created client"); - - pClient->setClientCallbacks(new MyClientCallback()); - - // Connect to the remove BLE Server. - pClient->connect(myDevice); // if you pass BLEAdvertisedDevice instead of address, it will be recognized type of peer device address (public or private) - Serial.println(" - Connected to server"); - pClient->setMTU(517); //set client to request maximum MTU from server (default is 23 otherwise) - - // Obtain a reference to the service we are after in the remote BLE server. - BLERemoteService* pRemoteService = pClient->getService(serviceUUID); - if (pRemoteService == nullptr) { - Serial.print("Failed to find our service UUID: "); - Serial.println(serviceUUID.toString().c_str()); - pClient->disconnect(); - return false; - } - Serial.println(" - Found our service"); + Serial.print("Forming a connection to "); + Serial.println(myDevice->getAddress().toString().c_str()); + + BLEClient* pClient = BLEDevice::createClient(); + Serial.println(" - Created client"); + + pClient->setClientCallbacks(new MyClientCallback()); + + // Connect to the remove BLE Server. + pClient->connect(myDevice); // if you pass BLEAdvertisedDevice instead of address, it will be recognized type of peer device address (public or private) + Serial.println(" - Connected to server"); + pClient->setMTU(517); //set client to request maximum MTU from server (default is 23 otherwise) + + // Obtain a reference to the service we are after in the remote BLE server. + BLERemoteService* pRemoteService = pClient->getService(serviceUUID); + if (pRemoteService == nullptr) { + Serial.print("Failed to find our service UUID: "); + Serial.println(serviceUUID.toString().c_str()); + pClient->disconnect(); + return false; + } + Serial.println(" - Found our service"); - // Obtain a reference to the characteristic in the service of the remote BLE server. - pRemoteCharacteristic = pRemoteService->getCharacteristic(charUUID); - if (pRemoteCharacteristic == nullptr) { - Serial.print("Failed to find our characteristic UUID: "); - Serial.println(charUUID.toString().c_str()); - pClient->disconnect(); - return false; - } - Serial.println(" - Found our characteristic"); + // Obtain a reference to the characteristic in the service of the remote BLE server. + pRemoteCharacteristic = pRemoteService->getCharacteristic(charUUID); + if (pRemoteCharacteristic == nullptr) { + Serial.print("Failed to find our characteristic UUID: "); + Serial.println(charUUID.toString().c_str()); + pClient->disconnect(); + return false; + } + Serial.println(" - Found our characteristic"); - // Read the value of the characteristic. - if(pRemoteCharacteristic->canRead()) { - String value = pRemoteCharacteristic->readValue(); - Serial.print("The characteristic value was: "); - Serial.println(value.c_str()); - } + // Read the value of the characteristic. + if (pRemoteCharacteristic->canRead()) { + String value = pRemoteCharacteristic->readValue(); + Serial.print("The characteristic value was: "); + Serial.println(value.c_str()); + } - if(pRemoteCharacteristic->canNotify()) - pRemoteCharacteristic->registerForNotify(notifyCallback); + if (pRemoteCharacteristic->canNotify()) + pRemoteCharacteristic->registerForNotify(notifyCallback); - connected = true; - return true; + connected = true; + return true; } /** * Scan for BLE servers and find the first one that advertises the service we are looking for. */ -class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { - /** +class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks { + /** * Called for each advertising BLE server. */ void onResult(BLEAdvertisedDevice advertisedDevice) { @@ -110,9 +110,9 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { doConnect = true; doScan = true; - } // Found our server - } // onResult -}; // MyAdvertisedDeviceCallbacks + } // Found our server + } // onResult +}; // MyAdvertisedDeviceCallbacks void setup() { @@ -129,20 +129,20 @@ void setup() { pBLEScan->setWindow(449); pBLEScan->setActiveScan(true); pBLEScan->start(5, false); -} // End of setup. +} // End of setup. // This is the Arduino main loop function. void loop() { // If the flag "doConnect" is true then we have scanned for and found the desired - // BLE Server with which we wish to connect. Now we connect to it. Once we are + // BLE Server with which we wish to connect. Now we connect to it. Once we are // connected we set the connected flag to be true. if (doConnect == true) { if (connectToServer()) { Serial.println("We are now connected to the BLE Server."); } else { - Serial.println("We have failed to connect to the server; there is nothin more we will do."); + Serial.println("We have failed to connect to the server; there is nothing more we will do."); } doConnect = false; } @@ -150,14 +150,14 @@ void loop() { // If we are connected to a peer BLE Server, update the characteristic each time we are reached // with the current time since boot. if (connected) { - String newValue = "Time since boot: " + String(millis()/1000); + String newValue = "Time since boot: " + String(millis() / 1000); Serial.println("Setting new characteristic value to \"" + newValue + "\""); - + // Set the characteristic's value to be the array of bytes that is actually a string. pRemoteCharacteristic->writeValue(newValue.c_str(), newValue.length()); - }else if(doScan){ + } else if (doScan) { BLEDevice::getScan()->start(0); // this is just example to start scan after disconnect, most likely there is better way to do it in arduino } - - delay(1000); // Delay a second between loops. -} // End of loop + + delay(1000); // Delay a second between loops. +} // End of loop diff --git a/libraries/BLE/examples/EddystoneTLM_Beacon/EddystoneTLM_Beacon.ino b/libraries/BLE/examples/EddystoneTLM_Beacon/EddystoneTLM_Beacon.ino index c608133c7d1..dc8eadd9288 100644 --- a/libraries/BLE/examples/EddystoneTLM_Beacon/EddystoneTLM_Beacon.ino +++ b/libraries/BLE/examples/EddystoneTLM_Beacon/EddystoneTLM_Beacon.ino @@ -12,7 +12,7 @@ 4. wait 5. Stop advertising. 6. deep sleep - + To read data advertised by this beacon use second ESP with example sketch BLE_Beacon_Scanner */ #include "sys/time.h" @@ -27,10 +27,10 @@ #include "esp_sleep.h" -#define GPIO_DEEP_SLEEP_DURATION 10 // sleep x seconds and then wake up +#define GPIO_DEEP_SLEEP_DURATION 10 // sleep x seconds and then wake up #define BEACON_POWER ESP_PWR_LVL_N12 -RTC_DATA_ATTR static time_t last; // remember last boot in RTC Memory -RTC_DATA_ATTR static uint32_t bootcount; // remember number of boots in RTC Memory +RTC_DATA_ATTR static time_t last; // remember last boot in RTC Memory +RTC_DATA_ATTR static uint32_t bootcount; // remember number of boots in RTC Memory // See the following for generating UUIDs: // https://www.uuidgenerator.net/ @@ -39,17 +39,16 @@ struct timeval nowTimeStruct; time_t lastTenth; -#define BEACON_UUID "8ec76ea3-6668-48da-9866-75be8bc86f4d" // UUID 1 128-Bit (may use linux tool uuidgen or random numbers via https://www.uuidgenerator.net/) +#define BEACON_UUID "8ec76ea3-6668-48da-9866-75be8bc86f4d" // UUID 1 128-Bit (may use linux tool uuidgen or random numbers via https://www.uuidgenerator.net/) // Check // https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md // and http://www.hugi.scene.org/online/coding/hugi%2015%20-%20cmtadfix.htm // for the temperature value. It is a 8.8 fixed-point notation -void setBeacon() -{ +void setBeacon() { BLEEddystoneTLM EddystoneTLM; - EddystoneTLM.setVolt((uint16_t)random(2800, 3700)); // 3300mV = 3.3V - EddystoneTLM.setTemp(random(-3000, 3000) / 100.0f); // 3000 = 30.00 ˚C + EddystoneTLM.setVolt((uint16_t)random(2800, 3700)); // 3300mV = 3.3V + EddystoneTLM.setTemp(random(-3000, 3000) / 100.0f); // 3000 = 30.00 ˚C Serial.printf("Random Battery voltage is %d mV = 0x%04X\n", EddystoneTLM.getVolt(), EddystoneTLM.getVolt()); Serial.printf("Random temperature is %.2f°C\n", EddystoneTLM.getTemp()); Serial.printf("Converted to 8.8 format: 0x%04X\n", EddystoneTLM.getRawTemp()); @@ -63,8 +62,7 @@ void setBeacon() pAdvertising->setScanResponseData(oScanResponseData); } -void setup() -{ +void setup() { Serial.begin(115200); gettimeofday(&nowTimeStruct, NULL); @@ -72,7 +70,7 @@ void setup() Serial.printf("Deep sleep (%llds since last reset, %llds since last boot)\n", nowTimeStruct.tv_sec, nowTimeStruct.tv_sec - last); last = nowTimeStruct.tv_sec; - lastTenth = nowTimeStruct.tv_sec * 10; // Time since last reset as 0.1 second resolution counter + lastTenth = nowTimeStruct.tv_sec * 10; // Time since last reset as 0.1 second resolution counter // Create the BLE Device BLEDevice::init("TLMBeacon"); @@ -91,6 +89,5 @@ void setup() esp_deep_sleep(1000000LL * GPIO_DEEP_SLEEP_DURATION); } -void loop() -{ +void loop() { } diff --git a/libraries/BLE/examples/EddystoneURL_Beacon/EddystoneURL_Beacon.ino b/libraries/BLE/examples/EddystoneURL_Beacon/EddystoneURL_Beacon.ino index d2d9b2d25d2..a5805a5ed50 100644 --- a/libraries/BLE/examples/EddystoneURL_Beacon/EddystoneURL_Beacon.ino +++ b/libraries/BLE/examples/EddystoneURL_Beacon/EddystoneURL_Beacon.ino @@ -28,53 +28,51 @@ #include "BLEEddystoneURL.h" #include "esp_sleep.h" -char unprintable[] = {0x01, 0xFF, 0xDE, 0xAD}; +char unprintable[] = { 0x01, 0xFF, 0xDE, 0xAD }; String URL[] = { - "http://www.espressif.com/", // prefix 0x00, suffix 0x00 - "https://www.texas.gov", // prefix 0x01, suffix 0x0D - "http://en.mapy.cz", // prefix 0x02, no valid suffix - "https://arduino.cc", // prefix 0x03, no valid suffix - "google.com", // URL without specified prefix - the function will assume default prefix "http://www." = 0x00 - "diginfo.tv", // URL without specified prefix - the function will assume default prefix "http://www." = 0x00 -// "http://www.URLsAbove17BytesAreNotAllowed.com", // Too long URL - setSmartURL() will return 0 = ERR -// "", // Empty string - setSmartURL() will return 0 = ERR -// String(unprintable), // Unprintable characters / corrupted String - setSmartURL() will return 0 = ERR + "http://www.espressif.com/", // prefix 0x00, suffix 0x00 + "https://www.texas.gov", // prefix 0x01, suffix 0x0D + "http://en.mapy.cz", // prefix 0x02, no valid suffix + "https://arduino.cc", // prefix 0x03, no valid suffix + "google.com", // URL without specified prefix - the function will assume default prefix "http://www." = 0x00 + "diginfo.tv", // URL without specified prefix - the function will assume default prefix "http://www." = 0x00 + // "http://www.URLsAbove17BytesAreNotAllowed.com", // Too long URL - setSmartURL() will return 0 = ERR + // "", // Empty string - setSmartURL() will return 0 = ERR + // String(unprintable), // Unprintable characters / corrupted String - setSmartURL() will return 0 = ERR }; -#define GPIO_DEEP_SLEEP_DURATION 10 // sleep x seconds and then wake up +#define GPIO_DEEP_SLEEP_DURATION 10 // sleep x seconds and then wake up #define BEACON_POWER ESP_PWR_LVL_N12 -RTC_DATA_ATTR static time_t last; // remember last boot in RTC Memory -RTC_DATA_ATTR static uint32_t bootcount; // remember number of boots in RTC Memory +RTC_DATA_ATTR static time_t last; // remember last boot in RTC Memory +RTC_DATA_ATTR static uint32_t bootcount; // remember number of boots in RTC Memory // See the following for generating UUIDs: // https://www.uuidgenerator.net/ BLEAdvertising *pAdvertising; struct timeval now; -int setBeacon() -{ +int setBeacon() { BLEAdvertisementData oAdvertisementData = BLEAdvertisementData(); BLEAdvertisementData oScanResponseData = BLEAdvertisementData(); BLEEddystoneURL EddystoneURL; - EddystoneURL.setPower(BEACON_POWER); // This is only information about the power. The actual power is set by `BLEDevice::setPower(BEACON_POWER)` - if(EddystoneURL.setSmartURL(URL[bootcount%(sizeof(URL)/sizeof(URL[0]))])){ + EddystoneURL.setPower(BEACON_POWER); // This is only information about the power. The actual power is set by `BLEDevice::setPower(BEACON_POWER)` + if (EddystoneURL.setSmartURL(URL[bootcount % (sizeof(URL) / sizeof(URL[0]))])) { String frame = EddystoneURL.getFrame(); String data(EddystoneURL.getFrame().c_str(), frame.length()); oAdvertisementData.addData(data); oScanResponseData.setName("ESP32 URLBeacon"); pAdvertising->setAdvertisementData(oAdvertisementData); pAdvertising->setScanResponseData(oScanResponseData); - Serial.printf("Advertise URL \"%s\"\n", URL[bootcount%(sizeof(URL)/sizeof(URL[0]))].c_str()); - return 1; // OK - }else{ + Serial.printf("Advertise URL \"%s\"\n", URL[bootcount % (sizeof(URL) / sizeof(URL[0]))].c_str()); + return 1; // OK + } else { Serial.println("Smart URL set ERR"); - return 0; // ERR + return 0; // ERR } } -void setup() -{ +void setup() { Serial.begin(115200); gettimeofday(&now, NULL); @@ -92,7 +90,7 @@ void setup() pAdvertising = BLEDevice::getAdvertising(); - if(setBeacon()){ + if (setBeacon()) { // Start advertising pAdvertising->start(); Serial.println("Advertising started..."); @@ -104,6 +102,5 @@ void setup() esp_deep_sleep(1000000LL * GPIO_DEEP_SLEEP_DURATION); } -void loop() -{ +void loop() { } diff --git a/libraries/BLE/examples/Notify/Notify.ino b/libraries/BLE/examples/Notify/Notify.ino index 42b9e7273f3..59cc8f3cf20 100644 --- a/libraries/BLE/examples/Notify/Notify.ino +++ b/libraries/BLE/examples/Notify/Notify.ino @@ -16,7 +16,7 @@ 5. Start the service. 6. Start advertising. - A connect hander associated with the server starts a background task that performs notification + A connect handler associated with the server starts a background task that performs notification every couple of seconds. */ #include @@ -33,18 +33,18 @@ uint32_t value = 0; // See the following for generating UUIDs: // https://www.uuidgenerator.net/ -#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" +#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" -class MyServerCallbacks: public BLEServerCallbacks { - void onConnect(BLEServer* pServer) { - deviceConnected = true; - }; +class MyServerCallbacks : public BLEServerCallbacks { + void onConnect(BLEServer* pServer) { + deviceConnected = true; + }; - void onDisconnect(BLEServer* pServer) { - deviceConnected = false; - } + void onDisconnect(BLEServer* pServer) { + deviceConnected = false; + } }; @@ -60,16 +60,12 @@ void setup() { pServer->setCallbacks(new MyServerCallbacks()); // Create the BLE Service - BLEService *pService = pServer->createService(SERVICE_UUID); + BLEService* pService = pServer->createService(SERVICE_UUID); // Create a BLE Characteristic pCharacteristic = pService->createCharacteristic( - CHARACTERISTIC_UUID, - BLECharacteristic::PROPERTY_READ | - BLECharacteristic::PROPERTY_WRITE | - BLECharacteristic::PROPERTY_NOTIFY | - BLECharacteristic::PROPERTY_INDICATE - ); + CHARACTERISTIC_UUID, + BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE); // https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml // Create a BLE Descriptor @@ -79,7 +75,7 @@ void setup() { pService->start(); // Start advertising - BLEAdvertising *pAdvertising = BLEDevice::getAdvertising(); + BLEAdvertising* pAdvertising = BLEDevice::getAdvertising(); pAdvertising->addServiceUUID(SERVICE_UUID); pAdvertising->setScanResponse(false); pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter @@ -88,23 +84,23 @@ void setup() { } void loop() { - // notify changed value - if (deviceConnected) { - pCharacteristic->setValue((uint8_t*)&value, 4); - pCharacteristic->notify(); - value++; - delay(3); // bluetooth stack will go into congestion, if too many packets are sent, in 6 hours test i was able to go as low as 3ms - } - // disconnecting - if (!deviceConnected && oldDeviceConnected) { - delay(500); // give the bluetooth stack the chance to get things ready - pServer->startAdvertising(); // restart advertising - Serial.println("start advertising"); - oldDeviceConnected = deviceConnected; - } - // connecting - if (deviceConnected && !oldDeviceConnected) { - // do stuff here on connecting - oldDeviceConnected = deviceConnected; - } -} \ No newline at end of file + // notify changed value + if (deviceConnected) { + pCharacteristic->setValue((uint8_t*)&value, 4); + pCharacteristic->notify(); + value++; + delay(3); // bluetooth stack will go into congestion, if too many packets are sent, in 6 hours test i was able to go as low as 3ms + } + // disconnecting + if (!deviceConnected && oldDeviceConnected) { + delay(500); // give the bluetooth stack the chance to get things ready + pServer->startAdvertising(); // restart advertising + Serial.println("start advertising"); + oldDeviceConnected = deviceConnected; + } + // connecting + if (deviceConnected && !oldDeviceConnected) { + // do stuff here on connecting + oldDeviceConnected = deviceConnected; + } +} diff --git a/libraries/BLE/examples/Scan/Scan.ino b/libraries/BLE/examples/Scan/Scan.ino index fee31b76da9..b9f7eb11690 100644 --- a/libraries/BLE/examples/Scan/Scan.ino +++ b/libraries/BLE/examples/Scan/Scan.ino @@ -8,13 +8,13 @@ #include #include -int scanTime = 5; //In seconds +int scanTime = 5; //In seconds BLEScan* pBLEScan; -class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { - void onResult(BLEAdvertisedDevice advertisedDevice) { - Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str()); - } +class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks { + void onResult(BLEAdvertisedDevice advertisedDevice) { + Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str()); + } }; void setup() { @@ -22,19 +22,19 @@ void setup() { Serial.println("Scanning..."); BLEDevice::init(""); - pBLEScan = BLEDevice::getScan(); //create new scan + pBLEScan = BLEDevice::getScan(); //create new scan pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); - pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster + pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster pBLEScan->setInterval(100); pBLEScan->setWindow(99); // less or equal setInterval value } void loop() { // put your main code here, to run repeatedly: - BLEScanResults *foundDevices = pBLEScan->start(scanTime, false); + BLEScanResults* foundDevices = pBLEScan->start(scanTime, false); Serial.print("Devices found: "); Serial.println(foundDevices->getCount()); Serial.println("Scan done!"); - pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory + pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory delay(2000); -} \ No newline at end of file +} diff --git a/libraries/BLE/examples/Server/Server.ino b/libraries/BLE/examples/Server/Server.ino index 3f9176acf5e..952be38542d 100644 --- a/libraries/BLE/examples/Server/Server.ino +++ b/libraries/BLE/examples/Server/Server.ino @@ -11,7 +11,7 @@ // See the following for generating UUIDs: // https://www.uuidgenerator.net/ -#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" +#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setup() { @@ -22,10 +22,8 @@ void setup() { BLEServer *pServer = BLEDevice::createServer(); BLEService *pService = pServer->createService(SERVICE_UUID); BLECharacteristic *pCharacteristic = pService->createCharacteristic( - CHARACTERISTIC_UUID, - BLECharacteristic::PROPERTY_READ | - BLECharacteristic::PROPERTY_WRITE - ); + CHARACTERISTIC_UUID, + BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE); pCharacteristic->setValue("Hello World says Neil"); pService->start(); @@ -42,4 +40,4 @@ void setup() { void loop() { // put your main code here, to run repeatedly: delay(2000); -} \ No newline at end of file +} diff --git a/libraries/BLE/examples/Server_multiconnect/Server_multiconnect.ino b/libraries/BLE/examples/Server_multiconnect/Server_multiconnect.ino index 90704ef16ad..b26f7e8fff2 100644 --- a/libraries/BLE/examples/Server_multiconnect/Server_multiconnect.ino +++ b/libraries/BLE/examples/Server_multiconnect/Server_multiconnect.ino @@ -16,7 +16,7 @@ 5. Start the service. 6. Start advertising. - A connect hander associated with the server starts a background task that performs notification + A connect handler associated with the server starts a background task that performs notification every couple of seconds. */ #include @@ -33,19 +33,19 @@ uint32_t value = 0; // See the following for generating UUIDs: // https://www.uuidgenerator.net/ -#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" +#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" -class MyServerCallbacks: public BLEServerCallbacks { - void onConnect(BLEServer* pServer) { - deviceConnected = true; - BLEDevice::startAdvertising(); - }; +class MyServerCallbacks : public BLEServerCallbacks { + void onConnect(BLEServer* pServer) { + deviceConnected = true; + BLEDevice::startAdvertising(); + }; - void onDisconnect(BLEServer* pServer) { - deviceConnected = false; - } + void onDisconnect(BLEServer* pServer) { + deviceConnected = false; + } }; @@ -61,16 +61,12 @@ void setup() { pServer->setCallbacks(new MyServerCallbacks()); // Create the BLE Service - BLEService *pService = pServer->createService(SERVICE_UUID); + BLEService* pService = pServer->createService(SERVICE_UUID); // Create a BLE Characteristic pCharacteristic = pService->createCharacteristic( - CHARACTERISTIC_UUID, - BLECharacteristic::PROPERTY_READ | - BLECharacteristic::PROPERTY_WRITE | - BLECharacteristic::PROPERTY_NOTIFY | - BLECharacteristic::PROPERTY_INDICATE - ); + CHARACTERISTIC_UUID, + BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE); // https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml // Create a BLE Descriptor @@ -80,7 +76,7 @@ void setup() { pService->start(); // Start advertising - BLEAdvertising *pAdvertising = BLEDevice::getAdvertising(); + BLEAdvertising* pAdvertising = BLEDevice::getAdvertising(); pAdvertising->addServiceUUID(SERVICE_UUID); pAdvertising->setScanResponse(false); pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter @@ -89,23 +85,23 @@ void setup() { } void loop() { - // notify changed value - if (deviceConnected) { - pCharacteristic->setValue((uint8_t*)&value, 4); - pCharacteristic->notify(); - value++; - delay(10); // bluetooth stack will go into congestion, if too many packets are sent, in 6 hours test i was able to go as low as 3ms - } - // disconnecting - if (!deviceConnected && oldDeviceConnected) { - delay(500); // give the bluetooth stack the chance to get things ready - pServer->startAdvertising(); // restart advertising - Serial.println("start advertising"); - oldDeviceConnected = deviceConnected; - } - // connecting - if (deviceConnected && !oldDeviceConnected) { - // do stuff here on connecting - oldDeviceConnected = deviceConnected; - } + // notify changed value + if (deviceConnected) { + pCharacteristic->setValue((uint8_t*)&value, 4); + pCharacteristic->notify(); + value++; + delay(10); // bluetooth stack will go into congestion, if too many packets are sent, in 6 hours test i was able to go as low as 3ms + } + // disconnecting + if (!deviceConnected && oldDeviceConnected) { + delay(500); // give the bluetooth stack the chance to get things ready + pServer->startAdvertising(); // restart advertising + Serial.println("start advertising"); + oldDeviceConnected = deviceConnected; + } + // connecting + if (deviceConnected && !oldDeviceConnected) { + // do stuff here on connecting + oldDeviceConnected = deviceConnected; + } } diff --git a/libraries/BLE/examples/UART/UART.ino b/libraries/BLE/examples/UART/UART.ino index 2d188fc61d0..725b45c0bfd 100644 --- a/libraries/BLE/examples/UART/UART.ino +++ b/libraries/BLE/examples/UART/UART.ino @@ -5,7 +5,7 @@ Create a BLE server that, once we receive a connection, will send periodic notifications. The service advertises itself as: 6E400001-B5A3-F393-E0A9-E50E24DCCA9E - Has a characteristic of: 6E400002-B5A3-F393-E0A9-E50E24DCCA9E - used for receiving data with "WRITE" + Has a characteristic of: 6E400002-B5A3-F393-E0A9-E50E24DCCA9E - used for receiving data with "WRITE" Has a characteristic of: 6E400003-B5A3-F393-E0A9-E50E24DCCA9E - used to send data with "NOTIFY" The design of creating the BLE server is: @@ -17,7 +17,7 @@ 6. Start advertising. In this example rxValue is the data received (only accessible inside that function). - And txValue is the data to be sent, in this example just a byte incremented every second. + And txValue is the data to be sent, in this example just a byte incremented every second. */ #include #include @@ -25,7 +25,7 @@ #include BLEServer *pServer = NULL; -BLECharacteristic * pTxCharacteristic; +BLECharacteristic *pTxCharacteristic; bool deviceConnected = false; bool oldDeviceConnected = false; uint8_t txValue = 0; @@ -33,35 +33,35 @@ uint8_t txValue = 0; // See the following for generating UUIDs: // https://www.uuidgenerator.net/ -#define SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E" // UART service UUID +#define SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E" // UART service UUID #define CHARACTERISTIC_UUID_RX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E" #define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E" -class MyServerCallbacks: public BLEServerCallbacks { - void onConnect(BLEServer* pServer) { - deviceConnected = true; - }; +class MyServerCallbacks : public BLEServerCallbacks { + void onConnect(BLEServer *pServer) { + deviceConnected = true; + }; - void onDisconnect(BLEServer* pServer) { - deviceConnected = false; - } + void onDisconnect(BLEServer *pServer) { + deviceConnected = false; + } }; -class MyCallbacks: public BLECharacteristicCallbacks { - void onWrite(BLECharacteristic *pCharacteristic) { - String rxValue = pCharacteristic->getValue(); +class MyCallbacks : public BLECharacteristicCallbacks { + void onWrite(BLECharacteristic *pCharacteristic) { + String rxValue = pCharacteristic->getValue(); - if (rxValue.length() > 0) { - Serial.println("*********"); - Serial.print("Received Value: "); - for (int i = 0; i < rxValue.length(); i++) - Serial.print(rxValue[i]); + if (rxValue.length() > 0) { + Serial.println("*********"); + Serial.print("Received Value: "); + for (int i = 0; i < rxValue.length(); i++) + Serial.print(rxValue[i]); - Serial.println(); - Serial.println("*********"); - } + Serial.println(); + Serial.println("*********"); } + } }; @@ -80,16 +80,14 @@ void setup() { // Create a BLE Characteristic pTxCharacteristic = pService->createCharacteristic( - CHARACTERISTIC_UUID_TX, - BLECharacteristic::PROPERTY_NOTIFY - ); + CHARACTERISTIC_UUID_TX, + BLECharacteristic::PROPERTY_NOTIFY); pTxCharacteristic->addDescriptor(new BLE2902()); - BLECharacteristic * pRxCharacteristic = pService->createCharacteristic( - CHARACTERISTIC_UUID_RX, - BLECharacteristic::PROPERTY_WRITE - ); + BLECharacteristic *pRxCharacteristic = pService->createCharacteristic( + CHARACTERISTIC_UUID_RX, + BLECharacteristic::PROPERTY_WRITE); pRxCharacteristic->setCallbacks(new MyCallbacks()); @@ -107,13 +105,13 @@ void loop() { pTxCharacteristic->setValue(&txValue, 1); pTxCharacteristic->notify(); txValue++; - delay(10); // bluetooth stack will go into congestion, if too many packets are sent + delay(10); // bluetooth stack will go into congestion, if too many packets are sent } // disconnecting if (!deviceConnected && oldDeviceConnected) { - delay(500); // give the bluetooth stack the chance to get things ready - pServer->startAdvertising(); // restart advertising + delay(500); // give the bluetooth stack the chance to get things ready + pServer->startAdvertising(); // restart advertising Serial.println("start advertising"); oldDeviceConnected = deviceConnected; } diff --git a/libraries/BLE/examples/Write/Write.ino b/libraries/BLE/examples/Write/Write.ino index 138bfa603ef..efad59f31b6 100644 --- a/libraries/BLE/examples/Write/Write.ino +++ b/libraries/BLE/examples/Write/Write.ino @@ -10,24 +10,24 @@ // See the following for generating UUIDs: // https://www.uuidgenerator.net/ -#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" +#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" -class MyCallbacks: public BLECharacteristicCallbacks { - void onWrite(BLECharacteristic *pCharacteristic) { - String value = pCharacteristic->getValue(); +class MyCallbacks : public BLECharacteristicCallbacks { + void onWrite(BLECharacteristic *pCharacteristic) { + String value = pCharacteristic->getValue(); - if (value.length() > 0) { - Serial.println("*********"); - Serial.print("New value: "); - for (int i = 0; i < value.length(); i++) - Serial.print(value[i]); + if (value.length() > 0) { + Serial.println("*********"); + Serial.print("New value: "); + for (int i = 0; i < value.length(); i++) + Serial.print(value[i]); - Serial.println(); - Serial.println("*********"); - } + Serial.println(); + Serial.println("*********"); } + } }; void setup() { @@ -45,10 +45,8 @@ void setup() { BLEService *pService = pServer->createService(SERVICE_UUID); BLECharacteristic *pCharacteristic = pService->createCharacteristic( - CHARACTERISTIC_UUID, - BLECharacteristic::PROPERTY_READ | - BLECharacteristic::PROPERTY_WRITE - ); + CHARACTERISTIC_UUID, + BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE); pCharacteristic->setCallbacks(new MyCallbacks()); @@ -62,4 +60,4 @@ void setup() { void loop() { // put your main code here, to run repeatedly: delay(2000); -} \ No newline at end of file +} diff --git a/libraries/BLE/examples/iBeacon/iBeacon.ino b/libraries/BLE/examples/iBeacon/iBeacon.ino index e7885269520..bc46f4f8e26 100644 --- a/libraries/BLE/examples/iBeacon/iBeacon.ino +++ b/libraries/BLE/examples/iBeacon/iBeacon.ino @@ -1,138 +1,134 @@ -/* - Based on 31337Ghost's reference code from https://github.com/nkolban/esp32-snippets/issues/385#issuecomment-362535434 - which is based on pcbreflux's Arduino ESP32 port of Neil Kolban's example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp -*/ - -/* - Create a BLE server that will send periodic iBeacon frames. - The design of creating the BLE server is: - 1. Create a BLE Server - 2. Create advertising data - 3. Start advertising. - 4. wait - 5. Stop advertising. -*/ -#include -#include -#include -#include -#include - -#define DEVICE_NAME "ESP32" -#define SERVICE_UUID "7A0247E7-8E88-409B-A959-AB5092DDB03E" -#define BEACON_UUID "2D7A9F0C-E0E8-4CC9-A71B-A21DB2D034A1" -#define BEACON_UUID_REV "A134D0B2-1DA2-1BA7-C94C-E8E00C9F7A2D" -#define CHARACTERISTIC_UUID "82258BAA-DF72-47E8-99BC-B73D7ECD08A5" - -BLEServer *pServer; -BLECharacteristic *pCharacteristic; -bool deviceConnected = false; -uint8_t value = 0; - -class MyServerCallbacks: public BLEServerCallbacks { - void onConnect(BLEServer* pServer) { - deviceConnected = true; - Serial.println("deviceConnected = true"); - }; - - void onDisconnect(BLEServer* pServer) { - deviceConnected = false; - Serial.println("deviceConnected = false"); - - // Restart advertising to be visible and connectable again - BLEAdvertising* pAdvertising; - pAdvertising = pServer->getAdvertising(); - pAdvertising->start(); - Serial.println("iBeacon advertising restarted"); - } -}; - -class MyCallbacks: public BLECharacteristicCallbacks { - void onWrite(BLECharacteristic *pCharacteristic) { - String rxValue = pCharacteristic->getValue(); - - if (rxValue.length() > 0) { - Serial.println("*********"); - Serial.print("Received Value: "); - for (int i = 0; i < rxValue.length(); i++) { - Serial.print(rxValue[i]); - } - Serial.println(); - Serial.println("*********"); - - } - } -}; - - -void init_service() { - BLEAdvertising* pAdvertising; - pAdvertising = pServer->getAdvertising(); - pAdvertising->stop(); - - // Create the BLE Service - BLEService *pService = pServer->createService(BLEUUID(SERVICE_UUID)); - - // Create a BLE Characteristic - pCharacteristic = pService->createCharacteristic( - CHARACTERISTIC_UUID, - BLECharacteristic::PROPERTY_READ | - BLECharacteristic::PROPERTY_WRITE | - BLECharacteristic::PROPERTY_NOTIFY - ); - pCharacteristic->setCallbacks(new MyCallbacks()); - pCharacteristic->addDescriptor(new BLE2902()); - - pAdvertising->addServiceUUID(BLEUUID(SERVICE_UUID)); - - // Start the service - pService->start(); - - pAdvertising->start(); -} - -void init_beacon() { - BLEAdvertising* pAdvertising; - pAdvertising = pServer->getAdvertising(); - pAdvertising->stop(); - // iBeacon - BLEBeacon myBeacon; - myBeacon.setManufacturerId(0x4c00); - myBeacon.setMajor(5); - myBeacon.setMinor(88); - myBeacon.setSignalPower(0xc5); - myBeacon.setProximityUUID(BLEUUID(BEACON_UUID_REV)); - - BLEAdvertisementData advertisementData; - advertisementData.setFlags(0x1A); - advertisementData.setManufacturerData(myBeacon.getData()); - pAdvertising->setAdvertisementData(advertisementData); - - pAdvertising->start(); -} - -void setup() { - Serial.begin(115200); - Serial.println(); - Serial.println("Initializing..."); - Serial.flush(); - - BLEDevice::init(DEVICE_NAME); - pServer = BLEDevice::createServer(); - pServer->setCallbacks(new MyServerCallbacks()); - - init_service(); - init_beacon(); - - Serial.println("iBeacon + service defined and advertising!"); -} - -void loop() { - if (deviceConnected) { - Serial.printf("*** NOTIFY: %d ***\n", value); - pCharacteristic->setValue(&value, 1); - pCharacteristic->notify(); - value++; - } - delay(2000); -} +/* + Based on 31337Ghost's reference code from https://github.com/nkolban/esp32-snippets/issues/385#issuecomment-362535434 + which is based on pcbreflux's Arduino ESP32 port of Neil Kolban's example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp +*/ + +/* + Create a BLE server that will send periodic iBeacon frames. + The design of creating the BLE server is: + 1. Create a BLE Server + 2. Create advertising data + 3. Start advertising. + 4. wait + 5. Stop advertising. +*/ +#include +#include +#include +#include +#include + +#define DEVICE_NAME "ESP32" +#define SERVICE_UUID "7A0247E7-8E88-409B-A959-AB5092DDB03E" +#define BEACON_UUID "2D7A9F0C-E0E8-4CC9-A71B-A21DB2D034A1" +#define BEACON_UUID_REV "A134D0B2-1DA2-1BA7-C94C-E8E00C9F7A2D" +#define CHARACTERISTIC_UUID "82258BAA-DF72-47E8-99BC-B73D7ECD08A5" + +BLEServer* pServer; +BLECharacteristic* pCharacteristic; +bool deviceConnected = false; +uint8_t value = 0; + +class MyServerCallbacks : public BLEServerCallbacks { + void onConnect(BLEServer* pServer) { + deviceConnected = true; + Serial.println("deviceConnected = true"); + }; + + void onDisconnect(BLEServer* pServer) { + deviceConnected = false; + Serial.println("deviceConnected = false"); + + // Restart advertising to be visible and connectable again + BLEAdvertising* pAdvertising; + pAdvertising = pServer->getAdvertising(); + pAdvertising->start(); + Serial.println("iBeacon advertising restarted"); + } +}; + +class MyCallbacks : public BLECharacteristicCallbacks { + void onWrite(BLECharacteristic* pCharacteristic) { + String rxValue = pCharacteristic->getValue(); + + if (rxValue.length() > 0) { + Serial.println("*********"); + Serial.print("Received Value: "); + for (int i = 0; i < rxValue.length(); i++) { + Serial.print(rxValue[i]); + } + Serial.println(); + Serial.println("*********"); + } + } +}; + + +void init_service() { + BLEAdvertising* pAdvertising; + pAdvertising = pServer->getAdvertising(); + pAdvertising->stop(); + + // Create the BLE Service + BLEService* pService = pServer->createService(BLEUUID(SERVICE_UUID)); + + // Create a BLE Characteristic + pCharacteristic = pService->createCharacteristic( + CHARACTERISTIC_UUID, + BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY); + pCharacteristic->setCallbacks(new MyCallbacks()); + pCharacteristic->addDescriptor(new BLE2902()); + + pAdvertising->addServiceUUID(BLEUUID(SERVICE_UUID)); + + // Start the service + pService->start(); + + pAdvertising->start(); +} + +void init_beacon() { + BLEAdvertising* pAdvertising; + pAdvertising = pServer->getAdvertising(); + pAdvertising->stop(); + // iBeacon + BLEBeacon myBeacon; + myBeacon.setManufacturerId(0x4c00); + myBeacon.setMajor(5); + myBeacon.setMinor(88); + myBeacon.setSignalPower(0xc5); + myBeacon.setProximityUUID(BLEUUID(BEACON_UUID_REV)); + + BLEAdvertisementData advertisementData; + advertisementData.setFlags(0x1A); + advertisementData.setManufacturerData(myBeacon.getData()); + pAdvertising->setAdvertisementData(advertisementData); + + pAdvertising->start(); +} + +void setup() { + Serial.begin(115200); + Serial.println(); + Serial.println("Initializing..."); + Serial.flush(); + + BLEDevice::init(DEVICE_NAME); + pServer = BLEDevice::createServer(); + pServer->setCallbacks(new MyServerCallbacks()); + + init_service(); + init_beacon(); + + Serial.println("iBeacon + service defined and advertising!"); +} + +void loop() { + if (deviceConnected) { + Serial.printf("*** NOTIFY: %d ***\n", value); + pCharacteristic->setValue(&value, 1); + pCharacteristic->notify(); + value++; + } + delay(2000); +} diff --git a/libraries/BLE/library.properties b/libraries/BLE/library.properties index 4f91de22f35..074eaa639a6 100644 --- a/libraries/BLE/library.properties +++ b/libraries/BLE/library.properties @@ -3,7 +3,7 @@ version=2.0.0 author=Neil Kolban maintainer=Dariusz Krempa sentence=BLE functions for ESP32 -paragraph=This library provides an implementation Bluetooth Low Energy support for the ESP32 using the Arduino platform. +paragraph=This library provides an implementation Bluetooth Low Energy support for the ESP32 using the Arduino platform. category=Communication url=https://github.com/nkolban/ESP32_BLE_Arduino architectures=esp32 diff --git a/libraries/BLE/src/BLE2902.cpp b/libraries/BLE/src/BLE2902.cpp index 6faa5d8d688..0aa05067e29 100644 --- a/libraries/BLE/src/BLE2902.cpp +++ b/libraries/BLE/src/BLE2902.cpp @@ -17,10 +17,11 @@ #include "BLE2902.h" -BLE2902::BLE2902() : BLEDescriptor(BLEUUID((uint16_t) 0x2902)) { - uint8_t data[2] = { 0, 0 }; - setValue(data, 2); -} // BLE2902 +BLE2902::BLE2902() + : BLEDescriptor(BLEUUID((uint16_t)0x2902)) { + uint8_t data[2] = { 0, 0 }; + setValue(data, 2); +} // BLE2902 /** @@ -28,8 +29,8 @@ BLE2902::BLE2902() : BLEDescriptor(BLEUUID((uint16_t) 0x2902)) { * @return The notifications value. True if notifications are enabled and false if not. */ bool BLE2902::getNotifications() { - return (getValue()[0] & (1 << 0)) != 0; -} // getNotifications + return (getValue()[0] & (1 << 0)) != 0; +} // getNotifications /** @@ -37,8 +38,8 @@ bool BLE2902::getNotifications() { * @return The indications value. True if indications are enabled and false if not. */ bool BLE2902::getIndications() { - return (getValue()[0] & (1 << 1)) != 0; -} // getIndications + return (getValue()[0] & (1 << 1)) != 0; +} // getIndications /** @@ -46,11 +47,11 @@ bool BLE2902::getIndications() { * @param [in] flag The indications flag. */ void BLE2902::setIndications(bool flag) { - uint8_t *pValue = getValue(); - if (flag) pValue[0] |= 1 << 1; - else pValue[0] &= ~(1 << 1); - setValue(pValue, 2); -} // setIndications + uint8_t *pValue = getValue(); + if (flag) pValue[0] |= 1 << 1; + else pValue[0] &= ~(1 << 1); + setValue(pValue, 2); +} // setIndications /** @@ -58,11 +59,11 @@ void BLE2902::setIndications(bool flag) { * @param [in] flag The notifications flag. */ void BLE2902::setNotifications(bool flag) { - uint8_t *pValue = getValue(); - if (flag) pValue[0] |= 1 << 0; - else pValue[0] &= ~(1 << 0); - setValue(pValue, 2); -} // setNotifications + uint8_t *pValue = getValue(); + if (flag) pValue[0] |= 1 << 0; + else pValue[0] &= ~(1 << 0); + setValue(pValue, 2); +} // setNotifications #endif #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLE2902.h b/libraries/BLE/src/BLE2902.h index 6218ed3ca8e..74a477f3151 100644 --- a/libraries/BLE/src/BLE2902.h +++ b/libraries/BLE/src/BLE2902.h @@ -23,15 +23,15 @@ * See also: * https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml */ -class BLE2902: public BLEDescriptor { +class BLE2902 : public BLEDescriptor { public: - BLE2902(); - bool getNotifications(); - bool getIndications(); - void setNotifications(bool flag); - void setIndications(bool flag); + BLE2902(); + bool getNotifications(); + bool getIndications(); + void setNotifications(bool flag); + void setIndications(bool flag); -}; // BLE2902 +}; // BLE2902 #endif /* CONFIG_BLUEDROID_ENABLED */ #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLE2904.cpp b/libraries/BLE/src/BLE2904.cpp index 56710212cb1..2268fafefcf 100644 --- a/libraries/BLE/src/BLE2904.cpp +++ b/libraries/BLE/src/BLE2904.cpp @@ -18,22 +18,23 @@ #include "BLE2904.h" -BLE2904::BLE2904() : BLEDescriptor(BLEUUID((uint16_t) 0x2904)) { - m_data.m_format = 0; - m_data.m_exponent = 0; - m_data.m_namespace = 1; // 1 = Bluetooth SIG Assigned Numbers - m_data.m_unit = 0; - m_data.m_description = 0; - setValue((uint8_t*) &m_data, sizeof(m_data)); -} // BLE2902 +BLE2904::BLE2904() + : BLEDescriptor(BLEUUID((uint16_t)0x2904)) { + m_data.m_format = 0; + m_data.m_exponent = 0; + m_data.m_namespace = 1; // 1 = Bluetooth SIG Assigned Numbers + m_data.m_unit = 0; + m_data.m_description = 0; + setValue((uint8_t*)&m_data, sizeof(m_data)); +} // BLE2902 /** * @brief Set the description. */ void BLE2904::setDescription(uint16_t description) { - m_data.m_description = description; - setValue((uint8_t*) &m_data, sizeof(m_data)); + m_data.m_description = description; + setValue((uint8_t*)&m_data, sizeof(m_data)); } @@ -41,27 +42,27 @@ void BLE2904::setDescription(uint16_t description) { * @brief Set the exponent. */ void BLE2904::setExponent(int8_t exponent) { - m_data.m_exponent = exponent; - setValue((uint8_t*) &m_data, sizeof(m_data)); -} // setExponent + m_data.m_exponent = exponent; + setValue((uint8_t*)&m_data, sizeof(m_data)); +} // setExponent /** * @brief Set the format. */ void BLE2904::setFormat(uint8_t format) { - m_data.m_format = format; - setValue((uint8_t*) &m_data, sizeof(m_data)); -} // setFormat + m_data.m_format = format; + setValue((uint8_t*)&m_data, sizeof(m_data)); +} // setFormat /** * @brief Set the namespace. */ void BLE2904::setNamespace(uint8_t namespace_value) { - m_data.m_namespace = namespace_value; - setValue((uint8_t*) &m_data, sizeof(m_data)); -} // setNamespace + m_data.m_namespace = namespace_value; + setValue((uint8_t*)&m_data, sizeof(m_data)); +} // setNamespace /** @@ -70,9 +71,9 @@ void BLE2904::setNamespace(uint8_t namespace_value) { * @param [in] unit The type of units of this characteristic as defined by assigned numbers. */ void BLE2904::setUnit(uint16_t unit) { - m_data.m_unit = unit; - setValue((uint8_t*) &m_data, sizeof(m_data)); -} // setUnit + m_data.m_unit = unit; + setValue((uint8_t*)&m_data, sizeof(m_data)); +} // setUnit #endif #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLE2904.h b/libraries/BLE/src/BLE2904.h index c1b9e392528..3ba66da0dc8 100644 --- a/libraries/BLE/src/BLE2904.h +++ b/libraries/BLE/src/BLE2904.h @@ -16,11 +16,11 @@ #include "BLEDescriptor.h" struct BLE2904_Data { - uint8_t m_format; - int8_t m_exponent; - uint16_t m_unit; // See https://www.bluetooth.com/specifications/assigned-numbers/units - uint8_t m_namespace; - uint16_t m_description; + uint8_t m_format; + int8_t m_exponent; + uint16_t m_unit; // See https://www.bluetooth.com/specifications/assigned-numbers/units + uint8_t m_namespace; + uint16_t m_description; } __attribute__((packed)); @@ -32,46 +32,46 @@ struct BLE2904_Data { * See also: * https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml */ -class BLE2904: public BLEDescriptor { +class BLE2904 : public BLEDescriptor { public: - BLE2904(); - static const uint8_t FORMAT_BOOLEAN = 1; - static const uint8_t FORMAT_UINT2 = 2; - static const uint8_t FORMAT_UINT4 = 3; - static const uint8_t FORMAT_UINT8 = 4; - static const uint8_t FORMAT_UINT12 = 5; - static const uint8_t FORMAT_UINT16 = 6; - static const uint8_t FORMAT_UINT24 = 7; - static const uint8_t FORMAT_UINT32 = 8; - static const uint8_t FORMAT_UINT48 = 9; - static const uint8_t FORMAT_UINT64 = 10; - static const uint8_t FORMAT_UINT128 = 11; - static const uint8_t FORMAT_SINT8 = 12; - static const uint8_t FORMAT_SINT12 = 13; - static const uint8_t FORMAT_SINT16 = 14; - static const uint8_t FORMAT_SINT24 = 15; - static const uint8_t FORMAT_SINT32 = 16; - static const uint8_t FORMAT_SINT48 = 17; - static const uint8_t FORMAT_SINT64 = 18; - static const uint8_t FORMAT_SINT128 = 19; - static const uint8_t FORMAT_FLOAT32 = 20; - static const uint8_t FORMAT_FLOAT64 = 21; - static const uint8_t FORMAT_SFLOAT16 = 22; - static const uint8_t FORMAT_SFLOAT32 = 23; - static const uint8_t FORMAT_IEEE20601 = 24; - static const uint8_t FORMAT_UTF8 = 25; - static const uint8_t FORMAT_UTF16 = 26; - static const uint8_t FORMAT_OPAQUE = 27; + BLE2904(); + static const uint8_t FORMAT_BOOLEAN = 1; + static const uint8_t FORMAT_UINT2 = 2; + static const uint8_t FORMAT_UINT4 = 3; + static const uint8_t FORMAT_UINT8 = 4; + static const uint8_t FORMAT_UINT12 = 5; + static const uint8_t FORMAT_UINT16 = 6; + static const uint8_t FORMAT_UINT24 = 7; + static const uint8_t FORMAT_UINT32 = 8; + static const uint8_t FORMAT_UINT48 = 9; + static const uint8_t FORMAT_UINT64 = 10; + static const uint8_t FORMAT_UINT128 = 11; + static const uint8_t FORMAT_SINT8 = 12; + static const uint8_t FORMAT_SINT12 = 13; + static const uint8_t FORMAT_SINT16 = 14; + static const uint8_t FORMAT_SINT24 = 15; + static const uint8_t FORMAT_SINT32 = 16; + static const uint8_t FORMAT_SINT48 = 17; + static const uint8_t FORMAT_SINT64 = 18; + static const uint8_t FORMAT_SINT128 = 19; + static const uint8_t FORMAT_FLOAT32 = 20; + static const uint8_t FORMAT_FLOAT64 = 21; + static const uint8_t FORMAT_SFLOAT16 = 22; + static const uint8_t FORMAT_SFLOAT32 = 23; + static const uint8_t FORMAT_IEEE20601 = 24; + static const uint8_t FORMAT_UTF8 = 25; + static const uint8_t FORMAT_UTF16 = 26; + static const uint8_t FORMAT_OPAQUE = 27; - void setDescription(uint16_t); - void setExponent(int8_t exponent); - void setFormat(uint8_t format); - void setNamespace(uint8_t namespace_value); - void setUnit(uint16_t unit); + void setDescription(uint16_t); + void setExponent(int8_t exponent); + void setFormat(uint8_t format); + void setNamespace(uint8_t namespace_value); + void setUnit(uint16_t unit); private: - BLE2904_Data m_data; -}; // BLE2904 + BLE2904_Data m_data; +}; // BLE2904 #endif /* CONFIG_BLUEDROID_ENABLED */ #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLEAddress.cpp b/libraries/BLE/src/BLEAddress.cpp index 9bed3518116..ccdfca16292 100644 --- a/libraries/BLE/src/BLEAddress.cpp +++ b/libraries/BLE/src/BLEAddress.cpp @@ -27,8 +27,8 @@ * @param [in] address The native representation. */ BLEAddress::BLEAddress(esp_bd_addr_t address) { - memcpy(m_address, address, ESP_BD_ADDR_LEN); -} // BLEAddress + memcpy(m_address, address, ESP_BD_ADDR_LEN); +} // BLEAddress /** @@ -43,17 +43,17 @@ BLEAddress::BLEAddress(esp_bd_addr_t address) { * @param [in] stringAddress The hex representation of the address. */ BLEAddress::BLEAddress(String stringAddress) { - if (stringAddress.length() != 17) return; + if (stringAddress.length() != 17) return; - int data[6]; - sscanf(stringAddress.c_str(), "%x:%x:%x:%x:%x:%x", &data[0], &data[1], &data[2], &data[3], &data[4], &data[5]); - m_address[0] = (uint8_t) data[0]; - m_address[1] = (uint8_t) data[1]; - m_address[2] = (uint8_t) data[2]; - m_address[3] = (uint8_t) data[3]; - m_address[4] = (uint8_t) data[4]; - m_address[5] = (uint8_t) data[5]; -} // BLEAddress + int data[6]; + sscanf(stringAddress.c_str(), "%x:%x:%x:%x:%x:%x", &data[0], &data[1], &data[2], &data[3], &data[4], &data[5]); + m_address[0] = (uint8_t)data[0]; + m_address[1] = (uint8_t)data[1]; + m_address[2] = (uint8_t)data[2]; + m_address[3] = (uint8_t)data[3]; + m_address[4] = (uint8_t)data[4]; + m_address[5] = (uint8_t)data[5]; +} // BLEAddress /** @@ -62,11 +62,11 @@ BLEAddress::BLEAddress(String stringAddress) { * @return True if the addresses are equal. */ bool BLEAddress::equals(BLEAddress otherAddress) { - return memcmp(otherAddress.getNative(), m_address, ESP_BD_ADDR_LEN) == 0; -} // equals + return memcmp(otherAddress.getNative(), m_address, ESP_BD_ADDR_LEN) == 0; +} // equals bool BLEAddress::operator==(const BLEAddress& otherAddress) const { - return memcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) == 0; + return memcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) == 0; } bool BLEAddress::operator!=(const BLEAddress& otherAddress) const { @@ -92,10 +92,10 @@ bool BLEAddress::operator>(const BLEAddress& otherAddress) const { /** * @brief Return the native representation of the address. * @return The native representation of the address. - */ -esp_bd_addr_t *BLEAddress::getNative() { - return &m_address; -} // getNative + */ +esp_bd_addr_t* BLEAddress::getNative() { + return &m_address; +} // getNative /** @@ -110,13 +110,13 @@ esp_bd_addr_t *BLEAddress::getNative() { * @return The string representation of the address. */ String BLEAddress::toString() { - 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]); - String ret(res); - free(res); - return ret; -} // toString + 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]); + String ret(res); + free(res); + return ret; +} // toString #endif #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLEAddress.h b/libraries/BLE/src/BLEAddress.h index cca2c6c385b..d743dfabc5d 100644 --- a/libraries/BLE/src/BLEAddress.h +++ b/libraries/BLE/src/BLEAddress.h @@ -13,7 +13,7 @@ #include "sdkconfig.h" #if defined(CONFIG_BLUEDROID_ENABLED) -#include // ESP32 BLE +#include // ESP32 BLE #include @@ -24,20 +24,20 @@ */ class BLEAddress { public: - BLEAddress(esp_bd_addr_t address); - BLEAddress(String stringAddress); - bool equals(BLEAddress otherAddress); - bool operator==(const BLEAddress& otherAddress) const; - bool operator!=(const BLEAddress& otherAddress) const; - bool operator<(const BLEAddress& otherAddress) const; - bool operator<=(const BLEAddress& otherAddress) const; - bool operator>(const BLEAddress& otherAddress) const; - bool operator>=(const BLEAddress& otherAddress) const; + BLEAddress(esp_bd_addr_t address); + BLEAddress(String stringAddress); + bool equals(BLEAddress otherAddress); + bool operator==(const BLEAddress& otherAddress) const; + bool operator!=(const BLEAddress& otherAddress) const; + bool operator<(const BLEAddress& otherAddress) const; + bool operator<=(const BLEAddress& otherAddress) const; + bool operator>(const BLEAddress& otherAddress) const; + bool operator>=(const BLEAddress& otherAddress) const; esp_bd_addr_t* getNative(); - String toString(); + String toString(); private: - esp_bd_addr_t m_address; + esp_bd_addr_t m_address; }; #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLEAdvertisedDevice.cpp b/libraries/BLE/src/BLEAdvertisedDevice.cpp index 987d5c13876..3f9cab95835 100644 --- a/libraries/BLE/src/BLEAdvertisedDevice.cpp +++ b/libraries/BLE/src/BLEAdvertisedDevice.cpp @@ -21,25 +21,25 @@ #include "esp32-hal-log.h" BLEAdvertisedDevice::BLEAdvertisedDevice() { - m_adFlag = 0; - m_appearance = 0; - m_deviceType = 0; - m_manufacturerData = ""; - m_name = ""; - m_rssi = -9999; - m_serviceUUIDs = {}; - m_serviceData = {}; - m_serviceDataUUIDs = {}; - m_txPower = 0; - m_pScan = nullptr; + m_adFlag = 0; + m_appearance = 0; + m_deviceType = 0; + m_manufacturerData = ""; + m_name = ""; + m_rssi = -9999; + m_serviceUUIDs = {}; + m_serviceData = {}; + m_serviceDataUUIDs = {}; + m_txPower = 0; + m_pScan = nullptr; - m_haveAppearance = false; - m_haveManufacturerData = false; - m_haveName = false; - m_haveRSSI = false; - m_haveTXPower = false; + m_haveAppearance = false; + m_haveManufacturerData = false; + m_haveName = false; + m_haveRSSI = false; + m_haveTXPower = false; -} // BLEAdvertisedDevice +} // BLEAdvertisedDevice /** @@ -51,21 +51,21 @@ BLEAdvertisedDevice::BLEAdvertisedDevice() { * @return The address of the advertised device. */ BLEAddress BLEAdvertisedDevice::getAddress() { - return m_address; -} // getAddress + return m_address; +} // getAddress /** * @brief Get the appearance. * * A %BLE device can declare its own appearance. The appearance is how it would like to be shown to an end user - * typcially in the form of an icon. + * typically in the form of an icon. * * @return The appearance of the advertised device. */ uint16_t BLEAdvertisedDevice::getAppearance() { - return m_appearance; -} // getAppearance + return m_appearance; +} // getAppearance /** @@ -73,8 +73,8 @@ uint16_t BLEAdvertisedDevice::getAppearance() { * @return The manufacturer data of the advertised device. */ String BLEAdvertisedDevice::getManufacturerData() { - return m_manufacturerData; -} // getManufacturerData + return m_manufacturerData; +} // getManufacturerData /** @@ -82,8 +82,8 @@ String BLEAdvertisedDevice::getManufacturerData() { * @return The name of the advertised device. */ String BLEAdvertisedDevice::getName() { - return m_name; -} // getName + return m_name; +} // getName /** @@ -91,8 +91,8 @@ String BLEAdvertisedDevice::getName() { * @return The RSSI of the advertised device. */ int BLEAdvertisedDevice::getRSSI() { - return m_rssi; -} // getRSSI + return m_rssi; +} // getRSSI /** @@ -100,90 +100,90 @@ int BLEAdvertisedDevice::getRSSI() { * @return The scan object. */ BLEScan* BLEAdvertisedDevice::getScan() { - return m_pScan; -} // getScan + return m_pScan; +} // getScan /** * @brief Get the number of service data. * @return Number of service data discovered. */ int BLEAdvertisedDevice::getServiceDataCount() { - return m_serviceData.size(); -} //getServiceDataCount + return m_serviceData.size(); +} //getServiceDataCount /** * @brief Get the service data. * @return The ServiceData of the advertised device. */ String BLEAdvertisedDevice::getServiceData() { - return m_serviceData.empty() ? String() : m_serviceData.front(); -} //getServiceData + return m_serviceData.empty() ? String() : m_serviceData.front(); +} //getServiceData /** * @brief Get the service data. * @return The ServiceData of the advertised device. */ String BLEAdvertisedDevice::getServiceData(int i) { - return m_serviceData[i]; -} //getServiceData + return m_serviceData[i]; +} //getServiceData /** * @brief Get the number of service data UUIDs. * @return Number of service data UUIDs discovered. */ int BLEAdvertisedDevice::getServiceDataUUIDCount() { - return m_serviceDataUUIDs.size(); -} //getServiceDataUUIDCount + return m_serviceDataUUIDs.size(); +} //getServiceDataUUIDCount /** * @brief Get the service data UUID. * @return The service data UUID. */ BLEUUID BLEAdvertisedDevice::getServiceDataUUID() { - return m_serviceDataUUIDs.empty() ? BLEUUID() : m_serviceDataUUIDs.front(); -} // getServiceDataUUID + return m_serviceDataUUIDs.empty() ? BLEUUID() : m_serviceDataUUIDs.front(); +} // getServiceDataUUID /** * @brief Get the service data UUID. * @return The service data UUID. */ BLEUUID BLEAdvertisedDevice::getServiceDataUUID(int i) { - return m_serviceDataUUIDs[i]; -} // getServiceDataUUID + return m_serviceDataUUIDs[i]; +} // getServiceDataUUID /** * @brief Get the number of service UUIDs. * @return Number of service UUIDs discovered. */ int BLEAdvertisedDevice::getServiceUUIDCount() { - return m_serviceUUIDs.size(); -} //getServiceUUIDCount + return m_serviceUUIDs.size(); +} //getServiceUUIDCount /** * @brief Get the Service UUID. * @return The Service UUID of the advertised device. */ BLEUUID BLEAdvertisedDevice::getServiceUUID() { - return m_serviceUUIDs.empty() ? BLEUUID() : m_serviceUUIDs.front(); -} // getServiceUUID + return m_serviceUUIDs.empty() ? BLEUUID() : m_serviceUUIDs.front(); +} // getServiceUUID /** * @brief Get the Service UUID. * @return The Service UUID of the advertised device. */ BLEUUID BLEAdvertisedDevice::getServiceUUID(int i) { - return m_serviceUUIDs[i]; -} // getServiceUUID + return m_serviceUUIDs[i]; +} // getServiceUUID /** * @brief Check advertised serviced for existence required UUID * @return Return true if service is advertised */ -bool BLEAdvertisedDevice::isAdvertisingService(BLEUUID uuid){ - for (int i = 0; i < getServiceUUIDCount(); i++) { - if (m_serviceUUIDs[i].equals(uuid)) return true; - } - return false; +bool BLEAdvertisedDevice::isAdvertisingService(BLEUUID uuid) { + for (int i = 0; i < getServiceUUIDCount(); i++) { + if (m_serviceUUIDs[i].equals(uuid)) return true; + } + return false; } /** @@ -191,8 +191,8 @@ bool BLEAdvertisedDevice::isAdvertisingService(BLEUUID uuid){ * @return The TX Power of the advertised device. */ int8_t BLEAdvertisedDevice::getTXPower() { - return m_txPower; -} // getTXPower + return m_txPower; +} // getTXPower @@ -201,8 +201,8 @@ int8_t BLEAdvertisedDevice::getTXPower() { * @return True if there is an appearance value present. */ bool BLEAdvertisedDevice::haveAppearance() { - return m_haveAppearance; -} // haveAppearance + return m_haveAppearance; +} // haveAppearance /** @@ -210,8 +210,8 @@ bool BLEAdvertisedDevice::haveAppearance() { * @return True if there is manufacturer data present. */ bool BLEAdvertisedDevice::haveManufacturerData() { - return m_haveManufacturerData; -} // haveManufacturerData + return m_haveManufacturerData; +} // haveManufacturerData /** @@ -219,8 +219,8 @@ bool BLEAdvertisedDevice::haveManufacturerData() { * @return True if there is a name value present. */ bool BLEAdvertisedDevice::haveName() { - return m_haveName; -} // haveName + return m_haveName; +} // haveName /** @@ -228,8 +228,8 @@ bool BLEAdvertisedDevice::haveName() { * @return True if there is a signal strength value present. */ bool BLEAdvertisedDevice::haveRSSI() { - return m_haveRSSI; -} // haveRSSI + return m_haveRSSI; +} // haveRSSI /** @@ -237,8 +237,8 @@ bool BLEAdvertisedDevice::haveRSSI() { * @return True if there is a service data value present. */ bool BLEAdvertisedDevice::haveServiceData() { - return !m_serviceData.empty(); -} // haveServiceData + return !m_serviceData.empty(); +} // haveServiceData /** @@ -246,8 +246,8 @@ bool BLEAdvertisedDevice::haveServiceData() { * @return True if there is a service UUID value present. */ bool BLEAdvertisedDevice::haveServiceUUID() { - return !m_serviceUUIDs.empty(); -} // haveServiceUUID + return !m_serviceUUIDs.empty(); +} // haveServiceUUID /** @@ -255,8 +255,8 @@ bool BLEAdvertisedDevice::haveServiceUUID() { * @return True if there is a transmission power value present. */ bool BLEAdvertisedDevice::haveTXPower() { - return m_haveTXPower; -} // haveTXPower + return m_haveTXPower; +} // haveTXPower /** @@ -272,134 +272,147 @@ bool BLEAdvertisedDevice::haveTXPower() { * https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile */ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len) { - uint8_t length; - uint8_t ad_type; - uint8_t sizeConsumed = 0; - bool finished = false; - m_payload = payload; - m_payloadLength = total_len; - - while(!finished) { - length = *payload; // Retrieve the length of the record. - payload++; // Skip to type - sizeConsumed += 1 + length; // increase the size consumed. - - if (length != 0) { // A length of 0 indicates that we have reached the end. - ad_type = *payload; - payload++; - length--; - - char* pHex = BLEUtils::buildHexData(nullptr, payload, length); - log_d("Type: 0x%.2x (%s), length: %d, data: %s", - ad_type, BLEUtils::advTypeToString(ad_type), length, pHex); - free(pHex); - - switch(ad_type) { - case ESP_BLE_AD_TYPE_NAME_CMPL: { // Adv Data Type: 0x09 - setName(String(reinterpret_cast(payload), length)); - break; - } // ESP_BLE_AD_TYPE_NAME_CMPL - - case ESP_BLE_AD_TYPE_TX_PWR: { // Adv Data Type: 0x0A - setTXPower(*payload); - break; - } // ESP_BLE_AD_TYPE_TX_PWR - - case ESP_BLE_AD_TYPE_APPEARANCE: { // Adv Data Type: 0x19 - setAppearance(*reinterpret_cast(payload)); - break; - } // ESP_BLE_AD_TYPE_APPEARANCE - - case ESP_BLE_AD_TYPE_FLAG: { // Adv Data Type: 0x01 - setAdFlag(*payload); - break; - } // ESP_BLE_AD_TYPE_FLAG - - case ESP_BLE_AD_TYPE_16SRV_CMPL: - case ESP_BLE_AD_TYPE_16SRV_PART: { // Adv Data Type: 0x02 - for (int var = 0; var < length/2; ++var) { - setServiceUUID(BLEUUID(*reinterpret_cast(payload + var * 2))); - } - break; - } // ESP_BLE_AD_TYPE_16SRV_PART - - case ESP_BLE_AD_TYPE_32SRV_CMPL: - case ESP_BLE_AD_TYPE_32SRV_PART: { // Adv Data Type: 0x04 - for (int var = 0; var < length/4; ++var) { - setServiceUUID(BLEUUID(*reinterpret_cast(payload + var * 4))); - } - break; - } // ESP_BLE_AD_TYPE_32SRV_PART - - case ESP_BLE_AD_TYPE_128SRV_CMPL: { // Adv Data Type: 0x07 - setServiceUUID(BLEUUID(payload, 16, false)); - break; - } // ESP_BLE_AD_TYPE_128SRV_CMPL - - case ESP_BLE_AD_TYPE_128SRV_PART: { // Adv Data Type: 0x06 - setServiceUUID(BLEUUID(payload, 16, false)); - break; - } // ESP_BLE_AD_TYPE_128SRV_PART - - // See CSS Part A 1.4 Manufacturer Specific Data - case ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE: { - setManufacturerData(String(reinterpret_cast(payload), length)); - break; - } // ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE - - case ESP_BLE_AD_TYPE_SERVICE_DATA: { // Adv Data Type: 0x16 (Service Data) - 2 byte UUID - if (length < 2) { - log_e("Length too small for ESP_BLE_AD_TYPE_SERVICE_DATA"); - break; - } - uint16_t uuid = *(uint16_t*)payload; - setServiceDataUUID(BLEUUID(uuid)); - if (length > 2) { - setServiceData(String(reinterpret_cast(payload + 2), length - 2)); - } - break; - } //ESP_BLE_AD_TYPE_SERVICE_DATA - - case ESP_BLE_AD_TYPE_32SERVICE_DATA: { // Adv Data Type: 0x20 (Service Data) - 4 byte UUID - if (length < 4) { - log_e("Length too small for ESP_BLE_AD_TYPE_32SERVICE_DATA"); - break; - } - uint32_t uuid = *(uint32_t*) payload; - setServiceDataUUID(BLEUUID(uuid)); - if (length > 4) { - setServiceData(String(reinterpret_cast(payload + 4), length - 4)); - } - break; - } //ESP_BLE_AD_TYPE_32SERVICE_DATA - - case ESP_BLE_AD_TYPE_128SERVICE_DATA: { // Adv Data Type: 0x21 (Service Data) - 16 byte UUID - if (length < 16) { - log_e("Length too small for ESP_BLE_AD_TYPE_128SERVICE_DATA"); - break; - } - - setServiceDataUUID(BLEUUID(payload, (size_t)16, false)); - if (length > 16) { - setServiceData(String(reinterpret_cast(payload + 16), length - 16)); - } - break; - } //ESP_BLE_AD_TYPE_32SERVICE_DATA - - default: { - log_d("Unhandled type: adType: %d - 0x%.2x", ad_type, ad_type); - break; - } - } // switch - payload += length; - } // Length <> 0 - - - if (sizeConsumed >= total_len) - finished = true; - - } // !finished -} // parseAdvertisement + uint8_t length; + uint8_t ad_type; + uint8_t sizeConsumed = 0; + bool finished = false; + m_payload = payload; + m_payloadLength = total_len; + + while (!finished) { + length = *payload; // Retrieve the length of the record. + payload++; // Skip to type + sizeConsumed += 1 + length; // increase the size consumed. + + if (length != 0) { // A length of 0 indicates that we have reached the end. + ad_type = *payload; + payload++; + length--; + + char* pHex = BLEUtils::buildHexData(nullptr, payload, length); + log_d("Type: 0x%.2x (%s), length: %d, data: %s", + ad_type, BLEUtils::advTypeToString(ad_type), length, pHex); + free(pHex); + + switch (ad_type) { + case ESP_BLE_AD_TYPE_NAME_CMPL: + { // Adv Data Type: 0x09 + setName(String(reinterpret_cast(payload), length)); + break; + } // ESP_BLE_AD_TYPE_NAME_CMPL + + case ESP_BLE_AD_TYPE_TX_PWR: + { // Adv Data Type: 0x0A + setTXPower(*payload); + break; + } // ESP_BLE_AD_TYPE_TX_PWR + + case ESP_BLE_AD_TYPE_APPEARANCE: + { // Adv Data Type: 0x19 + setAppearance(*reinterpret_cast(payload)); + break; + } // ESP_BLE_AD_TYPE_APPEARANCE + + case ESP_BLE_AD_TYPE_FLAG: + { // Adv Data Type: 0x01 + setAdFlag(*payload); + break; + } // ESP_BLE_AD_TYPE_FLAG + + case ESP_BLE_AD_TYPE_16SRV_CMPL: + case ESP_BLE_AD_TYPE_16SRV_PART: + { // Adv Data Type: 0x02 + for (int var = 0; var < length / 2; ++var) { + setServiceUUID(BLEUUID(*reinterpret_cast(payload + var * 2))); + } + break; + } // ESP_BLE_AD_TYPE_16SRV_PART + + case ESP_BLE_AD_TYPE_32SRV_CMPL: + case ESP_BLE_AD_TYPE_32SRV_PART: + { // Adv Data Type: 0x04 + for (int var = 0; var < length / 4; ++var) { + setServiceUUID(BLEUUID(*reinterpret_cast(payload + var * 4))); + } + break; + } // ESP_BLE_AD_TYPE_32SRV_PART + + case ESP_BLE_AD_TYPE_128SRV_CMPL: + { // Adv Data Type: 0x07 + setServiceUUID(BLEUUID(payload, 16, false)); + break; + } // ESP_BLE_AD_TYPE_128SRV_CMPL + + case ESP_BLE_AD_TYPE_128SRV_PART: + { // Adv Data Type: 0x06 + setServiceUUID(BLEUUID(payload, 16, false)); + break; + } // ESP_BLE_AD_TYPE_128SRV_PART + + // See CSS Part A 1.4 Manufacturer Specific Data + case ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE: + { + setManufacturerData(String(reinterpret_cast(payload), length)); + break; + } // ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE + + case ESP_BLE_AD_TYPE_SERVICE_DATA: + { // Adv Data Type: 0x16 (Service Data) - 2 byte UUID + if (length < 2) { + log_e("Length too small for ESP_BLE_AD_TYPE_SERVICE_DATA"); + break; + } + uint16_t uuid = *(uint16_t*)payload; + setServiceDataUUID(BLEUUID(uuid)); + if (length > 2) { + setServiceData(String(reinterpret_cast(payload + 2), length - 2)); + } + break; + } //ESP_BLE_AD_TYPE_SERVICE_DATA + + case ESP_BLE_AD_TYPE_32SERVICE_DATA: + { // Adv Data Type: 0x20 (Service Data) - 4 byte UUID + if (length < 4) { + log_e("Length too small for ESP_BLE_AD_TYPE_32SERVICE_DATA"); + break; + } + uint32_t uuid = *(uint32_t*)payload; + setServiceDataUUID(BLEUUID(uuid)); + if (length > 4) { + setServiceData(String(reinterpret_cast(payload + 4), length - 4)); + } + break; + } //ESP_BLE_AD_TYPE_32SERVICE_DATA + + case ESP_BLE_AD_TYPE_128SERVICE_DATA: + { // Adv Data Type: 0x21 (Service Data) - 16 byte UUID + if (length < 16) { + log_e("Length too small for ESP_BLE_AD_TYPE_128SERVICE_DATA"); + break; + } + + setServiceDataUUID(BLEUUID(payload, (size_t)16, false)); + if (length > 16) { + setServiceData(String(reinterpret_cast(payload + 16), length - 16)); + } + break; + } //ESP_BLE_AD_TYPE_32SERVICE_DATA + + default: + { + log_d("Unhandled type: adType: %d - 0x%.2x", ad_type, ad_type); + break; + } + } // switch + payload += length; + } // Length <> 0 + + + if (sizeConsumed >= total_len) + finished = true; + + } // !finished +} // parseAdvertisement /** * @brief Parse the advertising payload. @@ -407,17 +420,17 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len) * @param [in] total_len The length of payload */ void BLEAdvertisedDevice::setPayload(uint8_t* payload, size_t total_len) { - m_payload = payload; - m_payloadLength = total_len; -} // setPayload + m_payload = payload; + m_payloadLength = total_len; +} // setPayload /** * @brief Set the address of the advertised device. * @param [in] address The address of the advertised device. */ void BLEAdvertisedDevice::setAddress(BLEAddress address) { - m_address = address; -} // setAddress + m_address = address; +} // setAddress /** @@ -425,8 +438,8 @@ void BLEAdvertisedDevice::setAddress(BLEAddress address) { * @param [in] The discovered adFlag. */ void BLEAdvertisedDevice::setAdFlag(uint8_t adFlag) { - m_adFlag = adFlag; -} // setAdFlag + m_adFlag = adFlag; +} // setAdFlag /** @@ -434,10 +447,10 @@ void BLEAdvertisedDevice::setAdFlag(uint8_t adFlag) { * @param [in] The discovered appearance. */ void BLEAdvertisedDevice::setAppearance(uint16_t appearance) { - m_appearance = appearance; - m_haveAppearance = true; - log_d("- appearance: %d", m_appearance); -} // setAppearance + m_appearance = appearance; + m_haveAppearance = true; + log_d("- appearance: %d", m_appearance); +} // setAppearance /** @@ -445,12 +458,12 @@ void BLEAdvertisedDevice::setAppearance(uint16_t appearance) { * @param [in] The discovered manufacturer data. */ void BLEAdvertisedDevice::setManufacturerData(String manufacturerData) { - m_manufacturerData = manufacturerData; - m_haveManufacturerData = true; - char* pHex = BLEUtils::buildHexData(nullptr, (uint8_t*) m_manufacturerData.c_str(), (uint8_t) m_manufacturerData.length()); - log_d("- manufacturer data: %s", pHex); - free(pHex); -} // setManufacturerData + m_manufacturerData = manufacturerData; + m_haveManufacturerData = true; + char* pHex = BLEUtils::buildHexData(nullptr, (uint8_t*)m_manufacturerData.c_str(), (uint8_t)m_manufacturerData.length()); + log_d("- manufacturer data: %s", pHex); + free(pHex); +} // setManufacturerData /** @@ -458,10 +471,10 @@ void BLEAdvertisedDevice::setManufacturerData(String manufacturerData) { * @param [in] name The discovered name. */ void BLEAdvertisedDevice::setName(String name) { - m_name = name; - m_haveName = true; - log_d("- setName(): name: %s", m_name.c_str()); -} // setName + m_name = name; + m_haveName = true; + log_d("- setName(): name: %s", m_name.c_str()); +} // setName /** @@ -469,10 +482,10 @@ void BLEAdvertisedDevice::setName(String name) { * @param [in] rssi The discovered RSSI. */ void BLEAdvertisedDevice::setRSSI(int rssi) { - m_rssi = rssi; - m_haveRSSI = true; - log_d("- setRSSI(): rssi: %d", m_rssi); -} // setRSSI + m_rssi = rssi; + m_haveRSSI = true; + log_d("- setRSSI(): rssi: %d", m_rssi); +} // setRSSI /** @@ -480,8 +493,8 @@ void BLEAdvertisedDevice::setRSSI(int rssi) { * @param pScan The Scan that created this advertised device. */ void BLEAdvertisedDevice::setScan(BLEScan* pScan) { - m_pScan = pScan; -} // setScan + m_pScan = pScan; +} // setScan /** @@ -489,8 +502,8 @@ void BLEAdvertisedDevice::setScan(BLEScan* pScan) { * @param [in] serviceUUID The discovered serviceUUID */ void BLEAdvertisedDevice::setServiceUUID(const char* serviceUUID) { - return setServiceUUID(BLEUUID(serviceUUID)); -} // setServiceUUID + return setServiceUUID(BLEUUID(serviceUUID)); +} // setServiceUUID /** @@ -498,9 +511,9 @@ void BLEAdvertisedDevice::setServiceUUID(const char* serviceUUID) { * @param [in] serviceUUID The discovered serviceUUID */ void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) { - m_serviceUUIDs.push_back(serviceUUID); - log_d("- addServiceUUID(): serviceUUID: %s", serviceUUID.toString().c_str()); -} // setServiceUUID + m_serviceUUIDs.push_back(serviceUUID); + log_d("- addServiceUUID(): serviceUUID: %s", serviceUUID.toString().c_str()); +} // setServiceUUID /** @@ -508,8 +521,8 @@ void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) { * @param [in] data ServiceData value. */ void BLEAdvertisedDevice::setServiceData(String serviceData) { - m_serviceData.push_back(serviceData); // Save the service data that we received. -} //setServiceData + m_serviceData.push_back(serviceData); // Save the service data that we received. +} //setServiceData /** @@ -517,9 +530,9 @@ void BLEAdvertisedDevice::setServiceData(String serviceData) { * @param [in] data ServiceDataUUID value. */ void BLEAdvertisedDevice::setServiceDataUUID(BLEUUID uuid) { - m_serviceDataUUIDs.push_back(uuid); - log_d("- addServiceDataUUID(): serviceDataUUID: %s", uuid.toString().c_str()); -} // setServiceDataUUID + m_serviceDataUUIDs.push_back(uuid); + log_d("- addServiceDataUUID(): serviceDataUUID: %s", uuid.toString().c_str()); +} // setServiceDataUUID /** @@ -527,10 +540,10 @@ void BLEAdvertisedDevice::setServiceDataUUID(BLEUUID uuid) { * @param [in] txPower The discovered power level. */ void BLEAdvertisedDevice::setTXPower(int8_t txPower) { - m_txPower = txPower; - m_haveTXPower = true; - log_d("- txPower: %d", m_txPower); -} // setTXPower + m_txPower = txPower; + m_haveTXPower = true; + log_d("- txPower: %d", m_txPower); +} // setTXPower /** @@ -538,62 +551,62 @@ void BLEAdvertisedDevice::setTXPower(int8_t txPower) { * @return A string representation of this device. */ String BLEAdvertisedDevice::toString() { - String res = "Name: " + getName() + ", Address: " + getAddress().toString(); - if (haveAppearance()) { - char val[6]; - snprintf(val, sizeof(val), "%d", getAppearance()); - res += ", appearance: "; - res += val; - } - if (haveManufacturerData()) { - char *pHex = BLEUtils::buildHexData(nullptr, (uint8_t*)getManufacturerData().c_str(), getManufacturerData().length()); - res += ", manufacturer data: "; - res += pHex; - free(pHex); - } - if (haveServiceUUID()) { - for (int i=0; i < getServiceUUIDCount(); i++) { - res += ", serviceUUID: " + getServiceUUID(i).toString(); - } - } - if (haveTXPower()) { - char val[6]; - snprintf(val, sizeof(val), "%d", getTXPower()); - res += ", txPower: "; - res += val; - } - if (haveRSSI()) { - char val[4]; - snprintf(val, sizeof(val), "%i", getRSSI()); - res += ", rssi: "; - res += val; - } - if (haveServiceData()) { - for (int i=0; i = i+3 && m_payload[i+1] == 0xAA && m_payload[i+2] == 0xFE && m_payload[i+3] == 0x00){ + if (m_payload[i] == 0x16 && m_payloadLength >= i + 3 && m_payload[i + 1] == 0xAA && m_payload[i + 2] == 0xFE && m_payload[i + 3] == 0x00) { return BLE_EDDYSTONE_UUID_FRAME; } - if(m_payload[i] == 0x16 && m_payloadLength >= i+3 && m_payload[i+1] == 0xAA && m_payload[i+2] == 0xFE && m_payload[i+3] == 0x10){ + if (m_payload[i] == 0x16 && m_payloadLength >= i + 3 && m_payload[i + 1] == 0xAA && m_payload[i + 2] == 0xFE && m_payload[i + 3] == 0x10) { return BLE_EDDYSTONE_URL_FRAME; } - if(m_payload[i] == 0x16 && m_payloadLength >= i+3 && m_payload[i+1] == 0xAA && m_payload[i+2] == 0xFE && m_payload[i+3] == 0x20){ + if (m_payload[i] == 0x16 && m_payloadLength >= i + 3 && m_payload[i + 1] == 0xAA && m_payload[i + 2] == 0xFE && m_payload[i + 3] == 0x20) { return BLE_EDDYSTONE_TLM_FRAME; } } @@ -601,11 +614,11 @@ ble_frame_type_t BLEAdvertisedDevice::getFrameType(){ } void BLEAdvertisedDevice::setAddressType(esp_ble_addr_type_t type) { - m_addressType = type; + m_addressType = type; } size_t BLEAdvertisedDevice::getPayloadLength() { - return m_payloadLength; + return m_payloadLength; } #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLEAdvertisedDevice.h b/libraries/BLE/src/BLEAdvertisedDevice.h index 9e24156da29..b9f640073b6 100644 --- a/libraries/BLE/src/BLEAdvertisedDevice.h +++ b/libraries/BLE/src/BLEAdvertisedDevice.h @@ -21,11 +21,11 @@ #include "BLEUUID.h" typedef enum { - BLE_UNKNOWN_FRAME, - BLE_EDDYSTONE_UUID_FRAME, - BLE_EDDYSTONE_URL_FRAME, - BLE_EDDYSTONE_TLM_FRAME, - BLE_FRAME_MAX + BLE_UNKNOWN_FRAME, + BLE_EDDYSTONE_UUID_FRAME, + BLE_EDDYSTONE_URL_FRAME, + BLE_EDDYSTONE_TLM_FRAME, + BLE_FRAME_MAX } ble_frame_type_t; class BLEScan; @@ -37,83 +37,83 @@ class BLEScan; */ class BLEAdvertisedDevice { public: - BLEAdvertisedDevice(); - - BLEAddress getAddress(); - uint16_t getAppearance(); - String getManufacturerData(); - String getName(); - int getRSSI(); - BLEScan* getScan(); - String getServiceData(); - String getServiceData(int i); - BLEUUID getServiceDataUUID(); - BLEUUID getServiceDataUUID(int i); - BLEUUID getServiceUUID(); - BLEUUID getServiceUUID(int i); - int getServiceDataCount(); - int getServiceDataUUIDCount(); - int getServiceUUIDCount(); - int8_t getTXPower(); - uint8_t* getPayload(); - size_t getPayloadLength(); - esp_ble_addr_type_t getAddressType(); - ble_frame_type_t getFrameType(); - void setAddressType(esp_ble_addr_type_t type); - - - bool isAdvertisingService(BLEUUID uuid); - bool haveAppearance(); - bool haveManufacturerData(); - bool haveName(); - bool haveRSSI(); - bool haveServiceData(); - bool haveServiceUUID(); - bool haveTXPower(); - - String toString(); + BLEAdvertisedDevice(); + + BLEAddress getAddress(); + uint16_t getAppearance(); + String getManufacturerData(); + String getName(); + int getRSSI(); + BLEScan* getScan(); + String getServiceData(); + String getServiceData(int i); + BLEUUID getServiceDataUUID(); + BLEUUID getServiceDataUUID(int i); + BLEUUID getServiceUUID(); + BLEUUID getServiceUUID(int i); + int getServiceDataCount(); + int getServiceDataUUIDCount(); + int getServiceUUIDCount(); + int8_t getTXPower(); + uint8_t* getPayload(); + size_t getPayloadLength(); + esp_ble_addr_type_t getAddressType(); + ble_frame_type_t getFrameType(); + void setAddressType(esp_ble_addr_type_t type); + + + bool isAdvertisingService(BLEUUID uuid); + bool haveAppearance(); + bool haveManufacturerData(); + bool haveName(); + bool haveRSSI(); + bool haveServiceData(); + bool haveServiceUUID(); + bool haveTXPower(); + + String toString(); private: - friend class BLEScan; - - void parseAdvertisement(uint8_t* payload, size_t total_len=62); - void setPayload(uint8_t* payload, size_t total_len=62); - void setAddress(BLEAddress address); - void setAdFlag(uint8_t adFlag); - void setAdvertizementResult(uint8_t* payload); - void setAppearance(uint16_t appearance); - void setManufacturerData(String manufacturerData); - void setName(String name); - void setRSSI(int rssi); - void setScan(BLEScan* pScan); - void setServiceData(String data); - void setServiceDataUUID(BLEUUID uuid); - void setServiceUUID(const char* serviceUUID); - void setServiceUUID(BLEUUID serviceUUID); - void setTXPower(int8_t txPower); - - bool m_haveAppearance; - bool m_haveManufacturerData; - bool m_haveName; - bool m_haveRSSI; - bool m_haveTXPower; - - - BLEAddress m_address = BLEAddress((uint8_t*)"\0\0\0\0\0\0"); - uint8_t m_adFlag; - uint16_t m_appearance; - int m_deviceType; - String m_manufacturerData; - String m_name; - BLEScan* m_pScan; - int m_rssi; - std::vector m_serviceUUIDs; - int8_t m_txPower; - std::vector m_serviceData; - std::vector m_serviceDataUUIDs; - uint8_t* m_payload; - size_t m_payloadLength = 0; - esp_ble_addr_type_t m_addressType; + friend class BLEScan; + + void parseAdvertisement(uint8_t* payload, size_t total_len = 62); + void setPayload(uint8_t* payload, size_t total_len = 62); + void setAddress(BLEAddress address); + void setAdFlag(uint8_t adFlag); + void setAdvertizementResult(uint8_t* payload); + void setAppearance(uint16_t appearance); + void setManufacturerData(String manufacturerData); + void setName(String name); + void setRSSI(int rssi); + void setScan(BLEScan* pScan); + void setServiceData(String data); + void setServiceDataUUID(BLEUUID uuid); + void setServiceUUID(const char* serviceUUID); + void setServiceUUID(BLEUUID serviceUUID); + void setTXPower(int8_t txPower); + + bool m_haveAppearance; + bool m_haveManufacturerData; + bool m_haveName; + bool m_haveRSSI; + bool m_haveTXPower; + + + BLEAddress m_address = BLEAddress((uint8_t*)"\0\0\0\0\0\0"); + uint8_t m_adFlag; + uint16_t m_appearance; + int m_deviceType; + String m_manufacturerData; + String m_name; + BLEScan* m_pScan; + int m_rssi; + std::vector m_serviceUUIDs; + int8_t m_txPower; + std::vector m_serviceData; + std::vector m_serviceDataUUIDs; + uint8_t* m_payload; + size_t m_payloadLength = 0; + esp_ble_addr_type_t m_addressType; }; /** @@ -125,29 +125,29 @@ class BLEAdvertisedDevice { */ class BLEAdvertisedDeviceCallbacks { public: - virtual ~BLEAdvertisedDeviceCallbacks() {} - /** + virtual ~BLEAdvertisedDeviceCallbacks() {} + /** * @brief Called when a new scan result is detected. * * As we are scanning, we will find new devices. When found, this call back is invoked with a reference to the * device that was found. During any individual scan, a device will only be detected one time. */ - virtual void onResult(BLEAdvertisedDevice advertisedDevice) = 0; + virtual void onResult(BLEAdvertisedDevice advertisedDevice) = 0; }; #ifdef SOC_BLE_50_SUPPORTED class BLEExtAdvertisingCallbacks { public: - virtual ~BLEExtAdvertisingCallbacks() {} - /** + virtual ~BLEExtAdvertisingCallbacks() {} + /** * @brief Called when a new scan result is detected. * * As we are scanning, we will find new devices. When found, this call back is invoked with a reference to the * device that was found. During any individual scan, a device will only be detected one time. */ - virtual void onResult(esp_ble_gap_ext_adv_report_t report) = 0; + virtual void onResult(esp_ble_gap_ext_adv_report_t report) = 0; }; -#endif // SOC_BLE_50_SUPPORTED +#endif // SOC_BLE_50_SUPPORTED #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLEAdvertising.cpp b/libraries/BLE/src/BLEAdvertising.cpp index 3e934d28f1e..9aebfe6a3bd 100644 --- a/libraries/BLE/src/BLEAdvertising.cpp +++ b/libraries/BLE/src/BLEAdvertising.cpp @@ -32,33 +32,32 @@ * */ BLEAdvertising::BLEAdvertising() -: m_scanRespData{} -{ - m_advData.set_scan_rsp = false; - m_advData.include_name = true; - m_advData.include_txpower = true; - m_advData.min_interval = 0x20; - m_advData.max_interval = 0x40; - m_advData.appearance = 0x00; - m_advData.manufacturer_len = 0; - m_advData.p_manufacturer_data = nullptr; - m_advData.service_data_len = 0; - m_advData.p_service_data = nullptr; - m_advData.service_uuid_len = 0; - m_advData.p_service_uuid = nullptr; - m_advData.flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT); - - m_advParams.adv_int_min = 0x20; - m_advParams.adv_int_max = 0x40; - m_advParams.adv_type = ADV_TYPE_IND; - m_advParams.own_addr_type = BLE_ADDR_TYPE_PUBLIC; - m_advParams.channel_map = ADV_CHNL_ALL; - m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY; - m_advParams.peer_addr_type = BLE_ADDR_TYPE_PUBLIC; - - m_customAdvData = false; // No custom advertising data - m_customScanResponseData = false; // No custom scan response data -} // BLEAdvertising + : m_scanRespData{} { + m_advData.set_scan_rsp = false; + m_advData.include_name = true; + m_advData.include_txpower = true; + m_advData.min_interval = 0x20; + m_advData.max_interval = 0x40; + m_advData.appearance = 0x00; + m_advData.manufacturer_len = 0; + m_advData.p_manufacturer_data = nullptr; + m_advData.service_data_len = 0; + m_advData.p_service_data = nullptr; + m_advData.service_uuid_len = 0; + m_advData.p_service_uuid = nullptr; + m_advData.flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT); + + m_advParams.adv_int_min = 0x20; + m_advParams.adv_int_max = 0x40; + m_advParams.adv_type = ADV_TYPE_IND; + m_advParams.own_addr_type = BLE_ADDR_TYPE_PUBLIC; + m_advParams.channel_map = ADV_CHNL_ALL; + m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY; + m_advParams.peer_addr_type = BLE_ADDR_TYPE_PUBLIC; + + m_customAdvData = false; // No custom advertising data + m_customScanResponseData = false; // No custom scan response data +} // BLEAdvertising /** @@ -66,8 +65,8 @@ BLEAdvertising::BLEAdvertising() * @param [in] serviceUUID The UUID of the service to expose. */ void BLEAdvertising::addServiceUUID(BLEUUID serviceUUID) { - m_serviceUUIDs.push_back(serviceUUID); -} // addServiceUUID + m_serviceUUIDs.push_back(serviceUUID); +} // addServiceUUID /** @@ -75,8 +74,8 @@ void BLEAdvertising::addServiceUUID(BLEUUID serviceUUID) { * @param [in] serviceUUID The string representation of the service to expose. */ void BLEAdvertising::addServiceUUID(const char* serviceUUID) { - addServiceUUID(BLEUUID(serviceUUID)); -} // addServiceUUID + addServiceUUID(BLEUUID(serviceUUID)); +} // addServiceUUID /** @@ -84,34 +83,34 @@ void BLEAdvertising::addServiceUUID(const char* serviceUUID) { * @param [in] index The index of the service to stop exposing. */ bool BLEAdvertising::removeServiceUUID(int index) { - - // If index is larger than the size of the - // advertised services, return false - if(index > m_serviceUUIDs.size()) return false; - - m_serviceUUIDs.erase(m_serviceUUIDs.begin() + index); - return true; + + // If index is larger than the size of the + // advertised services, return false + if (index > m_serviceUUIDs.size()) return false; + + m_serviceUUIDs.erase(m_serviceUUIDs.begin() + index); + return true; } - + /** * @brief Remove a service uuid to exposed list of services. * @param [in] serviceUUID The BLEUUID of the service to stop exposing. */ bool BLEAdvertising::removeServiceUUID(BLEUUID serviceUUID) { - for(int i = 0; i < m_serviceUUIDs.size(); i++) { - if(m_serviceUUIDs.at(i).equals(serviceUUID)) { - return removeServiceUUID(i); - } - } - return false; + for (int i = 0; i < m_serviceUUIDs.size(); i++) { + if (m_serviceUUIDs.at(i).equals(serviceUUID)) { + return removeServiceUUID(i); + } + } + return false; } - + /** * @brief Remove a service uuid to exposed list of services. * @param [in] serviceUUID The string of the service to stop exposing. */ bool BLEAdvertising::removeServiceUUID(const char* serviceUUID) { - return removeServiceUUID(BLEUUID(serviceUUID)); + return removeServiceUUID(BLEUUID(serviceUUID)); } /** @@ -122,35 +121,35 @@ bool BLEAdvertising::removeServiceUUID(const char* serviceUUID) { * @return N/A. */ void BLEAdvertising::setAppearance(uint16_t appearance) { - m_advData.appearance = appearance; -} // setAppearance + m_advData.appearance = appearance; +} // setAppearance -void BLEAdvertising::setAdvertisementType(esp_ble_adv_type_t adv_type){ - m_advParams.adv_type = adv_type; -} // setAdvertisementType +void BLEAdvertising::setAdvertisementType(esp_ble_adv_type_t adv_type) { + m_advParams.adv_type = adv_type; +} // setAdvertisementType void BLEAdvertising::setAdvertisementChannelMap(esp_ble_adv_channel_t channel_map) { - m_advParams.channel_map = channel_map; -} // setAdvertisementChannelMap + m_advParams.channel_map = channel_map; +} // setAdvertisementChannelMap void BLEAdvertising::setMinInterval(uint16_t mininterval) { - m_advParams.adv_int_min = mininterval; -} // setMinInterval + m_advParams.adv_int_min = mininterval; +} // setMinInterval void BLEAdvertising::setMaxInterval(uint16_t maxinterval) { - m_advParams.adv_int_max = maxinterval; -} // setMaxInterval + m_advParams.adv_int_max = maxinterval; +} // setMaxInterval void BLEAdvertising::setMinPreferred(uint16_t mininterval) { - m_advData.min_interval = mininterval; -} // + m_advData.min_interval = mininterval; +} // void BLEAdvertising::setMaxPreferred(uint16_t maxinterval) { - m_advData.max_interval = maxinterval; -} // + m_advData.max_interval = maxinterval; +} // void BLEAdvertising::setScanResponse(bool set) { - m_scanResp = set; + m_scanResp = set; } /** @@ -159,28 +158,28 @@ void BLEAdvertising::setScanResponse(bool set) { * @param [in] connectWhitelistOnly If true, only allow connections from those on the white list. */ void BLEAdvertising::setScanFilter(bool scanRequestWhitelistOnly, bool connectWhitelistOnly) { - log_v(">> setScanFilter: scanRequestWhitelistOnly: %d, connectWhitelistOnly: %d", scanRequestWhitelistOnly, connectWhitelistOnly); - if (!scanRequestWhitelistOnly && !connectWhitelistOnly) { - m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY; - log_v("<< setScanFilter"); - return; - } - if (scanRequestWhitelistOnly && !connectWhitelistOnly) { - m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY; - log_v("<< setScanFilter"); - return; - } - if (!scanRequestWhitelistOnly && connectWhitelistOnly) { - m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST; - log_v("<< setScanFilter"); - return; - } - if (scanRequestWhitelistOnly && connectWhitelistOnly) { - m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST; - log_v("<< setScanFilter"); - return; - } -} // setScanFilter + log_v(">> setScanFilter: scanRequestWhitelistOnly: %d, connectWhitelistOnly: %d", scanRequestWhitelistOnly, connectWhitelistOnly); + if (!scanRequestWhitelistOnly && !connectWhitelistOnly) { + m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY; + log_v("<< setScanFilter"); + return; + } + if (scanRequestWhitelistOnly && !connectWhitelistOnly) { + m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY; + log_v("<< setScanFilter"); + return; + } + if (!scanRequestWhitelistOnly && connectWhitelistOnly) { + m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST; + log_v("<< setScanFilter"); + return; + } + if (scanRequestWhitelistOnly && connectWhitelistOnly) { + m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST; + log_v("<< setScanFilter"); + return; + } +} // setScanFilter /** @@ -188,16 +187,16 @@ void BLEAdvertising::setScanFilter(bool scanRequestWhitelistOnly, bool connectWh * @param [in] advertisementData The data to be advertised. */ void BLEAdvertising::setAdvertisementData(BLEAdvertisementData& advertisementData) { - log_v(">> setAdvertisementData"); - esp_err_t errRc = ::esp_ble_gap_config_adv_data_raw( - (uint8_t*)advertisementData.getPayload().c_str(), - advertisementData.getPayload().length()); - if (errRc != ESP_OK) { - log_e("esp_ble_gap_config_adv_data_raw: %d %s", errRc, GeneralUtils::errorToString(errRc)); - } - m_customAdvData = true; // Set the flag that indicates we are using custom advertising data. - log_v("<< setAdvertisementData"); -} // setAdvertisementData + log_v(">> setAdvertisementData"); + esp_err_t errRc = ::esp_ble_gap_config_adv_data_raw( + (uint8_t*)advertisementData.getPayload().c_str(), + advertisementData.getPayload().length()); + if (errRc != ESP_OK) { + log_e("esp_ble_gap_config_adv_data_raw: %d %s", errRc, GeneralUtils::errorToString(errRc)); + } + m_customAdvData = true; // Set the flag that indicates we are using custom advertising data. + log_v("<< setAdvertisementData"); +} // setAdvertisementData /** @@ -205,16 +204,16 @@ void BLEAdvertising::setAdvertisementData(BLEAdvertisementData& advertisementDat * @param [in] advertisementData The data to be advertised. */ void BLEAdvertising::setScanResponseData(BLEAdvertisementData& advertisementData) { - log_v(">> setScanResponseData"); - esp_err_t errRc = ::esp_ble_gap_config_scan_rsp_data_raw( - (uint8_t*)advertisementData.getPayload().c_str(), - advertisementData.getPayload().length()); - if (errRc != ESP_OK) { - log_e("esp_ble_gap_config_scan_rsp_data_raw: %d %s", errRc, GeneralUtils::errorToString(errRc)); - } - m_customScanResponseData = true; // Set the flag that indicates we are using custom scan response data. - log_v("<< setScanResponseData"); -} // setScanResponseData + log_v(">> setScanResponseData"); + esp_err_t errRc = ::esp_ble_gap_config_scan_rsp_data_raw( + (uint8_t*)advertisementData.getPayload().c_str(), + advertisementData.getPayload().length()); + if (errRc != ESP_OK) { + log_e("esp_ble_gap_config_scan_rsp_data_raw: %d %s", errRc, GeneralUtils::errorToString(errRc)); + } + m_customScanResponseData = true; // Set the flag that indicates we are using custom scan response data. + log_v("<< setScanResponseData"); +} // setScanResponseData /** * @brief Start advertising. @@ -222,76 +221,76 @@ void BLEAdvertising::setScanResponseData(BLEAdvertisementData& advertisementData * @return N/A. */ void BLEAdvertising::start() { - log_v(">> start: customAdvData: %d, customScanResponseData: %d", m_customAdvData, m_customScanResponseData); - - // We have a vector of service UUIDs that we wish to advertise. In order to use the - // ESP-IDF framework, these must be supplied in a contiguous array of their 128bit (16 byte) - // representations. If we have 1 or more services to advertise then we allocate enough - // storage to host them and then copy them in one at a time into the contiguous storage. - int numServices = m_serviceUUIDs.size(); - if (numServices > 0) { - m_advData.service_uuid_len = 16 * numServices; - m_advData.p_service_uuid = (uint8_t *)malloc(m_advData.service_uuid_len); - if(!m_advData.p_service_uuid) { - log_e(">> start failed: out of memory"); - return; - } - - uint8_t* p = m_advData.p_service_uuid; - for (int i = 0; i < numServices; i++) { - log_d("- advertising service: %s", m_serviceUUIDs[i].toString().c_str()); - BLEUUID serviceUUID128 = m_serviceUUIDs[i].to128(); - memcpy(p, serviceUUID128.getNative()->uuid.uuid128, 16); - p += 16; - } - } else { - m_advData.service_uuid_len = 0; - log_d("- no services advertised"); - } - - esp_err_t errRc; - - if (!m_customAdvData) { - // Set the configuration for advertising. - m_advData.set_scan_rsp = false; - m_advData.include_name = !m_scanResp; - m_advData.include_txpower = !m_scanResp; - errRc = ::esp_ble_gap_config_adv_data(&m_advData); - if (errRc != ESP_OK) { - log_e("<< esp_ble_gap_config_adv_data: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } - } - - if (!m_customScanResponseData && m_scanResp) { - // Set the configuration for scan response. - memcpy(&m_scanRespData, &m_advData, sizeof(esp_ble_adv_data_t)); // Copy the content of m_advData. - m_scanRespData.set_scan_rsp = true; // Define this struct as scan response data - m_scanRespData.include_name = true; // Caution: This may lead to a crash if the device name has more than 29 characters - m_scanRespData.include_txpower = true; - m_scanRespData.appearance = 0; // If defined the 'Appearance' attribute is already included in the advertising data - m_scanRespData.flag = 0; // 'Flags' attribute should no be included in the scan response - - errRc = ::esp_ble_gap_config_adv_data(&m_scanRespData); - if (errRc != ESP_OK) { - log_e("<< esp_ble_gap_config_adv_data (Scan response): rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } - } - - // If we had services to advertise then we previously allocated some storage for them. - // Here we release that storage. - free(m_advData.p_service_uuid); //TODO change this variable to local scope? - m_advData.p_service_uuid = nullptr; - - // Start advertising. - errRc = ::esp_ble_gap_start_advertising(&m_advParams); - if (errRc != ESP_OK) { - log_e("<< esp_ble_gap_start_advertising: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } - log_v("<< start"); -} // start + log_v(">> start: customAdvData: %d, customScanResponseData: %d", m_customAdvData, m_customScanResponseData); + + // We have a vector of service UUIDs that we wish to advertise. In order to use the + // ESP-IDF framework, these must be supplied in a contiguous array of their 128bit (16 byte) + // representations. If we have 1 or more services to advertise then we allocate enough + // storage to host them and then copy them in one at a time into the contiguous storage. + int numServices = m_serviceUUIDs.size(); + if (numServices > 0) { + m_advData.service_uuid_len = 16 * numServices; + m_advData.p_service_uuid = (uint8_t*)malloc(m_advData.service_uuid_len); + if (!m_advData.p_service_uuid) { + log_e(">> start failed: out of memory"); + return; + } + + uint8_t* p = m_advData.p_service_uuid; + for (int i = 0; i < numServices; i++) { + log_d("- advertising service: %s", m_serviceUUIDs[i].toString().c_str()); + BLEUUID serviceUUID128 = m_serviceUUIDs[i].to128(); + memcpy(p, serviceUUID128.getNative()->uuid.uuid128, 16); + p += 16; + } + } else { + m_advData.service_uuid_len = 0; + log_d("- no services advertised"); + } + + esp_err_t errRc; + + if (!m_customAdvData) { + // Set the configuration for advertising. + m_advData.set_scan_rsp = false; + m_advData.include_name = !m_scanResp; + m_advData.include_txpower = !m_scanResp; + errRc = ::esp_ble_gap_config_adv_data(&m_advData); + if (errRc != ESP_OK) { + log_e("<< esp_ble_gap_config_adv_data: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } + } + + if (!m_customScanResponseData && m_scanResp) { + // Set the configuration for scan response. + memcpy(&m_scanRespData, &m_advData, sizeof(esp_ble_adv_data_t)); // Copy the content of m_advData. + m_scanRespData.set_scan_rsp = true; // Define this struct as scan response data + m_scanRespData.include_name = true; // Caution: This may lead to a crash if the device name has more than 29 characters + m_scanRespData.include_txpower = true; + m_scanRespData.appearance = 0; // If defined the 'Appearance' attribute is already included in the advertising data + m_scanRespData.flag = 0; // 'Flags' attribute should no be included in the scan response + + errRc = ::esp_ble_gap_config_adv_data(&m_scanRespData); + if (errRc != ESP_OK) { + log_e("<< esp_ble_gap_config_adv_data (Scan response): rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } + } + + // If we had services to advertise then we previously allocated some storage for them. + // Here we release that storage. + free(m_advData.p_service_uuid); //TODO change this variable to local scope? + m_advData.p_service_uuid = nullptr; + + // Start advertising. + errRc = ::esp_ble_gap_start_advertising(&m_advParams); + if (errRc != ESP_OK) { + log_e("<< esp_ble_gap_start_advertising: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } + log_v("<< start"); +} // start /** @@ -300,14 +299,14 @@ void BLEAdvertising::start() { * @return N/A. */ void BLEAdvertising::stop() { - log_v(">> stop"); - esp_err_t errRc = ::esp_ble_gap_stop_advertising(); - if (errRc != ESP_OK) { - log_e("esp_ble_gap_stop_advertising: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } - log_v("<< stop"); -} // stop + log_v(">> stop"); + esp_err_t errRc = ::esp_ble_gap_stop_advertising(); + if (errRc != ESP_OK) { + log_e("esp_ble_gap_stop_advertising: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } + log_v("<< stop"); +} // stop /** * @brief Set BLE address. @@ -316,30 +315,28 @@ void BLEAdvertising::stop() { * Set BLE address. */ -void BLEAdvertising::setDeviceAddress(esp_bd_addr_t addr, esp_ble_addr_type_t type) -{ - log_v(">> setPrivateAddress"); +void BLEAdvertising::setDeviceAddress(esp_bd_addr_t addr, esp_ble_addr_type_t type) { + log_v(">> setPrivateAddress"); - m_advParams.own_addr_type = type; - esp_err_t errRc = esp_ble_gap_set_rand_addr((uint8_t*)addr); - if (errRc != ESP_OK) - { - log_e("esp_ble_gap_set_rand_addr: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } - log_v("<< setPrivateAddress"); -} // setPrivateAddress + m_advParams.own_addr_type = type; + esp_err_t errRc = esp_ble_gap_set_rand_addr((uint8_t*)addr); + if (errRc != ESP_OK) { + log_e("esp_ble_gap_set_rand_addr: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } + log_v("<< setPrivateAddress"); +} // setPrivateAddress /** * @brief Add data to the payload to be advertised. * @param [in] data The data to be added to the payload. */ void BLEAdvertisementData::addData(String data) { - if ((m_payload.length() + data.length()) > ESP_BLE_ADV_DATA_LEN_MAX) { - return; - } - m_payload.concat(data); -} // addData + if ((m_payload.length() + data.length()) > ESP_BLE_ADV_DATA_LEN_MAX) { + return; + } + m_payload.concat(data); +} // addData /** @@ -350,11 +347,11 @@ void BLEAdvertisementData::addData(String data) { * https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.gap.appearance.xml */ void BLEAdvertisementData::setAppearance(uint16_t appearance) { - char cdata[2]; - cdata[0] = 3; - cdata[1] = ESP_BLE_AD_TYPE_APPEARANCE; // 0x19 - addData(String(cdata, 2) + String((char*) &appearance, 2)); -} // setAppearance + char cdata[2]; + cdata[0] = 3; + cdata[1] = ESP_BLE_AD_TYPE_APPEARANCE; // 0x19 + addData(String(cdata, 2) + String((char*)&appearance, 2)); +} // setAppearance /** @@ -362,36 +359,39 @@ void BLEAdvertisementData::setAppearance(uint16_t appearance) { * @param [in] uuid The single service to advertise. */ void BLEAdvertisementData::setCompleteServices(BLEUUID uuid) { - char cdata[2]; - switch (uuid.bitSize()) { - case 16: { - // [Len] [0x02] [LL] [HH] - cdata[0] = 3; - cdata[1] = ESP_BLE_AD_TYPE_16SRV_CMPL; // 0x03 - addData(String(cdata, 2) + String((char*) &uuid.getNative()->uuid.uuid16, 2)); - break; - } - - case 32: { - // [Len] [0x04] [LL] [LL] [HH] [HH] - cdata[0] = 5; - cdata[1] = ESP_BLE_AD_TYPE_32SRV_CMPL; // 0x05 - addData(String(cdata, 2) + String((char*) &uuid.getNative()->uuid.uuid32, 4)); - break; - } - - case 128: { - // [Len] [0x04] [0] [1] ... [15] - cdata[0] = 17; - cdata[1] = ESP_BLE_AD_TYPE_128SRV_CMPL; // 0x07 - addData(String(cdata, 2) + String((char*) uuid.getNative()->uuid.uuid128, 16)); - break; - } - - default: - return; - } -} // setCompleteServices + char cdata[2]; + switch (uuid.bitSize()) { + case 16: + { + // [Len] [0x02] [LL] [HH] + cdata[0] = 3; + cdata[1] = ESP_BLE_AD_TYPE_16SRV_CMPL; // 0x03 + addData(String(cdata, 2) + String((char*)&uuid.getNative()->uuid.uuid16, 2)); + break; + } + + case 32: + { + // [Len] [0x04] [LL] [LL] [HH] [HH] + cdata[0] = 5; + cdata[1] = ESP_BLE_AD_TYPE_32SRV_CMPL; // 0x05 + addData(String(cdata, 2) + String((char*)&uuid.getNative()->uuid.uuid32, 4)); + break; + } + + case 128: + { + // [Len] [0x04] [0] [1] ... [15] + cdata[0] = 17; + cdata[1] = ESP_BLE_AD_TYPE_128SRV_CMPL; // 0x07 + addData(String(cdata, 2) + String((char*)uuid.getNative()->uuid.uuid128, 16)); + break; + } + + default: + return; + } +} // setCompleteServices /** @@ -406,12 +406,12 @@ void BLEAdvertisementData::setCompleteServices(BLEUUID uuid) { * * ESP_BLE_ADV_FLAG_NON_LIMIT_DISC */ void BLEAdvertisementData::setFlags(uint8_t flag) { - char cdata[3]; - cdata[0] = 2; - cdata[1] = ESP_BLE_AD_TYPE_FLAG; // 0x01 - cdata[2] = flag; - addData(String(cdata, 3)); -} // setFlag + char cdata[3]; + cdata[0] = 2; + cdata[1] = ESP_BLE_AD_TYPE_FLAG; // 0x01 + cdata[2] = flag; + addData(String(cdata, 3)); +} // setFlag @@ -420,13 +420,13 @@ void BLEAdvertisementData::setFlags(uint8_t flag) { * @param [in] data Manufacturer data. */ void BLEAdvertisementData::setManufacturerData(String data) { - log_d("BLEAdvertisementData", ">> setManufacturerData"); - char cdata[2]; - cdata[0] = data.length() + 1; - cdata[1] = ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE; // 0xff - addData(String(cdata, 2) + data); - log_d("BLEAdvertisementData", "<< setManufacturerData"); -} // setManufacturerData + log_d("BLEAdvertisementData", ">> setManufacturerData"); + char cdata[2]; + cdata[0] = data.length() + 1; + cdata[1] = ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE; // 0xff + addData(String(cdata, 2) + data); + log_d("BLEAdvertisementData", "<< setManufacturerData"); +} // setManufacturerData /** @@ -434,13 +434,13 @@ void BLEAdvertisementData::setManufacturerData(String data) { * @param [in] The complete name of the device. */ void BLEAdvertisementData::setName(String name) { - log_d("BLEAdvertisementData", ">> setName: %s", name.c_str()); - char cdata[2]; - cdata[0] = name.length() + 1; - cdata[1] = ESP_BLE_AD_TYPE_NAME_CMPL; // 0x09 - addData(String(cdata, 2) + name); - log_d("BLEAdvertisementData", "<< setName"); -} // setName + log_d("BLEAdvertisementData", ">> setName: %s", name.c_str()); + char cdata[2]; + cdata[0] = name.length() + 1; + cdata[1] = ESP_BLE_AD_TYPE_NAME_CMPL; // 0x09 + addData(String(cdata, 2) + name); + log_d("BLEAdvertisementData", "<< setName"); +} // setName /** @@ -448,36 +448,39 @@ void BLEAdvertisementData::setName(String name) { * @param [in] uuid The single service to advertise. */ void BLEAdvertisementData::setPartialServices(BLEUUID uuid) { - char cdata[2]; - switch (uuid.bitSize()) { - case 16: { - // [Len] [0x02] [LL] [HH] - cdata[0] = 3; - cdata[1] = ESP_BLE_AD_TYPE_16SRV_PART; // 0x02 - addData(String(cdata, 2) + String((char *) &uuid.getNative()->uuid.uuid16, 2)); - break; - } - - case 32: { - // [Len] [0x04] [LL] [LL] [HH] [HH] - cdata[0] = 5; - cdata[1] = ESP_BLE_AD_TYPE_32SRV_PART; // 0x04 - addData(String(cdata, 2) + String((char *) &uuid.getNative()->uuid.uuid32, 4)); - break; - } - - case 128: { - // [Len] [0x04] [0] [1] ... [15] - cdata[0] = 17; - cdata[1] = ESP_BLE_AD_TYPE_128SRV_PART; // 0x06 - addData(String(cdata, 2) + String((char *) &uuid.getNative()->uuid.uuid128, 16)); - break; - } - - default: - return; - } -} // setPartialServices + char cdata[2]; + switch (uuid.bitSize()) { + case 16: + { + // [Len] [0x02] [LL] [HH] + cdata[0] = 3; + cdata[1] = ESP_BLE_AD_TYPE_16SRV_PART; // 0x02 + addData(String(cdata, 2) + String((char*)&uuid.getNative()->uuid.uuid16, 2)); + break; + } + + case 32: + { + // [Len] [0x04] [LL] [LL] [HH] [HH] + cdata[0] = 5; + cdata[1] = ESP_BLE_AD_TYPE_32SRV_PART; // 0x04 + addData(String(cdata, 2) + String((char*)&uuid.getNative()->uuid.uuid32, 4)); + break; + } + + case 128: + { + // [Len] [0x04] [0] [1] ... [15] + cdata[0] = 17; + cdata[1] = ESP_BLE_AD_TYPE_128SRV_PART; // 0x06 + addData(String(cdata, 2) + String((char*)&uuid.getNative()->uuid.uuid128, 16)); + break; + } + + default: + return; + } +} // setPartialServices /** @@ -486,36 +489,39 @@ void BLEAdvertisementData::setPartialServices(BLEUUID uuid) { * @param [in] data The data to be associated with the service data advert. */ void BLEAdvertisementData::setServiceData(BLEUUID uuid, String data) { - char cdata[2]; - switch (uuid.bitSize()) { - case 16: { - // [Len] [0x16] [UUID16] data - cdata[0] = data.length() + 3; - cdata[1] = ESP_BLE_AD_TYPE_SERVICE_DATA; // 0x16 - addData(String(cdata, 2) + String((char*) &uuid.getNative()->uuid.uuid16, 2) + data); - break; - } - - case 32: { - // [Len] [0x20] [UUID32] data - cdata[0] = data.length() + 5; - cdata[1] = ESP_BLE_AD_TYPE_32SERVICE_DATA; // 0x20 - addData(String(cdata, 2) + String((char*) &uuid.getNative()->uuid.uuid32, 4) + data); - break; - } - - case 128: { - // [Len] [0x21] [UUID128] data - cdata[0] = data.length() + 17; - cdata[1] = ESP_BLE_AD_TYPE_128SERVICE_DATA; // 0x21 - addData(String(cdata, 2) + String((char*) &uuid.getNative()->uuid.uuid128, 16) + data); - break; - } - - default: - return; - } -} // setServiceData + char cdata[2]; + switch (uuid.bitSize()) { + case 16: + { + // [Len] [0x16] [UUID16] data + cdata[0] = data.length() + 3; + cdata[1] = ESP_BLE_AD_TYPE_SERVICE_DATA; // 0x16 + addData(String(cdata, 2) + String((char*)&uuid.getNative()->uuid.uuid16, 2) + data); + break; + } + + case 32: + { + // [Len] [0x20] [UUID32] data + cdata[0] = data.length() + 5; + cdata[1] = ESP_BLE_AD_TYPE_32SERVICE_DATA; // 0x20 + addData(String(cdata, 2) + String((char*)&uuid.getNative()->uuid.uuid32, 4) + data); + break; + } + + case 128: + { + // [Len] [0x21] [UUID128] data + cdata[0] = data.length() + 17; + cdata[1] = ESP_BLE_AD_TYPE_128SERVICE_DATA; // 0x21 + addData(String(cdata, 2) + String((char*)&uuid.getNative()->uuid.uuid128, 16) + data); + break; + } + + default: + return; + } +} // setServiceData /** @@ -523,13 +529,13 @@ void BLEAdvertisementData::setServiceData(BLEUUID uuid, String data) { * @param [in] The short name of the device. */ void BLEAdvertisementData::setShortName(String name) { - log_d("BLEAdvertisementData", ">> setShortName: %s", name.c_str()); - char cdata[2]; - cdata[0] = name.length() + 1; - cdata[1] = ESP_BLE_AD_TYPE_NAME_SHORT; // 0x08 - addData(String(cdata, 2) + name); - log_d("BLEAdvertisementData", "<< setShortName"); -} // setShortName + log_d("BLEAdvertisementData", ">> setShortName: %s", name.c_str()); + char cdata[2]; + cdata[0] = name.length() + 1; + cdata[1] = ESP_BLE_AD_TYPE_NAME_SHORT; // 0x08 + addData(String(cdata, 2) + name); + log_d("BLEAdvertisementData", "<< setShortName"); +} // setShortName /** @@ -537,36 +543,40 @@ void BLEAdvertisementData::setShortName(String name) { * @return The payload that is to be advertised. */ String BLEAdvertisementData::getPayload() { - return m_payload; -} // getPayload + return m_payload; +} // getPayload void BLEAdvertising::handleGAPEvent( - esp_gap_ble_cb_event_t event, - esp_ble_gap_cb_param_t* param) { - - log_d("handleGAPEvent [event no: %d]", (int)event); - - switch(event) { - case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: { - // m_semaphoreSetAdv.give(); - break; - } - case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT: { - // m_semaphoreSetAdv.give(); - break; - } - case ESP_GAP_BLE_ADV_START_COMPLETE_EVT: { - // m_semaphoreSetAdv.give(); - break; - } - case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT: { - log_i("STOP advertising"); - //start(); - break; - } - default: - break; - } + esp_gap_ble_cb_event_t event, + esp_ble_gap_cb_param_t* param) { + + log_d("handleGAPEvent [event no: %d]", (int)event); + + switch (event) { + case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: + { + // m_semaphoreSetAdv.give(); + break; + } + case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT: + { + // m_semaphoreSetAdv.give(); + break; + } + case ESP_GAP_BLE_ADV_START_COMPLETE_EVT: + { + // m_semaphoreSetAdv.give(); + break; + } + case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT: + { + log_i("STOP advertising"); + //start(); + break; + } + default: + break; + } } #ifdef SOC_BLE_50_SUPPORTED @@ -578,11 +588,10 @@ void BLEAdvertising::handleGAPEvent( * * */ -BLEMultiAdvertising::BLEMultiAdvertising(uint8_t num) -{ - params_arrays = (esp_ble_gap_ext_adv_params_t*)calloc(num, sizeof(esp_ble_gap_ext_adv_params_t)); - ext_adv = (esp_ble_gap_ext_adv_t*)calloc(num, sizeof(esp_ble_gap_ext_adv_t)); - count = num; +BLEMultiAdvertising::BLEMultiAdvertising(uint8_t num) { + params_arrays = (esp_ble_gap_ext_adv_params_t*)calloc(num, sizeof(esp_ble_gap_ext_adv_params_t)); + ext_adv = (esp_ble_gap_ext_adv_t*)calloc(num, sizeof(esp_ble_gap_ext_adv_t)); + count = num; } /** @@ -595,13 +604,12 @@ BLEMultiAdvertising::BLEMultiAdvertising(uint8_t num) * - false : failed * */ -bool BLEMultiAdvertising::setAdvertisingParams(uint8_t instance, const esp_ble_gap_ext_adv_params_t* params) -{ - if (params->type == ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_IND && params->primary_phy == ESP_BLE_GAP_PHY_2M) return false; - esp_err_t rc; - rc = esp_ble_gap_ext_adv_set_params(instance, params); +bool BLEMultiAdvertising::setAdvertisingParams(uint8_t instance, const esp_ble_gap_ext_adv_params_t* params) { + if (params->type == ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_IND && params->primary_phy == ESP_BLE_GAP_PHY_2M) return false; + esp_err_t rc; + rc = esp_ble_gap_ext_adv_set_params(instance, params); - return ESP_OK == rc; + return ESP_OK == rc; } /** @@ -615,22 +623,20 @@ bool BLEMultiAdvertising::setAdvertisingParams(uint8_t instance, const esp_ble_g * - false : failed * */ -bool BLEMultiAdvertising::setAdvertisingData(uint8_t instance, uint16_t length, const uint8_t* data) -{ - esp_err_t rc; - rc = esp_ble_gap_config_ext_adv_data_raw(instance, length, data); - if (rc) log_e("set advertising data err: %d", rc); +bool BLEMultiAdvertising::setAdvertisingData(uint8_t instance, uint16_t length, const uint8_t* data) { + esp_err_t rc; + rc = esp_ble_gap_config_ext_adv_data_raw(instance, length, data); + if (rc) log_e("set advertising data err: %d", rc); - return ESP_OK == rc; + return ESP_OK == rc; } -bool BLEMultiAdvertising::setScanRspData(uint8_t instance, uint16_t length, const uint8_t* data) -{ - esp_err_t rc; - rc = esp_ble_gap_config_ext_scan_rsp_data_raw(instance, length, data); - if (rc) log_e("set scan resp data err: %d", rc); +bool BLEMultiAdvertising::setScanRspData(uint8_t instance, uint16_t length, const uint8_t* data) { + esp_err_t rc; + rc = esp_ble_gap_config_ext_scan_rsp_data_raw(instance, length, data); + if (rc) log_e("set scan resp data err: %d", rc); - return ESP_OK == rc; + return ESP_OK == rc; } /** @@ -641,9 +647,8 @@ bool BLEMultiAdvertising::setScanRspData(uint8_t instance, uint16_t length, cons * - false : failed * */ -bool BLEMultiAdvertising::start() -{ - return start(count, 0); +bool BLEMultiAdvertising::start() { + return start(count, 0); } /** @@ -657,15 +662,14 @@ bool BLEMultiAdvertising::start() * - false : failed * */ -bool BLEMultiAdvertising::start(uint8_t num, uint8_t from) -{ - if (num > count || from >= count) return false; +bool BLEMultiAdvertising::start(uint8_t num, uint8_t from) { + if (num > count || from >= count) return false; - esp_err_t rc; - rc = esp_ble_gap_ext_adv_start(num, &ext_adv[from]); - if (rc) log_e("start extended advertising err: %d", rc); + esp_err_t rc; + rc = esp_ble_gap_ext_adv_start(num, &ext_adv[from]); + if (rc) log_e("start extended advertising err: %d", rc); - return ESP_OK == rc; + return ESP_OK == rc; } /** @@ -679,13 +683,12 @@ bool BLEMultiAdvertising::start(uint8_t num, uint8_t from) * - other : failed * */ -bool BLEMultiAdvertising::stop(uint8_t num_adv, const uint8_t* ext_adv_inst) -{ - esp_err_t rc; - rc = esp_ble_gap_ext_adv_stop(num_adv, ext_adv_inst); - if (rc) log_e("stop extended advertising err: %d", rc); +bool BLEMultiAdvertising::stop(uint8_t num_adv, const uint8_t* ext_adv_inst) { + esp_err_t rc; + rc = esp_ble_gap_ext_adv_stop(num_adv, ext_adv_inst); + if (rc) log_e("stop extended advertising err: %d", rc); - return ESP_OK == rc; + return ESP_OK == rc; } /** @@ -697,13 +700,12 @@ bool BLEMultiAdvertising::stop(uint8_t num_adv, const uint8_t* ext_adv_inst) * - other : failed * */ -bool BLEMultiAdvertising::remove(uint8_t instance) -{ - esp_err_t rc; - rc = esp_ble_gap_ext_adv_set_remove(instance); - if (rc) log_e("remove extended advertising err: %d", rc); +bool BLEMultiAdvertising::remove(uint8_t instance) { + esp_err_t rc; + rc = esp_ble_gap_ext_adv_set_remove(instance); + if (rc) log_e("remove extended advertising err: %d", rc); - return ESP_OK == rc; + return ESP_OK == rc; } /** @@ -714,13 +716,12 @@ bool BLEMultiAdvertising::remove(uint8_t instance) * - other : failed * */ -bool BLEMultiAdvertising::clear() -{ - esp_err_t rc; - rc = esp_ble_gap_ext_adv_set_clear(); - if (rc) log_e("clear extended advertising err: %d", rc); +bool BLEMultiAdvertising::clear() { + esp_err_t rc; + rc = esp_ble_gap_ext_adv_set_clear(); + if (rc) log_e("clear extended advertising err: %d", rc); - return ESP_OK == rc; + return ESP_OK == rc; } /** @@ -733,13 +734,12 @@ bool BLEMultiAdvertising::clear() * - false : failed * */ -bool BLEMultiAdvertising::setInstanceAddress(uint8_t instance, uint8_t* addr_legacy) -{ - esp_err_t rc; - rc = esp_ble_gap_ext_adv_set_rand_addr(instance, addr_legacy); - if (rc) log_e("set random address err: %d", rc); +bool BLEMultiAdvertising::setInstanceAddress(uint8_t instance, uint8_t* addr_legacy) { + esp_err_t rc; + rc = esp_ble_gap_ext_adv_set_rand_addr(instance, addr_legacy); + if (rc) log_e("set random address err: %d", rc); - return ESP_OK == rc; + return ESP_OK == rc; } /** @@ -752,13 +752,12 @@ bool BLEMultiAdvertising::setInstanceAddress(uint8_t instance, uint8_t* addr_leg * - false : failed * */ -bool BLEMultiAdvertising::setPeriodicAdvertisingParams(uint8_t instance, const esp_ble_gap_periodic_adv_params_t* params) -{ - esp_err_t rc; - rc = esp_ble_gap_periodic_adv_set_params(instance, params); - if (rc) log_e("set periodic advertising params err: %d", rc); +bool BLEMultiAdvertising::setPeriodicAdvertisingParams(uint8_t instance, const esp_ble_gap_periodic_adv_params_t* params) { + esp_err_t rc; + rc = esp_ble_gap_periodic_adv_set_params(instance, params); + if (rc) log_e("set periodic advertising params err: %d", rc); - return ESP_OK == rc; + return ESP_OK == rc; } /** @@ -772,13 +771,12 @@ bool BLEMultiAdvertising::setPeriodicAdvertisingParams(uint8_t instance, const e * - false : failed * */ -bool BLEMultiAdvertising::setPeriodicAdvertisingData(uint8_t instance, uint16_t length, const uint8_t* data) -{ - esp_err_t rc; - rc = esp_ble_gap_config_periodic_adv_data_raw(instance, length, data); - if (rc) log_e("set periodic advertising raw data err: %d", rc); +bool BLEMultiAdvertising::setPeriodicAdvertisingData(uint8_t instance, uint16_t length, const uint8_t* data) { + esp_err_t rc; + rc = esp_ble_gap_config_periodic_adv_data_raw(instance, length, data); + if (rc) log_e("set periodic advertising raw data err: %d", rc); - return ESP_OK == rc; + return ESP_OK == rc; } /** @@ -790,21 +788,19 @@ bool BLEMultiAdvertising::setPeriodicAdvertisingData(uint8_t instance, uint16_t * - false : failed * */ -bool BLEMultiAdvertising::startPeriodicAdvertising(uint8_t instance) -{ - esp_err_t rc; - rc = esp_ble_gap_periodic_adv_start(instance); - if (rc) log_e("start periodic advertising err: %d", rc); +bool BLEMultiAdvertising::startPeriodicAdvertising(uint8_t instance) { + esp_err_t rc; + rc = esp_ble_gap_periodic_adv_start(instance); + if (rc) log_e("start periodic advertising err: %d", rc); - return ESP_OK == rc; + return ESP_OK == rc; } -void BLEMultiAdvertising::setDuration(uint8_t instance, int duration, int max_events) -{ - ext_adv[instance] = { instance, duration, max_events }; +void BLEMultiAdvertising::setDuration(uint8_t instance, int duration, int max_events) { + ext_adv[instance] = { instance, duration, max_events }; } -#endif // SOC_BLE_50_SUPPORTED +#endif // SOC_BLE_50_SUPPORTED #endif /* CONFIG_BLUEDROID_ENABLED */ #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLEAdvertising.h b/libraries/BLE/src/BLEAdvertising.h index b10c0228698..7dda327735b 100644 --- a/libraries/BLE/src/BLEAdvertising.h +++ b/libraries/BLE/src/BLEAdvertising.h @@ -21,25 +21,25 @@ * @brief Advertisement data set by the programmer to be published by the %BLE server. */ class BLEAdvertisementData { - // Only a subset of the possible BLE architected advertisement fields are currently exposed. Others will - // be exposed on demand/request or as time permits. - // + // Only a subset of the possible BLE architected advertisement fields are currently exposed. Others will + // be exposed on demand/request or as time permits. + // public: - void setAppearance(uint16_t appearance); - void setCompleteServices(BLEUUID uuid); - void setFlags(uint8_t); - void setManufacturerData(String data); - void setName(String name); - void setPartialServices(BLEUUID uuid); - void setServiceData(BLEUUID uuid, String data); - void setShortName(String name); - void addData(String data); // Add data to the payload. - String getPayload(); // Retrieve the current advert payload. + void setAppearance(uint16_t appearance); + void setCompleteServices(BLEUUID uuid); + void setFlags(uint8_t); + void setManufacturerData(String data); + void setName(String name); + void setPartialServices(BLEUUID uuid); + void setServiceData(BLEUUID uuid, String data); + void setShortName(String name); + void addData(String data); // Add data to the payload. + String getPayload(); // Retrieve the current advert payload. private: - friend class BLEAdvertising; - String m_payload; // The payload of the advertisement. -}; // BLEAdvertisementData + friend class BLEAdvertising; + String m_payload; // The payload of the advertisement. +}; // BLEAdvertisementData /** @@ -49,71 +49,69 @@ class BLEAdvertisementData { */ class BLEAdvertising { public: - BLEAdvertising(); - void addServiceUUID(BLEUUID serviceUUID); - void addServiceUUID(const char* serviceUUID); - bool removeServiceUUID(int index); - bool removeServiceUUID(BLEUUID serviceUUID); - bool removeServiceUUID(const char* serviceUUID); - void start(); - void stop(); - void setAppearance(uint16_t appearance); - void setAdvertisementType(esp_ble_adv_type_t adv_type); - void setAdvertisementChannelMap(esp_ble_adv_channel_t channel_map); - void setMaxInterval(uint16_t maxinterval); - void setMinInterval(uint16_t mininterval); - void setAdvertisementData(BLEAdvertisementData& advertisementData); - void setScanFilter(bool scanRequertWhitelistOnly, bool connectWhitelistOnly); - void setScanResponseData(BLEAdvertisementData& advertisementData); - void setPrivateAddress(esp_ble_addr_type_t type = BLE_ADDR_TYPE_RANDOM); - void setDeviceAddress(esp_bd_addr_t addr, esp_ble_addr_type_t type = BLE_ADDR_TYPE_RANDOM); + BLEAdvertising(); + void addServiceUUID(BLEUUID serviceUUID); + void addServiceUUID(const char* serviceUUID); + bool removeServiceUUID(int index); + bool removeServiceUUID(BLEUUID serviceUUID); + bool removeServiceUUID(const char* serviceUUID); + void start(); + void stop(); + void setAppearance(uint16_t appearance); + void setAdvertisementType(esp_ble_adv_type_t adv_type); + void setAdvertisementChannelMap(esp_ble_adv_channel_t channel_map); + void setMaxInterval(uint16_t maxinterval); + void setMinInterval(uint16_t mininterval); + void setAdvertisementData(BLEAdvertisementData& advertisementData); + void setScanFilter(bool scanRequertWhitelistOnly, bool connectWhitelistOnly); + void setScanResponseData(BLEAdvertisementData& advertisementData); + void setPrivateAddress(esp_ble_addr_type_t type = BLE_ADDR_TYPE_RANDOM); + void setDeviceAddress(esp_bd_addr_t addr, esp_ble_addr_type_t type = BLE_ADDR_TYPE_RANDOM); - void handleGAPEvent(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param); - void setMinPreferred(uint16_t); - void setMaxPreferred(uint16_t); - void setScanResponse(bool); + void handleGAPEvent(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param); + void setMinPreferred(uint16_t); + void setMaxPreferred(uint16_t); + void setScanResponse(bool); private: - esp_ble_adv_data_t m_advData; - esp_ble_adv_data_t m_scanRespData; // Used for configuration of scan response data when m_scanResp is true - esp_ble_adv_params_t m_advParams; - std::vector m_serviceUUIDs; - bool m_customAdvData = false; // Are we using custom advertising data? - bool m_customScanResponseData = false; // Are we using custom scan response data? - FreeRTOS::Semaphore m_semaphoreSetAdv = FreeRTOS::Semaphore("startAdvert"); - bool m_scanResp = true; - + esp_ble_adv_data_t m_advData; + esp_ble_adv_data_t m_scanRespData; // Used for configuration of scan response data when m_scanResp is true + esp_ble_adv_params_t m_advParams; + std::vector m_serviceUUIDs; + bool m_customAdvData = false; // Are we using custom advertising data? + bool m_customScanResponseData = false; // Are we using custom scan response data? + FreeRTOS::Semaphore m_semaphoreSetAdv = FreeRTOS::Semaphore("startAdvert"); + bool m_scanResp = true; }; #ifdef SOC_BLE_50_SUPPORTED -class BLEMultiAdvertising -{ +class BLEMultiAdvertising { private: - esp_ble_gap_ext_adv_params_t* params_arrays; - esp_ble_gap_ext_adv_t* ext_adv; - uint8_t count; + esp_ble_gap_ext_adv_params_t* params_arrays; + esp_ble_gap_ext_adv_t* ext_adv; + uint8_t count; public: - BLEMultiAdvertising(uint8_t num = 1); - ~BLEMultiAdvertising() {} + BLEMultiAdvertising(uint8_t num = 1); + ~BLEMultiAdvertising() {} - bool setAdvertisingParams(uint8_t instance, const esp_ble_gap_ext_adv_params_t* params); - bool setAdvertisingData(uint8_t instance, uint16_t length, const uint8_t* data); - bool setScanRspData(uint8_t instance, uint16_t length, const uint8_t* data); - bool start(); - bool start(uint8_t num, uint8_t from); - void setDuration(uint8_t instance, int duration = 0, int max_events = 0); - bool setInstanceAddress(uint8_t instance, esp_bd_addr_t rand_addr); - bool stop(uint8_t num_adv, const uint8_t* ext_adv_inst); - bool remove(uint8_t instance); - bool clear(); - bool setPeriodicAdvertisingParams(uint8_t instance, const esp_ble_gap_periodic_adv_params_t* params); - bool setPeriodicAdvertisingData(uint8_t instance, uint16_t length, const uint8_t* data); - bool startPeriodicAdvertising(uint8_t instance); + bool setAdvertisingParams(uint8_t instance, const esp_ble_gap_ext_adv_params_t* params); + bool setAdvertisingData(uint8_t instance, uint16_t length, const uint8_t* data); + bool setScanRspData(uint8_t instance, uint16_t length, const uint8_t* data); + bool start(); + bool start(uint8_t num, uint8_t from); + void setDuration(uint8_t instance, int duration = 0, int max_events = 0); + bool setInstanceAddress(uint8_t instance, esp_bd_addr_t rand_addr); + bool stop(uint8_t num_adv, const uint8_t* ext_adv_inst); + bool remove(uint8_t instance); + bool clear(); + bool setPeriodicAdvertisingParams(uint8_t instance, const esp_ble_gap_periodic_adv_params_t* params); + bool setPeriodicAdvertisingData(uint8_t instance, uint16_t length, const uint8_t* data); + bool startPeriodicAdvertising(uint8_t instance); }; -#endif // SOC_BLE_50_SUPPORTED +#endif // SOC_BLE_50_SUPPORTED #endif /* CONFIG_BLUEDROID_ENABLED */ #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLEBeacon.cpp b/libraries/BLE/src/BLEBeacon.cpp index 641ac47cd8c..1ae2b62bb40 100644 --- a/libraries/BLE/src/BLEBeacon.cpp +++ b/libraries/BLE/src/BLEBeacon.cpp @@ -12,74 +12,74 @@ #include "BLEBeacon.h" #include "esp32-hal-log.h" -#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00)>>8) + (((x)&0xFF)<<8)) +#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00) >> 8) + (((x)&0xFF) << 8)) BLEBeacon::BLEBeacon() { - m_beaconData.manufacturerId = 0x4c00; - m_beaconData.subType = 0x02; - m_beaconData.subTypeLength = 0x15; - m_beaconData.major = 0; - m_beaconData.minor = 0; - m_beaconData.signalPower = 0; - memset(m_beaconData.proximityUUID, 0, sizeof(m_beaconData.proximityUUID)); -} // BLEBeacon + m_beaconData.manufacturerId = 0x4c00; + m_beaconData.subType = 0x02; + m_beaconData.subTypeLength = 0x15; + m_beaconData.major = 0; + m_beaconData.minor = 0; + m_beaconData.signalPower = 0; + memset(m_beaconData.proximityUUID, 0, sizeof(m_beaconData.proximityUUID)); +} // BLEBeacon String BLEBeacon::getData() { - return String((char*) &m_beaconData, sizeof(m_beaconData)); -} // getData + return String((char*)&m_beaconData, sizeof(m_beaconData)); +} // getData uint16_t BLEBeacon::getMajor() { - return m_beaconData.major; + return m_beaconData.major; } uint16_t BLEBeacon::getManufacturerId() { - return m_beaconData.manufacturerId; + return m_beaconData.manufacturerId; } uint16_t BLEBeacon::getMinor() { - return m_beaconData.minor; + return m_beaconData.minor; } BLEUUID BLEBeacon::getProximityUUID() { - return BLEUUID(m_beaconData.proximityUUID, 16, true); + return BLEUUID(m_beaconData.proximityUUID, 16, true); } int8_t BLEBeacon::getSignalPower() { - return m_beaconData.signalPower; + return m_beaconData.signalPower; } /** * Set the raw data for the beacon record. */ void BLEBeacon::setData(String data) { - if (data.length() != sizeof(m_beaconData)) { - log_e("Unable to set the data ... length passed in was %d and expected %d", data.length(), sizeof(m_beaconData)); - return; - } - memcpy(&m_beaconData, data.c_str(), sizeof(m_beaconData)); -} // setData + if (data.length() != sizeof(m_beaconData)) { + log_e("Unable to set the data ... length passed in was %d and expected %d", data.length(), sizeof(m_beaconData)); + return; + } + memcpy(&m_beaconData, data.c_str(), sizeof(m_beaconData)); +} // setData void BLEBeacon::setMajor(uint16_t major) { - m_beaconData.major = ENDIAN_CHANGE_U16(major); -} // setMajor + m_beaconData.major = ENDIAN_CHANGE_U16(major); +} // setMajor void BLEBeacon::setManufacturerId(uint16_t manufacturerId) { - m_beaconData.manufacturerId = ENDIAN_CHANGE_U16(manufacturerId); -} // setManufacturerId + m_beaconData.manufacturerId = ENDIAN_CHANGE_U16(manufacturerId); +} // setManufacturerId void BLEBeacon::setMinor(uint16_t minor) { - m_beaconData.minor = ENDIAN_CHANGE_U16(minor); -} // setMinior + m_beaconData.minor = ENDIAN_CHANGE_U16(minor); +} // setMinior void BLEBeacon::setProximityUUID(BLEUUID uuid) { - uuid = uuid.to128(); - memcpy(m_beaconData.proximityUUID, uuid.getNative()->uuid.uuid128, 16); -} // setProximityUUID + uuid = uuid.to128(); + memcpy(m_beaconData.proximityUUID, uuid.getNative()->uuid.uuid128, 16); +} // setProximityUUID void BLEBeacon::setSignalPower(int8_t signalPower) { - m_beaconData.signalPower = signalPower; -} // setSignalPower + m_beaconData.signalPower = signalPower; +} // setSignalPower #endif diff --git a/libraries/BLE/src/BLEBeacon.h b/libraries/BLE/src/BLEBeacon.h index 2adcda6abcb..ee8d8244d59 100644 --- a/libraries/BLE/src/BLEBeacon.h +++ b/libraries/BLE/src/BLEBeacon.h @@ -18,30 +18,30 @@ */ class BLEBeacon { private: - struct { - uint16_t manufacturerId; - uint8_t subType; - uint8_t subTypeLength; - uint8_t proximityUUID[16]; - uint16_t major; - uint16_t minor; - int8_t signalPower; - } __attribute__((packed)) m_beaconData; + struct { + uint16_t manufacturerId; + uint8_t subType; + uint8_t subTypeLength; + uint8_t proximityUUID[16]; + uint16_t major; + uint16_t minor; + int8_t signalPower; + } __attribute__((packed)) m_beaconData; public: - BLEBeacon(); - String getData(); - uint16_t getMajor(); - uint16_t getMinor(); - uint16_t getManufacturerId(); - BLEUUID getProximityUUID(); - int8_t getSignalPower(); - void setData(String data); - void setMajor(uint16_t major); - void setMinor(uint16_t minor); - void setManufacturerId(uint16_t manufacturerId); - void setProximityUUID(BLEUUID uuid); - void setSignalPower(int8_t signalPower); -}; // BLEBeacon + BLEBeacon(); + String getData(); + uint16_t getMajor(); + uint16_t getMinor(); + uint16_t getManufacturerId(); + BLEUUID getProximityUUID(); + int8_t getSignalPower(); + void setData(String data); + void setMajor(uint16_t major); + void setMinor(uint16_t minor); + void setManufacturerId(uint16_t manufacturerId); + void setProximityUUID(BLEUUID uuid); + void setSignalPower(int8_t signalPower); +}; // BLEBeacon #endif /* SOC_BLE_SUPPORTED */ #endif /* COMPONENTS_CPP_UTILS_BLEBEACON_H_ */ diff --git a/libraries/BLE/src/BLECharacteristic.cpp b/libraries/BLE/src/BLECharacteristic.cpp index d4ac6a7039b..b07e915a051 100644 --- a/libraries/BLE/src/BLECharacteristic.cpp +++ b/libraries/BLE/src/BLECharacteristic.cpp @@ -25,14 +25,15 @@ #define NULL_HANDLE (0xffff) -static BLECharacteristicCallbacks defaultCallback; //null-object-pattern +static BLECharacteristicCallbacks defaultCallback; //null-object-pattern /** * @brief Construct a characteristic * @param [in] uuid - UUID (const char*) for the characteristic. * @param [in] properties - Properties for the characteristic. */ -BLECharacteristic::BLECharacteristic(const char* uuid, uint32_t properties) : BLECharacteristic(BLEUUID(uuid), properties) { +BLECharacteristic::BLECharacteristic(const char* uuid, uint32_t properties) + : BLECharacteristic(BLEUUID(uuid), properties) { } /** @@ -41,25 +42,25 @@ BLECharacteristic::BLECharacteristic(const char* uuid, uint32_t properties) : BL * @param [in] properties - Properties for the characteristic. */ BLECharacteristic::BLECharacteristic(BLEUUID uuid, uint32_t properties) { - m_bleUUID = uuid; - m_handle = NULL_HANDLE; - m_properties = (esp_gatt_char_prop_t)0; - m_pCallbacks = &defaultCallback; - - setBroadcastProperty((properties & PROPERTY_BROADCAST) != 0); - setReadProperty((properties & PROPERTY_READ) != 0); - setWriteProperty((properties & PROPERTY_WRITE) != 0); - setNotifyProperty((properties & PROPERTY_NOTIFY) != 0); - setIndicateProperty((properties & PROPERTY_INDICATE) != 0); - setWriteNoResponseProperty((properties & PROPERTY_WRITE_NR) != 0); -} // BLECharacteristic + m_bleUUID = uuid; + m_handle = NULL_HANDLE; + m_properties = (esp_gatt_char_prop_t)0; + m_pCallbacks = &defaultCallback; + + setBroadcastProperty((properties & PROPERTY_BROADCAST) != 0); + setReadProperty((properties & PROPERTY_READ) != 0); + setWriteProperty((properties & PROPERTY_WRITE) != 0); + setNotifyProperty((properties & PROPERTY_NOTIFY) != 0); + setIndicateProperty((properties & PROPERTY_INDICATE) != 0); + setWriteNoResponseProperty((properties & PROPERTY_WRITE_NR) != 0); +} // BLECharacteristic /** * @brief Destructor. */ BLECharacteristic::~BLECharacteristic() { - //free(m_value.attr_value); // Release the storage for the value. -} // ~BLECharacteristic + //free(m_value.attr_value); // Release the storage for the value. +} // ~BLECharacteristic /** @@ -68,10 +69,10 @@ BLECharacteristic::~BLECharacteristic() { * @return N/A. */ void BLECharacteristic::addDescriptor(BLEDescriptor* pDescriptor) { - log_v(">> addDescriptor(): Adding %s to %s", pDescriptor->toString().c_str(), toString().c_str()); - m_descriptorMap.setByUUID(pDescriptor->getUUID(), pDescriptor); - log_v("<< addDescriptor()"); -} // addDescriptor + log_v(">> addDescriptor(): Adding %s to %s", pDescriptor->toString().c_str(), toString().c_str()); + m_descriptorMap.setByUUID(pDescriptor->getUUID(), pDescriptor); + log_v("<< addDescriptor()"); +} // addDescriptor /** @@ -79,45 +80,45 @@ void BLECharacteristic::addDescriptor(BLEDescriptor* pDescriptor) { * @param [in] pService The service with which to associate this characteristic. */ void BLECharacteristic::executeCreate(BLEService* pService) { - log_v(">> executeCreate()"); + log_v(">> executeCreate()"); - if (m_handle != NULL_HANDLE) { - log_e("Characteristic already has a handle."); - return; - } + if (m_handle != NULL_HANDLE) { + log_e("Characteristic already has a handle."); + return; + } - m_pService = pService; // Save the service to which this characteristic belongs. + m_pService = pService; // Save the service to which this characteristic belongs. - log_d("Registering characteristic (esp_ble_gatts_add_char): uuid: %s, service: %s", - getUUID().toString().c_str(), - m_pService->toString().c_str()); + log_d("Registering characteristic (esp_ble_gatts_add_char): uuid: %s, service: %s", + getUUID().toString().c_str(), + m_pService->toString().c_str()); - esp_attr_control_t control; - control.auto_rsp = ESP_GATT_RSP_BY_APP; + esp_attr_control_t control; + control.auto_rsp = ESP_GATT_RSP_BY_APP; - m_semaphoreCreateEvt.take("executeCreate"); - esp_err_t errRc = ::esp_ble_gatts_add_char( - m_pService->getHandle(), - getUUID().getNative(), - static_cast(m_permissions), - getProperties(), - nullptr, - &control); // Whether to auto respond or not. + m_semaphoreCreateEvt.take("executeCreate"); + esp_err_t errRc = ::esp_ble_gatts_add_char( + m_pService->getHandle(), + getUUID().getNative(), + static_cast(m_permissions), + getProperties(), + nullptr, + &control); // Whether to auto respond or not. - if (errRc != ESP_OK) { - log_e("<< esp_ble_gatts_add_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } - m_semaphoreCreateEvt.wait("executeCreate"); + if (errRc != ESP_OK) { + log_e("<< esp_ble_gatts_add_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } + m_semaphoreCreateEvt.wait("executeCreate"); - BLEDescriptor* pDescriptor = m_descriptorMap.getFirst(); - while (pDescriptor != nullptr) { - pDescriptor->executeCreate(this); - pDescriptor = m_descriptorMap.getNext(); - } // End while + BLEDescriptor* pDescriptor = m_descriptorMap.getFirst(); + while (pDescriptor != nullptr) { + pDescriptor->executeCreate(this); + pDescriptor = m_descriptorMap.getNext(); + } // End while - log_v("<< executeCreate"); -} // executeCreate + log_v("<< executeCreate"); +} // executeCreate /** @@ -126,8 +127,8 @@ void BLECharacteristic::executeCreate(BLEService* pService) { * @return The BLE Descriptor. If no such descriptor is associated with the characteristic, nullptr is returned. */ BLEDescriptor* BLECharacteristic::getDescriptorByUUID(const char* descriptorUUID) { - return m_descriptorMap.getByUUID(BLEUUID(descriptorUUID)); -} // getDescriptorByUUID + return m_descriptorMap.getByUUID(BLEUUID(descriptorUUID)); +} // getDescriptorByUUID /** @@ -136,8 +137,8 @@ BLEDescriptor* BLECharacteristic::getDescriptorByUUID(const char* descriptorUUID * @return The BLE Descriptor. If no such descriptor is associated with the characteristic, nullptr is returned. */ BLEDescriptor* BLECharacteristic::getDescriptorByUUID(BLEUUID descriptorUUID) { - return m_descriptorMap.getByUUID(descriptorUUID); -} // getDescriptorByUUID + return m_descriptorMap.getByUUID(descriptorUUID); +} // getDescriptorByUUID /** @@ -145,24 +146,24 @@ BLEDescriptor* BLECharacteristic::getDescriptorByUUID(BLEUUID descriptorUUID) { * @return The handle of the characteristic. */ uint16_t BLECharacteristic::getHandle() { - return m_handle; -} // getHandle + return m_handle; +} // getHandle void BLECharacteristic::setAccessPermissions(esp_gatt_perm_t perm) { - m_permissions = perm; + m_permissions = perm; } esp_gatt_char_prop_t BLECharacteristic::getProperties() { - return m_properties; -} // getProperties + return m_properties; +} // getProperties /** * @brief Get the service associated with this characteristic. */ BLEService* BLECharacteristic::getService() { - return m_pService; -} // getService + return m_pService; +} // getService /** @@ -170,8 +171,8 @@ BLEService* BLECharacteristic::getService() { * @return The UUID of the characteristic. */ BLEUUID BLECharacteristic::getUUID() { - return m_bleUUID; -} // getUUID + return m_bleUUID; +} // getUUID /** @@ -179,294 +180,302 @@ BLEUUID BLECharacteristic::getUUID() { * @return A pointer to storage containing the current characteristic value. */ String BLECharacteristic::getValue() { - return m_value.getValue(); -} // getValue + return m_value.getValue(); +} // getValue /** * @brief Retrieve the current raw data of the characteristic. * @return A pointer to storage containing the current characteristic data. */ uint8_t* BLECharacteristic::getData() { - return m_value.getData(); -} // getData + return m_value.getData(); +} // getData /** * @brief Retrieve the current length of the data of the characteristic. * @return Amount of databytes of the characteristic. */ size_t BLECharacteristic::getLength() { - return m_value.getLength(); -} // getLength + return m_value.getLength(); +} // getLength /** * Handle a GATT server event. */ void BLECharacteristic::handleGATTServerEvent( - esp_gatts_cb_event_t event, - esp_gatt_if_t gatts_if, - esp_ble_gatts_cb_param_t* param) { - log_v(">> handleGATTServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str()); - - switch(event) { - // Events handled: - // - // ESP_GATTS_ADD_CHAR_EVT - // ESP_GATTS_CONF_EVT - // ESP_GATTS_CONNECT_EVT - // ESP_GATTS_DISCONNECT_EVT - // ESP_GATTS_EXEC_WRITE_EVT - // ESP_GATTS_READ_EVT - // ESP_GATTS_WRITE_EVT - - // - // ESP_GATTS_EXEC_WRITE_EVT - // When we receive this event it is an indication that a previous write long needs to be committed. - // - // exec_write: - // - uint16_t conn_id - // - uint32_t trans_id - // - esp_bd_addr_t bda - // - uint8_t exec_write_flag - Either ESP_GATT_PREP_WRITE_EXEC or ESP_GATT_PREP_WRITE_CANCEL - // - case ESP_GATTS_EXEC_WRITE_EVT: { - if(m_writeEvt){ - m_writeEvt = false; - if (param->exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_EXEC) { - m_value.commit(); - // Invoke the onWrite callback handler. - m_pCallbacks->onWrite(this, param); - } else { - m_value.cancel(); - } - // ??? - esp_err_t errRc = ::esp_ble_gatts_send_response( - gatts_if, - param->write.conn_id, - param->write.trans_id, ESP_GATT_OK, nullptr); - if (errRc != ESP_OK) { - log_e("esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - } - } - break; - } // ESP_GATTS_EXEC_WRITE_EVT - - - // ESP_GATTS_ADD_CHAR_EVT - Indicate that a characteristic was added to the service. - // add_char: - // - esp_gatt_status_t status - // - uint16_t attr_handle - // - uint16_t service_handle - // - esp_bt_uuid_t char_uuid - case ESP_GATTS_ADD_CHAR_EVT: { - if (getHandle() == param->add_char.attr_handle) { - // we have created characteristic, now we can create descriptors - // BLEDescriptor* pDescriptor = m_descriptorMap.getFirst(); - // while (pDescriptor != nullptr) { - // pDescriptor->executeCreate(this); - // pDescriptor = m_descriptorMap.getNext(); - // } // End while - m_semaphoreCreateEvt.give(); - } - break; - } // ESP_GATTS_ADD_CHAR_EVT - - - // ESP_GATTS_WRITE_EVT - A request to write the value of a characteristic has arrived. - // - // write: - // - uint16_t conn_id - // - uint16_t trans_id - // - esp_bd_addr_t bda - // - uint16_t handle - // - uint16_t offset - // - bool need_rsp - // - bool is_prep - // - uint16_t len - // - uint8_t *value - // - case ESP_GATTS_WRITE_EVT: { -// We check if this write request is for us by comparing the handles in the event. If it is for us -// we save the new value. Next we look at the need_rsp flag which indicates whether or not we need -// to send a response. If we do, then we formulate a response and send it. - if (param->write.handle == m_handle) { - if (param->write.is_prep) { - m_value.addPart(param->write.value, param->write.len); - m_writeEvt = true; - } else { - setValue(param->write.value, param->write.len); - } - - log_d(" - Response to write event: New value: handle: %.2x, uuid: %s", - getHandle(), getUUID().toString().c_str()); - - char* pHexData = BLEUtils::buildHexData(nullptr, param->write.value, param->write.len); - log_d(" - Data: length: %d, data: %s", param->write.len, pHexData); - free(pHexData); - - if (param->write.need_rsp) { - esp_gatt_rsp_t rsp; - - rsp.attr_value.len = param->write.len; - rsp.attr_value.handle = m_handle; - rsp.attr_value.offset = param->write.offset; - rsp.attr_value.auth_req = ESP_GATT_AUTH_REQ_NONE; - memcpy(rsp.attr_value.value, param->write.value, param->write.len); - - esp_err_t errRc = ::esp_ble_gatts_send_response( - gatts_if, - param->write.conn_id, - param->write.trans_id, ESP_GATT_OK, &rsp); - if (errRc != ESP_OK) { - log_e("esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - } - } // Response needed - - if (param->write.is_prep != true) { - // Invoke the onWrite callback handler. - m_pCallbacks->onWrite(this, param); - } - } // Match on handles. - break; - } // ESP_GATTS_WRITE_EVT - - - // ESP_GATTS_READ_EVT - A request to read the value of a characteristic has arrived. - // - // read: - // - uint16_t conn_id - // - uint32_t trans_id - // - esp_bd_addr_t bda - // - uint16_t handle - // - uint16_t offset - // - bool is_long - // - bool need_rsp - // - case ESP_GATTS_READ_EVT: { - if (param->read.handle == m_handle) { - - - -// Here's an interesting thing. The read request has the option of saying whether we need a response -// or not. What would it "mean" to receive a read request and NOT send a response back? That feels like -// a very strange read. -// -// We have to handle the case where the data we wish to send back to the client is greater than the maximum -// packet size of 22 bytes. In this case, we become responsible for chunking the data into units of 22 bytes. -// The apparent algorithm is as follows: -// -// If the is_long flag is set then this is a follow on from an original read and we will already have sent at least 22 bytes. -// If the is_long flag is not set then we need to check how much data we are going to send. If we are sending LESS than -// 22 bytes, then we "just" send it and thats the end of the story. -// If we are sending 22 bytes exactly, we just send it BUT we will get a follow on request. -// If we are sending more than 22 bytes, we send the first 22 bytes and we will get a follow on request. -// Because of follow on request processing, we need to maintain an offset of how much data we have already sent -// so that when a follow on request arrives, we know where to start in the data to send the next sequence. -// Note that the indication that the client will send a follow on request is that we sent exactly 22 bytes as a response. -// If our payload is divisible by 22 then the last response will be a response of 0 bytes in length. -// -// The following code has deliberately not been factored to make it fewer statements because this would cloud the -// the logic flow comprehension. -// - - // get mtu for peer device that we are sending read request to - uint16_t maxOffset = getService()->getServer()->getPeerMTU(param->read.conn_id) - 1; - log_d("mtu value: %d", maxOffset); - if (param->read.need_rsp) { - log_d("Sending a response (esp_ble_gatts_send_response)"); - esp_gatt_rsp_t rsp; - - if (param->read.is_long) { - String value = m_value.getValue(); - - if (value.length() - m_value.getReadOffset() < maxOffset) { - // This is the last in the chain - rsp.attr_value.len = value.length() - m_value.getReadOffset(); - rsp.attr_value.offset = m_value.getReadOffset(); - memcpy(rsp.attr_value.value, value.c_str() + rsp.attr_value.offset, rsp.attr_value.len); - m_value.setReadOffset(0); - } else { - // There will be more to come. - rsp.attr_value.len = maxOffset; - rsp.attr_value.offset = m_value.getReadOffset(); - memcpy(rsp.attr_value.value, value.c_str() + rsp.attr_value.offset, rsp.attr_value.len); - m_value.setReadOffset(rsp.attr_value.offset + maxOffset); - } - } else { // read.is_long == false - - // If is.long is false then this is the first (or only) request to read data, so invoke the callback - // Invoke the read callback. - m_pCallbacks->onRead(this, param); - - String value = m_value.getValue(); - - if (value.length() + 1 > maxOffset) { - // Too big for a single shot entry. - m_value.setReadOffset(maxOffset); - rsp.attr_value.len = maxOffset; - rsp.attr_value.offset = 0; - memcpy(rsp.attr_value.value, value.c_str(), rsp.attr_value.len); - } else { - // Will fit in a single packet with no callbacks required. - rsp.attr_value.len = value.length(); - rsp.attr_value.offset = 0; - memcpy(rsp.attr_value.value, value.c_str(), rsp.attr_value.len); - } - } - rsp.attr_value.handle = param->read.handle; - rsp.attr_value.auth_req = ESP_GATT_AUTH_REQ_NONE; - - char *pHexData = BLEUtils::buildHexData(nullptr, rsp.attr_value.value, rsp.attr_value.len); - log_d(" - Data: length=%d, data=%s, offset=%d", rsp.attr_value.len, pHexData, rsp.attr_value.offset); - free(pHexData); - - esp_err_t errRc = ::esp_ble_gatts_send_response( - gatts_if, param->read.conn_id, - param->read.trans_id, - ESP_GATT_OK, - &rsp); - if (errRc != ESP_OK) { - log_e("esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - } - } // Response needed - } // Handle matches this characteristic. - break; - } // ESP_GATTS_READ_EVT - - - // ESP_GATTS_CONF_EVT - // - // conf: - // - esp_gatt_status_t status – The status code. - // - uint16_t conn_id – The connection used. - // - case ESP_GATTS_CONF_EVT: { - // log_d("m_handle = %d, conf->handle = %d", m_handle, param->conf.handle); - if(param->conf.conn_id == getService()->getServer()->getConnId()) // && param->conf.handle == m_handle) // bug in esp-idf and not implemented in arduino yet - m_semaphoreConfEvt.give(param->conf.status); - break; - } - - case ESP_GATTS_CONNECT_EVT: { - break; - } - - case ESP_GATTS_DISCONNECT_EVT: { - m_semaphoreConfEvt.give(); - break; - } - - default: { - break; - } // default - - } // switch event - - // Give each of the descriptors associated with this characteristic the opportunity to handle the - // event. - - m_descriptorMap.handleGATTServerEvent(event, gatts_if, param); - log_v("<< handleGATTServerEvent"); -} // handleGATTServerEvent + esp_gatts_cb_event_t event, + esp_gatt_if_t gatts_if, + esp_ble_gatts_cb_param_t* param) { + log_v(">> handleGATTServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str()); + + switch (event) { + // Events handled: + // + // ESP_GATTS_ADD_CHAR_EVT + // ESP_GATTS_CONF_EVT + // ESP_GATTS_CONNECT_EVT + // ESP_GATTS_DISCONNECT_EVT + // ESP_GATTS_EXEC_WRITE_EVT + // ESP_GATTS_READ_EVT + // ESP_GATTS_WRITE_EVT + + // + // ESP_GATTS_EXEC_WRITE_EVT + // When we receive this event it is an indication that a previous write long needs to be committed. + // + // exec_write: + // - uint16_t conn_id + // - uint32_t trans_id + // - esp_bd_addr_t bda + // - uint8_t exec_write_flag - Either ESP_GATT_PREP_WRITE_EXEC or ESP_GATT_PREP_WRITE_CANCEL + // + case ESP_GATTS_EXEC_WRITE_EVT: + { + if (m_writeEvt) { + m_writeEvt = false; + if (param->exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_EXEC) { + m_value.commit(); + // Invoke the onWrite callback handler. + m_pCallbacks->onWrite(this, param); + } else { + m_value.cancel(); + } + // ??? + esp_err_t errRc = ::esp_ble_gatts_send_response( + gatts_if, + param->write.conn_id, + param->write.trans_id, ESP_GATT_OK, nullptr); + if (errRc != ESP_OK) { + log_e("esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + } + } + break; + } // ESP_GATTS_EXEC_WRITE_EVT + + + // ESP_GATTS_ADD_CHAR_EVT - Indicate that a characteristic was added to the service. + // add_char: + // - esp_gatt_status_t status + // - uint16_t attr_handle + // - uint16_t service_handle + // - esp_bt_uuid_t char_uuid + case ESP_GATTS_ADD_CHAR_EVT: + { + if (getHandle() == param->add_char.attr_handle) { + // we have created characteristic, now we can create descriptors + // BLEDescriptor* pDescriptor = m_descriptorMap.getFirst(); + // while (pDescriptor != nullptr) { + // pDescriptor->executeCreate(this); + // pDescriptor = m_descriptorMap.getNext(); + // } // End while + m_semaphoreCreateEvt.give(); + } + break; + } // ESP_GATTS_ADD_CHAR_EVT + + + // ESP_GATTS_WRITE_EVT - A request to write the value of a characteristic has arrived. + // + // write: + // - uint16_t conn_id + // - uint16_t trans_id + // - esp_bd_addr_t bda + // - uint16_t handle + // - uint16_t offset + // - bool need_rsp + // - bool is_prep + // - uint16_t len + // - uint8_t *value + // + case ESP_GATTS_WRITE_EVT: + { + // We check if this write request is for us by comparing the handles in the event. If it is for us + // we save the new value. Next we look at the need_rsp flag which indicates whether or not we need + // to send a response. If we do, then we formulate a response and send it. + if (param->write.handle == m_handle) { + if (param->write.is_prep) { + m_value.addPart(param->write.value, param->write.len); + m_writeEvt = true; + } else { + setValue(param->write.value, param->write.len); + } + + log_d(" - Response to write event: New value: handle: %.2x, uuid: %s", + getHandle(), getUUID().toString().c_str()); + + char* pHexData = BLEUtils::buildHexData(nullptr, param->write.value, param->write.len); + log_d(" - Data: length: %d, data: %s", param->write.len, pHexData); + free(pHexData); + + if (param->write.need_rsp) { + esp_gatt_rsp_t rsp; + + rsp.attr_value.len = param->write.len; + rsp.attr_value.handle = m_handle; + rsp.attr_value.offset = param->write.offset; + rsp.attr_value.auth_req = ESP_GATT_AUTH_REQ_NONE; + memcpy(rsp.attr_value.value, param->write.value, param->write.len); + + esp_err_t errRc = ::esp_ble_gatts_send_response( + gatts_if, + param->write.conn_id, + param->write.trans_id, ESP_GATT_OK, &rsp); + if (errRc != ESP_OK) { + log_e("esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + } + } // Response needed + + if (param->write.is_prep != true) { + // Invoke the onWrite callback handler. + m_pCallbacks->onWrite(this, param); + } + } // Match on handles. + break; + } // ESP_GATTS_WRITE_EVT + + + // ESP_GATTS_READ_EVT - A request to read the value of a characteristic has arrived. + // + // read: + // - uint16_t conn_id + // - uint32_t trans_id + // - esp_bd_addr_t bda + // - uint16_t handle + // - uint16_t offset + // - bool is_long + // - bool need_rsp + // + case ESP_GATTS_READ_EVT: + { + if (param->read.handle == m_handle) { + + + + // Here's an interesting thing. The read request has the option of saying whether we need a response + // or not. What would it "mean" to receive a read request and NOT send a response back? That feels like + // a very strange read. + // + // We have to handle the case where the data we wish to send back to the client is greater than the maximum + // packet size of 22 bytes. In this case, we become responsible for chunking the data into units of 22 bytes. + // The apparent algorithm is as follows: + // + // If the is_long flag is set then this is a follow on from an original read and we will already have sent at least 22 bytes. + // If the is_long flag is not set then we need to check how much data we are going to send. If we are sending LESS than + // 22 bytes, then we "just" send it and that's the end of the story. + // If we are sending 22 bytes exactly, we just send it BUT we will get a follow on request. + // If we are sending more than 22 bytes, we send the first 22 bytes and we will get a follow on request. + // Because of follow on request processing, we need to maintain an offset of how much data we have already sent + // so that when a follow on request arrives, we know where to start in the data to send the next sequence. + // Note that the indication that the client will send a follow on request is that we sent exactly 22 bytes as a response. + // If our payload is divisible by 22 then the last response will be a response of 0 bytes in length. + // + // The following code has deliberately not been factored to make it fewer statements because this would cloud the + // the logic flow comprehension. + // + + // get mtu for peer device that we are sending read request to + uint16_t maxOffset = getService()->getServer()->getPeerMTU(param->read.conn_id) - 1; + log_d("mtu value: %d", maxOffset); + if (param->read.need_rsp) { + log_d("Sending a response (esp_ble_gatts_send_response)"); + esp_gatt_rsp_t rsp; + + if (param->read.is_long) { + String value = m_value.getValue(); + + if (value.length() - m_value.getReadOffset() < maxOffset) { + // This is the last in the chain + rsp.attr_value.len = value.length() - m_value.getReadOffset(); + rsp.attr_value.offset = m_value.getReadOffset(); + memcpy(rsp.attr_value.value, value.c_str() + rsp.attr_value.offset, rsp.attr_value.len); + m_value.setReadOffset(0); + } else { + // There will be more to come. + rsp.attr_value.len = maxOffset; + rsp.attr_value.offset = m_value.getReadOffset(); + memcpy(rsp.attr_value.value, value.c_str() + rsp.attr_value.offset, rsp.attr_value.len); + m_value.setReadOffset(rsp.attr_value.offset + maxOffset); + } + } else { // read.is_long == false + + // If is.long is false then this is the first (or only) request to read data, so invoke the callback + // Invoke the read callback. + m_pCallbacks->onRead(this, param); + + String value = m_value.getValue(); + + if (value.length() + 1 > maxOffset) { + // Too big for a single shot entry. + m_value.setReadOffset(maxOffset); + rsp.attr_value.len = maxOffset; + rsp.attr_value.offset = 0; + memcpy(rsp.attr_value.value, value.c_str(), rsp.attr_value.len); + } else { + // Will fit in a single packet with no callbacks required. + rsp.attr_value.len = value.length(); + rsp.attr_value.offset = 0; + memcpy(rsp.attr_value.value, value.c_str(), rsp.attr_value.len); + } + } + rsp.attr_value.handle = param->read.handle; + rsp.attr_value.auth_req = ESP_GATT_AUTH_REQ_NONE; + + char* pHexData = BLEUtils::buildHexData(nullptr, rsp.attr_value.value, rsp.attr_value.len); + log_d(" - Data: length=%d, data=%s, offset=%d", rsp.attr_value.len, pHexData, rsp.attr_value.offset); + free(pHexData); + + esp_err_t errRc = ::esp_ble_gatts_send_response( + gatts_if, param->read.conn_id, + param->read.trans_id, + ESP_GATT_OK, + &rsp); + if (errRc != ESP_OK) { + log_e("esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + } + } // Response needed + } // Handle matches this characteristic. + break; + } // ESP_GATTS_READ_EVT + + + // ESP_GATTS_CONF_EVT + // + // conf: + // - esp_gatt_status_t status – The status code. + // - uint16_t conn_id – The connection used. + // + case ESP_GATTS_CONF_EVT: + { + // log_d("m_handle = %d, conf->handle = %d", m_handle, param->conf.handle); + if (param->conf.conn_id == getService()->getServer()->getConnId()) // && param->conf.handle == m_handle) // bug in esp-idf and not implemented in arduino yet + m_semaphoreConfEvt.give(param->conf.status); + break; + } + + case ESP_GATTS_CONNECT_EVT: + { + break; + } + + case ESP_GATTS_DISCONNECT_EVT: + { + m_semaphoreConfEvt.give(); + break; + } + + default: + { + break; + } // default + + } // switch event + + // Give each of the descriptors associated with this characteristic the opportunity to handle the + // event. + + m_descriptorMap.handleGATTServerEvent(event, gatts_if, param); + log_v("<< handleGATTServerEvent"); +} // handleGATTServerEvent /** @@ -477,10 +486,10 @@ void BLECharacteristic::handleGATTServerEvent( */ void BLECharacteristic::indicate() { - log_v(">> indicate: length: %d", m_value.getValue().length()); - notify(false); - log_v("<< indicate"); -} // indicate + log_v(">> indicate: length: %d", m_value.getValue().length()); + notify(false); + log_v("<< indicate"); +} // indicate /** @@ -490,75 +499,74 @@ void BLECharacteristic::indicate() { * @return N/A. */ void BLECharacteristic::notify(bool is_notification) { - log_v(">> notify: length: %d", m_value.getValue().length()); - - assert(getService() != nullptr); - assert(getService()->getServer() != nullptr); - - m_pCallbacks->onNotify(this); // Invoke the notify callback. - - GeneralUtils::hexDump((uint8_t*)m_value.getValue().c_str(), m_value.getValue().length()); - - if (getService()->getServer()->getConnectedCount() == 0) { - log_v("<< notify: No connected clients."); - m_pCallbacks->onStatus(this, BLECharacteristicCallbacks::Status::ERROR_NO_CLIENT, 0); - return; - } - - // Test to see if we have a 0x2902 descriptor. If we do, then check to see if notification is enabled - // and, if not, prevent the notification. - - BLE2902 *p2902 = (BLE2902*)getDescriptorByUUID((uint16_t)0x2902); - if(is_notification) { - if (p2902 != nullptr && !p2902->getNotifications()) { - log_v("<< notifications disabled; ignoring"); - m_pCallbacks->onStatus(this, BLECharacteristicCallbacks::Status::ERROR_NOTIFY_DISABLED, 0); // Invoke the notify callback. - return; - } - } - else{ - if (p2902 != nullptr && !p2902->getIndications()) { - log_v("<< indications disabled; ignoring"); - m_pCallbacks->onStatus(this, BLECharacteristicCallbacks::Status::ERROR_INDICATE_DISABLED, 0); // Invoke the notify callback. - return; - } - } - for (auto &myPair : getService()->getServer()->getPeerDevices(false)) { - uint16_t _mtu = (myPair.second.mtu); - if (m_value.getValue().length() > _mtu - 3) { - log_w("- Truncating to %d bytes (maximum notify size)", _mtu - 3); - } - - size_t length = m_value.getValue().length(); - if(!is_notification) // is indication - m_semaphoreConfEvt.take("indicate"); - esp_err_t errRc = ::esp_ble_gatts_send_indicate( - getService()->getServer()->getGattsIf(), - myPair.first, - getHandle(), length, (uint8_t*)m_value.getValue().c_str(), !is_notification); // The need_confirm = false makes this a notify. - if (errRc != ESP_OK) { - log_e("<< esp_ble_gatts_send_ %s: rc=%d %s",is_notification?"notify":"indicate", errRc, GeneralUtils::errorToString(errRc)); - m_semaphoreConfEvt.give(); - m_pCallbacks->onStatus(this, BLECharacteristicCallbacks::Status::ERROR_GATT, errRc); // Invoke the notify callback. - return; - } - if(!is_notification){ // is indication - if(!m_semaphoreConfEvt.timedWait("indicate", indicationTimeout)){ - m_pCallbacks->onStatus(this, BLECharacteristicCallbacks::Status::ERROR_INDICATE_TIMEOUT, 0); // Invoke the notify callback. - } else { - auto code = (esp_gatt_status_t) m_semaphoreConfEvt.value(); - if(code == ESP_GATT_OK) { - m_pCallbacks->onStatus(this, BLECharacteristicCallbacks::Status::SUCCESS_INDICATE, code); // Invoke the notify callback. - } else { - m_pCallbacks->onStatus(this, BLECharacteristicCallbacks::Status::ERROR_INDICATE_FAILURE, code); - } - } - } else { - m_pCallbacks->onStatus(this, BLECharacteristicCallbacks::Status::SUCCESS_NOTIFY, 0); // Invoke the notify callback. - } - } - log_v("<< notify"); -} // Notify + log_v(">> notify: length: %d", m_value.getValue().length()); + + assert(getService() != nullptr); + assert(getService()->getServer() != nullptr); + + m_pCallbacks->onNotify(this); // Invoke the notify callback. + + GeneralUtils::hexDump((uint8_t*)m_value.getValue().c_str(), m_value.getValue().length()); + + if (getService()->getServer()->getConnectedCount() == 0) { + log_v("<< notify: No connected clients."); + m_pCallbacks->onStatus(this, BLECharacteristicCallbacks::Status::ERROR_NO_CLIENT, 0); + return; + } + + // Test to see if we have a 0x2902 descriptor. If we do, then check to see if notification is enabled + // and, if not, prevent the notification. + + BLE2902* p2902 = (BLE2902*)getDescriptorByUUID((uint16_t)0x2902); + if (is_notification) { + if (p2902 != nullptr && !p2902->getNotifications()) { + log_v("<< notifications disabled; ignoring"); + m_pCallbacks->onStatus(this, BLECharacteristicCallbacks::Status::ERROR_NOTIFY_DISABLED, 0); // Invoke the notify callback. + return; + } + } else { + if (p2902 != nullptr && !p2902->getIndications()) { + log_v("<< indications disabled; ignoring"); + m_pCallbacks->onStatus(this, BLECharacteristicCallbacks::Status::ERROR_INDICATE_DISABLED, 0); // Invoke the notify callback. + return; + } + } + for (auto& myPair : getService()->getServer()->getPeerDevices(false)) { + uint16_t _mtu = (myPair.second.mtu); + if (m_value.getValue().length() > _mtu - 3) { + log_w("- Truncating to %d bytes (maximum notify size)", _mtu - 3); + } + + size_t length = m_value.getValue().length(); + if (!is_notification) // is indication + m_semaphoreConfEvt.take("indicate"); + esp_err_t errRc = ::esp_ble_gatts_send_indicate( + getService()->getServer()->getGattsIf(), + myPair.first, + getHandle(), length, (uint8_t*)m_value.getValue().c_str(), !is_notification); // The need_confirm = false makes this a notify. + if (errRc != ESP_OK) { + log_e("<< esp_ble_gatts_send_ %s: rc=%d %s", is_notification ? "notify" : "indicate", errRc, GeneralUtils::errorToString(errRc)); + m_semaphoreConfEvt.give(); + m_pCallbacks->onStatus(this, BLECharacteristicCallbacks::Status::ERROR_GATT, errRc); // Invoke the notify callback. + return; + } + if (!is_notification) { // is indication + if (!m_semaphoreConfEvt.timedWait("indicate", indicationTimeout)) { + m_pCallbacks->onStatus(this, BLECharacteristicCallbacks::Status::ERROR_INDICATE_TIMEOUT, 0); // Invoke the notify callback. + } else { + auto code = (esp_gatt_status_t)m_semaphoreConfEvt.value(); + if (code == ESP_GATT_OK) { + m_pCallbacks->onStatus(this, BLECharacteristicCallbacks::Status::SUCCESS_INDICATE, code); // Invoke the notify callback. + } else { + m_pCallbacks->onStatus(this, BLECharacteristicCallbacks::Status::ERROR_INDICATE_FAILURE, code); + } + } + } else { + m_pCallbacks->onStatus(this, BLECharacteristicCallbacks::Status::SUCCESS_NOTIFY, 0); // Invoke the notify callback. + } + } + log_v("<< notify"); +} // Notify /** @@ -569,13 +577,13 @@ void BLECharacteristic::notify(bool is_notification) { * @return N/A */ void BLECharacteristic::setBroadcastProperty(bool value) { - //log_d("setBroadcastProperty(%d)", value); - if (value) { - m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_BROADCAST); - } else { - m_properties = (esp_gatt_char_prop_t)(m_properties & ~ESP_GATT_CHAR_PROP_BIT_BROADCAST); - } -} // setBroadcastProperty + //log_d("setBroadcastProperty(%d)", value); + if (value) { + m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_BROADCAST); + } else { + m_properties = (esp_gatt_char_prop_t)(m_properties & ~ESP_GATT_CHAR_PROP_BIT_BROADCAST); + } +} // setBroadcastProperty /** @@ -583,14 +591,14 @@ void BLECharacteristic::setBroadcastProperty(bool value) { * @param [in] pCallbacks An instance of a callbacks structure used to define any callbacks for the characteristic. */ void BLECharacteristic::setCallbacks(BLECharacteristicCallbacks* pCallbacks) { - log_v(">> setCallbacks: 0x%x", (uint32_t)pCallbacks); - if (pCallbacks != nullptr){ - m_pCallbacks = pCallbacks; - } else { - m_pCallbacks = &defaultCallback; - } - log_v("<< setCallbacks"); -} // setCallbacks + log_v(">> setCallbacks: 0x%x", (uint32_t)pCallbacks); + if (pCallbacks != nullptr) { + m_pCallbacks = pCallbacks; + } else { + m_pCallbacks = &defaultCallback; + } + log_v("<< setCallbacks"); +} // setCallbacks /** @@ -604,10 +612,10 @@ void BLECharacteristic::setCallbacks(BLECharacteristicCallbacks* pCallbacks) { * @param [in] handle The handle associated with this characteristic. */ void BLECharacteristic::setHandle(uint16_t handle) { - log_v(">> setHandle: handle=0x%.2x, characteristic uuid=%s", handle, getUUID().toString().c_str()); - m_handle = handle; - log_v("<< setHandle"); -} // setHandle + log_v(">> setHandle: handle=0x%.2x, characteristic uuid=%s", handle, getUUID().toString().c_str()); + m_handle = handle; + log_v("<< setHandle"); +} // setHandle /** @@ -615,13 +623,13 @@ void BLECharacteristic::setHandle(uint16_t handle) { * @param [in] value Set to true if we are to allow indicate messages. */ void BLECharacteristic::setIndicateProperty(bool value) { - //log_d("setIndicateProperty(%d)", value); - if (value) { - m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_INDICATE); - } else { - m_properties = (esp_gatt_char_prop_t)(m_properties & ~ESP_GATT_CHAR_PROP_BIT_INDICATE); - } -} // setIndicateProperty + //log_d("setIndicateProperty(%d)", value); + if (value) { + m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_INDICATE); + } else { + m_properties = (esp_gatt_char_prop_t)(m_properties & ~ESP_GATT_CHAR_PROP_BIT_INDICATE); + } +} // setIndicateProperty /** @@ -629,13 +637,13 @@ void BLECharacteristic::setIndicateProperty(bool value) { * @param [in] value Set to true if we are to allow notification messages. */ void BLECharacteristic::setNotifyProperty(bool value) { - //log_d("setNotifyProperty(%d)", value); - if (value) { - m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_NOTIFY); - } else { - m_properties = (esp_gatt_char_prop_t)(m_properties & ~ESP_GATT_CHAR_PROP_BIT_NOTIFY); - } -} // setNotifyProperty + //log_d("setNotifyProperty(%d)", value); + if (value) { + m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_NOTIFY); + } else { + m_properties = (esp_gatt_char_prop_t)(m_properties & ~ESP_GATT_CHAR_PROP_BIT_NOTIFY); + } +} // setNotifyProperty /** @@ -643,13 +651,13 @@ void BLECharacteristic::setNotifyProperty(bool value) { * @param [in] value Set to true if we are to allow reads. */ void BLECharacteristic::setReadProperty(bool value) { - //log_d("setReadProperty(%d)", value); - if (value) { - m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_READ); - } else { - m_properties = (esp_gatt_char_prop_t)(m_properties & ~ESP_GATT_CHAR_PROP_BIT_READ); - } -} // setReadProperty + //log_d("setReadProperty(%d)", value); + if (value) { + m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_READ); + } else { + m_properties = (esp_gatt_char_prop_t)(m_properties & ~ESP_GATT_CHAR_PROP_BIT_READ); + } +} // setReadProperty /** @@ -658,18 +666,18 @@ void BLECharacteristic::setReadProperty(bool value) { * @param [in] length The length of the data in bytes. */ void BLECharacteristic::setValue(uint8_t* data, size_t length) { - char* pHex = BLEUtils::buildHexData(nullptr, data, length); - log_v(">> setValue: length=%d, data=%s, characteristic UUID=%s", length, pHex, getUUID().toString().c_str()); - free(pHex); - if (length > ESP_GATT_MAX_ATTR_LEN) { - log_e("Size %d too large, must be no bigger than %d", length, ESP_GATT_MAX_ATTR_LEN); - return; - } - m_semaphoreSetValue.take(); - m_value.setValue(data, length); - m_semaphoreSetValue.give(); - log_v("<< setValue"); -} // setValue + char* pHex = BLEUtils::buildHexData(nullptr, data, length); + log_v(">> setValue: length=%d, data=%s, characteristic UUID=%s", length, pHex, getUUID().toString().c_str()); + free(pHex); + if (length > ESP_GATT_MAX_ATTR_LEN) { + log_e("Size %d too large, must be no bigger than %d", length, ESP_GATT_MAX_ATTR_LEN); + return; + } + m_semaphoreSetValue.take(); + m_value.setValue(data, length); + m_semaphoreSetValue.give(); + log_v("<< setValue"); +} // setValue /** @@ -680,43 +688,43 @@ void BLECharacteristic::setValue(uint8_t* data, size_t length) { * @return N/A. */ void BLECharacteristic::setValue(String value) { - setValue((uint8_t*)(value.c_str()), value.length()); -} // setValue + setValue((uint8_t*)(value.c_str()), value.length()); +} // setValue void BLECharacteristic::setValue(uint16_t& data16) { - uint8_t temp[2]; - temp[0] = data16; - temp[1] = data16 >> 8; - setValue(temp, 2); -} // setValue + uint8_t temp[2]; + temp[0] = data16; + temp[1] = data16 >> 8; + setValue(temp, 2); +} // setValue void BLECharacteristic::setValue(uint32_t& data32) { - uint8_t temp[4]; - temp[0] = data32; - temp[1] = data32 >> 8; - temp[2] = data32 >> 16; - temp[3] = data32 >> 24; - setValue(temp, 4); -} // setValue + uint8_t temp[4]; + temp[0] = data32; + temp[1] = data32 >> 8; + temp[2] = data32 >> 16; + temp[3] = data32 >> 24; + setValue(temp, 4); +} // setValue void BLECharacteristic::setValue(int& data32) { - uint8_t temp[4]; - temp[0] = data32; - temp[1] = data32 >> 8; - temp[2] = data32 >> 16; - temp[3] = data32 >> 24; - setValue(temp, 4); -} // setValue + uint8_t temp[4]; + temp[0] = data32; + temp[1] = data32 >> 8; + temp[2] = data32 >> 16; + temp[3] = data32 >> 24; + setValue(temp, 4); +} // setValue void BLECharacteristic::setValue(float& data32) { - float temp = data32; - setValue((uint8_t*)&temp, 4); -} // setValue + float temp = data32; + setValue((uint8_t*)&temp, 4); +} // setValue void BLECharacteristic::setValue(double& data64) { - double temp = data64; - setValue((uint8_t*)&temp, 8); -} // setValue + double temp = data64; + setValue((uint8_t*)&temp, 8); +} // setValue /** @@ -724,13 +732,13 @@ void BLECharacteristic::setValue(double& data64) { * @param [in] value Set to true if we are to allow writes with no response. */ void BLECharacteristic::setWriteNoResponseProperty(bool value) { - //log_d("setWriteNoResponseProperty(%d)", value); - if (value) { - m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_WRITE_NR); - } else { - m_properties = (esp_gatt_char_prop_t)(m_properties & ~ESP_GATT_CHAR_PROP_BIT_WRITE_NR); - } -} // setWriteNoResponseProperty + //log_d("setWriteNoResponseProperty(%d)", value); + if (value) { + m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_WRITE_NR); + } else { + m_properties = (esp_gatt_char_prop_t)(m_properties & ~ESP_GATT_CHAR_PROP_BIT_WRITE_NR); + } +} // setWriteNoResponseProperty /** @@ -738,13 +746,13 @@ void BLECharacteristic::setWriteNoResponseProperty(bool value) { * @param [in] value Set to true if we are to allow writes. */ void BLECharacteristic::setWriteProperty(bool value) { - //log_d("setWriteProperty(%d)", value); - if (value) { - m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_WRITE); - } else { - m_properties = (esp_gatt_char_prop_t)(m_properties & ~ESP_GATT_CHAR_PROP_BIT_WRITE); - } -} // setWriteProperty + //log_d("setWriteProperty(%d)", value); + if (value) { + m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_WRITE); + } else { + m_properties = (esp_gatt_char_prop_t)(m_properties & ~ESP_GATT_CHAR_PROP_BIT_WRITE); + } +} // setWriteProperty /** @@ -752,53 +760,53 @@ void BLECharacteristic::setWriteProperty(bool value) { * @return A string representation of the characteristic. */ String BLECharacteristic::toString() { - String res = "UUID: " + m_bleUUID.toString() + ", handle : 0x"; - char hex[5]; - snprintf(hex, sizeof(hex), "%04x", m_handle); - res += hex; - res += " "; - if (m_properties & ESP_GATT_CHAR_PROP_BIT_READ) res += "Read "; - if (m_properties & ESP_GATT_CHAR_PROP_BIT_WRITE) res += "Write "; - if (m_properties & ESP_GATT_CHAR_PROP_BIT_WRITE_NR) res += "WriteNoResponse "; - if (m_properties & ESP_GATT_CHAR_PROP_BIT_BROADCAST) res += "Broadcast "; - if (m_properties & ESP_GATT_CHAR_PROP_BIT_NOTIFY) res += "Notify "; - if (m_properties & ESP_GATT_CHAR_PROP_BIT_INDICATE) res += "Indicate "; - return res; -} // toString + String res = "UUID: " + m_bleUUID.toString() + ", handle : 0x"; + char hex[5]; + snprintf(hex, sizeof(hex), "%04x", m_handle); + res += hex; + res += " "; + if (m_properties & ESP_GATT_CHAR_PROP_BIT_READ) res += "Read "; + if (m_properties & ESP_GATT_CHAR_PROP_BIT_WRITE) res += "Write "; + if (m_properties & ESP_GATT_CHAR_PROP_BIT_WRITE_NR) res += "WriteNoResponse "; + if (m_properties & ESP_GATT_CHAR_PROP_BIT_BROADCAST) res += "Broadcast "; + if (m_properties & ESP_GATT_CHAR_PROP_BIT_NOTIFY) res += "Notify "; + if (m_properties & ESP_GATT_CHAR_PROP_BIT_INDICATE) res += "Indicate "; + return res; +} // toString BLECharacteristicCallbacks::~BLECharacteristicCallbacks() {} void BLECharacteristicCallbacks::onRead(BLECharacteristic* pCharacteristic, esp_ble_gatts_cb_param_t* param) { - onRead(pCharacteristic); -} // onRead + onRead(pCharacteristic); +} // onRead void BLECharacteristicCallbacks::onRead(BLECharacteristic* pCharacteristic) { - log_d(">> onRead: default"); - log_d("<< onRead"); -} // onRead + log_d(">> onRead: default"); + log_d("<< onRead"); +} // onRead void BLECharacteristicCallbacks::onWrite(BLECharacteristic* pCharacteristic, esp_ble_gatts_cb_param_t* param) { - onWrite(pCharacteristic); -} // onWrite + onWrite(pCharacteristic); +} // onWrite void BLECharacteristicCallbacks::onWrite(BLECharacteristic* pCharacteristic) { - log_d(">> onWrite: default"); - log_d("<< onWrite"); -} // onWrite + log_d(">> onWrite: default"); + log_d("<< onWrite"); +} // onWrite void BLECharacteristicCallbacks::onNotify(BLECharacteristic* pCharacteristic) { - log_d(">> onNotify: default"); - log_d("<< onNotify"); -} // onNotify + log_d(">> onNotify: default"); + log_d("<< onNotify"); +} // onNotify void BLECharacteristicCallbacks::onStatus(BLECharacteristic* pCharacteristic, Status s, uint32_t code) { - log_d(">> onStatus: default"); - log_d("<< onStatus"); -} // onStatus + log_d(">> onStatus: default"); + log_d("<< onStatus"); +} // onStatus #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLECharacteristic.h b/libraries/BLE/src/BLECharacteristic.h index 3ff9397475d..1428b0fe3ae 100644 --- a/libraries/BLE/src/BLECharacteristic.h +++ b/libraries/BLE/src/BLECharacteristic.h @@ -30,20 +30,20 @@ class BLECharacteristicCallbacks; */ class BLEDescriptorMap { public: - void setByUUID(const char* uuid, BLEDescriptor* pDescriptor); - void setByUUID(BLEUUID uuid, BLEDescriptor* pDescriptor); - void setByHandle(uint16_t handle, BLEDescriptor* pDescriptor); - BLEDescriptor* getByUUID(const char* uuid); - BLEDescriptor* getByUUID(BLEUUID uuid); - BLEDescriptor* getByHandle(uint16_t handle); - String toString(); - void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param); - BLEDescriptor* getFirst(); - BLEDescriptor* getNext(); + void setByUUID(const char* uuid, BLEDescriptor* pDescriptor); + void setByUUID(BLEUUID uuid, BLEDescriptor* pDescriptor); + void setByHandle(uint16_t handle, BLEDescriptor* pDescriptor); + BLEDescriptor* getByUUID(const char* uuid); + BLEDescriptor* getByUUID(BLEUUID uuid); + BLEDescriptor* getByHandle(uint16_t handle); + String toString(); + void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param); + BLEDescriptor* getFirst(); + BLEDescriptor* getNext(); private: - std::map m_uuidMap; - std::map m_handleMap; - std::map::iterator m_iterator; + std::map m_uuidMap; + std::map m_handleMap; + std::map::iterator m_iterator; }; @@ -55,77 +55,77 @@ class BLEDescriptorMap { */ class BLECharacteristic { public: - BLECharacteristic(const char* uuid, uint32_t properties = 0); - BLECharacteristic(BLEUUID uuid, uint32_t properties = 0); - virtual ~BLECharacteristic(); - - void addDescriptor(BLEDescriptor* pDescriptor); - BLEDescriptor* getDescriptorByUUID(const char* descriptorUUID); - BLEDescriptor* getDescriptorByUUID(BLEUUID descriptorUUID); - BLEUUID getUUID(); - String getValue(); - uint8_t* getData(); - size_t getLength(); - - void indicate(); - void notify(bool is_notification = true); - void setBroadcastProperty(bool value); - void setCallbacks(BLECharacteristicCallbacks* pCallbacks); - void setIndicateProperty(bool value); - void setNotifyProperty(bool value); - void setReadProperty(bool value); - void setValue(uint8_t* data, size_t size); - void setValue(String value); - void setValue(uint16_t& data16); - void setValue(uint32_t& data32); - void setValue(int& data32); - void setValue(float& data32); - void setValue(double& data64); - void setWriteProperty(bool value); - void setWriteNoResponseProperty(bool value); - String toString(); - uint16_t getHandle(); - void setAccessPermissions(esp_gatt_perm_t perm); - - static const uint32_t PROPERTY_READ = 1<<0; - static const uint32_t PROPERTY_WRITE = 1<<1; - static const uint32_t PROPERTY_NOTIFY = 1<<2; - static const uint32_t PROPERTY_BROADCAST = 1<<3; - static const uint32_t PROPERTY_INDICATE = 1<<4; - static const uint32_t PROPERTY_WRITE_NR = 1<<5; - - static const uint32_t indicationTimeout = 1000; + BLECharacteristic(const char* uuid, uint32_t properties = 0); + BLECharacteristic(BLEUUID uuid, uint32_t properties = 0); + virtual ~BLECharacteristic(); + + void addDescriptor(BLEDescriptor* pDescriptor); + BLEDescriptor* getDescriptorByUUID(const char* descriptorUUID); + BLEDescriptor* getDescriptorByUUID(BLEUUID descriptorUUID); + BLEUUID getUUID(); + String getValue(); + uint8_t* getData(); + size_t getLength(); + + void indicate(); + void notify(bool is_notification = true); + void setBroadcastProperty(bool value); + void setCallbacks(BLECharacteristicCallbacks* pCallbacks); + void setIndicateProperty(bool value); + void setNotifyProperty(bool value); + void setReadProperty(bool value); + void setValue(uint8_t* data, size_t size); + void setValue(String value); + void setValue(uint16_t& data16); + void setValue(uint32_t& data32); + void setValue(int& data32); + void setValue(float& data32); + void setValue(double& data64); + void setWriteProperty(bool value); + void setWriteNoResponseProperty(bool value); + String toString(); + uint16_t getHandle(); + void setAccessPermissions(esp_gatt_perm_t perm); + + static const uint32_t PROPERTY_READ = 1 << 0; + static const uint32_t PROPERTY_WRITE = 1 << 1; + static const uint32_t PROPERTY_NOTIFY = 1 << 2; + static const uint32_t PROPERTY_BROADCAST = 1 << 3; + static const uint32_t PROPERTY_INDICATE = 1 << 4; + static const uint32_t PROPERTY_WRITE_NR = 1 << 5; + + static const uint32_t indicationTimeout = 1000; private: - friend class BLEServer; - friend class BLEService; - friend class BLEDescriptor; - friend class BLECharacteristicMap; - - BLEUUID m_bleUUID; - BLEDescriptorMap m_descriptorMap; - uint16_t m_handle; - esp_gatt_char_prop_t m_properties; - BLECharacteristicCallbacks* m_pCallbacks; - BLEService* m_pService; - BLEValue m_value; - esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE; - bool m_writeEvt = false; // If we have started a long write, this tells the commit code that we were the target - - void handleGATTServerEvent( - esp_gatts_cb_event_t event, - esp_gatt_if_t gatts_if, - esp_ble_gatts_cb_param_t* param); - - void executeCreate(BLEService* pService); - esp_gatt_char_prop_t getProperties(); - BLEService* getService(); - void setHandle(uint16_t handle); - FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt"); - FreeRTOS::Semaphore m_semaphoreConfEvt = FreeRTOS::Semaphore("ConfEvt"); - FreeRTOS::Semaphore m_semaphoreSetValue = FreeRTOS::Semaphore("SetValue"); -}; // BLECharacteristic + friend class BLEServer; + friend class BLEService; + friend class BLEDescriptor; + friend class BLECharacteristicMap; + + BLEUUID m_bleUUID; + BLEDescriptorMap m_descriptorMap; + uint16_t m_handle; + esp_gatt_char_prop_t m_properties; + BLECharacteristicCallbacks* m_pCallbacks; + BLEService* m_pService; + BLEValue m_value; + esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE; + bool m_writeEvt = false; // If we have started a long write, this tells the commit code that we were the target + + void handleGATTServerEvent( + esp_gatts_cb_event_t event, + esp_gatt_if_t gatts_if, + esp_ble_gatts_cb_param_t* param); + + void executeCreate(BLEService* pService); + esp_gatt_char_prop_t getProperties(); + BLEService* getService(); + void setHandle(uint16_t handle); + FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt"); + FreeRTOS::Semaphore m_semaphoreConfEvt = FreeRTOS::Semaphore("ConfEvt"); + FreeRTOS::Semaphore m_semaphoreSetValue = FreeRTOS::Semaphore("SetValue"); +}; // BLECharacteristic /** @@ -137,56 +137,56 @@ class BLECharacteristic { */ class BLECharacteristicCallbacks { public: - typedef enum { - SUCCESS_INDICATE, - SUCCESS_NOTIFY, - ERROR_INDICATE_DISABLED, - ERROR_NOTIFY_DISABLED, - ERROR_GATT, - ERROR_NO_CLIENT, - ERROR_INDICATE_TIMEOUT, - ERROR_INDICATE_FAILURE - }Status; - - virtual ~BLECharacteristicCallbacks(); - - /** + typedef enum { + SUCCESS_INDICATE, + SUCCESS_NOTIFY, + ERROR_INDICATE_DISABLED, + ERROR_NOTIFY_DISABLED, + ERROR_GATT, + ERROR_NO_CLIENT, + ERROR_INDICATE_TIMEOUT, + ERROR_INDICATE_FAILURE + } Status; + + virtual ~BLECharacteristicCallbacks(); + + /** * @brief Callback function to support a read request. * @param [in] pCharacteristic The characteristic that is the source of the event. * @param [in] param The BLE GATTS param. Use param->read. */ - virtual void onRead(BLECharacteristic* pCharacteristic, esp_ble_gatts_cb_param_t* param); - /** - * @brief DEPRECATED! Callback function to support a read request. Called only if onRead(,) not overrided. + virtual void onRead(BLECharacteristic* pCharacteristic, esp_ble_gatts_cb_param_t* param); + /** + * @brief DEPRECATED! Callback function to support a read request. Called only if onRead(,) is not overridden * @param [in] pCharacteristic The characteristic that is the source of the event. */ - virtual void onRead(BLECharacteristic* pCharacteristic); + virtual void onRead(BLECharacteristic* pCharacteristic); - /** + /** * @brief Callback function to support a write request. * @param [in] pCharacteristic The characteristic that is the source of the event. * @param [in] param The BLE GATTS param. Use param->write. */ - virtual void onWrite(BLECharacteristic* pCharacteristic, esp_ble_gatts_cb_param_t* param); - /** - * @brief DEPRECATED! Callback function to support a write request. Called only if onWrite(,) not overrided. + virtual void onWrite(BLECharacteristic* pCharacteristic, esp_ble_gatts_cb_param_t* param); + /** + * @brief DEPRECATED! Callback function to support a write request. Called only if onWrite(,) is not overridden. * @param [in] pCharacteristic The characteristic that is the source of the event. */ - virtual void onWrite(BLECharacteristic* pCharacteristic); + virtual void onWrite(BLECharacteristic* pCharacteristic); - /** + /** * @brief Callback function to support a Notify request. * @param [in] pCharacteristic The characteristic that is the source of the event. */ - virtual void onNotify(BLECharacteristic* pCharacteristic); + virtual void onNotify(BLECharacteristic* pCharacteristic); - /** + /** * @brief Callback function to support a Notify/Indicate Status report. * @param [in] pCharacteristic The characteristic that is the source of the event. * @param [in] s Status of the notification/indication * @param [in] code Additional code of underlying errors */ - virtual void onStatus(BLECharacteristic* pCharacteristic, Status s, uint32_t code); + virtual void onStatus(BLECharacteristic* pCharacteristic, Status s, uint32_t code); }; #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLECharacteristicMap.cpp b/libraries/BLE/src/BLECharacteristicMap.cpp index c574b53edcd..6d8b336918c 100644 --- a/libraries/BLE/src/BLECharacteristicMap.cpp +++ b/libraries/BLE/src/BLECharacteristicMap.cpp @@ -24,7 +24,7 @@ */ BLECharacteristic* BLECharacteristicMap::getByHandle(uint16_t handle) { return m_handleMap.at(handle); -} // getByHandle +} // getByHandle /** @@ -33,7 +33,7 @@ BLECharacteristic* BLECharacteristicMap::getByHandle(uint16_t handle) { * @return The characteristic. */ BLECharacteristic* BLECharacteristicMap::getByUUID(const char* uuid) { - return getByUUID(BLEUUID(uuid)); + return getByUUID(BLEUUID(uuid)); } @@ -43,14 +43,14 @@ BLECharacteristic* BLECharacteristicMap::getByUUID(const char* uuid) { * @return The characteristic. */ BLECharacteristic* BLECharacteristicMap::getByUUID(BLEUUID uuid) { - for (auto &myPair : m_uuidMap) { + for (auto& myPair : m_uuidMap) { if (myPair.first->getUUID().equals(uuid)) { return myPair.first; } } //return m_uuidMap.at(uuid.toString()); return nullptr; -} // getByUUID +} // getByUUID /** @@ -63,7 +63,7 @@ BLECharacteristic* BLECharacteristicMap::getFirst() { BLECharacteristic* pRet = m_iterator->first; m_iterator++; return pRet; -} // getFirst +} // getFirst /** @@ -75,7 +75,7 @@ BLECharacteristic* BLECharacteristicMap::getNext() { BLECharacteristic* pRet = m_iterator->first; m_iterator++; return pRet; -} // getNext +} // getNext /** @@ -89,7 +89,7 @@ void BLECharacteristicMap::handleGATTServerEvent(esp_gatts_cb_event_t event, esp for (auto& myPair : m_uuidMap) { myPair.first->handleGATTServerEvent(event, gatts_if, param); } -} // handleGATTServerEvent +} // handleGATTServerEvent /** @@ -100,7 +100,7 @@ void BLECharacteristicMap::handleGATTServerEvent(esp_gatts_cb_event_t event, esp */ void BLECharacteristicMap::setByHandle(uint16_t handle, BLECharacteristic* characteristic) { m_handleMap.insert(std::pair(handle, characteristic)); -} // setByHandle +} // setByHandle /** @@ -111,7 +111,7 @@ void BLECharacteristicMap::setByHandle(uint16_t handle, BLECharacteristic* chara */ void BLECharacteristicMap::setByUUID(BLECharacteristic* pCharacteristic, BLEUUID uuid) { m_uuidMap.insert(std::pair(pCharacteristic, uuid.toString())); -} // setByUUID +} // setByUUID /** @@ -122,8 +122,8 @@ String BLECharacteristicMap::toString() { String res; int count = 0; char hex[5]; - for (auto &myPair: m_uuidMap) { - if (count > 0) {res += "\n";} + for (auto& myPair : m_uuidMap) { + if (count > 0) { res += "\n"; } snprintf(hex, sizeof(hex), "%04x", myPair.first->getHandle()); count++; res += "handle: 0x"; @@ -131,7 +131,7 @@ String BLECharacteristicMap::toString() { res += ", uuid: " + myPair.first->getUUID().toString(); } return res; -} // toString +} // toString #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLEClient.cpp b/libraries/BLE/src/BLEClient.cpp index 60ee53c0fa0..37b3b26d8be 100644 --- a/libraries/BLE/src/BLEClient.cpp +++ b/libraries/BLE/src/BLEClient.cpp @@ -13,7 +13,7 @@ #include #include #include -#include // ESP32 BLE +#include // ESP32 BLE #include "BLEClient.h" #include "BLEUtils.h" #include "BLEService.h" @@ -47,11 +47,11 @@ BLEClient::BLEClient() { m_pClientCallbacks = nullptr; - m_conn_id = ESP_GATT_IF_NONE; - m_gattc_if = ESP_GATT_IF_NONE; - m_haveServices = false; - m_isConnected = false; // Initially, we are flagged as not connected. -} // BLEClient + m_conn_id = ESP_GATT_IF_NONE; + m_gattc_if = ESP_GATT_IF_NONE; + m_haveServices = false; + m_isConnected = false; // Initially, we are flagged as not connected. +} // BLEClient /** @@ -60,12 +60,12 @@ BLEClient::BLEClient() { BLEClient::~BLEClient() { // We may have allocated service references associated with this client. Before we are finished // with the client, we must release resources. - for (auto &myPair : m_servicesMap) { - delete myPair.second; + for (auto& myPair : m_servicesMap) { + delete myPair.second; } m_servicesMap.clear(); m_servicesMapByInstID.clear(); -} // ~BLEClient +} // ~BLEClient /** @@ -75,19 +75,19 @@ BLEClient::~BLEClient() { void BLEClient::clearServices() { log_v(">> clearServices"); // Delete all the services. - for (auto &myPair : m_servicesMap) { - delete myPair.second; + for (auto& myPair : m_servicesMap) { + delete myPair.second; } m_servicesMap.clear(); m_haveServices = false; log_v("<< clearServices"); -} // clearServices +} // clearServices /** * Add overloaded function to ease connect to peer device with not public address */ bool BLEClient::connect(BLEAdvertisedDevice* device) { - BLEAddress address = device->getAddress(); + BLEAddress address = device->getAddress(); esp_ble_addr_type_t type = device->getAddressType(); return connect(address, type); } @@ -96,9 +96,9 @@ bool BLEClient::connect(BLEAdvertisedDevice* device) { * Add overloaded function to ease connect to peer device with not public address */ bool BLEClient::connectTimeout(BLEAdvertisedDevice* device, uint32_t timeoutMs) { - BLEAddress address = device->getAddress(); - esp_ble_addr_type_t type = device->getAddressType(); - return connect(address, type, timeoutMs); + BLEAddress address = device->getAddress(); + esp_ble_addr_type_t type = device->getAddressType(); + return connect(address, type, timeoutMs); } /** @@ -111,8 +111,8 @@ bool BLEClient::connectTimeout(BLEAdvertisedDevice* device, uint32_t timeoutMs) bool BLEClient::connect(BLEAddress address, esp_ble_addr_type_t type, uint32_t timeoutMs) { log_v(">> connect(%s)", address.toString().c_str()); -// We need the connection handle that we get from registering the application. We register the app -// and then block on its completion. When the event has arrived, we will have the handle. + // We need the connection handle that we get from registering the application. We register the app + // and then block on its completion. When the event has arrived, we will have the handle. m_appId = BLEDevice::m_appId++; BLEDevice::addPeerDevice(this, true, m_appId); m_semaphoreRegEvt.take("connect"); @@ -143,9 +143,9 @@ bool BLEClient::connect(BLEAddress address, esp_ble_addr_type_t type, uint32_t t m_semaphoreOpenEvt.take("connect"); errRc = ::esp_ble_gattc_open( m_gattc_if, - *getPeerAddress().getNative(), // address - type, // Note: This was added on 2018-04-03 when the latest ESP-IDF was detected to have changed the signature. - 1 // direct connection <-- maybe needs to be changed in case of direct indirect connection??? + *getPeerAddress().getNative(), // address + type, // Note: This was added on 2018-04-03 when the latest ESP-IDF was detected to have changed the signature. + 1 // direct connection <-- maybe needs to be changed in case of direct indirect connection??? ); if (errRc != ESP_OK) { log_e("esp_ble_gattc_open: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); @@ -153,7 +153,7 @@ bool BLEClient::connect(BLEAddress address, esp_ble_addr_type_t type, uint32_t t return false; } - bool got_sem = m_semaphoreOpenEvt.timedWait("connect", timeoutMs); // Wait for the connection to complete. + bool got_sem = m_semaphoreOpenEvt.timedWait("connect", timeoutMs); // Wait for the connection to complete. rc = m_semaphoreOpenEvt.value(); // check the status of the connection and cleanup in case of failure if (!got_sem || rc != ESP_GATT_OK) { @@ -161,9 +161,9 @@ bool BLEClient::connect(BLEAddress address, esp_ble_addr_type_t type, uint32_t t esp_ble_gattc_app_unregister(m_gattc_if); m_gattc_if = ESP_GATT_IF_NONE; } - log_v("<< connect(), rc=%d", rc==ESP_GATT_OK); + log_v("<< connect(), rc=%d", rc == ESP_GATT_OK); return rc == ESP_GATT_OK; -} // connect +} // connect /** @@ -178,19 +178,19 @@ void BLEClient::disconnect() { return; } log_v("<< disconnect()"); -} // disconnect +} // disconnect /** * @brief Handle GATT Client events */ void BLEClient::gattClientEventHandler( - esp_gattc_cb_event_t event, - esp_gatt_if_t gattc_if, + esp_gattc_cb_event_t event, + esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* evtParam) { log_d("gattClientEventHandler [esp_gatt_if: %d] ... %s", - gattc_if, BLEUtils::gattClientEventTypeToString(event).c_str()); + gattc_if, BLEUtils::gattClientEventTypeToString(event).c_str()); // it is possible to receive events from other connections while waiting for registration if (m_gattc_if == ESP_GATT_IF_NONE && event != ESP_GATTC_REG_EVT) { @@ -198,17 +198,18 @@ void BLEClient::gattClientEventHandler( } // Execute handler code based on the type of event received. - switch(event) { + switch (event) { case ESP_GATTC_SRVC_CHG_EVT: log_i("SERVICE CHANGED"); break; - case ESP_GATTC_CLOSE_EVT: { + case ESP_GATTC_CLOSE_EVT: + { // esp_ble_gattc_app_unregister(m_appId); // BLEDevice::removePeerDevice(m_gattc_if, true); - break; - } + break; + } // // ESP_GATTC_DISCONNECT_EVT @@ -217,7 +218,8 @@ void BLEClient::gattClientEventHandler( // - esp_gatt_status_t status // - uint16_t conn_id // - esp_bd_addr_t remote_bda - case ESP_GATTC_DISCONNECT_EVT: { + case ESP_GATTC_DISCONNECT_EVT: + { if (evtParam->disconnect.conn_id != getConnId()) break; // If we receive a disconnect event, set the class flag that indicates that we are // no longer connected. @@ -233,7 +235,7 @@ void BLEClient::gattClientEventHandler( m_pClientCallbacks->onDisconnect(this); } break; - } // ESP_GATTC_DISCONNECT_EVT + } // ESP_GATTC_DISCONNECT_EVT // // ESP_GATTC_OPEN_EVT @@ -243,19 +245,20 @@ void BLEClient::gattClientEventHandler( // - uint16_t conn_id // - esp_bd_addr_t remote_bda // - case ESP_GATTC_OPEN_EVT: { - m_conn_id = evtParam->open.conn_id; - if (evtParam->open.status == ESP_GATT_OK) { - m_isConnected = true; // Flag us as connected. - if (m_pClientCallbacks != nullptr) { - m_pClientCallbacks->onConnect(this); + case ESP_GATTC_OPEN_EVT: + { + m_conn_id = evtParam->open.conn_id; + if (evtParam->open.status == ESP_GATT_OK) { + m_isConnected = true; // Flag us as connected. + if (m_pClientCallbacks != nullptr) { + m_pClientCallbacks->onConnect(this); + } + } else { + log_e("Failed to connect, status=%s", GeneralUtils::errorToString(evtParam->open.status)); } - } else { - log_e("Failed to connect, status=%s", GeneralUtils::errorToString(evtParam->open.status)); - } - m_semaphoreOpenEvt.give(evtParam->open.status); - break; - } // ESP_GATTC_OPEN_EVT + m_semaphoreOpenEvt.give(evtParam->open.status); + break; + } // ESP_GATTC_OPEN_EVT // @@ -265,35 +268,37 @@ void BLEClient::gattClientEventHandler( // esp_gatt_status_t status // uint16_t app_id // - case ESP_GATTC_REG_EVT: { - m_gattc_if = gattc_if; - // pass on the registration status result, in case of failure - m_semaphoreRegEvt.give(evtParam->reg.status); - break; - } // ESP_GATTC_REG_EVT + case ESP_GATTC_REG_EVT: + { + m_gattc_if = gattc_if; + // pass on the registration status result, in case of failure + m_semaphoreRegEvt.give(evtParam->reg.status); + break; + } // ESP_GATTC_REG_EVT case ESP_GATTC_CFG_MTU_EVT: if (evtParam->cfg_mtu.conn_id != getConnId()) break; - if(evtParam->cfg_mtu.status != ESP_GATT_OK) { + if (evtParam->cfg_mtu.status != ESP_GATT_OK) { log_e("Config mtu failed"); } m_mtu = evtParam->cfg_mtu.mtu; break; - case ESP_GATTC_CONNECT_EVT: { - if (evtParam->connect.conn_id != getConnId()) break; - BLEDevice::updatePeerDevice(this, true, m_appId); - esp_err_t errRc = esp_ble_gattc_send_mtu_req(gattc_if, evtParam->connect.conn_id); - if (errRc != ESP_OK) { - log_e("esp_ble_gattc_send_mtu_req: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - } -#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig - if(BLEDevice::m_securityLevel){ - esp_ble_set_encryption(evtParam->connect.remote_bda, BLEDevice::m_securityLevel); - } + case ESP_GATTC_CONNECT_EVT: + { + if (evtParam->connect.conn_id != getConnId()) break; + BLEDevice::updatePeerDevice(this, true, m_appId); + esp_err_t errRc = esp_ble_gattc_send_mtu_req(gattc_if, evtParam->connect.conn_id); + if (errRc != ESP_OK) { + log_e("esp_ble_gattc_send_mtu_req: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + } +#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig + if (BLEDevice::m_securityLevel) { + esp_ble_set_encryption(evtParam->connect.remote_bda, BLEDevice::m_securityLevel); + } #endif // CONFIG_BLE_SMP_ENABLE - break; - } // ESP_GATTC_CONNECT_EVT + break; + } // ESP_GATTC_CONNECT_EVT // // ESP_GATTC_SEARCH_CMPL_EVT @@ -302,26 +307,27 @@ void BLEClient::gattClientEventHandler( // - esp_gatt_status_t status // - uint16_t conn_id // - case ESP_GATTC_SEARCH_CMPL_EVT: { - if (evtParam->search_cmpl.conn_id != getConnId()) break; - esp_ble_gattc_cb_param_t* p_data = (esp_ble_gattc_cb_param_t*)evtParam; - if (p_data->search_cmpl.status != ESP_GATT_OK){ - log_e("search service failed, error status = %x", p_data->search_cmpl.status); - break; - } + case ESP_GATTC_SEARCH_CMPL_EVT: + { + if (evtParam->search_cmpl.conn_id != getConnId()) break; + esp_ble_gattc_cb_param_t* p_data = (esp_ble_gattc_cb_param_t*)evtParam; + if (p_data->search_cmpl.status != ESP_GATT_OK) { + log_e("search service failed, error status = %x", p_data->search_cmpl.status); + break; + } #ifndef ARDUINO_ARCH_ESP32 // commented out just for now to keep backward compatibility - // if(p_data->search_cmpl.searched_service_source == ESP_GATT_SERVICE_FROM_REMOTE_DEVICE) { - // log_i("Get service information from remote device"); - // } else if (p_data->search_cmpl.searched_service_source == ESP_GATT_SERVICE_FROM_NVS_FLASH) { - // log_i("Get service information from flash"); - // } else { - // log_i("unknown service source"); - // } +// if(p_data->search_cmpl.searched_service_source == ESP_GATT_SERVICE_FROM_REMOTE_DEVICE) { +// log_i("Get service information from remote device"); +// } else if (p_data->search_cmpl.searched_service_source == ESP_GATT_SERVICE_FROM_NVS_FLASH) { +// log_i("Get service information from flash"); +// } else { +// log_i("unknown service source"); +// } #endif - m_semaphoreSearchCmplEvt.give(0); - break; - } // ESP_GATTC_SEARCH_CMPL_EVT + m_semaphoreSearchCmplEvt.give(0); + break; + } // ESP_GATTC_SEARCH_CMPL_EVT // @@ -333,43 +339,44 @@ void BLEClient::gattClientEventHandler( // - uint16_t end_handle // - esp_gatt_id_t srvc_id // - case ESP_GATTC_SEARCH_RES_EVT: { - if (evtParam->search_res.conn_id != getConnId()) break; - BLEUUID uuid = BLEUUID(evtParam->search_res.srvc_id); - BLERemoteService* pRemoteService = new BLERemoteService( - evtParam->search_res.srvc_id, - this, - evtParam->search_res.start_handle, - evtParam->search_res.end_handle - ); - m_servicesMap.insert(std::pair(uuid.toString(), pRemoteService)); - m_servicesMapByInstID.insert(std::pair(pRemoteService, evtParam->search_res.srvc_id.inst_id)); - break; - } // ESP_GATTC_SEARCH_RES_EVT + case ESP_GATTC_SEARCH_RES_EVT: + { + if (evtParam->search_res.conn_id != getConnId()) break; + BLEUUID uuid = BLEUUID(evtParam->search_res.srvc_id); + BLERemoteService* pRemoteService = new BLERemoteService( + evtParam->search_res.srvc_id, + this, + evtParam->search_res.start_handle, + evtParam->search_res.end_handle); + m_servicesMap.insert(std::pair(uuid.toString(), pRemoteService)); + m_servicesMapByInstID.insert(std::pair(pRemoteService, evtParam->search_res.srvc_id.inst_id)); + break; + } // ESP_GATTC_SEARCH_RES_EVT - default: { - break; - } - } // Switch + default: + { + break; + } + } // Switch // Pass the request on to all services. - for (auto &myPair : m_servicesMap) { - myPair.second->gattClientEventHandler(event, gattc_if, evtParam); + for (auto& myPair : m_servicesMap) { + myPair.second->gattClientEventHandler(event, gattc_if, evtParam); } -} // gattClientEventHandler +} // gattClientEventHandler uint16_t BLEClient::getConnId() { return m_conn_id; -} // getConnId +} // getConnId esp_gatt_if_t BLEClient::getGattcIf() { return m_gattc_if; -} // getGattcIf +} // getGattcIf /** @@ -379,7 +386,7 @@ esp_gatt_if_t BLEClient::getGattcIf() { */ BLEAddress BLEClient::getPeerAddress() { return m_peerAddress; -} // getAddress +} // getAddress /** @@ -404,7 +411,7 @@ int BLEClient::getRssi() { int rssiValue = m_semaphoreRssiCmplEvt.wait("getRssi"); log_v("<< getRssi(): %d", rssiValue); return rssiValue; -} // getRssi +} // getRssi /** @@ -413,8 +420,8 @@ int BLEClient::getRssi() { * @return A reference to the Service or nullptr if don't know about it. */ BLERemoteService* BLEClient::getService(const char* uuid) { - return getService(BLEUUID(uuid)); -} // getService + return getService(BLEUUID(uuid)); +} // getService /** @@ -425,25 +432,25 @@ BLERemoteService* BLEClient::getService(const char* uuid) { */ BLERemoteService* BLEClient::getService(BLEUUID uuid) { log_v(">> getService: uuid: %s", uuid.toString().c_str()); -// Design -// ------ -// We wish to retrieve the service given its UUID. It is possible that we have not yet asked the -// device what services it has in which case we have nothing to match against. If we have not -// asked the device about its services, then we do that now. Once we get the results we can then -// examine the services map to see if it has the service we are looking for. + // Design + // ------ + // We wish to retrieve the service given its UUID. It is possible that we have not yet asked the + // device what services it has in which case we have nothing to match against. If we have not + // asked the device about its services, then we do that now. Once we get the results we can then + // examine the services map to see if it has the service we are looking for. if (!m_haveServices) { getServices(); } String uuidStr = uuid.toString(); - for (auto &myPair : m_servicesMap) { + for (auto& myPair : m_servicesMap) { if (myPair.first == uuidStr) { log_v("<< getService: found the service with uuid: %s", uuid.toString().c_str()); return myPair.second; } - } // End of each of the services. + } // End of each of the services. log_v("<< getService: not found"); return nullptr; -} // getService +} // getService /** @@ -453,7 +460,7 @@ BLERemoteService* BLEClient::getService(BLEUUID uuid) { * @return N/A */ std::map* BLEClient::getServices() { -/* + /* * Design * ------ * We invoke esp_ble_gattc_search_service. This will request a list of the service exposed by the @@ -461,13 +468,13 @@ std::map* BLEClient::getServices() { * and will culminate with an ESP_GATTC_SEARCH_CMPL_EVT when all have been received. */ log_v(">> getServices"); -// TODO implement retrieving services from cache - clearServices(); // Clear any services that may exist. + // TODO implement retrieving services from cache + clearServices(); // Clear any services that may exist. esp_err_t errRc = esp_ble_gattc_search_service( getGattcIf(), getConnId(), - NULL // Filter UUID + NULL // Filter UUID ); m_semaphoreSearchCmplEvt.take("getServices"); @@ -475,11 +482,11 @@ std::map* BLEClient::getServices() { log_e("esp_ble_gattc_search_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return &m_servicesMap; } - // If sucessfull, remember that we now have services. + // If successful, remember that we now have services. m_haveServices = (m_semaphoreSearchCmplEvt.wait("getServices") == 0); log_v("<< getServices"); return &m_servicesMap; -} // getServices +} // getServices /** @@ -493,7 +500,7 @@ String BLEClient::getValue(BLEUUID serviceUUID, BLEUUID characteristicUUID) { String ret = getService(serviceUUID)->getCharacteristic(characteristicUUID)->readValue(); log_v("<read_rssi_cmpl.rssi); - break; - } // ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT + case ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT: + { + m_semaphoreRssiCmplEvt.give((uint32_t)param->read_rssi_cmpl.rssi); + break; + } // ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT default: break; } -} // handleGAPEvent +} // handleGAPEvent /** @@ -532,7 +540,7 @@ void BLEClient::handleGAPEvent( */ bool BLEClient::isConnected() { return m_isConnected; -} // isConnected +} // isConnected @@ -542,7 +550,7 @@ bool BLEClient::isConnected() { */ void BLEClient::setClientCallbacks(BLEClientCallbacks* pClientCallbacks) { m_pClientCallbacks = pClientCallbacks; -} // setClientCallbacks +} // setClientCallbacks /** @@ -555,7 +563,7 @@ void BLEClient::setValue(BLEUUID serviceUUID, BLEUUID characteristicUUID, String log_v(">> setValue: serviceUUID: %s, characteristicUUID: %s", serviceUUID.toString().c_str(), characteristicUUID.toString().c_str()); getService(serviceUUID)->getCharacteristic(characteristicUUID)->writeValue(value); log_v("<< setValue"); -} // setValue +} // setValue uint16_t BLEClient::getMTU() { return m_mtu; @@ -567,26 +575,21 @@ uint16_t BLEClient::getMTU() { Should be called once after client connects if MTU size needs to be changed. @return bool indicating if MTU was successfully set locally and on remote. */ -bool BLEClient::setMTU(uint16_t mtu) -{ +bool BLEClient::setMTU(uint16_t mtu) { esp_err_t err = esp_ble_gatt_set_local_mtu(mtu); //First must set local MTU value. - if (err == ESP_OK) - { - err = esp_ble_gattc_send_mtu_req(m_gattc_if,m_conn_id); //Once local is set successfully set remote size - if (err!=ESP_OK) - { - log_e("Error setting send MTU request MTU: %d err=%d", mtu,err); + if (err == ESP_OK) { + err = esp_ble_gattc_send_mtu_req(m_gattc_if, m_conn_id); //Once local is set successfully set remote size + if (err != ESP_OK) { + log_e("Error setting send MTU request MTU: %d err=%d", mtu, err); return false; } - } - else - { + } else { log_e("can't set local mtu value: %d", mtu); return false; } log_v("<< setLocalMTU"); - m_mtu = mtu; //successfully changed + m_mtu = mtu; //successfully changed return true; } @@ -601,12 +604,12 @@ bool BLEClient::setMTU(uint16_t mtu) String BLEClient::toString() { String res = "peer address: " + m_peerAddress.toString(); res += "\nServices:\n"; - for (auto &myPair : m_servicesMap) { + for (auto& myPair : m_servicesMap) { res += myPair.second->toString() + "\n"; // myPair.second is the value } return res; -} // toString +} // toString #endif /* CONFIG_BLUEDROID_ENABLED */ #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLEClient.h b/libraries/BLE/src/BLEClient.h index 2c8bc2c4ab9..84a12b92245 100644 --- a/libraries/BLE/src/BLEClient.h +++ b/libraries/BLE/src/BLEClient.h @@ -36,61 +36,61 @@ class BLEClient { BLEClient(); ~BLEClient(); - bool connect(BLEAdvertisedDevice* device); - bool connectTimeout(BLEAdvertisedDevice* device, uint32_t timeoutMS = portMAX_DELAY); - bool connect(BLEAddress address, esp_ble_addr_type_t type = BLE_ADDR_TYPE_PUBLIC, uint32_t timeoutMS = portMAX_DELAY); // Connect to the remote BLE Server - void disconnect(); // Disconnect from the remote BLE Server - BLEAddress getPeerAddress(); // Get the address of the remote BLE Server - int getRssi(); // Get the RSSI of the remote BLE Server - std::map* getServices(); // Get a map of the services offered by the remote BLE Server - BLERemoteService* getService(const char* uuid); // Get a reference to a specified service offered by the remote BLE server. - BLERemoteService* getService(BLEUUID uuid); // Get a reference to a specified service offered by the remote BLE server. - String getValue(BLEUUID serviceUUID, BLEUUID characteristicUUID); // Get the value of a given characteristic at a given service. - - void handleGAPEvent( - esp_gap_ble_cb_event_t event, - esp_ble_gap_cb_param_t* param); - - bool isConnected(); // Return true if we are connected. - - void setClientCallbacks(BLEClientCallbacks *pClientCallbacks); - void setValue(BLEUUID serviceUUID, BLEUUID characteristicUUID, String value); // Set the value of a given characteristic at a given service. - - String toString(); // Return a string representation of this client. - uint16_t getConnId(); - esp_gatt_if_t getGattcIf(); - uint16_t getMTU(); - bool setMTU(uint16_t mtu); - -uint16_t m_appId; + bool connect(BLEAdvertisedDevice* device); + bool connectTimeout(BLEAdvertisedDevice* device, uint32_t timeoutMS = portMAX_DELAY); + bool connect(BLEAddress address, esp_ble_addr_type_t type = BLE_ADDR_TYPE_PUBLIC, uint32_t timeoutMS = portMAX_DELAY); // Connect to the remote BLE Server + void disconnect(); // Disconnect from the remote BLE Server + BLEAddress getPeerAddress(); // Get the address of the remote BLE Server + int getRssi(); // Get the RSSI of the remote BLE Server + std::map* getServices(); // Get a map of the services offered by the remote BLE Server + BLERemoteService* getService(const char* uuid); // Get a reference to a specified service offered by the remote BLE server. + BLERemoteService* getService(BLEUUID uuid); // Get a reference to a specified service offered by the remote BLE server. + String getValue(BLEUUID serviceUUID, BLEUUID characteristicUUID); // Get the value of a given characteristic at a given service. + + void handleGAPEvent( + esp_gap_ble_cb_event_t event, + esp_ble_gap_cb_param_t* param); + + bool isConnected(); // Return true if we are connected. + + void setClientCallbacks(BLEClientCallbacks* pClientCallbacks); + void setValue(BLEUUID serviceUUID, BLEUUID characteristicUUID, String value); // Set the value of a given characteristic at a given service. + + String toString(); // Return a string representation of this client. + uint16_t getConnId(); + esp_gatt_if_t getGattcIf(); + uint16_t getMTU(); + bool setMTU(uint16_t mtu); + + uint16_t m_appId; private: friend class BLEDevice; friend class BLERemoteService; friend class BLERemoteCharacteristic; friend class BLERemoteDescriptor; - void gattClientEventHandler( + void gattClientEventHandler( esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* param); - BLEAddress m_peerAddress = BLEAddress((uint8_t*)"\0\0\0\0\0\0"); // The BD address of the remote server. - uint16_t m_conn_id; -// int m_deviceType; + BLEAddress m_peerAddress = BLEAddress((uint8_t*)"\0\0\0\0\0\0"); // The BD address of the remote server. + uint16_t m_conn_id; + // int m_deviceType; esp_gatt_if_t m_gattc_if; - bool m_haveServices = false; // Have we previously obtain the set of services from the remote server. - bool m_isConnected = false; // Are we currently connected. + bool m_haveServices = false; // Have we previously obtain the set of services from the remote server. + bool m_isConnected = false; // Are we currently connected. BLEClientCallbacks* m_pClientCallbacks; - FreeRTOS::Semaphore m_semaphoreRegEvt = FreeRTOS::Semaphore("RegEvt"); - FreeRTOS::Semaphore m_semaphoreOpenEvt = FreeRTOS::Semaphore("OpenEvt"); + FreeRTOS::Semaphore m_semaphoreRegEvt = FreeRTOS::Semaphore("RegEvt"); + FreeRTOS::Semaphore m_semaphoreOpenEvt = FreeRTOS::Semaphore("OpenEvt"); FreeRTOS::Semaphore m_semaphoreSearchCmplEvt = FreeRTOS::Semaphore("SearchCmplEvt"); - FreeRTOS::Semaphore m_semaphoreRssiCmplEvt = FreeRTOS::Semaphore("RssiCmplEvt"); + FreeRTOS::Semaphore m_semaphoreRssiCmplEvt = FreeRTOS::Semaphore("RssiCmplEvt"); std::map m_servicesMap; std::map m_servicesMapByInstID; - void clearServices(); // Clear any existing services. + void clearServices(); // Clear any existing services. uint16_t m_mtu = 23; -}; // class BLEDevice +}; // class BLEDevice /** @@ -98,9 +98,9 @@ uint16_t m_appId; */ class BLEClientCallbacks { public: - virtual ~BLEClientCallbacks() {}; - virtual void onConnect(BLEClient *pClient) = 0; - virtual void onDisconnect(BLEClient *pClient) = 0; + virtual ~BLEClientCallbacks(){}; + virtual void onConnect(BLEClient* pClient) = 0; + virtual void onDisconnect(BLEClient* pClient) = 0; }; #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLEDescriptor.cpp b/libraries/BLE/src/BLEDescriptor.cpp index d39c3b43d6c..3132f4d2efa 100644 --- a/libraries/BLE/src/BLEDescriptor.cpp +++ b/libraries/BLE/src/BLEDescriptor.cpp @@ -26,30 +26,31 @@ /** * @brief BLEDescriptor constructor. */ -BLEDescriptor::BLEDescriptor(const char* uuid, uint16_t len) : BLEDescriptor(BLEUUID(uuid), len) { +BLEDescriptor::BLEDescriptor(const char* uuid, uint16_t len) + : BLEDescriptor(BLEUUID(uuid), len) { } /** * @brief BLEDescriptor constructor. */ BLEDescriptor::BLEDescriptor(BLEUUID uuid, uint16_t max_len) { - m_bleUUID = uuid; - m_value.attr_len = 0; // Initial length is 0. - m_value.attr_max_len = max_len; // Maximum length of the data. - m_handle = NULL_HANDLE; // Handle is initially unknown. - m_pCharacteristic = nullptr; // No initial characteristic. - m_pCallback = nullptr; // No initial callback. + m_bleUUID = uuid; + m_value.attr_len = 0; // Initial length is 0. + m_value.attr_max_len = max_len; // Maximum length of the data. + m_handle = NULL_HANDLE; // Handle is initially unknown. + m_pCharacteristic = nullptr; // No initial characteristic. + m_pCallback = nullptr; // No initial callback. - m_value.attr_value = (uint8_t*) malloc(max_len); // Allocate storage for the value. -} // BLEDescriptor + m_value.attr_value = (uint8_t*)malloc(max_len); // Allocate storage for the value. +} // BLEDescriptor /** * @brief BLEDescriptor destructor. */ BLEDescriptor::~BLEDescriptor() { - free(m_value.attr_value); // Release the storage we created in the constructor. -} // ~BLEDescriptor + free(m_value.attr_value); // Release the storage we created in the constructor. +} // ~BLEDescriptor /** @@ -64,17 +65,17 @@ void BLEDescriptor::executeCreate(BLECharacteristic* pCharacteristic) { return; } - m_pCharacteristic = pCharacteristic; // Save the characteristic associated with this service. + m_pCharacteristic = pCharacteristic; // Save the characteristic associated with this service. esp_attr_control_t control; control.auto_rsp = ESP_GATT_AUTO_RSP; m_semaphoreCreateEvt.take("executeCreate"); esp_err_t errRc = ::esp_ble_gatts_add_char_descr( - pCharacteristic->getService()->getHandle(), - getUUID().getNative(), - (esp_gatt_perm_t)m_permissions, - &m_value, - &control); + pCharacteristic->getService()->getHandle(), + getUUID().getNative(), + (esp_gatt_perm_t)m_permissions, + &m_value, + &control); if (errRc != ESP_OK) { log_e("<< esp_ble_gatts_add_char_descr: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); return; @@ -82,7 +83,7 @@ void BLEDescriptor::executeCreate(BLECharacteristic* pCharacteristic) { m_semaphoreCreateEvt.wait("executeCreate"); log_v("<< executeCreate"); -} // executeCreate +} // executeCreate /** @@ -91,7 +92,7 @@ void BLEDescriptor::executeCreate(BLECharacteristic* pCharacteristic) { */ uint16_t BLEDescriptor::getHandle() { return m_handle; -} // getHandle +} // getHandle /** @@ -100,7 +101,7 @@ uint16_t BLEDescriptor::getHandle() { */ size_t BLEDescriptor::getLength() { return m_value.attr_len; -} // getLength +} // getLength /** @@ -108,7 +109,7 @@ size_t BLEDescriptor::getLength() { */ BLEUUID BLEDescriptor::getUUID() { return m_bleUUID; -} // getUUID +} // getUUID @@ -118,7 +119,7 @@ BLEUUID BLEDescriptor::getUUID() { */ uint8_t* BLEDescriptor::getValue() { return m_value.attr_value; -} // getValue +} // getValue /** @@ -128,9 +129,9 @@ uint8_t* BLEDescriptor::getValue() { * @param [in] param */ void BLEDescriptor::handleGATTServerEvent( - esp_gatts_cb_event_t event, - esp_gatt_if_t gatts_if, - esp_ble_gatts_cb_param_t* param) { + esp_gatts_cb_event_t event, + esp_gatt_if_t gatts_if, + esp_ble_gatts_cb_param_t* param) { switch (event) { // ESP_GATTS_ADD_CHAR_DESCR_EVT // @@ -139,16 +140,14 @@ void BLEDescriptor::handleGATTServerEvent( // - uint16_t attr_handle // - uint16_t service_handle // - esp_bt_uuid_t char_uuid - case ESP_GATTS_ADD_CHAR_DESCR_EVT: { - if (m_pCharacteristic != nullptr && - m_bleUUID.equals(BLEUUID(param->add_char_descr.descr_uuid)) && - m_pCharacteristic->getService()->getHandle() == param->add_char_descr.service_handle && - m_pCharacteristic == m_pCharacteristic->getService()->getLastCreatedCharacteristic()) { - setHandle(param->add_char_descr.attr_handle); - m_semaphoreCreateEvt.give(); - } - break; - } // ESP_GATTS_ADD_CHAR_DESCR_EVT + case ESP_GATTS_ADD_CHAR_DESCR_EVT: + { + if (m_pCharacteristic != nullptr && m_bleUUID.equals(BLEUUID(param->add_char_descr.descr_uuid)) && m_pCharacteristic->getService()->getHandle() == param->add_char_descr.service_handle && m_pCharacteristic == m_pCharacteristic->getService()->getLastCreatedCharacteristic()) { + setHandle(param->add_char_descr.attr_handle); + m_semaphoreCreateEvt.give(); + } + break; + } // ESP_GATTS_ADD_CHAR_DESCR_EVT // ESP_GATTS_WRITE_EVT - A request to write the value of a descriptor has arrived. // @@ -162,17 +161,18 @@ void BLEDescriptor::handleGATTServerEvent( // - bool is_prep // - uint16_t len // - uint8_t *value - case ESP_GATTS_WRITE_EVT: { - if (param->write.handle == m_handle) { - setValue(param->write.value, param->write.len); // Set the value of the descriptor. + case ESP_GATTS_WRITE_EVT: + { + if (param->write.handle == m_handle) { + setValue(param->write.value, param->write.len); // Set the value of the descriptor. - if (m_pCallback != nullptr) { // We have completed the write, if there is a user supplied callback handler, invoke it now. - m_pCallback->onWrite(this); // Invoke the onWrite callback handler. - } - } // End of ... this is our handle. + if (m_pCallback != nullptr) { // We have completed the write, if there is a user supplied callback handler, invoke it now. + m_pCallback->onWrite(this); // Invoke the onWrite callback handler. + } + } // End of ... this is our handle. - break; - } // ESP_GATTS_WRITE_EVT + break; + } // ESP_GATTS_WRITE_EVT // ESP_GATTS_READ_EVT - A request to read the value of a descriptor has arrived. // @@ -185,21 +185,22 @@ void BLEDescriptor::handleGATTServerEvent( // - bool is_long // - bool need_rsp // - case ESP_GATTS_READ_EVT: { - if (param->read.handle == m_handle) { // If this event is for this descriptor ... process it + case ESP_GATTS_READ_EVT: + { + if (param->read.handle == m_handle) { // If this event is for this descriptor ... process it - if (m_pCallback != nullptr) { // If we have a user supplied callback, invoke it now. - m_pCallback->onRead(this); // Invoke the onRead callback method in the callback handler. - } + if (m_pCallback != nullptr) { // If we have a user supplied callback, invoke it now. + m_pCallback->onRead(this); // Invoke the onRead callback method in the callback handler. + } - } // End of this is our handle - break; - } // ESP_GATTS_READ_EVT + } // End of this is our handle + break; + } // ESP_GATTS_READ_EVT default: break; - } // switch event -} // handleGATTServerEvent + } // switch event +} // handleGATTServerEvent /** @@ -207,10 +208,10 @@ void BLEDescriptor::handleGATTServerEvent( * @param [in] pCallbacks An instance of a callback structure used to define any callbacks for the descriptor. */ void BLEDescriptor::setCallbacks(BLEDescriptorCallbacks* pCallback) { - log_v(">> setCallbacks: 0x%x", (uint32_t) pCallback); + log_v(">> setCallbacks: 0x%x", (uint32_t)pCallback); m_pCallback = pCallback; log_v("<< setCallbacks"); -} // setCallbacks +} // setCallbacks /** @@ -223,7 +224,7 @@ void BLEDescriptor::setHandle(uint16_t handle) { log_v(">> setHandle(0x%.2x): Setting descriptor handle to be 0x%.2x", handle, handle); m_handle = handle; log_v("<< setHandle()"); -} // setHandle +} // setHandle /** @@ -239,10 +240,10 @@ void BLEDescriptor::setValue(uint8_t* data, size_t length) { m_value.attr_len = length; memcpy(m_value.attr_value, data, length); if (m_handle != NULL_HANDLE) { - esp_ble_gatts_set_attr_value(m_handle, length, (const uint8_t *)data); + esp_ble_gatts_set_attr_value(m_handle, length, (const uint8_t*)data); log_d("Set the value in the GATTS database using handle 0x%x", m_handle); } -} // setValue +} // setValue /** @@ -250,8 +251,8 @@ void BLEDescriptor::setValue(uint8_t* data, size_t length) { * @param [in] value The value of the descriptor in string form. */ void BLEDescriptor::setValue(String value) { - setValue((uint8_t*) value.c_str(), value.length()); -} // setValue + setValue((uint8_t*)value.c_str(), value.length()); +} // setValue void BLEDescriptor::setAccessPermissions(esp_gatt_perm_t perm) { m_permissions = perm; @@ -266,7 +267,7 @@ String BLEDescriptor::toString() { snprintf(hex, sizeof(hex), "%04x", m_handle); String res = "UUID: " + m_bleUUID.toString() + ", handle: 0x" + hex; return res; -} // toString +} // toString BLEDescriptorCallbacks::~BLEDescriptorCallbacks() {} @@ -278,7 +279,7 @@ BLEDescriptorCallbacks::~BLEDescriptorCallbacks() {} void BLEDescriptorCallbacks::onRead(BLEDescriptor* pDescriptor) { log_d("BLEDescriptorCallbacks", ">> onRead: default"); log_d("BLEDescriptorCallbacks", "<< onRead"); -} // onRead +} // onRead /** @@ -288,7 +289,7 @@ void BLEDescriptorCallbacks::onRead(BLEDescriptor* pDescriptor) { void BLEDescriptorCallbacks::onWrite(BLEDescriptor* pDescriptor) { log_d("BLEDescriptorCallbacks", ">> onWrite: default"); log_d("BLEDescriptorCallbacks", "<< onWrite"); -} // onWrite +} // onWrite #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLEDescriptor.h b/libraries/BLE/src/BLEDescriptor.h index 2e834079de3..07dfd0dfba9 100644 --- a/libraries/BLE/src/BLEDescriptor.h +++ b/libraries/BLE/src/BLEDescriptor.h @@ -31,36 +31,36 @@ class BLEDescriptor { BLEDescriptor(BLEUUID uuid, uint16_t max_len = 100); virtual ~BLEDescriptor(); - uint16_t getHandle(); // Get the handle of the descriptor. - size_t getLength(); // Get the length of the value of the descriptor. - BLEUUID getUUID(); // Get the UUID of the descriptor. - uint8_t* getValue(); // Get a pointer to the value of the descriptor. + uint16_t getHandle(); // Get the handle of the descriptor. + size_t getLength(); // Get the length of the value of the descriptor. + BLEUUID getUUID(); // Get the UUID of the descriptor. + uint8_t* getValue(); // Get a pointer to the value of the descriptor. void handleGATTServerEvent( - esp_gatts_cb_event_t event, - esp_gatt_if_t gatts_if, - esp_ble_gatts_cb_param_t* param); + esp_gatts_cb_event_t event, + esp_gatt_if_t gatts_if, + esp_ble_gatts_cb_param_t* param); void setAccessPermissions(esp_gatt_perm_t perm); // Set the permissions of the descriptor. void setCallbacks(BLEDescriptorCallbacks* pCallbacks); // Set callbacks to be invoked for the descriptor. void setValue(uint8_t* data, size_t size); // Set the value of the descriptor as a pointer to data. - void setValue(String value); // Set the value of the descriptor as a data buffer. + void setValue(String value); // Set the value of the descriptor as a data buffer. - String toString(); // Convert the descriptor to a string representation. + String toString(); // Convert the descriptor to a string representation. private: friend class BLEDescriptorMap; friend class BLECharacteristic; - BLEUUID m_bleUUID; - uint16_t m_handle; + BLEUUID m_bleUUID; + uint16_t m_handle; BLEDescriptorCallbacks* m_pCallback; - BLECharacteristic* m_pCharacteristic; - esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE; - FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt"); - esp_attr_value_t m_value; + BLECharacteristic* m_pCharacteristic; + esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE; + FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt"); + esp_attr_value_t m_value; void executeCreate(BLECharacteristic* pCharacteristic); void setHandle(uint16_t handle); -}; // BLEDescriptor +}; // BLEDescriptor /** diff --git a/libraries/BLE/src/BLEDescriptorMap.cpp b/libraries/BLE/src/BLEDescriptorMap.cpp index 50f23d76541..3f2ffaaa8d9 100644 --- a/libraries/BLE/src/BLEDescriptorMap.cpp +++ b/libraries/BLE/src/BLEDescriptorMap.cpp @@ -13,7 +13,7 @@ #include #include "BLECharacteristic.h" #include "BLEDescriptor.h" -#include // ESP32 BLE +#include // ESP32 BLE #ifdef ARDUINO_ARCH_ESP32 #include "esp32-hal-log.h" #endif @@ -24,7 +24,7 @@ * @return The descriptor. If not present, then nullptr is returned. */ BLEDescriptor* BLEDescriptorMap::getByUUID(const char* uuid) { - return getByUUID(BLEUUID(uuid)); + return getByUUID(BLEUUID(uuid)); } @@ -34,14 +34,14 @@ BLEDescriptor* BLEDescriptorMap::getByUUID(const char* uuid) { * @return The descriptor. If not present, then nullptr is returned. */ BLEDescriptor* BLEDescriptorMap::getByUUID(BLEUUID uuid) { - for (auto &myPair : m_uuidMap) { - if (myPair.first->getUUID().equals(uuid)) { - return myPair.first; - } - } - //return m_uuidMap.at(uuid.toString()); - return nullptr; -} // getByUUID + for (auto& myPair : m_uuidMap) { + if (myPair.first->getUUID().equals(uuid)) { + return myPair.first; + } + } + //return m_uuidMap.at(uuid.toString()); + return nullptr; +} // getByUUID /** @@ -50,8 +50,8 @@ BLEDescriptor* BLEDescriptorMap::getByUUID(BLEUUID uuid) { * @return The descriptor. */ BLEDescriptor* BLEDescriptorMap::getByHandle(uint16_t handle) { - return m_handleMap.at(handle); -} // getByHandle + return m_handleMap.at(handle); +} // getByHandle /** @@ -60,9 +60,9 @@ BLEDescriptor* BLEDescriptorMap::getByHandle(uint16_t handle) { * @param [in] characteristic The descriptor to cache. * @return N/A. */ -void BLEDescriptorMap::setByUUID(const char* uuid, BLEDescriptor* pDescriptor){ - m_uuidMap.insert(std::pair(pDescriptor, uuid)); -} // setByUUID +void BLEDescriptorMap::setByUUID(const char* uuid, BLEDescriptor* pDescriptor) { + m_uuidMap.insert(std::pair(pDescriptor, uuid)); +} // setByUUID @@ -73,8 +73,8 @@ void BLEDescriptorMap::setByUUID(const char* uuid, BLEDescriptor* pDescriptor){ * @return N/A. */ void BLEDescriptorMap::setByUUID(BLEUUID uuid, BLEDescriptor* pDescriptor) { - m_uuidMap.insert(std::pair(pDescriptor, uuid.toString())); -} // setByUUID + m_uuidMap.insert(std::pair(pDescriptor, uuid.toString())); +} // setByUUID /** @@ -84,8 +84,8 @@ void BLEDescriptorMap::setByUUID(BLEUUID uuid, BLEDescriptor* pDescriptor) { * @return N/A. */ void BLEDescriptorMap::setByHandle(uint16_t handle, BLEDescriptor* pDescriptor) { - m_handleMap.insert(std::pair(handle, pDescriptor)); -} // setByHandle + m_handleMap.insert(std::pair(handle, pDescriptor)); +} // setByHandle /** @@ -93,36 +93,36 @@ void BLEDescriptorMap::setByHandle(uint16_t handle, BLEDescriptor* pDescriptor) * @return A string representation of the descriptor map. */ String BLEDescriptorMap::toString() { - String res; - char hex[5]; - int count = 0; - for (auto &myPair : m_uuidMap) { - if (count > 0) {res += "\n";} - snprintf(hex, sizeof(hex), "%04x", myPair.first->getHandle()); - count++; - res += "handle: 0x"; - res += hex; - res += ", uuid: " + myPair.first->getUUID().toString(); - } - return res; -} // toString + String res; + char hex[5]; + int count = 0; + for (auto& myPair : m_uuidMap) { + if (count > 0) { res += "\n"; } + snprintf(hex, sizeof(hex), "%04x", myPair.first->getHandle()); + count++; + res += "handle: 0x"; + res += hex; + res += ", uuid: " + myPair.first->getUUID().toString(); + } + return res; +} // toString /** - * @breif Pass the GATT server event onwards to each of the descriptors found in the mapping + * @brief Pass the GATT server event onwards to each of the descriptors found in the mapping * @param [in] event * @param [in] gatts_if * @param [in] param */ void BLEDescriptorMap::handleGATTServerEvent( - esp_gatts_cb_event_t event, - esp_gatt_if_t gatts_if, - esp_ble_gatts_cb_param_t* param) { - // Invoke the handler for every descriptor we have. - for (auto &myPair : m_uuidMap) { - myPair.first->handleGATTServerEvent(event, gatts_if, param); - } -} // handleGATTServerEvent + esp_gatts_cb_event_t event, + esp_gatt_if_t gatts_if, + esp_ble_gatts_cb_param_t* param) { + // Invoke the handler for every descriptor we have. + for (auto& myPair : m_uuidMap) { + myPair.first->handleGATTServerEvent(event, gatts_if, param); + } +} // handleGATTServerEvent /** @@ -130,12 +130,12 @@ void BLEDescriptorMap::handleGATTServerEvent( * @return The first descriptor in the map. */ BLEDescriptor* BLEDescriptorMap::getFirst() { - m_iterator = m_uuidMap.begin(); - if (m_iterator == m_uuidMap.end()) return nullptr; - BLEDescriptor* pRet = m_iterator->first; - m_iterator++; - return pRet; -} // getFirst + m_iterator = m_uuidMap.begin(); + if (m_iterator == m_uuidMap.end()) return nullptr; + BLEDescriptor* pRet = m_iterator->first; + m_iterator++; + return pRet; +} // getFirst /** @@ -143,11 +143,11 @@ BLEDescriptor* BLEDescriptorMap::getFirst() { * @return The next descriptor in the map. */ BLEDescriptor* BLEDescriptorMap::getNext() { - if (m_iterator == m_uuidMap.end()) return nullptr; - BLEDescriptor* pRet = m_iterator->first; - m_iterator++; - return pRet; -} // getNext + if (m_iterator == m_uuidMap.end()) return nullptr; + BLEDescriptor* pRet = m_iterator->first; + m_iterator++; + return pRet; +} // getNext #endif /* CONFIG_BLUEDROID_ENABLED */ #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLEDevice.cpp b/libraries/BLE/src/BLEDevice.cpp index 141e8eb96b9..d20bc141d1b 100644 --- a/libraries/BLE/src/BLEDevice.cpp +++ b/libraries/BLE/src/BLEDevice.cpp @@ -14,17 +14,17 @@ #include #include #include -#include // ESP32 BLE -#include // ESP32 BLE -#include // ESP32 BLE -#include // ESP32 BLE -#include // ESP32 BLE -#include // ESP32 BLE -#include // ESP32 BLE -#include // ESP32 ESP-IDF -#include // Part of C++ Standard library -#include // Part of C++ Standard library -#include // Part of C++ Standard library +#include // ESP32 BLE +#include // ESP32 BLE +#include // ESP32 BLE +#include // ESP32 BLE +#include // ESP32 BLE +#include // ESP32 BLE +#include // ESP32 BLE +#include // ESP32 ESP-IDF +#include // Part of C++ Standard library +#include // Part of C++ Standard library +#include // Part of C++ Standard library #include "BLEDevice.h" #include "BLEClient.h" @@ -42,12 +42,12 @@ * Singletons for the BLEDevice. */ BLEServer* BLEDevice::m_pServer = nullptr; -BLEScan* BLEDevice::m_pScan = nullptr; +BLEScan* BLEDevice::m_pScan = nullptr; BLEClient* BLEDevice::m_pClient = nullptr; -bool initialized = false; +bool initialized = false; esp_ble_sec_act_t BLEDevice::m_securityLevel = (esp_ble_sec_act_t)0; BLESecurityCallbacks* BLEDevice::m_securityCallbacks = nullptr; -uint16_t BLEDevice::m_localMTU = 23; // not sure if this variable is useful +uint16_t BLEDevice::m_localMTU = 23; // not sure if this variable is useful BLEAdvertising* BLEDevice::m_bleAdvertising = nullptr; uint16_t BLEDevice::m_appId = 0; std::map BLEDevice::m_connectedClientsMap; @@ -60,15 +60,15 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @return A new instance of the client. */ /* STATIC */ BLEClient* BLEDevice::createClient() { - log_v(">> createClient"); + log_v(">> createClient"); #ifndef CONFIG_GATTC_ENABLE // Check that BLE GATTC is enabled in make menuconfig - log_e("BLE GATTC is not enabled - CONFIG_GATTC_ENABLE not defined"); - abort(); + log_e("BLE GATTC is not enabled - CONFIG_GATTC_ENABLE not defined"); + abort(); #endif // CONFIG_GATTC_ENABLE - m_pClient = new BLEClient(); - log_v("<< createClient"); - return m_pClient; -} // createClient + m_pClient = new BLEClient(); + log_v("<< createClient"); + return m_pClient; +} // createClient /** @@ -76,16 +76,16 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @return A new instance of the server. */ /* STATIC */ BLEServer* BLEDevice::createServer() { - log_v(">> createServer"); + log_v(">> createServer"); #ifndef CONFIG_GATTS_ENABLE // Check that BLE GATTS is enabled in make menuconfig - log_e("BLE GATTS is not enabled - CONFIG_GATTS_ENABLE not defined"); - abort(); -#endif // CONFIG_GATTS_ENABLE - m_pServer = new BLEServer(); - m_pServer->createApp(m_appId++); - log_v("<< createServer"); - return m_pServer; -} // createServer + log_e("BLE GATTS is not enabled - CONFIG_GATTS_ENABLE not defined"); + abort(); +#endif // CONFIG_GATTS_ENABLE + m_pServer = new BLEServer(); + m_pServer->createApp(m_appId++); + log_v("<< createServer"); + return m_pServer; +} // createServer /** @@ -96,41 +96,42 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @param [in] param Parameters for the event. */ /* STATIC */ void BLEDevice::gattServerEventHandler( - esp_gatts_cb_event_t event, - esp_gatt_if_t gatts_if, - esp_ble_gatts_cb_param_t* param -) { - log_d("gattServerEventHandler [esp_gatt_if: %d] ... %s", - gatts_if, - BLEUtils::gattServerEventTypeToString(event).c_str()); + esp_gatts_cb_event_t event, + esp_gatt_if_t gatts_if, + esp_ble_gatts_cb_param_t* param) { + log_d("gattServerEventHandler [esp_gatt_if: %d] ... %s", + gatts_if, + BLEUtils::gattServerEventTypeToString(event).c_str()); - BLEUtils::dumpGattServerEvent(event, gatts_if, param); + BLEUtils::dumpGattServerEvent(event, gatts_if, param); - switch (event) { - case ESP_GATTS_CONNECT_EVT: { -#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig - if(BLEDevice::m_securityLevel){ - esp_ble_set_encryption(param->connect.remote_bda, BLEDevice::m_securityLevel); - } -#endif // CONFIG_BLE_SMP_ENABLE - break; - } // ESP_GATTS_CONNECT_EVT + switch (event) { + case ESP_GATTS_CONNECT_EVT: + { +#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig + if (BLEDevice::m_securityLevel) { + esp_ble_set_encryption(param->connect.remote_bda, BLEDevice::m_securityLevel); + } +#endif // CONFIG_BLE_SMP_ENABLE + break; + } // ESP_GATTS_CONNECT_EVT - default: { - break; - } - } // switch + default: + { + break; + } + } // switch - if (BLEDevice::m_pServer != nullptr) { - BLEDevice::m_pServer->handleGATTServerEvent(event, gatts_if, param); - } + if (BLEDevice::m_pServer != nullptr) { + BLEDevice::m_pServer->handleGATTServerEvent(event, gatts_if, param); + } - if(m_customGattsHandler != nullptr) { - m_customGattsHandler(event, gatts_if, param); - } + if (m_customGattsHandler != nullptr) { + m_customGattsHandler(event, gatts_if, param); + } -} // gattServerEventHandler +} // gattServerEventHandler /** @@ -143,145 +144,146 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @param [in] param */ /* STATIC */ void BLEDevice::gattClientEventHandler( - esp_gattc_cb_event_t event, - esp_gatt_if_t gattc_if, - esp_ble_gattc_cb_param_t* param) { - - log_d("gattClientEventHandler [esp_gatt_if: %d] ... %s", - gattc_if, BLEUtils::gattClientEventTypeToString(event).c_str()); - BLEUtils::dumpGattClientEvent(event, gattc_if, param); - - switch(event) { - case ESP_GATTC_CONNECT_EVT: { -#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig - if(BLEDevice::m_securityLevel){ - esp_ble_set_encryption(param->connect.remote_bda, BLEDevice::m_securityLevel); - } -#endif // CONFIG_BLE_SMP_ENABLE - break; - } // ESP_GATTS_CONNECT_EVT - - default: - break; - } // switch - for(auto &myPair : BLEDevice::getPeerDevices(true)) { - conn_status_t conn_status = (conn_status_t)myPair.second; - if(((BLEClient*)conn_status.peer_device)->getGattcIf() == gattc_if || ((BLEClient*)conn_status.peer_device)->getGattcIf() == ESP_GATT_IF_NONE || gattc_if == ESP_GATT_IF_NONE){ - ((BLEClient*)conn_status.peer_device)->gattClientEventHandler(event, gattc_if, param); - } - } - - if(m_customGattcHandler != nullptr) { - m_customGattcHandler(event, gattc_if, param); - } - - -} // gattClientEventHandler + esp_gattc_cb_event_t event, + esp_gatt_if_t gattc_if, + esp_ble_gattc_cb_param_t* param) { + + log_d("gattClientEventHandler [esp_gatt_if: %d] ... %s", + gattc_if, BLEUtils::gattClientEventTypeToString(event).c_str()); + BLEUtils::dumpGattClientEvent(event, gattc_if, param); + + switch (event) { + case ESP_GATTC_CONNECT_EVT: + { +#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig + if (BLEDevice::m_securityLevel) { + esp_ble_set_encryption(param->connect.remote_bda, BLEDevice::m_securityLevel); + } +#endif // CONFIG_BLE_SMP_ENABLE + break; + } // ESP_GATTS_CONNECT_EVT + + default: + break; + } // switch + for (auto& myPair : BLEDevice::getPeerDevices(true)) { + conn_status_t conn_status = (conn_status_t)myPair.second; + if (((BLEClient*)conn_status.peer_device)->getGattcIf() == gattc_if || ((BLEClient*)conn_status.peer_device)->getGattcIf() == ESP_GATT_IF_NONE || gattc_if == ESP_GATT_IF_NONE) { + ((BLEClient*)conn_status.peer_device)->gattClientEventHandler(event, gattc_if, param); + } + } + + if (m_customGattcHandler != nullptr) { + m_customGattcHandler(event, gattc_if, param); + } + + +} // gattClientEventHandler /** * @brief Handle GAP events. */ /* STATIC */ void BLEDevice::gapEventHandler( - esp_gap_ble_cb_event_t event, - esp_ble_gap_cb_param_t *param) { - - BLEUtils::dumpGapEvent(event, param); - - switch(event) { - - case ESP_GAP_BLE_OOB_REQ_EVT: /* OOB request event */ - log_i("ESP_GAP_BLE_OOB_REQ_EVT"); - break; - case ESP_GAP_BLE_LOCAL_IR_EVT: /* BLE local IR event */ - log_i("ESP_GAP_BLE_LOCAL_IR_EVT"); - break; - case ESP_GAP_BLE_LOCAL_ER_EVT: /* BLE local ER event */ - log_i("ESP_GAP_BLE_LOCAL_ER_EVT"); - break; - case ESP_GAP_BLE_NC_REQ_EVT: /* NUMERIC CONFIRMATION */ - log_i("ESP_GAP_BLE_NC_REQ_EVT"); -#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig - if(BLEDevice::m_securityCallbacks != nullptr){ - esp_ble_confirm_reply(param->ble_security.ble_req.bd_addr, BLEDevice::m_securityCallbacks->onConfirmPIN(param->ble_security.key_notif.passkey)); - } -#endif // CONFIG_BLE_SMP_ENABLE - break; - case ESP_GAP_BLE_PASSKEY_REQ_EVT: /* passkey request event */ - log_i("ESP_GAP_BLE_PASSKEY_REQ_EVT: "); - // esp_log_buffer_hex(m_remote_bda, sizeof(m_remote_bda)); -#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig - if(BLEDevice::m_securityCallbacks != nullptr){ - esp_ble_passkey_reply(param->ble_security.ble_req.bd_addr, true, BLEDevice::m_securityCallbacks->onPassKeyRequest()); - } -#endif // CONFIG_BLE_SMP_ENABLE - break; - /* + esp_gap_ble_cb_event_t event, + esp_ble_gap_cb_param_t* param) { + + BLEUtils::dumpGapEvent(event, param); + + switch (event) { + + case ESP_GAP_BLE_OOB_REQ_EVT: /* OOB request event */ + log_i("ESP_GAP_BLE_OOB_REQ_EVT"); + break; + case ESP_GAP_BLE_LOCAL_IR_EVT: /* BLE local IR event */ + log_i("ESP_GAP_BLE_LOCAL_IR_EVT"); + break; + case ESP_GAP_BLE_LOCAL_ER_EVT: /* BLE local ER event */ + log_i("ESP_GAP_BLE_LOCAL_ER_EVT"); + break; + case ESP_GAP_BLE_NC_REQ_EVT: /* NUMERIC CONFIRMATION */ + log_i("ESP_GAP_BLE_NC_REQ_EVT"); +#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig + if (BLEDevice::m_securityCallbacks != nullptr) { + esp_ble_confirm_reply(param->ble_security.ble_req.bd_addr, BLEDevice::m_securityCallbacks->onConfirmPIN(param->ble_security.key_notif.passkey)); + } +#endif // CONFIG_BLE_SMP_ENABLE + break; + case ESP_GAP_BLE_PASSKEY_REQ_EVT: /* passkey request event */ + log_i("ESP_GAP_BLE_PASSKEY_REQ_EVT: "); + // esp_log_buffer_hex(m_remote_bda, sizeof(m_remote_bda)); +#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig + if (BLEDevice::m_securityCallbacks != nullptr) { + esp_ble_passkey_reply(param->ble_security.ble_req.bd_addr, true, BLEDevice::m_securityCallbacks->onPassKeyRequest()); + } +#endif // CONFIG_BLE_SMP_ENABLE + break; + /* * TODO should we add white/black list comparison? */ - case ESP_GAP_BLE_SEC_REQ_EVT: - /* send the positive(true) security response to the peer device to accept the security request. + case ESP_GAP_BLE_SEC_REQ_EVT: + /* send the positive(true) security response to the peer device to accept the security request. If not accept the security request, should sent the security response with negative(false) accept value*/ - log_i("ESP_GAP_BLE_SEC_REQ_EVT"); -#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig - if(BLEDevice::m_securityCallbacks!=nullptr){ - esp_ble_gap_security_rsp(param->ble_security.ble_req.bd_addr, BLEDevice::m_securityCallbacks->onSecurityRequest()); - } - else{ - esp_ble_gap_security_rsp(param->ble_security.ble_req.bd_addr, true); - } -#endif // CONFIG_BLE_SMP_ENABLE - break; - /* + log_i("ESP_GAP_BLE_SEC_REQ_EVT"); +#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig + if (BLEDevice::m_securityCallbacks != nullptr) { + esp_ble_gap_security_rsp(param->ble_security.ble_req.bd_addr, BLEDevice::m_securityCallbacks->onSecurityRequest()); + } else { + esp_ble_gap_security_rsp(param->ble_security.ble_req.bd_addr, true); + } +#endif // CONFIG_BLE_SMP_ENABLE + break; + /* * */ - case ESP_GAP_BLE_PASSKEY_NOTIF_EVT: //the app will receive this evt when the IO has Output capability and the peer device IO has Input capability. - //display the passkey number to the user to input it in the peer deivce within 30 seconds - log_i("ESP_GAP_BLE_PASSKEY_NOTIF_EVT"); -#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig - log_i("passKey = %d", param->ble_security.key_notif.passkey); - if(BLEDevice::m_securityCallbacks!=nullptr){ - BLEDevice::m_securityCallbacks->onPassKeyNotify(param->ble_security.key_notif.passkey); - } -#endif // CONFIG_BLE_SMP_ENABLE - break; - case ESP_GAP_BLE_KEY_EVT: - //shows the ble key type info share with peer device to the user. - log_d("ESP_GAP_BLE_KEY_EVT"); -#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig - log_i("key type = %s", BLESecurity::esp_key_type_to_str(param->ble_security.ble_key.key_type)); -#endif // CONFIG_BLE_SMP_ENABLE - break; - case ESP_GAP_BLE_AUTH_CMPL_EVT: - log_i("ESP_GAP_BLE_AUTH_CMPL_EVT"); -#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig - if(BLEDevice::m_securityCallbacks != nullptr){ - BLEDevice::m_securityCallbacks->onAuthenticationComplete(param->ble_security.auth_cmpl); - } -#endif // CONFIG_BLE_SMP_ENABLE - break; - default: { - break; - } - } // switch - - if (BLEDevice::m_pClient != nullptr) { - BLEDevice::m_pClient->handleGAPEvent(event, param); - } - - if (BLEDevice::m_pScan != nullptr) { - BLEDevice::getScan()->handleGAPEvent(event, param); - } - - if(m_bleAdvertising != nullptr) { - BLEDevice::getAdvertising()->handleGAPEvent(event, param); - } - - if(m_customGapHandler != nullptr) { - BLEDevice::m_customGapHandler(event, param); - } - -} // gapEventHandler + case ESP_GAP_BLE_PASSKEY_NOTIF_EVT: //the app will receive this evt when the IO has Output capability and the peer device IO has Input capability. + //display the passkey number to the user to input it in the peer device within 30 seconds + log_i("ESP_GAP_BLE_PASSKEY_NOTIF_EVT"); +#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig + log_i("passKey = %d", param->ble_security.key_notif.passkey); + if (BLEDevice::m_securityCallbacks != nullptr) { + BLEDevice::m_securityCallbacks->onPassKeyNotify(param->ble_security.key_notif.passkey); + } +#endif // CONFIG_BLE_SMP_ENABLE + break; + case ESP_GAP_BLE_KEY_EVT: + //shows the ble key type info share with peer device to the user. + log_d("ESP_GAP_BLE_KEY_EVT"); +#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig + log_i("key type = %s", BLESecurity::esp_key_type_to_str(param->ble_security.ble_key.key_type)); +#endif // CONFIG_BLE_SMP_ENABLE + break; + case ESP_GAP_BLE_AUTH_CMPL_EVT: + log_i("ESP_GAP_BLE_AUTH_CMPL_EVT"); +#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig + if (BLEDevice::m_securityCallbacks != nullptr) { + BLEDevice::m_securityCallbacks->onAuthenticationComplete(param->ble_security.auth_cmpl); + } +#endif // CONFIG_BLE_SMP_ENABLE + break; + default: + { + break; + } + } // switch + + if (BLEDevice::m_pClient != nullptr) { + BLEDevice::m_pClient->handleGAPEvent(event, param); + } + + if (BLEDevice::m_pScan != nullptr) { + BLEDevice::getScan()->handleGAPEvent(event, param); + } + + if (m_bleAdvertising != nullptr) { + BLEDevice::getAdvertising()->handleGAPEvent(event, param); + } + + if (m_customGapHandler != nullptr) { + BLEDevice::m_customGapHandler(event, param); + } + +} // gapEventHandler /** @@ -289,11 +291,11 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @return The BLE device address. */ /* STATIC*/ BLEAddress BLEDevice::getAddress() { - const uint8_t* bdAddr = esp_bt_dev_get_address(); - esp_bd_addr_t addr; - memcpy(addr, bdAddr, sizeof(addr)); - return BLEAddress(addr); -} // getAddress + const uint8_t* bdAddr = esp_bt_dev_get_address(); + esp_bd_addr_t addr; + memcpy(addr, bdAddr, sizeof(addr)); + return BLEAddress(addr); +} // getAddress /** @@ -302,14 +304,14 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * try and release/delete it. */ /* STATIC */ BLEScan* BLEDevice::getScan() { - //log_v(">> getScan"); - if (m_pScan == nullptr) { - m_pScan = new BLEScan(); - //log_d(" - creating a new scan object"); - } - //log_v("<< getScan: Returning object at 0x%x", (uint32_t)m_pScan); - return m_pScan; -} // getScan + //log_v(">> getScan"); + if (m_pScan == nullptr) { + m_pScan = new BLEScan(); + //log_d(" - creating a new scan object"); + } + //log_v("<< getScan: Returning object at 0x%x", (uint32_t)m_pScan); + return m_pScan; +} // getScan /** @@ -319,14 +321,14 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @param [in] characteristicUUID */ /* STATIC */ String BLEDevice::getValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID) { - log_v(">> getValue: bdAddress: %s, serviceUUID: %s, characteristicUUID: %s", bdAddress.toString().c_str(), serviceUUID.toString().c_str(), characteristicUUID.toString().c_str()); - BLEClient* pClient = createClient(); - pClient->connect(bdAddress); - String ret = pClient->getValue(serviceUUID, characteristicUUID); - pClient->disconnect(); - log_v("<< getValue"); - return ret; -} // getValue + log_v(">> getValue: bdAddress: %s, serviceUUID: %s, characteristicUUID: %s", bdAddress.toString().c_str(), serviceUUID.toString().c_str(), characteristicUUID.toString().c_str()); + BLEClient* pClient = createClient(); + pClient->connect(bdAddress); + String ret = pClient->getValue(serviceUUID, characteristicUUID); + pClient->disconnect(); + log_v("<< getValue"); + return ret; +} // getValue /** @@ -334,103 +336,103 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @param deviceName The device name of the device. */ /* STATIC */ void BLEDevice::init(String deviceName) { - if(!initialized){ - initialized = true; // Set the initialization flag to ensure we are only initialized once. + if (!initialized) { + initialized = true; // Set the initialization flag to ensure we are only initialized once. - esp_err_t errRc = ESP_OK; + esp_err_t errRc = ESP_OK; #ifdef ARDUINO_ARCH_ESP32 - if (!btStart()) { - errRc = ESP_FAIL; - return; - } + if (!btStart()) { + errRc = ESP_FAIL; + return; + } #else - errRc = ::nvs_flash_init(); - if (errRc != ESP_OK) { - log_e("nvs_flash_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } + errRc = ::nvs_flash_init(); + if (errRc != ESP_OK) { + log_e("nvs_flash_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } #ifndef CONFIG_BT_CLASSIC_ENABLED - esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); + esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); #endif - esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); - errRc = esp_bt_controller_init(&bt_cfg); - if (errRc != ESP_OK) { - log_e("esp_bt_controller_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } + esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); + errRc = esp_bt_controller_init(&bt_cfg); + if (errRc != ESP_OK) { + log_e("esp_bt_controller_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } #ifndef CONFIG_BT_CLASSIC_ENABLED - errRc = esp_bt_controller_enable(ESP_BT_MODE_BLE); - if (errRc != ESP_OK) { - log_e("esp_bt_controller_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } + errRc = esp_bt_controller_enable(ESP_BT_MODE_BLE); + if (errRc != ESP_OK) { + log_e("esp_bt_controller_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } #else - errRc = esp_bt_controller_enable(ESP_BT_MODE_BTDM); - if (errRc != ESP_OK) { - log_e("esp_bt_controller_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } + errRc = esp_bt_controller_enable(ESP_BT_MODE_BTDM); + if (errRc != ESP_OK) { + log_e("esp_bt_controller_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } #endif #endif - esp_bluedroid_status_t bt_state = esp_bluedroid_get_status(); - if (bt_state == ESP_BLUEDROID_STATUS_UNINITIALIZED) { - errRc = esp_bluedroid_init(); - if (errRc != ESP_OK) { - log_e("esp_bluedroid_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } - } - - if (bt_state != ESP_BLUEDROID_STATUS_ENABLED) { - errRc = esp_bluedroid_enable(); - if (errRc != ESP_OK) { - log_e("esp_bluedroid_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } - } - - errRc = esp_ble_gap_register_callback(BLEDevice::gapEventHandler); - if (errRc != ESP_OK) { - log_e("esp_ble_gap_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } - -#ifdef CONFIG_GATTC_ENABLE // Check that BLE client is configured in make menuconfig - errRc = esp_ble_gattc_register_callback(BLEDevice::gattClientEventHandler); - if (errRc != ESP_OK) { - log_e("esp_ble_gattc_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } -#endif // CONFIG_GATTC_ENABLE + esp_bluedroid_status_t bt_state = esp_bluedroid_get_status(); + if (bt_state == ESP_BLUEDROID_STATUS_UNINITIALIZED) { + errRc = esp_bluedroid_init(); + if (errRc != ESP_OK) { + log_e("esp_bluedroid_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } + } + + if (bt_state != ESP_BLUEDROID_STATUS_ENABLED) { + errRc = esp_bluedroid_enable(); + if (errRc != ESP_OK) { + log_e("esp_bluedroid_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } + } + + errRc = esp_ble_gap_register_callback(BLEDevice::gapEventHandler); + if (errRc != ESP_OK) { + log_e("esp_ble_gap_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } + +#ifdef CONFIG_GATTC_ENABLE // Check that BLE client is configured in make menuconfig + errRc = esp_ble_gattc_register_callback(BLEDevice::gattClientEventHandler); + if (errRc != ESP_OK) { + log_e("esp_ble_gattc_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } +#endif // CONFIG_GATTC_ENABLE #ifdef CONFIG_GATTS_ENABLE // Check that BLE server is configured in make menuconfig - errRc = esp_ble_gatts_register_callback(BLEDevice::gattServerEventHandler); - if (errRc != ESP_OK) { - log_e("esp_ble_gatts_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } -#endif // CONFIG_GATTS_ENABLE - - errRc = ::esp_ble_gap_set_device_name(deviceName.c_str()); - if (errRc != ESP_OK) { - log_e("esp_ble_gap_set_device_name: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - }; - -#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig - esp_ble_io_cap_t iocap = ESP_IO_CAP_NONE; - errRc = ::esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t)); - if (errRc != ESP_OK) { - log_e("esp_ble_gap_set_security_param: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - }; -#endif // CONFIG_BLE_SMP_ENABLE - } - vTaskDelay(200 / portTICK_PERIOD_MS); // Delay for 200 msecs as a workaround to an apparent Arduino environment issue. -} // init + errRc = esp_ble_gatts_register_callback(BLEDevice::gattServerEventHandler); + if (errRc != ESP_OK) { + log_e("esp_ble_gatts_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } +#endif // CONFIG_GATTS_ENABLE + + errRc = ::esp_ble_gap_set_device_name(deviceName.c_str()); + if (errRc != ESP_OK) { + log_e("esp_ble_gap_set_device_name: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + }; + +#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig + esp_ble_io_cap_t iocap = ESP_IO_CAP_NONE; + errRc = ::esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t)); + if (errRc != ESP_OK) { + log_e("esp_ble_gap_set_security_param: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + }; +#endif // CONFIG_BLE_SMP_ENABLE + } + vTaskDelay(200 / portTICK_PERIOD_MS); // Delay for 200 msecs as a workaround to an apparent Arduino environment issue. +} // init /** @@ -462,13 +464,13 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @param [in] powerLevel. */ /* STATIC */ void BLEDevice::setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType) { - log_v(">> setPower: %d (type: %d)", powerLevel, powerType); - esp_err_t errRc = ::esp_ble_tx_power_set(powerType, powerLevel); - if (errRc != ESP_OK) { - log_e("esp_ble_tx_power_set: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - }; - log_v("<< setPower"); -} // setPower + log_v(">> setPower: %d (type: %d)", powerLevel, powerType); + esp_err_t errRc = ::esp_ble_tx_power_set(powerType, powerLevel); + if (errRc != ESP_OK) { + log_e("esp_ble_tx_power_set: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + }; + log_v("<< setPower"); +} // setPower /** @@ -478,12 +480,12 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @param [in] characteristicUUID */ /* STATIC */ void BLEDevice::setValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID, String value) { - log_v(">> setValue: bdAddress: %s, serviceUUID: %s, characteristicUUID: %s", bdAddress.toString().c_str(), serviceUUID.toString().c_str(), characteristicUUID.toString().c_str()); - BLEClient* pClient = createClient(); - pClient->connect(bdAddress); - pClient->setValue(serviceUUID, characteristicUUID, value); - pClient->disconnect(); -} // setValue + log_v(">> setValue: bdAddress: %s, serviceUUID: %s, characteristicUUID: %s", bdAddress.toString().c_str(), serviceUUID.toString().c_str(), characteristicUUID.toString().c_str()); + BLEClient* pClient = createClient(); + pClient->connect(bdAddress); + pClient->setValue(serviceUUID, characteristicUUID, value); + pClient->disconnect(); +} // setValue /** @@ -491,9 +493,9 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @return A string representation of the nature of this device. */ /* STATIC */ String BLEDevice::toString() { - String res = "BD Address: " + getAddress().toString(); - return res; -} // toString + String res = "BD Address: " + getAddress().toString(); + return res; +} // toString /** @@ -501,17 +503,17 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; * @param [in] address The address to add to the white list. */ void BLEDevice::whiteListAdd(BLEAddress address) { - log_v(">> whiteListAdd: %s", address.toString().c_str()); + log_v(">> whiteListAdd: %s", address.toString().c_str()); #ifdef ESP_IDF_VERSION_MAJOR - esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative(), BLE_WL_ADDR_TYPE_PUBLIC); // HACK!!! True to add an entry. + esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative(), BLE_WL_ADDR_TYPE_PUBLIC); // HACK!!! True to add an entry. #else - esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative()); // True to add an entry. + esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative()); // True to add an entry. #endif - if (errRc != ESP_OK) { - log_e("esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - } - log_v("<< whiteListAdd"); -} // whiteListAdd + if (errRc != ESP_OK) { + log_e("esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + } + log_v("<< whiteListAdd"); +} // whiteListAdd /** @@ -519,24 +521,24 @@ void BLEDevice::whiteListAdd(BLEAddress address) { * @param [in] address The address to remove from the white list. */ void BLEDevice::whiteListRemove(BLEAddress address) { - log_v(">> whiteListRemove: %s", address.toString().c_str()); + log_v(">> whiteListRemove: %s", address.toString().c_str()); #ifdef ESP_IDF_VERSION_MAJOR - esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative(), BLE_WL_ADDR_TYPE_PUBLIC); // HACK!!! False to remove an entry. + esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative(), BLE_WL_ADDR_TYPE_PUBLIC); // HACK!!! False to remove an entry. #else - esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative()); // False to remove an entry. + esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative()); // False to remove an entry. #endif - if (errRc != ESP_OK) { - log_e("esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - } - log_v("<< whiteListRemove"); -} // whiteListRemove + if (errRc != ESP_OK) { + log_e("esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + } + log_v("<< whiteListRemove"); +} // whiteListRemove /* * @brief Set encryption level that will be negotiated with peer device durng connection * @param [in] level Requested encryption level */ void BLEDevice::setEncryptionLevel(esp_ble_sec_act_t level) { - BLEDevice::m_securityLevel = level; + BLEDevice::m_securityLevel = level; } /* @@ -544,7 +546,7 @@ void BLEDevice::setEncryptionLevel(esp_ble_sec_act_t level) { * @param [in] cllbacks Pointer to BLESecurityCallbacks class callback */ void BLEDevice::setSecurityCallbacks(BLESecurityCallbacks* callbacks) { - BLEDevice::m_securityCallbacks = callbacks; + BLEDevice::m_securityCallbacks = callbacks; } /* @@ -552,95 +554,95 @@ void BLEDevice::setSecurityCallbacks(BLESecurityCallbacks* callbacks) { * @param [in] mtu Value to set local mtu, should be larger than 23 and lower or equal to 517 */ esp_err_t BLEDevice::setMTU(uint16_t mtu) { - log_v(">> setLocalMTU: %d", mtu); - esp_err_t err = esp_ble_gatt_set_local_mtu(mtu); - if (err == ESP_OK) { - m_localMTU = mtu; - } else { - log_e("can't set local mtu value: %d", mtu); - } - log_v("<< setLocalMTU"); - return err; + log_v(">> setLocalMTU: %d", mtu); + esp_err_t err = esp_ble_gatt_set_local_mtu(mtu); + if (err == ESP_OK) { + m_localMTU = mtu; + } else { + log_e("can't set local mtu value: %d", mtu); + } + log_v("<< setLocalMTU"); + return err; } /* * @brief Get local MTU value set during mtu request or default value */ uint16_t BLEDevice::getMTU() { - return m_localMTU; + return m_localMTU; } bool BLEDevice::getInitialized() { - return initialized; + return initialized; } BLEAdvertising* BLEDevice::getAdvertising() { - if(m_bleAdvertising == nullptr) { - m_bleAdvertising = new BLEAdvertising(); - log_i("create advertising"); - } - log_d("get advertising"); - return m_bleAdvertising; + if (m_bleAdvertising == nullptr) { + m_bleAdvertising = new BLEAdvertising(); + log_i("create advertising"); + } + log_d("get advertising"); + return m_bleAdvertising; } void BLEDevice::startAdvertising() { - log_v(">> startAdvertising"); - getAdvertising()->start(); - log_v("<< startAdvertising"); -} // startAdvertising + log_v(">> startAdvertising"); + getAdvertising()->start(); + log_v("<< startAdvertising"); +} // startAdvertising void BLEDevice::stopAdvertising() { - log_v(">> stopAdvertising"); - getAdvertising()->stop(); - log_v("<< stopAdvertising"); -} // stopAdvertising + log_v(">> stopAdvertising"); + getAdvertising()->stop(); + log_v("<< stopAdvertising"); +} // stopAdvertising /* multi connect support */ /* requires a little more work */ std::map BLEDevice::getPeerDevices(bool _client) { - return m_connectedClientsMap; + return m_connectedClientsMap; } BLEClient* BLEDevice::getClientByGattIf(uint16_t conn_id) { - return (BLEClient*)m_connectedClientsMap.find(conn_id)->second.peer_device; + return (BLEClient*)m_connectedClientsMap.find(conn_id)->second.peer_device; } void BLEDevice::updatePeerDevice(void* peer, bool _client, uint16_t conn_id) { - log_d("update conn_id: %d, GATT role: %s", conn_id, _client? "client":"server"); - std::map::iterator it = m_connectedClientsMap.find(ESP_GATT_IF_NONE); - if (it != m_connectedClientsMap.end()) { - std::swap(m_connectedClientsMap[conn_id], it->second); - m_connectedClientsMap.erase(it); - }else{ - it = m_connectedClientsMap.find(conn_id); - if (it != m_connectedClientsMap.end()) { - conn_status_t _st = it->second; - _st.peer_device = peer; - std::swap(m_connectedClientsMap[conn_id], _st); - } - } + log_d("update conn_id: %d, GATT role: %s", conn_id, _client ? "client" : "server"); + std::map::iterator it = m_connectedClientsMap.find(ESP_GATT_IF_NONE); + if (it != m_connectedClientsMap.end()) { + std::swap(m_connectedClientsMap[conn_id], it->second); + m_connectedClientsMap.erase(it); + } else { + it = m_connectedClientsMap.find(conn_id); + if (it != m_connectedClientsMap.end()) { + conn_status_t _st = it->second; + _st.peer_device = peer; + std::swap(m_connectedClientsMap[conn_id], _st); + } + } } void BLEDevice::addPeerDevice(void* peer, bool _client, uint16_t conn_id) { - log_i("add conn_id: %d, GATT role: %s", conn_id, _client? "client":"server"); - conn_status_t status = { - .peer_device = peer, - .connected = true, - .mtu = 23 - }; - - m_connectedClientsMap.insert(std::pair(conn_id, status)); + log_i("add conn_id: %d, GATT role: %s", conn_id, _client ? "client" : "server"); + conn_status_t status = { + .peer_device = peer, + .connected = true, + .mtu = 23 + }; + + m_connectedClientsMap.insert(std::pair(conn_id, status)); } //there may have some situation that invoking this function simultaneously, that will cause CORRUPT HEAP //let this function serializable portMUX_TYPE BLEDevice::mux = portMUX_INITIALIZER_UNLOCKED; void BLEDevice::removePeerDevice(uint16_t conn_id, bool _client) { - portENTER_CRITICAL(&mux); - log_i("remove: %d, GATT role %s", conn_id, _client?"client":"server"); - if(m_connectedClientsMap.find(conn_id) != m_connectedClientsMap.end()) - m_connectedClientsMap.erase(conn_id); - portEXIT_CRITICAL(&mux); + portENTER_CRITICAL(&mux); + log_i("remove: %d, GATT role %s", conn_id, _client ? "client" : "server"); + if (m_connectedClientsMap.find(conn_id) != m_connectedClientsMap.end()) + m_connectedClientsMap.erase(conn_id); + portEXIT_CRITICAL(&mux); } /* multi connect support */ @@ -650,31 +652,31 @@ void BLEDevice::removePeerDevice(uint16_t conn_id, bool _client) { * @param release_memory release the internal BT stack memory */ /* STATIC */ void BLEDevice::deinit(bool release_memory) { - if (!initialized) return; + if (!initialized) return; - esp_bluedroid_disable(); - esp_bluedroid_deinit(); - esp_bt_controller_disable(); - esp_bt_controller_deinit(); + esp_bluedroid_disable(); + esp_bluedroid_deinit(); + esp_bt_controller_disable(); + esp_bt_controller_deinit(); #ifdef ARDUINO_ARCH_ESP32 - if (release_memory) { - esp_bt_controller_mem_release(ESP_BT_MODE_BTDM); // <-- require tests because we released classic BT memory and this can cause crash (most likely not, esp-idf takes care of it) - } else { - initialized = false; - } + if (release_memory) { + esp_bt_controller_mem_release(ESP_BT_MODE_BTDM); // <-- require tests because we released classic BT memory and this can cause crash (most likely not, esp-idf takes care of it) + } else { + initialized = false; + } #endif } void BLEDevice::setCustomGapHandler(gap_event_handler handler) { - m_customGapHandler = handler; + m_customGapHandler = handler; } void BLEDevice::setCustomGattcHandler(gattc_event_handler handler) { - m_customGattcHandler = handler; + m_customGattcHandler = handler; } void BLEDevice::setCustomGattsHandler(gatts_event_handler handler) { - m_customGattsHandler = handler; + m_customGattsHandler = handler; } #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLEDevice.h b/libraries/BLE/src/BLEDevice.h index 805517ce842..80b0e2ac870 100644 --- a/libraries/BLE/src/BLEDevice.h +++ b/libraries/BLE/src/BLEDevice.h @@ -12,9 +12,9 @@ #include "sdkconfig.h" #if defined(CONFIG_BLUEDROID_ENABLED) -#include // ESP32 BLE -#include // ESP32 BLE -#include // Part of C++ STL +#include // ESP32 BLE +#include // ESP32 BLE +#include // Part of C++ STL #include #include @@ -27,78 +27,78 @@ /** * @brief BLE functions. */ -typedef void (*gap_event_handler)(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param); +typedef void (*gap_event_handler)(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param); typedef void (*gattc_event_handler)(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* param); typedef void (*gatts_event_handler)(esp_gatts_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gatts_cb_param_t* param); class BLEDevice { public: - static BLEClient* createClient(); // Create a new BLE client. - static BLEServer* createServer(); // Cretae a new BLE server. - static BLEAddress getAddress(); // Retrieve our own local BD address. - static BLEScan* getScan(); // Get the scan object - static String getValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID); // Get the value of a characteristic of a service on a server. - static void init(String deviceName); // Initialize the local BLE environment. - static void setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType=ESP_BLE_PWR_TYPE_DEFAULT); // Set our power level. - static void setValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID, String value); // Set the value of a characteristic on a service on a server. - static String toString(); // Return a string representation of our device. - static void whiteListAdd(BLEAddress address); // Add an entry to the BLE white list. - static void whiteListRemove(BLEAddress address); // Remove an entry from the BLE white list. - static void setEncryptionLevel(esp_ble_sec_act_t level); - static void setSecurityCallbacks(BLESecurityCallbacks* pCallbacks); - static esp_err_t setMTU(uint16_t mtu); - static uint16_t getMTU(); - static bool getInitialized(); // Returns the state of the device, is it initialized or not? - /* move advertising to BLEDevice for saving ram and flash in beacons */ - static BLEAdvertising* getAdvertising(); - static void startAdvertising(); - static void stopAdvertising(); - static uint16_t m_appId; - /* multi connect */ - static std::map getPeerDevices(bool client); - static void addPeerDevice(void* peer, bool is_client, uint16_t conn_id); - static void updatePeerDevice(void* peer, bool _client, uint16_t conn_id); - static void removePeerDevice(uint16_t conn_id, bool client); - static BLEClient* getClientByGattIf(uint16_t conn_id); - static void setCustomGapHandler(gap_event_handler handler); - static void setCustomGattcHandler(gattc_event_handler handler); - static void setCustomGattsHandler(gatts_event_handler handler); - static void deinit(bool release_memory = false); - static uint16_t m_localMTU; - static esp_ble_sec_act_t m_securityLevel; + static BLEClient* createClient(); // Create a new BLE client. + static BLEServer* createServer(); // Create a new BLE server. + static BLEAddress getAddress(); // Retrieve our own local BD address. + static BLEScan* getScan(); // Get the scan object + static String getValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID); // Get the value of a characteristic of a service on a server. + static void init(String deviceName); // Initialize the local BLE environment. + static void setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType = ESP_BLE_PWR_TYPE_DEFAULT); // Set our power level. + static void setValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID, String value); // Set the value of a characteristic on a service on a server. + static String toString(); // Return a string representation of our device. + static void whiteListAdd(BLEAddress address); // Add an entry to the BLE white list. + static void whiteListRemove(BLEAddress address); // Remove an entry from the BLE white list. + static void setEncryptionLevel(esp_ble_sec_act_t level); + static void setSecurityCallbacks(BLESecurityCallbacks* pCallbacks); + static esp_err_t setMTU(uint16_t mtu); + static uint16_t getMTU(); + static bool getInitialized(); // Returns the state of the device, is it initialized or not? + /* move advertising to BLEDevice for saving ram and flash in beacons */ + static BLEAdvertising* getAdvertising(); + static void startAdvertising(); + static void stopAdvertising(); + static uint16_t m_appId; + /* multi connect */ + static std::map getPeerDevices(bool client); + static void addPeerDevice(void* peer, bool is_client, uint16_t conn_id); + static void updatePeerDevice(void* peer, bool _client, uint16_t conn_id); + static void removePeerDevice(uint16_t conn_id, bool client); + static BLEClient* getClientByGattIf(uint16_t conn_id); + static void setCustomGapHandler(gap_event_handler handler); + static void setCustomGattcHandler(gattc_event_handler handler); + static void setCustomGattsHandler(gatts_event_handler handler); + static void deinit(bool release_memory = false); + static uint16_t m_localMTU; + static esp_ble_sec_act_t m_securityLevel; private: - static BLEServer* m_pServer; - static BLEScan* m_pScan; - static BLEClient* m_pClient; - static BLESecurityCallbacks* m_securityCallbacks; - static BLEAdvertising* m_bleAdvertising; - static esp_gatt_if_t getGattcIF(); - static std::map m_connectedClientsMap; - static portMUX_TYPE mux; + static BLEServer* m_pServer; + static BLEScan* m_pScan; + static BLEClient* m_pClient; + static BLESecurityCallbacks* m_securityCallbacks; + static BLEAdvertising* m_bleAdvertising; + static esp_gatt_if_t getGattcIF(); + static std::map m_connectedClientsMap; + static portMUX_TYPE mux; - static void gattClientEventHandler( - esp_gattc_cb_event_t event, - esp_gatt_if_t gattc_if, - esp_ble_gattc_cb_param_t* param); + static void gattClientEventHandler( + esp_gattc_cb_event_t event, + esp_gatt_if_t gattc_if, + esp_ble_gattc_cb_param_t* param); - static void gattServerEventHandler( - esp_gatts_cb_event_t event, - esp_gatt_if_t gatts_if, - esp_ble_gatts_cb_param_t* param); + static void gattServerEventHandler( + esp_gatts_cb_event_t event, + esp_gatt_if_t gatts_if, + esp_ble_gatts_cb_param_t* param); - static void gapEventHandler( - esp_gap_ble_cb_event_t event, - esp_ble_gap_cb_param_t* param); + static void gapEventHandler( + esp_gap_ble_cb_event_t event, + esp_ble_gap_cb_param_t* param); public: -/* custom gap and gatt handlers for flexibility */ - static gap_event_handler m_customGapHandler; - static gattc_event_handler m_customGattcHandler; - static gatts_event_handler m_customGattsHandler; + /* custom gap and gatt handlers for flexibility */ + static gap_event_handler m_customGapHandler; + static gattc_event_handler m_customGattcHandler; + static gatts_event_handler m_customGattsHandler; -}; // class BLE +}; // class BLE #endif /* CONFIG_BLUEDROID_ENABLED */ #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLEEddystoneTLM.cpp b/libraries/BLE/src/BLEEddystoneTLM.cpp index 4e6bdfe492a..67081361f41 100644 --- a/libraries/BLE/src/BLEEddystoneTLM.cpp +++ b/libraries/BLE/src/BLEEddystoneTLM.cpp @@ -7,7 +7,7 @@ * Fix temperature value (8.8 fixed format) * Fix time stamp (0.1 second resolution) * Fixes based on EddystoneTLM frame specification https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md - * + * */ #include "soc/soc_caps.h" #if SOC_BLE_SUPPORTED @@ -24,54 +24,54 @@ static const char LOG_TAG[] = "BLEEddystoneTLM"; BLEEddystoneTLM::BLEEddystoneTLM() { m_eddystoneData.frameType = EDDYSTONE_TLM_FRAME_TYPE; m_eddystoneData.version = 0; - m_eddystoneData.volt = 3300; // 3300mV = 3.3V - m_eddystoneData.temp = (uint16_t) ((float) 23.00)/256; + m_eddystoneData.volt = 3300; // 3300mV = 3.3V + m_eddystoneData.temp = (uint16_t)((float)23.00) / 256; m_eddystoneData.advCount = 0; m_eddystoneData.tmil = 0; -} // BLEEddystoneTLM +} // BLEEddystoneTLM -BLEEddystoneTLM::BLEEddystoneTLM(BLEAdvertisedDevice *advertisedDevice){ +BLEEddystoneTLM::BLEEddystoneTLM(BLEAdvertisedDevice* advertisedDevice) { char* payload = (char*)advertisedDevice->getPayload(); - for(int i = 0; i < advertisedDevice->getPayloadLength(); ++i){ - if(payload[i] == 0x16 && advertisedDevice->getPayloadLength() >= i+2+sizeof(m_eddystoneData) && payload[i+1] == 0xAA && payload[i+2] == 0xFE && payload[i+3] == 0x20){ - log_d("Eddystone TLM data frame starting at byte [%d]", i+3); - setData(String(payload+i+3, sizeof(m_eddystoneData))); + for (int i = 0; i < advertisedDevice->getPayloadLength(); ++i) { + if (payload[i] == 0x16 && advertisedDevice->getPayloadLength() >= i + 2 + sizeof(m_eddystoneData) && payload[i + 1] == 0xAA && payload[i + 2] == 0xFE && payload[i + 3] == 0x20) { + log_d("Eddystone TLM data frame starting at byte [%d]", i + 3); + setData(String(payload + i + 3, sizeof(m_eddystoneData))); break; } } } String BLEEddystoneTLM::getData() { - return String((char*) &m_eddystoneData, sizeof(m_eddystoneData)); -} // getData + return String((char*)&m_eddystoneData, sizeof(m_eddystoneData)); +} // getData BLEUUID BLEEddystoneTLM::getUUID() { return beaconUUID; -} // getUUID +} // getUUID uint8_t BLEEddystoneTLM::getVersion() { return m_eddystoneData.version; -} // getVersion +} // getVersion uint16_t BLEEddystoneTLM::getVolt() { return ENDIAN_CHANGE_U16(m_eddystoneData.volt); -} // getVolt +} // getVolt float BLEEddystoneTLM::getTemp() { return EDDYSTONE_TEMP_U16_TO_FLOAT(m_eddystoneData.temp); -} // getTemp +} // getTemp uint16_t BLEEddystoneTLM::getRawTemp() { return ENDIAN_CHANGE_U16(m_eddystoneData.temp); -} // getRawTemp +} // getRawTemp uint32_t BLEEddystoneTLM::getCount() { return ENDIAN_CHANGE_U32(m_eddystoneData.advCount); -} // getCount +} // getCount uint32_t BLEEddystoneTLM::getTime() { return (ENDIAN_CHANGE_U32(m_eddystoneData.tmil)) / 10; -} // getTime +} // getTime String BLEEddystoneTLM::toString() { String out = ""; @@ -82,7 +82,7 @@ String BLEEddystoneTLM::toString() { //snprintf(val, sizeof(val), "%d", m_eddystoneData.version); //out += val; out += "\n"; - out += "Battery Voltage "; // + ENDIAN_CHANGE_U16(m_eddystoneData.volt); + out += "Battery Voltage "; // + ENDIAN_CHANGE_U16(m_eddystoneData.volt); snprintf(val, sizeof(val), "%d", ENDIAN_CHANGE_U16(m_eddystoneData.volt)); out += val; out += " mV\n"; @@ -98,7 +98,7 @@ String BLEEddystoneTLM::toString() { out += "\n"; out += "Time in seconds "; - snprintf(val, sizeof(val), "%ld", rawsec/10); + snprintf(val, sizeof(val), "%ld", rawsec / 10); out += val; out += "\n"; @@ -121,7 +121,7 @@ String BLEEddystoneTLM::toString() { out += "\n"; return out; -} // toString +} // toString /** * Set the raw data for the beacon record. @@ -148,32 +148,32 @@ void BLEEddystoneTLM::setData(String data) { return; } memcpy(&m_eddystoneData, data.c_str(), data.length()); -} // setData +} // setData void BLEEddystoneTLM::setUUID(BLEUUID l_uuid) { beaconUUID = l_uuid; -} // setUUID +} // setUUID void BLEEddystoneTLM::setVersion(uint8_t version) { m_eddystoneData.version = version; -} // setVersion +} // setVersion // Set voltage in ESP32 native Big endian and convert it to little endian used for BLE Frame void BLEEddystoneTLM::setVolt(uint16_t volt) { m_eddystoneData.volt = ENDIAN_CHANGE_U16(volt); -} // setVolt +} // setVolt void BLEEddystoneTLM::setTemp(float temp) { m_eddystoneData.temp = EDDYSTONE_TEMP_FLOAT_TO_U16(temp); -} // setTemp +} // setTemp void BLEEddystoneTLM::setCount(uint32_t advCount) { m_eddystoneData.advCount = advCount; -} // setCount +} // setCount void BLEEddystoneTLM::setTime(uint32_t tmil) { m_eddystoneData.tmil = tmil; -} // setTime +} // setTime #endif /* CONFIG_BLUEDROID_ENABLED */ #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLEEddystoneTLM.cppwithheadder b/libraries/BLE/src/BLEEddystoneTLM.cppwithheadder index fe3701529ad..07002dbab1f 100644 --- a/libraries/BLE/src/BLEEddystoneTLM.cppwithheadder +++ b/libraries/BLE/src/BLEEddystoneTLM.cppwithheadder @@ -7,7 +7,7 @@ * Fix temperature value (8.8 fixed format) * Fix time stamp (0.1 second resolution) * Fixes based on EddystoneTLM frame specification https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md - * + * */ #include "sdkconfig.h" #if defined(CONFIG_BLUEDROID_ENABLED) @@ -199,4 +199,4 @@ void BLEEddystoneTLM::_initHeadder(){ BLEHeadder[11] = 0x20; // Eddystone Frame Type - TLM } -#endif \ No newline at end of file +#endif diff --git a/libraries/BLE/src/BLEEddystoneTLM.h b/libraries/BLE/src/BLEEddystoneTLM.h index dab28c72c14..1126ef94b87 100644 --- a/libraries/BLE/src/BLEEddystoneTLM.h +++ b/libraries/BLE/src/BLEEddystoneTLM.h @@ -14,10 +14,10 @@ #include #define EDDYSTONE_TLM_FRAME_TYPE 0x20 -#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00)>>8) + (((x)&0xFF)<<8)) -#define ENDIAN_CHANGE_U32(x) ((((x)&0xFF000000)>>24) + (((x)&0x00FF0000)>>8)) + ((((x)&0xFF00)<<8) + (((x)&0xFF)<<24)) -#define EDDYSTONE_TEMP_U16_TO_FLOAT(tempU16) (((int16_t)ENDIAN_CHANGE_U16(tempU16)) / 256.0f) -#define EDDYSTONE_TEMP_FLOAT_TO_U16(tempFloat) (ENDIAN_CHANGE_U16(((int)((tempFloat) * 256)))) +#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00) >> 8) + (((x)&0xFF) << 8)) +#define ENDIAN_CHANGE_U32(x) ((((x)&0xFF000000) >> 24) + (((x)&0x00FF0000) >> 8)) + ((((x)&0xFF00) << 8) + (((x)&0xFF) << 24)) +#define EDDYSTONE_TEMP_U16_TO_FLOAT(tempU16) (((int16_t)ENDIAN_CHANGE_U16(tempU16)) / 256.0f) +#define EDDYSTONE_TEMP_FLOAT_TO_U16(tempFloat) (ENDIAN_CHANGE_U16(((int)((tempFloat)*256)))) /** * @brief Representation of a beacon. @@ -29,21 +29,21 @@ class BLEEddystoneTLM { BLEEddystoneTLM(); BLEEddystoneTLM(BLEAdvertisedDevice *advertisedDevice); String getData(); - BLEUUID getUUID(); - uint8_t getVersion(); - uint16_t getVolt(); - float getTemp(); - uint16_t getRawTemp(); - uint32_t getCount(); - uint32_t getTime(); + BLEUUID getUUID(); + uint8_t getVersion(); + uint16_t getVolt(); + float getTemp(); + uint16_t getRawTemp(); + uint32_t getCount(); + uint32_t getTime(); String toString(); - void setData(String data); - void setUUID(BLEUUID l_uuid); - void setVersion(uint8_t version); - void setVolt(uint16_t volt); - void setTemp(float temp); - void setCount(uint32_t advCount); - void setTime(uint32_t tmil); + void setData(String data); + void setUUID(BLEUUID l_uuid); + void setVersion(uint8_t version); + void setVolt(uint16_t volt); + void setTemp(float temp); + void setCount(uint32_t advCount); + void setTime(uint32_t tmil); private: BLEUUID beaconUUID; @@ -55,7 +55,7 @@ class BLEEddystoneTLM { uint32_t advCount; uint32_t tmil; } __attribute__((packed)) m_eddystoneData; -}; // BLEEddystoneTLM +}; // BLEEddystoneTLM #endif /* SOC_BLE_SUPPORTED */ #endif /* _BLEEddystoneTLM_H_ */ diff --git a/libraries/BLE/src/BLEEddystoneURL.cpp b/libraries/BLE/src/BLEEddystoneURL.cpp index c10e00c1f6f..cd04d627758 100644 --- a/libraries/BLE/src/BLEEddystoneURL.cpp +++ b/libraries/BLE/src/BLEEddystoneURL.cpp @@ -16,29 +16,29 @@ #include "BLEEddystoneURL.h" String EDDYSTONE_URL_PREFIX[] = { - "http://www.", // 0x00 - "https://www.", // 0x01 - "http://", // 0x02 - "https://", // 0x03 - "" // Any other code number results in empty string + "http://www.", // 0x00 + "https://www.", // 0x01 + "http://", // 0x02 + "https://", // 0x03 + "" // Any other code number results in empty string }; String EDDYSTONE_URL_SUFFIX[] = { - ".com/", // 0x00 - ".org/", // 0x01 - ".edu/", // 0x02 - ".net/", // 0x03 - ".info/", // 0x04 - ".biz/", // 0x05 - ".gov/", // 0x06 - ".com", // 0x07 - ".org", // 0x08 - ".edu", // 0x09 - ".net", // 0x0A - ".info", // 0x0B - ".biz", // 0x0C - ".gov", // 0x0D - "" // Any other code number results in empty string + ".com/", // 0x00 + ".org/", // 0x01 + ".edu/", // 0x02 + ".net/", // 0x03 + ".info/", // 0x04 + ".biz/", // 0x05 + ".gov/", // 0x06 + ".com", // 0x07 + ".org", // 0x08 + ".edu", // 0x09 + ".net", // 0x0A + ".info", // 0x0B + ".biz", // 0x0C + ".gov", // 0x0D + "" // Any other code number results in empty string }; BLEEddystoneURL::BLEEddystoneURL() { @@ -46,20 +46,20 @@ BLEEddystoneURL::BLEEddystoneURL() { m_eddystoneData.advertisedTxPower = 0; memset(m_eddystoneData.url, 0, sizeof(m_eddystoneData.url)); _initHeadder(); -} // BLEEddystoneURL +} // BLEEddystoneURL -BLEEddystoneURL::BLEEddystoneURL(BLEAdvertisedDevice *advertisedDevice){ - const char *payload = (char*)advertisedDevice->getPayload(); +BLEEddystoneURL::BLEEddystoneURL(BLEAdvertisedDevice *advertisedDevice) { + const char *payload = (char *)advertisedDevice->getPayload(); memset(m_eddystoneData.url, 0, sizeof(m_eddystoneData.url)); lengthURL = 0; m_eddystoneData.advertisedTxPower = 0; - for(int i = 0; i < advertisedDevice->getPayloadLength(); ++i){ - if(payload[i] == 0x16 && advertisedDevice->getPayloadLength() >= i+2+sizeof(m_eddystoneData) && payload[i+1] == 0xAA && payload[i+2] == 0xFE && payload[i+3] == 0x10){ - lengthURL = payload[i-1] - 5; // Subtracting 5 Bytes containing header and other data which are not actual URL data - m_eddystoneData.advertisedTxPower = payload[i+1]; - if(lengthURL <= 18){ - setData(String(payload+i+4, lengthURL+1)); - }else{ + for (int i = 0; i < advertisedDevice->getPayloadLength(); ++i) { + if (payload[i] == 0x16 && advertisedDevice->getPayloadLength() >= i + 2 + sizeof(m_eddystoneData) && payload[i + 1] == 0xAA && payload[i + 2] == 0xFE && payload[i + 3] == 0x10) { + lengthURL = payload[i - 1] - 5; // Subtracting 5 Bytes containing header and other data which are not actual URL data + m_eddystoneData.advertisedTxPower = payload[i + 1]; + if (lengthURL <= 18) { + setData(String(payload + i + 4, lengthURL + 1)); + } else { log_e("Too long URL %d", lengthURL); } } @@ -68,42 +68,42 @@ BLEEddystoneURL::BLEEddystoneURL(BLEAdvertisedDevice *advertisedDevice){ } String BLEEddystoneURL::getData() { - return String((char*) &m_eddystoneData, sizeof(m_eddystoneData)); -} // getData + return String((char *)&m_eddystoneData, sizeof(m_eddystoneData)); +} // getData String BLEEddystoneURL::getFrame() { - BLEHeadder[7] = lengthURL + 5; // Fill in real: Type + 2B UUID + Frame Type + Tx power + URL (note: the Byte holding the length does not count itself) + BLEHeadder[7] = lengthURL + 5; // Fill in real: Type + 2B UUID + Frame Type + Tx power + URL (note: the Byte holding the length does not count itself) String frame(BLEHeadder, sizeof(BLEHeadder)); - frame += String((char*) &m_eddystoneData, lengthURL+1); // + 1 for TX power + frame += String((char *)&m_eddystoneData, lengthURL + 1); // + 1 for TX power return frame; -} // getFrame +} // getFrame BLEUUID BLEEddystoneURL::getUUID() { uint16_t uuid = (((uint16_t)BLEHeadder[10]) << 8) | BLEHeadder[9]; return BLEUUID(uuid); -} // getUUID +} // getUUID int8_t BLEEddystoneURL::getPower() { return m_eddystoneData.advertisedTxPower; -} // getPower +} // getPower String BLEEddystoneURL::getURL() { - return String((char*) &m_eddystoneData.url, lengthURL); -} // getURL + return String((char *)&m_eddystoneData.url, lengthURL); +} // getURL -String BLEEddystoneURL::getPrefix(){ - if(m_eddystoneData.url[0] <= 0x03){ +String BLEEddystoneURL::getPrefix() { + if (m_eddystoneData.url[0] <= 0x03) { return EDDYSTONE_URL_PREFIX[m_eddystoneData.url[0]]; - }else{ + } else { return ""; } } -String BLEEddystoneURL::getSuffix(){ - if(m_eddystoneData.url[lengthURL-1] <= 0x0D){ - return EDDYSTONE_URL_SUFFIX[m_eddystoneData.url[lengthURL-1]]; - }else{ +String BLEEddystoneURL::getSuffix() { + if (m_eddystoneData.url[lengthURL - 1] <= 0x0D) { + return EDDYSTONE_URL_SUFFIX[m_eddystoneData.url[lengthURL - 1]]; + } else { return ""; } } @@ -111,21 +111,21 @@ String BLEEddystoneURL::getSuffix(){ String BLEEddystoneURL::getDecodedURL() { std::string decodedURL = ""; decodedURL += getPrefix().c_str(); - if(decodedURL.length() == 0){ // No prefix extracted - interpret byte [0] as character + if (decodedURL.length() == 0) { // No prefix extracted - interpret byte [0] as character decodedURL += (char)m_eddystoneData.url[0]; } - for(int i = 1; i < lengthURL; i++) { + for (int i = 1; i < lengthURL; i++) { if (m_eddystoneData.url[i] >= 33 && m_eddystoneData.url[i] < 127) { decodedURL += (char)m_eddystoneData.url[i]; - }else{ - if(i != lengthURL-1 || m_eddystoneData.url[i] > 0x0D){ // Ignore last Byte and values used for suffix + } else { + if (i != lengthURL - 1 || m_eddystoneData.url[i] > 0x0D) { // Ignore last Byte and values used for suffix log_e("Unexpected unprintable char in URL 0x%02X: m_eddystoneData.url[%d]", m_eddystoneData.url[i], i); } } } decodedURL += getSuffix().c_str(); return String(decodedURL.c_str()); -} // getDecodedURL +} // getDecodedURL /** * Set the raw data for the beacon record. @@ -154,51 +154,51 @@ void BLEEddystoneURL::setData(String data) { memset(&m_eddystoneData, 0, sizeof(m_eddystoneData)); memcpy(&m_eddystoneData, data.c_str(), data.length()); lengthURL = data.length() - (sizeof(m_eddystoneData) - sizeof(m_eddystoneData.url)); -} // setData +} // setData void BLEEddystoneURL::setUUID(BLEUUID l_uuid) { uint16_t beaconUUID = l_uuid.getNative()->uuid.uuid16; BLEHeadder[10] = beaconUUID >> 8; BLEHeadder[9] = beaconUUID & 0x00FF; -} // setUUID +} // setUUID void BLEEddystoneURL::setPower(esp_power_level_t advertisedTxPower) { int tx_power; - switch(advertisedTxPower){ - case ESP_PWR_LVL_N12: // 12dbm + switch (advertisedTxPower) { + case ESP_PWR_LVL_N12: // 12dbm tx_power = -12; break; - case ESP_PWR_LVL_N9: // -9dbm - tx_power = -9; + case ESP_PWR_LVL_N9: // -9dbm + tx_power = -9; break; - case ESP_PWR_LVL_N6: // -6dbm - tx_power = -6; + case ESP_PWR_LVL_N6: // -6dbm + tx_power = -6; break; - case ESP_PWR_LVL_N3: // -3dbm - tx_power = -3; + case ESP_PWR_LVL_N3: // -3dbm + tx_power = -3; break; - case ESP_PWR_LVL_N0: // 0dbm - tx_power = 0; + case ESP_PWR_LVL_N0: // 0dbm + tx_power = 0; break; - case ESP_PWR_LVL_P3: // +3dbm - tx_power = +3; + case ESP_PWR_LVL_P3: // +3dbm + tx_power = +3; break; - case ESP_PWR_LVL_P6: // +6dbm - tx_power = +6; + case ESP_PWR_LVL_P6: // +6dbm + tx_power = +6; break; - case ESP_PWR_LVL_P9: // +9dbm - tx_power = +9; + case ESP_PWR_LVL_P9: // +9dbm + tx_power = +9; break; - default: tx_power = 0; + default: tx_power = 0; } m_eddystoneData.advertisedTxPower = int8_t((tx_power - -100) / 2); -} // setPower +} // setPower void BLEEddystoneURL::setPower(int8_t advertisedTxPower) { m_eddystoneData.advertisedTxPower = advertisedTxPower; -} // setPower +} // setPower // Set URL bytes including prefix and optional suffix // | Field | Prefix | URL + optional Suffix | @@ -208,47 +208,47 @@ void BLEEddystoneURL::setPower(int8_t advertisedTxPower) { // | Decoded | http:// | g o o g l e .com | void BLEEddystoneURL::setURL(String url) { if (url.length() > sizeof(m_eddystoneData.url)) { - log_e("Unable to set the url ... length passed in was %d and max expected %d", url.length(), sizeof(m_eddystoneData.url)); - return; + log_e("Unable to set the url ... length passed in was %d and max expected %d", url.length(), sizeof(m_eddystoneData.url)); + return; } memset(m_eddystoneData.url, 0, sizeof(m_eddystoneData.url)); memcpy(m_eddystoneData.url, url.c_str(), url.length()); lengthURL = url.length(); -} // setURL +} // setURL int BLEEddystoneURL::setSmartURL(String url) { - if(url.length() == 0){ + if (url.length() == 0) { log_e("URL String has 0 length"); - return 0; // ERROR + return 0; // ERROR } - for(auto character : url){ - if(!isPrintable(character)){ + for (auto character : url) { + if (!isPrintable(character)) { log_e("URL contains unprintable character(s)"); - return 0; // ERROR + return 0; // ERROR } } bool hasPrefix = false; bool hasSuffix = false; - m_eddystoneData.url[0] = 0x00; // Init with default prefix "http://www." - uint8_t suffix = 0x0E; // Init with empty string + m_eddystoneData.url[0] = 0x00; // Init with default prefix "http://www." + uint8_t suffix = 0x0E; // Init with empty string log_d("Encode url \"%s\" with length %d", url.c_str(), url.length()); - for(uint8_t i = 0; i < 4; ++i){ - if(url.substring(0, EDDYSTONE_URL_PREFIX[i].length()) == EDDYSTONE_URL_PREFIX[i]){ + for (uint8_t i = 0; i < 4; ++i) { + if (url.substring(0, EDDYSTONE_URL_PREFIX[i].length()) == EDDYSTONE_URL_PREFIX[i]) { m_eddystoneData.url[0] = i; hasPrefix = true; break; } } - if(hasPrefix == false){ + if (hasPrefix == false) { log_w("Prefix not found - using default prefix \"http://www.\" = 0x00\n\tNote: URL must contain one of the prefixes: \"http://www.\", \"https://www.\", \"http://\", \"https://\""); } - for(uint8_t i = 0; i < 0x0E; ++i){ + for (uint8_t i = 0; i < 0x0E; ++i) { std::string std_url(url.c_str()); std::string std_suffix(EDDYSTONE_URL_SUFFIX[i].c_str()); size_t found_pos = std_url.find(std_suffix); - if(found_pos != std::string::npos){ + if (found_pos != std::string::npos) { hasSuffix = true; suffix = i; break; @@ -257,33 +257,33 @@ int BLEEddystoneURL::setSmartURL(String url) { size_t baseUrlLen = url.length() - (hasPrefix ? EDDYSTONE_URL_PREFIX[m_eddystoneData.url[0]].length() : 0) - EDDYSTONE_URL_SUFFIX[suffix].length(); lengthURL = baseUrlLen + 1 + (hasSuffix ? 1 : 0); - if(lengthURL > 18){ + if (lengthURL > 18) { log_e("Encoded URL is too long %d B - max 18 B", lengthURL); - return 0; // ERROR + return 0; // ERROR } - String baseUrl = url.substring((hasPrefix ? EDDYSTONE_URL_PREFIX[m_eddystoneData.url[0]].length() : 0), baseUrlLen+(hasPrefix ? EDDYSTONE_URL_PREFIX[m_eddystoneData.url[0]].length() : 0)); - memcpy((void*)(m_eddystoneData.url+1), (void*)baseUrl.c_str(), baseUrl.length()); // substr for Arduino String + String baseUrl = url.substring((hasPrefix ? EDDYSTONE_URL_PREFIX[m_eddystoneData.url[0]].length() : 0), baseUrlLen + (hasPrefix ? EDDYSTONE_URL_PREFIX[m_eddystoneData.url[0]].length() : 0)); + memcpy((void *)(m_eddystoneData.url + 1), (void *)baseUrl.c_str(), baseUrl.length()); // substr for Arduino String - if(hasSuffix){ - m_eddystoneData.url[1+baseUrlLen] = suffix; + if (hasSuffix) { + m_eddystoneData.url[1 + baseUrlLen] = suffix; } - return 1; // OK -} // setSmartURL + return 1; // OK +} // setSmartURL -void BLEEddystoneURL::_initHeadder(){ - BLEHeadder[0] = 0x02; // Len - BLEHeadder[1] = 0x01; // Type Flags - BLEHeadder[2] = 0x06; // GENERAL_DISC_MODE 0x02 | BR_EDR_NOT_SUPPORTED 0x04 - BLEHeadder[3] = 0x03; // Len - BLEHeadder[4] = 0x03; // Type 16-Bit UUID - BLEHeadder[5] = 0xAA; // Eddystone UUID 2 -> 0xFEAA LSB - BLEHeadder[6] = 0xFE; // Eddystone UUID 1 MSB - BLEHeadder[7] = 0x00; // Length of Beacon Data shall be calculated later - BLEHeadder[8] = 0x16; // Type Service Data - BLEHeadder[9] = 0xAA; // Eddystone UUID 2 -> 0xFEAA LSB - BLEHeadder[10] = 0xFE; // Eddystone UUID 1 MSB - BLEHeadder[11] = 0x10; // Eddystone Frame Type - URL +void BLEEddystoneURL::_initHeadder() { + BLEHeadder[0] = 0x02; // Len + BLEHeadder[1] = 0x01; // Type Flags + BLEHeadder[2] = 0x06; // GENERAL_DISC_MODE 0x02 | BR_EDR_NOT_SUPPORTED 0x04 + BLEHeadder[3] = 0x03; // Len + BLEHeadder[4] = 0x03; // Type 16-Bit UUID + BLEHeadder[5] = 0xAA; // Eddystone UUID 2 -> 0xFEAA LSB + BLEHeadder[6] = 0xFE; // Eddystone UUID 1 MSB + BLEHeadder[7] = 0x00; // Length of Beacon Data shall be calculated later + BLEHeadder[8] = 0x16; // Type Service Data + BLEHeadder[9] = 0xAA; // Eddystone UUID 2 -> 0xFEAA LSB + BLEHeadder[10] = 0xFE; // Eddystone UUID 1 MSB + BLEHeadder[11] = 0x10; // Eddystone Frame Type - URL } #endif diff --git a/libraries/BLE/src/BLEEddystoneURL.h b/libraries/BLE/src/BLEEddystoneURL.h index 7f6e114f894..b3289a348f3 100644 --- a/libraries/BLE/src/BLEEddystoneURL.h +++ b/libraries/BLE/src/BLEEddystoneURL.h @@ -31,30 +31,30 @@ class BLEEddystoneURL { public: BLEEddystoneURL(); BLEEddystoneURL(BLEAdvertisedDevice *advertisedDevice); - String getData(); - String getFrame(); - BLEUUID getUUID(); - int8_t getPower(); - String getURL(); - String getPrefix(); - String getSuffix(); - String getDecodedURL(); - void setData(String data); - void setUUID(BLEUUID l_uuid); - void setPower(int8_t advertisedTxPower); - void setPower(esp_power_level_t advertisedTxPower); - void setURL(String url); - int setSmartURL(String url); + String getData(); + String getFrame(); + BLEUUID getUUID(); + int8_t getPower(); + String getURL(); + String getPrefix(); + String getSuffix(); + String getDecodedURL(); + void setData(String data); + void setUUID(BLEUUID l_uuid); + void setPower(int8_t advertisedTxPower); + void setPower(esp_power_level_t advertisedTxPower); + void setURL(String url); + int setSmartURL(String url); private: - uint8_t lengthURL; // Describes the length of the URL part including prefix and optional suffix - max 18 B (excluding TX power, frame type and preceding header) + uint8_t lengthURL; // Describes the length of the URL part including prefix and optional suffix - max 18 B (excluding TX power, frame type and preceding header) struct { - int8_t advertisedTxPower; - uint8_t url[18]; // Byte [0] is for prefix. Last valid byte **can** contain suffix - i.e. the next byte after the URL + int8_t advertisedTxPower; + uint8_t url[18]; // Byte [0] is for prefix. Last valid byte **can** contain suffix - i.e. the next byte after the URL } __attribute__((packed)) m_eddystoneData; void _initHeadder(); char BLEHeadder[12]; -}; // BLEEddystoneURL +}; // BLEEddystoneURL #endif /* SOC_BLE_SUPPORTED */ #endif /* _BLEEddystoneURL_H_ */ diff --git a/libraries/BLE/src/BLEExceptions.cpp b/libraries/BLE/src/BLEExceptions.cpp index 549e4425bd8..4e6c31fca22 100644 --- a/libraries/BLE/src/BLEExceptions.cpp +++ b/libraries/BLE/src/BLEExceptions.cpp @@ -6,4 +6,3 @@ */ //#include "BLEExceptions.h" - diff --git a/libraries/BLE/src/BLEExceptions.h b/libraries/BLE/src/BLEExceptions.h index 1fa10046789..ea2b8c97587 100644 --- a/libraries/BLE/src/BLEExceptions.h +++ b/libraries/BLE/src/BLEExceptions.h @@ -20,15 +20,15 @@ class BLEDisconnectedException : public std::exception { - const char* what() const throw () { - return "BLE Disconnected"; - } + const char* what() const throw() { + return "BLE Disconnected"; + } }; class BLEUuidNotFoundException : public std::exception { - const char* what() const throw () { - return "No such UUID"; - } + const char* what() const throw() { + return "No such UUID"; + } }; #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLEHIDDevice.cpp b/libraries/BLE/src/BLEHIDDevice.cpp index 27d88044cec..3ceae347c75 100644 --- a/libraries/BLE/src/BLEHIDDevice.cpp +++ b/libraries/BLE/src/BLEHIDDevice.cpp @@ -15,47 +15,47 @@ BLEHIDDevice::BLEHIDDevice(BLEServer* server) { - /* + /* * Here we create mandatory services described in bluetooth specification */ - m_deviceInfoService = server->createService(BLEUUID((uint16_t) 0x180a)); - m_hidService = server->createService(BLEUUID((uint16_t) 0x1812), 40); - m_batteryService = server->createService(BLEUUID((uint16_t) 0x180f)); + m_deviceInfoService = server->createService(BLEUUID((uint16_t)0x180a)); + m_hidService = server->createService(BLEUUID((uint16_t)0x1812), 40); + m_batteryService = server->createService(BLEUUID((uint16_t)0x180f)); - /* + /* * Mandatory characteristic for device info service */ - m_pnpCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t) 0x2a50, BLECharacteristic::PROPERTY_READ); + m_pnpCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t)0x2a50, BLECharacteristic::PROPERTY_READ); - /* + /* * Mandatory characteristics for HID service */ - m_hidInfoCharacteristic = m_hidService->createCharacteristic((uint16_t) 0x2a4a, BLECharacteristic::PROPERTY_READ); - m_reportMapCharacteristic = m_hidService->createCharacteristic((uint16_t) 0x2a4b, BLECharacteristic::PROPERTY_READ); - m_hidControlCharacteristic = m_hidService->createCharacteristic((uint16_t) 0x2a4c, BLECharacteristic::PROPERTY_WRITE_NR); - m_protocolModeCharacteristic = m_hidService->createCharacteristic((uint16_t) 0x2a4e, BLECharacteristic::PROPERTY_WRITE_NR | BLECharacteristic::PROPERTY_READ); + m_hidInfoCharacteristic = m_hidService->createCharacteristic((uint16_t)0x2a4a, BLECharacteristic::PROPERTY_READ); + m_reportMapCharacteristic = m_hidService->createCharacteristic((uint16_t)0x2a4b, BLECharacteristic::PROPERTY_READ); + m_hidControlCharacteristic = m_hidService->createCharacteristic((uint16_t)0x2a4c, BLECharacteristic::PROPERTY_WRITE_NR); + m_protocolModeCharacteristic = m_hidService->createCharacteristic((uint16_t)0x2a4e, BLECharacteristic::PROPERTY_WRITE_NR | BLECharacteristic::PROPERTY_READ); - /* + /* * Mandatory battery level characteristic with notification and presence descriptor */ - BLE2904* batteryLevelDescriptor = new BLE2904(); - batteryLevelDescriptor->setFormat(BLE2904::FORMAT_UINT8); - batteryLevelDescriptor->setNamespace(1); - batteryLevelDescriptor->setUnit(0x27ad); - - m_batteryLevelCharacteristic = m_batteryService->createCharacteristic((uint16_t) 0x2a19, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY); - m_batteryLevelCharacteristic->addDescriptor(batteryLevelDescriptor); - BLE2902 *batLevelIndicator = new BLE2902(); - // Battery Level Notification is ON by default, making it work always on BLE Pairing and Bonding - batLevelIndicator->setNotifications(true); - m_batteryLevelCharacteristic->addDescriptor(batLevelIndicator); - - /* + BLE2904* batteryLevelDescriptor = new BLE2904(); + batteryLevelDescriptor->setFormat(BLE2904::FORMAT_UINT8); + batteryLevelDescriptor->setNamespace(1); + batteryLevelDescriptor->setUnit(0x27ad); + + m_batteryLevelCharacteristic = m_batteryService->createCharacteristic((uint16_t)0x2a19, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY); + m_batteryLevelCharacteristic->addDescriptor(batteryLevelDescriptor); + BLE2902* batLevelIndicator = new BLE2902(); + // Battery Level Notification is ON by default, making it work always on BLE Pairing and Bonding + batLevelIndicator->setNotifications(true); + m_batteryLevelCharacteristic->addDescriptor(batLevelIndicator); + + /* * This value is setup here because its default value in most usage cases, its very rare to use boot mode * and we want to simplify library using as much as possible */ - const uint8_t pMode[] = { 0x01 }; - protocolMode()->setValue((uint8_t*) pMode, 1); + const uint8_t pMode[] = { 0x01 }; + protocolMode()->setValue((uint8_t*)pMode, 1); } BLEHIDDevice::~BLEHIDDevice() { @@ -65,24 +65,24 @@ BLEHIDDevice::~BLEHIDDevice() { * @brief */ void BLEHIDDevice::reportMap(uint8_t* map, uint16_t size) { - m_reportMapCharacteristic->setValue(map, size); + m_reportMapCharacteristic->setValue(map, size); } /* * @brief This function suppose to be called at the end, when we have created all characteristics we need to build HID service */ void BLEHIDDevice::startServices() { - m_deviceInfoService->start(); - m_hidService->start(); - m_batteryService->start(); + m_deviceInfoService->start(); + m_hidService->start(); + m_batteryService->start(); } /* * @brief Create manufacturer characteristic (this characteristic is optional) */ BLECharacteristic* BLEHIDDevice::manufacturer() { - m_manufacturerCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t) 0x2a29, BLECharacteristic::PROPERTY_READ); - return m_manufacturerCharacteristic; + m_manufacturerCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t)0x2a29, BLECharacteristic::PROPERTY_READ); + return m_manufacturerCharacteristic; } /* @@ -90,23 +90,23 @@ BLECharacteristic* BLEHIDDevice::manufacturer() { * @param [in] name manufacturer name */ void BLEHIDDevice::manufacturer(String name) { - m_manufacturerCharacteristic->setValue(name); + m_manufacturerCharacteristic->setValue(name); } /* * @brief */ void BLEHIDDevice::pnp(uint8_t sig, uint16_t vid, uint16_t pid, uint16_t version) { - uint8_t pnp[] = { sig, (uint8_t) (vid >> 8), (uint8_t) vid, (uint8_t) (pid >> 8), (uint8_t) pid, (uint8_t) (version >> 8), (uint8_t) version }; - m_pnpCharacteristic->setValue(pnp, sizeof(pnp)); + uint8_t pnp[] = { sig, (uint8_t)(vid >> 8), (uint8_t)vid, (uint8_t)(pid >> 8), (uint8_t)pid, (uint8_t)(version >> 8), (uint8_t)version }; + m_pnpCharacteristic->setValue(pnp, sizeof(pnp)); } /* * @brief */ void BLEHIDDevice::hidInfo(uint8_t country, uint8_t flags) { - uint8_t info[] = { 0x11, 0x1, country, flags }; - m_hidInfoCharacteristic->setValue(info, sizeof(info)); + uint8_t info[] = { 0x11, 0x1, country, flags }; + m_hidInfoCharacteristic->setValue(info, sizeof(info)); } /* @@ -115,19 +115,19 @@ void BLEHIDDevice::hidInfo(uint8_t country, uint8_t flags) { * @return pointer to new input report characteristic */ BLECharacteristic* BLEHIDDevice::inputReport(uint8_t reportID) { - BLECharacteristic* inputReportCharacteristic = m_hidService->createCharacteristic((uint16_t) 0x2a4d, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY); - BLEDescriptor* inputReportDescriptor = new BLEDescriptor(BLEUUID((uint16_t) 0x2908)); - BLE2902* p2902 = new BLE2902(); - inputReportCharacteristic->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED); - inputReportDescriptor->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED); - p2902->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED); + BLECharacteristic* inputReportCharacteristic = m_hidService->createCharacteristic((uint16_t)0x2a4d, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY); + BLEDescriptor* inputReportDescriptor = new BLEDescriptor(BLEUUID((uint16_t)0x2908)); + BLE2902* p2902 = new BLE2902(); + inputReportCharacteristic->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED); + inputReportDescriptor->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED); + p2902->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED); - uint8_t desc1_val[] = { reportID, 0x01 }; - inputReportDescriptor->setValue((uint8_t*) desc1_val, 2); - inputReportCharacteristic->addDescriptor(p2902); - inputReportCharacteristic->addDescriptor(inputReportDescriptor); + uint8_t desc1_val[] = { reportID, 0x01 }; + inputReportDescriptor->setValue((uint8_t*)desc1_val, 2); + inputReportCharacteristic->addDescriptor(p2902); + inputReportCharacteristic->addDescriptor(inputReportDescriptor); - return inputReportCharacteristic; + return inputReportCharacteristic; } /* @@ -136,16 +136,16 @@ BLECharacteristic* BLEHIDDevice::inputReport(uint8_t reportID) { * @return Pointer to new output report characteristic */ BLECharacteristic* BLEHIDDevice::outputReport(uint8_t reportID) { - BLECharacteristic* outputReportCharacteristic = m_hidService->createCharacteristic((uint16_t) 0x2a4d, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_WRITE_NR); - BLEDescriptor* outputReportDescriptor = new BLEDescriptor(BLEUUID((uint16_t) 0x2908)); - outputReportCharacteristic->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED); - outputReportDescriptor->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED); + BLECharacteristic* outputReportCharacteristic = m_hidService->createCharacteristic((uint16_t)0x2a4d, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_WRITE_NR); + BLEDescriptor* outputReportDescriptor = new BLEDescriptor(BLEUUID((uint16_t)0x2908)); + outputReportCharacteristic->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED); + outputReportDescriptor->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED); - uint8_t desc1_val[] = { reportID, 0x02 }; - outputReportDescriptor->setValue((uint8_t*) desc1_val, 2); - outputReportCharacteristic->addDescriptor(outputReportDescriptor); + uint8_t desc1_val[] = { reportID, 0x02 }; + outputReportDescriptor->setValue((uint8_t*)desc1_val, 2); + outputReportCharacteristic->addDescriptor(outputReportDescriptor); - return outputReportCharacteristic; + return outputReportCharacteristic; } /* @@ -154,58 +154,59 @@ BLECharacteristic* BLEHIDDevice::outputReport(uint8_t reportID) { * @return Pointer to new feature report characteristic */ BLECharacteristic* BLEHIDDevice::featureReport(uint8_t reportID) { - BLECharacteristic* featureReportCharacteristic = m_hidService->createCharacteristic((uint16_t) 0x2a4d, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE); - BLEDescriptor* featureReportDescriptor = new BLEDescriptor(BLEUUID((uint16_t) 0x2908)); + BLECharacteristic* featureReportCharacteristic = m_hidService->createCharacteristic((uint16_t)0x2a4d, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE); + BLEDescriptor* featureReportDescriptor = new BLEDescriptor(BLEUUID((uint16_t)0x2908)); - featureReportCharacteristic->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED); - featureReportDescriptor->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED); + featureReportCharacteristic->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED); + featureReportDescriptor->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED); - uint8_t desc1_val[] = { reportID, 0x03 }; - featureReportDescriptor->setValue((uint8_t*) desc1_val, 2); - featureReportCharacteristic->addDescriptor(featureReportDescriptor); + uint8_t desc1_val[] = { reportID, 0x03 }; + featureReportDescriptor->setValue((uint8_t*)desc1_val, 2); + featureReportCharacteristic->addDescriptor(featureReportDescriptor); - return featureReportCharacteristic; + return featureReportCharacteristic; } /* * @brief */ BLECharacteristic* BLEHIDDevice::bootInput() { - BLECharacteristic* bootInputCharacteristic = m_hidService->createCharacteristic((uint16_t) 0x2a22, BLECharacteristic::PROPERTY_NOTIFY); - bootInputCharacteristic->addDescriptor(new BLE2902()); + BLECharacteristic* bootInputCharacteristic = m_hidService->createCharacteristic((uint16_t)0x2a22, BLECharacteristic::PROPERTY_NOTIFY); + bootInputCharacteristic->addDescriptor(new BLE2902()); - return bootInputCharacteristic; + return bootInputCharacteristic; } /* * @brief */ BLECharacteristic* BLEHIDDevice::bootOutput() { - return m_hidService->createCharacteristic((uint16_t) 0x2a32, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_WRITE_NR); + return m_hidService->createCharacteristic((uint16_t)0x2a32, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_WRITE_NR); } /* * @brief */ BLECharacteristic* BLEHIDDevice::hidControl() { - return m_hidControlCharacteristic; + return m_hidControlCharacteristic; } /* * @brief */ BLECharacteristic* BLEHIDDevice::protocolMode() { - return m_protocolModeCharacteristic; + return m_protocolModeCharacteristic; } void BLEHIDDevice::setBatteryLevel(uint8_t level) { - m_batteryLevelCharacteristic->setValue(&level, 1); - m_batteryLevelCharacteristic->notify(); + m_batteryLevelCharacteristic->setValue(&level, 1); + m_batteryLevelCharacteristic->notify(); } /* * @brief Returns battery level characteristic * @ return battery level characteristic - *//* + */ +/* BLECharacteristic* BLEHIDDevice::batteryLevel() { return m_batteryLevelCharacteristic; } @@ -229,21 +230,21 @@ BLECharacteristic* BLEHIDDevice::hidInfo() { * @brief */ BLEService* BLEHIDDevice::deviceInfo() { - return m_deviceInfoService; + return m_deviceInfoService; } /* * @brief */ BLEService* BLEHIDDevice::hidService() { - return m_hidService; + return m_hidService; } /* * @brief */ BLEService* BLEHIDDevice::batteryService() { - return m_batteryService; + return m_batteryService; } #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLEHIDDevice.h b/libraries/BLE/src/BLEHIDDevice.h index 956dbada806..143f4421a4b 100644 --- a/libraries/BLE/src/BLEHIDDevice.h +++ b/libraries/BLE/src/BLEHIDDevice.h @@ -20,60 +20,60 @@ #include "BLE2902.h" #include "HIDTypes.h" -#define GENERIC_HID 0x03C0 -#define HID_KEYBOARD 0x03C1 -#define HID_MOUSE 0x03C2 -#define HID_JOYSTICK 0x03C3 -#define HID_GAMEPAD 0x03C4 -#define HID_TABLET 0x03C5 -#define HID_CARD_READER 0x03C6 -#define HID_DIGITAL_PEN 0x03C7 -#define HID_BARCODE 0x03C8 -#define HID_BRAILLE_DISPLAY 0x03C9 +#define GENERIC_HID 0x03C0 +#define HID_KEYBOARD 0x03C1 +#define HID_MOUSE 0x03C2 +#define HID_JOYSTICK 0x03C3 +#define HID_GAMEPAD 0x03C4 +#define HID_TABLET 0x03C5 +#define HID_CARD_READER 0x03C6 +#define HID_DIGITAL_PEN 0x03C7 +#define HID_BARCODE 0x03C8 +#define HID_BRAILLE_DISPLAY 0x03C9 class BLEHIDDevice { public: - BLEHIDDevice(BLEServer*); - virtual ~BLEHIDDevice(); + BLEHIDDevice(BLEServer*); + virtual ~BLEHIDDevice(); - void reportMap(uint8_t* map, uint16_t); - void startServices(); + void reportMap(uint8_t* map, uint16_t); + void startServices(); - BLEService* deviceInfo(); - BLEService* hidService(); - BLEService* batteryService(); + BLEService* deviceInfo(); + BLEService* hidService(); + BLEService* batteryService(); - BLECharacteristic* manufacturer(); - void manufacturer(String name); - //BLECharacteristic* pnp(); - void pnp(uint8_t sig, uint16_t vid, uint16_t pid, uint16_t version); - //BLECharacteristic* hidInfo(); - void hidInfo(uint8_t country, uint8_t flags); - //BLECharacteristic* batteryLevel(); - void setBatteryLevel(uint8_t level); + BLECharacteristic* manufacturer(); + void manufacturer(String name); + //BLECharacteristic* pnp(); + void pnp(uint8_t sig, uint16_t vid, uint16_t pid, uint16_t version); + //BLECharacteristic* hidInfo(); + void hidInfo(uint8_t country, uint8_t flags); + //BLECharacteristic* batteryLevel(); + void setBatteryLevel(uint8_t level); - //BLECharacteristic* reportMap(); - BLECharacteristic* hidControl(); - BLECharacteristic* inputReport(uint8_t reportID); - BLECharacteristic* outputReport(uint8_t reportID); - BLECharacteristic* featureReport(uint8_t reportID); - BLECharacteristic* protocolMode(); - BLECharacteristic* bootInput(); - BLECharacteristic* bootOutput(); + //BLECharacteristic* reportMap(); + BLECharacteristic* hidControl(); + BLECharacteristic* inputReport(uint8_t reportID); + BLECharacteristic* outputReport(uint8_t reportID); + BLECharacteristic* featureReport(uint8_t reportID); + BLECharacteristic* protocolMode(); + BLECharacteristic* bootInput(); + BLECharacteristic* bootOutput(); private: - BLEService* m_deviceInfoService; //0x180a - BLEService* m_hidService; //0x1812 - BLEService* m_batteryService = 0; //0x180f + BLEService* m_deviceInfoService; //0x180a + BLEService* m_hidService; //0x1812 + BLEService* m_batteryService = 0; //0x180f - BLECharacteristic* m_manufacturerCharacteristic; //0x2a29 - BLECharacteristic* m_pnpCharacteristic; //0x2a50 - BLECharacteristic* m_hidInfoCharacteristic; //0x2a4a - BLECharacteristic* m_reportMapCharacteristic; //0x2a4b - BLECharacteristic* m_hidControlCharacteristic; //0x2a4c - BLECharacteristic* m_protocolModeCharacteristic; //0x2a4e - BLECharacteristic* m_batteryLevelCharacteristic; //0x2a19 + BLECharacteristic* m_manufacturerCharacteristic; //0x2a29 + BLECharacteristic* m_pnpCharacteristic; //0x2a50 + BLECharacteristic* m_hidInfoCharacteristic; //0x2a4a + BLECharacteristic* m_reportMapCharacteristic; //0x2a4b + BLECharacteristic* m_hidControlCharacteristic; //0x2a4c + BLECharacteristic* m_protocolModeCharacteristic; //0x2a4e + BLECharacteristic* m_batteryLevelCharacteristic; //0x2a19 }; #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLERemoteCharacteristic.cpp b/libraries/BLE/src/BLERemoteCharacteristic.cpp index 620951b66c8..44d6954f184 100644 --- a/libraries/BLE/src/BLERemoteCharacteristic.cpp +++ b/libraries/BLE/src/BLERemoteCharacteristic.cpp @@ -32,31 +32,31 @@ * @param [in] pRemoteService A reference to the remote service to which this remote characteristic pertains. */ BLERemoteCharacteristic::BLERemoteCharacteristic( - uint16_t handle, - BLEUUID uuid, - esp_gatt_char_prop_t charProp, - BLERemoteService* pRemoteService) { - log_v(">> BLERemoteCharacteristic: handle: %d 0x%d, uuid: %s", handle, handle, uuid.toString().c_str()); - m_handle = handle; - m_uuid = uuid; - m_charProp = charProp; - m_pRemoteService = pRemoteService; - m_notifyCallback = nullptr; - m_rawData = nullptr; - m_auth = ESP_GATT_AUTH_REQ_NONE; - - retrieveDescriptors(); // Get the descriptors for this characteristic - log_v("<< BLERemoteCharacteristic"); -} // BLERemoteCharacteristic + uint16_t handle, + BLEUUID uuid, + esp_gatt_char_prop_t charProp, + BLERemoteService* pRemoteService) { + log_v(">> BLERemoteCharacteristic: handle: %d 0x%d, uuid: %s", handle, handle, uuid.toString().c_str()); + m_handle = handle; + m_uuid = uuid; + m_charProp = charProp; + m_pRemoteService = pRemoteService; + m_notifyCallback = nullptr; + m_rawData = nullptr; + m_auth = ESP_GATT_AUTH_REQ_NONE; + + retrieveDescriptors(); // Get the descriptors for this characteristic + log_v("<< BLERemoteCharacteristic"); +} // BLERemoteCharacteristic /** *@brief Destructor. */ BLERemoteCharacteristic::~BLERemoteCharacteristic() { - removeDescriptors(); // Release resources for any descriptor information we may have allocated. - free(m_rawData); -} // ~BLERemoteCharacteristic + removeDescriptors(); // Release resources for any descriptor information we may have allocated. + free(m_rawData); +} // ~BLERemoteCharacteristic /** @@ -64,8 +64,8 @@ BLERemoteCharacteristic::~BLERemoteCharacteristic() { * @return True if the characteristic supports broadcasting. */ bool BLERemoteCharacteristic::canBroadcast() { - return (m_charProp & ESP_GATT_CHAR_PROP_BIT_BROADCAST) != 0; -} // canBroadcast + return (m_charProp & ESP_GATT_CHAR_PROP_BIT_BROADCAST) != 0; +} // canBroadcast /** @@ -73,8 +73,8 @@ bool BLERemoteCharacteristic::canBroadcast() { * @return True if the characteristic supports indications. */ bool BLERemoteCharacteristic::canIndicate() { - return (m_charProp & ESP_GATT_CHAR_PROP_BIT_INDICATE) != 0; -} // canIndicate + return (m_charProp & ESP_GATT_CHAR_PROP_BIT_INDICATE) != 0; +} // canIndicate /** @@ -82,8 +82,8 @@ bool BLERemoteCharacteristic::canIndicate() { * @return True if the characteristic supports notifications. */ bool BLERemoteCharacteristic::canNotify() { - return (m_charProp & ESP_GATT_CHAR_PROP_BIT_NOTIFY) != 0; -} // canNotify + return (m_charProp & ESP_GATT_CHAR_PROP_BIT_NOTIFY) != 0; +} // canNotify /** @@ -91,8 +91,8 @@ bool BLERemoteCharacteristic::canNotify() { * @return True if the characteristic supports reading. */ bool BLERemoteCharacteristic::canRead() { - return (m_charProp & ESP_GATT_CHAR_PROP_BIT_READ) != 0; -} // canRead + return (m_charProp & ESP_GATT_CHAR_PROP_BIT_READ) != 0; +} // canRead /** @@ -100,8 +100,8 @@ bool BLERemoteCharacteristic::canRead() { * @return True if the characteristic supports writing. */ bool BLERemoteCharacteristic::canWrite() { - return (m_charProp & ESP_GATT_CHAR_PROP_BIT_WRITE) != 0; -} // canWrite + return (m_charProp & ESP_GATT_CHAR_PROP_BIT_WRITE) != 0; +} // canWrite /** @@ -109,8 +109,8 @@ bool BLERemoteCharacteristic::canWrite() { * @return True if the characteristic supports writing with no response. */ bool BLERemoteCharacteristic::canWriteNoResponse() { - return (m_charProp & ESP_GATT_CHAR_PROP_BIT_WRITE_NR) != 0; -} // canWriteNoResponse + return (m_charProp & ESP_GATT_CHAR_PROP_BIT_WRITE_NR) != 0; +} // canWriteNoResponse /* @@ -148,177 +148,180 @@ static bool compareGattId(esp_gatt_id_t id1, esp_gatt_id_t id2) { * @returns N/A */ void BLERemoteCharacteristic::gattClientEventHandler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* evtParam) { - switch(event) { - // ESP_GATTC_NOTIFY_EVT - // - // notify - // - uint16_t conn_id - The connection identifier of the server. - // - esp_bd_addr_t remote_bda - The device address of the BLE server. - // - uint16_t handle - The handle of the characteristic for which the event is being received. - // - uint16_t value_len - The length of the received data. - // - uint8_t* value - The received data. - // - bool is_notify - True if this is a notify, false if it is an indicate. - // - // We have received a notification event which means that the server wishes us to know about a notification - // piece of data. What we must now do is find the characteristic with the associated handle and then - // invoke its notification callback (if it has one). - case ESP_GATTC_NOTIFY_EVT: { - if (evtParam->notify.handle != getHandle()) break; - if (m_notifyCallback != nullptr) { - log_d("Invoking callback for notification on characteristic %s", toString().c_str()); - m_notifyCallback(this, evtParam->notify.value, evtParam->notify.value_len, evtParam->notify.is_notify); - } // End we have a callback function ... - break; - } // ESP_GATTC_NOTIFY_EVT - - // ESP_GATTC_READ_CHAR_EVT - // This event indicates that the server has responded to the read request. - // - // read: - // - esp_gatt_status_t status - // - uint16_t conn_id - // - uint16_t handle - // - uint8_t* value - // - uint16_t value_len - case ESP_GATTC_READ_CHAR_EVT: { - // If this event is not for us, then nothing further to do. - if (evtParam->read.handle != getHandle()) break; - - // At this point, we have determined that the event is for us, so now we save the value - // and unlock the semaphore to ensure that the requestor of the data can continue. - if (evtParam->read.status == ESP_GATT_OK) { - m_value = String((char*) evtParam->read.value, evtParam->read.value_len); - if(m_rawData != nullptr) free(m_rawData); - m_rawData = (uint8_t*) calloc(evtParam->read.value_len, sizeof(uint8_t)); - memcpy(m_rawData, evtParam->read.value, evtParam->read.value_len); - } else { - m_value = ""; - } - - m_semaphoreReadCharEvt.give(); - break; - } // ESP_GATTC_READ_CHAR_EVT - - // ESP_GATTC_REG_FOR_NOTIFY_EVT - // - // reg_for_notify: - // - esp_gatt_status_t status - // - uint16_t handle - case ESP_GATTC_REG_FOR_NOTIFY_EVT: { - // If the request is not for this BLERemoteCharacteristic then move on to the next. - if (evtParam->reg_for_notify.handle != getHandle()) break; - - // We have processed the notify registration and can unlock the semaphore. - m_semaphoreRegForNotifyEvt.give(); - break; - } // ESP_GATTC_REG_FOR_NOTIFY_EVT - - // ESP_GATTC_UNREG_FOR_NOTIFY_EVT - // - // unreg_for_notify: - // - esp_gatt_status_t status - // - uint16_t handle - case ESP_GATTC_UNREG_FOR_NOTIFY_EVT: { - if (evtParam->unreg_for_notify.handle != getHandle()) break; - // We have processed the notify un-registration and can unlock the semaphore. - m_semaphoreRegForNotifyEvt.give(); - break; - } // ESP_GATTC_UNREG_FOR_NOTIFY_EVT: - - // ESP_GATTC_WRITE_CHAR_EVT - // - // write: - // - esp_gatt_status_t status - // - uint16_t conn_id - // - uint16_t handle - case ESP_GATTC_WRITE_CHAR_EVT: { - // Determine if this event is for us and, if not, pass onwards. - if (evtParam->write.handle != getHandle()) break; - - // There is nothing further we need to do here. This is merely an indication - // that the write has completed and we can unlock the caller. - m_semaphoreWriteCharEvt.give(); - break; - } // ESP_GATTC_WRITE_CHAR_EVT - - case ESP_GATTC_READ_DESCR_EVT: - case ESP_GATTC_WRITE_DESCR_EVT: - for (auto &myPair : m_descriptorMap) { - myPair.second->gattClientEventHandler( - event, gattc_if, evtParam); - } - break; - - case ESP_GATTC_DISCONNECT_EVT: - // Cleanup semaphores to avoid deadlocks. - m_semaphoreReadCharEvt.give(1); - m_semaphoreWriteCharEvt.give(1); - break; - - default: - break; - } // End switch -}; // gattClientEventHandler + switch (event) { + // ESP_GATTC_NOTIFY_EVT + // + // notify + // - uint16_t conn_id - The connection identifier of the server. + // - esp_bd_addr_t remote_bda - The device address of the BLE server. + // - uint16_t handle - The handle of the characteristic for which the event is being received. + // - uint16_t value_len - The length of the received data. + // - uint8_t* value - The received data. + // - bool is_notify - True if this is a notify, false if it is an indicate. + // + // We have received a notification event which means that the server wishes us to know about a notification + // piece of data. What we must now do is find the characteristic with the associated handle and then + // invoke its notification callback (if it has one). + case ESP_GATTC_NOTIFY_EVT: + { + if (evtParam->notify.handle != getHandle()) break; + if (m_notifyCallback != nullptr) { + log_d("Invoking callback for notification on characteristic %s", toString().c_str()); + m_notifyCallback(this, evtParam->notify.value, evtParam->notify.value_len, evtParam->notify.is_notify); + } // End we have a callback function ... + break; + } // ESP_GATTC_NOTIFY_EVT + + // ESP_GATTC_READ_CHAR_EVT + // This event indicates that the server has responded to the read request. + // + // read: + // - esp_gatt_status_t status + // - uint16_t conn_id + // - uint16_t handle + // - uint8_t* value + // - uint16_t value_len + case ESP_GATTC_READ_CHAR_EVT: + { + // If this event is not for us, then nothing further to do. + if (evtParam->read.handle != getHandle()) break; + + // At this point, we have determined that the event is for us, so now we save the value + // and unlock the semaphore to ensure that the requestor of the data can continue. + if (evtParam->read.status == ESP_GATT_OK) { + m_value = String((char*)evtParam->read.value, evtParam->read.value_len); + if (m_rawData != nullptr) free(m_rawData); + m_rawData = (uint8_t*)calloc(evtParam->read.value_len, sizeof(uint8_t)); + memcpy(m_rawData, evtParam->read.value, evtParam->read.value_len); + } else { + m_value = ""; + } + + m_semaphoreReadCharEvt.give(); + break; + } // ESP_GATTC_READ_CHAR_EVT + + // ESP_GATTC_REG_FOR_NOTIFY_EVT + // + // reg_for_notify: + // - esp_gatt_status_t status + // - uint16_t handle + case ESP_GATTC_REG_FOR_NOTIFY_EVT: + { + // If the request is not for this BLERemoteCharacteristic then move on to the next. + if (evtParam->reg_for_notify.handle != getHandle()) break; + + // We have processed the notify registration and can unlock the semaphore. + m_semaphoreRegForNotifyEvt.give(); + break; + } // ESP_GATTC_REG_FOR_NOTIFY_EVT + + // ESP_GATTC_UNREG_FOR_NOTIFY_EVT + // + // unreg_for_notify: + // - esp_gatt_status_t status + // - uint16_t handle + case ESP_GATTC_UNREG_FOR_NOTIFY_EVT: + { + if (evtParam->unreg_for_notify.handle != getHandle()) break; + // We have processed the notify un-registration and can unlock the semaphore. + m_semaphoreRegForNotifyEvt.give(); + break; + } // ESP_GATTC_UNREG_FOR_NOTIFY_EVT: + + // ESP_GATTC_WRITE_CHAR_EVT + // + // write: + // - esp_gatt_status_t status + // - uint16_t conn_id + // - uint16_t handle + case ESP_GATTC_WRITE_CHAR_EVT: + { + // Determine if this event is for us and, if not, pass onwards. + if (evtParam->write.handle != getHandle()) break; + + // There is nothing further we need to do here. This is merely an indication + // that the write has completed and we can unlock the caller. + m_semaphoreWriteCharEvt.give(); + break; + } // ESP_GATTC_WRITE_CHAR_EVT + + case ESP_GATTC_READ_DESCR_EVT: + case ESP_GATTC_WRITE_DESCR_EVT: + for (auto& myPair : m_descriptorMap) { + myPair.second->gattClientEventHandler( + event, gattc_if, evtParam); + } + break; + + case ESP_GATTC_DISCONNECT_EVT: + // Cleanup semaphores to avoid deadlocks. + m_semaphoreReadCharEvt.give(1); + m_semaphoreWriteCharEvt.give(1); + break; + + default: + break; + } // End switch +}; // gattClientEventHandler /** * @brief Populate the descriptors (if any) for this characteristic. */ void BLERemoteCharacteristic::retrieveDescriptors() { - log_v(">> retrieveDescriptors() for characteristic: %s", getUUID().toString().c_str()); - - removeDescriptors(); // Remove any existing descriptors. - - // Loop over each of the descriptors within the service associated with this characteristic. - // For each descriptor we find, create a BLERemoteDescriptor instance. - uint16_t offset = 0; - esp_gattc_descr_elem_t result; - while(true) { - uint16_t count = 10; - esp_gatt_status_t status = ::esp_ble_gattc_get_all_descr( - getRemoteService()->getClient()->getGattcIf(), - getRemoteService()->getClient()->getConnId(), - getHandle(), - &result, - &count, - offset - ); - - if (status == ESP_GATT_INVALID_OFFSET) { // We have reached the end of the entries. - break; - } - - if (status != ESP_GATT_OK) { - log_e("esp_ble_gattc_get_all_descr: %s", BLEUtils::gattStatusToString(status).c_str()); - break; - } - - if (count == 0) break; - - log_d("Found a descriptor: Handle: %d, UUID: %s", result.handle, BLEUUID(result.uuid).toString().c_str()); - - // We now have a new characteristic ... let us add that to our set of known characteristics - BLERemoteDescriptor* pNewRemoteDescriptor = new BLERemoteDescriptor( - result.handle, - BLEUUID(result.uuid), - this - ); - - m_descriptorMap.insert(std::pair(pNewRemoteDescriptor->getUUID().toString(), pNewRemoteDescriptor)); - - offset++; - } // while true - //m_haveCharacteristics = true; // Remember that we have received the characteristics. - log_v("<< retrieveDescriptors(): Found %d descriptors.", offset); -} // getDescriptors + log_v(">> retrieveDescriptors() for characteristic: %s", getUUID().toString().c_str()); + + removeDescriptors(); // Remove any existing descriptors. + + // Loop over each of the descriptors within the service associated with this characteristic. + // For each descriptor we find, create a BLERemoteDescriptor instance. + uint16_t offset = 0; + esp_gattc_descr_elem_t result; + while (true) { + uint16_t count = 10; + esp_gatt_status_t status = ::esp_ble_gattc_get_all_descr( + getRemoteService()->getClient()->getGattcIf(), + getRemoteService()->getClient()->getConnId(), + getHandle(), + &result, + &count, + offset); + + if (status == ESP_GATT_INVALID_OFFSET) { // We have reached the end of the entries. + break; + } + + if (status != ESP_GATT_OK) { + log_e("esp_ble_gattc_get_all_descr: %s", BLEUtils::gattStatusToString(status).c_str()); + break; + } + + if (count == 0) break; + + log_d("Found a descriptor: Handle: %d, UUID: %s", result.handle, BLEUUID(result.uuid).toString().c_str()); + + // We now have a new characteristic ... let us add that to our set of known characteristics + BLERemoteDescriptor* pNewRemoteDescriptor = new BLERemoteDescriptor( + result.handle, + BLEUUID(result.uuid), + this); + + m_descriptorMap.insert(std::pair(pNewRemoteDescriptor->getUUID().toString(), pNewRemoteDescriptor)); + + offset++; + } // while true + //m_haveCharacteristics = true; // Remember that we have received the characteristics. + log_v("<< retrieveDescriptors(): Found %d descriptors.", offset); +} // getDescriptors /** * @brief Retrieve the map of descriptors keyed by UUID. */ std::map* BLERemoteCharacteristic::getDescriptors() { - return &m_descriptorMap; -} // getDescriptors + return &m_descriptorMap; +} // getDescriptors /** @@ -326,10 +329,10 @@ std::map* BLERemoteCharacteristic::getDescriptors( * @return The handle for this characteristic. */ uint16_t BLERemoteCharacteristic::getHandle() { - //log_v(">> getHandle: Characteristic: %s", getUUID().toString().c_str()); - //log_v("<< getHandle: %d 0x%.2x", m_handle, m_handle); - return m_handle; -} // getHandle + //log_v(">> getHandle: Characteristic: %s", getUUID().toString().c_str()); + //log_v("<< getHandle: %d 0x%.2x", m_handle, m_handle); + return m_handle; +} // getHandle /** @@ -338,17 +341,17 @@ uint16_t BLERemoteCharacteristic::getHandle() { * @return The Remote descriptor (if present) or null if not present. */ BLERemoteDescriptor* BLERemoteCharacteristic::getDescriptor(BLEUUID uuid) { - log_v(">> getDescriptor: uuid: %s", uuid.toString().c_str()); - String v = uuid.toString(); - for (auto &myPair : m_descriptorMap) { - if (myPair.first == v) { - log_v("<< getDescriptor: found"); - return myPair.second; - } - } - log_v("<< getDescriptor: Not found"); - return nullptr; -} // getDescriptor + log_v(">> getDescriptor: uuid: %s", uuid.toString().c_str()); + String v = uuid.toString(); + for (auto& myPair : m_descriptorMap) { + if (myPair.first == v) { + log_v("<< getDescriptor: found"); + return myPair.second; + } + } + log_v("<< getDescriptor: Not found"); + return nullptr; +} // getDescriptor /** @@ -356,8 +359,8 @@ BLERemoteDescriptor* BLERemoteCharacteristic::getDescriptor(BLEUUID uuid) { * @return The remote service associated with this characteristic. */ BLERemoteService* BLERemoteCharacteristic::getRemoteService() { - return m_pRemoteService; -} // getRemoteService + return m_pRemoteService; +} // getRemoteService /** @@ -365,8 +368,8 @@ BLERemoteService* BLERemoteCharacteristic::getRemoteService() { * @return The UUID for this characteristic. */ BLEUUID BLERemoteCharacteristic::getUUID() { - return m_uuid; -} // getUUID + return m_uuid; +} // getUUID /** @@ -374,12 +377,12 @@ BLEUUID BLERemoteCharacteristic::getUUID() { * @return The unsigned 16 bit value. */ uint16_t BLERemoteCharacteristic::readUInt16() { - String value = readValue(); - if (value.length() >= 2) { - return *(uint16_t*)(value.c_str()); - } - return 0; -} // readUInt16 + String value = readValue(); + if (value.length() >= 2) { + return *(uint16_t*)(value.c_str()); + } + return 0; +} // readUInt16 /** @@ -387,12 +390,12 @@ uint16_t BLERemoteCharacteristic::readUInt16() { * @return the unsigned 32 bit value. */ uint32_t BLERemoteCharacteristic::readUInt32() { - String value = readValue(); - if (value.length() >= 4) { - return *(uint32_t*)(value.c_str()); - } - return 0; -} // readUInt32 + String value = readValue(); + if (value.length() >= 4) { + return *(uint32_t*)(value.c_str()); + } + return 0; +} // readUInt32 /** @@ -400,61 +403,61 @@ uint32_t BLERemoteCharacteristic::readUInt32() { * @return The value as a byte */ uint8_t BLERemoteCharacteristic::readUInt8() { - String value = readValue(); - if (value.length() >= 1) { - return (uint8_t)value[0]; - } - return 0; -} // readUInt8 + String value = readValue(); + if (value.length() >= 1) { + return (uint8_t)value[0]; + } + return 0; +} // readUInt8 /** * @brief Read a float value. * @return the float value. */ float BLERemoteCharacteristic::readFloat() { - String value = readValue(); - if (value.length() >= 4) { - return *(float*)(value.c_str()); - } - return 0.0; -} // readFloat + String value = readValue(); + if (value.length() >= 4) { + return *(float*)(value.c_str()); + } + return 0.0; +} // readFloat /** * @brief Read the value of the remote characteristic. * @return The value of the remote characteristic. */ String BLERemoteCharacteristic::readValue() { - log_v(">> readValue(): uuid: %s, handle: %d 0x%.2x", getUUID().toString().c_str(), getHandle(), getHandle()); + log_v(">> readValue(): uuid: %s, handle: %d 0x%.2x", getUUID().toString().c_str(), getHandle(), getHandle()); - // Check to see that we are connected. - if (!getRemoteService()->getClient()->isConnected()) { - log_e("Disconnected"); - return String(); - } + // Check to see that we are connected. + if (!getRemoteService()->getClient()->isConnected()) { + log_e("Disconnected"); + return String(); + } - m_semaphoreReadCharEvt.take("readValue"); + m_semaphoreReadCharEvt.take("readValue"); - // Ask the BLE subsystem to retrieve the value for the remote hosted characteristic. - // This is an asynchronous request which means that we must block waiting for the response - // to become available. - esp_err_t errRc = ::esp_ble_gattc_read_char( - m_pRemoteService->getClient()->getGattcIf(), - m_pRemoteService->getClient()->getConnId(), // The connection ID to the BLE server - getHandle(), // The handle of this characteristic - m_auth); // Security + // Ask the BLE subsystem to retrieve the value for the remote hosted characteristic. + // This is an asynchronous request which means that we must block waiting for the response + // to become available. + esp_err_t errRc = ::esp_ble_gattc_read_char( + m_pRemoteService->getClient()->getGattcIf(), + m_pRemoteService->getClient()->getConnId(), // The connection ID to the BLE server + getHandle(), // The handle of this characteristic + m_auth); // Security - if (errRc != ESP_OK) { - log_e("esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return ""; - } + if (errRc != ESP_OK) { + log_e("esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return ""; + } - // Block waiting for the event that indicates that the read has completed. When it has, the String found - // in m_value will contain our data. - m_semaphoreReadCharEvt.wait("readValue"); + // Block waiting for the event that indicates that the read has completed. When it has, the String found + // in m_value will contain our data. + m_semaphoreReadCharEvt.wait("readValue"); - log_v("<< readValue(): length: %d", m_value.length()); - return m_value; -} // readValue + log_v("<< readValue(): length: %d", m_value.length()); + return m_value; +} // readValue /** @@ -464,66 +467,64 @@ String BLERemoteCharacteristic::readValue() { * @return N/A. */ void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback, bool notifications, bool descriptorRequiresRegistration) { - log_v(">> registerForNotify(): %s", toString().c_str()); + log_v(">> registerForNotify(): %s", toString().c_str()); - m_notifyCallback = notifyCallback; // Save the notification callback. + m_notifyCallback = notifyCallback; // Save the notification callback. - m_semaphoreRegForNotifyEvt.take("registerForNotify"); + m_semaphoreRegForNotifyEvt.take("registerForNotify"); - if (notifyCallback != nullptr) { // If we have a callback function, then this is a registration. - esp_err_t errRc = ::esp_ble_gattc_register_for_notify( - m_pRemoteService->getClient()->getGattcIf(), - *m_pRemoteService->getClient()->getPeerAddress().getNative(), - getHandle() - ); + if (notifyCallback != nullptr) { // If we have a callback function, then this is a registration. + esp_err_t errRc = ::esp_ble_gattc_register_for_notify( + m_pRemoteService->getClient()->getGattcIf(), + *m_pRemoteService->getClient()->getPeerAddress().getNative(), + getHandle()); - if (errRc != ESP_OK) { - log_e("esp_ble_gattc_register_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - } + if (errRc != ESP_OK) { + log_e("esp_ble_gattc_register_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + } - uint8_t val[] = {0x01, 0x00}; - if(!notifications) val[0] = 0x02; - BLERemoteDescriptor* desc = getDescriptor(BLEUUID((uint16_t)0x2902)); - if (desc != nullptr && descriptorRequiresRegistration) - desc->writeValue(val, 2, true); - } // End Register - else { // If we weren't passed a callback function, then this is an unregistration. - esp_err_t errRc = ::esp_ble_gattc_unregister_for_notify( - m_pRemoteService->getClient()->getGattcIf(), - *m_pRemoteService->getClient()->getPeerAddress().getNative(), - getHandle() - ); + uint8_t val[] = { 0x01, 0x00 }; + if (!notifications) val[0] = 0x02; + BLERemoteDescriptor* desc = getDescriptor(BLEUUID((uint16_t)0x2902)); + if (desc != nullptr && descriptorRequiresRegistration) + desc->writeValue(val, 2, true); + } // End Register + else { // If we weren't passed a callback function, then this is an unregistration. + esp_err_t errRc = ::esp_ble_gattc_unregister_for_notify( + m_pRemoteService->getClient()->getGattcIf(), + *m_pRemoteService->getClient()->getPeerAddress().getNative(), + getHandle()); - if (errRc != ESP_OK) { - log_e("esp_ble_gattc_unregister_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - } + if (errRc != ESP_OK) { + log_e("esp_ble_gattc_unregister_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + } - uint8_t val[] = {0x00, 0x00}; - BLERemoteDescriptor* desc = getDescriptor((uint16_t)0x2902); - if (desc != nullptr && descriptorRequiresRegistration) - desc->writeValue(val, 2, true); - } // End Unregister + uint8_t val[] = { 0x00, 0x00 }; + BLERemoteDescriptor* desc = getDescriptor((uint16_t)0x2902); + if (desc != nullptr && descriptorRequiresRegistration) + desc->writeValue(val, 2, true); + } // End Unregister - m_semaphoreRegForNotifyEvt.wait("registerForNotify"); + m_semaphoreRegForNotifyEvt.wait("registerForNotify"); - log_v("<< registerForNotify()"); -} // registerForNotify + log_v("<< registerForNotify()"); +} // registerForNotify /** * @brief Delete the descriptors in the descriptor map. * We maintain a map called m_descriptorMap that contains pointers to BLERemoteDescriptors - * object references. Since we allocated these in this class, we are also responsible for deleteing + * object references. Since we allocated these in this class, we are also responsible for deleting * them. This method does just that. * @return N/A. */ void BLERemoteCharacteristic::removeDescriptors() { - // Iterate through all the descriptors releasing their storage and erasing them from the map. - for (auto &myPair : m_descriptorMap) { - delete myPair.second; - } - m_descriptorMap.clear(); -} // removeCharacteristics + // Iterate through all the descriptors releasing their storage and erasing them from the map. + for (auto& myPair : m_descriptorMap) { + delete myPair.second; + } + m_descriptorMap.clear(); +} // removeCharacteristics /** @@ -531,17 +532,17 @@ void BLERemoteCharacteristic::removeDescriptors() { * @return a String representation. */ String BLERemoteCharacteristic::toString() { - String res = "Characteristic: uuid: " + m_uuid.toString(); - char val[6]; - res += ", handle: "; - snprintf(val, sizeof(val), "%d", getHandle()); - res += val; - res += " 0x"; - snprintf(val, sizeof(val), "%04x", getHandle()); - res += val; - res += ", props: " + BLEUtils::characteristicPropertiesToString(m_charProp); - return res; -} // toString + String res = "Characteristic: uuid: " + m_uuid.toString(); + char val[6]; + res += ", handle: "; + snprintf(val, sizeof(val), "%d", getHandle()); + res += val; + res += " 0x"; + snprintf(val, sizeof(val), "%04x", getHandle()); + res += val; + res += ", props: " + BLEUtils::characteristicPropertiesToString(m_charProp); + return res; +} // toString /** @@ -551,8 +552,8 @@ String BLERemoteCharacteristic::toString() { * @return N/A. */ void BLERemoteCharacteristic::writeValue(String newValue, bool response) { - writeValue((uint8_t*)newValue.c_str(), newValue.length(), response); -} // writeValue + writeValue((uint8_t*)newValue.c_str(), newValue.length(), response); +} // writeValue /** @@ -564,8 +565,8 @@ void BLERemoteCharacteristic::writeValue(String newValue, bool response) { * @return N/A. */ void BLERemoteCharacteristic::writeValue(uint8_t newValue, bool response) { - writeValue(&newValue, 1, response); -} // writeValue + writeValue(&newValue, 1, response); +} // writeValue /** @@ -575,43 +576,42 @@ void BLERemoteCharacteristic::writeValue(uint8_t newValue, bool response) { * @param [in] response Whether we require a response from the write. */ void BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool response) { - // writeValue(String((char*)data, length), response); - log_v(">> writeValue(), length: %d", length); - - // Check to see that we are connected. - if (!getRemoteService()->getClient()->isConnected()) { - log_e("Disconnected"); - return; - } - - m_semaphoreWriteCharEvt.take("writeValue"); - // Invoke the ESP-IDF API to perform the write. - esp_err_t errRc = ::esp_ble_gattc_write_char( - m_pRemoteService->getClient()->getGattcIf(), - m_pRemoteService->getClient()->getConnId(), - getHandle(), - length, - data, - response?ESP_GATT_WRITE_TYPE_RSP:ESP_GATT_WRITE_TYPE_NO_RSP, - m_auth - ); - - if (errRc != ESP_OK) { - log_e("esp_ble_gattc_write_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } - - m_semaphoreWriteCharEvt.wait("writeValue"); - - log_v("<< writeValue"); -} // writeValue + // writeValue(String((char*)data, length), response); + log_v(">> writeValue(), length: %d", length); + + // Check to see that we are connected. + if (!getRemoteService()->getClient()->isConnected()) { + log_e("Disconnected"); + return; + } + + m_semaphoreWriteCharEvt.take("writeValue"); + // Invoke the ESP-IDF API to perform the write. + esp_err_t errRc = ::esp_ble_gattc_write_char( + m_pRemoteService->getClient()->getGattcIf(), + m_pRemoteService->getClient()->getConnId(), + getHandle(), + length, + data, + response ? ESP_GATT_WRITE_TYPE_RSP : ESP_GATT_WRITE_TYPE_NO_RSP, + m_auth); + + if (errRc != ESP_OK) { + log_e("esp_ble_gattc_write_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } + + m_semaphoreWriteCharEvt.wait("writeValue"); + + log_v("<< writeValue"); +} // writeValue /** * @brief Read raw data from remote characteristic as hex bytes * @return return pointer data read */ uint8_t* BLERemoteCharacteristic::readRawData() { - return m_rawData; + return m_rawData; } /** @@ -619,7 +619,7 @@ uint8_t* BLERemoteCharacteristic::readRawData() { * @param [in] auth Authentication request type. */ void BLERemoteCharacteristic::setAuth(esp_gatt_auth_req_t auth) { - m_auth = auth; + m_auth = auth; } #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLERemoteCharacteristic.h b/libraries/BLE/src/BLERemoteCharacteristic.h index 1ba4ec3c04d..086bb2aab8a 100644 --- a/libraries/BLE/src/BLERemoteCharacteristic.h +++ b/libraries/BLE/src/BLERemoteCharacteristic.h @@ -29,61 +29,61 @@ typedef std::function* getDescriptors(); - BLERemoteService* getRemoteService(); - uint16_t getHandle(); - BLEUUID getUUID(); - String readValue(); - uint8_t readUInt8(); - uint16_t readUInt16(); - uint32_t readUInt32(); - float readFloat(); - void registerForNotify(notify_callback _callback, bool notifications = true, bool descriptorRequiresRegistration = true); - void writeValue(uint8_t* data, size_t length, bool response = false); - void writeValue(String newValue, bool response = false); - void writeValue(uint8_t newValue, bool response = false); - String toString(); - uint8_t* readRawData(); - void setAuth(esp_gatt_auth_req_t auth); + // Public member functions + bool canBroadcast(); + bool canIndicate(); + bool canNotify(); + bool canRead(); + bool canWrite(); + bool canWriteNoResponse(); + BLERemoteDescriptor* getDescriptor(BLEUUID uuid); + std::map* getDescriptors(); + BLERemoteService* getRemoteService(); + uint16_t getHandle(); + BLEUUID getUUID(); + String readValue(); + uint8_t readUInt8(); + uint16_t readUInt16(); + uint32_t readUInt32(); + float readFloat(); + void registerForNotify(notify_callback _callback, bool notifications = true, bool descriptorRequiresRegistration = true); + void writeValue(uint8_t* data, size_t length, bool response = false); + void writeValue(String newValue, bool response = false); + void writeValue(uint8_t newValue, bool response = false); + String toString(); + uint8_t* readRawData(); + void setAuth(esp_gatt_auth_req_t auth); private: - BLERemoteCharacteristic(uint16_t handle, BLEUUID uuid, esp_gatt_char_prop_t charProp, BLERemoteService* pRemoteService); - friend class BLEClient; - friend class BLERemoteService; - friend class BLERemoteDescriptor; + BLERemoteCharacteristic(uint16_t handle, BLEUUID uuid, esp_gatt_char_prop_t charProp, BLERemoteService* pRemoteService); + friend class BLEClient; + friend class BLERemoteService; + friend class BLERemoteDescriptor; - // Private member functions - void gattClientEventHandler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* evtParam); + // Private member functions + void gattClientEventHandler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* evtParam); - void removeDescriptors(); - void retrieveDescriptors(); + void removeDescriptors(); + void retrieveDescriptors(); - // Private properties - BLEUUID m_uuid; - esp_gatt_char_prop_t m_charProp; - esp_gatt_auth_req_t m_auth; - uint16_t m_handle; - BLERemoteService* m_pRemoteService; - FreeRTOS::Semaphore m_semaphoreReadCharEvt = FreeRTOS::Semaphore("ReadCharEvt"); - FreeRTOS::Semaphore m_semaphoreRegForNotifyEvt = FreeRTOS::Semaphore("RegForNotifyEvt"); - FreeRTOS::Semaphore m_semaphoreWriteCharEvt = FreeRTOS::Semaphore("WriteCharEvt"); - String m_value; - uint8_t *m_rawData; - notify_callback m_notifyCallback; + // Private properties + BLEUUID m_uuid; + esp_gatt_char_prop_t m_charProp; + esp_gatt_auth_req_t m_auth; + uint16_t m_handle; + BLERemoteService* m_pRemoteService; + FreeRTOS::Semaphore m_semaphoreReadCharEvt = FreeRTOS::Semaphore("ReadCharEvt"); + FreeRTOS::Semaphore m_semaphoreRegForNotifyEvt = FreeRTOS::Semaphore("RegForNotifyEvt"); + FreeRTOS::Semaphore m_semaphoreWriteCharEvt = FreeRTOS::Semaphore("WriteCharEvt"); + String m_value; + uint8_t* m_rawData; + notify_callback m_notifyCallback; - // We maintain a map of descriptors owned by this characteristic keyed by a string representation of the UUID. - std::map m_descriptorMap; -}; // BLERemoteCharacteristic + // We maintain a map of descriptors owned by this characteristic keyed by a string representation of the UUID. + std::map m_descriptorMap; +}; // BLERemoteCharacteristic #endif /* CONFIG_BLUEDROID_ENABLED */ #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLERemoteDescriptor.cpp b/libraries/BLE/src/BLERemoteDescriptor.cpp index 92554e328e8..a67694e7147 100644 --- a/libraries/BLE/src/BLERemoteDescriptor.cpp +++ b/libraries/BLE/src/BLERemoteDescriptor.cpp @@ -15,14 +15,14 @@ #include "esp32-hal-log.h" BLERemoteDescriptor::BLERemoteDescriptor( - uint16_t handle, - BLEUUID uuid, + uint16_t handle, + BLEUUID uuid, BLERemoteCharacteristic* pRemoteCharacteristic) { - m_handle = handle; - m_uuid = uuid; + m_handle = handle; + m_uuid = uuid; m_pRemoteCharacteristic = pRemoteCharacteristic; - m_auth = ESP_GATT_AUTH_REQ_NONE; + m_auth = ESP_GATT_AUTH_REQ_NONE; } @@ -32,7 +32,7 @@ BLERemoteDescriptor::BLERemoteDescriptor( */ uint16_t BLERemoteDescriptor::getHandle() { return m_handle; -} // getHandle +} // getHandle /** @@ -41,7 +41,7 @@ uint16_t BLERemoteDescriptor::getHandle() { */ BLERemoteCharacteristic* BLERemoteDescriptor::getRemoteCharacteristic() { return m_pRemoteCharacteristic; -} // getRemoteCharacteristic +} // getRemoteCharacteristic /** @@ -50,10 +50,10 @@ BLERemoteCharacteristic* BLERemoteDescriptor::getRemoteCharacteristic() { */ BLEUUID BLERemoteDescriptor::getUUID() { return m_uuid; -} // getUUID +} // getUUID void BLERemoteDescriptor::gattClientEventHandler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* evtParam) { - switch(event) { + switch (event) { // ESP_GATTC_READ_DESCR_EVT // This event indicates that the server has responded to the read request. // @@ -69,7 +69,7 @@ void BLERemoteDescriptor::gattClientEventHandler(esp_gattc_cb_event_t event, esp // At this point, we have determined that the event is for us, so now we save the value if (evtParam->read.status == ESP_GATT_OK) { // it will read the cached value of the descriptor - m_value = String((char*) evtParam->read.value, evtParam->read.value_len); + m_value = String((char*)evtParam->read.value, evtParam->read.value_len); } else { m_value = ""; } @@ -101,9 +101,9 @@ String BLERemoteDescriptor::readValue() { // Ask the BLE subsystem to retrieve the value for the remote hosted characteristic. esp_err_t errRc = ::esp_ble_gattc_read_char_descr( m_pRemoteCharacteristic->getRemoteService()->getClient()->getGattcIf(), - m_pRemoteCharacteristic->getRemoteService()->getClient()->getConnId(), // The connection ID to the BLE server - getHandle(), // The handle of this characteristic - m_auth); // Security + m_pRemoteCharacteristic->getRemoteService()->getClient()->getConnId(), // The connection ID to the BLE server + getHandle(), // The handle of this characteristic + m_auth); // Security if (errRc != ESP_OK) { log_e("esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); @@ -116,39 +116,39 @@ String BLERemoteDescriptor::readValue() { log_v("<< readValue(): length: %d", m_value.length()); return m_value; -} // readValue +} // readValue uint8_t BLERemoteDescriptor::readUInt8() { String value = readValue(); if (value.length() >= 1) { - return (uint8_t) value[0]; + return (uint8_t)value[0]; } return 0; -} // readUInt8 +} // readUInt8 uint16_t BLERemoteDescriptor::readUInt16() { String value = readValue(); if (value.length() >= 2) { - return *(uint16_t*) value.c_str(); + return *(uint16_t*)value.c_str(); } return 0; -} // readUInt16 +} // readUInt16 uint32_t BLERemoteDescriptor::readUInt32() { String value = readValue(); if (value.length() >= 4) { - return *(uint32_t*) value.c_str(); + return *(uint32_t*)value.c_str(); } return 0; -} // readUInt32 +} // readUInt32 /** * @brief Return a string representation of this BLE Remote Descriptor. - * @retun A string representation of this BLE Remote Descriptor. + * @return A string representation of this BLE Remote Descriptor. */ String BLERemoteDescriptor::toString() { char val[6]; @@ -157,7 +157,7 @@ String BLERemoteDescriptor::toString() { res += val; res += ", uuid: " + getUUID().toString(); return res; -} // toString +} // toString /** @@ -180,18 +180,17 @@ void BLERemoteDescriptor::writeValue(uint8_t* data, size_t length, bool response m_pRemoteCharacteristic->getRemoteService()->getClient()->getGattcIf(), m_pRemoteCharacteristic->getRemoteService()->getClient()->getConnId(), getHandle(), - length, // Data length - data, // Data + length, // Data length + data, // Data response ? ESP_GATT_WRITE_TYPE_RSP : ESP_GATT_WRITE_TYPE_NO_RSP, - m_auth - ); + m_auth); if (errRc != ESP_OK) { log_e("esp_ble_gattc_write_char_descr: %d", errRc); } m_semaphoreWriteDescrEvt.wait("writeValue"); log_v("<< writeValue"); -} // writeValue +} // writeValue /** @@ -200,8 +199,8 @@ void BLERemoteDescriptor::writeValue(uint8_t* data, size_t length, bool response * @param [in] response True if we expect a response. */ void BLERemoteDescriptor::writeValue(String newValue, bool response) { - writeValue((uint8_t*) newValue.c_str(), newValue.length(), response); -} // writeValue + writeValue((uint8_t*)newValue.c_str(), newValue.length(), response); +} // writeValue /** @@ -211,14 +210,14 @@ void BLERemoteDescriptor::writeValue(String newValue, bool response) { */ void BLERemoteDescriptor::writeValue(uint8_t newValue, bool response) { writeValue(&newValue, 1, response); -} // writeValue +} // writeValue /** * @brief Set authentication request type for characteristic * @param [in] auth Authentication request type. */ void BLERemoteDescriptor::setAuth(esp_gatt_auth_req_t auth) { - m_auth = auth; + m_auth = auth; } #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLERemoteDescriptor.h b/libraries/BLE/src/BLERemoteDescriptor.h index 5b9cb355595..be23431a416 100644 --- a/libraries/BLE/src/BLERemoteDescriptor.h +++ b/libraries/BLE/src/BLERemoteDescriptor.h @@ -26,36 +26,33 @@ class BLERemoteCharacteristic; */ class BLERemoteDescriptor { public: - uint16_t getHandle(); + uint16_t getHandle(); BLERemoteCharacteristic* getRemoteCharacteristic(); - BLEUUID getUUID(); + BLEUUID getUUID(); String readValue(void); - uint8_t readUInt8(void); - uint16_t readUInt16(void); - uint32_t readUInt32(void); + uint8_t readUInt8(void); + uint16_t readUInt16(void); + uint32_t readUInt32(void); String toString(void); - void writeValue(uint8_t* data, size_t length, bool response = false); - void writeValue(String newValue, bool response = false); - void writeValue(uint8_t newValue, bool response = false); - void setAuth(esp_gatt_auth_req_t auth); - void gattClientEventHandler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* evtParam); + void writeValue(uint8_t* data, size_t length, bool response = false); + void writeValue(String newValue, bool response = false); + void writeValue(uint8_t newValue, bool response = false); + void setAuth(esp_gatt_auth_req_t auth); + void gattClientEventHandler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* evtParam); private: friend class BLERemoteCharacteristic; BLERemoteDescriptor( - uint16_t handle, - BLEUUID uuid, - BLERemoteCharacteristic* pRemoteCharacteristic - ); - uint16_t m_handle; // Server handle of this descriptor. - BLEUUID m_uuid; // UUID of this descriptor. - String m_value; // Last received value of the descriptor. - BLERemoteCharacteristic* m_pRemoteCharacteristic; // Reference to the Remote characteristic of which this descriptor is associated. - FreeRTOS::Semaphore m_semaphoreReadDescrEvt = FreeRTOS::Semaphore("ReadDescrEvt"); - FreeRTOS::Semaphore m_semaphoreWriteDescrEvt = FreeRTOS::Semaphore("WriteDescrEvt"); - esp_gatt_auth_req_t m_auth; - - + uint16_t handle, + BLEUUID uuid, + BLERemoteCharacteristic* pRemoteCharacteristic); + uint16_t m_handle; // Server handle of this descriptor. + BLEUUID m_uuid; // UUID of this descriptor. + String m_value; // Last received value of the descriptor. + BLERemoteCharacteristic* m_pRemoteCharacteristic; // Reference to the Remote characteristic of which this descriptor is associated. + FreeRTOS::Semaphore m_semaphoreReadDescrEvt = FreeRTOS::Semaphore("ReadDescrEvt"); + FreeRTOS::Semaphore m_semaphoreWriteDescrEvt = FreeRTOS::Semaphore("WriteDescrEvt"); + esp_gatt_auth_req_t m_auth; }; #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLERemoteService.cpp b/libraries/BLE/src/BLERemoteService.cpp index 874687748ba..dfe6f2acafc 100644 --- a/libraries/BLE/src/BLERemoteService.cpp +++ b/libraries/BLE/src/BLERemoteService.cpp @@ -20,16 +20,15 @@ #pragma GCC diagnostic warning "-Wunused-but-set-parameter" BLERemoteService::BLERemoteService( - esp_gatt_id_t srvcId, - BLEClient* pClient, - uint16_t startHandle, - uint16_t endHandle - ) { + esp_gatt_id_t srvcId, + BLEClient* pClient, + uint16_t startHandle, + uint16_t endHandle) { log_v(">> BLERemoteService()"); - m_srvcId = srvcId; + m_srvcId = srvcId; m_pClient = pClient; - m_uuid = BLEUUID(m_srvcId); + m_uuid = BLEUUID(m_srvcId); m_haveCharacteristics = false; m_startHandle = startHandle; m_endHandle = endHandle; @@ -58,21 +57,21 @@ static bool compareSrvcId(esp_gatt_srvc_id_t id1, esp_gatt_srvc_id_t id2) { * @brief Handle GATT Client events */ void BLERemoteService::gattClientEventHandler( - esp_gattc_cb_event_t event, - esp_gatt_if_t gattc_if, + esp_gattc_cb_event_t event, + esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* evtParam) { switch (event) { - // - // ESP_GATTC_GET_CHAR_EVT - // - // get_char: - // - esp_gatt_status_t status - // - uin1t6_t conn_id - // - esp_gatt_srvc_id_t srvc_id - // - esp_gatt_id_t char_id - // - esp_gatt_char_prop_t char_prop - // - /* + // + // ESP_GATTC_GET_CHAR_EVT + // + // get_char: + // - esp_gatt_status_t status + // - uin1t6_t conn_id + // - esp_gatt_srvc_id_t srvc_id + // - esp_gatt_id_t char_id + // - esp_gatt_char_prop_t char_prop + // + /* case ESP_GATTC_GET_CHAR_EVT: { // Is this event for this service? If yes, then the local srvc_id and the event srvc_id will be // the same. @@ -110,13 +109,13 @@ void BLERemoteService::gattClientEventHandler( */ default: break; - } // switch + } // switch // Send the event to each of the characteristics owned by this service. - for (auto &myPair : m_characteristicMapByHandle) { - myPair.second->gattClientEventHandler(event, gattc_if, evtParam); + for (auto& myPair : m_characteristicMapByHandle) { + myPair.second->gattClientEventHandler(event, gattc_if, evtParam); } -} // gattClientEventHandler +} // gattClientEventHandler /** @@ -126,8 +125,8 @@ void BLERemoteService::gattClientEventHandler( * @throws BLEUuidNotFoundException */ BLERemoteCharacteristic* BLERemoteService::getCharacteristic(const char* uuid) { - return getCharacteristic(BLEUUID(uuid)); -} // getCharacteristic + return getCharacteristic(BLEUUID(uuid)); +} // getCharacteristic /** * @brief Get the characteristic object for the UUID. @@ -136,24 +135,24 @@ BLERemoteCharacteristic* BLERemoteService::getCharacteristic(const char* uuid) { * @throws BLEUuidNotFoundException */ BLERemoteCharacteristic* BLERemoteService::getCharacteristic(BLEUUID uuid) { -// Design -// ------ -// We wish to retrieve the characteristic given its UUID. It is possible that we have not yet asked the -// device what characteristics it has in which case we have nothing to match against. If we have not -// asked the device about its characteristics, then we do that now. Once we get the results we can then -// examine the characteristics map to see if it has the characteristic we are looking for. + // Design + // ------ + // We wish to retrieve the characteristic given its UUID. It is possible that we have not yet asked the + // device what characteristics it has in which case we have nothing to match against. If we have not + // asked the device about its characteristics, then we do that now. Once we get the results we can then + // examine the characteristics map to see if it has the characteristic we are looking for. if (!m_haveCharacteristics) { retrieveCharacteristics(); } String v = uuid.toString(); - for (auto &myPair : m_characteristicMap) { + for (auto& myPair : m_characteristicMap) { if (myPair.first == v) { return myPair.second; } } // throw new BLEUuidNotFoundException(); // <-- we dont want exception here, which will cause app crash, we want to search if any characteristic can be found one after another return nullptr; -} // getCharacteristic +} // getCharacteristic /** @@ -164,12 +163,12 @@ BLERemoteCharacteristic* BLERemoteService::getCharacteristic(BLEUUID uuid) { void BLERemoteService::retrieveCharacteristics() { log_v(">> getCharacteristics() for service: %s", getUUID().toString().c_str()); - removeCharacteristics(); // Forget any previous characteristics. + removeCharacteristics(); // Forget any previous characteristics. uint16_t offset = 0; esp_gattc_char_elem_t result; while (true) { - uint16_t count = 1; // only room for 1 result allocated, so go one by one + uint16_t count = 1; // only room for 1 result allocated, so go one by one esp_gatt_status_t status = ::esp_ble_gattc_get_all_char( getClient()->getGattcIf(), getClient()->getConnId(), @@ -177,40 +176,38 @@ void BLERemoteService::retrieveCharacteristics() { m_endHandle, &result, &count, - offset - ); + offset); - if (status == ESP_GATT_INVALID_OFFSET) { // We have reached the end of the entries. + if (status == ESP_GATT_INVALID_OFFSET) { // We have reached the end of the entries. break; } - if (status != ESP_GATT_OK) { // If we got an error, end. + if (status != ESP_GATT_OK) { // If we got an error, end. log_e("esp_ble_gattc_get_all_char: %s", BLEUtils::gattStatusToString(status).c_str()); break; } - if (count == 0) { // If we failed to get any new records, end. + if (count == 0) { // If we failed to get any new records, end. break; } log_d("Found a characteristic: Handle: %d, UUID: %s", result.char_handle, BLEUUID(result.uuid).toString().c_str()); // We now have a new characteristic ... let us add that to our set of known characteristics - BLERemoteCharacteristic *pNewRemoteCharacteristic = new BLERemoteCharacteristic( + BLERemoteCharacteristic* pNewRemoteCharacteristic = new BLERemoteCharacteristic( result.char_handle, BLEUUID(result.uuid), result.properties, - this - ); + this); m_characteristicMap.insert(std::pair(pNewRemoteCharacteristic->getUUID().toString(), pNewRemoteCharacteristic)); m_characteristicMapByHandle.insert(std::pair(result.char_handle, pNewRemoteCharacteristic)); - offset++; // Increment our count of number of descriptors found. - } // Loop forever (until we break inside the loop). + offset++; // Increment our count of number of descriptors found. + } // Loop forever (until we break inside the loop). - m_haveCharacteristics = true; // Remember that we have received the characteristics. + m_haveCharacteristics = true; // Remember that we have received the characteristics. log_v("<< getCharacteristics()"); -} // getCharacteristics +} // getCharacteristics /** @@ -227,7 +224,7 @@ std::map* BLERemoteService::getCharacteristics } log_v("<< getCharacteristics() for service: %s", getUUID().toString().c_str()); return &m_characteristicMap; -} // getCharacteristics +} // getCharacteristics /** * @brief Retrieve a map of all the characteristics of this service. @@ -241,7 +238,7 @@ std::map* BLERemoteService::getCharacteristi retrieveCharacteristics(); } return &m_characteristicMapByHandle; -} // getCharacteristicsByHandle +} // getCharacteristicsByHandle /** * @brief This function is designed to get characteristics map when we have multiple characteristics with the same UUID @@ -265,29 +262,29 @@ void BLERemoteService::getCharacteristics(std::map> getHandle: service: %s", getUUID().toString().c_str()); log_v("<< getHandle: %d 0x%.2x", getStartHandle(), getStartHandle()); return getStartHandle(); -} // getHandle +} // getHandle BLEUUID BLERemoteService::getUUID() { @@ -299,28 +296,28 @@ BLEUUID BLERemoteService::getUUID() { */ String BLERemoteService::getValue(BLEUUID characteristicUuid) { log_v(">> readValue: uuid: %s", characteristicUuid.toString().c_str()); - String ret = getCharacteristic(characteristicUuid)->readValue(); + String ret = getCharacteristic(characteristicUuid)->readValue(); log_v("<< readValue"); return ret; -} // readValue +} // readValue /** * @brief Delete the characteristics in the characteristics map. * We maintain a map called m_characteristicsMap that contains pointers to BLERemoteCharacteristic - * object references. Since we allocated these in this class, we are also responsible for deleteing + * object references. Since we allocated these in this class, we are also responsible for deleting * them. This method does just that. * @return N/A. */ void BLERemoteService::removeCharacteristics() { - m_characteristicMap.clear(); // Clear the map - for (auto &myPair : m_characteristicMapByHandle) { - delete myPair.second; - // delete the characteristics only once + m_characteristicMap.clear(); // Clear the map + for (auto& myPair : m_characteristicMapByHandle) { + delete myPair.second; + // delete the characteristics only once } - m_characteristicMapByHandle.clear(); // Clear the map -} // removeCharacteristics + m_characteristicMapByHandle.clear(); // Clear the map +} // removeCharacteristics /** @@ -333,7 +330,7 @@ void BLERemoteService::setValue(BLEUUID characteristicUuid, String value) { log_v(">> setValue: uuid: %s", characteristicUuid.toString().c_str()); getCharacteristic(characteristicUuid)->writeValue(value); log_v("<< setValue"); -} // setValue +} // setValue /** @@ -355,12 +352,12 @@ String BLERemoteService::toString() { snprintf(val, sizeof(val), "%04x", m_endHandle); res += " 0x"; res += val; - for (auto &myPair : m_characteristicMap) { + for (auto& myPair : m_characteristicMap) { res += "\n" + myPair.second->toString(); - // myPair.second is the value + // myPair.second is the value } return res; -} // toString +} // toString #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLERemoteService.h b/libraries/BLE/src/BLERemoteService.h index 6907260ea31..dd55b0a0349 100644 --- a/libraries/BLE/src/BLERemoteService.h +++ b/libraries/BLE/src/BLERemoteService.h @@ -29,60 +29,60 @@ class BLERemoteCharacteristic; */ class BLERemoteService { public: - virtual ~BLERemoteService(); - - // Public methods - BLERemoteCharacteristic* getCharacteristic(const char* uuid); // Get the specified characteristic reference. - BLERemoteCharacteristic* getCharacteristic(BLEUUID uuid); // Get the specified characteristic reference. - BLERemoteCharacteristic* getCharacteristic(uint16_t uuid); // Get the specified characteristic reference. - std::map* getCharacteristics(); - std::map* getCharacteristicsByHandle(); // Get the characteristics map. - void getCharacteristics(std::map** pCharacteristicMap); - - BLEClient* getClient(void); // Get a reference to the client associated with this service. - uint16_t getHandle(); // Get the handle of this service. - BLEUUID getUUID(void); // Get the UUID of this service. - String getValue(BLEUUID characteristicUuid); // Get the value of a characteristic. - void setValue(BLEUUID characteristicUuid, String value); // Set the value of a characteristic. - String toString(void); + virtual ~BLERemoteService(); + + // Public methods + BLERemoteCharacteristic* getCharacteristic(const char* uuid); // Get the specified characteristic reference. + BLERemoteCharacteristic* getCharacteristic(BLEUUID uuid); // Get the specified characteristic reference. + BLERemoteCharacteristic* getCharacteristic(uint16_t uuid); // Get the specified characteristic reference. + std::map* getCharacteristics(); + std::map* getCharacteristicsByHandle(); // Get the characteristics map. + void getCharacteristics(std::map** pCharacteristicMap); + + BLEClient* getClient(void); // Get a reference to the client associated with this service. + uint16_t getHandle(); // Get the handle of this service. + BLEUUID getUUID(void); // Get the UUID of this service. + String getValue(BLEUUID characteristicUuid); // Get the value of a characteristic. + void setValue(BLEUUID characteristicUuid, String value); // Set the value of a characteristic. + String toString(void); private: - // Private constructor ... never meant to be created by a user application. - BLERemoteService(esp_gatt_id_t srvcId, BLEClient* pClient, uint16_t startHandle, uint16_t endHandle); - - // Friends - friend class BLEClient; - friend class BLERemoteCharacteristic; - - // Private methods - void retrieveCharacteristics(void); // Retrieve the characteristics from the BLE Server. - esp_gatt_id_t* getSrvcId(void); - uint16_t getStartHandle(); // Get the start handle for this service. - uint16_t getEndHandle(); // Get the end handle for this service. - - void gattClientEventHandler( - esp_gattc_cb_event_t event, - esp_gatt_if_t gattc_if, - esp_ble_gattc_cb_param_t* evtParam); - - void removeCharacteristics(); - - // Properties - - // We maintain a map of characteristics owned by this service keyed by a string representation of the UUID. - std::map m_characteristicMap; - - // We maintain a map of characteristics owned by this service keyed by a handle. - std::map m_characteristicMapByHandle; - - bool m_haveCharacteristics; // Have we previously obtained the characteristics. - BLEClient* m_pClient; - FreeRTOS::Semaphore m_semaphoreGetCharEvt = FreeRTOS::Semaphore("GetCharEvt"); - esp_gatt_id_t m_srvcId; - BLEUUID m_uuid; // The UUID of this service. - uint16_t m_startHandle; // The starting handle of this service. - uint16_t m_endHandle; // The ending handle of this service. -}; // BLERemoteService + // Private constructor ... never meant to be created by a user application. + BLERemoteService(esp_gatt_id_t srvcId, BLEClient* pClient, uint16_t startHandle, uint16_t endHandle); + + // Friends + friend class BLEClient; + friend class BLERemoteCharacteristic; + + // Private methods + void retrieveCharacteristics(void); // Retrieve the characteristics from the BLE Server. + esp_gatt_id_t* getSrvcId(void); + uint16_t getStartHandle(); // Get the start handle for this service. + uint16_t getEndHandle(); // Get the end handle for this service. + + void gattClientEventHandler( + esp_gattc_cb_event_t event, + esp_gatt_if_t gattc_if, + esp_ble_gattc_cb_param_t* evtParam); + + void removeCharacteristics(); + + // Properties + + // We maintain a map of characteristics owned by this service keyed by a string representation of the UUID. + std::map m_characteristicMap; + + // We maintain a map of characteristics owned by this service keyed by a handle. + std::map m_characteristicMapByHandle; + + bool m_haveCharacteristics; // Have we previously obtained the characteristics. + BLEClient* m_pClient; + FreeRTOS::Semaphore m_semaphoreGetCharEvt = FreeRTOS::Semaphore("GetCharEvt"); + esp_gatt_id_t m_srvcId; + BLEUUID m_uuid; // The UUID of this service. + uint16_t m_startHandle; // The starting handle of this service. + uint16_t m_endHandle; // The ending handle of this service. +}; // BLERemoteService #endif /* CONFIG_BLUEDROID_ENABLED */ #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLEScan.cpp b/libraries/BLE/src/BLEScan.cpp index 5162d0b1852..1ba0f3a05d9 100644 --- a/libraries/BLE/src/BLEScan.cpp +++ b/libraries/BLE/src/BLEScan.cpp @@ -3,7 +3,7 @@ * * Created on: Jul 1, 2017 * Author: kolban - * + * * Update: April, 2021 * add BLE5 support */ @@ -27,18 +27,18 @@ * Constructor */ BLEScan::BLEScan() { - memset(&m_scan_params, 0, sizeof(m_scan_params)); // Initialize all params - m_scan_params.scan_type = BLE_SCAN_TYPE_PASSIVE; // Default is a passive scan. - m_scan_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC; - m_scan_params.scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL; - m_scan_params.scan_duplicate = BLE_SCAN_DUPLICATE_DISABLE; - m_pAdvertisedDeviceCallbacks = nullptr; - m_stopped = true; - m_wantDuplicates = false; - m_shouldParse = true; - setInterval(100); - setWindow(100); -} // BLEScan + memset(&m_scan_params, 0, sizeof(m_scan_params)); // Initialize all params + m_scan_params.scan_type = BLE_SCAN_TYPE_PASSIVE; // Default is a passive scan. + m_scan_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC; + m_scan_params.scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL; + m_scan_params.scan_duplicate = BLE_SCAN_DUPLICATE_DISABLE; + m_pAdvertisedDeviceCallbacks = nullptr; + m_stopped = true; + m_wantDuplicates = false; + m_shouldParse = true; + setInterval(100); + setWindow(100); +} // BLEScan /** @@ -47,205 +47,203 @@ BLEScan::BLEScan() { * @param [in] param Parameter data for this event. */ void BLEScan::handleGAPEvent( - esp_gap_ble_cb_event_t event, - esp_ble_gap_cb_param_t* param) { - - switch(event) { - - // --------------------------- - // scan_rst: - // esp_gap_search_evt_t search_evt - // esp_bd_addr_t bda - // esp_bt_dev_type_t dev_type - // esp_ble_addr_type_t ble_addr_type - // esp_ble_evt_type_t ble_evt_type - // int rssi - // uint8_t ble_adv[ESP_BLE_ADV_DATA_LEN_MAX] - // int flag - // int num_resps - // uint8_t adv_data_len - // uint8_t scan_rsp_len - case ESP_GAP_BLE_SCAN_RESULT_EVT: { - - switch(param->scan_rst.search_evt) { - // - // ESP_GAP_SEARCH_INQ_CMPL_EVT - // - // Event that indicates that the duration allowed for the search has completed or that we have been - // asked to stop. - case ESP_GAP_SEARCH_INQ_CMPL_EVT: { - log_w("ESP_GAP_SEARCH_INQ_CMPL_EVT"); - m_stopped = true; - m_semaphoreScanEnd.give(); - if (m_scanCompleteCB != nullptr) { - m_scanCompleteCB(m_scanResults); - } - break; - } // ESP_GAP_SEARCH_INQ_CMPL_EVT - - // - // ESP_GAP_SEARCH_INQ_RES_EVT - // - // Result that has arrived back from a Scan inquiry. - case ESP_GAP_SEARCH_INQ_RES_EVT: { - if (m_stopped) { // If we are not scanning, nothing to do with the extra results. - break; - } - -// Examine our list of previously scanned addresses and, if we found this one already, -// ignore it. - BLEAddress advertisedAddress(param->scan_rst.bda); - bool found = false; - bool shouldDelete = true; - - if (!m_wantDuplicates) { - if (m_scanResults.m_vectorAdvertisedDevices.count(advertisedAddress.toString()) != 0) { - found = true; - } - - if (found) { // If we found a previous entry AND we don't want duplicates, then we are done. - log_d("Ignoring %s, already seen it.", advertisedAddress.toString().c_str()); - vTaskDelay(1); // <--- allow to switch task in case we scan infinity and dont have new devices to report, or we are blocked here - break; - } - } - - // We now construct a model of the advertised device that we have just found for the first - // time. - // ESP_LOG_BUFFER_HEXDUMP((uint8_t*)param->scan_rst.ble_adv, param->scan_rst.adv_data_len + param->scan_rst.scan_rsp_len, ESP_LOG_DEBUG); - // log_w("bytes length: %d + %d, addr type: %d", param->scan_rst.adv_data_len, param->scan_rst.scan_rsp_len, param->scan_rst.ble_addr_type); - BLEAdvertisedDevice *advertisedDevice = new BLEAdvertisedDevice(); - advertisedDevice->setAddress(advertisedAddress); - advertisedDevice->setRSSI(param->scan_rst.rssi); - advertisedDevice->setAdFlag(param->scan_rst.flag); - if (m_shouldParse) { - advertisedDevice->parseAdvertisement((uint8_t*)param->scan_rst.ble_adv, param->scan_rst.adv_data_len + param->scan_rst.scan_rsp_len); - } else { - advertisedDevice->setPayload((uint8_t*)param->scan_rst.ble_adv, param->scan_rst.adv_data_len + param->scan_rst.scan_rsp_len); - } - advertisedDevice->setScan(this); - advertisedDevice->setAddressType(param->scan_rst.ble_addr_type); - - if (m_pAdvertisedDeviceCallbacks) { // if has callback, no need to record to vector - m_pAdvertisedDeviceCallbacks->onResult(*advertisedDevice); - } - if (!m_wantDuplicates && !found) { // if no callback and not want duplicate, and not already in vector, record it - m_scanResults.m_vectorAdvertisedDevices.insert(std::pair(advertisedAddress.toString(), advertisedDevice)); - shouldDelete = false; - } - if (shouldDelete) { - delete advertisedDevice; - } - - break; - } // ESP_GAP_SEARCH_INQ_RES_EVT - - default: { - break; - } - } // switch - search_evt - - - break; - } // ESP_GAP_BLE_SCAN_RESULT_EVT + esp_gap_ble_cb_event_t event, + esp_ble_gap_cb_param_t* param) { + + switch (event) { + + // --------------------------- + // scan_rst: + // esp_gap_search_evt_t search_evt + // esp_bd_addr_t bda + // esp_bt_dev_type_t dev_type + // esp_ble_addr_type_t ble_addr_type + // esp_ble_evt_type_t ble_evt_type + // int rssi + // uint8_t ble_adv[ESP_BLE_ADV_DATA_LEN_MAX] + // int flag + // int num_resps + // uint8_t adv_data_len + // uint8_t scan_rsp_len + case ESP_GAP_BLE_SCAN_RESULT_EVT: + { + + switch (param->scan_rst.search_evt) { + // + // ESP_GAP_SEARCH_INQ_CMPL_EVT + // + // Event that indicates that the duration allowed for the search has completed or that we have been + // asked to stop. + case ESP_GAP_SEARCH_INQ_CMPL_EVT: + { + log_w("ESP_GAP_SEARCH_INQ_CMPL_EVT"); + m_stopped = true; + m_semaphoreScanEnd.give(); + if (m_scanCompleteCB != nullptr) { + m_scanCompleteCB(m_scanResults); + } + break; + } // ESP_GAP_SEARCH_INQ_CMPL_EVT + + // + // ESP_GAP_SEARCH_INQ_RES_EVT + // + // Result that has arrived back from a Scan inquiry. + case ESP_GAP_SEARCH_INQ_RES_EVT: + { + if (m_stopped) { // If we are not scanning, nothing to do with the extra results. + break; + } + + // Examine our list of previously scanned addresses and, if we found this one already, + // ignore it. + BLEAddress advertisedAddress(param->scan_rst.bda); + bool found = false; + bool shouldDelete = true; + + if (!m_wantDuplicates) { + if (m_scanResults.m_vectorAdvertisedDevices.count(advertisedAddress.toString()) != 0) { + found = true; + } + + if (found) { // If we found a previous entry AND we don't want duplicates, then we are done. + log_d("Ignoring %s, already seen it.", advertisedAddress.toString().c_str()); + vTaskDelay(1); // <--- allow to switch task in case we scan infinity and dont have new devices to report, or we are blocked here + break; + } + } + + // We now construct a model of the advertised device that we have just found for the first + // time. + // ESP_LOG_BUFFER_HEXDUMP((uint8_t*)param->scan_rst.ble_adv, param->scan_rst.adv_data_len + param->scan_rst.scan_rsp_len, ESP_LOG_DEBUG); + // log_w("bytes length: %d + %d, addr type: %d", param->scan_rst.adv_data_len, param->scan_rst.scan_rsp_len, param->scan_rst.ble_addr_type); + BLEAdvertisedDevice* advertisedDevice = new BLEAdvertisedDevice(); + advertisedDevice->setAddress(advertisedAddress); + advertisedDevice->setRSSI(param->scan_rst.rssi); + advertisedDevice->setAdFlag(param->scan_rst.flag); + if (m_shouldParse) { + advertisedDevice->parseAdvertisement((uint8_t*)param->scan_rst.ble_adv, param->scan_rst.adv_data_len + param->scan_rst.scan_rsp_len); + } else { + advertisedDevice->setPayload((uint8_t*)param->scan_rst.ble_adv, param->scan_rst.adv_data_len + param->scan_rst.scan_rsp_len); + } + advertisedDevice->setScan(this); + advertisedDevice->setAddressType(param->scan_rst.ble_addr_type); + + if (m_pAdvertisedDeviceCallbacks) { // if has callback, no need to record to vector + m_pAdvertisedDeviceCallbacks->onResult(*advertisedDevice); + } + if (!m_wantDuplicates && !found) { // if no callback and not want duplicate, and not already in vector, record it + m_scanResults.m_vectorAdvertisedDevices.insert(std::pair(advertisedAddress.toString(), advertisedDevice)); + shouldDelete = false; + } + if (shouldDelete) { + delete advertisedDevice; + } + + break; + } // ESP_GAP_SEARCH_INQ_RES_EVT + + default: + { + break; + } + } // switch - search_evt + + + break; + } // ESP_GAP_BLE_SCAN_RESULT_EVT #ifdef SOC_BLE_50_SUPPORTED - case ESP_GAP_BLE_EXT_ADV_REPORT_EVT: { - if (param->ext_adv_report.params.event_type & ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY) { - log_v("legacy adv, adv type 0x%x data len %d", param->ext_adv_report.params.event_type, param->ext_adv_report.params.adv_data_len); - } - else { - log_v("extend adv, adv type 0x%x data len %d, data status: %d", param->ext_adv_report.params.event_type, param->ext_adv_report.params.adv_data_len, param->ext_adv_report.params.data_status); - } - - if (m_pExtendedScanCb != nullptr) - { - m_pExtendedScanCb->onResult(param->ext_adv_report.params); - } - - break; - } - - case ESP_GAP_BLE_SET_EXT_SCAN_PARAMS_COMPLETE_EVT: { - if (param->set_ext_scan_params.status != ESP_BT_STATUS_SUCCESS) { - log_e("extend scan parameters set failed, error status = %x", param->set_ext_scan_params.status); - break; - } - log_v("extend scan params set successfully"); - break; - } - - case ESP_GAP_BLE_EXT_SCAN_START_COMPLETE_EVT: - if (param->ext_scan_start.status != ESP_BT_STATUS_SUCCESS) { - log_e("scan start failed, error status = %x", param->scan_start_cmpl.status); - break; - } - log_v("Scan start success"); - break; - - case ESP_GAP_BLE_EXT_SCAN_STOP_COMPLETE_EVT: - if (m_pPeriodicScanCb != nullptr) - { - m_pPeriodicScanCb->onStop(param->ext_scan_stop.status); - } - - if (param->ext_scan_stop.status != ESP_BT_STATUS_SUCCESS){ - log_e("extend Scan stop failed, error status = %x", param->ext_scan_stop.status); - break; - } - log_v("Stop extend scan successfully"); - break; - - case ESP_GAP_BLE_PERIODIC_ADV_CREATE_SYNC_COMPLETE_EVT: - if (m_pPeriodicScanCb != nullptr) - { - m_pPeriodicScanCb->onCreateSync(param->period_adv_create_sync.status); - } - - log_v("ESP_GAP_BLE_PERIODIC_ADV_CREATE_SYNC_COMPLETE_EVT, status %d", param->period_adv_create_sync.status); - break; - case ESP_GAP_BLE_PERIODIC_ADV_SYNC_CANCEL_COMPLETE_EVT: - if (m_pPeriodicScanCb != nullptr) - { - m_pPeriodicScanCb->onCancelSync(param->period_adv_sync_cancel.status); - } - log_v("ESP_GAP_BLE_PERIODIC_ADV_SYNC_CANCEL_COMPLETE_EVT, status %d", param->period_adv_sync_cancel.status); - break; - case ESP_GAP_BLE_PERIODIC_ADV_SYNC_TERMINATE_COMPLETE_EVT: - if (m_pPeriodicScanCb != nullptr) - { - m_pPeriodicScanCb->onTerminateSync(param->period_adv_sync_term.status); - } - log_v("ESP_GAP_BLE_PERIODIC_ADV_SYNC_TERMINATE_COMPLETE_EVT, status %d", param->period_adv_sync_term.status); - break; - case ESP_GAP_BLE_PERIODIC_ADV_SYNC_LOST_EVT: - if (m_pPeriodicScanCb != nullptr) - { - m_pPeriodicScanCb->onLostSync(param->periodic_adv_sync_lost.sync_handle); - } - log_v("ESP_GAP_BLE_PERIODIC_ADV_SYNC_LOST_EVT, sync handle %d", param->periodic_adv_sync_lost.sync_handle); - break; - case ESP_GAP_BLE_PERIODIC_ADV_SYNC_ESTAB_EVT: - if (m_pPeriodicScanCb != nullptr) - { - m_pPeriodicScanCb->onSync(*(esp_ble_periodic_adv_sync_estab_param_t*)¶m->periodic_adv_sync_estab); - } - log_v("ESP_GAP_BLE_PERIODIC_ADV_SYNC_ESTAB_EVT, status %d", param->periodic_adv_sync_estab.status); - break; - - case ESP_GAP_BLE_PERIODIC_ADV_REPORT_EVT: - if (m_pPeriodicScanCb != nullptr) - { - m_pPeriodicScanCb->onReport(param->period_adv_report.params); - } - break; - -#endif // SOC_BLE_50_SUPPORTED - - default: { - break; - } // default - } // End switch -} // gapEventHandler + case ESP_GAP_BLE_EXT_ADV_REPORT_EVT: + { + if (param->ext_adv_report.params.event_type & ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY) { + log_v("legacy adv, adv type 0x%x data len %d", param->ext_adv_report.params.event_type, param->ext_adv_report.params.adv_data_len); + } else { + log_v("extend adv, adv type 0x%x data len %d, data status: %d", param->ext_adv_report.params.event_type, param->ext_adv_report.params.adv_data_len, param->ext_adv_report.params.data_status); + } + + if (m_pExtendedScanCb != nullptr) { + m_pExtendedScanCb->onResult(param->ext_adv_report.params); + } + + break; + } + + case ESP_GAP_BLE_SET_EXT_SCAN_PARAMS_COMPLETE_EVT: + { + if (param->set_ext_scan_params.status != ESP_BT_STATUS_SUCCESS) { + log_e("extend scan parameters set failed, error status = %x", param->set_ext_scan_params.status); + break; + } + log_v("extend scan params set successfully"); + break; + } + + case ESP_GAP_BLE_EXT_SCAN_START_COMPLETE_EVT: + if (param->ext_scan_start.status != ESP_BT_STATUS_SUCCESS) { + log_e("scan start failed, error status = %x", param->scan_start_cmpl.status); + break; + } + log_v("Scan start success"); + break; + + case ESP_GAP_BLE_EXT_SCAN_STOP_COMPLETE_EVT: + if (m_pPeriodicScanCb != nullptr) { + m_pPeriodicScanCb->onStop(param->ext_scan_stop.status); + } + + if (param->ext_scan_stop.status != ESP_BT_STATUS_SUCCESS) { + log_e("extend Scan stop failed, error status = %x", param->ext_scan_stop.status); + break; + } + log_v("Stop extend scan successfully"); + break; + + case ESP_GAP_BLE_PERIODIC_ADV_CREATE_SYNC_COMPLETE_EVT: + if (m_pPeriodicScanCb != nullptr) { + m_pPeriodicScanCb->onCreateSync(param->period_adv_create_sync.status); + } + + log_v("ESP_GAP_BLE_PERIODIC_ADV_CREATE_SYNC_COMPLETE_EVT, status %d", param->period_adv_create_sync.status); + break; + case ESP_GAP_BLE_PERIODIC_ADV_SYNC_CANCEL_COMPLETE_EVT: + if (m_pPeriodicScanCb != nullptr) { + m_pPeriodicScanCb->onCancelSync(param->period_adv_sync_cancel.status); + } + log_v("ESP_GAP_BLE_PERIODIC_ADV_SYNC_CANCEL_COMPLETE_EVT, status %d", param->period_adv_sync_cancel.status); + break; + case ESP_GAP_BLE_PERIODIC_ADV_SYNC_TERMINATE_COMPLETE_EVT: + if (m_pPeriodicScanCb != nullptr) { + m_pPeriodicScanCb->onTerminateSync(param->period_adv_sync_term.status); + } + log_v("ESP_GAP_BLE_PERIODIC_ADV_SYNC_TERMINATE_COMPLETE_EVT, status %d", param->period_adv_sync_term.status); + break; + case ESP_GAP_BLE_PERIODIC_ADV_SYNC_LOST_EVT: + if (m_pPeriodicScanCb != nullptr) { + m_pPeriodicScanCb->onLostSync(param->periodic_adv_sync_lost.sync_handle); + } + log_v("ESP_GAP_BLE_PERIODIC_ADV_SYNC_LOST_EVT, sync handle %d", param->periodic_adv_sync_lost.sync_handle); + break; + case ESP_GAP_BLE_PERIODIC_ADV_SYNC_ESTAB_EVT: + if (m_pPeriodicScanCb != nullptr) { + m_pPeriodicScanCb->onSync(*(esp_ble_periodic_adv_sync_estab_param_t*)¶m->periodic_adv_sync_estab); + } + log_v("ESP_GAP_BLE_PERIODIC_ADV_SYNC_ESTAB_EVT, status %d", param->periodic_adv_sync_estab.status); + break; + + case ESP_GAP_BLE_PERIODIC_ADV_REPORT_EVT: + if (m_pPeriodicScanCb != nullptr) { + m_pPeriodicScanCb->onReport(param->period_adv_report.params); + } + break; + +#endif // SOC_BLE_50_SUPPORTED + + default: + { + break; + } // default + } // End switch +} // gapEventHandler /** @@ -255,12 +253,12 @@ void BLEScan::handleGAPEvent( * @return N/A. */ void BLEScan::setActiveScan(bool active) { - if (active) { - m_scan_params.scan_type = BLE_SCAN_TYPE_ACTIVE; - } else { - m_scan_params.scan_type = BLE_SCAN_TYPE_PASSIVE; - } -} // setActiveScan + if (active) { + m_scan_params.scan_type = BLE_SCAN_TYPE_ACTIVE; + } else { + m_scan_params.scan_type = BLE_SCAN_TYPE_PASSIVE; + } +} // setActiveScan /** @@ -270,16 +268,15 @@ void BLEScan::setActiveScan(bool active) { * @param [in] shouldParse True if we wish to parse advertised package or raw payload. Default is true. */ void BLEScan::setAdvertisedDeviceCallbacks(BLEAdvertisedDeviceCallbacks* pAdvertisedDeviceCallbacks, bool wantDuplicates, bool shouldParse) { - m_wantDuplicates = wantDuplicates; - m_pAdvertisedDeviceCallbacks = pAdvertisedDeviceCallbacks; - m_shouldParse = shouldParse; -} // setAdvertisedDeviceCallbacks + m_wantDuplicates = wantDuplicates; + m_pAdvertisedDeviceCallbacks = pAdvertisedDeviceCallbacks; + m_shouldParse = shouldParse; +} // setAdvertisedDeviceCallbacks #ifdef SOC_BLE_50_SUPPORTED -void BLEScan::setExtendedScanCallback(BLEExtAdvertisingCallbacks* cb) -{ - m_pExtendedScanCb = cb; +void BLEScan::setExtendedScanCallback(BLEExtAdvertisingCallbacks* cb) { + m_pExtendedScanCb = cb; } /** @@ -290,22 +287,21 @@ void BLEScan::setExtendedScanCallback(BLEExtAdvertisingCallbacks* cb) * - other : failed * */ -esp_err_t BLEScan::setExtScanParams() -{ - esp_ble_ext_scan_params_t ext_scan_params = { - .own_addr_type = BLE_ADDR_TYPE_PUBLIC, - .filter_policy = BLE_SCAN_FILTER_ALLOW_ALL, - .scan_duplicate = BLE_SCAN_DUPLICATE_DISABLE, - .cfg_mask = ESP_BLE_GAP_EXT_SCAN_CFG_UNCODE_MASK | ESP_BLE_GAP_EXT_SCAN_CFG_CODE_MASK, - .uncoded_cfg = {BLE_SCAN_TYPE_ACTIVE, 40, 40}, - .coded_cfg = {BLE_SCAN_TYPE_ACTIVE, 40, 40}, - }; - - esp_err_t rc = esp_ble_gap_set_ext_scan_params(&ext_scan_params); - if (rc) { - log_e("set extend scan params error, error code = %x", rc); - } - return rc; +esp_err_t BLEScan::setExtScanParams() { + esp_ble_ext_scan_params_t ext_scan_params = { + .own_addr_type = BLE_ADDR_TYPE_PUBLIC, + .filter_policy = BLE_SCAN_FILTER_ALLOW_ALL, + .scan_duplicate = BLE_SCAN_DUPLICATE_DISABLE, + .cfg_mask = ESP_BLE_GAP_EXT_SCAN_CFG_UNCODE_MASK | ESP_BLE_GAP_EXT_SCAN_CFG_CODE_MASK, + .uncoded_cfg = { BLE_SCAN_TYPE_ACTIVE, 40, 40 }, + .coded_cfg = { BLE_SCAN_TYPE_ACTIVE, 40, 40 }, + }; + + esp_err_t rc = esp_ble_gap_set_ext_scan_params(&ext_scan_params); + if (rc) { + log_e("set extend scan params error, error code = %x", rc); + } + return rc; } /** @@ -317,13 +313,12 @@ esp_err_t BLEScan::setExtScanParams() * - other : failed * */ -esp_err_t BLEScan::setExtScanParams(esp_ble_ext_scan_params_t* ext_scan_params) -{ - esp_err_t rc = esp_ble_gap_set_ext_scan_params(ext_scan_params); - if (rc) { - log_e("set extend scan params error, error code = %x", rc); - } - return rc; +esp_err_t BLEScan::setExtScanParams(esp_ble_ext_scan_params_t* ext_scan_params) { + esp_err_t rc = esp_ble_gap_set_ext_scan_params(ext_scan_params); + if (rc) { + log_e("set extend scan params error, error code = %x", rc); + } + return rc; } /** @@ -336,35 +331,32 @@ esp_err_t BLEScan::setExtScanParams(esp_ble_ext_scan_params_t* ext_scan_params) * - other : failed * */ -esp_err_t BLEScan::startExtScan(uint32_t duration, uint16_t period) -{ - esp_err_t rc = esp_ble_gap_start_ext_scan(duration, period); - if(rc) log_e("extended scan start failed: %d", rc); - return rc; +esp_err_t BLEScan::startExtScan(uint32_t duration, uint16_t period) { + esp_err_t rc = esp_ble_gap_start_ext_scan(duration, period); + if (rc) log_e("extended scan start failed: %d", rc); + return rc; } -esp_err_t BLEScan::stopExtScan() -{ - esp_err_t rc; - rc = esp_ble_gap_stop_ext_scan(); +esp_err_t BLEScan::stopExtScan() { + esp_err_t rc; + rc = esp_ble_gap_stop_ext_scan(); - return rc; + return rc; } -void BLEScan::setPeriodicScanCallback(BLEPeriodicScanCallbacks* cb) -{ - m_pPeriodicScanCb = cb; +void BLEScan::setPeriodicScanCallback(BLEPeriodicScanCallbacks* cb) { + m_pPeriodicScanCb = cb; } -#endif // SOC_BLE_50_SUPPORTED +#endif // SOC_BLE_50_SUPPORTED /** * @brief Set the interval to scan. * @param [in] The interval in msecs. */ void BLEScan::setInterval(uint16_t intervalMSecs) { - m_scan_params.scan_interval = intervalMSecs / 0.625; -} // setInterval + m_scan_params.scan_interval = intervalMSecs / 0.625; +} // setInterval /** @@ -372,8 +364,8 @@ void BLEScan::setInterval(uint16_t intervalMSecs) { * @param [in] windowMSecs How long to actively scan. */ void BLEScan::setWindow(uint16_t windowMSecs) { - m_scan_params.scan_window = windowMSecs / 0.625; -} // setWindow + m_scan_params.scan_window = windowMSecs / 0.625; +} // setWindow /** @@ -384,41 +376,41 @@ void BLEScan::setWindow(uint16_t windowMSecs) { * @return True if scan started or false if there was an error. */ bool BLEScan::start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults), bool is_continue) { - log_v(">> start(duration=%d)", duration); + log_v(">> start(duration=%d)", duration); - m_semaphoreScanEnd.take(String("start")); - m_scanCompleteCB = scanCompleteCB; // Save the callback to be invoked when the scan completes. + m_semaphoreScanEnd.take(String("start")); + m_scanCompleteCB = scanCompleteCB; // Save the callback to be invoked when the scan completes. - // if we are connecting to devices that are advertising even after being connected, multiconnecting peripherals - // then we should not clear map or we will connect the same device few times - if(!is_continue) { - for(auto _dev : m_scanResults.m_vectorAdvertisedDevices){ - delete _dev.second; - } - m_scanResults.m_vectorAdvertisedDevices.clear(); - } + // if we are connecting to devices that are advertising even after being connected, multiconnecting peripherals + // then we should not clear map or we will connect the same device few times + if (!is_continue) { + for (auto _dev : m_scanResults.m_vectorAdvertisedDevices) { + delete _dev.second; + } + m_scanResults.m_vectorAdvertisedDevices.clear(); + } - esp_err_t errRc = ::esp_ble_gap_set_scan_params(&m_scan_params); + esp_err_t errRc = ::esp_ble_gap_set_scan_params(&m_scan_params); - if (errRc != ESP_OK) { - log_e("esp_ble_gap_set_scan_params: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc)); - m_semaphoreScanEnd.give(); - return false; - } + if (errRc != ESP_OK) { + log_e("esp_ble_gap_set_scan_params: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc)); + m_semaphoreScanEnd.give(); + return false; + } - errRc = ::esp_ble_gap_start_scanning(duration); + errRc = ::esp_ble_gap_start_scanning(duration); - if (errRc != ESP_OK) { - log_e("esp_ble_gap_start_scanning: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc)); - m_semaphoreScanEnd.give(); - return false; - } + if (errRc != ESP_OK) { + log_e("esp_ble_gap_start_scanning: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc)); + m_semaphoreScanEnd.give(); + return false; + } - m_stopped = false; + m_stopped = false; - log_v("<< start()"); - return true; -} // start + log_v("<< start()"); + return true; +} // start /** @@ -427,11 +419,11 @@ bool BLEScan::start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults), b * @return The BLEScanResults. */ BLEScanResults* BLEScan::start(uint32_t duration, bool is_continue) { - if(start(duration, nullptr, is_continue)) { - m_semaphoreScanEnd.wait("start"); // Wait for the semaphore to release. - } - return &m_scanResults; -} // start + if (start(duration, nullptr, is_continue)) { + m_semaphoreScanEnd.wait("start"); // Wait for the semaphore to release. + } + return &m_scanResults; +} // start /** @@ -439,27 +431,27 @@ BLEScanResults* BLEScan::start(uint32_t duration, bool is_continue) { * @return N/A. */ void BLEScan::stop() { - log_v(">> stop()"); + log_v(">> stop()"); - esp_err_t errRc = ::esp_ble_gap_stop_scanning(); + esp_err_t errRc = ::esp_ble_gap_stop_scanning(); - m_stopped = true; - m_semaphoreScanEnd.give(); + m_stopped = true; + m_semaphoreScanEnd.give(); - if (errRc != ESP_OK) { - log_e("esp_ble_gap_stop_scanning: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } + if (errRc != ESP_OK) { + log_e("esp_ble_gap_stop_scanning: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } - log_v("<< stop()"); -} // stop + log_v("<< stop()"); +} // stop // delete peer device from cache after disconnecting, it is required in case we are connecting to devices with not public address void BLEScan::erase(BLEAddress address) { - log_i("erase device: %s", address.toString().c_str()); - BLEAdvertisedDevice *advertisedDevice = m_scanResults.m_vectorAdvertisedDevices.find(address.toString())->second; - m_scanResults.m_vectorAdvertisedDevices.erase(address.toString()); - delete advertisedDevice; + log_i("erase device: %s", address.toString().c_str()); + BLEAdvertisedDevice* advertisedDevice = m_scanResults.m_vectorAdvertisedDevices.find(address.toString())->second; + m_scanResults.m_vectorAdvertisedDevices.erase(address.toString()); + delete advertisedDevice; } @@ -467,11 +459,11 @@ void BLEScan::erase(BLEAddress address) { * @brief Dump the scan results to the log. */ void BLEScanResults::dump() { - log_v(">> Dump scan results:"); - for (int i=0; i> Dump scan results:"); + for (int i = 0; i < getCount(); i++) { + log_d("- %s", getDevice(i).toString().c_str()); + } +} // dump /** @@ -479,8 +471,8 @@ void BLEScanResults::dump() { * @return The number of devices found in the last scan. */ int BLEScanResults::getCount() { - return m_vectorAdvertisedDevices.size(); -} // getCount + return m_vectorAdvertisedDevices.size(); +} // getCount /** @@ -490,25 +482,25 @@ int BLEScanResults::getCount() { * @return The device at the specified index. */ BLEAdvertisedDevice BLEScanResults::getDevice(uint32_t i) { - uint32_t x = 0; - BLEAdvertisedDevice dev = *m_vectorAdvertisedDevices.begin()->second; - for (auto it = m_vectorAdvertisedDevices.begin(); it != m_vectorAdvertisedDevices.end(); it++) { - dev = *it->second; - if (x==i) break; - x++; - } - return dev; + uint32_t x = 0; + BLEAdvertisedDevice dev = *m_vectorAdvertisedDevices.begin()->second; + for (auto it = m_vectorAdvertisedDevices.begin(); it != m_vectorAdvertisedDevices.end(); it++) { + dev = *it->second; + if (x == i) break; + x++; + } + return dev; } BLEScanResults* BLEScan::getResults() { - return &m_scanResults; + return &m_scanResults; } void BLEScan::clearResults() { - for(auto _dev : m_scanResults.m_vectorAdvertisedDevices){ - delete _dev.second; - } - m_scanResults.m_vectorAdvertisedDevices.clear(); + for (auto _dev : m_scanResults.m_vectorAdvertisedDevices) { + delete _dev.second; + } + m_scanResults.m_vectorAdvertisedDevices.clear(); } #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLEScan.h b/libraries/BLE/src/BLEScan.h index 4a00cafff4c..2620909cba7 100644 --- a/libraries/BLE/src/BLEScan.h +++ b/libraries/BLE/src/BLEScan.h @@ -28,14 +28,14 @@ class BLEScan; class BLEPeriodicScanCallbacks; struct esp_ble_periodic_adv_sync_estab_param_t { - uint8_t status; /*!< periodic advertising sync status */ - uint16_t sync_handle; /*!< periodic advertising sync handle */ - uint8_t sid; /*!< periodic advertising sid */ - esp_ble_addr_type_t adv_addr_type; /*!< periodic advertising address type */ - esp_bd_addr_t adv_addr; /*!< periodic advertising address */ - esp_ble_gap_phy_t adv_phy; /*!< periodic advertising phy type */ - uint16_t period_adv_interval; /*!< periodic advertising interval */ - uint8_t adv_clk_accuracy; /*!< periodic advertising clock accuracy */ + uint8_t status; /*!< periodic advertising sync status */ + uint16_t sync_handle; /*!< periodic advertising sync handle */ + uint8_t sid; /*!< periodic advertising sid */ + esp_ble_addr_type_t adv_addr_type; /*!< periodic advertising address type */ + esp_bd_addr_t adv_addr; /*!< periodic advertising address */ + esp_ble_gap_phy_t adv_phy; /*!< periodic advertising phy type */ + uint16_t period_adv_interval; /*!< periodic advertising interval */ + uint8_t adv_clk_accuracy; /*!< periodic advertising clock accuracy */ }; /** @@ -47,13 +47,13 @@ struct esp_ble_periodic_adv_sync_estab_param_t { */ class BLEScanResults { public: - void dump(); - int getCount(); - BLEAdvertisedDevice getDevice(uint32_t i); + void dump(); + int getCount(); + BLEAdvertisedDevice getDevice(uint32_t i); private: - friend BLEScan; - std::map m_vectorAdvertisedDevices; + friend BLEScan; + std::map m_vectorAdvertisedDevices; }; /** @@ -63,62 +63,62 @@ class BLEScanResults { */ class BLEScan { public: - void setActiveScan(bool active); - void setAdvertisedDeviceCallbacks( - BLEAdvertisedDeviceCallbacks* pAdvertisedDeviceCallbacks, - bool wantDuplicates = false, - bool shouldParse = true); - void setInterval(uint16_t intervalMSecs); - void setWindow(uint16_t windowMSecs); - bool start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults), bool is_continue = false); - BLEScanResults* start(uint32_t duration, bool is_continue = false); - void stop(); - void erase(BLEAddress address); - BLEScanResults* getResults(); - void clearResults(); + void setActiveScan(bool active); + void setAdvertisedDeviceCallbacks( + BLEAdvertisedDeviceCallbacks* pAdvertisedDeviceCallbacks, + bool wantDuplicates = false, + bool shouldParse = true); + void setInterval(uint16_t intervalMSecs); + void setWindow(uint16_t windowMSecs); + bool start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults), bool is_continue = false); + BLEScanResults* start(uint32_t duration, bool is_continue = false); + void stop(); + void erase(BLEAddress address); + BLEScanResults* getResults(); + void clearResults(); #ifdef SOC_BLE_50_SUPPORTED - void setExtendedScanCallback(BLEExtAdvertisingCallbacks* cb); - void setPeriodicScanCallback(BLEPeriodicScanCallbacks* cb); + void setExtendedScanCallback(BLEExtAdvertisingCallbacks* cb); + void setPeriodicScanCallback(BLEPeriodicScanCallbacks* cb); - esp_err_t stopExtScan(); - esp_err_t setExtScanParams(); - esp_err_t setExtScanParams(esp_ble_ext_scan_params_t* ext_scan_params); - esp_err_t startExtScan(uint32_t duration, uint16_t period); + esp_err_t stopExtScan(); + esp_err_t setExtScanParams(); + esp_err_t setExtScanParams(esp_ble_ext_scan_params_t* ext_scan_params); + esp_err_t startExtScan(uint32_t duration, uint16_t period); private: - BLEExtAdvertisingCallbacks* m_pExtendedScanCb = nullptr; - BLEPeriodicScanCallbacks* m_pPeriodicScanCb = nullptr; -#endif // SOC_BLE_50_SUPPORTED + BLEExtAdvertisingCallbacks* m_pExtendedScanCb = nullptr; + BLEPeriodicScanCallbacks* m_pPeriodicScanCb = nullptr; +#endif // SOC_BLE_50_SUPPORTED private: - BLEScan(); // One doesn't create a new instance instead one asks the BLEDevice for the singleton. - friend class BLEDevice; - void handleGAPEvent( - esp_gap_ble_cb_event_t event, - esp_ble_gap_cb_param_t* param); - - - esp_ble_scan_params_t m_scan_params; - BLEAdvertisedDeviceCallbacks* m_pAdvertisedDeviceCallbacks = nullptr; - bool m_stopped = true; - bool m_shouldParse = true; - FreeRTOS::Semaphore m_semaphoreScanEnd = FreeRTOS::Semaphore("ScanEnd"); - BLEScanResults m_scanResults; - bool m_wantDuplicates; - void (*m_scanCompleteCB)(BLEScanResults scanResults); -}; // BLEScan + BLEScan(); // One doesn't create a new instance instead one asks the BLEDevice for the singleton. + friend class BLEDevice; + void handleGAPEvent( + esp_gap_ble_cb_event_t event, + esp_ble_gap_cb_param_t* param); + + + esp_ble_scan_params_t m_scan_params; + BLEAdvertisedDeviceCallbacks* m_pAdvertisedDeviceCallbacks = nullptr; + bool m_stopped = true; + bool m_shouldParse = true; + FreeRTOS::Semaphore m_semaphoreScanEnd = FreeRTOS::Semaphore("ScanEnd"); + BLEScanResults m_scanResults; + bool m_wantDuplicates; + void (*m_scanCompleteCB)(BLEScanResults scanResults); +}; // BLEScan class BLEPeriodicScanCallbacks { public: - virtual ~BLEPeriodicScanCallbacks() {} - - virtual void onCreateSync(esp_bt_status_t status) {} - virtual void onCancelSync(esp_bt_status_t status) {} - virtual void onTerminateSync(esp_bt_status_t status) {} - virtual void onLostSync(uint16_t sync_handle) {} - virtual void onSync(esp_ble_periodic_adv_sync_estab_param_t) {} - virtual void onReport(esp_ble_gap_periodic_adv_report_t params) {} - virtual void onStop(esp_bt_status_t status) {} + virtual ~BLEPeriodicScanCallbacks() {} + + virtual void onCreateSync(esp_bt_status_t status) {} + virtual void onCancelSync(esp_bt_status_t status) {} + virtual void onTerminateSync(esp_bt_status_t status) {} + virtual void onLostSync(uint16_t sync_handle) {} + virtual void onSync(esp_ble_periodic_adv_sync_estab_param_t) {} + virtual void onReport(esp_ble_gap_periodic_adv_report_t params) {} + virtual void onStop(esp_bt_status_t status) {} }; #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLESecurity.cpp b/libraries/BLE/src/BLESecurity.cpp index 8437ee721e4..37f72ffa045 100644 --- a/libraries/BLE/src/BLESecurity.cpp +++ b/libraries/BLE/src/BLESecurity.cpp @@ -21,8 +21,8 @@ BLESecurity::~BLESecurity() { * @brief Set requested authentication mode */ void BLESecurity::setAuthenticationMode(esp_ble_auth_req_t auth_req) { - m_authReq = auth_req; - esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &m_authReq, sizeof(uint8_t)); // <--- setup requested authentication mode + m_authReq = auth_req; + esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &m_authReq, sizeof(uint8_t)); // <--- setup requested authentication mode } /** @@ -30,9 +30,9 @@ void BLESecurity::setAuthenticationMode(esp_ble_auth_req_t auth_req) { * either by displaying or entering generated 6-digits pin code */ void BLESecurity::setCapability(esp_ble_io_cap_t iocap) { - m_iocap = iocap; - esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t)); -} // setCapability + m_iocap = iocap; + esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t)); +} // setCapability /** @@ -40,9 +40,9 @@ void BLESecurity::setCapability(esp_ble_io_cap_t iocap) { * @param key_size is value between 7 and 16 */ void BLESecurity::setInitEncryptionKey(uint8_t init_key) { - m_initKey = init_key; - esp_ble_gap_set_security_param(ESP_BLE_SM_SET_INIT_KEY, &m_initKey, sizeof(uint8_t)); -} // setInitEncryptionKey + m_initKey = init_key; + esp_ble_gap_set_security_param(ESP_BLE_SM_SET_INIT_KEY, &m_initKey, sizeof(uint8_t)); +} // setInitEncryptionKey /** @@ -50,9 +50,9 @@ void BLESecurity::setInitEncryptionKey(uint8_t init_key) { * @param key_size is value between 7 and 16 */ void BLESecurity::setRespEncryptionKey(uint8_t resp_key) { - m_respKey = resp_key; - esp_ble_gap_set_security_param(ESP_BLE_SM_SET_RSP_KEY, &m_respKey, sizeof(uint8_t)); -} // setRespEncryptionKey + m_respKey = resp_key; + esp_ble_gap_set_security_param(ESP_BLE_SM_SET_RSP_KEY, &m_respKey, sizeof(uint8_t)); +} // setRespEncryptionKey /** @@ -60,61 +60,61 @@ void BLESecurity::setRespEncryptionKey(uint8_t resp_key) { * */ void BLESecurity::setKeySize(uint8_t key_size) { - m_keySize = key_size; - esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &m_keySize, sizeof(uint8_t)); -} //setKeySize + m_keySize = key_size; + esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &m_keySize, sizeof(uint8_t)); +} //setKeySize /** * Setup for static PIN connection, call it first and then call setAuthenticationMode eventually to change it */ -void BLESecurity::setStaticPIN(uint32_t pin){ - uint32_t passkey = pin; - esp_ble_gap_set_security_param(ESP_BLE_SM_SET_STATIC_PASSKEY, &passkey, sizeof(uint32_t)); - setCapability(ESP_IO_CAP_OUT); - setKeySize(); - setAuthenticationMode(ESP_LE_AUTH_REQ_SC_ONLY); - setInitEncryptionKey(ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK); +void BLESecurity::setStaticPIN(uint32_t pin) { + uint32_t passkey = pin; + esp_ble_gap_set_security_param(ESP_BLE_SM_SET_STATIC_PASSKEY, &passkey, sizeof(uint32_t)); + setCapability(ESP_IO_CAP_OUT); + setKeySize(); + setAuthenticationMode(ESP_LE_AUTH_REQ_SC_ONLY); + setInitEncryptionKey(ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK); } /** * @brief Debug function to display what keys are exchanged by peers */ char* BLESecurity::esp_key_type_to_str(esp_ble_key_type_t key_type) { - char* key_str = nullptr; - switch (key_type) { - case ESP_LE_KEY_NONE: - key_str = (char*) "ESP_LE_KEY_NONE"; - break; - case ESP_LE_KEY_PENC: - key_str = (char*) "ESP_LE_KEY_PENC"; - break; - case ESP_LE_KEY_PID: - key_str = (char*) "ESP_LE_KEY_PID"; - break; - case ESP_LE_KEY_PCSRK: - key_str = (char*) "ESP_LE_KEY_PCSRK"; - break; - case ESP_LE_KEY_PLK: - key_str = (char*) "ESP_LE_KEY_PLK"; - break; - case ESP_LE_KEY_LLK: - key_str = (char*) "ESP_LE_KEY_LLK"; - break; - case ESP_LE_KEY_LENC: - key_str = (char*) "ESP_LE_KEY_LENC"; - break; - case ESP_LE_KEY_LID: - key_str = (char*) "ESP_LE_KEY_LID"; - break; - case ESP_LE_KEY_LCSRK: - key_str = (char*) "ESP_LE_KEY_LCSRK"; - break; - default: - key_str = (char*) "INVALID BLE KEY TYPE"; - break; - } - return key_str; -} // esp_key_type_to_str + char* key_str = nullptr; + switch (key_type) { + case ESP_LE_KEY_NONE: + key_str = (char*)"ESP_LE_KEY_NONE"; + break; + case ESP_LE_KEY_PENC: + key_str = (char*)"ESP_LE_KEY_PENC"; + break; + case ESP_LE_KEY_PID: + key_str = (char*)"ESP_LE_KEY_PID"; + break; + case ESP_LE_KEY_PCSRK: + key_str = (char*)"ESP_LE_KEY_PCSRK"; + break; + case ESP_LE_KEY_PLK: + key_str = (char*)"ESP_LE_KEY_PLK"; + break; + case ESP_LE_KEY_LLK: + key_str = (char*)"ESP_LE_KEY_LLK"; + break; + case ESP_LE_KEY_LENC: + key_str = (char*)"ESP_LE_KEY_LENC"; + break; + case ESP_LE_KEY_LID: + key_str = (char*)"ESP_LE_KEY_LID"; + break; + case ESP_LE_KEY_LCSRK: + key_str = (char*)"ESP_LE_KEY_LCSRK"; + break; + default: + key_str = (char*)"INVALID BLE KEY TYPE"; + break; + } + return key_str; +} // esp_key_type_to_str #endif /* CONFIG_BLUEDROID_ENABLED */ #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLESecurity.h b/libraries/BLE/src/BLESecurity.h index 06c7dcd30dc..9b555c64eb0 100644 --- a/libraries/BLE/src/BLESecurity.h +++ b/libraries/BLE/src/BLESecurity.h @@ -17,24 +17,24 @@ class BLESecurity { public: - BLESecurity(); - virtual ~BLESecurity(); - void setAuthenticationMode(esp_ble_auth_req_t auth_req); - void setCapability(esp_ble_io_cap_t iocap); - void setInitEncryptionKey(uint8_t init_key); - void setRespEncryptionKey(uint8_t resp_key); - void setKeySize(uint8_t key_size = 16); - void setStaticPIN(uint32_t pin); - static char* esp_key_type_to_str(esp_ble_key_type_t key_type); + BLESecurity(); + virtual ~BLESecurity(); + void setAuthenticationMode(esp_ble_auth_req_t auth_req); + void setCapability(esp_ble_io_cap_t iocap); + void setInitEncryptionKey(uint8_t init_key); + void setRespEncryptionKey(uint8_t resp_key); + void setKeySize(uint8_t key_size = 16); + void setStaticPIN(uint32_t pin); + static char* esp_key_type_to_str(esp_ble_key_type_t key_type); private: - esp_ble_auth_req_t m_authReq; - esp_ble_io_cap_t m_iocap; - uint8_t m_initKey; - uint8_t m_respKey; - uint8_t m_keySize; + esp_ble_auth_req_t m_authReq; + esp_ble_io_cap_t m_iocap; + uint8_t m_initKey; + uint8_t m_respKey; + uint8_t m_keySize; -}; // BLESecurity +}; // BLESecurity /* @@ -42,36 +42,36 @@ class BLESecurity { */ class BLESecurityCallbacks { public: - virtual ~BLESecurityCallbacks() {}; + virtual ~BLESecurityCallbacks(){}; - /** + /** * @brief Its request from peer device to input authentication pin code displayed on peer device. * It requires that our device is capable to input 6-digits code by end user * @return Return 6-digits integer value from input device */ - virtual uint32_t onPassKeyRequest() = 0; + virtual uint32_t onPassKeyRequest() = 0; - /** + /** * @brief Provide us 6-digits code to perform authentication. * It requires that our device is capable to display this code to end user * @param */ - virtual void onPassKeyNotify(uint32_t pass_key) = 0; + virtual void onPassKeyNotify(uint32_t pass_key) = 0; - /** + /** * @brief Here we can make decision if we want to let negotiate authorization with peer device or not * return Return true if we accept this peer device request */ - virtual bool onSecurityRequest() = 0 ; - /** + virtual bool onSecurityRequest() = 0; + /** * Provide us information when authentication process is completed */ - virtual void onAuthenticationComplete(esp_ble_auth_cmpl_t) = 0; + virtual void onAuthenticationComplete(esp_ble_auth_cmpl_t) = 0; - virtual bool onConfirmPIN(uint32_t pin) = 0; -}; // BLESecurityCallbacks + virtual bool onConfirmPIN(uint32_t pin) = 0; +}; // BLESecurityCallbacks -#endif /* CONFIG_BLUEDROID_ENABLED */ -#endif /* SOC_BLE_SUPPORTED */ -#endif // COMPONENTS_CPP_UTILS_BLESECURITY_H_ +#endif /* CONFIG_BLUEDROID_ENABLED */ +#endif /* SOC_BLE_SUPPORTED */ +#endif // COMPONENTS_CPP_UTILS_BLESECURITY_H_ diff --git a/libraries/BLE/src/BLEServer.cpp b/libraries/BLE/src/BLEServer.cpp index 2fe3b64d0c3..8324a60cc56 100644 --- a/libraries/BLE/src/BLEServer.cpp +++ b/libraries/BLE/src/BLEServer.cpp @@ -28,18 +28,18 @@ * the BLEDevice class. */ BLEServer::BLEServer() { - m_appId = ESP_GATT_IF_NONE; - m_gatts_if = ESP_GATT_IF_NONE; - m_connectedCount = 0; - m_connId = ESP_GATT_IF_NONE; - m_pServerCallbacks = nullptr; -} // BLEServer + m_appId = ESP_GATT_IF_NONE; + m_gatts_if = ESP_GATT_IF_NONE; + m_connectedCount = 0; + m_connId = ESP_GATT_IF_NONE; + m_pServerCallbacks = nullptr; +} // BLEServer void BLEServer::createApp(uint16_t appId) { - m_appId = appId; - registerApp(appId); -} // createApp + m_appId = appId; + registerApp(appId); +} // createApp /** @@ -51,7 +51,7 @@ void BLEServer::createApp(uint16_t appId) { * @return A reference to the new service object. */ BLEService* BLEServer::createService(const char* uuid) { - return createService(BLEUUID(uuid)); + return createService(BLEUUID(uuid)); } @@ -66,25 +66,25 @@ BLEService* BLEServer::createService(const char* uuid) { * @return A reference to the new service object. */ BLEService* BLEServer::createService(BLEUUID uuid, uint32_t numHandles, uint8_t inst_id) { - log_v(">> createService - %s", uuid.toString().c_str()); - m_semaphoreCreateEvt.take("createService"); + log_v(">> createService - %s", uuid.toString().c_str()); + m_semaphoreCreateEvt.take("createService"); - // Check that a service with the supplied UUID does not already exist. - if (m_serviceMap.getByUUID(uuid) != nullptr) { - log_w("<< Attempt to create a new service with uuid %s but a service with that UUID already exists.", - uuid.toString().c_str()); - } + // Check that a service with the supplied UUID does not already exist. + if (m_serviceMap.getByUUID(uuid) != nullptr) { + log_w("<< Attempt to create a new service with uuid %s but a service with that UUID already exists.", + uuid.toString().c_str()); + } - BLEService* pService = new BLEService(uuid, numHandles); - pService->m_instId = inst_id; - m_serviceMap.setByUUID(uuid, pService); // Save a reference to this service being on this server. - pService->executeCreate(this); // Perform the API calls to actually create the service. + BLEService* pService = new BLEService(uuid, numHandles); + pService->m_instId = inst_id; + m_serviceMap.setByUUID(uuid, pService); // Save a reference to this service being on this server. + pService->executeCreate(this); // Perform the API calls to actually create the service. - m_semaphoreCreateEvt.wait("createService"); + m_semaphoreCreateEvt.wait("createService"); - log_v("<< createService"); - return pService; -} // createService + log_v("<< createService"); + return pService; +} // createService /** @@ -93,7 +93,7 @@ BLEService* BLEServer::createService(BLEUUID uuid, uint32_t numHandles, uint8_t * @return A reference to the service object. */ BLEService* BLEServer::getServiceByUUID(const char* uuid) { - return m_serviceMap.getByUUID(uuid); + return m_serviceMap.getByUUID(uuid); } /** @@ -102,7 +102,7 @@ BLEService* BLEServer::getServiceByUUID(const char* uuid) { * @return A reference to the service object. */ BLEService* BLEServer::getServiceByUUID(BLEUUID uuid) { - return m_serviceMap.getByUUID(uuid); + return m_serviceMap.getByUUID(uuid); } /** @@ -111,11 +111,11 @@ BLEService* BLEServer::getServiceByUUID(BLEUUID uuid) { * @return An advertising object. */ BLEAdvertising* BLEServer::getAdvertising() { - return BLEDevice::getAdvertising(); + return BLEDevice::getAdvertising(); } uint16_t BLEServer::getConnId() { - return m_connId; + return m_connId; } @@ -124,12 +124,12 @@ uint16_t BLEServer::getConnId() { * @return The number of connected clients. */ uint32_t BLEServer::getConnectedCount() { - return m_connectedCount; -} // getConnectedCount + return m_connectedCount; +} // getConnectedCount uint16_t BLEServer::getGattsIf() { - return m_gatts_if; + return m_gatts_if; } @@ -142,146 +142,153 @@ uint16_t BLEServer::getGattsIf() { * */ void BLEServer::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param) { - log_v(">> handleGATTServerEvent: %s", - BLEUtils::gattServerEventTypeToString(event).c_str()); - - switch(event) { - // ESP_GATTS_ADD_CHAR_EVT - Indicate that a characteristic was added to the service. - // add_char: - // - esp_gatt_status_t status - // - uint16_t attr_handle - // - uint16_t service_handle - // - esp_bt_uuid_t char_uuid - // - case ESP_GATTS_ADD_CHAR_EVT: { - break; - } // ESP_GATTS_ADD_CHAR_EVT - - case ESP_GATTS_MTU_EVT: - updatePeerMTU(param->mtu.conn_id, param->mtu.mtu); - if (m_pServerCallbacks != nullptr) { - m_pServerCallbacks->onMtuChanged(this, param); - } - break; - - // ESP_GATTS_CONNECT_EVT - // connect: - // - uint16_t conn_id - // - esp_bd_addr_t remote_bda - // - case ESP_GATTS_CONNECT_EVT: { - m_connId = param->connect.conn_id; - addPeerDevice((void*)this, false, m_connId); - if (m_pServerCallbacks != nullptr) { - m_pServerCallbacks->onConnect(this); - m_pServerCallbacks->onConnect(this, param); - } - m_connectedCount++; // Increment the number of connected devices count. - break; - } // ESP_GATTS_CONNECT_EVT - - - // ESP_GATTS_CREATE_EVT - // Called when a new service is registered as having been created. - // - // create: - // * esp_gatt_status_t status - // * uint16_t service_handle - // * esp_gatt_srvc_id_t service_id - // - case ESP_GATTS_CREATE_EVT: { - BLEService* pService = m_serviceMap.getByUUID(param->create.service_id.id.uuid, param->create.service_id.id.inst_id); // <--- very big bug for multi services with the same uuid - m_serviceMap.setByHandle(param->create.service_handle, pService); - m_semaphoreCreateEvt.give(); - break; - } // ESP_GATTS_CREATE_EVT - - - // ESP_GATTS_DISCONNECT_EVT - // - // disconnect - // - uint16_t conn_id - // - esp_bd_addr_t remote_bda - // - esp_gatt_conn_reason_t reason - // - // If we receive a disconnect event then invoke the callback for disconnects (if one is present). - // we also want to start advertising again. - case ESP_GATTS_DISCONNECT_EVT: { - if (m_pServerCallbacks != nullptr) { // If we have callbacks, call now. - m_pServerCallbacks->onDisconnect(this); - m_pServerCallbacks->onDisconnect(this, param); - } - if(m_connId == ESP_GATT_IF_NONE) { - return; - } - - // only decrement if connection is found in map and removed - // sometimes this event triggers w/o a valid connection - if(removePeerDevice(param->disconnect.conn_id, false)) { - m_connectedCount--; // Decrement the number of connected devices count. - } - break; - } // ESP_GATTS_DISCONNECT_EVT - - - // ESP_GATTS_READ_EVT - A request to read the value of a characteristic has arrived. - // - // read: - // - uint16_t conn_id - // - uint32_t trans_id - // - esp_bd_addr_t bda - // - uint16_t handle - // - uint16_t offset - // - bool is_long - // - bool need_rsp - // - case ESP_GATTS_READ_EVT: { - break; - } // ESP_GATTS_READ_EVT - - - // ESP_GATTS_REG_EVT - // reg: - // - esp_gatt_status_t status - // - uint16_t app_id - // - case ESP_GATTS_REG_EVT: { - m_gatts_if = gatts_if; - m_semaphoreRegisterAppEvt.give(); // Unlock the mutex waiting for the registration of the app. - break; - } // ESP_GATTS_REG_EVT - - - // ESP_GATTS_WRITE_EVT - A request to write the value of a characteristic has arrived. - // - // write: - // - uint16_t conn_id - // - uint16_t trans_id - // - esp_bd_addr_t bda - // - uint16_t handle - // - uint16_t offset - // - bool need_rsp - // - bool is_prep - // - uint16_t len - // - uint8_t* value - // - case ESP_GATTS_WRITE_EVT: { - break; - } - - case ESP_GATTS_OPEN_EVT: - m_semaphoreOpenEvt.give(param->open.status); - break; - - default: - break; - } - - // Invoke the handler for every Service we have. - m_serviceMap.handleGATTServerEvent(event, gatts_if, param); - - log_v("<< handleGATTServerEvent"); -} // handleGATTServerEvent + log_v(">> handleGATTServerEvent: %s", + BLEUtils::gattServerEventTypeToString(event).c_str()); + + switch (event) { + // ESP_GATTS_ADD_CHAR_EVT - Indicate that a characteristic was added to the service. + // add_char: + // - esp_gatt_status_t status + // - uint16_t attr_handle + // - uint16_t service_handle + // - esp_bt_uuid_t char_uuid + // + case ESP_GATTS_ADD_CHAR_EVT: + { + break; + } // ESP_GATTS_ADD_CHAR_EVT + + case ESP_GATTS_MTU_EVT: + updatePeerMTU(param->mtu.conn_id, param->mtu.mtu); + if (m_pServerCallbacks != nullptr) { + m_pServerCallbacks->onMtuChanged(this, param); + } + break; + + // ESP_GATTS_CONNECT_EVT + // connect: + // - uint16_t conn_id + // - esp_bd_addr_t remote_bda + // + case ESP_GATTS_CONNECT_EVT: + { + m_connId = param->connect.conn_id; + addPeerDevice((void*)this, false, m_connId); + if (m_pServerCallbacks != nullptr) { + m_pServerCallbacks->onConnect(this); + m_pServerCallbacks->onConnect(this, param); + } + m_connectedCount++; // Increment the number of connected devices count. + break; + } // ESP_GATTS_CONNECT_EVT + + + // ESP_GATTS_CREATE_EVT + // Called when a new service is registered as having been created. + // + // create: + // * esp_gatt_status_t status + // * uint16_t service_handle + // * esp_gatt_srvc_id_t service_id + // + case ESP_GATTS_CREATE_EVT: + { + BLEService* pService = m_serviceMap.getByUUID(param->create.service_id.id.uuid, param->create.service_id.id.inst_id); // <--- very big bug for multi services with the same uuid + m_serviceMap.setByHandle(param->create.service_handle, pService); + m_semaphoreCreateEvt.give(); + break; + } // ESP_GATTS_CREATE_EVT + + + // ESP_GATTS_DISCONNECT_EVT + // + // disconnect + // - uint16_t conn_id + // - esp_bd_addr_t remote_bda + // - esp_gatt_conn_reason_t reason + // + // If we receive a disconnect event then invoke the callback for disconnects (if one is present). + // we also want to start advertising again. + case ESP_GATTS_DISCONNECT_EVT: + { + if (m_pServerCallbacks != nullptr) { // If we have callbacks, call now. + m_pServerCallbacks->onDisconnect(this); + m_pServerCallbacks->onDisconnect(this, param); + } + if (m_connId == ESP_GATT_IF_NONE) { + return; + } + + // only decrement if connection is found in map and removed + // sometimes this event triggers w/o a valid connection + if (removePeerDevice(param->disconnect.conn_id, false)) { + m_connectedCount--; // Decrement the number of connected devices count. + } + break; + } // ESP_GATTS_DISCONNECT_EVT + + + // ESP_GATTS_READ_EVT - A request to read the value of a characteristic has arrived. + // + // read: + // - uint16_t conn_id + // - uint32_t trans_id + // - esp_bd_addr_t bda + // - uint16_t handle + // - uint16_t offset + // - bool is_long + // - bool need_rsp + // + case ESP_GATTS_READ_EVT: + { + break; + } // ESP_GATTS_READ_EVT + + + // ESP_GATTS_REG_EVT + // reg: + // - esp_gatt_status_t status + // - uint16_t app_id + // + case ESP_GATTS_REG_EVT: + { + m_gatts_if = gatts_if; + m_semaphoreRegisterAppEvt.give(); // Unlock the mutex waiting for the registration of the app. + break; + } // ESP_GATTS_REG_EVT + + + // ESP_GATTS_WRITE_EVT - A request to write the value of a characteristic has arrived. + // + // write: + // - uint16_t conn_id + // - uint16_t trans_id + // - esp_bd_addr_t bda + // - uint16_t handle + // - uint16_t offset + // - bool need_rsp + // - bool is_prep + // - uint16_t len + // - uint8_t* value + // + case ESP_GATTS_WRITE_EVT: + { + break; + } + + case ESP_GATTS_OPEN_EVT: + m_semaphoreOpenEvt.give(param->open.status); + break; + + default: + break; + } + + // Invoke the handler for every Service we have. + m_serviceMap.handleGATTServerEvent(event, gatts_if, param); + + log_v("<< handleGATTServerEvent"); +} // handleGATTServerEvent /** @@ -290,12 +297,12 @@ void BLEServer::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t * @return N/A */ void BLEServer::registerApp(uint16_t m_appId) { - log_v(">> registerApp - %d", m_appId); - m_semaphoreRegisterAppEvt.take("registerApp"); // Take the mutex, will be released by ESP_GATTS_REG_EVT event. - ::esp_ble_gatts_app_register(m_appId); - m_semaphoreRegisterAppEvt.wait("registerApp"); - log_v("<< registerApp"); -} // registerApp + log_v(">> registerApp - %d", m_appId); + m_semaphoreRegisterAppEvt.take("registerApp"); // Take the mutex, will be released by ESP_GATTS_REG_EVT event. + ::esp_ble_gatts_app_register(m_appId); + m_semaphoreRegisterAppEvt.wait("registerApp"); + log_v("<< registerApp"); +} // registerApp /** @@ -308,16 +315,16 @@ void BLEServer::registerApp(uint16_t m_appId) { * @param [in] pCallbacks The callbacks to be invoked. */ void BLEServer::setCallbacks(BLEServerCallbacks* pCallbacks) { - m_pServerCallbacks = pCallbacks; -} // setCallbacks + m_pServerCallbacks = pCallbacks; +} // setCallbacks /* * Remove service */ void BLEServer::removeService(BLEService* service) { - service->stop(); - service->executeDelete(); - m_serviceMap.removeService(service); + service->stop(); + service->executeDelete(); + m_serviceMap.removeService(service); } /** @@ -327,100 +334,100 @@ void BLEServer::removeService(BLEService* service) { * retrieving the advertising object and invoking start upon it. */ void BLEServer::startAdvertising() { - log_v(">> startAdvertising"); - BLEDevice::startAdvertising(); - log_v("<< startAdvertising"); -} // startAdvertising + log_v(">> startAdvertising"); + BLEDevice::startAdvertising(); + log_v("<< startAdvertising"); +} // startAdvertising /** * Allow to connect GATT server to peer device * Probably can be used in ANCS for iPhone */ bool BLEServer::connect(BLEAddress address) { - esp_bd_addr_t addr; - memcpy(&addr, address.getNative(), 6); - // Perform the open connection request against the target BLE Server. - m_semaphoreOpenEvt.take("connect"); - esp_err_t errRc = ::esp_ble_gatts_open( - getGattsIf(), - addr, // address - 1 // direct connection - ); - if (errRc != ESP_OK) { - log_e("esp_ble_gattc_open: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return false; - } - - uint32_t rc = m_semaphoreOpenEvt.wait("connect"); // Wait for the connection to complete. - log_v("<< connect(), rc=%d", rc==ESP_GATT_OK); - return rc == ESP_GATT_OK; -} // connect + esp_bd_addr_t addr; + memcpy(&addr, address.getNative(), 6); + // Perform the open connection request against the target BLE Server. + m_semaphoreOpenEvt.take("connect"); + esp_err_t errRc = ::esp_ble_gatts_open( + getGattsIf(), + addr, // address + 1 // direct connection + ); + if (errRc != ESP_OK) { + log_e("esp_ble_gattc_open: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return false; + } + + uint32_t rc = m_semaphoreOpenEvt.wait("connect"); // Wait for the connection to complete. + log_v("<< connect(), rc=%d", rc == ESP_GATT_OK); + return rc == ESP_GATT_OK; +} // connect void BLEServerCallbacks::onConnect(BLEServer* pServer) { - log_d("BLEServerCallbacks", ">> onConnect(): Default"); - log_d("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str()); - log_d("BLEServerCallbacks", "<< onConnect()"); -} // onConnect + log_d("BLEServerCallbacks", ">> onConnect(): Default"); + log_d("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str()); + log_d("BLEServerCallbacks", "<< onConnect()"); +} // onConnect void BLEServerCallbacks::onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t* param) { - log_d("BLEServerCallbacks", ">> onConnect(): Default"); - log_d("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str()); - log_d("BLEServerCallbacks", "<< onConnect()"); -} // onConnect + log_d("BLEServerCallbacks", ">> onConnect(): Default"); + log_d("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str()); + log_d("BLEServerCallbacks", "<< onConnect()"); +} // onConnect void BLEServerCallbacks::onDisconnect(BLEServer* pServer) { - log_d("BLEServerCallbacks", ">> onDisconnect(): Default"); - log_d("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str()); - log_d("BLEServerCallbacks", "<< onDisconnect()"); -} // onDisconnect + log_d("BLEServerCallbacks", ">> onDisconnect(): Default"); + log_d("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str()); + log_d("BLEServerCallbacks", "<< onDisconnect()"); +} // onDisconnect void BLEServerCallbacks::onDisconnect(BLEServer* pServer, esp_ble_gatts_cb_param_t* param) { - log_d("BLEServerCallbacks", ">> onDisconnect(): Default"); - log_d("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str()); - log_d("BLEServerCallbacks", "<< onDisconnect()"); -} // onDisconnect + log_d("BLEServerCallbacks", ">> onDisconnect(): Default"); + log_d("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str()); + log_d("BLEServerCallbacks", "<< onDisconnect()"); +} // onDisconnect void BLEServerCallbacks::onMtuChanged(BLEServer* pServer, esp_ble_gatts_cb_param_t* param) { - log_d("BLEServerCallbacks", ">> onMtuChanged(): Default"); - log_d("BLEServerCallbacks", "Device: %s MTU: %d", BLEDevice::toString().c_str(), param->mtu.mtu); - log_d("BLEServerCallbacks", "<< onMtuChanged()"); -} // onMtuChanged + log_d("BLEServerCallbacks", ">> onMtuChanged(): Default"); + log_d("BLEServerCallbacks", "Device: %s MTU: %d", BLEDevice::toString().c_str(), param->mtu.mtu); + log_d("BLEServerCallbacks", "<< onMtuChanged()"); +} // onMtuChanged /* multi connect support */ /* TODO do some more tweaks */ void BLEServer::updatePeerMTU(uint16_t conn_id, uint16_t mtu) { - // set mtu in conn_status_t - const std::map::iterator it = m_connectedServersMap.find(conn_id); - if (it != m_connectedServersMap.end()) { - it->second.mtu = mtu; - std::swap(m_connectedServersMap[conn_id], it->second); - } + // set mtu in conn_status_t + const std::map::iterator it = m_connectedServersMap.find(conn_id); + if (it != m_connectedServersMap.end()) { + it->second.mtu = mtu; + std::swap(m_connectedServersMap[conn_id], it->second); + } } std::map BLEServer::getPeerDevices(bool _client) { - return m_connectedServersMap; + return m_connectedServersMap; } uint16_t BLEServer::getPeerMTU(uint16_t conn_id) { - return m_connectedServersMap.find(conn_id)->second.mtu; + return m_connectedServersMap.find(conn_id)->second.mtu; } void BLEServer::addPeerDevice(void* peer, bool _client, uint16_t conn_id) { - conn_status_t status = { - .peer_device = peer, - .connected = true, - .mtu = 23 - }; + conn_status_t status = { + .peer_device = peer, + .connected = true, + .mtu = 23 + }; - m_connectedServersMap.insert(std::pair(conn_id, status)); + m_connectedServersMap.insert(std::pair(conn_id, status)); } bool BLEServer::removePeerDevice(uint16_t conn_id, bool _client) { - return m_connectedServersMap.erase(conn_id) > 0; + return m_connectedServersMap.erase(conn_id) > 0; } /* multi connect support */ @@ -428,17 +435,17 @@ bool BLEServer::removePeerDevice(uint16_t conn_id, bool _client) { * Update connection parameters can be called only after connection has been established */ void BLEServer::updateConnParams(esp_bd_addr_t remote_bda, uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout) { - esp_ble_conn_update_params_t conn_params; - memcpy(conn_params.bda, remote_bda, sizeof(esp_bd_addr_t)); - conn_params.latency = latency; - conn_params.max_int = maxInterval; // max_int = 0x20*1.25ms = 40ms - conn_params.min_int = minInterval; // min_int = 0x10*1.25ms = 20ms - conn_params.timeout = timeout; // timeout = 400*10ms = 4000ms - esp_ble_gap_update_conn_params(&conn_params); + esp_ble_conn_update_params_t conn_params; + memcpy(conn_params.bda, remote_bda, sizeof(esp_bd_addr_t)); + conn_params.latency = latency; + conn_params.max_int = maxInterval; // max_int = 0x20*1.25ms = 40ms + conn_params.min_int = minInterval; // min_int = 0x10*1.25ms = 20ms + conn_params.timeout = timeout; // timeout = 400*10ms = 4000ms + esp_ble_gap_update_conn_params(&conn_params); } void BLEServer::disconnect(uint16_t connId) { - esp_ble_gatts_close(m_gatts_if, connId); + esp_ble_gatts_close(m_gatts_if, connId); } #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLEServer.h b/libraries/BLE/src/BLEServer.h index ef2d8f9af7e..1f5b377a3ce 100644 --- a/libraries/BLE/src/BLEServer.h +++ b/libraries/BLE/src/BLEServer.h @@ -27,11 +27,11 @@ #include "BLEAddress.h" class BLEServerCallbacks; -/* TODO possibly refactor this struct */ +/* TODO possibly refactor this struct */ typedef struct { - void *peer_device; // peer device BLEClient or BLEServer - maybe its better to have 2 structures or union here - bool connected; // do we need it? - uint16_t mtu; // every peer device negotiate own mtu + void* peer_device; // peer device BLEClient or BLEServer - maybe its better to have 2 structures or union here + bool connected; // do we need it? + uint16_t mtu; // every peer device negotiate own mtu } conn_status_t; @@ -40,23 +40,23 @@ typedef struct { */ class BLEServiceMap { public: - BLEService* getByHandle(uint16_t handle); - BLEService* getByUUID(const char* uuid); - BLEService* getByUUID(BLEUUID uuid, uint8_t inst_id = 0); - void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param); - void setByHandle(uint16_t handle, BLEService* service); - void setByUUID(const char* uuid, BLEService* service); - void setByUUID(BLEUUID uuid, BLEService* service); - String toString(); - BLEService* getFirst(); - BLEService* getNext(); - void removeService(BLEService *service); - int getRegisteredServiceCount(); + BLEService* getByHandle(uint16_t handle); + BLEService* getByUUID(const char* uuid); + BLEService* getByUUID(BLEUUID uuid, uint8_t inst_id = 0); + void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param); + void setByHandle(uint16_t handle, BLEService* service); + void setByUUID(const char* uuid, BLEService* service); + void setByUUID(BLEUUID uuid, BLEService* service); + String toString(); + BLEService* getFirst(); + BLEService* getNext(); + void removeService(BLEService* service); + int getRegisteredServiceCount(); private: - std::map m_handleMap; - std::map m_uuidMap; - std::map::iterator m_iterator; + std::map m_handleMap; + std::map m_uuidMap; + std::map::iterator m_iterator; }; @@ -65,53 +65,53 @@ class BLEServiceMap { */ class BLEServer { public: - uint32_t getConnectedCount(); - BLEService* createService(const char* uuid); - BLEService* createService(BLEUUID uuid, uint32_t numHandles=15, uint8_t inst_id=0); - BLEAdvertising* getAdvertising(); - void setCallbacks(BLEServerCallbacks* pCallbacks); - void startAdvertising(); - void removeService(BLEService* service); - BLEService* getServiceByUUID(const char* uuid); - BLEService* getServiceByUUID(BLEUUID uuid); - bool connect(BLEAddress address); - void disconnect(uint16_t connId); - uint16_t m_appId; - void updateConnParams(esp_bd_addr_t remote_bda, uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout); - - /* multi connection support */ - std::map getPeerDevices(bool client); - void addPeerDevice(void* peer, bool is_client, uint16_t conn_id); - bool removePeerDevice(uint16_t conn_id, bool client); - BLEServer* getServerByConnId(uint16_t conn_id); - void updatePeerMTU(uint16_t connId, uint16_t mtu); - uint16_t getPeerMTU(uint16_t conn_id); - uint16_t getConnId(); + uint32_t getConnectedCount(); + BLEService* createService(const char* uuid); + BLEService* createService(BLEUUID uuid, uint32_t numHandles = 15, uint8_t inst_id = 0); + BLEAdvertising* getAdvertising(); + void setCallbacks(BLEServerCallbacks* pCallbacks); + void startAdvertising(); + void removeService(BLEService* service); + BLEService* getServiceByUUID(const char* uuid); + BLEService* getServiceByUUID(BLEUUID uuid); + bool connect(BLEAddress address); + void disconnect(uint16_t connId); + uint16_t m_appId; + void updateConnParams(esp_bd_addr_t remote_bda, uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout); + + /* multi connection support */ + std::map getPeerDevices(bool client); + void addPeerDevice(void* peer, bool is_client, uint16_t conn_id); + bool removePeerDevice(uint16_t conn_id, bool client); + BLEServer* getServerByConnId(uint16_t conn_id); + void updatePeerMTU(uint16_t connId, uint16_t mtu); + uint16_t getPeerMTU(uint16_t conn_id); + uint16_t getConnId(); private: - BLEServer(); - friend class BLEService; - friend class BLECharacteristic; - friend class BLEDevice; - esp_ble_adv_data_t m_adv_data; - // BLEAdvertising m_bleAdvertising; - uint16_t m_connId; - uint32_t m_connectedCount; - uint16_t m_gatts_if; - std::map m_connectedServersMap; - - FreeRTOS::Semaphore m_semaphoreRegisterAppEvt = FreeRTOS::Semaphore("RegisterAppEvt"); - FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt"); - FreeRTOS::Semaphore m_semaphoreOpenEvt = FreeRTOS::Semaphore("OpenEvt"); - BLEServiceMap m_serviceMap; - BLEServerCallbacks* m_pServerCallbacks = nullptr; - - void createApp(uint16_t appId); - uint16_t getGattsIf(); - void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param); - void registerApp(uint16_t); -}; // BLEServer + BLEServer(); + friend class BLEService; + friend class BLECharacteristic; + friend class BLEDevice; + esp_ble_adv_data_t m_adv_data; + // BLEAdvertising m_bleAdvertising; + uint16_t m_connId; + uint32_t m_connectedCount; + uint16_t m_gatts_if; + std::map m_connectedServersMap; + + FreeRTOS::Semaphore m_semaphoreRegisterAppEvt = FreeRTOS::Semaphore("RegisterAppEvt"); + FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt"); + FreeRTOS::Semaphore m_semaphoreOpenEvt = FreeRTOS::Semaphore("OpenEvt"); + BLEServiceMap m_serviceMap; + BLEServerCallbacks* m_pServerCallbacks = nullptr; + + void createApp(uint16_t appId); + uint16_t getGattsIf(); + void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param); + void registerApp(uint16_t); +}; // BLEServer /** @@ -119,27 +119,27 @@ class BLEServer { */ class BLEServerCallbacks { public: - virtual ~BLEServerCallbacks() {}; - /** + virtual ~BLEServerCallbacks(){}; + /** * @brief Handle a new client connection. * * When a new client connects, we are invoked. * * @param [in] pServer A reference to the %BLE server that received the client connection. */ - virtual void onConnect(BLEServer* pServer); - virtual void onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param); - /** + virtual void onConnect(BLEServer* pServer); + virtual void onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t* param); + /** * @brief Handle an existing client disconnection. * * When an existing client disconnects, we are invoked. * * @param [in] pServer A reference to the %BLE server that received the existing client disconnection. */ - virtual void onDisconnect(BLEServer* pServer); - virtual void onDisconnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param); + virtual void onDisconnect(BLEServer* pServer); + virtual void onDisconnect(BLEServer* pServer, esp_ble_gatts_cb_param_t* param); - /** + /** * @brief Handle a new client connection. * * When the MTU changes this method is invoked. @@ -147,8 +147,8 @@ class BLEServerCallbacks { * @param [in] pServer A reference to the %BLE server that received the client connection. * @param [in] param A reference to esp_ble_gatts_cb_param_t. */ - virtual void onMtuChanged(BLEServer* pServer, esp_ble_gatts_cb_param_t* param); -}; // BLEServerCallbacks + virtual void onMtuChanged(BLEServer* pServer, esp_ble_gatts_cb_param_t* param); +}; // BLEServerCallbacks #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLEService.cpp b/libraries/BLE/src/BLEService.cpp index 554db974ca8..8ea939e756b 100644 --- a/libraries/BLE/src/BLEService.cpp +++ b/libraries/BLE/src/BLEService.cpp @@ -33,7 +33,8 @@ * @param [in] uuid The UUID of the service. * @param [in] numHandles The maximum number of handles associated with the service. */ -BLEService::BLEService(const char* uuid, uint16_t numHandles) : BLEService(BLEUUID(uuid), numHandles) { +BLEService::BLEService(const char* uuid, uint16_t numHandles) + : BLEService(BLEUUID(uuid), numHandles) { } @@ -43,13 +44,13 @@ BLEService::BLEService(const char* uuid, uint16_t numHandles) : BLEService(BLEUU * @param [in] numHandles The maximum number of handles associated with the service. */ BLEService::BLEService(BLEUUID uuid, uint16_t numHandles) { - m_uuid = uuid; - m_handle = NULL_HANDLE; - m_pServer = nullptr; - //m_serializeMutex.setName("BLEService"); - m_lastCreatedCharacteristic = nullptr; - m_numHandles = numHandles; -} // BLEService + m_uuid = uuid; + m_handle = NULL_HANDLE; + m_pServer = nullptr; + //m_serializeMutex.setName("BLEService"); + m_lastCreatedCharacteristic = nullptr; + m_numHandles = numHandles; +} // BLEService /** @@ -60,24 +61,24 @@ BLEService::BLEService(BLEUUID uuid, uint16_t numHandles) { */ void BLEService::executeCreate(BLEServer* pServer) { - log_v(">> executeCreate() - Creating service (esp_ble_gatts_create_service) service uuid: %s", getUUID().toString().c_str()); - m_pServer = pServer; - m_semaphoreCreateEvt.take("executeCreate"); // Take the mutex and release at event ESP_GATTS_CREATE_EVT + log_v(">> executeCreate() - Creating service (esp_ble_gatts_create_service) service uuid: %s", getUUID().toString().c_str()); + m_pServer = pServer; + m_semaphoreCreateEvt.take("executeCreate"); // Take the mutex and release at event ESP_GATTS_CREATE_EVT - esp_gatt_srvc_id_t srvc_id; - srvc_id.is_primary = true; - srvc_id.id.inst_id = m_instId; - srvc_id.id.uuid = *m_uuid.getNative(); - esp_err_t errRc = ::esp_ble_gatts_create_service(getServer()->getGattsIf(), &srvc_id, m_numHandles); // The maximum number of handles associated with the service. + esp_gatt_srvc_id_t srvc_id; + srvc_id.is_primary = true; + srvc_id.id.inst_id = m_instId; + srvc_id.id.uuid = *m_uuid.getNative(); + esp_err_t errRc = ::esp_ble_gatts_create_service(getServer()->getGattsIf(), &srvc_id, m_numHandles); // The maximum number of handles associated with the service. - if (errRc != ESP_OK) { - log_e("esp_ble_gatts_create_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } + if (errRc != ESP_OK) { + log_e("esp_ble_gatts_create_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } - m_semaphoreCreateEvt.wait("executeCreate"); - log_v("<< executeCreate"); -} // executeCreate + m_semaphoreCreateEvt.wait("executeCreate"); + log_v("<< executeCreate"); +} // executeCreate /** @@ -87,19 +88,19 @@ void BLEService::executeCreate(BLEServer* pServer) { */ void BLEService::executeDelete() { - log_v(">> executeDelete()"); - m_semaphoreDeleteEvt.take("executeDelete"); // Take the mutex and release at event ESP_GATTS_DELETE_EVT + log_v(">> executeDelete()"); + m_semaphoreDeleteEvt.take("executeDelete"); // Take the mutex and release at event ESP_GATTS_DELETE_EVT - esp_err_t errRc = ::esp_ble_gatts_delete_service(getHandle()); + esp_err_t errRc = ::esp_ble_gatts_delete_service(getHandle()); - if (errRc != ESP_OK) { - log_e("esp_ble_gatts_delete_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } + if (errRc != ESP_OK) { + log_e("esp_ble_gatts_delete_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } - m_semaphoreDeleteEvt.wait("executeDelete"); - log_v("<< executeDelete"); -} // executeDelete + m_semaphoreDeleteEvt.wait("executeDelete"); + log_v("<< executeDelete"); +} // executeDelete /** @@ -107,11 +108,11 @@ void BLEService::executeDelete() { * @return N/A. */ void BLEService::dump() { - log_d("Service: uuid:%s, handle: 0x%.2x", - m_uuid.toString().c_str(), - m_handle); - log_d("Characteristics:\n%s", m_characteristicMap.toString().c_str()); -} // dump + log_d("Service: uuid:%s, handle: 0x%.2x", + m_uuid.toString().c_str(), + m_handle); + log_d("Characteristics:\n%s", m_characteristicMap.toString().c_str()); +} // dump /** @@ -119,8 +120,8 @@ void BLEService::dump() { * @return the UUID of the service. */ BLEUUID BLEService::getUUID() { - return m_uuid; -} // getUUID + return m_uuid; +} // getUUID /** @@ -130,63 +131,63 @@ BLEUUID BLEService::getUUID() { * @return Start the service. */ void BLEService::start() { -// We ask the BLE runtime to start the service and then create each of the characteristics. -// We start the service through its local handle which was returned in the ESP_GATTS_CREATE_EVT event -// obtained as a result of calling esp_ble_gatts_create_service(). -// - log_v(">> start(): Starting service (esp_ble_gatts_start_service): %s", toString().c_str()); - if (m_handle == NULL_HANDLE) { - log_e("<< !!! We attempted to start a service but don't know its handle!"); - return; - } + // We ask the BLE runtime to start the service and then create each of the characteristics. + // We start the service through its local handle which was returned in the ESP_GATTS_CREATE_EVT event + // obtained as a result of calling esp_ble_gatts_create_service(). + // + log_v(">> start(): Starting service (esp_ble_gatts_start_service): %s", toString().c_str()); + if (m_handle == NULL_HANDLE) { + log_e("<< !!! We attempted to start a service but don't know its handle!"); + return; + } - BLECharacteristic *pCharacteristic = m_characteristicMap.getFirst(); + BLECharacteristic* pCharacteristic = m_characteristicMap.getFirst(); - while (pCharacteristic != nullptr) { - m_lastCreatedCharacteristic = pCharacteristic; - pCharacteristic->executeCreate(this); + while (pCharacteristic != nullptr) { + m_lastCreatedCharacteristic = pCharacteristic; + pCharacteristic->executeCreate(this); - pCharacteristic = m_characteristicMap.getNext(); - } - // Start each of the characteristics ... these are found in the m_characteristicMap. + pCharacteristic = m_characteristicMap.getNext(); + } + // Start each of the characteristics ... these are found in the m_characteristicMap. - m_semaphoreStartEvt.take("start"); - esp_err_t errRc = ::esp_ble_gatts_start_service(m_handle); + m_semaphoreStartEvt.take("start"); + esp_err_t errRc = ::esp_ble_gatts_start_service(m_handle); - if (errRc != ESP_OK) { - log_e("<< esp_ble_gatts_start_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } - m_semaphoreStartEvt.wait("start"); + if (errRc != ESP_OK) { + log_e("<< esp_ble_gatts_start_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } + m_semaphoreStartEvt.wait("start"); - log_v("<< start()"); -} // start + log_v("<< start()"); +} // start /** * @brief Stop the service. */ void BLEService::stop() { -// We ask the BLE runtime to start the service and then create each of the characteristics. -// We start the service through its local handle which was returned in the ESP_GATTS_CREATE_EVT event -// obtained as a result of calling esp_ble_gatts_create_service(). - log_v(">> stop(): Stopping service (esp_ble_gatts_stop_service): %s", toString().c_str()); - if (m_handle == NULL_HANDLE) { - log_e("<< !!! We attempted to stop a service but don't know its handle!"); - return; - } + // We ask the BLE runtime to start the service and then create each of the characteristics. + // We start the service through its local handle which was returned in the ESP_GATTS_CREATE_EVT event + // obtained as a result of calling esp_ble_gatts_create_service(). + log_v(">> stop(): Stopping service (esp_ble_gatts_stop_service): %s", toString().c_str()); + if (m_handle == NULL_HANDLE) { + log_e("<< !!! We attempted to stop a service but don't know its handle!"); + return; + } - m_semaphoreStopEvt.take("stop"); - esp_err_t errRc = ::esp_ble_gatts_stop_service(m_handle); + m_semaphoreStopEvt.take("stop"); + esp_err_t errRc = ::esp_ble_gatts_stop_service(m_handle); - if (errRc != ESP_OK) { - log_e("<< esp_ble_gatts_stop_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); - return; - } - m_semaphoreStopEvt.wait("stop"); + if (errRc != ESP_OK) { + log_e("<< esp_ble_gatts_stop_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } + m_semaphoreStopEvt.wait("stop"); - log_v("<< stop()"); -} // start + log_v("<< stop()"); +} // start /** @@ -194,14 +195,14 @@ void BLEService::stop() { * @param [in] handle The handle associated with the service. */ void BLEService::setHandle(uint16_t handle) { - log_v(">> setHandle - Handle=0x%.2x, service UUID=%s)", handle, getUUID().toString().c_str()); - if (m_handle != NULL_HANDLE) { - log_e("!!! Handle is already set %.2x", m_handle); - return; - } - m_handle = handle; - log_v("<< setHandle"); -} // setHandle + log_v(">> setHandle - Handle=0x%.2x, service UUID=%s)", handle, getUUID().toString().c_str()); + if (m_handle != NULL_HANDLE) { + log_e("!!! Handle is already set %.2x", m_handle); + return; + } + m_handle = handle; + log_v("<< setHandle"); +} // setHandle /** @@ -209,8 +210,8 @@ void BLEService::setHandle(uint16_t handle) { * @return The handle associated with this service. */ uint16_t BLEService::getHandle() { - return m_handle; -} // getHandle + return m_handle; +} // getHandle /** @@ -218,27 +219,27 @@ uint16_t BLEService::getHandle() { * @param [in] pCharacteristic A pointer to the characteristic to be added. */ void BLEService::addCharacteristic(BLECharacteristic* pCharacteristic) { - // We maintain a mapping of characteristics owned by this service. These are managed by the - // BLECharacteristicMap class instance found in m_characteristicMap. We add the characteristic - // to the map and then ask the service to add the characteristic at the BLE level (ESP-IDF). + // We maintain a mapping of characteristics owned by this service. These are managed by the + // BLECharacteristicMap class instance found in m_characteristicMap. We add the characteristic + // to the map and then ask the service to add the characteristic at the BLE level (ESP-IDF). - log_v(">> addCharacteristic()"); - log_d("Adding characteristic: uuid=%s to service: %s", - pCharacteristic->getUUID().toString().c_str(), - toString().c_str()); + log_v(">> addCharacteristic()"); + log_d("Adding characteristic: uuid=%s to service: %s", + pCharacteristic->getUUID().toString().c_str(), + toString().c_str()); - // Check that we don't add the same characteristic twice. - if (m_characteristicMap.getByUUID(pCharacteristic->getUUID()) != nullptr) { - log_w("<< Adding a new characteristic with the same UUID as a previous one"); - //return; - } + // Check that we don't add the same characteristic twice. + if (m_characteristicMap.getByUUID(pCharacteristic->getUUID()) != nullptr) { + log_w("<< Adding a new characteristic with the same UUID as a previous one"); + //return; + } - // Remember this characteristic in our map of characteristics. At this point, we can lookup by UUID - // but not by handle. The handle is allocated to us on the ESP_GATTS_ADD_CHAR_EVT. - m_characteristicMap.setByUUID(pCharacteristic, pCharacteristic->getUUID()); + // Remember this characteristic in our map of characteristics. At this point, we can lookup by UUID + // but not by handle. The handle is allocated to us on the ESP_GATTS_ADD_CHAR_EVT. + m_characteristicMap.setByUUID(pCharacteristic, pCharacteristic->getUUID()); - log_v("<< addCharacteristic()"); -} // addCharacteristic + log_v("<< addCharacteristic()"); +} // addCharacteristic /** @@ -248,9 +249,9 @@ void BLEService::addCharacteristic(BLECharacteristic* pCharacteristic) { * @return The new BLE characteristic. */ BLECharacteristic* BLEService::createCharacteristic(const char* uuid, uint32_t properties) { - return createCharacteristic(BLEUUID(uuid), properties); + return createCharacteristic(BLEUUID(uuid), properties); } - + /** * @brief Create a new BLE Characteristic associated with this service. @@ -259,120 +260,125 @@ BLECharacteristic* BLEService::createCharacteristic(const char* uuid, uint32_t p * @return The new BLE characteristic. */ BLECharacteristic* BLEService::createCharacteristic(BLEUUID uuid, uint32_t properties) { - BLECharacteristic* pCharacteristic = new BLECharacteristic(uuid, properties); - addCharacteristic(pCharacteristic); - return pCharacteristic; -} // createCharacteristic + BLECharacteristic* pCharacteristic = new BLECharacteristic(uuid, properties); + addCharacteristic(pCharacteristic); + return pCharacteristic; +} // createCharacteristic /** * @brief Handle a GATTS server event. */ void BLEService::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param) { - switch (event) { - // ESP_GATTS_ADD_CHAR_EVT - Indicate that a characteristic was added to the service. - // add_char: - // - esp_gatt_status_t status - // - uint16_t attr_handle - // - uint16_t service_handle - // - esp_bt_uuid_t char_uuid - - // If we have reached the correct service, then locate the characteristic and remember the handle - // for that characteristic. - case ESP_GATTS_ADD_CHAR_EVT: { - if (m_handle == param->add_char.service_handle) { - BLECharacteristic *pCharacteristic = getLastCreatedCharacteristic(); - if (pCharacteristic == nullptr) { - log_e("Expected to find characteristic with UUID: %s, but didnt!", - BLEUUID(param->add_char.char_uuid).toString().c_str()); - dump(); - break; - } - pCharacteristic->setHandle(param->add_char.attr_handle); - m_characteristicMap.setByHandle(param->add_char.attr_handle, pCharacteristic); - break; - } // Reached the correct service. - break; - } // ESP_GATTS_ADD_CHAR_EVT - - - // ESP_GATTS_START_EVT - // - // start: - // esp_gatt_status_t status - // uint16_t service_handle - case ESP_GATTS_START_EVT: { - if (param->start.service_handle == getHandle()) { - m_semaphoreStartEvt.give(); - } - break; - } // ESP_GATTS_START_EVT - - // ESP_GATTS_STOP_EVT - // - // stop: - // esp_gatt_status_t status - // uint16_t service_handle - // - case ESP_GATTS_STOP_EVT: { - if (param->stop.service_handle == getHandle()) { - m_semaphoreStopEvt.give(); - } - break; - } // ESP_GATTS_STOP_EVT - - - // ESP_GATTS_CREATE_EVT - // Called when a new service is registered as having been created. - // - // create: - // * esp_gatt_status_t status - // * uint16_t service_handle - // * esp_gatt_srvc_id_t service_id - // * - esp_gatt_id id - // * - esp_bt_uuid uuid - // * - uint8_t inst_id - // * - bool is_primary - // - case ESP_GATTS_CREATE_EVT: { - if (getUUID().equals(BLEUUID(param->create.service_id.id.uuid)) && m_instId == param->create.service_id.id.inst_id) { - setHandle(param->create.service_handle); - m_semaphoreCreateEvt.give(); - } - break; - } // ESP_GATTS_CREATE_EVT - - - // ESP_GATTS_DELETE_EVT - // Called when a service is deleted. - // - // delete: - // * esp_gatt_status_t status - // * uint16_t service_handle - // - case ESP_GATTS_DELETE_EVT: { - if (param->del.service_handle == getHandle()) { - m_semaphoreDeleteEvt.give(); - } - break; - } // ESP_GATTS_DELETE_EVT - - default: - break; - } // Switch - - // Invoke the GATTS handler in each of the associated characteristics. - m_characteristicMap.handleGATTServerEvent(event, gatts_if, param); -} // handleGATTServerEvent + switch (event) { + // ESP_GATTS_ADD_CHAR_EVT - Indicate that a characteristic was added to the service. + // add_char: + // - esp_gatt_status_t status + // - uint16_t attr_handle + // - uint16_t service_handle + // - esp_bt_uuid_t char_uuid + + // If we have reached the correct service, then locate the characteristic and remember the handle + // for that characteristic. + case ESP_GATTS_ADD_CHAR_EVT: + { + if (m_handle == param->add_char.service_handle) { + BLECharacteristic* pCharacteristic = getLastCreatedCharacteristic(); + if (pCharacteristic == nullptr) { + log_e("Expected to find characteristic with UUID: %s, but didn't!", + BLEUUID(param->add_char.char_uuid).toString().c_str()); + dump(); + break; + } + pCharacteristic->setHandle(param->add_char.attr_handle); + m_characteristicMap.setByHandle(param->add_char.attr_handle, pCharacteristic); + break; + } // Reached the correct service. + break; + } // ESP_GATTS_ADD_CHAR_EVT + + + // ESP_GATTS_START_EVT + // + // start: + // esp_gatt_status_t status + // uint16_t service_handle + case ESP_GATTS_START_EVT: + { + if (param->start.service_handle == getHandle()) { + m_semaphoreStartEvt.give(); + } + break; + } // ESP_GATTS_START_EVT + + // ESP_GATTS_STOP_EVT + // + // stop: + // esp_gatt_status_t status + // uint16_t service_handle + // + case ESP_GATTS_STOP_EVT: + { + if (param->stop.service_handle == getHandle()) { + m_semaphoreStopEvt.give(); + } + break; + } // ESP_GATTS_STOP_EVT + + + // ESP_GATTS_CREATE_EVT + // Called when a new service is registered as having been created. + // + // create: + // * esp_gatt_status_t status + // * uint16_t service_handle + // * esp_gatt_srvc_id_t service_id + // * - esp_gatt_id id + // * - esp_bt_uuid uuid + // * - uint8_t inst_id + // * - bool is_primary + // + case ESP_GATTS_CREATE_EVT: + { + if (getUUID().equals(BLEUUID(param->create.service_id.id.uuid)) && m_instId == param->create.service_id.id.inst_id) { + setHandle(param->create.service_handle); + m_semaphoreCreateEvt.give(); + } + break; + } // ESP_GATTS_CREATE_EVT + + + // ESP_GATTS_DELETE_EVT + // Called when a service is deleted. + // + // delete: + // * esp_gatt_status_t status + // * uint16_t service_handle + // + case ESP_GATTS_DELETE_EVT: + { + if (param->del.service_handle == getHandle()) { + m_semaphoreDeleteEvt.give(); + } + break; + } // ESP_GATTS_DELETE_EVT + + default: + break; + } // Switch + + // Invoke the GATTS handler in each of the associated characteristics. + m_characteristicMap.handleGATTServerEvent(event, gatts_if, param); +} // handleGATTServerEvent BLECharacteristic* BLEService::getCharacteristic(const char* uuid) { - return getCharacteristic(BLEUUID(uuid)); + return getCharacteristic(BLEUUID(uuid)); } BLECharacteristic* BLEService::getCharacteristic(BLEUUID uuid) { - return m_characteristicMap.getByUUID(uuid); + return m_characteristicMap.getByUUID(uuid); } @@ -384,13 +390,13 @@ BLECharacteristic* BLEService::getCharacteristic(BLEUUID uuid) { * @return A string representation of this service. */ String BLEService::toString() { - String res = "UUID: " + getUUID().toString(); - char hex[5]; - snprintf(hex, sizeof(hex), "%04x", getHandle()); - res += ", handle: 0x"; - res += hex; - return res; -} // toString + String res = "UUID: " + getUUID().toString(); + char hex[5]; + snprintf(hex, sizeof(hex), "%04x", getHandle()); + res += ", handle: 0x"; + res += hex; + return res; +} // toString /** @@ -401,8 +407,8 @@ String BLEService::toString() { * @return The last created characteristic. */ BLECharacteristic* BLEService::getLastCreatedCharacteristic() { - return m_lastCreatedCharacteristic; -} // getLastCreatedCharacteristic + return m_lastCreatedCharacteristic; +} // getLastCreatedCharacteristic /** @@ -410,8 +416,8 @@ BLECharacteristic* BLEService::getLastCreatedCharacteristic() { * @return The BLEServer associated with this service. */ BLEServer* BLEService::getServer() { - return m_pServer; -} // getServer + return m_pServer; +} // getServer #endif /* CONFIG_BLUEDROID_ENABLED */ #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLEService.h b/libraries/BLE/src/BLEService.h index 2d8a03b1fba..b65981ef298 100644 --- a/libraries/BLE/src/BLEService.h +++ b/libraries/BLE/src/BLEService.h @@ -27,21 +27,21 @@ class BLEServer; */ class BLECharacteristicMap { public: - void setByUUID(BLECharacteristic* pCharacteristic, const char* uuid); - void setByUUID(BLECharacteristic* pCharacteristic, BLEUUID uuid); - void setByHandle(uint16_t handle, BLECharacteristic* pCharacteristic); - BLECharacteristic* getByUUID(const char* uuid); - BLECharacteristic* getByUUID(BLEUUID uuid); - BLECharacteristic* getByHandle(uint16_t handle); - BLECharacteristic* getFirst(); - BLECharacteristic* getNext(); - String toString(); - void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param); + void setByUUID(BLECharacteristic* pCharacteristic, const char* uuid); + void setByUUID(BLECharacteristic* pCharacteristic, BLEUUID uuid); + void setByHandle(uint16_t handle, BLECharacteristic* pCharacteristic); + BLECharacteristic* getByUUID(const char* uuid); + BLECharacteristic* getByUUID(BLEUUID uuid); + BLECharacteristic* getByHandle(uint16_t handle); + BLECharacteristic* getFirst(); + BLECharacteristic* getNext(); + String toString(); + void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param); private: - std::map m_uuidMap; - std::map m_handleMap; - std::map::iterator m_iterator; + std::map m_uuidMap; + std::map m_handleMap; + std::map::iterator m_iterator; }; @@ -51,49 +51,49 @@ class BLECharacteristicMap { */ class BLEService { public: - void addCharacteristic(BLECharacteristic* pCharacteristic); - BLECharacteristic* createCharacteristic(const char* uuid, uint32_t properties); - BLECharacteristic* createCharacteristic(BLEUUID uuid, uint32_t properties); - void dump(); - void executeCreate(BLEServer* pServer); - void executeDelete(); - BLECharacteristic* getCharacteristic(const char* uuid); - BLECharacteristic* getCharacteristic(BLEUUID uuid); - BLEUUID getUUID(); - BLEServer* getServer(); - void start(); - void stop(); - String toString(); - uint16_t getHandle(); - uint8_t m_instId = 0; + void addCharacteristic(BLECharacteristic* pCharacteristic); + BLECharacteristic* createCharacteristic(const char* uuid, uint32_t properties); + BLECharacteristic* createCharacteristic(BLEUUID uuid, uint32_t properties); + void dump(); + void executeCreate(BLEServer* pServer); + void executeDelete(); + BLECharacteristic* getCharacteristic(const char* uuid); + BLECharacteristic* getCharacteristic(BLEUUID uuid); + BLEUUID getUUID(); + BLEServer* getServer(); + void start(); + void stop(); + String toString(); + uint16_t getHandle(); + uint8_t m_instId = 0; private: - BLEService(const char* uuid, uint16_t numHandles); - BLEService(BLEUUID uuid, uint16_t numHandles); - friend class BLEServer; - friend class BLEServiceMap; - friend class BLEDescriptor; - friend class BLECharacteristic; - friend class BLEDevice; - - BLECharacteristicMap m_characteristicMap; - uint16_t m_handle; - BLECharacteristic* m_lastCreatedCharacteristic = nullptr; - BLEServer* m_pServer = nullptr; - BLEUUID m_uuid; - - FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt"); - FreeRTOS::Semaphore m_semaphoreDeleteEvt = FreeRTOS::Semaphore("DeleteEvt"); - FreeRTOS::Semaphore m_semaphoreStartEvt = FreeRTOS::Semaphore("StartEvt"); - FreeRTOS::Semaphore m_semaphoreStopEvt = FreeRTOS::Semaphore("StopEvt"); - - uint16_t m_numHandles; - - BLECharacteristic* getLastCreatedCharacteristic(); - void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param); - void setHandle(uint16_t handle); - //void setService(esp_gatt_srvc_id_t srvc_id); -}; // BLEService + BLEService(const char* uuid, uint16_t numHandles); + BLEService(BLEUUID uuid, uint16_t numHandles); + friend class BLEServer; + friend class BLEServiceMap; + friend class BLEDescriptor; + friend class BLECharacteristic; + friend class BLEDevice; + + BLECharacteristicMap m_characteristicMap; + uint16_t m_handle; + BLECharacteristic* m_lastCreatedCharacteristic = nullptr; + BLEServer* m_pServer = nullptr; + BLEUUID m_uuid; + + FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt"); + FreeRTOS::Semaphore m_semaphoreDeleteEvt = FreeRTOS::Semaphore("DeleteEvt"); + FreeRTOS::Semaphore m_semaphoreStartEvt = FreeRTOS::Semaphore("StartEvt"); + FreeRTOS::Semaphore m_semaphoreStopEvt = FreeRTOS::Semaphore("StopEvt"); + + uint16_t m_numHandles; + + BLECharacteristic* getLastCreatedCharacteristic(); + void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param); + void setHandle(uint16_t handle); + //void setService(esp_gatt_srvc_id_t srvc_id); +}; // BLEService #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLEServiceMap.cpp b/libraries/BLE/src/BLEServiceMap.cpp index eab54cf08bf..0e36ef68dbf 100644 --- a/libraries/BLE/src/BLEServiceMap.cpp +++ b/libraries/BLE/src/BLEServiceMap.cpp @@ -20,7 +20,7 @@ * @return The characteristic. */ BLEService* BLEServiceMap::getByUUID(const char* uuid) { - return getByUUID(BLEUUID(uuid)); + return getByUUID(BLEUUID(uuid)); } /** @@ -29,14 +29,14 @@ BLEService* BLEServiceMap::getByUUID(const char* uuid) { * @return The characteristic. */ BLEService* BLEServiceMap::getByUUID(BLEUUID uuid, uint8_t inst_id) { - for (auto &myPair : m_uuidMap) { - if (myPair.first->getUUID().equals(uuid)) { - return myPair.first; - } - } - //return m_uuidMap.at(uuid.toString()); - return nullptr; -} // getByUUID + for (auto& myPair : m_uuidMap) { + if (myPair.first->getUUID().equals(uuid)) { + return myPair.first; + } + } + //return m_uuidMap.at(uuid.toString()); + return nullptr; +} // getByUUID /** @@ -45,8 +45,8 @@ BLEService* BLEServiceMap::getByUUID(BLEUUID uuid, uint8_t inst_id) { * @return The service. */ BLEService* BLEServiceMap::getByHandle(uint16_t handle) { - return m_handleMap.at(handle); -} // getByHandle + return m_handleMap.at(handle); +} // getByHandle /** @@ -56,8 +56,8 @@ BLEService* BLEServiceMap::getByHandle(uint16_t handle) { * @return N/A. */ void BLEServiceMap::setByUUID(BLEUUID uuid, BLEService* service) { - m_uuidMap.insert(std::pair(service, uuid.toString())); -} // setByUUID + m_uuidMap.insert(std::pair(service, uuid.toString())); +} // setByUUID /** @@ -67,8 +67,8 @@ void BLEServiceMap::setByUUID(BLEUUID uuid, BLEService* service) { * @return N/A. */ void BLEServiceMap::setByHandle(uint16_t handle, BLEService* service) { - m_handleMap.insert(std::pair(handle, service)); -} // setByHandle + m_handleMap.insert(std::pair(handle, service)); +} // setByHandle /** @@ -76,25 +76,25 @@ void BLEServiceMap::setByHandle(uint16_t handle, BLEService* service) { * @return A string representation of the service map. */ String BLEServiceMap::toString() { - String res; - char hex[5]; - for (auto &myPair: m_handleMap) { - res += "handle: 0x"; - snprintf(hex, sizeof(hex), "%04x", myPair.first); - res += hex; - res += ", uuid: " + myPair.second->getUUID().toString() + "\n"; - } - return res; -} // toString + String res; + char hex[5]; + for (auto& myPair : m_handleMap) { + res += "handle: 0x"; + snprintf(hex, sizeof(hex), "%04x", myPair.first); + res += hex; + res += ", uuid: " + myPair.second->getUUID().toString() + "\n"; + } + return res; +} // toString void BLEServiceMap::handleGATTServerEvent( - esp_gatts_cb_event_t event, - esp_gatt_if_t gatts_if, - esp_ble_gatts_cb_param_t* param) { - // Invoke the handler for every Service we have. - for (auto &myPair : m_uuidMap) { - myPair.first->handleGATTServerEvent(event, gatts_if, param); - } + esp_gatts_cb_event_t event, + esp_gatt_if_t gatts_if, + esp_ble_gatts_cb_param_t* param) { + // Invoke the handler for every Service we have. + for (auto& myPair : m_uuidMap) { + myPair.first->handleGATTServerEvent(event, gatts_if, param); + } } /** @@ -102,39 +102,39 @@ void BLEServiceMap::handleGATTServerEvent( * @return The first service in the map. */ BLEService* BLEServiceMap::getFirst() { - m_iterator = m_uuidMap.begin(); - if (m_iterator == m_uuidMap.end()) return nullptr; - BLEService* pRet = m_iterator->first; - m_iterator++; - return pRet; -} // getFirst + m_iterator = m_uuidMap.begin(); + if (m_iterator == m_uuidMap.end()) return nullptr; + BLEService* pRet = m_iterator->first; + m_iterator++; + return pRet; +} // getFirst /** * @brief Get the next service in the map. * @return The next service in the map. */ BLEService* BLEServiceMap::getNext() { - if (m_iterator == m_uuidMap.end()) return nullptr; - BLEService* pRet = m_iterator->first; - m_iterator++; - return pRet; -} // getNext + if (m_iterator == m_uuidMap.end()) return nullptr; + BLEService* pRet = m_iterator->first; + m_iterator++; + return pRet; +} // getNext /** * @brief Removes service from maps. * @return N/A. */ void BLEServiceMap::removeService(BLEService* service) { - m_handleMap.erase(service->getHandle()); - m_uuidMap.erase(service); -} // removeService + m_handleMap.erase(service->getHandle()); + m_uuidMap.erase(service); +} // removeService /** * @brief Returns the amount of registered services * @return amount of registered services */ -int BLEServiceMap::getRegisteredServiceCount(){ - return m_handleMap.size(); +int BLEServiceMap::getRegisteredServiceCount() { + return m_handleMap.size(); } #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLEUUID.cpp b/libraries/BLE/src/BLEUUID.cpp index d34537203ed..134d55333e0 100644 --- a/libraries/BLE/src/BLEUUID.cpp +++ b/libraries/BLE/src/BLEUUID.cpp @@ -38,15 +38,15 @@ * @param [in] size The number of bytes to copy */ static void memrcpy(uint8_t* target, uint8_t* source, uint32_t size) { - assert(size > 0); - target += (size - 1); // Point target to the last byte of the target data - while (size > 0) { - *target = *source; - target--; - source++; - size--; - } -} // memrcpy + assert(size > 0); + target += (size - 1); // Point target to the last byte of the target data + while (size > 0) { + *target = *source; + target--; + source++; + size--; + } +} // memrcpy /** @@ -67,61 +67,57 @@ static void memrcpy(uint8_t* target, uint8_t* source, uint32_t size) { * @param [in] value The string to build a UUID from. */ BLEUUID::BLEUUID(String value) { - //Serial.printf("BLEUUID constructor from String=\"%s\"\n", value.c_str()); - m_valueSet = true; - if (value.length() == 4) { - m_uuid.len = ESP_UUID_LEN_16; - m_uuid.uuid.uuid16 = 0; - for(int i=0;i '9') MSB -= 7; - if(LSB > '9') LSB -= 7; - m_uuid.uuid.uuid16 += (((MSB&0x0F) <<4) | (LSB & 0x0F))<<(2-i)*4; - i+=2; - } - } - else if (value.length() == 8) { - m_uuid.len = ESP_UUID_LEN_32; - m_uuid.uuid.uuid32 = 0; - for(int i=0;i '9') MSB -= 7; - if(LSB > '9') LSB -= 7; - m_uuid.uuid.uuid32 += (((MSB&0x0F) <<4) | (LSB & 0x0F))<<(6-i)*4; - i+=2; - } - } - else if (value.length() == 16) { // How we can have 16 byte length string representing 128 bit uuid??? needs to be investigated (lack of time) - maybe raw data encoded as String (128b==16B)? - m_uuid.len = ESP_UUID_LEN_128; - memrcpy(m_uuid.uuid.uuid128, (uint8_t*)value.c_str(), 16); - } - else if (value.length() == 36) { - //log_d("36 characters:"); - // If the length of the string is 36 bytes then we will assume it is a long hex string in - // UUID format. - m_uuid.len = ESP_UUID_LEN_128; - int n = 0; - for(int i=0;i '9') MSB -= 7; - if(LSB > '9') LSB -= 7; - m_uuid.uuid.uuid128[15-n++] = ((MSB&0x0F) <<4) | (LSB & 0x0F); - i+=2; - } - } - else { - log_e("ERROR: UUID value not 2, 4, 16 or 36 bytes"); - m_valueSet = false; - } -} //BLEUUID(String) + //Serial.printf("BLEUUID constructor from String=\"%s\"\n", value.c_str()); + m_valueSet = true; + if (value.length() == 4) { + m_uuid.len = ESP_UUID_LEN_16; + m_uuid.uuid.uuid16 = 0; + for (int i = 0; i < value.length();) { + uint8_t MSB = value.c_str()[i]; + uint8_t LSB = value.c_str()[i + 1]; + + if (MSB > '9') MSB -= 7; + if (LSB > '9') LSB -= 7; + m_uuid.uuid.uuid16 += (((MSB & 0x0F) << 4) | (LSB & 0x0F)) << (2 - i) * 4; + i += 2; + } + } else if (value.length() == 8) { + m_uuid.len = ESP_UUID_LEN_32; + m_uuid.uuid.uuid32 = 0; + for (int i = 0; i < value.length();) { + uint8_t MSB = value.c_str()[i]; + uint8_t LSB = value.c_str()[i + 1]; + + if (MSB > '9') MSB -= 7; + if (LSB > '9') LSB -= 7; + m_uuid.uuid.uuid32 += (((MSB & 0x0F) << 4) | (LSB & 0x0F)) << (6 - i) * 4; + i += 2; + } + } else if (value.length() == 16) { // How we can have 16 byte length string representing 128 bit uuid??? needs to be investigated (lack of time) - maybe raw data encoded as String (128b==16B)? + m_uuid.len = ESP_UUID_LEN_128; + memrcpy(m_uuid.uuid.uuid128, (uint8_t*)value.c_str(), 16); + } else if (value.length() == 36) { + //log_d("36 characters:"); + // If the length of the string is 36 bytes then we will assume it is a long hex string in + // UUID format. + m_uuid.len = ESP_UUID_LEN_128; + int n = 0; + for (int i = 0; i < value.length();) { + if (value.c_str()[i] == '-') + i++; + uint8_t MSB = value.c_str()[i]; + uint8_t LSB = value.c_str()[i + 1]; + + if (MSB > '9') MSB -= 7; + if (LSB > '9') LSB -= 7; + m_uuid.uuid.uuid128[15 - n++] = ((MSB & 0x0F) << 4) | (LSB & 0x0F); + i += 2; + } + } else { + log_e("ERROR: UUID value not 2, 4, 16 or 36 bytes"); + m_valueSet = false; + } +} //BLEUUID(String) /* BLEUUID::BLEUUID(String value) { @@ -137,18 +133,18 @@ BLEUUID::BLEUUID(String value) { * @param [in] msbFirst Is the MSB first in pData memory? */ BLEUUID::BLEUUID(uint8_t* pData, size_t size, bool msbFirst) { - if (size != 16) { - log_e("ERROR: UUID length not 16 bytes"); - return; - } - m_uuid.len = ESP_UUID_LEN_128; - if (msbFirst) { - memrcpy(m_uuid.uuid.uuid128, pData, 16); - } else { - memcpy(m_uuid.uuid.uuid128, pData, 16); - } - m_valueSet = true; -} // BLEUUID + if (size != 16) { + log_e("ERROR: UUID length not 16 bytes"); + return; + } + m_uuid.len = ESP_UUID_LEN_128; + if (msbFirst) { + memrcpy(m_uuid.uuid.uuid128, pData, 16); + } else { + memcpy(m_uuid.uuid.uuid128, pData, 16); + } + m_valueSet = true; +} // BLEUUID /** @@ -157,10 +153,10 @@ BLEUUID::BLEUUID(uint8_t* pData, size_t size, bool msbFirst) { * @param [in] uuid The 16bit short form UUID. */ BLEUUID::BLEUUID(uint16_t uuid) { - m_uuid.len = ESP_UUID_LEN_16; - m_uuid.uuid.uuid16 = uuid; - m_valueSet = true; -} // BLEUUID + m_uuid.len = ESP_UUID_LEN_16; + m_uuid.uuid.uuid16 = uuid; + m_valueSet = true; +} // BLEUUID /** @@ -169,10 +165,10 @@ BLEUUID::BLEUUID(uint16_t uuid) { * @param [in] uuid The 32bit short form UUID. */ BLEUUID::BLEUUID(uint32_t uuid) { - m_uuid.len = ESP_UUID_LEN_32; - m_uuid.uuid.uuid32 = uuid; - m_valueSet = true; -} // BLEUUID + m_uuid.len = ESP_UUID_LEN_32; + m_uuid.uuid.uuid32 = uuid; + m_valueSet = true; +} // BLEUUID /** @@ -181,9 +177,9 @@ BLEUUID::BLEUUID(uint32_t uuid) { * @param [in] uuid The native UUID. */ BLEUUID::BLEUUID(esp_bt_uuid_t uuid) { - m_uuid = uuid; - m_valueSet = true; -} // BLEUUID + m_uuid = uuid; + m_valueSet = true; +} // BLEUUID /** @@ -191,13 +187,14 @@ BLEUUID::BLEUUID(esp_bt_uuid_t uuid) { * * @param [in] gattId The data to create the UUID from. */ -BLEUUID::BLEUUID(esp_gatt_id_t gattId) : BLEUUID(gattId.uuid) { -} // BLEUUID +BLEUUID::BLEUUID(esp_gatt_id_t gattId) + : BLEUUID(gattId.uuid) { +} // BLEUUID BLEUUID::BLEUUID() { - m_valueSet = false; -} // BLEUUID + m_valueSet = false; +} // BLEUUID /** @@ -205,19 +202,19 @@ BLEUUID::BLEUUID() { * @return The number of bits in the UUID. One of 16, 32 or 128. */ uint8_t BLEUUID::bitSize() { - if (!m_valueSet) return 0; - switch (m_uuid.len) { - case ESP_UUID_LEN_16: - return 16; - case ESP_UUID_LEN_32: - return 32; - case ESP_UUID_LEN_128: - return 128; - default: - log_e("Unknown UUID length: %d", m_uuid.len); - return 0; - } // End of switch -} // bitSize + if (!m_valueSet) return 0; + switch (m_uuid.len) { + case ESP_UUID_LEN_16: + return 16; + case ESP_UUID_LEN_32: + return 32; + case ESP_UUID_LEN_128: + return 128; + default: + log_e("Unknown UUID length: %d", m_uuid.len); + return 0; + } // End of switch +} // bitSize /** @@ -227,23 +224,23 @@ uint8_t BLEUUID::bitSize() { * @return True if the UUIDs are equal and false otherwise. */ bool BLEUUID::equals(BLEUUID uuid) { - //log_d("Comparing: %s to %s", toString().c_str(), uuid.toString().c_str()); - if (!m_valueSet || !uuid.m_valueSet) return false; + //log_d("Comparing: %s to %s", toString().c_str(), uuid.toString().c_str()); + if (!m_valueSet || !uuid.m_valueSet) return false; - if (uuid.m_uuid.len != m_uuid.len) { - return uuid.toString() == toString(); - } + if (uuid.m_uuid.len != m_uuid.len) { + return uuid.toString() == toString(); + } - if (uuid.m_uuid.len == ESP_UUID_LEN_16) { - return uuid.m_uuid.uuid.uuid16 == m_uuid.uuid.uuid16; - } + if (uuid.m_uuid.len == ESP_UUID_LEN_16) { + return uuid.m_uuid.uuid.uuid16 == m_uuid.uuid.uuid16; + } - if (uuid.m_uuid.len == ESP_UUID_LEN_32) { - return uuid.m_uuid.uuid.uuid32 == m_uuid.uuid.uuid32; - } + if (uuid.m_uuid.len == ESP_UUID_LEN_32) { + return uuid.m_uuid.uuid.uuid32 == m_uuid.uuid.uuid32; + } - return memcmp(uuid.m_uuid.uuid.uuid128, m_uuid.uuid.uuid128, 16) == 0; -} // equals + return memcmp(uuid.m_uuid.uuid.uuid128, m_uuid.uuid.uuid128, 16) == 0; +} // equals /** @@ -256,23 +253,23 @@ bool BLEUUID::equals(BLEUUID uuid) { * */ BLEUUID BLEUUID::fromString(String _uuid) { - uint8_t start = 0; - if (strstr(_uuid.c_str(), "0x") != nullptr) { // If the string starts with 0x, skip those characters. - start = 2; - } - uint8_t len = _uuid.length() - start; // Calculate the length of the string we are going to use. - - if(len == 4) { - uint16_t x = strtoul(_uuid.substring(start, start+len).c_str(), NULL, 16); - return BLEUUID(x); - } else if (len == 8) { - uint32_t x = strtoul(_uuid.substring(start, start+len).c_str(), NULL, 16); - return BLEUUID(x); - } else if (len == 36) { - return BLEUUID(_uuid); - } - return BLEUUID(); -} // fromString + uint8_t start = 0; + if (strstr(_uuid.c_str(), "0x") != nullptr) { // If the string starts with 0x, skip those characters. + start = 2; + } + uint8_t len = _uuid.length() - start; // Calculate the length of the string we are going to use. + + if (len == 4) { + uint16_t x = strtoul(_uuid.substring(start, start + len).c_str(), NULL, 16); + return BLEUUID(x); + } else if (len == 8) { + uint32_t x = strtoul(_uuid.substring(start, start + len).c_str(), NULL, 16); + return BLEUUID(x); + } else if (len == 36) { + return BLEUUID(_uuid); + } + return BLEUUID(); +} // fromString /** @@ -281,14 +278,14 @@ BLEUUID BLEUUID::fromString(String _uuid) { * @return The native UUID value or NULL if not set. */ esp_bt_uuid_t* BLEUUID::getNative() { - //log_d(">> getNative()") - if (m_valueSet == false) { - log_v("<< Return of un-initialized UUID!"); - return nullptr; - } - //log_d("<< getNative()"); - return &m_uuid; -} // getNative + //log_d(">> getNative()") + if (m_valueSet == false) { + log_v("<< Return of un-initialized UUID!"); + return nullptr; + } + //log_d("<< getNative()"); + return &m_uuid; +} // getNative /** @@ -298,51 +295,50 @@ esp_bt_uuid_t* BLEUUID::getNative() { * will convert 16 or 32 bit representations to the full 128bit. */ BLEUUID BLEUUID::to128() { - //log_v(">> toFull() - %s", toString().c_str()); + //log_v(">> toFull() - %s", toString().c_str()); - // If we either don't have a value or are already a 128 bit UUID, nothing further to do. - if (!m_valueSet || m_uuid.len == ESP_UUID_LEN_128) { - return *this; - } + // If we either don't have a value or are already a 128 bit UUID, nothing further to do. + if (!m_valueSet || m_uuid.len == ESP_UUID_LEN_128) { + return *this; + } - // If we are 16 bit or 32 bit, then set the 4 bytes of the variable part of the UUID. - if (m_uuid.len == ESP_UUID_LEN_16) { - uint16_t temp = m_uuid.uuid.uuid16; - m_uuid.uuid.uuid128[15] = 0; - m_uuid.uuid.uuid128[14] = 0; - m_uuid.uuid.uuid128[13] = (temp >> 8) & 0xff; - m_uuid.uuid.uuid128[12] = temp & 0xff; + // If we are 16 bit or 32 bit, then set the 4 bytes of the variable part of the UUID. + if (m_uuid.len == ESP_UUID_LEN_16) { + uint16_t temp = m_uuid.uuid.uuid16; + m_uuid.uuid.uuid128[15] = 0; + m_uuid.uuid.uuid128[14] = 0; + m_uuid.uuid.uuid128[13] = (temp >> 8) & 0xff; + m_uuid.uuid.uuid128[12] = temp & 0xff; - } - else if (m_uuid.len == ESP_UUID_LEN_32) { - uint32_t temp = m_uuid.uuid.uuid32; - m_uuid.uuid.uuid128[15] = (temp >> 24) & 0xff; - m_uuid.uuid.uuid128[14] = (temp >> 16) & 0xff; - m_uuid.uuid.uuid128[13] = (temp >> 8) & 0xff; - m_uuid.uuid.uuid128[12] = temp & 0xff; - } + } else if (m_uuid.len == ESP_UUID_LEN_32) { + uint32_t temp = m_uuid.uuid.uuid32; + m_uuid.uuid.uuid128[15] = (temp >> 24) & 0xff; + m_uuid.uuid.uuid128[14] = (temp >> 16) & 0xff; + m_uuid.uuid.uuid128[13] = (temp >> 8) & 0xff; + m_uuid.uuid.uuid128[12] = temp & 0xff; + } - // Set the fixed parts of the UUID. - m_uuid.uuid.uuid128[11] = 0x00; - m_uuid.uuid.uuid128[10] = 0x00; + // Set the fixed parts of the UUID. + m_uuid.uuid.uuid128[11] = 0x00; + m_uuid.uuid.uuid128[10] = 0x00; - m_uuid.uuid.uuid128[9] = 0x10; - m_uuid.uuid.uuid128[8] = 0x00; + m_uuid.uuid.uuid128[9] = 0x10; + m_uuid.uuid.uuid128[8] = 0x00; - m_uuid.uuid.uuid128[7] = 0x80; - m_uuid.uuid.uuid128[6] = 0x00; + m_uuid.uuid.uuid128[7] = 0x80; + m_uuid.uuid.uuid128[6] = 0x00; - m_uuid.uuid.uuid128[5] = 0x00; - m_uuid.uuid.uuid128[4] = 0x80; - m_uuid.uuid.uuid128[3] = 0x5f; - m_uuid.uuid.uuid128[2] = 0x9b; - m_uuid.uuid.uuid128[1] = 0x34; - m_uuid.uuid.uuid128[0] = 0xfb; + m_uuid.uuid.uuid128[5] = 0x00; + m_uuid.uuid.uuid128[4] = 0x80; + m_uuid.uuid.uuid128[3] = 0x5f; + m_uuid.uuid.uuid128[2] = 0x9b; + m_uuid.uuid.uuid128[1] = 0x34; + m_uuid.uuid.uuid128[0] = 0xfb; - m_uuid.len = ESP_UUID_LEN_128; - //log_d("<< toFull <- %s", toString().c_str()); - return *this; -} // to128 + m_uuid.len = ESP_UUID_LEN_128; + //log_d("<< toFull <- %s", toString().c_str()); + return *this; +} // to128 @@ -358,40 +354,40 @@ BLEUUID BLEUUID::to128() { * @return A string representation of the UUID. */ String BLEUUID::toString() { - if (!m_valueSet) return ""; // If we have no value, nothing to format. - // If the UUIDs are 16 or 32 bit, pad correctly. - - if (m_uuid.len == ESP_UUID_LEN_16) { // If the UUID is 16bit, pad correctly. - char hex[9]; - snprintf(hex, sizeof(hex), "%08x", m_uuid.uuid.uuid16); - return String(hex) + "-0000-1000-8000-00805f9b34fb"; - } // End 16bit UUID - - if (m_uuid.len == ESP_UUID_LEN_32) { // If the UUID is 32bit, pad correctly. - char hex[9]; - snprintf(hex, sizeof(hex), "%08lx", m_uuid.uuid.uuid32); - return String(hex) + "-0000-1000-8000-00805f9b34fb"; - } // End 32bit UUID - - // The UUID is not 16bit or 32bit which means that it is 128bit. - // - // UUID string format: - // AABBCCDD-EEFF-GGHH-IIJJ-KKLLMMNNOOPP - auto size = 37; // 32 for UUID data, 4 for '-' delimiters and one for a terminator == 37 chars - char *hex = (char *)malloc(size); - snprintf(hex, size, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", - m_uuid.uuid.uuid128[15], m_uuid.uuid.uuid128[14], - m_uuid.uuid.uuid128[13], m_uuid.uuid.uuid128[12], - m_uuid.uuid.uuid128[11], m_uuid.uuid.uuid128[10], - m_uuid.uuid.uuid128[9], m_uuid.uuid.uuid128[8], - m_uuid.uuid.uuid128[7], m_uuid.uuid.uuid128[6], - m_uuid.uuid.uuid128[5], m_uuid.uuid.uuid128[4], - m_uuid.uuid.uuid128[3], m_uuid.uuid.uuid128[2], - m_uuid.uuid.uuid128[1], m_uuid.uuid.uuid128[0]); - String res(hex); - free(hex); - return res; -} // toString + if (!m_valueSet) return ""; // If we have no value, nothing to format. + // If the UUIDs are 16 or 32 bit, pad correctly. + + if (m_uuid.len == ESP_UUID_LEN_16) { // If the UUID is 16bit, pad correctly. + char hex[9]; + snprintf(hex, sizeof(hex), "%08x", m_uuid.uuid.uuid16); + return String(hex) + "-0000-1000-8000-00805f9b34fb"; + } // End 16bit UUID + + if (m_uuid.len == ESP_UUID_LEN_32) { // If the UUID is 32bit, pad correctly. + char hex[9]; + snprintf(hex, sizeof(hex), "%08lx", m_uuid.uuid.uuid32); + return String(hex) + "-0000-1000-8000-00805f9b34fb"; + } // End 32bit UUID + + // The UUID is not 16bit or 32bit which means that it is 128bit. + // + // UUID string format: + // AABBCCDD-EEFF-GGHH-IIJJ-KKLLMMNNOOPP + auto size = 37; // 32 for UUID data, 4 for '-' delimiters and one for a terminator == 37 chars + char* hex = (char*)malloc(size); + snprintf(hex, size, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", + m_uuid.uuid.uuid128[15], m_uuid.uuid.uuid128[14], + m_uuid.uuid.uuid128[13], m_uuid.uuid.uuid128[12], + m_uuid.uuid.uuid128[11], m_uuid.uuid.uuid128[10], + m_uuid.uuid.uuid128[9], m_uuid.uuid.uuid128[8], + m_uuid.uuid.uuid128[7], m_uuid.uuid.uuid128[6], + m_uuid.uuid.uuid128[5], m_uuid.uuid.uuid128[4], + m_uuid.uuid.uuid128[3], m_uuid.uuid.uuid128[2], + m_uuid.uuid.uuid128[1], m_uuid.uuid.uuid128[0]); + String res(hex); + free(hex); + return res; +} // toString #endif /* CONFIG_BLUEDROID_ENABLED */ #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLEUUID.h b/libraries/BLE/src/BLEUUID.h index 7101f0e0fa2..b8677984851 100644 --- a/libraries/BLE/src/BLEUUID.h +++ b/libraries/BLE/src/BLEUUID.h @@ -27,17 +27,17 @@ class BLEUUID { BLEUUID(uint8_t* pData, size_t size, bool msbFirst); BLEUUID(esp_gatt_id_t gattId); BLEUUID(); - uint8_t bitSize(); // Get the number of bits in this uuid. - bool equals(BLEUUID uuid); + uint8_t bitSize(); // Get the number of bits in this uuid. + bool equals(BLEUUID uuid); esp_bt_uuid_t* getNative(); - BLEUUID to128(); - String toString(); + BLEUUID to128(); + String toString(); static BLEUUID fromString(String uuid); // Create a BLEUUID from a string private: - esp_bt_uuid_t m_uuid; // The underlying UUID structure that this class wraps. - bool m_valueSet = false; // Is there a value set for this instance. -}; // BLEUUID + esp_bt_uuid_t m_uuid; // The underlying UUID structure that this class wraps. + bool m_valueSet = false; // Is there a value set for this instance. +}; // BLEUUID #endif /* CONFIG_BLUEDROID_ENABLED */ #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLEUtils.cpp b/libraries/BLE/src/BLEUtils.cpp index c226a13e663..6ad4dae3c62 100644 --- a/libraries/BLE/src/BLEUtils.cpp +++ b/libraries/BLE/src/BLEUtils.cpp @@ -17,537 +17,537 @@ #include #include -#include // ESP32 BLE -#include // ESP32 BLE -#include // ESP32 BLE -#include // ESP32 BLE -#include // ESP32 ESP-IDF -#include // Part of C++ STL +#include // ESP32 BLE +#include // ESP32 BLE +#include // ESP32 BLE +#include // ESP32 BLE +#include // ESP32 ESP-IDF +#include // Part of C++ STL #include #include #include "esp32-hal-log.h" typedef struct { - uint32_t assignedNumber; - const char* name; + uint32_t assignedNumber; + const char* name; } member_t; static const member_t members_ids[] = { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - {0xFE08, "Microsoft"}, - {0xFE09, "Pillsy, Inc."}, - {0xFE0A, "ruwido austria gmbh"}, - {0xFE0B, "ruwido austria gmbh"}, - {0xFE0C, "Procter & Gamble"}, - {0xFE0D, "Procter & Gamble"}, - {0xFE0E, "Setec Pty Ltd"}, - {0xFE0F, "Philips Lighting B.V."}, - {0xFE10, "Lapis Semiconductor Co., Ltd."}, - {0xFE11, "GMC-I Messtechnik GmbH"}, - {0xFE12, "M-Way Solutions GmbH"}, - {0xFE13, "Apple Inc."}, - {0xFE14, "Flextronics International USA Inc."}, - {0xFE15, "Amazon Fulfillment Services, Inc."}, - {0xFE16, "Footmarks, Inc."}, - {0xFE17, "Telit Wireless Solutions GmbH"}, - {0xFE18, "Runtime, Inc."}, - {0xFE19, "Google Inc."}, - {0xFE1A, "Tyto Life LLC"}, - {0xFE1B, "Tyto Life LLC"}, - {0xFE1C, "NetMedia, Inc."}, - {0xFE1D, "Illuminati Instrument Corporation"}, - {0xFE1E, "Smart Innovations Co., Ltd"}, - {0xFE1F, "Garmin International, Inc."}, - {0xFE20, "Emerson"}, - {0xFE21, "Bose Corporation"}, - {0xFE22, "Zoll Medical Corporation"}, - {0xFE23, "Zoll Medical Corporation"}, - {0xFE24, "August Home Inc"}, - {0xFE25, "Apple, Inc. "}, - {0xFE26, "Google Inc."}, - {0xFE27, "Google Inc."}, - {0xFE28, "Ayla Networks"}, - {0xFE29, "Gibson Innovations"}, - {0xFE2A, "DaisyWorks, Inc."}, - {0xFE2B, "ITT Industries"}, - {0xFE2C, "Google Inc."}, - {0xFE2D, "SMART INNOVATION Co.,Ltd"}, - {0xFE2E, "ERi,Inc."}, - {0xFE2F, "CRESCO Wireless, Inc"}, - {0xFE30, "Volkswagen AG"}, - {0xFE31, "Volkswagen AG"}, - {0xFE32, "Pro-Mark, Inc."}, - {0xFE33, "CHIPOLO d.o.o."}, - {0xFE34, "SmallLoop LLC"}, - {0xFE35, "HUAWEI Technologies Co., Ltd"}, - {0xFE36, "HUAWEI Technologies Co., Ltd"}, - {0xFE37, "Spaceek LTD"}, - {0xFE38, "Spaceek LTD"}, - {0xFE39, "TTS Tooltechnic Systems AG & Co. KG"}, - {0xFE3A, "TTS Tooltechnic Systems AG & Co. KG"}, - {0xFE3B, "Dolby Laboratories"}, - {0xFE3C, "Alibaba"}, - {0xFE3D, "BD Medical"}, - {0xFE3E, "BD Medical"}, - {0xFE3F, "Friday Labs Limited"}, - {0xFE40, "Inugo Systems Limited"}, - {0xFE41, "Inugo Systems Limited"}, - {0xFE42, "Nets A/S "}, - {0xFE43, "Andreas Stihl AG & Co. KG"}, - {0xFE44, "SK Telecom "}, - {0xFE45, "Snapchat Inc"}, - {0xFE46, "B&O Play A/S "}, - {0xFE47, "General Motors"}, - {0xFE48, "General Motors"}, - {0xFE49, "SenionLab AB"}, - {0xFE4A, "OMRON HEALTHCARE Co., Ltd."}, - {0xFE4B, "Philips Lighting B.V."}, - {0xFE4C, "Volkswagen AG"}, - {0xFE4D, "Casambi Technologies Oy"}, - {0xFE4E, "NTT docomo"}, - {0xFE4F, "Molekule, Inc."}, - {0xFE50, "Google Inc."}, - {0xFE51, "SRAM"}, - {0xFE52, "SetPoint Medical"}, - {0xFE53, "3M"}, - {0xFE54, "Motiv, Inc."}, - {0xFE55, "Google Inc."}, - {0xFE56, "Google Inc."}, - {0xFE57, "Dotted Labs"}, - {0xFE58, "Nordic Semiconductor ASA"}, - {0xFE59, "Nordic Semiconductor ASA"}, - {0xFE5A, "Chronologics Corporation"}, - {0xFE5B, "GT-tronics HK Ltd"}, - {0xFE5C, "million hunters GmbH"}, - {0xFE5D, "Grundfos A/S"}, - {0xFE5E, "Plastc Corporation"}, - {0xFE5F, "Eyefi, Inc."}, - {0xFE60, "Lierda Science & Technology Group Co., Ltd."}, - {0xFE61, "Logitech International SA"}, - {0xFE62, "Indagem Tech LLC"}, - {0xFE63, "Connected Yard, Inc."}, - {0xFE64, "Siemens AG"}, - {0xFE65, "CHIPOLO d.o.o."}, - {0xFE66, "Intel Corporation"}, - {0xFE67, "Lab Sensor Solutions"}, - {0xFE68, "Qualcomm Life Inc"}, - {0xFE69, "Qualcomm Life Inc"}, - {0xFE6A, "Kontakt Micro-Location Sp. z o.o."}, - {0xFE6B, "TASER International, Inc."}, - {0xFE6C, "TASER International, Inc."}, - {0xFE6D, "The University of Tokyo"}, - {0xFE6E, "The University of Tokyo"}, - {0xFE6F, "LINE Corporation"}, - {0xFE70, "Beijing Jingdong Century Trading Co., Ltd."}, - {0xFE71, "Plume Design Inc"}, - {0xFE72, "St. Jude Medical, Inc."}, - {0xFE73, "St. Jude Medical, Inc."}, - {0xFE74, "unwire"}, - {0xFE75, "TangoMe"}, - {0xFE76, "TangoMe"}, - {0xFE77, "Hewlett-Packard Company"}, - {0xFE78, "Hewlett-Packard Company"}, - {0xFE79, "Zebra Technologies"}, - {0xFE7A, "Bragi GmbH"}, - {0xFE7B, "Orion Labs, Inc."}, - {0xFE7C, "Telit Wireless Solutions (Formerly Stollmann E+V GmbH)"}, - {0xFE7D, "Aterica Health Inc."}, - {0xFE7E, "Awear Solutions Ltd"}, - {0xFE7F, "Doppler Lab"}, - {0xFE80, "Doppler Lab"}, - {0xFE81, "Medtronic Inc."}, - {0xFE82, "Medtronic Inc."}, - {0xFE83, "Blue Bite"}, - {0xFE84, "RF Digital Corp"}, - {0xFE85, "RF Digital Corp"}, - {0xFE86, "HUAWEI Technologies Co., Ltd. ( )"}, - {0xFE87, "Qingdao Yeelink Information Technology Co., Ltd. ( )"}, - {0xFE88, "SALTO SYSTEMS S.L."}, - {0xFE89, "B&O Play A/S"}, - {0xFE8A, "Apple, Inc."}, - {0xFE8B, "Apple, Inc."}, - {0xFE8C, "TRON Forum"}, - {0xFE8D, "Interaxon Inc."}, - {0xFE8E, "ARM Ltd"}, - {0xFE8F, "CSR"}, - {0xFE90, "JUMA"}, - {0xFE91, "Shanghai Imilab Technology Co.,Ltd"}, - {0xFE92, "Jarden Safety & Security"}, - {0xFE93, "OttoQ Inc."}, - {0xFE94, "OttoQ Inc."}, - {0xFE95, "Xiaomi Inc."}, - {0xFE96, "Tesla Motor Inc."}, - {0xFE97, "Tesla Motor Inc."}, - {0xFE98, "Currant, Inc."}, - {0xFE99, "Currant, Inc."}, - {0xFE9A, "Estimote"}, - {0xFE9B, "Samsara Networks, Inc"}, - {0xFE9C, "GSI Laboratories, Inc."}, - {0xFE9D, "Mobiquity Networks Inc"}, - {0xFE9E, "Dialog Semiconductor B.V."}, - {0xFE9F, "Google Inc."}, - {0xFEA0, "Google Inc."}, - {0xFEA1, "Intrepid Control Systems, Inc."}, - {0xFEA2, "Intrepid Control Systems, Inc."}, - {0xFEA3, "ITT Industries"}, - {0xFEA4, "Paxton Access Ltd"}, - {0xFEA5, "GoPro, Inc."}, - {0xFEA6, "GoPro, Inc."}, - {0xFEA7, "UTC Fire and Security"}, - {0xFEA8, "Savant Systems LLC"}, - {0xFEA9, "Savant Systems LLC"}, - {0xFEAA, "Google Inc."}, - {0xFEAB, "Nokia Corporation"}, - {0xFEAC, "Nokia Corporation"}, - {0xFEAD, "Nokia Corporation"}, - {0xFEAE, "Nokia Corporation"}, - {0xFEAF, "Nest Labs Inc."}, - {0xFEB0, "Nest Labs Inc."}, - {0xFEB1, "Electronics Tomorrow Limited"}, - {0xFEB2, "Microsoft Corporation"}, - {0xFEB3, "Taobao"}, - {0xFEB4, "WiSilica Inc."}, - {0xFEB5, "WiSilica Inc."}, - {0xFEB6, "Vencer Co, Ltd"}, - {0xFEB7, "Facebook, Inc."}, - {0xFEB8, "Facebook, Inc."}, - {0xFEB9, "LG Electronics"}, - {0xFEBA, "Tencent Holdings Limited"}, - {0xFEBB, "adafruit industries"}, - {0xFEBC, "Dexcom, Inc. "}, - {0xFEBD, "Clover Network, Inc."}, - {0xFEBE, "Bose Corporation"}, - {0xFEBF, "Nod, Inc."}, - {0xFEC0, "KDDI Corporation"}, - {0xFEC1, "KDDI Corporation"}, - {0xFEC2, "Blue Spark Technologies, Inc."}, - {0xFEC3, "360fly, Inc."}, - {0xFEC4, "PLUS Location Systems"}, - {0xFEC5, "Realtek Semiconductor Corp."}, - {0xFEC6, "Kocomojo, LLC"}, - {0xFEC7, "Apple, Inc."}, - {0xFEC8, "Apple, Inc."}, - {0xFEC9, "Apple, Inc."}, - {0xFECA, "Apple, Inc."}, - {0xFECB, "Apple, Inc."}, - {0xFECC, "Apple, Inc."}, - {0xFECD, "Apple, Inc."}, - {0xFECE, "Apple, Inc."}, - {0xFECF, "Apple, Inc."}, - {0xFED0, "Apple, Inc."}, - {0xFED1, "Apple, Inc."}, - {0xFED2, "Apple, Inc."}, - {0xFED3, "Apple, Inc."}, - {0xFED4, "Apple, Inc."}, - {0xFED5, "Plantronics Inc."}, - {0xFED6, "Broadcom Corporation"}, - {0xFED7, "Broadcom Corporation"}, - {0xFED8, "Google Inc."}, - {0xFED9, "Pebble Technology Corporation"}, - {0xFEDA, "ISSC Technologies Corporation"}, - {0xFEDB, "Perka, Inc."}, - {0xFEDC, "Jawbone"}, - {0xFEDD, "Jawbone"}, - {0xFEDE, "Coin, Inc."}, - {0xFEDF, "Design SHIFT"}, - {0xFEE0, "Anhui Huami Information Technology Co."}, - {0xFEE1, "Anhui Huami Information Technology Co."}, - {0xFEE2, "Anki, Inc."}, - {0xFEE3, "Anki, Inc."}, - {0xFEE4, "Nordic Semiconductor ASA"}, - {0xFEE5, "Nordic Semiconductor ASA"}, - {0xFEE6, "Silvair, Inc."}, - {0xFEE7, "Tencent Holdings Limited"}, - {0xFEE8, "Quintic Corp."}, - {0xFEE9, "Quintic Corp."}, - {0xFEEA, "Swirl Networks, Inc."}, - {0xFEEB, "Swirl Networks, Inc."}, - {0xFEEC, "Tile, Inc."}, - {0xFEED, "Tile, Inc."}, - {0xFEEE, "Polar Electro Oy"}, - {0xFEEF, "Polar Electro Oy"}, - {0xFEF0, "Intel"}, - {0xFEF1, "CSR"}, - {0xFEF2, "CSR"}, - {0xFEF3, "Google Inc."}, - {0xFEF4, "Google Inc."}, - {0xFEF5, "Dialog Semiconductor GmbH"}, - {0xFEF6, "Wicentric, Inc."}, - {0xFEF7, "Aplix Corporation"}, - {0xFEF8, "Aplix Corporation"}, - {0xFEF9, "PayPal, Inc."}, - {0xFEFA, "PayPal, Inc."}, - {0xFEFB, "Telit Wireless Solutions (Formerly Stollmann E+V GmbH)"}, - {0xFEFC, "Gimbal, Inc."}, - {0xFEFD, "Gimbal, Inc."}, - {0xFEFE, "GN ReSound A/S"}, - {0xFEFF, "GN Netcom"}, - {0xFFFF, "Reserved"}, /*for testing purposes only*/ + { 0xFE08, "Microsoft" }, + { 0xFE09, "Pillsy, Inc." }, + { 0xFE0A, "ruwido austria gmbh" }, + { 0xFE0B, "ruwido austria gmbh" }, + { 0xFE0C, "Procter & Gamble" }, + { 0xFE0D, "Procter & Gamble" }, + { 0xFE0E, "Setec Pty Ltd" }, + { 0xFE0F, "Philips Lighting B.V." }, + { 0xFE10, "Lapis Semiconductor Co., Ltd." }, + { 0xFE11, "GMC-I Messtechnik GmbH" }, + { 0xFE12, "M-Way Solutions GmbH" }, + { 0xFE13, "Apple Inc." }, + { 0xFE14, "Flextronics International USA Inc." }, + { 0xFE15, "Amazon Fulfillment Services, Inc." }, + { 0xFE16, "Footmarks, Inc." }, + { 0xFE17, "Telit Wireless Solutions GmbH" }, + { 0xFE18, "Runtime, Inc." }, + { 0xFE19, "Google Inc." }, + { 0xFE1A, "Tyto Life LLC" }, + { 0xFE1B, "Tyto Life LLC" }, + { 0xFE1C, "NetMedia, Inc." }, + { 0xFE1D, "Illuminati Instrument Corporation" }, + { 0xFE1E, "Smart Innovations Co., Ltd" }, + { 0xFE1F, "Garmin International, Inc." }, + { 0xFE20, "Emerson" }, + { 0xFE21, "Bose Corporation" }, + { 0xFE22, "Zoll Medical Corporation" }, + { 0xFE23, "Zoll Medical Corporation" }, + { 0xFE24, "August Home Inc" }, + { 0xFE25, "Apple, Inc. " }, + { 0xFE26, "Google Inc." }, + { 0xFE27, "Google Inc." }, + { 0xFE28, "Ayla Networks" }, + { 0xFE29, "Gibson Innovations" }, + { 0xFE2A, "DaisyWorks, Inc." }, + { 0xFE2B, "ITT Industries" }, + { 0xFE2C, "Google Inc." }, + { 0xFE2D, "SMART INNOVATION Co.,Ltd" }, + { 0xFE2E, "ERi,Inc." }, + { 0xFE2F, "CRESCO Wireless, Inc" }, + { 0xFE30, "Volkswagen AG" }, + { 0xFE31, "Volkswagen AG" }, + { 0xFE32, "Pro-Mark, Inc." }, + { 0xFE33, "CHIPOLO d.o.o." }, + { 0xFE34, "SmallLoop LLC" }, + { 0xFE35, "HUAWEI Technologies Co., Ltd" }, + { 0xFE36, "HUAWEI Technologies Co., Ltd" }, + { 0xFE37, "Spaceek LTD" }, + { 0xFE38, "Spaceek LTD" }, + { 0xFE39, "TTS Tooltechnic Systems AG & Co. KG" }, + { 0xFE3A, "TTS Tooltechnic Systems AG & Co. KG" }, + { 0xFE3B, "Dolby Laboratories" }, + { 0xFE3C, "Alibaba" }, + { 0xFE3D, "BD Medical" }, + { 0xFE3E, "BD Medical" }, + { 0xFE3F, "Friday Labs Limited" }, + { 0xFE40, "Inugo Systems Limited" }, + { 0xFE41, "Inugo Systems Limited" }, + { 0xFE42, "Nets A/S " }, + { 0xFE43, "Andreas Stihl AG & Co. KG" }, + { 0xFE44, "SK Telecom " }, + { 0xFE45, "Snapchat Inc" }, + { 0xFE46, "B&O Play A/S " }, + { 0xFE47, "General Motors" }, + { 0xFE48, "General Motors" }, + { 0xFE49, "SenionLab AB" }, + { 0xFE4A, "OMRON HEALTHCARE Co., Ltd." }, + { 0xFE4B, "Philips Lighting B.V." }, + { 0xFE4C, "Volkswagen AG" }, + { 0xFE4D, "Casambi Technologies Oy" }, + { 0xFE4E, "NTT docomo" }, + { 0xFE4F, "Molekule, Inc." }, + { 0xFE50, "Google Inc." }, + { 0xFE51, "SRAM" }, + { 0xFE52, "SetPoint Medical" }, + { 0xFE53, "3M" }, + { 0xFE54, "Motiv, Inc." }, + { 0xFE55, "Google Inc." }, + { 0xFE56, "Google Inc." }, + { 0xFE57, "Dotted Labs" }, + { 0xFE58, "Nordic Semiconductor ASA" }, + { 0xFE59, "Nordic Semiconductor ASA" }, + { 0xFE5A, "Chronologics Corporation" }, + { 0xFE5B, "GT-tronics HK Ltd" }, + { 0xFE5C, "million hunters GmbH" }, + { 0xFE5D, "Grundfos A/S" }, + { 0xFE5E, "Plastc Corporation" }, + { 0xFE5F, "Eyefi, Inc." }, + { 0xFE60, "Lierda Science & Technology Group Co., Ltd." }, + { 0xFE61, "Logitech International SA" }, + { 0xFE62, "Indagem Tech LLC" }, + { 0xFE63, "Connected Yard, Inc." }, + { 0xFE64, "Siemens AG" }, + { 0xFE65, "CHIPOLO d.o.o." }, + { 0xFE66, "Intel Corporation" }, + { 0xFE67, "Lab Sensor Solutions" }, + { 0xFE68, "Qualcomm Life Inc" }, + { 0xFE69, "Qualcomm Life Inc" }, + { 0xFE6A, "Kontakt Micro-Location Sp. z o.o." }, + { 0xFE6B, "TASER International, Inc." }, + { 0xFE6C, "TASER International, Inc." }, + { 0xFE6D, "The University of Tokyo" }, + { 0xFE6E, "The University of Tokyo" }, + { 0xFE6F, "LINE Corporation" }, + { 0xFE70, "Beijing Jingdong Century Trading Co., Ltd." }, + { 0xFE71, "Plume Design Inc" }, + { 0xFE72, "St. Jude Medical, Inc." }, + { 0xFE73, "St. Jude Medical, Inc." }, + { 0xFE74, "unwire" }, + { 0xFE75, "TangoMe" }, + { 0xFE76, "TangoMe" }, + { 0xFE77, "Hewlett-Packard Company" }, + { 0xFE78, "Hewlett-Packard Company" }, + { 0xFE79, "Zebra Technologies" }, + { 0xFE7A, "Bragi GmbH" }, + { 0xFE7B, "Orion Labs, Inc." }, + { 0xFE7C, "Telit Wireless Solutions (Formerly Stollmann E+V GmbH)" }, + { 0xFE7D, "Aterica Health Inc." }, + { 0xFE7E, "Awear Solutions Ltd" }, + { 0xFE7F, "Doppler Lab" }, + { 0xFE80, "Doppler Lab" }, + { 0xFE81, "Medtronic Inc." }, + { 0xFE82, "Medtronic Inc." }, + { 0xFE83, "Blue Bite" }, + { 0xFE84, "RF Digital Corp" }, + { 0xFE85, "RF Digital Corp" }, + { 0xFE86, "HUAWEI Technologies Co., Ltd. ( )" }, + { 0xFE87, "Qingdao Yeelink Information Technology Co., Ltd. ( )" }, + { 0xFE88, "SALTO SYSTEMS S.L." }, + { 0xFE89, "B&O Play A/S" }, + { 0xFE8A, "Apple, Inc." }, + { 0xFE8B, "Apple, Inc." }, + { 0xFE8C, "TRON Forum" }, + { 0xFE8D, "Interaxon Inc." }, + { 0xFE8E, "ARM Ltd" }, + { 0xFE8F, "CSR" }, + { 0xFE90, "JUMA" }, + { 0xFE91, "Shanghai Imilab Technology Co.,Ltd" }, + { 0xFE92, "Jarden Safety & Security" }, + { 0xFE93, "OttoQ Inc." }, + { 0xFE94, "OttoQ Inc." }, + { 0xFE95, "Xiaomi Inc." }, + { 0xFE96, "Tesla Motor Inc." }, + { 0xFE97, "Tesla Motor Inc." }, + { 0xFE98, "Currant, Inc." }, + { 0xFE99, "Currant, Inc." }, + { 0xFE9A, "Estimote" }, + { 0xFE9B, "Samsara Networks, Inc" }, + { 0xFE9C, "GSI Laboratories, Inc." }, + { 0xFE9D, "Mobiquity Networks Inc" }, + { 0xFE9E, "Dialog Semiconductor B.V." }, + { 0xFE9F, "Google Inc." }, + { 0xFEA0, "Google Inc." }, + { 0xFEA1, "Intrepid Control Systems, Inc." }, + { 0xFEA2, "Intrepid Control Systems, Inc." }, + { 0xFEA3, "ITT Industries" }, + { 0xFEA4, "Paxton Access Ltd" }, + { 0xFEA5, "GoPro, Inc." }, + { 0xFEA6, "GoPro, Inc." }, + { 0xFEA7, "UTC Fire and Security" }, + { 0xFEA8, "Savant Systems LLC" }, + { 0xFEA9, "Savant Systems LLC" }, + { 0xFEAA, "Google Inc." }, + { 0xFEAB, "Nokia Corporation" }, + { 0xFEAC, "Nokia Corporation" }, + { 0xFEAD, "Nokia Corporation" }, + { 0xFEAE, "Nokia Corporation" }, + { 0xFEAF, "Nest Labs Inc." }, + { 0xFEB0, "Nest Labs Inc." }, + { 0xFEB1, "Electronics Tomorrow Limited" }, + { 0xFEB2, "Microsoft Corporation" }, + { 0xFEB3, "Taobao" }, + { 0xFEB4, "WiSilica Inc." }, + { 0xFEB5, "WiSilica Inc." }, + { 0xFEB6, "Vencer Co, Ltd" }, + { 0xFEB7, "Facebook, Inc." }, + { 0xFEB8, "Facebook, Inc." }, + { 0xFEB9, "LG Electronics" }, + { 0xFEBA, "Tencent Holdings Limited" }, + { 0xFEBB, "adafruit industries" }, + { 0xFEBC, "Dexcom, Inc. " }, + { 0xFEBD, "Clover Network, Inc." }, + { 0xFEBE, "Bose Corporation" }, + { 0xFEBF, "Nod, Inc." }, + { 0xFEC0, "KDDI Corporation" }, + { 0xFEC1, "KDDI Corporation" }, + { 0xFEC2, "Blue Spark Technologies, Inc." }, + { 0xFEC3, "360fly, Inc." }, + { 0xFEC4, "PLUS Location Systems" }, + { 0xFEC5, "Realtek Semiconductor Corp." }, + { 0xFEC6, "Kocomojo, LLC" }, + { 0xFEC7, "Apple, Inc." }, + { 0xFEC8, "Apple, Inc." }, + { 0xFEC9, "Apple, Inc." }, + { 0xFECA, "Apple, Inc." }, + { 0xFECB, "Apple, Inc." }, + { 0xFECC, "Apple, Inc." }, + { 0xFECD, "Apple, Inc." }, + { 0xFECE, "Apple, Inc." }, + { 0xFECF, "Apple, Inc." }, + { 0xFED0, "Apple, Inc." }, + { 0xFED1, "Apple, Inc." }, + { 0xFED2, "Apple, Inc." }, + { 0xFED3, "Apple, Inc." }, + { 0xFED4, "Apple, Inc." }, + { 0xFED5, "Plantronics Inc." }, + { 0xFED6, "Broadcom Corporation" }, + { 0xFED7, "Broadcom Corporation" }, + { 0xFED8, "Google Inc." }, + { 0xFED9, "Pebble Technology Corporation" }, + { 0xFEDA, "ISSC Technologies Corporation" }, + { 0xFEDB, "Perka, Inc." }, + { 0xFEDC, "Jawbone" }, + { 0xFEDD, "Jawbone" }, + { 0xFEDE, "Coin, Inc." }, + { 0xFEDF, "Design SHIFT" }, + { 0xFEE0, "Anhui Huami Information Technology Co." }, + { 0xFEE1, "Anhui Huami Information Technology Co." }, + { 0xFEE2, "Anki, Inc." }, + { 0xFEE3, "Anki, Inc." }, + { 0xFEE4, "Nordic Semiconductor ASA" }, + { 0xFEE5, "Nordic Semiconductor ASA" }, + { 0xFEE6, "Silvair, Inc." }, + { 0xFEE7, "Tencent Holdings Limited" }, + { 0xFEE8, "Quintic Corp." }, + { 0xFEE9, "Quintic Corp." }, + { 0xFEEA, "Swirl Networks, Inc." }, + { 0xFEEB, "Swirl Networks, Inc." }, + { 0xFEEC, "Tile, Inc." }, + { 0xFEED, "Tile, Inc." }, + { 0xFEEE, "Polar Electro Oy" }, + { 0xFEEF, "Polar Electro Oy" }, + { 0xFEF0, "Intel" }, + { 0xFEF1, "CSR" }, + { 0xFEF2, "CSR" }, + { 0xFEF3, "Google Inc." }, + { 0xFEF4, "Google Inc." }, + { 0xFEF5, "Dialog Semiconductor GmbH" }, + { 0xFEF6, "Wicentric, Inc." }, + { 0xFEF7, "Aplix Corporation" }, + { 0xFEF8, "Aplix Corporation" }, + { 0xFEF9, "PayPal, Inc." }, + { 0xFEFA, "PayPal, Inc." }, + { 0xFEFB, "Telit Wireless Solutions (Formerly Stollmann E+V GmbH)" }, + { 0xFEFC, "Gimbal, Inc." }, + { 0xFEFD, "Gimbal, Inc." }, + { 0xFEFE, "GN ReSound A/S" }, + { 0xFEFF, "GN Netcom" }, + { 0xFFFF, "Reserved" }, /*for testing purposes only*/ #endif - {0, "" } + { 0, "" } }; typedef struct { - uint32_t assignedNumber; - const char* name; + uint32_t assignedNumber; + const char* name; } gattdescriptor_t; static const gattdescriptor_t g_descriptor_ids[] = { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - {0x2905,"Characteristic Aggregate Format"}, - {0x2900,"Characteristic Extended Properties"}, - {0x2904,"Characteristic Presentation Format"}, - {0x2901,"Characteristic User Description"}, - {0x2902,"Client Characteristic Configuration"}, - {0x290B,"Environmental Sensing Configuration"}, - {0x290C,"Environmental Sensing Measurement"}, - {0x290D,"Environmental Sensing Trigger Setting"}, - {0x2907,"External Report Reference"}, - {0x2909,"Number of Digitals"}, - {0x2908,"Report Reference"}, - {0x2903,"Server Characteristic Configuration"}, - {0x290E,"Time Trigger Setting"}, - {0x2906,"Valid Range"}, - {0x290A,"Value Trigger Setting"}, + { 0x2905, "Characteristic Aggregate Format" }, + { 0x2900, "Characteristic Extended Properties" }, + { 0x2904, "Characteristic Presentation Format" }, + { 0x2901, "Characteristic User Description" }, + { 0x2902, "Client Characteristic Configuration" }, + { 0x290B, "Environmental Sensing Configuration" }, + { 0x290C, "Environmental Sensing Measurement" }, + { 0x290D, "Environmental Sensing Trigger Setting" }, + { 0x2907, "External Report Reference" }, + { 0x2909, "Number of Digitals" }, + { 0x2908, "Report Reference" }, + { 0x2903, "Server Characteristic Configuration" }, + { 0x290E, "Time Trigger Setting" }, + { 0x2906, "Valid Range" }, + { 0x290A, "Value Trigger Setting" }, #endif - { 0, "" } + { 0, "" } }; typedef struct { - uint32_t assignedNumber; - const char* name; + uint32_t assignedNumber; + const char* name; } characteristicMap_t; static const characteristicMap_t g_characteristicsMappings[] = { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - {0x2A7E,"Aerobic Heart Rate Lower Limit"}, - {0x2A84,"Aerobic Heart Rate Upper Limit"}, - {0x2A7F,"Aerobic Threshold"}, - {0x2A80,"Age"}, - {0x2A5A,"Aggregate"}, - {0x2A43,"Alert Category ID"}, - {0x2A42,"Alert Category ID Bit Mask"}, - {0x2A06,"Alert Level"}, - {0x2A44,"Alert Notification Control Point"}, - {0x2A3F,"Alert Status"}, - {0x2AB3,"Altitude"}, - {0x2A81,"Anaerobic Heart Rate Lower Limit"}, - {0x2A82,"Anaerobic Heart Rate Upper Limit"}, - {0x2A83,"Anaerobic Threshold"}, - {0x2A58,"Analog"}, - {0x2A59,"Analog Output"}, - {0x2A73,"Apparent Wind Direction"}, - {0x2A72,"Apparent Wind Speed"}, - {0x2A01,"Appearance"}, - {0x2AA3,"Barometric Pressure Trend"}, - {0x2A19,"Battery Level"}, - {0x2A1B,"Battery Level State"}, - {0x2A1A,"Battery Power State"}, - {0x2A49,"Blood Pressure Feature"}, - {0x2A35,"Blood Pressure Measurement"}, - {0x2A9B,"Body Composition Feature"}, - {0x2A9C,"Body Composition Measurement"}, - {0x2A38,"Body Sensor Location"}, - {0x2AA4,"Bond Management Control Point"}, - {0x2AA5,"Bond Management Features"}, - {0x2A22,"Boot Keyboard Input Report"}, - {0x2A32,"Boot Keyboard Output Report"}, - {0x2A33,"Boot Mouse Input Report"}, - {0x2AA6,"Central Address Resolution"}, - {0x2AA8,"CGM Feature"}, - {0x2AA7,"CGM Measurement"}, - {0x2AAB,"CGM Session Run Time"}, - {0x2AAA,"CGM Session Start Time"}, - {0x2AAC,"CGM Specific Ops Control Point"}, - {0x2AA9,"CGM Status"}, - {0x2ACE,"Cross Trainer Data"}, - {0x2A5C,"CSC Feature"}, - {0x2A5B,"CSC Measurement"}, - {0x2A2B,"Current Time"}, - {0x2A66,"Cycling Power Control Point"}, - {0x2A66,"Cycling Power Control Point"}, - {0x2A65,"Cycling Power Feature"}, - {0x2A65,"Cycling Power Feature"}, - {0x2A63,"Cycling Power Measurement"}, - {0x2A64,"Cycling Power Vector"}, - {0x2A99,"Database Change Increment"}, - {0x2A85,"Date of Birth"}, - {0x2A86,"Date of Threshold Assessment"}, - {0x2A08,"Date Time"}, - {0x2A0A,"Day Date Time"}, - {0x2A09,"Day of Week"}, - {0x2A7D,"Descriptor Value Changed"}, - {0x2A00,"Device Name"}, - {0x2A7B,"Dew Point"}, - {0x2A56,"Digital"}, - {0x2A57,"Digital Output"}, - {0x2A0D,"DST Offset"}, - {0x2A6C,"Elevation"}, - {0x2A87,"Email Address"}, - {0x2A0B,"Exact Time 100"}, - {0x2A0C,"Exact Time 256"}, - {0x2A88,"Fat Burn Heart Rate Lower Limit"}, - {0x2A89,"Fat Burn Heart Rate Upper Limit"}, - {0x2A26,"Firmware Revision String"}, - {0x2A8A,"First Name"}, - {0x2AD9,"Fitness Machine Control Point"}, - {0x2ACC,"Fitness Machine Feature"}, - {0x2ADA,"Fitness Machine Status"}, - {0x2A8B,"Five Zone Heart Rate Limits"}, - {0x2AB2,"Floor Number"}, - {0x2A8C,"Gender"}, - {0x2A51,"Glucose Feature"}, - {0x2A18,"Glucose Measurement"}, - {0x2A34,"Glucose Measurement Context"}, - {0x2A74,"Gust Factor"}, - {0x2A27,"Hardware Revision String"}, - {0x2A39,"Heart Rate Control Point"}, - {0x2A8D,"Heart Rate Max"}, - {0x2A37,"Heart Rate Measurement"}, - {0x2A7A,"Heat Index"}, - {0x2A8E,"Height"}, - {0x2A4C,"HID Control Point"}, - {0x2A4A,"HID Information"}, - {0x2A8F,"Hip Circumference"}, - {0x2ABA,"HTTP Control Point"}, - {0x2AB9,"HTTP Entity Body"}, - {0x2AB7,"HTTP Headers"}, - {0x2AB8,"HTTP Status Code"}, - {0x2ABB,"HTTPS Security"}, - {0x2A6F,"Humidity"}, - {0x2A2A,"IEEE 11073-20601 Regulatory Certification Data List"}, - {0x2AD2,"Indoor Bike Data"}, - {0x2AAD,"Indoor Positioning Configuration"}, - {0x2A36,"Intermediate Cuff Pressure"}, - {0x2A1E,"Intermediate Temperature"}, - {0x2A77,"Irradiance"}, - {0x2AA2,"Language"}, - {0x2A90,"Last Name"}, - {0x2AAE,"Latitude"}, - {0x2A6B,"LN Control Point"}, - {0x2A6A,"LN Feature"}, - {0x2AB1,"Local East Coordinate"}, - {0x2AB0,"Local North Coordinate"}, - {0x2A0F,"Local Time Information"}, - {0x2A67,"Location and Speed Characteristic"}, - {0x2AB5,"Location Name"}, - {0x2AAF,"Longitude"}, - {0x2A2C,"Magnetic Declination"}, - {0x2AA0,"Magnetic Flux Density - 2D"}, - {0x2AA1,"Magnetic Flux Density - 3D"}, - {0x2A29,"Manufacturer Name String"}, - {0x2A91,"Maximum Recommended Heart Rate"}, - {0x2A21,"Measurement Interval"}, - {0x2A24,"Model Number String"}, - {0x2A68,"Navigation"}, - {0x2A3E,"Network Availability"}, - {0x2A46,"New Alert"}, - {0x2AC5,"Object Action Control Point"}, - {0x2AC8,"Object Changed"}, - {0x2AC1,"Object First-Created"}, - {0x2AC3,"Object ID"}, - {0x2AC2,"Object Last-Modified"}, - {0x2AC6,"Object List Control Point"}, - {0x2AC7,"Object List Filter"}, - {0x2ABE,"Object Name"}, - {0x2AC4,"Object Properties"}, - {0x2AC0,"Object Size"}, - {0x2ABF,"Object Type"}, - {0x2ABD,"OTS Feature"}, - {0x2A04,"Peripheral Preferred Connection Parameters"}, - {0x2A02,"Peripheral Privacy Flag"}, - {0x2A5F,"PLX Continuous Measurement Characteristic"}, - {0x2A60,"PLX Features"}, - {0x2A5E,"PLX Spot-Check Measurement"}, - {0x2A50,"PnP ID"}, - {0x2A75,"Pollen Concentration"}, - {0x2A2F,"Position 2D"}, - {0x2A30,"Position 3D"}, - {0x2A69,"Position Quality"}, - {0x2A6D,"Pressure"}, - {0x2A4E,"Protocol Mode"}, - {0x2A62,"Pulse Oximetry Control Point"}, - {0x2A60,"Pulse Oximetry Pulsatile Event Characteristic"}, - {0x2A78,"Rainfall"}, - {0x2A03,"Reconnection Address"}, - {0x2A52,"Record Access Control Point"}, - {0x2A14,"Reference Time Information"}, - {0x2A3A,"Removable"}, - {0x2A4D,"Report"}, - {0x2A4B,"Report Map"}, - {0x2AC9,"Resolvable Private Address Only"}, - {0x2A92,"Resting Heart Rate"}, - {0x2A40,"Ringer Control point"}, - {0x2A41,"Ringer Setting"}, - {0x2AD1,"Rower Data"}, - {0x2A54,"RSC Feature"}, - {0x2A53,"RSC Measurement"}, - {0x2A55,"SC Control Point"}, - {0x2A4F,"Scan Interval Window"}, - {0x2A31,"Scan Refresh"}, - {0x2A3C,"Scientific Temperature Celsius"}, - {0x2A10,"Secondary Time Zone"}, - {0x2A5D,"Sensor Location"}, - {0x2A25,"Serial Number String"}, - {0x2A05,"Service Changed"}, - {0x2A3B,"Service Required"}, - {0x2A28,"Software Revision String"}, - {0x2A93,"Sport Type for Aerobic and Anaerobic Thresholds"}, - {0x2AD0,"Stair Climber Data"}, - {0x2ACF,"Step Climber Data"}, - {0x2A3D,"String"}, - {0x2AD7,"Supported Heart Rate Range"}, - {0x2AD5,"Supported Inclination Range"}, - {0x2A47,"Supported New Alert Category"}, - {0x2AD8,"Supported Power Range"}, - {0x2AD6,"Supported Resistance Level Range"}, - {0x2AD4,"Supported Speed Range"}, - {0x2A48,"Supported Unread Alert Category"}, - {0x2A23,"System ID"}, - {0x2ABC,"TDS Control Point"}, - {0x2A6E,"Temperature"}, - {0x2A1F,"Temperature Celsius"}, - {0x2A20,"Temperature Fahrenheit"}, - {0x2A1C,"Temperature Measurement"}, - {0x2A1D,"Temperature Type"}, - {0x2A94,"Three Zone Heart Rate Limits"}, - {0x2A12,"Time Accuracy"}, - {0x2A15,"Time Broadcast"}, - {0x2A13,"Time Source"}, - {0x2A16,"Time Update Control Point"}, - {0x2A17,"Time Update State"}, - {0x2A11,"Time with DST"}, - {0x2A0E,"Time Zone"}, - {0x2AD3,"Training Status"}, - {0x2ACD,"Treadmill Data"}, - {0x2A71,"True Wind Direction"}, - {0x2A70,"True Wind Speed"}, - {0x2A95,"Two Zone Heart Rate Limit"}, - {0x2A07,"Tx Power Level"}, - {0x2AB4,"Uncertainty"}, - {0x2A45,"Unread Alert Status"}, - {0x2AB6,"URI"}, - {0x2A9F,"User Control Point"}, - {0x2A9A,"User Index"}, - {0x2A76,"UV Index"}, - {0x2A96,"VO2 Max"}, - {0x2A97,"Waist Circumference"}, - {0x2A98,"Weight"}, - {0x2A9D,"Weight Measurement"}, - {0x2A9E,"Weight Scale Feature"}, - {0x2A79,"Wind Chill"}, + { 0x2A7E, "Aerobic Heart Rate Lower Limit" }, + { 0x2A84, "Aerobic Heart Rate Upper Limit" }, + { 0x2A7F, "Aerobic Threshold" }, + { 0x2A80, "Age" }, + { 0x2A5A, "Aggregate" }, + { 0x2A43, "Alert Category ID" }, + { 0x2A42, "Alert Category ID Bit Mask" }, + { 0x2A06, "Alert Level" }, + { 0x2A44, "Alert Notification Control Point" }, + { 0x2A3F, "Alert Status" }, + { 0x2AB3, "Altitude" }, + { 0x2A81, "Anaerobic Heart Rate Lower Limit" }, + { 0x2A82, "Anaerobic Heart Rate Upper Limit" }, + { 0x2A83, "Anaerobic Threshold" }, + { 0x2A58, "Analog" }, + { 0x2A59, "Analog Output" }, + { 0x2A73, "Apparent Wind Direction" }, + { 0x2A72, "Apparent Wind Speed" }, + { 0x2A01, "Appearance" }, + { 0x2AA3, "Barometric Pressure Trend" }, + { 0x2A19, "Battery Level" }, + { 0x2A1B, "Battery Level State" }, + { 0x2A1A, "Battery Power State" }, + { 0x2A49, "Blood Pressure Feature" }, + { 0x2A35, "Blood Pressure Measurement" }, + { 0x2A9B, "Body Composition Feature" }, + { 0x2A9C, "Body Composition Measurement" }, + { 0x2A38, "Body Sensor Location" }, + { 0x2AA4, "Bond Management Control Point" }, + { 0x2AA5, "Bond Management Features" }, + { 0x2A22, "Boot Keyboard Input Report" }, + { 0x2A32, "Boot Keyboard Output Report" }, + { 0x2A33, "Boot Mouse Input Report" }, + { 0x2AA6, "Central Address Resolution" }, + { 0x2AA8, "CGM Feature" }, + { 0x2AA7, "CGM Measurement" }, + { 0x2AAB, "CGM Session Run Time" }, + { 0x2AAA, "CGM Session Start Time" }, + { 0x2AAC, "CGM Specific Ops Control Point" }, + { 0x2AA9, "CGM Status" }, + { 0x2ACE, "Cross Trainer Data" }, + { 0x2A5C, "CSC Feature" }, + { 0x2A5B, "CSC Measurement" }, + { 0x2A2B, "Current Time" }, + { 0x2A66, "Cycling Power Control Point" }, + { 0x2A66, "Cycling Power Control Point" }, + { 0x2A65, "Cycling Power Feature" }, + { 0x2A65, "Cycling Power Feature" }, + { 0x2A63, "Cycling Power Measurement" }, + { 0x2A64, "Cycling Power Vector" }, + { 0x2A99, "Database Change Increment" }, + { 0x2A85, "Date of Birth" }, + { 0x2A86, "Date of Threshold Assessment" }, + { 0x2A08, "Date Time" }, + { 0x2A0A, "Day Date Time" }, + { 0x2A09, "Day of Week" }, + { 0x2A7D, "Descriptor Value Changed" }, + { 0x2A00, "Device Name" }, + { 0x2A7B, "Dew Point" }, + { 0x2A56, "Digital" }, + { 0x2A57, "Digital Output" }, + { 0x2A0D, "DST Offset" }, + { 0x2A6C, "Elevation" }, + { 0x2A87, "Email Address" }, + { 0x2A0B, "Exact Time 100" }, + { 0x2A0C, "Exact Time 256" }, + { 0x2A88, "Fat Burn Heart Rate Lower Limit" }, + { 0x2A89, "Fat Burn Heart Rate Upper Limit" }, + { 0x2A26, "Firmware Revision String" }, + { 0x2A8A, "First Name" }, + { 0x2AD9, "Fitness Machine Control Point" }, + { 0x2ACC, "Fitness Machine Feature" }, + { 0x2ADA, "Fitness Machine Status" }, + { 0x2A8B, "Five Zone Heart Rate Limits" }, + { 0x2AB2, "Floor Number" }, + { 0x2A8C, "Gender" }, + { 0x2A51, "Glucose Feature" }, + { 0x2A18, "Glucose Measurement" }, + { 0x2A34, "Glucose Measurement Context" }, + { 0x2A74, "Gust Factor" }, + { 0x2A27, "Hardware Revision String" }, + { 0x2A39, "Heart Rate Control Point" }, + { 0x2A8D, "Heart Rate Max" }, + { 0x2A37, "Heart Rate Measurement" }, + { 0x2A7A, "Heat Index" }, + { 0x2A8E, "Height" }, + { 0x2A4C, "HID Control Point" }, + { 0x2A4A, "HID Information" }, + { 0x2A8F, "Hip Circumference" }, + { 0x2ABA, "HTTP Control Point" }, + { 0x2AB9, "HTTP Entity Body" }, + { 0x2AB7, "HTTP Headers" }, + { 0x2AB8, "HTTP Status Code" }, + { 0x2ABB, "HTTPS Security" }, + { 0x2A6F, "Humidity" }, + { 0x2A2A, "IEEE 11073-20601 Regulatory Certification Data List" }, + { 0x2AD2, "Indoor Bike Data" }, + { 0x2AAD, "Indoor Positioning Configuration" }, + { 0x2A36, "Intermediate Cuff Pressure" }, + { 0x2A1E, "Intermediate Temperature" }, + { 0x2A77, "Irradiance" }, + { 0x2AA2, "Language" }, + { 0x2A90, "Last Name" }, + { 0x2AAE, "Latitude" }, + { 0x2A6B, "LN Control Point" }, + { 0x2A6A, "LN Feature" }, + { 0x2AB1, "Local East Coordinate" }, + { 0x2AB0, "Local North Coordinate" }, + { 0x2A0F, "Local Time Information" }, + { 0x2A67, "Location and Speed Characteristic" }, + { 0x2AB5, "Location Name" }, + { 0x2AAF, "Longitude" }, + { 0x2A2C, "Magnetic Declination" }, + { 0x2AA0, "Magnetic Flux Density - 2D" }, + { 0x2AA1, "Magnetic Flux Density - 3D" }, + { 0x2A29, "Manufacturer Name String" }, + { 0x2A91, "Maximum Recommended Heart Rate" }, + { 0x2A21, "Measurement Interval" }, + { 0x2A24, "Model Number String" }, + { 0x2A68, "Navigation" }, + { 0x2A3E, "Network Availability" }, + { 0x2A46, "New Alert" }, + { 0x2AC5, "Object Action Control Point" }, + { 0x2AC8, "Object Changed" }, + { 0x2AC1, "Object First-Created" }, + { 0x2AC3, "Object ID" }, + { 0x2AC2, "Object Last-Modified" }, + { 0x2AC6, "Object List Control Point" }, + { 0x2AC7, "Object List Filter" }, + { 0x2ABE, "Object Name" }, + { 0x2AC4, "Object Properties" }, + { 0x2AC0, "Object Size" }, + { 0x2ABF, "Object Type" }, + { 0x2ABD, "OTS Feature" }, + { 0x2A04, "Peripheral Preferred Connection Parameters" }, + { 0x2A02, "Peripheral Privacy Flag" }, + { 0x2A5F, "PLX Continuous Measurement Characteristic" }, + { 0x2A60, "PLX Features" }, + { 0x2A5E, "PLX Spot-Check Measurement" }, + { 0x2A50, "PnP ID" }, + { 0x2A75, "Pollen Concentration" }, + { 0x2A2F, "Position 2D" }, + { 0x2A30, "Position 3D" }, + { 0x2A69, "Position Quality" }, + { 0x2A6D, "Pressure" }, + { 0x2A4E, "Protocol Mode" }, + { 0x2A62, "Pulse Oximetry Control Point" }, + { 0x2A60, "Pulse Oximetry Pulsatile Event Characteristic" }, + { 0x2A78, "Rainfall" }, + { 0x2A03, "Reconnection Address" }, + { 0x2A52, "Record Access Control Point" }, + { 0x2A14, "Reference Time Information" }, + { 0x2A3A, "Removable" }, + { 0x2A4D, "Report" }, + { 0x2A4B, "Report Map" }, + { 0x2AC9, "Resolvable Private Address Only" }, + { 0x2A92, "Resting Heart Rate" }, + { 0x2A40, "Ringer Control point" }, + { 0x2A41, "Ringer Setting" }, + { 0x2AD1, "Rower Data" }, + { 0x2A54, "RSC Feature" }, + { 0x2A53, "RSC Measurement" }, + { 0x2A55, "SC Control Point" }, + { 0x2A4F, "Scan Interval Window" }, + { 0x2A31, "Scan Refresh" }, + { 0x2A3C, "Scientific Temperature Celsius" }, + { 0x2A10, "Secondary Time Zone" }, + { 0x2A5D, "Sensor Location" }, + { 0x2A25, "Serial Number String" }, + { 0x2A05, "Service Changed" }, + { 0x2A3B, "Service Required" }, + { 0x2A28, "Software Revision String" }, + { 0x2A93, "Sport Type for Aerobic and Anaerobic Thresholds" }, + { 0x2AD0, "Stair Climber Data" }, + { 0x2ACF, "Step Climber Data" }, + { 0x2A3D, "String" }, + { 0x2AD7, "Supported Heart Rate Range" }, + { 0x2AD5, "Supported Inclination Range" }, + { 0x2A47, "Supported New Alert Category" }, + { 0x2AD8, "Supported Power Range" }, + { 0x2AD6, "Supported Resistance Level Range" }, + { 0x2AD4, "Supported Speed Range" }, + { 0x2A48, "Supported Unread Alert Category" }, + { 0x2A23, "System ID" }, + { 0x2ABC, "TDS Control Point" }, + { 0x2A6E, "Temperature" }, + { 0x2A1F, "Temperature Celsius" }, + { 0x2A20, "Temperature Fahrenheit" }, + { 0x2A1C, "Temperature Measurement" }, + { 0x2A1D, "Temperature Type" }, + { 0x2A94, "Three Zone Heart Rate Limits" }, + { 0x2A12, "Time Accuracy" }, + { 0x2A15, "Time Broadcast" }, + { 0x2A13, "Time Source" }, + { 0x2A16, "Time Update Control Point" }, + { 0x2A17, "Time Update State" }, + { 0x2A11, "Time with DST" }, + { 0x2A0E, "Time Zone" }, + { 0x2AD3, "Training Status" }, + { 0x2ACD, "Treadmill Data" }, + { 0x2A71, "True Wind Direction" }, + { 0x2A70, "True Wind Speed" }, + { 0x2A95, "Two Zone Heart Rate Limit" }, + { 0x2A07, "Tx Power Level" }, + { 0x2AB4, "Uncertainty" }, + { 0x2A45, "Unread Alert Status" }, + { 0x2AB6, "URI" }, + { 0x2A9F, "User Control Point" }, + { 0x2A9A, "User Index" }, + { 0x2A76, "UV Index" }, + { 0x2A96, "VO2 Max" }, + { 0x2A97, "Waist Circumference" }, + { 0x2A98, "Weight" }, + { 0x2A9D, "Weight Measurement" }, + { 0x2A9E, "Weight Scale Feature" }, + { 0x2A79, "Wind Chill" }, #endif - {0, ""} + { 0, "" } }; /** * @brief Mapping from service ids to names */ typedef struct { - const char* name; - const char* type; - uint32_t assignedNumber; + const char* name; + const char* type; + uint32_t assignedNumber; } gattService_t; @@ -556,43 +556,43 @@ typedef struct { */ static const gattService_t g_gattServices[] = { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - {"Alert Notification Service", "org.bluetooth.service.alert_notification", 0x1811}, - {"Automation IO", "org.bluetooth.service.automation_io", 0x1815 }, - {"Battery Service","org.bluetooth.service.battery_service", 0x180F}, - {"Blood Pressure", "org.bluetooth.service.blood_pressure", 0x1810}, - {"Body Composition", "org.bluetooth.service.body_composition", 0x181B}, - {"Bond Management", "org.bluetooth.service.bond_management", 0x181E}, - {"Continuous Glucose Monitoring", "org.bluetooth.service.continuous_glucose_monitoring", 0x181F}, - {"Current Time Service", "org.bluetooth.service.current_time", 0x1805}, - {"Cycling Power", "org.bluetooth.service.cycling_power", 0x1818}, - {"Cycling Speed and Cadence", "org.bluetooth.service.cycling_speed_and_cadence", 0x1816}, - {"Device Information", "org.bluetooth.service.device_information", 0x180A}, - {"Environmental Sensing", "org.bluetooth.service.environmental_sensing", 0x181A}, - {"Generic Access", "org.bluetooth.service.generic_access", 0x1800}, - {"Generic Attribute", "org.bluetooth.service.generic_attribute", 0x1801}, - {"Glucose", "org.bluetooth.service.glucose", 0x1808}, - {"Health Thermometer", "org.bluetooth.service.health_thermometer", 0x1809}, - {"Heart Rate", "org.bluetooth.service.heart_rate", 0x180D}, - {"HTTP Proxy", "org.bluetooth.service.http_proxy", 0x1823}, - {"Human Interface Device", "org.bluetooth.service.human_interface_device", 0x1812}, - {"Immediate Alert", "org.bluetooth.service.immediate_alert", 0x1802}, - {"Indoor Positioning", "org.bluetooth.service.indoor_positioning", 0x1821}, - {"Internet Protocol Support", "org.bluetooth.service.internet_protocol_support", 0x1820}, - {"Link Loss", "org.bluetooth.service.link_loss", 0x1803}, - {"Location and Navigation", "org.bluetooth.service.location_and_navigation", 0x1819}, - {"Next DST Change Service", "org.bluetooth.service.next_dst_change", 0x1807}, - {"Object Transfer", "org.bluetooth.service.object_transfer", 0x1825}, - {"Phone Alert Status Service", "org.bluetooth.service.phone_alert_status", 0x180E}, - {"Pulse Oximeter", "org.bluetooth.service.pulse_oximeter", 0x1822}, - {"Reference Time Update Service", "org.bluetooth.service.reference_time_update", 0x1806}, - {"Running Speed and Cadence", "org.bluetooth.service.running_speed_and_cadence", 0x1814}, - {"Scan Parameters", "org.bluetooth.service.scan_parameters", 0x1813}, - {"Transport Discovery", "org.bluetooth.service.transport_discovery", 0x1824}, - {"Tx Power", "org.bluetooth.service.tx_power", 0x1804}, - {"User Data", "org.bluetooth.service.user_data", 0x181C}, - {"Weight Scale", "org.bluetooth.service.weight_scale", 0x181D}, + { "Alert Notification Service", "org.bluetooth.service.alert_notification", 0x1811 }, + { "Automation IO", "org.bluetooth.service.automation_io", 0x1815 }, + { "Battery Service", "org.bluetooth.service.battery_service", 0x180F }, + { "Blood Pressure", "org.bluetooth.service.blood_pressure", 0x1810 }, + { "Body Composition", "org.bluetooth.service.body_composition", 0x181B }, + { "Bond Management", "org.bluetooth.service.bond_management", 0x181E }, + { "Continuous Glucose Monitoring", "org.bluetooth.service.continuous_glucose_monitoring", 0x181F }, + { "Current Time Service", "org.bluetooth.service.current_time", 0x1805 }, + { "Cycling Power", "org.bluetooth.service.cycling_power", 0x1818 }, + { "Cycling Speed and Cadence", "org.bluetooth.service.cycling_speed_and_cadence", 0x1816 }, + { "Device Information", "org.bluetooth.service.device_information", 0x180A }, + { "Environmental Sensing", "org.bluetooth.service.environmental_sensing", 0x181A }, + { "Generic Access", "org.bluetooth.service.generic_access", 0x1800 }, + { "Generic Attribute", "org.bluetooth.service.generic_attribute", 0x1801 }, + { "Glucose", "org.bluetooth.service.glucose", 0x1808 }, + { "Health Thermometer", "org.bluetooth.service.health_thermometer", 0x1809 }, + { "Heart Rate", "org.bluetooth.service.heart_rate", 0x180D }, + { "HTTP Proxy", "org.bluetooth.service.http_proxy", 0x1823 }, + { "Human Interface Device", "org.bluetooth.service.human_interface_device", 0x1812 }, + { "Immediate Alert", "org.bluetooth.service.immediate_alert", 0x1802 }, + { "Indoor Positioning", "org.bluetooth.service.indoor_positioning", 0x1821 }, + { "Internet Protocol Support", "org.bluetooth.service.internet_protocol_support", 0x1820 }, + { "Link Loss", "org.bluetooth.service.link_loss", 0x1803 }, + { "Location and Navigation", "org.bluetooth.service.location_and_navigation", 0x1819 }, + { "Next DST Change Service", "org.bluetooth.service.next_dst_change", 0x1807 }, + { "Object Transfer", "org.bluetooth.service.object_transfer", 0x1825 }, + { "Phone Alert Status Service", "org.bluetooth.service.phone_alert_status", 0x180E }, + { "Pulse Oximeter", "org.bluetooth.service.pulse_oximeter", 0x1822 }, + { "Reference Time Update Service", "org.bluetooth.service.reference_time_update", 0x1806 }, + { "Running Speed and Cadence", "org.bluetooth.service.running_speed_and_cadence", 0x1814 }, + { "Scan Parameters", "org.bluetooth.service.scan_parameters", 0x1813 }, + { "Transport Discovery", "org.bluetooth.service.transport_discovery", 0x1824 }, + { "Tx Power", "org.bluetooth.service.tx_power", 0x1804 }, + { "User Data", "org.bluetooth.service.user_data", 0x181C }, + { "Weight Scale", "org.bluetooth.service.weight_scale", 0x181D }, #endif - {"", "", 0 } + { "", "", 0 } }; @@ -602,54 +602,54 @@ static const gattService_t g_gattServices[] = { * @return A string representation of characteristic properties. */ String BLEUtils::characteristicPropertiesToString(esp_gatt_char_prop_t prop) { - String res = "broadcast: "; - res += ((prop & ESP_GATT_CHAR_PROP_BIT_BROADCAST)?"1":"0"); - res += ", read: "; - res += ((prop & ESP_GATT_CHAR_PROP_BIT_READ)?"1":"0"); - res += ", write_nr: "; - res += ((prop & ESP_GATT_CHAR_PROP_BIT_WRITE_NR)?"1":"0"); - res += ", write: "; - res += ((prop & ESP_GATT_CHAR_PROP_BIT_WRITE)?"1":"0"); - res += ", notify: "; - res += ((prop & ESP_GATT_CHAR_PROP_BIT_NOTIFY)?"1":"0"); - res += ", indicate: "; - res += ((prop & ESP_GATT_CHAR_PROP_BIT_INDICATE)?"1":"0"); - res += ", auth: "; - res += ((prop & ESP_GATT_CHAR_PROP_BIT_AUTH)?"1":"0"); - return res; -} // characteristicPropertiesToString + String res = "broadcast: "; + res += ((prop & ESP_GATT_CHAR_PROP_BIT_BROADCAST) ? "1" : "0"); + res += ", read: "; + res += ((prop & ESP_GATT_CHAR_PROP_BIT_READ) ? "1" : "0"); + res += ", write_nr: "; + res += ((prop & ESP_GATT_CHAR_PROP_BIT_WRITE_NR) ? "1" : "0"); + res += ", write: "; + res += ((prop & ESP_GATT_CHAR_PROP_BIT_WRITE) ? "1" : "0"); + res += ", notify: "; + res += ((prop & ESP_GATT_CHAR_PROP_BIT_NOTIFY) ? "1" : "0"); + res += ", indicate: "; + res += ((prop & ESP_GATT_CHAR_PROP_BIT_INDICATE) ? "1" : "0"); + res += ", auth: "; + res += ((prop & ESP_GATT_CHAR_PROP_BIT_AUTH) ? "1" : "0"); + return res; +} // characteristicPropertiesToString /** * @brief Convert an esp_gatt_id_t to a string. */ static String gattIdToString(esp_gatt_id_t gattId) { - String res = "uuid: " + BLEUUID(gattId.uuid).toString() + ", inst_id: "; - char val[8]; - snprintf(val, sizeof(val), "%d", (int)gattId.inst_id); - res += val; - return res; -} // gattIdToString + String res = "uuid: " + BLEUUID(gattId.uuid).toString() + ", inst_id: "; + char val[8]; + snprintf(val, sizeof(val), "%d", (int)gattId.inst_id); + res += val; + return res; +} // gattIdToString /** * @brief Convert an esp_ble_addr_type_t to a string representation. */ const char* BLEUtils::addressTypeToString(esp_ble_addr_type_t type) { - switch (type) { + switch (type) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - case BLE_ADDR_TYPE_PUBLIC: - return "BLE_ADDR_TYPE_PUBLIC"; - case BLE_ADDR_TYPE_RANDOM: - return "BLE_ADDR_TYPE_RANDOM"; - case BLE_ADDR_TYPE_RPA_PUBLIC: - return "BLE_ADDR_TYPE_RPA_PUBLIC"; - case BLE_ADDR_TYPE_RPA_RANDOM: - return "BLE_ADDR_TYPE_RPA_RANDOM"; + case BLE_ADDR_TYPE_PUBLIC: + return "BLE_ADDR_TYPE_PUBLIC"; + case BLE_ADDR_TYPE_RANDOM: + return "BLE_ADDR_TYPE_RANDOM"; + case BLE_ADDR_TYPE_RPA_PUBLIC: + return "BLE_ADDR_TYPE_RPA_PUBLIC"; + case BLE_ADDR_TYPE_RPA_RANDOM: + return "BLE_ADDR_TYPE_RPA_RANDOM"; #endif - default: - return " esp_ble_addr_type_t"; - } -} // addressTypeToString + default: + return " esp_ble_addr_type_t"; + } +} // addressTypeToString /** @@ -658,24 +658,24 @@ const char* BLEUtils::addressTypeToString(esp_ble_addr_type_t type) { * @return String A string representation of the advertising flags. */ String BLEUtils::adFlagsToString(uint8_t adFlags) { - String res; - if (adFlags & (1 << 0)) { - res += "[LE Limited Discoverable Mode] "; - } - if (adFlags & (1 << 1)) { - res += "[LE General Discoverable Mode] "; - } - if (adFlags & (1 << 2)) { - res += "[BR/EDR Not Supported] "; - } - if (adFlags & (1 << 3)) { - res += "[Simultaneous LE and BR/EDR to Same Device Capable (Controller)] "; - } - if (adFlags & (1 << 4)) { - res += "[Simultaneous LE and BR/EDR to Same Device Capable (Host)] "; - } - return res; -} // adFlagsToString + String res; + if (adFlags & (1 << 0)) { + res += "[LE Limited Discoverable Mode] "; + } + if (adFlags & (1 << 1)) { + res += "[LE General Discoverable Mode] "; + } + if (adFlags & (1 << 2)) { + res += "[BR/EDR Not Supported] "; + } + if (adFlags & (1 << 3)) { + res += "[Simultaneous LE and BR/EDR to Same Device Capable (Controller)] "; + } + if (adFlags & (1 << 4)) { + res += "[Simultaneous LE and BR/EDR to Same Device Capable (Host)] "; + } + return res; +} // adFlagsToString /** @@ -687,78 +687,78 @@ String BLEUtils::adFlagsToString(uint8_t adFlags) { * @return A string representation of the type. */ const char* BLEUtils::advTypeToString(uint8_t advType) { - switch (advType) { + switch (advType) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - case ESP_BLE_AD_TYPE_FLAG: // 0x01 - return "ESP_BLE_AD_TYPE_FLAG"; - case ESP_BLE_AD_TYPE_16SRV_PART: // 0x02 - return "ESP_BLE_AD_TYPE_16SRV_PART"; - case ESP_BLE_AD_TYPE_16SRV_CMPL: // 0x03 - return "ESP_BLE_AD_TYPE_16SRV_CMPL"; - case ESP_BLE_AD_TYPE_32SRV_PART: // 0x04 - return "ESP_BLE_AD_TYPE_32SRV_PART"; - case ESP_BLE_AD_TYPE_32SRV_CMPL: // 0x05 - return "ESP_BLE_AD_TYPE_32SRV_CMPL"; - case ESP_BLE_AD_TYPE_128SRV_PART: // 0x06 - return "ESP_BLE_AD_TYPE_128SRV_PART"; - case ESP_BLE_AD_TYPE_128SRV_CMPL: // 0x07 - return "ESP_BLE_AD_TYPE_128SRV_CMPL"; - case ESP_BLE_AD_TYPE_NAME_SHORT: // 0x08 - return "ESP_BLE_AD_TYPE_NAME_SHORT"; - case ESP_BLE_AD_TYPE_NAME_CMPL: // 0x09 - return "ESP_BLE_AD_TYPE_NAME_CMPL"; - case ESP_BLE_AD_TYPE_TX_PWR: // 0x0a - return "ESP_BLE_AD_TYPE_TX_PWR"; - case ESP_BLE_AD_TYPE_DEV_CLASS: // 0x0b - return "ESP_BLE_AD_TYPE_DEV_CLASS"; - case ESP_BLE_AD_TYPE_SM_TK: // 0x10 - return "ESP_BLE_AD_TYPE_SM_TK"; - case ESP_BLE_AD_TYPE_SM_OOB_FLAG: // 0x11 - return "ESP_BLE_AD_TYPE_SM_OOB_FLAG"; - case ESP_BLE_AD_TYPE_INT_RANGE: // 0x12 - return "ESP_BLE_AD_TYPE_INT_RANGE"; - case ESP_BLE_AD_TYPE_SOL_SRV_UUID: // 0x14 - return "ESP_BLE_AD_TYPE_SOL_SRV_UUID"; - case ESP_BLE_AD_TYPE_128SOL_SRV_UUID: // 0x15 - return "ESP_BLE_AD_TYPE_128SOL_SRV_UUID"; - case ESP_BLE_AD_TYPE_SERVICE_DATA: // 0x16 - return "ESP_BLE_AD_TYPE_SERVICE_DATA"; - case ESP_BLE_AD_TYPE_PUBLIC_TARGET: // 0x17 - return "ESP_BLE_AD_TYPE_PUBLIC_TARGET"; - case ESP_BLE_AD_TYPE_RANDOM_TARGET: // 0x18 - return "ESP_BLE_AD_TYPE_RANDOM_TARGET"; - case ESP_BLE_AD_TYPE_APPEARANCE: // 0x19 - return "ESP_BLE_AD_TYPE_APPEARANCE"; - case ESP_BLE_AD_TYPE_ADV_INT: // 0x1a - return "ESP_BLE_AD_TYPE_ADV_INT"; - case ESP_BLE_AD_TYPE_32SOL_SRV_UUID: - return "ESP_BLE_AD_TYPE_32SOL_SRV_UUID"; - case ESP_BLE_AD_TYPE_32SERVICE_DATA: // 0x20 - return "ESP_BLE_AD_TYPE_32SERVICE_DATA"; - case ESP_BLE_AD_TYPE_128SERVICE_DATA: // 0x21 - return "ESP_BLE_AD_TYPE_128SERVICE_DATA"; - case ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE: // 0xff - return "ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE"; + case ESP_BLE_AD_TYPE_FLAG: // 0x01 + return "ESP_BLE_AD_TYPE_FLAG"; + case ESP_BLE_AD_TYPE_16SRV_PART: // 0x02 + return "ESP_BLE_AD_TYPE_16SRV_PART"; + case ESP_BLE_AD_TYPE_16SRV_CMPL: // 0x03 + return "ESP_BLE_AD_TYPE_16SRV_CMPL"; + case ESP_BLE_AD_TYPE_32SRV_PART: // 0x04 + return "ESP_BLE_AD_TYPE_32SRV_PART"; + case ESP_BLE_AD_TYPE_32SRV_CMPL: // 0x05 + return "ESP_BLE_AD_TYPE_32SRV_CMPL"; + case ESP_BLE_AD_TYPE_128SRV_PART: // 0x06 + return "ESP_BLE_AD_TYPE_128SRV_PART"; + case ESP_BLE_AD_TYPE_128SRV_CMPL: // 0x07 + return "ESP_BLE_AD_TYPE_128SRV_CMPL"; + case ESP_BLE_AD_TYPE_NAME_SHORT: // 0x08 + return "ESP_BLE_AD_TYPE_NAME_SHORT"; + case ESP_BLE_AD_TYPE_NAME_CMPL: // 0x09 + return "ESP_BLE_AD_TYPE_NAME_CMPL"; + case ESP_BLE_AD_TYPE_TX_PWR: // 0x0a + return "ESP_BLE_AD_TYPE_TX_PWR"; + case ESP_BLE_AD_TYPE_DEV_CLASS: // 0x0b + return "ESP_BLE_AD_TYPE_DEV_CLASS"; + case ESP_BLE_AD_TYPE_SM_TK: // 0x10 + return "ESP_BLE_AD_TYPE_SM_TK"; + case ESP_BLE_AD_TYPE_SM_OOB_FLAG: // 0x11 + return "ESP_BLE_AD_TYPE_SM_OOB_FLAG"; + case ESP_BLE_AD_TYPE_INT_RANGE: // 0x12 + return "ESP_BLE_AD_TYPE_INT_RANGE"; + case ESP_BLE_AD_TYPE_SOL_SRV_UUID: // 0x14 + return "ESP_BLE_AD_TYPE_SOL_SRV_UUID"; + case ESP_BLE_AD_TYPE_128SOL_SRV_UUID: // 0x15 + return "ESP_BLE_AD_TYPE_128SOL_SRV_UUID"; + case ESP_BLE_AD_TYPE_SERVICE_DATA: // 0x16 + return "ESP_BLE_AD_TYPE_SERVICE_DATA"; + case ESP_BLE_AD_TYPE_PUBLIC_TARGET: // 0x17 + return "ESP_BLE_AD_TYPE_PUBLIC_TARGET"; + case ESP_BLE_AD_TYPE_RANDOM_TARGET: // 0x18 + return "ESP_BLE_AD_TYPE_RANDOM_TARGET"; + case ESP_BLE_AD_TYPE_APPEARANCE: // 0x19 + return "ESP_BLE_AD_TYPE_APPEARANCE"; + case ESP_BLE_AD_TYPE_ADV_INT: // 0x1a + return "ESP_BLE_AD_TYPE_ADV_INT"; + case ESP_BLE_AD_TYPE_32SOL_SRV_UUID: + return "ESP_BLE_AD_TYPE_32SOL_SRV_UUID"; + case ESP_BLE_AD_TYPE_32SERVICE_DATA: // 0x20 + return "ESP_BLE_AD_TYPE_32SERVICE_DATA"; + case ESP_BLE_AD_TYPE_128SERVICE_DATA: // 0x21 + return "ESP_BLE_AD_TYPE_128SERVICE_DATA"; + case ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE: // 0xff + return "ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE"; #endif - default: - log_v(" adv data type: 0x%x", advType); - return ""; - } // End switch -} // advTypeToString + default: + log_v(" adv data type: 0x%x", advType); + return ""; + } // End switch +} // advTypeToString esp_gatt_id_t BLEUtils::buildGattId(esp_bt_uuid_t uuid, uint8_t inst_id) { - esp_gatt_id_t retGattId; - retGattId.uuid = uuid; - retGattId.inst_id = inst_id; - return retGattId; + esp_gatt_id_t retGattId; + retGattId.uuid = uuid; + retGattId.inst_id = inst_id; + return retGattId; } esp_gatt_srvc_id_t BLEUtils::buildGattSrvcId(esp_gatt_id_t gattId, bool is_primary) { - esp_gatt_srvc_id_t retSrvcId; - retSrvcId.id = gattId; - retSrvcId.is_primary = is_primary; - return retSrvcId; + esp_gatt_srvc_id_t retSrvcId; + retSrvcId.id = gattId; + retSrvcId.is_primary = is_primary; + return retSrvcId; } /** @@ -770,31 +770,31 @@ esp_gatt_srvc_id_t BLEUtils::buildGattSrvcId(esp_gatt_id_t gattId, bool is_prima * @return A pointer to the formatted buffer. */ char* BLEUtils::buildHexData(uint8_t* target, uint8_t* source, uint8_t length) { - // Guard against too much data. - if (length > 100) length = 100; + // Guard against too much data. + if (length > 100) length = 100; - if (target == nullptr) { - target = (uint8_t*) malloc(length * 2 + 1); - if (target == nullptr) { - log_e("buildHexData: malloc failed"); - return nullptr; - } - } - char* startOfData = (char*) target; + if (target == nullptr) { + target = (uint8_t*)malloc(length * 2 + 1); + if (target == nullptr) { + log_e("buildHexData: malloc failed"); + return nullptr; + } + } + char* startOfData = (char*)target; - for (int i = 0; i < length; i++) { - sprintf((char*) target, "%.2x", (char) *source); - source++; - target += 2; - } + for (int i = 0; i < length; i++) { + sprintf((char*)target, "%.2x", (char)*source); + source++; + target += 2; + } - // Handle the special case where there was no data. - if (length == 0) { - *startOfData = 0; - } + // Handle the special case where there was no data. + if (length == 0) { + *startOfData = 0; + } - return startOfData; -} // buildHexData + return startOfData; +} // buildHexData /** @@ -806,14 +806,14 @@ char* BLEUtils::buildHexData(uint8_t* target, uint8_t* source, uint8_t length) { * @return A string representation of a piece of memory. */ String BLEUtils::buildPrintData(uint8_t* source, size_t length) { - String res; - for (int i = 0; i < length; i++) { - char c = *source; - res += (isprint(c) ? c : '.'); - source++; - } - return res; -} // buildPrintData + String res; + for (int i = 0; i < length; i++) { + char c = *source; + res += (isprint(c) ? c : '.'); + source++; + } + return res; +} // buildPrintData /** @@ -822,134 +822,144 @@ String BLEUtils::buildPrintData(uint8_t* source, size_t length) { * @return A string representation of the reason. */ String BLEUtils::gattCloseReasonToString(esp_gatt_conn_reason_t reason) { - switch (reason) { + switch (reason) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - case ESP_GATT_CONN_UNKNOWN: { - return "ESP_GATT_CONN_UNKNOWN"; - } - case ESP_GATT_CONN_L2C_FAILURE: { - return "ESP_GATT_CONN_L2C_FAILURE"; - } - case ESP_GATT_CONN_TIMEOUT: { - return "ESP_GATT_CONN_TIMEOUT"; - } - case ESP_GATT_CONN_TERMINATE_PEER_USER: { - return "ESP_GATT_CONN_TERMINATE_PEER_USER"; - } - case ESP_GATT_CONN_TERMINATE_LOCAL_HOST: { - return "ESP_GATT_CONN_TERMINATE_LOCAL_HOST"; - } - case ESP_GATT_CONN_FAIL_ESTABLISH: { - return "ESP_GATT_CONN_FAIL_ESTABLISH"; - } - case ESP_GATT_CONN_LMP_TIMEOUT: { - return "ESP_GATT_CONN_LMP_TIMEOUT"; - } - case ESP_GATT_CONN_CONN_CANCEL: { - return "ESP_GATT_CONN_CONN_CANCEL"; - } - case ESP_GATT_CONN_NONE: { - return "ESP_GATT_CONN_NONE"; - } + case ESP_GATT_CONN_UNKNOWN: + { + return "ESP_GATT_CONN_UNKNOWN"; + } + case ESP_GATT_CONN_L2C_FAILURE: + { + return "ESP_GATT_CONN_L2C_FAILURE"; + } + case ESP_GATT_CONN_TIMEOUT: + { + return "ESP_GATT_CONN_TIMEOUT"; + } + case ESP_GATT_CONN_TERMINATE_PEER_USER: + { + return "ESP_GATT_CONN_TERMINATE_PEER_USER"; + } + case ESP_GATT_CONN_TERMINATE_LOCAL_HOST: + { + return "ESP_GATT_CONN_TERMINATE_LOCAL_HOST"; + } + case ESP_GATT_CONN_FAIL_ESTABLISH: + { + return "ESP_GATT_CONN_FAIL_ESTABLISH"; + } + case ESP_GATT_CONN_LMP_TIMEOUT: + { + return "ESP_GATT_CONN_LMP_TIMEOUT"; + } + case ESP_GATT_CONN_CONN_CANCEL: + { + return "ESP_GATT_CONN_CONN_CANCEL"; + } + case ESP_GATT_CONN_NONE: + { + return "ESP_GATT_CONN_NONE"; + } #endif - default: { - return "Unknown"; - } - } -} // gattCloseReasonToString + default: + { + return "Unknown"; + } + } +} // gattCloseReasonToString String BLEUtils::gattClientEventTypeToString(esp_gattc_cb_event_t eventType) { - switch (eventType) { + switch (eventType) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - case ESP_GATTC_ACL_EVT: - return "ESP_GATTC_ACL_EVT"; - case ESP_GATTC_ADV_DATA_EVT: - return "ESP_GATTC_ADV_DATA_EVT"; - case ESP_GATTC_ADV_VSC_EVT: - return "ESP_GATTC_ADV_VSC_EVT"; - case ESP_GATTC_BTH_SCAN_CFG_EVT: - return "ESP_GATTC_BTH_SCAN_CFG_EVT"; - case ESP_GATTC_BTH_SCAN_DIS_EVT: - return "ESP_GATTC_BTH_SCAN_DIS_EVT"; - case ESP_GATTC_BTH_SCAN_ENB_EVT: - return "ESP_GATTC_BTH_SCAN_ENB_EVT"; - case ESP_GATTC_BTH_SCAN_PARAM_EVT: - return "ESP_GATTC_BTH_SCAN_PARAM_EVT"; - case ESP_GATTC_BTH_SCAN_RD_EVT: - return "ESP_GATTC_BTH_SCAN_RD_EVT"; - case ESP_GATTC_BTH_SCAN_THR_EVT: - return "ESP_GATTC_BTH_SCAN_THR_EVT"; - case ESP_GATTC_CANCEL_OPEN_EVT: - return "ESP_GATTC_CANCEL_OPEN_EVT"; - case ESP_GATTC_CFG_MTU_EVT: - return "ESP_GATTC_CFG_MTU_EVT"; - case ESP_GATTC_CLOSE_EVT: - return "ESP_GATTC_CLOSE_EVT"; - case ESP_GATTC_CONGEST_EVT: - return "ESP_GATTC_CONGEST_EVT"; - case ESP_GATTC_CONNECT_EVT: - return "ESP_GATTC_CONNECT_EVT"; - case ESP_GATTC_DISCONNECT_EVT: - return "ESP_GATTC_DISCONNECT_EVT"; - case ESP_GATTC_ENC_CMPL_CB_EVT: - return "ESP_GATTC_ENC_CMPL_CB_EVT"; - case ESP_GATTC_EXEC_EVT: - return "ESP_GATTC_EXEC_EVT"; - //case ESP_GATTC_GET_CHAR_EVT: -// return "ESP_GATTC_GET_CHAR_EVT"; - //case ESP_GATTC_GET_DESCR_EVT: -// return "ESP_GATTC_GET_DESCR_EVT"; - //case ESP_GATTC_GET_INCL_SRVC_EVT: -// return "ESP_GATTC_GET_INCL_SRVC_EVT"; - case ESP_GATTC_MULT_ADV_DATA_EVT: - return "ESP_GATTC_MULT_ADV_DATA_EVT"; - case ESP_GATTC_MULT_ADV_DIS_EVT: - return "ESP_GATTC_MULT_ADV_DIS_EVT"; - case ESP_GATTC_MULT_ADV_ENB_EVT: - return "ESP_GATTC_MULT_ADV_ENB_EVT"; - case ESP_GATTC_MULT_ADV_UPD_EVT: - return "ESP_GATTC_MULT_ADV_UPD_EVT"; - case ESP_GATTC_NOTIFY_EVT: - return "ESP_GATTC_NOTIFY_EVT"; - case ESP_GATTC_OPEN_EVT: - return "ESP_GATTC_OPEN_EVT"; - case ESP_GATTC_PREP_WRITE_EVT: - return "ESP_GATTC_PREP_WRITE_EVT"; - case ESP_GATTC_READ_CHAR_EVT: - return "ESP_GATTC_READ_CHAR_EVT"; - case ESP_GATTC_REG_EVT: - return "ESP_GATTC_REG_EVT"; - case ESP_GATTC_REG_FOR_NOTIFY_EVT: - return "ESP_GATTC_REG_FOR_NOTIFY_EVT"; - case ESP_GATTC_SCAN_FLT_CFG_EVT: - return "ESP_GATTC_SCAN_FLT_CFG_EVT"; - case ESP_GATTC_SCAN_FLT_PARAM_EVT: - return "ESP_GATTC_SCAN_FLT_PARAM_EVT"; - case ESP_GATTC_SCAN_FLT_STATUS_EVT: - return "ESP_GATTC_SCAN_FLT_STATUS_EVT"; - case ESP_GATTC_SEARCH_CMPL_EVT: - return "ESP_GATTC_SEARCH_CMPL_EVT"; - case ESP_GATTC_SEARCH_RES_EVT: - return "ESP_GATTC_SEARCH_RES_EVT"; - case ESP_GATTC_SRVC_CHG_EVT: - return "ESP_GATTC_SRVC_CHG_EVT"; - case ESP_GATTC_READ_DESCR_EVT: - return "ESP_GATTC_READ_DESCR_EVT"; - case ESP_GATTC_UNREG_EVT: - return "ESP_GATTC_UNREG_EVT"; - case ESP_GATTC_UNREG_FOR_NOTIFY_EVT: - return "ESP_GATTC_UNREG_FOR_NOTIFY_EVT"; - case ESP_GATTC_WRITE_CHAR_EVT: - return "ESP_GATTC_WRITE_CHAR_EVT"; - case ESP_GATTC_WRITE_DESCR_EVT: - return "ESP_GATTC_WRITE_DESCR_EVT"; + case ESP_GATTC_ACL_EVT: + return "ESP_GATTC_ACL_EVT"; + case ESP_GATTC_ADV_DATA_EVT: + return "ESP_GATTC_ADV_DATA_EVT"; + case ESP_GATTC_ADV_VSC_EVT: + return "ESP_GATTC_ADV_VSC_EVT"; + case ESP_GATTC_BTH_SCAN_CFG_EVT: + return "ESP_GATTC_BTH_SCAN_CFG_EVT"; + case ESP_GATTC_BTH_SCAN_DIS_EVT: + return "ESP_GATTC_BTH_SCAN_DIS_EVT"; + case ESP_GATTC_BTH_SCAN_ENB_EVT: + return "ESP_GATTC_BTH_SCAN_ENB_EVT"; + case ESP_GATTC_BTH_SCAN_PARAM_EVT: + return "ESP_GATTC_BTH_SCAN_PARAM_EVT"; + case ESP_GATTC_BTH_SCAN_RD_EVT: + return "ESP_GATTC_BTH_SCAN_RD_EVT"; + case ESP_GATTC_BTH_SCAN_THR_EVT: + return "ESP_GATTC_BTH_SCAN_THR_EVT"; + case ESP_GATTC_CANCEL_OPEN_EVT: + return "ESP_GATTC_CANCEL_OPEN_EVT"; + case ESP_GATTC_CFG_MTU_EVT: + return "ESP_GATTC_CFG_MTU_EVT"; + case ESP_GATTC_CLOSE_EVT: + return "ESP_GATTC_CLOSE_EVT"; + case ESP_GATTC_CONGEST_EVT: + return "ESP_GATTC_CONGEST_EVT"; + case ESP_GATTC_CONNECT_EVT: + return "ESP_GATTC_CONNECT_EVT"; + case ESP_GATTC_DISCONNECT_EVT: + return "ESP_GATTC_DISCONNECT_EVT"; + case ESP_GATTC_ENC_CMPL_CB_EVT: + return "ESP_GATTC_ENC_CMPL_CB_EVT"; + case ESP_GATTC_EXEC_EVT: + return "ESP_GATTC_EXEC_EVT"; + //case ESP_GATTC_GET_CHAR_EVT: + // return "ESP_GATTC_GET_CHAR_EVT"; + //case ESP_GATTC_GET_DESCR_EVT: + // return "ESP_GATTC_GET_DESCR_EVT"; + //case ESP_GATTC_GET_INCL_SRVC_EVT: + // return "ESP_GATTC_GET_INCL_SRVC_EVT"; + case ESP_GATTC_MULT_ADV_DATA_EVT: + return "ESP_GATTC_MULT_ADV_DATA_EVT"; + case ESP_GATTC_MULT_ADV_DIS_EVT: + return "ESP_GATTC_MULT_ADV_DIS_EVT"; + case ESP_GATTC_MULT_ADV_ENB_EVT: + return "ESP_GATTC_MULT_ADV_ENB_EVT"; + case ESP_GATTC_MULT_ADV_UPD_EVT: + return "ESP_GATTC_MULT_ADV_UPD_EVT"; + case ESP_GATTC_NOTIFY_EVT: + return "ESP_GATTC_NOTIFY_EVT"; + case ESP_GATTC_OPEN_EVT: + return "ESP_GATTC_OPEN_EVT"; + case ESP_GATTC_PREP_WRITE_EVT: + return "ESP_GATTC_PREP_WRITE_EVT"; + case ESP_GATTC_READ_CHAR_EVT: + return "ESP_GATTC_READ_CHAR_EVT"; + case ESP_GATTC_REG_EVT: + return "ESP_GATTC_REG_EVT"; + case ESP_GATTC_REG_FOR_NOTIFY_EVT: + return "ESP_GATTC_REG_FOR_NOTIFY_EVT"; + case ESP_GATTC_SCAN_FLT_CFG_EVT: + return "ESP_GATTC_SCAN_FLT_CFG_EVT"; + case ESP_GATTC_SCAN_FLT_PARAM_EVT: + return "ESP_GATTC_SCAN_FLT_PARAM_EVT"; + case ESP_GATTC_SCAN_FLT_STATUS_EVT: + return "ESP_GATTC_SCAN_FLT_STATUS_EVT"; + case ESP_GATTC_SEARCH_CMPL_EVT: + return "ESP_GATTC_SEARCH_CMPL_EVT"; + case ESP_GATTC_SEARCH_RES_EVT: + return "ESP_GATTC_SEARCH_RES_EVT"; + case ESP_GATTC_SRVC_CHG_EVT: + return "ESP_GATTC_SRVC_CHG_EVT"; + case ESP_GATTC_READ_DESCR_EVT: + return "ESP_GATTC_READ_DESCR_EVT"; + case ESP_GATTC_UNREG_EVT: + return "ESP_GATTC_UNREG_EVT"; + case ESP_GATTC_UNREG_FOR_NOTIFY_EVT: + return "ESP_GATTC_UNREG_FOR_NOTIFY_EVT"; + case ESP_GATTC_WRITE_CHAR_EVT: + return "ESP_GATTC_WRITE_CHAR_EVT"; + case ESP_GATTC_WRITE_DESCR_EVT: + return "ESP_GATTC_WRITE_DESCR_EVT"; #endif - default: - log_v("Unknown GATT Client event type: %d", eventType); - return "Unknown"; - } -} // gattClientEventTypeToString + default: + log_v("Unknown GATT Client event type: %d", eventType); + return "Unknown"; + } +} // gattClientEventTypeToString /** @@ -958,63 +968,63 @@ String BLEUtils::gattClientEventTypeToString(esp_gattc_cb_event_t eventType) { * @return A string representation of the GATT server event code. */ String BLEUtils::gattServerEventTypeToString(esp_gatts_cb_event_t eventType) { - switch (eventType) { + switch (eventType) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - case ESP_GATTS_REG_EVT: - return "ESP_GATTS_REG_EVT"; - case ESP_GATTS_READ_EVT: - return "ESP_GATTS_READ_EVT"; - case ESP_GATTS_WRITE_EVT: - return "ESP_GATTS_WRITE_EVT"; - case ESP_GATTS_EXEC_WRITE_EVT: - return "ESP_GATTS_EXEC_WRITE_EVT"; - case ESP_GATTS_MTU_EVT: - return "ESP_GATTS_MTU_EVT"; - case ESP_GATTS_CONF_EVT: - return "ESP_GATTS_CONF_EVT"; - case ESP_GATTS_UNREG_EVT: - return "ESP_GATTS_UNREG_EVT"; - case ESP_GATTS_CREATE_EVT: - return "ESP_GATTS_CREATE_EVT"; - case ESP_GATTS_ADD_INCL_SRVC_EVT: - return "ESP_GATTS_ADD_INCL_SRVC_EVT"; - case ESP_GATTS_ADD_CHAR_EVT: - return "ESP_GATTS_ADD_CHAR_EVT"; - case ESP_GATTS_ADD_CHAR_DESCR_EVT: - return "ESP_GATTS_ADD_CHAR_DESCR_EVT"; - case ESP_GATTS_DELETE_EVT: - return "ESP_GATTS_DELETE_EVT"; - case ESP_GATTS_START_EVT: - return "ESP_GATTS_START_EVT"; - case ESP_GATTS_STOP_EVT: - return "ESP_GATTS_STOP_EVT"; - case ESP_GATTS_CONNECT_EVT: - return "ESP_GATTS_CONNECT_EVT"; - case ESP_GATTS_DISCONNECT_EVT: - return "ESP_GATTS_DISCONNECT_EVT"; - case ESP_GATTS_OPEN_EVT: - return "ESP_GATTS_OPEN_EVT"; - case ESP_GATTS_CANCEL_OPEN_EVT: - return "ESP_GATTS_CANCEL_OPEN_EVT"; - case ESP_GATTS_CLOSE_EVT: - return "ESP_GATTS_CLOSE_EVT"; - case ESP_GATTS_LISTEN_EVT: - return "ESP_GATTS_LISTEN_EVT"; - case ESP_GATTS_CONGEST_EVT: - return "ESP_GATTS_CONGEST_EVT"; - case ESP_GATTS_RESPONSE_EVT: - return "ESP_GATTS_RESPONSE_EVT"; - case ESP_GATTS_CREAT_ATTR_TAB_EVT: - return "ESP_GATTS_CREAT_ATTR_TAB_EVT"; - case ESP_GATTS_SET_ATTR_VAL_EVT: - return "ESP_GATTS_SET_ATTR_VAL_EVT"; - case ESP_GATTS_SEND_SERVICE_CHANGE_EVT: - return "ESP_GATTS_SEND_SERVICE_CHANGE_EVT"; + case ESP_GATTS_REG_EVT: + return "ESP_GATTS_REG_EVT"; + case ESP_GATTS_READ_EVT: + return "ESP_GATTS_READ_EVT"; + case ESP_GATTS_WRITE_EVT: + return "ESP_GATTS_WRITE_EVT"; + case ESP_GATTS_EXEC_WRITE_EVT: + return "ESP_GATTS_EXEC_WRITE_EVT"; + case ESP_GATTS_MTU_EVT: + return "ESP_GATTS_MTU_EVT"; + case ESP_GATTS_CONF_EVT: + return "ESP_GATTS_CONF_EVT"; + case ESP_GATTS_UNREG_EVT: + return "ESP_GATTS_UNREG_EVT"; + case ESP_GATTS_CREATE_EVT: + return "ESP_GATTS_CREATE_EVT"; + case ESP_GATTS_ADD_INCL_SRVC_EVT: + return "ESP_GATTS_ADD_INCL_SRVC_EVT"; + case ESP_GATTS_ADD_CHAR_EVT: + return "ESP_GATTS_ADD_CHAR_EVT"; + case ESP_GATTS_ADD_CHAR_DESCR_EVT: + return "ESP_GATTS_ADD_CHAR_DESCR_EVT"; + case ESP_GATTS_DELETE_EVT: + return "ESP_GATTS_DELETE_EVT"; + case ESP_GATTS_START_EVT: + return "ESP_GATTS_START_EVT"; + case ESP_GATTS_STOP_EVT: + return "ESP_GATTS_STOP_EVT"; + case ESP_GATTS_CONNECT_EVT: + return "ESP_GATTS_CONNECT_EVT"; + case ESP_GATTS_DISCONNECT_EVT: + return "ESP_GATTS_DISCONNECT_EVT"; + case ESP_GATTS_OPEN_EVT: + return "ESP_GATTS_OPEN_EVT"; + case ESP_GATTS_CANCEL_OPEN_EVT: + return "ESP_GATTS_CANCEL_OPEN_EVT"; + case ESP_GATTS_CLOSE_EVT: + return "ESP_GATTS_CLOSE_EVT"; + case ESP_GATTS_LISTEN_EVT: + return "ESP_GATTS_LISTEN_EVT"; + case ESP_GATTS_CONGEST_EVT: + return "ESP_GATTS_CONGEST_EVT"; + case ESP_GATTS_RESPONSE_EVT: + return "ESP_GATTS_RESPONSE_EVT"; + case ESP_GATTS_CREAT_ATTR_TAB_EVT: + return "ESP_GATTS_CREAT_ATTR_TAB_EVT"; + case ESP_GATTS_SET_ATTR_VAL_EVT: + return "ESP_GATTS_SET_ATTR_VAL_EVT"; + case ESP_GATTS_SEND_SERVICE_CHANGE_EVT: + return "ESP_GATTS_SEND_SERVICE_CHANGE_EVT"; #endif - default: - return "Unknown"; - } -} // gattServerEventTypeToString + default: + return "Unknown"; + } +} // gattServerEventTypeToString @@ -1023,247 +1033,264 @@ String BLEUtils::gattServerEventTypeToString(esp_gatts_cb_event_t eventType) { * @param [in] type The device type. */ const char* BLEUtils::devTypeToString(esp_bt_dev_type_t type) { - switch (type) { + switch (type) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - case ESP_BT_DEVICE_TYPE_BREDR: - return "ESP_BT_DEVICE_TYPE_BREDR"; - case ESP_BT_DEVICE_TYPE_BLE: - return "ESP_BT_DEVICE_TYPE_BLE"; - case ESP_BT_DEVICE_TYPE_DUMO: - return "ESP_BT_DEVICE_TYPE_DUMO"; + case ESP_BT_DEVICE_TYPE_BREDR: + return "ESP_BT_DEVICE_TYPE_BREDR"; + case ESP_BT_DEVICE_TYPE_BLE: + return "ESP_BT_DEVICE_TYPE_BLE"; + case ESP_BT_DEVICE_TYPE_DUMO: + return "ESP_BT_DEVICE_TYPE_DUMO"; #endif - default: - return "Unknown"; - } -} // devTypeToString + default: + return "Unknown"; + } +} // devTypeToString /** * @brief Dump the GAP event to the log. */ void BLEUtils::dumpGapEvent( - esp_gap_ble_cb_event_t event, - esp_ble_gap_cb_param_t* param) { - log_v("Received a GAP event: %s", gapEventToString(event)); - switch (event) { + esp_gap_ble_cb_event_t event, + esp_ble_gap_cb_param_t* param) { + log_v("Received a GAP event: %s", gapEventToString(event)); + switch (event) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - // ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT - // adv_data_cmpl - // - esp_bt_status_t - case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: { - log_v("[status: %d]", param->adv_data_cmpl.status); - break; - } // ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT - - // ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT - // - // adv_data_raw_cmpl - // - esp_bt_status_t status - case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT: { - log_v("[status: %d]", param->adv_data_raw_cmpl.status); - break; - } // ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT - - // ESP_GAP_BLE_ADV_START_COMPLETE_EVT - // - // adv_start_cmpl - // - esp_bt_status_t status - case ESP_GAP_BLE_ADV_START_COMPLETE_EVT: { - log_v("[status: %d]", param->adv_start_cmpl.status); - break; - } // ESP_GAP_BLE_ADV_START_COMPLETE_EVT - - // ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT - // - // adv_stop_cmpl - // - esp_bt_status_t status - case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT: { - log_v("[status: %d]", param->adv_stop_cmpl.status); - break; - } // ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT - - // ESP_GAP_BLE_AUTH_CMPL_EVT - // - // auth_cmpl - // - esp_bd_addr_t bd_addr - // - bool key_present - // - esp_link_key key - // - bool success - // - uint8_t fail_reason - // - esp_bd_addr_type_t addr_type - // - esp_bt_dev_type_t dev_type - case ESP_GAP_BLE_AUTH_CMPL_EVT: { - log_v("[bd_addr: %s, key_present: %d, key: ***, key_type: %d, success: %d, fail_reason: %d, addr_type: ***, dev_type: %s]", - BLEAddress(param->ble_security.auth_cmpl.bd_addr).toString().c_str(), - param->ble_security.auth_cmpl.key_present, - param->ble_security.auth_cmpl.key_type, - param->ble_security.auth_cmpl.success, - param->ble_security.auth_cmpl.fail_reason, - BLEUtils::devTypeToString(param->ble_security.auth_cmpl.dev_type) - ); - break; - } // ESP_GAP_BLE_AUTH_CMPL_EVT - - // ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT - // - // clear_bond_dev_cmpl - // - esp_bt_status_t status - case ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT: { - log_v("[status: %d]", param->clear_bond_dev_cmpl.status); - break; - } // ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT - - // ESP_GAP_BLE_LOCAL_IR_EVT - case ESP_GAP_BLE_LOCAL_IR_EVT: { - break; - } // ESP_GAP_BLE_LOCAL_IR_EVT - - // ESP_GAP_BLE_LOCAL_ER_EVT - case ESP_GAP_BLE_LOCAL_ER_EVT: { - break; - } // ESP_GAP_BLE_LOCAL_ER_EVT - - // ESP_GAP_BLE_NC_REQ_EVT - case ESP_GAP_BLE_NC_REQ_EVT: { - log_v("[bd_addr: %s, passkey: %d]", - BLEAddress(param->ble_security.key_notif.bd_addr).toString().c_str(), - param->ble_security.key_notif.passkey); - break; - } // ESP_GAP_BLE_NC_REQ_EVT - - // ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT - // - // read_rssi_cmpl - // - esp_bt_status_t status - // - int8_t rssi - // - esp_bd_addr_t remote_addr - case ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT: { - log_v("[status: %d, rssi: %d, remote_addr: %s]", - param->read_rssi_cmpl.status, - param->read_rssi_cmpl.rssi, - BLEAddress(param->read_rssi_cmpl.remote_addr).toString().c_str() - ); - break; - } // ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT - - // ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT - // - // scan_param_cmpl. - // - esp_bt_status_t status - case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: { - log_v("[status: %d]", param->scan_param_cmpl.status); - break; - } // ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT - - // ESP_GAP_BLE_SCAN_RESULT_EVT - // - // scan_rst: - // - search_evt - // - bda - // - dev_type - // - ble_addr_type - // - ble_evt_type - // - rssi - // - ble_adv - // - flag - // - num_resps - // - adv_data_len - // - scan_rsp_len - case ESP_GAP_BLE_SCAN_RESULT_EVT: { - switch (param->scan_rst.search_evt) { - case ESP_GAP_SEARCH_INQ_RES_EVT: { - log_v("search_evt: %s, bda: %s, dev_type: %s, ble_addr_type: %s, ble_evt_type: %s, rssi: %d, ble_adv: ??, flag: %d (%s), num_resps: %d, adv_data_len: %d, scan_rsp_len: %d", - searchEventTypeToString(param->scan_rst.search_evt), - BLEAddress(param->scan_rst.bda).toString().c_str(), - devTypeToString(param->scan_rst.dev_type), - addressTypeToString(param->scan_rst.ble_addr_type), - eventTypeToString(param->scan_rst.ble_evt_type), - param->scan_rst.rssi, - param->scan_rst.flag, - adFlagsToString(param->scan_rst.flag).c_str(), - param->scan_rst.num_resps, - param->scan_rst.adv_data_len, - param->scan_rst.scan_rsp_len - ); - break; - } // ESP_GAP_SEARCH_INQ_RES_EVT - - default: { - log_v("search_evt: %s",searchEventTypeToString(param->scan_rst.search_evt)); - break; - } - } - break; - } // ESP_GAP_BLE_SCAN_RESULT_EVT - - // ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT - // - // scan_rsp_data_cmpl - // - esp_bt_status_t status - case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT: { - log_v("[status: %d]", param->scan_rsp_data_cmpl.status); - break; - } // ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT - - // ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT - case ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT: { - log_v("[status: %d]", param->scan_rsp_data_raw_cmpl.status); - break; - } // ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT - - // ESP_GAP_BLE_SCAN_START_COMPLETE_EVT - // - // scan_start_cmpl - // - esp_bt_status_t status - case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT: { - log_v("[status: %d]", param->scan_start_cmpl.status); - break; - } // ESP_GAP_BLE_SCAN_START_COMPLETE_EVT - - // ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT - // - // scan_stop_cmpl - // - esp_bt_status_t status - case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT: { - log_v("[status: %d]", param->scan_stop_cmpl.status); - break; - } // ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT - - // ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT - // - // update_conn_params - // - esp_bt_status_t status - // - esp_bd_addr_t bda - // - uint16_t min_int - // - uint16_t max_int - // - uint16_t latency - // - uint16_t conn_int - // - uint16_t timeout - case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT: { - log_v("[status: %d, bd_addr: %s, min_int: %d, max_int: %d, latency: %d, conn_int: %d, timeout: %d]", - param->update_conn_params.status, - BLEAddress(param->update_conn_params.bda).toString().c_str(), - param->update_conn_params.min_int, - param->update_conn_params.max_int, - param->update_conn_params.latency, - param->update_conn_params.conn_int, - param->update_conn_params.timeout - ); - break; - } // ESP_GAP_BLE_SCAN_UPDATE_CONN_PARAMS_EVT - - // ESP_GAP_BLE_SEC_REQ_EVT - case ESP_GAP_BLE_SEC_REQ_EVT: { - log_v("[bd_addr: %s]", BLEAddress(param->ble_security.ble_req.bd_addr).toString().c_str()); - break; - } // ESP_GAP_BLE_SEC_REQ_EVT + // ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT + // adv_data_cmpl + // - esp_bt_status_t + case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: + { + log_v("[status: %d]", param->adv_data_cmpl.status); + break; + } // ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT + + // ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT + // + // adv_data_raw_cmpl + // - esp_bt_status_t status + case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT: + { + log_v("[status: %d]", param->adv_data_raw_cmpl.status); + break; + } // ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT + + // ESP_GAP_BLE_ADV_START_COMPLETE_EVT + // + // adv_start_cmpl + // - esp_bt_status_t status + case ESP_GAP_BLE_ADV_START_COMPLETE_EVT: + { + log_v("[status: %d]", param->adv_start_cmpl.status); + break; + } // ESP_GAP_BLE_ADV_START_COMPLETE_EVT + + // ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT + // + // adv_stop_cmpl + // - esp_bt_status_t status + case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT: + { + log_v("[status: %d]", param->adv_stop_cmpl.status); + break; + } // ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT + + // ESP_GAP_BLE_AUTH_CMPL_EVT + // + // auth_cmpl + // - esp_bd_addr_t bd_addr + // - bool key_present + // - esp_link_key key + // - bool success + // - uint8_t fail_reason + // - esp_bd_addr_type_t addr_type + // - esp_bt_dev_type_t dev_type + case ESP_GAP_BLE_AUTH_CMPL_EVT: + { + log_v("[bd_addr: %s, key_present: %d, key: ***, key_type: %d, success: %d, fail_reason: %d, addr_type: ***, dev_type: %s]", + BLEAddress(param->ble_security.auth_cmpl.bd_addr).toString().c_str(), + param->ble_security.auth_cmpl.key_present, + param->ble_security.auth_cmpl.key_type, + param->ble_security.auth_cmpl.success, + param->ble_security.auth_cmpl.fail_reason, + BLEUtils::devTypeToString(param->ble_security.auth_cmpl.dev_type)); + break; + } // ESP_GAP_BLE_AUTH_CMPL_EVT + + // ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT + // + // clear_bond_dev_cmpl + // - esp_bt_status_t status + case ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT: + { + log_v("[status: %d]", param->clear_bond_dev_cmpl.status); + break; + } // ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT + + // ESP_GAP_BLE_LOCAL_IR_EVT + case ESP_GAP_BLE_LOCAL_IR_EVT: + { + break; + } // ESP_GAP_BLE_LOCAL_IR_EVT + + // ESP_GAP_BLE_LOCAL_ER_EVT + case ESP_GAP_BLE_LOCAL_ER_EVT: + { + break; + } // ESP_GAP_BLE_LOCAL_ER_EVT + + // ESP_GAP_BLE_NC_REQ_EVT + case ESP_GAP_BLE_NC_REQ_EVT: + { + log_v("[bd_addr: %s, passkey: %d]", + BLEAddress(param->ble_security.key_notif.bd_addr).toString().c_str(), + param->ble_security.key_notif.passkey); + break; + } // ESP_GAP_BLE_NC_REQ_EVT + + // ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT + // + // read_rssi_cmpl + // - esp_bt_status_t status + // - int8_t rssi + // - esp_bd_addr_t remote_addr + case ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT: + { + log_v("[status: %d, rssi: %d, remote_addr: %s]", + param->read_rssi_cmpl.status, + param->read_rssi_cmpl.rssi, + BLEAddress(param->read_rssi_cmpl.remote_addr).toString().c_str()); + break; + } // ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT + + // ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT + // + // scan_param_cmpl. + // - esp_bt_status_t status + case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: + { + log_v("[status: %d]", param->scan_param_cmpl.status); + break; + } // ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT + + // ESP_GAP_BLE_SCAN_RESULT_EVT + // + // scan_rst: + // - search_evt + // - bda + // - dev_type + // - ble_addr_type + // - ble_evt_type + // - rssi + // - ble_adv + // - flag + // - num_resps + // - adv_data_len + // - scan_rsp_len + case ESP_GAP_BLE_SCAN_RESULT_EVT: + { + switch (param->scan_rst.search_evt) { + case ESP_GAP_SEARCH_INQ_RES_EVT: + { + log_v("search_evt: %s, bda: %s, dev_type: %s, ble_addr_type: %s, ble_evt_type: %s, rssi: %d, ble_adv: ??, flag: %d (%s), num_resps: %d, adv_data_len: %d, scan_rsp_len: %d", + searchEventTypeToString(param->scan_rst.search_evt), + BLEAddress(param->scan_rst.bda).toString().c_str(), + devTypeToString(param->scan_rst.dev_type), + addressTypeToString(param->scan_rst.ble_addr_type), + eventTypeToString(param->scan_rst.ble_evt_type), + param->scan_rst.rssi, + param->scan_rst.flag, + adFlagsToString(param->scan_rst.flag).c_str(), + param->scan_rst.num_resps, + param->scan_rst.adv_data_len, + param->scan_rst.scan_rsp_len); + break; + } // ESP_GAP_SEARCH_INQ_RES_EVT + + default: + { + log_v("search_evt: %s", searchEventTypeToString(param->scan_rst.search_evt)); + break; + } + } + break; + } // ESP_GAP_BLE_SCAN_RESULT_EVT + + // ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT + // + // scan_rsp_data_cmpl + // - esp_bt_status_t status + case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT: + { + log_v("[status: %d]", param->scan_rsp_data_cmpl.status); + break; + } // ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT + + // ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT + case ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT: + { + log_v("[status: %d]", param->scan_rsp_data_raw_cmpl.status); + break; + } // ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT + + // ESP_GAP_BLE_SCAN_START_COMPLETE_EVT + // + // scan_start_cmpl + // - esp_bt_status_t status + case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT: + { + log_v("[status: %d]", param->scan_start_cmpl.status); + break; + } // ESP_GAP_BLE_SCAN_START_COMPLETE_EVT + + // ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT + // + // scan_stop_cmpl + // - esp_bt_status_t status + case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT: + { + log_v("[status: %d]", param->scan_stop_cmpl.status); + break; + } // ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT + + // ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT + // + // update_conn_params + // - esp_bt_status_t status + // - esp_bd_addr_t bda + // - uint16_t min_int + // - uint16_t max_int + // - uint16_t latency + // - uint16_t conn_int + // - uint16_t timeout + case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT: + { + log_v("[status: %d, bd_addr: %s, min_int: %d, max_int: %d, latency: %d, conn_int: %d, timeout: %d]", + param->update_conn_params.status, + BLEAddress(param->update_conn_params.bda).toString().c_str(), + param->update_conn_params.min_int, + param->update_conn_params.max_int, + param->update_conn_params.latency, + param->update_conn_params.conn_int, + param->update_conn_params.timeout); + break; + } // ESP_GAP_BLE_SCAN_UPDATE_CONN_PARAMS_EVT + + // ESP_GAP_BLE_SEC_REQ_EVT + case ESP_GAP_BLE_SEC_REQ_EVT: + { + log_v("[bd_addr: %s]", BLEAddress(param->ble_security.ble_req.bd_addr).toString().c_str()); + break; + } // ESP_GAP_BLE_SEC_REQ_EVT #endif - default: { - log_v("*** dumpGapEvent: Logger not coded ***"); - break; - } // default - } // switch -} // dumpGapEvent + default: + { + log_v("*** dumpGapEvent: Logger not coded ***"); + break; + } // default + } // switch +} // dumpGapEvent /** @@ -1273,67 +1300,68 @@ void BLEUtils::dumpGapEvent( * @param [in] evtParam The data associated with the event. */ void BLEUtils::dumpGattClientEvent( - esp_gattc_cb_event_t event, - esp_gatt_if_t gattc_if, - esp_ble_gattc_cb_param_t* evtParam) { + esp_gattc_cb_event_t event, + esp_gatt_if_t gattc_if, + esp_ble_gattc_cb_param_t* evtParam) { - //esp_ble_gattc_cb_param_t* evtParam = (esp_ble_gattc_cb_param_t*) param; - log_v("GATT Event: %s", BLEUtils::gattClientEventTypeToString(event).c_str()); - switch (event) { + //esp_ble_gattc_cb_param_t* evtParam = (esp_ble_gattc_cb_param_t*) param; + log_v("GATT Event: %s", BLEUtils::gattClientEventTypeToString(event).c_str()); + switch (event) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - // ESP_GATTC_CLOSE_EVT - // - // close: - // - esp_gatt_status_t status - // - uint16_t conn_id - // - esp_bd_addr_t remote_bda - // - esp_gatt_conn_reason_t reason - case ESP_GATTC_CLOSE_EVT: { - log_v("[status: %s, reason:%s, conn_id: %d]", - BLEUtils::gattStatusToString(evtParam->close.status).c_str(), - BLEUtils::gattCloseReasonToString(evtParam->close.reason).c_str(), - evtParam->close.conn_id); - break; - } - - // ESP_GATTC_CONNECT_EVT - // - // connect: - // - esp_gatt_status_t status - // - uint16_t conn_id - // - esp_bd_addr_t remote_bda - case ESP_GATTC_CONNECT_EVT: { - log_v("[conn_id: %d, remote_bda: %s]", - evtParam->connect.conn_id, - BLEAddress(evtParam->connect.remote_bda).toString().c_str() - ); - break; - } - - // ESP_GATTC_DISCONNECT_EVT - // - // disconnect: - // - esp_gatt_conn_reason_t reason - // - uint16_t conn_id - // - esp_bd_addr_t remote_bda - case ESP_GATTC_DISCONNECT_EVT: { - log_v("[reason: %s, conn_id: %d, remote_bda: %s]", - BLEUtils::gattCloseReasonToString(evtParam->disconnect.reason).c_str(), - evtParam->disconnect.conn_id, - BLEAddress(evtParam->disconnect.remote_bda).toString().c_str() - ); - break; - } // ESP_GATTC_DISCONNECT_EVT - - // ESP_GATTC_GET_CHAR_EVT - // - // get_char: - // - esp_gatt_status_t status - // - uin1t6_t conn_id - // - esp_gatt_srvc_id_t srvc_id - // - esp_gatt_id_t char_id - // - esp_gatt_char_prop_t char_prop - /* + // ESP_GATTC_CLOSE_EVT + // + // close: + // - esp_gatt_status_t status + // - uint16_t conn_id + // - esp_bd_addr_t remote_bda + // - esp_gatt_conn_reason_t reason + case ESP_GATTC_CLOSE_EVT: + { + log_v("[status: %s, reason:%s, conn_id: %d]", + BLEUtils::gattStatusToString(evtParam->close.status).c_str(), + BLEUtils::gattCloseReasonToString(evtParam->close.reason).c_str(), + evtParam->close.conn_id); + break; + } + + // ESP_GATTC_CONNECT_EVT + // + // connect: + // - esp_gatt_status_t status + // - uint16_t conn_id + // - esp_bd_addr_t remote_bda + case ESP_GATTC_CONNECT_EVT: + { + log_v("[conn_id: %d, remote_bda: %s]", + evtParam->connect.conn_id, + BLEAddress(evtParam->connect.remote_bda).toString().c_str()); + break; + } + + // ESP_GATTC_DISCONNECT_EVT + // + // disconnect: + // - esp_gatt_conn_reason_t reason + // - uint16_t conn_id + // - esp_bd_addr_t remote_bda + case ESP_GATTC_DISCONNECT_EVT: + { + log_v("[reason: %s, conn_id: %d, remote_bda: %s]", + BLEUtils::gattCloseReasonToString(evtParam->disconnect.reason).c_str(), + evtParam->disconnect.conn_id, + BLEAddress(evtParam->disconnect.remote_bda).toString().c_str()); + break; + } // ESP_GATTC_DISCONNECT_EVT + + // ESP_GATTC_GET_CHAR_EVT + // + // get_char: + // - esp_gatt_status_t status + // - uin1t6_t conn_id + // - esp_gatt_srvc_id_t srvc_id + // - esp_gatt_id_t char_id + // - esp_gatt_char_prop_t char_prop + /* case ESP_GATTC_GET_CHAR_EVT: { // If the status of the event shows that we have a value other than ESP_GATT_OK then the @@ -1362,153 +1390,157 @@ void BLEUtils::dumpGattClientEvent( } // ESP_GATTC_GET_CHAR_EVT */ - // ESP_GATTC_NOTIFY_EVT - // - // notify - // uint16_t conn_id - // esp_bd_addr_t remote_bda - // handle handle - // uint16_t value_len - // uint8_t* value - // bool is_notify - // - case ESP_GATTC_NOTIFY_EVT: { - log_v("[conn_id: %d, remote_bda: %s, handle: %d 0x%.2x, value_len: %d, is_notify: %d]", - evtParam->notify.conn_id, - BLEAddress(evtParam->notify.remote_bda).toString().c_str(), - evtParam->notify.handle, - evtParam->notify.handle, - evtParam->notify.value_len, - evtParam->notify.is_notify - ); - break; - } - - // ESP_GATTC_OPEN_EVT - // - // open: - // - esp_gatt_status_t status - // - uint16_t conn_id - // - esp_bd_addr_t remote_bda - // - uint16_t mtu - // - case ESP_GATTC_OPEN_EVT: { - log_v("[status: %s, conn_id: %d, remote_bda: %s, mtu: %d]", - BLEUtils::gattStatusToString(evtParam->open.status).c_str(), - evtParam->open.conn_id, - BLEAddress(evtParam->open.remote_bda).toString().c_str(), - evtParam->open.mtu); - break; - } // ESP_GATTC_OPEN_EVT - - // ESP_GATTC_READ_CHAR_EVT - // - // Callback to indicate that requested data that we wanted to read is now available. - // - // read: - // esp_gatt_status_t status - // uint16_t conn_id - // uint16_t handle - // uint8_t* value - // uint16_t value_type - // uint16_t value_len - case ESP_GATTC_READ_CHAR_EVT: { - log_v("[status: %s, conn_id: %d, handle: %d 0x%.2x, value_len: %d]", - BLEUtils::gattStatusToString(evtParam->read.status).c_str(), - evtParam->read.conn_id, - evtParam->read.handle, - evtParam->read.handle, - evtParam->read.value_len - ); - if (evtParam->read.status == ESP_GATT_OK) { - GeneralUtils::hexDump(evtParam->read.value, evtParam->read.value_len); - /* + // ESP_GATTC_NOTIFY_EVT + // + // notify + // uint16_t conn_id + // esp_bd_addr_t remote_bda + // handle handle + // uint16_t value_len + // uint8_t* value + // bool is_notify + // + case ESP_GATTC_NOTIFY_EVT: + { + log_v("[conn_id: %d, remote_bda: %s, handle: %d 0x%.2x, value_len: %d, is_notify: %d]", + evtParam->notify.conn_id, + BLEAddress(evtParam->notify.remote_bda).toString().c_str(), + evtParam->notify.handle, + evtParam->notify.handle, + evtParam->notify.value_len, + evtParam->notify.is_notify); + break; + } + + // ESP_GATTC_OPEN_EVT + // + // open: + // - esp_gatt_status_t status + // - uint16_t conn_id + // - esp_bd_addr_t remote_bda + // - uint16_t mtu + // + case ESP_GATTC_OPEN_EVT: + { + log_v("[status: %s, conn_id: %d, remote_bda: %s, mtu: %d]", + BLEUtils::gattStatusToString(evtParam->open.status).c_str(), + evtParam->open.conn_id, + BLEAddress(evtParam->open.remote_bda).toString().c_str(), + evtParam->open.mtu); + break; + } // ESP_GATTC_OPEN_EVT + + // ESP_GATTC_READ_CHAR_EVT + // + // Callback to indicate that requested data that we wanted to read is now available. + // + // read: + // esp_gatt_status_t status + // uint16_t conn_id + // uint16_t handle + // uint8_t* value + // uint16_t value_type + // uint16_t value_len + case ESP_GATTC_READ_CHAR_EVT: + { + log_v("[status: %s, conn_id: %d, handle: %d 0x%.2x, value_len: %d]", + BLEUtils::gattStatusToString(evtParam->read.status).c_str(), + evtParam->read.conn_id, + evtParam->read.handle, + evtParam->read.handle, + evtParam->read.value_len); + if (evtParam->read.status == ESP_GATT_OK) { + GeneralUtils::hexDump(evtParam->read.value, evtParam->read.value_len); + /* char* pHexData = BLEUtils::buildHexData(nullptr, evtParam->read.value, evtParam->read.value_len); log_v("value: %s \"%s\"", pHexData, BLEUtils::buildPrintData(evtParam->read.value, evtParam->read.value_len).c_str()); free(pHexData); */ - } - break; - } // ESP_GATTC_READ_CHAR_EVT - - // ESP_GATTC_REG_EVT - // - // reg: - // - esp_gatt_status_t status - // - uint16_t app_id - case ESP_GATTC_REG_EVT: { - log_v("[status: %s, app_id: 0x%x]", - BLEUtils::gattStatusToString(evtParam->reg.status).c_str(), - evtParam->reg.app_id); - break; - } // ESP_GATTC_REG_EVT - - // ESP_GATTC_REG_FOR_NOTIFY_EVT - // - // reg_for_notify: - // - esp_gatt_status_t status - // - uint16_t handle - case ESP_GATTC_REG_FOR_NOTIFY_EVT: { - log_v("[status: %s, handle: %d 0x%.2x]", - BLEUtils::gattStatusToString(evtParam->reg_for_notify.status).c_str(), - evtParam->reg_for_notify.handle, - evtParam->reg_for_notify.handle - ); - break; - } // ESP_GATTC_REG_FOR_NOTIFY_EVT - - // ESP_GATTC_SEARCH_CMPL_EVT - // - // search_cmpl: - // - esp_gatt_status_t status - // - uint16_t conn_id - case ESP_GATTC_SEARCH_CMPL_EVT: { - log_v("[status: %s, conn_id: %d]", - BLEUtils::gattStatusToString(evtParam->search_cmpl.status).c_str(), - evtParam->search_cmpl.conn_id); - break; - } // ESP_GATTC_SEARCH_CMPL_EVT - - // ESP_GATTC_SEARCH_RES_EVT - // - // search_res: - // - uint16_t conn_id - // - uint16_t start_handle - // - uint16_t end_handle - // - esp_gatt_id_t srvc_id - case ESP_GATTC_SEARCH_RES_EVT: { - log_v("[conn_id: %d, start_handle: %d 0x%.2x, end_handle: %d 0x%.2x, srvc_id: %s", - evtParam->search_res.conn_id, - evtParam->search_res.start_handle, - evtParam->search_res.start_handle, - evtParam->search_res.end_handle, - evtParam->search_res.end_handle, - gattIdToString(evtParam->search_res.srvc_id).c_str()); - break; - } // ESP_GATTC_SEARCH_RES_EVT - - // ESP_GATTC_WRITE_CHAR_EVT - // - // write: - // - esp_gatt_status_t status - // - uint16_t conn_id - // - uint16_t handle - // - uint16_t offset - case ESP_GATTC_WRITE_CHAR_EVT: { - log_v("[status: %s, conn_id: %d, handle: %d 0x%.2x, offset: %d]", - BLEUtils::gattStatusToString(evtParam->write.status).c_str(), - evtParam->write.conn_id, - evtParam->write.handle, - evtParam->write.handle, - evtParam->write.offset - ); - break; - } // ESP_GATTC_WRITE_CHAR_EVT + } + break; + } // ESP_GATTC_READ_CHAR_EVT + + // ESP_GATTC_REG_EVT + // + // reg: + // - esp_gatt_status_t status + // - uint16_t app_id + case ESP_GATTC_REG_EVT: + { + log_v("[status: %s, app_id: 0x%x]", + BLEUtils::gattStatusToString(evtParam->reg.status).c_str(), + evtParam->reg.app_id); + break; + } // ESP_GATTC_REG_EVT + + // ESP_GATTC_REG_FOR_NOTIFY_EVT + // + // reg_for_notify: + // - esp_gatt_status_t status + // - uint16_t handle + case ESP_GATTC_REG_FOR_NOTIFY_EVT: + { + log_v("[status: %s, handle: %d 0x%.2x]", + BLEUtils::gattStatusToString(evtParam->reg_for_notify.status).c_str(), + evtParam->reg_for_notify.handle, + evtParam->reg_for_notify.handle); + break; + } // ESP_GATTC_REG_FOR_NOTIFY_EVT + + // ESP_GATTC_SEARCH_CMPL_EVT + // + // search_cmpl: + // - esp_gatt_status_t status + // - uint16_t conn_id + case ESP_GATTC_SEARCH_CMPL_EVT: + { + log_v("[status: %s, conn_id: %d]", + BLEUtils::gattStatusToString(evtParam->search_cmpl.status).c_str(), + evtParam->search_cmpl.conn_id); + break; + } // ESP_GATTC_SEARCH_CMPL_EVT + + // ESP_GATTC_SEARCH_RES_EVT + // + // search_res: + // - uint16_t conn_id + // - uint16_t start_handle + // - uint16_t end_handle + // - esp_gatt_id_t srvc_id + case ESP_GATTC_SEARCH_RES_EVT: + { + log_v("[conn_id: %d, start_handle: %d 0x%.2x, end_handle: %d 0x%.2x, srvc_id: %s", + evtParam->search_res.conn_id, + evtParam->search_res.start_handle, + evtParam->search_res.start_handle, + evtParam->search_res.end_handle, + evtParam->search_res.end_handle, + gattIdToString(evtParam->search_res.srvc_id).c_str()); + break; + } // ESP_GATTC_SEARCH_RES_EVT + + // ESP_GATTC_WRITE_CHAR_EVT + // + // write: + // - esp_gatt_status_t status + // - uint16_t conn_id + // - uint16_t handle + // - uint16_t offset + case ESP_GATTC_WRITE_CHAR_EVT: + { + log_v("[status: %s, conn_id: %d, handle: %d 0x%.2x, offset: %d]", + BLEUtils::gattStatusToString(evtParam->write.status).c_str(), + evtParam->write.conn_id, + evtParam->write.handle, + evtParam->write.handle, + evtParam->write.offset); + break; + } // ESP_GATTC_WRITE_CHAR_EVT #endif - default: - break; - } -} // dumpGattClientEvent + default: + break; + } +} // dumpGattClientEvent /** @@ -1522,204 +1554,220 @@ void BLEUtils::dumpGattClientEvent( * @param [in] evtParam A union of structures only one of which is populated. */ void BLEUtils::dumpGattServerEvent( - esp_gatts_cb_event_t event, - esp_gatt_if_t gatts_if, - esp_ble_gatts_cb_param_t* evtParam) { - log_v("GATT ServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str()); - switch (event) { + esp_gatts_cb_event_t event, + esp_gatt_if_t gatts_if, + esp_ble_gatts_cb_param_t* evtParam) { + log_v("GATT ServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str()); + switch (event) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - case ESP_GATTS_ADD_CHAR_DESCR_EVT: { - log_v("[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]", - gattStatusToString(evtParam->add_char_descr.status).c_str(), - evtParam->add_char_descr.attr_handle, - evtParam->add_char_descr.attr_handle, - evtParam->add_char_descr.service_handle, - evtParam->add_char_descr.service_handle, - BLEUUID(evtParam->add_char_descr.descr_uuid).toString().c_str()); - break; - } // ESP_GATTS_ADD_CHAR_DESCR_EVT - - case ESP_GATTS_ADD_CHAR_EVT: { - if (evtParam->add_char.status == ESP_GATT_OK) { - log_v("[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]", - gattStatusToString(evtParam->add_char.status).c_str(), - evtParam->add_char.attr_handle, - evtParam->add_char.attr_handle, - evtParam->add_char.service_handle, - evtParam->add_char.service_handle, - BLEUUID(evtParam->add_char.char_uuid).toString().c_str()); - } else { - log_e("[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]", - gattStatusToString(evtParam->add_char.status).c_str(), - evtParam->add_char.attr_handle, - evtParam->add_char.attr_handle, - evtParam->add_char.service_handle, - evtParam->add_char.service_handle, - BLEUUID(evtParam->add_char.char_uuid).toString().c_str()); - } - break; - } // ESP_GATTS_ADD_CHAR_EVT - - - // ESP_GATTS_CONF_EVT - // - // conf: - // - esp_gatt_status_t status – The status code. - // - uint16_t conn_id – The connection used. - case ESP_GATTS_CONF_EVT: { - log_v("[status: %s, conn_id: 0x%.2x]", - gattStatusToString(evtParam->conf.status).c_str(), - evtParam->conf.conn_id); - break; - } // ESP_GATTS_CONF_EVT - - - case ESP_GATTS_CONGEST_EVT: { - log_v("[conn_id: %d, congested: %d]", - evtParam->congest.conn_id, - evtParam->congest.congested); - break; - } // ESP_GATTS_CONGEST_EVT - - case ESP_GATTS_CONNECT_EVT: { - log_v("[conn_id: %d, remote_bda: %s]", - evtParam->connect.conn_id, - BLEAddress(evtParam->connect.remote_bda).toString().c_str()); - break; - } // ESP_GATTS_CONNECT_EVT - - case ESP_GATTS_CREATE_EVT: { - log_v("[status: %s, service_handle: %d 0x%.2x, service_id: [%s]]", - gattStatusToString(evtParam->create.status).c_str(), - evtParam->create.service_handle, - evtParam->create.service_handle, - gattServiceIdToString(evtParam->create.service_id).c_str()); - break; - } // ESP_GATTS_CREATE_EVT - - case ESP_GATTS_DISCONNECT_EVT: { - log_v("[conn_id: %d, remote_bda: %s]", - evtParam->connect.conn_id, - BLEAddress(evtParam->connect.remote_bda).toString().c_str()); - break; - } // ESP_GATTS_DISCONNECT_EVT - - - // ESP_GATTS_EXEC_WRITE_EVT - // exec_write: - // - uint16_t conn_id - // - uint32_t trans_id - // - esp_bd_addr_t bda - // - uint8_t exec_write_flag + case ESP_GATTS_ADD_CHAR_DESCR_EVT: + { + log_v("[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]", + gattStatusToString(evtParam->add_char_descr.status).c_str(), + evtParam->add_char_descr.attr_handle, + evtParam->add_char_descr.attr_handle, + evtParam->add_char_descr.service_handle, + evtParam->add_char_descr.service_handle, + BLEUUID(evtParam->add_char_descr.descr_uuid).toString().c_str()); + break; + } // ESP_GATTS_ADD_CHAR_DESCR_EVT + + case ESP_GATTS_ADD_CHAR_EVT: + { + if (evtParam->add_char.status == ESP_GATT_OK) { + log_v("[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]", + gattStatusToString(evtParam->add_char.status).c_str(), + evtParam->add_char.attr_handle, + evtParam->add_char.attr_handle, + evtParam->add_char.service_handle, + evtParam->add_char.service_handle, + BLEUUID(evtParam->add_char.char_uuid).toString().c_str()); + } else { + log_e("[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]", + gattStatusToString(evtParam->add_char.status).c_str(), + evtParam->add_char.attr_handle, + evtParam->add_char.attr_handle, + evtParam->add_char.service_handle, + evtParam->add_char.service_handle, + BLEUUID(evtParam->add_char.char_uuid).toString().c_str()); + } + break; + } // ESP_GATTS_ADD_CHAR_EVT + + + // ESP_GATTS_CONF_EVT + // + // conf: + // - esp_gatt_status_t status – The status code. + // - uint16_t conn_id – The connection used. + case ESP_GATTS_CONF_EVT: + { + log_v("[status: %s, conn_id: 0x%.2x]", + gattStatusToString(evtParam->conf.status).c_str(), + evtParam->conf.conn_id); + break; + } // ESP_GATTS_CONF_EVT + + + case ESP_GATTS_CONGEST_EVT: + { + log_v("[conn_id: %d, congested: %d]", + evtParam->congest.conn_id, + evtParam->congest.congested); + break; + } // ESP_GATTS_CONGEST_EVT + + case ESP_GATTS_CONNECT_EVT: + { + log_v("[conn_id: %d, remote_bda: %s]", + evtParam->connect.conn_id, + BLEAddress(evtParam->connect.remote_bda).toString().c_str()); + break; + } // ESP_GATTS_CONNECT_EVT + + case ESP_GATTS_CREATE_EVT: + { + log_v("[status: %s, service_handle: %d 0x%.2x, service_id: [%s]]", + gattStatusToString(evtParam->create.status).c_str(), + evtParam->create.service_handle, + evtParam->create.service_handle, + gattServiceIdToString(evtParam->create.service_id).c_str()); + break; + } // ESP_GATTS_CREATE_EVT + + case ESP_GATTS_DISCONNECT_EVT: + { + log_v("[conn_id: %d, remote_bda: %s]", + evtParam->connect.conn_id, + BLEAddress(evtParam->connect.remote_bda).toString().c_str()); + break; + } // ESP_GATTS_DISCONNECT_EVT + + + // ESP_GATTS_EXEC_WRITE_EVT + // exec_write: + // - uint16_t conn_id + // - uint32_t trans_id + // - esp_bd_addr_t bda + // - uint8_t exec_write_flag #ifdef ARDUHAL_LOG_LEVEL_VERBOSE - case ESP_GATTS_EXEC_WRITE_EVT: { - char* pWriteFlagText; - switch (evtParam->exec_write.exec_write_flag) { - case ESP_GATT_PREP_WRITE_EXEC: { - pWriteFlagText = (char*) "WRITE"; - break; - } - - case ESP_GATT_PREP_WRITE_CANCEL: { - pWriteFlagText = (char*) "CANCEL"; - break; - } - - default: - pWriteFlagText = (char*) ""; - break; - } - - log_v("[conn_id: %d, trans_id: %d, bda: %s, exec_write_flag: 0x%.2x=%s]", - evtParam->exec_write.conn_id, - evtParam->exec_write.trans_id, - BLEAddress(evtParam->exec_write.bda).toString().c_str(), - evtParam->exec_write.exec_write_flag, - pWriteFlagText); - break; - } // ESP_GATTS_DISCONNECT_EVT + case ESP_GATTS_EXEC_WRITE_EVT: + { + char* pWriteFlagText; + switch (evtParam->exec_write.exec_write_flag) { + case ESP_GATT_PREP_WRITE_EXEC: + { + pWriteFlagText = (char*)"WRITE"; + break; + } + + case ESP_GATT_PREP_WRITE_CANCEL: + { + pWriteFlagText = (char*)"CANCEL"; + break; + } + + default: + pWriteFlagText = (char*)""; + break; + } + + log_v("[conn_id: %d, trans_id: %d, bda: %s, exec_write_flag: 0x%.2x=%s]", + evtParam->exec_write.conn_id, + evtParam->exec_write.trans_id, + BLEAddress(evtParam->exec_write.bda).toString().c_str(), + evtParam->exec_write.exec_write_flag, + pWriteFlagText); + break; + } // ESP_GATTS_DISCONNECT_EVT #endif - case ESP_GATTS_MTU_EVT: { - log_v("[conn_id: %d, mtu: %d]", - evtParam->mtu.conn_id, - evtParam->mtu.mtu); - break; - } // ESP_GATTS_MTU_EVT - - case ESP_GATTS_READ_EVT: { - log_v("[conn_id: %d, trans_id: %d, bda: %s, handle: 0x%.2x, is_long: %d, need_rsp:%d]", - evtParam->read.conn_id, - evtParam->read.trans_id, - BLEAddress(evtParam->read.bda).toString().c_str(), - evtParam->read.handle, - evtParam->read.is_long, - evtParam->read.need_rsp); - break; - } // ESP_GATTS_READ_EVT - - case ESP_GATTS_RESPONSE_EVT: { - log_v("[status: %s, handle: 0x%.2x]", - gattStatusToString(evtParam->rsp.status).c_str(), - evtParam->rsp.handle); - break; - } // ESP_GATTS_RESPONSE_EVT - - case ESP_GATTS_REG_EVT: { - log_v("[status: %s, app_id: %d]", - gattStatusToString(evtParam->reg.status).c_str(), - evtParam->reg.app_id); - break; - } // ESP_GATTS_REG_EVT - - - // ESP_GATTS_START_EVT - // - // start: - // - esp_gatt_status_t status - // - uint16_t service_handle - case ESP_GATTS_START_EVT: { - log_v("[status: %s, service_handle: 0x%.2x]", - gattStatusToString(evtParam->start.status).c_str(), - evtParam->start.service_handle); - break; - } // ESP_GATTS_START_EVT - - - // ESP_GATTS_WRITE_EVT - // - // write: - // - uint16_t conn_id – The connection id. - // - uint16_t trans_id – The transfer id. - // - esp_bd_addr_t bda – The address of the partner. - // - uint16_t handle – The attribute handle. - // - uint16_t offset – The offset of the currently received within the whole value. - // - bool need_rsp – Do we need a response? - // - bool is_prep – Is this a write prepare? If set, then this is to be considered part of the received value and not the whole value. A subsequent ESP_GATTS_EXEC_WRITE will mark the total. - // - uint16_t len – The length of the incoming value part. - // - uint8_t* value – The data for this value part. - case ESP_GATTS_WRITE_EVT: { - log_v("[conn_id: %d, trans_id: %d, bda: %s, handle: 0x%.2x, offset: %d, need_rsp: %d, is_prep: %d, len: %d]", - evtParam->write.conn_id, - evtParam->write.trans_id, - BLEAddress(evtParam->write.bda).toString().c_str(), - evtParam->write.handle, - evtParam->write.offset, - evtParam->write.need_rsp, - evtParam->write.is_prep, - evtParam->write.len); - char* pHex = buildHexData(nullptr, evtParam->write.value, evtParam->write.len); - log_v("[Data: %s]", pHex); - free(pHex); - break; - } // ESP_GATTS_WRITE_EVT + case ESP_GATTS_MTU_EVT: + { + log_v("[conn_id: %d, mtu: %d]", + evtParam->mtu.conn_id, + evtParam->mtu.mtu); + break; + } // ESP_GATTS_MTU_EVT + + case ESP_GATTS_READ_EVT: + { + log_v("[conn_id: %d, trans_id: %d, bda: %s, handle: 0x%.2x, is_long: %d, need_rsp:%d]", + evtParam->read.conn_id, + evtParam->read.trans_id, + BLEAddress(evtParam->read.bda).toString().c_str(), + evtParam->read.handle, + evtParam->read.is_long, + evtParam->read.need_rsp); + break; + } // ESP_GATTS_READ_EVT + + case ESP_GATTS_RESPONSE_EVT: + { + log_v("[status: %s, handle: 0x%.2x]", + gattStatusToString(evtParam->rsp.status).c_str(), + evtParam->rsp.handle); + break; + } // ESP_GATTS_RESPONSE_EVT + + case ESP_GATTS_REG_EVT: + { + log_v("[status: %s, app_id: %d]", + gattStatusToString(evtParam->reg.status).c_str(), + evtParam->reg.app_id); + break; + } // ESP_GATTS_REG_EVT + + + // ESP_GATTS_START_EVT + // + // start: + // - esp_gatt_status_t status + // - uint16_t service_handle + case ESP_GATTS_START_EVT: + { + log_v("[status: %s, service_handle: 0x%.2x]", + gattStatusToString(evtParam->start.status).c_str(), + evtParam->start.service_handle); + break; + } // ESP_GATTS_START_EVT + + + // ESP_GATTS_WRITE_EVT + // + // write: + // - uint16_t conn_id – The connection id. + // - uint16_t trans_id – The transfer id. + // - esp_bd_addr_t bda – The address of the partner. + // - uint16_t handle – The attribute handle. + // - uint16_t offset – The offset of the currently received within the whole value. + // - bool need_rsp – Do we need a response? + // - bool is_prep – Is this a write prepare? If set, then this is to be considered part of the received value and not the whole value. A subsequent ESP_GATTS_EXEC_WRITE will mark the total. + // - uint16_t len – The length of the incoming value part. + // - uint8_t* value – The data for this value part. + case ESP_GATTS_WRITE_EVT: + { + log_v("[conn_id: %d, trans_id: %d, bda: %s, handle: 0x%.2x, offset: %d, need_rsp: %d, is_prep: %d, len: %d]", + evtParam->write.conn_id, + evtParam->write.trans_id, + BLEAddress(evtParam->write.bda).toString().c_str(), + evtParam->write.handle, + evtParam->write.offset, + evtParam->write.need_rsp, + evtParam->write.is_prep, + evtParam->write.len); + char* pHex = buildHexData(nullptr, evtParam->write.value, evtParam->write.len); + log_v("[Data: %s]", pHex); + free(pHex); + break; + } // ESP_GATTS_WRITE_EVT #endif - default: - log_v("dumpGattServerEvent: *** NOT CODED ***"); - break; - } -} // dumpGattServerEvent + default: + log_v("dumpGattServerEvent: *** NOT CODED ***"); + break; + } +} // dumpGattServerEvent /** @@ -1728,24 +1776,24 @@ void BLEUtils::dumpGattServerEvent( * @return The event type as a string. */ const char* BLEUtils::eventTypeToString(esp_ble_evt_type_t eventType) { - switch (eventType) { + switch (eventType) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - case ESP_BLE_EVT_CONN_ADV: - return "ESP_BLE_EVT_CONN_ADV"; - case ESP_BLE_EVT_CONN_DIR_ADV: - return "ESP_BLE_EVT_CONN_DIR_ADV"; - case ESP_BLE_EVT_DISC_ADV: - return "ESP_BLE_EVT_DISC_ADV"; - case ESP_BLE_EVT_NON_CONN_ADV: - return "ESP_BLE_EVT_NON_CONN_ADV"; - case ESP_BLE_EVT_SCAN_RSP: - return "ESP_BLE_EVT_SCAN_RSP"; + case ESP_BLE_EVT_CONN_ADV: + return "ESP_BLE_EVT_CONN_ADV"; + case ESP_BLE_EVT_CONN_DIR_ADV: + return "ESP_BLE_EVT_CONN_DIR_ADV"; + case ESP_BLE_EVT_DISC_ADV: + return "ESP_BLE_EVT_DISC_ADV"; + case ESP_BLE_EVT_NON_CONN_ADV: + return "ESP_BLE_EVT_NON_CONN_ADV"; + case ESP_BLE_EVT_SCAN_RSP: + return "ESP_BLE_EVT_SCAN_RSP"; #endif - default: - log_v("Unknown esp_ble_evt_type_t: %d (0x%.2x)", eventType, eventType); - return "*** Unknown ***"; - } -} // eventTypeToString + default: + log_v("Unknown esp_ble_evt_type_t: %d (0x%.2x)", eventType, eventType); + return "*** Unknown ***"; + } +} // eventTypeToString @@ -1755,80 +1803,80 @@ const char* BLEUtils::eventTypeToString(esp_ble_evt_type_t eventType) { * @return A string representation of the event type. */ const char* BLEUtils::gapEventToString(uint32_t eventType) { - switch (eventType) { + switch (eventType) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: - return "ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT"; - case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT: - return "ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT"; - case ESP_GAP_BLE_ADV_START_COMPLETE_EVT: - return "ESP_GAP_BLE_ADV_START_COMPLETE_EVT"; - case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT: /* !< When stop adv complete, the event comes */ - return "ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT"; - case ESP_GAP_BLE_AUTH_CMPL_EVT: /* Authentication complete indication. */ - return "ESP_GAP_BLE_AUTH_CMPL_EVT"; - case ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT: - return "ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT"; - case ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT: - return "ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT"; - case ESP_GAP_BLE_KEY_EVT: /* BLE key event for peer device keys */ - return "ESP_GAP_BLE_KEY_EVT"; - case ESP_GAP_BLE_LOCAL_IR_EVT: /* BLE local IR event */ - return "ESP_GAP_BLE_LOCAL_IR_EVT"; - case ESP_GAP_BLE_LOCAL_ER_EVT: /* BLE local ER event */ - return "ESP_GAP_BLE_LOCAL_ER_EVT"; - case ESP_GAP_BLE_NC_REQ_EVT: /* Numeric Comparison request event */ - return "ESP_GAP_BLE_NC_REQ_EVT"; - case ESP_GAP_BLE_OOB_REQ_EVT: /* OOB request event */ - return "ESP_GAP_BLE_OOB_REQ_EVT"; - case ESP_GAP_BLE_PASSKEY_NOTIF_EVT: /* passkey notification event */ - return "ESP_GAP_BLE_PASSKEY_NOTIF_EVT"; - case ESP_GAP_BLE_PASSKEY_REQ_EVT: /* passkey request event */ - return "ESP_GAP_BLE_PASSKEY_REQ_EVT"; - case ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT: - return "ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT"; - case ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT: - return "ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT"; - case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: - return "ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT"; - case ESP_GAP_BLE_SCAN_RESULT_EVT: - return "ESP_GAP_BLE_SCAN_RESULT_EVT"; - case ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT: - return "ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT"; - case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT: - return "ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT"; - case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT: - return "ESP_GAP_BLE_SCAN_START_COMPLETE_EVT"; - case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT: - return "ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT"; - case ESP_GAP_BLE_SEC_REQ_EVT: /* BLE security request */ - return "ESP_GAP_BLE_SEC_REQ_EVT"; - case ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT: - return "ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT"; - case ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT: - return "ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT"; - case ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT: - return "ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT"; - case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT: - return "ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT"; + case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: + return "ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT"; + case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT: + return "ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT"; + case ESP_GAP_BLE_ADV_START_COMPLETE_EVT: + return "ESP_GAP_BLE_ADV_START_COMPLETE_EVT"; + case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT: /* !< When stop adv complete, the event comes */ + return "ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT"; + case ESP_GAP_BLE_AUTH_CMPL_EVT: /* Authentication complete indication. */ + return "ESP_GAP_BLE_AUTH_CMPL_EVT"; + case ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT: + return "ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT"; + case ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT: + return "ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT"; + case ESP_GAP_BLE_KEY_EVT: /* BLE key event for peer device keys */ + return "ESP_GAP_BLE_KEY_EVT"; + case ESP_GAP_BLE_LOCAL_IR_EVT: /* BLE local IR event */ + return "ESP_GAP_BLE_LOCAL_IR_EVT"; + case ESP_GAP_BLE_LOCAL_ER_EVT: /* BLE local ER event */ + return "ESP_GAP_BLE_LOCAL_ER_EVT"; + case ESP_GAP_BLE_NC_REQ_EVT: /* Numeric Comparison request event */ + return "ESP_GAP_BLE_NC_REQ_EVT"; + case ESP_GAP_BLE_OOB_REQ_EVT: /* OOB request event */ + return "ESP_GAP_BLE_OOB_REQ_EVT"; + case ESP_GAP_BLE_PASSKEY_NOTIF_EVT: /* passkey notification event */ + return "ESP_GAP_BLE_PASSKEY_NOTIF_EVT"; + case ESP_GAP_BLE_PASSKEY_REQ_EVT: /* passkey request event */ + return "ESP_GAP_BLE_PASSKEY_REQ_EVT"; + case ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT: + return "ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT"; + case ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT: + return "ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT"; + case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: + return "ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT"; + case ESP_GAP_BLE_SCAN_RESULT_EVT: + return "ESP_GAP_BLE_SCAN_RESULT_EVT"; + case ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT: + return "ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT"; + case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT: + return "ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT"; + case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT: + return "ESP_GAP_BLE_SCAN_START_COMPLETE_EVT"; + case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT: + return "ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT"; + case ESP_GAP_BLE_SEC_REQ_EVT: /* BLE security request */ + return "ESP_GAP_BLE_SEC_REQ_EVT"; + case ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT: + return "ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT"; + case ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT: + return "ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT"; + case ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT: + return "ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT"; + case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT: + return "ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT"; #endif - default: - log_v("gapEventToString: Unknown event type %d 0x%.2x", eventType, eventType); - return "Unknown event type"; - } -} // gapEventToString + default: + log_v("gapEventToString: Unknown event type %d 0x%.2x", eventType, eventType); + return "Unknown event type"; + } +} // gapEventToString String BLEUtils::gattCharacteristicUUIDToString(uint32_t characteristicUUID) { - const characteristicMap_t* p = g_characteristicsMappings; - while (strlen(p->name) > 0) { - if (p->assignedNumber == characteristicUUID) { - return String(p->name); - } - p++; - } - return "Unknown"; -} // gattCharacteristicUUIDToString + const characteristicMap_t* p = g_characteristicsMappings; + while (strlen(p->name) > 0) { + if (p->assignedNumber == characteristicUUID) { + return String(p->name); + } + p++; + } + return "Unknown"; +} // gattCharacteristicUUIDToString /** @@ -1837,15 +1885,15 @@ String BLEUtils::gattCharacteristicUUIDToString(uint32_t characteristicUUID) { * @return The string representation of a descriptor UUID. */ String BLEUtils::gattDescriptorUUIDToString(uint32_t descriptorUUID) { - gattdescriptor_t* p = (gattdescriptor_t*) g_descriptor_ids; - while (strlen(p->name) > 0) { - if (p->assignedNumber == descriptorUUID) { - return String(p->name); - } - p++; - } - return ""; -} // gattDescriptorUUIDToString + gattdescriptor_t* p = (gattdescriptor_t*)g_descriptor_ids; + while (strlen(p->name) > 0) { + if (p->assignedNumber == descriptorUUID) { + return String(p->name); + } + p++; + } + return ""; +} // gattDescriptorUUIDToString /** @@ -1853,43 +1901,43 @@ String BLEUtils::gattDescriptorUUIDToString(uint32_t descriptorUUID) { * @return A string representation of an esp_gattc_service_elem_t. */ String BLEUtils::gattcServiceElementToString(esp_gattc_service_elem_t* pGATTCServiceElement) { - String res; - char val[6]; - res += "[uuid: " + BLEUUID(pGATTCServiceElement->uuid).toString() + ", start_handle: "; - snprintf(val, sizeof(val), "%d", pGATTCServiceElement->start_handle); - res += val; - res += " 0x"; - snprintf(val, sizeof(val), "%04x", pGATTCServiceElement->start_handle); - res += val; - res += ", end_handle: "; - snprintf(val, sizeof(val), "%d", pGATTCServiceElement->end_handle); - res += val; - res += " 0x"; - snprintf(val, sizeof(val), "%04x", pGATTCServiceElement->end_handle); - res += val; - res += "]"; - return res; -} // gattcServiceElementToString + String res; + char val[6]; + res += "[uuid: " + BLEUUID(pGATTCServiceElement->uuid).toString() + ", start_handle: "; + snprintf(val, sizeof(val), "%d", pGATTCServiceElement->start_handle); + res += val; + res += " 0x"; + snprintf(val, sizeof(val), "%04x", pGATTCServiceElement->start_handle); + res += val; + res += ", end_handle: "; + snprintf(val, sizeof(val), "%d", pGATTCServiceElement->end_handle); + res += val; + res += " 0x"; + snprintf(val, sizeof(val), "%04x", pGATTCServiceElement->end_handle); + res += val; + res += "]"; + return res; +} // gattcServiceElementToString /** * @brief Convert an esp_gatt_srvc_id_t to a string. */ String BLEUtils::gattServiceIdToString(esp_gatt_srvc_id_t srvcId) { - return gattIdToString(srvcId.id); -} // gattServiceIdToString + return gattIdToString(srvcId.id); +} // gattServiceIdToString String BLEUtils::gattServiceToString(uint32_t serviceId) { - gattService_t* p = (gattService_t*) g_gattServices; - while (strlen(p->name) > 0) { - if (p->assignedNumber == serviceId) { - return String(p->name); - } - p++; - } - return "Unknown"; -} // gattServiceToString + gattService_t* p = (gattService_t*)g_gattServices; + while (strlen(p->name) > 0) { + if (p->assignedNumber == serviceId) { + return String(p->name); + } + p++; + } + return "Unknown"; +} // gattServiceToString /** @@ -1899,112 +1947,112 @@ String BLEUtils::gattServiceToString(uint32_t serviceId) { * @return A string representation of the status. */ String BLEUtils::gattStatusToString(esp_gatt_status_t status) { - switch (status) { + switch (status) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - case ESP_GATT_OK: - return "ESP_GATT_OK"; - case ESP_GATT_INVALID_HANDLE: - return "ESP_GATT_INVALID_HANDLE"; - case ESP_GATT_READ_NOT_PERMIT: - return "ESP_GATT_READ_NOT_PERMIT"; - case ESP_GATT_WRITE_NOT_PERMIT: - return "ESP_GATT_WRITE_NOT_PERMIT"; - case ESP_GATT_INVALID_PDU: - return "ESP_GATT_INVALID_PDU"; - case ESP_GATT_INSUF_AUTHENTICATION: - return "ESP_GATT_INSUF_AUTHENTICATION"; - case ESP_GATT_REQ_NOT_SUPPORTED: - return "ESP_GATT_REQ_NOT_SUPPORTED"; - case ESP_GATT_INVALID_OFFSET: - return "ESP_GATT_INVALID_OFFSET"; - case ESP_GATT_INSUF_AUTHORIZATION: - return "ESP_GATT_INSUF_AUTHORIZATION"; - case ESP_GATT_PREPARE_Q_FULL: - return "ESP_GATT_PREPARE_Q_FULL"; - case ESP_GATT_NOT_FOUND: - return "ESP_GATT_NOT_FOUND"; - case ESP_GATT_NOT_LONG: - return "ESP_GATT_NOT_LONG"; - case ESP_GATT_INSUF_KEY_SIZE: - return "ESP_GATT_INSUF_KEY_SIZE"; - case ESP_GATT_INVALID_ATTR_LEN: - return "ESP_GATT_INVALID_ATTR_LEN"; - case ESP_GATT_ERR_UNLIKELY: - return "ESP_GATT_ERR_UNLIKELY"; - case ESP_GATT_INSUF_ENCRYPTION: - return "ESP_GATT_INSUF_ENCRYPTION"; - case ESP_GATT_UNSUPPORT_GRP_TYPE: - return "ESP_GATT_UNSUPPORT_GRP_TYPE"; - case ESP_GATT_INSUF_RESOURCE: - return "ESP_GATT_INSUF_RESOURCE"; - case ESP_GATT_NO_RESOURCES: - return "ESP_GATT_NO_RESOURCES"; - case ESP_GATT_INTERNAL_ERROR: - return "ESP_GATT_INTERNAL_ERROR"; - case ESP_GATT_WRONG_STATE: - return "ESP_GATT_WRONG_STATE"; - case ESP_GATT_DB_FULL: - return "ESP_GATT_DB_FULL"; - case ESP_GATT_BUSY: - return "ESP_GATT_BUSY"; - case ESP_GATT_ERROR: - return "ESP_GATT_ERROR"; - case ESP_GATT_CMD_STARTED: - return "ESP_GATT_CMD_STARTED"; - case ESP_GATT_ILLEGAL_PARAMETER: - return "ESP_GATT_ILLEGAL_PARAMETER"; - case ESP_GATT_PENDING: - return "ESP_GATT_PENDING"; - case ESP_GATT_AUTH_FAIL: - return "ESP_GATT_AUTH_FAIL"; - case ESP_GATT_MORE: - return "ESP_GATT_MORE"; - case ESP_GATT_INVALID_CFG: - return "ESP_GATT_INVALID_CFG"; - case ESP_GATT_SERVICE_STARTED: - return "ESP_GATT_SERVICE_STARTED"; - case ESP_GATT_ENCRYPTED_NO_MITM: - return "ESP_GATT_ENCRYPTED_NO_MITM"; - case ESP_GATT_NOT_ENCRYPTED: - return "ESP_GATT_NOT_ENCRYPTED"; - case ESP_GATT_CONGESTED: - return "ESP_GATT_CONGESTED"; - case ESP_GATT_DUP_REG: - return "ESP_GATT_DUP_REG"; - case ESP_GATT_ALREADY_OPEN: - return "ESP_GATT_ALREADY_OPEN"; - case ESP_GATT_CANCEL: - return "ESP_GATT_CANCEL"; - case ESP_GATT_STACK_RSP: - return "ESP_GATT_STACK_RSP"; - case ESP_GATT_APP_RSP: - return "ESP_GATT_APP_RSP"; - case ESP_GATT_UNKNOWN_ERROR: - return "ESP_GATT_UNKNOWN_ERROR"; - case ESP_GATT_CCC_CFG_ERR: - return "ESP_GATT_CCC_CFG_ERR"; - case ESP_GATT_PRC_IN_PROGRESS: - return "ESP_GATT_PRC_IN_PROGRESS"; - case ESP_GATT_OUT_OF_RANGE: - return "ESP_GATT_OUT_OF_RANGE"; + case ESP_GATT_OK: + return "ESP_GATT_OK"; + case ESP_GATT_INVALID_HANDLE: + return "ESP_GATT_INVALID_HANDLE"; + case ESP_GATT_READ_NOT_PERMIT: + return "ESP_GATT_READ_NOT_PERMIT"; + case ESP_GATT_WRITE_NOT_PERMIT: + return "ESP_GATT_WRITE_NOT_PERMIT"; + case ESP_GATT_INVALID_PDU: + return "ESP_GATT_INVALID_PDU"; + case ESP_GATT_INSUF_AUTHENTICATION: + return "ESP_GATT_INSUF_AUTHENTICATION"; + case ESP_GATT_REQ_NOT_SUPPORTED: + return "ESP_GATT_REQ_NOT_SUPPORTED"; + case ESP_GATT_INVALID_OFFSET: + return "ESP_GATT_INVALID_OFFSET"; + case ESP_GATT_INSUF_AUTHORIZATION: + return "ESP_GATT_INSUF_AUTHORIZATION"; + case ESP_GATT_PREPARE_Q_FULL: + return "ESP_GATT_PREPARE_Q_FULL"; + case ESP_GATT_NOT_FOUND: + return "ESP_GATT_NOT_FOUND"; + case ESP_GATT_NOT_LONG: + return "ESP_GATT_NOT_LONG"; + case ESP_GATT_INSUF_KEY_SIZE: + return "ESP_GATT_INSUF_KEY_SIZE"; + case ESP_GATT_INVALID_ATTR_LEN: + return "ESP_GATT_INVALID_ATTR_LEN"; + case ESP_GATT_ERR_UNLIKELY: + return "ESP_GATT_ERR_UNLIKELY"; + case ESP_GATT_INSUF_ENCRYPTION: + return "ESP_GATT_INSUF_ENCRYPTION"; + case ESP_GATT_UNSUPPORT_GRP_TYPE: + return "ESP_GATT_UNSUPPORT_GRP_TYPE"; + case ESP_GATT_INSUF_RESOURCE: + return "ESP_GATT_INSUF_RESOURCE"; + case ESP_GATT_NO_RESOURCES: + return "ESP_GATT_NO_RESOURCES"; + case ESP_GATT_INTERNAL_ERROR: + return "ESP_GATT_INTERNAL_ERROR"; + case ESP_GATT_WRONG_STATE: + return "ESP_GATT_WRONG_STATE"; + case ESP_GATT_DB_FULL: + return "ESP_GATT_DB_FULL"; + case ESP_GATT_BUSY: + return "ESP_GATT_BUSY"; + case ESP_GATT_ERROR: + return "ESP_GATT_ERROR"; + case ESP_GATT_CMD_STARTED: + return "ESP_GATT_CMD_STARTED"; + case ESP_GATT_ILLEGAL_PARAMETER: + return "ESP_GATT_ILLEGAL_PARAMETER"; + case ESP_GATT_PENDING: + return "ESP_GATT_PENDING"; + case ESP_GATT_AUTH_FAIL: + return "ESP_GATT_AUTH_FAIL"; + case ESP_GATT_MORE: + return "ESP_GATT_MORE"; + case ESP_GATT_INVALID_CFG: + return "ESP_GATT_INVALID_CFG"; + case ESP_GATT_SERVICE_STARTED: + return "ESP_GATT_SERVICE_STARTED"; + case ESP_GATT_ENCRYPTED_NO_MITM: + return "ESP_GATT_ENCRYPTED_NO_MITM"; + case ESP_GATT_NOT_ENCRYPTED: + return "ESP_GATT_NOT_ENCRYPTED"; + case ESP_GATT_CONGESTED: + return "ESP_GATT_CONGESTED"; + case ESP_GATT_DUP_REG: + return "ESP_GATT_DUP_REG"; + case ESP_GATT_ALREADY_OPEN: + return "ESP_GATT_ALREADY_OPEN"; + case ESP_GATT_CANCEL: + return "ESP_GATT_CANCEL"; + case ESP_GATT_STACK_RSP: + return "ESP_GATT_STACK_RSP"; + case ESP_GATT_APP_RSP: + return "ESP_GATT_APP_RSP"; + case ESP_GATT_UNKNOWN_ERROR: + return "ESP_GATT_UNKNOWN_ERROR"; + case ESP_GATT_CCC_CFG_ERR: + return "ESP_GATT_CCC_CFG_ERR"; + case ESP_GATT_PRC_IN_PROGRESS: + return "ESP_GATT_PRC_IN_PROGRESS"; + case ESP_GATT_OUT_OF_RANGE: + return "ESP_GATT_OUT_OF_RANGE"; #endif - default: - return "Unknown"; - } -} // gattStatusToString + default: + return "Unknown"; + } +} // gattStatusToString String BLEUtils::getMember(uint32_t memberId) { - member_t* p = (member_t*) members_ids; - - while (strlen(p->name) > 0) { - if (p->assignedNumber == memberId) { - return String(p->name); - } - p++; - } - return "Unknown"; + member_t* p = (member_t*)members_ids; + + while (strlen(p->name) > 0) { + if (p->assignedNumber == memberId) { + return String(p->name); + } + p++; + } + return "Unknown"; } /** @@ -2013,28 +2061,28 @@ String BLEUtils::getMember(uint32_t memberId) { * @return The search event type as a string. */ const char* BLEUtils::searchEventTypeToString(esp_gap_search_evt_t searchEvt) { - switch (searchEvt) { + switch (searchEvt) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - case ESP_GAP_SEARCH_INQ_RES_EVT: - return "ESP_GAP_SEARCH_INQ_RES_EVT"; - case ESP_GAP_SEARCH_INQ_CMPL_EVT: - return "ESP_GAP_SEARCH_INQ_CMPL_EVT"; - case ESP_GAP_SEARCH_DISC_RES_EVT: - return "ESP_GAP_SEARCH_DISC_RES_EVT"; - case ESP_GAP_SEARCH_DISC_BLE_RES_EVT: - return "ESP_GAP_SEARCH_DISC_BLE_RES_EVT"; - case ESP_GAP_SEARCH_DISC_CMPL_EVT: - return "ESP_GAP_SEARCH_DISC_CMPL_EVT"; - case ESP_GAP_SEARCH_DI_DISC_CMPL_EVT: - return "ESP_GAP_SEARCH_DI_DISC_CMPL_EVT"; - case ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT: - return "ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT"; + case ESP_GAP_SEARCH_INQ_RES_EVT: + return "ESP_GAP_SEARCH_INQ_RES_EVT"; + case ESP_GAP_SEARCH_INQ_CMPL_EVT: + return "ESP_GAP_SEARCH_INQ_CMPL_EVT"; + case ESP_GAP_SEARCH_DISC_RES_EVT: + return "ESP_GAP_SEARCH_DISC_RES_EVT"; + case ESP_GAP_SEARCH_DISC_BLE_RES_EVT: + return "ESP_GAP_SEARCH_DISC_BLE_RES_EVT"; + case ESP_GAP_SEARCH_DISC_CMPL_EVT: + return "ESP_GAP_SEARCH_DISC_CMPL_EVT"; + case ESP_GAP_SEARCH_DI_DISC_CMPL_EVT: + return "ESP_GAP_SEARCH_DI_DISC_CMPL_EVT"; + case ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT: + return "ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT"; #endif - default: - log_v("Unknown event type: 0x%x", searchEvt); - return "Unknown event type"; - } -} // searchEventTypeToString + default: + log_v("Unknown event type: 0x%x", searchEvt); + return "Unknown event type"; + } +} // searchEventTypeToString #endif /* CONFIG_BLUEDROID_ENABLED */ #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/BLEUtils.h b/libraries/BLE/src/BLEUtils.h index d0ec8348130..4dcea2e02e8 100644 --- a/libraries/BLE/src/BLEUtils.h +++ b/libraries/BLE/src/BLEUtils.h @@ -12,9 +12,9 @@ #include "sdkconfig.h" #if defined(CONFIG_BLUEDROID_ENABLED) -#include // ESP32 BLE -#include // ESP32 BLE -#include // ESP32 BLE +#include // ESP32 BLE +#include // ESP32 BLE +#include // ESP32 BLE #include #include "BLEClient.h" @@ -23,43 +23,43 @@ */ class BLEUtils { public: - static const char* addressTypeToString(esp_ble_addr_type_t type); - static String adFlagsToString(uint8_t adFlags); - static const char* advTypeToString(uint8_t advType); - static char* buildHexData(uint8_t* target, uint8_t* source, uint8_t length); - static String buildPrintData(uint8_t* source, size_t length); - static String characteristicPropertiesToString(esp_gatt_char_prop_t prop); - static const char* devTypeToString(esp_bt_dev_type_t type); - static esp_gatt_id_t buildGattId(esp_bt_uuid_t uuid, uint8_t inst_id = 0); - static esp_gatt_srvc_id_t buildGattSrvcId(esp_gatt_id_t gattId, bool is_primary = true); - static void dumpGapEvent( - esp_gap_ble_cb_event_t event, - esp_ble_gap_cb_param_t* param); - static void dumpGattClientEvent( - esp_gattc_cb_event_t event, - esp_gatt_if_t gattc_if, - esp_ble_gattc_cb_param_t* evtParam); - static void dumpGattServerEvent( - esp_gatts_cb_event_t event, - esp_gatt_if_t gatts_if, - esp_ble_gatts_cb_param_t* evtParam); - static const char* eventTypeToString(esp_ble_evt_type_t eventType); - static BLEClient* findByAddress(BLEAddress address); - static BLEClient* findByConnId(uint16_t conn_id); - static const char* gapEventToString(uint32_t eventType); - static String gattCharacteristicUUIDToString(uint32_t characteristicUUID); - static String gattClientEventTypeToString(esp_gattc_cb_event_t eventType); - static String gattCloseReasonToString(esp_gatt_conn_reason_t reason); - static String gattcServiceElementToString(esp_gattc_service_elem_t* pGATTCServiceElement); - static String gattDescriptorUUIDToString(uint32_t descriptorUUID); - static String gattServerEventTypeToString(esp_gatts_cb_event_t eventType); - static String gattServiceIdToString(esp_gatt_srvc_id_t srvcId); - static String gattServiceToString(uint32_t serviceId); - static String gattStatusToString(esp_gatt_status_t status); - static String getMember(uint32_t memberId); - static void registerByAddress(BLEAddress address, BLEClient* pDevice); - static void registerByConnId(uint16_t conn_id, BLEClient* pDevice); - static const char* searchEventTypeToString(esp_gap_search_evt_t searchEvt); + static const char* addressTypeToString(esp_ble_addr_type_t type); + static String adFlagsToString(uint8_t adFlags); + static const char* advTypeToString(uint8_t advType); + static char* buildHexData(uint8_t* target, uint8_t* source, uint8_t length); + static String buildPrintData(uint8_t* source, size_t length); + static String characteristicPropertiesToString(esp_gatt_char_prop_t prop); + static const char* devTypeToString(esp_bt_dev_type_t type); + static esp_gatt_id_t buildGattId(esp_bt_uuid_t uuid, uint8_t inst_id = 0); + static esp_gatt_srvc_id_t buildGattSrvcId(esp_gatt_id_t gattId, bool is_primary = true); + static void dumpGapEvent( + esp_gap_ble_cb_event_t event, + esp_ble_gap_cb_param_t* param); + static void dumpGattClientEvent( + esp_gattc_cb_event_t event, + esp_gatt_if_t gattc_if, + esp_ble_gattc_cb_param_t* evtParam); + static void dumpGattServerEvent( + esp_gatts_cb_event_t event, + esp_gatt_if_t gatts_if, + esp_ble_gatts_cb_param_t* evtParam); + static const char* eventTypeToString(esp_ble_evt_type_t eventType); + static BLEClient* findByAddress(BLEAddress address); + static BLEClient* findByConnId(uint16_t conn_id); + static const char* gapEventToString(uint32_t eventType); + static String gattCharacteristicUUIDToString(uint32_t characteristicUUID); + static String gattClientEventTypeToString(esp_gattc_cb_event_t eventType); + static String gattCloseReasonToString(esp_gatt_conn_reason_t reason); + static String gattcServiceElementToString(esp_gattc_service_elem_t* pGATTCServiceElement); + static String gattDescriptorUUIDToString(uint32_t descriptorUUID); + static String gattServerEventTypeToString(esp_gatts_cb_event_t eventType); + static String gattServiceIdToString(esp_gatt_srvc_id_t srvcId); + static String gattServiceToString(uint32_t serviceId); + static String gattStatusToString(esp_gatt_status_t status); + static String getMember(uint32_t memberId); + static void registerByAddress(BLEAddress address, BLEClient* pDevice); + static void registerByConnId(uint16_t conn_id, BLEClient* pDevice); + static const char* searchEventTypeToString(esp_gap_search_evt_t searchEvt); }; #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLEValue.cpp b/libraries/BLE/src/BLEValue.cpp index e67bba4d18e..08a564fd798 100644 --- a/libraries/BLE/src/BLEValue.cpp +++ b/libraries/BLE/src/BLEValue.cpp @@ -13,10 +13,10 @@ #include "esp32-hal-log.h" BLEValue::BLEValue() { - m_accumulation = ""; - m_value = ""; - m_readOffset = 0; -} // BLEValue + m_accumulation = ""; + m_value = ""; + m_readOffset = 0; +} // BLEValue /** @@ -25,9 +25,9 @@ BLEValue::BLEValue() { * @param [in] part A message part being added. */ void BLEValue::addPart(String part) { - log_v(">> addPart: length=%d", part.length()); - m_accumulation += part; -} // addPart + log_v(">> addPart: length=%d", part.length()); + m_accumulation += part; +} // addPart /** @@ -37,19 +37,19 @@ void BLEValue::addPart(String part) { * @param [in] length The number of bytes being added. */ void BLEValue::addPart(uint8_t* pData, size_t length) { - log_v(">> addPart: length=%d", length); - m_accumulation += String((char*) pData, length); -} // addPart + log_v(">> addPart: length=%d", length); + m_accumulation += String((char*)pData, length); +} // addPart /** * @brief Cancel the current accumulation. */ void BLEValue::cancel() { - log_v(">> cancel"); - m_accumulation = ""; - m_readOffset = 0; -} // cancel + log_v(">> cancel"); + m_accumulation = ""; + m_readOffset = 0; +} // cancel /** @@ -59,13 +59,13 @@ void BLEValue::cancel() { * we now have the complete message and commit the change as a unit. */ void BLEValue::commit() { - log_v(">> commit"); - // If there is nothing to commit, do nothing. - if (m_accumulation.length() == 0) return; - setValue(m_accumulation); - m_accumulation = ""; - m_readOffset = 0; -} // commit + log_v(">> commit"); + // If there is nothing to commit, do nothing. + if (m_accumulation.length() == 0) return; + setValue(m_accumulation); + m_accumulation = ""; + m_readOffset = 0; +} // commit /** @@ -73,7 +73,7 @@ void BLEValue::commit() { * @return A pointer to the data. */ uint8_t* BLEValue::getData() { - return (uint8_t*) m_value.c_str(); + return (uint8_t*)m_value.c_str(); } @@ -82,8 +82,8 @@ uint8_t* BLEValue::getData() { * @return The length of the data in bytes. */ size_t BLEValue::getLength() { - return m_value.length(); -} // getLength + return m_value.length(); +} // getLength /** @@ -91,16 +91,16 @@ size_t BLEValue::getLength() { * @return The read offset into the read. */ uint16_t BLEValue::getReadOffset() { - return m_readOffset; -} // getReadOffset + return m_readOffset; +} // getReadOffset /** * @brief Get the current value. */ String BLEValue::getValue() { - return m_value; -} // getValue + return m_value; +} // getValue /** @@ -108,16 +108,16 @@ String BLEValue::getValue() { * @param [in] readOffset The offset into the read. */ void BLEValue::setReadOffset(uint16_t readOffset) { - m_readOffset = readOffset; -} // setReadOffset + m_readOffset = readOffset; +} // setReadOffset /** * @brief Set the current value. */ void BLEValue::setValue(String value) { - m_value = value; -} // setValue + m_value = value; +} // setValue /** @@ -126,8 +126,8 @@ void BLEValue::setValue(String value) { * @param [in] The length of the new current value. */ void BLEValue::setValue(uint8_t* pData, size_t length) { - m_value = String((char*) pData, length); -} // setValue + m_value = String((char*)pData, length); +} // setValue #endif /* CONFIG_BLUEDROID_ENABLED */ diff --git a/libraries/BLE/src/BLEValue.h b/libraries/BLE/src/BLEValue.h index 0740a6999c2..ba1e08e5bf3 100644 --- a/libraries/BLE/src/BLEValue.h +++ b/libraries/BLE/src/BLEValue.h @@ -20,23 +20,22 @@ class BLEValue { public: BLEValue(); - void addPart(String part); - void addPart(uint8_t* pData, size_t length); - void cancel(); - void commit(); - uint8_t* getData(); - size_t getLength(); - uint16_t getReadOffset(); - String getValue(); - void setReadOffset(uint16_t readOffset); - void setValue(String value); - void setValue(uint8_t* pData, size_t length); + void addPart(String part); + void addPart(uint8_t* pData, size_t length); + void cancel(); + void commit(); + uint8_t* getData(); + size_t getLength(); + uint16_t getReadOffset(); + String getValue(); + void setReadOffset(uint16_t readOffset); + void setValue(String value); + void setValue(uint8_t* pData, size_t length); private: - String m_accumulation; - uint16_t m_readOffset; - String m_value; - + String m_accumulation; + uint16_t m_readOffset; + String m_value; }; #endif /* CONFIG_BLUEDROID_ENABLED */ #endif /* SOC_BLE_SUPPORTED */ diff --git a/libraries/BLE/src/FreeRTOS.cpp b/libraries/BLE/src/FreeRTOS.cpp index 69417275dc4..ce716395d7b 100644 --- a/libraries/BLE/src/FreeRTOS.cpp +++ b/libraries/BLE/src/FreeRTOS.cpp @@ -4,9 +4,9 @@ * Created on: Feb 24, 2017 * Author: kolban */ -#include // Include the base FreeRTOS definitions -#include // Include the task definitions -#include // Include the semaphore definitions +#include // Include the base FreeRTOS definitions +#include // Include the task definitions +#include // Include the semaphore definitions #include #include #include @@ -19,8 +19,8 @@ * @param[in] ms The period in milliseconds for which to sleep. */ void FreeRTOS::sleep(uint32_t ms) { - ::vTaskDelay(ms / portTICK_PERIOD_MS); -} // sleep + ::vTaskDelay(ms / portTICK_PERIOD_MS); +} // sleep /** @@ -28,11 +28,11 @@ void FreeRTOS::sleep(uint32_t ms) { * @param[in] task The function pointer to the function to be run in the task. * @param[in] taskName A string identifier for the task. * @param[in] param An optional parameter to be passed to the started task. - * @param[in] stackSize An optional paremeter supplying the size of the stack in which to run the task. + * @param[in] stackSize An optional parameter supplying the size of the stack in which to run the task. */ void FreeRTOS::startTask(void task(void*), String taskName, void* param, uint32_t stackSize) { - ::xTaskCreate(task, taskName.c_str(), stackSize, param, 5, NULL); -} // startTask + ::xTaskCreate(task, taskName.c_str(), stackSize, param, 5, NULL); +} // startTask /** @@ -40,8 +40,8 @@ void FreeRTOS::startTask(void task(void*), String taskName, void* param, uint32_ * @param[in] pTask An optional handle to the task to be deleted. If not supplied the calling task will be deleted. */ void FreeRTOS::deleteTask(TaskHandle_t pTask) { - ::vTaskDelete(pTask); -} // deleteTask + ::vTaskDelete(pTask); +} // deleteTask /** @@ -49,8 +49,8 @@ void FreeRTOS::deleteTask(TaskHandle_t pTask) { * @return The time in milliseconds since the %FreeRTOS scheduler started. */ uint32_t FreeRTOS::getTimeSinceStart() { - return (uint32_t) (xTaskGetTickCount() * portTICK_PERIOD_MS); -} // getTimeSinceStart + return (uint32_t)(xTaskGetTickCount() * portTICK_PERIOD_MS); +} // getTimeSinceStart /** @@ -60,23 +60,23 @@ uint32_t FreeRTOS::getTimeSinceStart() { * @return The value associated with the semaphore. */ uint32_t FreeRTOS::Semaphore::wait(String owner) { - log_v(">> wait: Semaphore waiting: %s for %s", toString().c_str(), owner.c_str()); - - if (m_usePthreads) { - pthread_mutex_lock(&m_pthread_mutex); - } else { - xSemaphoreTake(m_semaphore, portMAX_DELAY); - } - - if (m_usePthreads) { - pthread_mutex_unlock(&m_pthread_mutex); - } else { - xSemaphoreGive(m_semaphore); - } - - log_v("<< wait: Semaphore released: %s", toString().c_str()); - return m_value; -} // wait + log_v(">> wait: Semaphore waiting: %s for %s", toString().c_str(), owner.c_str()); + + if (m_usePthreads) { + pthread_mutex_lock(&m_pthread_mutex); + } else { + xSemaphoreTake(m_semaphore, portMAX_DELAY); + } + + if (m_usePthreads) { + pthread_mutex_unlock(&m_pthread_mutex); + } else { + xSemaphoreGive(m_semaphore); + } + + log_v("<< wait: Semaphore released: %s", toString().c_str()); + return m_value; +} // wait /** * @brief Wait for a semaphore to be released in a given period of time by trying to take it and @@ -86,52 +86,52 @@ uint32_t FreeRTOS::Semaphore::wait(String owner) { * @return True if we took the semaphore within timeframe. */ bool FreeRTOS::Semaphore::timedWait(String owner, uint32_t timeoutMs) { - log_v(">> wait: Semaphore waiting: %s for %s", toString().c_str(), owner.c_str()); + log_v(">> wait: Semaphore waiting: %s for %s", toString().c_str(), owner.c_str()); - if (m_usePthreads && timeoutMs != portMAX_DELAY) { - assert(false); // We apparently don't have a timed wait for pthreads. - } + if (m_usePthreads && timeoutMs != portMAX_DELAY) { + assert(false); // We apparently don't have a timed wait for pthreads. + } - auto ret = pdTRUE; + auto ret = pdTRUE; - if (m_usePthreads) { - pthread_mutex_lock(&m_pthread_mutex); - } else { - ret = xSemaphoreTake(m_semaphore, timeoutMs); - } + if (m_usePthreads) { + pthread_mutex_lock(&m_pthread_mutex); + } else { + ret = xSemaphoreTake(m_semaphore, timeoutMs); + } - if (m_usePthreads) { - pthread_mutex_unlock(&m_pthread_mutex); - } else { - xSemaphoreGive(m_semaphore); - } + if (m_usePthreads) { + pthread_mutex_unlock(&m_pthread_mutex); + } else { + xSemaphoreGive(m_semaphore); + } - log_v("<< wait: Semaphore %s released: %d", toString().c_str(), ret); - return ret; -} // wait + log_v("<< wait: Semaphore %s released: %d", toString().c_str(), ret); + return ret; +} // wait FreeRTOS::Semaphore::Semaphore(String name) { - m_usePthreads = false; // Are we using pThreads or FreeRTOS? - if (m_usePthreads) { - pthread_mutex_init(&m_pthread_mutex, nullptr); - } else { - m_semaphore = xSemaphoreCreateBinary(); - xSemaphoreGive(m_semaphore); - } - - m_name = name; - m_owner = String(""); - m_value = 0; + m_usePthreads = false; // Are we using pThreads or FreeRTOS? + if (m_usePthreads) { + pthread_mutex_init(&m_pthread_mutex, nullptr); + } else { + m_semaphore = xSemaphoreCreateBinary(); + xSemaphoreGive(m_semaphore); + } + + m_name = name; + m_owner = String(""); + m_value = 0; } FreeRTOS::Semaphore::~Semaphore() { - if (m_usePthreads) { - pthread_mutex_destroy(&m_pthread_mutex); - } else { - vSemaphoreDelete(m_semaphore); - } + if (m_usePthreads) { + pthread_mutex_destroy(&m_pthread_mutex); + } else { + vSemaphoreDelete(m_semaphore); + } } @@ -140,19 +140,19 @@ FreeRTOS::Semaphore::~Semaphore() { * The Semaphore is given. */ void FreeRTOS::Semaphore::give() { - log_v("Semaphore giving: %s", toString().c_str()); - m_owner = String(""); - - if (m_usePthreads) { - pthread_mutex_unlock(&m_pthread_mutex); - } else { - xSemaphoreGive(m_semaphore); - } -// #ifdef ARDUINO_ARCH_ESP32 -// FreeRTOS::sleep(10); -// #endif + log_v("Semaphore giving: %s", toString().c_str()); + m_owner = String(""); -} // Semaphore::give + if (m_usePthreads) { + pthread_mutex_unlock(&m_pthread_mutex); + } else { + xSemaphoreGive(m_semaphore); + } + // #ifdef ARDUINO_ARCH_ESP32 + // FreeRTOS::sleep(10); + // #endif + +} // Semaphore::give /** @@ -161,22 +161,22 @@ void FreeRTOS::Semaphore::give() { * @param [in] value The value to associate with the semaphore. */ void FreeRTOS::Semaphore::give(uint32_t value) { - m_value = value; - give(); -} // give + m_value = value; + give(); +} // give /** * @brief Give a semaphore from an ISR. */ void FreeRTOS::Semaphore::giveFromISR() { - BaseType_t higherPriorityTaskWoken; - if (m_usePthreads) { - assert(false); - } else { - xSemaphoreGiveFromISR(m_semaphore, &higherPriorityTaskWoken); - } -} // giveFromISR + BaseType_t higherPriorityTaskWoken; + if (m_usePthreads) { + assert(false); + } else { + xSemaphoreGiveFromISR(m_semaphore, &higherPriorityTaskWoken); + } +} // giveFromISR /** @@ -186,21 +186,21 @@ void FreeRTOS::Semaphore::giveFromISR() { * @return True if we took the semaphore. */ bool FreeRTOS::Semaphore::take(String owner) { - log_v("Semaphore taking: %s for %s", toString().c_str(), owner.c_str()); - bool rc = false; - if (m_usePthreads) { - pthread_mutex_lock(&m_pthread_mutex); - } else { - rc = ::xSemaphoreTake(m_semaphore, portMAX_DELAY) == pdTRUE; - } - if (rc) { - m_owner = owner; - log_v("Semaphore taken: %s", toString().c_str()); - } else { - log_e("Semaphore NOT taken: %s", toString().c_str()); - } - return rc; -} // Semaphore::take + log_v("Semaphore taking: %s for %s", toString().c_str(), owner.c_str()); + bool rc = false; + if (m_usePthreads) { + pthread_mutex_lock(&m_pthread_mutex); + } else { + rc = ::xSemaphoreTake(m_semaphore, portMAX_DELAY) == pdTRUE; + } + if (rc) { + m_owner = owner; + log_v("Semaphore taken: %s", toString().c_str()); + } else { + log_e("Semaphore NOT taken: %s", toString().c_str()); + } + return rc; +} // Semaphore::take /** @@ -211,21 +211,21 @@ bool FreeRTOS::Semaphore::take(String owner) { * @return True if we took the semaphore. */ bool FreeRTOS::Semaphore::take(uint32_t timeoutMs, String owner) { - log_v("Semaphore taking: %s for %s", toString().c_str(), owner.c_str()); - bool rc = false; - if (m_usePthreads) { - assert(false); // We apparently don't have a timed wait for pthreads. - } else { - rc = ::xSemaphoreTake(m_semaphore, timeoutMs / portTICK_PERIOD_MS) == pdTRUE; - } - if (rc) { - m_owner = owner; - log_v("Semaphore taken: %s", toString().c_str()); - } else { - log_e("Semaphore NOT taken: %s", toString().c_str()); - } - return rc; -} // Semaphore::take + log_v("Semaphore taking: %s for %s", toString().c_str(), owner.c_str()); + bool rc = false; + if (m_usePthreads) { + assert(false); // We apparently don't have a timed wait for pthreads. + } else { + rc = ::xSemaphoreTake(m_semaphore, timeoutMs / portTICK_PERIOD_MS) == pdTRUE; + } + if (rc) { + m_owner = owner; + log_v("Semaphore taken: %s", toString().c_str()); + } else { + log_e("Semaphore NOT taken: %s", toString().c_str()); + } + return rc; +} // Semaphore::take @@ -234,13 +234,13 @@ bool FreeRTOS::Semaphore::take(uint32_t timeoutMs, String owner) { * @return A string representation of the semaphore. */ String FreeRTOS::Semaphore::toString() { - char hex[9]; - String res = "name: " + m_name + " (0x"; - snprintf(hex, sizeof(hex), "%08lx", (uint32_t)m_semaphore); - res += hex; - res += "), owner: " + m_owner; - return res; -} // toString + char hex[9]; + String res = "name: " + m_name + " (0x"; + snprintf(hex, sizeof(hex), "%08lx", (uint32_t)m_semaphore); + res += hex; + res += "), owner: " + m_owner; + return res; +} // toString /** @@ -248,8 +248,8 @@ String FreeRTOS::Semaphore::toString() { * @param [in] name The name of the semaphore. */ void FreeRTOS::Semaphore::setName(String name) { - m_name = name; -} // setName + m_name = name; +} // setName /** @@ -263,13 +263,13 @@ Ringbuffer::Ringbuffer(size_t length, RingbufferType_t type) Ringbuffer::Ringbuffer(size_t length, ringbuf_type_t type) #endif { - m_handle = ::xRingbufferCreate(length, type); -} // Ringbuffer + m_handle = ::xRingbufferCreate(length, type); +} // Ringbuffer Ringbuffer::~Ringbuffer() { - ::vRingbufferDelete(m_handle); -} // ~Ringbuffer + ::vRingbufferDelete(m_handle); +} // ~Ringbuffer /** @@ -279,8 +279,8 @@ Ringbuffer::~Ringbuffer() { * @return A pointer to the storage retrieved. */ void* Ringbuffer::receive(size_t* size, TickType_t wait) { - return ::xRingbufferReceive(m_handle, size, wait); -} // receive + return ::xRingbufferReceive(m_handle, size, wait); +} // receive /** @@ -288,8 +288,8 @@ void* Ringbuffer::receive(size_t* size, TickType_t wait) { * @param [in] item The item to be returned/released. */ void Ringbuffer::returnItem(void* item) { - ::vRingbufferReturnItem(m_handle, item); -} // returnItem + ::vRingbufferReturnItem(m_handle, item); +} // returnItem /** @@ -300,7 +300,5 @@ void Ringbuffer::returnItem(void* item) { * @return */ bool Ringbuffer::send(void* data, size_t length, TickType_t wait) { - return ::xRingbufferSend(m_handle, data, length, wait) == pdTRUE; -} // send - - + return ::xRingbufferSend(m_handle, data, length, wait) == pdTRUE; +} // send diff --git a/libraries/BLE/src/GeneralUtils.cpp b/libraries/BLE/src/GeneralUtils.cpp index 0c86bf40dd5..1ee40db7852 100644 --- a/libraries/BLE/src/GeneralUtils.cpp +++ b/libraries/BLE/src/GeneralUtils.cpp @@ -22,32 +22,32 @@ #include "esp32-hal-log.h" static const char kBase64Alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789+/"; + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/"; static int base64EncodedLength(size_t length) { - return (length + 2 - ((length + 2) % 3)) / 3 * 4; -} // base64EncodedLength + return (length + 2 - ((length + 2) % 3)) / 3 * 4; +} // base64EncodedLength static int base64EncodedLength(const String& in) { - return base64EncodedLength(in.length()); -} // base64EncodedLength + return base64EncodedLength(in.length()); +} // base64EncodedLength static void a3_to_a4(unsigned char* a4, unsigned char* a3) { - a4[0] = (a3[0] & 0xfc) >> 2; - a4[1] = ((a3[0] & 0x03) << 4) + ((a3[1] & 0xf0) >> 4); - a4[2] = ((a3[1] & 0x0f) << 2) + ((a3[2] & 0xc0) >> 6); - a4[3] = (a3[2] & 0x3f); -} // a3_to_a4 + a4[0] = (a3[0] & 0xfc) >> 2; + a4[1] = ((a3[0] & 0x03) << 4) + ((a3[1] & 0xf0) >> 4); + a4[2] = ((a3[1] & 0x0f) << 2) + ((a3[2] & 0xc0) >> 6); + a4[3] = (a3[2] & 0x3f); +} // a3_to_a4 static void a4_to_a3(unsigned char* a3, unsigned char* a4) { - a3[0] = (a4[0] << 2) + ((a4[1] & 0x30) >> 4); - a3[1] = ((a4[1] & 0xf) << 4) + ((a4[2] & 0x3c) >> 2); - a3[2] = ((a4[2] & 0x3) << 6) + a4[3]; -} // a4_to_a3 + a3[0] = (a4[0] << 2) + ((a4[1] & 0x30) >> 4); + a3[1] = ((a4[1] & 0xf) << 4) + ((a4[2] & 0x3c) >> 2); + a3[2] = ((a4[2] & 0x3) << 6) + a4[3]; +} // a4_to_a3 /** @@ -56,49 +56,49 @@ static void a4_to_a3(unsigned char* a3, unsigned char* a4) { * @param [out] out */ bool GeneralUtils::base64Encode(const String& in, String* out) { - std::string std_in(in.c_str()); - std::string std_out(out->c_str()); - int i = 0, j = 0; - size_t enc_len = 0; - unsigned char a3[3]; - unsigned char a4[4]; - std_out.resize(base64EncodedLength(in)); - - int input_len = std_in.length(); - std::string::const_iterator input = std_in.begin(); - - while (input_len--) { - a3[i++] = *(input++); - if (i == 3) { - a3_to_a4(a4, a3); - - for (i = 0; i < 4; i++) { - (std_out)[enc_len++] = kBase64Alphabet[a4[i]]; - } - - i = 0; - } - } + std::string std_in(in.c_str()); + std::string std_out(out->c_str()); + int i = 0, j = 0; + size_t enc_len = 0; + unsigned char a3[3]; + unsigned char a4[4]; + std_out.resize(base64EncodedLength(in)); - if (i) { - for (j = i; j < 3; j++) { - a3[j] = '\0'; - } + int input_len = std_in.length(); + std::string::const_iterator input = std_in.begin(); - a3_to_a4(a4, a3); + while (input_len--) { + a3[i++] = *(input++); + if (i == 3) { + a3_to_a4(a4, a3); - for (j = 0; j < i + 1; j++) { - (std_out)[enc_len++] = kBase64Alphabet[a4[j]]; - } + for (i = 0; i < 4; i++) { + (std_out)[enc_len++] = kBase64Alphabet[a4[i]]; + } - while ((i++ < 3)) { - (std_out)[enc_len++] = '='; - } - } - *out = String(std_out.c_str()); + i = 0; + } + } + + if (i) { + for (j = i; j < 3; j++) { + a3[j] = '\0'; + } + + a3_to_a4(a4, a3); - return (enc_len == out->length()); -} // base64Encode + for (j = 0; j < i + 1; j++) { + (std_out)[enc_len++] = kBase64Alphabet[a4[j]]; + } + + while ((i++ < 3)) { + (std_out)[enc_len++] = '='; + } + } + *out = String(std_out.c_str()); + + return (enc_len == out->length()); +} // base64Encode /** @@ -107,14 +107,14 @@ bool GeneralUtils::base64Encode(const String& in, String* out) { * * Amount of free RAM */ void GeneralUtils::dumpInfo() { - esp_chip_info_t chipInfo; - esp_chip_info(&chipInfo); - log_v("--- dumpInfo ---"); - log_v("Free heap: %d", heap_caps_get_free_size(MALLOC_CAP_8BIT)); - log_v("Chip Info: Model: %d, cores: %d, revision: %d", chipInfo.model, chipInfo.cores, chipInfo.revision); - log_v("ESP-IDF version: %s", esp_get_idf_version()); - log_v("---"); -} // dumpInfo + esp_chip_info_t chipInfo; + esp_chip_info(&chipInfo); + log_v("--- dumpInfo ---"); + log_v("Free heap: %d", heap_caps_get_free_size(MALLOC_CAP_8BIT)); + log_v("Chip Info: Model: %d, cores: %d, revision: %d", chipInfo.model, chipInfo.cores, chipInfo.revision); + log_v("ESP-IDF version: %s", esp_get_idf_version()); + log_v("---"); +} // dumpInfo /** @@ -124,14 +124,14 @@ void GeneralUtils::dumpInfo() { * @return True if the string ends with the given character. */ bool GeneralUtils::endsWith(String str, char c) { - if (str.length() == 0) { - return false; - } - if (str.charAt(str.length() - 1) == c) { - return true; - } - return false; -} // endsWidth + if (str.length() == 0) { + return false; + } + if (str.charAt(str.length() - 1) == c) { + return true; + } + return false; +} // endsWidth /* static int DecodedLength(const String& in) { @@ -147,13 +147,13 @@ static int DecodedLength(const String& in) { */ static unsigned char b64_lookup(unsigned char c) { - if(c >='A' && c <='Z') return c - 'A'; - if(c >='a' && c <='z') return c - 71; - if(c >='0' && c <='9') return c + 4; - if(c == '+') return 62; - if(c == '/') return 63; - return 255; -}; // b64_lookup + if (c >= 'A' && c <= 'Z') return c - 'A'; + if (c >= 'a' && c <= 'z') return c - 71; + if (c >= '0' && c <= '9') return c + 4; + if (c == '+') return 62; + if (c == '/') return 63; + return 255; +}; // b64_lookup /** @@ -162,57 +162,57 @@ static unsigned char b64_lookup(unsigned char c) { * @param [out] out The resulting data. */ bool GeneralUtils::base64Decode(const String& in, String* out) { - int i = 0, j = 0; - size_t dec_len = 0; - unsigned char a3[3]; - unsigned char a4[4]; + int i = 0, j = 0; + size_t dec_len = 0; + unsigned char a3[3]; + unsigned char a4[4]; - int input_len = in.length(); - int input_iterator = 0; + int input_len = in.length(); + int input_iterator = 0; - //out->resize(DecodedLength(in)); + //out->resize(DecodedLength(in)); - while (input_len--) { - //if (*input == '=') { - if (in[input_iterator] == '=') { - break; - } + while (input_len--) { + //if (*input == '=') { + if (in[input_iterator] == '=') { + break; + } - a4[i++] = in[input_iterator++]; - if (i == 4) { - for (i = 0; i <4; i++) { - a4[i] = b64_lookup(a4[i]); - } + a4[i++] = in[input_iterator++]; + if (i == 4) { + for (i = 0; i < 4; i++) { + a4[i] = b64_lookup(a4[i]); + } - a4_to_a3(a3,a4); + a4_to_a3(a3, a4); - for (i = 0; i < 3; i++) { - out->concat(a3[i]); - dec_len++; - } + for (i = 0; i < 3; i++) { + out->concat(a3[i]); + dec_len++; + } - i = 0; - } - } + i = 0; + } + } - if (i) { - for (j = i; j < 4; j++) { - a4[j] = '\0'; - } + if (i) { + for (j = i; j < 4; j++) { + a4[j] = '\0'; + } - for (j = 0; j < 4; j++) { - a4[j] = b64_lookup(a4[j]); - } + for (j = 0; j < 4; j++) { + a4[j] = b64_lookup(a4[j]); + } - a4_to_a3(a3,a4); + a4_to_a3(a3, a4); - for (j = 0; j < i - 1; j++) { - (*out)[dec_len++] = a3[j]; - } - } + for (j = 0; j < i - 1; j++) { + (*out)[dec_len++] = a3[j]; + } + } - return (dec_len == out->length()); - } // base64Decode + return (dec_len == out->length()); +} // base64Decode /* void GeneralUtils::hexDump(uint8_t* pData, uint32_t length) { @@ -294,41 +294,41 @@ void GeneralUtils::hexDump(uint8_t* pData, uint32_t length) { * @return N/A. */ void GeneralUtils::hexDump(const uint8_t* pData, uint32_t length) { - char ascii[80]; - char hex[80]; - char tempBuf[80]; - uint32_t lineNumber = 0; - - log_v(" 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f"); - log_v(" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --"); - strcpy(ascii, ""); - strcpy(hex, ""); - uint32_t index = 0; - while (index < length) { - sprintf(tempBuf, "%.2x ", pData[index]); - strcat(hex, tempBuf); - if (isprint(pData[index])) { - sprintf(tempBuf, "%c", pData[index]); - } else { - sprintf(tempBuf, "."); - } - strcat(ascii, tempBuf); - index++; - if (index % 16 == 0) { - log_v("%.4x %s %s", lineNumber * 16, hex, ascii); - strcpy(ascii, ""); - strcpy(hex, ""); - lineNumber++; - } - } - if (index %16 != 0) { - while (index % 16 != 0) { - strcat(hex, " "); - index++; - } - log_v("%.4x %s %s", lineNumber * 16, hex, ascii); - } -} // hexDump + char ascii[80]; + char hex[80]; + char tempBuf[80]; + uint32_t lineNumber = 0; + + log_v(" 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f"); + log_v(" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --"); + strcpy(ascii, ""); + strcpy(hex, ""); + uint32_t index = 0; + while (index < length) { + sprintf(tempBuf, "%.2x ", pData[index]); + strcat(hex, tempBuf); + if (isprint(pData[index])) { + sprintf(tempBuf, "%c", pData[index]); + } else { + sprintf(tempBuf, "."); + } + strcat(ascii, tempBuf); + index++; + if (index % 16 == 0) { + log_v("%.4x %s %s", lineNumber * 16, hex, ascii); + strcpy(ascii, ""); + strcpy(hex, ""); + lineNumber++; + } + } + if (index % 16 != 0) { + while (index % 16 != 0) { + strcat(hex, " "); + index++; + } + log_v("%.4x %s %s", lineNumber * 16, hex, ascii); + } +} // hexDump /** @@ -336,14 +336,14 @@ void GeneralUtils::hexDump(const uint8_t* pData, uint32_t length) { * @param ip The 4 byte IP address. * @return A string representation of the IP address. */ -String GeneralUtils::ipToString(uint8_t *ip) { - auto size = 16; - char *val = (char*)malloc(size); - snprintf(val, size, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); - String res(val); - free(val); - return res; -} // ipToString +String GeneralUtils::ipToString(uint8_t* ip) { + auto size = 16; + char* val = (char*)malloc(size); + snprintf(val, size, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); + String res(val); + free(val); + return res; +} // ipToString /** @@ -353,19 +353,19 @@ String GeneralUtils::ipToString(uint8_t *ip) { * @return A vector of strings that are the split of the input. */ std::vector GeneralUtils::split(String source, char delimiter) { - // See also: https://stackoverflow.com/questions/5167625/splitting-a-c-stdstring-using-tokens-e-g - std::vector strings; - std::size_t current, previous = 0; - std::string std_source(source.c_str()); - current = std_source.find(delimiter); - while (current != std::string::npos) { - strings.push_back(trim(source.substring(previous, current))); - previous = current + 1; - current = std_source.find(delimiter, previous); - } - strings.push_back(trim(source.substring(previous, current))); - return strings; -} // split + // See also: https://stackoverflow.com/questions/5167625/splitting-a-c-stdstring-using-tokens-e-g + std::vector strings; + std::size_t current, previous = 0; + std::string std_source(source.c_str()); + current = std_source.find(delimiter); + while (current != std::string::npos) { + strings.push_back(trim(source.substring(previous, current))); + previous = current + 1; + current = std_source.find(delimiter, previous); + } + strings.push_back(trim(source.substring(previous, current))); + return strings; +} // split /** @@ -374,79 +374,79 @@ std::vector GeneralUtils::split(String source, char delimiter) { * @return A string representation of the error code. */ const char* GeneralUtils::errorToString(esp_err_t errCode) { - switch (errCode) { + switch (errCode) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - case ESP_OK: - return "ESP_OK"; - case ESP_FAIL: - return "ESP_FAIL"; - case ESP_ERR_NO_MEM: - return "ESP_ERR_NO_MEM"; - case ESP_ERR_INVALID_ARG: - return "ESP_ERR_INVALID_ARG"; - case ESP_ERR_INVALID_SIZE: - return "ESP_ERR_INVALID_SIZE"; - case ESP_ERR_INVALID_STATE: - return "ESP_ERR_INVALID_STATE"; - case ESP_ERR_NOT_FOUND: - return "ESP_ERR_NOT_FOUND"; - case ESP_ERR_NOT_SUPPORTED: - return "ESP_ERR_NOT_SUPPORTED"; - case ESP_ERR_TIMEOUT: - return "ESP_ERR_TIMEOUT"; - case ESP_ERR_NVS_NOT_INITIALIZED: - return "ESP_ERR_NVS_NOT_INITIALIZED"; - case ESP_ERR_NVS_NOT_FOUND: - return "ESP_ERR_NVS_NOT_FOUND"; - case ESP_ERR_NVS_TYPE_MISMATCH: - return "ESP_ERR_NVS_TYPE_MISMATCH"; - case ESP_ERR_NVS_READ_ONLY: - return "ESP_ERR_NVS_READ_ONLY"; - case ESP_ERR_NVS_NOT_ENOUGH_SPACE: - return "ESP_ERR_NVS_NOT_ENOUGH_SPACE"; - case ESP_ERR_NVS_INVALID_NAME: - return "ESP_ERR_NVS_INVALID_NAME"; - case ESP_ERR_NVS_INVALID_HANDLE: - return "ESP_ERR_NVS_INVALID_HANDLE"; - case ESP_ERR_NVS_REMOVE_FAILED: - return "ESP_ERR_NVS_REMOVE_FAILED"; - case ESP_ERR_NVS_KEY_TOO_LONG: - return "ESP_ERR_NVS_KEY_TOO_LONG"; - case ESP_ERR_NVS_PAGE_FULL: - return "ESP_ERR_NVS_PAGE_FULL"; - case ESP_ERR_NVS_INVALID_STATE: - return "ESP_ERR_NVS_INVALID_STATE"; - case ESP_ERR_NVS_INVALID_LENGTH: - return "ESP_ERR_NVS_INVALID_LENGTH"; - case ESP_ERR_WIFI_NOT_INIT: - return "ESP_ERR_WIFI_NOT_INIT"; - //case ESP_ERR_WIFI_NOT_START: - // return "ESP_ERR_WIFI_NOT_START"; - case ESP_ERR_WIFI_IF: - return "ESP_ERR_WIFI_IF"; - case ESP_ERR_WIFI_MODE: - return "ESP_ERR_WIFI_MODE"; - case ESP_ERR_WIFI_STATE: - return "ESP_ERR_WIFI_STATE"; - case ESP_ERR_WIFI_CONN: - return "ESP_ERR_WIFI_CONN"; - case ESP_ERR_WIFI_NVS: - return "ESP_ERR_WIFI_NVS"; - case ESP_ERR_WIFI_MAC: - return "ESP_ERR_WIFI_MAC"; - case ESP_ERR_WIFI_SSID: - return "ESP_ERR_WIFI_SSID"; - case ESP_ERR_WIFI_PASSWORD: - return "ESP_ERR_WIFI_PASSWORD"; - case ESP_ERR_WIFI_TIMEOUT: - return "ESP_ERR_WIFI_TIMEOUT"; - case ESP_ERR_WIFI_WAKE_FAIL: - return "ESP_ERR_WIFI_WAKE_FAIL"; + case ESP_OK: + return "ESP_OK"; + case ESP_FAIL: + return "ESP_FAIL"; + case ESP_ERR_NO_MEM: + return "ESP_ERR_NO_MEM"; + case ESP_ERR_INVALID_ARG: + return "ESP_ERR_INVALID_ARG"; + case ESP_ERR_INVALID_SIZE: + return "ESP_ERR_INVALID_SIZE"; + case ESP_ERR_INVALID_STATE: + return "ESP_ERR_INVALID_STATE"; + case ESP_ERR_NOT_FOUND: + return "ESP_ERR_NOT_FOUND"; + case ESP_ERR_NOT_SUPPORTED: + return "ESP_ERR_NOT_SUPPORTED"; + case ESP_ERR_TIMEOUT: + return "ESP_ERR_TIMEOUT"; + case ESP_ERR_NVS_NOT_INITIALIZED: + return "ESP_ERR_NVS_NOT_INITIALIZED"; + case ESP_ERR_NVS_NOT_FOUND: + return "ESP_ERR_NVS_NOT_FOUND"; + case ESP_ERR_NVS_TYPE_MISMATCH: + return "ESP_ERR_NVS_TYPE_MISMATCH"; + case ESP_ERR_NVS_READ_ONLY: + return "ESP_ERR_NVS_READ_ONLY"; + case ESP_ERR_NVS_NOT_ENOUGH_SPACE: + return "ESP_ERR_NVS_NOT_ENOUGH_SPACE"; + case ESP_ERR_NVS_INVALID_NAME: + return "ESP_ERR_NVS_INVALID_NAME"; + case ESP_ERR_NVS_INVALID_HANDLE: + return "ESP_ERR_NVS_INVALID_HANDLE"; + case ESP_ERR_NVS_REMOVE_FAILED: + return "ESP_ERR_NVS_REMOVE_FAILED"; + case ESP_ERR_NVS_KEY_TOO_LONG: + return "ESP_ERR_NVS_KEY_TOO_LONG"; + case ESP_ERR_NVS_PAGE_FULL: + return "ESP_ERR_NVS_PAGE_FULL"; + case ESP_ERR_NVS_INVALID_STATE: + return "ESP_ERR_NVS_INVALID_STATE"; + case ESP_ERR_NVS_INVALID_LENGTH: + return "ESP_ERR_NVS_INVALID_LENGTH"; + case ESP_ERR_WIFI_NOT_INIT: + return "ESP_ERR_WIFI_NOT_INIT"; + //case ESP_ERR_WIFI_NOT_START: + // return "ESP_ERR_WIFI_NOT_START"; + case ESP_ERR_WIFI_IF: + return "ESP_ERR_WIFI_IF"; + case ESP_ERR_WIFI_MODE: + return "ESP_ERR_WIFI_MODE"; + case ESP_ERR_WIFI_STATE: + return "ESP_ERR_WIFI_STATE"; + case ESP_ERR_WIFI_CONN: + return "ESP_ERR_WIFI_CONN"; + case ESP_ERR_WIFI_NVS: + return "ESP_ERR_WIFI_NVS"; + case ESP_ERR_WIFI_MAC: + return "ESP_ERR_WIFI_MAC"; + case ESP_ERR_WIFI_SSID: + return "ESP_ERR_WIFI_SSID"; + case ESP_ERR_WIFI_PASSWORD: + return "ESP_ERR_WIFI_PASSWORD"; + case ESP_ERR_WIFI_TIMEOUT: + return "ESP_ERR_WIFI_TIMEOUT"; + case ESP_ERR_WIFI_WAKE_FAIL: + return "ESP_ERR_WIFI_WAKE_FAIL"; #endif - default: - return "Unknown ESP_ERR error"; - } -} // errorToString + default: + return "Unknown ESP_ERR error"; + } +} // errorToString /** * @brief Convert a wifi_err_reason_t code to a string. @@ -456,72 +456,72 @@ const char* GeneralUtils::errorToString(esp_err_t errCode) { * @note: wifi_err_reason_t values as of April 2018 are: (1-24, 200-204) and are defined in ~/esp-idf/components/esp32/include/esp_wifi_types.h. */ const char* GeneralUtils::wifiErrorToString(uint8_t errCode) { - if (errCode == ESP_OK) return "ESP_OK (received SYSTEM_EVENT_STA_GOT_IP event)"; - if (errCode == UINT8_MAX) return "Not Connected (default value)"; + if (errCode == ESP_OK) return "ESP_OK (received SYSTEM_EVENT_STA_GOT_IP event)"; + if (errCode == UINT8_MAX) return "Not Connected (default value)"; - switch ((wifi_err_reason_t) errCode) { + switch ((wifi_err_reason_t)errCode) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - case WIFI_REASON_UNSPECIFIED: - return "WIFI_REASON_UNSPECIFIED"; - case WIFI_REASON_AUTH_EXPIRE: - return "WIFI_REASON_AUTH_EXPIRE"; - case WIFI_REASON_AUTH_LEAVE: - return "WIFI_REASON_AUTH_LEAVE"; - case WIFI_REASON_ASSOC_EXPIRE: - return "WIFI_REASON_ASSOC_EXPIRE"; - case WIFI_REASON_ASSOC_TOOMANY: - return "WIFI_REASON_ASSOC_TOOMANY"; - case WIFI_REASON_NOT_AUTHED: - return "WIFI_REASON_NOT_AUTHED"; - case WIFI_REASON_NOT_ASSOCED: - return "WIFI_REASON_NOT_ASSOCED"; - case WIFI_REASON_ASSOC_LEAVE: - return "WIFI_REASON_ASSOC_LEAVE"; - case WIFI_REASON_ASSOC_NOT_AUTHED: - return "WIFI_REASON_ASSOC_NOT_AUTHED"; - case WIFI_REASON_DISASSOC_PWRCAP_BAD: - return "WIFI_REASON_DISASSOC_PWRCAP_BAD"; - case WIFI_REASON_DISASSOC_SUPCHAN_BAD: - return "WIFI_REASON_DISASSOC_SUPCHAN_BAD"; - case WIFI_REASON_IE_INVALID: - return "WIFI_REASON_IE_INVALID"; - case WIFI_REASON_MIC_FAILURE: - return "WIFI_REASON_MIC_FAILURE"; - case WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT: - return "WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT"; - case WIFI_REASON_GROUP_KEY_UPDATE_TIMEOUT: - return "WIFI_REASON_GROUP_KEY_UPDATE_TIMEOUT"; - case WIFI_REASON_IE_IN_4WAY_DIFFERS: - return "WIFI_REASON_IE_IN_4WAY_DIFFERS"; - case WIFI_REASON_GROUP_CIPHER_INVALID: - return "WIFI_REASON_GROUP_CIPHER_INVALID"; - case WIFI_REASON_PAIRWISE_CIPHER_INVALID: - return "WIFI_REASON_PAIRWISE_CIPHER_INVALID"; - case WIFI_REASON_AKMP_INVALID: - return "WIFI_REASON_AKMP_INVALID"; - case WIFI_REASON_UNSUPP_RSN_IE_VERSION: - return "WIFI_REASON_UNSUPP_RSN_IE_VERSION"; - case WIFI_REASON_INVALID_RSN_IE_CAP: - return "WIFI_REASON_INVALID_RSN_IE_CAP"; - case WIFI_REASON_802_1X_AUTH_FAILED: - return "WIFI_REASON_802_1X_AUTH_FAILED"; - case WIFI_REASON_CIPHER_SUITE_REJECTED: - return "WIFI_REASON_CIPHER_SUITE_REJECTED"; - case WIFI_REASON_BEACON_TIMEOUT: - return "WIFI_REASON_BEACON_TIMEOUT"; - case WIFI_REASON_NO_AP_FOUND: - return "WIFI_REASON_NO_AP_FOUND"; - case WIFI_REASON_AUTH_FAIL: - return "WIFI_REASON_AUTH_FAIL"; - case WIFI_REASON_ASSOC_FAIL: - return "WIFI_REASON_ASSOC_FAIL"; - case WIFI_REASON_HANDSHAKE_TIMEOUT: - return "WIFI_REASON_HANDSHAKE_TIMEOUT"; + case WIFI_REASON_UNSPECIFIED: + return "WIFI_REASON_UNSPECIFIED"; + case WIFI_REASON_AUTH_EXPIRE: + return "WIFI_REASON_AUTH_EXPIRE"; + case WIFI_REASON_AUTH_LEAVE: + return "WIFI_REASON_AUTH_LEAVE"; + case WIFI_REASON_ASSOC_EXPIRE: + return "WIFI_REASON_ASSOC_EXPIRE"; + case WIFI_REASON_ASSOC_TOOMANY: + return "WIFI_REASON_ASSOC_TOOMANY"; + case WIFI_REASON_NOT_AUTHED: + return "WIFI_REASON_NOT_AUTHED"; + case WIFI_REASON_NOT_ASSOCED: + return "WIFI_REASON_NOT_ASSOCED"; + case WIFI_REASON_ASSOC_LEAVE: + return "WIFI_REASON_ASSOC_LEAVE"; + case WIFI_REASON_ASSOC_NOT_AUTHED: + return "WIFI_REASON_ASSOC_NOT_AUTHED"; + case WIFI_REASON_DISASSOC_PWRCAP_BAD: + return "WIFI_REASON_DISASSOC_PWRCAP_BAD"; + case WIFI_REASON_DISASSOC_SUPCHAN_BAD: + return "WIFI_REASON_DISASSOC_SUPCHAN_BAD"; + case WIFI_REASON_IE_INVALID: + return "WIFI_REASON_IE_INVALID"; + case WIFI_REASON_MIC_FAILURE: + return "WIFI_REASON_MIC_FAILURE"; + case WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT: + return "WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT"; + case WIFI_REASON_GROUP_KEY_UPDATE_TIMEOUT: + return "WIFI_REASON_GROUP_KEY_UPDATE_TIMEOUT"; + case WIFI_REASON_IE_IN_4WAY_DIFFERS: + return "WIFI_REASON_IE_IN_4WAY_DIFFERS"; + case WIFI_REASON_GROUP_CIPHER_INVALID: + return "WIFI_REASON_GROUP_CIPHER_INVALID"; + case WIFI_REASON_PAIRWISE_CIPHER_INVALID: + return "WIFI_REASON_PAIRWISE_CIPHER_INVALID"; + case WIFI_REASON_AKMP_INVALID: + return "WIFI_REASON_AKMP_INVALID"; + case WIFI_REASON_UNSUPP_RSN_IE_VERSION: + return "WIFI_REASON_UNSUPP_RSN_IE_VERSION"; + case WIFI_REASON_INVALID_RSN_IE_CAP: + return "WIFI_REASON_INVALID_RSN_IE_CAP"; + case WIFI_REASON_802_1X_AUTH_FAILED: + return "WIFI_REASON_802_1X_AUTH_FAILED"; + case WIFI_REASON_CIPHER_SUITE_REJECTED: + return "WIFI_REASON_CIPHER_SUITE_REJECTED"; + case WIFI_REASON_BEACON_TIMEOUT: + return "WIFI_REASON_BEACON_TIMEOUT"; + case WIFI_REASON_NO_AP_FOUND: + return "WIFI_REASON_NO_AP_FOUND"; + case WIFI_REASON_AUTH_FAIL: + return "WIFI_REASON_AUTH_FAIL"; + case WIFI_REASON_ASSOC_FAIL: + return "WIFI_REASON_ASSOC_FAIL"; + case WIFI_REASON_HANDSHAKE_TIMEOUT: + return "WIFI_REASON_HANDSHAKE_TIMEOUT"; #endif - default: - return "Unknown ESP_ERR error"; - } -} // wifiErrorToString + default: + return "Unknown ESP_ERR error"; + } +} // wifiErrorToString /** @@ -530,20 +530,20 @@ const char* GeneralUtils::wifiErrorToString(uint8_t errCode) { * @return A lower case representation of the string. */ String GeneralUtils::toLower(String& value) { - // Question: Could this be improved with a signature of: - // String& GeneralUtils::toLower(String& value) - std::transform(value.begin(), value.end(), value.begin(), ::tolower); - return value; -} // toLower + // Question: Could this be improved with a signature of: + // String& GeneralUtils::toLower(String& value) + std::transform(value.begin(), value.end(), value.begin(), ::tolower); + return value; +} // toLower /** * @brief Remove white space from a string. */ String GeneralUtils::trim(const String& str) { - std::string std_str(str.c_str()); - size_t first = std_str.find_first_not_of(' '); - if (std::string::npos == first) return str; - size_t last = std_str.find_last_not_of(' '); - return str.substring(first, (last + 1)); -} // trim + std::string std_str(str.c_str()); + size_t first = std_str.find_first_not_of(' '); + if (std::string::npos == first) return str; + size_t last = std_str.find_last_not_of(' '); + return str.substring(first, (last + 1)); +} // trim diff --git a/libraries/BLE/src/GeneralUtils.h b/libraries/BLE/src/GeneralUtils.h index 285261be1bc..5e714f86399 100644 --- a/libraries/BLE/src/GeneralUtils.h +++ b/libraries/BLE/src/GeneralUtils.h @@ -19,18 +19,17 @@ */ class GeneralUtils { public: - static bool base64Decode(const String& in, String* out); - static bool base64Encode(const String& in, String* out); - static void dumpInfo(); - static bool endsWith(String str, char c); - static const char* errorToString(esp_err_t errCode); - static const char* wifiErrorToString(uint8_t value); - static void hexDump(const uint8_t* pData, uint32_t length); - static String ipToString(uint8_t* ip); - static std::vector split(String source, char delimiter); - static String toLower(String& value); - static String trim(const String& str); - + static bool base64Decode(const String& in, String* out); + static bool base64Encode(const String& in, String* out); + static void dumpInfo(); + static bool endsWith(String str, char c); + static const char* errorToString(esp_err_t errCode); + static const char* wifiErrorToString(uint8_t value); + static void hexDump(const uint8_t* pData, uint32_t length); + static String ipToString(uint8_t* ip); + static std::vector split(String source, char delimiter); + static String toLower(String& value); + static String trim(const String& str); }; #endif /* COMPONENTS_CPP_UTILS_GENERALUTILS_H_ */ diff --git a/libraries/BLE/src/HIDKeyboardTypes.h b/libraries/BLE/src/HIDKeyboardTypes.h index 4e221d57f8d..74825da7ba0 100644 --- a/libraries/BLE/src/HIDKeyboardTypes.h +++ b/libraries/BLE/src/HIDKeyboardTypes.h @@ -22,380 +22,386 @@ #define KEYBOARD_DEFS_H #define REPORT_ID_KEYBOARD 1 -#define REPORT_ID_VOLUME 3 +#define REPORT_ID_VOLUME 3 /* Modifiers */ enum MODIFIER_KEY { - KEY_CTRL = 1, - KEY_SHIFT = 2, - KEY_ALT = 4, + KEY_CTRL = 1, + KEY_SHIFT = 2, + KEY_ALT = 4, }; enum MEDIA_KEY { - KEY_NEXT_TRACK, /*!< next Track Button */ - KEY_PREVIOUS_TRACK, /*!< Previous track Button */ - KEY_STOP, /*!< Stop Button */ - KEY_PLAY_PAUSE, /*!< Play/Pause Button */ - KEY_MUTE, /*!< Mute Button */ - KEY_VOLUME_UP, /*!< Volume Up Button */ - KEY_VOLUME_DOWN, /*!< Volume Down Button */ + KEY_NEXT_TRACK, /*!< next Track Button */ + KEY_PREVIOUS_TRACK, /*!< Previous track Button */ + KEY_STOP, /*!< Stop Button */ + KEY_PLAY_PAUSE, /*!< Play/Pause Button */ + KEY_MUTE, /*!< Mute Button */ + KEY_VOLUME_UP, /*!< Volume Up Button */ + KEY_VOLUME_DOWN, /*!< Volume Down Button */ }; enum FUNCTION_KEY { - KEY_F1 = 128, /* F1 key */ - KEY_F2, /* F2 key */ - KEY_F3, /* F3 key */ - KEY_F4, /* F4 key */ - KEY_F5, /* F5 key */ - KEY_F6, /* F6 key */ - KEY_F7, /* F7 key */ - KEY_F8, /* F8 key */ - KEY_F9, /* F9 key */ - KEY_F10, /* F10 key */ - KEY_F11, /* F11 key */ - KEY_F12, /* F12 key */ + KEY_F1 = 128, /* F1 key */ + KEY_F2, /* F2 key */ + KEY_F3, /* F3 key */ + KEY_F4, /* F4 key */ + KEY_F5, /* F5 key */ + KEY_F6, /* F6 key */ + KEY_F7, /* F7 key */ + KEY_F8, /* F8 key */ + KEY_F9, /* F9 key */ + KEY_F10, /* F10 key */ + KEY_F11, /* F11 key */ + KEY_F12, /* F12 key */ - KEY_PRINT_SCREEN, /* Print Screen key */ - KEY_SCROLL_LOCK, /* Scroll lock */ - KEY_CAPS_LOCK, /* caps lock */ - KEY_NUM_LOCK, /* num lock */ - KEY_INSERT, /* Insert key */ - KEY_HOME, /* Home key */ - KEY_PAGE_UP, /* Page Up key */ - KEY_PAGE_DOWN, /* Page Down key */ + KEY_PRINT_SCREEN, /* Print Screen key */ + KEY_SCROLL_LOCK, /* Scroll lock */ + KEY_CAPS_LOCK, /* caps lock */ + KEY_NUM_LOCK, /* num lock */ + KEY_INSERT, /* Insert key */ + KEY_HOME, /* Home key */ + KEY_PAGE_UP, /* Page Up key */ + KEY_PAGE_DOWN, /* Page Down key */ - RIGHT_ARROW, /* Right arrow */ - LEFT_ARROW, /* Left arrow */ - DOWN_ARROW, /* Down arrow */ - UP_ARROW, /* Up arrow */ + RIGHT_ARROW, /* Right arrow */ + LEFT_ARROW, /* Left arrow */ + DOWN_ARROW, /* Down arrow */ + UP_ARROW, /* Up arrow */ }; typedef struct { - unsigned char usage; - unsigned char modifier; + unsigned char usage; + unsigned char modifier; } KEYMAP; #ifdef US_KEYBOARD /* US keyboard (as HID standard) */ #define KEYMAP_SIZE (152) const KEYMAP keymap[KEYMAP_SIZE] = { - {0, 0}, /* NUL */ - {0, 0}, /* SOH */ - {0, 0}, /* STX */ - {0, 0}, /* ETX */ - {0, 0}, /* EOT */ - {0, 0}, /* ENQ */ - {0, 0}, /* ACK */ - {0, 0}, /* BEL */ - {0x2a, 0}, /* BS */ /* Keyboard Delete (Backspace) */ - {0x2b, 0}, /* TAB */ /* Keyboard Tab */ - {0x28, 0}, /* LF */ /* Keyboard Return (Enter) */ - {0, 0}, /* VT */ - {0, 0}, /* FF */ - {0, 0}, /* CR */ - {0, 0}, /* SO */ - {0, 0}, /* SI */ - {0, 0}, /* DEL */ - {0, 0}, /* DC1 */ - {0, 0}, /* DC2 */ - {0, 0}, /* DC3 */ - {0, 0}, /* DC4 */ - {0, 0}, /* NAK */ - {0, 0}, /* SYN */ - {0, 0}, /* ETB */ - {0, 0}, /* CAN */ - {0, 0}, /* EM */ - {0, 0}, /* SUB */ - {0, 0}, /* ESC */ - {0, 0}, /* FS */ - {0, 0}, /* GS */ - {0, 0}, /* RS */ - {0, 0}, /* US */ - {0x2c, 0}, /* */ - {0x1e, KEY_SHIFT}, /* ! */ - {0x34, KEY_SHIFT}, /* " */ - {0x20, KEY_SHIFT}, /* # */ - {0x21, KEY_SHIFT}, /* $ */ - {0x22, KEY_SHIFT}, /* % */ - {0x24, KEY_SHIFT}, /* & */ - {0x34, 0}, /* ' */ - {0x26, KEY_SHIFT}, /* ( */ - {0x27, KEY_SHIFT}, /* ) */ - {0x25, KEY_SHIFT}, /* * */ - {0x2e, KEY_SHIFT}, /* + */ - {0x36, 0}, /* , */ - {0x2d, 0}, /* - */ - {0x37, 0}, /* . */ - {0x38, 0}, /* / */ - {0x27, 0}, /* 0 */ - {0x1e, 0}, /* 1 */ - {0x1f, 0}, /* 2 */ - {0x20, 0}, /* 3 */ - {0x21, 0}, /* 4 */ - {0x22, 0}, /* 5 */ - {0x23, 0}, /* 6 */ - {0x24, 0}, /* 7 */ - {0x25, 0}, /* 8 */ - {0x26, 0}, /* 9 */ - {0x33, KEY_SHIFT}, /* : */ - {0x33, 0}, /* ; */ - {0x36, KEY_SHIFT}, /* < */ - {0x2e, 0}, /* = */ - {0x37, KEY_SHIFT}, /* > */ - {0x38, KEY_SHIFT}, /* ? */ - {0x1f, KEY_SHIFT}, /* @ */ - {0x04, KEY_SHIFT}, /* A */ - {0x05, KEY_SHIFT}, /* B */ - {0x06, KEY_SHIFT}, /* C */ - {0x07, KEY_SHIFT}, /* D */ - {0x08, KEY_SHIFT}, /* E */ - {0x09, KEY_SHIFT}, /* F */ - {0x0a, KEY_SHIFT}, /* G */ - {0x0b, KEY_SHIFT}, /* H */ - {0x0c, KEY_SHIFT}, /* I */ - {0x0d, KEY_SHIFT}, /* J */ - {0x0e, KEY_SHIFT}, /* K */ - {0x0f, KEY_SHIFT}, /* L */ - {0x10, KEY_SHIFT}, /* M */ - {0x11, KEY_SHIFT}, /* N */ - {0x12, KEY_SHIFT}, /* O */ - {0x13, KEY_SHIFT}, /* P */ - {0x14, KEY_SHIFT}, /* Q */ - {0x15, KEY_SHIFT}, /* R */ - {0x16, KEY_SHIFT}, /* S */ - {0x17, KEY_SHIFT}, /* T */ - {0x18, KEY_SHIFT}, /* U */ - {0x19, KEY_SHIFT}, /* V */ - {0x1a, KEY_SHIFT}, /* W */ - {0x1b, KEY_SHIFT}, /* X */ - {0x1c, KEY_SHIFT}, /* Y */ - {0x1d, KEY_SHIFT}, /* Z */ - {0x2f, 0}, /* [ */ - {0x31, 0}, /* \ */ - {0x30, 0}, /* ] */ - {0x23, KEY_SHIFT}, /* ^ */ - {0x2d, KEY_SHIFT}, /* _ */ - {0x35, 0}, /* ` */ - {0x04, 0}, /* a */ - {0x05, 0}, /* b */ - {0x06, 0}, /* c */ - {0x07, 0}, /* d */ - {0x08, 0}, /* e */ - {0x09, 0}, /* f */ - {0x0a, 0}, /* g */ - {0x0b, 0}, /* h */ - {0x0c, 0}, /* i */ - {0x0d, 0}, /* j */ - {0x0e, 0}, /* k */ - {0x0f, 0}, /* l */ - {0x10, 0}, /* m */ - {0x11, 0}, /* n */ - {0x12, 0}, /* o */ - {0x13, 0}, /* p */ - {0x14, 0}, /* q */ - {0x15, 0}, /* r */ - {0x16, 0}, /* s */ - {0x17, 0}, /* t */ - {0x18, 0}, /* u */ - {0x19, 0}, /* v */ - {0x1a, 0}, /* w */ - {0x1b, 0}, /* x */ - {0x1c, 0}, /* y */ - {0x1d, 0}, /* z */ - {0x2f, KEY_SHIFT}, /* { */ - {0x31, KEY_SHIFT}, /* | */ - {0x30, KEY_SHIFT}, /* } */ - {0x35, KEY_SHIFT}, /* ~ */ - {0,0}, /* DEL */ + { 0, 0 }, /* NUL */ + { 0, 0 }, /* SOH */ + { 0, 0 }, /* STX */ + { 0, 0 }, /* ETX */ + { 0, 0 }, /* EOT */ + { 0, 0 }, /* ENQ */ + { 0, 0 }, /* ACK */ + { 0, 0 }, /* BEL */ + { 0x2a, 0 }, + /* BS */ /* Keyboard Delete (Backspace) */ + { 0x2b, 0 }, + /* TAB */ /* Keyboard Tab */ + { 0x28, 0 }, + /* LF */ /* Keyboard Return (Enter) */ + { 0, 0 }, /* VT */ + { 0, 0 }, /* FF */ + { 0, 0 }, /* CR */ + { 0, 0 }, /* SO */ + { 0, 0 }, /* SI */ + { 0, 0 }, /* DEL */ + { 0, 0 }, /* DC1 */ + { 0, 0 }, /* DC2 */ + { 0, 0 }, /* DC3 */ + { 0, 0 }, /* DC4 */ + { 0, 0 }, /* NAK */ + { 0, 0 }, /* SYN */ + { 0, 0 }, /* ETB */ + { 0, 0 }, /* CAN */ + { 0, 0 }, /* EM */ + { 0, 0 }, /* SUB */ + { 0, 0 }, /* ESC */ + { 0, 0 }, /* FS */ + { 0, 0 }, /* GS */ + { 0, 0 }, /* RS */ + { 0, 0 }, /* US */ + { 0x2c, 0 }, /* */ + { 0x1e, KEY_SHIFT }, /* ! */ + { 0x34, KEY_SHIFT }, /* " */ + { 0x20, KEY_SHIFT }, /* # */ + { 0x21, KEY_SHIFT }, /* $ */ + { 0x22, KEY_SHIFT }, /* % */ + { 0x24, KEY_SHIFT }, /* & */ + { 0x34, 0 }, /* ' */ + { 0x26, KEY_SHIFT }, /* ( */ + { 0x27, KEY_SHIFT }, /* ) */ + { 0x25, KEY_SHIFT }, /* * */ + { 0x2e, KEY_SHIFT }, /* + */ + { 0x36, 0 }, /* , */ + { 0x2d, 0 }, /* - */ + { 0x37, 0 }, /* . */ + { 0x38, 0 }, /* / */ + { 0x27, 0 }, /* 0 */ + { 0x1e, 0 }, /* 1 */ + { 0x1f, 0 }, /* 2 */ + { 0x20, 0 }, /* 3 */ + { 0x21, 0 }, /* 4 */ + { 0x22, 0 }, /* 5 */ + { 0x23, 0 }, /* 6 */ + { 0x24, 0 }, /* 7 */ + { 0x25, 0 }, /* 8 */ + { 0x26, 0 }, /* 9 */ + { 0x33, KEY_SHIFT }, /* : */ + { 0x33, 0 }, /* ; */ + { 0x36, KEY_SHIFT }, /* < */ + { 0x2e, 0 }, /* = */ + { 0x37, KEY_SHIFT }, /* > */ + { 0x38, KEY_SHIFT }, /* ? */ + { 0x1f, KEY_SHIFT }, /* @ */ + { 0x04, KEY_SHIFT }, /* A */ + { 0x05, KEY_SHIFT }, /* B */ + { 0x06, KEY_SHIFT }, /* C */ + { 0x07, KEY_SHIFT }, /* D */ + { 0x08, KEY_SHIFT }, /* E */ + { 0x09, KEY_SHIFT }, /* F */ + { 0x0a, KEY_SHIFT }, /* G */ + { 0x0b, KEY_SHIFT }, /* H */ + { 0x0c, KEY_SHIFT }, /* I */ + { 0x0d, KEY_SHIFT }, /* J */ + { 0x0e, KEY_SHIFT }, /* K */ + { 0x0f, KEY_SHIFT }, /* L */ + { 0x10, KEY_SHIFT }, /* M */ + { 0x11, KEY_SHIFT }, /* N */ + { 0x12, KEY_SHIFT }, /* O */ + { 0x13, KEY_SHIFT }, /* P */ + { 0x14, KEY_SHIFT }, /* Q */ + { 0x15, KEY_SHIFT }, /* R */ + { 0x16, KEY_SHIFT }, /* S */ + { 0x17, KEY_SHIFT }, /* T */ + { 0x18, KEY_SHIFT }, /* U */ + { 0x19, KEY_SHIFT }, /* V */ + { 0x1a, KEY_SHIFT }, /* W */ + { 0x1b, KEY_SHIFT }, /* X */ + { 0x1c, KEY_SHIFT }, /* Y */ + { 0x1d, KEY_SHIFT }, /* Z */ + { 0x2f, 0 }, /* [ */ + { 0x31, 0 }, /* \ */ + { 0x30, 0 }, /* ] */ + { 0x23, KEY_SHIFT }, /* ^ */ + { 0x2d, KEY_SHIFT }, /* _ */ + { 0x35, 0 }, /* ` */ + { 0x04, 0 }, /* a */ + { 0x05, 0 }, /* b */ + { 0x06, 0 }, /* c */ + { 0x07, 0 }, /* d */ + { 0x08, 0 }, /* e */ + { 0x09, 0 }, /* f */ + { 0x0a, 0 }, /* g */ + { 0x0b, 0 }, /* h */ + { 0x0c, 0 }, /* i */ + { 0x0d, 0 }, /* j */ + { 0x0e, 0 }, /* k */ + { 0x0f, 0 }, /* l */ + { 0x10, 0 }, /* m */ + { 0x11, 0 }, /* n */ + { 0x12, 0 }, /* o */ + { 0x13, 0 }, /* p */ + { 0x14, 0 }, /* q */ + { 0x15, 0 }, /* r */ + { 0x16, 0 }, /* s */ + { 0x17, 0 }, /* t */ + { 0x18, 0 }, /* u */ + { 0x19, 0 }, /* v */ + { 0x1a, 0 }, /* w */ + { 0x1b, 0 }, /* x */ + { 0x1c, 0 }, /* y */ + { 0x1d, 0 }, /* z */ + { 0x2f, KEY_SHIFT }, /* { */ + { 0x31, KEY_SHIFT }, /* | */ + { 0x30, KEY_SHIFT }, /* } */ + { 0x35, KEY_SHIFT }, /* ~ */ + { 0, 0 }, /* DEL */ - {0x3a, 0}, /* F1 */ - {0x3b, 0}, /* F2 */ - {0x3c, 0}, /* F3 */ - {0x3d, 0}, /* F4 */ - {0x3e, 0}, /* F5 */ - {0x3f, 0}, /* F6 */ - {0x40, 0}, /* F7 */ - {0x41, 0}, /* F8 */ - {0x42, 0}, /* F9 */ - {0x43, 0}, /* F10 */ - {0x44, 0}, /* F11 */ - {0x45, 0}, /* F12 */ + { 0x3a, 0 }, /* F1 */ + { 0x3b, 0 }, /* F2 */ + { 0x3c, 0 }, /* F3 */ + { 0x3d, 0 }, /* F4 */ + { 0x3e, 0 }, /* F5 */ + { 0x3f, 0 }, /* F6 */ + { 0x40, 0 }, /* F7 */ + { 0x41, 0 }, /* F8 */ + { 0x42, 0 }, /* F9 */ + { 0x43, 0 }, /* F10 */ + { 0x44, 0 }, /* F11 */ + { 0x45, 0 }, /* F12 */ - {0x46, 0}, /* PRINT_SCREEN */ - {0x47, 0}, /* SCROLL_LOCK */ - {0x39, 0}, /* CAPS_LOCK */ - {0x53, 0}, /* NUM_LOCK */ - {0x49, 0}, /* INSERT */ - {0x4a, 0}, /* HOME */ - {0x4b, 0}, /* PAGE_UP */ - {0x4e, 0}, /* PAGE_DOWN */ + { 0x46, 0 }, /* PRINT_SCREEN */ + { 0x47, 0 }, /* SCROLL_LOCK */ + { 0x39, 0 }, /* CAPS_LOCK */ + { 0x53, 0 }, /* NUM_LOCK */ + { 0x49, 0 }, /* INSERT */ + { 0x4a, 0 }, /* HOME */ + { 0x4b, 0 }, /* PAGE_UP */ + { 0x4e, 0 }, /* PAGE_DOWN */ - {0x4f, 0}, /* RIGHT_ARROW */ - {0x50, 0}, /* LEFT_ARROW */ - {0x51, 0}, /* DOWN_ARROW */ - {0x52, 0}, /* UP_ARROW */ + { 0x4f, 0 }, /* RIGHT_ARROW */ + { 0x50, 0 }, /* LEFT_ARROW */ + { 0x51, 0 }, /* DOWN_ARROW */ + { 0x52, 0 }, /* UP_ARROW */ }; #else /* UK keyboard */ #define KEYMAP_SIZE (152) const KEYMAP keymap[KEYMAP_SIZE] = { - {0, 0}, /* NUL */ - {0, 0}, /* SOH */ - {0, 0}, /* STX */ - {0, 0}, /* ETX */ - {0, 0}, /* EOT */ - {0, 0}, /* ENQ */ - {0, 0}, /* ACK */ - {0, 0}, /* BEL */ - {0x2a, 0}, /* BS */ /* Keyboard Delete (Backspace) */ - {0x2b, 0}, /* TAB */ /* Keyboard Tab */ - {0x28, 0}, /* LF */ /* Keyboard Return (Enter) */ - {0, 0}, /* VT */ - {0, 0}, /* FF */ - {0, 0}, /* CR */ - {0, 0}, /* SO */ - {0, 0}, /* SI */ - {0, 0}, /* DEL */ - {0, 0}, /* DC1 */ - {0, 0}, /* DC2 */ - {0, 0}, /* DC3 */ - {0, 0}, /* DC4 */ - {0, 0}, /* NAK */ - {0, 0}, /* SYN */ - {0, 0}, /* ETB */ - {0, 0}, /* CAN */ - {0, 0}, /* EM */ - {0, 0}, /* SUB */ - {0, 0}, /* ESC */ - {0, 0}, /* FS */ - {0, 0}, /* GS */ - {0, 0}, /* RS */ - {0, 0}, /* US */ - {0x2c, 0}, /* */ - {0x1e, KEY_SHIFT}, /* ! */ - {0x1f, KEY_SHIFT}, /* " */ - {0x32, 0}, /* # */ - {0x21, KEY_SHIFT}, /* $ */ - {0x22, KEY_SHIFT}, /* % */ - {0x24, KEY_SHIFT}, /* & */ - {0x34, 0}, /* ' */ - {0x26, KEY_SHIFT}, /* ( */ - {0x27, KEY_SHIFT}, /* ) */ - {0x25, KEY_SHIFT}, /* * */ - {0x2e, KEY_SHIFT}, /* + */ - {0x36, 0}, /* , */ - {0x2d, 0}, /* - */ - {0x37, 0}, /* . */ - {0x38, 0}, /* / */ - {0x27, 0}, /* 0 */ - {0x1e, 0}, /* 1 */ - {0x1f, 0}, /* 2 */ - {0x20, 0}, /* 3 */ - {0x21, 0}, /* 4 */ - {0x22, 0}, /* 5 */ - {0x23, 0}, /* 6 */ - {0x24, 0}, /* 7 */ - {0x25, 0}, /* 8 */ - {0x26, 0}, /* 9 */ - {0x33, KEY_SHIFT}, /* : */ - {0x33, 0}, /* ; */ - {0x36, KEY_SHIFT}, /* < */ - {0x2e, 0}, /* = */ - {0x37, KEY_SHIFT}, /* > */ - {0x38, KEY_SHIFT}, /* ? */ - {0x34, KEY_SHIFT}, /* @ */ - {0x04, KEY_SHIFT}, /* A */ - {0x05, KEY_SHIFT}, /* B */ - {0x06, KEY_SHIFT}, /* C */ - {0x07, KEY_SHIFT}, /* D */ - {0x08, KEY_SHIFT}, /* E */ - {0x09, KEY_SHIFT}, /* F */ - {0x0a, KEY_SHIFT}, /* G */ - {0x0b, KEY_SHIFT}, /* H */ - {0x0c, KEY_SHIFT}, /* I */ - {0x0d, KEY_SHIFT}, /* J */ - {0x0e, KEY_SHIFT}, /* K */ - {0x0f, KEY_SHIFT}, /* L */ - {0x10, KEY_SHIFT}, /* M */ - {0x11, KEY_SHIFT}, /* N */ - {0x12, KEY_SHIFT}, /* O */ - {0x13, KEY_SHIFT}, /* P */ - {0x14, KEY_SHIFT}, /* Q */ - {0x15, KEY_SHIFT}, /* R */ - {0x16, KEY_SHIFT}, /* S */ - {0x17, KEY_SHIFT}, /* T */ - {0x18, KEY_SHIFT}, /* U */ - {0x19, KEY_SHIFT}, /* V */ - {0x1a, KEY_SHIFT}, /* W */ - {0x1b, KEY_SHIFT}, /* X */ - {0x1c, KEY_SHIFT}, /* Y */ - {0x1d, KEY_SHIFT}, /* Z */ - {0x2f, 0}, /* [ */ - {0x64, 0}, /* \ */ - {0x30, 0}, /* ] */ - {0x23, KEY_SHIFT}, /* ^ */ - {0x2d, KEY_SHIFT}, /* _ */ - {0x35, 0}, /* ` */ - {0x04, 0}, /* a */ - {0x05, 0}, /* b */ - {0x06, 0}, /* c */ - {0x07, 0}, /* d */ - {0x08, 0}, /* e */ - {0x09, 0}, /* f */ - {0x0a, 0}, /* g */ - {0x0b, 0}, /* h */ - {0x0c, 0}, /* i */ - {0x0d, 0}, /* j */ - {0x0e, 0}, /* k */ - {0x0f, 0}, /* l */ - {0x10, 0}, /* m */ - {0x11, 0}, /* n */ - {0x12, 0}, /* o */ - {0x13, 0}, /* p */ - {0x14, 0}, /* q */ - {0x15, 0}, /* r */ - {0x16, 0}, /* s */ - {0x17, 0}, /* t */ - {0x18, 0}, /* u */ - {0x19, 0}, /* v */ - {0x1a, 0}, /* w */ - {0x1b, 0}, /* x */ - {0x1c, 0}, /* y */ - {0x1d, 0}, /* z */ - {0x2f, KEY_SHIFT}, /* { */ - {0x64, KEY_SHIFT}, /* | */ - {0x30, KEY_SHIFT}, /* } */ - {0x32, KEY_SHIFT}, /* ~ */ - {0,0}, /* DEL */ + { 0, 0 }, /* NUL */ + { 0, 0 }, /* SOH */ + { 0, 0 }, /* STX */ + { 0, 0 }, /* ETX */ + { 0, 0 }, /* EOT */ + { 0, 0 }, /* ENQ */ + { 0, 0 }, /* ACK */ + { 0, 0 }, /* BEL */ + { 0x2a, 0 }, + /* BS */ /* Keyboard Delete (Backspace) */ + { 0x2b, 0 }, + /* TAB */ /* Keyboard Tab */ + { 0x28, 0 }, + /* LF */ /* Keyboard Return (Enter) */ + { 0, 0 }, /* VT */ + { 0, 0 }, /* FF */ + { 0, 0 }, /* CR */ + { 0, 0 }, /* SO */ + { 0, 0 }, /* SI */ + { 0, 0 }, /* DEL */ + { 0, 0 }, /* DC1 */ + { 0, 0 }, /* DC2 */ + { 0, 0 }, /* DC3 */ + { 0, 0 }, /* DC4 */ + { 0, 0 }, /* NAK */ + { 0, 0 }, /* SYN */ + { 0, 0 }, /* ETB */ + { 0, 0 }, /* CAN */ + { 0, 0 }, /* EM */ + { 0, 0 }, /* SUB */ + { 0, 0 }, /* ESC */ + { 0, 0 }, /* FS */ + { 0, 0 }, /* GS */ + { 0, 0 }, /* RS */ + { 0, 0 }, /* US */ + { 0x2c, 0 }, /* */ + { 0x1e, KEY_SHIFT }, /* ! */ + { 0x1f, KEY_SHIFT }, /* " */ + { 0x32, 0 }, /* # */ + { 0x21, KEY_SHIFT }, /* $ */ + { 0x22, KEY_SHIFT }, /* % */ + { 0x24, KEY_SHIFT }, /* & */ + { 0x34, 0 }, /* ' */ + { 0x26, KEY_SHIFT }, /* ( */ + { 0x27, KEY_SHIFT }, /* ) */ + { 0x25, KEY_SHIFT }, /* * */ + { 0x2e, KEY_SHIFT }, /* + */ + { 0x36, 0 }, /* , */ + { 0x2d, 0 }, /* - */ + { 0x37, 0 }, /* . */ + { 0x38, 0 }, /* / */ + { 0x27, 0 }, /* 0 */ + { 0x1e, 0 }, /* 1 */ + { 0x1f, 0 }, /* 2 */ + { 0x20, 0 }, /* 3 */ + { 0x21, 0 }, /* 4 */ + { 0x22, 0 }, /* 5 */ + { 0x23, 0 }, /* 6 */ + { 0x24, 0 }, /* 7 */ + { 0x25, 0 }, /* 8 */ + { 0x26, 0 }, /* 9 */ + { 0x33, KEY_SHIFT }, /* : */ + { 0x33, 0 }, /* ; */ + { 0x36, KEY_SHIFT }, /* < */ + { 0x2e, 0 }, /* = */ + { 0x37, KEY_SHIFT }, /* > */ + { 0x38, KEY_SHIFT }, /* ? */ + { 0x34, KEY_SHIFT }, /* @ */ + { 0x04, KEY_SHIFT }, /* A */ + { 0x05, KEY_SHIFT }, /* B */ + { 0x06, KEY_SHIFT }, /* C */ + { 0x07, KEY_SHIFT }, /* D */ + { 0x08, KEY_SHIFT }, /* E */ + { 0x09, KEY_SHIFT }, /* F */ + { 0x0a, KEY_SHIFT }, /* G */ + { 0x0b, KEY_SHIFT }, /* H */ + { 0x0c, KEY_SHIFT }, /* I */ + { 0x0d, KEY_SHIFT }, /* J */ + { 0x0e, KEY_SHIFT }, /* K */ + { 0x0f, KEY_SHIFT }, /* L */ + { 0x10, KEY_SHIFT }, /* M */ + { 0x11, KEY_SHIFT }, /* N */ + { 0x12, KEY_SHIFT }, /* O */ + { 0x13, KEY_SHIFT }, /* P */ + { 0x14, KEY_SHIFT }, /* Q */ + { 0x15, KEY_SHIFT }, /* R */ + { 0x16, KEY_SHIFT }, /* S */ + { 0x17, KEY_SHIFT }, /* T */ + { 0x18, KEY_SHIFT }, /* U */ + { 0x19, KEY_SHIFT }, /* V */ + { 0x1a, KEY_SHIFT }, /* W */ + { 0x1b, KEY_SHIFT }, /* X */ + { 0x1c, KEY_SHIFT }, /* Y */ + { 0x1d, KEY_SHIFT }, /* Z */ + { 0x2f, 0 }, /* [ */ + { 0x64, 0 }, /* \ */ + { 0x30, 0 }, /* ] */ + { 0x23, KEY_SHIFT }, /* ^ */ + { 0x2d, KEY_SHIFT }, /* _ */ + { 0x35, 0 }, /* ` */ + { 0x04, 0 }, /* a */ + { 0x05, 0 }, /* b */ + { 0x06, 0 }, /* c */ + { 0x07, 0 }, /* d */ + { 0x08, 0 }, /* e */ + { 0x09, 0 }, /* f */ + { 0x0a, 0 }, /* g */ + { 0x0b, 0 }, /* h */ + { 0x0c, 0 }, /* i */ + { 0x0d, 0 }, /* j */ + { 0x0e, 0 }, /* k */ + { 0x0f, 0 }, /* l */ + { 0x10, 0 }, /* m */ + { 0x11, 0 }, /* n */ + { 0x12, 0 }, /* o */ + { 0x13, 0 }, /* p */ + { 0x14, 0 }, /* q */ + { 0x15, 0 }, /* r */ + { 0x16, 0 }, /* s */ + { 0x17, 0 }, /* t */ + { 0x18, 0 }, /* u */ + { 0x19, 0 }, /* v */ + { 0x1a, 0 }, /* w */ + { 0x1b, 0 }, /* x */ + { 0x1c, 0 }, /* y */ + { 0x1d, 0 }, /* z */ + { 0x2f, KEY_SHIFT }, /* { */ + { 0x64, KEY_SHIFT }, /* | */ + { 0x30, KEY_SHIFT }, /* } */ + { 0x32, KEY_SHIFT }, /* ~ */ + { 0, 0 }, /* DEL */ - {0x3a, 0}, /* F1 */ - {0x3b, 0}, /* F2 */ - {0x3c, 0}, /* F3 */ - {0x3d, 0}, /* F4 */ - {0x3e, 0}, /* F5 */ - {0x3f, 0}, /* F6 */ - {0x40, 0}, /* F7 */ - {0x41, 0}, /* F8 */ - {0x42, 0}, /* F9 */ - {0x43, 0}, /* F10 */ - {0x44, 0}, /* F11 */ - {0x45, 0}, /* F12 */ + { 0x3a, 0 }, /* F1 */ + { 0x3b, 0 }, /* F2 */ + { 0x3c, 0 }, /* F3 */ + { 0x3d, 0 }, /* F4 */ + { 0x3e, 0 }, /* F5 */ + { 0x3f, 0 }, /* F6 */ + { 0x40, 0 }, /* F7 */ + { 0x41, 0 }, /* F8 */ + { 0x42, 0 }, /* F9 */ + { 0x43, 0 }, /* F10 */ + { 0x44, 0 }, /* F11 */ + { 0x45, 0 }, /* F12 */ - {0x46, 0}, /* PRINT_SCREEN */ - {0x47, 0}, /* SCROLL_LOCK */ - {0x39, 0}, /* CAPS_LOCK */ - {0x53, 0}, /* NUM_LOCK */ - {0x49, 0}, /* INSERT */ - {0x4a, 0}, /* HOME */ - {0x4b, 0}, /* PAGE_UP */ - {0x4e, 0}, /* PAGE_DOWN */ + { 0x46, 0 }, /* PRINT_SCREEN */ + { 0x47, 0 }, /* SCROLL_LOCK */ + { 0x39, 0 }, /* CAPS_LOCK */ + { 0x53, 0 }, /* NUM_LOCK */ + { 0x49, 0 }, /* INSERT */ + { 0x4a, 0 }, /* HOME */ + { 0x4b, 0 }, /* PAGE_UP */ + { 0x4e, 0 }, /* PAGE_DOWN */ - {0x4f, 0}, /* RIGHT_ARROW */ - {0x50, 0}, /* LEFT_ARROW */ - {0x51, 0}, /* DOWN_ARROW */ - {0x52, 0}, /* UP_ARROW */ + { 0x4f, 0 }, /* RIGHT_ARROW */ + { 0x50, 0 }, /* LEFT_ARROW */ + { 0x51, 0 }, /* DOWN_ARROW */ + { 0x52, 0 }, /* UP_ARROW */ }; #endif diff --git a/libraries/BLE/src/HIDTypes.h b/libraries/BLE/src/HIDTypes.h index 7bc09889330..d57f9c28f74 100644 --- a/libraries/BLE/src/HIDTypes.h +++ b/libraries/BLE/src/HIDTypes.h @@ -22,23 +22,23 @@ #include /* */ -#define HID_VERSION_1_11 (0x0111) +#define HID_VERSION_1_11 (0x0111) /* HID Class */ -#define BLE_HID_CLASS (3) -#define BLE_HID_SUBCLASS_NONE (0) -#define BLE_HID_PROTOCOL_NONE (0) +#define BLE_HID_CLASS (3) +#define BLE_HID_SUBCLASS_NONE (0) +#define BLE_HID_PROTOCOL_NONE (0) /* Descriptors */ -#define HID_DESCRIPTOR (33) -#define HID_DESCRIPTOR_LENGTH (0x09) -#define REPORT_DESCRIPTOR (34) +#define HID_DESCRIPTOR (33) +#define HID_DESCRIPTOR_LENGTH (0x09) +#define REPORT_DESCRIPTOR (34) /* Class requests */ #define GET_REPORT (0x1) -#define GET_IDLE (0x2) +#define GET_IDLE (0x2) #define SET_REPORT (0x9) -#define SET_IDLE (0xa) +#define SET_IDLE (0xa) /* HID Class Report Descriptor */ /* Short items: size is 0, 1, 2 or 3 specifying 0, 1, 2 or 4 (four) bytes */ @@ -46,41 +46,41 @@ /* Main items */ #ifdef ARDUINO_ARCH_ESP32 -#define HIDINPUT(size) (0x80 | size) -#define HIDOUTPUT(size) (0x90 | size) +#define HIDINPUT(size) (0x80 | size) +#define HIDOUTPUT(size) (0x90 | size) #else -#define INPUT(size) (0x80 | size) -#define OUTPUT(size) (0x90 | size) +#define INPUT(size) (0x80 | size) +#define OUTPUT(size) (0x90 | size) #endif -#define FEATURE(size) (0xb0 | size) -#define COLLECTION(size) (0xa0 | size) -#define END_COLLECTION(size) (0xc0 | size) +#define FEATURE(size) (0xb0 | size) +#define COLLECTION(size) (0xa0 | size) +#define END_COLLECTION(size) (0xc0 | size) /* Global items */ -#define USAGE_PAGE(size) (0x04 | size) -#define LOGICAL_MINIMUM(size) (0x14 | size) -#define LOGICAL_MAXIMUM(size) (0x24 | size) -#define PHYSICAL_MINIMUM(size) (0x34 | size) -#define PHYSICAL_MAXIMUM(size) (0x44 | size) -#define UNIT_EXPONENT(size) (0x54 | size) -#define UNIT(size) (0x64 | size) -#define REPORT_SIZE(size) (0x74 | size) //bits -#define REPORT_ID(size) (0x84 | size) -#define REPORT_COUNT(size) (0x94 | size) //bytes -#define PUSH(size) (0xa4 | size) -#define POP(size) (0xb4 | size) +#define USAGE_PAGE(size) (0x04 | size) +#define LOGICAL_MINIMUM(size) (0x14 | size) +#define LOGICAL_MAXIMUM(size) (0x24 | size) +#define PHYSICAL_MINIMUM(size) (0x34 | size) +#define PHYSICAL_MAXIMUM(size) (0x44 | size) +#define UNIT_EXPONENT(size) (0x54 | size) +#define UNIT(size) (0x64 | size) +#define REPORT_SIZE(size) (0x74 | size) //bits +#define REPORT_ID(size) (0x84 | size) +#define REPORT_COUNT(size) (0x94 | size) //bytes +#define PUSH(size) (0xa4 | size) +#define POP(size) (0xb4 | size) /* Local items */ -#define USAGE(size) (0x08 | size) -#define USAGE_MINIMUM(size) (0x18 | size) -#define USAGE_MAXIMUM(size) (0x28 | size) -#define DESIGNATOR_INDEX(size) (0x38 | size) -#define DESIGNATOR_MINIMUM(size) (0x48 | size) -#define DESIGNATOR_MAXIMUM(size) (0x58 | size) -#define STRING_INDEX(size) (0x78 | size) -#define STRING_MINIMUM(size) (0x88 | size) -#define STRING_MAXIMUM(size) (0x98 | size) -#define DELIMITER(size) (0xa8 | size) +#define USAGE(size) (0x08 | size) +#define USAGE_MINIMUM(size) (0x18 | size) +#define USAGE_MAXIMUM(size) (0x28 | size) +#define DESIGNATOR_INDEX(size) (0x38 | size) +#define DESIGNATOR_MINIMUM(size) (0x48 | size) +#define DESIGNATOR_MAXIMUM(size) (0x58 | size) +#define STRING_INDEX(size) (0x78 | size) +#define STRING_MINIMUM(size) (0x88 | size) +#define STRING_MAXIMUM(size) (0x98 | size) +#define DELIMITER(size) (0xa8 | size) /* HID Report */ /* Where report IDs are used the first byte of 'data' will be the */ @@ -89,8 +89,8 @@ #define MAX_HID_REPORT_SIZE (64) typedef struct { - uint32_t length; - uint8_t data[MAX_HID_REPORT_SIZE]; + uint32_t length; + uint8_t data[MAX_HID_REPORT_SIZE]; } HID_REPORT; #endif diff --git a/libraries/BLE/src/RTOS.h b/libraries/BLE/src/RTOS.h index 65362a94958..74a81205b1b 100644 --- a/libraries/BLE/src/RTOS.h +++ b/libraries/BLE/src/RTOS.h @@ -12,10 +12,10 @@ #include #include -#include // Include the base FreeRTOS definitions. -#include // Include the task definitions. -#include // Include the semaphore definitions. -#include // Include the ringbuffer definitions. +#include // Include the base FreeRTOS definitions. +#include // Include the task definitions. +#include // Include the semaphore definitions. +#include // Include the ringbuffer definitions. /** @@ -23,36 +23,37 @@ */ class FreeRTOS { public: - static void sleep(uint32_t ms); - static void startTask(void task(void*), String taskName, void* param = nullptr, uint32_t stackSize = 2048); - static void deleteTask(TaskHandle_t pTask = nullptr); + static void sleep(uint32_t ms); + static void startTask(void task(void*), String taskName, void* param = nullptr, uint32_t stackSize = 2048); + static void deleteTask(TaskHandle_t pTask = nullptr); - static uint32_t getTimeSinceStart(); + static uint32_t getTimeSinceStart(); - class Semaphore { - public: - Semaphore(String owner = ""); - ~Semaphore(); - void give(); - void give(uint32_t value); - void giveFromISR(); - void setName(String name); - bool take(String owner = ""); - bool take(uint32_t timeoutMs, String owner = ""); - String toString(); - uint32_t wait(String owner = ""); - bool timedWait(String owner = "", uint32_t timeoutMs = portMAX_DELAY); - uint32_t value(){ return m_value; }; + class Semaphore { + public: + Semaphore(String owner = ""); + ~Semaphore(); + void give(); + void give(uint32_t value); + void giveFromISR(); + void setName(String name); + bool take(String owner = ""); + bool take(uint32_t timeoutMs, String owner = ""); + String toString(); + uint32_t wait(String owner = ""); + bool timedWait(String owner = "", uint32_t timeoutMs = portMAX_DELAY); + uint32_t value() { + return m_value; + }; - private: - SemaphoreHandle_t m_semaphore; - pthread_mutex_t m_pthread_mutex; - String m_name; - String m_owner; - uint32_t m_value; - bool m_usePthreads; - - }; + private: + SemaphoreHandle_t m_semaphore; + pthread_mutex_t m_pthread_mutex; + String m_name; + String m_owner; + uint32_t m_value; + bool m_usePthreads; + }; }; @@ -66,13 +67,13 @@ class Ringbuffer { #else Ringbuffer(size_t length, ringbuf_type_t type = RINGBUF_TYPE_NOSPLIT); #endif - ~Ringbuffer(); + ~Ringbuffer(); - void* receive(size_t* size, TickType_t wait = portMAX_DELAY); - void returnItem(void* item); - bool send(void* data, size_t length, TickType_t wait = portMAX_DELAY); + void* receive(size_t* size, TickType_t wait = portMAX_DELAY); + void returnItem(void* item); + bool send(void* data, size_t length, TickType_t wait = portMAX_DELAY); private: - RingbufHandle_t m_handle; + RingbufHandle_t m_handle; }; #endif /* MAIN_FREERTOS_H_ */ diff --git a/libraries/BluetoothSerial/README.md b/libraries/BluetoothSerial/README.md index 4989b3a088c..218c147992e 100644 --- a/libraries/BluetoothSerial/README.md +++ b/libraries/BluetoothSerial/README.md @@ -75,4 +75,4 @@ To use Legacy pairing you will have to use [Arduino as an IDF component](https:/ Please refer to the documentation on how to setup Arduino as an IDF component and when you are done, run `idf.py menuconfig` navigate to `Component Config -> Bluetooth -> Bluedroid -> [ ] Secure Simple Pairing` and disable it. While in the menuconfig you will also need to change the partition scheme `Partition Table -> Partition Table -> (X) Single Factory app (large), no OTA`. After these changes save & quit menuconfig and you are ready to go: `idf.py monitor flash`. -Please note that to use the PIN in smartphones and computers you need to use characters `SerialBT.setPin("1234", 4);` not a number `SerialBT.setPin(1234, 4);` . Numbers CAN be used if the other side uses them too, but phones and computers use characters. \ No newline at end of file +Please note that to use the PIN in smartphones and computers you need to use characters `SerialBT.setPin("1234", 4);` not a number `SerialBT.setPin(1234, 4);` . Numbers CAN be used if the other side uses them too, but phones and computers use characters. diff --git a/libraries/BluetoothSerial/examples/DiscoverConnect/DiscoverConnect.ino b/libraries/BluetoothSerial/examples/DiscoverConnect/DiscoverConnect.ino index 2ebea81b570..e6d9850c399 100644 --- a/libraries/BluetoothSerial/examples/DiscoverConnect/DiscoverConnect.ino +++ b/libraries/BluetoothSerial/examples/DiscoverConnect/DiscoverConnect.ino @@ -1,16 +1,16 @@ /** * Bluetooth Classic Example - * Scan for devices - asyncronously, print device as soon as found + * Scan for devices - asynchronously, print device as soon as found * query devices for SPP - SDP profile * connect to first device offering a SPP connection - * + * * Example python server: * source: https://gist.github.com/ukBaz/217875c83c2535d22a16ba38fc8f2a91 * - * Tested with Raspberry Pi onboard Wifi/BT, USB BT 4.0 dongles, USB BT 1.1 dongles, + * Tested with Raspberry Pi onboard Wifi/BT, USB BT 4.0 dongles, USB BT 1.1 dongles, * 202202: does NOT work with USB BT 2.0 dongles when esp32 arduino lib is compiled with SSP support! * see https://github.com/espressif/esp-idf/issues/8394 - * + * * use ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE in connect() if remote side requests 'RequireAuthentication': dbus.Boolean(True), * use ESP_SPP_SEC_NONE or ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE in connect() if remote side has Authentication: False */ @@ -19,24 +19,24 @@ #include #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) - #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it +#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. +#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip. #endif BluetoothSerial SerialBT; -#define BT_DISCOVER_TIME 10000 -esp_spp_sec_t sec_mask = ESP_SPP_SEC_NONE; // or ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE to request pincode confirmation -esp_spp_role_t role = ESP_SPP_ROLE_SLAVE; // or ESP_SPP_ROLE_MASTER +#define BT_DISCOVER_TIME 10000 +esp_spp_sec_t sec_mask = ESP_SPP_SEC_NONE; // or ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE to request pincode confirmation +esp_spp_role_t role = ESP_SPP_ROLE_SLAVE; // or ESP_SPP_ROLE_MASTER // std::map btDeviceList; void setup() { Serial.begin(115200); - if(! SerialBT.begin("ESP32test", true) ) { + if (!SerialBT.begin("ESP32test", true)) { Serial.println("========== serialBT failed!"); abort(); } @@ -47,34 +47,33 @@ void setup() { Serial.println("Starting discoverAsync..."); BTScanResults* btDeviceList = SerialBT.getScanResults(); // maybe accessing from different threads! if (SerialBT.discoverAsync([](BTAdvertisedDevice* pDevice) { - // BTAdvertisedDeviceSet*set = reinterpret_cast(pDevice); - // btDeviceList[pDevice->getAddress()] = * set; - Serial.printf(">>>>>>>>>>>Found a new device asynchronously: %s\n", pDevice->toString().c_str()); - } ) - ) { + // BTAdvertisedDeviceSet*set = reinterpret_cast(pDevice); + // btDeviceList[pDevice->getAddress()] = * set; + Serial.printf(">>>>>>>>>>>Found a new device asynchronously: %s\n", pDevice->toString().c_str()); + })) { delay(BT_DISCOVER_TIME); Serial.print("Stopping discoverAsync... "); SerialBT.discoverAsyncStop(); Serial.println("discoverAsync stopped"); delay(5000); - if(btDeviceList->getCount() > 0) { + if (btDeviceList->getCount() > 0) { BTAddress addr; - int channel=0; + int channel = 0; Serial.println("Found devices:"); - for (int i=0; i < btDeviceList->getCount(); i++) { - BTAdvertisedDevice *device=btDeviceList->getDevice(i); + for (int i = 0; i < btDeviceList->getCount(); i++) { + BTAdvertisedDevice* device = btDeviceList->getDevice(i); Serial.printf(" ----- %s %s %d\n", device->getAddress().toString().c_str(), device->getName().c_str(), device->getRSSI()); - std::map channels=SerialBT.getChannels(device->getAddress()); + std::map channels = SerialBT.getChannels(device->getAddress()); Serial.printf("scanned for services, found %d\n", channels.size()); - for(auto const &entry : channels) { + for (auto const& entry : channels) { Serial.printf(" channel %d (%s)\n", entry.first, entry.second.c_str()); } - if(channels.size() > 0) { + if (channels.size() > 0) { addr = device->getAddress(); - channel=channels.begin()->first; + channel = channels.begin()->first; } } - if(addr) { + if (addr) { Serial.printf("connecting to %s - %d\n", addr.toString().c_str(), channel); SerialBT.connect(addr, channel, sec_mask, role); } @@ -87,21 +86,21 @@ void setup() { } -String sendData="Hi from esp32!\n"; +String sendData = "Hi from esp32!\n"; void loop() { - if(! SerialBT.isClosed() && SerialBT.connected()) { - if( SerialBT.write((const uint8_t*) sendData.c_str(),sendData.length()) != sendData.length()) { + if (!SerialBT.isClosed() && SerialBT.connected()) { + if (SerialBT.write((const uint8_t*)sendData.c_str(), sendData.length()) != sendData.length()) { Serial.println("tx: error"); } else { - Serial.printf("tx: %s",sendData.c_str()); + Serial.printf("tx: %s", sendData.c_str()); } - if(SerialBT.available()) { + if (SerialBT.available()) { Serial.print("rx: "); - while(SerialBT.available()) { - int c=SerialBT.read(); - if(c >= 0) { - Serial.print((char) c); + while (SerialBT.available()) { + int c = SerialBT.read(); + if (c >= 0) { + Serial.print((char)c); } } Serial.println(); diff --git a/libraries/BluetoothSerial/examples/GetLocalMAC/GetLocalMAC.ino b/libraries/BluetoothSerial/examples/GetLocalMAC/GetLocalMAC.ino index 2930067bf5d..cc55a4af5c1 100644 --- a/libraries/BluetoothSerial/examples/GetLocalMAC/GetLocalMAC.ino +++ b/libraries/BluetoothSerial/examples/GetLocalMAC/GetLocalMAC.ino @@ -6,41 +6,45 @@ 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 +#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. +#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 + 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 + 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 + 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("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(":"); + 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.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 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()); + Serial.print("The mac address using string: "); + Serial.println(mac_str.c_str()); } -void loop(){ - +void loop() { } diff --git a/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino b/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino index c5ac06b992f..53579c73334 100644 --- a/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino +++ b/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino @@ -11,19 +11,19 @@ String device_name = "ESP32-BT-Slave"; // Check if Bluetooth is available #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) - #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it +#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it #endif // Check Serial Port Profile #if !defined(CONFIG_BT_SPP_ENABLED) - #error Serial Port Profile for Bluetooth is not available or not enabled. It is only available for the ESP32 chip. +#error Serial Port Profile for Bluetooth is 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 + SerialBT.begin(device_name); //Bluetooth device name //SerialBT.deleteAllBondedDevices(); // Uncomment this to delete paired devices; Must be called after begin Serial.printf("The device with name \"%s\" is started.\nNow you can pair it with Bluetooth!\n", device_name.c_str()); } diff --git a/libraries/BluetoothSerial/examples/SerialToSerialBTM/SerialToSerialBTM.ino b/libraries/BluetoothSerial/examples/SerialToSerialBTM/SerialToSerialBTM.ino index a4917bfa141..fb3ce1ab396 100644 --- a/libraries/BluetoothSerial/examples/SerialToSerialBTM/SerialToSerialBTM.ino +++ b/libraries/BluetoothSerial/examples/SerialToSerialBTM/SerialToSerialBTM.ino @@ -17,24 +17,24 @@ #include "BluetoothSerial.h" -#define USE_NAME // Comment this to use MAC address instead of a slaveName +#define USE_NAME // Comment this to use MAC address instead of a slaveName // Check if Bluetooth is available #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) - #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it +#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it #endif // Check Serial Port Profile #if !defined(CONFIG_BT_SPP_ENABLED) - #error Serial Port Profile for Bluetooth is not available or not enabled. It is only available for the ESP32 chip. +#error Serial Port Profile for Bluetooth is not available or not enabled. It is only available for the ESP32 chip. #endif BluetoothSerial SerialBT; #ifdef USE_NAME - String slaveName = "ESP32-BT-Slave"; // Change this to reflect the real name of your slave BT device +String slaveName = "ESP32-BT-Slave"; // Change this to reflect the real name of your slave BT device #else - String MACadd = "AA:BB:CC:11:22:33"; // This only for printing - uint8_t address[6] = {0xAA, 0xBB, 0xCC, 0x11, 0x22, 0x33}; // Change this to reflect real MAC address of your slave BT device +String MACadd = "AA:BB:CC:11:22:33"; // This only for printing +uint8_t address[6] = { 0xAA, 0xBB, 0xCC, 0x11, 0x22, 0x33 }; // Change this to reflect real MAC address of your slave BT device #endif String myName = "ESP32-BT-Master"; @@ -47,26 +47,27 @@ void setup() { //SerialBT.deleteAllBondedDevices(); // Uncomment this to delete paired devices; Must be called after begin Serial.printf("The device \"%s\" started in master mode, make sure slave BT device is on!\n", myName.c_str()); - #ifndef USE_NAME - SerialBT.setPin(pin); - Serial.println("Using PIN"); - #endif +#ifndef USE_NAME + SerialBT.setPin(pin); + Serial.println("Using PIN"); +#endif - // connect(address) is fast (up to 10 secs max), connect(slaveName) is slow (up to 30 secs max) as it needs - // to resolve slaveName to address first, but it allows to connect to different devices with the same name. - // Set CoreDebugLevel to Info to view devices Bluetooth address and device names - #ifdef USE_NAME - connected = SerialBT.connect(slaveName); - Serial.printf("Connecting to slave BT device named \"%s\"\n", slaveName.c_str()); - #else - connected = SerialBT.connect(address); - Serial.print("Connecting to slave BT device with MAC "); Serial.println(MACadd); - #endif +// connect(address) is fast (up to 10 secs max), connect(slaveName) is slow (up to 30 secs max) as it needs +// to resolve slaveName to address first, but it allows to connect to different devices with the same name. +// Set CoreDebugLevel to Info to view devices Bluetooth address and device names +#ifdef USE_NAME + connected = SerialBT.connect(slaveName); + Serial.printf("Connecting to slave BT device named \"%s\"\n", slaveName.c_str()); +#else + connected = SerialBT.connect(address); + Serial.print("Connecting to slave BT device with MAC "); + Serial.println(MACadd); +#endif - if(connected) { + if (connected) { Serial.println("Connected Successfully!"); } else { - while(!SerialBT.connected(10000)) { + while (!SerialBT.connected(10000)) { Serial.println("Failed to connect. Make sure remote device is available and in range, then restart app."); } } @@ -76,10 +77,10 @@ void setup() { } // This would reconnect to the slaveName(will use address, if resolved) or address used with connect(slaveName/address). SerialBT.connect(); - if(connected) { + if (connected) { Serial.println("Reconnected Successfully!"); } else { - while(!SerialBT.connected(10000)) { + while (!SerialBT.connected(10000)) { Serial.println("Failed to reconnect. Make sure remote device is available and in range, then restart app."); } } diff --git a/libraries/BluetoothSerial/examples/SerialToSerialBT_Legacy/SerialToSerialBT_Legacy.ino b/libraries/BluetoothSerial/examples/SerialToSerialBT_Legacy/SerialToSerialBT_Legacy.ino index 2343b5ca93d..5f55ad85ad6 100644 --- a/libraries/BluetoothSerial/examples/SerialToSerialBT_Legacy/SerialToSerialBT_Legacy.ino +++ b/libraries/BluetoothSerial/examples/SerialToSerialBT_Legacy/SerialToSerialBT_Legacy.ino @@ -9,27 +9,27 @@ // Check if Bluetooth is available #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) - #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it +#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it #endif // Check Serial Port Profile #if !defined(CONFIG_BT_SPP_ENABLED) - #error Serial Port Profile for Bluetooth is not available or not enabled. It is only available for the ESP32 chip. +#error Serial Port Profile for Bluetooth is not available or not enabled. It is only available for the ESP32 chip. #endif // Check Simple Secure Pairing #if defined(CONFIG_BT_SSP_ENABLED) - #warning Legacy Pairing is disabled (CONFIG_BT_SSP_ENABLED is enabled. Disable it in menuconfig). - void setup(){} - void loop(){} +#warning Legacy Pairing is disabled (CONFIG_BT_SSP_ENABLED is enabled. Disable it in menuconfig). +void setup() {} +void loop() {} #else -const char * deviceName = "ESP32_Legacy_example"; +const char* deviceName = "ESP32_Legacy_example"; BluetoothSerial SerialBT; bool confirmRequestDone = false; -void BTAuthCompleteCallback(boolean success){ - if (success){ +void BTAuthCompleteCallback(boolean success) { + if (success) { confirmRequestDone = true; Serial.println("Pairing success!!"); } else { @@ -37,29 +37,29 @@ void BTAuthCompleteCallback(boolean success){ } } -void serial_response(){ - if (Serial.available()){ +void serial_response() { + if (Serial.available()) { SerialBT.write(Serial.read()); } - if (SerialBT.available()){ + if (SerialBT.available()) { Serial.write(SerialBT.read()); } delay(20); } -void setup(){ +void setup() { Serial.begin(115200); SerialBT.onAuthComplete(BTAuthCompleteCallback); - SerialBT.begin(deviceName); // Initiate Bluetooth device with name in parameter + SerialBT.begin(deviceName); // Initiate Bluetooth device with name in parameter SerialBT.setPin("1234", 4); Serial.printf("The device started with name \"%s\", now you can pair it with Bluetooth!\n", deviceName); } -void loop(){ - if (confirmRequestDone){ +void loop() { + if (confirmRequestDone) { serial_response(); } else { - delay(1); // Feed the watchdog + delay(1); // Feed the watchdog } } #endif diff --git a/libraries/BluetoothSerial/examples/SerialToSerialBT_SSP/SerialToSerialBT_SSP.ino b/libraries/BluetoothSerial/examples/SerialToSerialBT_SSP/SerialToSerialBT_SSP.ino index a39dbf1a064..4855a6b01ae 100644 --- a/libraries/BluetoothSerial/examples/SerialToSerialBT_SSP/SerialToSerialBT_SSP.ino +++ b/libraries/BluetoothSerial/examples/SerialToSerialBT_SSP/SerialToSerialBT_SSP.ino @@ -14,20 +14,20 @@ // Check if Bluetooth is available #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) - #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it +#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it #endif // Check Serial Port Profile #if !defined(CONFIG_BT_SPP_ENABLED) - #error Serial Port Profile for Bluetooth is not available or not enabled. It is only available for the ESP32 chip. +#error Serial Port Profile for Bluetooth is not available or not enabled. It is only available for the ESP32 chip. #endif // Check Simple Secure Pairing #if !defined(CONFIG_BT_SSP_ENABLED) - #error Simple Secure Pairing for Bluetooth is not available or not enabled. +#error Simple Secure Pairing for Bluetooth is not available or not enabled. #endif -const char * deviceName = "ESP32_SSP_example"; +const char* deviceName = "ESP32_SSP_example"; // The following lines defines the method of pairing // When both Input and Output are false only the other device authenticates pairing without any pin. @@ -37,26 +37,25 @@ const char * deviceName = "ESP32_SSP_example"; // otherwise call `confirmReply(false)` to reject the pairing. // When Input is true and Output is false User will be required to input the passkey to the ESP32 device to authenticate. // - This must be implemented by registering callback via onKeyRequest() and in this callback the entered passkey will be responded via respondPasskey(passkey); -const bool INPUT_CAPABILITY = false; // Defines if ESP32 device has input method (Serial terminal, keyboard or similar) -const bool OUTPUT_CAPABILITY = true; // Defines if ESP32 device has output method (Serial terminal, display or similar) +const bool INPUT_CAPABILITY = false; // Defines if ESP32 device has input method (Serial terminal, keyboard or similar) +const bool OUTPUT_CAPABILITY = true; // Defines if ESP32 device has output method (Serial terminal, display or similar) BluetoothSerial SerialBT; bool confirmRequestDone = false; -void BTConfirmRequestCallback(uint32_t numVal){ +void BTConfirmRequestCallback(uint32_t numVal) { confirmRequestDone = false; #ifndef AUTO_PAIR - Serial.printf("The PIN is: %06lu. If it matches number displayed on the other device write \'Y\' or \'y\':\n", numVal); // Note the formatting "%06lu" - PIN can start with zero(s) which would be ignored with simple "%lu" + Serial.printf("The PIN is: %06lu. If it matches number displayed on the other device write \'Y\' or \'y\':\n", numVal); // Note the formatting "%06lu" - PIN can start with zero(s) which would be ignored with simple "%lu" while (!Serial.available()) { - delay(1); // Feed the watchdog + delay(1); // Feed the watchdog // Wait until data is available on the Serial port. } Serial.printf("Oh you sent %d Bytes, lets see...", Serial.available()); int dat = Serial.read(); - if (dat == 'Y' || dat == 'y'){ + if (dat == 'Y' || dat == 'y') { SerialBT.confirmReply(true); - } - else{ + } else { SerialBT.confirmReply(false); } #else @@ -64,17 +63,17 @@ void BTConfirmRequestCallback(uint32_t numVal){ #endif } -void BTKeyRequestCallback(){ - Serial.println("BTKeyRequestCallback"); // debug - char buffer[7] = {0}; // 6 bytes for number, one for termination '0' +void BTKeyRequestCallback() { + Serial.println("BTKeyRequestCallback"); // debug + char buffer[7] = { 0 }; // 6 bytes for number, one for termination '0' while (1) { Serial.print("Enter the passkey displayed on the other device: "); while (!Serial.available()) { - delay(1); // Feed the watchdog + delay(1); // Feed the watchdog // Wait until data is available on the Serial port. } size_t len = Serial.readBytesUntil('\n', buffer, sizeof(buffer) - 1); - buffer[len] = '\0'; // Null-terminate the string. + buffer[len] = '\0'; // Null-terminate the string. try { uint32_t passkey = std::stoi(buffer); Serial.printf("Entered PIN: %lu\n", passkey); @@ -82,12 +81,12 @@ void BTKeyRequestCallback(){ return; } catch (...) { Serial.print("Wrong PIN! Try again."); - } // try - } // while(1) + } // try + } // while(1) } -void BTAuthCompleteCallback(boolean success){ - if (success){ +void BTAuthCompleteCallback(boolean success) { + if (success) { confirmRequestDone = true; Serial.println("Pairing success!!"); } else { @@ -95,40 +94,40 @@ void BTAuthCompleteCallback(boolean success){ } } -void serial_response(){ - if (Serial.available()){ +void serial_response() { + if (Serial.available()) { SerialBT.write(Serial.read()); } - if (SerialBT.available()){ + if (SerialBT.available()) { Serial.write(SerialBT.read()); } delay(20); } -void setup(){ +void setup() { Serial.begin(115200); - SerialBT.enableSSP(INPUT_CAPABILITY, OUTPUT_CAPABILITY); // Must be called before begin + SerialBT.enableSSP(INPUT_CAPABILITY, OUTPUT_CAPABILITY); // Must be called before begin SerialBT.onConfirmRequest(BTConfirmRequestCallback); SerialBT.onKeyRequest(BTKeyRequestCallback); SerialBT.onAuthComplete(BTAuthCompleteCallback); - SerialBT.begin(deviceName); // Initiate Bluetooth device with name in parameter + SerialBT.begin(deviceName); // Initiate Bluetooth device with name in parameter //SerialBT.deleteAllBondedDevices(); // Uncomment this to delete paired devices; Must be called after begin Serial.printf("The device started with name \"%s\", now you can pair it with Bluetooth!\n", deviceName); - if(INPUT_CAPABILITY and OUTPUT_CAPABILITY){ + if (INPUT_CAPABILITY and OUTPUT_CAPABILITY) { Serial.println("Both devices will display randomly generated code and if they match authenticate pairing on both devices"); - }else if(not INPUT_CAPABILITY and not OUTPUT_CAPABILITY){ + } else if (not INPUT_CAPABILITY and not OUTPUT_CAPABILITY) { Serial.println("Authenticate pairing on the other device. No PIN is used"); - }else if(not INPUT_CAPABILITY and OUTPUT_CAPABILITY){ + } else if (not INPUT_CAPABILITY and OUTPUT_CAPABILITY) { Serial.println("Authenticate pairing on the other device. No PIN is used"); - }else if(INPUT_CAPABILITY and not OUTPUT_CAPABILITY){ + } else if (INPUT_CAPABILITY and not OUTPUT_CAPABILITY) { Serial.println("After pairing is initiated you will be required to enter the passkey to the ESP32 device to authenticate\n > The Passkey will displayed on the other device"); } } -void loop(){ - if (confirmRequestDone){ +void loop() { + if (confirmRequestDone) { serial_response(); } else { - delay(1); // Feed the watchdog + delay(1); // Feed the watchdog } } diff --git a/libraries/BluetoothSerial/examples/bt_classic_device_discovery/bt_classic_device_discovery.ino b/libraries/BluetoothSerial/examples/bt_classic_device_discovery/bt_classic_device_discovery.ino index b4ee741924d..453fafb15c5 100644 --- a/libraries/BluetoothSerial/examples/bt_classic_device_discovery/bt_classic_device_discovery.ino +++ b/libraries/BluetoothSerial/examples/bt_classic_device_discovery/bt_classic_device_discovery.ino @@ -1,11 +1,11 @@ #include #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) - #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it +#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. +#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip. #endif BluetoothSerial SerialBT; @@ -24,7 +24,7 @@ void btAdvertisedDeviceFound(BTAdvertisedDevice* pDevice) { void setup() { Serial.begin(115200); - SerialBT.begin("ESP32test"); //Bluetooth device name + SerialBT.begin("ESP32test"); //Bluetooth device name Serial.println("The device started, now you can pair it with bluetooth!"); @@ -40,10 +40,10 @@ void setup() { Serial.println("Error on discoverAsync f.e. not working after a \"connect\""); } } - + if (btScanSync) { Serial.println("Starting synchronous discovery... "); - BTScanResults *pResults = SerialBT.discover(BT_DISCOVER_TIME); + BTScanResults* pResults = SerialBT.discover(BT_DISCOVER_TIME); if (pResults) pResults->dump(&Serial); else diff --git a/libraries/BluetoothSerial/examples/bt_remove_paired_devices/bt_remove_paired_devices.ino b/libraries/BluetoothSerial/examples/bt_remove_paired_devices/bt_remove_paired_devices.ino old mode 100755 new mode 100644 index d6f6786828a..d8124fe1cfe --- a/libraries/BluetoothSerial/examples/bt_remove_paired_devices/bt_remove_paired_devices.ino +++ b/libraries/BluetoothSerial/examples/bt_remove_paired_devices/bt_remove_paired_devices.ino @@ -15,15 +15,15 @@ //#include "esp_bt_device.h" #if !defined(CONFIG_BT_SPP_ENABLED) - #error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip. +#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip. #endif #define REMOVE_BONDED_DEVICES true // <- Set to `false` to view all bonded devices addresses, set to `true` to remove #define PAIR_MAX_DEVICES 20 BluetoothSerial SerialBT; -char *bda2str(const uint8_t* bda, char *str, size_t size){ - if (bda == NULL || str == NULL || size < 18){ +char *bda2str(const uint8_t *bda, char *str, size_t size) { + if (bda == NULL || str == NULL || size < 18) { return NULL; } sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x", @@ -31,7 +31,7 @@ char *bda2str(const uint8_t* bda, char *str, size_t size){ return str; } -void setup(){ +void setup() { char bda_str[18]; uint8_t pairedDeviceBtAddr[PAIR_MAX_DEVICES][6]; Serial.begin(115200); @@ -41,34 +41,34 @@ void setup(){ // SerialBT.deleteAllBondedDevices(); // If you want just delete all, this is the way // Get the numbers of bonded/paired devices in the BT module int count = SerialBT.getNumberOfBondedDevices(); - if(!count){ + if (!count) { Serial.println("No bonded devices found."); } else { Serial.printf("Bonded device count: %d\n", count); - if(PAIR_MAX_DEVICES < count){ + if (PAIR_MAX_DEVICES < count) { count = PAIR_MAX_DEVICES; Serial.printf("Reset %d bonded devices\n", count); } count = SerialBT.getBondedDevices(count, pairedDeviceBtAddr); char rmt_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1]; - if(count > 0){ - for(int i = 0; i < count; i++){ + if (count > 0) { + for (int i = 0; i < count; i++) { SerialBT.requestRemoteName(pairedDeviceBtAddr[i]); - while(!SerialBT.readRemoteName(rmt_name)){ - delay(1); // Wait for response with the device name + while (!SerialBT.readRemoteName(rmt_name)) { + delay(1); // Wait for response with the device name } Serial.printf("Found bonded device #%d BDA:%s; Name:\"%s\"\n", i, bda2str(pairedDeviceBtAddr[i], bda_str, 18), rmt_name); - SerialBT.invalidateRemoteName(); // Allows waiting for next reading - if(REMOVE_BONDED_DEVICES){ - if(SerialBT.deleteBondedDevice(pairedDeviceBtAddr[i])){ + SerialBT.invalidateRemoteName(); // Allows waiting for next reading + if (REMOVE_BONDED_DEVICES) { + if (SerialBT.deleteBondedDevice(pairedDeviceBtAddr[i])) { Serial.printf("Removed bonded device # %d\n", i); } else { Serial.printf("Failed to remove bonded device # %d", i); - } // if(ESP_OK == tError) - } // if(REMOVE_BONDED_DEVICES) - } // for(int i = 0; i < count; i++) - } // if(ESP_OK == tError) - } // if(!count) + } // if(ESP_OK == tError) + } // if(REMOVE_BONDED_DEVICES) + } // for(int i = 0; i < count; i++) + } // if(ESP_OK == tError) + } // if(!count) } void loop() {} diff --git a/libraries/BluetoothSerial/src/BTAddress.cpp b/libraries/BluetoothSerial/src/BTAddress.cpp index 2cde9edf4e8..8a469ea7dd5 100644 --- a/libraries/BluetoothSerial/src/BTAddress.cpp +++ b/libraries/BluetoothSerial/src/BTAddress.cpp @@ -26,12 +26,12 @@ * @param [in] address The native representation. */ BTAddress::BTAddress(esp_bd_addr_t address) { - memcpy(m_address, address, ESP_BD_ADDR_LEN); -} // BTAddress + memcpy(m_address, address, ESP_BD_ADDR_LEN); +} // BTAddress BTAddress::BTAddress() { - bzero(m_address, ESP_BD_ADDR_LEN); -} // BTAddress + bzero(m_address, ESP_BD_ADDR_LEN); +} // BTAddress /** * @brief Create an address from a hex string @@ -45,17 +45,17 @@ BTAddress::BTAddress() { * @param [in] stringAddress The hex representation of the address. */ BTAddress::BTAddress(String stringAddress) { - if (stringAddress.length() != 17) return; + if (stringAddress.length() != 17) return; - int data[6]; - sscanf(stringAddress.c_str(), "%x:%x:%x:%x:%x:%x", &data[0], &data[1], &data[2], &data[3], &data[4], &data[5]); - m_address[0] = (uint8_t) data[0]; - m_address[1] = (uint8_t) data[1]; - m_address[2] = (uint8_t) data[2]; - m_address[3] = (uint8_t) data[3]; - m_address[4] = (uint8_t) data[4]; - m_address[5] = (uint8_t) data[5]; -} // BTAddress + int data[6]; + sscanf(stringAddress.c_str(), "%x:%x:%x:%x:%x:%x", &data[0], &data[1], &data[2], &data[3], &data[4], &data[5]); + m_address[0] = (uint8_t)data[0]; + m_address[1] = (uint8_t)data[1]; + m_address[2] = (uint8_t)data[2]; + m_address[3] = (uint8_t)data[3]; + m_address[4] = (uint8_t)data[4]; + m_address[5] = (uint8_t)data[5]; +} // BTAddress /** @@ -64,24 +64,24 @@ BTAddress::BTAddress(String stringAddress) { * @return True if the addresses are equal. */ bool BTAddress::equals(BTAddress otherAddress) { - return memcmp(otherAddress.getNative(), m_address, 6) == 0; -} // equals + return memcmp(otherAddress.getNative(), m_address, 6) == 0; +} // equals -BTAddress::operator bool () const { - for(int i = 0; i < ESP_BD_ADDR_LEN; i++){ - if(this->m_address[i]) - return true; - } - return false; -} // operator () +BTAddress::operator bool() const { + for (int i = 0; i < ESP_BD_ADDR_LEN; i++) { + if (this->m_address[i]) + return true; + } + return false; +} // operator () /** * @brief Return the native representation of the address. * @return The native representation of the address. */ esp_bd_addr_t *BTAddress::getNative() const { - return const_cast(&m_address); -} // getNative + return const_cast(&m_address); +} // getNative /** @@ -98,15 +98,15 @@ esp_bd_addr_t *BTAddress::getNative() const { * @return The string representation of the address. */ String BTAddress::toString(bool capital) const { - auto size = 18; - char *res = (char*)malloc(size); - 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 + auto size = 18; + char *res = (char *)malloc(size); + 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 #endif diff --git a/libraries/BluetoothSerial/src/BTAddress.h b/libraries/BluetoothSerial/src/BTAddress.h index a173a296fe0..2b5fce8d606 100644 --- a/libraries/BluetoothSerial/src/BTAddress.h +++ b/libraries/BluetoothSerial/src/BTAddress.h @@ -11,7 +11,7 @@ #define COMPONENTS_CPP_UTILS_BTADDRESS_H_ #include "sdkconfig.h" #if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BLUEDROID_ENABLED) -#include // ESP32 BT +#include // ESP32 BT #include @@ -22,17 +22,17 @@ */ class BTAddress { public: - BTAddress(); - BTAddress(esp_bd_addr_t address); - BTAddress(String stringAddress); - bool equals(BTAddress otherAddress); - operator bool () const; + BTAddress(); + BTAddress(esp_bd_addr_t address); + BTAddress(String stringAddress); + bool equals(BTAddress otherAddress); + operator bool() const; - esp_bd_addr_t* getNative() const; - String toString(bool capital = false) const; + esp_bd_addr_t* getNative() const; + String toString(bool capital = false) const; private: - esp_bd_addr_t m_address; + esp_bd_addr_t m_address; }; #endif /* CONFIG_BT_ENABLED */ diff --git a/libraries/BluetoothSerial/src/BTAdvertisedDevice.h b/libraries/BluetoothSerial/src/BTAdvertisedDevice.h index 53e74338dfa..5e223f6558f 100644 --- a/libraries/BluetoothSerial/src/BTAdvertisedDevice.h +++ b/libraries/BluetoothSerial/src/BTAdvertisedDevice.h @@ -13,53 +13,53 @@ class BTAdvertisedDevice { public: - virtual ~BTAdvertisedDevice() = default; + virtual ~BTAdvertisedDevice() = default; - virtual BTAddress getAddress() = 0; - virtual uint32_t getCOD() const = 0; - virtual std::string getName() const = 0; - virtual int8_t getRSSI() const = 0; + virtual BTAddress getAddress() = 0; + virtual uint32_t getCOD() const = 0; + virtual std::string getName() const = 0; + virtual int8_t getRSSI() const = 0; - virtual bool haveCOD() const = 0; - virtual bool haveName() const = 0; - virtual bool haveRSSI() const = 0; + virtual bool haveCOD() const = 0; + virtual bool haveName() const = 0; + virtual bool haveRSSI() const = 0; - virtual std::string toString() = 0; + virtual std::string toString() = 0; }; class BTAdvertisedDeviceSet : public virtual BTAdvertisedDevice { public: - BTAdvertisedDeviceSet(); - //~BTAdvertisedDeviceSet() = default; - + BTAdvertisedDeviceSet(); + //~BTAdvertisedDeviceSet() = default; - BTAddress getAddress(); - uint32_t getCOD() const; - std::string getName() const; - int8_t getRSSI() const; + BTAddress getAddress(); + uint32_t getCOD() const; + std::string getName() const; + int8_t getRSSI() const; - bool haveCOD() const; - bool haveName() const; - bool haveRSSI() const; - std::string toString(); + bool haveCOD() const; + bool haveName() const; + bool haveRSSI() const; - void setAddress(BTAddress address); - void setCOD(uint32_t cod); - void setName(std::string name); - void setRSSI(int8_t rssi); + std::string toString(); - bool m_haveCOD; - bool m_haveName; - bool m_haveRSSI; + void setAddress(BTAddress address); + void setCOD(uint32_t cod); + void setName(std::string name); + void setRSSI(int8_t rssi); + bool m_haveCOD; + bool m_haveName; + bool m_haveRSSI; - BTAddress m_address = BTAddress((uint8_t*)"\0\0\0\0\0\0"); - uint32_t m_cod; - std::string m_name; - int8_t m_rssi; + + BTAddress m_address = BTAddress((uint8_t*)"\0\0\0\0\0\0"); + uint32_t m_cod; + std::string m_name; + int8_t m_rssi; }; #endif diff --git a/libraries/BluetoothSerial/src/BTAdvertisedDeviceSet.cpp b/libraries/BluetoothSerial/src/BTAdvertisedDeviceSet.cpp index fecc5f7cf66..f780727a942 100644 --- a/libraries/BluetoothSerial/src/BTAdvertisedDeviceSet.cpp +++ b/libraries/BluetoothSerial/src/BTAdvertisedDeviceSet.cpp @@ -15,64 +15,78 @@ BTAdvertisedDeviceSet::BTAdvertisedDeviceSet() { - m_cod = 0; - m_name = ""; - m_rssi = 0; + m_cod = 0; + m_name = ""; + m_rssi = 0; - m_haveCOD = false; - m_haveName = false; - m_haveRSSI = false; -} // BTAdvertisedDeviceSet + m_haveCOD = false; + m_haveName = false; + m_haveRSSI = false; +} // BTAdvertisedDeviceSet -BTAddress BTAdvertisedDeviceSet::getAddress() { return m_address; } -uint32_t BTAdvertisedDeviceSet::getCOD() const { return m_cod; } -std::string BTAdvertisedDeviceSet::getName() const { return m_name; } -int8_t BTAdvertisedDeviceSet::getRSSI() const { return m_rssi; } +BTAddress BTAdvertisedDeviceSet::getAddress() { + return m_address; +} +uint32_t BTAdvertisedDeviceSet::getCOD() const { + return m_cod; +} +std::string BTAdvertisedDeviceSet::getName() const { + return m_name; +} +int8_t BTAdvertisedDeviceSet::getRSSI() const { + return m_rssi; +} -bool BTAdvertisedDeviceSet::haveCOD() const { return m_haveCOD; } -bool BTAdvertisedDeviceSet::haveName() const { return m_haveName; } -bool BTAdvertisedDeviceSet::haveRSSI() const { return m_haveRSSI; } +bool BTAdvertisedDeviceSet::haveCOD() const { + return m_haveCOD; +} +bool BTAdvertisedDeviceSet::haveName() const { + return m_haveName; +} +bool BTAdvertisedDeviceSet::haveRSSI() const { + return m_haveRSSI; +} /** * @brief Create a string representation of this device. * @return A string representation of this device. */ std::string BTAdvertisedDeviceSet::toString() { - std::string res = "Name: " + getName() + ", Address: " + std::string(getAddress().toString().c_str(), getAddress().toString().length()); - if (haveCOD()) { - char val[7]; //6 hex digits + null - snprintf(val, sizeof(val), "%06lx", getCOD() & 0xFFFFFF); - res += ", cod: 0x"; - res += val; - } - if (haveRSSI()) { - char val[6]; - snprintf(val, sizeof(val), "%d", (int8_t)getRSSI()); - res += ", rssi: "; - res += val; - } - return res; -} // toString + std::string res = "Name: " + getName() + ", Address: " + std::string(getAddress().toString().c_str(), getAddress().toString().length()); + if (haveCOD()) { + char val[7]; //6 hex digits + null + snprintf(val, sizeof(val), "%06lx", getCOD() & 0xFFFFFF); + res += ", cod: 0x"; + res += val; + } + if (haveRSSI()) { + char val[6]; + snprintf(val, sizeof(val), "%d", (int8_t)getRSSI()); + res += ", rssi: "; + res += val; + } + return res; +} // toString void BTAdvertisedDeviceSet::setAddress(BTAddress address) { - m_address = address; + m_address = address; } void BTAdvertisedDeviceSet::setCOD(uint32_t cod) { - m_cod = cod; - m_haveCOD = true; + m_cod = cod; + m_haveCOD = true; } void BTAdvertisedDeviceSet::setName(std::string name) { - m_name = name; - m_haveName = true; + m_name = name; + m_haveName = true; } void BTAdvertisedDeviceSet::setRSSI(int8_t rssi) { - m_rssi = rssi; - m_haveRSSI = true; + m_rssi = rssi; + m_haveRSSI = true; } #endif /* CONFIG_BT_ENABLED */ diff --git a/libraries/BluetoothSerial/src/BTScan.h b/libraries/BluetoothSerial/src/BTScan.h index c8630750fd3..f03e3d35caf 100644 --- a/libraries/BluetoothSerial/src/BTScan.h +++ b/libraries/BluetoothSerial/src/BTScan.h @@ -20,23 +20,23 @@ class BTAdvertisedDeviceSet; class BTScanResults { public: - virtual ~BTScanResults() = default; + virtual ~BTScanResults() = default; - virtual void dump(Print *print = nullptr) = 0; - virtual int getCount() = 0; - virtual BTAdvertisedDevice* getDevice(int i) = 0; + virtual void dump(Print* print = nullptr) = 0; + virtual int getCount() = 0; + virtual BTAdvertisedDevice* getDevice(int i) = 0; }; class BTScanResultsSet : public BTScanResults { public: - void dump(Print *print = nullptr); - int getCount(); - BTAdvertisedDevice* getDevice(int i); + void dump(Print* print = nullptr); + int getCount(); + BTAdvertisedDevice* getDevice(int i); - bool add(BTAdvertisedDeviceSet advertisedDevice, bool unique = true); - void clear(); + bool add(BTAdvertisedDeviceSet advertisedDevice, bool unique = true); + void clear(); - std::map m_vectorAdvertisedDevices; + std::map m_vectorAdvertisedDevices; }; #endif diff --git a/libraries/BluetoothSerial/src/BTScanResultsSet.cpp b/libraries/BluetoothSerial/src/BTScanResultsSet.cpp index e7745e431ce..65f07936cb0 100644 --- a/libraries/BluetoothSerial/src/BTScanResultsSet.cpp +++ b/libraries/BluetoothSerial/src/BTScanResultsSet.cpp @@ -22,30 +22,30 @@ class BTAdvertisedDevice; /** * @brief Dump the scan results to the log. */ -void BTScanResultsSet::dump(Print *print) { - int cnt = getCount(); - if (print == nullptr) { - log_v(">> Dump scan results : %d", cnt); - for (int i=0; i < cnt; i++) { - BTAdvertisedDevice* dev = getDevice(i); - if (dev) - log_d("- %d: %s\n", i+1, dev->toString().c_str()); - else - log_d("- %d is null\n", i+1); - } - log_v("-- dump finished --"); - } else { - print->printf(">> Dump scan results: %d\n", cnt); - for (int i=0; i < cnt; i++) { - BTAdvertisedDevice* dev = getDevice(i); - if (dev) - print->printf("- %d: %s\n", i+1, dev->toString().c_str()); - else - print->printf("- %d is null\n", i+1); - } - print->println("-- Dump finished --"); - } -} // dump +void BTScanResultsSet::dump(Print* print) { + int cnt = getCount(); + if (print == nullptr) { + log_v(">> Dump scan results : %d", cnt); + for (int i = 0; i < cnt; i++) { + BTAdvertisedDevice* dev = getDevice(i); + if (dev) + log_d("- %d: %s\n", i + 1, dev->toString().c_str()); + else + log_d("- %d is null\n", i + 1); + } + log_v("-- dump finished --"); + } else { + print->printf(">> Dump scan results: %d\n", cnt); + for (int i = 0; i < cnt; i++) { + BTAdvertisedDevice* dev = getDevice(i); + if (dev) + print->printf("- %d: %s\n", i + 1, dev->toString().c_str()); + else + print->printf("- %d is null\n", i + 1); + } + print->println("-- Dump finished --"); + } +} // dump /** @@ -53,8 +53,8 @@ void BTScanResultsSet::dump(Print *print) { * @return The number of devices found in the last scan. */ int BTScanResultsSet::getCount() { - return m_vectorAdvertisedDevices.size(); -} // getCount + return m_vectorAdvertisedDevices.size(); +} // getCount /** @@ -64,32 +64,32 @@ int BTScanResultsSet::getCount() { * @return The device at the specified index. */ BTAdvertisedDevice* BTScanResultsSet::getDevice(int i) { - if (i < 0) - return nullptr; + if (i < 0) + return nullptr; - int x = 0; - BTAdvertisedDeviceSet* pDev = &m_vectorAdvertisedDevices.begin()->second; - for (auto it = m_vectorAdvertisedDevices.begin(); it != m_vectorAdvertisedDevices.end(); it++) { - pDev = &it->second; - if (x==i) break; - x++; - } - return x==i ? pDev : nullptr; + int x = 0; + BTAdvertisedDeviceSet* pDev = &m_vectorAdvertisedDevices.begin()->second; + for (auto it = m_vectorAdvertisedDevices.begin(); it != m_vectorAdvertisedDevices.end(); it++) { + pDev = &it->second; + if (x == i) break; + x++; + } + return x == i ? pDev : nullptr; } void BTScanResultsSet::clear() { - //for(auto _dev : m_vectorAdvertisedDevices) - // delete _dev.second; - m_vectorAdvertisedDevices.clear(); + //for(auto _dev : m_vectorAdvertisedDevices) + // delete _dev.second; + m_vectorAdvertisedDevices.clear(); } bool BTScanResultsSet::add(BTAdvertisedDeviceSet advertisedDevice, bool unique) { - 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(key, advertisedDevice)); - return true; - } else - return false; + 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(key, advertisedDevice)); + return true; + } else + return false; } #endif diff --git a/libraries/BluetoothSerial/src/BluetoothSerial.cpp b/libraries/BluetoothSerial/src/BluetoothSerial.cpp index eb6b9043d58..dbe4d6c138c 100644 --- a/libraries/BluetoothSerial/src/BluetoothSerial.cpp +++ b/libraries/BluetoothSerial/src/BluetoothSerial.cpp @@ -24,7 +24,7 @@ #if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BLUEDROID_ENABLED) #ifdef ARDUINO_ARCH_ESP32 - #include "esp32-hal-log.h" +#include "esp32-hal-log.h" #endif #include "BluetoothSerial.h" @@ -39,7 +39,7 @@ #include "esp32-hal-log.h" -const char * _spp_server_name = "ESP32SPP"; +const char *_spp_server_name = "ESP32SPP"; #define RX_QUEUE_SIZE 512 #define TX_QUEUE_SIZE 32 @@ -62,7 +62,7 @@ static ConfirmRequestCb confirm_request_callback = NULL; static KeyRequestCb key_request_callback = NULL; static AuthCompleteCb auth_complete_callback = NULL; static bool _rmt_name_valid = false; -static uint8_t _rmt_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1] = {0}; +static uint8_t _rmt_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1] = { 0 }; #define INQ_LEN 0x10 #define INQ_NUM_RSPS 20 @@ -73,895 +73,870 @@ static char _remote_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1]; static bool _isRemoteAddressSet; static bool _isMaster; #ifdef CONFIG_BT_SSP_ENABLED - static bool _enableSSP; - static bool _IO_CAP_INPUT; - static bool _IO_CAP_OUTPUT; +static bool _enableSSP; +static bool _IO_CAP_INPUT; +static bool _IO_CAP_OUTPUT; #endif -esp_bt_pin_code_t _pin_code = {0}; -uint8_t _pin_code_len = 0; // Number of valid Bytes in the esp_bt_pin_code_t array +esp_bt_pin_code_t _pin_code = { 0 }; +uint8_t _pin_code_len = 0; // Number of valid Bytes in the esp_bt_pin_code_t array static esp_spp_sec_t _sec_mask; static esp_spp_role_t _role; // start connect on ESP_SPP_DISCOVERY_COMP_EVT or save entry for getChannels static bool _doConnect; -static std::map sdpRecords; +static std::map sdpRecords; static BTScanResultsSet scanResults; static BTAdvertisedDeviceCb advertisedDeviceCb = nullptr; // _spp_event_group -#define SPP_RUNNING 0x01 -#define SPP_CONNECTED 0x02 -#define SPP_CONGESTED 0x04 +#define SPP_RUNNING 0x01 +#define SPP_CONNECTED 0x02 +#define SPP_CONGESTED 0x04 // true until OPEN successful, changes to false on CLOSE #define SPP_DISCONNECTED 0x08 // true until connect(), changes to true on CLOSE -#define SPP_CLOSED 0x10 +#define SPP_CLOSED 0x10 // _bt_event_group -#define BT_DISCOVERY_RUNNING 0x01 -#define BT_DISCOVERY_COMPLETED 0x02 +#define BT_DISCOVERY_RUNNING 0x01 +#define BT_DISCOVERY_COMPLETED 0x02 -#define BT_SDP_RUNNING 0x04 -#define BT_SDP_COMPLETED 0x08 +#define BT_SDP_RUNNING 0x04 +#define BT_SDP_COMPLETED 0x08 typedef struct { - size_t len; - uint8_t data[]; + size_t len; + uint8_t data[]; } spp_packet_t; #if (ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO) -static char *bda2str(esp_bd_addr_t bda, char *str, size_t size) -{ +static char *bda2str(esp_bd_addr_t bda, char *str, size_t size) { if (bda == NULL || str == NULL || size < 18) { return NULL; } uint8_t *p = bda; snprintf(str, size, "%02x:%02x:%02x:%02x:%02x:%02x", - p[0], p[1], p[2], p[3], p[4], p[5]); + p[0], p[1], p[2], p[3], p[4], p[5]); return str; } #endif -static bool get_name_from_eir(uint8_t *eir, char *bdname, uint8_t *bdname_len) -{ - if (!eir || !bdname || !bdname_len) { - return false; - } +static bool get_name_from_eir(uint8_t *eir, char *bdname, uint8_t *bdname_len) { + if (!eir || !bdname || !bdname_len) { + return false; + } - uint8_t *rmt_bdname, rmt_bdname_len; - *bdname = *bdname_len = rmt_bdname_len = 0; + uint8_t *rmt_bdname, rmt_bdname_len; + *bdname = *bdname_len = rmt_bdname_len = 0; - rmt_bdname = esp_bt_gap_resolve_eir_data(eir, ESP_BT_EIR_TYPE_CMPL_LOCAL_NAME, &rmt_bdname_len); - if (!rmt_bdname) { - rmt_bdname = esp_bt_gap_resolve_eir_data(eir, ESP_BT_EIR_TYPE_SHORT_LOCAL_NAME, &rmt_bdname_len); - } - if (rmt_bdname) { - rmt_bdname_len = rmt_bdname_len > ESP_BT_GAP_MAX_BDNAME_LEN ? ESP_BT_GAP_MAX_BDNAME_LEN : rmt_bdname_len; - memcpy(bdname, rmt_bdname, rmt_bdname_len); - bdname[rmt_bdname_len] = 0; - *bdname_len = rmt_bdname_len; - return true; - } - return false; + rmt_bdname = esp_bt_gap_resolve_eir_data(eir, ESP_BT_EIR_TYPE_CMPL_LOCAL_NAME, &rmt_bdname_len); + if (!rmt_bdname) { + rmt_bdname = esp_bt_gap_resolve_eir_data(eir, ESP_BT_EIR_TYPE_SHORT_LOCAL_NAME, &rmt_bdname_len); + } + if (rmt_bdname) { + rmt_bdname_len = rmt_bdname_len > ESP_BT_GAP_MAX_BDNAME_LEN ? ESP_BT_GAP_MAX_BDNAME_LEN : rmt_bdname_len; + memcpy(bdname, rmt_bdname, rmt_bdname_len); + bdname[rmt_bdname_len] = 0; + *bdname_len = rmt_bdname_len; + return true; + } + return false; } -static esp_err_t _spp_queue_packet(uint8_t *data, size_t len){ - if(!data || !len){ - log_w("No data provided"); - return ESP_OK; - } - spp_packet_t * packet = (spp_packet_t*)malloc(sizeof(spp_packet_t) + len); - if(!packet){ - log_e("SPP TX Packet Malloc Failed!"); - return ESP_FAIL; - } - packet->len = len; - memcpy(packet->data, data, len); - if (!_spp_tx_queue || xQueueSend(_spp_tx_queue, &packet, SPP_TX_QUEUE_TIMEOUT) != pdPASS) { - log_e("SPP TX Queue Send Failed!"); - free(packet); - return ESP_FAIL; - } +static esp_err_t _spp_queue_packet(uint8_t *data, size_t len) { + if (!data || !len) { + log_w("No data provided"); return ESP_OK; + } + spp_packet_t *packet = (spp_packet_t *)malloc(sizeof(spp_packet_t) + len); + if (!packet) { + log_e("SPP TX Packet Malloc Failed!"); + return ESP_FAIL; + } + packet->len = len; + memcpy(packet->data, data, len); + if (!_spp_tx_queue || xQueueSend(_spp_tx_queue, &packet, SPP_TX_QUEUE_TIMEOUT) != pdPASS) { + log_e("SPP TX Queue Send Failed!"); + free(packet); + return ESP_FAIL; + } + return ESP_OK; } const uint16_t SPP_TX_MAX = 330; static uint8_t _spp_tx_buffer[SPP_TX_MAX]; static uint16_t _spp_tx_buffer_len = 0; -static bool _spp_send_buffer(){ - if((xEventGroupWaitBits(_spp_event_group, SPP_CONGESTED, pdFALSE, pdTRUE, SPP_CONGESTED_TIMEOUT) & SPP_CONGESTED) != 0){ - if(!_spp_client){ - log_v("SPP Client Gone!"); - return false; - } - log_v("SPP Write %u", _spp_tx_buffer_len); - esp_err_t err = esp_spp_write(_spp_client, _spp_tx_buffer_len, _spp_tx_buffer); - if(err != ESP_OK){ - log_e("SPP Write Failed! [0x%X]", err); - return false; - } - _spp_tx_buffer_len = 0; - if(xSemaphoreTake(_spp_tx_done, SPP_TX_DONE_TIMEOUT) != pdTRUE){ - log_e("SPP Ack Failed!"); - return false; - } - return true; +static bool _spp_send_buffer() { + if ((xEventGroupWaitBits(_spp_event_group, SPP_CONGESTED, pdFALSE, pdTRUE, SPP_CONGESTED_TIMEOUT) & SPP_CONGESTED) != 0) { + if (!_spp_client) { + log_v("SPP Client Gone!"); + return false; } - log_e("SPP Write Congested!"); - return false; + log_v("SPP Write %u", _spp_tx_buffer_len); + esp_err_t err = esp_spp_write(_spp_client, _spp_tx_buffer_len, _spp_tx_buffer); + if (err != ESP_OK) { + log_e("SPP Write Failed! [0x%X]", err); + return false; + } + _spp_tx_buffer_len = 0; + if (xSemaphoreTake(_spp_tx_done, SPP_TX_DONE_TIMEOUT) != pdTRUE) { + log_e("SPP Ack Failed!"); + return false; + } + return true; + } + log_e("SPP Write Congested!"); + return false; } -static void _spp_tx_task(void * arg){ - spp_packet_t *packet = NULL; - size_t len = 0, to_send = 0; - uint8_t * data = NULL; - for (;;) { - if(_spp_tx_queue && xQueueReceive(_spp_tx_queue, &packet, portMAX_DELAY) == pdTRUE && packet){ - if(packet->len <= (SPP_TX_MAX - _spp_tx_buffer_len)){ - memcpy(_spp_tx_buffer+_spp_tx_buffer_len, packet->data, packet->len); - _spp_tx_buffer_len+=packet->len; - free(packet); - packet = NULL; - if(SPP_TX_MAX == _spp_tx_buffer_len || uxQueueMessagesWaiting(_spp_tx_queue) == 0){ - _spp_send_buffer(); - } - } else { - len = packet->len; - data = packet->data; - to_send = SPP_TX_MAX - _spp_tx_buffer_len; - memcpy(_spp_tx_buffer+_spp_tx_buffer_len, data, to_send); - _spp_tx_buffer_len = SPP_TX_MAX; - data += to_send; - len -= to_send; - if(!_spp_send_buffer()){ - len = 0; - } - while(len >= SPP_TX_MAX){ - memcpy(_spp_tx_buffer, data, SPP_TX_MAX); - _spp_tx_buffer_len = SPP_TX_MAX; - data += SPP_TX_MAX; - len -= SPP_TX_MAX; - if(!_spp_send_buffer()){ - len = 0; - break; - } - } - if(len){ - memcpy(_spp_tx_buffer, data, len); - _spp_tx_buffer_len += len; - if(uxQueueMessagesWaiting(_spp_tx_queue) == 0){ - _spp_send_buffer(); - } - } - free(packet); - packet = NULL; - } - } else { - log_e("Something went horribly wrong"); +static void _spp_tx_task(void *arg) { + spp_packet_t *packet = NULL; + size_t len = 0, to_send = 0; + uint8_t *data = NULL; + for (;;) { + if (_spp_tx_queue && xQueueReceive(_spp_tx_queue, &packet, portMAX_DELAY) == pdTRUE && packet) { + if (packet->len <= (SPP_TX_MAX - _spp_tx_buffer_len)) { + memcpy(_spp_tx_buffer + _spp_tx_buffer_len, packet->data, packet->len); + _spp_tx_buffer_len += packet->len; + free(packet); + packet = NULL; + if (SPP_TX_MAX == _spp_tx_buffer_len || uxQueueMessagesWaiting(_spp_tx_queue) == 0) { + _spp_send_buffer(); + } + } else { + len = packet->len; + data = packet->data; + to_send = SPP_TX_MAX - _spp_tx_buffer_len; + memcpy(_spp_tx_buffer + _spp_tx_buffer_len, data, to_send); + _spp_tx_buffer_len = SPP_TX_MAX; + data += to_send; + len -= to_send; + if (!_spp_send_buffer()) { + len = 0; + } + while (len >= SPP_TX_MAX) { + memcpy(_spp_tx_buffer, data, SPP_TX_MAX); + _spp_tx_buffer_len = SPP_TX_MAX; + data += SPP_TX_MAX; + len -= SPP_TX_MAX; + if (!_spp_send_buffer()) { + len = 0; + break; + } + } + if (len) { + memcpy(_spp_tx_buffer, data, len); + _spp_tx_buffer_len += len; + if (uxQueueMessagesWaiting(_spp_tx_queue) == 0) { + _spp_send_buffer(); + } } + free(packet); + packet = NULL; + } + } else { + log_e("Something went horribly wrong"); } - vTaskDelete(NULL); - _spp_task_handle = NULL; + } + vTaskDelete(NULL); + _spp_task_handle = NULL; } -static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) -{ - switch (event) - { - case ESP_SPP_INIT_EVT: // Enum 0 - When SPP is initialized - log_i("ESP_SPP_INIT_EVT"); +static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) { + switch (event) { + case ESP_SPP_INIT_EVT: // Enum 0 - When SPP is initialized + log_i("ESP_SPP_INIT_EVT"); #ifdef ESP_IDF_VERSION_MAJOR - esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); + esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); #else - esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); + esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); #endif - log_i("ESP_SPP_INIT_EVT: %s: start", _isMaster ? "master" : "slave"); - esp_spp_start_srv(ESP_SPP_SEC_NONE, _isMaster ? ESP_SPP_ROLE_MASTER : ESP_SPP_ROLE_SLAVE, 0, _spp_server_name); - xEventGroupSetBits(_spp_event_group, SPP_RUNNING); - break; - - case ESP_SPP_UNINIT_EVT: // Enum 1 - When SPP is deinitialized - log_i("ESP_SPP_UNINIT_EVT: SPP is deinitialized"); - break; - - case ESP_SPP_DISCOVERY_COMP_EVT: // Enum 8 - When SDP discovery complete - log_i("ESP_SPP_DISCOVERY_COMP_EVT num=%d", param->disc_comp.scn_num); - if (param->disc_comp.status == ESP_SPP_SUCCESS) { - for(int i=0; i < param->disc_comp.scn_num; i++) { - log_d("ESP_SPP_DISCOVERY_COMP_EVT: spp [%d] channel: %d service name:%s", i, param->disc_comp.scn[i], param->disc_comp.service_name[0]); - } - if(_doConnect) { - if(param->disc_comp.scn_num > 0) { + log_i("ESP_SPP_INIT_EVT: %s: start", _isMaster ? "master" : "slave"); + esp_spp_start_srv(ESP_SPP_SEC_NONE, _isMaster ? ESP_SPP_ROLE_MASTER : ESP_SPP_ROLE_SLAVE, 0, _spp_server_name); + xEventGroupSetBits(_spp_event_group, SPP_RUNNING); + break; + + case ESP_SPP_UNINIT_EVT: // Enum 1 - When SPP is deinitialized + log_i("ESP_SPP_UNINIT_EVT: SPP is deinitialized"); + break; + + case ESP_SPP_DISCOVERY_COMP_EVT: // Enum 8 - When SDP discovery complete + log_i("ESP_SPP_DISCOVERY_COMP_EVT num=%d", param->disc_comp.scn_num); + if (param->disc_comp.status == ESP_SPP_SUCCESS) { + for (int i = 0; i < param->disc_comp.scn_num; i++) { + log_d("ESP_SPP_DISCOVERY_COMP_EVT: spp [%d] channel: %d service name:%s", i, param->disc_comp.scn[i], param->disc_comp.service_name[0]); + } + if (_doConnect) { + if (param->disc_comp.scn_num > 0) { #if (ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO) - char bda_str[18]; - log_i("ESP_SPP_DISCOVERY_COMP_EVT: spp connect to remote %s channel %d", - bda2str(_peer_bd_addr, bda_str, sizeof(bda_str)), - param->disc_comp.scn[0]); + char bda_str[18]; + log_i("ESP_SPP_DISCOVERY_COMP_EVT: spp connect to remote %s channel %d", + bda2str(_peer_bd_addr, bda_str, sizeof(bda_str)), + param->disc_comp.scn[0]); #endif - xEventGroupClearBits(_spp_event_group, SPP_CLOSED); - if(esp_spp_connect(_sec_mask, _role, param->disc_comp.scn[0], _peer_bd_addr) != ESP_OK) { - log_e("ESP_SPP_DISCOVERY_COMP_EVT connect failed"); - xEventGroupSetBits(_spp_event_group, SPP_CLOSED); - } - } else { - log_e("ESP_SPP_DISCOVERY_COMP_EVT remote doesn't offer an SPP channel"); - xEventGroupSetBits(_spp_event_group, SPP_CLOSED); - } - } else { - for(int i=0; i < param->disc_comp.scn_num; i++) { - sdpRecords[param->disc_comp.scn[i]] = param->disc_comp.service_name[0]; - } + xEventGroupClearBits(_spp_event_group, SPP_CLOSED); + if (esp_spp_connect(_sec_mask, _role, param->disc_comp.scn[0], _peer_bd_addr) != ESP_OK) { + log_e("ESP_SPP_DISCOVERY_COMP_EVT connect failed"); + xEventGroupSetBits(_spp_event_group, SPP_CLOSED); } + } else { + log_e("ESP_SPP_DISCOVERY_COMP_EVT remote doesn't offer an SPP channel"); + xEventGroupSetBits(_spp_event_group, SPP_CLOSED); + } } else { - log_e("ESP_SPP_DISCOVERY_COMP_EVT failed!, status:%d", param->disc_comp.status); - } - xEventGroupSetBits(_bt_event_group, BT_SDP_COMPLETED); - break; - - case ESP_SPP_OPEN_EVT: // Enum 26 - When SPP Client connection open - log_i("ESP_SPP_OPEN_EVT"); - if (!_spp_client){ - _spp_client = param->open.handle; - } else { - secondConnectionAttempt = true; - esp_spp_disconnect(param->open.handle); + for (int i = 0; i < param->disc_comp.scn_num; i++) { + sdpRecords[param->disc_comp.scn[i]] = param->disc_comp.service_name[0]; + } } - xEventGroupClearBits(_spp_event_group, SPP_DISCONNECTED); - xEventGroupSetBits(_spp_event_group, SPP_CONNECTED); - xEventGroupSetBits(_spp_event_group, SPP_CONGESTED); - break; - - case ESP_SPP_CLOSE_EVT: // Enum 27 - When SPP connection closed - if ((param->close.async == false && param->close.status == ESP_SPP_SUCCESS) || param->close.async) { - log_i("ESP_SPP_CLOSE_EVT status:%d handle:%d close_by_remote:%d attempt %u", param->close.status, - param->close.handle, param->close.async, secondConnectionAttempt); - if(secondConnectionAttempt) { - secondConnectionAttempt = false; - } else { - _spp_client = 0; - xEventGroupSetBits(_spp_event_group, SPP_DISCONNECTED); - xEventGroupSetBits(_spp_event_group, SPP_CONGESTED); - xEventGroupSetBits(_spp_event_group, SPP_CLOSED); - xEventGroupClearBits(_spp_event_group, SPP_CONNECTED); - } + } else { + log_e("ESP_SPP_DISCOVERY_COMP_EVT failed!, status:%d", param->disc_comp.status); + } + xEventGroupSetBits(_bt_event_group, BT_SDP_COMPLETED); + break; + + case ESP_SPP_OPEN_EVT: // Enum 26 - When SPP Client connection open + log_i("ESP_SPP_OPEN_EVT"); + if (!_spp_client) { + _spp_client = param->open.handle; + } else { + secondConnectionAttempt = true; + esp_spp_disconnect(param->open.handle); + } + xEventGroupClearBits(_spp_event_group, SPP_DISCONNECTED); + xEventGroupSetBits(_spp_event_group, SPP_CONNECTED); + xEventGroupSetBits(_spp_event_group, SPP_CONGESTED); + break; + + case ESP_SPP_CLOSE_EVT: // Enum 27 - When SPP connection closed + if ((param->close.async == false && param->close.status == ESP_SPP_SUCCESS) || param->close.async) { + log_i("ESP_SPP_CLOSE_EVT status:%d handle:%d close_by_remote:%d attempt %u", param->close.status, + param->close.handle, param->close.async, secondConnectionAttempt); + if (secondConnectionAttempt) { + secondConnectionAttempt = false; } else { - log_e("ESP_SPP_CLOSE_EVT failed!, status:%d", param->close.status); + _spp_client = 0; + xEventGroupSetBits(_spp_event_group, SPP_DISCONNECTED); + xEventGroupSetBits(_spp_event_group, SPP_CONGESTED); + xEventGroupSetBits(_spp_event_group, SPP_CLOSED); + xEventGroupClearBits(_spp_event_group, SPP_CONNECTED); } - break; - - case ESP_SPP_START_EVT: // Enum 28 - When SPP server started - log_i("ESP_SPP_START_EVT"); - break; - - case ESP_SPP_CL_INIT_EVT: // Enum 29 - When SPP client initiated a connection - if (param->cl_init.status == ESP_SPP_SUCCESS) { - log_i("ESP_SPP_CL_INIT_EVT handle:%d sec_id:%d", param->cl_init.handle, param->cl_init.sec_id); - } else { - log_i("ESP_SPP_CL_INIT_EVT status:%d", param->cl_init.status); - } - break; - - case ESP_SPP_DATA_IND_EVT: // Enum 30 - When SPP connection received data, only for ESP_SPP_MODE_CB - log_v("ESP_SPP_DATA_IND_EVT len=%d handle=%d", param->data_ind.len, param->data_ind.handle); - //esp_log_buffer_hex("",param->data_ind.data,param->data_ind.len); //for low level debug - //ets_printf("r:%u\n", param->data_ind.len); - - if(custom_data_callback){ - custom_data_callback(param->data_ind.data, param->data_ind.len); - } else if (_spp_rx_queue != NULL){ - for (int i = 0; i < param->data_ind.len; i++){ - if(xQueueSend(_spp_rx_queue, param->data_ind.data + i, (TickType_t)0) != pdTRUE){ - log_e("RX Full! Discarding %u bytes", param->data_ind.len - i); - break; - } - } - } - break; - - case ESP_SPP_CONG_EVT: // Enum 31 - When SPP connection congestion status changed, only for ESP_SPP_MODE_CB - if(param->cong.cong){ - xEventGroupClearBits(_spp_event_group, SPP_CONGESTED); - } else { - xEventGroupSetBits(_spp_event_group, SPP_CONGESTED); + } else { + log_e("ESP_SPP_CLOSE_EVT failed!, status:%d", param->close.status); + } + break; + + case ESP_SPP_START_EVT: // Enum 28 - When SPP server started + log_i("ESP_SPP_START_EVT"); + break; + + case ESP_SPP_CL_INIT_EVT: // Enum 29 - When SPP client initiated a connection + if (param->cl_init.status == ESP_SPP_SUCCESS) { + log_i("ESP_SPP_CL_INIT_EVT handle:%d sec_id:%d", param->cl_init.handle, param->cl_init.sec_id); + } else { + log_i("ESP_SPP_CL_INIT_EVT status:%d", param->cl_init.status); + } + break; + + case ESP_SPP_DATA_IND_EVT: // Enum 30 - When SPP connection received data, only for ESP_SPP_MODE_CB + log_v("ESP_SPP_DATA_IND_EVT len=%d handle=%d", param->data_ind.len, param->data_ind.handle); + //esp_log_buffer_hex("",param->data_ind.data,param->data_ind.len); //for low level debug + //ets_printf("r:%u\n", param->data_ind.len); + + if (custom_data_callback) { + custom_data_callback(param->data_ind.data, param->data_ind.len); + } else if (_spp_rx_queue != NULL) { + for (int i = 0; i < param->data_ind.len; i++) { + if (xQueueSend(_spp_rx_queue, param->data_ind.data + i, (TickType_t)0) != pdTRUE) { + log_e("RX Full! Discarding %u bytes", param->data_ind.len - i); + break; + } } - log_v("ESP_SPP_CONG_EVT: %s", param->cong.cong?"CONGESTED":"FREE"); - break; + } + break; - case ESP_SPP_WRITE_EVT: // Enum 33 - When SPP write operation completes, only for ESP_SPP_MODE_CB - if (param->write.status == ESP_SPP_SUCCESS) { - if(param->write.cong){ - xEventGroupClearBits(_spp_event_group, SPP_CONGESTED); - } - log_v("ESP_SPP_WRITE_EVT: %u %s", param->write.len, param->write.cong?"CONGESTED":""); - } else { - log_e("ESP_SPP_WRITE_EVT failed!, status:%d", param->write.status); + case ESP_SPP_CONG_EVT: // Enum 31 - When SPP connection congestion status changed, only for ESP_SPP_MODE_CB + if (param->cong.cong) { + xEventGroupClearBits(_spp_event_group, SPP_CONGESTED); + } else { + xEventGroupSetBits(_spp_event_group, SPP_CONGESTED); + } + log_v("ESP_SPP_CONG_EVT: %s", param->cong.cong ? "CONGESTED" : "FREE"); + break; + + case ESP_SPP_WRITE_EVT: // Enum 33 - When SPP write operation completes, only for ESP_SPP_MODE_CB + if (param->write.status == ESP_SPP_SUCCESS) { + if (param->write.cong) { + xEventGroupClearBits(_spp_event_group, SPP_CONGESTED); } - xSemaphoreGive(_spp_tx_done);//we can try to send another packet - break; - - case ESP_SPP_SRV_OPEN_EVT: // Enum 34 - When SPP Server connection open - if (param->srv_open.status == ESP_SPP_SUCCESS) { - log_i("ESP_SPP_SRV_OPEN_EVT: %u", _spp_client); - if (!_spp_client){ - _spp_client = param->srv_open.handle; - _spp_tx_buffer_len = 0; - } else { - secondConnectionAttempt = true; - esp_spp_disconnect(param->srv_open.handle); - } - xEventGroupClearBits(_spp_event_group, SPP_DISCONNECTED); - xEventGroupSetBits(_spp_event_group, SPP_CONNECTED); + log_v("ESP_SPP_WRITE_EVT: %u %s", param->write.len, param->write.cong ? "CONGESTED" : ""); + } else { + log_e("ESP_SPP_WRITE_EVT failed!, status:%d", param->write.status); + } + xSemaphoreGive(_spp_tx_done); //we can try to send another packet + break; + + case ESP_SPP_SRV_OPEN_EVT: // Enum 34 - When SPP Server connection open + if (param->srv_open.status == ESP_SPP_SUCCESS) { + log_i("ESP_SPP_SRV_OPEN_EVT: %u", _spp_client); + if (!_spp_client) { + _spp_client = param->srv_open.handle; + _spp_tx_buffer_len = 0; } else { - log_e("ESP_SPP_SRV_OPEN_EVT Failed!, status:%d", param->srv_open.status); + secondConnectionAttempt = true; + esp_spp_disconnect(param->srv_open.handle); } - break; + xEventGroupClearBits(_spp_event_group, SPP_DISCONNECTED); + xEventGroupSetBits(_spp_event_group, SPP_CONNECTED); + } else { + log_e("ESP_SPP_SRV_OPEN_EVT Failed!, status:%d", param->srv_open.status); + } + break; - case ESP_SPP_SRV_STOP_EVT: // Enum 35 - When SPP server stopped - log_i("ESP_SPP_SRV_STOP_EVT"); - break; + case ESP_SPP_SRV_STOP_EVT: // Enum 35 - When SPP server stopped + log_i("ESP_SPP_SRV_STOP_EVT"); + break; - case ESP_SPP_VFS_REGISTER_EVT: // Enum 36 - When SPP VFS register - log_i("ESP_SPP_VFS_REGISTER_EVT"); - break; + case ESP_SPP_VFS_REGISTER_EVT: // Enum 36 - When SPP VFS register + log_i("ESP_SPP_VFS_REGISTER_EVT"); + break; - case ESP_SPP_VFS_UNREGISTER_EVT: // Enum 37 - When SPP VFS unregister - log_i("ESP_SPP_VFS_UNREGISTER_EVT"); - break; + case ESP_SPP_VFS_UNREGISTER_EVT: // Enum 37 - When SPP VFS unregister + log_i("ESP_SPP_VFS_UNREGISTER_EVT"); + break; default: - log_i("ESP_SPP_* event #%d unhandled", event); - break; - } - if(custom_spp_callback)(*custom_spp_callback)(event, param); + log_i("ESP_SPP_* event #%d unhandled", event); + break; + } + if (custom_spp_callback) (*custom_spp_callback)(event, param); } -void BluetoothSerial::onData(BluetoothSerialDataCb cb){ - custom_data_callback = cb; +void BluetoothSerial::onData(BluetoothSerialDataCb cb) { + custom_data_callback = cb; } -static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) -{ - switch(event){ - case ESP_BT_GAP_DISC_RES_EVT: { // Enum 0 - Device discovery result event - log_i("ESP_BT_GAP_DISC_RES_EVT properties=%d", param->disc_res.num_prop); +static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) { + switch (event) { + case ESP_BT_GAP_DISC_RES_EVT: + { // Enum 0 - Device discovery result event + log_i("ESP_BT_GAP_DISC_RES_EVT properties=%d", param->disc_res.num_prop); #if (ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO) - char bda_str[18]; - log_i("Scanned device: %s", bda2str(param->disc_res.bda, bda_str, 18)); + char bda_str[18]; + log_i("Scanned device: %s", bda2str(param->disc_res.bda, bda_str, 18)); #endif - BTAdvertisedDeviceSet advertisedDevice; - uint8_t peer_bdname_len = 0; - char peer_bdname[ESP_BT_GAP_MAX_BDNAME_LEN + 1]; - for (int i = 0; i < param->disc_res.num_prop; i++) { - switch(param->disc_res.prop[i].type) { - case ESP_BT_GAP_DEV_PROP_BDNAME: // Enum 1 - Bluetooth device name, value type is int8_t [] - peer_bdname_len = param->disc_res.prop[i].len; - memcpy(peer_bdname, param->disc_res.prop[i].val, peer_bdname_len); - peer_bdname_len--; // len includes 0 terminator - log_v("ESP_BT_GAP_DISC_RES_EVT : BDNAME : %s : %d", peer_bdname, peer_bdname_len); - if (strlen(_remote_name) == peer_bdname_len - && strncmp(peer_bdname, _remote_name, peer_bdname_len) == 0) { - log_i("ESP_BT_GAP_DISC_RES_EVT : SPP_START_DISCOVERY_BDNAME : %s", peer_bdname); - _isRemoteAddressSet = true; - memcpy(_peer_bd_addr, param->disc_res.bda, ESP_BD_ADDR_LEN); - esp_bt_gap_cancel_discovery(); - esp_spp_start_discovery(_peer_bd_addr); - } - break; - - case ESP_BT_GAP_DEV_PROP_COD: // Enum 2 - Class of Device, value type is uint32_t - if (param->disc_res.prop[i].len <= sizeof(int)) { - uint32_t cod = 0; - memcpy(&cod, param->disc_res.prop[i].val, param->disc_res.prop[i].len); - advertisedDevice.setCOD(cod); - log_d("ESP_BT_GAP_DEV_PROP_COD 0x%x", cod); - } else { - log_d("ESP_BT_GAP_DEV_PROP_COD invalid COD: Value size larger than integer"); - } - break; - - case ESP_BT_GAP_DEV_PROP_RSSI: // Enum 3 - Received Signal strength Indication, value type is int8_t, ranging from -128 to 127 - if (param->disc_res.prop[i].len <= sizeof(int)) { - uint8_t rssi = 0; - memcpy(&rssi, param->disc_res.prop[i].val, param->disc_res.prop[i].len); - log_d("ESP_BT_GAP_DEV_PROP_RSSI %d", rssi); - advertisedDevice.setRSSI(rssi); - } else { - log_d("ESP_BT_GAP_DEV_PROP_RSSI invalid RSSI: Value size larger than integer"); - } - break; - - case ESP_BT_GAP_DEV_PROP_EIR: // Enum 4 - Extended Inquiry Response, value type is uint8_t [] - if (get_name_from_eir((uint8_t*)param->disc_res.prop[i].val, peer_bdname, &peer_bdname_len)) { - log_i("ESP_BT_GAP_DISC_RES_EVT : EIR : %s : %d", peer_bdname, peer_bdname_len); - if (strlen(_remote_name) == peer_bdname_len - && strncmp(peer_bdname, _remote_name, peer_bdname_len) == 0) { - log_v("ESP_BT_GAP_DISC_RES_EVT : SPP_START_DISCOVERY_EIR : %s", peer_bdname, peer_bdname_len); - _isRemoteAddressSet = true; - memcpy(_peer_bd_addr, param->disc_res.bda, ESP_BD_ADDR_LEN); - esp_bt_gap_cancel_discovery(); - esp_spp_start_discovery(_peer_bd_addr); - } - } - break; - - default: - log_i("ESP_BT_GAP_DISC_RES_EVT unknown property [%d]:type:%d", i, param->disc_res.prop[i].type); - break; - } - if (_isRemoteAddressSet) - break; - } - if (peer_bdname_len) - advertisedDevice.setName(peer_bdname); - esp_bd_addr_t addr; - memcpy(addr, param->disc_res.bda, ESP_BD_ADDR_LEN); - advertisedDevice.setAddress(BTAddress(addr)); - if (scanResults.add(advertisedDevice) && advertisedDeviceCb) - advertisedDeviceCb(&advertisedDevice); - } - break; - - case ESP_BT_GAP_DISC_STATE_CHANGED_EVT: // Enum 1 - Discovery state changed event - if (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STOPPED) { - log_i("ESP_BT_GAP_DISC_STATE_CHANGED_EVT stopped"); - xEventGroupClearBits(_bt_event_group, BT_DISCOVERY_RUNNING); - xEventGroupSetBits(_bt_event_group, BT_DISCOVERY_COMPLETED); - } else { // ESP_BT_GAP_DISCOVERY_STARTED - log_i("ESP_BT_GAP_DISC_STATE_CHANGED_EVT started"); - xEventGroupClearBits(_bt_event_group, BT_DISCOVERY_COMPLETED); - xEventGroupSetBits(_bt_event_group, BT_DISCOVERY_RUNNING); - } - break; - - case ESP_BT_GAP_RMT_SRVCS_EVT: // Enum 2 - Get remote services event - log_i( "ESP_BT_GAP_RMT_SRVCS_EVT: status = %d, num_uuids = %d", param->rmt_srvcs.stat, param->rmt_srvcs.num_uuids); - break; - - case ESP_BT_GAP_RMT_SRVC_REC_EVT: // Enum 3 - Get remote service record event - log_i("ESP_BT_GAP_RMT_SRVC_REC_EVT: status = %d", param->rmt_srvc_rec.stat); - break; - - case ESP_BT_GAP_AUTH_CMPL_EVT: // Enum 4 - Authentication complete event - if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) { - log_v("authentication success: %s", param->auth_cmpl.device_name); - if (auth_complete_callback) { - auth_complete_callback(true); - } - } else { - log_e("authentication failed, status:%d", param->auth_cmpl.stat); - if (auth_complete_callback) { - auth_complete_callback(false); + BTAdvertisedDeviceSet advertisedDevice; + uint8_t peer_bdname_len = 0; + char peer_bdname[ESP_BT_GAP_MAX_BDNAME_LEN + 1]; + for (int i = 0; i < param->disc_res.num_prop; i++) { + switch (param->disc_res.prop[i].type) { + case ESP_BT_GAP_DEV_PROP_BDNAME: // Enum 1 - Bluetooth device name, value type is int8_t [] + peer_bdname_len = param->disc_res.prop[i].len; + memcpy(peer_bdname, param->disc_res.prop[i].val, peer_bdname_len); + peer_bdname_len--; // len includes 0 terminator + log_v("ESP_BT_GAP_DISC_RES_EVT : BDNAME : %s : %d", peer_bdname, peer_bdname_len); + if (strlen(_remote_name) == peer_bdname_len + && strncmp(peer_bdname, _remote_name, peer_bdname_len) == 0) { + log_i("ESP_BT_GAP_DISC_RES_EVT : SPP_START_DISCOVERY_BDNAME : %s", peer_bdname); + _isRemoteAddressSet = true; + memcpy(_peer_bd_addr, param->disc_res.bda, ESP_BD_ADDR_LEN); + esp_bt_gap_cancel_discovery(); + esp_spp_start_discovery(_peer_bd_addr); + } + break; + + case ESP_BT_GAP_DEV_PROP_COD: // Enum 2 - Class of Device, value type is uint32_t + if (param->disc_res.prop[i].len <= sizeof(int)) { + uint32_t cod = 0; + memcpy(&cod, param->disc_res.prop[i].val, param->disc_res.prop[i].len); + advertisedDevice.setCOD(cod); + log_d("ESP_BT_GAP_DEV_PROP_COD 0x%x", cod); + } else { + log_d("ESP_BT_GAP_DEV_PROP_COD invalid COD: Value size larger than integer"); + } + break; + + case ESP_BT_GAP_DEV_PROP_RSSI: // Enum 3 - Received Signal strength Indication, value type is int8_t, ranging from -128 to 127 + if (param->disc_res.prop[i].len <= sizeof(int)) { + uint8_t rssi = 0; + memcpy(&rssi, param->disc_res.prop[i].val, param->disc_res.prop[i].len); + log_d("ESP_BT_GAP_DEV_PROP_RSSI %d", rssi); + advertisedDevice.setRSSI(rssi); + } else { + log_d("ESP_BT_GAP_DEV_PROP_RSSI invalid RSSI: Value size larger than integer"); + } + break; + + case ESP_BT_GAP_DEV_PROP_EIR: // Enum 4 - Extended Inquiry Response, value type is uint8_t [] + if (get_name_from_eir((uint8_t *)param->disc_res.prop[i].val, peer_bdname, &peer_bdname_len)) { + log_i("ESP_BT_GAP_DISC_RES_EVT : EIR : %s : %d", peer_bdname, peer_bdname_len); + if (strlen(_remote_name) == peer_bdname_len + && strncmp(peer_bdname, _remote_name, peer_bdname_len) == 0) { + log_v("ESP_BT_GAP_DISC_RES_EVT : SPP_START_DISCOVERY_EIR : %s", peer_bdname, peer_bdname_len); + _isRemoteAddressSet = true; + memcpy(_peer_bd_addr, param->disc_res.bda, ESP_BD_ADDR_LEN); + esp_bt_gap_cancel_discovery(); + esp_spp_start_discovery(_peer_bd_addr); } - } - break; - case ESP_BT_GAP_PIN_REQ_EVT: // Enum 5 - Legacy Pairing Pin code request - log_i("ESP_BT_GAP_PIN_REQ_EVT (min_16_digit=%d)", param->pin_req.min_16_digit); - if (param->pin_req.min_16_digit && _pin_code_len < 16) { - esp_bt_gap_pin_reply(param->pin_req.bda, false, 0, NULL); - } else { - //log_i("Input pin code: \"%s\"=0x%x", _pin_code); - log_i("Input pin code: \"%.*s\"=0x%x", _pin_code_len, _pin_code, *(int*)_pin_code); - esp_bt_gap_pin_reply(param->pin_req.bda, true, _pin_code_len, _pin_code); - } + } + break; + + default: + log_i("ESP_BT_GAP_DISC_RES_EVT unknown property [%d]:type:%d", i, param->disc_res.prop[i].type); + break; + } + if (_isRemoteAddressSet) break; + } + if (peer_bdname_len) + advertisedDevice.setName(peer_bdname); + esp_bd_addr_t addr; + memcpy(addr, param->disc_res.bda, ESP_BD_ADDR_LEN); + advertisedDevice.setAddress(BTAddress(addr)); + if (scanResults.add(advertisedDevice) && advertisedDeviceCb) + advertisedDeviceCb(&advertisedDevice); + } + break; + + case ESP_BT_GAP_DISC_STATE_CHANGED_EVT: // Enum 1 - Discovery state changed event + if (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STOPPED) { + log_i("ESP_BT_GAP_DISC_STATE_CHANGED_EVT stopped"); + xEventGroupClearBits(_bt_event_group, BT_DISCOVERY_RUNNING); + xEventGroupSetBits(_bt_event_group, BT_DISCOVERY_COMPLETED); + } else { // ESP_BT_GAP_DISCOVERY_STARTED + log_i("ESP_BT_GAP_DISC_STATE_CHANGED_EVT started"); + xEventGroupClearBits(_bt_event_group, BT_DISCOVERY_COMPLETED); + xEventGroupSetBits(_bt_event_group, BT_DISCOVERY_RUNNING); + } + break; + + case ESP_BT_GAP_RMT_SRVCS_EVT: // Enum 2 - Get remote services event + log_i("ESP_BT_GAP_RMT_SRVCS_EVT: status = %d, num_uuids = %d", param->rmt_srvcs.stat, param->rmt_srvcs.num_uuids); + break; + + case ESP_BT_GAP_RMT_SRVC_REC_EVT: // Enum 3 - Get remote service record event + log_i("ESP_BT_GAP_RMT_SRVC_REC_EVT: status = %d", param->rmt_srvc_rec.stat); + break; + + case ESP_BT_GAP_AUTH_CMPL_EVT: // Enum 4 - Authentication complete event + if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) { + log_v("authentication success: %s", param->auth_cmpl.device_name); + if (auth_complete_callback) { + auth_complete_callback(true); + } + } else { + log_e("authentication failed, status:%d", param->auth_cmpl.stat); + if (auth_complete_callback) { + auth_complete_callback(false); + } + } + break; + case ESP_BT_GAP_PIN_REQ_EVT: // Enum 5 - Legacy Pairing Pin code request + log_i("ESP_BT_GAP_PIN_REQ_EVT (min_16_digit=%d)", param->pin_req.min_16_digit); + if (param->pin_req.min_16_digit && _pin_code_len < 16) { + esp_bt_gap_pin_reply(param->pin_req.bda, false, 0, NULL); + } else { + //log_i("Input pin code: \"%s\"=0x%x", _pin_code); + log_i("Input pin code: \"%.*s\"=0x%x", _pin_code_len, _pin_code, *(int *)_pin_code); + esp_bt_gap_pin_reply(param->pin_req.bda, true, _pin_code_len, _pin_code); + } + break; #ifdef CONFIG_BT_SSP_ENABLED - case ESP_BT_GAP_CFM_REQ_EVT: // Enum 6 - Security Simple Pairing User Confirmation request. - log_i("ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", param->cfm_req.num_val); - if (confirm_request_callback) { - memcpy(current_bd_addr, param->cfm_req.bda, sizeof(esp_bd_addr_t)); - confirm_request_callback(param->cfm_req.num_val); - } - else { - log_w("ESP_BT_GAP_CFM_REQ_EVT: confirm_request_callback does not exist - refusing pairing"); - esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, false); - } - break; + case ESP_BT_GAP_CFM_REQ_EVT: // Enum 6 - Security Simple Pairing User Confirmation request. + log_i("ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", param->cfm_req.num_val); + if (confirm_request_callback) { + memcpy(current_bd_addr, param->cfm_req.bda, sizeof(esp_bd_addr_t)); + confirm_request_callback(param->cfm_req.num_val); + } else { + log_w("ESP_BT_GAP_CFM_REQ_EVT: confirm_request_callback does not exist - refusing pairing"); + esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, false); + } + break; #endif - case ESP_BT_GAP_KEY_NOTIF_EVT: // Enum 7 - Security Simple Pairing Passkey Notification - log_i("ESP_BT_GAP_KEY_NOTIF_EVT passkey:%d", param->key_notif.passkey); - break; + case ESP_BT_GAP_KEY_NOTIF_EVT: // Enum 7 - Security Simple Pairing Passkey Notification + log_i("ESP_BT_GAP_KEY_NOTIF_EVT passkey:%d", param->key_notif.passkey); + break; #ifdef CONFIG_BT_SSP_ENABLED - case ESP_BT_GAP_KEY_REQ_EVT: // Enum 8 - Security Simple Pairing Passkey request - log_i("ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!"); - if (key_request_callback) { - memcpy(current_bd_addr, param->cfm_req.bda, sizeof(esp_bd_addr_t)); - key_request_callback(); - } else { - log_w("ESP_BT_GAP_KEY_REQ_EVT: key_request_callback does not exist - refuseing pairing"); - esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, false); - } - break; + case ESP_BT_GAP_KEY_REQ_EVT: // Enum 8 - Security Simple Pairing Passkey request + log_i("ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!"); + if (key_request_callback) { + memcpy(current_bd_addr, param->cfm_req.bda, sizeof(esp_bd_addr_t)); + key_request_callback(); + } else { + log_w("ESP_BT_GAP_KEY_REQ_EVT: key_request_callback does not exist - refuseing pairing"); + esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, false); + } + break; #endif - case ESP_BT_GAP_READ_RSSI_DELTA_EVT: // Enum 9 - Read rssi event - log_i("ESP_BT_GAP_READ_RSSI_DELTA_EVT Read rssi event"); - break; - case ESP_BT_GAP_CONFIG_EIR_DATA_EVT: // Enum 10 - Config EIR data event - log_i("ESP_BT_GAP_CONFIG_EIR_DATA_EVT: stat:%d num:%d", param->config_eir_data.stat, param->config_eir_data.eir_type_num); - break; + case ESP_BT_GAP_READ_RSSI_DELTA_EVT: // Enum 9 - Read rssi event + log_i("ESP_BT_GAP_READ_RSSI_DELTA_EVT Read rssi event"); + break; + case ESP_BT_GAP_CONFIG_EIR_DATA_EVT: // Enum 10 - Config EIR data event + log_i("ESP_BT_GAP_CONFIG_EIR_DATA_EVT: stat:%d num:%d", param->config_eir_data.stat, param->config_eir_data.eir_type_num); + break; - case ESP_BT_GAP_SET_AFH_CHANNELS_EVT: // Enum 11 - Set AFH channels event - log_i("ESP_BT_GAP_SET_AFH_CHANNELS_EVT Set AFH channels event"); - break; + case ESP_BT_GAP_SET_AFH_CHANNELS_EVT: // Enum 11 - Set AFH channels event + log_i("ESP_BT_GAP_SET_AFH_CHANNELS_EVT Set AFH channels event"); + break; - case ESP_BT_GAP_READ_REMOTE_NAME_EVT: // Enum 12 - Read Remote Name event - if (param->read_rmt_name.stat == ESP_BT_STATUS_SUCCESS ) { - log_i("ESP_BT_GAP_READ_REMOTE_NAME_EVT: %s", param->read_rmt_name.rmt_name); - memcpy(_rmt_name, param->read_rmt_name.rmt_name, ESP_BT_GAP_MAX_BDNAME_LEN + 1); - _rmt_name_valid = true; - } else { - log_i("ESP_BT_GAP_READ_REMOTE_NAME_EVT: no success stat:%d", param->read_rmt_name.stat); - } - break; + case ESP_BT_GAP_READ_REMOTE_NAME_EVT: // Enum 12 - Read Remote Name event + if (param->read_rmt_name.stat == ESP_BT_STATUS_SUCCESS) { + log_i("ESP_BT_GAP_READ_REMOTE_NAME_EVT: %s", param->read_rmt_name.rmt_name); + memcpy(_rmt_name, param->read_rmt_name.rmt_name, ESP_BT_GAP_MAX_BDNAME_LEN + 1); + _rmt_name_valid = true; + } else { + log_i("ESP_BT_GAP_READ_REMOTE_NAME_EVT: no success stat:%d", param->read_rmt_name.stat); + } + break; - case ESP_BT_GAP_MODE_CHG_EVT: // Enum 13 - log_i("ESP_BT_GAP_MODE_CHG_EVT: mode: %d", param->mode_chg.mode); - break; + case ESP_BT_GAP_MODE_CHG_EVT: // Enum 13 + log_i("ESP_BT_GAP_MODE_CHG_EVT: mode: %d", param->mode_chg.mode); + break; - case ESP_BT_GAP_REMOVE_BOND_DEV_COMPLETE_EVT: // Enum - 14 remove bond device complete event - log_i("ESP_BT_GAP_REMOVE_BOND_DEV_COMPLETE_EVT remove bond device complete event"); - break; + case ESP_BT_GAP_REMOVE_BOND_DEV_COMPLETE_EVT: // Enum - 14 remove bond device complete event + log_i("ESP_BT_GAP_REMOVE_BOND_DEV_COMPLETE_EVT remove bond device complete event"); + break; - case ESP_BT_GAP_QOS_CMPL_EVT: // Enum 15 - QOS complete event - log_i("ESP_BT_GAP_QOS_CMPL_EVT QOS complete event"); - break; + case ESP_BT_GAP_QOS_CMPL_EVT: // Enum 15 - QOS complete event + log_i("ESP_BT_GAP_QOS_CMPL_EVT QOS complete event"); + break; - case ESP_BT_GAP_ACL_CONN_CMPL_STAT_EVT: // Enum 16 - ACL connection complete status event - log_i("ESP_BT_GAP_ACL_CONN_CMPL_STAT_EVT ACL connection complete status event"); - break; + case ESP_BT_GAP_ACL_CONN_CMPL_STAT_EVT: // Enum 16 - ACL connection complete status event + log_i("ESP_BT_GAP_ACL_CONN_CMPL_STAT_EVT ACL connection complete status event"); + break; - case ESP_BT_GAP_ACL_DISCONN_CMPL_STAT_EVT: // Enum 17 - ACL disconnection complete status event - log_i("ESP_BT_GAP_ACL_DISCONN_CMPL_STAT_EVT ACL disconnection complete status event: reason %d, handle %d", param->acl_disconn_cmpl_stat.reason, param->acl_disconn_cmpl_stat.handle); - break; + case ESP_BT_GAP_ACL_DISCONN_CMPL_STAT_EVT: // Enum 17 - ACL disconnection complete status event + log_i("ESP_BT_GAP_ACL_DISCONN_CMPL_STAT_EVT ACL disconnection complete status event: reason %d, handle %d", param->acl_disconn_cmpl_stat.reason, param->acl_disconn_cmpl_stat.handle); + break; - default: - log_i("ESP-BT_GAP_* unknown message: %d", event); - break; - } + default: + log_i("ESP-BT_GAP_* unknown message: %d", event); + break; + } } -static bool _init_bt(const char *deviceName, bt_mode mode) -{ - if(!_bt_event_group){ - _bt_event_group = xEventGroupCreate(); - if(!_bt_event_group){ - log_e("BT Event Group Create Failed!"); - return false; - } - xEventGroupClearBits(_bt_event_group, 0xFFFFFF); - } - if(!_spp_event_group){ - _spp_event_group = xEventGroupCreate(); - if(!_spp_event_group){ - log_e("SPP Event Group Create Failed!"); - return false; - } - xEventGroupClearBits(_spp_event_group, 0xFFFFFF); - xEventGroupSetBits(_spp_event_group, SPP_CONGESTED); - xEventGroupSetBits(_spp_event_group, SPP_DISCONNECTED); - xEventGroupSetBits(_spp_event_group, SPP_CLOSED); +static bool _init_bt(const char *deviceName, bt_mode mode) { + if (!_bt_event_group) { + _bt_event_group = xEventGroupCreate(); + if (!_bt_event_group) { + log_e("BT Event Group Create Failed!"); + return false; } - if (_spp_rx_queue == NULL){ - _spp_rx_queue = xQueueCreate(RX_QUEUE_SIZE, sizeof(uint8_t)); //initialize the queue - if (_spp_rx_queue == NULL){ - log_e("RX Queue Create Failed"); - return false; - } + xEventGroupClearBits(_bt_event_group, 0xFFFFFF); + } + if (!_spp_event_group) { + _spp_event_group = xEventGroupCreate(); + if (!_spp_event_group) { + log_e("SPP Event Group Create Failed!"); + return false; + } + xEventGroupClearBits(_spp_event_group, 0xFFFFFF); + xEventGroupSetBits(_spp_event_group, SPP_CONGESTED); + xEventGroupSetBits(_spp_event_group, SPP_DISCONNECTED); + xEventGroupSetBits(_spp_event_group, SPP_CLOSED); + } + if (_spp_rx_queue == NULL) { + _spp_rx_queue = xQueueCreate(RX_QUEUE_SIZE, sizeof(uint8_t)); //initialize the queue + if (_spp_rx_queue == NULL) { + log_e("RX Queue Create Failed"); + return false; } - if (_spp_tx_queue == NULL){ - _spp_tx_queue = xQueueCreate(TX_QUEUE_SIZE, sizeof(spp_packet_t*)); //initialize the queue - if (_spp_tx_queue == NULL){ - log_e("TX Queue Create Failed"); - return false; - } + } + if (_spp_tx_queue == NULL) { + _spp_tx_queue = xQueueCreate(TX_QUEUE_SIZE, sizeof(spp_packet_t *)); //initialize the queue + if (_spp_tx_queue == NULL) { + log_e("TX Queue Create Failed"); + return false; } - if(_spp_tx_done == NULL){ - _spp_tx_done = xSemaphoreCreateBinary(); - if (_spp_tx_done == NULL){ - log_e("TX Semaphore Create Failed"); - return false; - } - xSemaphoreTake(_spp_tx_done, 0); + } + if (_spp_tx_done == NULL) { + _spp_tx_done = xSemaphoreCreateBinary(); + if (_spp_tx_done == NULL) { + log_e("TX Semaphore Create Failed"); + return false; } + xSemaphoreTake(_spp_tx_done, 0); + } - if(!_spp_task_handle){ - xTaskCreatePinnedToCore(_spp_tx_task, "spp_tx", 4096, NULL, configMAX_PRIORITIES-1, &_spp_task_handle, 0); - if(!_spp_task_handle){ - log_e("Network Event Task Start Failed!"); - return false; - } + if (!_spp_task_handle) { + xTaskCreatePinnedToCore(_spp_tx_task, "spp_tx", 4096, NULL, configMAX_PRIORITIES - 1, &_spp_task_handle, 0); + if (!_spp_task_handle) { + log_e("Network Event Task Start Failed!"); + return false; } + } - if (!btStarted() && !btStartMode(mode)){ - log_e("initialize controller failed"); - return false; - } - - esp_bluedroid_status_t bt_state = esp_bluedroid_get_status(); - if (bt_state == ESP_BLUEDROID_STATUS_UNINITIALIZED){ - if (esp_bluedroid_init()) { - log_e("initialize bluedroid failed"); - return false; - } - } - - if (bt_state != ESP_BLUEDROID_STATUS_ENABLED){ - if (esp_bluedroid_enable()) { - log_e("enable bluedroid failed"); - return false; - } - } + if (!btStarted() && !btStartMode(mode)) { + log_e("initialize controller failed"); + return false; + } - if (esp_bt_gap_register_callback(esp_bt_gap_cb) != ESP_OK) { - log_e("gap register failed"); - return false; + esp_bluedroid_status_t bt_state = esp_bluedroid_get_status(); + if (bt_state == ESP_BLUEDROID_STATUS_UNINITIALIZED) { + if (esp_bluedroid_init()) { + log_e("initialize bluedroid failed"); + return false; } + } - if (esp_spp_register_callback(esp_spp_cb) != ESP_OK){ - log_e("spp register failed"); - return false; + if (bt_state != ESP_BLUEDROID_STATUS_ENABLED) { + if (esp_bluedroid_enable()) { + log_e("enable bluedroid failed"); + return false; } + } - esp_spp_cfg_t cfg = BT_SPP_DEFAULT_CONFIG(); - cfg.mode = ESP_SPP_MODE_CB; - if (esp_spp_enhanced_init(&cfg) != ESP_OK){ - log_e("spp init failed"); - return false; - } + if (esp_bt_gap_register_callback(esp_bt_gap_cb) != ESP_OK) { + log_e("gap register failed"); + return false; + } - log_i("device name set"); - esp_bt_dev_set_device_name(deviceName); + if (esp_spp_register_callback(esp_spp_cb) != ESP_OK) { + log_e("spp register failed"); + return false; + } + + esp_spp_cfg_t cfg = BT_SPP_DEFAULT_CONFIG(); + cfg.mode = ESP_SPP_MODE_CB; + if (esp_spp_enhanced_init(&cfg) != ESP_OK) { + log_e("spp init failed"); + return false; + } + + log_i("device name set"); + esp_bt_dev_set_device_name(deviceName); #ifdef CONFIG_BT_SSP_ENABLED - if (_enableSSP) { - log_i("Simple Secure Pairing"); - esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; - esp_bt_io_cap_t iocap; - if(_IO_CAP_INPUT && _IO_CAP_OUTPUT){ - iocap = ESP_BT_IO_CAP_IO; // Display with prompt - }else if(!_IO_CAP_INPUT && _IO_CAP_OUTPUT){ - iocap = ESP_BT_IO_CAP_OUT; // DisplayOnly - }else if(_IO_CAP_INPUT && !_IO_CAP_OUTPUT){ - iocap = ESP_BT_IO_CAP_IN; // Input only - }else if(!_IO_CAP_INPUT && !_IO_CAP_OUTPUT){ - iocap = ESP_BT_IO_CAP_NONE; // No input/output - } - esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t)); - } + if (_enableSSP) { + log_i("Simple Secure Pairing"); + esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; + esp_bt_io_cap_t iocap; + if (_IO_CAP_INPUT && _IO_CAP_OUTPUT) { + iocap = ESP_BT_IO_CAP_IO; // Display with prompt + } else if (!_IO_CAP_INPUT && _IO_CAP_OUTPUT) { + iocap = ESP_BT_IO_CAP_OUT; // DisplayOnly + } else if (_IO_CAP_INPUT && !_IO_CAP_OUTPUT) { + iocap = ESP_BT_IO_CAP_IN; // Input only + } else if (!_IO_CAP_INPUT && !_IO_CAP_OUTPUT) { + iocap = ESP_BT_IO_CAP_NONE; // No input/output + } + esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t)); + } #endif - // the default BTA_DM_COD_LOUDSPEAKER does not work with the macOS BT stack - esp_bt_cod_t cod; - cod.major = 0b00001; - cod.minor = 0b000100; - cod.service = 0b00000010110; - if (esp_bt_gap_set_cod(cod, ESP_BT_INIT_COD) != ESP_OK) { - log_e("set cod failed"); - return false; - } - return true; + // the default BTA_DM_COD_LOUDSPEAKER does not work with the macOS BT stack + esp_bt_cod_t cod; + cod.major = 0b00001; + cod.minor = 0b000100; + cod.service = 0b00000010110; + if (esp_bt_gap_set_cod(cod, ESP_BT_INIT_COD) != ESP_OK) { + log_e("set cod failed"); + return false; + } + return true; } -static bool _stop_bt() -{ - if (btStarted()){ - if(_spp_client) - esp_spp_disconnect(_spp_client); - esp_spp_deinit(); - esp_bluedroid_disable(); - esp_bluedroid_deinit(); - btStop(); - } - _spp_client = 0; - if(_spp_task_handle){ - vTaskDelete(_spp_task_handle); - _spp_task_handle = NULL; - } - if(_spp_event_group){ - vEventGroupDelete(_spp_event_group); - _spp_event_group = NULL; - } - if(_spp_rx_queue){ - vQueueDelete(_spp_rx_queue); - //ToDo: clear RX queue when in packet mode - _spp_rx_queue = NULL; - } - if(_spp_tx_queue){ - spp_packet_t *packet = NULL; - while(xQueueReceive(_spp_tx_queue, &packet, 0) == pdTRUE){ - free(packet); - } - vQueueDelete(_spp_tx_queue); - _spp_tx_queue = NULL; - } - if (_spp_tx_done) { - vSemaphoreDelete(_spp_tx_done); - _spp_tx_done = NULL; - } - if (_bt_event_group) { - vEventGroupDelete(_bt_event_group); - _bt_event_group = NULL; +static bool _stop_bt() { + if (btStarted()) { + if (_spp_client) + esp_spp_disconnect(_spp_client); + esp_spp_deinit(); + esp_bluedroid_disable(); + esp_bluedroid_deinit(); + btStop(); + } + _spp_client = 0; + if (_spp_task_handle) { + vTaskDelete(_spp_task_handle); + _spp_task_handle = NULL; + } + if (_spp_event_group) { + vEventGroupDelete(_spp_event_group); + _spp_event_group = NULL; + } + if (_spp_rx_queue) { + vQueueDelete(_spp_rx_queue); + //ToDo: clear RX queue when in packet mode + _spp_rx_queue = NULL; + } + if (_spp_tx_queue) { + spp_packet_t *packet = NULL; + while (xQueueReceive(_spp_tx_queue, &packet, 0) == pdTRUE) { + free(packet); } - return true; + vQueueDelete(_spp_tx_queue); + _spp_tx_queue = NULL; + } + if (_spp_tx_done) { + vSemaphoreDelete(_spp_tx_done); + _spp_tx_done = NULL; + } + if (_bt_event_group) { + vEventGroupDelete(_bt_event_group); + _bt_event_group = NULL; + } + return true; } static bool waitForConnect(int timeout) { - TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS; - // wait for connected or closed - EventBits_t rc = xEventGroupWaitBits(_spp_event_group, SPP_CONNECTED | SPP_CLOSED, pdFALSE, pdFALSE, xTicksToWait); - if((rc & SPP_CONNECTED) != 0) - return true; - else if((rc & SPP_CLOSED) != 0) { - log_d("connection closed!"); - return false; - } - log_d("timeout"); + TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS; + // wait for connected or closed + EventBits_t rc = xEventGroupWaitBits(_spp_event_group, SPP_CONNECTED | SPP_CLOSED, pdFALSE, pdFALSE, xTicksToWait); + if ((rc & SPP_CONNECTED) != 0) + return true; + else if ((rc & SPP_CLOSED) != 0) { + log_d("connection closed!"); return false; + } + log_d("timeout"); + return false; } static bool waitForDiscovered(int timeout) { - TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS; - return (xEventGroupWaitBits(_spp_event_group, BT_DISCOVERY_COMPLETED, pdFALSE, pdTRUE, xTicksToWait) & BT_DISCOVERY_COMPLETED) != 0; + TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS; + return (xEventGroupWaitBits(_spp_event_group, BT_DISCOVERY_COMPLETED, pdFALSE, pdTRUE, xTicksToWait) & BT_DISCOVERY_COMPLETED) != 0; } static bool waitForSDPRecord(int timeout) { - TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS; - return (xEventGroupWaitBits(_bt_event_group, BT_SDP_COMPLETED, pdFALSE, pdTRUE, xTicksToWait) & BT_SDP_COMPLETED) != 0; + TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS; + return (xEventGroupWaitBits(_bt_event_group, BT_SDP_COMPLETED, pdFALSE, pdTRUE, xTicksToWait) & BT_SDP_COMPLETED) != 0; } /** * Serial Bluetooth Arduino * */ -BluetoothSerial::BluetoothSerial() -{ - local_name = "ESP32"; //default bluetooth name +BluetoothSerial::BluetoothSerial() { + local_name = "ESP32"; //default bluetooth name } -BluetoothSerial::~BluetoothSerial(void) -{ - _stop_bt(); +BluetoothSerial::~BluetoothSerial(void) { + _stop_bt(); } /** * @param isMaster set to true if you want to connect to an other device * @param disableBLE if BLE is not used, its ram can be freed to get +10kB free ram */ -bool BluetoothSerial::begin(String localName, bool isMaster, bool disableBLE) -{ - _isMaster = isMaster; - if (localName.length()){ - local_name = localName; - } - return _init_bt(local_name.c_str(), disableBLE ? BT_MODE_CLASSIC_BT : BT_MODE_BTDM); +bool BluetoothSerial::begin(String localName, bool isMaster, bool disableBLE) { + _isMaster = isMaster; + if (localName.length()) { + local_name = localName; + } + return _init_bt(local_name.c_str(), disableBLE ? BT_MODE_CLASSIC_BT : BT_MODE_BTDM); } -int BluetoothSerial::available(void) -{ - if (_spp_rx_queue == NULL){ - return 0; - } - return uxQueueMessagesWaiting(_spp_rx_queue); +int BluetoothSerial::available(void) { + if (_spp_rx_queue == NULL) { + return 0; + } + return uxQueueMessagesWaiting(_spp_rx_queue); } -int BluetoothSerial::peek(void) -{ - uint8_t c; - if (_spp_rx_queue && xQueuePeek(_spp_rx_queue, &c, this->timeoutTicks)){ - return c; - } - return -1; +int BluetoothSerial::peek(void) { + uint8_t c; + if (_spp_rx_queue && xQueuePeek(_spp_rx_queue, &c, this->timeoutTicks)) { + return c; + } + return -1; } -bool BluetoothSerial::hasClient(void) -{ - return _spp_client > 0; +bool BluetoothSerial::hasClient(void) { + return _spp_client > 0; } -int BluetoothSerial::read() -{ +int BluetoothSerial::read() { - uint8_t c = 0; - if (_spp_rx_queue && xQueueReceive(_spp_rx_queue, &c, this->timeoutTicks)){ - return c; - } - return -1; + uint8_t c = 0; + if (_spp_rx_queue && xQueueReceive(_spp_rx_queue, &c, this->timeoutTicks)) { + return c; + } + return -1; } /** * Set timeout for read / peek */ -void BluetoothSerial::setTimeout(int timeoutMS) -{ - Stream::setTimeout(timeoutMS); - this->timeoutTicks=timeoutMS / portTICK_PERIOD_MS; +void BluetoothSerial::setTimeout(int timeoutMS) { + Stream::setTimeout(timeoutMS); + this->timeoutTicks = timeoutMS / portTICK_PERIOD_MS; } -size_t BluetoothSerial::write(uint8_t c) -{ - return write(&c, 1); +size_t BluetoothSerial::write(uint8_t c) { + return write(&c, 1); } -size_t BluetoothSerial::write(const uint8_t *buffer, size_t size) -{ - if (!_spp_client){ - return 0; - } - return (_spp_queue_packet((uint8_t *)buffer, size) == ESP_OK) ? size : 0; +size_t BluetoothSerial::write(const uint8_t *buffer, size_t size) { + if (!_spp_client) { + return 0; + } + return (_spp_queue_packet((uint8_t *)buffer, size) == ESP_OK) ? size : 0; } -void BluetoothSerial::flush() -{ - if (_spp_tx_queue != NULL){ - while(uxQueueMessagesWaiting(_spp_tx_queue) > 0){ - delay(100); - } +void BluetoothSerial::flush() { + if (_spp_tx_queue != NULL) { + while (uxQueueMessagesWaiting(_spp_tx_queue) > 0) { + delay(100); } + } } -void BluetoothSerial::end() -{ - _stop_bt(); +void BluetoothSerial::end() { + _stop_bt(); } /** * free additional ~30kB ram, reset is required to enable BT again */ -void BluetoothSerial::memrelease() -{ - esp_bt_mem_release(ESP_BT_MODE_BTDM); +void BluetoothSerial::memrelease() { + esp_bt_mem_release(ESP_BT_MODE_BTDM); } #ifdef CONFIG_BT_SSP_ENABLED -void BluetoothSerial::onConfirmRequest(ConfirmRequestCb cb) -{ - confirm_request_callback = cb; +void BluetoothSerial::onConfirmRequest(ConfirmRequestCb cb) { + confirm_request_callback = cb; } -void BluetoothSerial::onKeyRequest(KeyRequestCb cb) -{ - key_request_callback = cb; +void BluetoothSerial::onKeyRequest(KeyRequestCb cb) { + key_request_callback = cb; } -void BluetoothSerial::respondPasskey(uint32_t passkey){ - esp_bt_gap_ssp_passkey_reply(current_bd_addr, true, passkey); +void BluetoothSerial::respondPasskey(uint32_t passkey) { + esp_bt_gap_ssp_passkey_reply(current_bd_addr, true, passkey); } #endif -void BluetoothSerial::onAuthComplete(AuthCompleteCb cb) -{ - auth_complete_callback = cb; +void BluetoothSerial::onAuthComplete(AuthCompleteCb cb) { + auth_complete_callback = cb; } -void BluetoothSerial::confirmReply(boolean confirm) -{ - esp_bt_gap_ssp_confirm_reply(current_bd_addr, confirm); +void BluetoothSerial::confirmReply(boolean confirm) { + esp_bt_gap_ssp_confirm_reply(current_bd_addr, confirm); } -esp_err_t BluetoothSerial::register_callback(esp_spp_cb_t callback) -{ - custom_spp_callback = callback; - return ESP_OK; +esp_err_t BluetoothSerial::register_callback(esp_spp_cb_t callback) { + custom_spp_callback = callback; + return ESP_OK; } #ifdef CONFIG_BT_SSP_ENABLED // Enable Simple Secure Pairing (using generated PIN) // This must be called before calling begin, otherwise has no effect! void BluetoothSerial::enableSSP() { - if(isReady(false, READY_TIMEOUT)){ - log_i("Attempted to enable SSP for already initialized driver. Restart to take effect with end() followed by begin()"); - return; - } - _enableSSP = true; - _IO_CAP_INPUT = true; - _IO_CAP_OUTPUT = true; + if (isReady(false, READY_TIMEOUT)) { + log_i("Attempted to enable SSP for already initialized driver. Restart to take effect with end() followed by begin()"); + return; + } + _enableSSP = true; + _IO_CAP_INPUT = true; + _IO_CAP_OUTPUT = true; } // Enable Simple Secure Pairing (using generated PIN) @@ -975,62 +950,61 @@ void BluetoothSerial::enableSSP() { // When Input is true and Output is false User will be required to input the passkey to the ESP32 device to authenticate. // - This must be implemented by registering callback via onKeyRequest() and in this callback the entered passkey will be responded via respondPasskey(passkey); void BluetoothSerial::enableSSP(bool inputCpability, bool outputCapability) { - log_i("Enabling SSP: input capability=%d; output capability=%d", inputCpability, outputCapability); - _enableSSP = true; - _IO_CAP_INPUT = inputCpability; - _IO_CAP_OUTPUT = outputCapability; + log_i("Enabling SSP: input capability=%d; output capability=%d", inputCpability, outputCapability); + _enableSSP = true; + _IO_CAP_INPUT = inputCpability; + _IO_CAP_OUTPUT = outputCapability; } // Disable Simple Secure Pairing (using generated PIN) // This must be called before calling begin, otherwise has no effect! void BluetoothSerial::disableSSP() { - _enableSSP = false; + _enableSSP = false; } #else -bool BluetoothSerial::setPin(const char *pin, uint8_t pin_code_len){ - if(pin_code_len == 0 || pin_code_len > 16){ - log_e("PIN code must be 1-16 Bytes long! Called with length %d", pin_code_len); - return false; - } - _pin_code_len = pin_code_len; - memcpy(_pin_code, pin, pin_code_len); - return (esp_bt_gap_set_pin(ESP_BT_PIN_TYPE_FIXED, _pin_code_len, _pin_code) == ESP_OK); +bool BluetoothSerial::setPin(const char *pin, uint8_t pin_code_len) { + if (pin_code_len == 0 || pin_code_len > 16) { + log_e("PIN code must be 1-16 Bytes long! Called with length %d", pin_code_len); + return false; + } + _pin_code_len = pin_code_len; + memcpy(_pin_code, pin, pin_code_len); + return (esp_bt_gap_set_pin(ESP_BT_PIN_TYPE_FIXED, _pin_code_len, _pin_code) == ESP_OK); } #endif -bool BluetoothSerial::connect(String remoteName) -{ - bool retval = false; +bool BluetoothSerial::connect(String remoteName) { + bool retval = false; - if (!isReady(true, READY_TIMEOUT)) return false; - if (remoteName && remoteName.length() < 1) { - log_e("No remote name is provided"); - return false; - } - disconnect(); - _doConnect = true; - _isRemoteAddressSet = true; - _sec_mask = ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE; - _role = ESP_SPP_ROLE_MASTER; - strncpy(_remote_name, remoteName.c_str(), ESP_BT_GAP_MAX_BDNAME_LEN); - _remote_name[ESP_BT_GAP_MAX_BDNAME_LEN] = 0; - log_i("master : remoteName"); - // will first resolve name to address + if (!isReady(true, READY_TIMEOUT)) return false; + if (remoteName && remoteName.length() < 1) { + log_e("No remote name is provided"); + return false; + } + disconnect(); + _doConnect = true; + _isRemoteAddressSet = true; + _sec_mask = ESP_SPP_SEC_ENCRYPT | ESP_SPP_SEC_AUTHENTICATE; + _role = ESP_SPP_ROLE_MASTER; + strncpy(_remote_name, remoteName.c_str(), ESP_BT_GAP_MAX_BDNAME_LEN); + _remote_name[ESP_BT_GAP_MAX_BDNAME_LEN] = 0; + log_i("master : remoteName"); + // will first resolve name to address #ifdef ESP_IDF_VERSION_MAJOR - esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); + esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); #else - esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); + esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); #endif - xEventGroupClearBits(_spp_event_group, SPP_CLOSED); - if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS) == ESP_OK) { - retval = waitForConnect(SCAN_TIMEOUT); - } - if (retval == false) { - _isRemoteAddressSet = false; - } - return retval; + xEventGroupClearBits(_spp_event_group, SPP_CLOSED); + if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS) == ESP_OK) { + retval = waitForConnect(SCAN_TIMEOUT); + } + if (retval == false) { + _isRemoteAddressSet = false; + } + return retval; } /** @@ -1044,44 +1018,43 @@ bool BluetoothSerial::connect(String remoteName) * ESP_SPP_ROLE_MASTER master can handle up to 7 connections to slaves * ESP_SPP_ROLE_SLAVE can only have one connection to a master */ -bool BluetoothSerial::connect(uint8_t remoteAddress[], int channel, esp_spp_sec_t sec_mask, esp_spp_role_t role) -{ - bool retval = false; - if (!isReady(true, READY_TIMEOUT)) return false; - if (!remoteAddress) { - log_e("No remote address is provided"); - return false; - } - disconnect(); - _doConnect = true; - _remote_name[0] = 0; - _isRemoteAddressSet = true; - _sec_mask = sec_mask; - _role = role; - memcpy(_peer_bd_addr, remoteAddress, ESP_BD_ADDR_LEN); - log_i("master : remoteAddress"); - xEventGroupClearBits(_spp_event_group, SPP_CLOSED); - if (channel > 0) { +bool BluetoothSerial::connect(uint8_t remoteAddress[], int channel, esp_spp_sec_t sec_mask, esp_spp_role_t role) { + bool retval = false; + if (!isReady(true, READY_TIMEOUT)) return false; + if (!remoteAddress) { + log_e("No remote address is provided"); + return false; + } + disconnect(); + _doConnect = true; + _remote_name[0] = 0; + _isRemoteAddressSet = true; + _sec_mask = sec_mask; + _role = role; + memcpy(_peer_bd_addr, remoteAddress, ESP_BD_ADDR_LEN); + log_i("master : remoteAddress"); + xEventGroupClearBits(_spp_event_group, SPP_CLOSED); + if (channel > 0) { #if (ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO) - char bda_str[18]; - log_i("spp connect to remote %s channel %d", - bda2str(_peer_bd_addr, bda_str, sizeof(bda_str)), - channel); + char bda_str[18]; + log_i("spp connect to remote %s channel %d", + bda2str(_peer_bd_addr, bda_str, sizeof(bda_str)), + channel); #endif - if(esp_spp_connect(sec_mask, role, channel, _peer_bd_addr) != ESP_OK ) { - log_e("spp connect failed"); + if (esp_spp_connect(sec_mask, role, channel, _peer_bd_addr) != ESP_OK) { + log_e("spp connect failed"); retval = false; } else { retval = waitForConnect(READY_TIMEOUT); - if(retval) { - log_i("connected"); + if (retval) { + log_i("connected"); + } else { + if (this->isClosed()) { + log_e("connect failed"); } else { - if(this->isClosed()) { - log_e("connect failed"); - } else { - log_e("connect timed out after %dms", READY_TIMEOUT); - } + log_e("connect timed out after %dms", READY_TIMEOUT); } + } } } else if (esp_spp_start_discovery(_peer_bd_addr) == ESP_OK) { retval = waitForConnect(READY_TIMEOUT); @@ -1089,82 +1062,81 @@ bool BluetoothSerial::connect(uint8_t remoteAddress[], int channel, esp_spp_sec_ if (!retval) { _isRemoteAddressSet = false; - } - return retval; + } + return retval; } -bool BluetoothSerial::connect() -{ - if (!isReady(true, READY_TIMEOUT)) return false; - _doConnect = true; - if (_isRemoteAddressSet){ - disconnect(); - // use resolved or set address first - log_i("master : remoteAddress"); - if (esp_spp_start_discovery(_peer_bd_addr) == ESP_OK) { - return waitForConnect(READY_TIMEOUT); - } - return false; - } else if (_remote_name[0]) { - disconnect(); - log_i("master : remoteName"); - // will resolve name to address first - it may take a while +bool BluetoothSerial::connect() { + if (!isReady(true, READY_TIMEOUT)) return false; + _doConnect = true; + if (_isRemoteAddressSet) { + disconnect(); + // use resolved or set address first + log_i("master : remoteAddress"); + if (esp_spp_start_discovery(_peer_bd_addr) == ESP_OK) { + return waitForConnect(READY_TIMEOUT); + } + return false; + } else if (_remote_name[0]) { + disconnect(); + log_i("master : remoteName"); + // will resolve name to address first - it may take a while #ifdef ESP_IDF_VERSION_MAJOR - esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); + esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); #else - esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); + esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); #endif - if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS) == ESP_OK) { - return waitForConnect(SCAN_TIMEOUT); - } - return false; + if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS) == ESP_OK) { + return waitForConnect(SCAN_TIMEOUT); } - log_e("Neither Remote name nor address was provided"); return false; + } + log_e("Neither Remote name nor address was provided"); + return false; } bool BluetoothSerial::disconnect() { - if (_spp_client) { - flush(); - log_i("disconnecting"); - if (esp_spp_disconnect(_spp_client) == ESP_OK) { - TickType_t xTicksToWait = READY_TIMEOUT / portTICK_PERIOD_MS; - return (xEventGroupWaitBits(_spp_event_group, SPP_DISCONNECTED, pdFALSE, pdTRUE, xTicksToWait) & SPP_DISCONNECTED) != 0; - } + if (_spp_client) { + flush(); + log_i("disconnecting"); + if (esp_spp_disconnect(_spp_client) == ESP_OK) { + TickType_t xTicksToWait = READY_TIMEOUT / portTICK_PERIOD_MS; + return (xEventGroupWaitBits(_spp_event_group, SPP_DISCONNECTED, pdFALSE, pdTRUE, xTicksToWait) & SPP_DISCONNECTED) != 0; } - return false; + } + return false; } bool BluetoothSerial::unpairDevice(uint8_t remoteAddress[]) { - if (isReady(false, READY_TIMEOUT)) { - log_i("removing bonded device"); - return (esp_bt_gap_remove_bond_device(remoteAddress) == ESP_OK); - } - return false; + if (isReady(false, READY_TIMEOUT)) { + log_i("removing bonded device"); + return (esp_bt_gap_remove_bond_device(remoteAddress) == ESP_OK); + } + return false; } bool BluetoothSerial::connected(int timeout) { - return waitForConnect(timeout); + return waitForConnect(timeout); } /** * true if a connection terminated or a connection attempt failed */ bool BluetoothSerial::isClosed() { - return xEventGroupGetBits(_spp_event_group) & SPP_CLOSED; + return xEventGroupGetBits(_spp_event_group) & SPP_CLOSED; } bool BluetoothSerial::isReady(bool checkMaster, int timeout) { - if (checkMaster && !_isMaster) { - log_e("Master mode is not active. Call begin(localName, true) to enable Master mode"); - return false; - } - if (!btStarted()) { - log_e("BT is not initialized. Call begin() first"); - return false; - } - TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS; - return (xEventGroupWaitBits(_spp_event_group, SPP_RUNNING, pdFALSE, pdTRUE, xTicksToWait) & SPP_RUNNING) != 0; + if (checkMaster && !_isMaster) { + log_e("Master mode is not active. Call begin(localName, true) to enable Master mode"); + return false; + } + if (!btStarted()) { + log_e("BT is not initialized. Call begin() first"); + return false; + } + TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS; + return (xEventGroupWaitBits(_spp_event_group, SPP_RUNNING, pdFALSE, pdTRUE, xTicksToWait) & SPP_RUNNING) != 0; } @@ -1174,24 +1146,24 @@ bool BluetoothSerial::isReady(bool checkMaster, int timeout) { * @param[in] timeoutMs can range from MIN_INQ_TIME to MAX_INQ_TIME * @return in case of Error immediately Empty ScanResults. */ -BTScanResults* BluetoothSerial::discover(int timeoutMs) { - scanResults.clear(); - if (timeoutMs < MIN_INQ_TIME || timeoutMs > MAX_INQ_TIME){ - log_e("Timeout out of bounds: MIN=%d; MAX=%d; requested=%d", MIN_INQ_TIME, MAX_INQ_TIME, timeoutMs); - return nullptr; - } - int timeout = timeoutMs / INQ_TIME; - log_i("discover::disconnect"); - disconnect(); - log_i("discovering"); - // will resolve name to address first - it may take a while - esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); - if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, timeout, 0) == ESP_OK) { - waitForDiscovered(timeoutMs); - log_i("gap_cancel_discovery()"); - esp_bt_gap_cancel_discovery(); - } - return &scanResults; +BTScanResults *BluetoothSerial::discover(int timeoutMs) { + scanResults.clear(); + if (timeoutMs < MIN_INQ_TIME || timeoutMs > MAX_INQ_TIME) { + log_e("Timeout out of bounds: MIN=%d; MAX=%d; requested=%d", MIN_INQ_TIME, MAX_INQ_TIME, timeoutMs); + return nullptr; + } + int timeout = timeoutMs / INQ_TIME; + log_i("discover::disconnect"); + disconnect(); + log_i("discovering"); + // will resolve name to address first - it may take a while + esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); + if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, timeout, 0) == ESP_OK) { + waitForDiscovered(timeoutMs); + log_i("gap_cancel_discovery()"); + esp_bt_gap_cancel_discovery(); + } + return &scanResults; } /** @@ -1203,29 +1175,29 @@ BTScanResults* BluetoothSerial::discover(int timeoutMs) { * @return Whether start was successful or problems with params */ bool BluetoothSerial::discoverAsync(BTAdvertisedDeviceCb cb, int timeoutMs) { - scanResults.clear(); - if (strlen(_remote_name) || _isRemoteAddressSet) - return false; - int timeout = timeoutMs / INQ_TIME; - disconnect(); - advertisedDeviceCb = cb; - log_i("discovering"); - // will resolve name to address first - it may take a while - esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); - if (timeout > 0) - return esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, timeout, 0) == ESP_OK; - else return esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, ESP_BT_GAP_MAX_INQ_LEN, 0) == ESP_OK; + scanResults.clear(); + if (strlen(_remote_name) || _isRemoteAddressSet) + return false; + int timeout = timeoutMs / INQ_TIME; + disconnect(); + advertisedDeviceCb = cb; + log_i("discovering"); + // will resolve name to address first - it may take a while + esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); + if (timeout > 0) + return esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, timeout, 0) == ESP_OK; + else return esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, ESP_BT_GAP_MAX_INQ_LEN, 0) == ESP_OK; } /** @brief Stops the asynchronous discovery and clears the callback */ void BluetoothSerial::discoverAsyncStop() { - esp_bt_gap_cancel_discovery(); - advertisedDeviceCb = nullptr; + esp_bt_gap_cancel_discovery(); + advertisedDeviceCb = nullptr; } /** @brief Clears scanResult entries */ void BluetoothSerial::discoverClear() { - scanResults.clear(); + scanResults.clear(); } /** @brief Can be used while discovering asynchronously @@ -1233,13 +1205,12 @@ void BluetoothSerial::discoverClear() { * * @return BTScanResults contains several information of found devices */ -BTScanResults* BluetoothSerial::getScanResults() { - return &scanResults; +BTScanResults *BluetoothSerial::getScanResults() { + return &scanResults; } -BluetoothSerial::operator bool() const -{ - return true; +BluetoothSerial::operator bool() const { + return true; } /** @@ -1247,25 +1218,25 @@ BluetoothSerial::operator bool() const * esp_spp_start_discovery doesn't tell us the btAddress in the callback, so we have to wait until it's finished */ std::map BluetoothSerial::getChannels(const BTAddress &remoteAddress) { - if(xEventGroupGetBits(_bt_event_group) & BT_SDP_RUNNING) { - log_e("getChannels failed - already running"); - } - xEventGroupSetBits(_bt_event_group, BT_SDP_RUNNING); - xEventGroupClearBits(_bt_event_group, BT_SDP_COMPLETED); - _doConnect = false; - sdpRecords.clear(); - log_d("esp_spp_start_discovery"); - if (esp_spp_start_discovery(*remoteAddress.getNative()) != ESP_OK) { - log_e("esp_spp_start_discovery failed"); - } else { - if(! waitForSDPRecord(READY_TIMEOUT)) { - log_e("getChannels failed timeout"); - } - log_d("esp_spp_start_discovery wait for BT_SDP_COMPLETED done (%dms)", READY_TIMEOUT); - } - log_d("esp_spp_start_discovery done, found %d services", sdpRecords.size()); - xEventGroupClearBits(_bt_event_group, BT_SDP_RUNNING); - return sdpRecords; + if (xEventGroupGetBits(_bt_event_group) & BT_SDP_RUNNING) { + log_e("getChannels failed - already running"); + } + xEventGroupSetBits(_bt_event_group, BT_SDP_RUNNING); + xEventGroupClearBits(_bt_event_group, BT_SDP_COMPLETED); + _doConnect = false; + sdpRecords.clear(); + log_d("esp_spp_start_discovery"); + if (esp_spp_start_discovery(*remoteAddress.getNative()) != ESP_OK) { + log_e("esp_spp_start_discovery failed"); + } else { + if (!waitForSDPRecord(READY_TIMEOUT)) { + log_e("getChannels failed timeout"); + } + log_d("esp_spp_start_discovery wait for BT_SDP_COMPLETED done (%dms)", READY_TIMEOUT); + } + log_d("esp_spp_start_discovery done, found %d services", sdpRecords.size()); + xEventGroupClearBits(_bt_event_group, BT_SDP_RUNNING); + return sdpRecords; } /** @@ -1274,8 +1245,8 @@ std::map BluetoothSerial::getChannels(const BTAddress &remoteA * @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); + 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. @@ -1283,9 +1254,9 @@ void BluetoothSerial::getBtAddress(uint8_t *mac) { * @return The BTAddress object. */ BTAddress BluetoothSerial::getBtAddressObject() { - uint8_t mac_arr[ESP_BD_ADDR_LEN]; - getBtAddress(mac_arr); - return BTAddress(mac_arr); + 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. @@ -1293,110 +1264,110 @@ BTAddress BluetoothSerial::getBtAddressObject() { * @return The BT MAC address string. */ String BluetoothSerial::getBtAddressString() { - return getBtAddressObject().toString(true); + return getBtAddressObject().toString(true); } // Send a request to the remote device defined by the remoteAddress to send back its name. // The name will be read by background task and stored. It can be later read with radRemoteName() -void BluetoothSerial::requestRemoteName(uint8_t remoteAddress[]){ - if(isReady(false, READY_TIMEOUT)){ - esp_bt_gap_read_remote_name(remoteAddress); - } +void BluetoothSerial::requestRemoteName(uint8_t remoteAddress[]) { + if (isReady(false, READY_TIMEOUT)) { + esp_bt_gap_read_remote_name(remoteAddress); + } } // If remote name is valid (was already received) this function will copy the name to the aprameter rmt_name // The buffer must have size at least ESP_BT_GAP_MAX_BDNAME_LEN + 1 // If the name is valid the function will return true // If the name is not valid (was not read yet) returns false -bool BluetoothSerial::readRemoteName(char rmt_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1]){ - if(_rmt_name_valid){ - memcpy(rmt_name, _rmt_name, ESP_BT_GAP_MAX_BDNAME_LEN + 1); - return true; - } - return false; +bool BluetoothSerial::readRemoteName(char rmt_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1]) { + if (_rmt_name_valid) { + memcpy(rmt_name, _rmt_name, ESP_BT_GAP_MAX_BDNAME_LEN + 1); + return true; + } + return false; } // Set validity of remote name before reading name from different device -void BluetoothSerial::invalidateRemoteName(){ - _rmt_name_valid = false; +void BluetoothSerial::invalidateRemoteName() { + _rmt_name_valid = false; } -int BluetoothSerial::getNumberOfBondedDevices(){ - return esp_bt_gap_get_bond_device_num(); +int BluetoothSerial::getNumberOfBondedDevices() { + return esp_bt_gap_get_bond_device_num(); } // Accepts the maximum number of devices that can fit in given array dev_list. // Create you list this way: esp_bd_addr_t dev_list[dev_num]; // Returns number of retrieved devices (on error returns 0) -int BluetoothSerial::getBondedDevices(uint dev_num, esp_bd_addr_t *dev_list){ - // typedef uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN] - if(dev_list == NULL){ - log_e("Device list is NULL"); - return 0; - } - if(dev_num == 0){ - log_e("Device number must be larger than 0!"); - return 0; - } - int _dev_num = dev_num; - esp_bt_gap_get_bond_device_list(&_dev_num, dev_list); - return _dev_num; +int BluetoothSerial::getBondedDevices(uint dev_num, esp_bd_addr_t *dev_list) { + // typedef uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN] + if (dev_list == NULL) { + log_e("Device list is NULL"); + return 0; + } + if (dev_num == 0) { + log_e("Device number must be larger than 0!"); + return 0; + } + int _dev_num = dev_num; + esp_bt_gap_get_bond_device_list(&_dev_num, dev_list); + return _dev_num; } -bool BluetoothSerial::deleteBondedDevice(uint8_t *remoteAddress){ - esp_err_t ret = esp_bt_gap_remove_bond_device(remoteAddress); - if(ret == ESP_OK){ - return true; - }else{ - return false; - } +bool BluetoothSerial::deleteBondedDevice(uint8_t *remoteAddress) { + esp_err_t ret = esp_bt_gap_remove_bond_device(remoteAddress); + if (ret == ESP_OK) { + return true; + } else { + return false; + } } -void BluetoothSerial::deleteAllBondedDevices(){ - if(!isReady(false, READY_TIMEOUT)){ - log_w("Attempted to drop cache for uninitialized driver. First call begin()"); - return; - } +void BluetoothSerial::deleteAllBondedDevices() { + if (!isReady(false, READY_TIMEOUT)) { + log_w("Attempted to drop cache for uninitialized driver. First call begin()"); + return; + } - int expected_dev_num = esp_bt_gap_get_bond_device_num(); - if(expected_dev_num == 0){ - log_i("No devices in cache."); - return; - } else { - log_d("Found %d bonded devices", expected_dev_num); - } - esp_err_t ret; - - // typedef uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN] // ESP_BD_ADDR_LEN = 6 - esp_bd_addr_t *dev_list = NULL; - log_d("Allocate buffer: sizeof(esp_bd_addr_t)=%d * expected_dev_num=%d", sizeof(esp_bd_addr_t), expected_dev_num); - dev_list = (esp_bd_addr_t*) malloc(sizeof(esp_bd_addr_t) * expected_dev_num); - if(dev_list == NULL){ - log_e("Could not allocated BT device buffer!"); - return; - } - //uint8_t dev_list [20][6]; - - int dev_num; - ret = esp_bt_gap_get_bond_device_list(&dev_num, dev_list); - log_d("esp_bt_gap_get_bond_device_list ret = %d", ret); - if(ret == ESP_OK){ - if(dev_num != expected_dev_num){ - log_w("Inconsistent number of bonded devices. Expected %d; returned %d",expected_dev_num, dev_num); - } - for(int i=0; i BluetoothSerialD typedef std::function ConfirmRequestCb; typedef std::function KeyRequestCb; typedef std::function AuthCompleteCb; -typedef std::function BTAdvertisedDeviceCb; - -class BluetoothSerial: public Stream -{ - public: - - BluetoothSerial(void); - ~BluetoothSerial(void); - - bool begin(String localName=String(), bool isMaster=false, bool disableBLE=false); - bool begin(unsigned long baud){//compatibility - return begin(); - } - int available(void); - int peek(void); - bool hasClient(void); - int read(void); - size_t write(uint8_t c); - size_t write(const uint8_t *buffer, size_t size); - void flush(); - void end(void); - void memrelease(); - void setTimeout(int timeoutMS); - void onData(BluetoothSerialDataCb cb); - esp_err_t register_callback(esp_spp_cb_t callback); - +typedef std::function BTAdvertisedDeviceCb; + +class BluetoothSerial : public Stream { +public: + + BluetoothSerial(void); + ~BluetoothSerial(void); + + bool begin(String localName = String(), bool isMaster = false, bool disableBLE = false); + bool begin(unsigned long baud) { //compatibility + return begin(); + } + int available(void); + int peek(void); + bool hasClient(void); + int read(void); + size_t write(uint8_t c); + size_t write(const uint8_t *buffer, size_t size); + void flush(); + void end(void); + void memrelease(); + void setTimeout(int timeoutMS); + void onData(BluetoothSerialDataCb cb); + esp_err_t register_callback(esp_spp_cb_t callback); + #ifdef CONFIG_BT_SSP_ENABLED - void onConfirmRequest(ConfirmRequestCb cb); - void onKeyRequest(KeyRequestCb cb); - void respondPasskey(uint32_t passkey); + void onConfirmRequest(ConfirmRequestCb cb); + void onKeyRequest(KeyRequestCb cb); + void respondPasskey(uint32_t passkey); #endif - void onAuthComplete(AuthCompleteCb cb); - void confirmReply(boolean confirm); + void onAuthComplete(AuthCompleteCb cb); + void confirmReply(boolean confirm); #ifdef CONFIG_BT_SSP_ENABLED - void enableSSP(); - void enableSSP(bool inputCapability, bool outputCapability); - void disableSSP(); + void enableSSP(); + void enableSSP(bool inputCapability, bool outputCapability); + void disableSSP(); #else - bool setPin(const char *pin, uint8_t pin_code_len); + bool setPin(const char *pin, uint8_t pin_code_len); #endif - bool connect(String remoteName); - bool connect(uint8_t remoteAddress[], int channel=0, esp_spp_sec_t sec_mask=(ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE), esp_spp_role_t role=ESP_SPP_ROLE_MASTER); - bool connect(const BTAddress &remoteAddress, int channel=0, esp_spp_sec_t sec_mask=(ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE), esp_spp_role_t role=ESP_SPP_ROLE_MASTER) { - return connect(*remoteAddress.getNative(), channel, sec_mask); }; - bool connect(); - bool connected(int timeout=0); - bool isClosed(); - bool isReady(bool checkMaster=false, int timeout=0); - bool disconnect(); - bool unpairDevice(uint8_t remoteAddress[]); - - BTScanResults* discover(int timeout=0x30*1280); - bool discoverAsync(BTAdvertisedDeviceCb cb, int timeout=0x30*1280); - void discoverAsyncStop(); - void discoverClear(); - BTScanResults* getScanResults(); - - std::map getChannels(const BTAddress &remoteAddress); - - const int INQ_TIME = 1280; // Inquire Time unit 1280 ms - const int MIN_INQ_TIME = (ESP_BT_GAP_MIN_INQ_LEN * INQ_TIME); - 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(); - //void dropCache(); // To be replaced - void requestRemoteName(uint8_t *remoteAddress); - bool readRemoteName(char rmt_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1]); - void invalidateRemoteName(); - int getNumberOfBondedDevices(); - int getBondedDevices(uint dev_num, esp_bd_addr_t *dev_list); - bool deleteBondedDevice(uint8_t *remoteAddress); - void deleteAllBondedDevices(); - private: - String local_name; - int timeoutTicks=0; + bool connect(String remoteName); + bool connect(uint8_t remoteAddress[], int channel = 0, esp_spp_sec_t sec_mask = (ESP_SPP_SEC_ENCRYPT | ESP_SPP_SEC_AUTHENTICATE), esp_spp_role_t role = ESP_SPP_ROLE_MASTER); + bool connect(const BTAddress &remoteAddress, int channel = 0, esp_spp_sec_t sec_mask = (ESP_SPP_SEC_ENCRYPT | ESP_SPP_SEC_AUTHENTICATE), esp_spp_role_t role = ESP_SPP_ROLE_MASTER) { + return connect(*remoteAddress.getNative(), channel, sec_mask); + }; + bool connect(); + bool connected(int timeout = 0); + bool isClosed(); + bool isReady(bool checkMaster = false, int timeout = 0); + bool disconnect(); + bool unpairDevice(uint8_t remoteAddress[]); + + BTScanResults *discover(int timeout = 0x30 * 1280); + bool discoverAsync(BTAdvertisedDeviceCb cb, int timeout = 0x30 * 1280); + void discoverAsyncStop(); + void discoverClear(); + BTScanResults *getScanResults(); + + std::map getChannels(const BTAddress &remoteAddress); + + const int INQ_TIME = 1280; // Inquire Time unit 1280 ms + const int MIN_INQ_TIME = (ESP_BT_GAP_MIN_INQ_LEN * INQ_TIME); + 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(); + //void dropCache(); // To be replaced + void requestRemoteName(uint8_t *remoteAddress); + bool readRemoteName(char rmt_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1]); + void invalidateRemoteName(); + int getNumberOfBondedDevices(); + int getBondedDevices(uint dev_num, esp_bd_addr_t *dev_list); + bool deleteBondedDevice(uint8_t *remoteAddress); + void deleteAllBondedDevices(); +private: + String local_name; + int timeoutTicks = 0; }; #endif diff --git a/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino b/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino index 7e292e1adfb..9f4f95e5c58 100644 --- a/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino +++ b/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino @@ -17,7 +17,7 @@ WebServer server(80); static const char responsePortal[] = R"===( ESP32 CaptivePortal -

Hello World!

This is a captive portal example page. All unknown http requests will +

Hello World!

This is a captive portal example page. All unknown http requests will be redirected here.

)==="; @@ -39,14 +39,16 @@ void setup() { WiFi.softAP("ESP32-DNSServer"); // by default DNSServer is started serving any "*" domain name. It will reply - // AccessPoint's IP to all DNS request (this is requred for Captive Portal detection) + // AccessPoint's IP to all DNS request (this is required for Captive Portal detection) dnsServer.start(); // serve a simple root page server.on("/", handleRoot); // serve portal page - server.on("/portal",[](){server.send(200, "text/html", responsePortal);}); + server.on("/portal", []() { + server.send(200, "text/html", responsePortal); + }); // all unknown pages are redirected to captive portal server.onNotFound(handleNotFound); @@ -55,5 +57,5 @@ void setup() { void loop() { server.handleClient(); - delay(5); // give CPU some idle time + delay(5); // give CPU some idle time } diff --git a/libraries/DNSServer/src/DNSServer.cpp b/libraries/DNSServer/src/DNSServer.cpp index 42b28a7d361..e976981e2bf 100644 --- a/libraries/DNSServer/src/DNSServer.cpp +++ b/libraries/DNSServer/src/DNSServer.cpp @@ -11,32 +11,36 @@ #define DEBUG_OUTPUT Serial #endif -#define DNS_MIN_REQ_LEN 17 // minimal size for DNS request asking ROOT = DNS_HEADER_SIZE + 1 null byte for Name + 4 bytes type/class +#define DNS_MIN_REQ_LEN 17 // minimal size for DNS request asking ROOT = DNS_HEADER_SIZE + 1 null byte for Name + 4 bytes type/class -DNSServer::DNSServer() : _port(DNS_DEFAULT_PORT), _ttl(htonl(DNS_DEFAULT_TTL)), _errorReplyCode(DNSReplyCode::NonExistentDomain){} +DNSServer::DNSServer() + : _port(DNS_DEFAULT_PORT), _ttl(htonl(DNS_DEFAULT_TTL)), _errorReplyCode(DNSReplyCode::NonExistentDomain) {} -DNSServer::DNSServer(const String &domainName) : _port(DNS_DEFAULT_PORT), _ttl(htonl(DNS_DEFAULT_TTL)), _errorReplyCode(DNSReplyCode::NonExistentDomain), _domainName(domainName){}; +DNSServer::DNSServer(const String& domainName) + : _port(DNS_DEFAULT_PORT), _ttl(htonl(DNS_DEFAULT_TTL)), _errorReplyCode(DNSReplyCode::NonExistentDomain), _domainName(domainName){}; -bool DNSServer::start(){ - if (_resolvedIP.operator uint32_t() == 0){ // no address is set, try to obtain AP interface's IP +bool DNSServer::start() { + if (_resolvedIP.operator uint32_t() == 0) { // no address is set, try to obtain AP interface's IP #if SOC_WIFI_SUPPORTED - if (WiFi.getMode() & WIFI_AP){ + if (WiFi.getMode() & WIFI_AP) { _resolvedIP = WiFi.softAPIP(); return true; } #endif - return false; // won't run if WiFi is not in AP mode - } + return false; // won't run if WiFi is not in AP mode + } _udp.close(); - _udp.onPacket([this](AsyncUDPPacket& pkt){ this->_handleUDP(pkt); }); + _udp.onPacket([this](AsyncUDPPacket& pkt) { + this->_handleUDP(pkt); + }); return _udp.listen(_port); } -bool DNSServer::start(uint16_t port, const String &domainName, const IPAddress &resolvedIP){ +bool DNSServer::start(uint16_t port, const String& domainName, const IPAddress& resolvedIP) { _port = port; - if (domainName != "*"){ + if (domainName != "*") { _domainName = domainName; downcaseAndRemoveWwwPrefix(_domainName); } else @@ -44,145 +48,128 @@ bool DNSServer::start(uint16_t port, const String &domainName, const IPAddress & _resolvedIP = resolvedIP; _udp.close(); - _udp.onPacket([this](AsyncUDPPacket& pkt){ this->_handleUDP(pkt); }); + _udp.onPacket([this](AsyncUDPPacket& pkt) { + this->_handleUDP(pkt); + }); return _udp.listen(_port); } -void DNSServer::setErrorReplyCode(const DNSReplyCode &replyCode) -{ +void DNSServer::setErrorReplyCode(const DNSReplyCode& replyCode) { _errorReplyCode = replyCode; } -void DNSServer::setTTL(const uint32_t &ttl) -{ +void DNSServer::setTTL(const uint32_t& ttl) { _ttl = htonl(ttl); } -void DNSServer::stop() -{ +void DNSServer::stop() { _udp.close(); } -void DNSServer::downcaseAndRemoveWwwPrefix(String &domainName) -{ +void DNSServer::downcaseAndRemoveWwwPrefix(String& domainName) { domainName.toLowerCase(); domainName.replace("www.", ""); } -void DNSServer::_handleUDP(AsyncUDPPacket& pkt) -{ - if (pkt.length() < DNS_MIN_REQ_LEN) return; // truncated packet or not a DNS req +void DNSServer::_handleUDP(AsyncUDPPacket& pkt) { + if (pkt.length() < DNS_MIN_REQ_LEN) return; // truncated packet or not a DNS req // get DNS header (beginning of message) DNSHeader dnsHeader; DNSQuestion dnsQuestion; - memcpy( &dnsHeader, pkt.data(), DNS_HEADER_SIZE ); - if (dnsHeader.QR != DNS_QR_QUERY) return; // ignore non-query mesages + memcpy(&dnsHeader, pkt.data(), DNS_HEADER_SIZE); + if (dnsHeader.QR != DNS_QR_QUERY) return; // ignore non-query messages - if ( requestIncludesOnlyOneQuestion(dnsHeader) ) - { -/* + if (requestIncludesOnlyOneQuestion(dnsHeader)) { + /* // The QName has a variable length, maximum 255 bytes and is comprised of multiple labels. - // Each label contains a byte to describe its length and the label itself. The list of + // Each label contains a byte to describe its length and the label itself. The list of // labels terminates with a zero-valued byte. In "github.com", we have two labels "github" & "com" */ - const char * enoflbls = strchr(reinterpret_cast(pkt.data()) + DNS_HEADER_SIZE, 0); // find end_of_label marker - ++enoflbls; // advance after null terminator - dnsQuestion.QName = pkt.data() + DNS_HEADER_SIZE; // we can reference labels from the request - dnsQuestion.QNameLength = enoflbls - (char*)pkt.data() - DNS_HEADER_SIZE; - /* + const char* enoflbls = strchr(reinterpret_cast(pkt.data()) + DNS_HEADER_SIZE, 0); // find end_of_label marker + ++enoflbls; // advance after null terminator + dnsQuestion.QName = pkt.data() + DNS_HEADER_SIZE; // we can reference labels from the request + dnsQuestion.QNameLength = enoflbls - (char*)pkt.data() - DNS_HEADER_SIZE; + /* check if we aint going out of pkt bounds proper dns req should have label terminator at least 4 bytes before end of packet */ - if (dnsQuestion.QNameLength > pkt.length() - DNS_HEADER_SIZE - sizeof(dnsQuestion.QType) - sizeof(dnsQuestion.QClass)) return; // malformed packet - - // Copy the QType and QClass - memcpy( &dnsQuestion.QType, enoflbls, sizeof(dnsQuestion.QType) ); - memcpy( &dnsQuestion.QClass, enoflbls + sizeof(dnsQuestion.QType), sizeof(dnsQuestion.QClass) ); - } + if (dnsQuestion.QNameLength > pkt.length() - DNS_HEADER_SIZE - sizeof(dnsQuestion.QType) - sizeof(dnsQuestion.QClass)) return; // malformed packet - // will reply with IP only to "*" or if doman matches without www. subdomain - if (dnsHeader.OPCode == DNS_OPCODE_QUERY && - requestIncludesOnlyOneQuestion(dnsHeader) && - (_domainName.isEmpty() || - getDomainNameWithoutWwwPrefix(static_cast(dnsQuestion.QName), dnsQuestion.QNameLength) == _domainName) - ) - { - replyWithIP(pkt, dnsHeader, dnsQuestion); - return; - } + // Copy the QType and QClass + memcpy(&dnsQuestion.QType, enoflbls, sizeof(dnsQuestion.QType)); + memcpy(&dnsQuestion.QClass, enoflbls + sizeof(dnsQuestion.QType), sizeof(dnsQuestion.QClass)); + } - // otherwise reply with custom code - replyWithCustomCode(pkt, dnsHeader); + // will reply with IP only to "*" or if domain matches without www. subdomain + if (dnsHeader.OPCode == DNS_OPCODE_QUERY && requestIncludesOnlyOneQuestion(dnsHeader) && (_domainName.isEmpty() || getDomainNameWithoutWwwPrefix(static_cast(dnsQuestion.QName), dnsQuestion.QNameLength) == _domainName)) { + replyWithIP(pkt, dnsHeader, dnsQuestion); + return; + } + + // otherwise reply with custom code + replyWithCustomCode(pkt, dnsHeader); } -bool DNSServer::requestIncludesOnlyOneQuestion(DNSHeader& dnsHeader) -{ - return ntohs(dnsHeader.QDCount) == 1 && - dnsHeader.ANCount == 0 && - dnsHeader.NSCount == 0 && - dnsHeader.ARCount == 0; +bool DNSServer::requestIncludesOnlyOneQuestion(DNSHeader& dnsHeader) { + return ntohs(dnsHeader.QDCount) == 1 && dnsHeader.ANCount == 0 && dnsHeader.NSCount == 0 && dnsHeader.ARCount == 0; } -String DNSServer::getDomainNameWithoutWwwPrefix(const unsigned char* start, size_t len) -{ - String parsedDomainName(start, --len); // exclude trailing null byte from labels length, String constructor will add it anyway +String DNSServer::getDomainNameWithoutWwwPrefix(const unsigned char* start, size_t len) { + String parsedDomainName(start, --len); // exclude trailing null byte from labels length, String constructor will add it anyway int pos = 0; - while(pos(&ip), sizeof(uint32_t)); // The IPv4 address to return + rpl.write(reinterpret_cast(&ip), sizeof(uint32_t)); // The IPv4 address to return _udp.sendTo(rpl, req.remoteIP(), req.remotePort()); - #ifdef DEBUG_ESP_DNS - DEBUG_OUTPUT.printf("DNS responds: %s for %s\n", - _resolvedIP.toString().c_str(), getDomainNameWithoutWwwPrefix(static_cast(dnsQuestion.QName), dnsQuestion.QNameLength).c_str() ); - #endif +#ifdef DEBUG_ESP_DNS + DEBUG_OUTPUT.printf("DNS responds: %s for %s\n", + _resolvedIP.toString().c_str(), getDomainNameWithoutWwwPrefix(static_cast(dnsQuestion.QName), dnsQuestion.QNameLength).c_str()); +#endif } -void DNSServer::replyWithCustomCode(AsyncUDPPacket& req, DNSHeader& dnsHeader) -{ +void DNSServer::replyWithCustomCode(AsyncUDPPacket& req, DNSHeader& dnsHeader) { dnsHeader.QR = DNS_QR_RESPONSE; dnsHeader.RCode = static_cast(_errorReplyCode); dnsHeader.QDCount = 0; diff --git a/libraries/DNSServer/src/DNSServer.h b/libraries/DNSServer/src/DNSServer.h index 860507ac9ec..622a956085e 100644 --- a/libraries/DNSServer/src/DNSServer.h +++ b/libraries/DNSServer/src/DNSServer.h @@ -4,52 +4,47 @@ #define DNS_QR_QUERY 0 #define DNS_QR_RESPONSE 1 #define DNS_OPCODE_QUERY 0 -#define DNS_DEFAULT_TTL 60 // Default Time To Live : time interval in seconds that the resource record should be cached before being discarded -#define DNS_HEADER_SIZE 12 -#define DNS_OFFSET_DOMAIN_NAME DNS_HEADER_SIZE // Offset in bytes to reach the domain name labels in the DNS message -#define DNS_DEFAULT_PORT 53 - -enum class DNSReplyCode:uint16_t -{ - NoError = 0, +#define DNS_DEFAULT_TTL 60 // Default Time To Live : time interval in seconds that the resource record should be cached before being discarded +#define DNS_HEADER_SIZE 12 +#define DNS_OFFSET_DOMAIN_NAME DNS_HEADER_SIZE // Offset in bytes to reach the domain name labels in the DNS message +#define DNS_DEFAULT_PORT 53 + +enum class DNSReplyCode : uint16_t { + NoError = 0, FormError = 1, - ServerFailure = 2, + ServerFailure = 2, NonExistentDomain = 3, - NotImplemented = 4, - Refused = 5, - YXDomain = 6, - YXRRSet = 7, - NXRRSet = 8 + NotImplemented = 4, + Refused = 5, + YXDomain = 6, + YXRRSet = 7, + NXRRSet = 8 +}; + +enum DNSType { + DNS_TYPE_A = 1, // Host Address + DNS_TYPE_AAAA = 28, // IPv6 Address + DNS_TYPE_SOA = 6, // Start Of a zone of Authority + DNS_TYPE_PTR = 12, // Domain name PoinTeR + DNS_TYPE_DNAME = 39 // Delegation Name }; -enum DNSType -{ - DNS_TYPE_A = 1, // Host Address - DNS_TYPE_AAAA = 28, // IPv6 Address - DNS_TYPE_SOA = 6, // Start Of a zone of Authority - DNS_TYPE_PTR = 12, // Domain name PoinTeR - DNS_TYPE_DNAME = 39 // Delegation Name -} ; - -enum DNSClass -{ - DNS_CLASS_IN = 1, // INternet - DNS_CLASS_CH = 3 // CHaos -} ; - -enum DNSRDLength -{ - DNS_RDLENGTH_IPV4 = 4 // 4 bytes for an IPv4 address -} ; - -struct DNSHeader -{ - uint16_t ID; // identification number +enum DNSClass { + DNS_CLASS_IN = 1, // INternet + DNS_CLASS_CH = 3 // CHaos +}; + +enum DNSRDLength { + DNS_RDLENGTH_IPV4 = 4 // 4 bytes for an IPv4 address +}; + +struct DNSHeader { + uint16_t ID; // identification number union { struct { uint16_t RD : 1; // recursion desired uint16_t TC : 1; // truncated message - uint16_t AA : 1; // authoritive answer + uint16_t AA : 1; // authoritative answer uint16_t OPCode : 4; // message_type uint16_t QR : 1; // query/response flag uint16_t RCode : 4; // response code @@ -58,133 +53,135 @@ struct DNSHeader }; uint16_t Flags; }; - uint16_t QDCount; // number of question entries - uint16_t ANCount; // number of ANswer entries - uint16_t NSCount; // number of authority entries - uint16_t ARCount; // number of Additional Resource entries + uint16_t QDCount; // number of question entries + uint16_t ANCount; // number of ANswer entries + uint16_t NSCount; // number of authority entries + uint16_t ARCount; // number of Additional Resource entries }; -struct DNSQuestion -{ +struct DNSQuestion { const uint8_t* QName; - uint16_t QNameLength ; - uint16_t QType ; - uint16_t QClass ; -} ; - -class DNSServer -{ - public: - /** + uint16_t QNameLength; + uint16_t QType; + uint16_t QClass; +}; + +class DNSServer { +public: + /** * @brief Construct a new DNSServer object * by default server is configured to run in "Captive-portal" mode * it must be started with start() call to establish a listening socket - * + * */ - DNSServer(); + DNSServer(); - /** + /** * @brief Construct a new DNSServer object * builds DNS server with default parameters * @param domainName - domain name to serve */ - DNSServer(const String &domainName); - ~DNSServer(){}; // default d-tor + DNSServer(const String& domainName); + ~DNSServer(){}; // default d-tor - // Copy semantics not implemented (won't run on same UDP port anyway) - DNSServer(const DNSServer&) = delete; - DNSServer& operator=(const DNSServer&) = delete; + // Copy semantics not implemented (won't run on same UDP port anyway) + DNSServer(const DNSServer&) = delete; + DNSServer& operator=(const DNSServer&) = delete; - /** + /** * @brief stub, left for compatibility with an old version * does nothing actually - * + * */ - void processNextRequest(){}; + void processNextRequest(){}; - /** - * @brief Set the Error Reply Code for all req's not matching predifined domain - * - * @param replyCode + /** + * @brief Set the Error Reply Code for all req's not matching predefined domain + * + * @param replyCode */ - void setErrorReplyCode(const DNSReplyCode &replyCode); + void setErrorReplyCode(const DNSReplyCode& replyCode); - /** - * @brief set TTL for successfull replies - * + /** + * @brief set TTL for successful replies + * * @param ttl in seconds */ - void setTTL(const uint32_t &ttl); + void setTTL(const uint32_t& ttl); - /** + /** * @brief (re)Starts a server with current configuration or with default parameters * if it's the first call. * Defaults are: * port: 53 * domainName: any * ip: WiFi AP's IP address - * + * * @return true on success * @return false if IP or socket error */ - bool start(); + bool start(); - /** + /** * @brief (re)Starts a server with provided configuration - * + * * @return true on success * @return false if IP or socket error */ - bool start(uint16_t port, - const String &domainName, - const IPAddress &resolvedIP); + bool start(uint16_t port, + const String& domainName, + const IPAddress& resolvedIP); - /** + /** * @brief stops the server and close UDP socket - * + * */ - void stop(); + void stop(); - /** + /** * @brief returns true if DNS server runs in captive-portal mode * i.e. all requests are served with AP's ip address - * + * * @return true if catch-all mode active * @return false otherwise */ - inline bool isCaptive() const { return _domainName.isEmpty(); }; + inline bool isCaptive() const { + return _domainName.isEmpty(); + }; - /** + /** * @brief returns 'true' if server is up and UDP socket is listening for UDP req's - * + * * @return true if server is up * @return false otherwise */ - inline bool isUp() { return _udp.connected(); }; + inline bool isUp() { + return _udp.connected(); + }; - private: - AsyncUDP _udp; - uint16_t _port; - uint32_t _ttl; - DNSReplyCode _errorReplyCode; - String _domainName; - IPAddress _resolvedIP; +private: + AsyncUDP _udp; + uint16_t _port; + uint32_t _ttl; + DNSReplyCode _errorReplyCode; + String _domainName; + IPAddress _resolvedIP; - void downcaseAndRemoveWwwPrefix(String &domainName); + void downcaseAndRemoveWwwPrefix(String& domainName); - /** + /** * @brief Get the Domain Name Without Www Prefix object * scan labels in DNS packet and build a string of a domain name - * truncate any www. label if found + * truncate any www. label if found * @param start a pointer to the start of labels records in DNS packet * @param len labels length - * @return String + * @return String */ - String getDomainNameWithoutWwwPrefix(const unsigned char* start, size_t len); - inline bool requestIncludesOnlyOneQuestion(DNSHeader& dnsHeader); - void replyWithIP(AsyncUDPPacket& req, DNSHeader& dnsHeader, DNSQuestion& dnsQuestion); - inline void replyWithCustomCode(AsyncUDPPacket& req, DNSHeader& dnsHeader); - void _handleUDP(AsyncUDPPacket& pkt); + String getDomainNameWithoutWwwPrefix(const unsigned char* start, size_t len); + inline bool requestIncludesOnlyOneQuestion(DNSHeader& dnsHeader); + void replyWithIP(AsyncUDPPacket& req, DNSHeader& dnsHeader, DNSQuestion& dnsQuestion); + inline void replyWithCustomCode(AsyncUDPPacket& req, DNSHeader& dnsHeader); + void _handleUDP(AsyncUDPPacket& pkt); }; diff --git a/libraries/EEPROM/examples/eeprom_class/eeprom_class.ino b/libraries/EEPROM/examples/eeprom_class/eeprom_class.ino index 5d2961e1237..6afe39efaec 100644 --- a/libraries/EEPROM/examples/eeprom_class/eeprom_class.ino +++ b/libraries/EEPROM/examples/eeprom_class/eeprom_class.ino @@ -2,7 +2,7 @@ ESP32 eeprom_class example with EEPROM library This simple example demonstrates using EEPROM library to store different data in ESP32 Flash memory in a multiple user-defined EEPROM class objects. - + Created for arduino-esp32 on 25 Dec, 2017 by Elochukwu Ifediora (fedy0) converted to nvs by lbernstone - 06/22/2019 @@ -11,28 +11,28 @@ #include "EEPROM.h" // Instantiate eeprom objects with parameter/argument names and sizes -EEPROMClass NAMES("eeprom0"); -EEPROMClass HEIGHT("eeprom1"); -EEPROMClass AGE("eeprom2"); +EEPROMClass NAMES("eeprom0"); +EEPROMClass HEIGHT("eeprom1"); +EEPROMClass AGE("eeprom2"); void setup() { Serial.begin(115200); delay(1000); Serial.println("Testing EEPROMClass\n"); if (!NAMES.begin(0x500)) { - Serial.println("Failed to initialise NAMES"); + Serial.println("Failed to initialize NAMES"); Serial.println("Restarting..."); delay(1000); ESP.restart(); } if (!HEIGHT.begin(0x200)) { - Serial.println("Failed to initialise HEIGHT"); + Serial.println("Failed to initialize HEIGHT"); Serial.println("Restarting..."); delay(1000); ESP.restart(); } if (!AGE.begin(0x100)) { - Serial.println("Failed to initialise AGE"); + Serial.println("Failed to initialize AGE"); Serial.println("Restarting..."); delay(1000); ESP.restart(); @@ -47,28 +47,37 @@ void setup() { NAMES.writeString(0, name); HEIGHT.put(0, height); AGE.put(0, age); - Serial.print("name: "); Serial.println(name); - Serial.print("height: "); Serial.println(height); - Serial.print("age: "); Serial.println(age); + Serial.print("name: "); + Serial.println(name); + Serial.print("height: "); + Serial.println(height); + Serial.print("age: "); + Serial.println(age); Serial.println("------------------------------------\n"); // Clear variables rname[0] = '\0'; height = 0; age = 0; - Serial.print("name: "); Serial.println(rname); - Serial.print("height: "); Serial.println(height); - Serial.print("age: "); Serial.println(age); + Serial.print("name: "); + Serial.println(rname); + Serial.print("height: "); + Serial.println(height); + Serial.print("age: "); + Serial.println(age); Serial.println("------------------------------------\n"); // Read: Variables <--- EEPROM stores NAMES.get(0, rname); HEIGHT.get(0, height); AGE.get(0, age); - Serial.print("name: "); Serial.println(rname); - Serial.print("height: "); Serial.println(height); - Serial.print("age: "); Serial.println(age); - + Serial.print("name: "); + Serial.println(rname); + Serial.print("height: "); + Serial.println(height); + Serial.print("age: "); + Serial.println(age); + Serial.println("Done!"); } diff --git a/libraries/EEPROM/examples/eeprom_extra/eeprom_extra.ino b/libraries/EEPROM/examples/eeprom_extra/eeprom_extra.ino index ba062bca046..78e8b269f96 100644 --- a/libraries/EEPROM/examples/eeprom_extra/eeprom_extra.ino +++ b/libraries/EEPROM/examples/eeprom_extra/eeprom_extra.ino @@ -14,7 +14,7 @@ void setup() { Serial.begin(115200); Serial.println("\nTesting EEPROM Library\n"); if (!EEPROM.begin(1000)) { - Serial.println("Failed to initialise EEPROM"); + Serial.println("Failed to initialize EEPROM"); Serial.println("Restarting..."); delay(1000); ESP.restart(); @@ -22,38 +22,38 @@ void setup() { int address = 0; - EEPROM.writeByte(address, -128); // -2^7 + EEPROM.writeByte(address, -128); // -2^7 address += sizeof(byte); - EEPROM.writeChar(address, 'A'); // Same as writyByte and readByte + EEPROM.writeChar(address, 'A'); // Same as writyByte and readByte address += sizeof(char); - EEPROM.writeUChar(address, 255); // 2^8 - 1 + EEPROM.writeUChar(address, 255); // 2^8 - 1 address += sizeof(unsigned char); - EEPROM.writeShort(address, -32768); // -2^15 + EEPROM.writeShort(address, -32768); // -2^15 address += sizeof(short); - EEPROM.writeUShort(address, 65535); // 2^16 - 1 + EEPROM.writeUShort(address, 65535); // 2^16 - 1 address += sizeof(unsigned short); - EEPROM.writeInt(address, -2147483648); // -2^31 + EEPROM.writeInt(address, -2147483648); // -2^31 address += sizeof(int); - EEPROM.writeUInt(address, 4294967295); // 2^32 - 1 + EEPROM.writeUInt(address, 4294967295); // 2^32 - 1 address += sizeof(unsigned int); - EEPROM.writeLong(address, -2147483648); // Same as writeInt and readInt + EEPROM.writeLong(address, -2147483648); // Same as writeInt and readInt address += sizeof(long); - EEPROM.writeULong(address, 4294967295); // Same as writeUInt and readUInt + EEPROM.writeULong(address, 4294967295); // Same as writeUInt and readUInt address += sizeof(unsigned long); - int64_t value = -1223372036854775808LL; // -2^63 + int64_t value = -1223372036854775808LL; // -2^63 EEPROM.writeLong64(address, value); address += sizeof(int64_t); - uint64_t Value = 18446744073709551615ULL; // 2^64 - 1 + uint64_t Value = 18446744073709551615ULL; // 2^64 - 1 EEPROM.writeULong64(address, Value); address += sizeof(uint64_t); @@ -77,7 +77,7 @@ void setup() { // See also the general purpose writeBytes() and readBytes() for BLOB in EEPROM library EEPROM.commit(); address = 0; - + Serial.println(EEPROM.readByte(address)); address += sizeof(byte); @@ -107,14 +107,14 @@ void setup() { value = 0; value = EEPROM.readLong64(value); - Serial.printf("0x%08lX", (uint32_t)(value >> 32)); // Print High 4 bytes in HEX - Serial.printf("%08lX\n", (uint32_t)value); // Print Low 4 bytes in HEX + Serial.printf("0x%08lX", (uint32_t)(value >> 32)); // Print High 4 bytes in HEX + Serial.printf("%08lX\n", (uint32_t)value); // Print Low 4 bytes in HEX address += sizeof(int64_t); - Value = 0; // Clear Value + Value = 0; // Clear Value Value = EEPROM.readULong64(Value); - Serial.printf("0x%08lX", (uint32_t)(Value >> 32)); // Print High 4 bytes in HEX - Serial.printf("%08lX\n", (uint32_t)Value); // Print Low 4 bytes in HEX + Serial.printf("0x%08lX", (uint32_t)(Value >> 32)); // Print High 4 bytes in HEX + Serial.printf("%08lX\n", (uint32_t)Value); // Print Low 4 bytes in HEX address += sizeof(uint64_t); Serial.println(EEPROM.readFloat(address), 4); @@ -135,5 +135,4 @@ void setup() { void loop() { // put your main code here, to run repeatedly: - } diff --git a/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino b/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino index a4dbb8c3867..b93146793b0 100644 --- a/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino +++ b/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino @@ -12,25 +12,23 @@ // we're going to write to next) int addr = 0; #define EEPROM_SIZE 64 -void setup() -{ +void setup() { Serial.begin(115200); Serial.println("start..."); - if (!EEPROM.begin(EEPROM_SIZE)) - { - Serial.println("failed to initialise EEPROM"); delay(1000000); + if (!EEPROM.begin(EEPROM_SIZE)) { + Serial.println("failed to initialize EEPROM"); + delay(1000000); } Serial.println(" bytes read from Flash . Values are:"); - for (int i = 0; i < EEPROM_SIZE; i++) - { - Serial.print(byte(EEPROM.read(i))); Serial.print(" "); + for (int i = 0; i < EEPROM_SIZE; i++) { + Serial.print(byte(EEPROM.read(i))); + Serial.print(" "); } Serial.println(); Serial.println("writing random n. in memory"); } -void loop() -{ +void loop() { // need to divide by 4 because analog inputs range from // 0 to 1023 and each byte of the EEPROM can only hold a // value from 0 to 255. @@ -40,23 +38,24 @@ void loop() // these values will remain there when the board is // turned off. EEPROM.write(addr, val); - Serial.print(val); Serial.print(" "); + Serial.print(val); + Serial.print(" "); // advance to the next address. there are 512 bytes in // the EEPROM, so go back to 0 when we hit 512. // save all changes to the flash. addr = addr + 1; - if (addr == EEPROM_SIZE) - { + if (addr == EEPROM_SIZE) { Serial.println(); addr = 0; EEPROM.commit(); Serial.print(EEPROM_SIZE); Serial.println(" bytes written on Flash . Values are:"); - for (int i = 0; i < EEPROM_SIZE; i++) - { - Serial.print(byte(EEPROM.read(i))); Serial.print(" "); + for (int i = 0; i < EEPROM_SIZE; i++) { + Serial.print(byte(EEPROM.read(i))); + Serial.print(" "); } - Serial.println(); Serial.println("----------------------------------"); + Serial.println(); + Serial.println("----------------------------------"); } delay(100); diff --git a/libraries/EEPROM/keywords.txt b/libraries/EEPROM/keywords.txt index 0e2552e12c4..d14b49729f8 100644 --- a/libraries/EEPROM/keywords.txt +++ b/libraries/EEPROM/keywords.txt @@ -16,4 +16,3 @@ EEPROMClass KEYWORD1 ####################################### # Constants (LITERAL1) ####################################### - diff --git a/libraries/EEPROM/src/EEPROM.cpp b/libraries/EEPROM/src/EEPROM.cpp index 356255cbf24..0fe0c9febe1 100644 --- a/libraries/EEPROM/src/EEPROM.cpp +++ b/libraries/EEPROM/src/EEPROM.cpp @@ -29,31 +29,16 @@ #include EEPROMClass::EEPROMClass(void) - : _handle(0) - , _data(0) - , _size(0) - , _dirty(false) - , _name("eeprom") -{ + : _handle(0), _data(0), _size(0), _dirty(false), _name("eeprom") { } EEPROMClass::EEPROMClass(uint32_t sector) -// Only for compatiility, no sectors in nvs! - : _handle(0) - , _data(0) - , _size(0) - , _dirty(false) - , _name("eeprom") -{ + // Only for compatiility, no sectors in nvs! + : _handle(0), _data(0), _size(0), _dirty(false), _name("eeprom") { } EEPROMClass::EEPROMClass(const char* name) - : _handle(0) - , _data(0) - , _size(0) - , _dirty(false) - , _name(name) -{ + : _handle(0), _data(0), _size(0), _dirty(false), _name(name) { } EEPROMClass::~EEPROMClass() { @@ -62,74 +47,73 @@ EEPROMClass::~EEPROMClass() { bool EEPROMClass::begin(size_t size) { if (!size) { - return false; + return false; } esp_err_t res = nvs_open(_name, NVS_READWRITE, &_handle); if (res != ESP_OK) { - log_e("Unable to open NVS namespace: %d", res); - return false; + log_e("Unable to open NVS namespace: %d", res); + return false; } size_t key_size = 0; res = nvs_get_blob(_handle, _name, NULL, &key_size); - if(res != ESP_OK && res != ESP_ERR_NVS_NOT_FOUND) { - log_e("Unable to read NVS key: %d", res); - return false; - } - if (size < key_size) { // truncate - log_w("truncating EEPROM from %d to %d", key_size, size); - uint8_t* key_data = (uint8_t*) malloc(key_size); - if(!key_data) { - log_e("Not enough memory to truncate EEPROM!"); - return false; - } - nvs_get_blob(_handle, _name, key_data, &key_size); - nvs_set_blob(_handle, _name, key_data, size); - nvs_commit(_handle); - free(key_data); + if (res != ESP_OK && res != ESP_ERR_NVS_NOT_FOUND) { + log_e("Unable to read NVS key: %d", res); + return false; } - else if (size > key_size) { // expand or new - size_t expand_size = size - key_size; - uint8_t* expand_key = (uint8_t*) malloc(expand_size); - if(!expand_key) { - log_e("Not enough memory to expand EEPROM!"); - return false; - } - // check for adequate free space - if(nvs_set_blob(_handle, "expand", expand_key, expand_size)) { - log_e("Not enough space to expand EEPROM from %d to %d", key_size, size); - free(expand_key); - return false; - } + if (size < key_size) { // truncate + log_w("truncating EEPROM from %d to %d", key_size, size); + uint8_t* key_data = (uint8_t*)malloc(key_size); + if (!key_data) { + log_e("Not enough memory to truncate EEPROM!"); + return false; + } + nvs_get_blob(_handle, _name, key_data, &key_size); + nvs_set_blob(_handle, _name, key_data, size); + nvs_commit(_handle); + free(key_data); + } else if (size > key_size) { // expand or new + size_t expand_size = size - key_size; + uint8_t* expand_key = (uint8_t*)malloc(expand_size); + if (!expand_key) { + log_e("Not enough memory to expand EEPROM!"); + return false; + } + // check for adequate free space + if (nvs_set_blob(_handle, "expand", expand_key, expand_size)) { + log_e("Not enough space to expand EEPROM from %d to %d", key_size, size); free(expand_key); - nvs_erase_key(_handle, "expand"); - uint8_t* key_data = (uint8_t*) malloc(size); - if(!key_data) { - log_e("Not enough memory to expand EEPROM!"); - return false; - } - memset(key_data, 0xFF, size); - if(key_size) { - log_i("Expanding EEPROM from %d to %d", key_size, size); - // hold data while key is deleted - nvs_get_blob(_handle, _name, key_data, &key_size); - nvs_erase_key(_handle, _name); - } else { - log_i("New EEPROM of %d bytes", size); - } - nvs_commit(_handle); - nvs_set_blob(_handle, _name, key_data, size); - free(key_data); - nvs_commit(_handle); + return false; + } + free(expand_key); + nvs_erase_key(_handle, "expand"); + uint8_t* key_data = (uint8_t*)malloc(size); + if (!key_data) { + log_e("Not enough memory to expand EEPROM!"); + return false; + } + memset(key_data, 0xFF, size); + if (key_size) { + log_i("Expanding EEPROM from %d to %d", key_size, size); + // hold data while key is deleted + nvs_get_blob(_handle, _name, key_data, &key_size); + nvs_erase_key(_handle, _name); + } else { + log_i("New EEPROM of %d bytes", size); + } + nvs_commit(_handle); + nvs_set_blob(_handle, _name, key_data, size); + free(key_data); + nvs_commit(_handle); } if (_data) { delete[] _data; } - _data = (uint8_t*) malloc(size); - if(!_data) { + _data = (uint8_t*)malloc(size); + if (!_data) { log_e("Not enough memory for %d bytes in EEPROM", size); return false; } @@ -171,10 +155,9 @@ void EEPROMClass::write(int address, uint8_t value) { if (!_data) return; - // Optimise _dirty. Only flagged if data written is different. + // Optimize _dirty. Only flagged if data written is different. uint8_t* pData = &_data[address]; - if (*pData != value) - { + if (*pData != value) { *pData = value; _dirty = true; } @@ -203,7 +186,7 @@ bool EEPROMClass::commit() { return ret; } -uint8_t * EEPROMClass::getDataPtr() { +uint8_t* EEPROMClass::getDataPtr() { _dirty = true; return &_data[0]; } @@ -211,17 +194,15 @@ uint8_t * EEPROMClass::getDataPtr() { /* Get EEPROM total size in byte defined by the user */ -uint16_t EEPROMClass::length () -{ +uint16_t EEPROMClass::length() { return _size; } -/* +/* Convert EEPROM partition into nvs blob Call convert before you call begin */ -uint16_t EEPROMClass::convert (bool clear, const char* EEPROMname, const char* nvsname) -{ +uint16_t EEPROMClass::convert(bool clear, const char* EEPROMname, const char* nvsname) { uint16_t result = 0; const esp_partition_t* mypart = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, EEPROMname); if (mypart == NULL) { @@ -230,20 +211,20 @@ uint16_t EEPROMClass::convert (bool clear, const char* EEPROMname, const char* n } size_t size = mypart->size; - uint8_t* data = (uint8_t*) malloc(size); + uint8_t* data = (uint8_t*)malloc(size); if (!data) { log_e("Not enough memory to convert EEPROM!"); goto exit; } - if (esp_partition_read (mypart, 0, (void *) data, size) != ESP_OK) { + if (esp_partition_read(mypart, 0, (void*)data, size) != ESP_OK) { log_e("Unable to read EEPROM partition"); goto exit; } bool empty; empty = true; - for (int x=0; x maxLen) - return 0; //Maybe return part of the string instead? + return 0; //Maybe return part of the string instead? - memcpy((uint8_t*) value, _data + address, len); + memcpy((uint8_t*)value, _data + address, len); value[len] = 0; return len; } -String EEPROMClass::readString (int address) -{ +String EEPROMClass::readString(int address) { if (address < 0 || address > _size) return String(); @@ -401,110 +366,93 @@ String EEPROMClass::readString (int address) if (address + len > _size) return String(); - char value[len+1]; - memcpy((uint8_t*) value, _data + address, len); + char value[len + 1]; + memcpy((uint8_t*)value, _data + address, len); value[len] = 0; return String(value); } -size_t EEPROMClass::readBytes (int address, void* value, size_t maxLen) -{ +size_t EEPROMClass::readBytes(int address, void* value, size_t maxLen) { if (!value || !maxLen) return 0; if (address < 0 || address + maxLen > _size) return 0; - memcpy((void*) value, _data + address, maxLen); + memcpy((void*)value, _data + address, maxLen); return maxLen; } -template T EEPROMClass::readAll (int address, T &value) -{ +template T EEPROMClass::readAll(int address, T& value) { if (address < 0 || address + sizeof(T) > _size) return value; - memcpy((uint8_t*) &value, _data + address, sizeof(T)); + memcpy((uint8_t*)&value, _data + address, sizeof(T)); return value; } /* Write 'value' to 'address' */ -size_t EEPROMClass::writeByte (int address, uint8_t value) -{ - return EEPROMClass::writeAll (address, value); +size_t EEPROMClass::writeByte(int address, uint8_t value) { + return EEPROMClass::writeAll(address, value); } -size_t EEPROMClass::writeChar (int address, int8_t value) -{ - return EEPROMClass::writeAll (address, value); +size_t EEPROMClass::writeChar(int address, int8_t value) { + return EEPROMClass::writeAll(address, value); } -size_t EEPROMClass::writeUChar (int address, uint8_t value) -{ - return EEPROMClass::writeAll (address, value); +size_t EEPROMClass::writeUChar(int address, uint8_t value) { + return EEPROMClass::writeAll(address, value); } -size_t EEPROMClass::writeShort (int address, int16_t value) -{ - return EEPROMClass::writeAll (address, value); +size_t EEPROMClass::writeShort(int address, int16_t value) { + return EEPROMClass::writeAll(address, value); } -size_t EEPROMClass::writeUShort (int address, uint16_t value) -{ - return EEPROMClass::writeAll (address, value); +size_t EEPROMClass::writeUShort(int address, uint16_t value) { + return EEPROMClass::writeAll(address, value); } -size_t EEPROMClass::writeInt (int address, int32_t value) -{ - return EEPROMClass::writeAll (address, value); +size_t EEPROMClass::writeInt(int address, int32_t value) { + return EEPROMClass::writeAll(address, value); } -size_t EEPROMClass::writeUInt (int address, uint32_t value) -{ - return EEPROMClass::writeAll (address, value); +size_t EEPROMClass::writeUInt(int address, uint32_t value) { + return EEPROMClass::writeAll(address, value); } -size_t EEPROMClass::writeLong (int address, int32_t value) -{ - return EEPROMClass::writeAll (address, value); +size_t EEPROMClass::writeLong(int address, int32_t value) { + return EEPROMClass::writeAll(address, value); } -size_t EEPROMClass::writeULong (int address, uint32_t value) -{ - return EEPROMClass::writeAll (address, value); +size_t EEPROMClass::writeULong(int address, uint32_t value) { + return EEPROMClass::writeAll(address, value); } -size_t EEPROMClass::writeLong64 (int address, int64_t value) -{ - return EEPROMClass::writeAll (address, value); +size_t EEPROMClass::writeLong64(int address, int64_t value) { + return EEPROMClass::writeAll(address, value); } -size_t EEPROMClass::writeULong64 (int address, uint64_t value) -{ - return EEPROMClass::writeAll (address, value); +size_t EEPROMClass::writeULong64(int address, uint64_t value) { + return EEPROMClass::writeAll(address, value); } -size_t EEPROMClass::writeFloat (int address, float_t value) -{ - return EEPROMClass::writeAll (address, value); +size_t EEPROMClass::writeFloat(int address, float_t value) { + return EEPROMClass::writeAll(address, value); } -size_t EEPROMClass::writeDouble (int address, double_t value) -{ - return EEPROMClass::writeAll (address, value); +size_t EEPROMClass::writeDouble(int address, double_t value) { + return EEPROMClass::writeAll(address, value); } -size_t EEPROMClass::writeBool (int address, bool value) -{ +size_t EEPROMClass::writeBool(int address, bool value) { int8_t Bool; value ? Bool = 1 : Bool = 0; - return EEPROMClass::writeAll (address, Bool); + return EEPROMClass::writeAll(address, Bool); } -size_t EEPROMClass::writeString (int address, const char* value) -{ +size_t EEPROMClass::writeString(int address, const char* value) { if (!value) return 0; @@ -519,38 +467,35 @@ size_t EEPROMClass::writeString (int address, const char* value) if (address + len > _size) return 0; - memcpy(_data + address, (const uint8_t*) value, len + 1); + memcpy(_data + address, (const uint8_t*)value, len + 1); _dirty = true; return strlen(value); } -size_t EEPROMClass::writeString (int address, String value) -{ - return EEPROMClass::writeString (address, value.c_str()); +size_t EEPROMClass::writeString(int address, String value) { + return EEPROMClass::writeString(address, value.c_str()); } -size_t EEPROMClass::writeBytes (int address, const void* value, size_t len) -{ +size_t EEPROMClass::writeBytes(int address, const void* value, size_t len) { if (!value || !len) return 0; if (address < 0 || address + len > _size) return 0; - memcpy(_data + address, (const void*) value, len); + memcpy(_data + address, (const void*)value, len); _dirty = true; return len; } -template T EEPROMClass::writeAll (int address, const T &value) -{ +template T EEPROMClass::writeAll(int address, const T& value) { if (address < 0 || address + sizeof(T) > _size) return value; - memcpy(_data + address, (const uint8_t*) &value, sizeof(T)); + memcpy(_data + address, (const uint8_t*)&value, sizeof(T)); _dirty = true; - return sizeof (value); + return sizeof(value); } #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM) diff --git a/libraries/EEPROM/src/EEPROM.h b/libraries/EEPROM/src/EEPROM.h index b4e849f536b..b2599fd8126 100644 --- a/libraries/EEPROM/src/EEPROM.h +++ b/libraries/EEPROM/src/EEPROM.h @@ -33,85 +33,85 @@ typedef uint32_t nvs_handle; class EEPROMClass { - public: - EEPROMClass(uint32_t sector); - EEPROMClass(const char* name); - EEPROMClass(void); - ~EEPROMClass(void); - - bool begin(size_t size); - uint8_t read(int address); - void write(int address, uint8_t val); - uint16_t length(); - bool commit(); - void end(); - - uint8_t * getDataPtr(); - uint16_t convert(bool clear, const char* EEPROMname = "eeprom", const char* nvsname = "eeprom"); - - template - T &get(int address, T &t) { - if (address < 0 || address + sizeof(T) > _size) - return t; - - memcpy((uint8_t*) &t, _data + address, sizeof(T)); +public: + EEPROMClass(uint32_t sector); + EEPROMClass(const char* name); + EEPROMClass(void); + ~EEPROMClass(void); + + bool begin(size_t size); + uint8_t read(int address); + void write(int address, uint8_t val); + uint16_t length(); + bool commit(); + void end(); + + uint8_t* getDataPtr(); + uint16_t convert(bool clear, const char* EEPROMname = "eeprom", const char* nvsname = "eeprom"); + + template + T& get(int address, T& t) { + if (address < 0 || address + sizeof(T) > _size) return t; - } - template - const T &put(int address, const T &t) { - if (address < 0 || address + sizeof(T) > _size) - return t; + memcpy((uint8_t*)&t, _data + address, sizeof(T)); + return t; + } - memcpy(_data + address, (const uint8_t*) &t, sizeof(T)); - _dirty = true; + template + const T& put(int address, const T& t) { + if (address < 0 || address + sizeof(T) > _size) return t; - } - - uint8_t readByte(int address); - int8_t readChar(int address); - uint8_t readUChar(int address); - int16_t readShort(int address); - uint16_t readUShort(int address); - int32_t readInt(int address); - uint32_t readUInt(int address); - int32_t readLong(int address); - uint32_t readULong(int address); - int64_t readLong64(int address); - uint64_t readULong64(int address); - float_t readFloat(int address); - double_t readDouble(int address); - bool readBool(int address); - size_t readString(int address, char* value, size_t maxLen); - String readString(int address); - size_t readBytes(int address, void * value, size_t maxLen); - template T readAll (int address, T &); - - size_t writeByte(int address, uint8_t value); - size_t writeChar(int address, int8_t value); - size_t writeUChar(int address, uint8_t value); - size_t writeShort(int address, int16_t value); - size_t writeUShort(int address, uint16_t value); - size_t writeInt(int address, int32_t value); - size_t writeUInt(int address, uint32_t value); - size_t writeLong(int address, int32_t value); - size_t writeULong(int address, uint32_t value); - size_t writeLong64(int address, int64_t value); - size_t writeULong64(int address, uint64_t value); - size_t writeFloat(int address, float_t value); - size_t writeDouble(int address, double_t value); - size_t writeBool(int address, bool value); - size_t writeString(int address, const char* value); - size_t writeString(int address, String value); - size_t writeBytes(int address, const void* value, size_t len); - template T writeAll (int address, const T &); - - protected: - nvs_handle _handle; - uint8_t* _data; - size_t _size; - bool _dirty; - const char* _name; + + memcpy(_data + address, (const uint8_t*)&t, sizeof(T)); + _dirty = true; + return t; + } + + uint8_t readByte(int address); + int8_t readChar(int address); + uint8_t readUChar(int address); + int16_t readShort(int address); + uint16_t readUShort(int address); + int32_t readInt(int address); + uint32_t readUInt(int address); + int32_t readLong(int address); + uint32_t readULong(int address); + int64_t readLong64(int address); + uint64_t readULong64(int address); + float_t readFloat(int address); + double_t readDouble(int address); + bool readBool(int address); + size_t readString(int address, char* value, size_t maxLen); + String readString(int address); + size_t readBytes(int address, void* value, size_t maxLen); + template T readAll(int address, T&); + + size_t writeByte(int address, uint8_t value); + size_t writeChar(int address, int8_t value); + size_t writeUChar(int address, uint8_t value); + size_t writeShort(int address, int16_t value); + size_t writeUShort(int address, uint16_t value); + size_t writeInt(int address, int32_t value); + size_t writeUInt(int address, uint32_t value); + size_t writeLong(int address, int32_t value); + size_t writeULong(int address, uint32_t value); + size_t writeLong64(int address, int64_t value); + size_t writeULong64(int address, uint64_t value); + size_t writeFloat(int address, float_t value); + size_t writeDouble(int address, double_t value); + size_t writeBool(int address, bool value); + size_t writeString(int address, const char* value); + size_t writeString(int address, String value); + size_t writeBytes(int address, const void* value, size_t len); + template T writeAll(int address, const T&); + +protected: + nvs_handle _handle; + uint8_t* _data; + size_t _size; + bool _dirty; + const char* _name; }; #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM) diff --git a/libraries/ESP32/examples/AnalogOut/LEDCFade/LEDCFade.ino b/libraries/ESP32/examples/AnalogOut/LEDCFade/LEDCFade.ino index 19c2be3428d..223352629ca 100644 --- a/libraries/ESP32/examples/AnalogOut/LEDCFade/LEDCFade.ino +++ b/libraries/ESP32/examples/AnalogOut/LEDCFade/LEDCFade.ino @@ -6,32 +6,31 @@ CONDITIONS OF ANY KIND, either express or implied. */ -// use 12 bit precission for LEDC timer -#define LEDC_TIMER_12_BIT 12 +// use 12 bit precision for LEDC timer +#define LEDC_TIMER_12_BIT 12 // use 5000 Hz as a LEDC base frequency -#define LEDC_BASE_FREQ 5000 +#define LEDC_BASE_FREQ 5000 // fade LED PIN (replace with LED_BUILTIN constant for built-in LED) -#define LED_PIN 4 +#define LED_PIN 4 // define starting duty, target duty and maximum fade time -#define LEDC_START_DUTY (0) -#define LEDC_TARGET_DUTY (4095) -#define LEDC_FADE_TIME (3000) +#define LEDC_START_DUTY (0) +#define LEDC_TARGET_DUTY (4095) +#define LEDC_FADE_TIME (3000) -bool fade_ended = false; // status of LED fade +bool fade_ended = false; // status of LED fade bool fade_on = true; -void ARDUINO_ISR_ATTR LED_FADE_ISR() -{ +void ARDUINO_ISR_ATTR LED_FADE_ISR() { fade_ended = true; } void setup() { // Initialize serial communication at 115200 bits per second: Serial.begin(115200); - while(!Serial) delay(10); + while (!Serial) delay(10); // Setup timer with given frequency, resolution and attach it to a led pin with auto-selected channel ledcAttach(LED_PIN, LEDC_BASE_FREQ, LEDC_TIMER_12_BIT); @@ -44,26 +43,25 @@ void setup() { delay(LEDC_FADE_TIME); // Setup and start fade off led and use ISR (duty from 4095 to 0) - ledcFadeWithInterrupt(LED_PIN, LEDC_TARGET_DUTY, LEDC_START_DUTY, LEDC_FADE_TIME, LED_FADE_ISR); + ledcFadeWithInterrupt(LED_PIN, LEDC_TARGET_DUTY, LEDC_START_DUTY, LEDC_FADE_TIME, LED_FADE_ISR); Serial.println("LED Fade off started."); } void loop() { // Check if fade_ended flag was set to true in ISR - if(fade_ended){ + if (fade_ended) { Serial.println("LED fade ended"); fade_ended = false; // Check if last fade was fade on - if(fade_on){ - ledcFadeWithInterrupt(LED_PIN, LEDC_START_DUTY, LEDC_TARGET_DUTY, LEDC_FADE_TIME, LED_FADE_ISR); + if (fade_on) { + ledcFadeWithInterrupt(LED_PIN, LEDC_START_DUTY, LEDC_TARGET_DUTY, LEDC_FADE_TIME, LED_FADE_ISR); Serial.println("LED Fade off started."); fade_on = false; - } - else { - ledcFadeWithInterrupt(LED_PIN, LEDC_TARGET_DUTY, LEDC_START_DUTY, LEDC_FADE_TIME, LED_FADE_ISR); + } else { + ledcFadeWithInterrupt(LED_PIN, LEDC_TARGET_DUTY, LEDC_START_DUTY, LEDC_FADE_TIME, LED_FADE_ISR); Serial.println("LED Fade on started."); fade_on = true; } } -} \ No newline at end of file +} diff --git a/libraries/ESP32/examples/AnalogOut/LEDCSoftwareFade/LEDCSoftwareFade.ino b/libraries/ESP32/examples/AnalogOut/LEDCSoftwareFade/LEDCSoftwareFade.ino index 239e37f3615..c605a89bc0b 100644 --- a/libraries/ESP32/examples/AnalogOut/LEDCSoftwareFade/LEDCSoftwareFade.ino +++ b/libraries/ESP32/examples/AnalogOut/LEDCSoftwareFade/LEDCSoftwareFade.ino @@ -10,17 +10,17 @@ This example code is in the public domain. */ -// use 12 bit precission for LEDC timer -#define LEDC_TIMER_12_BIT 12 +// use 12 bit precision for LEDC timer +#define LEDC_TIMER_12_BIT 12 // use 5000 Hz as a LEDC base frequency -#define LEDC_BASE_FREQ 5000 +#define LEDC_BASE_FREQ 5000 // fade LED PIN (replace with LED_BUILTIN constant for built-in LED) -#define LED_PIN 5 +#define LED_PIN 5 -int brightness = 0; // how bright the LED is -int fadeAmount = 5; // how many points to fade the LED by +int brightness = 0; // how bright the LED is +int fadeAmount = 5; // how many points to fade the LED by // Arduino like analogWrite // value has to be between 0 and valueMax @@ -50,4 +50,4 @@ void loop() { } // wait for 30 milliseconds to see the dimming effect delay(30); -} \ No newline at end of file +} diff --git a/libraries/ESP32/examples/AnalogOut/SigmaDelta/SigmaDelta.ino b/libraries/ESP32/examples/AnalogOut/SigmaDelta/SigmaDelta.ino index 261263fa98e..d244a4ee61f 100644 --- a/libraries/ESP32/examples/AnalogOut/SigmaDelta/SigmaDelta.ino +++ b/libraries/ESP32/examples/AnalogOut/SigmaDelta/SigmaDelta.ino @@ -1,16 +1,14 @@ -void setup() -{ - //setup on pin 18 with frequency 312500 Hz - sigmaDeltaAttach(18, 312500); - //set pin 18 to off - sigmaDeltaWrite(18, 0); +void setup() { + //setup on pin 18 with frequency 312500 Hz + sigmaDeltaAttach(18, 312500); + //set pin 18 to off + sigmaDeltaWrite(18, 0); } -void loop() -{ - //slowly ramp-up the value - //will overflow at 256 - static uint8_t i = 0; - sigmaDeltaWrite(18, i++); - delay(100); +void loop() { + //slowly ramp-up the value + //will overflow at 256 + static uint8_t i = 0; + sigmaDeltaWrite(18, i++); + delay(100); } diff --git a/libraries/ESP32/examples/AnalogOut/ledcFrequency/ledcFrequency.ino b/libraries/ESP32/examples/AnalogOut/ledcFrequency/ledcFrequency.ino index 772e5da7e39..f81def389fc 100644 --- a/libraries/ESP32/examples/AnalogOut/ledcFrequency/ledcFrequency.ino +++ b/libraries/ESP32/examples/AnalogOut/ledcFrequency/ledcFrequency.ino @@ -14,7 +14,7 @@ #define PIN 2 void setup() { - ledcAttach(PIN,1000,8); + ledcAttach(PIN, 1000, 8); uint32_t min_frequency; uint32_t max_frequency; @@ -24,56 +24,55 @@ void setup() { uint32_t min_freq_array[SOC_LEDC_TIMER_BIT_WIDTH]; // Find Max Frequency - for(uint8_t resolution = 1; resolution <= SOC_LEDC_TIMER_BIT_WIDTH; ++resolution){ - max_freq_array[resolution-1] = 0; + for (uint8_t resolution = 1; resolution <= SOC_LEDC_TIMER_BIT_WIDTH; ++resolution) { + max_freq_array[resolution - 1] = 0; min_frequency = 0; max_frequency = UINT32_MAX; successful_frequency = 0; - while(min_frequency != max_frequency && min_frequency+1 != max_frequency){ - frequency = min_frequency + ((max_frequency-min_frequency)/2); - if(ledcChangeFrequency(PIN, frequency, resolution)){ + while (min_frequency != max_frequency && min_frequency + 1 != max_frequency) { + frequency = min_frequency + ((max_frequency - min_frequency) / 2); + if (ledcChangeFrequency(PIN, frequency, resolution)) { min_frequency = frequency; successful_frequency = frequency; - }else{ + } else { max_frequency = frequency; } - } // while not found the maximum - max_freq_array[resolution-1] = successful_frequency; - } // for all resolutions + } // while not found the maximum + max_freq_array[resolution - 1] = successful_frequency; + } // for all resolutions // Find Min Frequency - for(uint8_t resolution = 1; resolution <= SOC_LEDC_TIMER_BIT_WIDTH; ++resolution){ - min_freq_array[resolution-1] = 0; + for (uint8_t resolution = 1; resolution <= SOC_LEDC_TIMER_BIT_WIDTH; ++resolution) { + min_freq_array[resolution - 1] = 0; min_frequency = 0; - max_frequency = max_freq_array[resolution-1]; + max_frequency = max_freq_array[resolution - 1]; successful_frequency = max_frequency; - while(min_frequency != max_frequency && min_frequency+1 != max_frequency){ - frequency = min_frequency + ((max_frequency-min_frequency)/2); - if(ledcChangeFrequency(PIN, frequency, resolution)){ + while (min_frequency != max_frequency && min_frequency + 1 != max_frequency) { + frequency = min_frequency + ((max_frequency - min_frequency) / 2); + if (ledcChangeFrequency(PIN, frequency, resolution)) { max_frequency = frequency; successful_frequency = frequency; - }else{ + } else { min_frequency = frequency; } - } // while not found the maximum - min_freq_array[resolution-1] = successful_frequency; - } // for all resolutions + } // while not found the maximum + min_freq_array[resolution - 1] = successful_frequency; + } // for all resolutions printf("Bit resolution | Min Frequency [Hz] | Max Frequency [Hz]\n"); - for(uint8_t r = 1; r <= SOC_LEDC_TIMER_BIT_WIDTH; ++r){ + for (uint8_t r = 1; r <= SOC_LEDC_TIMER_BIT_WIDTH; ++r) { size_t max_len = std::to_string(UINT32_MAX).length(); printf(" %s%d | %s%lu | %s%lu\n", - std::string (2 - std::to_string(r).length(), ' ').c_str(), r, - std::string (max_len - std::to_string(min_freq_array[r-1]).length(), ' ').c_str(), - min_freq_array[r-1], - std::string (max_len - std::to_string(max_freq_array[r-1]).length(), ' ').c_str(), - max_freq_array[r-1]); + std::string(2 - std::to_string(r).length(), ' ').c_str(), r, + std::string(max_len - std::to_string(min_freq_array[r - 1]).length(), ' ').c_str(), + min_freq_array[r - 1], + std::string(max_len - std::to_string(max_freq_array[r - 1]).length(), ' ').c_str(), + max_freq_array[r - 1]); } ledcDetach(PIN); } -void loop() -{ +void loop() { delay(1000); } diff --git a/libraries/ESP32/examples/AnalogOut/ledcWrite_RGB/ledcWrite_RGB.ino b/libraries/ESP32/examples/AnalogOut/ledcWrite_RGB/ledcWrite_RGB.ino index 0135ab1d0c1..a81a929261a 100644 --- a/libraries/ESP32/examples/AnalogOut/ledcWrite_RGB/ledcWrite_RGB.ino +++ b/libraries/ESP32/examples/AnalogOut/ledcWrite_RGB/ledcWrite_RGB.ino @@ -1,40 +1,38 @@ /* ledcWrite_RGB.ino - Runs through the full 255 color spectrum for an rgb led + Runs through the full 255 color spectrum for an rgb led Demonstrate ledcWrite functionality for driving leds with PWM on ESP32 - + This example code is in the public domain. - + Some basic modifications were made by vseven, mostly commenting. */ - + // Set up the rgb led names uint8_t ledR = 0; uint8_t ledG = 2; -uint8_t ledB = 4; +uint8_t ledB = 4; -const boolean invert = true; // set true if common anode, false if common cathode +const boolean invert = true; // set true if common anode, false if common cathode -uint8_t color = 0; // a value from 0 to 255 representing the hue -uint32_t R, G, B; // the Red Green and Blue color components +uint8_t color = 0; // a value from 0 to 255 representing the hue +uint32_t R, G, B; // the Red Green and Blue color components uint8_t brightness = 255; // 255 is maximum brightness, but can be changed. Might need 256 for common anode to fully turn off. // the setup routine runs once when you press reset: -void setup() -{ +void setup() { Serial.begin(115200); - delay(10); - - // Initialize pins as LEDC channels + delay(10); + + // Initialize pins as LEDC channels // resolution 1-16 bits, freq limits depend on resolution, channel is automatically selected - ledcAttach(ledR, 12000, 8); // 12 kHz PWM, 8-bit resolution + ledcAttach(ledR, 12000, 8); // 12 kHz PWM, 8-bit resolution ledcAttach(ledG, 12000, 8); ledcAttach(ledB, 12000, 8); } // void loop runs over and over again -void loop() -{ +void loop() { Serial.println("Send all LEDs a 255 and wait 2 seconds."); // If your RGB LED turns off instead of on here you should check if the LED is common anode or cathode. // If it doesn't fully turn off and is common anode try using 256. @@ -47,77 +45,74 @@ void loop() ledcWrite(ledG, 0); ledcWrite(ledB, 0); delay(2000); - + Serial.println("Starting color fade loop."); - - for (color = 0; color < 255; color++) { // Slew through the color spectrum - - hueToRGB(color, brightness); // call function to convert hue to RGB - - // write the RGB values to the pins - ledcWrite(ledR, R); // write red component to channel 1, etc. - ledcWrite(ledG, G); - ledcWrite(ledB, B); - - delay(100); // full cycle of rgb over 256 colors takes 26 seconds - } - + + for (color = 0; color < 255; color++) { // Slew through the color spectrum + + hueToRGB(color, brightness); // call function to convert hue to RGB + + // write the RGB values to the pins + ledcWrite(ledR, R); // write red component to channel 1, etc. + ledcWrite(ledG, G); + ledcWrite(ledB, B); + + delay(100); // full cycle of rgb over 256 colors takes 26 seconds + } } // Courtesy http://www.instructables.com/id/How-to-Use-an-RGB-LED/?ALLSTEPS // function to convert a color to its Red, Green, and Blue components. -void hueToRGB(uint8_t hue, uint8_t brightness) -{ - uint16_t scaledHue = (hue * 6); - uint8_t segment = scaledHue / 256; // segment 0 to 5 around the - // color wheel - uint16_t segmentOffset = - scaledHue - (segment * 256); // position within the segment - - uint8_t complement = 0; - uint16_t prev = (brightness * ( 255 - segmentOffset)) / 256; - uint16_t next = (brightness * segmentOffset) / 256; - - if(invert) - { - brightness = 255 - brightness; - complement = 255; - prev = 255 - prev; - next = 255 - next; - } - - switch(segment ) { - case 0: // red - R = brightness; - G = next; - B = complement; - break; - case 1: // yellow - R = prev; - G = brightness; - B = complement; - break; - case 2: // green - R = complement; - G = brightness; - B = next; - break; - case 3: // cyan - R = complement; - G = prev; - B = brightness; - break; - case 4: // blue - R = next; - G = complement; - B = brightness; - break; - case 5: // magenta +void hueToRGB(uint8_t hue, uint8_t brightness) { + uint16_t scaledHue = (hue * 6); + uint8_t segment = scaledHue / 256; // segment 0 to 5 around the + // color wheel + uint16_t segmentOffset = + scaledHue - (segment * 256); // position within the segment + + uint8_t complement = 0; + uint16_t prev = (brightness * (255 - segmentOffset)) / 256; + uint16_t next = (brightness * segmentOffset) / 256; + + if (invert) { + brightness = 255 - brightness; + complement = 255; + prev = 255 - prev; + next = 255 - next; + } + + switch (segment) { + case 0: // red + R = brightness; + G = next; + B = complement; + break; + case 1: // yellow + R = prev; + G = brightness; + B = complement; + break; + case 2: // green + R = complement; + G = brightness; + B = next; + break; + case 3: // cyan + R = complement; + G = prev; + B = brightness; + break; + case 4: // blue + R = next; + G = complement; + B = brightness; + break; + case 5: // magenta default: - R = brightness; - G = complement; - B = prev; - break; - } + R = brightness; + G = complement; + B = prev; + break; + } } diff --git a/libraries/ESP32/examples/AnalogRead/AnalogRead.ino b/libraries/ESP32/examples/AnalogRead/AnalogRead.ino index 647e16ba8bd..f887305bd31 100644 --- a/libraries/ESP32/examples/AnalogRead/AnalogRead.ino +++ b/libraries/ESP32/examples/AnalogRead/AnalogRead.ino @@ -1,7 +1,7 @@ void setup() { // initialize serial communication at 115200 bits per second: Serial.begin(115200); - + //set the resolution to 12 bits (0-4095) analogReadResolution(12); } @@ -10,10 +10,10 @@ void loop() { // read the analog / millivolts value for pin 2: int analogValue = analogRead(2); int analogVolts = analogReadMilliVolts(2); - + // print out the values you read: - Serial.printf("ADC analog value = %d\n",analogValue); - Serial.printf("ADC millivolts value = %d\n",analogVolts); - + Serial.printf("ADC analog value = %d\n", analogValue); + Serial.printf("ADC millivolts value = %d\n", analogVolts); + delay(100); // delay in between reads for clear read from serial } diff --git a/libraries/ESP32/examples/AnalogReadContinuous/AnalogReadContinuous.ino b/libraries/ESP32/examples/AnalogReadContinuous/AnalogReadContinuous.ino index c0928318fb6..8457ae1b2c2 100644 --- a/libraries/ESP32/examples/AnalogReadContinuous/AnalogReadContinuous.ino +++ b/libraries/ESP32/examples/AnalogReadContinuous/AnalogReadContinuous.ino @@ -4,9 +4,9 @@ // Declare array of ADC pins that will be used for ADC Continuous mode - ONLY ADC1 pins are supported // Number of selected pins can be from 1 to ALL ADC1 pins. #ifdef CONFIG_IDF_TARGET_ESP32 -uint8_t adc_pins[] = {36, 39, 34, 35}; //some of ADC1 pins for ESP32 +uint8_t adc_pins[] = { 36, 39, 34, 35 }; //some of ADC1 pins for ESP32 #else -uint8_t adc_pins[] = {1, 2, 3, 4}; //ADC1 common pins for ESP32S2/S3 + ESP32C3/C6 + ESP32H2 +uint8_t adc_pins[] = { 1, 2, 3, 4 }; //ADC1 common pins for ESP32S2/S3 + ESP32C3/C6 + ESP32H2 #endif // Calculate how many pins are declared in the array - needed as input for the setup function of ADC Continuous @@ -16,7 +16,7 @@ uint8_t adc_pins_count = sizeof(adc_pins) / sizeof(uint8_t); volatile bool adc_coversion_done = false; // Result structure for ADC Continuous reading -adc_continuos_data_t * result = NULL; +adc_continuos_data_t* result = NULL; // ISR Function that will be triggered when ADC conversion is done void ARDUINO_ISR_ATTR adcComplete() { @@ -24,48 +24,47 @@ void ARDUINO_ISR_ATTR adcComplete() { } void setup() { - // Initialize serial communication at 115200 bits per second: - Serial.begin(115200); + // Initialize serial communication at 115200 bits per second: + Serial.begin(115200); - // Optional for ESP32: Set the resolution to 9-12 bits (default is 12 bits) - analogContinuousSetWidth(12); + // Optional for ESP32: Set the resolution to 9-12 bits (default is 12 bits) + analogContinuousSetWidth(12); - // Optional: Set different attenaution (default is ADC_11db) - analogContinuousSetAtten(ADC_11db); + // Optional: Set different attenaution (default is ADC_11db) + analogContinuousSetAtten(ADC_11db); - // Setup ADC Continuous with following input: - // array of pins, count of the pins, how many conversions per pin in one cycle will happen, sampling frequency, callback function - analogContinuous(adc_pins, adc_pins_count, CONVERSIONS_PER_PIN, 20000, &adcComplete); + // Setup ADC Continuous with following input: + // array of pins, count of the pins, how many conversions per pin in one cycle will happen, sampling frequency, callback function + analogContinuous(adc_pins, adc_pins_count, CONVERSIONS_PER_PIN, 20000, &adcComplete); - // Start ADC Continuous conversions - analogContinuousStart(); + // Start ADC Continuous conversions + analogContinuousStart(); } void loop() { - // Check if conversion is done and try to read data - if (adc_coversion_done == true) { - // Set ISR flag back to false - adc_coversion_done = false; - // Read data from ADC - if (analogContinuousRead(&result, 0)) { + // Check if conversion is done and try to read data + if (adc_coversion_done == true) { + // Set ISR flag back to false + adc_coversion_done = false; + // Read data from ADC + if (analogContinuousRead(&result, 0)) { - // Optional: Stop ADC Continuous conversions to have more time to process (print) the data - analogContinuousStop(); + // Optional: Stop ADC Continuous conversions to have more time to process (print) the data + analogContinuousStop(); - for (int i = 0; i < adc_pins_count; i++) { - Serial.printf("\nADC PIN %d data:", result[i].pin); - Serial.printf("\n Avg raw value = %d", result[i].avg_read_raw); - Serial.printf("\n Avg milivolts value = %d", result[i].avg_read_mvolts); - } + for (int i = 0; i < adc_pins_count; i++) { + Serial.printf("\nADC PIN %d data:", result[i].pin); + Serial.printf("\n Avg raw value = %d", result[i].avg_read_raw); + Serial.printf("\n Avg millivolts value = %d", result[i].avg_read_mvolts); + } - // Delay for better readability of ADC data - delay(1000); + // Delay for better readability of ADC data + delay(1000); - // Optional: If ADC was stopped, start ADC conversions and wait for callback function to set adc_coversion_done flag to true - analogContinuousStart(); - } - else { - Serial.println("Error occured during reading data. Set Core Debug Level to error or lower for more informations."); - } + // Optional: If ADC was stopped, start ADC conversions and wait for callback function to set adc_coversion_done flag to true + analogContinuousStart(); + } else { + Serial.println("Error occurred during reading data. Set Core Debug Level to error or lower for more information."); } + } } diff --git a/libraries/ESP32/examples/ArduinoStackSize/ArduinoStackSize.ino b/libraries/ESP32/examples/ArduinoStackSize/ArduinoStackSize.ino index 73c42023591..e26d3d866c0 100644 --- a/libraries/ESP32/examples/ArduinoStackSize/ArduinoStackSize.ino +++ b/libraries/ESP32/examples/ArduinoStackSize/ArduinoStackSize.ino @@ -17,7 +17,7 @@ // This sets Arduino Stack Size - comment this line to use default 8K stack size -SET_LOOP_TASK_STACK_SIZE(16*1024); // 16KB +SET_LOOP_TASK_STACK_SIZE(16 * 1024); // 16KB void setup() { Serial.begin(115200); diff --git a/libraries/ESP32/examples/CI/CIBoardsTest/CIBoardsTest.ino b/libraries/ESP32/examples/CI/CIBoardsTest/CIBoardsTest.ino index 6b2faa86120..748deaa4e99 100644 --- a/libraries/ESP32/examples/CI/CIBoardsTest/CIBoardsTest.ino +++ b/libraries/ESP32/examples/CI/CIBoardsTest/CIBoardsTest.ino @@ -24,22 +24,22 @@ void loop() { Wire.write(0xFF); // data to write (if writing) Wire.endTransmission(); - Wire.requestFrom(0x68, 1); // number of bytes to read + Wire.requestFrom(0x68, 1); // number of bytes to read while (Wire.available()) { Serial.println(Wire.read()); } // SPI read/write - digitalWrite(SS, LOW); // select slave device - SPI.transfer(0x01); // data to write - digitalWrite(SS, HIGH); // deselect slave device + digitalWrite(SS, LOW); // select slave device + SPI.transfer(0x01); // data to write + digitalWrite(SS, HIGH); // deselect slave device - digitalWrite(SS, LOW); // select slave device - byte data = SPI.transfer(0x00);// data to read - digitalWrite(SS, HIGH); // deselect slave device + digitalWrite(SS, LOW); // select slave device + byte data = SPI.transfer(0x00); // data to read + digitalWrite(SS, HIGH); // deselect slave device Serial.println(data); - delay(1000); // wait for 1 second before repeating loop + delay(1000); // wait for 1 second before repeating loop } diff --git a/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino b/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino index 354ae68c0c7..8040eabb78f 100644 --- a/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino +++ b/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino @@ -7,14 +7,14 @@ // Partial images will be transmitted if image exceeds buffer size // // You must select partition scheme from the board menu that has at least 3MB APP space. -// Face Recognition is DISABLED for ESP32 and ESP32-S2, because it takes up from 15 +// Face Recognition is DISABLED for ESP32 and ESP32-S2, because it takes up from 15 // seconds to process single frame. Face Detection is ENABLED if PSRAM is enabled as well // =================== // Select camera model // =================== //#define CAMERA_MODEL_WROVER_KIT // Has PSRAM -#define CAMERA_MODEL_ESP_EYE // Has PSRAM +#define CAMERA_MODEL_ESP_EYE // Has PSRAM //#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM //#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM //#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM @@ -67,17 +67,17 @@ void setup() { config.pin_reset = RESET_GPIO_NUM; config.xclk_freq_hz = 20000000; config.frame_size = FRAMESIZE_UXGA; - config.pixel_format = PIXFORMAT_JPEG; // for streaming + config.pixel_format = PIXFORMAT_JPEG; // for streaming //config.pixel_format = PIXFORMAT_RGB565; // for face detection/recognition config.grab_mode = CAMERA_GRAB_WHEN_EMPTY; config.fb_location = CAMERA_FB_IN_PSRAM; config.jpeg_quality = 12; config.fb_count = 1; - + // if PSRAM IC present, init with UXGA resolution and higher JPEG quality // for larger pre-allocated frame buffer. - if(config.pixel_format == PIXFORMAT_JPEG){ - if(psramFound()){ + if (config.pixel_format == PIXFORMAT_JPEG) { + if (psramFound()) { config.jpeg_quality = 10; config.fb_count = 2; config.grab_mode = CAMERA_GRAB_LATEST; @@ -106,15 +106,15 @@ void setup() { return; } - sensor_t * s = esp_camera_sensor_get(); + sensor_t* s = esp_camera_sensor_get(); // initial sensors are flipped vertically and colors are a bit saturated if (s->id.PID == OV3660_PID) { - s->set_vflip(s, 1); // flip it back - s->set_brightness(s, 1); // up the brightness just a bit - s->set_saturation(s, -2); // lower the saturation + s->set_vflip(s, 1); // flip it back + s->set_brightness(s, 1); // up the brightness just a bit + s->set_saturation(s, -2); // lower the saturation } // drop down frame size for higher initial frame rate - if(config.pixel_format == PIXFORMAT_JPEG){ + if (config.pixel_format == PIXFORMAT_JPEG) { s->set_framesize(s, FRAMESIZE_QVGA); } diff --git a/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp b/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp index 64e3350fc33..17ad3bc2b03 100644 --- a/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp +++ b/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp @@ -58,7 +58,7 @@ #pragma GCC diagnostic error "-Wformat" #pragma GCC diagnostic warning "-Wstrict-aliasing" -#define QUANT_TYPE 0 //if set to 1 => very large firmware, very slow, reboots when streaming... +#define QUANT_TYPE 0 //if set to 1 => very large firmware, very slow, reboots when streaming... #define FACE_ID_SAVE_NUMBER 7 #endif @@ -79,7 +79,7 @@ // LED FLASH setup #if CONFIG_LED_ILLUMINATOR_ENABLED -#define LED_LEDC_GPIO 22 //configure LED pin +#define LED_LEDC_GPIO 22 //configure LED pin #define CONFIG_LED_MAX_INTENSITY 255 int led_duty = 0; @@ -89,8 +89,8 @@ bool isStreaming = false; typedef struct { - httpd_req_t *req; - size_t len; + httpd_req_t *req; + size_t len; } jpg_chunking_t; #define PART_BOUNDARY "123456789000000000000987654321" @@ -117,11 +117,11 @@ static int8_t recognition_enabled = 0; static int8_t is_enrolling = 0; #if QUANT_TYPE - // S16 model - FaceRecognition112V1S16 recognizer; +// S16 model +FaceRecognition112V1S16 recognizer; #else - // S8 model - FaceRecognition112V1S8 recognizer; +// S8 model +FaceRecognition112V1S8 recognizer; #endif #endif @@ -129,1270 +129,1198 @@ static int8_t is_enrolling = 0; typedef struct { - size_t size; //number of values used for filtering - size_t index; //current value index - size_t count; //value count - int sum; - int *values; //array to be filled with values + size_t size; //number of values used for filtering + size_t index; //current value index + size_t count; //value count + int sum; + int *values; //array to be filled with values } ra_filter_t; static ra_filter_t ra_filter; -static ra_filter_t *ra_filter_init(ra_filter_t *filter, size_t sample_size) -{ - memset(filter, 0, sizeof(ra_filter_t)); +static ra_filter_t *ra_filter_init(ra_filter_t *filter, size_t sample_size) { + memset(filter, 0, sizeof(ra_filter_t)); - filter->values = (int *)malloc(sample_size * sizeof(int)); - if (!filter->values) - { - return NULL; - } - memset(filter->values, 0, sample_size * sizeof(int)); + filter->values = (int *)malloc(sample_size * sizeof(int)); + if (!filter->values) { + return NULL; + } + memset(filter->values, 0, sample_size * sizeof(int)); - filter->size = sample_size; - return filter; + filter->size = sample_size; + return filter; } #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO -static int ra_filter_run(ra_filter_t *filter, int value) -{ - if (!filter->values) - { - return value; - } - filter->sum -= filter->values[filter->index]; - filter->values[filter->index] = value; - filter->sum += filter->values[filter->index]; - filter->index++; - filter->index = filter->index % filter->size; - if (filter->count < filter->size) - { - filter->count++; - } - return filter->sum / filter->count; +static int ra_filter_run(ra_filter_t *filter, int value) { + if (!filter->values) { + return value; + } + filter->sum -= filter->values[filter->index]; + filter->values[filter->index] = value; + filter->sum += filter->values[filter->index]; + filter->index++; + filter->index = filter->index % filter->size; + if (filter->count < filter->size) { + filter->count++; + } + return filter->sum / filter->count; } #endif #if CONFIG_ESP_FACE_DETECT_ENABLED #if CONFIG_ESP_FACE_RECOGNITION_ENABLED -static void rgb_print(fb_data_t *fb, uint32_t color, const char *str) -{ - fb_gfx_print(fb, (fb->width - (strlen(str) * 14)) / 2, 10, color, str); +static void rgb_print(fb_data_t *fb, uint32_t color, const char *str) { + fb_gfx_print(fb, (fb->width - (strlen(str) * 14)) / 2, 10, color, str); } -static int rgb_printf(fb_data_t *fb, uint32_t color, const char *format, ...) -{ - char loc_buf[64]; - char *temp = loc_buf; - int len; - va_list arg; - va_list copy; - va_start(arg, format); - va_copy(copy, arg); - len = vsnprintf(loc_buf, sizeof(loc_buf), format, arg); - va_end(copy); - if (len >= sizeof(loc_buf)) - { - temp = (char *)malloc(len + 1); - if (temp == NULL) - { - return 0; - } +static int rgb_printf(fb_data_t *fb, uint32_t color, const char *format, ...) { + char loc_buf[64]; + char *temp = loc_buf; + int len; + va_list arg; + va_list copy; + va_start(arg, format); + va_copy(copy, arg); + len = vsnprintf(loc_buf, sizeof(loc_buf), format, arg); + va_end(copy); + if (len >= sizeof(loc_buf)) { + temp = (char *)malloc(len + 1); + if (temp == NULL) { + return 0; } - vsnprintf(temp, len + 1, format, arg); - va_end(arg); - rgb_print(fb, color, temp); - if (len > 64) - { - free(temp); - } - return len; + } + vsnprintf(temp, len + 1, format, arg); + va_end(arg); + rgb_print(fb, color, temp); + if (len > 64) { + free(temp); + } + return len; } #endif -static void draw_face_boxes(fb_data_t *fb, std::list *results, int face_id) -{ - int x, y, w, h; - uint32_t color = FACE_COLOR_YELLOW; - if (face_id < 0) - { - color = FACE_COLOR_RED; +static void draw_face_boxes(fb_data_t *fb, std::list *results, int face_id) { + int x, y, w, h; + uint32_t color = FACE_COLOR_YELLOW; + if (face_id < 0) { + color = FACE_COLOR_RED; + } else if (face_id > 0) { + color = FACE_COLOR_GREEN; + } + if (fb->bytes_per_pixel == 2) { + //color = ((color >> 8) & 0xF800) | ((color >> 3) & 0x07E0) | (color & 0x001F); + color = ((color >> 16) & 0x001F) | ((color >> 3) & 0x07E0) | ((color << 8) & 0xF800); + } + int i = 0; + for (std::list::iterator prediction = results->begin(); prediction != results->end(); prediction++, i++) { + // rectangle box + x = (int)prediction->box[0]; + y = (int)prediction->box[1]; + w = (int)prediction->box[2] - x + 1; + h = (int)prediction->box[3] - y + 1; + if ((x + w) > fb->width) { + w = fb->width - x; } - else if (face_id > 0) - { - color = FACE_COLOR_GREEN; + if ((y + h) > fb->height) { + h = fb->height - y; } - if(fb->bytes_per_pixel == 2){ - //color = ((color >> 8) & 0xF800) | ((color >> 3) & 0x07E0) | (color & 0x001F); - color = ((color >> 16) & 0x001F) | ((color >> 3) & 0x07E0) | ((color << 8) & 0xF800); - } - int i = 0; - for (std::list::iterator prediction = results->begin(); prediction != results->end(); prediction++, i++) - { - // rectangle box - x = (int)prediction->box[0]; - y = (int)prediction->box[1]; - w = (int)prediction->box[2] - x + 1; - h = (int)prediction->box[3] - y + 1; - if((x + w) > fb->width){ - w = fb->width - x; - } - if((y + h) > fb->height){ - h = fb->height - y; - } - fb_gfx_drawFastHLine(fb, x, y, w, color); - fb_gfx_drawFastHLine(fb, x, y + h - 1, w, color); - fb_gfx_drawFastVLine(fb, x, y, h, color); - fb_gfx_drawFastVLine(fb, x + w - 1, y, h, color); + fb_gfx_drawFastHLine(fb, x, y, w, color); + fb_gfx_drawFastHLine(fb, x, y + h - 1, w, color); + fb_gfx_drawFastVLine(fb, x, y, h, color); + fb_gfx_drawFastVLine(fb, x + w - 1, y, h, color); #if TWO_STAGE - // landmarks (left eye, mouth left, nose, right eye, mouth right) - int x0, y0, j; - for (j = 0; j < 10; j+=2) { - x0 = (int)prediction->keypoint[j]; - y0 = (int)prediction->keypoint[j+1]; - fb_gfx_fillRect(fb, x0, y0, 3, 3, color); - } -#endif + // landmarks (left eye, mouth left, nose, right eye, mouth right) + int x0, y0, j; + for (j = 0; j < 10; j += 2) { + x0 = (int)prediction->keypoint[j]; + y0 = (int)prediction->keypoint[j + 1]; + fb_gfx_fillRect(fb, x0, y0, 3, 3, color); } +#endif + } } #if CONFIG_ESP_FACE_RECOGNITION_ENABLED -static int run_face_recognition(fb_data_t *fb, std::list *results) -{ - std::vector landmarks = results->front().keypoint; - int id = -1; - - Tensor tensor; - tensor.set_element((uint8_t *)fb->data).set_shape({fb->height, fb->width, 3}).set_auto_free(false); - - int enrolled_count = recognizer.get_enrolled_id_num(); - - if (enrolled_count < FACE_ID_SAVE_NUMBER && is_enrolling){ - id = recognizer.enroll_id(tensor, landmarks, "", true); - log_i("Enrolled ID: %d", id); - rgb_printf(fb, FACE_COLOR_CYAN, "ID[%u]", id); - } - - face_info_t recognize = recognizer.recognize(tensor, landmarks); - if(recognize.id >= 0){ - rgb_printf(fb, FACE_COLOR_GREEN, "ID[%u]: %.2f", recognize.id, recognize.similarity); - } else { - rgb_print(fb, FACE_COLOR_RED, "Intruder Alert!"); - } - return recognize.id; +static int run_face_recognition(fb_data_t *fb, std::list *results) { + std::vector landmarks = results->front().keypoint; + int id = -1; + + Tensor tensor; + tensor.set_element((uint8_t *)fb->data).set_shape({ fb->height, fb->width, 3 }).set_auto_free(false); + + int enrolled_count = recognizer.get_enrolled_id_num(); + + if (enrolled_count < FACE_ID_SAVE_NUMBER && is_enrolling) { + id = recognizer.enroll_id(tensor, landmarks, "", true); + log_i("Enrolled ID: %d", id); + rgb_printf(fb, FACE_COLOR_CYAN, "ID[%u]", id); + } + + face_info_t recognize = recognizer.recognize(tensor, landmarks); + if (recognize.id >= 0) { + rgb_printf(fb, FACE_COLOR_GREEN, "ID[%u]: %.2f", recognize.id, recognize.similarity); + } else { + rgb_print(fb, FACE_COLOR_RED, "Intruder Alert!"); + } + return recognize.id; } #endif #endif #if CONFIG_LED_ILLUMINATOR_ENABLED -void enable_led(bool en) -{ // Turn LED On or Off - int duty = en ? led_duty : 0; - if (en && isStreaming && (led_duty > CONFIG_LED_MAX_INTENSITY)) - { - duty = CONFIG_LED_MAX_INTENSITY; - } - ledcWrite(LED_LEDC_GPIO, duty); - //ledc_set_duty(CONFIG_LED_LEDC_SPEED_MODE, CONFIG_LED_LEDC_CHANNEL, duty); - //ledc_update_duty(CONFIG_LED_LEDC_SPEED_MODE, CONFIG_LED_LEDC_CHANNEL); - log_i("Set LED intensity to %d", duty); +void enable_led(bool en) { // Turn LED On or Off + int duty = en ? led_duty : 0; + if (en && isStreaming && (led_duty > CONFIG_LED_MAX_INTENSITY)) { + duty = CONFIG_LED_MAX_INTENSITY; + } + ledcWrite(LED_LEDC_GPIO, duty); + //ledc_set_duty(CONFIG_LED_LEDC_SPEED_MODE, CONFIG_LED_LEDC_CHANNEL, duty); + //ledc_update_duty(CONFIG_LED_LEDC_SPEED_MODE, CONFIG_LED_LEDC_CHANNEL); + log_i("Set LED intensity to %d", duty); } #endif -static esp_err_t bmp_handler(httpd_req_t *req) -{ - camera_fb_t *fb = NULL; - esp_err_t res = ESP_OK; +static esp_err_t bmp_handler(httpd_req_t *req) { + camera_fb_t *fb = NULL; + esp_err_t res = ESP_OK; #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - uint64_t fr_start = esp_timer_get_time(); + uint64_t fr_start = esp_timer_get_time(); #endif - fb = esp_camera_fb_get(); - if (!fb) - { - log_e("Camera capture failed"); - httpd_resp_send_500(req); - return ESP_FAIL; - } + fb = esp_camera_fb_get(); + if (!fb) { + log_e("Camera capture failed"); + httpd_resp_send_500(req); + return ESP_FAIL; + } - httpd_resp_set_type(req, "image/x-windows-bmp"); - httpd_resp_set_hdr(req, "Content-Disposition", "inline; filename=capture.bmp"); - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + httpd_resp_set_type(req, "image/x-windows-bmp"); + httpd_resp_set_hdr(req, "Content-Disposition", "inline; filename=capture.bmp"); + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - char ts[32]; - snprintf(ts, 32, "%lld.%06ld", fb->timestamp.tv_sec, fb->timestamp.tv_usec); - httpd_resp_set_hdr(req, "X-Timestamp", (const char *)ts); + char ts[32]; + snprintf(ts, 32, "%lld.%06ld", fb->timestamp.tv_sec, fb->timestamp.tv_usec); + httpd_resp_set_hdr(req, "X-Timestamp", (const char *)ts); - uint8_t * buf = NULL; - size_t buf_len = 0; - bool converted = frame2bmp(fb, &buf, &buf_len); - esp_camera_fb_return(fb); - if(!converted){ - log_e("BMP Conversion failed"); - httpd_resp_send_500(req); - return ESP_FAIL; - } - res = httpd_resp_send(req, (const char *)buf, buf_len); - free(buf); + uint8_t *buf = NULL; + size_t buf_len = 0; + bool converted = frame2bmp(fb, &buf, &buf_len); + esp_camera_fb_return(fb); + if (!converted) { + log_e("BMP Conversion failed"); + httpd_resp_send_500(req); + return ESP_FAIL; + } + res = httpd_resp_send(req, (const char *)buf, buf_len); + free(buf); #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - uint64_t fr_end = esp_timer_get_time(); + uint64_t fr_end = esp_timer_get_time(); #endif - log_i("BMP: %llums, %uB", (uint64_t)((fr_end - fr_start) / 1000), buf_len); - return res; + log_i("BMP: %llums, %uB", (uint64_t)((fr_end - fr_start) / 1000), buf_len); + return res; } -static size_t jpg_encode_stream(void *arg, size_t index, const void *data, size_t len) -{ - jpg_chunking_t *j = (jpg_chunking_t *)arg; - if (!index) - { - j->len = 0; - } - if (httpd_resp_send_chunk(j->req, (const char *)data, len) != ESP_OK) - { - return 0; - } - j->len += len; - return len; +static size_t jpg_encode_stream(void *arg, size_t index, const void *data, size_t len) { + jpg_chunking_t *j = (jpg_chunking_t *)arg; + if (!index) { + j->len = 0; + } + if (httpd_resp_send_chunk(j->req, (const char *)data, len) != ESP_OK) { + return 0; + } + j->len += len; + return len; } -static esp_err_t capture_handler(httpd_req_t *req) -{ - camera_fb_t *fb = NULL; - esp_err_t res = ESP_OK; +static esp_err_t capture_handler(httpd_req_t *req) { + camera_fb_t *fb = NULL; + esp_err_t res = ESP_OK; #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - int64_t fr_start = esp_timer_get_time(); + int64_t fr_start = esp_timer_get_time(); #endif #if CONFIG_LED_ILLUMINATOR_ENABLED - enable_led(true); - vTaskDelay(150 / portTICK_PERIOD_MS); // The LED needs to be turned on ~150ms before the call to esp_camera_fb_get() - fb = esp_camera_fb_get(); // or it won't be visible in the frame. A better way to do this is needed. - enable_led(false); + enable_led(true); + vTaskDelay(150 / portTICK_PERIOD_MS); // The LED needs to be turned on ~150ms before the call to esp_camera_fb_get() + fb = esp_camera_fb_get(); // or it won't be visible in the frame. A better way to do this is needed. + enable_led(false); #else - fb = esp_camera_fb_get(); + fb = esp_camera_fb_get(); #endif - if (!fb) - { - log_e("Camera capture failed"); - httpd_resp_send_500(req); - return ESP_FAIL; - } + if (!fb) { + log_e("Camera capture failed"); + httpd_resp_send_500(req); + return ESP_FAIL; + } - httpd_resp_set_type(req, "image/jpeg"); - httpd_resp_set_hdr(req, "Content-Disposition", "inline; filename=capture.jpg"); - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + httpd_resp_set_type(req, "image/jpeg"); + httpd_resp_set_hdr(req, "Content-Disposition", "inline; filename=capture.jpg"); + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - char ts[32]; - snprintf(ts, 32, "%lld.%06ld", fb->timestamp.tv_sec, fb->timestamp.tv_usec); - httpd_resp_set_hdr(req, "X-Timestamp", (const char *)ts); + char ts[32]; + snprintf(ts, 32, "%lld.%06ld", fb->timestamp.tv_sec, fb->timestamp.tv_usec); + httpd_resp_set_hdr(req, "X-Timestamp", (const char *)ts); #if CONFIG_ESP_FACE_DETECT_ENABLED - size_t out_len, out_width, out_height; - uint8_t *out_buf; - bool s; + size_t out_len, out_width, out_height; + uint8_t *out_buf; + bool s; #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - bool detected = false; + bool detected = false; #endif - int face_id = 0; - if (!detection_enabled || fb->width > 400) - { + int face_id = 0; + if (!detection_enabled || fb->width > 400) { #endif #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - size_t fb_len = 0; + size_t fb_len = 0; #endif - if (fb->format == PIXFORMAT_JPEG) - { + if (fb->format == PIXFORMAT_JPEG) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - fb_len = fb->len; + fb_len = fb->len; #endif - res = httpd_resp_send(req, (const char *)fb->buf, fb->len); - } - else - { - jpg_chunking_t jchunk = {req, 0}; - res = frame2jpg_cb(fb, 80, jpg_encode_stream, &jchunk) ? ESP_OK : ESP_FAIL; - httpd_resp_send_chunk(req, NULL, 0); + res = httpd_resp_send(req, (const char *)fb->buf, fb->len); + } else { + jpg_chunking_t jchunk = { req, 0 }; + res = frame2jpg_cb(fb, 80, jpg_encode_stream, &jchunk) ? ESP_OK : ESP_FAIL; + httpd_resp_send_chunk(req, NULL, 0); #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - fb_len = jchunk.len; + fb_len = jchunk.len; #endif - } - esp_camera_fb_return(fb); + } + esp_camera_fb_return(fb); #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - int64_t fr_end = esp_timer_get_time(); + int64_t fr_end = esp_timer_get_time(); #endif - log_i("JPG: %uB %ums", (uint32_t)(fb_len), (uint32_t)((fr_end - fr_start) / 1000)); - return res; + log_i("JPG: %uB %ums", (uint32_t)(fb_len), (uint32_t)((fr_end - fr_start) / 1000)); + return res; #if CONFIG_ESP_FACE_DETECT_ENABLED - } + } - jpg_chunking_t jchunk = {req, 0}; + jpg_chunking_t jchunk = { req, 0 }; - if (fb->format == PIXFORMAT_RGB565 + if (fb->format == PIXFORMAT_RGB565 #if CONFIG_ESP_FACE_RECOGNITION_ENABLED - && !recognition_enabled + && !recognition_enabled #endif - ){ + ) { #if TWO_STAGE - HumanFaceDetectMSR01 s1(0.1F, 0.5F, 10, 0.2F); - HumanFaceDetectMNP01 s2(0.5F, 0.3F, 5); - std::list &candidates = s1.infer((uint16_t *)fb->buf, {(int)fb->height, (int)fb->width, 3}); - std::list &results = s2.infer((uint16_t *)fb->buf, {(int)fb->height, (int)fb->width, 3}, candidates); + HumanFaceDetectMSR01 s1(0.1F, 0.5F, 10, 0.2F); + HumanFaceDetectMNP01 s2(0.5F, 0.3F, 5); + std::list &candidates = s1.infer((uint16_t *)fb->buf, { (int)fb->height, (int)fb->width, 3 }); + std::list &results = s2.infer((uint16_t *)fb->buf, { (int)fb->height, (int)fb->width, 3 }, candidates); #else - HumanFaceDetectMSR01 s1(0.3F, 0.5F, 10, 0.2F); - std::list &results = s1.infer((uint16_t *)fb->buf, {(int)fb->height, (int)fb->width, 3}); -#endif - if (results.size() > 0) { - fb_data_t rfb; - rfb.width = fb->width; - rfb.height = fb->height; - rfb.data = fb->buf; - rfb.bytes_per_pixel = 2; - rfb.format = FB_RGB565; + HumanFaceDetectMSR01 s1(0.3F, 0.5F, 10, 0.2F); + std::list &results = s1.infer((uint16_t *)fb->buf, { (int)fb->height, (int)fb->width, 3 }); +#endif + if (results.size() > 0) { + fb_data_t rfb; + rfb.width = fb->width; + rfb.height = fb->height; + rfb.data = fb->buf; + rfb.bytes_per_pixel = 2; + rfb.format = FB_RGB565; #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - detected = true; + detected = true; #endif - draw_face_boxes(&rfb, &results, face_id); - } - s = fmt2jpg_cb(fb->buf, fb->len, fb->width, fb->height, PIXFORMAT_RGB565, 90, jpg_encode_stream, &jchunk); - esp_camera_fb_return(fb); - } else - { - out_len = fb->width * fb->height * 3; - out_width = fb->width; - out_height = fb->height; - out_buf = (uint8_t*)malloc(out_len); - if (!out_buf) { - log_e("out_buf malloc failed"); - httpd_resp_send_500(req); - return ESP_FAIL; - } - s = fmt2rgb888(fb->buf, fb->len, fb->format, out_buf); - esp_camera_fb_return(fb); - if (!s) { - free(out_buf); - log_e("To rgb888 failed"); - httpd_resp_send_500(req); - return ESP_FAIL; - } + draw_face_boxes(&rfb, &results, face_id); + } + s = fmt2jpg_cb(fb->buf, fb->len, fb->width, fb->height, PIXFORMAT_RGB565, 90, jpg_encode_stream, &jchunk); + esp_camera_fb_return(fb); + } else { + out_len = fb->width * fb->height * 3; + out_width = fb->width; + out_height = fb->height; + out_buf = (uint8_t *)malloc(out_len); + if (!out_buf) { + log_e("out_buf malloc failed"); + httpd_resp_send_500(req); + return ESP_FAIL; + } + s = fmt2rgb888(fb->buf, fb->len, fb->format, out_buf); + esp_camera_fb_return(fb); + if (!s) { + free(out_buf); + log_e("To rgb888 failed"); + httpd_resp_send_500(req); + return ESP_FAIL; + } - fb_data_t rfb; - rfb.width = out_width; - rfb.height = out_height; - rfb.data = out_buf; - rfb.bytes_per_pixel = 3; - rfb.format = FB_BGR888; + fb_data_t rfb; + rfb.width = out_width; + rfb.height = out_height; + rfb.data = out_buf; + rfb.bytes_per_pixel = 3; + rfb.format = FB_BGR888; #if TWO_STAGE - HumanFaceDetectMSR01 s1(0.1F, 0.5F, 10, 0.2F); - HumanFaceDetectMNP01 s2(0.5F, 0.3F, 5); - std::list &candidates = s1.infer((uint8_t *)out_buf, {(int)out_height, (int)out_width, 3}); - std::list &results = s2.infer((uint8_t *)out_buf, {(int)out_height, (int)out_width, 3}, candidates); + HumanFaceDetectMSR01 s1(0.1F, 0.5F, 10, 0.2F); + HumanFaceDetectMNP01 s2(0.5F, 0.3F, 5); + std::list &candidates = s1.infer((uint8_t *)out_buf, { (int)out_height, (int)out_width, 3 }); + std::list &results = s2.infer((uint8_t *)out_buf, { (int)out_height, (int)out_width, 3 }, candidates); #else - HumanFaceDetectMSR01 s1(0.3F, 0.5F, 10, 0.2F); - std::list &results = s1.infer((uint8_t *)out_buf, {(int)out_height, (int)out_width, 3}); + HumanFaceDetectMSR01 s1(0.3F, 0.5F, 10, 0.2F); + std::list &results = s1.infer((uint8_t *)out_buf, { (int)out_height, (int)out_width, 3 }); #endif - if (results.size() > 0) { + if (results.size() > 0) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - detected = true; + detected = true; #endif #if CONFIG_ESP_FACE_RECOGNITION_ENABLED - if (recognition_enabled) { - face_id = run_face_recognition(&rfb, &results); - } + if (recognition_enabled) { + face_id = run_face_recognition(&rfb, &results); + } #endif - draw_face_boxes(&rfb, &results, face_id); - } - - s = fmt2jpg_cb(out_buf, out_len, out_width, out_height, PIXFORMAT_RGB888, 90, jpg_encode_stream, &jchunk); - free(out_buf); + draw_face_boxes(&rfb, &results, face_id); } - if (!s) { - log_e("JPEG compression failed"); - httpd_resp_send_500(req); - return ESP_FAIL; - } + s = fmt2jpg_cb(out_buf, out_len, out_width, out_height, PIXFORMAT_RGB888, 90, jpg_encode_stream, &jchunk); + free(out_buf); + } + + if (!s) { + log_e("JPEG compression failed"); + httpd_resp_send_500(req); + return ESP_FAIL; + } #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - int64_t fr_end = esp_timer_get_time(); + int64_t fr_end = esp_timer_get_time(); #endif - log_i("FACE: %uB %ums %s%d", (uint32_t)(jchunk.len), (uint32_t)((fr_end - fr_start) / 1000), detected ? "DETECTED " : "", face_id); - return res; + log_i("FACE: %uB %ums %s%d", (uint32_t)(jchunk.len), (uint32_t)((fr_end - fr_start) / 1000), detected ? "DETECTED " : "", face_id); + return res; #endif } -static esp_err_t stream_handler(httpd_req_t *req) -{ - camera_fb_t *fb = NULL; - struct timeval _timestamp; - esp_err_t res = ESP_OK; - size_t _jpg_buf_len = 0; - uint8_t *_jpg_buf = NULL; - char *part_buf[128]; +static esp_err_t stream_handler(httpd_req_t *req) { + camera_fb_t *fb = NULL; + struct timeval _timestamp; + esp_err_t res = ESP_OK; + size_t _jpg_buf_len = 0; + uint8_t *_jpg_buf = NULL; + char *part_buf[128]; #if CONFIG_ESP_FACE_DETECT_ENABLED - #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - bool detected = false; - int64_t fr_ready = 0; - int64_t fr_recognize = 0; - int64_t fr_encode = 0; - int64_t fr_face = 0; - int64_t fr_start = 0; - #endif - int face_id = 0; - size_t out_len = 0, out_width = 0, out_height = 0; - uint8_t *out_buf = NULL; - bool s = false; +#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO + bool detected = false; + int64_t fr_ready = 0; + int64_t fr_recognize = 0; + int64_t fr_encode = 0; + int64_t fr_face = 0; + int64_t fr_start = 0; +#endif + int face_id = 0; + size_t out_len = 0, out_width = 0, out_height = 0; + uint8_t *out_buf = NULL; + bool s = false; #if TWO_STAGE - HumanFaceDetectMSR01 s1(0.1F, 0.5F, 10, 0.2F); - HumanFaceDetectMNP01 s2(0.5F, 0.3F, 5); + HumanFaceDetectMSR01 s1(0.1F, 0.5F, 10, 0.2F); + HumanFaceDetectMNP01 s2(0.5F, 0.3F, 5); #else - HumanFaceDetectMSR01 s1(0.3F, 0.5F, 10, 0.2F); + HumanFaceDetectMSR01 s1(0.3F, 0.5F, 10, 0.2F); #endif #endif - static int64_t last_frame = 0; - if (!last_frame) - { - last_frame = esp_timer_get_time(); - } + static int64_t last_frame = 0; + if (!last_frame) { + last_frame = esp_timer_get_time(); + } - res = httpd_resp_set_type(req, _STREAM_CONTENT_TYPE); - if (res != ESP_OK) - { - return res; - } + res = httpd_resp_set_type(req, _STREAM_CONTENT_TYPE); + if (res != ESP_OK) { + return res; + } - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - httpd_resp_set_hdr(req, "X-Framerate", "60"); + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + httpd_resp_set_hdr(req, "X-Framerate", "60"); #if CONFIG_LED_ILLUMINATOR_ENABLED - isStreaming = true; - enable_led(true); + isStreaming = true; + enable_led(true); #endif - while (true) - { + while (true) { #if CONFIG_ESP_FACE_DETECT_ENABLED - #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - detected = false; - #endif - face_id = 0; +#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO + detected = false; +#endif + face_id = 0; #endif - fb = esp_camera_fb_get(); - if (!fb) - { - log_e("Camera capture failed"); + fb = esp_camera_fb_get(); + if (!fb) { + log_e("Camera capture failed"); + res = ESP_FAIL; + } else { + _timestamp.tv_sec = fb->timestamp.tv_sec; + _timestamp.tv_usec = fb->timestamp.tv_usec; +#if CONFIG_ESP_FACE_DETECT_ENABLED +#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO + fr_start = esp_timer_get_time(); + fr_ready = fr_start; + fr_encode = fr_start; + fr_recognize = fr_start; + fr_face = fr_start; +#endif + if (!detection_enabled || fb->width > 400) { +#endif + if (fb->format != PIXFORMAT_JPEG) { + bool jpeg_converted = frame2jpg(fb, 80, &_jpg_buf, &_jpg_buf_len); + esp_camera_fb_return(fb); + fb = NULL; + if (!jpeg_converted) { + log_e("JPEG compression failed"); res = ESP_FAIL; + } + } else { + _jpg_buf_len = fb->len; + _jpg_buf = fb->buf; } - else - { - _timestamp.tv_sec = fb->timestamp.tv_sec; - _timestamp.tv_usec = fb->timestamp.tv_usec; -#if CONFIG_ESP_FACE_DETECT_ENABLED - #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - fr_start = esp_timer_get_time(); - fr_ready = fr_start; - fr_encode = fr_start; - fr_recognize = fr_start; - fr_face = fr_start; - #endif - if (!detection_enabled || fb->width > 400) - { -#endif - if (fb->format != PIXFORMAT_JPEG) - { - bool jpeg_converted = frame2jpg(fb, 80, &_jpg_buf, &_jpg_buf_len); - esp_camera_fb_return(fb); - fb = NULL; - if (!jpeg_converted) - { - log_e("JPEG compression failed"); - res = ESP_FAIL; - } - } - else - { - _jpg_buf_len = fb->len; - _jpg_buf = fb->buf; - } #if CONFIG_ESP_FACE_DETECT_ENABLED - } - else - { - if (fb->format == PIXFORMAT_RGB565 + } else { + if (fb->format == PIXFORMAT_RGB565 #if CONFIG_ESP_FACE_RECOGNITION_ENABLED - && !recognition_enabled + && !recognition_enabled #endif - ){ + ) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - fr_ready = esp_timer_get_time(); + fr_ready = esp_timer_get_time(); #endif #if TWO_STAGE - std::list &candidates = s1.infer((uint16_t *)fb->buf, {(int)fb->height, (int)fb->width, 3}); - std::list &results = s2.infer((uint16_t *)fb->buf, {(int)fb->height, (int)fb->width, 3}, candidates); + std::list &candidates = s1.infer((uint16_t *)fb->buf, { (int)fb->height, (int)fb->width, 3 }); + std::list &results = s2.infer((uint16_t *)fb->buf, { (int)fb->height, (int)fb->width, 3 }, candidates); #else - std::list &results = s1.infer((uint16_t *)fb->buf, {(int)fb->height, (int)fb->width, 3}); + std::list &results = s1.infer((uint16_t *)fb->buf, { (int)fb->height, (int)fb->width, 3 }); #endif #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - fr_face = esp_timer_get_time(); - fr_recognize = fr_face; -#endif - if (results.size() > 0) { - fb_data_t rfb; - rfb.width = fb->width; - rfb.height = fb->height; - rfb.data = fb->buf; - rfb.bytes_per_pixel = 2; - rfb.format = FB_RGB565; + fr_face = esp_timer_get_time(); + fr_recognize = fr_face; +#endif + if (results.size() > 0) { + fb_data_t rfb; + rfb.width = fb->width; + rfb.height = fb->height; + rfb.data = fb->buf; + rfb.bytes_per_pixel = 2; + rfb.format = FB_RGB565; #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - detected = true; -#endif - draw_face_boxes(&rfb, &results, face_id); - } - s = fmt2jpg(fb->buf, fb->len, fb->width, fb->height, PIXFORMAT_RGB565, 80, &_jpg_buf, &_jpg_buf_len); - esp_camera_fb_return(fb); - fb = NULL; - if (!s) { - log_e("fmt2jpg failed"); - res = ESP_FAIL; - } + detected = true; +#endif + draw_face_boxes(&rfb, &results, face_id); + } + s = fmt2jpg(fb->buf, fb->len, fb->width, fb->height, PIXFORMAT_RGB565, 80, &_jpg_buf, &_jpg_buf_len); + esp_camera_fb_return(fb); + fb = NULL; + if (!s) { + log_e("fmt2jpg failed"); + res = ESP_FAIL; + } #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - fr_encode = esp_timer_get_time(); -#endif - } else - { - out_len = fb->width * fb->height * 3; - out_width = fb->width; - out_height = fb->height; - out_buf = (uint8_t*)malloc(out_len); - if (!out_buf) { - log_e("out_buf malloc failed"); - res = ESP_FAIL; - } else { - s = fmt2rgb888(fb->buf, fb->len, fb->format, out_buf); - esp_camera_fb_return(fb); - fb = NULL; - if (!s) { - free(out_buf); - log_e("To rgb888 failed"); - res = ESP_FAIL; - } else { + fr_encode = esp_timer_get_time(); +#endif + } else { + out_len = fb->width * fb->height * 3; + out_width = fb->width; + out_height = fb->height; + out_buf = (uint8_t *)malloc(out_len); + if (!out_buf) { + log_e("out_buf malloc failed"); + res = ESP_FAIL; + } else { + s = fmt2rgb888(fb->buf, fb->len, fb->format, out_buf); + esp_camera_fb_return(fb); + fb = NULL; + if (!s) { + free(out_buf); + log_e("To rgb888 failed"); + res = ESP_FAIL; + } else { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - fr_ready = esp_timer_get_time(); + fr_ready = esp_timer_get_time(); #endif - fb_data_t rfb; - rfb.width = out_width; - rfb.height = out_height; - rfb.data = out_buf; - rfb.bytes_per_pixel = 3; - rfb.format = FB_BGR888; + fb_data_t rfb; + rfb.width = out_width; + rfb.height = out_height; + rfb.data = out_buf; + rfb.bytes_per_pixel = 3; + rfb.format = FB_BGR888; #if TWO_STAGE - std::list &candidates = s1.infer((uint8_t *)out_buf, {(int)out_height, (int)out_width, 3}); - std::list &results = s2.infer((uint8_t *)out_buf, {(int)out_height, (int)out_width, 3}, candidates); + std::list &candidates = s1.infer((uint8_t *)out_buf, { (int)out_height, (int)out_width, 3 }); + std::list &results = s2.infer((uint8_t *)out_buf, { (int)out_height, (int)out_width, 3 }, candidates); #else - std::list &results = s1.infer((uint8_t *)out_buf, {(int)out_height, (int)out_width, 3}); + std::list &results = s1.infer((uint8_t *)out_buf, { (int)out_height, (int)out_width, 3 }); #endif #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - fr_face = esp_timer_get_time(); - fr_recognize = fr_face; + fr_face = esp_timer_get_time(); + fr_recognize = fr_face; #endif - if (results.size() > 0) { + if (results.size() > 0) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - detected = true; + detected = true; #endif #if CONFIG_ESP_FACE_RECOGNITION_ENABLED - if (recognition_enabled) { - face_id = run_face_recognition(&rfb, &results); - #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - fr_recognize = esp_timer_get_time(); - #endif - } -#endif - draw_face_boxes(&rfb, &results, face_id); - } - s = fmt2jpg(out_buf, out_len, out_width, out_height, PIXFORMAT_RGB888, 90, &_jpg_buf, &_jpg_buf_len); - free(out_buf); - if (!s) { - log_e("fmt2jpg failed"); - res = ESP_FAIL; - } -#if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - fr_encode = esp_timer_get_time(); + if (recognition_enabled) { + face_id = run_face_recognition(&rfb, &results); +#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO + fr_recognize = esp_timer_get_time(); #endif - } - } } - } #endif + draw_face_boxes(&rfb, &results, face_id); + } + s = fmt2jpg(out_buf, out_len, out_width, out_height, PIXFORMAT_RGB888, 90, &_jpg_buf, &_jpg_buf_len); + free(out_buf); + if (!s) { + log_e("fmt2jpg failed"); + res = ESP_FAIL; + } +#if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO + fr_encode = esp_timer_get_time(); +#endif + } + } } - if (res == ESP_OK) - { - res = httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY)); - } - if (res == ESP_OK) - { - size_t hlen = snprintf((char *)part_buf, 128, _STREAM_PART, _jpg_buf_len, _timestamp.tv_sec, _timestamp.tv_usec); - res = httpd_resp_send_chunk(req, (const char *)part_buf, hlen); - } - if (res == ESP_OK) - { - res = httpd_resp_send_chunk(req, (const char *)_jpg_buf, _jpg_buf_len); - } - if (fb) - { - esp_camera_fb_return(fb); - fb = NULL; - _jpg_buf = NULL; - } - else if (_jpg_buf) - { - free(_jpg_buf); - _jpg_buf = NULL; - } - if (res != ESP_OK) - { - log_e("Send frame failed"); - break; - } - int64_t fr_end = esp_timer_get_time(); + } +#endif + } + if (res == ESP_OK) { + res = httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY)); + } + if (res == ESP_OK) { + size_t hlen = snprintf((char *)part_buf, 128, _STREAM_PART, _jpg_buf_len, _timestamp.tv_sec, _timestamp.tv_usec); + res = httpd_resp_send_chunk(req, (const char *)part_buf, hlen); + } + if (res == ESP_OK) { + res = httpd_resp_send_chunk(req, (const char *)_jpg_buf, _jpg_buf_len); + } + if (fb) { + esp_camera_fb_return(fb); + fb = NULL; + _jpg_buf = NULL; + } else if (_jpg_buf) { + free(_jpg_buf); + _jpg_buf = NULL; + } + if (res != ESP_OK) { + log_e("Send frame failed"); + break; + } + int64_t fr_end = esp_timer_get_time(); #if CONFIG_ESP_FACE_DETECT_ENABLED && ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - int64_t ready_time = (fr_ready - fr_start) / 1000; - int64_t face_time = (fr_face - fr_ready) / 1000; - int64_t recognize_time = (fr_recognize - fr_face) / 1000; - int64_t encode_time = (fr_encode - fr_recognize) / 1000; - int64_t process_time = (fr_encode - fr_start) / 1000; + int64_t ready_time = (fr_ready - fr_start) / 1000; + int64_t face_time = (fr_face - fr_ready) / 1000; + int64_t recognize_time = (fr_recognize - fr_face) / 1000; + int64_t encode_time = (fr_encode - fr_recognize) / 1000; + int64_t process_time = (fr_encode - fr_start) / 1000; #endif - int64_t frame_time = fr_end - last_frame; - frame_time /= 1000; + int64_t frame_time = fr_end - last_frame; + frame_time /= 1000; #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - uint32_t avg_frame_time = ra_filter_run(&ra_filter, frame_time); + uint32_t avg_frame_time = ra_filter_run(&ra_filter, frame_time); #endif - log_i("MJPG: %uB %ums (%.1ffps), AVG: %ums (%.1ffps)" + log_i("MJPG: %uB %ums (%.1ffps), AVG: %ums (%.1ffps)" #if CONFIG_ESP_FACE_DETECT_ENABLED - ", %u+%u+%u+%u=%u %s%d" + ", %u+%u+%u+%u=%u %s%d" #endif - , - (uint32_t)(_jpg_buf_len), - (uint32_t)frame_time, 1000.0 / (uint32_t)frame_time, - avg_frame_time, 1000.0 / avg_frame_time + , + (uint32_t)(_jpg_buf_len), + (uint32_t)frame_time, 1000.0 / (uint32_t)frame_time, + avg_frame_time, 1000.0 / avg_frame_time #if CONFIG_ESP_FACE_DETECT_ENABLED - , - (uint32_t)ready_time, (uint32_t)face_time, (uint32_t)recognize_time, (uint32_t)encode_time, (uint32_t)process_time, - (detected) ? "DETECTED " : "", face_id + , + (uint32_t)ready_time, (uint32_t)face_time, (uint32_t)recognize_time, (uint32_t)encode_time, (uint32_t)process_time, + (detected) ? "DETECTED " : "", face_id #endif - ); - } + ); + } #if CONFIG_LED_ILLUMINATOR_ENABLED - isStreaming = false; - enable_led(false); + isStreaming = false; + enable_led(false); #endif - return res; + return res; } -static esp_err_t parse_get(httpd_req_t *req, char **obuf) -{ - char *buf = NULL; - size_t buf_len = 0; - - buf_len = httpd_req_get_url_query_len(req) + 1; - if (buf_len > 1) { - buf = (char *)malloc(buf_len); - if (!buf) { - httpd_resp_send_500(req); - return ESP_FAIL; - } - if (httpd_req_get_url_query_str(req, buf, buf_len) == ESP_OK) { - *obuf = buf; - return ESP_OK; - } - free(buf); +static esp_err_t parse_get(httpd_req_t *req, char **obuf) { + char *buf = NULL; + size_t buf_len = 0; + + buf_len = httpd_req_get_url_query_len(req) + 1; + if (buf_len > 1) { + buf = (char *)malloc(buf_len); + if (!buf) { + httpd_resp_send_500(req); + return ESP_FAIL; } - httpd_resp_send_404(req); - return ESP_FAIL; + if (httpd_req_get_url_query_str(req, buf, buf_len) == ESP_OK) { + *obuf = buf; + return ESP_OK; + } + free(buf); + } + httpd_resp_send_404(req); + return ESP_FAIL; } -static esp_err_t cmd_handler(httpd_req_t *req) -{ - char *buf = NULL; - char variable[32]; - char value[32]; +static esp_err_t cmd_handler(httpd_req_t *req) { + char *buf = NULL; + char variable[32]; + char value[32]; - if (parse_get(req, &buf) != ESP_OK) { - return ESP_FAIL; - } - if (httpd_query_key_value(buf, "var", variable, sizeof(variable)) != ESP_OK || - httpd_query_key_value(buf, "val", value, sizeof(value)) != ESP_OK) { - free(buf); - httpd_resp_send_404(req); - return ESP_FAIL; - } + if (parse_get(req, &buf) != ESP_OK) { + return ESP_FAIL; + } + if (httpd_query_key_value(buf, "var", variable, sizeof(variable)) != ESP_OK || httpd_query_key_value(buf, "val", value, sizeof(value)) != ESP_OK) { free(buf); + httpd_resp_send_404(req); + return ESP_FAIL; + } + free(buf); - int val = atoi(value); - log_i("%s = %d", variable, val); - sensor_t *s = esp_camera_sensor_get(); - int res = 0; + int val = atoi(value); + log_i("%s = %d", variable, val); + sensor_t *s = esp_camera_sensor_get(); + int res = 0; - if (!strcmp(variable, "framesize")) { - if (s->pixformat == PIXFORMAT_JPEG) { - res = s->set_framesize(s, (framesize_t)val); - } + if (!strcmp(variable, "framesize")) { + if (s->pixformat == PIXFORMAT_JPEG) { + res = s->set_framesize(s, (framesize_t)val); } - else if (!strcmp(variable, "quality")) - res = s->set_quality(s, val); - else if (!strcmp(variable, "contrast")) - res = s->set_contrast(s, val); - else if (!strcmp(variable, "brightness")) - res = s->set_brightness(s, val); - else if (!strcmp(variable, "saturation")) - res = s->set_saturation(s, val); - else if (!strcmp(variable, "gainceiling")) - res = s->set_gainceiling(s, (gainceiling_t)val); - else if (!strcmp(variable, "colorbar")) - res = s->set_colorbar(s, val); - else if (!strcmp(variable, "awb")) - res = s->set_whitebal(s, val); - else if (!strcmp(variable, "agc")) - res = s->set_gain_ctrl(s, val); - else if (!strcmp(variable, "aec")) - res = s->set_exposure_ctrl(s, val); - else if (!strcmp(variable, "hmirror")) - res = s->set_hmirror(s, val); - else if (!strcmp(variable, "vflip")) - res = s->set_vflip(s, val); - else if (!strcmp(variable, "awb_gain")) - res = s->set_awb_gain(s, val); - else if (!strcmp(variable, "agc_gain")) - res = s->set_agc_gain(s, val); - else if (!strcmp(variable, "aec_value")) - res = s->set_aec_value(s, val); - else if (!strcmp(variable, "aec2")) - res = s->set_aec2(s, val); - else if (!strcmp(variable, "dcw")) - res = s->set_dcw(s, val); - else if (!strcmp(variable, "bpc")) - res = s->set_bpc(s, val); - else if (!strcmp(variable, "wpc")) - res = s->set_wpc(s, val); - else if (!strcmp(variable, "raw_gma")) - res = s->set_raw_gma(s, val); - else if (!strcmp(variable, "lenc")) - res = s->set_lenc(s, val); - else if (!strcmp(variable, "special_effect")) - res = s->set_special_effect(s, val); - else if (!strcmp(variable, "wb_mode")) - res = s->set_wb_mode(s, val); - else if (!strcmp(variable, "ae_level")) - res = s->set_ae_level(s, val); + } else if (!strcmp(variable, "quality")) + res = s->set_quality(s, val); + else if (!strcmp(variable, "contrast")) + res = s->set_contrast(s, val); + else if (!strcmp(variable, "brightness")) + res = s->set_brightness(s, val); + else if (!strcmp(variable, "saturation")) + res = s->set_saturation(s, val); + else if (!strcmp(variable, "gainceiling")) + res = s->set_gainceiling(s, (gainceiling_t)val); + else if (!strcmp(variable, "colorbar")) + res = s->set_colorbar(s, val); + else if (!strcmp(variable, "awb")) + res = s->set_whitebal(s, val); + else if (!strcmp(variable, "agc")) + res = s->set_gain_ctrl(s, val); + else if (!strcmp(variable, "aec")) + res = s->set_exposure_ctrl(s, val); + else if (!strcmp(variable, "hmirror")) + res = s->set_hmirror(s, val); + else if (!strcmp(variable, "vflip")) + res = s->set_vflip(s, val); + else if (!strcmp(variable, "awb_gain")) + res = s->set_awb_gain(s, val); + else if (!strcmp(variable, "agc_gain")) + res = s->set_agc_gain(s, val); + else if (!strcmp(variable, "aec_value")) + res = s->set_aec_value(s, val); + else if (!strcmp(variable, "aec2")) + res = s->set_aec2(s, val); + else if (!strcmp(variable, "dcw")) + res = s->set_dcw(s, val); + else if (!strcmp(variable, "bpc")) + res = s->set_bpc(s, val); + else if (!strcmp(variable, "wpc")) + res = s->set_wpc(s, val); + else if (!strcmp(variable, "raw_gma")) + res = s->set_raw_gma(s, val); + else if (!strcmp(variable, "lenc")) + res = s->set_lenc(s, val); + else if (!strcmp(variable, "special_effect")) + res = s->set_special_effect(s, val); + else if (!strcmp(variable, "wb_mode")) + res = s->set_wb_mode(s, val); + else if (!strcmp(variable, "ae_level")) + res = s->set_ae_level(s, val); #if CONFIG_LED_ILLUMINATOR_ENABLED - else if (!strcmp(variable, "led_intensity")) { - led_duty = val; - if (isStreaming) - enable_led(true); - } + else if (!strcmp(variable, "led_intensity")) { + led_duty = val; + if (isStreaming) + enable_led(true); + } #endif #if CONFIG_ESP_FACE_DETECT_ENABLED - else if (!strcmp(variable, "face_detect")) { - detection_enabled = val; + else if (!strcmp(variable, "face_detect")) { + detection_enabled = val; #if CONFIG_ESP_FACE_RECOGNITION_ENABLED - if (!detection_enabled) { - recognition_enabled = 0; - } -#endif + if (!detection_enabled) { + recognition_enabled = 0; } +#endif + } #if CONFIG_ESP_FACE_RECOGNITION_ENABLED - else if (!strcmp(variable, "face_enroll")){ - is_enrolling = !is_enrolling; - log_i("Enrolling: %s", is_enrolling?"true":"false"); - } - else if (!strcmp(variable, "face_recognize")) { - recognition_enabled = val; - if (recognition_enabled) { - detection_enabled = val; - } + else if (!strcmp(variable, "face_enroll")) { + is_enrolling = !is_enrolling; + log_i("Enrolling: %s", is_enrolling ? "true" : "false"); + } else if (!strcmp(variable, "face_recognize")) { + recognition_enabled = val; + if (recognition_enabled) { + detection_enabled = val; } + } #endif #endif - else { - log_i("Unknown command: %s", variable); - res = -1; - } + else { + log_i("Unknown command: %s", variable); + res = -1; + } - if (res < 0) { - return httpd_resp_send_500(req); - } + if (res < 0) { + return httpd_resp_send_500(req); + } - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - return httpd_resp_send(req, NULL, 0); + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + return httpd_resp_send(req, NULL, 0); } -static int print_reg(char * p, sensor_t * s, uint16_t reg, uint32_t mask){ - return sprintf(p, "\"0x%x\":%u,", reg, s->get_reg(s, reg, mask)); +static int print_reg(char *p, sensor_t *s, uint16_t reg, uint32_t mask) { + return sprintf(p, "\"0x%x\":%u,", reg, s->get_reg(s, reg, mask)); } -static esp_err_t status_handler(httpd_req_t *req) -{ - static char json_response[1024]; +static esp_err_t status_handler(httpd_req_t *req) { + static char json_response[1024]; - sensor_t *s = esp_camera_sensor_get(); - char *p = json_response; - *p++ = '{'; + sensor_t *s = esp_camera_sensor_get(); + char *p = json_response; + *p++ = '{'; - if(s->id.PID == OV5640_PID || s->id.PID == OV3660_PID){ - for(int reg = 0x3400; reg < 0x3406; reg+=2){ - p+=print_reg(p, s, reg, 0xFFF);//12 bit - } - p+=print_reg(p, s, 0x3406, 0xFF); + if (s->id.PID == OV5640_PID || s->id.PID == OV3660_PID) { + for (int reg = 0x3400; reg < 0x3406; reg += 2) { + p += print_reg(p, s, reg, 0xFFF); //12 bit + } + p += print_reg(p, s, 0x3406, 0xFF); - p+=print_reg(p, s, 0x3500, 0xFFFF0);//16 bit - p+=print_reg(p, s, 0x3503, 0xFF); - p+=print_reg(p, s, 0x350a, 0x3FF);//10 bit - p+=print_reg(p, s, 0x350c, 0xFFFF);//16 bit + p += print_reg(p, s, 0x3500, 0xFFFF0); //16 bit + p += print_reg(p, s, 0x3503, 0xFF); + p += print_reg(p, s, 0x350a, 0x3FF); //10 bit + p += print_reg(p, s, 0x350c, 0xFFFF); //16 bit - for(int reg = 0x5480; reg <= 0x5490; reg++){ - p+=print_reg(p, s, reg, 0xFF); - } - - for(int reg = 0x5380; reg <= 0x538b; reg++){ - p+=print_reg(p, s, reg, 0xFF); - } + for (int reg = 0x5480; reg <= 0x5490; reg++) { + p += print_reg(p, s, reg, 0xFF); + } - for(int reg = 0x5580; reg < 0x558a; reg++){ - p+=print_reg(p, s, reg, 0xFF); - } - p+=print_reg(p, s, 0x558a, 0x1FF);//9 bit - } else if(s->id.PID == OV2640_PID){ - p+=print_reg(p, s, 0xd3, 0xFF); - p+=print_reg(p, s, 0x111, 0xFF); - p+=print_reg(p, s, 0x132, 0xFF); + for (int reg = 0x5380; reg <= 0x538b; reg++) { + p += print_reg(p, s, reg, 0xFF); } - p += sprintf(p, "\"xclk\":%u,", s->xclk_freq_hz / 1000000); - p += sprintf(p, "\"pixformat\":%u,", s->pixformat); - p += sprintf(p, "\"framesize\":%u,", s->status.framesize); - p += sprintf(p, "\"quality\":%u,", s->status.quality); - p += sprintf(p, "\"brightness\":%d,", s->status.brightness); - p += sprintf(p, "\"contrast\":%d,", s->status.contrast); - p += sprintf(p, "\"saturation\":%d,", s->status.saturation); - p += sprintf(p, "\"sharpness\":%d,", s->status.sharpness); - p += sprintf(p, "\"special_effect\":%u,", s->status.special_effect); - p += sprintf(p, "\"wb_mode\":%u,", s->status.wb_mode); - p += sprintf(p, "\"awb\":%u,", s->status.awb); - p += sprintf(p, "\"awb_gain\":%u,", s->status.awb_gain); - p += sprintf(p, "\"aec\":%u,", s->status.aec); - p += sprintf(p, "\"aec2\":%u,", s->status.aec2); - p += sprintf(p, "\"ae_level\":%d,", s->status.ae_level); - p += sprintf(p, "\"aec_value\":%u,", s->status.aec_value); - p += sprintf(p, "\"agc\":%u,", s->status.agc); - p += sprintf(p, "\"agc_gain\":%u,", s->status.agc_gain); - p += sprintf(p, "\"gainceiling\":%u,", s->status.gainceiling); - p += sprintf(p, "\"bpc\":%u,", s->status.bpc); - p += sprintf(p, "\"wpc\":%u,", s->status.wpc); - p += sprintf(p, "\"raw_gma\":%u,", s->status.raw_gma); - p += sprintf(p, "\"lenc\":%u,", s->status.lenc); - p += sprintf(p, "\"hmirror\":%u,", s->status.hmirror); - p += sprintf(p, "\"dcw\":%u,", s->status.dcw); - p += sprintf(p, "\"colorbar\":%u", s->status.colorbar); + for (int reg = 0x5580; reg < 0x558a; reg++) { + p += print_reg(p, s, reg, 0xFF); + } + p += print_reg(p, s, 0x558a, 0x1FF); //9 bit + } else if (s->id.PID == OV2640_PID) { + p += print_reg(p, s, 0xd3, 0xFF); + p += print_reg(p, s, 0x111, 0xFF); + p += print_reg(p, s, 0x132, 0xFF); + } + + p += sprintf(p, "\"xclk\":%u,", s->xclk_freq_hz / 1000000); + p += sprintf(p, "\"pixformat\":%u,", s->pixformat); + p += sprintf(p, "\"framesize\":%u,", s->status.framesize); + p += sprintf(p, "\"quality\":%u,", s->status.quality); + p += sprintf(p, "\"brightness\":%d,", s->status.brightness); + p += sprintf(p, "\"contrast\":%d,", s->status.contrast); + p += sprintf(p, "\"saturation\":%d,", s->status.saturation); + p += sprintf(p, "\"sharpness\":%d,", s->status.sharpness); + p += sprintf(p, "\"special_effect\":%u,", s->status.special_effect); + p += sprintf(p, "\"wb_mode\":%u,", s->status.wb_mode); + p += sprintf(p, "\"awb\":%u,", s->status.awb); + p += sprintf(p, "\"awb_gain\":%u,", s->status.awb_gain); + p += sprintf(p, "\"aec\":%u,", s->status.aec); + p += sprintf(p, "\"aec2\":%u,", s->status.aec2); + p += sprintf(p, "\"ae_level\":%d,", s->status.ae_level); + p += sprintf(p, "\"aec_value\":%u,", s->status.aec_value); + p += sprintf(p, "\"agc\":%u,", s->status.agc); + p += sprintf(p, "\"agc_gain\":%u,", s->status.agc_gain); + p += sprintf(p, "\"gainceiling\":%u,", s->status.gainceiling); + p += sprintf(p, "\"bpc\":%u,", s->status.bpc); + p += sprintf(p, "\"wpc\":%u,", s->status.wpc); + p += sprintf(p, "\"raw_gma\":%u,", s->status.raw_gma); + p += sprintf(p, "\"lenc\":%u,", s->status.lenc); + p += sprintf(p, "\"hmirror\":%u,", s->status.hmirror); + p += sprintf(p, "\"dcw\":%u,", s->status.dcw); + p += sprintf(p, "\"colorbar\":%u", s->status.colorbar); #if CONFIG_LED_ILLUMINATOR_ENABLED - p += sprintf(p, ",\"led_intensity\":%u", led_duty); + p += sprintf(p, ",\"led_intensity\":%u", led_duty); #else - p += sprintf(p, ",\"led_intensity\":%d", -1); + p += sprintf(p, ",\"led_intensity\":%d", -1); #endif #if CONFIG_ESP_FACE_DETECT_ENABLED - p += sprintf(p, ",\"face_detect\":%u", detection_enabled); + p += sprintf(p, ",\"face_detect\":%u", detection_enabled); #if CONFIG_ESP_FACE_RECOGNITION_ENABLED - p += sprintf(p, ",\"face_enroll\":%u,", is_enrolling); - p += sprintf(p, "\"face_recognize\":%u", recognition_enabled); + p += sprintf(p, ",\"face_enroll\":%u,", is_enrolling); + p += sprintf(p, "\"face_recognize\":%u", recognition_enabled); #endif #endif - *p++ = '}'; - *p++ = 0; - httpd_resp_set_type(req, "application/json"); - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - return httpd_resp_send(req, json_response, strlen(json_response)); + *p++ = '}'; + *p++ = 0; + httpd_resp_set_type(req, "application/json"); + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + return httpd_resp_send(req, json_response, strlen(json_response)); } -static esp_err_t xclk_handler(httpd_req_t *req) -{ - char *buf = NULL; - char _xclk[32]; +static esp_err_t xclk_handler(httpd_req_t *req) { + char *buf = NULL; + char _xclk[32]; - if (parse_get(req, &buf) != ESP_OK) { - return ESP_FAIL; - } - if (httpd_query_key_value(buf, "xclk", _xclk, sizeof(_xclk)) != ESP_OK) { - free(buf); - httpd_resp_send_404(req); - return ESP_FAIL; - } + if (parse_get(req, &buf) != ESP_OK) { + return ESP_FAIL; + } + if (httpd_query_key_value(buf, "xclk", _xclk, sizeof(_xclk)) != ESP_OK) { free(buf); + httpd_resp_send_404(req); + return ESP_FAIL; + } + free(buf); - int xclk = atoi(_xclk); - log_i("Set XCLK: %d MHz", xclk); + int xclk = atoi(_xclk); + log_i("Set XCLK: %d MHz", xclk); - sensor_t *s = esp_camera_sensor_get(); - int res = s->set_xclk(s, LEDC_TIMER_0, xclk); - if (res) { - return httpd_resp_send_500(req); - } + sensor_t *s = esp_camera_sensor_get(); + int res = s->set_xclk(s, LEDC_TIMER_0, xclk); + if (res) { + return httpd_resp_send_500(req); + } - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - return httpd_resp_send(req, NULL, 0); + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + return httpd_resp_send(req, NULL, 0); } -static esp_err_t reg_handler(httpd_req_t *req) -{ - char *buf = NULL; - char _reg[32]; - char _mask[32]; - char _val[32]; +static esp_err_t reg_handler(httpd_req_t *req) { + char *buf = NULL; + char _reg[32]; + char _mask[32]; + char _val[32]; - if (parse_get(req, &buf) != ESP_OK) { - return ESP_FAIL; - } - if (httpd_query_key_value(buf, "reg", _reg, sizeof(_reg)) != ESP_OK || - httpd_query_key_value(buf, "mask", _mask, sizeof(_mask)) != ESP_OK || - httpd_query_key_value(buf, "val", _val, sizeof(_val)) != ESP_OK) { - free(buf); - httpd_resp_send_404(req); - return ESP_FAIL; - } + if (parse_get(req, &buf) != ESP_OK) { + return ESP_FAIL; + } + if (httpd_query_key_value(buf, "reg", _reg, sizeof(_reg)) != ESP_OK || httpd_query_key_value(buf, "mask", _mask, sizeof(_mask)) != ESP_OK || httpd_query_key_value(buf, "val", _val, sizeof(_val)) != ESP_OK) { free(buf); - - int reg = atoi(_reg); - int mask = atoi(_mask); - int val = atoi(_val); - log_i("Set Register: reg: 0x%02x, mask: 0x%02x, value: 0x%02x", reg, mask, val); - - sensor_t *s = esp_camera_sensor_get(); - int res = s->set_reg(s, reg, mask, val); - if (res) { - return httpd_resp_send_500(req); - } - - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - return httpd_resp_send(req, NULL, 0); + httpd_resp_send_404(req); + return ESP_FAIL; + } + free(buf); + + int reg = atoi(_reg); + int mask = atoi(_mask); + int val = atoi(_val); + log_i("Set Register: reg: 0x%02x, mask: 0x%02x, value: 0x%02x", reg, mask, val); + + sensor_t *s = esp_camera_sensor_get(); + int res = s->set_reg(s, reg, mask, val); + if (res) { + return httpd_resp_send_500(req); + } + + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + return httpd_resp_send(req, NULL, 0); } -static esp_err_t greg_handler(httpd_req_t *req) -{ - char *buf = NULL; - char _reg[32]; - char _mask[32]; +static esp_err_t greg_handler(httpd_req_t *req) { + char *buf = NULL; + char _reg[32]; + char _mask[32]; - if (parse_get(req, &buf) != ESP_OK) { - return ESP_FAIL; - } - if (httpd_query_key_value(buf, "reg", _reg, sizeof(_reg)) != ESP_OK || - httpd_query_key_value(buf, "mask", _mask, sizeof(_mask)) != ESP_OK) { - free(buf); - httpd_resp_send_404(req); - return ESP_FAIL; - } + if (parse_get(req, &buf) != ESP_OK) { + return ESP_FAIL; + } + if (httpd_query_key_value(buf, "reg", _reg, sizeof(_reg)) != ESP_OK || httpd_query_key_value(buf, "mask", _mask, sizeof(_mask)) != ESP_OK) { free(buf); - - int reg = atoi(_reg); - int mask = atoi(_mask); - sensor_t *s = esp_camera_sensor_get(); - int res = s->get_reg(s, reg, mask); - if (res < 0) { - return httpd_resp_send_500(req); - } - log_i("Get Register: reg: 0x%02x, mask: 0x%02x, value: 0x%02x", reg, mask, res); - - char buffer[20]; - const char * val = itoa(res, buffer, 10); - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - return httpd_resp_send(req, val, strlen(val)); + httpd_resp_send_404(req); + return ESP_FAIL; + } + free(buf); + + int reg = atoi(_reg); + int mask = atoi(_mask); + sensor_t *s = esp_camera_sensor_get(); + int res = s->get_reg(s, reg, mask); + if (res < 0) { + return httpd_resp_send_500(req); + } + log_i("Get Register: reg: 0x%02x, mask: 0x%02x, value: 0x%02x", reg, mask, res); + + char buffer[20]; + const char *val = itoa(res, buffer, 10); + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + return httpd_resp_send(req, val, strlen(val)); } -static int parse_get_var(char *buf, const char * key, int def) -{ - char _int[16]; - if(httpd_query_key_value(buf, key, _int, sizeof(_int)) != ESP_OK){ - return def; - } - return atoi(_int); +static int parse_get_var(char *buf, const char *key, int def) { + char _int[16]; + if (httpd_query_key_value(buf, key, _int, sizeof(_int)) != ESP_OK) { + return def; + } + return atoi(_int); } -static esp_err_t pll_handler(httpd_req_t *req) -{ - char *buf = NULL; - - if (parse_get(req, &buf) != ESP_OK) { - return ESP_FAIL; - } - - int bypass = parse_get_var(buf, "bypass", 0); - int mul = parse_get_var(buf, "mul", 0); - int sys = parse_get_var(buf, "sys", 0); - int root = parse_get_var(buf, "root", 0); - int pre = parse_get_var(buf, "pre", 0); - int seld5 = parse_get_var(buf, "seld5", 0); - int pclken = parse_get_var(buf, "pclken", 0); - int pclk = parse_get_var(buf, "pclk", 0); - free(buf); - - log_i("Set Pll: bypass: %d, mul: %d, sys: %d, root: %d, pre: %d, seld5: %d, pclken: %d, pclk: %d", bypass, mul, sys, root, pre, seld5, pclken, pclk); - sensor_t *s = esp_camera_sensor_get(); - int res = s->set_pll(s, bypass, mul, sys, root, pre, seld5, pclken, pclk); - if (res) { - return httpd_resp_send_500(req); - } +static esp_err_t pll_handler(httpd_req_t *req) { + char *buf = NULL; - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - return httpd_resp_send(req, NULL, 0); + if (parse_get(req, &buf) != ESP_OK) { + return ESP_FAIL; + } + + int bypass = parse_get_var(buf, "bypass", 0); + int mul = parse_get_var(buf, "mul", 0); + int sys = parse_get_var(buf, "sys", 0); + int root = parse_get_var(buf, "root", 0); + int pre = parse_get_var(buf, "pre", 0); + int seld5 = parse_get_var(buf, "seld5", 0); + int pclken = parse_get_var(buf, "pclken", 0); + int pclk = parse_get_var(buf, "pclk", 0); + free(buf); + + log_i("Set Pll: bypass: %d, mul: %d, sys: %d, root: %d, pre: %d, seld5: %d, pclken: %d, pclk: %d", bypass, mul, sys, root, pre, seld5, pclken, pclk); + sensor_t *s = esp_camera_sensor_get(); + int res = s->set_pll(s, bypass, mul, sys, root, pre, seld5, pclken, pclk); + if (res) { + return httpd_resp_send_500(req); + } + + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + return httpd_resp_send(req, NULL, 0); } -static esp_err_t win_handler(httpd_req_t *req) -{ - char *buf = NULL; - - if (parse_get(req, &buf) != ESP_OK) { - return ESP_FAIL; - } +static esp_err_t win_handler(httpd_req_t *req) { + char *buf = NULL; - int startX = parse_get_var(buf, "sx", 0); - int startY = parse_get_var(buf, "sy", 0); - int endX = parse_get_var(buf, "ex", 0); - int endY = parse_get_var(buf, "ey", 0); - int offsetX = parse_get_var(buf, "offx", 0); - int offsetY = parse_get_var(buf, "offy", 0); - int totalX = parse_get_var(buf, "tx", 0); - int totalY = parse_get_var(buf, "ty", 0); - int outputX = parse_get_var(buf, "ox", 0); - int outputY = parse_get_var(buf, "oy", 0); - bool scale = parse_get_var(buf, "scale", 0) == 1; - bool binning = parse_get_var(buf, "binning", 0) == 1; - free(buf); - - log_i("Set Window: Start: %d %d, End: %d %d, Offset: %d %d, Total: %d %d, Output: %d %d, Scale: %u, Binning: %u", startX, startY, endX, endY, offsetX, offsetY, totalX, totalY, outputX, outputY, scale, binning); - sensor_t *s = esp_camera_sensor_get(); - int res = s->set_res_raw(s, startX, startY, endX, endY, offsetX, offsetY, totalX, totalY, outputX, outputY, scale, binning); - if (res) { - return httpd_resp_send_500(req); - } - - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - return httpd_resp_send(req, NULL, 0); + if (parse_get(req, &buf) != ESP_OK) { + return ESP_FAIL; + } + + int startX = parse_get_var(buf, "sx", 0); + int startY = parse_get_var(buf, "sy", 0); + int endX = parse_get_var(buf, "ex", 0); + int endY = parse_get_var(buf, "ey", 0); + int offsetX = parse_get_var(buf, "offx", 0); + int offsetY = parse_get_var(buf, "offy", 0); + int totalX = parse_get_var(buf, "tx", 0); + int totalY = parse_get_var(buf, "ty", 0); + int outputX = parse_get_var(buf, "ox", 0); + int outputY = parse_get_var(buf, "oy", 0); + bool scale = parse_get_var(buf, "scale", 0) == 1; + bool binning = parse_get_var(buf, "binning", 0) == 1; + free(buf); + + log_i("Set Window: Start: %d %d, End: %d %d, Offset: %d %d, Total: %d %d, Output: %d %d, Scale: %u, Binning: %u", startX, startY, endX, endY, offsetX, offsetY, totalX, totalY, outputX, outputY, scale, binning); + sensor_t *s = esp_camera_sensor_get(); + int res = s->set_res_raw(s, startX, startY, endX, endY, offsetX, offsetY, totalX, totalY, outputX, outputY, scale, binning); + if (res) { + return httpd_resp_send_500(req); + } + + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + return httpd_resp_send(req, NULL, 0); } -static esp_err_t index_handler(httpd_req_t *req) -{ - httpd_resp_set_type(req, "text/html"); - httpd_resp_set_hdr(req, "Content-Encoding", "gzip"); - sensor_t *s = esp_camera_sensor_get(); - if (s != NULL) { - if (s->id.PID == OV3660_PID) { - return httpd_resp_send(req, (const char *)index_ov3660_html_gz, index_ov3660_html_gz_len); - } else if (s->id.PID == OV5640_PID) { - return httpd_resp_send(req, (const char *)index_ov5640_html_gz, index_ov5640_html_gz_len); - } else { - return httpd_resp_send(req, (const char *)index_ov2640_html_gz, index_ov2640_html_gz_len); - } +static esp_err_t index_handler(httpd_req_t *req) { + httpd_resp_set_type(req, "text/html"); + httpd_resp_set_hdr(req, "Content-Encoding", "gzip"); + sensor_t *s = esp_camera_sensor_get(); + if (s != NULL) { + if (s->id.PID == OV3660_PID) { + return httpd_resp_send(req, (const char *)index_ov3660_html_gz, index_ov3660_html_gz_len); + } else if (s->id.PID == OV5640_PID) { + return httpd_resp_send(req, (const char *)index_ov5640_html_gz, index_ov5640_html_gz_len); } else { - log_e("Camera sensor not found"); - return httpd_resp_send_500(req); + return httpd_resp_send(req, (const char *)index_ov2640_html_gz, index_ov2640_html_gz_len); } + } else { + log_e("Camera sensor not found"); + return httpd_resp_send_500(req); + } } -void startCameraServer() -{ - httpd_config_t config = HTTPD_DEFAULT_CONFIG(); - config.max_uri_handlers = 16; - - httpd_uri_t index_uri = { - .uri = "/", - .method = HTTP_GET, - .handler = index_handler, - .user_ctx = NULL +void startCameraServer() { + httpd_config_t config = HTTPD_DEFAULT_CONFIG(); + config.max_uri_handlers = 16; + + httpd_uri_t index_uri = { + .uri = "/", + .method = HTTP_GET, + .handler = index_handler, + .user_ctx = NULL #ifdef CONFIG_HTTPD_WS_SUPPORT - , - .is_websocket = true, - .handle_ws_control_frames = false, - .supported_subprotocol = NULL -#endif - }; - - httpd_uri_t status_uri = { - .uri = "/status", - .method = HTTP_GET, - .handler = status_handler, - .user_ctx = NULL + , + .is_websocket = true, + .handle_ws_control_frames = false, + .supported_subprotocol = NULL +#endif + }; + + httpd_uri_t status_uri = { + .uri = "/status", + .method = HTTP_GET, + .handler = status_handler, + .user_ctx = NULL #ifdef CONFIG_HTTPD_WS_SUPPORT - , - .is_websocket = true, - .handle_ws_control_frames = false, - .supported_subprotocol = NULL -#endif - }; - - httpd_uri_t cmd_uri = { - .uri = "/control", - .method = HTTP_GET, - .handler = cmd_handler, - .user_ctx = NULL + , + .is_websocket = true, + .handle_ws_control_frames = false, + .supported_subprotocol = NULL +#endif + }; + + httpd_uri_t cmd_uri = { + .uri = "/control", + .method = HTTP_GET, + .handler = cmd_handler, + .user_ctx = NULL #ifdef CONFIG_HTTPD_WS_SUPPORT - , - .is_websocket = true, - .handle_ws_control_frames = false, - .supported_subprotocol = NULL -#endif - }; - - httpd_uri_t capture_uri = { - .uri = "/capture", - .method = HTTP_GET, - .handler = capture_handler, - .user_ctx = NULL + , + .is_websocket = true, + .handle_ws_control_frames = false, + .supported_subprotocol = NULL +#endif + }; + + httpd_uri_t capture_uri = { + .uri = "/capture", + .method = HTTP_GET, + .handler = capture_handler, + .user_ctx = NULL #ifdef CONFIG_HTTPD_WS_SUPPORT - , - .is_websocket = true, - .handle_ws_control_frames = false, - .supported_subprotocol = NULL -#endif - }; - - httpd_uri_t stream_uri = { - .uri = "/stream", - .method = HTTP_GET, - .handler = stream_handler, - .user_ctx = NULL + , + .is_websocket = true, + .handle_ws_control_frames = false, + .supported_subprotocol = NULL +#endif + }; + + httpd_uri_t stream_uri = { + .uri = "/stream", + .method = HTTP_GET, + .handler = stream_handler, + .user_ctx = NULL #ifdef CONFIG_HTTPD_WS_SUPPORT - , - .is_websocket = true, - .handle_ws_control_frames = false, - .supported_subprotocol = NULL -#endif - }; - - httpd_uri_t bmp_uri = { - .uri = "/bmp", - .method = HTTP_GET, - .handler = bmp_handler, - .user_ctx = NULL + , + .is_websocket = true, + .handle_ws_control_frames = false, + .supported_subprotocol = NULL +#endif + }; + + httpd_uri_t bmp_uri = { + .uri = "/bmp", + .method = HTTP_GET, + .handler = bmp_handler, + .user_ctx = NULL #ifdef CONFIG_HTTPD_WS_SUPPORT - , - .is_websocket = true, - .handle_ws_control_frames = false, - .supported_subprotocol = NULL -#endif - }; - - httpd_uri_t xclk_uri = { - .uri = "/xclk", - .method = HTTP_GET, - .handler = xclk_handler, - .user_ctx = NULL + , + .is_websocket = true, + .handle_ws_control_frames = false, + .supported_subprotocol = NULL +#endif + }; + + httpd_uri_t xclk_uri = { + .uri = "/xclk", + .method = HTTP_GET, + .handler = xclk_handler, + .user_ctx = NULL #ifdef CONFIG_HTTPD_WS_SUPPORT - , - .is_websocket = true, - .handle_ws_control_frames = false, - .supported_subprotocol = NULL -#endif - }; - - httpd_uri_t reg_uri = { - .uri = "/reg", - .method = HTTP_GET, - .handler = reg_handler, - .user_ctx = NULL + , + .is_websocket = true, + .handle_ws_control_frames = false, + .supported_subprotocol = NULL +#endif + }; + + httpd_uri_t reg_uri = { + .uri = "/reg", + .method = HTTP_GET, + .handler = reg_handler, + .user_ctx = NULL #ifdef CONFIG_HTTPD_WS_SUPPORT - , - .is_websocket = true, - .handle_ws_control_frames = false, - .supported_subprotocol = NULL -#endif - }; - - httpd_uri_t greg_uri = { - .uri = "/greg", - .method = HTTP_GET, - .handler = greg_handler, - .user_ctx = NULL + , + .is_websocket = true, + .handle_ws_control_frames = false, + .supported_subprotocol = NULL +#endif + }; + + httpd_uri_t greg_uri = { + .uri = "/greg", + .method = HTTP_GET, + .handler = greg_handler, + .user_ctx = NULL #ifdef CONFIG_HTTPD_WS_SUPPORT - , - .is_websocket = true, - .handle_ws_control_frames = false, - .supported_subprotocol = NULL -#endif - }; - - httpd_uri_t pll_uri = { - .uri = "/pll", - .method = HTTP_GET, - .handler = pll_handler, - .user_ctx = NULL + , + .is_websocket = true, + .handle_ws_control_frames = false, + .supported_subprotocol = NULL +#endif + }; + + httpd_uri_t pll_uri = { + .uri = "/pll", + .method = HTTP_GET, + .handler = pll_handler, + .user_ctx = NULL #ifdef CONFIG_HTTPD_WS_SUPPORT - , - .is_websocket = true, - .handle_ws_control_frames = false, - .supported_subprotocol = NULL -#endif - }; - - httpd_uri_t win_uri = { - .uri = "/resolution", - .method = HTTP_GET, - .handler = win_handler, - .user_ctx = NULL + , + .is_websocket = true, + .handle_ws_control_frames = false, + .supported_subprotocol = NULL +#endif + }; + + httpd_uri_t win_uri = { + .uri = "/resolution", + .method = HTTP_GET, + .handler = win_handler, + .user_ctx = NULL #ifdef CONFIG_HTTPD_WS_SUPPORT - , - .is_websocket = true, - .handle_ws_control_frames = false, - .supported_subprotocol = NULL + , + .is_websocket = true, + .handle_ws_control_frames = false, + .supported_subprotocol = NULL #endif - }; + }; - ra_filter_init(&ra_filter, 20); + ra_filter_init(&ra_filter, 20); #if CONFIG_ESP_FACE_RECOGNITION_ENABLED - recognizer.set_partition(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "fr"); - - // load ids from flash partition - recognizer.set_ids_from_flash(); -#endif - log_i("Starting web server on port: '%d'", config.server_port); - if (httpd_start(&camera_httpd, &config) == ESP_OK) - { - httpd_register_uri_handler(camera_httpd, &index_uri); - httpd_register_uri_handler(camera_httpd, &cmd_uri); - httpd_register_uri_handler(camera_httpd, &status_uri); - httpd_register_uri_handler(camera_httpd, &capture_uri); - httpd_register_uri_handler(camera_httpd, &bmp_uri); - - httpd_register_uri_handler(camera_httpd, &xclk_uri); - httpd_register_uri_handler(camera_httpd, ®_uri); - httpd_register_uri_handler(camera_httpd, &greg_uri); - httpd_register_uri_handler(camera_httpd, &pll_uri); - httpd_register_uri_handler(camera_httpd, &win_uri); - } - - config.server_port += 1; - config.ctrl_port += 1; - log_i("Starting stream server on port: '%d'", config.server_port); - if (httpd_start(&stream_httpd, &config) == ESP_OK) - { - httpd_register_uri_handler(stream_httpd, &stream_uri); - } + recognizer.set_partition(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "fr"); + + // load ids from flash partition + recognizer.set_ids_from_flash(); +#endif + log_i("Starting web server on port: '%d'", config.server_port); + if (httpd_start(&camera_httpd, &config) == ESP_OK) { + httpd_register_uri_handler(camera_httpd, &index_uri); + httpd_register_uri_handler(camera_httpd, &cmd_uri); + httpd_register_uri_handler(camera_httpd, &status_uri); + httpd_register_uri_handler(camera_httpd, &capture_uri); + httpd_register_uri_handler(camera_httpd, &bmp_uri); + + httpd_register_uri_handler(camera_httpd, &xclk_uri); + httpd_register_uri_handler(camera_httpd, ®_uri); + httpd_register_uri_handler(camera_httpd, &greg_uri); + httpd_register_uri_handler(camera_httpd, &pll_uri); + httpd_register_uri_handler(camera_httpd, &win_uri); + } + + config.server_port += 1; + config.ctrl_port += 1; + log_i("Starting stream server on port: '%d'", config.server_port); + if (httpd_start(&stream_httpd, &config) == ESP_OK) { + httpd_register_uri_handler(stream_httpd, &stream_uri); + } } -void setupLedFlash(int pin) -{ - #if CONFIG_LED_ILLUMINATOR_ENABLED - ledcAttach(pin, 5000, 8); - #else - log_i("LED flash is disabled -> CONFIG_LED_ILLUMINATOR_ENABLED = 0"); - #endif +void setupLedFlash(int pin) { +#if CONFIG_LED_ILLUMINATOR_ENABLED + ledcAttach(pin, 5000, 8); +#else + log_i("LED flash is disabled -> CONFIG_LED_ILLUMINATOR_ENABLED = 0"); +#endif } diff --git a/libraries/ESP32/examples/Camera/CameraWebServer/camera_index.h b/libraries/ESP32/examples/Camera/CameraWebServer/camera_index.h index fa42e690779..e2b9ba381ea 100644 --- a/libraries/ESP32/examples/Camera/CameraWebServer/camera_index.h +++ b/libraries/ESP32/examples/Camera/CameraWebServer/camera_index.h @@ -3,1569 +3,1568 @@ //File: index_ov2640.html.gz, Size: 6787 #define index_ov2640_html_gz_len 6787 const uint8_t index_ov2640_html_gz[] = { - 0x1F, 0x8B, 0x08, 0x08, 0x23, 0xFC, 0x69, 0x5E, 0x00, 0x03, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x5F, - 0x6F, 0x76, 0x32, 0x36, 0x34, 0x30, 0x2E, 0x68, 0x74, 0x6D, 0x6C, 0x00, 0xED, 0x3D, 0x6B, 0x73, - 0xDB, 0x46, 0x92, 0xDF, 0xFD, 0x2B, 0x60, 0x24, 0x6B, 0x92, 0x25, 0x92, 0x22, 0x29, 0x4A, 0x96, - 0x15, 0x89, 0x3E, 0x5B, 0x96, 0x1F, 0xB5, 0x76, 0xE2, 0xB5, 0x12, 0xC7, 0x5B, 0xA9, 0x2D, 0x07, - 0x04, 0x86, 0x24, 0x62, 0x10, 0xE0, 0x02, 0xA0, 0x48, 0x26, 0xA5, 0xDF, 0x71, 0x3F, 0xE8, 0xFE, - 0xD8, 0x75, 0xCF, 0x03, 0x18, 0x00, 0x83, 0x07, 0x49, 0x89, 0xF4, 0xFA, 0x8E, 0x4E, 0x45, 0x78, - 0x4C, 0xF7, 0xF4, 0xBB, 0x7B, 0x66, 0x30, 0xC0, 0xF9, 0x43, 0xCB, 0x33, 0xC3, 0xD5, 0x8C, 0x68, - 0x93, 0x70, 0xEA, 0x0C, 0x1E, 0x9C, 0xB3, 0x3F, 0x1A, 0xFC, 0xCE, 0x27, 0xC4, 0xB0, 0xD8, 0x21, - 0x3D, 0x9D, 0x92, 0xD0, 0xD0, 0xCC, 0x89, 0xE1, 0x07, 0x24, 0xBC, 0xD0, 0xE7, 0xE1, 0xA8, 0x75, - 0xAA, 0xA7, 0x6F, 0xBB, 0xC6, 0x94, 0x5C, 0xE8, 0x37, 0x36, 0x59, 0xCC, 0x3C, 0x3F, 0xD4, 0x35, - 0xD3, 0x73, 0x43, 0xE2, 0x42, 0xF3, 0x85, 0x6D, 0x85, 0x93, 0x0B, 0x8B, 0xDC, 0xD8, 0x26, 0x69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 0x31, 0x95, 0xB0, 0x59, 0x2D, 0x8C, 0x41, - 0xE1, 0xC4, 0x0E, 0x60, 0x10, 0x8E, 0x9F, 0xB3, 0x24, 0x0F, 0xF5, 0x28, 0x21, 0x96, 0xB2, 0x97, - 0x9D, 0xED, 0x4F, 0x88, 0x93, 0xC1, 0xC4, 0xB2, 0x7C, 0xC8, 0x79, 0xCC, 0x04, 0xA2, 0xA2, 0x79, - 0xB4, 0x35, 0x44, 0x18, 0xDD, 0xFE, 0x6A, 0xA5, 0xA8, 0x66, 0xA0, 0x54, 0x90, 0x11, 0x58, 0x2C, - 0xCB, 0x98, 0xD7, 0x8C, 0x34, 0x55, 0x93, 0x95, 0x05, 0x1A, 0xC5, 0x39, 0x7B, 0x65, 0x94, 0xCF, - 0xD7, 0x0A, 0x93, 0x38, 0x4B, 0xAC, 0xEC, 0x77, 0x7E, 0x28, 0x76, 0x16, 0xB0, 0x33, 0x2C, 0x18, - 0x07, 0x0F, 0xCE, 0x0F, 0x27, 0xE1, 0xD4, 0x19, 0x3C, 0xF8, 0x5F, 0x94, 0x18, 0xA6, 0xBF, 0xBA, - 0xAB, 0x00, 0x00 + 0x1F, 0x8B, 0x08, 0x08, 0x23, 0xFC, 0x69, 0x5E, 0x00, 0x03, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x5F, + 0x6F, 0x76, 0x32, 0x36, 0x34, 0x30, 0x2E, 0x68, 0x74, 0x6D, 0x6C, 0x00, 0xED, 0x3D, 0x6B, 0x73, + 0xDB, 0x46, 0x92, 0xDF, 0xFD, 0x2B, 0x60, 0x24, 0x6B, 0x92, 0x25, 0x92, 0x22, 0x29, 0x4A, 0x96, + 0x15, 0x89, 0x3E, 0x5B, 0x96, 0x1F, 0xB5, 0x76, 0xE2, 0xB5, 0x12, 0xC7, 0x5B, 0xA9, 0x2D, 0x07, + 0x04, 0x86, 0x24, 0x62, 0x10, 0xE0, 0x02, 0xA0, 0x48, 0x26, 0xA5, 0xDF, 0x71, 0x3F, 0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0x33, 0x2C, 0x18, + 0x07, 0x0F, 0xCE, 0x0F, 0x27, 0xE1, 0xD4, 0x19, 0x3C, 0xF8, 0x5F, 0x94, 0x18, 0xA6, 0xBF, 0xBA, + 0xAB, 0x00, 0x00 }; //File: index_ov3660.html.gz, Size: 8887 #define index_ov3660_html_gz_len 8887 const uint8_t index_ov3660_html_gz[] = { - 0x1F, 0x8B, 0x08, 0x08, 0xA3, 0xFA, 0x69, 0x5E, 0x00, 0x03, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x5F, - 0x6F, 0x76, 0x33, 0x36, 0x36, 0x30, 0x2E, 0x68, 0x74, 0x6D, 0x6C, 0x00, 0xED, 0x3D, 0x69, 0x73, - 0xDB, 0x46, 0xB2, 0xDF, 0xFD, 0x2B, 0x60, 0x24, 0x6B, 0x51, 0x65, 0x91, 0xE2, 0xAD, 0x23, 0x12, - 0xFD, 0x6C, 0x59, 0xB1, 0x53, 0x1B, 0x67, 0xBD, 0x71, 0xE2, 0x24, 0xB5, 0xB5, 0xE5, 0x80, 0xC4, - 0x90, 0x44, 0x0C, 0x02, 0x5C, 0x00, 0xD4, 0x91, 0x94, 0x7E, 0xC7, 0xFB, 0x41, 0xEF, 0x8F, 0xBD, - 0xEE, 0x39, 0x70, 0x71, 0x00, 0x0C, 0x00, 0x11, 0x52, 0xF2, 0x1E, 0x5D, 0x65, 0xE1, 0x98, 0xEE, - 0xE9, 0x7B, 0x7A, 0x7A, 0x06, 0xC0, 0xD9, 0x53, 0xD3, 0x9D, 0x05, 0xB7, 0x6B, 0xA2, 0x2D, 0x83, - 0x95, 0x3D, 0x79, 0x72, 0xC6, 0xFE, 0x68, 0xF0, 0x3B, 0x5B, 0x12, 0xC3, 0x64, 0x87, 0xF4, 0x74, - 0x45, 0x02, 0x43, 0x9B, 0x2D, 0x0D, 0xCF, 0x27, 0xC1, 0xB9, 0xBE, 0x09, 0xE6, 0xED, 0x63, 0x3D, - 0x7D, 0xDB, 0x31, 0x56, 0xE4, 0x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 0x7C, 0x75, 0x28, 0x79, 0xAA, 0x87, 0xA3, + 0x53, 0x21, 0x7B, 0xDB, 0x25, 0xF4, 0x84, 0x38, 0x19, 0x4C, 0x24, 0xCB, 0xA7, 0x9C, 0xC7, 0xAD, + 0xC0, 0x92, 0x57, 0xD6, 0x2A, 0x21, 0xC2, 0xF0, 0xF6, 0xA3, 0x95, 0xA2, 0x9C, 0x81, 0x42, 0x41, + 0x86, 0x60, 0x91, 0x2C, 0x23, 0x5E, 0xB7, 0xA4, 0x29, 0xAB, 0x1D, 0xE6, 0x68, 0x14, 0x4B, 0xE1, + 0xD2, 0x68, 0x9E, 0xAD, 0x15, 0x26, 0x71, 0x36, 0xCA, 0xB1, 0xDF, 0xD9, 0xA1, 0x78, 0x14, 0x8A, + 0x9D, 0x61, 0xF6, 0x36, 0x79, 0x72, 0x76, 0xB8, 0x0C, 0x56, 0xF6, 0xE4, 0xC9, 0xFF, 0x02, 0x49, + 0x60, 0xC8, 0xA8, 0x55, 0x0C, 0x01, 0x00 }; //File: index_ov5640.html.gz, Size: 9124 #define index_ov5640_html_gz_len 9124 const uint8_t index_ov5640_html_gz[] = { - 0x1F, 0x8B, 0x08, 0x08, 0xD9, 0x6C, 0x6A, 0x5E, 0x00, 0x03, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x5F, - 0x6F, 0x76, 0x35, 0x36, 0x34, 0x30, 0x2E, 0x68, 0x74, 0x6D, 0x6C, 0x00, 0xED, 0x3D, 0x6B, 0x77, - 0xDB, 0xB6, 0x92, 0xDF, 0xF3, 0x2B, 0x18, 0xF5, 0x6E, 0x24, 0x9F, 0x58, 0xB6, 0xA8, 0x97, 0x1F, - 0xB1, 0x95, 0x4D, 0x1C, 0x27, 0xE9, 0xB9, 0x4D, 0x6F, 0x1A, 0xA7, 0x69, 0x7B, 0xBA, 0x3D, 0x29, - 0x25, 0x41, 0x12, 0x1B, 0x8A, 0xD4, 0x25, 0x29, 0xCB, 0x6E, 0x8E, 0x7F, 0xC7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 0xCF, 0x1D, - 0xA2, 0x58, 0x33, 0x81, 0xC9, 0x70, 0x6A, 0x97, 0x0B, 0x1A, 0xB6, 0x14, 0xA0, 0x43, 0x3A, 0x32, - 0xA1, 0x83, 0x46, 0x6C, 0x6C, 0x0B, 0x4F, 0x95, 0x84, 0x15, 0xB6, 0x8E, 0x9C, 0x27, 0x42, 0xC0, - 0x26, 0x4A, 0x03, 0xAD, 0x97, 0x2C, 0x27, 0xB0, 0x84, 0x87, 0x31, 0x9B, 0x48, 0x6B, 0xC4, 0x06, - 0x21, 0x4B, 0xB1, 0x36, 0xA1, 0x83, 0x30, 0xF8, 0x34, 0x32, 0x73, 0x49, 0x61, 0xE5, 0xEA, 0xDA, - 0x7B, 0x8B, 0xE0, 0x34, 0x8F, 0xBF, 0xA9, 0xF3, 0xE2, 0xDB, 0xD7, 0x9A, 0xE3, 0x6A, 0x96, 0xB3, - 0x22, 0xB8, 0x59, 0x34, 0x58, 0x0A, 0xD6, 0x86, 0x04, 0x12, 0x4B, 0xC2, 0x26, 0xD3, 0x18, 0x87, - 0xFC, 0x99, 0xE9, 0x41, 0xEA, 0x8E, 0xEF, 0x93, 0x25, 0x8F, 0x6B, 0x61, 0x31, 0x34, 0x97, 0xBD, - 0xF5, 0xAD, 0x55, 0x31, 0x71, 0x32, 0x98, 0x48, 0x96, 0x8F, 0x39, 0x8F, 0x6B, 0xC1, 0x28, 0x6B, - 0xFA, 0x5E, 0x40, 0x84, 0xE1, 0xED, 0x07, 0x2B, 0x45, 0x39, 0x03, 0xB9, 0x82, 0x0C, 0xC1, 0x22, - 0x59, 0x46, 0xBC, 0xAE, 0x49, 0x53, 0x56, 0x23, 0xC9, 0xD0, 0x28, 0x96, 0x0B, 0xA5, 0x71, 0x3E, - 0x5D, 0x2B, 0x4C, 0xE2, 0x2C, 0x55, 0x67, 0xBF, 0xB3, 0xC3, 0xE0, 0xB1, 0x39, 0x76, 0x86, 0x8B, - 0x05, 0x83, 0x47, 0x67, 0x87, 0x33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, 0x12, 0x4B, 0xC2, 0x26, 0xD3, 0x18, 0x87, + 0xFC, 0x99, 0xE9, 0x41, 0xEA, 0x8E, 0xEF, 0x93, 0x25, 0x8F, 0x6B, 0x61, 0x31, 0x34, 0x97, 0xBD, + 0xF5, 0xAD, 0x55, 0x31, 0x71, 0x32, 0x98, 0x48, 0x96, 0x8F, 0x39, 0x8F, 0x6B, 0xC1, 0x28, 0x6B, + 0xFA, 0x5E, 0x40, 0x84, 0xE1, 0xED, 0x07, 0x2B, 0x45, 0x39, 0x03, 0xB9, 0x82, 0x0C, 0xC1, 0x22, + 0x59, 0x46, 0xBC, 0xAE, 0x49, 0x53, 0x56, 0x23, 0xC9, 0xD0, 0x28, 0x96, 0x0B, 0xA5, 0x71, 0x3E, + 0x5D, 0x2B, 0x4C, 0xE2, 0x2C, 0x55, 0x67, 0xBF, 0xB3, 0xC3, 0xE0, 0xB1, 0x39, 0x76, 0x86, 0x8B, + 0x05, 0x83, 0x47, 0x67, 0x87, 0x33, 0x7F, 0x6E, 0x0D, 0x1E, 0xFD, 0x2F, 0x5E, 0x72, 0x0B, 0x89, + 0x42, 0x10, 0x01, 0x00 }; - diff --git a/libraries/ESP32/examples/Camera/CameraWebServer/camera_pins.h b/libraries/ESP32/examples/Camera/CameraWebServer/camera_pins.h index caa97bed606..113abc506c8 100644 --- a/libraries/ESP32/examples/Camera/CameraWebServer/camera_pins.h +++ b/libraries/ESP32/examples/Camera/CameraWebServer/camera_pins.h @@ -1,277 +1,277 @@ #if defined(CAMERA_MODEL_WROVER_KIT) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 21 -#define SIOD_GPIO_NUM 26 -#define SIOC_GPIO_NUM 27 - -#define Y9_GPIO_NUM 35 -#define Y8_GPIO_NUM 34 -#define Y7_GPIO_NUM 39 -#define Y6_GPIO_NUM 36 -#define Y5_GPIO_NUM 19 -#define Y4_GPIO_NUM 18 -#define Y3_GPIO_NUM 5 -#define Y2_GPIO_NUM 4 -#define VSYNC_GPIO_NUM 25 -#define HREF_GPIO_NUM 23 -#define PCLK_GPIO_NUM 22 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 21 +#define SIOD_GPIO_NUM 26 +#define SIOC_GPIO_NUM 27 + +#define Y9_GPIO_NUM 35 +#define Y8_GPIO_NUM 34 +#define Y7_GPIO_NUM 39 +#define Y6_GPIO_NUM 36 +#define Y5_GPIO_NUM 19 +#define Y4_GPIO_NUM 18 +#define Y3_GPIO_NUM 5 +#define Y2_GPIO_NUM 4 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 23 +#define PCLK_GPIO_NUM 22 #elif defined(CAMERA_MODEL_ESP_EYE) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 4 -#define SIOD_GPIO_NUM 18 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 36 -#define Y8_GPIO_NUM 37 -#define Y7_GPIO_NUM 38 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 35 -#define Y4_GPIO_NUM 14 -#define Y3_GPIO_NUM 13 -#define Y2_GPIO_NUM 34 -#define VSYNC_GPIO_NUM 5 -#define HREF_GPIO_NUM 27 -#define PCLK_GPIO_NUM 25 - -#define LED_GPIO_NUM 22 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 4 +#define SIOD_GPIO_NUM 18 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 37 +#define Y7_GPIO_NUM 38 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 35 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 13 +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 + +#define LED_GPIO_NUM 22 #elif defined(CAMERA_MODEL_M5STACK_PSRAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 #elif defined(CAMERA_MODEL_M5STACK_V2_PSRAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 22 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 25 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 22 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 #elif defined(CAMERA_MODEL_M5STACK_WIDE) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 22 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 25 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 - -#define LED_GPIO_NUM 2 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 22 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 + +#define LED_GPIO_NUM 2 #elif defined(CAMERA_MODEL_M5STACK_ESP32CAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 17 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 17 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 #elif defined(CAMERA_MODEL_M5STACK_UNITCAM) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 32 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 32 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 #elif defined(CAMERA_MODEL_AI_THINKER) -#define PWDN_GPIO_NUM 32 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 0 -#define SIOD_GPIO_NUM 26 -#define SIOC_GPIO_NUM 27 - -#define Y9_GPIO_NUM 35 -#define Y8_GPIO_NUM 34 -#define Y7_GPIO_NUM 39 -#define Y6_GPIO_NUM 36 -#define Y5_GPIO_NUM 21 -#define Y4_GPIO_NUM 19 -#define Y3_GPIO_NUM 18 -#define Y2_GPIO_NUM 5 -#define VSYNC_GPIO_NUM 25 -#define HREF_GPIO_NUM 23 -#define PCLK_GPIO_NUM 22 +#define PWDN_GPIO_NUM 32 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 0 +#define SIOD_GPIO_NUM 26 +#define SIOC_GPIO_NUM 27 + +#define Y9_GPIO_NUM 35 +#define Y8_GPIO_NUM 34 +#define Y7_GPIO_NUM 39 +#define Y6_GPIO_NUM 36 +#define Y5_GPIO_NUM 21 +#define Y4_GPIO_NUM 19 +#define Y3_GPIO_NUM 18 +#define Y2_GPIO_NUM 5 +#define VSYNC_GPIO_NUM 25 +#define HREF_GPIO_NUM 23 +#define PCLK_GPIO_NUM 22 // 4 for flash led or 33 for normal led -#define LED_GPIO_NUM 4 +#define LED_GPIO_NUM 4 #elif defined(CAMERA_MODEL_TTGO_T_JOURNAL) -#define PWDN_GPIO_NUM 0 -#define RESET_GPIO_NUM 15 -#define XCLK_GPIO_NUM 27 -#define SIOD_GPIO_NUM 25 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 19 -#define Y8_GPIO_NUM 36 -#define Y7_GPIO_NUM 18 -#define Y6_GPIO_NUM 39 -#define Y5_GPIO_NUM 5 -#define Y4_GPIO_NUM 34 -#define Y3_GPIO_NUM 35 -#define Y2_GPIO_NUM 17 -#define VSYNC_GPIO_NUM 22 -#define HREF_GPIO_NUM 26 -#define PCLK_GPIO_NUM 21 +#define PWDN_GPIO_NUM 0 +#define RESET_GPIO_NUM 15 +#define XCLK_GPIO_NUM 27 +#define SIOD_GPIO_NUM 25 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 19 +#define Y8_GPIO_NUM 36 +#define Y7_GPIO_NUM 18 +#define Y6_GPIO_NUM 39 +#define Y5_GPIO_NUM 5 +#define Y4_GPIO_NUM 34 +#define Y3_GPIO_NUM 35 +#define Y2_GPIO_NUM 17 +#define VSYNC_GPIO_NUM 22 +#define HREF_GPIO_NUM 26 +#define PCLK_GPIO_NUM 21 #elif defined(CAMERA_MODEL_XIAO_ESP32S3) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 10 -#define SIOD_GPIO_NUM 40 -#define SIOC_GPIO_NUM 39 - -#define Y9_GPIO_NUM 48 -#define Y8_GPIO_NUM 11 -#define Y7_GPIO_NUM 12 -#define Y6_GPIO_NUM 14 -#define Y5_GPIO_NUM 16 -#define Y4_GPIO_NUM 18 -#define Y3_GPIO_NUM 17 -#define Y2_GPIO_NUM 15 -#define VSYNC_GPIO_NUM 38 -#define HREF_GPIO_NUM 47 -#define PCLK_GPIO_NUM 13 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 10 +#define SIOD_GPIO_NUM 40 +#define SIOC_GPIO_NUM 39 + +#define Y9_GPIO_NUM 48 +#define Y8_GPIO_NUM 11 +#define Y7_GPIO_NUM 12 +#define Y6_GPIO_NUM 14 +#define Y5_GPIO_NUM 16 +#define Y4_GPIO_NUM 18 +#define Y3_GPIO_NUM 17 +#define Y2_GPIO_NUM 15 +#define VSYNC_GPIO_NUM 38 +#define HREF_GPIO_NUM 47 +#define PCLK_GPIO_NUM 13 #elif defined(CAMERA_MODEL_ESP32_CAM_BOARD) // The 18 pin header on the board has Y5 and Y3 swapped -#define USE_BOARD_HEADER 0 -#define PWDN_GPIO_NUM 32 -#define RESET_GPIO_NUM 33 -#define XCLK_GPIO_NUM 4 -#define SIOD_GPIO_NUM 18 -#define SIOC_GPIO_NUM 23 - -#define Y9_GPIO_NUM 36 -#define Y8_GPIO_NUM 19 -#define Y7_GPIO_NUM 21 -#define Y6_GPIO_NUM 39 +#define USE_BOARD_HEADER 0 +#define PWDN_GPIO_NUM 32 +#define RESET_GPIO_NUM 33 +#define XCLK_GPIO_NUM 4 +#define SIOD_GPIO_NUM 18 +#define SIOC_GPIO_NUM 23 + +#define Y9_GPIO_NUM 36 +#define Y8_GPIO_NUM 19 +#define Y7_GPIO_NUM 21 +#define Y6_GPIO_NUM 39 #if USE_BOARD_HEADER -#define Y5_GPIO_NUM 13 +#define Y5_GPIO_NUM 13 #else -#define Y5_GPIO_NUM 35 +#define Y5_GPIO_NUM 35 #endif -#define Y4_GPIO_NUM 14 +#define Y4_GPIO_NUM 14 #if USE_BOARD_HEADER -#define Y3_GPIO_NUM 35 +#define Y3_GPIO_NUM 35 #else -#define Y3_GPIO_NUM 13 +#define Y3_GPIO_NUM 13 #endif -#define Y2_GPIO_NUM 34 -#define VSYNC_GPIO_NUM 5 -#define HREF_GPIO_NUM 27 -#define PCLK_GPIO_NUM 25 +#define Y2_GPIO_NUM 34 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 27 +#define PCLK_GPIO_NUM 25 #elif defined(CAMERA_MODEL_ESP32S3_CAM_LCD) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 40 -#define SIOD_GPIO_NUM 17 -#define SIOC_GPIO_NUM 18 - -#define Y9_GPIO_NUM 39 -#define Y8_GPIO_NUM 41 -#define Y7_GPIO_NUM 42 -#define Y6_GPIO_NUM 12 -#define Y5_GPIO_NUM 3 -#define Y4_GPIO_NUM 14 -#define Y3_GPIO_NUM 47 -#define Y2_GPIO_NUM 13 -#define VSYNC_GPIO_NUM 21 -#define HREF_GPIO_NUM 38 -#define PCLK_GPIO_NUM 11 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 40 +#define SIOD_GPIO_NUM 17 +#define SIOC_GPIO_NUM 18 + +#define Y9_GPIO_NUM 39 +#define Y8_GPIO_NUM 41 +#define Y7_GPIO_NUM 42 +#define Y6_GPIO_NUM 12 +#define Y5_GPIO_NUM 3 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 47 +#define Y2_GPIO_NUM 13 +#define VSYNC_GPIO_NUM 21 +#define HREF_GPIO_NUM 38 +#define PCLK_GPIO_NUM 11 #elif defined(CAMERA_MODEL_ESP32S2_CAM_BOARD) // The 18 pin header on the board has Y5 and Y3 swapped #define USE_BOARD_HEADER 0 -#define PWDN_GPIO_NUM 1 -#define RESET_GPIO_NUM 2 -#define XCLK_GPIO_NUM 42 -#define SIOD_GPIO_NUM 41 -#define SIOC_GPIO_NUM 18 - -#define Y9_GPIO_NUM 16 -#define Y8_GPIO_NUM 39 -#define Y7_GPIO_NUM 40 -#define Y6_GPIO_NUM 15 +#define PWDN_GPIO_NUM 1 +#define RESET_GPIO_NUM 2 +#define XCLK_GPIO_NUM 42 +#define SIOD_GPIO_NUM 41 +#define SIOC_GPIO_NUM 18 + +#define Y9_GPIO_NUM 16 +#define Y8_GPIO_NUM 39 +#define Y7_GPIO_NUM 40 +#define Y6_GPIO_NUM 15 #if USE_BOARD_HEADER -#define Y5_GPIO_NUM 12 +#define Y5_GPIO_NUM 12 #else -#define Y5_GPIO_NUM 13 +#define Y5_GPIO_NUM 13 #endif -#define Y4_GPIO_NUM 5 +#define Y4_GPIO_NUM 5 #if USE_BOARD_HEADER -#define Y3_GPIO_NUM 13 +#define Y3_GPIO_NUM 13 #else -#define Y3_GPIO_NUM 12 +#define Y3_GPIO_NUM 12 #endif -#define Y2_GPIO_NUM 14 -#define VSYNC_GPIO_NUM 38 -#define HREF_GPIO_NUM 4 -#define PCLK_GPIO_NUM 3 +#define Y2_GPIO_NUM 14 +#define VSYNC_GPIO_NUM 38 +#define HREF_GPIO_NUM 4 +#define PCLK_GPIO_NUM 3 #elif defined(CAMERA_MODEL_ESP32S3_EYE) #define PWDN_GPIO_NUM -1 @@ -294,23 +294,23 @@ #define PCLK_GPIO_NUM 13 #elif defined(CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3) || defined(CAMERA_MODEL_DFRobot_Romeo_ESP32S3) -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 45 -#define SIOD_GPIO_NUM 1 -#define SIOC_GPIO_NUM 2 - -#define Y9_GPIO_NUM 48 -#define Y8_GPIO_NUM 46 -#define Y7_GPIO_NUM 8 -#define Y6_GPIO_NUM 7 -#define Y5_GPIO_NUM 4 -#define Y4_GPIO_NUM 41 -#define Y3_GPIO_NUM 40 -#define Y2_GPIO_NUM 39 -#define VSYNC_GPIO_NUM 6 -#define HREF_GPIO_NUM 42 -#define PCLK_GPIO_NUM 5 +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 45 +#define SIOD_GPIO_NUM 1 +#define SIOC_GPIO_NUM 2 + +#define Y9_GPIO_NUM 48 +#define Y8_GPIO_NUM 46 +#define Y7_GPIO_NUM 8 +#define Y6_GPIO_NUM 7 +#define Y5_GPIO_NUM 4 +#define Y4_GPIO_NUM 41 +#define Y3_GPIO_NUM 40 +#define Y2_GPIO_NUM 39 +#define VSYNC_GPIO_NUM 6 +#define HREF_GPIO_NUM 42 +#define PCLK_GPIO_NUM 5 #else #error "Camera model not selected" diff --git a/libraries/ESP32/examples/ChipID/GetChipID/GetChipID.ino b/libraries/ESP32/examples/ChipID/GetChipID/GetChipID.ino index d6288c89fad..89a195b972f 100644 --- a/libraries/ESP32/examples/ChipID/GetChipID/GetChipID.ino +++ b/libraries/ESP32/examples/ChipID/GetChipID/GetChipID.ino @@ -1,30 +1,30 @@ /* The true ESP32 chip ID is essentially its MAC address. -This sketch provides an alternate chip ID that matches -the output of the ESP.getChipId() function on ESP8266 -(i.e. a 32-bit integer matching the last 3 bytes of -the MAC address. This is less unique than the -MAC address chip ID, but is helpful when you need -an identifier that can be no more than a 32-bit integer +This sketch provides an alternate chip ID that matches +the output of the ESP.getChipId() function on ESP8266 +(i.e. a 32-bit integer matching the last 3 bytes of +the MAC address. This is less unique than the +MAC address chip ID, but is helpful when you need +an identifier that can be no more than a 32-bit integer (like for switch...case). created 2020-06-07 by cweinhofer with help from Cicicok */ - + uint32_t chipId = 0; void setup() { - Serial.begin(115200); + Serial.begin(115200); } void loop() { - for(int i=0; i<17; i=i+8) { - chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i; - } + for (int i = 0; i < 17; i = i + 8) { + chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i; + } - Serial.printf("ESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), ESP.getChipRevision()); - Serial.printf("This chip has %d cores\n", ESP.getChipCores()); - Serial.print("Chip ID: "); Serial.println(chipId); - - delay(3000); + Serial.printf("ESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), ESP.getChipRevision()); + Serial.printf("This chip has %d cores\n", ESP.getChipCores()); + Serial.print("Chip ID: "); + Serial.println(chipId); + delay(3000); } diff --git a/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino b/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino index 8a13b77196d..3ac9c727d36 100644 --- a/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino +++ b/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino @@ -21,7 +21,7 @@ Author: Pranav Cherukupalli */ -#define BUTTON_PIN_BITMASK 0x200000000 // 2^33 in hex +#define BUTTON_PIN_BITMASK 0x200000000 // 2^33 in hex RTC_DATA_ATTR int bootCount = 0; @@ -29,25 +29,24 @@ RTC_DATA_ATTR int bootCount = 0; Method to print the reason by which ESP32 has been awaken from sleep */ -void print_wakeup_reason(){ +void print_wakeup_reason() { esp_sleep_wakeup_cause_t wakeup_reason; wakeup_reason = esp_sleep_get_wakeup_cause(); - switch(wakeup_reason) - { - case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break; - case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break; - case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break; - case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break; - case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break; - default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break; + switch (wakeup_reason) { + case ESP_SLEEP_WAKEUP_EXT0: Serial.println("Wakeup caused by external signal using RTC_IO"); break; + case ESP_SLEEP_WAKEUP_EXT1: Serial.println("Wakeup caused by external signal using RTC_CNTL"); break; + case ESP_SLEEP_WAKEUP_TIMER: Serial.println("Wakeup caused by timer"); break; + case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println("Wakeup caused by touchpad"); break; + case ESP_SLEEP_WAKEUP_ULP: Serial.println("Wakeup caused by ULP program"); break; + default: Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); break; } } -void setup(){ +void setup() { Serial.begin(115200); - delay(1000); //Take some time to open up the Serial Monitor + delay(1000); //Take some time to open up the Serial Monitor //Increment boot number and print it every reboot ++bootCount; @@ -61,12 +60,12 @@ void setup(){ We set our ESP32 to wake up for an external trigger. There are two types for ESP32, ext0 and ext1 . ext0 uses RTC_IO to wakeup thus requires RTC peripherals - to be on while ext1 uses RTC Controller so doesnt need + to be on while ext1 uses RTC Controller so does not need peripherals to be powered on. Note that using internal pullups/pulldowns also requires RTC peripherals to be turned on. */ - esp_sleep_enable_ext0_wakeup(GPIO_NUM_33,1); //1 = High, 0 = Low + esp_sleep_enable_ext0_wakeup(GPIO_NUM_33, 1); //1 = High, 0 = Low //If you were to use ext1, you would use it like //esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK,ESP_EXT1_WAKEUP_ANY_HIGH); @@ -77,6 +76,6 @@ void setup(){ Serial.println("This will never be printed"); } -void loop(){ +void loop() { //This is not going to be called } diff --git a/libraries/ESP32/examples/DeepSleep/SmoothBlink_ULP_Code/SmoothBlink_ULP_Code.ino b/libraries/ESP32/examples/DeepSleep/SmoothBlink_ULP_Code/SmoothBlink_ULP_Code.ino index 28f9ffbccf8..654456a392d 100644 --- a/libraries/ESP32/examples/DeepSleep/SmoothBlink_ULP_Code/SmoothBlink_ULP_Code.ino +++ b/libraries/ESP32/examples/DeepSleep/SmoothBlink_ULP_Code/SmoothBlink_ULP_Code.ino @@ -12,25 +12,25 @@ // RTC Memory used for ULP internal variable and Sketch interfacing #define RTC_dutyMeter 0 -#define RTC_dir 4 +#define RTC_dir 4 #define RTC_fadeDelay 12 -// *fadeCycleDelay is used to pass values to ULP and change its behaviour +// *fadeCycleDelay is used to pass values to ULP and change its behavior uint32_t *fadeCycleDelay = &RTC_SLOW_MEM[RTC_fadeDelay]; #define ULP_START_OFFSET 32 // For ESP32 Arduino, it is usually at offeset 512, defined in sdkconfig -RTC_DATA_ATTR uint32_t ULP_Started = 0; // 0 or 1 +RTC_DATA_ATTR uint32_t ULP_Started = 0; // 0 or 1 //Time-to-Sleep -#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */ -#define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in microseconds); multiplied by above conversion to achieve seconds*/ +#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */ +#define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in microseconds); multiplied by above conversion to achieve seconds*/ void ulp_setup() { if (ULP_Started) { return; } - *fadeCycleDelay = 5; // 5..200 works fine for a full Fade In + Out cycle + *fadeCycleDelay = 5; // 5..200 works fine for a full Fade In + Out cycle ULP_Started = 1; // GPIO2 initialization (set to output and initial value is 0) @@ -53,7 +53,7 @@ void ulp_setup() { DEC_DUTY, INC_DUTY, }; - + // Define ULP program const ulp_insn_t ulp_prog[] = { // Initial Value setup @@ -62,7 +62,7 @@ void ulp_setup() { I_MOVI(R1, 1), // R1 = 1 I_ST(R1, R0, RTC_dir), // RTC_SLOW_MEM[RTC_dir] = 1 - M_LABEL(INIFINITE_LOOP), // while(1) { + M_LABEL(INIFINITE_LOOP), // while(1) { // run certain PWM Duty for about (RTC_fadeDelay x 100) microseconds I_MOVI(R3, 0), // R3 = 0 @@ -70,32 +70,32 @@ void ulp_setup() { M_LABEL(RUN_PWM), // do { // repeat RTC_fadeDelay times: // execute about 10KHz PWM on GPIO2 using as duty cycle = RTC_SLOW_MEM[RTC_dutyMeter] - I_MOVI(R0, 0), // R0 = 0 - I_LD(R0, R0, RTC_dutyMeter), // R0 = RTC_SLOW_MEM[RTC_dutyMeter] - M_BL(NEXT_PWM_CYCLE, 1), // if (R0 > 0) turn on LED - I_WR_REG(RTC_GPIO_OUT_W1TS_REG, MeterPWMBit, MeterPWMBit, 1), // W1TS set bit to clear GPIO - GPIO2 on - M_LABEL(PWM_ON), // while (R0 > 0) // repeat RTC_dutyMeter times: - M_BL(NEXT_PWM_CYCLE, 1), // { + I_MOVI(R0, 0), // R0 = 0 + I_LD(R0, R0, RTC_dutyMeter), // R0 = RTC_SLOW_MEM[RTC_dutyMeter] + M_BL(NEXT_PWM_CYCLE, 1), // if (R0 > 0) turn on LED + I_WR_REG(RTC_GPIO_OUT_W1TS_REG, MeterPWMBit, MeterPWMBit, 1), // W1TS set bit to clear GPIO - GPIO2 on + M_LABEL(PWM_ON), // while (R0 > 0) // repeat RTC_dutyMeter times: + M_BL(NEXT_PWM_CYCLE, 1), // { //I_DELAY(8), // // 8 is about 1 microsecond based on 8MHz - I_SUBI(R0, R0, 1), // R0 = R0 - 1 - M_BX(PWM_ON), // } - M_LABEL(NEXT_PWM_CYCLE), // // toggle GPIO_2 - I_MOVI(R0, 0), // R0 = 0 - I_LD(R0, R0, RTC_dutyMeter), // R0 = RTC_SLOW_MEM[RTC_dutyMeter] - I_MOVI(R1, 100), // R1 = 100 - I_SUBR(R0, R1, R0), // R0 = 100 - dutyMeter - M_BL(END_PWM_CYCLE, 1), // if (R0 > 0) turn off LED - I_WR_REG(RTC_GPIO_OUT_W1TC_REG, MeterPWMBit, MeterPWMBit, 1), // W1TC set bit to clear GPIO - GPIO2 off - M_LABEL(PWM_OFF), // while (R0 > 0) // repeat (100 - RTC_dutyMeter) times: - M_BL(END_PWM_CYCLE, 1), // { + I_SUBI(R0, R0, 1), // R0 = R0 - 1 + M_BX(PWM_ON), // } + M_LABEL(NEXT_PWM_CYCLE), // // toggle GPIO_2 + I_MOVI(R0, 0), // R0 = 0 + I_LD(R0, R0, RTC_dutyMeter), // R0 = RTC_SLOW_MEM[RTC_dutyMeter] + I_MOVI(R1, 100), // R1 = 100 + I_SUBR(R0, R1, R0), // R0 = 100 - dutyMeter + M_BL(END_PWM_CYCLE, 1), // if (R0 > 0) turn off LED + I_WR_REG(RTC_GPIO_OUT_W1TC_REG, MeterPWMBit, MeterPWMBit, 1), // W1TC set bit to clear GPIO - GPIO2 off + M_LABEL(PWM_OFF), // while (R0 > 0) // repeat (100 - RTC_dutyMeter) times: + M_BL(END_PWM_CYCLE, 1), // { //I_DELAY(8), // // 8 is about 1us: ULP fetch+execution time - I_SUBI(R0, R0, 1), // R0 = R0 - 1 - M_BX(PWM_OFF), // } - M_LABEL(END_PWM_CYCLE), // + I_SUBI(R0, R0, 1), // R0 = R0 - 1 + M_BX(PWM_OFF), // } + M_LABEL(END_PWM_CYCLE), // - I_SUBI(R3, R3, 1), // R3 = R3 - 1 // RTC_fadeDelay - I_MOVR(R0, R3), // R0 = R3 // only R0 can be used to compare and branch - M_BGE(RUN_PWM, 1), // } while (R3 > 0) // ESP32 repeatinf RTC_fadeDelay times + I_SUBI(R3, R3, 1), // R3 = R3 - 1 // RTC_fadeDelay + I_MOVR(R0, R3), // R0 = R3 // only R0 can be used to compare and branch + M_BGE(RUN_PWM, 1), // } while (R3 > 0) // ESP32 repeatinf RTC_fadeDelay times // increase/decrease DutyMeter to apply Fade In/Out loop I_MOVI(R1, 0), // R1 = 0 @@ -103,21 +103,21 @@ void ulp_setup() { I_MOVI(R0, 0), // R0 = 0 I_LD(R0, R0, RTC_dir), // R0 = RTC_SLOW_MEM[RTC_dir] - M_BGE(POSITIVE_DIR, 1), // if(dir == 0) { // decrease duty by 2 + M_BGE(POSITIVE_DIR, 1), // if(dir == 0) { // decrease duty by 2 // Dir is 0, means decrease Duty by 2 I_MOVR(R0, R1), // R0 = Duty - M_BGE(DEC_DUTY, 1), // if (duty == 0) { // change direction and increase duty + M_BGE(DEC_DUTY, 1), // if (duty == 0) { // change direction and increase duty I_MOVI(R3, 0), // R3 = 0 I_MOVI(R2, 1), // R2 = 1 I_ST(R2, R3, RTC_dir), // RTC_SLOW_MEM[RTC_dir] = 1 // increasing direction - M_BX(INC_DUTY), // goto "increase Duty" - M_LABEL(DEC_DUTY), // } "decrease Duty": + M_BX(INC_DUTY), // goto "increase Duty" + M_LABEL(DEC_DUTY), // } "decrease Duty": I_SUBI(R0, R0, 2), // Duty -= 2 I_MOVI(R2, 0), // R2 = 0 I_ST(R0, R2, RTC_dutyMeter), // RTC_SLOW_MEM[RTC_dutyMeter] += 2 M_BX(INIFINITE_LOOP), // } - M_LABEL(POSITIVE_DIR), // else { // dir == 1 // increase duty by 2 + M_LABEL(POSITIVE_DIR), // else { // dir == 1 // increase duty by 2 // Dir is 1, means increase Duty by 2 I_MOVR(R0, R1), // R0 = Duty M_BL(INC_DUTY, 100), // if (duty == 100) { // change direction and decrease duty @@ -143,7 +143,7 @@ void setup() { Serial.begin(115200); while (!Serial) {} // wait for Serial to start - ulp_setup(); // it really only runs on the first ESP32 boot + ulp_setup(); // it really only runs on the first ESP32 boot Serial.printf("\nStarted smooth blink with delay %ld\n", *fadeCycleDelay); // *fadeCycleDelay resides in RTC_SLOW_MEM and persists along deep sleep waking up @@ -151,10 +151,10 @@ void setup() { if (*fadeCycleDelay < 195) { *fadeCycleDelay += 10; } else { - *fadeCycleDelay = 5; // 5..200 works fine for a full Fade In + Out cycle + *fadeCycleDelay = 5; // 5..200 works fine for a full Fade In + Out cycle } Serial.println("Entering in Deep Sleep"); - esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR /*/ 4*/); // time set with variable above + esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR /*/ 4*/); // time set with variable above esp_deep_sleep_start(); // From this point on, no code is executed in DEEP SLEEP mode } @@ -163,4 +163,3 @@ void setup() { void loop() { // It never reaches this code because it enters in Deep Sleep mode at the end of setup() } - diff --git a/libraries/ESP32/examples/DeepSleep/TimerWakeUp/TimerWakeUp.ino b/libraries/ESP32/examples/DeepSleep/TimerWakeUp/TimerWakeUp.ino index ec43cf72ea7..47af6b2efc5 100644 --- a/libraries/ESP32/examples/DeepSleep/TimerWakeUp/TimerWakeUp.ino +++ b/libraries/ESP32/examples/DeepSleep/TimerWakeUp/TimerWakeUp.ino @@ -19,8 +19,8 @@ Author: Pranav Cherukupalli */ -#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */ -#define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in seconds) */ +#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */ +#define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in seconds) */ RTC_DATA_ATTR int bootCount = 0; @@ -28,25 +28,24 @@ RTC_DATA_ATTR int bootCount = 0; Method to print the reason by which ESP32 has been awaken from sleep */ -void print_wakeup_reason(){ +void print_wakeup_reason() { esp_sleep_wakeup_cause_t wakeup_reason; wakeup_reason = esp_sleep_get_wakeup_cause(); - switch(wakeup_reason) - { - case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break; - case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break; - case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break; - case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break; - case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break; - default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break; + switch (wakeup_reason) { + case ESP_SLEEP_WAKEUP_EXT0: Serial.println("Wakeup caused by external signal using RTC_IO"); break; + case ESP_SLEEP_WAKEUP_EXT1: Serial.println("Wakeup caused by external signal using RTC_CNTL"); break; + case ESP_SLEEP_WAKEUP_TIMER: Serial.println("Wakeup caused by timer"); break; + case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println("Wakeup caused by touchpad"); break; + case ESP_SLEEP_WAKEUP_ULP: Serial.println("Wakeup caused by ULP program"); break; + default: Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); break; } } -void setup(){ +void setup() { Serial.begin(115200); - delay(1000); //Take some time to open up the Serial Monitor + delay(1000); //Take some time to open up the Serial Monitor //Increment boot number and print it every reboot ++bootCount; @@ -60,8 +59,7 @@ void setup(){ We set our ESP32 to wake up every 5 seconds */ esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); - Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) + - " Seconds"); + Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) + " Seconds"); /* Next we decide what all peripherals to shut down/keep on @@ -84,11 +82,11 @@ void setup(){ reset occurs. */ Serial.println("Going to sleep now"); - Serial.flush(); + Serial.flush(); esp_deep_sleep_start(); Serial.println("This will never be printed"); } -void loop(){ +void loop() { //This is not going to be called } diff --git a/libraries/ESP32/examples/DeepSleep/TouchWakeUp/TouchWakeUp.ino b/libraries/ESP32/examples/DeepSleep/TouchWakeUp/TouchWakeUp.ino index 94f2dc735a2..6b7419d5fe0 100644 --- a/libraries/ESP32/examples/DeepSleep/TouchWakeUp/TouchWakeUp.ino +++ b/libraries/ESP32/examples/DeepSleep/TouchWakeUp/TouchWakeUp.ino @@ -15,9 +15,9 @@ Pranav Cherukupalli */ #if CONFIG_IDF_TARGET_ESP32 - #define THRESHOLD 40 /* Greater the value, more the sensitivity */ -#else //ESP32-S2 and ESP32-S3 + default for other chips (to be adjusted) */ - #define THRESHOLD 5000 /* Lower the value, more the sensitivity */ +#define THRESHOLD 40 /* Greater the value, more the sensitivity */ +#else //ESP32-S2 and ESP32-S3 + default for other chips (to be adjusted) */ +#define THRESHOLD 5000 /* Lower the value, more the sensitivity */ #endif RTC_DATA_ATTR int bootCount = 0; @@ -26,19 +26,18 @@ touch_pad_t touchPin; Method to print the reason by which ESP32 has been awaken from sleep */ -void print_wakeup_reason(){ +void print_wakeup_reason() { esp_sleep_wakeup_cause_t wakeup_reason; wakeup_reason = esp_sleep_get_wakeup_cause(); - switch(wakeup_reason) - { - case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break; - case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break; - case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break; - case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break; - case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break; - default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break; + switch (wakeup_reason) { + case ESP_SLEEP_WAKEUP_EXT0: Serial.println("Wakeup caused by external signal using RTC_IO"); break; + case ESP_SLEEP_WAKEUP_EXT1: Serial.println("Wakeup caused by external signal using RTC_CNTL"); break; + case ESP_SLEEP_WAKEUP_TIMER: Serial.println("Wakeup caused by timer"); break; + case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println("Wakeup caused by touchpad"); break; + case ESP_SLEEP_WAKEUP_ULP: Serial.println("Wakeup caused by ULP program"); break; + default: Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); break; } } @@ -46,39 +45,35 @@ void print_wakeup_reason(){ Method to print the touchpad by which ESP32 has been awaken from sleep */ -void print_wakeup_touchpad(){ +void print_wakeup_touchpad() { touchPin = esp_sleep_get_touchpad_wakeup_status(); - #if CONFIG_IDF_TARGET_ESP32 - switch(touchPin) - { - case 0 : Serial.println("Touch detected on GPIO 4"); break; - case 1 : Serial.println("Touch detected on GPIO 0"); break; - case 2 : Serial.println("Touch detected on GPIO 2"); break; - case 3 : Serial.println("Touch detected on GPIO 15"); break; - case 4 : Serial.println("Touch detected on GPIO 13"); break; - case 5 : Serial.println("Touch detected on GPIO 12"); break; - case 6 : Serial.println("Touch detected on GPIO 14"); break; - case 7 : Serial.println("Touch detected on GPIO 27"); break; - case 8 : Serial.println("Touch detected on GPIO 33"); break; - case 9 : Serial.println("Touch detected on GPIO 32"); break; - default : Serial.println("Wakeup not by touchpad"); break; - } - #else - if(touchPin < TOUCH_PAD_MAX) - { - Serial.printf("Touch detected on GPIO %d\n", touchPin); - } - else - { - Serial.println("Wakeup not by touchpad"); - } - #endif +#if CONFIG_IDF_TARGET_ESP32 + switch (touchPin) { + case 0: Serial.println("Touch detected on GPIO 4"); break; + case 1: Serial.println("Touch detected on GPIO 0"); break; + case 2: Serial.println("Touch detected on GPIO 2"); break; + case 3: Serial.println("Touch detected on GPIO 15"); break; + case 4: Serial.println("Touch detected on GPIO 13"); break; + case 5: Serial.println("Touch detected on GPIO 12"); break; + case 6: Serial.println("Touch detected on GPIO 14"); break; + case 7: Serial.println("Touch detected on GPIO 27"); break; + case 8: Serial.println("Touch detected on GPIO 33"); break; + case 9: Serial.println("Touch detected on GPIO 32"); break; + default: Serial.println("Wakeup not by touchpad"); break; + } +#else + if (touchPin < TOUCH_PAD_MAX) { + Serial.printf("Touch detected on GPIO %d\n", touchPin); + } else { + Serial.println("Wakeup not by touchpad"); + } +#endif } -void setup(){ +void setup() { Serial.begin(115200); - delay(1000); //Take some time to open up the Serial Monitor + delay(1000); //Take some time to open up the Serial Monitor //Increment boot number and print it every reboot ++bootCount; @@ -88,16 +83,16 @@ void setup(){ print_wakeup_reason(); print_wakeup_touchpad(); - #if CONFIG_IDF_TARGET_ESP32 - //Setup sleep wakeup on Touch Pad 3 + 7 (GPIO15 + GPIO 27) - touchSleepWakeUpEnable(T3,THRESHOLD); - touchSleepWakeUpEnable(T7,THRESHOLD); - - #else //ESP32-S2 + ESP32-S3 - //Setup sleep wakeup on Touch Pad 3 (GPIO3) - touchSleepWakeUpEnable(T3,THRESHOLD); +#if CONFIG_IDF_TARGET_ESP32 + //Setup sleep wakeup on Touch Pad 3 + 7 (GPIO15 + GPIO 27) + touchSleepWakeUpEnable(T3, THRESHOLD); + touchSleepWakeUpEnable(T7, THRESHOLD); + +#else //ESP32-S2 + ESP32-S3 + //Setup sleep wakeup on Touch Pad 3 (GPIO3) + touchSleepWakeUpEnable(T3, THRESHOLD); - #endif +#endif //Go to sleep now Serial.println("Going to sleep now"); @@ -105,6 +100,6 @@ void setup(){ Serial.println("This will never be printed"); } -void loop(){ +void loop() { //This will never be reached -} \ No newline at end of file +} diff --git a/libraries/ESP32/examples/FreeRTOS/BasicMultiThreading/BasicMultiThreading.ino b/libraries/ESP32/examples/FreeRTOS/BasicMultiThreading/BasicMultiThreading.ino index 2cfe185a20c..9e26ca69416 100644 --- a/libraries/ESP32/examples/FreeRTOS/BasicMultiThreading/BasicMultiThreading.ino +++ b/libraries/ESP32/examples/FreeRTOS/BasicMultiThreading/BasicMultiThreading.ino @@ -15,49 +15,54 @@ #define ANALOG_INPUT_PIN A0 #ifndef LED_BUILTIN - #define LED_BUILTIN 13 // Specify the on which is your LED +#define LED_BUILTIN 13 // Specify the on which is your LED #endif // Define two tasks for Blink & AnalogRead. -void TaskBlink( void *pvParameters ); -void TaskAnalogRead( void *pvParameters ); -TaskHandle_t analog_read_task_handle; // You can (don't have to) use this to be able to manipulate a task from somewhere else. +void TaskBlink(void *pvParameters); +void TaskAnalogRead(void *pvParameters); +TaskHandle_t analog_read_task_handle; // You can (don't have to) use this to be able to manipulate a task from somewhere else. // The setup function runs once when you press reset or power on the board. void setup() { // Initialize serial communication at 115200 bits per second: Serial.begin(115200); // Set up two tasks to run independently. - uint32_t blink_delay = 1000; // Delay between changing state on LED pin + uint32_t blink_delay = 1000; // Delay between changing state on LED pin xTaskCreate( - TaskBlink - , "Task Blink" // A name just for humans - , 2048 // The stack size can be checked by calling `uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);` - , (void*) &blink_delay // Task parameter which can modify the task behavior. This must be passed as pointer to void. - , 2 // Priority - , NULL // Task handle is not used here - simply pass NULL - ); + TaskBlink, "Task Blink" // A name just for humans + , + 2048 // The stack size can be checked by calling `uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);` + , + (void *)&blink_delay // Task parameter which can modify the task behavior. This must be passed as pointer to void. + , + 2 // Priority + , + NULL // Task handle is not used here - simply pass NULL + ); // This variant of task creation can also specify on which core it will be run (only relevant for multi-core ESPs) xTaskCreatePinnedToCore( - TaskAnalogRead - , "Analog Read" - , 2048 // Stack size - , NULL // When no parameter is used, simply pass NULL - , 1 // Priority - , &analog_read_task_handle // With task handle we will be able to manipulate with this task. - , ARDUINO_RUNNING_CORE // Core on which the task will run - ); + TaskAnalogRead, "Analog Read", 2048 // Stack size + , + NULL // When no parameter is used, simply pass NULL + , + 1 // Priority + , + &analog_read_task_handle // With task handle we will be able to manipulate with this task. + , + ARDUINO_RUNNING_CORE // Core on which the task will run + ); Serial.printf("Basic Multi Threading Arduino Example\n"); // Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started. } -void loop(){ - if(analog_read_task_handle != NULL){ // Make sure that the task actually exists +void loop() { + if (analog_read_task_handle != NULL) { // Make sure that the task actually exists delay(10000); - vTaskDelete(analog_read_task_handle); // Delete task - analog_read_task_handle = NULL; // prevent calling vTaskDelete on non-existing task + vTaskDelete(analog_read_task_handle); // Delete task + analog_read_task_handle = NULL; // prevent calling vTaskDelete on non-existing task } } @@ -65,13 +70,13 @@ void loop(){ /*---------------------- Tasks ---------------------*/ /*--------------------------------------------------*/ -void TaskBlink(void *pvParameters){ // This is a task. - uint32_t blink_delay = *((uint32_t*)pvParameters); +void TaskBlink(void *pvParameters) { // This is a task. + uint32_t blink_delay = *((uint32_t *)pvParameters); -/* + /* Blink Turns on an LED on for one second, then off for one second, repeatedly. - + If you want to know what pin the on-board LED is connected to on your ESP32 model, check the Technical Specs of your board. */ @@ -79,26 +84,26 @@ void TaskBlink(void *pvParameters){ // This is a task. // initialize digital LED_BUILTIN on pin 13 as an output. pinMode(LED_BUILTIN, OUTPUT); - for (;;){ // A Task shall never return or exit. - digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) + for (;;) { // A Task shall never return or exit. + digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) // arduino-esp32 has FreeRTOS configured to have a tick-rate of 1000Hz and portTICK_PERIOD_MS // refers to how many milliseconds the period between each ticks is, ie. 1ms. delay(blink_delay); - digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW + digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW delay(blink_delay); } } -void TaskAnalogRead(void *pvParameters){ // This is a task. - (void) pvParameters; +void TaskAnalogRead(void *pvParameters) { // This is a task. + (void)pvParameters; // Check if the given analog pin is usable - if not - delete this task - if(digitalPinToAnalogChannel(ANALOG_INPUT_PIN) == -1){ + if (digitalPinToAnalogChannel(ANALOG_INPUT_PIN) == -1) { Serial.printf("TaskAnalogRead cannot work because the given pin %d cannot be used for ADC - the task will delete itself.\n", ANALOG_INPUT_PIN); - analog_read_task_handle = NULL; // Prevent calling vTaskDelete on non-existing task - vTaskDelete(NULL); // Delete this task + analog_read_task_handle = NULL; // Prevent calling vTaskDelete on non-existing task + vTaskDelete(NULL); // Delete this task } - -/* + + /* AnalogReadSerial Reads an analog input on pin A3, prints the result to the serial monitor. Graphical representation is available using serial plotter (Tools > Serial Plotter menu) @@ -107,11 +112,11 @@ void TaskAnalogRead(void *pvParameters){ // This is a task. This example code is in the public domain. */ - for (;;){ + for (;;) { // read the input on analog pin: int sensorValue = analogRead(ANALOG_INPUT_PIN); // print out the value you read: Serial.println(sensorValue); - delay(100); // 100ms delay + delay(100); // 100ms delay } } diff --git a/libraries/ESP32/examples/FreeRTOS/Mutex/Mutex.ino b/libraries/ESP32/examples/FreeRTOS/Mutex/Mutex.ino index 157c5742e69..ab55194da71 100644 --- a/libraries/ESP32/examples/FreeRTOS/Mutex/Mutex.ino +++ b/libraries/ESP32/examples/FreeRTOS/Mutex/Mutex.ino @@ -11,87 +11,93 @@ int shared_variable = 0; SemaphoreHandle_t shared_var_mutex = NULL; // Define a task function -void Task( void *pvParameters ); +void Task(void *pvParameters); // The setup function runs once when you press reset or power on the board. void setup() { // Initialize serial communication at 115200 bits per second: Serial.begin(115200); - while(!Serial) delay(100); + while (!Serial) delay(100); Serial.printf(" Task 0 | Task 1\n"); #ifdef USE_MUTEX - shared_var_mutex = xSemaphoreCreateMutex(); // Create the mutex + shared_var_mutex = xSemaphoreCreateMutex(); // Create the mutex #endif // Set up two tasks to run the same function independently. static int task_number0 = 0; xTaskCreate( - Task - , "Task 0" // A name just for humans - , 2048 // The stack size - , (void*)&task_number0 // Pass reference to a variable describing the task number + Task, "Task 0" // A name just for humans + , + 2048 // The stack size + , + (void *)&task_number0 // Pass reference to a variable describing the task number //, 5 // High priority - , 1 // priority - , NULL // Task handle is not used here - simply pass NULL - ); + , + 1 // priority + , + NULL // Task handle is not used here - simply pass NULL + ); static int task_number1 = 1; xTaskCreate( - Task - , "Task 1" - , 2048 // Stack size - , (void*)&task_number1 // Pass reference to a variable describing the task number - , 1 // Low priority - , NULL // Task handle is not used here - simply pass NULL - ); + Task, "Task 1", 2048 // Stack size + , + (void *)&task_number1 // Pass reference to a variable describing the task number + , + 1 // Low priority + , + NULL // Task handle is not used here - simply pass NULL + ); // Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started. } -void loop(){ +void loop() { } /*--------------------------------------------------*/ /*---------------------- Tasks ---------------------*/ /*--------------------------------------------------*/ -void Task(void *pvParameters){ // This is a task. - int task_num = *((int*)pvParameters); +void Task(void *pvParameters) { // This is a task. + int task_num = *((int *)pvParameters); Serial.printf("%s\n", task_num ? " Starting |" : " | Starting"); - for (;;){ // A Task shall never return or exit. + for (;;) { // A Task shall never return or exit. #ifdef USE_MUTEX - if(shared_var_mutex != NULL){ // Sanity check if the mutex exists - // Try to take the mutex and wait indefintly if needed - if(xSemaphoreTake(shared_var_mutex, portMAX_DELAY) == pdTRUE){ - // Mutex successfully taken + if (shared_var_mutex != NULL) { // Sanity check if the mutex exists + // Try to take the mutex and wait indefinitely if needed + if (xSemaphoreTake(shared_var_mutex, portMAX_DELAY) == pdTRUE) { + // Mutex successfully taken #endif - int new_value = random(1000); + int new_value = random(1000); - char str0[32]; sprintf(str0, " %d <- %d |", shared_variable, new_value); - char str1[32]; sprintf(str1, " | %d <- %d", shared_variable, new_value); - Serial.printf("%s\n", task_num ? str0 : str1); + char str0[32]; + sprintf(str0, " %d <- %d |", shared_variable, new_value); + char str1[32]; + sprintf(str1, " | %d <- %d", shared_variable, new_value); + Serial.printf("%s\n", task_num ? str0 : str1); - shared_variable = new_value; - delay(random(100)); // wait random time of max 100 ms - simulating some computation + shared_variable = new_value; + delay(random(100)); // wait random time of max 100 ms - simulating some computation - sprintf(str0, " R: %d |", shared_variable); - sprintf(str1, " | R: %d", shared_variable); - Serial.printf("%s\n", task_num ? str0 : str1); - //Serial.printf("Task %d after write: reading %d\n", task_num, shared_variable); + sprintf(str0, " R: %d |", shared_variable); + sprintf(str1, " | R: %d", shared_variable); + Serial.printf("%s\n", task_num ? str0 : str1); + //Serial.printf("Task %d after write: reading %d\n", task_num, shared_variable); - if(shared_variable != new_value){ - Serial.printf("%s\n", task_num ? " Mismatch! |" : " | Mismatch!"); - //Serial.printf("Task %d: detected race condition - the value changed!\n", task_num); - } + if (shared_variable != new_value) { + Serial.printf("%s\n", task_num ? " Mismatch! |" : " | Mismatch!"); + //Serial.printf("Task %d: detected race condition - the value changed!\n", task_num); + } #ifdef USE_MUTEX - xSemaphoreGive(shared_var_mutex); // After accessing the shared resource give the mutex and allow other processes to access it - }else{ - // We could not obtain the semaphore and can therefore not access the shared resource safely. - } // mutex take - } // sanity check + xSemaphoreGive(shared_var_mutex); // After accessing the shared resource give the mutex and allow other processes to access it + } else { + // We could not obtain the semaphore and can therefore not access the shared resource safely. + } // mutex take + } // sanity check #endif - delay(10); // Allow other task to be scheduled - } // Infinite loop -} \ No newline at end of file + delay(10); // Allow other task to be scheduled + } // Infinite loop +} diff --git a/libraries/ESP32/examples/FreeRTOS/Queue/Queue.ino b/libraries/ESP32/examples/FreeRTOS/Queue/Queue.ino index a26ee3310d6..3e3ab0f4218 100644 --- a/libraries/ESP32/examples/FreeRTOS/Queue/Queue.ino +++ b/libraries/ESP32/examples/FreeRTOS/Queue/Queue.ino @@ -15,7 +15,7 @@ void TaskReadFromSerial(void *pvParameters); // Define Queue handle QueueHandle_t QueueHandle; const int QueueElementSize = 10; -typedef struct{ +typedef struct { char line[MAX_LINE_LENGTH]; uint8_t line_length; } message_t; @@ -24,97 +24,101 @@ typedef struct{ void setup() { // Initialize serial communication at 115200 bits per second: Serial.begin(115200); - while(!Serial){delay(10);} + while (!Serial) { delay(10); } // Create the queue which will have number of elements, each of size `message_t` and pass the address to . QueueHandle = xQueueCreate(QueueElementSize, sizeof(message_t)); // Check if the queue was successfully created - if(QueueHandle == NULL){ + if (QueueHandle == NULL) { Serial.println("Queue could not be created. Halt."); - while(1) delay(1000); // Halt at this point as is not possible to continue + while (1) delay(1000); // Halt at this point as is not possible to continue } // Set up two tasks to run independently. xTaskCreate( - TaskWriteToSerial - , "Task Write To Serial" // A name just for humans - , 2048 // The stack size can be checked by calling `uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);` - , NULL // No parameter is used - , 2 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest. - , NULL // Task handle is not used here - ); + TaskWriteToSerial, "Task Write To Serial" // A name just for humans + , + 2048 // The stack size can be checked by calling `uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);` + , + NULL // No parameter is used + , + 2 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest. + , + NULL // Task handle is not used here + ); xTaskCreate( - TaskReadFromSerial - , "Task Read From Serial" - , 2048 // Stack size - , NULL // No parameter is used - , 1 // Priority - , NULL // Task handle is not used here - ); + TaskReadFromSerial, "Task Read From Serial", 2048 // Stack size + , + NULL // No parameter is used + , + 1 // Priority + , + NULL // Task handle is not used here + ); // Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started. - Serial.printf("\nAnything you write will return as echo.\nMaximum line length is %d characters (+ terminating '0').\nAnything longer will be sent as a separate line.\n\n", MAX_LINE_LENGTH-1); + Serial.printf("\nAnything you write will return as echo.\nMaximum line length is %d characters (+ terminating '0').\nAnything longer will be sent as a separate line.\n\n", MAX_LINE_LENGTH - 1); } -void loop(){ +void loop() { // Loop is free to do any other work - delay(1000); // While not being used yield the CPU to other tasks + delay(1000); // While not being used yield the CPU to other tasks } /*--------------------------------------------------*/ /*---------------------- Tasks ---------------------*/ /*--------------------------------------------------*/ -void TaskWriteToSerial(void *pvParameters){ // This is a task. +void TaskWriteToSerial(void *pvParameters) { // This is a task. message_t message; - for (;;){ // A Task shall never return or exit. + for (;;) { // A Task shall never return or exit. // One approach would be to poll the function (uxQueueMessagesWaiting(QueueHandle) and call delay if nothing is waiting. // The other approach is to use infinite time to wait defined by constant `portMAX_DELAY`: - if(QueueHandle != NULL){ // Sanity check just to make sure the queue actually exists + if (QueueHandle != NULL) { // Sanity check just to make sure the queue actually exists int ret = xQueueReceive(QueueHandle, &message, portMAX_DELAY); - if(ret == pdPASS){ + if (ret == pdPASS) { // The message was successfully received - send it back to Serial port and "Echo: " Serial.printf("Echo line of size %d: \"%s\"\n", message.line_length, message.line); // The item is queued by copy, not by reference, so lets free the buffer after use. - }else if(ret == pdFALSE){ + } else if (ret == pdFALSE) { Serial.println("The `TaskWriteToSerial` was unable to receive data from the Queue"); } - } // Sanity check - } // Infinite loop + } // Sanity check + } // Infinite loop } -void TaskReadFromSerial(void *pvParameters){ // This is a task. +void TaskReadFromSerial(void *pvParameters) { // This is a task. message_t message; - for (;;){ + for (;;) { // Check if any data are waiting in the Serial buffer message.line_length = Serial.available(); - if(message.line_length > 0){ + if (message.line_length > 0) { // Check if the queue exists AND if there is any free space in the queue - if(QueueHandle != NULL && uxQueueSpacesAvailable(QueueHandle) > 0){ - int max_length = message.line_length < MAX_LINE_LENGTH ? message.line_length : MAX_LINE_LENGTH-1; - for(int i = 0; i < max_length; ++i){ + if (QueueHandle != NULL && uxQueueSpacesAvailable(QueueHandle) > 0) { + int max_length = message.line_length < MAX_LINE_LENGTH ? message.line_length : MAX_LINE_LENGTH - 1; + for (int i = 0; i < max_length; ++i) { message.line[i] = Serial.read(); } message.line_length = max_length; - message.line[message.line_length] = 0; // Add the terminating nul char + message.line[message.line_length] = 0; // Add the terminating nul char // The line needs to be passed as pointer to void. // The last parameter states how many milliseconds should wait (keep trying to send) if is not possible to send right away. // When the wait parameter is 0 it will not wait and if the send is not possible the function will return errQUEUE_FULL - int ret = xQueueSend(QueueHandle, (void*) &message, 0); - if(ret == pdTRUE){ + int ret = xQueueSend(QueueHandle, (void *)&message, 0); + if (ret == pdTRUE) { // The message was successfully sent. - }else if(ret == errQUEUE_FULL){ + } else if (ret == errQUEUE_FULL) { // Since we are checking uxQueueSpacesAvailable this should not occur, however if more than one task should // write into the same queue it can fill-up between the test and actual send attempt Serial.println("The `TaskReadFromSerial` was unable to send data into the Queue"); - } // Queue send check - } // Queue sanity check - }else{ - delay(100); // Allow other tasks to run when there is nothing to read - } // Serial buffer check - } // Infinite loop + } // Queue send check + } // Queue sanity check + } else { + delay(100); // Allow other tasks to run when there is nothing to read + } // Serial buffer check + } // Infinite loop } diff --git a/libraries/ESP32/examples/FreeRTOS/Semaphore/Semaphore.ino b/libraries/ESP32/examples/FreeRTOS/Semaphore/Semaphore.ino index ae3b3fd1bf7..a6a5d58ae91 100644 --- a/libraries/ESP32/examples/FreeRTOS/Semaphore/Semaphore.ino +++ b/libraries/ESP32/examples/FreeRTOS/Semaphore/Semaphore.ino @@ -11,46 +11,46 @@ SemaphoreHandle_t package_delivered_semaphore; void delivery_truck_task(void *pvParameters) { - int truck_number = (int) pvParameters; - while(1) { - // Wait for a package to be delivered - // ... - // Notify the warehouse that a package has been delivered - xSemaphoreGive(package_delivered_semaphore); - Serial.printf("Package delivered by truck: %d\n", truck_number); - //wait for some time - vTaskDelay(1000 / portTICK_PERIOD_MS); - } + int truck_number = (int)pvParameters; + while (1) { + // Wait for a package to be delivered + // ... + // Notify the warehouse that a package has been delivered + xSemaphoreGive(package_delivered_semaphore); + Serial.printf("Package delivered by truck: %d\n", truck_number); + //wait for some time + vTaskDelay(1000 / portTICK_PERIOD_MS); + } } void warehouse_worker_task(void *pvParameters) { - int worker_number = (int) pvParameters; - while(1) { - // Wait for a package to be delivered - xSemaphoreTake(package_delivered_semaphore, portMAX_DELAY); - Serial.printf("Package received by worker: %d\n", worker_number); - // Receive the package - // ... - } + int worker_number = (int)pvParameters; + while (1) { + // Wait for a package to be delivered + xSemaphoreTake(package_delivered_semaphore, portMAX_DELAY); + Serial.printf("Package received by worker: %d\n", worker_number); + // Receive the package + // ... + } } void setup() { - Serial.begin(115200); - while(!Serial){ delay(100); } - // Create the semaphore - package_delivered_semaphore = xSemaphoreCreateCounting(10, 0); - - // Create multiple delivery truck tasks - for (int i = 0; i < 5; i++) { - xTaskCreate(delivery_truck_task, "Delivery Truck", 2048, (void *)i, tskIDLE_PRIORITY, NULL); - } - - // Create multiple warehouse worker tasks - for (int i = 0; i < 3; i++) { - xTaskCreate(warehouse_worker_task, "Warehouse Worker", 2048, (void *)i, tskIDLE_PRIORITY, NULL); - } + Serial.begin(115200); + while (!Serial) { delay(100); } + // Create the semaphore + package_delivered_semaphore = xSemaphoreCreateCounting(10, 0); + + // Create multiple delivery truck tasks + for (int i = 0; i < 5; i++) { + xTaskCreate(delivery_truck_task, "Delivery Truck", 2048, (void *)i, tskIDLE_PRIORITY, NULL); + } + + // Create multiple warehouse worker tasks + for (int i = 0; i < 3; i++) { + xTaskCreate(warehouse_worker_task, "Warehouse Worker", 2048, (void *)i, tskIDLE_PRIORITY, NULL); + } } void loop() { - // Empty loop -} \ No newline at end of file + // Empty loop +} diff --git a/libraries/ESP32/examples/GPIO/BlinkRGB/BlinkRGB.ino b/libraries/ESP32/examples/GPIO/BlinkRGB/BlinkRGB.ino index 3bc0e6a3116..fa4e7596099 100644 --- a/libraries/ESP32/examples/GPIO/BlinkRGB/BlinkRGB.ino +++ b/libraries/ESP32/examples/GPIO/BlinkRGB/BlinkRGB.ino @@ -4,8 +4,8 @@ Demonstrates usage of onboard RGB LED on some ESP dev boards. Calling digitalWrite(RGB_BUILTIN, HIGH) will use hidden RGB driver. - - RGBLedWrite demonstrates controll of each channel: + + RGBLedWrite demonstrates control of each channel: void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val) WARNING: After using digitalWrite to drive RGB LED it will be impossible to drive the same pin @@ -22,18 +22,18 @@ void setup() { // the loop function runs over and over again forever void loop() { #ifdef RGB_BUILTIN - digitalWrite(RGB_BUILTIN, HIGH); // Turn the RGB LED white + digitalWrite(RGB_BUILTIN, HIGH); // Turn the RGB LED white delay(1000); - digitalWrite(RGB_BUILTIN, LOW); // Turn the RGB LED off + digitalWrite(RGB_BUILTIN, LOW); // Turn the RGB LED off delay(1000); - neopixelWrite(RGB_BUILTIN,RGB_BRIGHTNESS,0,0); // Red + neopixelWrite(RGB_BUILTIN, RGB_BRIGHTNESS, 0, 0); // Red delay(1000); - neopixelWrite(RGB_BUILTIN,0,RGB_BRIGHTNESS,0); // Green + neopixelWrite(RGB_BUILTIN, 0, RGB_BRIGHTNESS, 0); // Green delay(1000); - neopixelWrite(RGB_BUILTIN,0,0,RGB_BRIGHTNESS); // Blue + neopixelWrite(RGB_BUILTIN, 0, 0, RGB_BRIGHTNESS); // Blue delay(1000); - neopixelWrite(RGB_BUILTIN,0,0,0); // Off / black + neopixelWrite(RGB_BUILTIN, 0, 0, 0); // Off / black delay(1000); #endif } diff --git a/libraries/ESP32/examples/GPIO/FunctionalInterrupt/FunctionalInterrupt.ino b/libraries/ESP32/examples/GPIO/FunctionalInterrupt/FunctionalInterrupt.ino index 1a82532e96b..2d6c428a683 100644 --- a/libraries/ESP32/examples/GPIO/FunctionalInterrupt/FunctionalInterrupt.ino +++ b/libraries/ESP32/examples/GPIO/FunctionalInterrupt/FunctionalInterrupt.ino @@ -19,49 +19,50 @@ #define BUTTON1 16 #define BUTTON2 17 -class Button{ +class Button { public: - Button(uint8_t reqPin) : PIN(reqPin){ + Button(uint8_t reqPin) + : PIN(reqPin) { pinMode(PIN, INPUT_PULLUP); }; - void begin(){ - attachInterrupt(PIN, std::bind(&Button::isr,this), FALLING); + void begin() { + attachInterrupt(PIN, std::bind(&Button::isr, this), FALLING); Serial.printf("Started button interrupt on pin %d\n", PIN); } - ~Button(){ + ~Button() { detachInterrupt(PIN); } - void ARDUINO_ISR_ATTR isr() { - numberKeyPresses = numberKeyPresses + 1; - pressed = true; - } + void ARDUINO_ISR_ATTR isr() { + numberKeyPresses = numberKeyPresses + 1; + pressed = true; + } - void checkPressed() { - if (pressed) { - Serial.printf("Button on pin %u has been pressed %lu times\n", PIN, numberKeyPresses); - pressed = false; - } - } + void checkPressed() { + if (pressed) { + Serial.printf("Button on pin %u has been pressed %lu times\n", PIN, numberKeyPresses); + pressed = false; + } + } private: - const uint8_t PIN; - volatile uint32_t numberKeyPresses; - volatile bool pressed; + const uint8_t PIN; + volatile uint32_t numberKeyPresses; + volatile bool pressed; }; Button button1(BUTTON1); Button button2(BUTTON2); void setup() { - Serial.begin(115200); - while(!Serial) delay(10); - Serial.println("Starting Functional Interrupt example."); - button1.begin(); - button2.begin(); - Serial.println("Setup done."); + Serial.begin(115200); + while (!Serial) delay(10); + Serial.println("Starting Functional Interrupt example."); + button1.begin(); + button2.begin(); + Serial.println("Setup done."); } void loop() { diff --git a/libraries/ESP32/examples/GPIO/FunctionalInterruptStruct/FunctionalInterruptStruct.ino b/libraries/ESP32/examples/GPIO/FunctionalInterruptStruct/FunctionalInterruptStruct.ino index 4e1f38dd5ba..6131ab267a0 100644 --- a/libraries/ESP32/examples/GPIO/FunctionalInterruptStruct/FunctionalInterruptStruct.ino +++ b/libraries/ESP32/examples/GPIO/FunctionalInterruptStruct/FunctionalInterruptStruct.ino @@ -10,20 +10,20 @@ struct Button { }; void isr(void* param) { - struct Button *button = (struct Button*) param; + struct Button* button = (struct Button*)param; button->numberKeyPresses = button->numberKeyPresses + 1; button->pressed = 1; } void checkPressed(struct Button* button) { - if(button->pressed) { + if (button->pressed) { Serial.printf("Button on pin %u has been pressed %lu times\n", button->PIN, button->numberKeyPresses); button->pressed = 0; } } -struct Button button1 = {BUTTON1, 0, 0}; -struct Button button2 = {BUTTON2, 0, 0}; +struct Button button1 = { BUTTON1, 0, 0 }; +struct Button button2 = { BUTTON2, 0, 0 }; void setup() { Serial.begin(115200); diff --git a/libraries/ESP32/examples/GPIO/GPIOInterrupt/GPIOInterrupt.ino b/libraries/ESP32/examples/GPIO/GPIOInterrupt/GPIOInterrupt.ino index f208024256f..942eae68d33 100644 --- a/libraries/ESP32/examples/GPIO/GPIOInterrupt/GPIOInterrupt.ino +++ b/libraries/ESP32/examples/GPIO/GPIOInterrupt/GPIOInterrupt.ino @@ -1,45 +1,45 @@ #include struct Button { - const uint8_t PIN; - uint32_t numberKeyPresses; - bool pressed; + const uint8_t PIN; + uint32_t numberKeyPresses; + bool pressed; }; -Button button1 = {23, 0, false}; -Button button2 = {18, 0, false}; +Button button1 = { 23, 0, false }; +Button button2 = { 18, 0, false }; void ARDUINO_ISR_ATTR isr(void* arg) { - Button* s = static_cast(arg); - s->numberKeyPresses += 1; - s->pressed = true; + Button* s = static_cast(arg); + s->numberKeyPresses += 1; + s->pressed = true; } void ARDUINO_ISR_ATTR isr() { - button2.numberKeyPresses += 1; - button2.pressed = true; + button2.numberKeyPresses += 1; + button2.pressed = true; } void setup() { - Serial.begin(115200); - pinMode(button1.PIN, INPUT_PULLUP); - attachInterruptArg(button1.PIN, isr, &button1, FALLING); - pinMode(button2.PIN, INPUT_PULLUP); - attachInterrupt(button2.PIN, isr, FALLING); + Serial.begin(115200); + pinMode(button1.PIN, INPUT_PULLUP); + attachInterruptArg(button1.PIN, isr, &button1, FALLING); + pinMode(button2.PIN, INPUT_PULLUP); + attachInterrupt(button2.PIN, isr, FALLING); } void loop() { - if (button1.pressed) { - Serial.printf("Button 1 has been pressed %lu times\n", button1.numberKeyPresses); - button1.pressed = false; - } - if (button2.pressed) { - Serial.printf("Button 2 has been pressed %lu times\n", button2.numberKeyPresses); - button2.pressed = false; - } - static uint32_t lastMillis = 0; - if (millis() - lastMillis > 10000) { - lastMillis = millis(); - detachInterrupt(button1.PIN); - } + if (button1.pressed) { + Serial.printf("Button 1 has been pressed %lu times\n", button1.numberKeyPresses); + button1.pressed = false; + } + if (button2.pressed) { + Serial.printf("Button 2 has been pressed %lu times\n", button2.numberKeyPresses); + button2.pressed = false; + } + static uint32_t lastMillis = 0; + if (millis() - lastMillis > 10000) { + lastMillis = millis(); + detachInterrupt(button1.PIN); + } } diff --git a/libraries/ESP32/examples/HWCDC_Events/.skip.esp32 b/libraries/ESP32/examples/HWCDC_Events/.skip.esp32 index 8b137891791..e69de29bb2d 100644 --- a/libraries/ESP32/examples/HWCDC_Events/.skip.esp32 +++ b/libraries/ESP32/examples/HWCDC_Events/.skip.esp32 @@ -1 +0,0 @@ - diff --git a/libraries/ESP32/examples/HWCDC_Events/.skip.esp32s2 b/libraries/ESP32/examples/HWCDC_Events/.skip.esp32s2 index 8b137891791..e69de29bb2d 100644 --- a/libraries/ESP32/examples/HWCDC_Events/.skip.esp32s2 +++ b/libraries/ESP32/examples/HWCDC_Events/.skip.esp32s2 @@ -1 +0,0 @@ - diff --git a/libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino b/libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino index 3376a7fddc8..c1e4110166b 100644 --- a/libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino +++ b/libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino @@ -1,23 +1,23 @@ /* * This Example demonstrates how to receive Hardware Serial Events * This USB interface is available for the ESP32-S3, ESP32-C3, ESP32-C6 and ESP32-H2 - * + * * It will log all events and USB status (plugged/unplugged) into UART0 * Any data read from UART0 will be sent to the USB CDC * Any data read from USB CDC will be sent to the UART0 - * + * * A suggestion is to use Arduino Serial Monitor for the UART0 port * and some other serial monitor application for the USB CDC port * in order to see the exchanged data and the Hardware Serial Events - * + * */ #ifndef ARDUINO_USB_MODE #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 0 #warning This sketch should be used when USB is in Hardware CDC and JTAG mode -void setup(){} -void loop(){} +void setup() {} +void loop() {} #else #if !ARDUINO_USB_CDC_ON_BOOT @@ -58,7 +58,7 @@ const char* _hwcdc_status[] = { const char* HWCDC_Status() { int i = HWCDCSerial.isPlugged() ? 0 : 2; - if(HWCDCSerial.isConnected()) i += 1; + if (HWCDCSerial.isConnected()) i += 1; return _hwcdc_status[i]; } @@ -73,7 +73,7 @@ void setup() { void loop() { static uint32_t counter = 0; - + Serial0.print(counter); Serial0.print(HWCDC_Status()); diff --git a/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino b/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino index b19efca844b..5a37bbcee2f 100644 --- a/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino +++ b/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino @@ -1,87 +1,88 @@ -/* - * GetMacAddress - * - * This sketch prints out the MAC addresses for different interfaces. - * - * Written by: Daniel Nebert - * - * The first printed MAC address is obtained by calling 'esp_efuse_mac_get_default' - * (https://docs.espressif.com/projects/esp-idf/en/release-v5.1/esp32/api-reference/system/misc_system_api.html#_CPPv425esp_efuse_mac_get_defaultP7uint8_t) - * which returns base MAC address which is factory-programmed by Espressif in EFUSE. - * - * The remaining printed MAC addresses is obtained by calling 'esp_read_mac' - * (https://docs.espressif.com/projects/esp-idf/en/release-v5.1/esp32/api-reference/system/misc_system_api.html#_CPPv412esp_read_macP7uint8_t14esp_mac_type_t) - * and passing in the 'esp_mac_type_t' type. - * (https://docs.espressif.com/projects/esp-idf/en/release-v5.1/esp32/api-reference/system/misc_system_api.html#esp__mac_8h_1a1b19aca597277a2179682869c140477a) - * - -esp_mac_type_t values: - - ESP_MAC_WIFI_STA - MAC for WiFi Station (6 bytes) - ESP_MAC_WIFI_SOFTAP - MAC for WiFi Soft-AP (6 bytes) - ESP_MAC_BT - MAC for Bluetooth (6 bytes) - ESP_MAC_ETH - MAC for Ethernet (6 bytes) - ESP_MAC_IEEE802154 - if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC for IEEE802154 (8 bytes) - ESP_MAC_BASE - Base MAC for that used for other MAC types (6 bytes) - ESP_MAC_EFUSE_FACTORY - MAC_FACTORY eFuse which was burned by Espressif in production (6 bytes) - ESP_MAC_EFUSE_CUSTOM - MAC_CUSTOM eFuse which was can be burned by customer (6 bytes) - ESP_MAC_EFUSE_EXT - if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC_EXT eFuse which is used as an extender for IEEE802154 MAC (2 bytes) - -*/ - -#include "esp_mac.h" // required - exposes esp_mac_type_t values - -void setup() { - - Serial.begin(115200); - while(!Serial) { delay( 100 ); } - - Serial.println("Interface\t\t\t\t\t\tMAC address (6 bytes, 4 universally administered, default)"); - - Serial.print("Wi-Fi Station (using 'esp_efuse_mac_get_default')\t"); - Serial.println(getDefaultMacAddress()); - - Serial.print("WiFi Station (using 'esp_read_mac')\t\t\t"); - Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_STA)); - - Serial.print("WiFi Soft-AP (using 'esp_read_mac')\t\t\t"); - Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_SOFTAP)); - - Serial.print("Bluetooth (using 'esp_read_mac')\t\t\t"); - Serial.println(getInterfaceMacAddress(ESP_MAC_BT)); - - Serial.print("Ethernet (using 'esp_read_mac')\t\t\t\t"); - Serial.println(getInterfaceMacAddress(ESP_MAC_ETH)); -} - -void loop() { /* Nothing in loop */ } - -String getDefaultMacAddress() { - - String mac = ""; - - unsigned char mac_base[6] = {0}; - - if(esp_efuse_mac_get_default(mac_base) == ESP_OK) { - char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator - sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); - mac = buffer; - } - - return mac; -} - -String getInterfaceMacAddress(esp_mac_type_t interface) { - - String mac = ""; - - unsigned char mac_base[6] = {0}; - - if(esp_read_mac(mac_base, interface) == ESP_OK) { - char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator - sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); - mac = buffer; - } - - return mac; -} +/* + * GetMacAddress + * + * This sketch prints out the MAC addresses for different interfaces. + * + * Written by: Daniel Nebert + * + * The first printed MAC address is obtained by calling 'esp_efuse_mac_get_default' + * (https://docs.espressif.com/projects/esp-idf/en/release-v5.1/esp32/api-reference/system/misc_system_api.html#_CPPv425esp_efuse_mac_get_defaultP7uint8_t) + * which returns base MAC address which is factory-programmed by Espressif in EFUSE. + * + * The remaining printed MAC addresses is obtained by calling 'esp_read_mac' + * (https://docs.espressif.com/projects/esp-idf/en/release-v5.1/esp32/api-reference/system/misc_system_api.html#_CPPv412esp_read_macP7uint8_t14esp_mac_type_t) + * and passing in the 'esp_mac_type_t' type. + * (https://docs.espressif.com/projects/esp-idf/en/release-v5.1/esp32/api-reference/system/misc_system_api.html#esp__mac_8h_1a1b19aca597277a2179682869c140477a) + * + +esp_mac_type_t values: + + ESP_MAC_WIFI_STA - MAC for WiFi Station (6 bytes) + ESP_MAC_WIFI_SOFTAP - MAC for WiFi Soft-AP (6 bytes) + ESP_MAC_BT - MAC for Bluetooth (6 bytes) + ESP_MAC_ETH - MAC for Ethernet (6 bytes) + ESP_MAC_IEEE802154 - if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC for IEEE802154 (8 bytes) + ESP_MAC_BASE - Base MAC for that used for other MAC types (6 bytes) + ESP_MAC_EFUSE_FACTORY - MAC_FACTORY eFuse which was burned by Espressif in production (6 bytes) + ESP_MAC_EFUSE_CUSTOM - MAC_CUSTOM eFuse which was can be burned by customer (6 bytes) + ESP_MAC_EFUSE_EXT - if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC_EXT eFuse which is used as an extender for IEEE802154 MAC (2 bytes) + +*/ + +#include "esp_mac.h" // required - exposes esp_mac_type_t values + +void setup() { + + Serial.begin(115200); + while (!Serial) { delay(100); } + + Serial.println("Interface\t\t\t\t\t\tMAC address (6 bytes, 4 universally administered, default)"); + + Serial.print("Wi-Fi Station (using 'esp_efuse_mac_get_default')\t"); + Serial.println(getDefaultMacAddress()); + + Serial.print("WiFi Station (using 'esp_read_mac')\t\t\t"); + Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_STA)); + + Serial.print("WiFi Soft-AP (using 'esp_read_mac')\t\t\t"); + Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_SOFTAP)); + + Serial.print("Bluetooth (using 'esp_read_mac')\t\t\t"); + Serial.println(getInterfaceMacAddress(ESP_MAC_BT)); + + Serial.print("Ethernet (using 'esp_read_mac')\t\t\t\t"); + Serial.println(getInterfaceMacAddress(ESP_MAC_ETH)); +} + +void loop() { /* Nothing in loop */ +} + +String getDefaultMacAddress() { + + String mac = ""; + + unsigned char mac_base[6] = { 0 }; + + if (esp_efuse_mac_get_default(mac_base) == ESP_OK) { + char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator + sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); + mac = buffer; + } + + return mac; +} + +String getInterfaceMacAddress(esp_mac_type_t interface) { + + String mac = ""; + + unsigned char mac_base[6] = { 0 }; + + if (esp_read_mac(mac_base, interface) == ESP_OK) { + char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator + sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); + mac = buffer; + } + + return mac; +} diff --git a/libraries/ESP32/examples/RMT/RMTCallback/RMTCallback.ino b/libraries/ESP32/examples/RMT/RMTCallback/RMTCallback.ino index 8a9a0ac27e0..21dd5119f26 100644 --- a/libraries/ESP32/examples/RMT/RMTCallback/RMTCallback.ino +++ b/libraries/ESP32/examples/RMT/RMTCallback/RMTCallback.ino @@ -14,69 +14,68 @@ /** * @brief This example demonstrate how to use a C++ Class to read several GPIO RMT signals - * calling a data processor when data is availble in background, using taks. - * - * The output is the last RMT data read in the GPIO, just to ilustrate how it works. - * + * calling a data processor when data is available in background, using tasks. + * + * The output is the last RMT data read in the GPIO, just to illustrate how it works. + * */ class MyProcessor { - private: - uint32_t buff; // rolling buffer of most recent 32 bits. - int at = 0; - size_t rx_num_symbols = RMT_MEM_NUM_BLOCKS_1 * RMT_SYMBOLS_PER_CHANNEL_BLOCK; - rmt_data_t rx_symbols[RMT_MEM_NUM_BLOCKS_1 * RMT_SYMBOLS_PER_CHANNEL_BLOCK]; - - public: - int8_t gpio = -1; - - MyProcessor(uint8_t pin, uint32_t rmtFreqHz) { - if (!rmtInit(pin, RMT_RX_MODE, RMT_MEM_NUM_BLOCKS_1, rmtFreqHz)) - { - Serial.println("init receiver failed\n"); - return; - } - gpio = pin; - } +private: + uint32_t buff; // rolling buffer of most recent 32 bits. + int at = 0; + size_t rx_num_symbols = RMT_MEM_NUM_BLOCKS_1 * RMT_SYMBOLS_PER_CHANNEL_BLOCK; + rmt_data_t rx_symbols[RMT_MEM_NUM_BLOCKS_1 * RMT_SYMBOLS_PER_CHANNEL_BLOCK]; + +public: + int8_t gpio = -1; - void begin() { - // Creating RMT RX Callback Task - xTaskCreate(readTask, "MyProcessor", 2048, this, 4, NULL); + MyProcessor(uint8_t pin, uint32_t rmtFreqHz) { + if (!rmtInit(pin, RMT_RX_MODE, RMT_MEM_NUM_BLOCKS_1, rmtFreqHz)) { + Serial.println("init receiver failed\n"); + return; } + gpio = pin; + } - static void readTask(void *args) { - MyProcessor *me = (MyProcessor *) args; + void begin() { + // Creating RMT RX Callback Task + xTaskCreate(readTask, "MyProcessor", 2048, this, 4, NULL); + } - while(1) { - // blocks until RMT has read data - rmtRead(me->gpio, me->rx_symbols, &me->rx_num_symbols, RMT_WAIT_FOR_EVER); - // process the data like a callback whenever there is data available - process(me->rx_symbols, me->rx_num_symbols, me); - } - vTaskDelete(NULL); - } + static void readTask(void *args) { + MyProcessor *me = (MyProcessor *)args; - static void process(rmt_data_t *data, size_t len, void *args) { - MyProcessor *me = (MyProcessor *) args; - uint32_t *buff = &me->buff; - - for (int i = 0; len; len--) { - if (data[i].duration0 == 0) - break; - *buff = (*buff << 1) | (data[i].level0 ? 1 : 0); - i++; - - if (data[i].duration1 == 0) - break; - *buff = (*buff << 1) | (data[i].level1 ? 1 : 0); - i++; - }; + while (1) { + // blocks until RMT has read data + rmtRead(me->gpio, me->rx_symbols, &me->rx_num_symbols, RMT_WAIT_FOR_EVER); + // process the data like a callback whenever there is data available + process(me->rx_symbols, me->rx_num_symbols, me); } + vTaskDelete(NULL); + } - uint32_t val() { - return buff; - } + static void process(rmt_data_t *data, size_t len, void *args) { + MyProcessor *me = (MyProcessor *)args; + uint32_t *buff = &me->buff; + + for (int i = 0; len; len--) { + if (data[i].duration0 == 0) + break; + *buff = (*buff << 1) | (data[i].level0 ? 1 : 0); + i++; + + if (data[i].duration1 == 0) + break; + *buff = (*buff << 1) | (data[i].level1 ? 1 : 0); + i++; + }; + } + + uint32_t val() { + return buff; + } }; // Attach 3 processors to GPIO 4, 5 and 10 with different tick/speeds. diff --git a/libraries/ESP32/examples/RMT/RMTLoopback/RMTLoopback.ino b/libraries/ESP32/examples/RMT/RMTLoopback/RMTLoopback.ino index c2d8a18ded1..4cfe4a2348b 100644 --- a/libraries/ESP32/examples/RMT/RMTLoopback/RMTLoopback.ino +++ b/libraries/ESP32/examples/RMT/RMTLoopback/RMTLoopback.ino @@ -16,9 +16,9 @@ * @brief This example demonstrates usage of RMT for testing a circuit loopback * using 2 GPIOs, one for sending RMT data and the other for receiving the data. * Those 2 GPIO must be connected to each other. - * + * * The output is the RMT data comparing what was sent and received - * + * */ #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 @@ -26,7 +26,7 @@ #define RMT_TX_PIN 4 #define RMT_RX_PIN 5 #define RMT_MEM_RX RMT_MEM_NUM_BLOCKS_2 -#else +#else #define RMT_TX_PIN 18 #define RMT_RX_PIN 21 #define RMT_MEM_RX RMT_MEM_NUM_BLOCKS_3 @@ -37,58 +37,59 @@ rmt_data_t data[256]; static EventGroupHandle_t events; -#define RMT_FREQ 10000000 // tick time is 100ns +#define RMT_FREQ 10000000 // tick time is 100ns #define RMT_NUM_EXCHANGED_DATA 30 void setup() { - Serial.begin(115200); - events = xEventGroupCreate(); - - if (!rmtInit(RMT_TX_PIN, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, RMT_FREQ)) { - Serial.println("init sender failed\n"); - } - if (!rmtInit(RMT_RX_PIN, RMT_RX_MODE, RMT_MEM_RX, RMT_FREQ)) { - Serial.println("init receiver failed\n"); - } - - // End of transmission shall be detected when line is idle for 2us = 20*100ns - rmtSetRxMaxThreshold(RMT_RX_PIN, 20); - // Disable Glitch filter - rmtSetRxMinThreshold(RMT_RX_PIN, 0); - - Serial.println("real tick set to: 100ns"); - Serial.printf("\nPlease connect GPIO %d to GPIO %d, now.\n", RMT_TX_PIN, RMT_RX_PIN); + Serial.begin(115200); + events = xEventGroupCreate(); + + if (!rmtInit(RMT_TX_PIN, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, RMT_FREQ)) { + Serial.println("init sender failed\n"); + } + if (!rmtInit(RMT_RX_PIN, RMT_RX_MODE, RMT_MEM_RX, RMT_FREQ)) { + Serial.println("init receiver failed\n"); + } + + // End of transmission shall be detected when line is idle for 2us = 20*100ns + rmtSetRxMaxThreshold(RMT_RX_PIN, 20); + // Disable Glitch filter + rmtSetRxMinThreshold(RMT_RX_PIN, 0); + + Serial.println("real tick set to: 100ns"); + Serial.printf("\nPlease connect GPIO %d to GPIO %d, now.\n", RMT_TX_PIN, RMT_RX_PIN); } void loop() { - // Init data - int i; - for (i=0; i<255; i++) { - data[i].val = 0x80010001 + ((i%13)<<16) + 13-(i%13); - my_data[i].val = 0; - } - data[255].val = 0; - - // Start an async data read - size_t rx_num_symbols = RMT_NUM_EXCHANGED_DATA; - rmtReadAsync(RMT_RX_PIN, my_data, &rx_num_symbols); - - // Write blocking the data to the loopback - rmtWrite(RMT_TX_PIN, data, RMT_NUM_EXCHANGED_DATA, RMT_WAIT_FOR_EVER); - - // Wait until data is read - while (!rmtReceiveCompleted(RMT_RX_PIN)); - - // Once data is available, the number of RMT Symbols is stored in rx_num_symbols - // and the received data is copied to my_data - Serial.printf("Got %d RMT symbols\n", rx_num_symbols); - - // Printout the received data plus the original values - for (i=0; i<60; i++) { - Serial.printf("%08lx=%08lx ", my_data[i].val, data[i].val ); - if (!((i+1)%4)) Serial.println(""); - } - Serial.println("\n"); - - delay(500); + // Init data + int i; + for (i = 0; i < 255; i++) { + data[i].val = 0x80010001 + ((i % 13) << 16) + 13 - (i % 13); + my_data[i].val = 0; + } + data[255].val = 0; + + // Start an async data read + size_t rx_num_symbols = RMT_NUM_EXCHANGED_DATA; + rmtReadAsync(RMT_RX_PIN, my_data, &rx_num_symbols); + + // Write blocking the data to the loopback + rmtWrite(RMT_TX_PIN, data, RMT_NUM_EXCHANGED_DATA, RMT_WAIT_FOR_EVER); + + // Wait until data is read + while (!rmtReceiveCompleted(RMT_RX_PIN)) + ; + + // Once data is available, the number of RMT Symbols is stored in rx_num_symbols + // and the received data is copied to my_data + Serial.printf("Got %d RMT symbols\n", rx_num_symbols); + + // Printout the received data plus the original values + for (i = 0; i < 60; i++) { + Serial.printf("%08lx=%08lx ", my_data[i].val, data[i].val); + if (!((i + 1) % 4)) Serial.println(""); + } + Serial.println("\n"); + + delay(500); } diff --git a/libraries/ESP32/examples/RMT/RMTReadXJT/RMTReadXJT.ino b/libraries/ESP32/examples/RMT/RMTReadXJT/RMTReadXJT.ino index 78e7e0b54cf..416f0b8faeb 100644 --- a/libraries/ESP32/examples/RMT/RMTReadXJT/RMTReadXJT.ino +++ b/libraries/ESP32/examples/RMT/RMTReadXJT/RMTReadXJT.ino @@ -14,9 +14,9 @@ /** * @brief This example demonstrates usage of RMT for receiving XJT D12 data - * + * * The output is the RMT data read and processed - * + * */ // @@ -53,30 +53,30 @@ // ; 0x13 - Tail, 0x7E (tail ID) typedef union { struct { - uint8_t head;//0x7E - uint8_t rxid;//Receiver Number - uint8_t flags;//Range:0x20, Bind:0x01 - uint8_t reserved0;//0x00 + uint8_t head; //0x7E + uint8_t rxid; //Receiver Number + uint8_t flags; //Range:0x20, Bind:0x01 + uint8_t reserved0; //0x00 union { struct { uint8_t ch0_l; - uint8_t ch0_h: 4; - uint8_t ch1_l: 4; + uint8_t ch0_h : 4; + uint8_t ch1_l : 4; uint8_t ch1_h; }; uint8_t bytes[3]; } channels[4]; - uint8_t reserved1;//0x00 + uint8_t reserved1; //0x00 uint8_t crc_h; uint8_t crc_l; - uint8_t tail;//0x7E + uint8_t tail; //0x7E }; uint8_t buffer[20]; } xjt_packet_t; #define XJT_VALID(i) (i->level0 && !i->level1 && i->duration0 >= 8 && i->duration0 <= 11) -static uint32_t *s_channels; +static uint32_t* s_channels; static uint32_t channels[16]; static uint8_t xjt_flags = 0x0; static uint8_t xjt_rxid = 0x0; @@ -114,7 +114,7 @@ static bool xjtReceiveBit(size_t index, bool bit) { //add bit xjt.buffer[xht_byte_index] &= ~(1 << --xjt_bit_index); } - if ((!xjt_bit_index) || (xjt_bit_index == 1 && xht_byte_index == 19) ) { + if ((!xjt_bit_index) || (xjt_bit_index == 1 && xht_byte_index == 19)) { xjt_bit_index = 8; if (!xht_byte_index && xjt.buffer[0] != 0x7E) { //fail! @@ -156,7 +156,7 @@ void parseRmt(rmt_data_t* items, size_t len, uint32_t* channels) { bool valid = true; rmt_data_t* it = NULL; - if (!channels) { + if (!channels) { log_e("Please provide data block for storing channel info"); return; } @@ -179,7 +179,6 @@ void parseRmt(rmt_data_t* items, size_t len, uint32_t* channels) { } } else if (!it->duration1 && !it->level1 && it->duration0 >= 5 && it->duration0 <= 8) { valid = xjtReceiveBit(i, false); - } } } diff --git a/libraries/ESP32/examples/RMT/RMTWriteNeoPixel/RMTWriteNeoPixel.ino b/libraries/ESP32/examples/RMT/RMTWriteNeoPixel/RMTWriteNeoPixel.ino index d8e9e662085..47d4041d1ac 100644 --- a/libraries/ESP32/examples/RMT/RMTWriteNeoPixel/RMTWriteNeoPixel.ino +++ b/libraries/ESP32/examples/RMT/RMTWriteNeoPixel/RMTWriteNeoPixel.ino @@ -14,24 +14,24 @@ /** * @brief This example demonstrates usage of RGB LED driven by RMT - * + * * The output is a visual WS2812 RGB LED color moving in a 8 x 4 LED matrix * Parameters can be changed by the user. In a single LED circuit, it will just blink. */ // The effect seen in (Espressif devkits) ESP32C6, ESP32H2, ESP32C3, ESP32S2 and ESP32S3 is like a Blink of RGB LED #ifdef PIN_NEOPIXEL -#define BUILTIN_RGBLED_PIN PIN_NEOPIXEL +#define BUILTIN_RGBLED_PIN PIN_NEOPIXEL #else -#define BUILTIN_RGBLED_PIN 21 // ESP32 has no builtin RGB LED (PIN_NEOPIXEL) +#define BUILTIN_RGBLED_PIN 21 // ESP32 has no builtin RGB LED (PIN_NEOPIXEL) #endif -#define NR_OF_LEDS 8*4 -#define NR_OF_ALL_BITS 24*NR_OF_LEDS +#define NR_OF_LEDS 8 * 4 +#define NR_OF_ALL_BITS 24 * NR_OF_LEDS // // Note: This example uses Neopixel LED board, 32 LEDs chained one -// after another, each RGB LED has its 24 bit value +// after another, each RGB LED has its 24 bit value // for color configuration (8b for each color) // // Bits encoded as pulses as follows: @@ -57,43 +57,43 @@ rmt_data_t led_data[NR_OF_ALL_BITS]; void setup() { - Serial.begin(115200); - if (!rmtInit(BUILTIN_RGBLED_PIN, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)) { - Serial.println("init sender failed\n"); - } - Serial.println("real tick set to: 100ns"); + Serial.begin(115200); + if (!rmtInit(BUILTIN_RGBLED_PIN, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)) { + Serial.println("init sender failed\n"); + } + Serial.println("real tick set to: 100ns"); } -int color[] = { 0x55, 0x11, 0x77 }; // Green Red Blue values +int color[] = { 0x55, 0x11, 0x77 }; // Green Red Blue values int led_index = 0; void loop() { - // Init data with only one led ON - int led, col, bit; - int i=0; - for (led=0; led=NR_OF_LEDS) { - led_index = 0; - } - // Send the data and wait until it is done - rmtWrite(BUILTIN_RGBLED_PIN, led_data, NR_OF_ALL_BITS, RMT_WAIT_FOR_EVER); - delay(100); + } + // make the led travel in the panel + if ((++led_index) >= NR_OF_LEDS) { + led_index = 0; + } + // Send the data and wait until it is done + rmtWrite(BUILTIN_RGBLED_PIN, led_data, NR_OF_ALL_BITS, RMT_WAIT_FOR_EVER); + delay(100); } diff --git a/libraries/ESP32/examples/RMT/RMT_CPUFreq_Test/RMT_CPUFreq_Test.ino b/libraries/ESP32/examples/RMT/RMT_CPUFreq_Test/RMT_CPUFreq_Test.ino index b55f7ad4d39..832114c5ace 100644 --- a/libraries/ESP32/examples/RMT/RMT_CPUFreq_Test/RMT_CPUFreq_Test.ino +++ b/libraries/ESP32/examples/RMT/RMT_CPUFreq_Test/RMT_CPUFreq_Test.ino @@ -13,14 +13,14 @@ // limitations under the License. /** - * @brief This example demonstrates usage of RGB LED driven by RMT to verify + * @brief This example demonstrates usage of RGB LED driven by RMT to verify * that RMT works on any CPU/APB Frequency. - * + * * It uses an ESP32 Arduino builtin RGB NeoLED function based on RMT: * void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val) - * + * * The output is a visual WS2812 RGB LED color change routine using each time a - * different CPU Frequency, just to ilustrate how it works. Serial output indicates + * different CPU Frequency, just to illustrate how it works. Serial output indicates * information about the CPU Frequency while controlling the RGB LED using RMT. */ @@ -28,29 +28,29 @@ // Default DevKit RGB LED GPIOs: // The effect seen in (Espressif devkits) ESP32C6, ESP32H2, ESP32C3, ESP32S2 and ESP32S3 is like a Blink of RGB LED #ifdef PIN_NEOPIXEL -#define MY_LED_GPIO PIN_NEOPIXEL +#define MY_LED_GPIO PIN_NEOPIXEL #else -#define MY_LED_GPIO 21 // ESP32 has no builtin RGB LED (PIN_NEOPIXEL) +#define MY_LED_GPIO 21 // ESP32 has no builtin RGB LED (PIN_NEOPIXEL) #endif // Set the correct GPIO to any necessary by changing RGB_LED_GPIO value -#define RGB_LED_GPIO MY_LED_GPIO // Any GPIO valid in the board +#define RGB_LED_GPIO MY_LED_GPIO // Any GPIO valid in the board // Change the RGB Brightness to any value from 0 (off) to 255 (max) -#define BRIGHTNESS 20 // Change color brightness (max 255) +#define BRIGHTNESS 20 // Change color brightness (max 255) void setup() { Serial.begin(115200); delay(500); Serial.printf("\nUsing GPIO %d attached to the RGB LED.\nInitial CPU setup:\n", RGB_LED_GPIO); - Serial.printf("CPU Freq = %lu MHz\n", getCpuFrequencyMhz()); + Serial.printf("CPU Freq = %lu MHz\n", getCpuFrequencyMhz()); Serial.printf("XTAL Freq = %lu MHz\n", getXtalFrequencyMhz()); - Serial.printf("APB Freq = %lu Hz\n", getApbFrequency()); + Serial.printf("APB Freq = %lu Hz\n", getApbFrequency()); } void loop() { - const uint8_t cpufreqs[] = {240, 160, 80, 40, 20, 10}; + const uint8_t cpufreqs[] = { 240, 160, 80, 40, 20, 10 }; static uint8_t i = 0; setCpuFrequencyMhz(cpufreqs[i]); @@ -66,22 +66,22 @@ void loop() { Serial.updateBaudRate(115200); Serial.printf("\n--changed CPU Frequency to %lu MHz\n", getCpuFrequencyMhz()); - neopixelWrite(RGB_LED_GPIO, BRIGHTNESS, BRIGHTNESS, BRIGHTNESS); // White + neopixelWrite(RGB_LED_GPIO, BRIGHTNESS, BRIGHTNESS, BRIGHTNESS); // White Serial.println("White"); delay(1000); - neopixelWrite(RGB_LED_GPIO, 0, 0, 0); // Off + neopixelWrite(RGB_LED_GPIO, 0, 0, 0); // Off Serial.println("Off"); delay(1000); - neopixelWrite(RGB_LED_GPIO, BRIGHTNESS, 0, 0); // Red + neopixelWrite(RGB_LED_GPIO, BRIGHTNESS, 0, 0); // Red Serial.println("Red"); delay(1000); - neopixelWrite(RGB_LED_GPIO, 0, BRIGHTNESS, 0); // Green + neopixelWrite(RGB_LED_GPIO, 0, BRIGHTNESS, 0); // Green Serial.println("Green"); delay(1000); - neopixelWrite(RGB_LED_GPIO, 0, 0, BRIGHTNESS); // Blue + neopixelWrite(RGB_LED_GPIO, 0, 0, BRIGHTNESS); // Blue Serial.println("Blue"); delay(1000); - neopixelWrite(RGB_LED_GPIO, 0, 0, 0); // Off + neopixelWrite(RGB_LED_GPIO, 0, 0, 0); // Off Serial.println("Off"); delay(1000); } diff --git a/libraries/ESP32/examples/RMT/RMT_EndOfTransmissionState/RMT_EndOfTransmissionState.ino b/libraries/ESP32/examples/RMT/RMT_EndOfTransmissionState/RMT_EndOfTransmissionState.ino index 90c4e4f7d08..c8ea4c7542e 100644 --- a/libraries/ESP32/examples/RMT/RMT_EndOfTransmissionState/RMT_EndOfTransmissionState.ino +++ b/libraries/ESP32/examples/RMT/RMT_EndOfTransmissionState/RMT_EndOfTransmissionState.ino @@ -1,7 +1,7 @@ #define BLINK_GPIO 2 #define EOT_INITIAL_STATE_TIME_MS 1000 -// BLINK_GPIO shall start at RMT_EOT (HIGH or LOW) as initial state for EOT_INITIAL_STATE_TIME_MS, +// BLINK_GPIO shall start at RMT_EOT (HIGH or LOW) as initial state for EOT_INITIAL_STATE_TIME_MS, // BLINK: 1 second ON, 1 second OFF and then return/stay to RMT_EOT level at the end. #define RMT_EOT HIGH @@ -9,45 +9,125 @@ // This RMT data sends a 0.5Hz pulse with 1s High and 1s Low signal rmt_data_t blink_1s_rmt_data[] = { // 400,000 x 2.5us = 1 second ON - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, // 400,000 x 2.5us = 1 second OFF - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, // Looping mode needs a Zero ending data to mark the EOF - {0, 0, 0, 0} + { 0, 0, 0, 0 } }; void setup() { Serial.begin(115200); Serial.println("Starting Blink testing..."); Serial.flush(); - + // 1 RMT Block has 64 RMT_SYMBOLS (ESP32|ESP32S2) or 48 RMT_SYMBOLS (ESP32C3|ESP32S3) - if (!rmtInit(BLINK_GPIO, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 400000)) { //2.5us tick + if (!rmtInit(BLINK_GPIO, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 400000)) { //2.5us tick Serial.println("===> rmtInit Error!"); } - + // sets the End of Transmission Level to HIGH, after writing to the pin. DEFAULT is LOW. rmtSetEOT(BLINK_GPIO, RMT_EOT); // set initial RMT state by writing a single RMT data - rmt_data_t initStateSetup_rmt_data[] = { {1, RMT_EOT, 0, 0} }; + rmt_data_t initStateSetup_rmt_data[] = { { 1, RMT_EOT, 0, 0 } }; rmtWrite(BLINK_GPIO, initStateSetup_rmt_data, RMT_SYMBOLS_OF(initStateSetup_rmt_data), RMT_WAIT_FOR_EVER); - Serial.printf("\nLED GPIO%d start in the inital level %s\n", BLINK_GPIO, RMT_EOT == LOW ? "LOW" : "HIGH"); - delay(EOT_INITIAL_STATE_TIME_MS); // set initial state of the LED is set by RMT_EOT. - + Serial.printf("\nLED GPIO%d start in the initial level %s\n", BLINK_GPIO, RMT_EOT == LOW ? "LOW" : "HIGH"); + delay(EOT_INITIAL_STATE_TIME_MS); // set initial state of the LED is set by RMT_EOT. + // Send the data and wait until it is done - set EOT level to HIGH Serial.printf("\nLED GPIO%d Blinks 1 second HIGH - 1 second LOW.\n", BLINK_GPIO); if (!rmtWrite(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data) - 2, RMT_WAIT_FOR_EVER)) { @@ -56,4 +136,4 @@ void setup() { Serial.printf("\nLED GPIO%d goes to the EOT level %s\n", BLINK_GPIO, RMT_EOT == LOW ? "LOW" : "HIGH"); } -void loop(){} +void loop() {} diff --git a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino index 3232fb71459..7f99a2af216 100644 --- a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino +++ b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino @@ -16,10 +16,10 @@ * @brief This example demonstrate how to use RMT to just blink a regular LED (GPIO) * It uses all the different RMT Writing APIs to blink the LED by hardware, not being * necessary the regular Blink code in Arduino. - * - * The output is the Blinking LED in the GPIO and a serial output describing what is + * + * The output is the Blinking LED in the GPIO and a serial output describing what is * going on, along the execution. - * + * * The circuit is just a LED and a resistor of 270 ohms connected to the GPIO * GPIO ---> resistor 270 ohms ---> + LED - ---> GND */ @@ -30,55 +30,195 @@ // This RMT data sends a 0.5Hz pulse with 1s High and 1s Low signal rmt_data_t blink_1s_rmt_data[] = { // 400,000 x 2.5us = 1 second ON - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, // 400,000 x 2.5us = 1 second OFF - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, // Looping mode needs a Zero ending data to mark the EOF - {0, 0, 0, 0} + { 0, 0, 0, 0 } }; // RMT is at 400KHz with a 2.5us tick // This RMT data sends a 1Hz pulse with 500ms High and 500ms Low signal rmt_data_t blink_500ms_rmt_data[] = { // 200,000 x 2.5us = 0.5 second ON - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, // 200,000 x 2.5us = 0.5 second OFF - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, // Looping mode needs a Zero ending data to mark the EOF - {0, 0, 0, 0} + { 0, 0, 0, 0 } }; // RMT is at 400KHz with a 2.5us tick // This RMT data sends a 2Hz pulse with 250ms High and 250ms Low signal rmt_data_t blink_250ms_rmt_data[] = { // 100,000 x 2.5us = 0.25 second ON - {25000, 1, 25000, 1,}, - {25000, 1, 25000, 1,}, + { + 25000, + 1, + 25000, + 1, + }, + { + 25000, + 1, + 25000, + 1, + }, // 100,000 x 2.5us = 0.25 second OFF - {25000, 0, 25000, 0,}, - {25000, 0, 25000, 0,}, + { + 25000, + 0, + 25000, + 0, + }, + { + 25000, + 0, + 25000, + 0, + }, // Looping mode needs a Zero ending data to mark the EOF - {0, 0, 0, 0} + { 0, 0, 0, 0 } }; void RMT_Mixed_Write_Blink() { @@ -87,7 +227,7 @@ void RMT_Mixed_Write_Blink() { if (!rmtWriteLooping(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data))) { Serial.println("===> rmtWriteLooping Blink 1s Error!"); } - delay(6000); // blinking happens here, done by hardware! + delay(6000); // blinking happens here, done by hardware! Serial.println("===> rmtWrite() (Blocking Mode) to Blink the LED."); Serial.println("Blinking at 500ms on + 500ms off :: 4 blinks"); @@ -104,7 +244,8 @@ void RMT_Mixed_Write_Blink() { Serial.println("===> rmtWrite Blink 0.25s Error!"); } // wait (blocks) until all the data is sent out - while (!rmtTransmitCompleted(BLINK_GPIO)); + while (!rmtTransmitCompleted(BLINK_GPIO)) + ; } Serial.println("Blinking OFF for 1 seconds"); delay(1000); @@ -166,7 +307,8 @@ void RMT_Write_Aync_Non_Blocking_Blink() { Serial.println("===> rmtWrite Blink 1s Error!"); } // wait (blocks) until all the data is sent out - while (!rmtTransmitCompleted(BLINK_GPIO)); + while (!rmtTransmitCompleted(BLINK_GPIO)) + ; } Serial.println("Blinking at 500ms on + 500ms off :: 5 blinks"); for (uint8_t i = 0; i < 5; i++) { @@ -174,7 +316,8 @@ void RMT_Write_Aync_Non_Blocking_Blink() { Serial.println("===> rmtWrite Blink 0.5s Error!"); } // wait (blocks) until all the data is sent out - while (!rmtTransmitCompleted(BLINK_GPIO)); + while (!rmtTransmitCompleted(BLINK_GPIO)) + ; } Serial.println("Blinking at 250ms on + 250ms off :: 5 blinks"); for (uint8_t i = 0; i < 5; i++) { @@ -182,7 +325,8 @@ void RMT_Write_Aync_Non_Blocking_Blink() { Serial.println("===> rmtWrite Blink 0.25s Error!"); } // wait (blocks) until all the data is sent out - while (!rmtTransmitCompleted(BLINK_GPIO)); + while (!rmtTransmitCompleted(BLINK_GPIO)) + ; } Serial.println("Blinking OFF for 1 seconds"); delay(1000); @@ -194,22 +338,22 @@ void setup() { Serial.flush(); // 1 RMT Block has 64 RMT_SYMBOLS (ESP32|ESP32S2) or 48 RMT_SYMBOLS (ESP32C3|ESP32S3) - if (!rmtInit(BLINK_GPIO, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 400000)) { //2.5us tick + if (!rmtInit(BLINK_GPIO, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 400000)) { //2.5us tick Serial.println("===> rmtInit Error!"); } else { Serial.println("===> rmtInit OK! Tick = 2.5us - OK for testing"); } Serial.println("\n======================================"); - Serial.println( "All set. Starting RMT testing Routine."); - Serial.println( "======================================\n"); + Serial.println("All set. Starting RMT testing Routine."); + Serial.println("======================================\n"); RMT_Mixed_Write_Blink(); Serial.println("End of Mixed Calls testing"); delay(1000); - + Serial.println("\n==============================="); - Serial.println( "Starting a Blinking sequence..."); - Serial.println( "===============================\n"); + Serial.println("Starting a Blinking sequence..."); + Serial.println("===============================\n"); } void loop() { diff --git a/libraries/ESP32/examples/ResetReason/ResetReason/ResetReason.ino b/libraries/ESP32/examples/ResetReason/ResetReason/ResetReason.ino index 476178420c6..0151556afe3 100644 --- a/libraries/ESP32/examples/ResetReason/ResetReason/ResetReason.ino +++ b/libraries/ESP32/examples/ResetReason/ResetReason/ResetReason.ino @@ -12,7 +12,7 @@ * Evandro Luis Copercini - 2017 */ -#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 #include "esp32/rom/rtc.h" #elif CONFIG_IDF_TARGET_ESP32S2 #include "esp32s2/rom/rtc.h" @@ -26,55 +26,51 @@ #include "esp32c6/rom/rtc.h" #elif CONFIG_IDF_TARGET_ESP32H2 #include "esp32h2/rom/rtc.h" -#else +#else #error Target CONFIG_IDF_TARGET is not supported #endif -#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */ +#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */ -void print_reset_reason(int reason) -{ - switch ( reason) - { - case 1 : Serial.println ("POWERON_RESET");break; /**<1, Vbat power on reset*/ - case 3 : Serial.println ("SW_RESET");break; /**<3, Software reset digital core*/ - case 4 : Serial.println ("OWDT_RESET");break; /**<4, Legacy watch dog reset digital core*/ - case 5 : Serial.println ("DEEPSLEEP_RESET");break; /**<5, Deep Sleep reset digital core*/ - case 6 : Serial.println ("SDIO_RESET");break; /**<6, Reset by SLC module, reset digital core*/ - case 7 : Serial.println ("TG0WDT_SYS_RESET");break; /**<7, Timer Group0 Watch dog reset digital core*/ - case 8 : Serial.println ("TG1WDT_SYS_RESET");break; /**<8, Timer Group1 Watch dog reset digital core*/ - case 9 : Serial.println ("RTCWDT_SYS_RESET");break; /**<9, RTC Watch dog Reset digital core*/ - case 10 : Serial.println ("INTRUSION_RESET");break; /**<10, Instrusion tested to reset CPU*/ - case 11 : Serial.println ("TGWDT_CPU_RESET");break; /**<11, Time Group reset CPU*/ - case 12 : Serial.println ("SW_CPU_RESET");break; /**<12, Software reset CPU*/ - case 13 : Serial.println ("RTCWDT_CPU_RESET");break; /**<13, RTC Watch dog Reset CPU*/ - case 14 : Serial.println ("EXT_CPU_RESET");break; /**<14, for APP CPU, reseted by PRO CPU*/ - case 15 : Serial.println ("RTCWDT_BROWN_OUT_RESET");break;/**<15, Reset when the vdd voltage is not stable*/ - case 16 : Serial.println ("RTCWDT_RTC_RESET");break; /**<16, RTC Watch dog reset digital core and rtc module*/ - default : Serial.println ("NO_MEAN"); +void print_reset_reason(int reason) { + switch (reason) { + case 1: Serial.println("POWERON_RESET"); break; /**<1, Vbat power on reset*/ + case 3: Serial.println("SW_RESET"); break; /**<3, Software reset digital core*/ + case 4: Serial.println("OWDT_RESET"); break; /**<4, Legacy watch dog reset digital core*/ + case 5: Serial.println("DEEPSLEEP_RESET"); break; /**<5, Deep Sleep reset digital core*/ + case 6: Serial.println("SDIO_RESET"); break; /**<6, Reset by SLC module, reset digital core*/ + case 7: Serial.println("TG0WDT_SYS_RESET"); break; /**<7, Timer Group0 Watch dog reset digital core*/ + case 8: Serial.println("TG1WDT_SYS_RESET"); break; /**<8, Timer Group1 Watch dog reset digital core*/ + case 9: Serial.println("RTCWDT_SYS_RESET"); break; /**<9, RTC Watch dog Reset digital core*/ + case 10: Serial.println("INTRUSION_RESET"); break; /**<10, Instrusion tested to reset CPU*/ + case 11: Serial.println("TGWDT_CPU_RESET"); break; /**<11, Time Group reset CPU*/ + case 12: Serial.println("SW_CPU_RESET"); break; /**<12, Software reset CPU*/ + case 13: Serial.println("RTCWDT_CPU_RESET"); break; /**<13, RTC Watch dog Reset CPU*/ + case 14: Serial.println("EXT_CPU_RESET"); break; /**<14, for APP CPU, reset by PRO CPU*/ + case 15: Serial.println("RTCWDT_BROWN_OUT_RESET"); break; /**<15, Reset when the vdd voltage is not stable*/ + case 16: Serial.println("RTCWDT_RTC_RESET"); break; /**<16, RTC Watch dog reset digital core and rtc module*/ + default: Serial.println("NO_MEAN"); } } -void verbose_print_reset_reason(int reason) -{ - switch ( reason) - { - case 1 : Serial.println ("Vbat power on reset");break; - case 3 : Serial.println ("Software reset digital core");break; - case 4 : Serial.println ("Legacy watch dog reset digital core");break; - case 5 : Serial.println ("Deep Sleep reset digital core");break; - case 6 : Serial.println ("Reset by SLC module, reset digital core");break; - case 7 : Serial.println ("Timer Group0 Watch dog reset digital core");break; - case 8 : Serial.println ("Timer Group1 Watch dog reset digital core");break; - case 9 : Serial.println ("RTC Watch dog Reset digital core");break; - case 10 : Serial.println ("Instrusion tested to reset CPU");break; - case 11 : Serial.println ("Time Group reset CPU");break; - case 12 : Serial.println ("Software reset CPU");break; - case 13 : Serial.println ("RTC Watch dog Reset CPU");break; - case 14 : Serial.println ("for APP CPU, reseted by PRO CPU");break; - case 15 : Serial.println ("Reset when the vdd voltage is not stable");break; - case 16 : Serial.println ("RTC Watch dog reset digital core and rtc module");break; - default : Serial.println ("NO_MEAN"); +void verbose_print_reset_reason(int reason) { + switch (reason) { + case 1: Serial.println("Vbat power on reset"); break; + case 3: Serial.println("Software reset digital core"); break; + case 4: Serial.println("Legacy watch dog reset digital core"); break; + case 5: Serial.println("Deep Sleep reset digital core"); break; + case 6: Serial.println("Reset by SLC module, reset digital core"); break; + case 7: Serial.println("Timer Group0 Watch dog reset digital core"); break; + case 8: Serial.println("Timer Group1 Watch dog reset digital core"); break; + case 9: Serial.println("RTC Watch dog Reset digital core"); break; + case 10: Serial.println("Instrusion tested to reset CPU"); break; + case 11: Serial.println("Time Group reset CPU"); break; + case 12: Serial.println("Software reset CPU"); break; + case 13: Serial.println("RTC Watch dog Reset CPU"); break; + case 14: Serial.println("for APP CPU, reset by PRO CPU"); break; + case 15: Serial.println("Reset when the vdd voltage is not stable"); break; + case 16: Serial.println("RTC Watch dog reset digital core and rtc module"); break; + default: Serial.println("NO_MEAN"); } } @@ -106,7 +102,6 @@ void setup() { void loop() { // put your main code here, to run repeatedly: - } /* @@ -127,7 +122,7 @@ RTCWDT_RTC_RESET RTC Watch dog reset digital core and rtc module CPU1 reset reason: EXT_CPU_RESET -for APP CPU, reseted by PRO CPU +for APP CPU, reset by PRO CPU Going to sleep ets Jun 8 2016 00:22:57 @@ -145,7 +140,7 @@ DEEPSLEEP_RESET Deep Sleep reset digital core CPU1 reset reason: EXT_CPU_RESET -for APP CPU, reseted by PRO CPU +for APP CPU, reset by PRO CPU Going to sleep ets Jun 8 2016 00:22:57 @@ -163,7 +158,7 @@ DEEPSLEEP_RESET Deep Sleep reset digital core CPU1 reset reason: EXT_CPU_RESET -for APP CPU, reseted by PRO CPU +for APP CPU, reset by PRO CPU Going to sleep */ diff --git a/libraries/ESP32/examples/ResetReason/ResetReason2/ResetReason2.ino b/libraries/ESP32/examples/ResetReason/ResetReason2/ResetReason2.ino index e0aa81ad523..f7b5d552482 100644 --- a/libraries/ESP32/examples/ResetReason/ResetReason2/ResetReason2.ino +++ b/libraries/ESP32/examples/ResetReason/ResetReason2/ResetReason2.ino @@ -21,27 +21,27 @@ //Converts reason type to a C string. //Type is located in /tools/sdk/esp32/include/esp_system/include/esp_system.h -const char * resetReasonName(esp_reset_reason_t r) { - switch(r) { +const char* resetReasonName(esp_reset_reason_t r) { + switch (r) { case ESP_RST_UNKNOWN: return "Unknown"; - case ESP_RST_POWERON: return "PowerOn"; //Power on or RST pin toggled - case ESP_RST_EXT: return "ExtPin"; //External pin - not applicable for ESP32 - case ESP_RST_SW: return "Reboot"; //esp_restart() - case ESP_RST_PANIC: return "Crash"; //Exception/panic - case ESP_RST_INT_WDT: return "WDT_Int"; //Interrupt watchdog (software or hardware) - case ESP_RST_TASK_WDT: return "WDT_Task"; //Task watchdog - case ESP_RST_WDT: return "WDT_Other"; //Other watchdog - case ESP_RST_DEEPSLEEP: return "Sleep"; //Reset after exiting deep sleep mode - case ESP_RST_BROWNOUT: return "BrownOut"; //Brownout reset (software or hardware) - case ESP_RST_SDIO: return "SDIO"; //Reset over SDIO + case ESP_RST_POWERON: return "PowerOn"; //Power on or RST pin toggled + case ESP_RST_EXT: return "ExtPin"; //External pin - not applicable for ESP32 + case ESP_RST_SW: return "Reboot"; //esp_restart() + case ESP_RST_PANIC: return "Crash"; //Exception/panic + case ESP_RST_INT_WDT: return "WDT_Int"; //Interrupt watchdog (software or hardware) + case ESP_RST_TASK_WDT: return "WDT_Task"; //Task watchdog + case ESP_RST_WDT: return "WDT_Other"; //Other watchdog + case ESP_RST_DEEPSLEEP: return "Sleep"; //Reset after exiting deep sleep mode + case ESP_RST_BROWNOUT: return "BrownOut"; //Brownout reset (software or hardware) + case ESP_RST_SDIO: return "SDIO"; //Reset over SDIO default: return ""; } } void PrintResetReason(void) { esp_reset_reason_t r = esp_reset_reason(); - if(r==ESP_RST_POWERON) { - delay(6000); //Wait for serial monitor to connect + if (r == ESP_RST_POWERON) { + delay(6000); //Wait for serial monitor to connect } Serial.printf("\r\nReset reason %i - %s\r\n", r, resetReasonName(r)); } @@ -51,7 +51,7 @@ void setup() { PrintResetReason(); //Start WDT monitor - if(esp_task_wdt_add(NULL) != ESP_OK) { + if (esp_task_wdt_add(NULL) != ESP_OK) { log_e("Failed to add current task to WDT"); } } @@ -60,5 +60,5 @@ void setup() { void loop() { Serial.printf("Alive %lums\r\n", millis()); //esp_task_wdt_reset(); - delay(1000); //1s delay -} \ No newline at end of file + delay(1000); //1s delay +} diff --git a/libraries/ESP32/examples/Serial/BaudRateDetect_Demo/BaudRateDetect_Demo.ino b/libraries/ESP32/examples/Serial/BaudRateDetect_Demo/BaudRateDetect_Demo.ino index 5c63960487e..0bf61815c45 100644 --- a/libraries/ESP32/examples/Serial/BaudRateDetect_Demo/BaudRateDetect_Demo.ino +++ b/libraries/ESP32/examples/Serial/BaudRateDetect_Demo/BaudRateDetect_Demo.ino @@ -5,23 +5,23 @@ Serial.begin(0) will start the baud rate detection. Valid range is 300 to 230400 baud. It will try to detect for 20 seconds, by default, while reading RX. This timeout of 20 seconds can be changed in the begin() function through <> parameter: - + void HardwareSerial::begin(baud, config, rxPin, txPin, invert, <>, rxfifo_full_thrhd) It is necessary that the other end sends some data within <>, otherwise the detection won't work. - IMPORTANT NOTE: baud rate detection seem to only work with ESP32 and ESP32-S2. + IMPORTANT NOTE: baud rate detection seem to only work with ESP32 and ESP32-S2. In other other SoCs, it doesn't work. */ -// Open the Serial Monitor with testing baud start typing and sending caracters +// Open the Serial Monitor with testing baud start typing and sending characters void setup() { - Serial.begin(0); // it will try to detect the baud rate for 20 seconds - + Serial.begin(0); // it will try to detect the baud rate for 20 seconds + Serial.print("\n==>The baud rate is "); - Serial.println(Serial.baudRate()); - + Serial.println(Serial.baudRate()); + //after 20 seconds timeout, when not detected, it will return zero - in this case, we set it back to 115200. if (Serial.baudRate() == 0) { // Trying to set Serial to a safe state at 115200 @@ -31,7 +31,7 @@ void setup() { delay(1000); log_e("Baud rate detection failed."); } - } +} void loop() { } diff --git a/libraries/ESP32/examples/Serial/OnReceiveError_BREAK_Demo/OnReceiveError_BREAK_Demo.ino b/libraries/ESP32/examples/Serial/OnReceiveError_BREAK_Demo/OnReceiveError_BREAK_Demo.ino index 3a712033506..d8f016a9826 100644 --- a/libraries/ESP32/examples/Serial/OnReceiveError_BREAK_Demo/OnReceiveError_BREAK_Demo.ino +++ b/libraries/ESP32/examples/Serial/OnReceiveError_BREAK_Demo/OnReceiveError_BREAK_Demo.ino @@ -5,7 +5,7 @@ void HardwareSerial::onReceiveError(OnReceiveErrorCb function) It is possible to register a UART callback function that will be called - everytime that UART detects an error which is also associated to an interrupt. + every time that UART detects an error which is also associated to an interrupt. There are some possible UART errors: @@ -30,14 +30,14 @@ In summary, HardwareSerial::onReceiveError() works like an UART Error Notification callback. Errors have priority in the order of the callbacks, therefore, as soon as an error is detected, - the registered callback is executed firt, and only after that, the OnReceive() registered + the registered callback is executed first, and only after that, the OnReceive() registered callback function will be executed. This will give opportunity for the Application to take action before reading data, if necessary. In long UART transmissions, some data will be received based on FIFO Full parameter, and whenever an error ocurs, it will raise the UART error interrupt. - This sketch produces BREAK UART error in the begining of a transmission and also at the end of a + This sketch produces BREAK UART error in the beginning of a transmission and also at the end of a transmission. It will be possible to understand the order of the events in the logs. */ @@ -48,19 +48,19 @@ // By physically connecting the pins 4 and 5 and then create a physical UART loopback, // Or by using the internal IO_MUX to connect the TX signal to the RX pin, creating the // same loopback internally. -#define USE_INTERNAL_PIN_LOOPBACK 1 // 1 uses the internal loopback, 0 for wiring pins 4 and 5 externally +#define USE_INTERNAL_PIN_LOOPBACK 1 // 1 uses the internal loopback, 0 for wiring pins 4 and 5 externally -#define DATA_SIZE 26 // 26 bytes is a lower than RX FIFO size (127 bytes) -#define BAUD 9600 // Any baudrate from 300 to 115200 -#define TEST_UART 1 // Serial1 will be used for the loopback testing with different RX FIFO FULL values -#define RXPIN 4 // GPIO 4 => RX for Serial1 -#define TXPIN 5 // GPIO 5 => TX for Serial1 +#define DATA_SIZE 26 // 26 bytes is a lower than RX FIFO size (127 bytes) +#define BAUD 9600 // Any baudrate from 300 to 115200 +#define TEST_UART 1 // Serial1 will be used for the loopback testing with different RX FIFO FULL values +#define RXPIN 4 // GPIO 4 => RX for Serial1 +#define TXPIN 5 // GPIO 5 => TX for Serial1 #define BREAK_BEFORE_MSG 0 #define BREAK_AT_END_MSG 1 -uint8_t fifoFullTestCases[] = {120, 20, 5, 1}; +uint8_t fifoFullTestCases[] = { 120, 20, 5, 1 }; // volatile declaration will avoid any compiler optimization when reading variable values volatile size_t sent_bytes = 0, received_bytes = 0; @@ -86,7 +86,7 @@ void onReceiveFunction() { size_t available = Serial1.available(); received_bytes = received_bytes + available; Serial.printf("onReceive Callback:: There are %d bytes available: {", available); - while (available --) { + while (available--) { Serial.print((char)Serial1.read()); } Serial.println("}"); @@ -98,7 +98,7 @@ void setup() { // UART1 will have its RX<->TX cross connected // GPIO4 <--> GPIO5 using external wire - Serial1.begin(BAUD, SERIAL_8N1, RXPIN, TXPIN); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3 + Serial1.begin(BAUD, SERIAL_8N1, RXPIN, TXPIN); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3 #if USE_INTERNAL_PIN_LOOPBACK uart_internal_loopback(TEST_UART, RXPIN); #endif @@ -107,19 +107,18 @@ void setup() { Serial.printf("\n\n================================\nTest Case #%d BREAK at END\n================================\n", i + 1); // First sending BREAK at the end of the UART data transmission testAndReport(fifoFullTestCases[i], BREAK_AT_END_MSG); - Serial.printf("\n\n================================\nTest Case #%d BREAK at BEGINING\n================================\n", i + 1); - // Now sending BREAK at the begining of the UART data transmission + Serial.printf("\n\n================================\nTest Case #%d BREAK at BEGINNING\n================================\n", i + 1); + // Now sending BREAK at the beginning of the UART data transmission testAndReport(fifoFullTestCases[i], BREAK_BEFORE_MSG); Serial.println("========================\nFinished!"); } - } void loop() { } void testAndReport(uint8_t fifoFull, bool break_at_the_end) { - // Let's send 125 bytes from Serial1 rx<->tx and mesaure time using diferent FIFO Full configurations + // Let's send 125 bytes from Serial1 rx<->tx and mesaure time using different FIFO Full configurations received_bytes = 0; sent_bytes = DATA_SIZE; // 26 characters @@ -128,7 +127,7 @@ void testAndReport(uint8_t fifoFull, bool break_at_the_end) { // initialize all data for (uint8_t i = 0; i < DATA_SIZE; i++) { - dataSent[i] = 'A' + i; // fill it with characters A..Z + dataSent[i] = 'A' + i; // fill it with characters A..Z } Serial.printf("\nTesting onReceive for receiving %d bytes at %d baud, using RX FIFO Full = %d.\n", sent_bytes, BAUD, fifoFull); @@ -136,12 +135,12 @@ void testAndReport(uint8_t fifoFull, bool break_at_the_end) { if (break_at_the_end) { Serial.printf("BREAK event will be sent at the END of the %d bytes\n", sent_bytes); } else { - Serial.printf("BREAK event will be sent at the BEGINING of the %d bytes\n", sent_bytes); + Serial.printf("BREAK event will be sent at the BEGINNING of the %d bytes\n", sent_bytes); } - Serial.flush(); // wait Serial FIFO to be empty and then spend almost no time processing it - Serial1.setRxFIFOFull(fifoFull); // testing diferent result based on FIFO Full setup - Serial1.onReceive(onReceiveFunction); // sets a RX callback function for Serial 1 - Serial1.onReceiveError(onReceiveErrorFunction); // sets a RX callback function for Serial 1 + Serial.flush(); // wait Serial FIFO to be empty and then spend almost no time processing it + Serial1.setRxFIFOFull(fifoFull); // testing different result based on FIFO Full setup + Serial1.onReceive(onReceiveFunction); // sets a RX callback function for Serial 1 + Serial1.onReceiveError(onReceiveErrorFunction); // sets a RX callback function for Serial 1 if (break_at_the_end) { sent_bytes = uart_send_msg_with_break(TEST_UART, dataSent, DATA_SIZE); @@ -158,6 +157,6 @@ void testAndReport(uint8_t fifoFull, bool break_at_the_end) { Serial.printf("\nIt has sent %d bytes from Serial1 TX to Serial1 RX\n", sent_bytes); Serial.printf("onReceive() has read a total of %d bytes\n", received_bytes); - Serial1.onReceiveError(NULL); // resets/disables the RX Error callback function for Serial 1 - Serial1.onReceive(NULL); // resets/disables the RX callback function for Serial 1 + Serial1.onReceiveError(NULL); // resets/disables the RX Error callback function for Serial 1 + Serial1.onReceive(NULL); // resets/disables the RX callback function for Serial 1 } diff --git a/libraries/ESP32/examples/Serial/OnReceive_Demo/OnReceive_Demo.ino b/libraries/ESP32/examples/Serial/OnReceive_Demo/OnReceive_Demo.ino index fa16645a64d..64f0903b8fa 100644 --- a/libraries/ESP32/examples/Serial/OnReceive_Demo/OnReceive_Demo.ino +++ b/libraries/ESP32/examples/Serial/OnReceive_Demo/OnReceive_Demo.ino @@ -5,14 +5,14 @@ void HardwareSerial::onReceive(OnReceiveCb function, bool onlyOnTimeout = false) It is possible to register a UART callback function that will be called - everytime that UART receives data and an associated interrupt is generated. + every time that UART receives data and an associated interrupt is generated. The receiving data interrupt can occur because of two possible events: 1- UART FIFO FULL: it happens when internal UART FIFO reaches a certain number of bytes. Its full capacity is 127 bytes. The FIFO Full threshold for the interrupt can be changed using HardwareSerial::setRxFIFOFull(uint8_t fifoFull). - Default FIFO Full Threshold is set at the UART initialzation using HardwareSerial::begin() + Default FIFO Full Threshold is set at the UART initialization using HardwareSerial::begin() This will depend on the baud rate set with when begin() is executed. For a baudrate of 115200 or lower, it it just 1 byte, mimicking original Arduino UART driver. For a baudrate over 115200 it will be 120 bytes for higher performance. @@ -44,15 +44,15 @@ // By physically connecting the pins 4 and 5 and then create a physical UART loopback, // Or by using the internal IO_MUX to connect the TX signal to the RX pin, creating the // same loopback internally. -#define USE_INTERNAL_PIN_LOOPBACK 1 // 1 uses the internal loopback, 0 for wiring pins 4 and 5 externally +#define USE_INTERNAL_PIN_LOOPBACK 1 // 1 uses the internal loopback, 0 for wiring pins 4 and 5 externally -#define DATA_SIZE 26 // 26 bytes is a lower than RX FIFO size (127 bytes) -#define BAUD 9600 // Any baudrate from 300 to 115200 -#define TEST_UART 1 // Serial1 will be used for the loopback testing with different RX FIFO FULL values -#define RXPIN 4 // GPIO 4 => RX for Serial1 -#define TXPIN 5 // GPIO 5 => TX for Serial1 +#define DATA_SIZE 26 // 26 bytes is a lower than RX FIFO size (127 bytes) +#define BAUD 9600 // Any baudrate from 300 to 115200 +#define TEST_UART 1 // Serial1 will be used for the loopback testing with different RX FIFO FULL values +#define RXPIN 4 // GPIO 4 => RX for Serial1 +#define TXPIN 5 // GPIO 5 => TX for Serial1 -uint8_t fifoFullTestCases[] = {120, 20, 5, 1}; +uint8_t fifoFullTestCases[] = { 120, 20, 5, 1 }; // volatile declaration will avoid any compiler optimization when reading variable values volatile size_t sent_bytes = 0, received_bytes = 0; @@ -62,7 +62,7 @@ void onReceiveFunction(void) { size_t available = Serial1.available(); received_bytes = received_bytes + available; Serial.printf("onReceive Callback:: There are %d bytes available: ", available); - while (available --) { + while (available--) { Serial.print((char)Serial1.read()); } Serial.println(); @@ -74,7 +74,7 @@ void setup() { // UART1 will have its RX<->TX cross connected // GPIO4 <--> GPIO5 using external wire - Serial1.begin(BAUD, SERIAL_8N1, RXPIN, TXPIN); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3 + Serial1.begin(BAUD, SERIAL_8N1, RXPIN, TXPIN); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3 #if USE_INTERNAL_PIN_LOOPBACK uart_internal_loopback(TEST_UART, RXPIN); #endif @@ -82,7 +82,7 @@ void setup() { for (uint8_t i = 0; i < sizeof(fifoFullTestCases); i++) { Serial.printf("\n\n================================\nTest Case #%d\n================================\n", i + 1); - // onReceive callback will be called on FIFO Full and RX timeout - default behaviour + // onReceive callback will be called on FIFO Full and RX timeout - default behavior testAndReport(fifoFullTestCases[i], false); } @@ -97,7 +97,7 @@ void loop() { } void testAndReport(uint8_t fifoFull, bool onlyOnTimeOut) { - // Let's send 125 bytes from Serial1 rx<->tx and mesaure time using diferent FIFO Full configurations + // Let's send 125 bytes from Serial1 rx<->tx and mesaure time using different FIFO Full configurations received_bytes = 0; sent_bytes = DATA_SIZE; // 26 characters @@ -106,7 +106,7 @@ void testAndReport(uint8_t fifoFull, bool onlyOnTimeOut) { // initialize all data for (uint8_t i = 0; i < DATA_SIZE; i++) { - dataSent[i] = 'A' + i; // fill it with characters A..Z + dataSent[i] = 'A' + i; // fill it with characters A..Z } Serial.printf("\nTesting onReceive for receiving %d bytes at %d baud, using RX FIFO Full = %d.\n", sent_bytes, BAUD, fifoFull); @@ -115,11 +115,11 @@ void testAndReport(uint8_t fifoFull, bool onlyOnTimeOut) { } else { Serial.println("onReceive is called on both FIFO Full and RX Timeout events."); } - Serial.flush(); // wait Serial FIFO to be empty and then spend almost no time processing it - Serial1.setRxFIFOFull(fifoFull); // testing diferent result based on FIFO Full setup - Serial1.onReceive(onReceiveFunction, onlyOnTimeOut); // sets a RX callback function for Serial 1 + Serial.flush(); // wait Serial FIFO to be empty and then spend almost no time processing it + Serial1.setRxFIFOFull(fifoFull); // testing different result based on FIFO Full setup + Serial1.onReceive(onReceiveFunction, onlyOnTimeOut); // sets a RX callback function for Serial 1 - sent_bytes = Serial1.write(dataSent, DATA_SIZE); // ESP32 TX FIFO is about 128 bytes, 125 bytes will fit fine + sent_bytes = Serial1.write(dataSent, DATA_SIZE); // ESP32 TX FIFO is about 128 bytes, 125 bytes will fit fine Serial.printf("\nSent String: %s\n", dataSent); while (received_bytes < sent_bytes) { // just wait for receiving all byte in the callback... @@ -129,5 +129,5 @@ void testAndReport(uint8_t fifoFull, bool onlyOnTimeOut) { Serial.printf("onReceive() has read a total of %d bytes\n", received_bytes); Serial.println("========================\nFinished!"); - Serial1.onReceive(NULL); // resets/disables the RX callback function for Serial 1 + Serial1.onReceive(NULL); // resets/disables the RX callback function for Serial 1 } diff --git a/libraries/ESP32/examples/Serial/RS485_Echo_Demo/RS485_Echo_Demo.ino b/libraries/ESP32/examples/Serial/RS485_Echo_Demo/RS485_Echo_Demo.ino index a19be7ffe25..8d69108af42 100644 --- a/libraries/ESP32/examples/Serial/RS485_Echo_Demo/RS485_Echo_Demo.ino +++ b/libraries/ESP32/examples/Serial/RS485_Echo_Demo/RS485_Echo_Demo.ino @@ -1,5 +1,5 @@ /* - This Sketch demonstrates how to use the Hardware Serial peripheral to communicate over an RS485 bus. + This Sketch demonstrates how to use the Hardware Serial peripheral to communicate over an RS485 bus. Data received on the primary serial port is relayed to the bus acting as an RS485 interface and vice versa. @@ -21,20 +21,20 @@ void setup() { Serial.begin(115200); - while(!Serial) { delay(10); } + while (!Serial) { delay(10); } RS485.begin(9600, SERIAL_8N1, RS485_RX_PIN, RS485_TX_PIN); - while(!RS485) { delay(10); } - if(!RS485.setPins(-1, -1, -1, RS485_RTS_PIN)){ + while (!RS485) { delay(10); } + if (!RS485.setPins(-1, -1, -1, RS485_RTS_PIN)) { Serial.print("Failed to set RS485 pins"); } // Certain versions of Arduino core don't define MODE_RS485_HALF_DUPLEX and so fail to compile. // By using UART_MODE_RS485_HALF_DUPLEX defined in hal/uart_types.h we work around this problem. - // If using a newer IDF and Arduino core you can ommit including hal/uart_types.h and use MODE_RS485_HALF_DUPLEX + // If using a newer IDF and Arduino core you can omit including hal/uart_types.h and use MODE_RS485_HALF_DUPLEX // defined in esp32-hal-uart.h (included during other build steps) instead. - if(!RS485.setMode(UART_MODE_RS485_HALF_DUPLEX)) { - Serial.print("Failed to set RS485 mode"); + if (!RS485.setMode(UART_MODE_RS485_HALF_DUPLEX)) { + Serial.print("Failed to set RS485 mode"); } } diff --git a/libraries/ESP32/examples/Serial/RxFIFOFull_Demo/RxFIFOFull_Demo.ino b/libraries/ESP32/examples/Serial/RxFIFOFull_Demo/RxFIFOFull_Demo.ino index 878150264da..833246b5be8 100644 --- a/libraries/ESP32/examples/Serial/RxFIFOFull_Demo/RxFIFOFull_Demo.ino +++ b/libraries/ESP32/examples/Serial/RxFIFOFull_Demo/RxFIFOFull_Demo.ino @@ -1,43 +1,43 @@ /* - * - * This Sketch demonstrates the effect of changing RX FIFO Full parameter into HardwareSerial Class + * + * This Sketch demonstrates the effect of changing RX FIFO Full parameter into HardwareSerial Class * Serial.setRxFIFOFull(byte) is used to change it. * By default, UART ISR will wait for 120 bytes to arrive into UART before making the data available - * to be read by an Arduino Sketch. It may also release fewer bytes after an RX Timeout equivalent by - * default to 2 UART symbols. - * + * to be read by an Arduino Sketch. It may also release fewer bytes after an RX Timeout equivalent by + * default to 2 UART symbols. + * * The way we demonstrate the effect of this parameter is by measuring the time the Sketch takes * to read data using Arduino HardwareSerial API. - * + * * The higher RX FIFO Full is, the lower consumption of the core to process and make the data available. * At the same time, it may take longer for the Sketch to be able to read it, because the data must first * populate RX UART FIFO. - * + * * The lower RX FIFO Full is, the higher consumption of the core to process and make the data available. * This is because the core will be interrupted often and it will copy data from the RX FIFO to the Arduino * internal buffer to be read by the sketch. By other hand, the data will be made available to the sketch - * faster, in a close to byte by byte communication. - * + * faster, in a close to byte by byte communication. + * * Therefore, it allows the decision of the architecture to be designed by the developer. * Some application based on certain protocols may need the sketch to read the Serial Port byte by byte, for example. - * + * */ #include // There are two ways to make this sketch work: // By physically connecting the pins 4 and 5 and then create a physical UART loopback, -// Or by using the internal IO_MUX to connect the TX signal to the RX pin, creating the +// Or by using the internal IO_MUX to connect the TX signal to the RX pin, creating the // same loopback internally. -#define USE_INTERNAL_PIN_LOOPBACK 1 // 1 uses the internal loopback, 0 for wiring pins 4 and 5 externally +#define USE_INTERNAL_PIN_LOOPBACK 1 // 1 uses the internal loopback, 0 for wiring pins 4 and 5 externally -#define DATA_SIZE 125 // 125 bytes is a bit higher than the default 120 bytes of RX FIFO FULL -#define BAUD 9600 // Any baudrate from 300 to 115200 -#define TEST_UART 1 // Serial1 will be used for the loopback testing with different RX FIFO FULL values -#define RXPIN 4 // GPIO 4 => RX for Serial1 -#define TXPIN 5 // GPIO 5 => TX for Serial1 +#define DATA_SIZE 125 // 125 bytes is a bit higher than the default 120 bytes of RX FIFO FULL +#define BAUD 9600 // Any baudrate from 300 to 115200 +#define TEST_UART 1 // Serial1 will be used for the loopback testing with different RX FIFO FULL values +#define RXPIN 4 // GPIO 4 => RX for Serial1 +#define TXPIN 5 // GPIO 5 => TX for Serial1 -uint8_t fifoFullTestCases[] = {120, 20, 5, 1}; +uint8_t fifoFullTestCases[] = { 120, 20, 5, 1 }; void setup() { // UART0 will be used to log information into Serial Monitor @@ -45,7 +45,7 @@ void setup() { // UART1 will have its RX<->TX cross connected // GPIO4 <--> GPIO5 using external wire - Serial1.begin(BAUD, SERIAL_8N1, RXPIN, TXPIN); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3 + Serial1.begin(BAUD, SERIAL_8N1, RXPIN, TXPIN); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3 #if USE_INTERNAL_PIN_LOOPBACK uart_internal_loopback(TEST_UART, RXPIN); #endif @@ -54,37 +54,36 @@ void setup() { Serial.printf("\n\n================================\nTest Case #%d\n================================\n", i + 1); testAndReport(fifoFullTestCases[i]); } - } void loop() { } void testAndReport(uint8_t fifoFull) { - // Let's send 125 bytes from Serial1 rx<->tx and mesaure time using diferent FIFO Full configurations + // Let's send 125 bytes from Serial1 rx<->tx and mesaure time using different FIFO Full configurations uint8_t bytesReceived = 0; uint8_t dataSent[DATA_SIZE], dataReceived[DATA_SIZE]; uint32_t timeStamp[DATA_SIZE], bytesJustReceived[DATA_SIZE]; uint8_t i; // initialize all data for (i = 0; i < DATA_SIZE; i++) { - dataSent[i] = '0' + (i % 10); // fill it with a repeated sequence of 0..9 characters + dataSent[i] = '0' + (i % 10); // fill it with a repeated sequence of 0..9 characters dataReceived[i] = 0; timeStamp[i] = 0; bytesJustReceived[i] = 0; } Serial.printf("Testing the time for receiving %d bytes at %d baud, using RX FIFO Full = %d:", DATA_SIZE, BAUD, fifoFull); - Serial.flush(); // wait Serial FIFO to be empty and then spend almost no time processing it - Serial1.setRxFIFOFull(fifoFull); // testing diferent result based on FIFO Full setup + Serial.flush(); // wait Serial FIFO to be empty and then spend almost no time processing it + Serial1.setRxFIFOFull(fifoFull); // testing different result based on FIFO Full setup - size_t sentBytes = Serial1.write(dataSent, sizeof(dataSent)); // ESP32 TX FIFO is about 128 bytes, 125 bytes will fit fine + size_t sentBytes = Serial1.write(dataSent, sizeof(dataSent)); // ESP32 TX FIFO is about 128 bytes, 125 bytes will fit fine uint32_t now = millis(); i = 0; while (bytesReceived < DATA_SIZE) { bytesReceived += (bytesJustReceived[i] = Serial1.read(dataReceived + bytesReceived, DATA_SIZE)); timeStamp[i] = millis(); - if (bytesJustReceived[i] > 0) i++; // next data only when we read something from Serial1 + if (bytesJustReceived[i] > 0) i++; // next data only when we read something from Serial1 // safety for array limit && timeout... in 5 seconds... if (i == DATA_SIZE || millis() - now > 5000) break; } @@ -100,4 +99,3 @@ void testAndReport(uint8_t fifoFull) { Serial.println("========================\nFinished!"); } - diff --git a/libraries/ESP32/examples/Serial/RxTimeout_Demo/RxTimeout_Demo.ino b/libraries/ESP32/examples/Serial/RxTimeout_Demo/RxTimeout_Demo.ino index b4592f8249d..7c58a535c88 100644 --- a/libraries/ESP32/examples/Serial/RxTimeout_Demo/RxTimeout_Demo.ino +++ b/libraries/ESP32/examples/Serial/RxTimeout_Demo/RxTimeout_Demo.ino @@ -6,8 +6,8 @@ of UART data has ended. For example, if just one byte is received, UART will send about 10 to 11 bits depending of the configuration (parity, number of stopbits). The timeout is measured in number of UART symbols, with 10 or 11 bits, in the current baudrate. - For 9600 baud, 1 bit takes 1/9600 of a second, equivalent to 104 microseconds, therefore, for 10 bits, - it takes about 1ms. A timeout of 2 UART symbols, with about 20 bits, would take about 2.1 milliseconds + For 9600 baud, 1 bit takes 1/9600 of a second, equivalent to 104 microseconds, therefore, for 10 bits, + it takes about 1ms. A timeout of 2 UART symbols, with about 20 bits, would take about 2.1 milliseconds for the ESP32 UART to trigger an IRQ telling the UART driver that the transmission has ended. Just at this point, the data will be made available to Arduino HardwareSerial API (read(), available(), etc). @@ -19,7 +19,7 @@ The driver will copy data from FIFO when RX Timeout is detected or when FIFO is full. ESP32 FIFO has 128 bytes and by default, the driver will copy the data when FIFO reaches 120 bytes. If UART receives less than 120 bytes, it will wait RX Timeout to understand that the bus is IDLE and - then copy the data from the FIFO to the Arduino internal buffer, making it availble to the Arduino API. + then copy the data from the FIFO to the Arduino internal buffer, making it available to the Arduino API. */ @@ -29,15 +29,15 @@ // By physically connecting the pins 4 and 5 and then create a physical UART loopback, // Or by using the internal IO_MUX to connect the TX signal to the RX pin, creating the // same loopback internally. -#define USE_INTERNAL_PIN_LOOPBACK 1 // 1 uses the internal loopback, 0 for wiring pins 4 and 5 externally +#define USE_INTERNAL_PIN_LOOPBACK 1 // 1 uses the internal loopback, 0 for wiring pins 4 and 5 externally -#define DATA_SIZE 10 // 10 bytes is lower than the default 120 bytes of RX FIFO FULL -#define BAUD 9600 // Any baudrate from 300 to 115200 -#define TEST_UART 1 // Serial1 will be used for the loopback testing with different RX FIFO FULL values -#define RXPIN 4 // GPIO 4 => RX for Serial1 -#define TXPIN 5 // GPIO 5 => TX for Serial1 +#define DATA_SIZE 10 // 10 bytes is lower than the default 120 bytes of RX FIFO FULL +#define BAUD 9600 // Any baudrate from 300 to 115200 +#define TEST_UART 1 // Serial1 will be used for the loopback testing with different RX FIFO FULL values +#define RXPIN 4 // GPIO 4 => RX for Serial1 +#define TXPIN 5 // GPIO 5 => TX for Serial1 -uint8_t rxTimeoutTestCases[] = {50, 20, 10, 5, 1}; +uint8_t rxTimeoutTestCases[] = { 50, 20, 10, 5, 1 }; void setup() { // UART0 will be used to log information into Serial Monitor @@ -45,7 +45,7 @@ void setup() { // UART1 will have its RX<->TX cross connected // GPIO4 <--> GPIO5 using external wire - Serial1.begin(BAUD, SERIAL_8N1, RXPIN, TXPIN); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3 + Serial1.begin(BAUD, SERIAL_8N1, RXPIN, TXPIN); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3 #if USE_INTERNAL_PIN_LOOPBACK uart_internal_loopback(TEST_UART, RXPIN); #endif @@ -54,30 +54,29 @@ void setup() { Serial.printf("\n\n================================\nTest Case #%d\n================================\n", i + 1); testAndReport(rxTimeoutTestCases[i]); } - } void loop() { } void testAndReport(uint8_t rxTimeout) { - // Let's send 10 bytes from Serial1 rx<->tx and mesaure time using diferent Rx Timeout configurations + // Let's send 10 bytes from Serial1 rx<->tx and mesaure time using different Rx Timeout configurations uint8_t bytesReceived = 0; uint8_t dataSent[DATA_SIZE], dataReceived[DATA_SIZE]; uint8_t i; // initialize all data for (i = 0; i < DATA_SIZE; i++) { - dataSent[i] = '0' + (i % 10); // fill it with a repeated sequence of 0..9 characters + dataSent[i] = '0' + (i % 10); // fill it with a repeated sequence of 0..9 characters dataReceived[i] = 0; } Serial.printf("Testing the time for receiving %d bytes at %d baud, using RX Timeout = %d:", DATA_SIZE, BAUD, rxTimeout); - Serial.flush(); // wait Serial FIFO to be empty and then spend almost no time processing it - Serial1.setRxTimeout(rxTimeout); // testing diferent results based on Rx Timeout setup + Serial.flush(); // wait Serial FIFO to be empty and then spend almost no time processing it + Serial1.setRxTimeout(rxTimeout); // testing different results based on Rx Timeout setup // For baud rates lower or equal to 57600, ESP32 Arduino makes it get byte-by-byte from FIFO, thus we will change it here: - Serial1.setRxFIFOFull(120); // forces it to wait receiving 120 bytes in FIFO before making it availble to Arduino + Serial1.setRxFIFOFull(120); // forces it to wait receiving 120 bytes in FIFO before making it available to Arduino - size_t sentBytes = Serial1.write(dataSent, sizeof(dataSent)); // ESP32 TX FIFO is about 128 bytes, 10 bytes will fit fine + size_t sentBytes = Serial1.write(dataSent, sizeof(dataSent)); // ESP32 TX FIFO is about 128 bytes, 10 bytes will fit fine uint32_t now = millis(); while (bytesReceived < DATA_SIZE) { bytesReceived += Serial1.read(dataReceived, DATA_SIZE); diff --git a/libraries/ESP32/examples/Serial/Serial_All_CPU_Freqs/Serial_All_CPU_Freqs.ino b/libraries/ESP32/examples/Serial/Serial_All_CPU_Freqs/Serial_All_CPU_Freqs.ino index 26a5125bbbc..ec2016b739b 100644 --- a/libraries/ESP32/examples/Serial/Serial_All_CPU_Freqs/Serial_All_CPU_Freqs.ino +++ b/libraries/ESP32/examples/Serial/Serial_All_CPU_Freqs/Serial_All_CPU_Freqs.ino @@ -9,7 +9,7 @@ */ -int cpufreqs[6] = {240, 160, 80, 40, 20, 10}; +int cpufreqs[6] = { 240, 160, 80, 40, 20, 10 }; #define NUM_CPU_FREQS (sizeof(cpufreqs) / sizeof(int)) void setup() { diff --git a/libraries/ESP32/examples/Serial/Serial_STD_Func_OnReceive/Serial_STD_Func_OnReceive.ino b/libraries/ESP32/examples/Serial/Serial_STD_Func_OnReceive/Serial_STD_Func_OnReceive.ino index eb3bddafcb7..d388d1a77cb 100644 --- a/libraries/ESP32/examples/Serial/Serial_STD_Func_OnReceive/Serial_STD_Func_OnReceive.ino +++ b/libraries/ESP32/examples/Serial/Serial_STD_Func_OnReceive/Serial_STD_Func_OnReceive.ino @@ -2,16 +2,16 @@ * This is C++ example that demonstrates the usage of a std::function as OnReceive Callback function to all the UARTs * It basically defines a general onReceive function that receives an extra parameter, the Serial pointer that is * executing the callback. - * - * For each HardwareSerial object (Serial, Serial1, Serial2), it is necessary to set the callback with - * the repective Serial pointer. It is done using lambda expression as a std::function. + * + * For each HardwareSerial object (Serial, Serial1, Serial2), it is necessary to set the callback with + * the respective Serial pointer. It is done using lambda expression as a std::function. * Example: * Serial1.onReceive([]() { processOnReceiving(&Serial1); }); - * + * */ // soc/soc_caps.h has information about each SoC target -// in this example, we use SOC_UART_NUM that goes from 1 to 3, +// in this example, we use SOC_UART_NUM that goes from 1 to 3, // depending on the number of available UARTs in the ESP32xx // This makes the code transparent to what SoC is used. #include "soc/soc_caps.h" @@ -19,15 +19,15 @@ // This example shall use UART1 or UART2 for testing and UART0 for console messages // If UART0 is used for testing, it is necessary to manually send data to it, using the Serial Monitor/Terminal // In case that USB CDC is available, it may be used as console for messages. -#define TEST_UART 1 // Serial# (0, 1 or 2) will be used for the loopback -#define RXPIN 4 // GPIO 4 => RX for Serial1 or Serial2 -#define TXPIN 5 // GPIO 5 => TX for Serial1 or Serial2 +#define TEST_UART 1 // Serial# (0, 1 or 2) will be used for the loopback +#define RXPIN 4 // GPIO 4 => RX for Serial1 or Serial2 +#define TXPIN 5 // GPIO 5 => TX for Serial1 or Serial2 // declare testingSerial (as reference) related to TEST_UART number defined above (only for Serial1 and Serial2) #if SOC_UART_NUM > 1 && TEST_UART == 1 - HardwareSerial &testingSerial = Serial1; +HardwareSerial &testingSerial = Serial1; #elif SOC_UART_NUM > 2 && TEST_UART == 2 - HardwareSerial &testingSerial = Serial2; +HardwareSerial &testingSerial = Serial2; #endif // General callback function for any UART -- used with a lambda std::function within HardwareSerial::onReceive() @@ -55,7 +55,7 @@ void processOnReceiving(HardwareSerial &mySerial) { Serial.printf("Received %d bytes\n", mySerial.available()); Serial.printf("First byte is '%c' [0x%02x]\n", mySerial.peek(), mySerial.peek()); uint8_t charPerLine = 0; - while(mySerial.available()) { + while (mySerial.available()) { char c = mySerial.read(); Serial.printf("'%c' [0x%02x] ", c, c); if (++charPerLine == 10) { @@ -67,26 +67,26 @@ void processOnReceiving(HardwareSerial &mySerial) { void setup() { // Serial can be the USB or UART0, depending on the settings and which SoC is used - Serial.begin(115200); - - // when data is received from UART0, it will call the general function + Serial.begin(115200); + + // when data is received from UART0, it will call the general function // passing Serial0 as parameter for processing #if TEST_UART == 0 - Serial0.begin(115200); // keeps default GPIOs + Serial0.begin(115200); // keeps default GPIOs Serial0.onReceive([]() { processOnReceiving(Serial0); }); #else // and so on for the other UARTs (Serial1 and Serial2) // Rx = 4, Tx = 5 will work for ESP32, S2, S3, C3, C6 and H2 - testingSerial.begin(115200, SERIAL_8N1, RXPIN, TXPIN); + testingSerial.begin(115200, SERIAL_8N1, RXPIN, TXPIN); testingSerial.onReceive([]() { processOnReceiving(testingSerial); }); #endif - // this helper function will connect TX pin (from TEST_UART number) to its RX pin - // creating a loopback that will allow to write to TEST_UART number + // this helper function will connect TX pin (from TEST_UART number) to its RX pin + // creating a loopback that will allow to write to TEST_UART number // and send it to RX with no need to physically connect both pins #if TEST_UART > 0 uart_internal_loopback(TEST_UART, RXPIN); @@ -94,19 +94,18 @@ void setup() { // when UART0 is used for testing, it is necessary to send data using the Serial Monitor/Terminal // Data must be sent by the CP2102, manually using the Serial Monitor/Terminal #endif - + delay(500); Serial.printf("\nSend bytes to UART%d in order to\n", TEST_UART); - Serial.println("see a single processing fuction display information about"); + Serial.println("see a single processing function display information about"); Serial.println("the received data.\n"); - } void loop() { // All done by the UART callback functions // just write a random number of bytes into the testing UART char serial_data[24]; - size_t len = random(sizeof(serial_data) - 1) + 1; // at least 1 byte will be sent + size_t len = random(sizeof(serial_data) - 1) + 1; // at least 1 byte will be sent for (uint8_t i = 0; i < len; i++) serial_data[i] = 'A' + i; #if TEST_UART > 0 @@ -120,4 +119,3 @@ void loop() { Serial.println("pausing for 15 seconds."); delay(15000); } - diff --git a/libraries/ESP32/examples/Serial/onReceiveExample/onReceiveExample.ino b/libraries/ESP32/examples/Serial/onReceiveExample/onReceiveExample.ino index 5338de15e96..7bac54b004f 100644 --- a/libraries/ESP32/examples/Serial/onReceiveExample/onReceiveExample.ino +++ b/libraries/ESP32/examples/Serial/onReceiveExample/onReceiveExample.ino @@ -13,7 +13,7 @@ OnReceive will be called, while receiving a stream of data, when every 120 bytes are received (default FIFO Full), which may not help in case that the application needs to get all data at once before processing it. Therefore, a way to make it work is by detecting the end of a stream transmission. This can be based on a protocol - or based on timeout with the UART line in idle (no data received - this is the case of this example). + or based on timeout with the UART line in idle (no data received - this is the case of this example). In some cases, it is necessary to wait for receiving all the data before processing it and parsing the UART input. This example demonstrates a way to create a String with all data received from UART0 and @@ -71,10 +71,10 @@ SemaphoreHandle_t uart_buffer_Mutex = NULL; void UART0_RX_CB() { // take the mutex, waits forever until loop() finishes its processing if (xSemaphoreTake(uart_buffer_Mutex, portMAX_DELAY)) { - uint32_t now = millis(); // tracks timeout + uint32_t now = millis(); // tracks timeout while ((millis() - now) < communicationTimeout_ms) { if (UART0.available()) { - uart_buffer += (char) UART0.read(); + uart_buffer += (char)UART0.read(); now = millis(); // reset the timer } } @@ -90,9 +90,9 @@ void setup() { // creates a mutex object to control access to uart_buffer uart_buffer_Mutex = xSemaphoreCreateMutex(); - if(uart_buffer_Mutex == NULL) { + if (uart_buffer_Mutex == NULL) { log_e("Error creating Mutex. Sketch will fail."); - while(true) { + while (true) { UART0.println("Mutex error (NULL). Program halted."); delay(2000); } @@ -118,7 +118,7 @@ void loop() { // releases the mutex for more data to be received xSemaphoreGive(uart_buffer_Mutex); } - } + } UART0.println("Sleeping for 1 second..."); delay(1000); } diff --git a/libraries/ESP32/examples/TWAI/TWAIreceive/TWAIreceive.ino b/libraries/ESP32/examples/TWAI/TWAIreceive/TWAIreceive.ino index ebf9f857e86..590ca4a0fea 100644 --- a/libraries/ESP32/examples/TWAI/TWAIreceive/TWAIreceive.ino +++ b/libraries/ESP32/examples/TWAI/TWAIreceive/TWAIreceive.ino @@ -31,7 +31,7 @@ #define RX_PIN 21 #define TX_PIN 22 -// Intervall: +// Interval: #define POLLING_RATE_MS 1000 static bool driver_installed = false; diff --git a/libraries/ESP32/examples/TWAI/TWAItransmit/TWAItransmit.ino b/libraries/ESP32/examples/TWAI/TWAItransmit/TWAItransmit.ino index d8fba7fa6f7..c2af7bf60ec 100644 --- a/libraries/ESP32/examples/TWAI/TWAItransmit/TWAItransmit.ino +++ b/libraries/ESP32/examples/TWAI/TWAItransmit/TWAItransmit.ino @@ -16,7 +16,7 @@ #define RX_PIN 21 #define TX_PIN 22 -// Intervall: +// Interval: #define TRANSMIT_RATE_MS 1000 #define POLLING_RATE_MS 1000 diff --git a/libraries/ESP32/examples/Template/ExampleTemplate/ExampleTemplate.ino b/libraries/ESP32/examples/Template/ExampleTemplate/ExampleTemplate.ino index ff9733d1cd4..572510d75ab 100644 --- a/libraries/ESP32/examples/Template/ExampleTemplate/ExampleTemplate.ino +++ b/libraries/ESP32/examples/Template/ExampleTemplate/ExampleTemplate.ino @@ -8,9 +8,7 @@ */ void setup() { - } void loop() { - } diff --git a/libraries/ESP32/examples/Time/SimpleTime/SimpleTime.ino b/libraries/ESP32/examples/Time/SimpleTime/SimpleTime.ino index e7e3fc3f1fd..9bdef912a47 100644 --- a/libraries/ESP32/examples/Time/SimpleTime/SimpleTime.ino +++ b/libraries/ESP32/examples/Time/SimpleTime/SimpleTime.ino @@ -2,76 +2,72 @@ #include "time.h" #include "esp_sntp.h" -const char* ssid = "YOUR_SSID"; -const char* password = "YOUR_PASS"; +const char* ssid = "YOUR_SSID"; +const char* password = "YOUR_PASS"; const char* ntpServer1 = "pool.ntp.org"; const char* ntpServer2 = "time.nist.gov"; -const long gmtOffset_sec = 3600; -const int daylightOffset_sec = 3600; +const long gmtOffset_sec = 3600; +const int daylightOffset_sec = 3600; const char* time_zone = "CET-1CEST,M3.5.0,M10.5.0/3"; // TimeZone rule for Europe/Rome including daylight adjustment rules (optional) -void printLocalTime() -{ +void printLocalTime() { struct tm timeinfo; - if(!getLocalTime(&timeinfo)){ + if (!getLocalTime(&timeinfo)) { Serial.println("No time available (yet)"); return; } Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S"); } -// Callback function (get's called when time adjusts via NTP) -void timeavailable(struct timeval *t) -{ +// Callback function (gets called when time adjusts via NTP) +void timeavailable(struct timeval* t) { Serial.println("Got time adjustment from NTP!"); printLocalTime(); } -void setup() -{ +void setup() { Serial.begin(115200); // First step is to configure WiFi STA and connect in order to get the current time and date. Serial.printf("Connecting to %s ", ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); + delay(500); + Serial.print("."); } Serial.println(" CONNECTED"); // set notification call-back function - sntp_set_time_sync_notification_cb( timeavailable ); + sntp_set_time_sync_notification_cb(timeavailable); /** - * NTP server address could be aquired via DHCP, + * NTP server address could be acquired via DHCP, * - * NOTE: This call should be made BEFORE esp32 aquires IP address via DHCP, + * NOTE: This call should be made BEFORE esp32 acquires IP address via DHCP, * otherwise SNTP option 42 would be rejected by default. * NOTE: configTime() function call if made AFTER DHCP-client run - * will OVERRIDE aquired NTP server address - */ - esp_sntp_servermode_dhcp(1);// (optional) + * will OVERRIDE acquired NTP server address + */ + esp_sntp_servermode_dhcp(1); // (optional) /** * This will set configured ntp servers and constant TimeZone/daylightOffset * should be OK if your time zone does not need to adjust daylightOffset twice a year, - * in such a case time adjustment won't be handled automagicaly. + * in such a case time adjustment won't be handled automagically. */ configTime(gmtOffset_sec, daylightOffset_sec, ntpServer1, ntpServer2); /** - * A more convenient approach to handle TimeZones with daylightOffset - * would be to specify a environmnet variable with TimeZone definition including daylight adjustmnet rules. + * A more convenient approach to handle TimeZones with daylightOffset + * would be to specify a environment variable with TimeZone definition including daylight adjustmnet rules. * A list of rules for your zone could be obtained from https://github.com/esp8266/Arduino/blob/master/cores/esp8266/TZ.h */ //configTzTime(time_zone, ntpServer1, ntpServer2); } -void loop() -{ +void loop() { delay(5000); - printLocalTime(); // it will take some time to sync time :) + printLocalTime(); // it will take some time to sync time :) } diff --git a/libraries/ESP32/examples/Timer/RepeatTimer/RepeatTimer.ino b/libraries/ESP32/examples/Timer/RepeatTimer/RepeatTimer.ino index 275cd0fac68..9bea5b37e29 100644 --- a/libraries/ESP32/examples/Timer/RepeatTimer/RepeatTimer.ino +++ b/libraries/ESP32/examples/Timer/RepeatTimer/RepeatTimer.ino @@ -9,16 +9,16 @@ */ // Stop button is attached to PIN 0 (IO0) -#define BTN_STOP_ALARM 0 +#define BTN_STOP_ALARM 0 -hw_timer_t * timer = NULL; +hw_timer_t* timer = NULL; volatile SemaphoreHandle_t timerSemaphore; portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED; volatile uint32_t isrCounter = 0; volatile uint32_t lastIsrAt = 0; -void ARDUINO_ISR_ATTR onTimer(){ +void ARDUINO_ISR_ATTR onTimer() { // Increment the counter and set the time of ISR portENTER_CRITICAL_ISR(&timerMux); isrCounter = isrCounter + 1; @@ -51,7 +51,7 @@ void setup() { void loop() { // If Timer has fired - if (xSemaphoreTake(timerSemaphore, 0) == pdTRUE){ + if (xSemaphoreTake(timerSemaphore, 0) == pdTRUE) { uint32_t isrCount = 0, isrTime = 0; // Read the interrupt count and time portENTER_CRITICAL(&timerMux); diff --git a/libraries/ESP32/examples/Timer/WatchdogTimer/WatchdogTimer.ino b/libraries/ESP32/examples/Timer/WatchdogTimer/WatchdogTimer.ino index d1a70f800b1..bd4275d71cf 100644 --- a/libraries/ESP32/examples/Timer/WatchdogTimer/WatchdogTimer.ino +++ b/libraries/ESP32/examples/Timer/WatchdogTimer/WatchdogTimer.ino @@ -3,7 +3,7 @@ const int button = 0; //gpio to use to trigger delay const int wdtTimeout = 3000; //time in ms to trigger the watchdog -hw_timer_t * timer = NULL; +hw_timer_t* timer = NULL; void ARDUINO_ISR_ATTR resetModule() { ets_printf("reboot\n"); @@ -15,25 +15,25 @@ void setup() { Serial.println(); Serial.println("running setup"); - pinMode(button, INPUT_PULLUP); //init control pin - timer = timerBegin(1000000); //timer 1Mhz resolution - timerAttachInterrupt(timer, &resetModule); //attach callback - timerAlarm(timer, wdtTimeout * 1000, false, 0); //set time in us + pinMode(button, INPUT_PULLUP); //init control pin + timer = timerBegin(1000000); //timer 1Mhz resolution + timerAttachInterrupt(timer, &resetModule); //attach callback + timerAlarm(timer, wdtTimeout * 1000, false, 0); //set time in us } void loop() { Serial.println("running main loop"); - timerWrite(timer, 0); //reset timer (feed watchdog) + timerWrite(timer, 0); //reset timer (feed watchdog) long loopTime = millis(); //while button is pressed, delay up to 3 seconds to trigger the timer while (!digitalRead(button)) { Serial.println("button pressed"); delay(500); } - delay(1000); //simulate work + delay(1000); //simulate work loopTime = millis() - loopTime; - + Serial.print("loop time is = "); - Serial.println(loopTime); //should be under 3000 + Serial.println(loopTime); //should be under 3000 } diff --git a/libraries/ESP32/examples/Touch/TouchButton/TouchButton.ino b/libraries/ESP32/examples/Touch/TouchButton/TouchButton.ino index b1dbc63fdcb..9acfdddb3a1 100644 --- a/libraries/ESP32/examples/Touch/TouchButton/TouchButton.ino +++ b/libraries/ESP32/examples/Touch/TouchButton/TouchButton.ino @@ -13,7 +13,7 @@ bool touchActive = false; bool lastTouchActive = false; bool testingLower = true; -void gotTouchEvent(){ +void gotTouchEvent() { if (lastTouchActive != testingLower) { touchActive = !touchActive; testingLower = !testingLower; @@ -24,7 +24,7 @@ void gotTouchEvent(){ void setup() { Serial.begin(115200); - delay(1000); // give me time to bring up serial monitor + delay(1000); // give me time to bring up serial monitor Serial.println("ESP32 Touch Interrupt Test"); touchAttachInterrupt(T2, gotTouchEvent, threshold); @@ -32,8 +32,8 @@ void setup() { touchInterruptSetThresholdDirection(testingLower); } -void loop(){ - if(lastTouchActive != touchActive){ +void loop() { + if (lastTouchActive != touchActive) { lastTouchActive = touchActive; if (touchActive) { Serial.println(" ---- Touch was Pressed"); diff --git a/libraries/ESP32/examples/Touch/TouchButtonV2/TouchButtonV2.ino b/libraries/ESP32/examples/Touch/TouchButtonV2/TouchButtonV2.ino index 9c489c2597c..5dc9bfeed3f 100644 --- a/libraries/ESP32/examples/Touch/TouchButtonV2/TouchButtonV2.ino +++ b/libraries/ESP32/examples/Touch/TouchButtonV2/TouchButtonV2.ino @@ -8,7 +8,7 @@ This method based on touchInterruptGetLastStatus() is only available for ESP32 S #include "Arduino.h" -int threshold = 1500; // ESP32S2 +int threshold = 1500; // ESP32S2 bool touch1detected = false; bool touch2detected = false; @@ -22,10 +22,10 @@ void gotTouch2() { void setup() { Serial.begin(115200); - delay(1000); // give me time to bring up serial monitor + delay(1000); // give me time to bring up serial monitor Serial.println("\n ESP32 Touch Interrupt Test\n"); - touchAttachInterrupt(T1, gotTouch1, threshold); + touchAttachInterrupt(T1, gotTouch1, threshold); touchAttachInterrupt(T2, gotTouch2, threshold); } @@ -33,17 +33,17 @@ void loop() { if (touch1detected) { touch1detected = false; if (touchInterruptGetLastStatus(T1)) { - Serial.println(" --- T1 Touched"); + Serial.println(" --- T1 Touched"); } else { - Serial.println(" --- T1 Released"); + Serial.println(" --- T1 Released"); } } if (touch2detected) { touch2detected = false; if (touchInterruptGetLastStatus(T2)) { - Serial.println(" --- T2 Touched"); + Serial.println(" --- T2 Touched"); } else { - Serial.println(" --- T2 Released"); + Serial.println(" --- T2 Released"); } } diff --git a/libraries/ESP32/examples/Touch/TouchInterrupt/TouchInterrupt.ino b/libraries/ESP32/examples/Touch/TouchInterrupt/TouchInterrupt.ino index 20bee460bc4..0f0880902fb 100644 --- a/libraries/ESP32/examples/Touch/TouchInterrupt/TouchInterrupt.ino +++ b/libraries/ESP32/examples/Touch/TouchInterrupt/TouchInterrupt.ino @@ -7,28 +7,28 @@ int threshold = 40; bool touch1detected = false; bool touch2detected = false; -void gotTouch1(){ - touch1detected = true; +void gotTouch1() { + touch1detected = true; } -void gotTouch2(){ - touch2detected = true; +void gotTouch2() { + touch2detected = true; } void setup() { Serial.begin(115200); - delay(1000); // give me time to bring up serial monitor + delay(1000); // give me time to bring up serial monitor Serial.println("ESP32 Touch Interrupt Test"); touchAttachInterrupt(T2, gotTouch1, threshold); touchAttachInterrupt(T3, gotTouch2, threshold); } -void loop(){ - if(touch1detected){ +void loop() { + if (touch1detected) { touch1detected = false; Serial.println("Touch 1 detected"); } - if(touch2detected){ + if (touch2detected) { touch2detected = false; Serial.println("Touch 2 detected"); } diff --git a/libraries/ESP32/examples/Touch/TouchRead/TouchRead.ino b/libraries/ESP32/examples/Touch/TouchRead/TouchRead.ino index 57312c62587..8e93ba44691 100644 --- a/libraries/ESP32/examples/Touch/TouchRead/TouchRead.ino +++ b/libraries/ESP32/examples/Touch/TouchRead/TouchRead.ino @@ -1,15 +1,13 @@ // ESP32 Touch Test // Just test touch pin - Touch0 is T0 which is on GPIO 4. -void setup() -{ +void setup() { Serial.begin(115200); - delay(1000); // give me time to bring up serial monitor + delay(1000); // give me time to bring up serial monitor Serial.println("ESP32 Touch Test"); } -void loop() -{ +void loop() { Serial.println(touchRead(T1)); // get value using T0 delay(1000); } diff --git a/libraries/ESP32/examples/Utilities/HEXBuilder/HEXBuilder.ino b/libraries/ESP32/examples/Utilities/HEXBuilder/HEXBuilder.ino index 3e9ae5bfd53..ce6ffcacacb 100644 --- a/libraries/ESP32/examples/Utilities/HEXBuilder/HEXBuilder.ino +++ b/libraries/ESP32/examples/Utilities/HEXBuilder/HEXBuilder.ino @@ -7,8 +7,8 @@ void setup() { // Convert a HEX string like 6c6c6f20576f726c64 to a binary buffer { - const char * out = "Hello World"; - const char * hexin = "48656c6c6f20576f726c6400"; // As the string above is \0 terminated too + const char *out = "Hello World"; + const char *hexin = "48656c6c6f20576f726c6400"; // As the string above is \0 terminated too unsigned char buff[256]; size_t len = HEXBuilder::hex2bytes(buff, sizeof(buff), hexin); @@ -16,7 +16,7 @@ void setup() { if (len != 1 + strlen(out)) Serial.println("Odd - length 1 is wrong"); - if (memcmp(buff, out, len) != 0) + if (memcmp(buff, out, len) != 0) Serial.println("Odd - decode 1 went wrong"); // Safe to print this binary buffer -- as we've included a \0 in the hex sequence. @@ -33,7 +33,7 @@ void setup() { if (len != strlen(hello)) Serial.println("Odd - length 2 is wrong"); - if (strcmp((char *) buff, hello) != 0) + if (strcmp((char *)buff, hello) != 0) Serial.println("Odd - decode 2 went wrong"); } diff --git a/libraries/ESP32/examples/Utilities/MD5Builder/MD5Builder.ino b/libraries/ESP32/examples/Utilities/MD5Builder/MD5Builder.ino index 9b439587000..04623890cc7 100644 --- a/libraries/ESP32/examples/Utilities/MD5Builder/MD5Builder.ino +++ b/libraries/ESP32/examples/Utilities/MD5Builder/MD5Builder.ino @@ -55,10 +55,8 @@ void setup() { Serial.println("Odd - failing MD5 on hex string"); Serial.println(md5); Serial.println(result); - } - else + } else Serial.println("OK!"); - } // Check that this also work if we add the password as @@ -80,16 +78,14 @@ void setup() { Serial.println("OK!"); // And also check that we can compare this as pure, raw, bytes - uint8_t raw[16] = { 0xb1, 0x0a, 0x8d, 0xb1, 0x64, 0xe0, 0x75, 0x41, - 0x05, 0xb7, 0xa9, 0x9b, 0xe7, 0x2e, 0x3f, 0xe5 - }; + uint8_t raw[16] = { 0xb1, 0x0a, 0x8d, 0xb1, 0x64, 0xe0, 0x75, 0x41, + 0x05, 0xb7, 0xa9, 0x9b, 0xe7, 0x2e, 0x3f, 0xe5 }; uint8_t res[16]; md.getBytes(res); if (memcmp(raw, res, 16)) Serial.println("Odd - failing MD5 on byte array when compared as bytes"); else Serial.println("OK!"); - } } diff --git a/libraries/ESP32/examples/Utilities/SHA1Builder/SHA1Builder.ino b/libraries/ESP32/examples/Utilities/SHA1Builder/SHA1Builder.ino index 40270953473..041aaceee1f 100644 --- a/libraries/ESP32/examples/Utilities/SHA1Builder/SHA1Builder.ino +++ b/libraries/ESP32/examples/Utilities/SHA1Builder/SHA1Builder.ino @@ -6,7 +6,7 @@ // source code. // // SHA1Builder helps you obfuscate this (This is not much more secure. -// SHA1 is past its retirement age and long obsolte/insecure, but it helps +// SHA1 is past its retirement age and long obsolete/insecure, but it helps // a little) by letting you create an (unsalted!) SHA1 of the data the // user entered; and then compare this to an SHA1 string that you have put // in your code. @@ -56,10 +56,8 @@ void setup() { Serial.println("Odd - failing SHA1 on hex string"); Serial.println(sha1_str); Serial.println(result); - } - else + } else Serial.println("OK!"); - } // Check that this also work if we add the password as @@ -81,16 +79,14 @@ void setup() { Serial.println("OK!"); // And also check that we can compare this as pure, raw, bytes - uint8_t raw[20] = { 0x0a, 0x4d, 0x55, 0xa8, 0xd7, 0x78, 0xe5, 0x02, 0x2f, 0xab, - 0x70, 0x19, 0x77, 0xc5, 0xd8, 0x40, 0xbb, 0xc4, 0x86, 0xd0 - }; + uint8_t raw[20] = { 0x0a, 0x4d, 0x55, 0xa8, 0xd7, 0x78, 0xe5, 0x02, 0x2f, 0xab, + 0x70, 0x19, 0x77, 0xc5, 0xd8, 0x40, 0xbb, 0xc4, 0x86, 0xd0 }; uint8_t res[20]; sha.getBytes(res); if (memcmp(raw, res, 20)) Serial.println("Odd - failing SHA1 on byte array when compared as bytes"); else Serial.println("OK!"); - } } diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/README.md b/libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/README.md index a1de3abef2c..a475cde214d 100644 --- a/libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/README.md +++ b/libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/README.md @@ -33,7 +33,7 @@ To get more information about the Espressif boards see [Espressif Development Ki ## Troubleshooting -If the End device flashed with this example is not connecting to the coordinator, erase the flash before flashing it to the board. It is recommended to do this if you did changes to the coordinator. +If the End device flashed with this example is not connecting to the coordinator, erase the flash before flashing it to the board. It is recommended to do this if you did changes to the coordinator. You can do the following: * In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled` diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/Zigbee_Light_Bulb.ino b/libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/Zigbee_Light_Bulb.ino index 1fc99897d9d..803d1df4cae 100644 --- a/libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/Zigbee_Light_Bulb.ino +++ b/libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/Zigbee_Light_Bulb.ino @@ -14,13 +14,13 @@ /** * @brief This example demonstrates simple Zigbee light bulb. - * + * * The example demonstrates how to use ESP Zigbee stack to create a end device light bulb. * The light bulb is a Zigbee end device, which is controlled by a Zigbee coordinator. - * - * Proper Zigbee mode must be selected in Tools->Zigbee mode + * + * Proper Zigbee mode must be selected in Tools->Zigbee mode * and also the correct partition scheme must be selected in Tools->Partition Scheme. - * + * * Please check the README.md for instructions and more detailed description. */ @@ -36,156 +36,151 @@ #define LED_PIN RGB_BUILTIN /* Default End Device config */ -#define ESP_ZB_ZED_CONFIG() \ - { \ - .esp_zb_role = ESP_ZB_DEVICE_TYPE_ED, \ - .install_code_policy = INSTALLCODE_POLICY_ENABLE, \ - .nwk_cfg = { \ - .zed_cfg = { \ - .ed_timeout = ED_AGING_TIMEOUT, \ - .keep_alive = ED_KEEP_ALIVE, \ - }, \ - }, \ - } - -#define ESP_ZB_DEFAULT_RADIO_CONFIG() \ - { \ - .radio_mode = RADIO_MODE_NATIVE, \ - } - -#define ESP_ZB_DEFAULT_HOST_CONFIG() \ - { \ - .host_connection_mode = HOST_CONNECTION_MODE_NONE, \ - } +#define ESP_ZB_ZED_CONFIG() \ + { \ + .esp_zb_role = ESP_ZB_DEVICE_TYPE_ED, \ + .install_code_policy = INSTALLCODE_POLICY_ENABLE, \ + .nwk_cfg = { \ + .zed_cfg = { \ + .ed_timeout = ED_AGING_TIMEOUT, \ + .keep_alive = ED_KEEP_ALIVE, \ + }, \ + }, \ + } + +#define ESP_ZB_DEFAULT_RADIO_CONFIG() \ + { \ + .radio_mode = RADIO_MODE_NATIVE, \ + } + +#define ESP_ZB_DEFAULT_HOST_CONFIG() \ + { \ + .host_connection_mode = HOST_CONNECTION_MODE_NONE, \ + } /* Zigbee configuration */ -#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */ -#define ED_AGING_TIMEOUT ESP_ZB_ED_AGING_TIMEOUT_64MIN -#define ED_KEEP_ALIVE 3000 /* 3000 millisecond */ -#define HA_ESP_LIGHT_ENDPOINT 10 /* esp light bulb device endpoint, used to process light controlling commands */ -#define ESP_ZB_PRIMARY_CHANNEL_MASK ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK /* Zigbee primary channel mask use in the example */ +#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */ +#define ED_AGING_TIMEOUT ESP_ZB_ED_AGING_TIMEOUT_64MIN +#define ED_KEEP_ALIVE 3000 /* 3000 millisecond */ +#define HA_ESP_LIGHT_ENDPOINT 10 /* esp light bulb device endpoint, used to process light controlling commands */ +#define ESP_ZB_PRIMARY_CHANNEL_MASK ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK /* Zigbee primary channel mask use in the example */ /********************* Zigbee functions **************************/ -static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) -{ - ESP_ERROR_CHECK(esp_zb_bdb_start_top_level_commissioning(mode_mask)); +static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) { + ESP_ERROR_CHECK(esp_zb_bdb_start_top_level_commissioning(mode_mask)); } -void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) -{ - uint32_t *p_sg_p = signal_struct->p_app_signal; - esp_err_t err_status = signal_struct->esp_err_status; - esp_zb_app_signal_type_t sig_type = (esp_zb_app_signal_type_t)*p_sg_p; - switch (sig_type) { +void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { + uint32_t *p_sg_p = signal_struct->p_app_signal; + esp_err_t err_status = signal_struct->esp_err_status; + esp_zb_app_signal_type_t sig_type = (esp_zb_app_signal_type_t)*p_sg_p; + switch (sig_type) { case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP: - log_i("Zigbee stack initialized"); - esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION); - break; + log_i("Zigbee stack initialized"); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION); + break; case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: - if (err_status == ESP_OK) { - log_i("Start network steering"); - esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); - } else { - /* commissioning failed */ - log_w("Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); - } - break; + if (err_status == ESP_OK) { + log_i("Start network steering"); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); + } else { + /* commissioning failed */ + log_w("Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + } + break; case ESP_ZB_BDB_SIGNAL_STEERING: - if (err_status == ESP_OK) { - esp_zb_ieee_addr_t extended_pan_id; - esp_zb_get_extended_pan_id(extended_pan_id); - log_i("Joined network successfully (Extended PAN ID: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx, Channel:%d, Short Address: 0x%04hx)", - extended_pan_id[7], extended_pan_id[6], extended_pan_id[5], extended_pan_id[4], - extended_pan_id[3], extended_pan_id[2], extended_pan_id[1], extended_pan_id[0], - esp_zb_get_pan_id(), esp_zb_get_current_channel(), esp_zb_get_short_address()); - } else { - log_i("Network steering was not successful (status: %s)", esp_err_to_name(err_status)); - esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_NETWORK_STEERING, 1000); - } - break; + if (err_status == ESP_OK) { + esp_zb_ieee_addr_t extended_pan_id; + esp_zb_get_extended_pan_id(extended_pan_id); + log_i("Joined network successfully (Extended PAN ID: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx, Channel:%d, Short Address: 0x%04hx)", + extended_pan_id[7], extended_pan_id[6], extended_pan_id[5], extended_pan_id[4], + extended_pan_id[3], extended_pan_id[2], extended_pan_id[1], extended_pan_id[0], + esp_zb_get_pan_id(), esp_zb_get_current_channel(), esp_zb_get_short_address()); + } else { + log_i("Network steering was not successful (status: %s)", esp_err_to_name(err_status)); + esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_NETWORK_STEERING, 1000); + } + break; default: - log_i("ZDO signal: %s (0x%x), status: %s", esp_zb_zdo_signal_to_string(sig_type), sig_type, - esp_err_to_name(err_status)); - break; - } + log_i("ZDO signal: %s (0x%x), status: %s", esp_zb_zdo_signal_to_string(sig_type), sig_type, + esp_err_to_name(err_status)); + break; + } } -static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id, const void *message) -{ - esp_err_t ret = ESP_OK; - switch (callback_id) { +static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id, const void *message) { + esp_err_t ret = ESP_OK; + switch (callback_id) { case ESP_ZB_CORE_SET_ATTR_VALUE_CB_ID: - ret = zb_attribute_handler((esp_zb_zcl_set_attr_value_message_t *)message); - break; + ret = zb_attribute_handler((esp_zb_zcl_set_attr_value_message_t *)message); + break; default: - log_w("Receive Zigbee action(0x%x) callback", callback_id); - break; - } - return ret; + log_w("Receive Zigbee action(0x%x) callback", callback_id); + break; + } + return ret; } -static void esp_zb_task(void *pvParameters) -{ - esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZED_CONFIG(); - esp_zb_init(&zb_nwk_cfg); - esp_zb_on_off_light_cfg_t light_cfg = ESP_ZB_DEFAULT_ON_OFF_LIGHT_CONFIG(); - esp_zb_ep_list_t *esp_zb_on_off_light_ep = esp_zb_on_off_light_ep_create(HA_ESP_LIGHT_ENDPOINT, &light_cfg); - esp_zb_device_register(esp_zb_on_off_light_ep); - esp_zb_core_action_handler_register(zb_action_handler); - esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK); - - //Erase NVRAM before creating connection to new Coordinator - //esp_zb_nvram_erase_at_start(true); //Comment out this line to erase NVRAM data if you are conneting to new Coordinator - - ESP_ERROR_CHECK(esp_zb_start(false)); - esp_zb_main_loop_iteration(); -} +static void esp_zb_task(void *pvParameters) { + esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZED_CONFIG(); + esp_zb_init(&zb_nwk_cfg); + esp_zb_on_off_light_cfg_t light_cfg = ESP_ZB_DEFAULT_ON_OFF_LIGHT_CONFIG(); + esp_zb_ep_list_t *esp_zb_on_off_light_ep = esp_zb_on_off_light_ep_create(HA_ESP_LIGHT_ENDPOINT, &light_cfg); + esp_zb_device_register(esp_zb_on_off_light_ep); + esp_zb_core_action_handler_register(zb_action_handler); + esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK); -/* Handle the light attribute */ + //Erase NVRAM before creating connection to new Coordinator + //esp_zb_nvram_erase_at_start(true); //Comment out this line to erase NVRAM data if you are conneting to new Coordinator -static esp_err_t zb_attribute_handler(const esp_zb_zcl_set_attr_value_message_t *message) -{ - esp_err_t ret = ESP_OK; - bool light_state = 0; + ESP_ERROR_CHECK(esp_zb_start(false)); + esp_zb_main_loop_iteration(); +} - if(!message){ - log_e("Empty message"); - } - if(message->info.status != ESP_ZB_ZCL_STATUS_SUCCESS){ - log_e("Received message: error status(%d)", message->info.status); - } +/* Handle the light attribute */ - log_i("Received message: endpoint(%d), cluster(0x%x), attribute(0x%x), data size(%d)", message->info.dst_endpoint, message->info.cluster, - message->attribute.id, message->attribute.data.size); - if (message->info.dst_endpoint == HA_ESP_LIGHT_ENDPOINT) { - if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_ON_OFF) { - if (message->attribute.id == ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID && message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_BOOL) { - light_state = message->attribute.data.value ? *(bool *)message->attribute.data.value : light_state; - log_i("Light sets to %s", light_state ? "On" : "Off"); - neopixelWrite(LED_PIN,255*light_state,255*light_state,255*light_state); // Toggle light - } - } +static esp_err_t zb_attribute_handler(const esp_zb_zcl_set_attr_value_message_t *message) { + esp_err_t ret = ESP_OK; + bool light_state = 0; + + if (!message) { + log_e("Empty message"); + } + if (message->info.status != ESP_ZB_ZCL_STATUS_SUCCESS) { + log_e("Received message: error status(%d)", message->info.status); + } + + log_i("Received message: endpoint(%d), cluster(0x%x), attribute(0x%x), data size(%d)", message->info.dst_endpoint, message->info.cluster, + message->attribute.id, message->attribute.data.size); + if (message->info.dst_endpoint == HA_ESP_LIGHT_ENDPOINT) { + if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_ON_OFF) { + if (message->attribute.id == ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID && message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_BOOL) { + light_state = message->attribute.data.value ? *(bool *)message->attribute.data.value : light_state; + log_i("Light sets to %s", light_state ? "On" : "Off"); + neopixelWrite(LED_PIN, 255 * light_state, 255 * light_state, 255 * light_state); // Toggle light + } } - return ret; + } + return ret; } /********************* Arduino functions **************************/ void setup() { - // Init Zigbee - esp_zb_platform_config_t config = { - .radio_config = ESP_ZB_DEFAULT_RADIO_CONFIG(), - .host_config = ESP_ZB_DEFAULT_HOST_CONFIG(), - }; - ESP_ERROR_CHECK(esp_zb_platform_config(&config)); - - // Init RMT and leave light OFF - neopixelWrite(LED_PIN,0,0,0); - - // Start Zigbee task - xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL); + // Init Zigbee + esp_zb_platform_config_t config = { + .radio_config = ESP_ZB_DEFAULT_RADIO_CONFIG(), + .host_config = ESP_ZB_DEFAULT_HOST_CONFIG(), + }; + ESP_ERROR_CHECK(esp_zb_platform_config(&config)); + + // Init RMT and leave light OFF + neopixelWrite(LED_PIN, 0, 0, 0); + + // Start Zigbee task + xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL); } void loop() { - //empty, zigbee running in task + //empty, zigbee running in task } diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/README.md b/libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/README.md index 98f509150a1..d296c41e093 100644 --- a/libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/README.md +++ b/libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/README.md @@ -33,7 +33,7 @@ To get more information about the Espressif boards see [Espressif Development Ki ## Troubleshooting -If the End device flashed with the example `Zigbee_Light_Bulb` is not connecting to the coordinator, erase the flash of the End device before flashing the example to the board. It is recommended to do this if you re-flash the coordinator. +If the End device flashed with the example `Zigbee_Light_Bulb` is not connecting to the coordinator, erase the flash of the End device before flashing the example to the board. It is recommended to do this if you re-flash the coordinator. You can do the following: * In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`. diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/Zigbee_Light_Switch.ino b/libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/Zigbee_Light_Switch.ino index d0f2d5c2ee8..eb1fd68f1f9 100644 --- a/libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/Zigbee_Light_Switch.ino +++ b/libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/Zigbee_Light_Switch.ino @@ -14,14 +14,14 @@ /** * @brief This example demonstrates simple Zigbee light switch. - * + * * The example demonstrates how to use ESP Zigbee stack to control a light bulb. * The light bulb is a Zigbee end device, which is controlled by a Zigbee coordinator. * Button switch and Zigbee runs in separate tasks. - * - * Proper Zigbee mode must be selected in Tools->Zigbee mode + * + * Proper Zigbee mode must be selected in Tools->Zigbee mode * and also the correct partition scheme must be selected in Tools->Partition Scheme. - * + * * Please check the README.md for instructions and more detailed description. */ @@ -35,268 +35,261 @@ #include "ha/esp_zigbee_ha_standard.h" /* Switch configuration */ -#define GPIO_INPUT_IO_TOGGLE_SWITCH GPIO_NUM_9 +#define GPIO_INPUT_IO_TOGGLE_SWITCH GPIO_NUM_9 #define PAIR_SIZE(TYPE_STR_PAIR) (sizeof(TYPE_STR_PAIR) / sizeof(TYPE_STR_PAIR[0])) typedef enum { - SWITCH_ON_CONTROL, - SWITCH_OFF_CONTROL, - SWITCH_ONOFF_TOGGLE_CONTROL, - SWITCH_LEVEL_UP_CONTROL, - SWITCH_LEVEL_DOWN_CONTROL, - SWITCH_LEVEL_CYCLE_CONTROL, - SWITCH_COLOR_CONTROL, + SWITCH_ON_CONTROL, + SWITCH_OFF_CONTROL, + SWITCH_ONOFF_TOGGLE_CONTROL, + SWITCH_LEVEL_UP_CONTROL, + SWITCH_LEVEL_DOWN_CONTROL, + SWITCH_LEVEL_CYCLE_CONTROL, + SWITCH_COLOR_CONTROL, } switch_func_t; typedef struct { - uint8_t pin; - switch_func_t func; + uint8_t pin; + switch_func_t func; } switch_func_pair_t; typedef enum { - SWITCH_IDLE, - SWITCH_PRESS_ARMED, - SWITCH_PRESS_DETECTED, - SWITCH_PRESSED, - SWITCH_RELEASE_DETECTED, + SWITCH_IDLE, + SWITCH_PRESS_ARMED, + SWITCH_PRESS_DETECTED, + SWITCH_PRESSED, + SWITCH_RELEASE_DETECTED, } switch_state_t; static switch_func_pair_t button_func_pair[] = { - {GPIO_INPUT_IO_TOGGLE_SWITCH, SWITCH_ONOFF_TOGGLE_CONTROL} + { GPIO_INPUT_IO_TOGGLE_SWITCH, SWITCH_ONOFF_TOGGLE_CONTROL } }; /* Default Coordinator config */ -#define ESP_ZB_ZC_CONFIG() \ - { \ - .esp_zb_role = ESP_ZB_DEVICE_TYPE_COORDINATOR, \ - .install_code_policy = INSTALLCODE_POLICY_ENABLE, \ - .nwk_cfg = { \ - .zczr_cfg = { \ - .max_children = MAX_CHILDREN, \ - }, \ - } \ - } +#define ESP_ZB_ZC_CONFIG() \ + { \ + .esp_zb_role = ESP_ZB_DEVICE_TYPE_COORDINATOR, \ + .install_code_policy = INSTALLCODE_POLICY_ENABLE, \ + .nwk_cfg = { \ + .zczr_cfg = { \ + .max_children = MAX_CHILDREN, \ + }, \ + } \ + } -#define ESP_ZB_DEFAULT_RADIO_CONFIG() \ - { \ - .radio_mode = RADIO_MODE_NATIVE, \ - } +#define ESP_ZB_DEFAULT_RADIO_CONFIG() \ + { \ + .radio_mode = RADIO_MODE_NATIVE, \ + } -#define ESP_ZB_DEFAULT_HOST_CONFIG() \ - { \ - .host_connection_mode = HOST_CONNECTION_MODE_NONE, \ - } +#define ESP_ZB_DEFAULT_HOST_CONFIG() \ + { \ + .host_connection_mode = HOST_CONNECTION_MODE_NONE, \ + } typedef struct light_bulb_device_params_s { - esp_zb_ieee_addr_t ieee_addr; - uint8_t endpoint; - uint16_t short_addr; + esp_zb_ieee_addr_t ieee_addr; + uint8_t endpoint; + uint16_t short_addr; } light_bulb_device_params_t; /* Zigbee configuration */ -#define MAX_CHILDREN 10 /* the max amount of connected devices */ -#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */ -#define HA_ONOFF_SWITCH_ENDPOINT 1 /* esp light switch device endpoint */ -#define ESP_ZB_PRIMARY_CHANNEL_MASK ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK /* Zigbee primary channel mask use in the example */ +#define MAX_CHILDREN 10 /* the max amount of connected devices */ +#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */ +#define HA_ONOFF_SWITCH_ENDPOINT 1 /* esp light switch device endpoint */ +#define ESP_ZB_PRIMARY_CHANNEL_MASK ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK /* Zigbee primary channel mask use in the example */ /********************* Define functions **************************/ -static void esp_zb_buttons_handler(switch_func_pair_t *button_func_pair) -{ - if (button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL) { - /* implemented light switch toggle functionality */ - esp_zb_zcl_on_off_cmd_t cmd_req; - cmd_req.zcl_basic_cmd.src_endpoint = HA_ONOFF_SWITCH_ENDPOINT; - cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; - cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_TOGGLE_ID; - log_i("Send 'on_off toggle' command"); - esp_zb_zcl_on_off_cmd_req(&cmd_req); - } +static void esp_zb_buttons_handler(switch_func_pair_t *button_func_pair) { + if (button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL) { + /* implemented light switch toggle functionality */ + esp_zb_zcl_on_off_cmd_t cmd_req; + cmd_req.zcl_basic_cmd.src_endpoint = HA_ONOFF_SWITCH_ENDPOINT; + cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; + cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_TOGGLE_ID; + log_i("Send 'on_off toggle' command"); + esp_zb_zcl_on_off_cmd_req(&cmd_req); + } } -static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) -{ - ESP_ERROR_CHECK(esp_zb_bdb_start_top_level_commissioning(mode_mask)); +static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) { + ESP_ERROR_CHECK(esp_zb_bdb_start_top_level_commissioning(mode_mask)); } -static void bind_cb(esp_zb_zdp_status_t zdo_status, void *user_ctx) -{ - if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) { - log_i("Bound successfully!"); - if (user_ctx) { - light_bulb_device_params_t *light = (light_bulb_device_params_t *)user_ctx; - log_i("The light originating from address(0x%x) on endpoint(%d)", light->short_addr, light->endpoint); - free(light); - } +static void bind_cb(esp_zb_zdp_status_t zdo_status, void *user_ctx) { + if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) { + log_i("Bound successfully!"); + if (user_ctx) { + light_bulb_device_params_t *light = (light_bulb_device_params_t *)user_ctx; + log_i("The light originating from address(0x%x) on endpoint(%d)", light->short_addr, light->endpoint); + free(light); } + } } -static void user_find_cb(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx) -{ - if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) { - log_i("Found light"); - esp_zb_zdo_bind_req_param_t bind_req; - light_bulb_device_params_t *light = (light_bulb_device_params_t *)malloc(sizeof(light_bulb_device_params_t)); - light->endpoint = endpoint; - light->short_addr = addr; - esp_zb_ieee_address_by_short(light->short_addr, light->ieee_addr); - esp_zb_get_long_address(bind_req.src_address); - bind_req.src_endp = HA_ONOFF_SWITCH_ENDPOINT; - bind_req.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_ON_OFF; - bind_req.dst_addr_mode = ESP_ZB_ZDO_BIND_DST_ADDR_MODE_64_BIT_EXTENDED; - memcpy(bind_req.dst_address_u.addr_long, light->ieee_addr, sizeof(esp_zb_ieee_addr_t)); - bind_req.dst_endp = endpoint; - bind_req.req_dst_addr = esp_zb_get_short_address(); - log_i("Try to bind On/Off"); - esp_zb_zdo_device_bind_req(&bind_req, bind_cb, (void *)light); - } +static void user_find_cb(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx) { + if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) { + log_i("Found light"); + esp_zb_zdo_bind_req_param_t bind_req; + light_bulb_device_params_t *light = (light_bulb_device_params_t *)malloc(sizeof(light_bulb_device_params_t)); + light->endpoint = endpoint; + light->short_addr = addr; + esp_zb_ieee_address_by_short(light->short_addr, light->ieee_addr); + esp_zb_get_long_address(bind_req.src_address); + bind_req.src_endp = HA_ONOFF_SWITCH_ENDPOINT; + bind_req.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_ON_OFF; + bind_req.dst_addr_mode = ESP_ZB_ZDO_BIND_DST_ADDR_MODE_64_BIT_EXTENDED; + memcpy(bind_req.dst_address_u.addr_long, light->ieee_addr, sizeof(esp_zb_ieee_addr_t)); + bind_req.dst_endp = endpoint; + bind_req.req_dst_addr = esp_zb_get_short_address(); + log_i("Try to bind On/Off"); + esp_zb_zdo_device_bind_req(&bind_req, bind_cb, (void *)light); + } } -void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) -{ - uint32_t *p_sg_p = signal_struct->p_app_signal; - esp_err_t err_status = signal_struct->esp_err_status; - esp_zb_app_signal_type_t sig_type = (esp_zb_app_signal_type_t)*p_sg_p; - esp_zb_zdo_signal_device_annce_params_t *dev_annce_params = NULL; - switch (sig_type) { +void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { + uint32_t *p_sg_p = signal_struct->p_app_signal; + esp_err_t err_status = signal_struct->esp_err_status; + esp_zb_app_signal_type_t sig_type = (esp_zb_app_signal_type_t)*p_sg_p; + esp_zb_zdo_signal_device_annce_params_t *dev_annce_params = NULL; + switch (sig_type) { case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP: - log_i("Zigbee stack initialized"); - esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION); - break; + log_i("Zigbee stack initialized"); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION); + break; case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: - if (err_status == ESP_OK) { - log_i("Start network formation"); - esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); - } else { - log_e("Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); - } - break; + if (err_status == ESP_OK) { + log_i("Start network formation"); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); + } else { + log_e("Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + } + break; case ESP_ZB_BDB_SIGNAL_FORMATION: - if (err_status == ESP_OK) { - esp_zb_ieee_addr_t extended_pan_id; - esp_zb_get_extended_pan_id(extended_pan_id); - log_i("Formed network successfully (Extended PAN ID: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx, Channel:%d, Short Address: 0x%04hx)", - extended_pan_id[7], extended_pan_id[6], extended_pan_id[5], extended_pan_id[4], - extended_pan_id[3], extended_pan_id[2], extended_pan_id[1], extended_pan_id[0], - esp_zb_get_pan_id(), esp_zb_get_current_channel(), esp_zb_get_short_address()); - esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); - } else { - log_i("Restart network formation (status: %s)", esp_err_to_name(err_status)); - esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_NETWORK_FORMATION, 1000); - } - break; + if (err_status == ESP_OK) { + esp_zb_ieee_addr_t extended_pan_id; + esp_zb_get_extended_pan_id(extended_pan_id); + log_i("Formed network successfully (Extended PAN ID: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx, Channel:%d, Short Address: 0x%04hx)", + extended_pan_id[7], extended_pan_id[6], extended_pan_id[5], extended_pan_id[4], + extended_pan_id[3], extended_pan_id[2], extended_pan_id[1], extended_pan_id[0], + esp_zb_get_pan_id(), esp_zb_get_current_channel(), esp_zb_get_short_address()); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); + } else { + log_i("Restart network formation (status: %s)", esp_err_to_name(err_status)); + esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_NETWORK_FORMATION, 1000); + } + break; case ESP_ZB_BDB_SIGNAL_STEERING: - if (err_status == ESP_OK) { - log_i("Network steering started"); - } - break; + if (err_status == ESP_OK) { + log_i("Network steering started"); + } + break; case ESP_ZB_ZDO_SIGNAL_DEVICE_ANNCE: - dev_annce_params = (esp_zb_zdo_signal_device_annce_params_t *)esp_zb_app_signal_get_params(p_sg_p); - log_i("New device commissioned or rejoined (short: 0x%04hx)", dev_annce_params->device_short_addr); - esp_zb_zdo_match_desc_req_param_t cmd_req; - cmd_req.dst_nwk_addr = dev_annce_params->device_short_addr; - cmd_req.addr_of_interest = dev_annce_params->device_short_addr; - esp_zb_zdo_find_on_off_light(&cmd_req, user_find_cb, NULL); - break; + dev_annce_params = (esp_zb_zdo_signal_device_annce_params_t *)esp_zb_app_signal_get_params(p_sg_p); + log_i("New device commissioned or rejoined (short: 0x%04hx)", dev_annce_params->device_short_addr); + esp_zb_zdo_match_desc_req_param_t cmd_req; + cmd_req.dst_nwk_addr = dev_annce_params->device_short_addr; + cmd_req.addr_of_interest = dev_annce_params->device_short_addr; + esp_zb_zdo_find_on_off_light(&cmd_req, user_find_cb, NULL); + break; default: - log_i("ZDO signal: %s (0x%x), status: %s", esp_zb_zdo_signal_to_string(sig_type), sig_type, - esp_err_to_name(err_status)); - break; - } + log_i("ZDO signal: %s (0x%x), status: %s", esp_zb_zdo_signal_to_string(sig_type), sig_type, + esp_err_to_name(err_status)); + break; + } } -static void esp_zb_task(void *pvParameters) -{ - esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZC_CONFIG(); - esp_zb_init(&zb_nwk_cfg); - esp_zb_on_off_switch_cfg_t switch_cfg = ESP_ZB_DEFAULT_ON_OFF_SWITCH_CONFIG(); - esp_zb_ep_list_t *esp_zb_on_off_switch_ep = esp_zb_on_off_switch_ep_create(HA_ONOFF_SWITCH_ENDPOINT, &switch_cfg); - esp_zb_device_register(esp_zb_on_off_switch_ep); - esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK); - ESP_ERROR_CHECK(esp_zb_start(false)); - esp_zb_main_loop_iteration(); +static void esp_zb_task(void *pvParameters) { + esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZC_CONFIG(); + esp_zb_init(&zb_nwk_cfg); + esp_zb_on_off_switch_cfg_t switch_cfg = ESP_ZB_DEFAULT_ON_OFF_SWITCH_CONFIG(); + esp_zb_ep_list_t *esp_zb_on_off_switch_ep = esp_zb_on_off_switch_ep_create(HA_ONOFF_SWITCH_ENDPOINT, &switch_cfg); + esp_zb_device_register(esp_zb_on_off_switch_ep); + esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK); + ESP_ERROR_CHECK(esp_zb_start(false)); + esp_zb_main_loop_iteration(); } /********************* GPIO functions **************************/ static QueueHandle_t gpio_evt_queue = NULL; -static void IRAM_ATTR gpio_isr_handler(void *arg) -{ - xQueueSendFromISR(gpio_evt_queue, (switch_func_pair_t *)arg, NULL); +static void IRAM_ATTR gpio_isr_handler(void *arg) { + xQueueSendFromISR(gpio_evt_queue, (switch_func_pair_t *)arg, NULL); } -static void switch_gpios_intr_enabled(bool enabled) -{ - for (int i = 0; i < PAIR_SIZE(button_func_pair); ++i) { - if (enabled) { - enableInterrupt((button_func_pair[i]).pin); - } else { - disableInterrupt((button_func_pair[i]).pin); - } +static void switch_gpios_intr_enabled(bool enabled) { + for (int i = 0; i < PAIR_SIZE(button_func_pair); ++i) { + if (enabled) { + enableInterrupt((button_func_pair[i]).pin); + } else { + disableInterrupt((button_func_pair[i]).pin); } + } } /********************* Arduino functions **************************/ void setup() { - // Init Zigbee - esp_zb_platform_config_t config = { - .radio_config = ESP_ZB_DEFAULT_RADIO_CONFIG(), - .host_config = ESP_ZB_DEFAULT_HOST_CONFIG(), - }; + // Init Zigbee + esp_zb_platform_config_t config = { + .radio_config = ESP_ZB_DEFAULT_RADIO_CONFIG(), + .host_config = ESP_ZB_DEFAULT_HOST_CONFIG(), + }; - ESP_ERROR_CHECK(esp_zb_platform_config(&config)); + ESP_ERROR_CHECK(esp_zb_platform_config(&config)); - // Init button switch - for (int i = 0; i < PAIR_SIZE(button_func_pair); i++) { - pinMode(button_func_pair[i].pin, INPUT_PULLUP); - /* create a queue to handle gpio event from isr */ - gpio_evt_queue = xQueueCreate(10, sizeof(switch_func_pair_t)); - if ( gpio_evt_queue == 0) { - log_e("Queue was not created and must not be used"); - while(1); - } - attachInterruptArg(button_func_pair[i].pin, gpio_isr_handler, (void *) (button_func_pair + i), FALLING); + // Init button switch + for (int i = 0; i < PAIR_SIZE(button_func_pair); i++) { + pinMode(button_func_pair[i].pin, INPUT_PULLUP); + /* create a queue to handle gpio event from isr */ + gpio_evt_queue = xQueueCreate(10, sizeof(switch_func_pair_t)); + if (gpio_evt_queue == 0) { + log_e("Queue was not created and must not be used"); + while (1) + ; } + attachInterruptArg(button_func_pair[i].pin, gpio_isr_handler, (void *)(button_func_pair + i), FALLING); + } - // Start Zigbee task - xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL); + // Start Zigbee task + xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL); } void loop() { - // Handle button switch in loop() - uint8_t pin = 0; - switch_func_pair_t button_func_pair; - static switch_state_t switch_state = SWITCH_IDLE; - bool evt_flag = false; + // Handle button switch in loop() + uint8_t pin = 0; + switch_func_pair_t button_func_pair; + static switch_state_t switch_state = SWITCH_IDLE; + bool evt_flag = false; - /* check if there is any queue received, if yes read out the button_func_pair */ - if (xQueueReceive(gpio_evt_queue, &button_func_pair, portMAX_DELAY)) { - pin = button_func_pair.pin; - switch_gpios_intr_enabled(false); - evt_flag = true; + /* check if there is any queue received, if yes read out the button_func_pair */ + if (xQueueReceive(gpio_evt_queue, &button_func_pair, portMAX_DELAY)) { + pin = button_func_pair.pin; + switch_gpios_intr_enabled(false); + evt_flag = true; + } + while (evt_flag) { + bool value = digitalRead(pin); + switch (switch_state) { + case SWITCH_IDLE: + switch_state = (value == LOW) ? SWITCH_PRESS_DETECTED : SWITCH_IDLE; + break; + case SWITCH_PRESS_DETECTED: + switch_state = (value == LOW) ? SWITCH_PRESS_DETECTED : SWITCH_RELEASE_DETECTED; + break; + case SWITCH_RELEASE_DETECTED: + switch_state = SWITCH_IDLE; + /* callback to button_handler */ + (*esp_zb_buttons_handler)(&button_func_pair); + break; + default: + break; } - while (evt_flag) { - bool value = digitalRead(pin); - switch (switch_state) { - case SWITCH_IDLE: - switch_state = (value == LOW) ? SWITCH_PRESS_DETECTED : SWITCH_IDLE; - break; - case SWITCH_PRESS_DETECTED: - switch_state = (value == LOW) ? SWITCH_PRESS_DETECTED : SWITCH_RELEASE_DETECTED; - break; - case SWITCH_RELEASE_DETECTED: - switch_state = SWITCH_IDLE; - /* callback to button_handler */ - (*esp_zb_buttons_handler)(&button_func_pair); - break; - default: - break; - } - if (switch_state == SWITCH_IDLE) { - switch_gpios_intr_enabled(true); - evt_flag = false; - break; - } - vTaskDelay(10 / portTICK_PERIOD_MS); + if (switch_state == SWITCH_IDLE) { + switch_gpios_intr_enabled(true); + evt_flag = false; + break; } + vTaskDelay(10 / portTICK_PERIOD_MS); + } } diff --git a/libraries/ESP32/keywords.txt b/libraries/ESP32/keywords.txt index 631ad8f81c8..6cfd3fcab4c 100644 --- a/libraries/ESP32/keywords.txt +++ b/libraries/ESP32/keywords.txt @@ -14,4 +14,4 @@ # Constants (LITERAL1) ####################################### -RGB_BUILTIN LITERAL1 \ No newline at end of file +RGB_BUILTIN LITERAL1 diff --git a/libraries/ESP_I2S/examples/ES8388_loopback/ES8388.cpp b/libraries/ESP_I2S/examples/ES8388_loopback/ES8388.cpp index b072ddd84af..40ec39015a1 100644 --- a/libraries/ESP_I2S/examples/ES8388_loopback/ES8388.cpp +++ b/libraries/ESP_I2S/examples/ES8388_loopback/ES8388.cpp @@ -33,8 +33,7 @@ Unmute and start the ES8388 codec data transmission. */ -void ES8388::start() -{ +void ES8388::start() { uint8_t prev_regval = 0; uint8_t regval = 0; @@ -42,88 +41,41 @@ void ES8388::start() _running = true; prev_regval = readReg(ES8388_DACCONTROL21); - if (_audio_mode == ES_MODULE_LINE) - { + if (_audio_mode == ES_MODULE_LINE) { writeReg(ES8388_DACCONTROL16, - ES8388_RMIXSEL_RIN2 | - ES8388_LMIXSEL_LIN2); + ES8388_RMIXSEL_RIN2 | ES8388_LMIXSEL_LIN2); writeReg(ES8388_DACCONTROL17, - ES8388_LI2LOVOL(ES8388_MIXER_GAIN_0DB) | - ES8388_LI2LO_ENABLE | - ES8388_LD2LO_DISABLE); + ES8388_LI2LOVOL(ES8388_MIXER_GAIN_0DB) | ES8388_LI2LO_ENABLE | ES8388_LD2LO_DISABLE); writeReg(ES8388_DACCONTROL20, - ES8388_RI2ROVOL(ES8388_MIXER_GAIN_0DB) | - ES8388_RI2RO_ENABLE | - ES8388_RD2RO_DISABLE); + ES8388_RI2ROVOL(ES8388_MIXER_GAIN_0DB) | ES8388_RI2RO_ENABLE | ES8388_RD2RO_DISABLE); writeReg(ES8388_DACCONTROL21, - ES8388_DAC_DLL_PWD_NORMAL | - ES8388_ADC_DLL_PWD_NORMAL | - ES8388_MCLK_DIS_NORMAL | - ES8388_OFFSET_DIS_DISABLE | - ES8388_LRCK_SEL_ADC | - ES8388_SLRCK_SAME); - } - else - { + ES8388_DAC_DLL_PWD_NORMAL | ES8388_ADC_DLL_PWD_NORMAL | ES8388_MCLK_DIS_NORMAL | ES8388_OFFSET_DIS_DISABLE | ES8388_LRCK_SEL_ADC | ES8388_SLRCK_SAME); + } else { writeReg(ES8388_DACCONTROL21, - ES8388_DAC_DLL_PWD_NORMAL | - ES8388_ADC_DLL_PWD_NORMAL | - ES8388_MCLK_DIS_NORMAL | - ES8388_OFFSET_DIS_DISABLE | - ES8388_LRCK_SEL_DAC | - ES8388_SLRCK_SAME); + ES8388_DAC_DLL_PWD_NORMAL | ES8388_ADC_DLL_PWD_NORMAL | ES8388_MCLK_DIS_NORMAL | ES8388_OFFSET_DIS_DISABLE | ES8388_LRCK_SEL_DAC | ES8388_SLRCK_SAME); } regval = readReg(ES8388_DACCONTROL21); - if (regval != prev_regval) - { + if (regval != prev_regval) { writeReg(ES8388_CHIPPOWER, - ES8388_DACVREF_PDN_PWRUP | - ES8388_ADCVREF_PDN_PWRUP | - ES8388_DACDLL_PDN_NORMAL | - ES8388_ADCDLL_PDN_NORMAL | - ES8388_DAC_STM_RST_RESET | - ES8388_ADC_STM_RST_RESET | - ES8388_DAC_DIGPDN_RESET | - ES8388_ADC_DIGPDN_RESET); + ES8388_DACVREF_PDN_PWRUP | ES8388_ADCVREF_PDN_PWRUP | ES8388_DACDLL_PDN_NORMAL | ES8388_ADCDLL_PDN_NORMAL | ES8388_DAC_STM_RST_RESET | ES8388_ADC_STM_RST_RESET | ES8388_DAC_DIGPDN_RESET | ES8388_ADC_DIGPDN_RESET); writeReg(ES8388_CHIPPOWER, - ES8388_DACVREF_PDN_PWRUP | - ES8388_ADCVREF_PDN_PWRUP | - ES8388_DACDLL_PDN_NORMAL | - ES8388_ADCDLL_PDN_NORMAL | - ES8388_DAC_STM_RST_NORMAL | - ES8388_ADC_STM_RST_NORMAL | - ES8388_DAC_DIGPDN_NORMAL | - ES8388_ADC_DIGPDN_NORMAL); - } - - if (_audio_mode == ES_MODULE_LINE || _audio_mode == ES_MODULE_ADC_DAC || _audio_mode == ES_MODULE_ADC) - { + ES8388_DACVREF_PDN_PWRUP | ES8388_ADCVREF_PDN_PWRUP | ES8388_DACDLL_PDN_NORMAL | ES8388_ADCDLL_PDN_NORMAL | ES8388_DAC_STM_RST_NORMAL | ES8388_ADC_STM_RST_NORMAL | ES8388_DAC_DIGPDN_NORMAL | ES8388_ADC_DIGPDN_NORMAL); + } + + if (_audio_mode == ES_MODULE_LINE || _audio_mode == ES_MODULE_ADC_DAC || _audio_mode == ES_MODULE_ADC) { writeReg(ES8388_ADCPOWER, - ES8388_INT1LP_NORMAL | - ES8388_FLASHLP_NORMAL | - ES8388_PDNADCBIASGEN_NORMAL | - ES8388_PDNMICB_PWRON | - ES8388_PDNADCR_PWRUP | - ES8388_PDNADCL_PWRUP | - ES8388_PDNAINR_NORMAL | - ES8388_PDNAINL_NORMAL); - } - - if (_audio_mode == ES_MODULE_LINE || _audio_mode == ES_MODULE_ADC_DAC || _audio_mode == ES_MODULE_DAC) - { + ES8388_INT1LP_NORMAL | ES8388_FLASHLP_NORMAL | ES8388_PDNADCBIASGEN_NORMAL | ES8388_PDNMICB_PWRON | ES8388_PDNADCR_PWRUP | ES8388_PDNADCL_PWRUP | ES8388_PDNAINR_NORMAL | ES8388_PDNAINL_NORMAL); + } + + if (_audio_mode == ES_MODULE_LINE || _audio_mode == ES_MODULE_ADC_DAC || _audio_mode == ES_MODULE_DAC) { writeReg(ES8388_DACPOWER, - ES8388_ROUT2_ENABLE | - ES8388_LOUT2_ENABLE | - ES8388_ROUT1_ENABLE | - ES8388_LOUT1_ENABLE | - ES8388_PDNDACR_PWRUP | - ES8388_PDNDACL_PWRUP); + ES8388_ROUT2_ENABLE | ES8388_LOUT2_ENABLE | ES8388_ROUT1_ENABLE | ES8388_LOUT1_ENABLE | ES8388_PDNDACR_PWRUP | ES8388_PDNDACL_PWRUP); } setmute(_audio_mode, false); @@ -137,8 +89,7 @@ void ES8388::start() Reset the ES8388 codec to a known state depending on the audio mode. */ -void ES8388::reset() -{ +void ES8388::reset() { uint8_t regconfig; log_v("Resetting ES8388..."); @@ -146,29 +97,13 @@ void ES8388::reset() _bpsamp, _samprate, _nchannels, _audio_mode, _dac_output, _adc_input, _mic_gain); writeReg(ES8388_DACCONTROL3, - ES8388_DACMUTE_MUTED | - ES8388_DACLER_NORMAL | - ES8388_DACSOFTRAMP_DISABLE | - ES8388_DACRAMPRATE_4LRCK); + ES8388_DACMUTE_MUTED | ES8388_DACLER_NORMAL | ES8388_DACSOFTRAMP_DISABLE | ES8388_DACRAMPRATE_4LRCK); writeReg(ES8388_CONTROL2, - ES8388_PDNVREFBUF_NORMAL | - ES8388_VREFLO_NORMAL | - ES8388_PDNIBIASGEN_NORMAL | - ES8388_PDNANA_NORMAL | - ES8388_LPVREFBUF_LP | - ES8388_LPVCMMOD_NORMAL | - (1 << 6)); /* Default value of undocumented bit */ + ES8388_PDNVREFBUF_NORMAL | ES8388_VREFLO_NORMAL | ES8388_PDNIBIASGEN_NORMAL | ES8388_PDNANA_NORMAL | ES8388_LPVREFBUF_LP | ES8388_LPVCMMOD_NORMAL | (1 << 6)); /* Default value of undocumented bit */ writeReg(ES8388_CHIPPOWER, - ES8388_DACVREF_PDN_PWRUP | - ES8388_ADCVREF_PDN_PWRUP | - ES8388_DACDLL_PDN_NORMAL | - ES8388_ADCDLL_PDN_NORMAL | - ES8388_DAC_STM_RST_NORMAL | - ES8388_ADC_STM_RST_NORMAL | - ES8388_DAC_DIGPDN_NORMAL | - ES8388_ADC_DIGPDN_NORMAL); + ES8388_DACVREF_PDN_PWRUP | ES8388_ADCVREF_PDN_PWRUP | ES8388_DACDLL_PDN_NORMAL | ES8388_ADCDLL_PDN_NORMAL | ES8388_DAC_STM_RST_NORMAL | ES8388_ADC_STM_RST_NORMAL | ES8388_DAC_DIGPDN_NORMAL | ES8388_ADC_DIGPDN_NORMAL); /* Disable the internal DLL to improve 8K sample rate */ @@ -177,27 +112,13 @@ void ES8388::reset() writeReg(0x39, 0xd0); writeReg(ES8388_MASTERMODE, - ES8388_BCLKDIV(ES_MCLK_DIV_AUTO) | - ES8388_BCLK_INV_NORMAL | - ES8388_MCLKDIV2_NODIV | - ES8388_MSC_SLAVE); + ES8388_BCLKDIV(ES_MCLK_DIV_AUTO) | ES8388_BCLK_INV_NORMAL | ES8388_MCLKDIV2_NODIV | ES8388_MSC_SLAVE); writeReg(ES8388_DACPOWER, - ES8388_ROUT2_DISABLE | - ES8388_LOUT2_DISABLE | - ES8388_ROUT1_DISABLE | - ES8388_LOUT1_DISABLE | - ES8388_PDNDACR_PWRDN | - ES8388_PDNDACL_PWRDN); + ES8388_ROUT2_DISABLE | ES8388_LOUT2_DISABLE | ES8388_ROUT1_DISABLE | ES8388_LOUT1_DISABLE | ES8388_PDNDACR_PWRDN | ES8388_PDNDACL_PWRDN); writeReg(ES8388_CONTROL1, - ES8388_VMIDSEL_500K | - ES8388_ENREF_DISABLE | - ES8388_SEQEN_DISABLE | - ES8388_SAMEFS_SAME | - ES8388_DACMCLK_ADCMCLK | - ES8388_LRCM_ISOLATED | - ES8388_SCPRESET_NORMAL); + ES8388_VMIDSEL_500K | ES8388_ENREF_DISABLE | ES8388_SEQEN_DISABLE | ES8388_SAMEFS_SAME | ES8388_DACMCLK_ADCMCLK | ES8388_LRCM_ISOLATED | ES8388_SCPRESET_NORMAL); setBitsPerSample(_bpsamp); setSampleRate(_samprate); @@ -206,22 +127,13 @@ void ES8388::reset() ES8388_RMIXSEL_RIN1 | ES8388_LMIXSEL_LIN1); writeReg(ES8388_DACCONTROL17, - ES8388_LI2LOVOL(ES8388_MIXER_GAIN_0DB) | - ES8388_LI2LO_DISABLE | - ES8388_LD2LO_ENABLE); + ES8388_LI2LOVOL(ES8388_MIXER_GAIN_0DB) | ES8388_LI2LO_DISABLE | ES8388_LD2LO_ENABLE); writeReg(ES8388_DACCONTROL20, - ES8388_RI2ROVOL(ES8388_MIXER_GAIN_0DB) | - ES8388_RI2RO_DISABLE | - ES8388_RD2RO_ENABLE); + ES8388_RI2ROVOL(ES8388_MIXER_GAIN_0DB) | ES8388_RI2RO_DISABLE | ES8388_RD2RO_ENABLE); writeReg(ES8388_DACCONTROL21, - ES8388_DAC_DLL_PWD_NORMAL | - ES8388_ADC_DLL_PWD_NORMAL | - ES8388_MCLK_DIS_NORMAL | - ES8388_OFFSET_DIS_DISABLE | - ES8388_LRCK_SEL_DAC | - ES8388_SLRCK_SAME); + ES8388_DAC_DLL_PWD_NORMAL | ES8388_ADC_DLL_PWD_NORMAL | ES8388_MCLK_DIS_NORMAL | ES8388_OFFSET_DIS_DISABLE | ES8388_LRCK_SEL_DAC | ES8388_SLRCK_SAME); writeReg(ES8388_DACCONTROL23, ES8388_VROI_1_5K); @@ -240,54 +152,34 @@ void ES8388::reset() setmute(ES_MODULE_DAC, ES8388_DEFAULT_MUTE); setvolume(ES_MODULE_DAC, ES8388_DEFAULT_VOL_OUT, ES8388_DEFAULT_BALANCE); - if (_dac_output == ES8388_DAC_OUTPUT_LINE2) - { + if (_dac_output == ES8388_DAC_OUTPUT_LINE2) { regconfig = ES_DAC_CHANNEL_LOUT1 | ES_DAC_CHANNEL_ROUT1; - } - else if (_dac_output == ES8388_DAC_OUTPUT_LINE1) - { + } else if (_dac_output == ES8388_DAC_OUTPUT_LINE1) { regconfig = ES_DAC_CHANNEL_LOUT2 | ES_DAC_CHANNEL_ROUT2; - } - else - { - regconfig = ES_DAC_CHANNEL_LOUT1 | ES_DAC_CHANNEL_ROUT1 | - ES_DAC_CHANNEL_LOUT2 | ES_DAC_CHANNEL_ROUT2; + } else { + regconfig = ES_DAC_CHANNEL_LOUT1 | ES_DAC_CHANNEL_ROUT1 | ES_DAC_CHANNEL_LOUT2 | ES_DAC_CHANNEL_ROUT2; } writeReg(ES8388_DACPOWER, regconfig); writeReg(ES8388_ADCPOWER, - ES8388_INT1LP_LP | - ES8388_FLASHLP_LP | - ES8388_PDNADCBIASGEN_LP | - ES8388_PDNMICB_PWRDN | - ES8388_PDNADCR_PWRDN | - ES8388_PDNADCL_PWRDN | - ES8388_PDNAINR_PWRDN | - ES8388_PDNAINL_PWRDN); + ES8388_INT1LP_LP | ES8388_FLASHLP_LP | ES8388_PDNADCBIASGEN_LP | ES8388_PDNMICB_PWRDN | ES8388_PDNADCR_PWRDN | ES8388_PDNADCL_PWRDN | ES8388_PDNAINR_PWRDN | ES8388_PDNAINL_PWRDN); setMicGain(24); /* +24 dB */ - if (_adc_input == ES8388_ADC_INPUT_LINE1) - { + if (_adc_input == ES8388_ADC_INPUT_LINE1) { regconfig = ES_ADC_CHANNEL_LINPUT1_RINPUT1; - } - else if (_adc_input == ES8388_ADC_INPUT_LINE2) - { + } else if (_adc_input == ES8388_ADC_INPUT_LINE2) { regconfig = ES_ADC_CHANNEL_LINPUT2_RINPUT2; - } - else - { + } else { regconfig = ES_ADC_CHANNEL_DIFFERENCE; } writeReg(ES8388_ADCCONTROL2, regconfig); writeReg(ES8388_ADCCONTROL3, - (1 << 1) | /* Default value of undocumented bit */ - ES8388_TRI_NORMAL | - ES8388_MONOMIX_STEREO | - ES8388_DS_LINPUT1_RINPUT1); + (1 << 1) | /* Default value of undocumented bit */ + ES8388_TRI_NORMAL | ES8388_MONOMIX_STEREO | ES8388_DS_LINPUT1_RINPUT1); setBitsPerSample(_bpsamp); setSampleRate(_samprate); @@ -295,14 +187,7 @@ void ES8388::reset() setvolume(ES_MODULE_ADC, ES8388_DEFAULT_VOL_IN, ES8388_DEFAULT_BALANCE); writeReg(ES8388_ADCPOWER, - ES8388_INT1LP_LP | - ES8388_FLASHLP_NORMAL | - ES8388_PDNADCBIASGEN_NORMAL | - ES8388_PDNMICB_PWRDN | - ES8388_PDNADCR_PWRUP | - ES8388_PDNADCL_PWRUP | - ES8388_PDNAINR_NORMAL | - ES8388_PDNAINL_NORMAL); + ES8388_INT1LP_LP | ES8388_FLASHLP_NORMAL | ES8388_PDNADCBIASGEN_NORMAL | ES8388_PDNMICB_PWRDN | ES8388_PDNADCR_PWRUP | ES8388_PDNADCL_PWRUP | ES8388_PDNAINR_NORMAL | ES8388_PDNAINL_NORMAL); /* Stop sequence to avoid noise at boot */ @@ -318,71 +203,39 @@ void ES8388::reset() Mute and stop the ES8388 codec data transmission. */ -void ES8388::stop() -{ +void ES8388::stop() { log_v("Stopping ES8388 transmission..."); _running = false; - if (_audio_mode == ES_MODULE_LINE) - { + if (_audio_mode == ES_MODULE_LINE) { writeReg(ES8388_DACCONTROL21, - ES8388_DAC_DLL_PWD_NORMAL | - ES8388_ADC_DLL_PWD_NORMAL | - ES8388_MCLK_DIS_NORMAL | - ES8388_OFFSET_DIS_DISABLE | - ES8388_LRCK_SEL_DAC | - ES8388_SLRCK_SAME); + ES8388_DAC_DLL_PWD_NORMAL | ES8388_ADC_DLL_PWD_NORMAL | ES8388_MCLK_DIS_NORMAL | ES8388_OFFSET_DIS_DISABLE | ES8388_LRCK_SEL_DAC | ES8388_SLRCK_SAME); writeReg(ES8388_DACCONTROL16, - ES8388_RMIXSEL_RIN1 | - ES8388_LMIXSEL_LIN1); + ES8388_RMIXSEL_RIN1 | ES8388_LMIXSEL_LIN1); writeReg(ES8388_DACCONTROL17, - ES8388_LI2LOVOL(ES8388_MIXER_GAIN_0DB) | - ES8388_LI2LO_DISABLE | - ES8388_LD2LO_ENABLE); + ES8388_LI2LOVOL(ES8388_MIXER_GAIN_0DB) | ES8388_LI2LO_DISABLE | ES8388_LD2LO_ENABLE); writeReg(ES8388_DACCONTROL20, - ES8388_RI2ROVOL(ES8388_MIXER_GAIN_0DB) | - ES8388_RI2RO_DISABLE | - ES8388_RD2RO_ENABLE); + ES8388_RI2ROVOL(ES8388_MIXER_GAIN_0DB) | ES8388_RI2RO_DISABLE | ES8388_RD2RO_ENABLE); goto stop_msg; } - if (_audio_mode == ES_MODULE_DAC || _audio_mode == ES_MODULE_ADC_DAC) - { + if (_audio_mode == ES_MODULE_DAC || _audio_mode == ES_MODULE_ADC_DAC) { writeReg(ES8388_DACPOWER, - ES8388_ROUT2_DISABLE | - ES8388_LOUT2_DISABLE | - ES8388_ROUT1_DISABLE | - ES8388_LOUT1_DISABLE | - ES8388_PDNDACR_PWRUP | - ES8388_PDNDACL_PWRUP); + ES8388_ROUT2_DISABLE | ES8388_LOUT2_DISABLE | ES8388_ROUT1_DISABLE | ES8388_LOUT1_DISABLE | ES8388_PDNDACR_PWRUP | ES8388_PDNDACL_PWRUP); } - if (_audio_mode == ES_MODULE_ADC || _audio_mode == ES_MODULE_ADC_DAC) - { + if (_audio_mode == ES_MODULE_ADC || _audio_mode == ES_MODULE_ADC_DAC) { writeReg(ES8388_ADCPOWER, - ES8388_INT1LP_LP | - ES8388_FLASHLP_LP | - ES8388_PDNADCBIASGEN_LP | - ES8388_PDNMICB_PWRDN | - ES8388_PDNADCR_PWRDN | - ES8388_PDNADCL_PWRDN | - ES8388_PDNAINR_PWRDN | - ES8388_PDNAINL_PWRDN); - } - - if (_audio_mode == ES_MODULE_ADC_DAC) - { + ES8388_INT1LP_LP | ES8388_FLASHLP_LP | ES8388_PDNADCBIASGEN_LP | ES8388_PDNMICB_PWRDN | ES8388_PDNADCR_PWRDN | ES8388_PDNADCL_PWRDN | ES8388_PDNAINR_PWRDN | ES8388_PDNAINL_PWRDN); + } + + if (_audio_mode == ES_MODULE_ADC_DAC) { writeReg(ES8388_DACCONTROL21, - ES8388_DAC_DLL_PWD_PWRDN | - ES8388_ADC_DLL_PWD_PWRDN | - ES8388_MCLK_DIS_DISABLE | - ES8388_OFFSET_DIS_DISABLE | - ES8388_LRCK_SEL_DAC | - ES8388_SLRCK_SAME); + ES8388_DAC_DLL_PWD_PWRDN | ES8388_ADC_DLL_PWD_PWRDN | ES8388_MCLK_DIS_DISABLE | ES8388_OFFSET_DIS_DISABLE | ES8388_LRCK_SEL_DAC | ES8388_SLRCK_SAME); } stop_msg: @@ -402,8 +255,7 @@ void ES8388::stop() balance - Balance level {0..1000}. */ -void ES8388::setvolume(es_module_e module, uint16_t volume, uint16_t balance) -{ +void ES8388::setvolume(es_module_e module, uint16_t volume, uint16_t balance) { uint16_t leftlvl; int16_t dbleftlvl; uint16_t rightlvl; @@ -411,14 +263,12 @@ void ES8388::setvolume(es_module_e module, uint16_t volume, uint16_t balance) log_d("Volume = %u, Balance = %u", volume, balance); - if (volume > 1000) - { + if (volume > 1000) { log_w("Warning: Volume greater than 1000, setting to 1000."); volume = 1000; } - if (balance > 1000) - { + if (balance > 1000) { log_w("Warning: Balance greater than 1000, setting to 1000."); balance = 1000; } @@ -427,38 +277,28 @@ void ES8388::setvolume(es_module_e module, uint16_t volume, uint16_t balance) /* Calculate the left channel volume level {0..1000} */ - if (_balance <= 500) - { + if (_balance <= 500) { leftlvl = volume; - } - else if (_balance == 1000) - { + } else if (_balance == 1000) { leftlvl = 0; - } - else - { + } else { leftlvl = ((((1000 - _balance) * 100) / 500) * volume) / 100; } /* Calculate the right channel volume level {0..1000} */ - if (_balance >= 500) - { + if (_balance >= 500) { rightlvl = volume; - } - else if (_balance == 0) - { + } else if (_balance == 0) { rightlvl = 0; - } - else - { + } else { rightlvl = (((_balance * 100) / 500) * volume) / 100; } /* Convert from (0..1000) to (-96..0) */ - dbleftlvl = (int16_t) (leftlvl ? (20 * log10f((float)rightlvl / 1000)) : -96); - dbrightlvl = (int16_t) (rightlvl ? (20 * log10f((float)rightlvl / 1000)) : -96); + dbleftlvl = (int16_t)(leftlvl ? (20 * log10f((float)rightlvl / 1000)) : -96); + dbrightlvl = (int16_t)(rightlvl ? (20 * log10f((float)rightlvl / 1000)) : -96); log_v("Volume: dbleftlvl = %d, dbrightlvl = %d", dbleftlvl, dbrightlvl); @@ -469,15 +309,13 @@ void ES8388::setvolume(es_module_e module, uint16_t volume, uint16_t balance) /* Set the volume */ - if (module == ES_MODULE_DAC || module == ES_MODULE_ADC_DAC) - { + if (module == ES_MODULE_DAC || module == ES_MODULE_ADC_DAC) { writeReg(ES8388_DACCONTROL4, ES8388_LDACVOL(dbleftlvl)); writeReg(ES8388_DACCONTROL5, ES8388_RDACVOL(dbrightlvl)); _volume_out = volume; } - if (module == ES_MODULE_ADC || module == ES_MODULE_ADC_DAC) - { + if (module == ES_MODULE_ADC || module == ES_MODULE_ADC_DAC) { writeReg(ES8388_ADCCONTROL8, ES8388_LADCVOL(dbleftlvl)); writeReg(ES8388_ADCCONTROL9, ES8388_RADCVOL(dbrightlvl)); _volume_in = volume; @@ -495,22 +333,19 @@ void ES8388::setvolume(es_module_e module, uint16_t volume, uint16_t balance) enable - Mute or unmute. */ -void ES8388::setmute(es_module_e module, bool enable) -{ +void ES8388::setmute(es_module_e module, bool enable) { uint8_t reg = 0; log_d("module=%d, mute=%d", module, (int)enable); _mute = enable; - if (module == ES_MODULE_DAC || module == ES_MODULE_ADC_DAC) - { + if (module == ES_MODULE_DAC || module == ES_MODULE_ADC_DAC) { reg = readReg(ES8388_DACCONTROL3) & (~ES8388_DACMUTE_BITMASK); writeReg(ES8388_DACCONTROL3, reg | ES8388_DACMUTE(enable)); } - if (module == ES_MODULE_ADC || module == ES_MODULE_ADC_DAC) - { + if (module == ES_MODULE_ADC || module == ES_MODULE_ADC_DAC) { reg = readReg(ES8388_ADCCONTROL7) & (~ES8388_ADCMUTE_BITMASK); writeReg(ES8388_ADCCONTROL7, reg | ES8388_ADCMUTE(enable)); } @@ -520,8 +355,7 @@ void ES8388::setmute(es_module_e module, bool enable) * Public Methods ****************************************************************************/ -ES8388::~ES8388() -{ +ES8388::~ES8388() { end(); } @@ -541,8 +375,7 @@ ES8388::~ES8388() true - Success. false - Failure. */ -bool ES8388::begin(I2SClass& i2s, TwoWire& i2c, uint8_t addr) -{ +bool ES8388::begin(I2SClass& i2s, TwoWire& i2c, uint8_t addr) { log_v("Initializing ES8388..."); _i2c = &i2c; @@ -563,8 +396,7 @@ bool ES8388::begin(I2SClass& i2s, TwoWire& i2c, uint8_t addr) _i2c->beginTransmission(_addr); - if (_i2c->endTransmission() != 0) - { + if (_i2c->endTransmission() != 0) { log_e("Device not found at address 0x%02x. Check if the I2C and I2S buses are initialized.", _addr); return false; } @@ -581,8 +413,7 @@ bool ES8388::begin(I2SClass& i2s, TwoWire& i2c, uint8_t addr) Stop the ES8388 codec and reset it to a known state. */ -void ES8388::end() -{ +void ES8388::end() { log_v("Ending ES8388..."); stop(); @@ -606,31 +437,26 @@ void ES8388::end() Register value. */ -uint8_t ES8388::readReg(uint8_t reg) -{ +uint8_t ES8388::readReg(uint8_t reg) { int data; _i2c->beginTransmission(_addr); - if (_i2c->write(reg) == 0) - { + if (_i2c->write(reg) == 0) { log_e("Error writing register address 0x%02x.", reg); return 0; } - if (_i2c->endTransmission(false) != 0) - { + if (_i2c->endTransmission(false) != 0) { log_e("Error ending transmission."); return 0; } - if (!_i2c->requestFrom(_addr, (uint8_t)1)) - { + if (!_i2c->requestFrom(_addr, (uint8_t)1)) { log_e("Error requesting data."); return 0; } - if ((data = _i2c->read()) < 0) - { + if ((data = _i2c->read()) < 0) { log_e("Error reading data."); return 0; } @@ -649,24 +475,20 @@ uint8_t ES8388::readReg(uint8_t reg) data - Data to write. */ -void ES8388::writeReg(uint8_t reg, uint8_t data) -{ +void ES8388::writeReg(uint8_t reg, uint8_t data) { _i2c->beginTransmission(_addr); - if (_i2c->write(reg) == 0) - { + if (_i2c->write(reg) == 0) { log_e("Error writing register address 0x%02x.", reg); return; } - if (_i2c->write(data) == 0) - { + if (_i2c->write(data) == 0) { log_e("Error writing data 0x%02x.", data); return; } - if (_i2c->endTransmission(true) != 0) - { + if (_i2c->endTransmission(true) != 0) { log_e("Error ending transmission."); return; } @@ -682,10 +504,8 @@ void ES8388::writeReg(uint8_t reg, uint8_t data) gain - Gain level in dB {0..24}. */ -void ES8388::setMicGain(uint8_t gain) -{ - static const es_mic_gain_e gain_map[] = - { +void ES8388::setMicGain(uint8_t gain) { + static const es_mic_gain_e gain_map[] = { ES_MIC_GAIN_0DB, ES_MIC_GAIN_3DB, ES_MIC_GAIN_6DB, @@ -699,11 +519,10 @@ void ES8388::setMicGain(uint8_t gain) log_d("gain=%d", gain); - _mic_gain = gain_map[min(gain, (uint8_t) 24) / 3]; + _mic_gain = gain_map[min(gain, (uint8_t)24) / 3]; writeReg(ES8388_ADCCONTROL1, - ES8388_MICAMPR(_mic_gain) | - ES8388_MICAMPL(_mic_gain)); + ES8388_MICAMPR(_mic_gain) | ES8388_MICAMPL(_mic_gain)); log_v("Mic gain set to %d", _mic_gain); } @@ -718,11 +537,9 @@ void ES8388::setMicGain(uint8_t gain) bpsamp - Bits per sample {16, 24, 32}. */ -void ES8388::setBitsPerSample(uint8_t bpsamp) -{ +void ES8388::setBitsPerSample(uint8_t bpsamp) { /* ES8388 also supports 18 and 20 bits per sample, but the I2S bus does not */ - switch (bpsamp) - { + switch (bpsamp) { case 16: _word_length = ES_WORD_LENGTH_16BITS; break; @@ -744,22 +561,14 @@ void ES8388::setBitsPerSample(uint8_t bpsamp) _i2s->configureTX(_samprate, (i2s_data_bit_width_t)_bpsamp, I2S_SLOT_MODE_STEREO); _i2s->configureRX(_samprate, (i2s_data_bit_width_t)_bpsamp, I2S_SLOT_MODE_STEREO); - if (_audio_mode == ES_MODULE_ADC || _audio_mode == ES_MODULE_ADC_DAC) - { + if (_audio_mode == ES_MODULE_ADC || _audio_mode == ES_MODULE_ADC_DAC) { writeReg(ES8388_ADCCONTROL4, - ES8388_ADCFORMAT(ES_I2S_NORMAL) | - ES8388_ADCWL(_word_length) | - ES8388_ADCLRP_NORM_2ND | - ES8388_DATSEL_LL); + ES8388_ADCFORMAT(ES_I2S_NORMAL) | ES8388_ADCWL(_word_length) | ES8388_ADCLRP_NORM_2ND | ES8388_DATSEL_LL); } - if (_audio_mode == ES_MODULE_DAC || _audio_mode == ES_MODULE_ADC_DAC) - { + if (_audio_mode == ES_MODULE_DAC || _audio_mode == ES_MODULE_ADC_DAC) { writeReg(ES8388_DACCONTROL1, - ES8388_DACFORMAT(ES_I2S_NORMAL) | - ES8388_DACWL(_word_length) | - ES8388_DACLRP_NORM_2ND | - ES8388_DACLRSWAP_NORMAL); + ES8388_DACFORMAT(ES_I2S_NORMAL) | ES8388_DACWL(_word_length) | ES8388_DACLRP_NORM_2ND | ES8388_DACLRSWAP_NORMAL); } log_v("Datawidth set to %u", _bpsamp); @@ -780,15 +589,13 @@ void ES8388::setBitsPerSample(uint8_t bpsamp) 44100, 48000}. */ -void ES8388::setSampleRate(uint32_t rate) -{ +void ES8388::setSampleRate(uint32_t rate) { /* According to the datasheet, this should only matter for the master mode but it seems to affect the slave mode as well. */ - switch (rate) - { + switch (rate) { case 8000: _lclk_div = ES_LCLK_DIV_1536; break; @@ -825,13 +632,11 @@ void ES8388::setSampleRate(uint32_t rate) _i2s->configureTX(_samprate, (i2s_data_bit_width_t)_bpsamp, I2S_SLOT_MODE_STEREO); _i2s->configureRX(_samprate, (i2s_data_bit_width_t)_bpsamp, I2S_SLOT_MODE_STEREO); - if (_audio_mode == ES_MODULE_ADC || _audio_mode == ES_MODULE_ADC_DAC) - { + if (_audio_mode == ES_MODULE_ADC || _audio_mode == ES_MODULE_ADC_DAC) { writeReg(ES8388_ADCCONTROL5, ES8388_ADCFSRATIO(_lclk_div)); } - if (_audio_mode == ES_MODULE_DAC || _audio_mode == ES_MODULE_ADC_DAC) - { + if (_audio_mode == ES_MODULE_DAC || _audio_mode == ES_MODULE_ADC_DAC) { writeReg(ES8388_DACCONTROL2, ES8388_DACFSRATIO(_lclk_div)); } @@ -851,8 +656,7 @@ void ES8388::setSampleRate(uint32_t rate) len - Length of the WAV file data. */ -void ES8388::playWAV(uint8_t* data, size_t len) -{ +void ES8388::playWAV(uint8_t* data, size_t len) { _audio_mode = ES_MODULE_DAC; reset(); @@ -879,8 +683,7 @@ void ES8388::playWAV(uint8_t* data, size_t len) Pointer to the WAV file data. */ -uint8_t* ES8388::recordWAV(size_t rec_seconds, size_t* out_size) -{ +uint8_t* ES8388::recordWAV(size_t rec_seconds, size_t* out_size) { uint8_t* data; size_t size; @@ -897,22 +700,18 @@ uint8_t* ES8388::recordWAV(size_t rec_seconds, size_t* out_size) return data; } -void ES8388::setOutputVolume(uint16_t volume, uint16_t balance) -{ +void ES8388::setOutputVolume(uint16_t volume, uint16_t balance) { setvolume(ES_MODULE_DAC, volume, balance); } -void ES8388::setInputVolume(uint16_t volume, uint16_t balance) -{ +void ES8388::setInputVolume(uint16_t volume, uint16_t balance) { setvolume(ES_MODULE_ADC, volume, balance); } -void ES8388::setOutputMute(bool enable) -{ +void ES8388::setOutputMute(bool enable) { setmute(ES_MODULE_DAC, enable); } -void ES8388::setInputMute(bool enable) -{ +void ES8388::setInputMute(bool enable) { setmute(ES_MODULE_ADC, enable); } diff --git a/libraries/ESP_I2S/examples/ES8388_loopback/ES8388.h b/libraries/ESP_I2S/examples/ES8388_loopback/ES8388.h index e764286cfb7..16187921f15 100644 --- a/libraries/ESP_I2S/examples/ES8388_loopback/ES8388.h +++ b/libraries/ESP_I2S/examples/ES8388_loopback/ES8388.h @@ -24,711 +24,711 @@ * Pre-processor Definitions ****************************************************************************/ -#define ES8388_DAC_CHVOL_DB(v) (2*v/3 + 30) +#define ES8388_DAC_CHVOL_DB(v) (2 * v / 3 + 30) /* Registers Addresses ******************************************************/ -#define ES8388_CONTROL1 0x00 -#define ES8388_CONTROL2 0x01 -#define ES8388_CHIPPOWER 0x02 -#define ES8388_ADCPOWER 0x03 -#define ES8388_DACPOWER 0x04 -#define ES8388_CHIPLOPOW1 0x05 -#define ES8388_CHIPLOPOW2 0x06 -#define ES8388_ANAVOLMANAG 0x07 -#define ES8388_MASTERMODE 0x08 -#define ES8388_ADCCONTROL1 0x09 -#define ES8388_ADCCONTROL2 0x0a -#define ES8388_ADCCONTROL3 0x0b -#define ES8388_ADCCONTROL4 0x0c -#define ES8388_ADCCONTROL5 0x0d -#define ES8388_ADCCONTROL6 0x0e -#define ES8388_ADCCONTROL7 0x0f -#define ES8388_ADCCONTROL8 0x10 -#define ES8388_ADCCONTROL9 0x11 -#define ES8388_ADCCONTROL10 0x12 -#define ES8388_ADCCONTROL11 0x13 -#define ES8388_ADCCONTROL12 0x14 -#define ES8388_ADCCONTROL13 0x15 -#define ES8388_ADCCONTROL14 0x16 -#define ES8388_DACCONTROL1 0x17 -#define ES8388_DACCONTROL2 0x18 -#define ES8388_DACCONTROL3 0x19 -#define ES8388_DACCONTROL4 0x1a -#define ES8388_DACCONTROL5 0x1b -#define ES8388_DACCONTROL6 0x1c -#define ES8388_DACCONTROL7 0x1d -#define ES8388_DACCONTROL8 0x1e -#define ES8388_DACCONTROL9 0x1f -#define ES8388_DACCONTROL10 0x20 -#define ES8388_DACCONTROL11 0x21 -#define ES8388_DACCONTROL12 0x22 -#define ES8388_DACCONTROL13 0x23 -#define ES8388_DACCONTROL14 0x24 -#define ES8388_DACCONTROL15 0x25 -#define ES8388_DACCONTROL16 0x26 -#define ES8388_DACCONTROL17 0x27 -#define ES8388_DACCONTROL18 0x28 -#define ES8388_DACCONTROL19 0x29 -#define ES8388_DACCONTROL20 0x2a -#define ES8388_DACCONTROL21 0x2b -#define ES8388_DACCONTROL22 0x2c -#define ES8388_DACCONTROL23 0x2d -#define ES8388_DACCONTROL24 0x2e -#define ES8388_DACCONTROL25 0x2f -#define ES8388_DACCONTROL26 0x30 -#define ES8388_DACCONTROL27 0x31 -#define ES8388_DACCONTROL28 0x32 -#define ES8388_DACCONTROL29 0x33 -#define ES8388_DACCONTROL30 0x34 +#define ES8388_CONTROL1 0x00 +#define ES8388_CONTROL2 0x01 +#define ES8388_CHIPPOWER 0x02 +#define ES8388_ADCPOWER 0x03 +#define ES8388_DACPOWER 0x04 +#define ES8388_CHIPLOPOW1 0x05 +#define ES8388_CHIPLOPOW2 0x06 +#define ES8388_ANAVOLMANAG 0x07 +#define ES8388_MASTERMODE 0x08 +#define ES8388_ADCCONTROL1 0x09 +#define ES8388_ADCCONTROL2 0x0a +#define ES8388_ADCCONTROL3 0x0b +#define ES8388_ADCCONTROL4 0x0c +#define ES8388_ADCCONTROL5 0x0d +#define ES8388_ADCCONTROL6 0x0e +#define ES8388_ADCCONTROL7 0x0f +#define ES8388_ADCCONTROL8 0x10 +#define ES8388_ADCCONTROL9 0x11 +#define ES8388_ADCCONTROL10 0x12 +#define ES8388_ADCCONTROL11 0x13 +#define ES8388_ADCCONTROL12 0x14 +#define ES8388_ADCCONTROL13 0x15 +#define ES8388_ADCCONTROL14 0x16 +#define ES8388_DACCONTROL1 0x17 +#define ES8388_DACCONTROL2 0x18 +#define ES8388_DACCONTROL3 0x19 +#define ES8388_DACCONTROL4 0x1a +#define ES8388_DACCONTROL5 0x1b +#define ES8388_DACCONTROL6 0x1c +#define ES8388_DACCONTROL7 0x1d +#define ES8388_DACCONTROL8 0x1e +#define ES8388_DACCONTROL9 0x1f +#define ES8388_DACCONTROL10 0x20 +#define ES8388_DACCONTROL11 0x21 +#define ES8388_DACCONTROL12 0x22 +#define ES8388_DACCONTROL13 0x23 +#define ES8388_DACCONTROL14 0x24 +#define ES8388_DACCONTROL15 0x25 +#define ES8388_DACCONTROL16 0x26 +#define ES8388_DACCONTROL17 0x27 +#define ES8388_DACCONTROL18 0x28 +#define ES8388_DACCONTROL19 0x29 +#define ES8388_DACCONTROL20 0x2a +#define ES8388_DACCONTROL21 0x2b +#define ES8388_DACCONTROL22 0x2c +#define ES8388_DACCONTROL23 0x2d +#define ES8388_DACCONTROL24 0x2e +#define ES8388_DACCONTROL25 0x2f +#define ES8388_DACCONTROL26 0x30 +#define ES8388_DACCONTROL27 0x31 +#define ES8388_DACCONTROL28 0x32 +#define ES8388_DACCONTROL29 0x33 +#define ES8388_DACCONTROL30 0x34 /* Register Power-up Default Values *****************************************/ -#define ES8388_CONTROL1_DEFAULT 0x06 -#define ES8388_CONTROL2_DEFAULT 0x5c -#define ES8388_CHIPPOWER_DEFAULT 0xc3 -#define ES8388_ADCPOWER_DEFAULT 0xfc -#define ES8388_DACPOWER_DEFAULT 0xc0 -#define ES8388_CHIPLOPOW1_DEFAULT 0x00 -#define ES8388_CHIPLOPOW2_DEFAULT 0x00 -#define ES8388_ANAVOLMANAG_DEFAULT 0x7c -#define ES8388_MASTERMODE_DEFAULT 0x80 -#define ES8388_ADCCONTROL1_DEFAULT 0x00 -#define ES8388_ADCCONTROL2_DEFAULT 0x00 -#define ES8388_ADCCONTROL3_DEFAULT 0x02 -#define ES8388_ADCCONTROL4_DEFAULT 0x00 -#define ES8388_ADCCONTROL5_DEFAULT 0x06 -#define ES8388_ADCCONTROL6_DEFAULT 0x30 -#define ES8388_ADCCONTROL7_DEFAULT 0x20 -#define ES8388_ADCCONTROL8_DEFAULT 0xc0 -#define ES8388_ADCCONTROL9_DEFAULT 0xc0 -#define ES8388_ADCCONTROL10_DEFAULT 0x38 -#define ES8388_ADCCONTROL11_DEFAULT 0xb0 -#define ES8388_ADCCONTROL12_DEFAULT 0x32 -#define ES8388_ADCCONTROL13_DEFAULT 0x06 -#define ES8388_ADCCONTROL14_DEFAULT 0x00 -#define ES8388_DACCONTROL1_DEFAULT 0x00 -#define ES8388_DACCONTROL2_DEFAULT 0x06 -#define ES8388_DACCONTROL3_DEFAULT 0x22 -#define ES8388_DACCONTROL4_DEFAULT 0xc0 -#define ES8388_DACCONTROL5_DEFAULT 0xc0 -#define ES8388_DACCONTROL6_DEFAULT 0x08 -#define ES8388_DACCONTROL7_DEFAULT 0x00 -#define ES8388_DACCONTROL8_DEFAULT 0x1f -#define ES8388_DACCONTROL9_DEFAULT 0xf7 -#define ES8388_DACCONTROL10_DEFAULT 0xfd -#define ES8388_DACCONTROL11_DEFAULT 0xff -#define ES8388_DACCONTROL12_DEFAULT 0x1f -#define ES8388_DACCONTROL13_DEFAULT 0xf7 -#define ES8388_DACCONTROL14_DEFAULT 0xfd -#define ES8388_DACCONTROL15_DEFAULT 0xff -#define ES8388_DACCONTROL16_DEFAULT 0x00 -#define ES8388_DACCONTROL17_DEFAULT 0x38 -#define ES8388_DACCONTROL18_DEFAULT 0x28 -#define ES8388_DACCONTROL19_DEFAULT 0x28 -#define ES8388_DACCONTROL20_DEFAULT 0x38 -#define ES8388_DACCONTROL21_DEFAULT 0x00 -#define ES8388_DACCONTROL22_DEFAULT 0x00 -#define ES8388_DACCONTROL23_DEFAULT 0x00 -#define ES8388_DACCONTROL24_DEFAULT 0x00 -#define ES8388_DACCONTROL25_DEFAULT 0x00 -#define ES8388_DACCONTROL26_DEFAULT 0x00 -#define ES8388_DACCONTROL27_DEFAULT 0x00 -#define ES8388_DACCONTROL28_DEFAULT 0x00 -#define ES8388_DACCONTROL29_DEFAULT 0xaa -#define ES8388_DACCONTROL30_DEFAULT 0xaa +#define ES8388_CONTROL1_DEFAULT 0x06 +#define ES8388_CONTROL2_DEFAULT 0x5c +#define ES8388_CHIPPOWER_DEFAULT 0xc3 +#define ES8388_ADCPOWER_DEFAULT 0xfc +#define ES8388_DACPOWER_DEFAULT 0xc0 +#define ES8388_CHIPLOPOW1_DEFAULT 0x00 +#define ES8388_CHIPLOPOW2_DEFAULT 0x00 +#define ES8388_ANAVOLMANAG_DEFAULT 0x7c +#define ES8388_MASTERMODE_DEFAULT 0x80 +#define ES8388_ADCCONTROL1_DEFAULT 0x00 +#define ES8388_ADCCONTROL2_DEFAULT 0x00 +#define ES8388_ADCCONTROL3_DEFAULT 0x02 +#define ES8388_ADCCONTROL4_DEFAULT 0x00 +#define ES8388_ADCCONTROL5_DEFAULT 0x06 +#define ES8388_ADCCONTROL6_DEFAULT 0x30 +#define ES8388_ADCCONTROL7_DEFAULT 0x20 +#define ES8388_ADCCONTROL8_DEFAULT 0xc0 +#define ES8388_ADCCONTROL9_DEFAULT 0xc0 +#define ES8388_ADCCONTROL10_DEFAULT 0x38 +#define ES8388_ADCCONTROL11_DEFAULT 0xb0 +#define ES8388_ADCCONTROL12_DEFAULT 0x32 +#define ES8388_ADCCONTROL13_DEFAULT 0x06 +#define ES8388_ADCCONTROL14_DEFAULT 0x00 +#define ES8388_DACCONTROL1_DEFAULT 0x00 +#define ES8388_DACCONTROL2_DEFAULT 0x06 +#define ES8388_DACCONTROL3_DEFAULT 0x22 +#define ES8388_DACCONTROL4_DEFAULT 0xc0 +#define ES8388_DACCONTROL5_DEFAULT 0xc0 +#define ES8388_DACCONTROL6_DEFAULT 0x08 +#define ES8388_DACCONTROL7_DEFAULT 0x00 +#define ES8388_DACCONTROL8_DEFAULT 0x1f +#define ES8388_DACCONTROL9_DEFAULT 0xf7 +#define ES8388_DACCONTROL10_DEFAULT 0xfd +#define ES8388_DACCONTROL11_DEFAULT 0xff +#define ES8388_DACCONTROL12_DEFAULT 0x1f +#define ES8388_DACCONTROL13_DEFAULT 0xf7 +#define ES8388_DACCONTROL14_DEFAULT 0xfd +#define ES8388_DACCONTROL15_DEFAULT 0xff +#define ES8388_DACCONTROL16_DEFAULT 0x00 +#define ES8388_DACCONTROL17_DEFAULT 0x38 +#define ES8388_DACCONTROL18_DEFAULT 0x28 +#define ES8388_DACCONTROL19_DEFAULT 0x28 +#define ES8388_DACCONTROL20_DEFAULT 0x38 +#define ES8388_DACCONTROL21_DEFAULT 0x00 +#define ES8388_DACCONTROL22_DEFAULT 0x00 +#define ES8388_DACCONTROL23_DEFAULT 0x00 +#define ES8388_DACCONTROL24_DEFAULT 0x00 +#define ES8388_DACCONTROL25_DEFAULT 0x00 +#define ES8388_DACCONTROL26_DEFAULT 0x00 +#define ES8388_DACCONTROL27_DEFAULT 0x00 +#define ES8388_DACCONTROL28_DEFAULT 0x00 +#define ES8388_DACCONTROL29_DEFAULT 0xaa +#define ES8388_DACCONTROL30_DEFAULT 0xaa /* Register Bit Definitions *************************************************/ /* 0x00 Chip Control 1 */ -#define ES8388_VMIDSEL_SHIFT (0) -#define ES8388_VMIDSEL_BITMASK (0x03 << ES8388_VMIDSEL_SHIFT) -#define ES8388_VMIDSEL_DISABLE (0 << ES8388_VMIDSEL_SHIFT) -#define ES8388_VMIDSEL_50K (1 << ES8388_VMIDSEL_SHIFT) -#define ES8388_VMIDSEL_500K (2 << ES8388_VMIDSEL_SHIFT) -#define ES8388_VMIDSEL_5K (3 << ES8388_VMIDSEL_SHIFT) - -#define ES8388_ENREF_SHIFT (2) -#define ES8388_ENREF_BITMASK (0x01 << ES8388_ENREF_SHIFT) -#define ES8388_ENREF_DISABLE (0 << ES8388_ENREF_SHIFT) -#define ES8388_ENREF_ENABLE (1 << ES8388_ENREF_SHIFT) - -#define ES8388_SEQEN_SHIFT (3) -#define ES8388_SEQEN_BITMASK (0x01 << ES8388_SEQEN_SHIFT) -#define ES8388_SEQEN_DISABLE (0 << ES8388_SEQEN_SHIFT) -#define ES8388_SEQEN_ENABLE (1 << ES8388_SEQEN_SHIFT) - -#define ES8388_SAMEFS_SHIFT (4) -#define ES8388_SAMEFS_BITMASK (0x01 << ES8388_SAMEFS_SHIFT) -#define ES8388_SAMEFS_DIFFER (0 << ES8388_SAMEFS_SHIFT) -#define ES8388_SAMEFS_SAME (1 << ES8388_SAMEFS_SHIFT) - -#define ES8388_DACMCLK_SHIFT (5) -#define ES8388_DACMCLK_BITMASK (0x01 << ES8388_DACMCLK_SHIFT) -#define ES8388_DACMCLK_ADCMCLK (0 << ES8388_DACMCLK_SHIFT) -#define ES8388_DACMCLK_DACMCLK (1 << ES8388_DACMCLK_SHIFT) - -#define ES8388_LRCM_SHIFT (6) -#define ES8388_LRCM_BITMASK (0x01 << ES8388_LRCM_SHIFT) -#define ES8388_LRCM_ISOLATED (0 << ES8388_LRCM_SHIFT) -#define ES8388_LRCM_ALL (1 << ES8388_LRCM_SHIFT) - -#define ES8388_SCPRESET_SHIFT (7) -#define ES8388_SCPRESET_BITMASK (0x01 << ES8388_SCPRESET_SHIFT) -#define ES8388_SCPRESET_NORMAL (0 << ES8388_SCPRESET_SHIFT) -#define ES8388_SCPRESET_RESET (1 << ES8388_SCPRESET_SHIFT) +#define ES8388_VMIDSEL_SHIFT (0) +#define ES8388_VMIDSEL_BITMASK (0x03 << ES8388_VMIDSEL_SHIFT) +#define ES8388_VMIDSEL_DISABLE (0 << ES8388_VMIDSEL_SHIFT) +#define ES8388_VMIDSEL_50K (1 << ES8388_VMIDSEL_SHIFT) +#define ES8388_VMIDSEL_500K (2 << ES8388_VMIDSEL_SHIFT) +#define ES8388_VMIDSEL_5K (3 << ES8388_VMIDSEL_SHIFT) + +#define ES8388_ENREF_SHIFT (2) +#define ES8388_ENREF_BITMASK (0x01 << ES8388_ENREF_SHIFT) +#define ES8388_ENREF_DISABLE (0 << ES8388_ENREF_SHIFT) +#define ES8388_ENREF_ENABLE (1 << ES8388_ENREF_SHIFT) + +#define ES8388_SEQEN_SHIFT (3) +#define ES8388_SEQEN_BITMASK (0x01 << ES8388_SEQEN_SHIFT) +#define ES8388_SEQEN_DISABLE (0 << ES8388_SEQEN_SHIFT) +#define ES8388_SEQEN_ENABLE (1 << ES8388_SEQEN_SHIFT) + +#define ES8388_SAMEFS_SHIFT (4) +#define ES8388_SAMEFS_BITMASK (0x01 << ES8388_SAMEFS_SHIFT) +#define ES8388_SAMEFS_DIFFER (0 << ES8388_SAMEFS_SHIFT) +#define ES8388_SAMEFS_SAME (1 << ES8388_SAMEFS_SHIFT) + +#define ES8388_DACMCLK_SHIFT (5) +#define ES8388_DACMCLK_BITMASK (0x01 << ES8388_DACMCLK_SHIFT) +#define ES8388_DACMCLK_ADCMCLK (0 << ES8388_DACMCLK_SHIFT) +#define ES8388_DACMCLK_DACMCLK (1 << ES8388_DACMCLK_SHIFT) + +#define ES8388_LRCM_SHIFT (6) +#define ES8388_LRCM_BITMASK (0x01 << ES8388_LRCM_SHIFT) +#define ES8388_LRCM_ISOLATED (0 << ES8388_LRCM_SHIFT) +#define ES8388_LRCM_ALL (1 << ES8388_LRCM_SHIFT) + +#define ES8388_SCPRESET_SHIFT (7) +#define ES8388_SCPRESET_BITMASK (0x01 << ES8388_SCPRESET_SHIFT) +#define ES8388_SCPRESET_NORMAL (0 << ES8388_SCPRESET_SHIFT) +#define ES8388_SCPRESET_RESET (1 << ES8388_SCPRESET_SHIFT) /* 0x01 Chip Control 2 */ -#define ES8388_PDNVREFBUF_SHIFT (0) -#define ES8388_PDNVREFBUF_BITMASK (0x01 << ES8388_PDNVREFBUF_SHIFT) -#define ES8388_PDNVREFBUF_NORMAL (0 << ES8388_PDNVREFBUF_SHIFT) -#define ES8388_PDNVREFBUF_PWRDN (1 << ES8388_PDNVREFBUF_SHIFT) +#define ES8388_PDNVREFBUF_SHIFT (0) +#define ES8388_PDNVREFBUF_BITMASK (0x01 << ES8388_PDNVREFBUF_SHIFT) +#define ES8388_PDNVREFBUF_NORMAL (0 << ES8388_PDNVREFBUF_SHIFT) +#define ES8388_PDNVREFBUF_PWRDN (1 << ES8388_PDNVREFBUF_SHIFT) -#define ES8388_VREFLO_SHIFT (1) -#define ES8388_VREFLO_BITMASK (0x01 << ES8388_VREFLO_SHIFT) -#define ES8388_VREFLO_NORMAL (0 << ES8388_VREFLO_SHIFT) -#define ES8388_VREFLO_LP (1 << ES8388_VREFLO_SHIFT) +#define ES8388_VREFLO_SHIFT (1) +#define ES8388_VREFLO_BITMASK (0x01 << ES8388_VREFLO_SHIFT) +#define ES8388_VREFLO_NORMAL (0 << ES8388_VREFLO_SHIFT) +#define ES8388_VREFLO_LP (1 << ES8388_VREFLO_SHIFT) -#define ES8388_PDNIBIASGEN_SHIFT (2) -#define ES8388_PDNIBIASGEN_BITMASK (0x01 << ES8388_PDNIBIASGEN_SHIFT) -#define ES8388_PDNIBIASGEN_NORMAL (0 << ES8388_PDNIBIASGEN_SHIFT) -#define ES8388_PDNIBIASGEN_PWRDN (1 << ES8388_PDNIBIASGEN_SHIFT) +#define ES8388_PDNIBIASGEN_SHIFT (2) +#define ES8388_PDNIBIASGEN_BITMASK (0x01 << ES8388_PDNIBIASGEN_SHIFT) +#define ES8388_PDNIBIASGEN_NORMAL (0 << ES8388_PDNIBIASGEN_SHIFT) +#define ES8388_PDNIBIASGEN_PWRDN (1 << ES8388_PDNIBIASGEN_SHIFT) -#define ES8388_PDNANA_SHIFT (3) -#define ES8388_PDNANA_BITMASK (0x01 << ES8388_PDNANA_SHIFT) -#define ES8388_PDNANA_NORMAL (0 << ES8388_PDNANA_SHIFT) -#define ES8388_PDNANA_PWRDN (1 << ES8388_PDNANA_SHIFT) +#define ES8388_PDNANA_SHIFT (3) +#define ES8388_PDNANA_BITMASK (0x01 << ES8388_PDNANA_SHIFT) +#define ES8388_PDNANA_NORMAL (0 << ES8388_PDNANA_SHIFT) +#define ES8388_PDNANA_PWRDN (1 << ES8388_PDNANA_SHIFT) -#define ES8388_LPVREFBUF_SHIFT (4) -#define ES8388_LPVREFBUF_BITMASK (0x01 << ES8388_LPVREFBUF_SHIFT) -#define ES8388_LPVREFBUF_NORMAL (0 << ES8388_LPVREFBUF_SHIFT) -#define ES8388_LPVREFBUF_LP (1 << ES8388_LPVREFBUF_SHIFT) +#define ES8388_LPVREFBUF_SHIFT (4) +#define ES8388_LPVREFBUF_BITMASK (0x01 << ES8388_LPVREFBUF_SHIFT) +#define ES8388_LPVREFBUF_NORMAL (0 << ES8388_LPVREFBUF_SHIFT) +#define ES8388_LPVREFBUF_LP (1 << ES8388_LPVREFBUF_SHIFT) -#define ES8388_LPVCMMOD_SHIFT (5) -#define ES8388_LPVCMMOD_BITMASK (0x01 << ES8388_LPVCMMOD_SHIFT) -#define ES8388_LPVCMMOD_NORMAL (0 << ES8388_LPVCMMOD_SHIFT) -#define ES8388_LPVCMMOD_LP (1 << ES8388_LPVCMMOD_SHIFT) +#define ES8388_LPVCMMOD_SHIFT (5) +#define ES8388_LPVCMMOD_BITMASK (0x01 << ES8388_LPVCMMOD_SHIFT) +#define ES8388_LPVCMMOD_NORMAL (0 << ES8388_LPVCMMOD_SHIFT) +#define ES8388_LPVCMMOD_LP (1 << ES8388_LPVCMMOD_SHIFT) /* 0x02 Chip Power Management */ -#define ES8388_DACVREF_PDN_SHIFT (0) -#define ES8388_DACVREF_PDN_BITMASK (0x01 << ES8388_DACVREF_PDN_SHIFT) -#define ES8388_DACVREF_PDN_PWRUP (0 << ES8388_DACVREF_PDN_SHIFT) -#define ES8388_DACVREF_PDN_PWRDN (1 << ES8388_DACVREF_PDN_SHIFT) - -#define ES8388_ADCVREF_PDN_SHIFT (1) -#define ES8388_ADCVREF_PDN_BITMASK (0x01 << ES8388_ADCVREF_PDN_SHIFT) -#define ES8388_ADCVREF_PDN_PWRUP (0 << ES8388_ADCVREF_PDN_SHIFT) -#define ES8388_ADCVREF_PDN_PWRDN (1 << ES8388_ADCVREF_PDN_SHIFT) - -#define ES8388_DACDLL_PDN_SHIFT (2) -#define ES8388_DACDLL_PDN_BITMASK (0x01 << ES8388_DACDLL_PDN_SHIFT) -#define ES8388_DACDLL_PDN_NORMAL (0 << ES8388_DACDLL_PDN_SHIFT) -#define ES8388_DACDLL_PDN_PWRDN (1 << ES8388_DACDLL_PDN_SHIFT) - -#define ES8388_ADCDLL_PDN_SHIFT (3) -#define ES8388_ADCDLL_PDN_BITMASK (0x01 << ES8388_ADCDLL_PDN_SHIFT) -#define ES8388_ADCDLL_PDN_NORMAL (0 << ES8388_ADCDLL_PDN_SHIFT) -#define ES8388_ADCDLL_PDN_PWRDN (1 << ES8388_ADCDLL_PDN_SHIFT) - -#define ES8388_DAC_STM_RST_SHIFT (4) -#define ES8388_DAC_STM_RST_BITMASK (0x01 << ES8388_DAC_STM_RST_SHIFT) -#define ES8388_DAC_STM_RST_NORMAL (0 << ES8388_DAC_STM_RST_SHIFT) -#define ES8388_DAC_STM_RST_RESET (1 << ES8388_DAC_STM_RST_SHIFT) - -#define ES8388_ADC_STM_RST_SHIFT (5) -#define ES8388_ADC_STM_RST_BITMASK (0x01 << ES8388_ADC_STM_RST_SHIFT) -#define ES8388_ADC_STM_RST_NORMAL (0 << ES8388_ADC_STM_RST_SHIFT) -#define ES8388_ADC_STM_RST_RESET (1 << ES8388_ADC_STM_RST_SHIFT) - -#define ES8388_DAC_DIGPDN_SHIFT (6) -#define ES8388_DAC_DIGPDN_BITMASK (0x01 << ES8388_DAC_DIGPDN_SHIFT) -#define ES8388_DAC_DIGPDN_NORMAL (0 << ES8388_DAC_DIGPDN_SHIFT) -#define ES8388_DAC_DIGPDN_RESET (1 << ES8388_DAC_DIGPDN_SHIFT) - -#define ES8388_ADC_DIGPDN_SHIFT (7) -#define ES8388_ADC_DIGPDN_BITMASK (0x01 << ES8388_ADC_DIGPDN_SHIFT) -#define ES8388_ADC_DIGPDN_NORMAL (0 << ES8388_ADC_DIGPDN_SHIFT) -#define ES8388_ADC_DIGPDN_RESET (1 << ES8388_ADC_DIGPDN_SHIFT) +#define ES8388_DACVREF_PDN_SHIFT (0) +#define ES8388_DACVREF_PDN_BITMASK (0x01 << ES8388_DACVREF_PDN_SHIFT) +#define ES8388_DACVREF_PDN_PWRUP (0 << ES8388_DACVREF_PDN_SHIFT) +#define ES8388_DACVREF_PDN_PWRDN (1 << ES8388_DACVREF_PDN_SHIFT) + +#define ES8388_ADCVREF_PDN_SHIFT (1) +#define ES8388_ADCVREF_PDN_BITMASK (0x01 << ES8388_ADCVREF_PDN_SHIFT) +#define ES8388_ADCVREF_PDN_PWRUP (0 << ES8388_ADCVREF_PDN_SHIFT) +#define ES8388_ADCVREF_PDN_PWRDN (1 << ES8388_ADCVREF_PDN_SHIFT) + +#define ES8388_DACDLL_PDN_SHIFT (2) +#define ES8388_DACDLL_PDN_BITMASK (0x01 << ES8388_DACDLL_PDN_SHIFT) +#define ES8388_DACDLL_PDN_NORMAL (0 << ES8388_DACDLL_PDN_SHIFT) +#define ES8388_DACDLL_PDN_PWRDN (1 << ES8388_DACDLL_PDN_SHIFT) + +#define ES8388_ADCDLL_PDN_SHIFT (3) +#define ES8388_ADCDLL_PDN_BITMASK (0x01 << ES8388_ADCDLL_PDN_SHIFT) +#define ES8388_ADCDLL_PDN_NORMAL (0 << ES8388_ADCDLL_PDN_SHIFT) +#define ES8388_ADCDLL_PDN_PWRDN (1 << ES8388_ADCDLL_PDN_SHIFT) + +#define ES8388_DAC_STM_RST_SHIFT (4) +#define ES8388_DAC_STM_RST_BITMASK (0x01 << ES8388_DAC_STM_RST_SHIFT) +#define ES8388_DAC_STM_RST_NORMAL (0 << ES8388_DAC_STM_RST_SHIFT) +#define ES8388_DAC_STM_RST_RESET (1 << ES8388_DAC_STM_RST_SHIFT) + +#define ES8388_ADC_STM_RST_SHIFT (5) +#define ES8388_ADC_STM_RST_BITMASK (0x01 << ES8388_ADC_STM_RST_SHIFT) +#define ES8388_ADC_STM_RST_NORMAL (0 << ES8388_ADC_STM_RST_SHIFT) +#define ES8388_ADC_STM_RST_RESET (1 << ES8388_ADC_STM_RST_SHIFT) + +#define ES8388_DAC_DIGPDN_SHIFT (6) +#define ES8388_DAC_DIGPDN_BITMASK (0x01 << ES8388_DAC_DIGPDN_SHIFT) +#define ES8388_DAC_DIGPDN_NORMAL (0 << ES8388_DAC_DIGPDN_SHIFT) +#define ES8388_DAC_DIGPDN_RESET (1 << ES8388_DAC_DIGPDN_SHIFT) + +#define ES8388_ADC_DIGPDN_SHIFT (7) +#define ES8388_ADC_DIGPDN_BITMASK (0x01 << ES8388_ADC_DIGPDN_SHIFT) +#define ES8388_ADC_DIGPDN_NORMAL (0 << ES8388_ADC_DIGPDN_SHIFT) +#define ES8388_ADC_DIGPDN_RESET (1 << ES8388_ADC_DIGPDN_SHIFT) /* 0x03 ADC Power Management */ -#define ES8388_INT1LP_SHIFT (0) -#define ES8388_INT1LP_BITMASK (0x01 << ES8388_INT1LP_SHIFT) -#define ES8388_INT1LP_NORMAL (0 << ES8388_INT1LP_SHIFT) -#define ES8388_INT1LP_LP (1 << ES8388_INT1LP_SHIFT) - -#define ES8388_FLASHLP_SHIFT (1) -#define ES8388_FLASHLP_BITMASK (0x01 << ES8388_FLASHLP_SHIFT) -#define ES8388_FLASHLP_NORMAL (0 << ES8388_FLASHLP_SHIFT) -#define ES8388_FLASHLP_LP (1 << ES8388_FLASHLP_SHIFT) - -#define ES8388_PDNADCBIASGEN_SHIFT (2) -#define ES8388_PDNADCBIASGEN_BITMASK (0x01 << ES8388_PDNADCBIASGEN_SHIFT) -#define ES8388_PDNADCBIASGEN_NORMAL (0 << ES8388_PDNADCBIASGEN_SHIFT) -#define ES8388_PDNADCBIASGEN_LP (1 << ES8388_PDNADCBIASGEN_SHIFT) - -#define ES8388_PDNMICB_SHIFT (3) -#define ES8388_PDNMICB_BITMASK (0x01 << ES8388_PDNMICB_SHIFT) -#define ES8388_PDNMICB_PWRON (0 << ES8388_PDNMICB_SHIFT) -#define ES8388_PDNMICB_PWRDN (1 << ES8388_PDNMICB_SHIFT) - -#define ES8388_PDNADCR_SHIFT (4) -#define ES8388_PDNADCR_BITMASK (0x01 << ES8388_PDNADCR_SHIFT) -#define ES8388_PDNADCR_PWRUP (0 << ES8388_PDNADCR_SHIFT) -#define ES8388_PDNADCR_PWRDN (1 << ES8388_PDNADCR_SHIFT) - -#define ES8388_PDNADCL_SHIFT (5) -#define ES8388_PDNADCL_BITMASK (0x01 << ES8388_PDNADCL_SHIFT) -#define ES8388_PDNADCL_PWRUP (0 << ES8388_PDNADCL_SHIFT) -#define ES8388_PDNADCL_PWRDN (1 << ES8388_PDNADCL_SHIFT) - -#define ES8388_PDNAINR_SHIFT (6) -#define ES8388_PDNAINR_BITMASK (0x01 << ES8388_PDNAINR_SHIFT) -#define ES8388_PDNAINR_NORMAL (0 << ES8388_PDNAINR_SHIFT) -#define ES8388_PDNAINR_PWRDN (1 << ES8388_PDNAINR_SHIFT) - -#define ES8388_PDNAINL_SHIFT (7) -#define ES8388_PDNAINL_BITMASK (0x01 << ES8388_PDNAINL_SHIFT) -#define ES8388_PDNAINL_NORMAL (0 << ES8388_PDNAINL_SHIFT) -#define ES8388_PDNAINL_PWRDN (1 << ES8388_PDNAINL_SHIFT) +#define ES8388_INT1LP_SHIFT (0) +#define ES8388_INT1LP_BITMASK (0x01 << ES8388_INT1LP_SHIFT) +#define ES8388_INT1LP_NORMAL (0 << ES8388_INT1LP_SHIFT) +#define ES8388_INT1LP_LP (1 << ES8388_INT1LP_SHIFT) + +#define ES8388_FLASHLP_SHIFT (1) +#define ES8388_FLASHLP_BITMASK (0x01 << ES8388_FLASHLP_SHIFT) +#define ES8388_FLASHLP_NORMAL (0 << ES8388_FLASHLP_SHIFT) +#define ES8388_FLASHLP_LP (1 << ES8388_FLASHLP_SHIFT) + +#define ES8388_PDNADCBIASGEN_SHIFT (2) +#define ES8388_PDNADCBIASGEN_BITMASK (0x01 << ES8388_PDNADCBIASGEN_SHIFT) +#define ES8388_PDNADCBIASGEN_NORMAL (0 << ES8388_PDNADCBIASGEN_SHIFT) +#define ES8388_PDNADCBIASGEN_LP (1 << ES8388_PDNADCBIASGEN_SHIFT) + +#define ES8388_PDNMICB_SHIFT (3) +#define ES8388_PDNMICB_BITMASK (0x01 << ES8388_PDNMICB_SHIFT) +#define ES8388_PDNMICB_PWRON (0 << ES8388_PDNMICB_SHIFT) +#define ES8388_PDNMICB_PWRDN (1 << ES8388_PDNMICB_SHIFT) + +#define ES8388_PDNADCR_SHIFT (4) +#define ES8388_PDNADCR_BITMASK (0x01 << ES8388_PDNADCR_SHIFT) +#define ES8388_PDNADCR_PWRUP (0 << ES8388_PDNADCR_SHIFT) +#define ES8388_PDNADCR_PWRDN (1 << ES8388_PDNADCR_SHIFT) + +#define ES8388_PDNADCL_SHIFT (5) +#define ES8388_PDNADCL_BITMASK (0x01 << ES8388_PDNADCL_SHIFT) +#define ES8388_PDNADCL_PWRUP (0 << ES8388_PDNADCL_SHIFT) +#define ES8388_PDNADCL_PWRDN (1 << ES8388_PDNADCL_SHIFT) + +#define ES8388_PDNAINR_SHIFT (6) +#define ES8388_PDNAINR_BITMASK (0x01 << ES8388_PDNAINR_SHIFT) +#define ES8388_PDNAINR_NORMAL (0 << ES8388_PDNAINR_SHIFT) +#define ES8388_PDNAINR_PWRDN (1 << ES8388_PDNAINR_SHIFT) + +#define ES8388_PDNAINL_SHIFT (7) +#define ES8388_PDNAINL_BITMASK (0x01 << ES8388_PDNAINL_SHIFT) +#define ES8388_PDNAINL_NORMAL (0 << ES8388_PDNAINL_SHIFT) +#define ES8388_PDNAINL_PWRDN (1 << ES8388_PDNAINL_SHIFT) /* 0x04 DAC Power Management */ -#define ES8388_ROUT2_SHIFT (2) -#define ES8388_ROUT2_BITMASK (0x01 << ES8388_ROUT2_SHIFT) -#define ES8388_ROUT2_DISABLE (0 << ES8388_ROUT2_SHIFT) -#define ES8388_ROUT2_ENABLE (1 << ES8388_ROUT2_SHIFT) +#define ES8388_ROUT2_SHIFT (2) +#define ES8388_ROUT2_BITMASK (0x01 << ES8388_ROUT2_SHIFT) +#define ES8388_ROUT2_DISABLE (0 << ES8388_ROUT2_SHIFT) +#define ES8388_ROUT2_ENABLE (1 << ES8388_ROUT2_SHIFT) -#define ES8388_LOUT2_SHIFT (3) -#define ES8388_LOUT2_BITMASK (0x01 << ES8388_LOUT2_SHIFT) -#define ES8388_LOUT2_DISABLE (0 << ES8388_LOUT2_SHIFT) -#define ES8388_LOUT2_ENABLE (1 << ES8388_LOUT2_SHIFT) +#define ES8388_LOUT2_SHIFT (3) +#define ES8388_LOUT2_BITMASK (0x01 << ES8388_LOUT2_SHIFT) +#define ES8388_LOUT2_DISABLE (0 << ES8388_LOUT2_SHIFT) +#define ES8388_LOUT2_ENABLE (1 << ES8388_LOUT2_SHIFT) -#define ES8388_ROUT1_SHIFT (4) -#define ES8388_ROUT1_BITMASK (0x01 << ES8388_ROUT1_SHIFT) -#define ES8388_ROUT1_DISABLE (0 << ES8388_ROUT1_SHIFT) -#define ES8388_ROUT1_ENABLE (1 << ES8388_ROUT1_SHIFT) +#define ES8388_ROUT1_SHIFT (4) +#define ES8388_ROUT1_BITMASK (0x01 << ES8388_ROUT1_SHIFT) +#define ES8388_ROUT1_DISABLE (0 << ES8388_ROUT1_SHIFT) +#define ES8388_ROUT1_ENABLE (1 << ES8388_ROUT1_SHIFT) -#define ES8388_LOUT1_SHIFT (5) -#define ES8388_LOUT1_BITMASK (0x01 << ES8388_LOUT1_SHIFT) -#define ES8388_LOUT1_DISABLE (0 << ES8388_LOUT1_SHIFT) -#define ES8388_LOUT1_ENABLE (1 << ES8388_LOUT1_SHIFT) +#define ES8388_LOUT1_SHIFT (5) +#define ES8388_LOUT1_BITMASK (0x01 << ES8388_LOUT1_SHIFT) +#define ES8388_LOUT1_DISABLE (0 << ES8388_LOUT1_SHIFT) +#define ES8388_LOUT1_ENABLE (1 << ES8388_LOUT1_SHIFT) -#define ES8388_PDNDACR_SHIFT (6) -#define ES8388_PDNDACR_BITMASK (0x01 << ES8388_PDNDACR_SHIFT) -#define ES8388_PDNDACR_PWRUP (0 << ES8388_PDNDACR_SHIFT) -#define ES8388_PDNDACR_PWRDN (1 << ES8388_PDNDACR_SHIFT) +#define ES8388_PDNDACR_SHIFT (6) +#define ES8388_PDNDACR_BITMASK (0x01 << ES8388_PDNDACR_SHIFT) +#define ES8388_PDNDACR_PWRUP (0 << ES8388_PDNDACR_SHIFT) +#define ES8388_PDNDACR_PWRDN (1 << ES8388_PDNDACR_SHIFT) -#define ES8388_PDNDACL_SHIFT (7) -#define ES8388_PDNDACL_BITMASK (0x01 << ES8388_PDNDACL_SHIFT) -#define ES8388_PDNDACL_PWRUP (0 << ES8388_PDNDACL_SHIFT) -#define ES8388_PDNDACL_PWRDN (1 << ES8388_PDNDACL_SHIFT) +#define ES8388_PDNDACL_SHIFT (7) +#define ES8388_PDNDACL_BITMASK (0x01 << ES8388_PDNDACL_SHIFT) +#define ES8388_PDNDACL_PWRUP (0 << ES8388_PDNDACL_SHIFT) +#define ES8388_PDNDACL_PWRDN (1 << ES8388_PDNDACL_SHIFT) /* 0x05 Chip Low Power 1 */ -#define ES8388_LPLOUT2_SHIFT (3) -#define ES8388_LPLOUT2_BITMASK (0x01 << ES8388_LPLOUT2_SHIFT) -#define ES8388_LPLOUT2_NORMAL (0 << ES8388_LPLOUT2_SHIFT) -#define ES8388_LPLOUT2_LP (1 << ES8388_LPLOUT2_SHIFT) +#define ES8388_LPLOUT2_SHIFT (3) +#define ES8388_LPLOUT2_BITMASK (0x01 << ES8388_LPLOUT2_SHIFT) +#define ES8388_LPLOUT2_NORMAL (0 << ES8388_LPLOUT2_SHIFT) +#define ES8388_LPLOUT2_LP (1 << ES8388_LPLOUT2_SHIFT) -#define ES8388_LPLOUT1_SHIFT (5) -#define ES8388_LPLOUT1_BITMASK (0x01 << ES8388_LPLOUT1_SHIFT) -#define ES8388_LPLOUT1_NORMAL (0 << ES8388_LPLOUT1_SHIFT) -#define ES8388_LPLOUT1_LP (1 << ES8388_LPLOUT1_SHIFT) +#define ES8388_LPLOUT1_SHIFT (5) +#define ES8388_LPLOUT1_BITMASK (0x01 << ES8388_LPLOUT1_SHIFT) +#define ES8388_LPLOUT1_NORMAL (0 << ES8388_LPLOUT1_SHIFT) +#define ES8388_LPLOUT1_LP (1 << ES8388_LPLOUT1_SHIFT) -#define ES8388_LPDACR_SHIFT (6) -#define ES8388_LPDACR_BITMASK (0x01 << ES8388_LPDACR_SHIFT) -#define ES8388_LPDACR_NORMAL (0 << ES8388_LPDACR_SHIFT) -#define ES8388_LPDACR_LP (1 << ES8388_LPDACR_SHIFT) +#define ES8388_LPDACR_SHIFT (6) +#define ES8388_LPDACR_BITMASK (0x01 << ES8388_LPDACR_SHIFT) +#define ES8388_LPDACR_NORMAL (0 << ES8388_LPDACR_SHIFT) +#define ES8388_LPDACR_LP (1 << ES8388_LPDACR_SHIFT) -#define ES8388_LPDACL_SHIFT (7) -#define ES8388_LPDACL_BITMASK (0x01 << ES8388_LPDACL_SHIFT) -#define ES8388_LPDACL_NORMAL (0 << ES8388_LPDACL_SHIFT) -#define ES8388_LPDACL_LP (1 << ES8388_LPDACL_SHIFT) +#define ES8388_LPDACL_SHIFT (7) +#define ES8388_LPDACL_BITMASK (0x01 << ES8388_LPDACL_SHIFT) +#define ES8388_LPDACL_NORMAL (0 << ES8388_LPDACL_SHIFT) +#define ES8388_LPDACL_LP (1 << ES8388_LPDACL_SHIFT) /* 0x06 Chip Low Power 2 */ -#define ES8388_LPDACVRP_SHIFT (0) -#define ES8388_LPDACVRP_BITMASK (0x01 << ES8388_LPDACVRP_SHIFT) -#define ES8388_LPDACVRP_NORMAL (0 << ES8388_LPDACVRP_SHIFT) -#define ES8388_LPDACVRP_LP (1 << ES8388_LPDACVRP_SHIFT) +#define ES8388_LPDACVRP_SHIFT (0) +#define ES8388_LPDACVRP_BITMASK (0x01 << ES8388_LPDACVRP_SHIFT) +#define ES8388_LPDACVRP_NORMAL (0 << ES8388_LPDACVRP_SHIFT) +#define ES8388_LPDACVRP_LP (1 << ES8388_LPDACVRP_SHIFT) -#define ES8388_LPADCVRP_SHIFT (1) -#define ES8388_LPADCVRP_BITMASK (0x01 << ES8388_LPDACVRP_SHIFT) -#define ES8388_LPADCVRP_NORMAL (0 << ES8388_LPDACVRP_SHIFT) -#define ES8388_LPADCVRP_LP (1 << ES8388_LPDACVRP_SHIFT) +#define ES8388_LPADCVRP_SHIFT (1) +#define ES8388_LPADCVRP_BITMASK (0x01 << ES8388_LPDACVRP_SHIFT) +#define ES8388_LPADCVRP_NORMAL (0 << ES8388_LPDACVRP_SHIFT) +#define ES8388_LPADCVRP_LP (1 << ES8388_LPDACVRP_SHIFT) -#define ES8388_LPLMIX_SHIFT (6) -#define ES8388_LPLMIX_BITMASK (0x01 << ES8388_LPLMIX_SHIFT) -#define ES8388_LPLMIX_NORMAL (0 << ES8388_LPLMIX_SHIFT) -#define ES8388_LPLMIX_LP (1 << ES8388_LPLMIX_SHIFT) +#define ES8388_LPLMIX_SHIFT (6) +#define ES8388_LPLMIX_BITMASK (0x01 << ES8388_LPLMIX_SHIFT) +#define ES8388_LPLMIX_NORMAL (0 << ES8388_LPLMIX_SHIFT) +#define ES8388_LPLMIX_LP (1 << ES8388_LPLMIX_SHIFT) -#define ES8388_LPPGA_SHIFT (7) -#define ES8388_LPPGA_BITMASK (0x01 << ES8388_LPPGA_SHIFT) -#define ES8388_LPPGA_NORMAL (0 << ES8388_LPPGA_SHIFT) -#define ES8388_LPPGA_LP (1 << ES8388_LPPGA_SHIFT) +#define ES8388_LPPGA_SHIFT (7) +#define ES8388_LPPGA_BITMASK (0x01 << ES8388_LPPGA_SHIFT) +#define ES8388_LPPGA_NORMAL (0 << ES8388_LPPGA_SHIFT) +#define ES8388_LPPGA_LP (1 << ES8388_LPPGA_SHIFT) /* 0x08 Master Mode Control */ -#define ES8388_BCLKDIV_SHIFT (0) -#define ES8388_BCLKDIV_BITMASK (0x1f << ES8388_BCLKDIV_SHIFT) -#define ES8388_BCLKDIV(a) (a << ES8388_BCLKDIV_SHIFT) +#define ES8388_BCLKDIV_SHIFT (0) +#define ES8388_BCLKDIV_BITMASK (0x1f << ES8388_BCLKDIV_SHIFT) +#define ES8388_BCLKDIV(a) (a << ES8388_BCLKDIV_SHIFT) -#define ES8388_BCLK_INV_SHIFT (5) -#define ES8388_BCLK_INV_BITMASL (0x01 << ES8388_BCLK_INV_SHIFT) -#define ES8388_BCLK_INV_NORMAL (0 << ES8388_BCLK_INV_SHIFT) -#define ES8388_BCLK_INV_INVERTED (1 << ES8388_BCLK_INV_SHIFT) +#define ES8388_BCLK_INV_SHIFT (5) +#define ES8388_BCLK_INV_BITMASL (0x01 << ES8388_BCLK_INV_SHIFT) +#define ES8388_BCLK_INV_NORMAL (0 << ES8388_BCLK_INV_SHIFT) +#define ES8388_BCLK_INV_INVERTED (1 << ES8388_BCLK_INV_SHIFT) -#define ES8388_MCLKDIV2_SHIFT (6) -#define ES8388_MCLKDIV2_BITMASK (0x01 << ES8388_MCLKDIV2_SHIFT) -#define ES8388_MCLKDIV2_NODIV (0 << ES8388_MCLKDIV2_SHIFT) -#define ES8388_MCLKDIV2_DIV2 (1 << ES8388_MCLKDIV2_SHIFT) +#define ES8388_MCLKDIV2_SHIFT (6) +#define ES8388_MCLKDIV2_BITMASK (0x01 << ES8388_MCLKDIV2_SHIFT) +#define ES8388_MCLKDIV2_NODIV (0 << ES8388_MCLKDIV2_SHIFT) +#define ES8388_MCLKDIV2_DIV2 (1 << ES8388_MCLKDIV2_SHIFT) -#define ES8388_MSC_SHIFT (7) -#define ES8388_MSC_BITMASK (0x01 << ES8388_MSC_SHIFT) -#define ES8388_MSC_SLAVE (0 << ES8388_MSC_SHIFT) -#define ES8388_MSC_MASTER (1 << ES8388_MSC_SHIFT) +#define ES8388_MSC_SHIFT (7) +#define ES8388_MSC_BITMASK (0x01 << ES8388_MSC_SHIFT) +#define ES8388_MSC_SLAVE (0 << ES8388_MSC_SHIFT) +#define ES8388_MSC_MASTER (1 << ES8388_MSC_SHIFT) /* 0x09 ADC Control 1 */ -#define ES8388_MICAMPR_SHIFT (0) -#define ES8388_MICAMPR_BITMASK (0x0f << ES8388_MICAMPR_SHIFT) -#define ES8388_MICAMPR(a) (a << ES8388_MICAMPR_SHIFT) +#define ES8388_MICAMPR_SHIFT (0) +#define ES8388_MICAMPR_BITMASK (0x0f << ES8388_MICAMPR_SHIFT) +#define ES8388_MICAMPR(a) (a << ES8388_MICAMPR_SHIFT) -#define ES8388_MICAMPL_SHIFT (4) -#define ES8388_MICAMPL_BITMASK (0x0f << ES8388_MICAMPL_SHIFT) -#define ES8388_MICAMPL(a) (a << ES8388_MICAMPL_SHIFT) +#define ES8388_MICAMPL_SHIFT (4) +#define ES8388_MICAMPL_BITMASK (0x0f << ES8388_MICAMPL_SHIFT) +#define ES8388_MICAMPL(a) (a << ES8388_MICAMPL_SHIFT) /* 0x0a ADC Control 2 */ -#define ES8388_DSR_SHIFT (2) -#define ES8388_DSR_BITMASK (0x01 << ES8388_DSR_SHIFT) -#define ES8388_DSR_LINPUT1_RINPUT1 (0 << ES8388_DSR_SHIFT) -#define ES8388_DSR_LINPUT2_RINPUT2 (1 << ES8388_DSR_SHIFT) +#define ES8388_DSR_SHIFT (2) +#define ES8388_DSR_BITMASK (0x01 << ES8388_DSR_SHIFT) +#define ES8388_DSR_LINPUT1_RINPUT1 (0 << ES8388_DSR_SHIFT) +#define ES8388_DSR_LINPUT2_RINPUT2 (1 << ES8388_DSR_SHIFT) -#define ES8388_DSSEL_SHIFT (3) -#define ES8388_DSSEL_BITMASK (0x01 << ES8388_DSSEL_SHIFT) -#define ES8388_DSSEL_ONE_REG (0 << ES8388_DSSEL_SHIFT) -#define ES8388_DSSEL_MULT_REG (1 << ES8388_DSSEL_SHIFT) +#define ES8388_DSSEL_SHIFT (3) +#define ES8388_DSSEL_BITMASK (0x01 << ES8388_DSSEL_SHIFT) +#define ES8388_DSSEL_ONE_REG (0 << ES8388_DSSEL_SHIFT) +#define ES8388_DSSEL_MULT_REG (1 << ES8388_DSSEL_SHIFT) -#define ES8388_RINSEL_SHIFT (4) -#define ES8388_RINSEL_BITMASK (0x03 << ES8388_RINSEL_SHIFT) -#define ES8388_RINSEL_RINPUT1 (0 << ES8388_RINSEL_SHIFT) -#define ES8388_RINSEL_RINPUT2 (1 << ES8388_RINSEL_SHIFT) -#define ES8388_RINSEL_DIFF (3 << ES8388_RINSEL_SHIFT) +#define ES8388_RINSEL_SHIFT (4) +#define ES8388_RINSEL_BITMASK (0x03 << ES8388_RINSEL_SHIFT) +#define ES8388_RINSEL_RINPUT1 (0 << ES8388_RINSEL_SHIFT) +#define ES8388_RINSEL_RINPUT2 (1 << ES8388_RINSEL_SHIFT) +#define ES8388_RINSEL_DIFF (3 << ES8388_RINSEL_SHIFT) -#define ES8388_LINSEL_SHIFT (6) -#define ES8388_LINSEL_BITMASK (0x03 << ES8388_LINSEL_SHIFT) -#define ES8388_LINSEL_LINPUT1 (0 << ES8388_LINSEL_SHIFT) -#define ES8388_LINSEL_LINPUT2 (1 << ES8388_LINSEL_SHIFT) -#define ES8388_LINSEL_DIFF (3 << ES8388_LINSEL_SHIFT) +#define ES8388_LINSEL_SHIFT (6) +#define ES8388_LINSEL_BITMASK (0x03 << ES8388_LINSEL_SHIFT) +#define ES8388_LINSEL_LINPUT1 (0 << ES8388_LINSEL_SHIFT) +#define ES8388_LINSEL_LINPUT2 (1 << ES8388_LINSEL_SHIFT) +#define ES8388_LINSEL_DIFF (3 << ES8388_LINSEL_SHIFT) /* 0x0b ADC Control 3 */ -#define ES8388_TRI_SHIFT (2) -#define ES8388_TRI_BITMASK (0x01 << ES8388_TRI_SHIFT) -#define ES8388_TRI_NORMAL (0 << ES8388_TRI_SHIFT) -#define ES8388_TRI_TRISTATED (1 << ES8388_TRI_SHIFT) +#define ES8388_TRI_SHIFT (2) +#define ES8388_TRI_BITMASK (0x01 << ES8388_TRI_SHIFT) +#define ES8388_TRI_NORMAL (0 << ES8388_TRI_SHIFT) +#define ES8388_TRI_TRISTATED (1 << ES8388_TRI_SHIFT) -#define ES8388_MONOMIX_SHIFT (3) -#define ES8388_MONOMIX_BITMASK (0x03 << ES8388_MONOMIX_SHIFT) -#define ES8388_MONOMIX_STEREO (0 << ES8388_MONOMIX_SHIFT) -#define ES8388_MONOMIX_LADC (1 << ES8388_MONOMIX_SHIFT) -#define ES8388_MONOMIX_RADC (2 << ES8388_MONOMIX_SHIFT) +#define ES8388_MONOMIX_SHIFT (3) +#define ES8388_MONOMIX_BITMASK (0x03 << ES8388_MONOMIX_SHIFT) +#define ES8388_MONOMIX_STEREO (0 << ES8388_MONOMIX_SHIFT) +#define ES8388_MONOMIX_LADC (1 << ES8388_MONOMIX_SHIFT) +#define ES8388_MONOMIX_RADC (2 << ES8388_MONOMIX_SHIFT) -#define ES8388_DS_SHIFT (7) -#define ES8388_DS_BITMASK (0x01 << ES8388_DS_SHIFT) -#define ES8388_DS_LINPUT1_RINPUT1 (0 << ES8388_DS_SHIFT) -#define ES8388_DS_LINPUT2_RINPUT2 (1 << ES8388_DS_SHIFT) +#define ES8388_DS_SHIFT (7) +#define ES8388_DS_BITMASK (0x01 << ES8388_DS_SHIFT) +#define ES8388_DS_LINPUT1_RINPUT1 (0 << ES8388_DS_SHIFT) +#define ES8388_DS_LINPUT2_RINPUT2 (1 << ES8388_DS_SHIFT) /* 0x0c ADC Control 4 */ -#define ES8388_ADCFORMAT_SHIFT (0) -#define ES8388_ADCFORMAT_BITMASK (0x03 << ES8388_ADCFORMAT_SHIFT) -#define ES8388_ADCFORMAT(a) (a << ES8388_ADCFORMAT_SHIFT) +#define ES8388_ADCFORMAT_SHIFT (0) +#define ES8388_ADCFORMAT_BITMASK (0x03 << ES8388_ADCFORMAT_SHIFT) +#define ES8388_ADCFORMAT(a) (a << ES8388_ADCFORMAT_SHIFT) -#define ES8388_ADCWL_SHIFT (2) -#define ES8388_ADCWL_BITMASK (0x07 << ES8388_ADCWL_SHIFT) -#define ES8388_ADCWL(a) (a << ES8388_ADCWL_SHIFT) +#define ES8388_ADCWL_SHIFT (2) +#define ES8388_ADCWL_BITMASK (0x07 << ES8388_ADCWL_SHIFT) +#define ES8388_ADCWL(a) (a << ES8388_ADCWL_SHIFT) -#define ES8388_ADCLRP_SHIFT (5) -#define ES8388_ADCLRP_BITMASK (0x01 << ES8388_ADCLRP_SHIFT) -#define ES8388_ADCLRP_NORM_2ND (0 << ES8388_ADCLRP_SHIFT) -#define ES8388_ADCLRP_INV_1ST (1 << ES8388_ADCLRP_SHIFT) +#define ES8388_ADCLRP_SHIFT (5) +#define ES8388_ADCLRP_BITMASK (0x01 << ES8388_ADCLRP_SHIFT) +#define ES8388_ADCLRP_NORM_2ND (0 << ES8388_ADCLRP_SHIFT) +#define ES8388_ADCLRP_INV_1ST (1 << ES8388_ADCLRP_SHIFT) -#define ES8388_DATSEL_SHIFT (6) -#define ES8388_DATSEL_BITMASK (0x03 << ES8388_DATSEL_SHIFT) -#define ES8388_DATSEL_LL (0 << ES8388_DATSEL_SHIFT) -#define ES8388_DATSEL_LR (1 << ES8388_DATSEL_SHIFT) -#define ES8388_DATSEL_RR (2 << ES8388_DATSEL_SHIFT) -#define ES8388_DATSEL_RL (3 << ES8388_DATSEL_SHIFT) +#define ES8388_DATSEL_SHIFT (6) +#define ES8388_DATSEL_BITMASK (0x03 << ES8388_DATSEL_SHIFT) +#define ES8388_DATSEL_LL (0 << ES8388_DATSEL_SHIFT) +#define ES8388_DATSEL_LR (1 << ES8388_DATSEL_SHIFT) +#define ES8388_DATSEL_RR (2 << ES8388_DATSEL_SHIFT) +#define ES8388_DATSEL_RL (3 << ES8388_DATSEL_SHIFT) /* 0x0d ADC Control 5 */ -#define ES8388_ADCFSRATIO_SHIFT (0) -#define ES8388_ADCFSRATIO_BITMASK (0x1f << ES8388_ADCFSRATIO_SHIFT) -#define ES8388_ADCFSRATIO(a) (a << ES8388_ADCFSRATIO_SHIFT) +#define ES8388_ADCFSRATIO_SHIFT (0) +#define ES8388_ADCFSRATIO_BITMASK (0x1f << ES8388_ADCFSRATIO_SHIFT) +#define ES8388_ADCFSRATIO(a) (a << ES8388_ADCFSRATIO_SHIFT) -#define ES8388_ADCFSMODE_SHIFT (5) -#define ES8388_ADCFSMODE_BITMASK (0x01 << ES8388_ADCFSMODE_SHIFT) -#define ES8388_ADCFSMODE_SINGLE (0 << ES8388_ADCFSMODE_SHIFT) -#define ES8388_ADCFSMODE_DOUBLE (1 << ES8388_ADCFSMODE_SHIFT) +#define ES8388_ADCFSMODE_SHIFT (5) +#define ES8388_ADCFSMODE_BITMASK (0x01 << ES8388_ADCFSMODE_SHIFT) +#define ES8388_ADCFSMODE_SINGLE (0 << ES8388_ADCFSMODE_SHIFT) +#define ES8388_ADCFSMODE_DOUBLE (1 << ES8388_ADCFSMODE_SHIFT) /* 0x0e ADC Control 6 */ -#define ES8388_ADC_HPF_R_SHIFT (4) -#define ES8388_ADC_HPF_R_BITMASK (0x01 << ES8388_ADC_HPF_R_SHIFT) -#define ES8388_ADC_HPF_R_DISABLE (0 << ES8388_ADC_HPF_R_SHIFT) -#define ES8388_ADC_HPF_R_ENABLE (1 << ES8388_ADC_HPF_R_SHIFT) +#define ES8388_ADC_HPF_R_SHIFT (4) +#define ES8388_ADC_HPF_R_BITMASK (0x01 << ES8388_ADC_HPF_R_SHIFT) +#define ES8388_ADC_HPF_R_DISABLE (0 << ES8388_ADC_HPF_R_SHIFT) +#define ES8388_ADC_HPF_R_ENABLE (1 << ES8388_ADC_HPF_R_SHIFT) -#define ES8388_ADC_HPF_L_SHIFT (5) -#define ES8388_ADC_HPF_L_BITMASK (0x01 << ES8388_ADC_HPF_L_SHIFT) -#define ES8388_ADC_HPF_L_DISABLE (0 << ES8388_ADC_HPF_L_SHIFT) -#define ES8388_ADC_HPF_L_ENABLE (1 << ES8388_ADC_HPF_L_SHIFT) +#define ES8388_ADC_HPF_L_SHIFT (5) +#define ES8388_ADC_HPF_L_BITMASK (0x01 << ES8388_ADC_HPF_L_SHIFT) +#define ES8388_ADC_HPF_L_DISABLE (0 << ES8388_ADC_HPF_L_SHIFT) +#define ES8388_ADC_HPF_L_ENABLE (1 << ES8388_ADC_HPF_L_SHIFT) -#define ES8388_ADC_INVR_SHIFT (6) -#define ES8388_ADC_INVR_BITMASK (0x01 << ES8388_ADC_INVR_SHIFT) -#define ES8388_ADC_INVR_NORMAL (0 << ES8388_ADC_INVR_SHIFT) -#define ES8388_ADC_INVR_INVERTED (1 << ES8388_ADC_INVR_SHIFT) +#define ES8388_ADC_INVR_SHIFT (6) +#define ES8388_ADC_INVR_BITMASK (0x01 << ES8388_ADC_INVR_SHIFT) +#define ES8388_ADC_INVR_NORMAL (0 << ES8388_ADC_INVR_SHIFT) +#define ES8388_ADC_INVR_INVERTED (1 << ES8388_ADC_INVR_SHIFT) -#define ES8388_ADC_INVL_SHIFT (7) -#define ES8388_ADC_INVL_BITMASK (0x01 << ES8388_ADC_INVL_SHIFT) -#define ES8388_ADC_INVL_NORMAL (0 << ES8388_ADC_INVL_SHIFT) -#define ES8388_ADC_INVL_INVERTED (1 << ES8388_ADC_INVL_SHIFT) +#define ES8388_ADC_INVL_SHIFT (7) +#define ES8388_ADC_INVL_BITMASK (0x01 << ES8388_ADC_INVL_SHIFT) +#define ES8388_ADC_INVL_NORMAL (0 << ES8388_ADC_INVL_SHIFT) +#define ES8388_ADC_INVL_INVERTED (1 << ES8388_ADC_INVL_SHIFT) /* 0x0f ADC Control 7 */ -#define ES8388_ADCMUTE_SHIFT (2) -#define ES8388_ADCMUTE_BITMASK (0x01 << ES8388_ADCMUTE_SHIFT) -#define ES8388_ADCMUTE(a) (((int)a) << ES8388_ADCMUTE_SHIFT) -#define ES8388_ADCMUTE_NORMAL (0 << ES8388_ADCMUTE_SHIFT) -#define ES8388_ADCMUTE_MUTED (1 << ES8388_ADCMUTE_SHIFT) - -#define ES8388_ADCLER_SHIFT (3) -#define ES8388_ADCLER_BITMASK (0x01 << ES8388_ADCLER_SHIFT) -#define ES8388_ADCLER_NORMAL (0 << ES8388_ADCLER_SHIFT) -#define ES8388_ADCLER_ADCLEFT (1 << ES8388_ADCLER_SHIFT) - -#define ES8388_ADCSOFTRAMP_SHIFT (5) -#define ES8388_ADCSOFTRAMP_BITMASK (0x01 << ES8388_ADCSOFTRAMP_SHIFT) -#define ES8388_ADCSOFTRAMP_DISABLE (0 << ES8388_ADCSOFTRAMP_SHIFT) -#define ES8388_ADCSOFTRAMP_ENABLE (1 << ES8388_ADCSOFTRAMP_SHIFT) - -#define ES8388_ADCRAMPRATE_SHIFT (6) -#define ES8388_ADCRAMPRATE_BITMASK (0x03 << ES8388_ADCRAMPRATE_SHIFT) -#define ES8388_ADCRAMPRATE_4LRCK (0 << ES8388_ADCRAMPRATE_SHIFT) -#define ES8388_ADCRAMPRATE_8LRCK (1 << ES8388_ADCRAMPRATE_SHIFT) -#define ES8388_ADCRAMPRATE_16LRCK (2 << ES8388_ADCRAMPRATE_SHIFT) -#define ES8388_ADCRAMPRATE_32LRCK (3 << ES8388_ADCRAMPRATE_SHIFT) +#define ES8388_ADCMUTE_SHIFT (2) +#define ES8388_ADCMUTE_BITMASK (0x01 << ES8388_ADCMUTE_SHIFT) +#define ES8388_ADCMUTE(a) (((int)a) << ES8388_ADCMUTE_SHIFT) +#define ES8388_ADCMUTE_NORMAL (0 << ES8388_ADCMUTE_SHIFT) +#define ES8388_ADCMUTE_MUTED (1 << ES8388_ADCMUTE_SHIFT) + +#define ES8388_ADCLER_SHIFT (3) +#define ES8388_ADCLER_BITMASK (0x01 << ES8388_ADCLER_SHIFT) +#define ES8388_ADCLER_NORMAL (0 << ES8388_ADCLER_SHIFT) +#define ES8388_ADCLER_ADCLEFT (1 << ES8388_ADCLER_SHIFT) + +#define ES8388_ADCSOFTRAMP_SHIFT (5) +#define ES8388_ADCSOFTRAMP_BITMASK (0x01 << ES8388_ADCSOFTRAMP_SHIFT) +#define ES8388_ADCSOFTRAMP_DISABLE (0 << ES8388_ADCSOFTRAMP_SHIFT) +#define ES8388_ADCSOFTRAMP_ENABLE (1 << ES8388_ADCSOFTRAMP_SHIFT) + +#define ES8388_ADCRAMPRATE_SHIFT (6) +#define ES8388_ADCRAMPRATE_BITMASK (0x03 << ES8388_ADCRAMPRATE_SHIFT) +#define ES8388_ADCRAMPRATE_4LRCK (0 << ES8388_ADCRAMPRATE_SHIFT) +#define ES8388_ADCRAMPRATE_8LRCK (1 << ES8388_ADCRAMPRATE_SHIFT) +#define ES8388_ADCRAMPRATE_16LRCK (2 << ES8388_ADCRAMPRATE_SHIFT) +#define ES8388_ADCRAMPRATE_32LRCK (3 << ES8388_ADCRAMPRATE_SHIFT) /* 0x10 ADC Control 8 */ -#define ES8388_LADCVOL_SHIFT (0) -#define ES8388_LADCVOL_BITMASK (0xff << ES8388_LADCVOL_SHIFT) -#define ES8388_LADCVOL(a) (a << ES8388_LADCVOL_SHIFT) +#define ES8388_LADCVOL_SHIFT (0) +#define ES8388_LADCVOL_BITMASK (0xff << ES8388_LADCVOL_SHIFT) +#define ES8388_LADCVOL(a) (a << ES8388_LADCVOL_SHIFT) /* 0x11 ADC Control 9 */ -#define ES8388_RADCVOL_SHIFT (0) -#define ES8388_RADCVOL_BITMASK (0xff << ES8388_RADCVOL_SHIFT) -#define ES8388_RADCVOL(a) (a << ES8388_RADCVOL_SHIFT) +#define ES8388_RADCVOL_SHIFT (0) +#define ES8388_RADCVOL_BITMASK (0xff << ES8388_RADCVOL_SHIFT) +#define ES8388_RADCVOL(a) (a << ES8388_RADCVOL_SHIFT) /* 0x12 ADC Control 10 */ -#define ES8388_MINGAIN_SHIFT (0) -#define ES8388_MINGAIN_BITMASK (0x07 << ES8388_MINGAIN_SHIFT) -#define ES8388_MINGAIN(a) (a << ES8388_MINGAIN_SHIFT) +#define ES8388_MINGAIN_SHIFT (0) +#define ES8388_MINGAIN_BITMASK (0x07 << ES8388_MINGAIN_SHIFT) +#define ES8388_MINGAIN(a) (a << ES8388_MINGAIN_SHIFT) -#define ES8388_MAXGAIN_SHIFT (3) -#define ES8388_MAXGAIN_BITMASK (0x07 << ES8388_MAXGAIN_SHIFT) -#define ES8388_MAXGAIN(a) (a << ES8388_MAXGAIN_SHIFT) +#define ES8388_MAXGAIN_SHIFT (3) +#define ES8388_MAXGAIN_BITMASK (0x07 << ES8388_MAXGAIN_SHIFT) +#define ES8388_MAXGAIN(a) (a << ES8388_MAXGAIN_SHIFT) -#define ES8388_ADCSEL_SHIFT (6) -#define ES8388_ADCSEL_BITMASK (0x03 << ES8388_ADCSEL_SHIFT) -#define ES8388_ADCSEL_OFF (0 << ES8388_ADCSEL_SHIFT) -#define ES8388_ADCSEL_RIGHT (1 << ES8388_ADCSEL_SHIFT) -#define ES8388_ADCSEL_LEFT (2 << ES8388_ADCSEL_SHIFT) -#define ES8388_ADCSEL_STEREO (3 << ES8388_ADCSEL_SHIFT) +#define ES8388_ADCSEL_SHIFT (6) +#define ES8388_ADCSEL_BITMASK (0x03 << ES8388_ADCSEL_SHIFT) +#define ES8388_ADCSEL_OFF (0 << ES8388_ADCSEL_SHIFT) +#define ES8388_ADCSEL_RIGHT (1 << ES8388_ADCSEL_SHIFT) +#define ES8388_ADCSEL_LEFT (2 << ES8388_ADCSEL_SHIFT) +#define ES8388_ADCSEL_STEREO (3 << ES8388_ADCSEL_SHIFT) /* 0x13 ADC Control 11 */ -#define ES8388_ALCHLD_SHIFT (0) -#define ES8388_ALCHLD_BITMASK (0x0f << ES8388_ALCHLD_SHIFT) -#define ES8388_ALCHLD(a) (a << ES8388_ALCHLD_SHIFT) +#define ES8388_ALCHLD_SHIFT (0) +#define ES8388_ALCHLD_BITMASK (0x0f << ES8388_ALCHLD_SHIFT) +#define ES8388_ALCHLD(a) (a << ES8388_ALCHLD_SHIFT) -#define ES8388_ALCLVL_SHIFT (4) -#define ES8388_ALCLVL_BITMASK (0x0f << ES8388_ALCLVL_SHIFT) -#define ES8388_ALCLVL(a) (a << ES8388_ALCLVL_SHIFT) +#define ES8388_ALCLVL_SHIFT (4) +#define ES8388_ALCLVL_BITMASK (0x0f << ES8388_ALCLVL_SHIFT) +#define ES8388_ALCLVL(a) (a << ES8388_ALCLVL_SHIFT) /* 0x14 ADC Control 12 */ -#define ES8388_ALCATK_SHIFT (0) -#define ES8388_ALCATK_BITMASK (0x0f << ES8388_ALCATK_SHIFT) -#define ES8388_ALCATK(a) (a << ES8388_ALCATK_SHIFT) +#define ES8388_ALCATK_SHIFT (0) +#define ES8388_ALCATK_BITMASK (0x0f << ES8388_ALCATK_SHIFT) +#define ES8388_ALCATK(a) (a << ES8388_ALCATK_SHIFT) -#define ES8388_ALCDCY_SHIFT (4) -#define ES8388_ALCDCY_BITMASK (0x0f << ES8388_ALCDCY_SHIFT) -#define ES8388_ALCDCY(a) (a << ES8388_ALCDCY_SHIFT) +#define ES8388_ALCDCY_SHIFT (4) +#define ES8388_ALCDCY_BITMASK (0x0f << ES8388_ALCDCY_SHIFT) +#define ES8388_ALCDCY(a) (a << ES8388_ALCDCY_SHIFT) /* 0x15 ADC Control 13 */ -#define ES8388_WIN_SIZE_SHIFT (0) -#define ES8388_WIN_SIZE_BITMASK (0x1f << ES8388_WIN_SIZE_SHIFT) -#define ES8388_WIN_SIZE(a) (a << ES8388_WIN_SIZE_SHIFT) +#define ES8388_WIN_SIZE_SHIFT (0) +#define ES8388_WIN_SIZE_BITMASK (0x1f << ES8388_WIN_SIZE_SHIFT) +#define ES8388_WIN_SIZE(a) (a << ES8388_WIN_SIZE_SHIFT) -#define ES8388_TIME_OUT_SHIFT (5) -#define ES8388_TIME_OUT_BITMASK (0x01 << ES8388_TIME_OUT_SHIFT) -#define ES8388_TIME_OUT_DISABLE (0 << ES8388_TIME_OUT_SHIFT) -#define ES8388_TIME_OUT_ENABLE (1 << ES8388_TIME_OUT_SHIFT) +#define ES8388_TIME_OUT_SHIFT (5) +#define ES8388_TIME_OUT_BITMASK (0x01 << ES8388_TIME_OUT_SHIFT) +#define ES8388_TIME_OUT_DISABLE (0 << ES8388_TIME_OUT_SHIFT) +#define ES8388_TIME_OUT_ENABLE (1 << ES8388_TIME_OUT_SHIFT) -#define ES8388_ALCZC_SHIFT (6) -#define ES8388_ALCZC_BITMASK (0x01 << ES8388_ALCZC_SHIFT) -#define ES8388_ALCZC_DISABLE (0 << ES8388_ALCZC_SHIFT) -#define ES8388_ALCZC_ENABLE (1 << ES8388_ALCZC_SHIFT) +#define ES8388_ALCZC_SHIFT (6) +#define ES8388_ALCZC_BITMASK (0x01 << ES8388_ALCZC_SHIFT) +#define ES8388_ALCZC_DISABLE (0 << ES8388_ALCZC_SHIFT) +#define ES8388_ALCZC_ENABLE (1 << ES8388_ALCZC_SHIFT) -#define ES8388_ALCMODE_SHIFT (7) -#define ES8388_ALCMODE_BITMASK (0x01 << ES8388_ALCMODE_SHIFT) -#define ES8388_ALCMODE_NORMAL (0 << ES8388_ALCMODE_SHIFT) -#define ES8388_ALCMODE_LIMITER (1 << ES8388_ALCMODE_SHIFT) +#define ES8388_ALCMODE_SHIFT (7) +#define ES8388_ALCMODE_BITMASK (0x01 << ES8388_ALCMODE_SHIFT) +#define ES8388_ALCMODE_NORMAL (0 << ES8388_ALCMODE_SHIFT) +#define ES8388_ALCMODE_LIMITER (1 << ES8388_ALCMODE_SHIFT) /* 0x16 ADC Control 14 */ -#define ES8388_NGAT_SHIFT (0) -#define ES8388_NGAT_BITMASK (0x01 << ES8388_NGAT_SHIFT) -#define ES8388_NGAT_DISABLE (0 << ES8388_NGAT_SHIFT) -#define ES8388_NGAT_ENABLE (1 << ES8388_NGAT_SHIFT) +#define ES8388_NGAT_SHIFT (0) +#define ES8388_NGAT_BITMASK (0x01 << ES8388_NGAT_SHIFT) +#define ES8388_NGAT_DISABLE (0 << ES8388_NGAT_SHIFT) +#define ES8388_NGAT_ENABLE (1 << ES8388_NGAT_SHIFT) -#define ES8388_NGG_SHIFT (1) -#define ES8388_NGG_BITMASK (0x01 << ES8388_NGG_SHIFT) -#define ES8388_NGG_CONST (0 << ES8388_NGG_SHIFT) -#define ES8388_NGG_MUTE (1 << ES8388_NGG_SHIFT) +#define ES8388_NGG_SHIFT (1) +#define ES8388_NGG_BITMASK (0x01 << ES8388_NGG_SHIFT) +#define ES8388_NGG_CONST (0 << ES8388_NGG_SHIFT) +#define ES8388_NGG_MUTE (1 << ES8388_NGG_SHIFT) -#define ES8388_NGTH_SHIFT (3) -#define ES8388_NGTH_BITMASK (0x1f << ES8388_NGTH_SHIFT) -#define ES8388_NGTH(a) (a << ES8388_NGTH_SHIFT) +#define ES8388_NGTH_SHIFT (3) +#define ES8388_NGTH_BITMASK (0x1f << ES8388_NGTH_SHIFT) +#define ES8388_NGTH(a) (a << ES8388_NGTH_SHIFT) /* 0x17 DAC Control 1 */ -#define ES8388_DACFORMAT_SHIFT (1) -#define ES8388_DACFORMAT_BITMASK (0x03 << ES8388_DACFORMAT_SHIFT) -#define ES8388_DACFORMAT(a) (a << ES8388_DACFORMAT_SHIFT) +#define ES8388_DACFORMAT_SHIFT (1) +#define ES8388_DACFORMAT_BITMASK (0x03 << ES8388_DACFORMAT_SHIFT) +#define ES8388_DACFORMAT(a) (a << ES8388_DACFORMAT_SHIFT) -#define ES8388_DACWL_SHIFT (3) -#define ES8388_DACWL_BITMASK (0x07 << ES8388_DACWL_SHIFT) -#define ES8388_DACWL(a) (a << ES8388_DACWL_SHIFT) +#define ES8388_DACWL_SHIFT (3) +#define ES8388_DACWL_BITMASK (0x07 << ES8388_DACWL_SHIFT) +#define ES8388_DACWL(a) (a << ES8388_DACWL_SHIFT) -#define ES8388_DACLRP_SHIFT (6) -#define ES8388_DACLRP_BITMASK (0x01 << ES8388_DACLRP_SHIFT) -#define ES8388_DACLRP_NORM_2ND (0 << ES8388_DACLRP_SHIFT) -#define ES8388_DACLRP_INV_1ST (1 << ES8388_DACLRP_SHIFT) +#define ES8388_DACLRP_SHIFT (6) +#define ES8388_DACLRP_BITMASK (0x01 << ES8388_DACLRP_SHIFT) +#define ES8388_DACLRP_NORM_2ND (0 << ES8388_DACLRP_SHIFT) +#define ES8388_DACLRP_INV_1ST (1 << ES8388_DACLRP_SHIFT) -#define ES8388_DACLRSWAP_SHIFT (7) -#define ES8388_DACLRSWAP_BITMASK (0x01 << ES8388_DACLRSWAP_SHIFT) -#define ES8388_DACLRSWAP_NORMAL (0 << ES8388_DACLRSWAP_SHIFT) -#define ES8388_DACLRSWAP_SWAP (1 << ES8388_DACLRSWAP_SHIFT) +#define ES8388_DACLRSWAP_SHIFT (7) +#define ES8388_DACLRSWAP_BITMASK (0x01 << ES8388_DACLRSWAP_SHIFT) +#define ES8388_DACLRSWAP_NORMAL (0 << ES8388_DACLRSWAP_SHIFT) +#define ES8388_DACLRSWAP_SWAP (1 << ES8388_DACLRSWAP_SHIFT) /* 0x18 DAC Control 2 */ -#define ES8388_DACFSRATIO_SHIFT (0) -#define ES8388_DACFSRATIO_BITMASK (0x1f << ES8388_DACFSRATIO_SHIFT) -#define ES8388_DACFSRATIO(a) (a << ES8388_DACFSRATIO_SHIFT) +#define ES8388_DACFSRATIO_SHIFT (0) +#define ES8388_DACFSRATIO_BITMASK (0x1f << ES8388_DACFSRATIO_SHIFT) +#define ES8388_DACFSRATIO(a) (a << ES8388_DACFSRATIO_SHIFT) -#define ES8388_DACFSMODE_SHIFT (5) -#define ES8388_DACFSMODE_BITMASK (0x01 << ES8388_DACFSMODE_SHIFT) -#define ES8388_DACFSMODE_SINGLE (0 << ES8388_DACFSMODE_SHIFT) -#define ES8388_DACFSMODE_DOUBLE (1 << ES8388_DACFSMODE_SHIFT) +#define ES8388_DACFSMODE_SHIFT (5) +#define ES8388_DACFSMODE_BITMASK (0x01 << ES8388_DACFSMODE_SHIFT) +#define ES8388_DACFSMODE_SINGLE (0 << ES8388_DACFSMODE_SHIFT) +#define ES8388_DACFSMODE_DOUBLE (1 << ES8388_DACFSMODE_SHIFT) /* 0x19 DAC Control 3 */ -#define ES8388_DACMUTE_SHIFT (2) -#define ES8388_DACMUTE_BITMASK (0x01 << ES8388_DACMUTE_SHIFT) -#define ES8388_DACMUTE(a) (((int)a) << ES8388_DACMUTE_SHIFT) -#define ES8388_DACMUTE_NORMAL (0 << ES8388_DACMUTE_SHIFT) -#define ES8388_DACMUTE_MUTED (1 << ES8388_DACMUTE_SHIFT) - -#define ES8388_DACLER_SHIFT (3) -#define ES8388_DACLER_BITMASK (0x01 << ES8388_DACLER_SHIFT) -#define ES8388_DACLER_NORMAL (0 << ES8388_DACLER_SHIFT) -#define ES8388_DACLER_ADCLEFT (1 << ES8388_DACLER_SHIFT) - -#define ES8388_DACSOFTRAMP_SHIFT (5) -#define ES8388_DACSOFTRAMP_BITMASK (0x01 << ES8388_DACSOFTRAMP_SHIFT) -#define ES8388_DACSOFTRAMP_DISABLE (0 << ES8388_DACSOFTRAMP_SHIFT) -#define ES8388_DACSOFTRAMP_ENABLE (1 << ES8388_DACSOFTRAMP_SHIFT) - -#define ES8388_DACRAMPRATE_SHIFT (6) -#define ES8388_DACRAMPRATE_BITMASK (0x03 << ES8388_DACRAMPRATE_SHIFT) -#define ES8388_DACRAMPRATE_4LRCK (0 << ES8388_DACRAMPRATE_SHIFT) -#define ES8388_DACRAMPRATE_32LRCK (1 << ES8388_DACRAMPRATE_SHIFT) -#define ES8388_DACRAMPRATE_64LRCK (2 << ES8388_DACRAMPRATE_SHIFT) -#define ES8388_DACRAMPRATE_128LRCK (3 << ES8388_DACRAMPRATE_SHIFT) +#define ES8388_DACMUTE_SHIFT (2) +#define ES8388_DACMUTE_BITMASK (0x01 << ES8388_DACMUTE_SHIFT) +#define ES8388_DACMUTE(a) (((int)a) << ES8388_DACMUTE_SHIFT) +#define ES8388_DACMUTE_NORMAL (0 << ES8388_DACMUTE_SHIFT) +#define ES8388_DACMUTE_MUTED (1 << ES8388_DACMUTE_SHIFT) + +#define ES8388_DACLER_SHIFT (3) +#define ES8388_DACLER_BITMASK (0x01 << ES8388_DACLER_SHIFT) +#define ES8388_DACLER_NORMAL (0 << ES8388_DACLER_SHIFT) +#define ES8388_DACLER_ADCLEFT (1 << ES8388_DACLER_SHIFT) + +#define ES8388_DACSOFTRAMP_SHIFT (5) +#define ES8388_DACSOFTRAMP_BITMASK (0x01 << ES8388_DACSOFTRAMP_SHIFT) +#define ES8388_DACSOFTRAMP_DISABLE (0 << ES8388_DACSOFTRAMP_SHIFT) +#define ES8388_DACSOFTRAMP_ENABLE (1 << ES8388_DACSOFTRAMP_SHIFT) + +#define ES8388_DACRAMPRATE_SHIFT (6) +#define ES8388_DACRAMPRATE_BITMASK (0x03 << ES8388_DACRAMPRATE_SHIFT) +#define ES8388_DACRAMPRATE_4LRCK (0 << ES8388_DACRAMPRATE_SHIFT) +#define ES8388_DACRAMPRATE_32LRCK (1 << ES8388_DACRAMPRATE_SHIFT) +#define ES8388_DACRAMPRATE_64LRCK (2 << ES8388_DACRAMPRATE_SHIFT) +#define ES8388_DACRAMPRATE_128LRCK (3 << ES8388_DACRAMPRATE_SHIFT) /* 0x1a DAC Control 4 */ -#define ES8388_LDACVOL_SHIFT (0) -#define ES8388_LDACVOL_BITMASK (0xff << ES8388_LDACVOL_SHIFT) -#define ES8388_LDACVOL(a) (a << ES8388_LDACVOL_SHIFT) +#define ES8388_LDACVOL_SHIFT (0) +#define ES8388_LDACVOL_BITMASK (0xff << ES8388_LDACVOL_SHIFT) +#define ES8388_LDACVOL(a) (a << ES8388_LDACVOL_SHIFT) /* 0x1b DAC Control 5 */ -#define ES8388_RDACVOL_SHIFT (0) -#define ES8388_RDACVOL_BITMASK (0xff << ES8388_RDACVOL_SHIFT) -#define ES8388_RDACVOL(a) (a << ES8388_RDACVOL_SHIFT) +#define ES8388_RDACVOL_SHIFT (0) +#define ES8388_RDACVOL_BITMASK (0xff << ES8388_RDACVOL_SHIFT) +#define ES8388_RDACVOL(a) (a << ES8388_RDACVOL_SHIFT) /* 0x1c DAC Control 6 */ -#define ES8388_CLICKFREE_SHIFT (3) -#define ES8388_CLICKFREE_BITMASK (0x01 << ES8388_CLICKFREE_SHIFT) -#define ES8388_CLICKFREE_DISABLE (0 << ES8388_CLICKFREE_SHIFT) -#define ES8388_CLICKFREE_ENABLE (1 << ES8388_CLICKFREE_SHIFT) +#define ES8388_CLICKFREE_SHIFT (3) +#define ES8388_CLICKFREE_BITMASK (0x01 << ES8388_CLICKFREE_SHIFT) +#define ES8388_CLICKFREE_DISABLE (0 << ES8388_CLICKFREE_SHIFT) +#define ES8388_CLICKFREE_ENABLE (1 << ES8388_CLICKFREE_SHIFT) -#define ES8388_DAC_INVR_SHIFT (4) -#define ES8388_DAC_INVR_BITMASK (0x01 << ES8388_DAC_INVR_SHIFT) -#define ES8388_DAC_INVR_NOINV (0 << ES8388_DAC_INVR_SHIFT) -#define ES8388_DAC_INVR_180INV (1 << ES8388_DAC_INVR_SHIFT) +#define ES8388_DAC_INVR_SHIFT (4) +#define ES8388_DAC_INVR_BITMASK (0x01 << ES8388_DAC_INVR_SHIFT) +#define ES8388_DAC_INVR_NOINV (0 << ES8388_DAC_INVR_SHIFT) +#define ES8388_DAC_INVR_180INV (1 << ES8388_DAC_INVR_SHIFT) -#define ES8388_DAC_INVL_SHIFT (5) -#define ES8388_DAC_INVL_BITMASK (0x01 << ES8388_DAC_INVL_SHIFT) -#define ES8388_DAC_INVL_NOINV (0 << ES8388_DAC_INVL_SHIFT) -#define ES8388_DAC_INVL_180INV (1 << ES8388_DAC_INVL_SHIFT) +#define ES8388_DAC_INVL_SHIFT (5) +#define ES8388_DAC_INVL_BITMASK (0x01 << ES8388_DAC_INVL_SHIFT) +#define ES8388_DAC_INVL_NOINV (0 << ES8388_DAC_INVL_SHIFT) +#define ES8388_DAC_INVL_180INV (1 << ES8388_DAC_INVL_SHIFT) -#define ES8388_DEEMP_SHIFT (6) -#define ES8388_DEEMP_BITMASK (0x03 << ES8388_DEEMP_SHIFT) -#define ES8388_DEEMP_DISABLE (0 << ES8388_DEEMP_SHIFT) -#define ES8388_DEEMP_32KHZ (1 << ES8388_DEEMP_SHIFT) -#define ES8388_DEEMP_44KHZ (2 << ES8388_DEEMP_SHIFT) -#define ES8388_DEEMP_48KHZ (3 << ES8388_DEEMP_SHIFT) +#define ES8388_DEEMP_SHIFT (6) +#define ES8388_DEEMP_BITMASK (0x03 << ES8388_DEEMP_SHIFT) +#define ES8388_DEEMP_DISABLE (0 << ES8388_DEEMP_SHIFT) +#define ES8388_DEEMP_32KHZ (1 << ES8388_DEEMP_SHIFT) +#define ES8388_DEEMP_44KHZ (2 << ES8388_DEEMP_SHIFT) +#define ES8388_DEEMP_48KHZ (3 << ES8388_DEEMP_SHIFT) /* 0x1d DAC Control 7 */ -#define ES8388_VPP_SCALE_SHIFT (0) -#define ES8388_VPP_SCALE_BITMASK (0x03 << ES8388_VPP_SCALE_SHIFT) -#define ES8388_VPP_SCALE_3_5V (0 << ES8388_VPP_SCALE_SHIFT) -#define ES8388_VPP_SCALE_4_0V (1 << ES8388_VPP_SCALE_SHIFT) -#define ES8388_VPP_SCALE_3_0V (2 << ES8388_VPP_SCALE_SHIFT) -#define ES8388_VPP_SCALE_2_5V (3 << ES8388_VPP_SCALE_SHIFT) +#define ES8388_VPP_SCALE_SHIFT (0) +#define ES8388_VPP_SCALE_BITMASK (0x03 << ES8388_VPP_SCALE_SHIFT) +#define ES8388_VPP_SCALE_3_5V (0 << ES8388_VPP_SCALE_SHIFT) +#define ES8388_VPP_SCALE_4_0V (1 << ES8388_VPP_SCALE_SHIFT) +#define ES8388_VPP_SCALE_3_0V (2 << ES8388_VPP_SCALE_SHIFT) +#define ES8388_VPP_SCALE_2_5V (3 << ES8388_VPP_SCALE_SHIFT) -#define ES8388_SE_SHIFT (2) -#define ES8388_SE_BITMASK (0x07 << ES8388_SE_SHIFT) -#define ES8388_SE(a) (a << ES8388_SE_SHIFT) +#define ES8388_SE_SHIFT (2) +#define ES8388_SE_BITMASK (0x07 << ES8388_SE_SHIFT) +#define ES8388_SE(a) (a << ES8388_SE_SHIFT) -#define ES8388_MONO_SHIFT (5) -#define ES8388_MONO_BITMASK (0x01 << ES8388_MONO_SHIFT) -#define ES8388_MONO_STEREO (0 << ES8388_MONO_SHIFT) -#define ES8388_MONO_MONO (1 << ES8388_MONO_SHIFT) +#define ES8388_MONO_SHIFT (5) +#define ES8388_MONO_BITMASK (0x01 << ES8388_MONO_SHIFT) +#define ES8388_MONO_STEREO (0 << ES8388_MONO_SHIFT) +#define ES8388_MONO_MONO (1 << ES8388_MONO_SHIFT) -#define ES8388_ZEROR_SHIFT (6) -#define ES8388_ZEROR_BITMASK (0x01 << ES8388_ZEROR_SHIFT) -#define ES8388_ZEROR_NORMAL (0 << ES8388_ZEROR_SHIFT) -#define ES8388_ZEROR_ZERO (1 << ES8388_ZEROR_SHIFT) +#define ES8388_ZEROR_SHIFT (6) +#define ES8388_ZEROR_BITMASK (0x01 << ES8388_ZEROR_SHIFT) +#define ES8388_ZEROR_NORMAL (0 << ES8388_ZEROR_SHIFT) +#define ES8388_ZEROR_ZERO (1 << ES8388_ZEROR_SHIFT) -#define ES8388_ZEROL_SHIFT (7) -#define ES8388_ZEROL_BITMASK (0x01 << ES8388_ZEROL_SHIFT) -#define ES8388_ZEROL_NORMAL (0 << ES8388_ZEROL_SHIFT) -#define ES8388_ZEROL_ZERO (1 << ES8388_ZEROL_SHIFT) +#define ES8388_ZEROL_SHIFT (7) +#define ES8388_ZEROL_BITMASK (0x01 << ES8388_ZEROL_SHIFT) +#define ES8388_ZEROL_NORMAL (0 << ES8388_ZEROL_SHIFT) +#define ES8388_ZEROL_ZERO (1 << ES8388_ZEROL_SHIFT) /* 0x1e DAC Control 8 * 0x1f DAC Control 9 @@ -740,164 +740,161 @@ * 0x25 DAC Control 15 */ -#define ES8388_SHELVING_COEF_SHIFT (0) -#define ES8388_SHELVING_COEF_BITMASK (0xff << ES8388_SHELVING_COEF_SHIFT) -#define ES8388_SHELVING_COEF(a) (a << ES8388_SHELVING_COEF_SHIFT) +#define ES8388_SHELVING_COEF_SHIFT (0) +#define ES8388_SHELVING_COEF_BITMASK (0xff << ES8388_SHELVING_COEF_SHIFT) +#define ES8388_SHELVING_COEF(a) (a << ES8388_SHELVING_COEF_SHIFT) /* 0x26 DAC Control 16 */ -#define ES8388_RMIXSEL_SHIFT (0) -#define ES8388_RMIXSEL_BITMASK (0x07 << ES8388_RMIXSEL_SHIFT) -#define ES8388_RMIXSEL_RIN1 (0 << ES8388_RMIXSEL_SHIFT) -#define ES8388_RMIXSEL_RIN2 (1 << ES8388_RMIXSEL_SHIFT) -#define ES8388_RMIXSEL_PIN (3 << ES8388_RMIXSEL_SHIFT) -#define ES8388_RMIXSEL_NIN (4 << ES8388_RMIXSEL_SHIFT) +#define ES8388_RMIXSEL_SHIFT (0) +#define ES8388_RMIXSEL_BITMASK (0x07 << ES8388_RMIXSEL_SHIFT) +#define ES8388_RMIXSEL_RIN1 (0 << ES8388_RMIXSEL_SHIFT) +#define ES8388_RMIXSEL_RIN2 (1 << ES8388_RMIXSEL_SHIFT) +#define ES8388_RMIXSEL_PIN (3 << ES8388_RMIXSEL_SHIFT) +#define ES8388_RMIXSEL_NIN (4 << ES8388_RMIXSEL_SHIFT) -#define ES8388_LMIXSEL_SHIFT (3) -#define ES8388_LMIXSEL_BITMASK (0x07 << ES8388_LMIXSEL_SHIFT) -#define ES8388_LMIXSEL_LIN1 (0 << ES8388_LMIXSEL_SHIFT) -#define ES8388_LMIXSEL_LIN2 (1 << ES8388_LMIXSEL_SHIFT) -#define ES8388_LMIXSEL_PIN (3 << ES8388_LMIXSEL_SHIFT) -#define ES8388_LMIXSEL_NIN (4 << ES8388_LMIXSEL_SHIFT) +#define ES8388_LMIXSEL_SHIFT (3) +#define ES8388_LMIXSEL_BITMASK (0x07 << ES8388_LMIXSEL_SHIFT) +#define ES8388_LMIXSEL_LIN1 (0 << ES8388_LMIXSEL_SHIFT) +#define ES8388_LMIXSEL_LIN2 (1 << ES8388_LMIXSEL_SHIFT) +#define ES8388_LMIXSEL_PIN (3 << ES8388_LMIXSEL_SHIFT) +#define ES8388_LMIXSEL_NIN (4 << ES8388_LMIXSEL_SHIFT) /* 0x27 DAC Control 17 */ -#define ES8388_LI2LOVOL_SHIFT (3) -#define ES8388_LI2LOVOL_BITMASK (0x07 << ES8388_LI2LOVOL_SHIFT) -#define ES8388_LI2LOVOL(a) (a << ES8388_LI2LOVOL_SHIFT) +#define ES8388_LI2LOVOL_SHIFT (3) +#define ES8388_LI2LOVOL_BITMASK (0x07 << ES8388_LI2LOVOL_SHIFT) +#define ES8388_LI2LOVOL(a) (a << ES8388_LI2LOVOL_SHIFT) -#define ES8388_LI2LO_SHIFT (6) -#define ES8388_LI2LO_BITMASK (0x01 << ES8388_LI2LO_SHIFT) -#define ES8388_LI2LO_DISABLE (0 << ES8388_LI2LO_SHIFT) -#define ES8388_LI2LO_ENABLE (1 << ES8388_LI2LO_SHIFT) +#define ES8388_LI2LO_SHIFT (6) +#define ES8388_LI2LO_BITMASK (0x01 << ES8388_LI2LO_SHIFT) +#define ES8388_LI2LO_DISABLE (0 << ES8388_LI2LO_SHIFT) +#define ES8388_LI2LO_ENABLE (1 << ES8388_LI2LO_SHIFT) -#define ES8388_LD2LO_SHIFT (7) -#define ES8388_LD2LO_BITMASK (0x01 << ES8388_LD2LO_SHIFT) -#define ES8388_LD2LO_DISABLE (0 << ES8388_LD2LO_SHIFT) -#define ES8388_LD2LO_ENABLE (1 << ES8388_LD2LO_SHIFT) +#define ES8388_LD2LO_SHIFT (7) +#define ES8388_LD2LO_BITMASK (0x01 << ES8388_LD2LO_SHIFT) +#define ES8388_LD2LO_DISABLE (0 << ES8388_LD2LO_SHIFT) +#define ES8388_LD2LO_ENABLE (1 << ES8388_LD2LO_SHIFT) /* 0x2a DAC Control 20 */ -#define ES8388_RI2ROVOL_SHIFT (3) -#define ES8388_RI2ROVOL_BITMASK (0x07 << ES8388_RI2ROVOL_SHIFT) -#define ES8388_RI2ROVOL(a) (a << ES8388_RI2ROVOL_SHIFT) +#define ES8388_RI2ROVOL_SHIFT (3) +#define ES8388_RI2ROVOL_BITMASK (0x07 << ES8388_RI2ROVOL_SHIFT) +#define ES8388_RI2ROVOL(a) (a << ES8388_RI2ROVOL_SHIFT) -#define ES8388_RI2RO_SHIFT (6) -#define ES8388_RI2RO_BITMASK (0x01 << ES8388_RI2RO_SHIFT) -#define ES8388_RI2RO_DISABLE (0 << ES8388_RI2RO_SHIFT) -#define ES8388_RI2RO_ENABLE (1 << ES8388_RI2RO_SHIFT) +#define ES8388_RI2RO_SHIFT (6) +#define ES8388_RI2RO_BITMASK (0x01 << ES8388_RI2RO_SHIFT) +#define ES8388_RI2RO_DISABLE (0 << ES8388_RI2RO_SHIFT) +#define ES8388_RI2RO_ENABLE (1 << ES8388_RI2RO_SHIFT) -#define ES8388_RD2RO_SHIFT (7) -#define ES8388_RD2RO_BITMASK (0x01 << ES8388_RD2RO_SHIFT) -#define ES8388_RD2RO_DISABLE (0 << ES8388_RD2RO_SHIFT) -#define ES8388_RD2RO_ENABLE (1 << ES8388_RD2RO_SHIFT) +#define ES8388_RD2RO_SHIFT (7) +#define ES8388_RD2RO_BITMASK (0x01 << ES8388_RD2RO_SHIFT) +#define ES8388_RD2RO_DISABLE (0 << ES8388_RD2RO_SHIFT) +#define ES8388_RD2RO_ENABLE (1 << ES8388_RD2RO_SHIFT) /* 0x2b DAC Control 21 */ -#define ES8388_DAC_DLL_PWD_SHIFT (2) -#define ES8388_DAC_DLL_PWD_BITMASK (0x01 << ES8388_DAC_DLL_PWD_SHIFT) -#define ES8388_DAC_DLL_PWD_NORMAL (0 << ES8388_DAC_DLL_PWD_SHIFT) -#define ES8388_DAC_DLL_PWD_PWRDN (1 << ES8388_DAC_DLL_PWD_SHIFT) +#define ES8388_DAC_DLL_PWD_SHIFT (2) +#define ES8388_DAC_DLL_PWD_BITMASK (0x01 << ES8388_DAC_DLL_PWD_SHIFT) +#define ES8388_DAC_DLL_PWD_NORMAL (0 << ES8388_DAC_DLL_PWD_SHIFT) +#define ES8388_DAC_DLL_PWD_PWRDN (1 << ES8388_DAC_DLL_PWD_SHIFT) -#define ES8388_ADC_DLL_PWD_SHIFT (3) -#define ES8388_ADC_DLL_PWD_BITMASK (0x01 << ES8388_ADC_DLL_PWD_SHIFT) -#define ES8388_ADC_DLL_PWD_NORMAL (0 << ES8388_ADC_DLL_PWD_SHIFT) -#define ES8388_ADC_DLL_PWD_PWRDN (1 << ES8388_ADC_DLL_PWD_SHIFT) +#define ES8388_ADC_DLL_PWD_SHIFT (3) +#define ES8388_ADC_DLL_PWD_BITMASK (0x01 << ES8388_ADC_DLL_PWD_SHIFT) +#define ES8388_ADC_DLL_PWD_NORMAL (0 << ES8388_ADC_DLL_PWD_SHIFT) +#define ES8388_ADC_DLL_PWD_PWRDN (1 << ES8388_ADC_DLL_PWD_SHIFT) -#define ES8388_MCLK_DIS_SHIFT (4) -#define ES8388_MCLK_DIS_BITMASK (0x01 << ES8388_MCLK_DIS_SHIFT) -#define ES8388_MCLK_DIS_NORMAL (0 << ES8388_MCLK_DIS_SHIFT) -#define ES8388_MCLK_DIS_DISABLE (1 << ES8388_MCLK_DIS_SHIFT) +#define ES8388_MCLK_DIS_SHIFT (4) +#define ES8388_MCLK_DIS_BITMASK (0x01 << ES8388_MCLK_DIS_SHIFT) +#define ES8388_MCLK_DIS_NORMAL (0 << ES8388_MCLK_DIS_SHIFT) +#define ES8388_MCLK_DIS_DISABLE (1 << ES8388_MCLK_DIS_SHIFT) -#define ES8388_OFFSET_DIS_SHIFT (5) -#define ES8388_OFFSET_DIS_BITMASK (0x01 << ES8388_OFFSET_DIS_SHIFT) -#define ES8388_OFFSET_DIS_DISABLE (0 << ES8388_OFFSET_DIS_SHIFT) -#define ES8388_OFFSET_DIS_ENABLE (1 << ES8388_OFFSET_DIS_SHIFT) +#define ES8388_OFFSET_DIS_SHIFT (5) +#define ES8388_OFFSET_DIS_BITMASK (0x01 << ES8388_OFFSET_DIS_SHIFT) +#define ES8388_OFFSET_DIS_DISABLE (0 << ES8388_OFFSET_DIS_SHIFT) +#define ES8388_OFFSET_DIS_ENABLE (1 << ES8388_OFFSET_DIS_SHIFT) -#define ES8388_LRCK_SEL_SHIFT (6) -#define ES8388_LRCK_SEL_BITMASK (0x01 << ES8388_LRCK_SEL_SHIFT) -#define ES8388_LRCK_SEL_DAC (0 << ES8388_LRCK_SEL_SHIFT) -#define ES8388_LRCK_SEL_ADC (1 << ES8388_LRCK_SEL_SHIFT) +#define ES8388_LRCK_SEL_SHIFT (6) +#define ES8388_LRCK_SEL_BITMASK (0x01 << ES8388_LRCK_SEL_SHIFT) +#define ES8388_LRCK_SEL_DAC (0 << ES8388_LRCK_SEL_SHIFT) +#define ES8388_LRCK_SEL_ADC (1 << ES8388_LRCK_SEL_SHIFT) -#define ES8388_SLRCK_SHIFT (7) -#define ES8388_SLRCK_BITMASK (0x01 << ES8388_SLRCK_SHIFT) -#define ES8388_SLRCK_SEPARATE (0 << ES8388_SLRCK_SHIFT) -#define ES8388_SLRCK_SAME (1 << ES8388_SLRCK_SHIFT) +#define ES8388_SLRCK_SHIFT (7) +#define ES8388_SLRCK_BITMASK (0x01 << ES8388_SLRCK_SHIFT) +#define ES8388_SLRCK_SEPARATE (0 << ES8388_SLRCK_SHIFT) +#define ES8388_SLRCK_SAME (1 << ES8388_SLRCK_SHIFT) /* 0x2c DAC Control 22 */ -#define ES8388_OFFSET_SHIFT (0) -#define ES8388_OFFSET_BITMASK (0xff << ES8388_OFFSET_SHIFT) -#define ES8388_OFFSET(a) (a << ES8388_OFFSET_SHIFT) +#define ES8388_OFFSET_SHIFT (0) +#define ES8388_OFFSET_BITMASK (0xff << ES8388_OFFSET_SHIFT) +#define ES8388_OFFSET(a) (a << ES8388_OFFSET_SHIFT) /* 0x2d DAC Control 23 */ -#define ES8388_VROI_SHIFT (4) -#define ES8388_VROI_BITMASK (0x01 << ES8388_VROI_SHIFT) -#define ES8388_VROI_1_5K (0 << ES8388_VROI_SHIFT) -#define ES8388_VROI_40K (1 << ES8388_VROI_SHIFT) +#define ES8388_VROI_SHIFT (4) +#define ES8388_VROI_BITMASK (0x01 << ES8388_VROI_SHIFT) +#define ES8388_VROI_1_5K (0 << ES8388_VROI_SHIFT) +#define ES8388_VROI_40K (1 << ES8388_VROI_SHIFT) /* 0x2e DAC Control 24 */ -#define ES8388_LOUT1VOL_SHIFT (0) -#define ES8388_LOUT1VOL_BITMASK (0x3f << ES8388_LOUT1VOL_SHIFT) -#define ES8388_LOUT1VOL(a) (a << ES8388_LOUT1VOL_SHIFT) +#define ES8388_LOUT1VOL_SHIFT (0) +#define ES8388_LOUT1VOL_BITMASK (0x3f << ES8388_LOUT1VOL_SHIFT) +#define ES8388_LOUT1VOL(a) (a << ES8388_LOUT1VOL_SHIFT) /* 0x2f DAC Control 25 */ -#define ES8388_ROUT1VOL_SHIFT (0) -#define ES8388_ROUT1VOL_BITMASK (0x3f << ES8388_ROUT1VOL_SHIFT) -#define ES8388_ROUT1VOL(a) (a << ES8388_ROUT1VOL_SHIFT) +#define ES8388_ROUT1VOL_SHIFT (0) +#define ES8388_ROUT1VOL_BITMASK (0x3f << ES8388_ROUT1VOL_SHIFT) +#define ES8388_ROUT1VOL(a) (a << ES8388_ROUT1VOL_SHIFT) /* 0x30 DAC Control 26 */ -#define ES8388_LOUT2VOL_SHIFT (0) -#define ES8388_LOUT2VOL_BITMASK (0x3f << ES8388_LOUT2VOL_SHIFT) -#define ES8388_LOUT2VOL(a) (a << ES8388_LOUT2VOL_SHIFT) +#define ES8388_LOUT2VOL_SHIFT (0) +#define ES8388_LOUT2VOL_BITMASK (0x3f << ES8388_LOUT2VOL_SHIFT) +#define ES8388_LOUT2VOL(a) (a << ES8388_LOUT2VOL_SHIFT) /* 0x31 DAC Control 27 */ -#define ES8388_ROUT2VOL_SHIFT (0) -#define ES8388_ROUT2VOL_BITMASK (0x3f << ES8388_ROUT2VOL_SHIFT) -#define ES8388_ROUT2VOL(a) (a << ES8388_ROUT2VOL_SHIFT) +#define ES8388_ROUT2VOL_SHIFT (0) +#define ES8388_ROUT2VOL_BITMASK (0x3f << ES8388_ROUT2VOL_SHIFT) +#define ES8388_ROUT2VOL(a) (a << ES8388_ROUT2VOL_SHIFT) /* Codec Default Parameters *************************************************/ -#define ES8388_DEFAULT_SAMPRATE 44100 -#define ES8388_DEFAULT_NCHANNELS 2 -#define ES8388_DEFAULT_BPSAMP 16 -#define ES8388_DEFAULT_VOL_OUT 250 -#define ES8388_DEFAULT_VOL_IN 1000 -#define ES8388_DEFAULT_BALANCE 500 -#define ES8388_DEFAULT_MUTE true -#define ES8388_DEFAULT_AUDIO_MODE ES_MODULE_ADC_DAC -#define ES8388_DEFAULT_DAC_OUTPUT ES8388_DAC_OUTPUT_ALL -#define ES8388_DEFAULT_ADC_INPUT ES8388_ADC_INPUT_LINE1 -#define ES8388_DEFAULT_MIC_GAIN ES_MIC_GAIN_24DB -#define ES8388_DEFAULT_MODE ES_MODE_SLAVE -#define ES8388_DEFAULT_FMT ES_I2S_NORMAL +#define ES8388_DEFAULT_SAMPRATE 44100 +#define ES8388_DEFAULT_NCHANNELS 2 +#define ES8388_DEFAULT_BPSAMP 16 +#define ES8388_DEFAULT_VOL_OUT 250 +#define ES8388_DEFAULT_VOL_IN 1000 +#define ES8388_DEFAULT_BALANCE 500 +#define ES8388_DEFAULT_MUTE true +#define ES8388_DEFAULT_AUDIO_MODE ES_MODULE_ADC_DAC +#define ES8388_DEFAULT_DAC_OUTPUT ES8388_DAC_OUTPUT_ALL +#define ES8388_DEFAULT_ADC_INPUT ES8388_ADC_INPUT_LINE1 +#define ES8388_DEFAULT_MIC_GAIN ES_MIC_GAIN_24DB +#define ES8388_DEFAULT_MODE ES_MODE_SLAVE +#define ES8388_DEFAULT_FMT ES_I2S_NORMAL /**************************************************************************** * Public Types ****************************************************************************/ -typedef enum -{ +typedef enum { ES8388_DAC_OUTPUT_LINE1, ES8388_DAC_OUTPUT_LINE2, ES8388_DAC_OUTPUT_ALL, } es8388_dac_output_e; -typedef enum -{ +typedef enum { ES8388_ADC_INPUT_LINE1, ES8388_ADC_INPUT_LINE2, ES8388_ADC_INPUT_ALL, ES8388_ADC_INPUT_DIFFERENCE, } es8388_adc_input_e; -typedef enum -{ +typedef enum { ES8388_MIXER_GAIN_6DB, ES8388_MIXER_GAIN_3DB, ES8388_MIXER_GAIN_0DB, @@ -908,8 +905,7 @@ typedef enum ES8388_MIXER_GAIN_N15DB, } es8388_mixer_gain_e; -typedef enum -{ +typedef enum { ES_WORD_LENGTH_16BITS = 0x03, ES_WORD_LENGTH_18BITS = 0x02, ES_WORD_LENGTH_20BITS = 0x01, @@ -917,8 +913,7 @@ typedef enum ES_WORD_LENGTH_32BITS = 0x04 } es_word_length_e; -typedef enum -{ +typedef enum { ES_MCLK_DIV_AUTO, ES_MCLK_DIV_1, ES_MCLK_DIV_2, @@ -953,8 +948,7 @@ typedef enum ES_MCLK_DIV_14 } es_sclk_div_e; -typedef enum -{ +typedef enum { ES_LCLK_DIV_128 = 0, ES_LCLK_DIV_192 = 1, ES_LCLK_DIV_256 = 2, @@ -982,14 +976,12 @@ typedef enum ES_LCLK_DIV_1500 = 27 } es_lclk_div_e; -typedef enum -{ +typedef enum { ES_D2SE_PGA_GAIN_DIS, ES_D2SE_PGA_GAIN_EN } es_d2se_pga_e; -typedef enum -{ +typedef enum { ES_ADC_CHANNEL_LINPUT1_RINPUT1 = 0x00, ES_ADC_CHANNEL_MIC1 = 0x05, ES_ADC_CHANNEL_MIC2 = 0x06, @@ -997,8 +989,7 @@ typedef enum ES_ADC_CHANNEL_DIFFERENCE = 0xf0 } es_adc_channel_e; -typedef enum -{ +typedef enum { ES_DAC_CHANNEL_LOUT1 = 0x04, ES_DAC_CHANNEL_LOUT2 = 0x08, ES_DAC_CHANNEL_SPK = 0x09, @@ -1007,8 +998,7 @@ typedef enum ES_DAC_CHANNEL_ALL = 0x3c } es_dac_channel_e; -typedef enum -{ +typedef enum { ES_MIC_GAIN_0DB, ES_MIC_GAIN_3DB, ES_MIC_GAIN_6DB, @@ -1020,22 +1010,19 @@ typedef enum ES_MIC_GAIN_24DB } es_mic_gain_e; -typedef enum -{ +typedef enum { ES_MODULE_ADC = 1, ES_MODULE_DAC, ES_MODULE_ADC_DAC, ES_MODULE_LINE } es_module_e; -typedef enum -{ +typedef enum { ES_MODE_SLAVE, ES_MODE_MASTER } es_mode_e; -typedef enum -{ +typedef enum { ES_I2S_NORMAL, ES_I2S_LEFT, ES_I2S_RIGHT, @@ -1046,48 +1033,47 @@ typedef enum * Class Definitions ****************************************************************************/ -class ES8388 -{ - private: - TwoWire* _i2c; /* The I2C bus */ - I2SClass* _i2s; /* The I2S bus */ - uint8_t _addr; /* The I2C address */ - es_i2s_fmt_e _fmt; /* The current I2S format */ - es_mode_e _mode; /* The current codec mode */ - uint32_t _samprate; /* Configured samprate (samples/sec) */ - uint16_t _balance; /* Current balance level {0..1000} */ - uint16_t _volume_out; /* Current output volume level {0..1000} */ - uint16_t _volume_in; /* Current input volume level {0..1000} */ - uint8_t _nchannels; /* Number of channels (1 or 2) */ - uint8_t _bpsamp; /* Bits per sample */ - bool _mute; /* True: Output is muted */ - es_module_e _audio_mode; /* The current audio mode of the ES8388 chip */ - es8388_dac_output_e _dac_output; /* The current output of the ES8388 DAC */ - es8388_adc_input_e _adc_input; /* The current input of the ES8388 ADC */ - es_mic_gain_e _mic_gain; /* The current microphone gain */ - bool _running; /* True: The ES8388 is running */ - es_lclk_div_e _lclk_div; /* The current LCLK divider */ - es_word_length_e _word_length; /* The current word length (enum of _bpsamp) */ - - void reset(); - void start(); - void stop(); - void setvolume(es_module_e module, uint16_t volume, uint16_t balance); - void setmute(es_module_e module, bool enable); - - public: - ~ES8388(); - bool begin(I2SClass& i2s, TwoWire& i2c = Wire, uint8_t addr = 0x10); - void end(); - void playWAV(uint8_t* data, size_t len); - uint8_t* recordWAV(size_t rec_seconds, size_t* out_size); - uint8_t readReg(uint8_t reg); - void writeReg(uint8_t reg, uint8_t data); - void setOutputVolume(uint16_t volume, uint16_t balance); - void setInputVolume(uint16_t volume, uint16_t balance); - void setOutputMute(bool enable); - void setInputMute(bool enable); - void setBitsPerSample(uint8_t bpsamp); - void setSampleRate(uint32_t rate); - void setMicGain(uint8_t gain); +class ES8388 { +private: + TwoWire* _i2c; /* The I2C bus */ + I2SClass* _i2s; /* The I2S bus */ + uint8_t _addr; /* The I2C address */ + es_i2s_fmt_e _fmt; /* The current I2S format */ + es_mode_e _mode; /* The current codec mode */ + uint32_t _samprate; /* Configured samprate (samples/sec) */ + uint16_t _balance; /* Current balance level {0..1000} */ + uint16_t _volume_out; /* Current output volume level {0..1000} */ + uint16_t _volume_in; /* Current input volume level {0..1000} */ + uint8_t _nchannels; /* Number of channels (1 or 2) */ + uint8_t _bpsamp; /* Bits per sample */ + bool _mute; /* True: Output is muted */ + es_module_e _audio_mode; /* The current audio mode of the ES8388 chip */ + es8388_dac_output_e _dac_output; /* The current output of the ES8388 DAC */ + es8388_adc_input_e _adc_input; /* The current input of the ES8388 ADC */ + es_mic_gain_e _mic_gain; /* The current microphone gain */ + bool _running; /* True: The ES8388 is running */ + es_lclk_div_e _lclk_div; /* The current LCLK divider */ + es_word_length_e _word_length; /* The current word length (enum of _bpsamp) */ + + void reset(); + void start(); + void stop(); + void setvolume(es_module_e module, uint16_t volume, uint16_t balance); + void setmute(es_module_e module, bool enable); + +public: + ~ES8388(); + bool begin(I2SClass& i2s, TwoWire& i2c = Wire, uint8_t addr = 0x10); + void end(); + void playWAV(uint8_t* data, size_t len); + uint8_t* recordWAV(size_t rec_seconds, size_t* out_size); + uint8_t readReg(uint8_t reg); + void writeReg(uint8_t reg, uint8_t data); + void setOutputVolume(uint16_t volume, uint16_t balance); + void setInputVolume(uint16_t volume, uint16_t balance); + void setOutputMute(bool enable); + void setInputMute(bool enable); + void setBitsPerSample(uint8_t bpsamp); + void setSampleRate(uint32_t rate); + void setMicGain(uint8_t gain); }; diff --git a/libraries/ESP_I2S/examples/ES8388_loopback/ES8388_loopback.ino b/libraries/ESP_I2S/examples/ES8388_loopback/ES8388_loopback.ino index e709e7df428..c937c3a3f5a 100644 --- a/libraries/ESP_I2S/examples/ES8388_loopback/ES8388_loopback.ino +++ b/libraries/ESP_I2S/examples/ES8388_loopback/ES8388_loopback.ino @@ -23,14 +23,14 @@ const uint8_t I2C_SDA = 18; const uint32_t I2C_FREQ = 400000; /* I2S */ -const uint8_t I2S_MCLK = 0; /* Master clock */ -const uint8_t I2S_SCK = 5; /* Audio data bit clock */ -const uint8_t I2S_WS = 25; /* Audio data left and right clock */ -const uint8_t I2S_SDOUT = 26; /* ESP32 audio data output (to speakers) */ -const uint8_t I2S_SDIN = 35; /* ESP32 audio data input (from microphone) */ +const uint8_t I2S_MCLK = 0; /* Master clock */ +const uint8_t I2S_SCK = 5; /* Audio data bit clock */ +const uint8_t I2S_WS = 25; /* Audio data left and right clock */ +const uint8_t I2S_SDOUT = 26; /* ESP32 audio data output (to speakers) */ +const uint8_t I2S_SDIN = 35; /* ESP32 audio data input (from microphone) */ /* PA */ -const uint8_t PA_ENABLE = 21; /* Power amplifier enable */ +const uint8_t PA_ENABLE = 21; /* Power amplifier enable */ void setup() { I2SClass i2s; diff --git a/libraries/ESP_I2S/examples/Record_to_WAV/Record_to_WAV.ino b/libraries/ESP_I2S/examples/Record_to_WAV/Record_to_WAV.ino index 6d3fe038b00..3ab3e5d63a0 100644 --- a/libraries/ESP_I2S/examples/Record_to_WAV/Record_to_WAV.ino +++ b/libraries/ESP_I2S/examples/Record_to_WAV/Record_to_WAV.ino @@ -55,7 +55,7 @@ void setup() { } // Mount the SD card - if(!SD_MMC.begin("/sdcard", true)){ + if (!SD_MMC.begin("/sdcard", true)) { Serial.println("Failed to initialize SD card!"); return; } diff --git a/libraries/ESP_I2S/examples/Simple_tone/Simple_tone.ino b/libraries/ESP_I2S/examples/Simple_tone/Simple_tone.ino index a9da190cf43..ff47fde7f83 100644 --- a/libraries/ESP_I2S/examples/Simple_tone/Simple_tone.ino +++ b/libraries/ESP_I2S/examples/Simple_tone/Simple_tone.ino @@ -28,17 +28,17 @@ #include -const int frequency = 440; // frequency of square wave in Hz -const int amplitude = 500; // amplitude of square wave -const int sampleRate = 8000; // sample rate in Hz +const int frequency = 440; // frequency of square wave in Hz +const int amplitude = 500; // amplitude of square wave +const int sampleRate = 8000; // sample rate in Hz i2s_data_bit_width_t bps = I2S_DATA_BIT_WIDTH_16BIT; i2s_mode_t mode = I2S_MODE_STD; i2s_slot_mode_t slot = I2S_SLOT_MODE_STEREO; -const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave +const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave -int32_t sample = amplitude; // current sample value +int32_t sample = amplitude; // current sample value int count = 0; I2SClass i2s; @@ -50,19 +50,20 @@ void setup() { // start I2S at the sample rate with 16-bits per sample if (!i2s.begin(mode, sampleRate, bps, slot)) { Serial.println("Failed to initialize I2S!"); - while (1); // do nothing + while (1) + ; // do nothing } } void loop() { - if (count % halfWavelength == 0 ) { - // invert the sample every half wavelength count multiple to generate square wave - sample = -1 * sample; - } + if (count % halfWavelength == 0) { + // invert the sample every half wavelength count multiple to generate square wave + sample = -1 * sample; + } - i2s.write(sample); // Right channel - i2s.write(sample); // Left channel + i2s.write(sample); // Right channel + i2s.write(sample); // Left channel - // increment the counter for the next sample - count++; + // increment the counter for the next sample + count++; } diff --git a/libraries/ESP_I2S/library.properties b/libraries/ESP_I2S/library.properties index d4e3e409071..a2e7b021fad 100755 --- a/libraries/ESP_I2S/library.properties +++ b/libraries/ESP_I2S/library.properties @@ -6,4 +6,4 @@ sentence=Library for ESP I2S communication paragraph=Supports ESP32 Arduino platforms. category=Sound url=https://github.com/espressif/arduino-esp32/ -architectures=esp32 \ No newline at end of file +architectures=esp32 diff --git a/libraries/ESP_I2S/src/ESP_I2S.cpp b/libraries/ESP_I2S/src/ESP_I2S.cpp index 7f65dfa8698..edc0c3c8a5a 100644 --- a/libraries/ESP_I2S/src/ESP_I2S.cpp +++ b/libraries/ESP_I2S/src/ESP_I2S.cpp @@ -11,142 +11,150 @@ #define I2S_READ_CHUNK_SIZE 1920 -#define I2S_DEFAULT_CFG() { \ - .id = I2S_NUM_AUTO, \ - .role = I2S_ROLE_MASTER, \ - .dma_desc_num = 6, \ - .dma_frame_num = 240, \ - .auto_clear = true, \ -} - -#define I2S_STD_CHAN_CFG(_sample_rate, _data_bit_width, _slot_mode) \ - { \ - .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(_sample_rate), \ - .slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(_data_bit_width, _slot_mode), \ - .gpio_cfg = { \ - .mclk = (gpio_num_t)_mclk, \ - .bclk = (gpio_num_t)_bclk, \ - .ws = (gpio_num_t)_ws, \ - .dout = (gpio_num_t)_dout, \ - .din = (gpio_num_t)_din, \ - .invert_flags = { \ - .mclk_inv = _mclk_inv, \ - .bclk_inv = _bclk_inv, \ - .ws_inv = _ws_inv, \ - }, \ - }, \ - } +#define I2S_DEFAULT_CFG() \ + { \ + .id = I2S_NUM_AUTO, \ + .role = I2S_ROLE_MASTER, \ + .dma_desc_num = 6, \ + .dma_frame_num = 240, \ + .auto_clear = true, \ + } + +#define I2S_STD_CHAN_CFG(_sample_rate, _data_bit_width, _slot_mode) \ + { \ + .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(_sample_rate), \ + .slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(_data_bit_width, _slot_mode), \ + .gpio_cfg = { \ + .mclk = (gpio_num_t)_mclk, \ + .bclk = (gpio_num_t)_bclk, \ + .ws = (gpio_num_t)_ws, \ + .dout = (gpio_num_t)_dout, \ + .din = (gpio_num_t)_din, \ + .invert_flags = { \ + .mclk_inv = _mclk_inv, \ + .bclk_inv = _bclk_inv, \ + .ws_inv = _ws_inv, \ + }, \ + }, \ + } #if SOC_I2S_SUPPORTS_TDM -#define I2S_TDM_CHAN_CFG(_sample_rate, _data_bit_width, _slot_mode, _mask) \ - { \ - .clk_cfg = I2S_TDM_CLK_DEFAULT_CONFIG(_sample_rate), \ - .slot_cfg = I2S_TDM_PHILIP_SLOT_DEFAULT_CONFIG(_data_bit_width, _slot_mode, _mask), \ - .gpio_cfg = { \ - .mclk = (gpio_num_t)_mclk, \ - .bclk = (gpio_num_t)_bclk, \ - .ws = (gpio_num_t)_ws, \ - .dout = (gpio_num_t)_dout, \ - .din = (gpio_num_t)_din, \ - .invert_flags = { \ - .mclk_inv = _mclk_inv, \ - .bclk_inv = _bclk_inv, \ - .ws_inv = _ws_inv, \ - }, \ - }, \ - } +#define I2S_TDM_CHAN_CFG(_sample_rate, _data_bit_width, _slot_mode, _mask) \ + { \ + .clk_cfg = I2S_TDM_CLK_DEFAULT_CONFIG(_sample_rate), \ + .slot_cfg = I2S_TDM_PHILIP_SLOT_DEFAULT_CONFIG(_data_bit_width, _slot_mode, _mask), \ + .gpio_cfg = { \ + .mclk = (gpio_num_t)_mclk, \ + .bclk = (gpio_num_t)_bclk, \ + .ws = (gpio_num_t)_ws, \ + .dout = (gpio_num_t)_dout, \ + .din = (gpio_num_t)_din, \ + .invert_flags = { \ + .mclk_inv = _mclk_inv, \ + .bclk_inv = _bclk_inv, \ + .ws_inv = _ws_inv, \ + }, \ + }, \ + } #endif #if SOC_I2S_SUPPORTS_PDM_TX #if (SOC_I2S_PDM_MAX_TX_LINES > 1) - #define I2S_PDM_TX_CHAN_CFG(_sample_rate, _data_bit_width, _slot_mode) \ - { \ - .clk_cfg = I2S_PDM_TX_CLK_DEFAULT_CONFIG(_sample_rate), \ - .slot_cfg = I2S_PDM_TX_SLOT_DEFAULT_CONFIG(_data_bit_width, _slot_mode), \ - .gpio_cfg = { \ - .clk = (gpio_num_t)_tx_clk, \ - .dout = (gpio_num_t)_tx_dout0, \ - .dout2 = (gpio_num_t)_tx_dout1, \ - .invert_flags = { \ - .clk_inv = _tx_clk_inv, \ - }, \ - }, \ - } +#define I2S_PDM_TX_CHAN_CFG(_sample_rate, _data_bit_width, _slot_mode) \ + { \ + .clk_cfg = I2S_PDM_TX_CLK_DEFAULT_CONFIG(_sample_rate), \ + .slot_cfg = I2S_PDM_TX_SLOT_DEFAULT_CONFIG(_data_bit_width, _slot_mode), \ + .gpio_cfg = { \ + .clk = (gpio_num_t)_tx_clk, \ + .dout = (gpio_num_t)_tx_dout0, \ + .dout2 = (gpio_num_t)_tx_dout1, \ + .invert_flags = { \ + .clk_inv = _tx_clk_inv, \ + }, \ + }, \ + } #else - #define I2S_PDM_TX_CHAN_CFG(_sample_rate, _data_bit_width, _slot_mode) \ - { \ - .clk_cfg = I2S_PDM_TX_CLK_DEFAULT_CONFIG(_sample_rate), \ - .slot_cfg = I2S_PDM_TX_SLOT_DEFAULT_CONFIG(_data_bit_width, _slot_mode), \ - .gpio_cfg = { \ - .clk = (gpio_num_t)_tx_clk, \ - .dout = (gpio_num_t)_tx_dout0, \ - .invert_flags = { \ - .clk_inv = _tx_clk_inv, \ - }, \ - }, \ - } +#define I2S_PDM_TX_CHAN_CFG(_sample_rate, _data_bit_width, _slot_mode) \ + { \ + .clk_cfg = I2S_PDM_TX_CLK_DEFAULT_CONFIG(_sample_rate), \ + .slot_cfg = I2S_PDM_TX_SLOT_DEFAULT_CONFIG(_data_bit_width, _slot_mode), \ + .gpio_cfg = { \ + .clk = (gpio_num_t)_tx_clk, \ + .dout = (gpio_num_t)_tx_dout0, \ + .invert_flags = { \ + .clk_inv = _tx_clk_inv, \ + }, \ + }, \ + } #endif #endif #if SOC_I2S_SUPPORTS_PDM_RX #if (SOC_I2S_PDM_MAX_RX_LINES > 1) - #define I2S_PDM_RX_CHAN_CFG(_sample_rate, _data_bit_width, _slot_mode) \ - { \ - .clk_cfg = I2S_PDM_RX_CLK_DEFAULT_CONFIG(_sample_rate), \ - .slot_cfg = I2S_PDM_RX_SLOT_DEFAULT_CONFIG(_data_bit_width, _slot_mode), \ - .gpio_cfg = { \ - .clk = (gpio_num_t)_rx_clk, \ - .dins = { \ - (gpio_num_t)_rx_din0, \ - (gpio_num_t)_rx_din1, \ - (gpio_num_t)_rx_din2, \ - (gpio_num_t)_rx_din3, \ - }, \ - .invert_flags = { \ - .clk_inv = _rx_clk_inv, \ - }, \ - }, \ - } +#define I2S_PDM_RX_CHAN_CFG(_sample_rate, _data_bit_width, _slot_mode) \ + { \ + .clk_cfg = I2S_PDM_RX_CLK_DEFAULT_CONFIG(_sample_rate), \ + .slot_cfg = I2S_PDM_RX_SLOT_DEFAULT_CONFIG(_data_bit_width, _slot_mode), \ + .gpio_cfg = { \ + .clk = (gpio_num_t)_rx_clk, \ + .dins = { \ + (gpio_num_t)_rx_din0, \ + (gpio_num_t)_rx_din1, \ + (gpio_num_t)_rx_din2, \ + (gpio_num_t)_rx_din3, \ + }, \ + .invert_flags = { \ + .clk_inv = _rx_clk_inv, \ + }, \ + }, \ + } #else - #define I2S_PDM_RX_CHAN_CFG(_sample_rate, _data_bit_width, _slot_mode) \ - { \ - .clk_cfg = I2S_PDM_RX_CLK_DEFAULT_CONFIG(_sample_rate), \ - .slot_cfg = I2S_PDM_RX_SLOT_DEFAULT_CONFIG(_data_bit_width, _slot_mode), \ - .gpio_cfg = { \ - .clk = (gpio_num_t)_rx_clk, \ - .din = (gpio_num_t)_rx_din0, \ - .invert_flags = { \ - .clk_inv = _rx_clk_inv, \ - }, \ - }, \ - } +#define I2S_PDM_RX_CHAN_CFG(_sample_rate, _data_bit_width, _slot_mode) \ + { \ + .clk_cfg = I2S_PDM_RX_CLK_DEFAULT_CONFIG(_sample_rate), \ + .slot_cfg = I2S_PDM_RX_SLOT_DEFAULT_CONFIG(_data_bit_width, _slot_mode), \ + .gpio_cfg = { \ + .clk = (gpio_num_t)_rx_clk, \ + .din = (gpio_num_t)_rx_din0, \ + .invert_flags = { \ + .clk_inv = _rx_clk_inv, \ + }, \ + }, \ + } #endif #endif -#define I2S_ERROR_CHECK_RETURN(x,r) do { last_error = (x); if(unlikely(last_error != ESP_OK)){ log_e("ERROR: %s", esp_err_to_name(last_error)); return (r); } } while(0) -#define I2S_ERROR_CHECK_RETURN_FALSE(x) I2S_ERROR_CHECK_RETURN(x,false) +#define I2S_ERROR_CHECK_RETURN(x, r) \ + do { \ + last_error = (x); \ + if (unlikely(last_error != ESP_OK)) { \ + log_e("ERROR: %s", esp_err_to_name(last_error)); \ + return (r); \ + } \ + } while (0) +#define I2S_ERROR_CHECK_RETURN_FALSE(x) I2S_ERROR_CHECK_RETURN(x, false) // Default read, no resmpling and temp buffer necessary -static esp_err_t i2s_channel_read_default(i2s_chan_handle_t handle, char * tmp_buf, void * dst, size_t len, size_t *bytes_read, uint32_t timeout_ms){ - return i2s_channel_read(handle, (char *)dst, len, bytes_read, timeout_ms); +static esp_err_t i2s_channel_read_default(i2s_chan_handle_t handle, char *tmp_buf, void *dst, size_t len, size_t *bytes_read, uint32_t timeout_ms) { + return i2s_channel_read(handle, (char *)dst, len, bytes_read, timeout_ms); } // Resample the 32bit SPH0645 microphone data into 16bit. SPH0645 is actually 18 bit, but this trick helps save some space -static esp_err_t i2s_channel_read_32_to_16(i2s_chan_handle_t handle, char * read_buff, void * dst, size_t len, size_t *bytes_read, uint32_t timeout_ms){ +static esp_err_t i2s_channel_read_32_to_16(i2s_chan_handle_t handle, char *read_buff, void *dst, size_t len, size_t *bytes_read, uint32_t timeout_ms) { size_t out_len = 0; size_t read_buff_len = len * 2; - if(read_buff == NULL){ + if (read_buff == NULL) { log_e("Temp buffer is NULL!"); return ESP_FAIL; } esp_err_t err = i2s_channel_read(handle, read_buff, read_buff_len, &out_len, timeout_ms); - if (err != ESP_OK){ + if (err != ESP_OK) { *bytes_read = 0; return err; } out_len /= 4; - uint16_t * ds = (uint16_t*)dst; - uint32_t * src = (uint32_t*)read_buff; - for (size_t i = 0; i < out_len; i++){ + uint16_t *ds = (uint16_t *)dst; + uint32_t *src = (uint32_t *)read_buff; + for (size_t i = 0; i < out_len; i++) { ds[i] = src[i] >> 16; } *bytes_read = out_len * 2; @@ -154,602 +162,654 @@ static esp_err_t i2s_channel_read_32_to_16(i2s_chan_handle_t handle, char * read } // Resample the 16bit stereo microphone data into 16bit mono. -static esp_err_t i2s_channel_read_16_stereo_to_mono(i2s_chan_handle_t handle, char * read_buff, void * dst, size_t len, size_t *bytes_read, uint32_t timeout_ms){ +static esp_err_t i2s_channel_read_16_stereo_to_mono(i2s_chan_handle_t handle, char *read_buff, void *dst, size_t len, size_t *bytes_read, uint32_t timeout_ms) { size_t out_len = 0; size_t read_buff_len = len * 2; - if(read_buff == NULL){ + if (read_buff == NULL) { log_e("Temp buffer is NULL!"); return ESP_FAIL; } esp_err_t err = i2s_channel_read(handle, read_buff, read_buff_len, &out_len, timeout_ms); - if (err != ESP_OK){ + if (err != ESP_OK) { *bytes_read = 0; return err; } out_len /= 2; - uint16_t * ds = (uint16_t*)dst; - uint16_t * src = (uint16_t*)read_buff; - for (size_t i = 0; i < out_len; i+=2){ + uint16_t *ds = (uint16_t *)dst; + uint16_t *src = (uint16_t *)read_buff; + for (size_t i = 0; i < out_len; i += 2) { *ds++ = src[i]; } *bytes_read = out_len; return ESP_OK; } -I2SClass::I2SClass(){ - last_error = ESP_OK; - - tx_chan = NULL; - tx_sample_rate = 0; - tx_data_bit_width = I2S_DATA_BIT_WIDTH_16BIT; - tx_slot_mode = I2S_SLOT_MODE_STEREO; - - rx_fn = i2s_channel_read_default; - rx_transform = I2S_RX_TRANSFORM_NONE; - rx_transform_buf = NULL; - rx_transform_buf_len = 0; - - rx_chan = NULL; - rx_sample_rate = 0; - rx_data_bit_width = I2S_DATA_BIT_WIDTH_16BIT; - rx_slot_mode = I2S_SLOT_MODE_STEREO; - - _mclk = -1; - _bclk = -1; - _ws = -1; - _dout = -1; - _din = -1; - _mclk_inv = false; - _bclk_inv = false; - _ws_inv = false; +I2SClass::I2SClass() { + last_error = ESP_OK; + + tx_chan = NULL; + tx_sample_rate = 0; + tx_data_bit_width = I2S_DATA_BIT_WIDTH_16BIT; + tx_slot_mode = I2S_SLOT_MODE_STEREO; + + rx_fn = i2s_channel_read_default; + rx_transform = I2S_RX_TRANSFORM_NONE; + rx_transform_buf = NULL; + rx_transform_buf_len = 0; + + rx_chan = NULL; + rx_sample_rate = 0; + rx_data_bit_width = I2S_DATA_BIT_WIDTH_16BIT; + rx_slot_mode = I2S_SLOT_MODE_STEREO; + + _mclk = -1; + _bclk = -1; + _ws = -1; + _dout = -1; + _din = -1; + _mclk_inv = false; + _bclk_inv = false; + _ws_inv = false; #if SOC_I2S_SUPPORTS_PDM_TX - _tx_clk = -1; - _tx_dout0 = -1; - _tx_dout1 = -1; - _tx_clk_inv = false; + _tx_clk = -1; + _tx_dout0 = -1; + _tx_dout1 = -1; + _tx_clk_inv = false; #endif #if SOC_I2S_SUPPORTS_PDM_RX - _rx_clk = -1; - _rx_din0 = -1; - _rx_din1 = -1; - _rx_din2 = -1; - _rx_din3 = -1; - _rx_clk_inv = false; + _rx_clk = -1; + _rx_din0 = -1; + _rx_din1 = -1; + _rx_din2 = -1; + _rx_din3 = -1; + _rx_clk_inv = false; #endif } -I2SClass::~I2SClass(){ +I2SClass::~I2SClass() { end(); } -bool I2SClass::i2sDetachBus(void * bus_pointer){ - I2SClass *bus = (I2SClass *) bus_pointer; - if(bus->tx_chan != NULL || bus->tx_chan != NULL){ - bus->end(); - } - return true; +bool I2SClass::i2sDetachBus(void *bus_pointer) { + I2SClass *bus = (I2SClass *)bus_pointer; + if (bus->tx_chan != NULL || bus->tx_chan != NULL) { + bus->end(); + } + return true; } // Set pins for STD and TDM mode -void I2SClass::setPins(int8_t bclk, int8_t ws, int8_t dout, int8_t din, int8_t mclk){ - _mclk = digitalPinToGPIONumber(mclk); - _bclk = digitalPinToGPIONumber(bclk); - _ws = digitalPinToGPIONumber(ws); - _dout = digitalPinToGPIONumber(dout); - _din = digitalPinToGPIONumber(din); +void I2SClass::setPins(int8_t bclk, int8_t ws, int8_t dout, int8_t din, int8_t mclk) { + _mclk = digitalPinToGPIONumber(mclk); + _bclk = digitalPinToGPIONumber(bclk); + _ws = digitalPinToGPIONumber(ws); + _dout = digitalPinToGPIONumber(dout); + _din = digitalPinToGPIONumber(din); } -void I2SClass::setInverted(bool bclk, bool ws, bool mclk){ - _mclk_inv = mclk; - _bclk_inv = bclk; - _ws_inv = ws; +void I2SClass::setInverted(bool bclk, bool ws, bool mclk) { + _mclk_inv = mclk; + _bclk_inv = bclk; + _ws_inv = ws; } // Set pins for PDM TX mode #if SOC_I2S_SUPPORTS_PDM_TX -void I2SClass::setPinsPdmTx(int8_t clk, int8_t dout0, int8_t dout1){ - _tx_clk = digitalPinToGPIONumber(clk); - _tx_dout0 = digitalPinToGPIONumber(dout0); +void I2SClass::setPinsPdmTx(int8_t clk, int8_t dout0, int8_t dout1) { + _tx_clk = digitalPinToGPIONumber(clk); + _tx_dout0 = digitalPinToGPIONumber(dout0); #if (SOC_I2S_PDM_MAX_TX_LINES > 1) - _tx_dout1 = digitalPinToGPIONumber(dout1); + _tx_dout1 = digitalPinToGPIONumber(dout1); #endif } #endif // Set pins for PDM RX mode #if SOC_I2S_SUPPORTS_PDM_RX -void I2SClass::setPinsPdmRx(int8_t clk, int8_t din0, int8_t din1, int8_t din2, int8_t din3){ - _rx_clk = digitalPinToGPIONumber(clk); - _rx_din0 = digitalPinToGPIONumber(din0); +void I2SClass::setPinsPdmRx(int8_t clk, int8_t din0, int8_t din1, int8_t din2, int8_t din3) { + _rx_clk = digitalPinToGPIONumber(clk); + _rx_din0 = digitalPinToGPIONumber(din0); #if (SOC_I2S_PDM_MAX_RX_LINES > 1) - _rx_din1 = digitalPinToGPIONumber(din1); - _rx_din2 = digitalPinToGPIONumber(din2); - _rx_din3 = digitalPinToGPIONumber(din3); + _rx_din1 = digitalPinToGPIONumber(din1); + _rx_din2 = digitalPinToGPIONumber(din2); + _rx_din3 = digitalPinToGPIONumber(din3); #endif } #endif #if SOC_I2S_SUPPORTS_PDM_TX || SOC_I2S_SUPPORTS_PDM_RX -void I2SClass::setInvertedPdm(bool clk){ +void I2SClass::setInvertedPdm(bool clk) { #if SOC_I2S_SUPPORTS_PDM_TX - _tx_clk_inv = clk; + _tx_clk_inv = clk; #endif #if SOC_I2S_SUPPORTS_PDM_RX - _rx_clk_inv = clk; + _rx_clk_inv = clk; #endif } #endif -bool I2SClass::initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask){ - // Peripheral manager deinit previous peripheral if pin was used - if (_mclk >= 0) if (!perimanClearPinBus(_mclk)){ return false; } - if (_bclk >= 0) if (!perimanClearPinBus(_bclk)){ return false; } - if (_ws >= 0) if (!perimanClearPinBus(_ws)) { return false; } - if (_dout >= 0) if (!perimanClearPinBus(_dout)){ return false; } - if (_din >= 0) if (!perimanClearPinBus(_din)) { return false; } - - // Set peripheral manager detach function for I2S - if (_mclk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_STD_MCLK, I2SClass::i2sDetachBus); } - if (_bclk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_STD_BCLK, I2SClass::i2sDetachBus); } - if (_ws >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_STD_WS, I2SClass::i2sDetachBus); } - if (_dout >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_STD_DOUT, I2SClass::i2sDetachBus); } - if (_din >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_STD_DIN, I2SClass::i2sDetachBus); } - - // I2S configuration - i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG(); - if (_dout >= 0 && _din >= 0) { - I2S_ERROR_CHECK_RETURN_FALSE(i2s_new_channel(&chan_cfg, &tx_chan, &rx_chan)); - } else if (_dout >= 0) { - I2S_ERROR_CHECK_RETURN_FALSE(i2s_new_channel(&chan_cfg, &tx_chan, NULL)); - } else if (_din >= 0) { - I2S_ERROR_CHECK_RETURN_FALSE(i2s_new_channel(&chan_cfg, NULL, &rx_chan)); - } - - i2s_std_config_t i2s_config = I2S_STD_CHAN_CFG(rate, bits_cfg, ch); - if(slot_mask >= 0 && (i2s_std_slot_mask_t)slot_mask <= I2S_STD_SLOT_BOTH){ - i2s_config.slot_cfg.slot_mask = (i2s_std_slot_mask_t)slot_mask; - } - if (tx_chan != NULL) { - tx_sample_rate = rate; - tx_data_bit_width = bits_cfg; - tx_slot_mode = ch; - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_init_std_mode(tx_chan, &i2s_config)); - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_enable(tx_chan)); - } - if (rx_chan != NULL) { - rx_sample_rate = rate; - rx_data_bit_width = bits_cfg; - rx_slot_mode = ch; - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_init_std_mode(rx_chan, &i2s_config)); - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_enable(rx_chan)); - } +bool I2SClass::initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask) { + // Peripheral manager deinit previous peripheral if pin was used + if (_mclk >= 0) + if (!perimanClearPinBus(_mclk)) { return false; } + if (_bclk >= 0) + if (!perimanClearPinBus(_bclk)) { return false; } + if (_ws >= 0) + if (!perimanClearPinBus(_ws)) { return false; } + if (_dout >= 0) + if (!perimanClearPinBus(_dout)) { return false; } + if (_din >= 0) + if (!perimanClearPinBus(_din)) { return false; } + + // Set peripheral manager detach function for I2S + if (_mclk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_STD_MCLK, I2SClass::i2sDetachBus); } + if (_bclk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_STD_BCLK, I2SClass::i2sDetachBus); } + if (_ws >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_STD_WS, I2SClass::i2sDetachBus); } + if (_dout >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_STD_DOUT, I2SClass::i2sDetachBus); } + if (_din >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_STD_DIN, I2SClass::i2sDetachBus); } + + // I2S configuration + i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG(); + if (_dout >= 0 && _din >= 0) { + I2S_ERROR_CHECK_RETURN_FALSE(i2s_new_channel(&chan_cfg, &tx_chan, &rx_chan)); + } else if (_dout >= 0) { + I2S_ERROR_CHECK_RETURN_FALSE(i2s_new_channel(&chan_cfg, &tx_chan, NULL)); + } else if (_din >= 0) { + I2S_ERROR_CHECK_RETURN_FALSE(i2s_new_channel(&chan_cfg, NULL, &rx_chan)); + } - // Peripheral manager set bus type to I2S - if (_mclk >= 0) if (!perimanSetPinBus(_mclk, ESP32_BUS_TYPE_I2S_STD_MCLK, (void *)(this), -1, -1)){ goto err; } - if (_bclk >= 0) if (!perimanSetPinBus(_bclk, ESP32_BUS_TYPE_I2S_STD_BCLK, (void *)(this), -1, -1)){ goto err; } - if (_ws >= 0) if (!perimanSetPinBus(_ws, ESP32_BUS_TYPE_I2S_STD_WS, (void *)(this), -1, -1)){ goto err; } - if (_dout >= 0) if (!perimanSetPinBus(_dout, ESP32_BUS_TYPE_I2S_STD_DOUT, (void *)(this), -1, -1)){ goto err; } - if (_din >= 0) if (!perimanSetPinBus(_din, ESP32_BUS_TYPE_I2S_STD_DIN, (void *)(this), -1, -1)){ goto err; } + i2s_std_config_t i2s_config = I2S_STD_CHAN_CFG(rate, bits_cfg, ch); + if (slot_mask >= 0 && (i2s_std_slot_mask_t)slot_mask <= I2S_STD_SLOT_BOTH) { + i2s_config.slot_cfg.slot_mask = (i2s_std_slot_mask_t)slot_mask; + } + if (tx_chan != NULL) { + tx_sample_rate = rate; + tx_data_bit_width = bits_cfg; + tx_slot_mode = ch; + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_init_std_mode(tx_chan, &i2s_config)); + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_enable(tx_chan)); + } + if (rx_chan != NULL) { + rx_sample_rate = rate; + rx_data_bit_width = bits_cfg; + rx_slot_mode = ch; + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_init_std_mode(rx_chan, &i2s_config)); + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_enable(rx_chan)); + } - return true; + // Peripheral manager set bus type to I2S + if (_mclk >= 0) + if (!perimanSetPinBus(_mclk, ESP32_BUS_TYPE_I2S_STD_MCLK, (void *)(this), -1, -1)) { goto err; } + if (_bclk >= 0) + if (!perimanSetPinBus(_bclk, ESP32_BUS_TYPE_I2S_STD_BCLK, (void *)(this), -1, -1)) { goto err; } + if (_ws >= 0) + if (!perimanSetPinBus(_ws, ESP32_BUS_TYPE_I2S_STD_WS, (void *)(this), -1, -1)) { goto err; } + if (_dout >= 0) + if (!perimanSetPinBus(_dout, ESP32_BUS_TYPE_I2S_STD_DOUT, (void *)(this), -1, -1)) { goto err; } + if (_din >= 0) + if (!perimanSetPinBus(_din, ESP32_BUS_TYPE_I2S_STD_DIN, (void *)(this), -1, -1)) { goto err; } + + return true; err: - log_e("Failed to set all pins bus to I2S_STD"); - I2SClass::i2sDetachBus((void *)(this)); - return false; + log_e("Failed to set all pins bus to I2S_STD"); + I2SClass::i2sDetachBus((void *)(this)); + return false; } #if SOC_I2S_SUPPORTS_TDM -bool I2SClass::initTDM(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask){ - // Peripheral manager deinit previous peripheral if pin was used - if (_mclk >= 0) if (!perimanClearPinBus(_mclk)){ return false; } - if (_bclk >= 0) if (!perimanClearPinBus(_bclk)){ return false; } - if (_ws >= 0) if (!perimanClearPinBus(_ws)) { return false; } - if (_dout >= 0) if (!perimanClearPinBus(_dout)){ return false; } - if (_din >= 0) if (!perimanClearPinBus(_din)) { return false; } - - // Set peripheral manager detach function for I2S - if (_mclk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_TDM_MCLK, I2SClass::i2sDetachBus); } - if (_bclk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_TDM_BCLK, I2SClass::i2sDetachBus); } - if (_ws >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_TDM_WS, I2SClass::i2sDetachBus); } - if (_dout >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_TDM_DOUT, I2SClass::i2sDetachBus); } - if (_din >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_TDM_DIN, I2SClass::i2sDetachBus); } - - // I2S configuration - i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG(); - if (_dout >= 0 && _din >= 0) { - I2S_ERROR_CHECK_RETURN_FALSE(i2s_new_channel(&chan_cfg, &tx_chan, &rx_chan)); - } else if (_dout >= 0) { - I2S_ERROR_CHECK_RETURN_FALSE(i2s_new_channel(&chan_cfg, &tx_chan, NULL)); - } else if (_din >= 0) { - I2S_ERROR_CHECK_RETURN_FALSE(i2s_new_channel(&chan_cfg, NULL, &rx_chan)); - } +bool I2SClass::initTDM(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask) { + // Peripheral manager deinit previous peripheral if pin was used + if (_mclk >= 0) + if (!perimanClearPinBus(_mclk)) { return false; } + if (_bclk >= 0) + if (!perimanClearPinBus(_bclk)) { return false; } + if (_ws >= 0) + if (!perimanClearPinBus(_ws)) { return false; } + if (_dout >= 0) + if (!perimanClearPinBus(_dout)) { return false; } + if (_din >= 0) + if (!perimanClearPinBus(_din)) { return false; } + + // Set peripheral manager detach function for I2S + if (_mclk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_TDM_MCLK, I2SClass::i2sDetachBus); } + if (_bclk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_TDM_BCLK, I2SClass::i2sDetachBus); } + if (_ws >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_TDM_WS, I2SClass::i2sDetachBus); } + if (_dout >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_TDM_DOUT, I2SClass::i2sDetachBus); } + if (_din >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_TDM_DIN, I2SClass::i2sDetachBus); } + + // I2S configuration + i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG(); + if (_dout >= 0 && _din >= 0) { + I2S_ERROR_CHECK_RETURN_FALSE(i2s_new_channel(&chan_cfg, &tx_chan, &rx_chan)); + } else if (_dout >= 0) { + I2S_ERROR_CHECK_RETURN_FALSE(i2s_new_channel(&chan_cfg, &tx_chan, NULL)); + } else if (_din >= 0) { + I2S_ERROR_CHECK_RETURN_FALSE(i2s_new_channel(&chan_cfg, NULL, &rx_chan)); + } - i2s_tdm_config_t i2s_tdm_config = I2S_TDM_CHAN_CFG(rate, bits_cfg, ch, (i2s_tdm_slot_mask_t)slot_mask); - if (tx_chan != NULL) { - tx_sample_rate = rate; - tx_data_bit_width = bits_cfg; - tx_slot_mode = ch; - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_init_tdm_mode(tx_chan, &i2s_tdm_config)); - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_enable(tx_chan)); - } - if (rx_chan != NULL) { - rx_sample_rate = rate; - rx_data_bit_width = bits_cfg; - rx_slot_mode = ch; - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_init_tdm_mode(rx_chan, &i2s_tdm_config)); - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_enable(rx_chan)); - } + i2s_tdm_config_t i2s_tdm_config = I2S_TDM_CHAN_CFG(rate, bits_cfg, ch, (i2s_tdm_slot_mask_t)slot_mask); + if (tx_chan != NULL) { + tx_sample_rate = rate; + tx_data_bit_width = bits_cfg; + tx_slot_mode = ch; + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_init_tdm_mode(tx_chan, &i2s_tdm_config)); + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_enable(tx_chan)); + } + if (rx_chan != NULL) { + rx_sample_rate = rate; + rx_data_bit_width = bits_cfg; + rx_slot_mode = ch; + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_init_tdm_mode(rx_chan, &i2s_tdm_config)); + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_enable(rx_chan)); + } - // Peripheral manager set bus type to I2S - if (_mclk >= 0) if (!perimanSetPinBus(_mclk, ESP32_BUS_TYPE_I2S_TDM_MCLK, (void *)(this), -1, -1)){ goto err; } - if (_bclk >= 0) if (!perimanSetPinBus(_bclk, ESP32_BUS_TYPE_I2S_TDM_BCLK, (void *)(this), -1, -1)){ goto err; } - if (_ws >= 0) if (!perimanSetPinBus(_ws, ESP32_BUS_TYPE_I2S_TDM_WS, (void *)(this), -1, -1)){ goto err; } - if (_dout >= 0) if (!perimanSetPinBus(_dout, ESP32_BUS_TYPE_I2S_TDM_DOUT, (void *)(this), -1, -1)){ goto err; } - if (_din >= 0) if (!perimanSetPinBus(_din, ESP32_BUS_TYPE_I2S_TDM_DIN, (void *)(this), -1, -1)){ goto err; } - - return true; + // Peripheral manager set bus type to I2S + if (_mclk >= 0) + if (!perimanSetPinBus(_mclk, ESP32_BUS_TYPE_I2S_TDM_MCLK, (void *)(this), -1, -1)) { goto err; } + if (_bclk >= 0) + if (!perimanSetPinBus(_bclk, ESP32_BUS_TYPE_I2S_TDM_BCLK, (void *)(this), -1, -1)) { goto err; } + if (_ws >= 0) + if (!perimanSetPinBus(_ws, ESP32_BUS_TYPE_I2S_TDM_WS, (void *)(this), -1, -1)) { goto err; } + if (_dout >= 0) + if (!perimanSetPinBus(_dout, ESP32_BUS_TYPE_I2S_TDM_DOUT, (void *)(this), -1, -1)) { goto err; } + if (_din >= 0) + if (!perimanSetPinBus(_din, ESP32_BUS_TYPE_I2S_TDM_DIN, (void *)(this), -1, -1)) { goto err; } + + return true; err: - log_e("Failed to set all pins bus to I2S_TDM"); - I2SClass::i2sDetachBus((void *)(this)); - return false; + log_e("Failed to set all pins bus to I2S_TDM"); + I2SClass::i2sDetachBus((void *)(this)); + return false; } #endif #if SOC_I2S_SUPPORTS_PDM_TX -bool I2SClass::initPDMtx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch){ - // Peripheral manager deinit previous peripheral if pin was used - if (_tx_clk >= 0) if (!perimanClearPinBus(_tx_clk)) { return false; } - if (_tx_dout0 >= 0) if (!perimanClearPinBus(_tx_dout0)){ return false; } - if (_tx_dout1 >= 0) if (!perimanClearPinBus(_tx_dout1)){ return false; } - - // Set peripheral manager detach function for I2S - if (_tx_clk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_TX_CLK, I2SClass::i2sDetachBus); } - if (_tx_dout0 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_TX_DOUT0, I2SClass::i2sDetachBus); } - if (_tx_dout1 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_TX_DOUT1, I2SClass::i2sDetachBus); } - - // I2S configuration - i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG(); - I2S_ERROR_CHECK_RETURN_FALSE(i2s_new_channel(&chan_cfg, &tx_chan, NULL)); - - i2s_pdm_tx_config_t i2s_pdm_tx_config = I2S_PDM_TX_CHAN_CFG(rate, bits_cfg, ch); - if (tx_chan != NULL) { - tx_sample_rate = rate; - tx_data_bit_width = bits_cfg; - tx_slot_mode = ch; - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_init_pdm_tx_mode(tx_chan, &i2s_pdm_tx_config)); - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_enable(tx_chan)); - } +bool I2SClass::initPDMtx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch) { + // Peripheral manager deinit previous peripheral if pin was used + if (_tx_clk >= 0) + if (!perimanClearPinBus(_tx_clk)) { return false; } + if (_tx_dout0 >= 0) + if (!perimanClearPinBus(_tx_dout0)) { return false; } + if (_tx_dout1 >= 0) + if (!perimanClearPinBus(_tx_dout1)) { return false; } + + // Set peripheral manager detach function for I2S + if (_tx_clk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_TX_CLK, I2SClass::i2sDetachBus); } + if (_tx_dout0 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_TX_DOUT0, I2SClass::i2sDetachBus); } + if (_tx_dout1 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_TX_DOUT1, I2SClass::i2sDetachBus); } + + // I2S configuration + i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG(); + I2S_ERROR_CHECK_RETURN_FALSE(i2s_new_channel(&chan_cfg, &tx_chan, NULL)); + + i2s_pdm_tx_config_t i2s_pdm_tx_config = I2S_PDM_TX_CHAN_CFG(rate, bits_cfg, ch); + if (tx_chan != NULL) { + tx_sample_rate = rate; + tx_data_bit_width = bits_cfg; + tx_slot_mode = ch; + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_init_pdm_tx_mode(tx_chan, &i2s_pdm_tx_config)); + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_enable(tx_chan)); + } - // Peripheral manager set bus type to I2S - if (_tx_clk >= 0) if (!perimanSetPinBus(_tx_clk, ESP32_BUS_TYPE_I2S_PDM_TX_CLK, (void *)(this), -1, -1)){ goto err; } - if (_tx_dout0 >= 0) if (!perimanSetPinBus(_tx_dout0, ESP32_BUS_TYPE_I2S_PDM_TX_DOUT0, (void *)(this), -1, -1)){ goto err; } - if (_tx_dout1 >= 0) if (!perimanSetPinBus(_tx_dout1, ESP32_BUS_TYPE_I2S_PDM_TX_DOUT1, (void *)(this), -1, -1)){ goto err; } + // Peripheral manager set bus type to I2S + if (_tx_clk >= 0) + if (!perimanSetPinBus(_tx_clk, ESP32_BUS_TYPE_I2S_PDM_TX_CLK, (void *)(this), -1, -1)) { goto err; } + if (_tx_dout0 >= 0) + if (!perimanSetPinBus(_tx_dout0, ESP32_BUS_TYPE_I2S_PDM_TX_DOUT0, (void *)(this), -1, -1)) { goto err; } + if (_tx_dout1 >= 0) + if (!perimanSetPinBus(_tx_dout1, ESP32_BUS_TYPE_I2S_PDM_TX_DOUT1, (void *)(this), -1, -1)) { goto err; } - return true; + return true; err: - log_e("Failed to set all pins bus to I2S_TDM"); - I2SClass::i2sDetachBus((void *)(this)); - return false; + log_e("Failed to set all pins bus to I2S_TDM"); + I2SClass::i2sDetachBus((void *)(this)); + return false; } #endif #if SOC_I2S_SUPPORTS_PDM_RX -bool I2SClass::initPDMrx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch){ - // Peripheral manager deinit previous peripheral if pin was used - if (_rx_clk >= 0) if (!perimanClearPinBus(_rx_clk)) { return false; } - if (_rx_din0 >= 0) if (!perimanClearPinBus(_rx_din0)){ return false; } - if (_rx_din1 >= 0) if (!perimanClearPinBus(_rx_din1)){ return false; } - if (_rx_din2 >= 0) if (!perimanClearPinBus(_rx_din2)){ return false; } - if (_rx_din3 >= 0) if (!perimanClearPinBus(_rx_din3)){ return false; } - - // Set peripheral manager detach function for I2S - if (_rx_clk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_RX_CLK, I2SClass::i2sDetachBus); } - if (_rx_din0 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_RX_DIN0, I2SClass::i2sDetachBus); } - if (_rx_din1 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_RX_DIN1, I2SClass::i2sDetachBus); } - if (_rx_din2 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_RX_DIN2, I2SClass::i2sDetachBus); } - if (_rx_din3 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_RX_DIN3, I2SClass::i2sDetachBus); } - - // I2S configuration - i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG(); - I2S_ERROR_CHECK_RETURN_FALSE(i2s_new_channel(&chan_cfg, NULL, &rx_chan)); - - i2s_pdm_rx_config_t i2s_pdf_rx_config = I2S_PDM_RX_CHAN_CFG(rate, bits_cfg, ch); - if (rx_chan != NULL) { - rx_sample_rate = rate; - rx_data_bit_width = bits_cfg; - rx_slot_mode = ch; - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_init_pdm_rx_mode(rx_chan, &i2s_pdf_rx_config)); - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_enable(rx_chan)); - } - - // Peripheral manager set bus type to I2S - if (_rx_clk >= 0) if (!perimanSetPinBus(_rx_clk, ESP32_BUS_TYPE_I2S_PDM_RX_CLK, (void *)(this), -1, -1)){ goto err; } - if (_rx_din0 >= 0) if (!perimanSetPinBus(_rx_din0, ESP32_BUS_TYPE_I2S_PDM_RX_DIN0, (void *)(this), -1, -1)){ goto err; } - if (_rx_din1 >= 0) if (!perimanSetPinBus(_rx_din1, ESP32_BUS_TYPE_I2S_PDM_RX_DIN1, (void *)(this), -1, -1)){ goto err; } - if (_rx_din2 >= 0) if (!perimanSetPinBus(_rx_din2, ESP32_BUS_TYPE_I2S_PDM_RX_DIN2, (void *)(this), -1, -1)){ goto err; } - if (_rx_din3 >= 0) if (!perimanSetPinBus(_rx_din3, ESP32_BUS_TYPE_I2S_PDM_RX_DIN3, (void *)(this), -1, -1)){ goto err; } +bool I2SClass::initPDMrx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch) { + // Peripheral manager deinit previous peripheral if pin was used + if (_rx_clk >= 0) + if (!perimanClearPinBus(_rx_clk)) { return false; } + if (_rx_din0 >= 0) + if (!perimanClearPinBus(_rx_din0)) { return false; } + if (_rx_din1 >= 0) + if (!perimanClearPinBus(_rx_din1)) { return false; } + if (_rx_din2 >= 0) + if (!perimanClearPinBus(_rx_din2)) { return false; } + if (_rx_din3 >= 0) + if (!perimanClearPinBus(_rx_din3)) { return false; } + + // Set peripheral manager detach function for I2S + if (_rx_clk >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_RX_CLK, I2SClass::i2sDetachBus); } + if (_rx_din0 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_RX_DIN0, I2SClass::i2sDetachBus); } + if (_rx_din1 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_RX_DIN1, I2SClass::i2sDetachBus); } + if (_rx_din2 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_RX_DIN2, I2SClass::i2sDetachBus); } + if (_rx_din3 >= 0) { perimanSetBusDeinit(ESP32_BUS_TYPE_I2S_PDM_RX_DIN3, I2SClass::i2sDetachBus); } + + // I2S configuration + i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG(); + I2S_ERROR_CHECK_RETURN_FALSE(i2s_new_channel(&chan_cfg, NULL, &rx_chan)); + + i2s_pdm_rx_config_t i2s_pdf_rx_config = I2S_PDM_RX_CHAN_CFG(rate, bits_cfg, ch); + if (rx_chan != NULL) { + rx_sample_rate = rate; + rx_data_bit_width = bits_cfg; + rx_slot_mode = ch; + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_init_pdm_rx_mode(rx_chan, &i2s_pdf_rx_config)); + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_enable(rx_chan)); + } - return true; + // Peripheral manager set bus type to I2S + if (_rx_clk >= 0) + if (!perimanSetPinBus(_rx_clk, ESP32_BUS_TYPE_I2S_PDM_RX_CLK, (void *)(this), -1, -1)) { goto err; } + if (_rx_din0 >= 0) + if (!perimanSetPinBus(_rx_din0, ESP32_BUS_TYPE_I2S_PDM_RX_DIN0, (void *)(this), -1, -1)) { goto err; } + if (_rx_din1 >= 0) + if (!perimanSetPinBus(_rx_din1, ESP32_BUS_TYPE_I2S_PDM_RX_DIN1, (void *)(this), -1, -1)) { goto err; } + if (_rx_din2 >= 0) + if (!perimanSetPinBus(_rx_din2, ESP32_BUS_TYPE_I2S_PDM_RX_DIN2, (void *)(this), -1, -1)) { goto err; } + if (_rx_din3 >= 0) + if (!perimanSetPinBus(_rx_din3, ESP32_BUS_TYPE_I2S_PDM_RX_DIN3, (void *)(this), -1, -1)) { goto err; } + + return true; err: - log_e("Failed to set all pins bus to I2S_TDM"); - I2SClass::i2sDetachBus((void *)(this)); - return false; + log_e("Failed to set all pins bus to I2S_TDM"); + I2SClass::i2sDetachBus((void *)(this)); + return false; } #endif -bool I2SClass::begin(i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask){ - /* Setup I2S peripheral */ - if (mode >= I2S_MODE_MAX){ - log_e("Invalid I2S mode selected."); - return false; - } - _mode = mode; +bool I2SClass::begin(i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask) { + /* Setup I2S peripheral */ + if (mode >= I2S_MODE_MAX) { + log_e("Invalid I2S mode selected."); + return false; + } + _mode = mode; - bool init = false; - switch (_mode){ - case I2S_MODE_STD: - init = initSTD(rate, bits_cfg, ch, slot_mask); - break; + bool init = false; + switch (_mode) { + case I2S_MODE_STD: + init = initSTD(rate, bits_cfg, ch, slot_mask); + break; #if SOC_I2S_SUPPORTS_TDM - case I2S_MODE_TDM: - init = initTDM(rate, bits_cfg, ch, slot_mask); - break; + case I2S_MODE_TDM: + init = initTDM(rate, bits_cfg, ch, slot_mask); + break; #endif #if SOC_I2S_SUPPORTS_PDM_TX - case I2S_MODE_PDM_TX: - init = initPDMtx(rate, bits_cfg, ch); - break; + case I2S_MODE_PDM_TX: + init = initPDMtx(rate, bits_cfg, ch); + break; #endif #if SOC_I2S_SUPPORTS_PDM_RX - case I2S_MODE_PDM_RX: - init = initPDMrx(rate, bits_cfg, ch); - break; + case I2S_MODE_PDM_RX: + init = initPDMrx(rate, bits_cfg, ch); + break; #endif - default: - break; - } + default: + break; + } - if (init == false){ - log_e("I2S initialization failed."); - return false; - } - return true; + if (init == false) { + log_e("I2S initialization failed."); + return false; + } + return true; } -bool I2SClass::end(){ - if (tx_chan != NULL){ - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_disable(tx_chan)); - I2S_ERROR_CHECK_RETURN_FALSE(i2s_del_channel(tx_chan)); - tx_chan = NULL; - } - if (rx_chan != NULL){ - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_disable(rx_chan)); - I2S_ERROR_CHECK_RETURN_FALSE(i2s_del_channel(rx_chan)); - rx_chan = NULL; - } - if(rx_transform_buf != NULL){ - free(rx_transform_buf); - rx_transform_buf = NULL; - rx_transform_buf_len = 0; - } +bool I2SClass::end() { + if (tx_chan != NULL) { + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_disable(tx_chan)); + I2S_ERROR_CHECK_RETURN_FALSE(i2s_del_channel(tx_chan)); + tx_chan = NULL; + } + if (rx_chan != NULL) { + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_disable(rx_chan)); + I2S_ERROR_CHECK_RETURN_FALSE(i2s_del_channel(rx_chan)); + rx_chan = NULL; + } + if (rx_transform_buf != NULL) { + free(rx_transform_buf); + rx_transform_buf = NULL; + rx_transform_buf_len = 0; + } - //Peripheral manager deinit used pins - switch (_mode){ - case I2S_MODE_STD: + //Peripheral manager deinit used pins + switch (_mode) { + case I2S_MODE_STD: #if SOC_I2S_SUPPORTS_TDM - case I2S_MODE_TDM: + case I2S_MODE_TDM: #endif - perimanClearPinBus(_mclk); - perimanClearPinBus(_bclk); - perimanClearPinBus(_ws); - if (_dout >= 0) perimanClearPinBus(_dout); - if (_din >= 0) perimanClearPinBus(_din); - break; + perimanClearPinBus(_mclk); + perimanClearPinBus(_bclk); + perimanClearPinBus(_ws); + if (_dout >= 0) perimanClearPinBus(_dout); + if (_din >= 0) perimanClearPinBus(_din); + break; #if SOC_I2S_SUPPORTS_PDM_TX - case I2S_MODE_PDM_TX: - perimanClearPinBus(_tx_clk); - if (_tx_dout0 >= 0) perimanClearPinBus(_tx_dout0); - if (_tx_dout1 >= 0) perimanClearPinBus(_tx_dout1); - break; + case I2S_MODE_PDM_TX: + perimanClearPinBus(_tx_clk); + if (_tx_dout0 >= 0) perimanClearPinBus(_tx_dout0); + if (_tx_dout1 >= 0) perimanClearPinBus(_tx_dout1); + break; #endif #if SOC_I2S_SUPPORTS_PDM_RX - case I2S_MODE_PDM_RX: - perimanClearPinBus(_rx_clk); - if (_rx_din0 >= 0) perimanClearPinBus(_rx_din0); - if (_rx_din1 >= 0) perimanClearPinBus(_rx_din1); - if (_rx_din2 >= 0) perimanClearPinBus(_rx_din2); - if (_rx_din3 >= 0) perimanClearPinBus(_rx_din3); - break; + case I2S_MODE_PDM_RX: + perimanClearPinBus(_rx_clk); + if (_rx_din0 >= 0) perimanClearPinBus(_rx_din0); + if (_rx_din1 >= 0) perimanClearPinBus(_rx_din1); + if (_rx_din2 >= 0) perimanClearPinBus(_rx_din2); + if (_rx_din3 >= 0) perimanClearPinBus(_rx_din3); + break; #endif - default: - break; - } - return true; + default: + break; + } + return true; } -bool I2SClass::configureTX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask){ - /* Setup I2S channels */ - if (tx_chan != NULL) { - if(tx_sample_rate == rate && tx_data_bit_width == bits_cfg && tx_slot_mode == ch){ - return true; - } - i2s_std_config_t i2s_config = I2S_STD_CHAN_CFG(rate, bits_cfg, ch); - if(slot_mask >= 0 && (i2s_std_slot_mask_t)slot_mask <= I2S_STD_SLOT_BOTH){ - i2s_config.slot_cfg.slot_mask = (i2s_std_slot_mask_t)slot_mask; - } - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_disable(tx_chan)); - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_reconfig_std_clock(tx_chan, &i2s_config.clk_cfg)); - tx_sample_rate = rate; - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_reconfig_std_slot(tx_chan, &i2s_config.slot_cfg)); - tx_data_bit_width = bits_cfg; - tx_slot_mode = ch; - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_enable(tx_chan)); - return true; +bool I2SClass::configureTX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask) { + /* Setup I2S channels */ + if (tx_chan != NULL) { + if (tx_sample_rate == rate && tx_data_bit_width == bits_cfg && tx_slot_mode == ch) { + return true; } - return false; -} - -bool I2SClass::configureRX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, i2s_rx_transform_t transform){ - /* Setup I2S channels */ - if (rx_chan != NULL) { - if(rx_sample_rate != rate || rx_data_bit_width != bits_cfg || rx_slot_mode != ch){ - i2s_std_config_t i2s_config = I2S_STD_CHAN_CFG(rate, bits_cfg, ch); - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_disable(rx_chan)); - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_reconfig_std_clock(rx_chan, &i2s_config.clk_cfg)); - rx_sample_rate = rate; - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_reconfig_std_slot(rx_chan, &i2s_config.slot_cfg)); - rx_data_bit_width = bits_cfg; - rx_slot_mode = ch; - I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_enable(rx_chan)); - return transformRX(transform); - } - if(rx_transform != transform){ - return transformRX(transform); - } - return true; + i2s_std_config_t i2s_config = I2S_STD_CHAN_CFG(rate, bits_cfg, ch); + if (slot_mask >= 0 && (i2s_std_slot_mask_t)slot_mask <= I2S_STD_SLOT_BOTH) { + i2s_config.slot_cfg.slot_mask = (i2s_std_slot_mask_t)slot_mask; } - return false; + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_disable(tx_chan)); + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_reconfig_std_clock(tx_chan, &i2s_config.clk_cfg)); + tx_sample_rate = rate; + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_reconfig_std_slot(tx_chan, &i2s_config.slot_cfg)); + tx_data_bit_width = bits_cfg; + tx_slot_mode = ch; + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_enable(tx_chan)); + return true; + } + return false; } -size_t I2SClass::readBytes(char *buffer, size_t size){ - size_t bytes_read = 0; - size_t total_size = 0; - last_error = ESP_FAIL; - if(rx_chan == NULL){ - return total_size; +bool I2SClass::configureRX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, i2s_rx_transform_t transform) { + /* Setup I2S channels */ + if (rx_chan != NULL) { + if (rx_sample_rate != rate || rx_data_bit_width != bits_cfg || rx_slot_mode != ch) { + i2s_std_config_t i2s_config = I2S_STD_CHAN_CFG(rate, bits_cfg, ch); + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_disable(rx_chan)); + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_reconfig_std_clock(rx_chan, &i2s_config.clk_cfg)); + rx_sample_rate = rate; + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_reconfig_std_slot(rx_chan, &i2s_config.slot_cfg)); + rx_data_bit_width = bits_cfg; + rx_slot_mode = ch; + I2S_ERROR_CHECK_RETURN_FALSE(i2s_channel_enable(rx_chan)); + return transformRX(transform); } - while (total_size < size) { - bytes_read = size - total_size; - if(rx_transform_buf != NULL && bytes_read > I2S_READ_CHUNK_SIZE){ bytes_read = I2S_READ_CHUNK_SIZE; } - I2S_ERROR_CHECK_RETURN(rx_fn(rx_chan, rx_transform_buf, (char*)(buffer + total_size), bytes_read, &bytes_read, _timeout), 0); - total_size += bytes_read; + if (rx_transform != transform) { + return transformRX(transform); } + return true; + } + return false; +} + +size_t I2SClass::readBytes(char *buffer, size_t size) { + size_t bytes_read = 0; + size_t total_size = 0; + last_error = ESP_FAIL; + if (rx_chan == NULL) { return total_size; + } + while (total_size < size) { + bytes_read = size - total_size; + if (rx_transform_buf != NULL && bytes_read > I2S_READ_CHUNK_SIZE) { bytes_read = I2S_READ_CHUNK_SIZE; } + I2S_ERROR_CHECK_RETURN(rx_fn(rx_chan, rx_transform_buf, (char *)(buffer + total_size), bytes_read, &bytes_read, _timeout), 0); + total_size += bytes_read; + } + return total_size; } -size_t I2SClass::write(uint8_t *buffer, size_t size){ - size_t written = 0; - size_t bytes_sent = 0; - last_error = ESP_FAIL; - if(tx_chan == NULL){ - return written; - } - while(written < size){ - bytes_sent = size - written; - esp_err_t err = i2s_channel_write(tx_chan, (char*)(buffer + written), bytes_sent, &bytes_sent, _timeout); - setWriteError(err); - I2S_ERROR_CHECK_RETURN(err, written); - written += bytes_sent; - } +size_t I2SClass::write(uint8_t *buffer, size_t size) { + size_t written = 0; + size_t bytes_sent = 0; + last_error = ESP_FAIL; + if (tx_chan == NULL) { return written; + } + while (written < size) { + bytes_sent = size - written; + esp_err_t err = i2s_channel_write(tx_chan, (char *)(buffer + written), bytes_sent, &bytes_sent, _timeout); + setWriteError(err); + I2S_ERROR_CHECK_RETURN(err, written); + written += bytes_sent; + } + return written; } -i2s_chan_handle_t I2SClass::txChan(){ return tx_chan; } -uint32_t I2SClass::txSampleRate(){ return tx_sample_rate; } -i2s_data_bit_width_t I2SClass::txDataWidth(){ return tx_data_bit_width; } -i2s_slot_mode_t I2SClass::txSlotMode(){ return tx_slot_mode; } +i2s_chan_handle_t I2SClass::txChan() { + return tx_chan; +} +uint32_t I2SClass::txSampleRate() { + return tx_sample_rate; +} +i2s_data_bit_width_t I2SClass::txDataWidth() { + return tx_data_bit_width; +} +i2s_slot_mode_t I2SClass::txSlotMode() { + return tx_slot_mode; +} -i2s_chan_handle_t I2SClass::rxChan(){ return rx_chan; } -uint32_t I2SClass::rxSampleRate(){ return rx_sample_rate; } -i2s_data_bit_width_t I2SClass::rxDataWidth(){ return rx_data_bit_width; } -i2s_slot_mode_t I2SClass::rxSlotMode(){ return rx_slot_mode; } +i2s_chan_handle_t I2SClass::rxChan() { + return rx_chan; +} +uint32_t I2SClass::rxSampleRate() { + return rx_sample_rate; +} +i2s_data_bit_width_t I2SClass::rxDataWidth() { + return rx_data_bit_width; +} +i2s_slot_mode_t I2SClass::rxSlotMode() { + return rx_slot_mode; +} -int I2SClass::lastError(){ - return (int)last_error; +int I2SClass::lastError() { + return (int)last_error; } -int I2SClass::available(){ - if(rx_chan == NULL){ - return -1; - } - return I2S_READ_CHUNK_SIZE;// / (rx_data_bit_width/8); +int I2SClass::available() { + if (rx_chan == NULL) { + return -1; + } + return I2S_READ_CHUNK_SIZE; // / (rx_data_bit_width/8); }; -int I2SClass::peek(){ - return -1; +int I2SClass::peek() { + return -1; }; -int I2SClass::read(){ - int out = 0; - if(readBytes((char *)&out, rx_data_bit_width/8) == (rx_data_bit_width/8)){ - return out; - } - return -1; +int I2SClass::read() { + int out = 0; + if (readBytes((char *)&out, rx_data_bit_width / 8) == (rx_data_bit_width / 8)) { + return out; + } + return -1; }; -size_t I2SClass::write(uint8_t d){ - return write(&d, 1); -} - -bool I2SClass::transformRX(i2s_rx_transform_t transform){ - switch(transform){ - case I2S_RX_TRANSFORM_NONE: - allocTranformRX(0); - rx_fn = i2s_channel_read_default; - break; - - case I2S_RX_TRANSFORM_32_TO_16: - if(rx_data_bit_width != I2S_DATA_BIT_WIDTH_32BIT){ - log_e("Wrong data width. Should be 32bit"); - return false; - } - if(!allocTranformRX(I2S_READ_CHUNK_SIZE * 2)){ - return false; - } - rx_fn = i2s_channel_read_32_to_16; - rx_data_bit_width = I2S_DATA_BIT_WIDTH_16BIT; - break; - - case I2S_RX_TRANSFORM_16_STEREO_TO_MONO: - if(rx_slot_mode != I2S_SLOT_MODE_STEREO){ - log_e("Wrong slot mode. Should be Stereo"); - return false; - } - if(!allocTranformRX(I2S_READ_CHUNK_SIZE * 2)){ - return false; - } - rx_fn = i2s_channel_read_16_stereo_to_mono; - rx_slot_mode = I2S_SLOT_MODE_MONO; - break; - - default: - log_e("Unknown RX Transform %d", transform); - return false; - } - rx_transform = transform; - return true; +size_t I2SClass::write(uint8_t d) { + return write(&d, 1); } -bool I2SClass::allocTranformRX(size_t buf_len){ - char* buf = NULL; - if(buf_len == 0){ - if(rx_transform_buf != NULL){ - free(rx_transform_buf); - rx_transform_buf = NULL; - rx_transform_buf_len = 0; - } - return true; - } - if(rx_transform_buf == NULL || rx_transform_buf_len != buf_len){ - buf = (char*)malloc(buf_len); - if(buf == NULL){ - log_e("malloc %u failed!", buf_len); - return false; - } - if(rx_transform_buf != NULL){ - free(rx_transform_buf); - } - rx_transform_buf = buf; - rx_transform_buf_len = buf_len; +bool I2SClass::transformRX(i2s_rx_transform_t transform) { + switch (transform) { + case I2S_RX_TRANSFORM_NONE: + allocTranformRX(0); + rx_fn = i2s_channel_read_default; + break; + + case I2S_RX_TRANSFORM_32_TO_16: + if (rx_data_bit_width != I2S_DATA_BIT_WIDTH_32BIT) { + log_e("Wrong data width. Should be 32bit"); + return false; + } + if (!allocTranformRX(I2S_READ_CHUNK_SIZE * 2)) { + return false; + } + rx_fn = i2s_channel_read_32_to_16; + rx_data_bit_width = I2S_DATA_BIT_WIDTH_16BIT; + break; + + case I2S_RX_TRANSFORM_16_STEREO_TO_MONO: + if (rx_slot_mode != I2S_SLOT_MODE_STEREO) { + log_e("Wrong slot mode. Should be Stereo"); + return false; + } + if (!allocTranformRX(I2S_READ_CHUNK_SIZE * 2)) { + return false; + } + rx_fn = i2s_channel_read_16_stereo_to_mono; + rx_slot_mode = I2S_SLOT_MODE_MONO; + break; + + default: + log_e("Unknown RX Transform %d", transform); + return false; + } + rx_transform = transform; + return true; +} + +bool I2SClass::allocTranformRX(size_t buf_len) { + char *buf = NULL; + if (buf_len == 0) { + if (rx_transform_buf != NULL) { + free(rx_transform_buf); + rx_transform_buf = NULL; + rx_transform_buf_len = 0; } return true; + } + if (rx_transform_buf == NULL || rx_transform_buf_len != buf_len) { + buf = (char *)malloc(buf_len); + if (buf == NULL) { + log_e("malloc %u failed!", buf_len); + return false; + } + if (rx_transform_buf != NULL) { + free(rx_transform_buf); + } + rx_transform_buf = buf; + rx_transform_buf_len = buf_len; + } + return true; } const int WAVE_HEADER_SIZE = PCM_WAV_HEADER_SIZE; //Record PCM WAV with current RX settings -uint8_t * I2SClass::recordWAV(size_t rec_seconds, size_t * out_size){ +uint8_t *I2SClass::recordWAV(size_t rec_seconds, size_t *out_size) { uint32_t sample_rate = rxSampleRate(); uint16_t sample_width = (uint16_t)rxDataWidth(); uint16_t num_channels = (uint16_t)rxSlotMode(); @@ -759,16 +819,16 @@ uint8_t * I2SClass::recordWAV(size_t rec_seconds, size_t * out_size){ log_d("Record WAV: rate:%lu, bits:%u, channels:%u, size:%lu", sample_rate, sample_width, num_channels, rec_size); - uint8_t * wav_buf = (uint8_t*)malloc(rec_size + WAVE_HEADER_SIZE); - if(wav_buf == NULL){ + uint8_t *wav_buf = (uint8_t *)malloc(rec_size + WAVE_HEADER_SIZE); + if (wav_buf == NULL) { log_e("Failed to allocate WAV buffer with size %u", rec_size + WAVE_HEADER_SIZE); return NULL; } memcpy(wav_buf, &wav_header, WAVE_HEADER_SIZE); - size_t wav_size = readBytes((char*)(wav_buf + WAVE_HEADER_SIZE), rec_size); - if(wav_size < rec_size){ + size_t wav_size = readBytes((char *)(wav_buf + WAVE_HEADER_SIZE), rec_size); + if (wav_size < rec_size) { log_e("Recorded %u bytes from %u", wav_size, rec_size); - } else if(lastError()){ + } else if (lastError()) { log_e("Read Failed! %d", lastError()); } else { *out_size = rec_size + WAVE_HEADER_SIZE; @@ -778,15 +838,15 @@ uint8_t * I2SClass::recordWAV(size_t rec_seconds, size_t * out_size){ return NULL; } -void I2SClass::playWAV(uint8_t * data, size_t len){ - pcm_wav_header_t * header = (pcm_wav_header_t*)data; - if(header->fmt_chunk.audio_format != 1){ +void I2SClass::playWAV(uint8_t *data, size_t len) { + pcm_wav_header_t *header = (pcm_wav_header_t *)data; + if (header->fmt_chunk.audio_format != 1) { log_e("Audio format is not PCM!"); return; } - wav_data_chunk_t * data_chunk = &header->data_chunk; + wav_data_chunk_t *data_chunk = &header->data_chunk; size_t data_offset = 0; - while(memcmp(data_chunk->subchunk_id, "data", 4) != 0){ + while (memcmp(data_chunk->subchunk_id, "data", 4) != 0) { log_d("Skip chunk: %c%c%c%c, len: %lu", data_chunk->subchunk_id[0], data_chunk->subchunk_id[1], data_chunk->subchunk_id[2], data_chunk->subchunk_id[3], data_chunk->subchunk_size + 8); data_offset += data_chunk->subchunk_size + 8; data_chunk = (wav_data_chunk_t *)(data + WAVE_HEADER_SIZE + data_offset - 8); @@ -796,43 +856,42 @@ void I2SClass::playWAV(uint8_t * data, size_t len){ write(data + WAVE_HEADER_SIZE + data_offset, data_chunk->subchunk_size); } -bool I2SClass::playMP3(uint8_t *src, size_t src_len) -{ - int16_t outBuf[MAX_NCHAN * MAX_NGRAN * MAX_NSAMP]; - uint8_t *readPtr=NULL; - int bytesAvailable=0, err=0, offset=0; - MP3FrameInfo frameInfo; - HMP3Decoder decoder=NULL; +bool I2SClass::playMP3(uint8_t *src, size_t src_len) { + int16_t outBuf[MAX_NCHAN * MAX_NGRAN * MAX_NSAMP]; + uint8_t *readPtr = NULL; + int bytesAvailable = 0, err = 0, offset = 0; + MP3FrameInfo frameInfo; + HMP3Decoder decoder = NULL; - bytesAvailable = src_len; - readPtr = src; + bytesAvailable = src_len; + readPtr = src; - decoder = MP3InitDecoder(); - if (decoder == NULL){ - log_e("Could not allocate decoder"); - return false; - } + decoder = MP3InitDecoder(); + if (decoder == NULL) { + log_e("Could not allocate decoder"); + return false; + } - do { - offset = MP3FindSyncWord(readPtr, bytesAvailable); - if (offset < 0) { - break; - } - readPtr += offset; - bytesAvailable -= offset; - err = MP3Decode(decoder, &readPtr, &bytesAvailable, outBuf, 0); - if (err) { - log_e("Decode ERROR: %d", err); - MP3FreeDecoder(decoder); - return false; - } else { - MP3GetLastFrameInfo(decoder, &frameInfo); - configureTX(frameInfo.samprate, (i2s_data_bit_width_t)frameInfo.bitsPerSample, (i2s_slot_mode_t)frameInfo.nChans); - write((uint8_t*)outBuf, (size_t)((frameInfo.bitsPerSample / 8) * frameInfo.outputSamps)); - } - } while (true); - MP3FreeDecoder(decoder); - return true; + do { + offset = MP3FindSyncWord(readPtr, bytesAvailable); + if (offset < 0) { + break; + } + readPtr += offset; + bytesAvailable -= offset; + err = MP3Decode(decoder, &readPtr, &bytesAvailable, outBuf, 0); + if (err) { + log_e("Decode ERROR: %d", err); + MP3FreeDecoder(decoder); + return false; + } else { + MP3GetLastFrameInfo(decoder, &frameInfo); + configureTX(frameInfo.samprate, (i2s_data_bit_width_t)frameInfo.bitsPerSample, (i2s_slot_mode_t)frameInfo.nChans); + write((uint8_t *)outBuf, (size_t)((frameInfo.bitsPerSample / 8) * frameInfo.outputSamps)); + } + } while (true); + MP3FreeDecoder(decoder); + return true; } #endif /* SOC_I2S_SUPPORTED */ diff --git a/libraries/ESP_I2S/src/ESP_I2S.h b/libraries/ESP_I2S/src/ESP_I2S.h index 13d80dead87..dd4fb43ef16 100644 --- a/libraries/ESP_I2S/src/ESP_I2S.h +++ b/libraries/ESP_I2S/src/ESP_I2S.h @@ -13,129 +13,129 @@ #include "driver/i2s_pdm.h" #endif -typedef esp_err_t (*i2s_channel_read_fn)(i2s_chan_handle_t handle, char * tmp_buf, void *dest, size_t size, size_t *bytes_read, uint32_t timeout_ms); +typedef esp_err_t (*i2s_channel_read_fn)(i2s_chan_handle_t handle, char *tmp_buf, void *dest, size_t size, size_t *bytes_read, uint32_t timeout_ms); typedef enum { - I2S_MODE_STD, + I2S_MODE_STD, #if SOC_I2S_SUPPORTS_TDM - I2S_MODE_TDM, + I2S_MODE_TDM, #endif #if SOC_I2S_SUPPORTS_PDM_TX - I2S_MODE_PDM_TX, + I2S_MODE_PDM_TX, #endif #if SOC_I2S_SUPPORTS_PDM_RX - I2S_MODE_PDM_RX, + I2S_MODE_PDM_RX, #endif - I2S_MODE_MAX + I2S_MODE_MAX } i2s_mode_t; typedef enum { - I2S_RX_TRANSFORM_NONE, - I2S_RX_TRANSFORM_32_TO_16, - I2S_RX_TRANSFORM_16_STEREO_TO_MONO, - I2S_RX_TRANSFORM_MAX + I2S_RX_TRANSFORM_NONE, + I2S_RX_TRANSFORM_32_TO_16, + I2S_RX_TRANSFORM_16_STEREO_TO_MONO, + I2S_RX_TRANSFORM_MAX } i2s_rx_transform_t; -class I2SClass: public Stream { - public: - I2SClass(); - ~I2SClass(); +class I2SClass : public Stream { +public: + I2SClass(); + ~I2SClass(); - //STD + TDM mode - void setPins(int8_t bclk, int8_t ws, int8_t dout, int8_t din=-1, int8_t mclk=-1); - void setInverted(bool bclk, bool ws, bool mclk=false); + //STD + TDM mode + void setPins(int8_t bclk, int8_t ws, int8_t dout, int8_t din = -1, int8_t mclk = -1); + void setInverted(bool bclk, bool ws, bool mclk = false); - //PDM TX + PDM RX mode + //PDM TX + PDM RX mode #if SOC_I2S_SUPPORTS_PDM_TX - void setPinsPdmTx(int8_t clk, int8_t dout0, int8_t dout1=-1); + void setPinsPdmTx(int8_t clk, int8_t dout0, int8_t dout1 = -1); #endif #if SOC_I2S_SUPPORTS_PDM_RX - void setPinsPdmRx(int8_t clk, int8_t din0, int8_t din1=-1, int8_t din2=-1, int8_t din3=-1); + void setPinsPdmRx(int8_t clk, int8_t din0, int8_t din1 = -1, int8_t din2 = -1, int8_t din3 = -1); #endif #if SOC_I2S_SUPPORTS_PDM_TX || SOC_I2S_SUPPORTS_PDM_RX - void setInvertedPdm(bool clk); + void setInvertedPdm(bool clk); #endif - bool begin(i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask=-1); - bool configureTX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask=-1); - bool configureRX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, i2s_rx_transform_t transform=I2S_RX_TRANSFORM_NONE); - bool end(); + bool begin(i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask = -1); + bool configureTX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask = -1); + bool configureRX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, i2s_rx_transform_t transform = I2S_RX_TRANSFORM_NONE); + bool end(); - size_t readBytes(char *buffer, size_t size); - size_t write(uint8_t *buffer, size_t size); + size_t readBytes(char *buffer, size_t size); + size_t write(uint8_t *buffer, size_t size); - i2s_chan_handle_t txChan(); - uint32_t txSampleRate(); - i2s_data_bit_width_t txDataWidth(); - i2s_slot_mode_t txSlotMode(); + i2s_chan_handle_t txChan(); + uint32_t txSampleRate(); + i2s_data_bit_width_t txDataWidth(); + i2s_slot_mode_t txSlotMode(); - i2s_chan_handle_t rxChan(); - uint32_t rxSampleRate(); - i2s_data_bit_width_t rxDataWidth(); - i2s_slot_mode_t rxSlotMode(); + i2s_chan_handle_t rxChan(); + uint32_t rxSampleRate(); + i2s_data_bit_width_t rxDataWidth(); + i2s_slot_mode_t rxSlotMode(); - int lastError(); + int lastError(); - int available(); - int peek(); - int read(); - size_t write(uint8_t d); + int available(); + int peek(); + int read(); + size_t write(uint8_t d); - // Record short PCM WAV to memory with current RX settings. Returns buffer that must be freed by the user. - uint8_t * recordWAV(size_t rec_seconds, size_t * out_size); - // Play short PCM WAV from memory - void playWAV(uint8_t * data, size_t len); - // Play short MP3 from memory - bool playMP3(uint8_t *src, size_t src_len); + // Record short PCM WAV to memory with current RX settings. Returns buffer that must be freed by the user. + uint8_t *recordWAV(size_t rec_seconds, size_t *out_size); + // Play short PCM WAV from memory + void playWAV(uint8_t *data, size_t len); + // Play short MP3 from memory + bool playMP3(uint8_t *src, size_t src_len); - private: - esp_err_t last_error; - i2s_mode_t _mode; +private: + esp_err_t last_error; + i2s_mode_t _mode; - i2s_chan_handle_t tx_chan; - uint32_t tx_sample_rate; - i2s_data_bit_width_t tx_data_bit_width; - i2s_slot_mode_t tx_slot_mode; + i2s_chan_handle_t tx_chan; + uint32_t tx_sample_rate; + i2s_data_bit_width_t tx_data_bit_width; + i2s_slot_mode_t tx_slot_mode; - i2s_channel_read_fn rx_fn; - i2s_rx_transform_t rx_transform; - char * rx_transform_buf; - size_t rx_transform_buf_len; + i2s_channel_read_fn rx_fn; + i2s_rx_transform_t rx_transform; + char *rx_transform_buf; + size_t rx_transform_buf_len; - i2s_chan_handle_t rx_chan; - uint32_t rx_sample_rate; - i2s_data_bit_width_t rx_data_bit_width; - i2s_slot_mode_t rx_slot_mode; + i2s_chan_handle_t rx_chan; + uint32_t rx_sample_rate; + i2s_data_bit_width_t rx_data_bit_width; + i2s_slot_mode_t rx_slot_mode; - //STD and TDM mode - int8_t _mclk, _bclk, _ws, _dout, _din; - bool _mclk_inv, _bclk_inv, _ws_inv; + //STD and TDM mode + int8_t _mclk, _bclk, _ws, _dout, _din; + bool _mclk_inv, _bclk_inv, _ws_inv; - //PDM mode + //PDM mode #if SOC_I2S_SUPPORTS_PDM_RX - int8_t _rx_clk, _rx_din0, _rx_din1, _rx_din2, _rx_din3; //TODO: soc_caps.h 1/4 - bool _rx_clk_inv; + int8_t _rx_clk, _rx_din0, _rx_din1, _rx_din2, _rx_din3; //TODO: soc_caps.h 1/4 + bool _rx_clk_inv; #endif #if SOC_I2S_SUPPORTS_PDM_TX - int8_t _tx_clk, _tx_dout0, _tx_dout1; - bool _tx_clk_inv; + int8_t _tx_clk, _tx_dout0, _tx_dout1; + bool _tx_clk_inv; #endif - bool allocTranformRX(size_t buf_len); - bool transformRX(i2s_rx_transform_t transform); + bool allocTranformRX(size_t buf_len); + bool transformRX(i2s_rx_transform_t transform); - static bool i2sDetachBus(void * bus_pointer); - bool initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask); + static bool i2sDetachBus(void *bus_pointer); + bool initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask); #if SOC_I2S_SUPPORTS_TDM - bool initTDM(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask); + bool initTDM(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask); #endif #if SOC_I2S_SUPPORTS_PDM_TX - bool initPDMtx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch); + bool initPDMtx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch); #endif #if SOC_I2S_SUPPORTS_PDM_RX - bool initPDMrx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch); + bool initPDMrx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch); #endif }; -#endif /* SOC_I2S_SUPPORTED */ \ No newline at end of file +#endif /* SOC_I2S_SUPPORTED */ diff --git a/libraries/ESP_I2S/src/wav_header.h b/libraries/ESP_I2S/src/wav_header.h index 3969cac4043..f5d8f74913b 100644 --- a/libraries/ESP_I2S/src/wav_header.h +++ b/libraries/ESP_I2S/src/wav_header.h @@ -11,81 +11,79 @@ */ typedef struct { - char chunk_id[4]; /*!< Contains the letters "RIFF" in ASCII form */ - uint32_t chunk_size; /*!< This is the size of the rest of the chunk following this number */ - char chunk_format[4]; /*!< Contains the letters "WAVE" */ + char chunk_id[4]; /*!< Contains the letters "RIFF" in ASCII form */ + uint32_t chunk_size; /*!< This is the size of the rest of the chunk following this number */ + char chunk_format[4]; /*!< Contains the letters "WAVE" */ } __attribute__((packed)) wav_descriptor_chunk_t; /*!< Canonical WAVE format starts with the RIFF header */ typedef struct { - char subchunk_id[4]; /*!< Contains the letters "fmt " */ - uint32_t subchunk_size; /*!< PCM = 16, This is the size of the rest of the Subchunk which follows this number */ - uint16_t audio_format; /*!< PCM = 1, values other than 1 indicate some form of compression */ - uint16_t num_of_channels; /*!< Mono = 1, Stereo = 2, etc. */ - uint32_t sample_rate; /*!< 8000, 44100, etc. */ - uint32_t byte_rate; /*!< ==SampleRate * NumChannels * BitsPerSample s/ 8 */ - uint16_t block_align; /*!< ==NumChannels * BitsPerSample / 8 */ - uint16_t bits_per_sample; /*!< 8 bits = 8, 16 bits = 16, etc. */ + char subchunk_id[4]; /*!< Contains the letters "fmt " */ + uint32_t subchunk_size; /*!< PCM = 16, This is the size of the rest of the Subchunk which follows this number */ + uint16_t audio_format; /*!< PCM = 1, values other than 1 indicate some form of compression */ + uint16_t num_of_channels; /*!< Mono = 1, Stereo = 2, etc. */ + uint32_t sample_rate; /*!< 8000, 44100, etc. */ + uint32_t byte_rate; /*!< ==SampleRate * NumChannels * BitsPerSample s/ 8 */ + uint16_t block_align; /*!< ==NumChannels * BitsPerSample / 8 */ + uint16_t bits_per_sample; /*!< 8 bits = 8, 16 bits = 16, etc. */ } __attribute__((packed)) pcm_wav_fmt_chunk_t; /*!< The "fmt " subchunk describes the sound data's format */ typedef struct { - char subchunk_id[4]; /*!< Contains the letters "fmt " */ - uint32_t subchunk_size; /*!< ALAW/MULAW = 18, This is the size of the rest of the Subchunk which follows this number */ - uint16_t audio_format; /*!< ALAW = 6, MULAW = 7, values other than 1 indicate some form of compression */ - uint16_t num_of_channels; /*!< ALAW/MULAW = 1, Mono = 1, Stereo = 2, etc. */ - uint32_t sample_rate; /*!< ALAW/MULAW = 8000, 8000, 44100, etc. */ - uint32_t byte_rate; /*!< ALAW/MULAW = 8000, ==SampleRate * NumChannels * BitsPerSample s/ 8 */ - uint16_t block_align; /*!< ALAW/MULAW = 1, ==NumChannels * BitsPerSample / 8 */ - uint16_t bits_per_sample; /*!< ALAW/MULAW = 8, 8 bits = 8, 16 bits = 16, etc. */ - uint16_t ext_size; /*!< ALAW/MULAW = 0, Size of the extension (0 or 22) */ + char subchunk_id[4]; /*!< Contains the letters "fmt " */ + uint32_t subchunk_size; /*!< ALAW/MULAW = 18, This is the size of the rest of the Subchunk which follows this number */ + uint16_t audio_format; /*!< ALAW = 6, MULAW = 7, values other than 1 indicate some form of compression */ + uint16_t num_of_channels; /*!< ALAW/MULAW = 1, Mono = 1, Stereo = 2, etc. */ + uint32_t sample_rate; /*!< ALAW/MULAW = 8000, 8000, 44100, etc. */ + uint32_t byte_rate; /*!< ALAW/MULAW = 8000, ==SampleRate * NumChannels * BitsPerSample s/ 8 */ + uint16_t block_align; /*!< ALAW/MULAW = 1, ==NumChannels * BitsPerSample / 8 */ + uint16_t bits_per_sample; /*!< ALAW/MULAW = 8, 8 bits = 8, 16 bits = 16, etc. */ + uint16_t ext_size; /*!< ALAW/MULAW = 0, Size of the extension (0 or 22) */ } __attribute__((packed)) non_pcm_wav_fmt_chunk_t; /*!< The "fmt " subchunk describes the sound data's format */ typedef struct { - char subchunk_id[4]; /*!< Contains the letters "data" */ - uint32_t subchunk_size; /*!< ==NumSamples * NumChannels * BitsPerSample / 8 */ + char subchunk_id[4]; /*!< Contains the letters "data" */ + uint32_t subchunk_size; /*!< ==NumSamples * NumChannels * BitsPerSample / 8 */ } __attribute__((packed)) wav_data_chunk_t; /*!< The "data" subchunk contains the size of the data and the actual sound */ typedef struct { - wav_descriptor_chunk_t descriptor_chunk; /*!< Canonical WAVE format starts with the RIFF header */ - pcm_wav_fmt_chunk_t fmt_chunk; /*!< The "fmt " subchunk describes the sound data's format */ - wav_data_chunk_t data_chunk; /*!< The "data" subchunk contains the size of the data and the actual sound */ + wav_descriptor_chunk_t descriptor_chunk; /*!< Canonical WAVE format starts with the RIFF header */ + pcm_wav_fmt_chunk_t fmt_chunk; /*!< The "fmt " subchunk describes the sound data's format */ + wav_data_chunk_t data_chunk; /*!< The "data" subchunk contains the size of the data and the actual sound */ } __attribute__((packed)) pcm_wav_header_t; typedef struct { - wav_descriptor_chunk_t descriptor_chunk; /*!< Canonical WAVE format starts with the RIFF header */ - non_pcm_wav_fmt_chunk_t fmt_chunk; /*!< The "fmt " subchunk describes the sound data's format */ - wav_data_chunk_t data_chunk; /*!< The "data" subchunk contains the size of the data and the actual sound */ + wav_descriptor_chunk_t descriptor_chunk; /*!< Canonical WAVE format starts with the RIFF header */ + non_pcm_wav_fmt_chunk_t fmt_chunk; /*!< The "fmt " subchunk describes the sound data's format */ + wav_data_chunk_t data_chunk; /*!< The "data" subchunk contains the size of the data and the actual sound */ } __attribute__((packed)) non_pcm_wav_header_t; -#define WAVE_FORMAT_PCM 1 // PCM -#define WAVE_FORMAT_IEEE_FLOAT 3 // IEEE float -#define WAVE_FORMAT_ALAW 6 // 8-bit ITU-T G.711 A-law -#define WAVE_FORMAT_MULAW 7 // 8-bit ITU-T G.711 µ-law +#define WAVE_FORMAT_PCM 1 // PCM +#define WAVE_FORMAT_IEEE_FLOAT 3 // IEEE float +#define WAVE_FORMAT_ALAW 6 // 8-bit ITU-T G.711 A-law +#define WAVE_FORMAT_MULAW 7 // 8-bit ITU-T G.711 µ-law -#define PCM_WAV_HEADER_SIZE 44 +#define PCM_WAV_HEADER_SIZE 44 #define NON_PCM_WAV_HEADER_SIZE 46 /** * @brief Default header for PCM format WAV files * */ -#define PCM_WAV_HEADER_DEFAULT(wav_sample_size, wav_sample_bits, wav_sample_rate, wav_channel_num) { \ +#define PCM_WAV_HEADER_DEFAULT(wav_sample_size, wav_sample_bits, wav_sample_rate, wav_channel_num) \ + { \ .descriptor_chunk = { \ - .chunk_id = {'R', 'I', 'F', 'F'}, \ - .chunk_size = (wav_sample_size) + sizeof(pcm_wav_header_t) - 8, \ - .chunk_format = {'W', 'A', 'V', 'E'} \ - }, \ - .fmt_chunk = { \ - .subchunk_id = {'f', 'm', 't', ' '}, \ - .subchunk_size = 16, /* 16 for PCM */ \ - .audio_format = WAVE_FORMAT_PCM, /* 1 for PCM */ \ - .num_of_channels = (uint16_t)(wav_channel_num), \ - .sample_rate = (wav_sample_rate), \ - .byte_rate = (wav_sample_bits) * (wav_sample_rate) * (wav_channel_num) / 8, \ - .block_align = (uint16_t)((wav_sample_bits) * (wav_channel_num) / 8), \ - .bits_per_sample = (uint16_t)(wav_sample_bits)\ + .chunk_id = { 'R', 'I', 'F', 'F' }, \ + .chunk_size = (wav_sample_size) + sizeof(pcm_wav_header_t) - 8, \ + .chunk_format = { 'W', 'A', 'V', 'E' } \ }, \ + .fmt_chunk = { .subchunk_id = { 'f', 'm', 't', ' ' }, .subchunk_size = 16, /* 16 for PCM */ \ + .audio_format = WAVE_FORMAT_PCM, /* 1 for PCM */ \ + .num_of_channels = (uint16_t)(wav_channel_num), \ + .sample_rate = (wav_sample_rate), \ + .byte_rate = (wav_sample_bits) * (wav_sample_rate) * (wav_channel_num) / 8, \ + .block_align = (uint16_t)((wav_sample_bits) * (wav_channel_num) / 8), \ + .bits_per_sample = (uint16_t)(wav_sample_bits) }, \ .data_chunk = { \ - .subchunk_id = {'d', 'a', 't', 'a'}, \ - .subchunk_size = (wav_sample_size) \ + .subchunk_id = { 'd', 'a', 't', 'a' }, \ + .subchunk_size = (wav_sample_size) \ } \ -} + } diff --git a/libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Master/ESP_NOW_Broadcast_Master.ino b/libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Master/ESP_NOW_Broadcast_Master.ino index 240195b12c5..bd365db8b58 100644 --- a/libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Master/ESP_NOW_Broadcast_Master.ino +++ b/libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Master/ESP_NOW_Broadcast_Master.ino @@ -14,7 +14,7 @@ #include "ESP32_NOW.h" #include "WiFi.h" -#include // For the MAC2STR and MACSTR macros +#include // For the MAC2STR and MACSTR macros /* Definitions */ @@ -26,79 +26,79 @@ class ESP_NOW_Broadcast_Peer : public ESP_NOW_Peer { public: - // Constructor of the class using the broadcast address - ESP_NOW_Broadcast_Peer(uint8_t channel, wifi_interface_t iface, const uint8_t *lmk) + // Constructor of the class using the broadcast address + ESP_NOW_Broadcast_Peer(uint8_t channel, wifi_interface_t iface, const uint8_t *lmk) : ESP_NOW_Peer(ESP_NOW.BROADCAST_ADDR, channel, iface, lmk) {} - // Destructor of the class - ~ESP_NOW_Broadcast_Peer() { - remove(); - } + // Destructor of the class + ~ESP_NOW_Broadcast_Peer() { + remove(); + } - // Function to properly initialize the ESP-NOW and register the broadcast peer - bool begin() { - if (!ESP_NOW.begin() || !add()) { - log_e("Failed to initialize ESP-NOW or register the broadcast peer"); - return false; - } - return true; + // Function to properly initialize the ESP-NOW and register the broadcast peer + bool begin() { + if (!ESP_NOW.begin() || !add()) { + log_e("Failed to initialize ESP-NOW or register the broadcast peer"); + return false; } - - // Function to send a message to all devices within the network - bool send_message(const uint8_t *data, size_t len) { - if (!send(data, len)) { - log_e("Failed to broadcast message"); - return false; - } - return true; + return true; + } + + // Function to send a message to all devices within the network + bool send_message(const uint8_t *data, size_t len) { + if (!send(data, len)) { + log_e("Failed to broadcast message"); + return false; } + return true; + } }; /* Global Variables */ uint32_t msg_count = 0; -// Create a boradcast peer object +// Create a broadcast peer object ESP_NOW_Broadcast_Peer broadcast_peer(ESPNOW_WIFI_CHANNEL, WIFI_IF_STA, NULL); /* Main */ void setup() { - Serial.begin(115200); - while (!Serial) delay(10); - - // Initialize the Wi-Fi module - WiFi.mode(WIFI_STA); - WiFi.setChannel(ESPNOW_WIFI_CHANNEL); - while(!WiFi.STA.started()) delay(100); - - Serial.println("ESP-NOW Example - Broadcast Master"); - Serial.println("Wi-Fi parameters:"); - Serial.println(" Mode: STA"); - Serial.println(" MAC Address: " + WiFi.macAddress()); - Serial.printf(" Channel: %d\n", ESPNOW_WIFI_CHANNEL); - - // Register the broadcast peer - if (!broadcast_peer.begin()) { - Serial.println("Failed to initialize broadcast peer"); - Serial.println("Reebooting in 5 seconds..."); - delay(5000); - ESP.restart(); - } + Serial.begin(115200); + while (!Serial) delay(10); + + // Initialize the Wi-Fi module + WiFi.mode(WIFI_STA); + WiFi.setChannel(ESPNOW_WIFI_CHANNEL); + while (!WiFi.STA.started()) delay(100); + + Serial.println("ESP-NOW Example - Broadcast Master"); + Serial.println("Wi-Fi parameters:"); + Serial.println(" Mode: STA"); + Serial.println(" MAC Address: " + WiFi.macAddress()); + Serial.printf(" Channel: %d\n", ESPNOW_WIFI_CHANNEL); + + // Register the broadcast peer + if (!broadcast_peer.begin()) { + Serial.println("Failed to initialize broadcast peer"); + Serial.println("Reebooting in 5 seconds..."); + delay(5000); + ESP.restart(); + } - Serial.println("Setup complete. Broadcasting messages every 5 seconds."); + Serial.println("Setup complete. Broadcasting messages every 5 seconds."); } void loop() { - // Broadcast a message to all devices within the network - char data[32]; - snprintf(data, sizeof(data), "Hello, World! #%lu", msg_count++); + // Broadcast a message to all devices within the network + char data[32]; + snprintf(data, sizeof(data), "Hello, World! #%lu", msg_count++); - Serial.printf("Broadcasting message: %s\n", data); + Serial.printf("Broadcasting message: %s\n", data); - if (!broadcast_peer.send_message((uint8_t *)data, sizeof(data))) { - Serial.println("Failed to broadcast message"); - } + if (!broadcast_peer.send_message((uint8_t *)data, sizeof(data))) { + Serial.println("Failed to broadcast message"); + } - delay(5000); + delay(5000); } diff --git a/libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Slave/ESP_NOW_Broadcast_Slave.ino b/libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Slave/ESP_NOW_Broadcast_Slave.ino index 41b1ad27fa4..b3c9b2c1117 100644 --- a/libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Slave/ESP_NOW_Broadcast_Slave.ino +++ b/libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Slave/ESP_NOW_Broadcast_Slave.ino @@ -13,7 +13,7 @@ #include "ESP32_NOW.h" #include "WiFi.h" -#include // For the MAC2STR and MACSTR macros +#include // For the MAC2STR and MACSTR macros #include @@ -27,29 +27,30 @@ class ESP_NOW_Peer_Class : public ESP_NOW_Peer { public: - // Constructor of the class - ESP_NOW_Peer_Class(const uint8_t *mac_addr, - uint8_t channel, - wifi_interface_t iface, - const uint8_t *lmk) : ESP_NOW_Peer(mac_addr, channel, iface, lmk) {} - - // Destructor of the class - ~ESP_NOW_Peer_Class() {} - - // Function to register the master peer - bool add_peer() { - if (!add()) { - log_e("Failed to register the broadcast peer"); - return false; - } - return true; - } - - // Function to print the received messages from the master - void onReceive(const uint8_t *data, size_t len, bool broadcast) { - Serial.printf("Received a message from master " MACSTR " (%s)\n", MAC2STR(addr()), broadcast ? "broadcast" : "unicast"); - Serial.printf(" Message: %s\n", (char *)data); + // Constructor of the class + ESP_NOW_Peer_Class(const uint8_t *mac_addr, + uint8_t channel, + wifi_interface_t iface, + const uint8_t *lmk) + : ESP_NOW_Peer(mac_addr, channel, iface, lmk) {} + + // Destructor of the class + ~ESP_NOW_Peer_Class() {} + + // Function to register the master peer + bool add_peer() { + if (!add()) { + log_e("Failed to register the broadcast peer"); + return false; } + return true; + } + + // Function to print the received messages from the master + void onReceive(const uint8_t *data, size_t len, bool broadcast) { + Serial.printf("Received a message from master " MACSTR " (%s)\n", MAC2STR(addr()), broadcast ? "broadcast" : "unicast"); + Serial.printf(" Message: %s\n", (char *)data); + } }; /* Global Variables */ @@ -61,55 +62,55 @@ std::vector masters; // Callback called when an unknown peer sends a message void register_new_master(const esp_now_recv_info_t *info, const uint8_t *data, int len, void *arg) { - if (memcmp(info->des_addr, ESP_NOW.BROADCAST_ADDR, 6) == 0) { - Serial.printf("Unknown peer " MACSTR " sent a broadcast message\n", MAC2STR(info->src_addr)); - Serial.println("Registering the peer as a master"); - - ESP_NOW_Peer_Class new_master(info->src_addr, ESPNOW_WIFI_CHANNEL, WIFI_IF_STA, NULL); - - masters.push_back(new_master); - if (!masters.back().add_peer()) { - Serial.println("Failed to register the new master"); - return; - } - } else { - // The slave will only receive broadcast messages - log_v("Received a unicast message from " MACSTR, MAC2STR(info->src_addr)); - log_v("Igorning the message"); + if (memcmp(info->des_addr, ESP_NOW.BROADCAST_ADDR, 6) == 0) { + Serial.printf("Unknown peer " MACSTR " sent a broadcast message\n", MAC2STR(info->src_addr)); + Serial.println("Registering the peer as a master"); + + ESP_NOW_Peer_Class new_master(info->src_addr, ESPNOW_WIFI_CHANNEL, WIFI_IF_STA, NULL); + + masters.push_back(new_master); + if (!masters.back().add_peer()) { + Serial.println("Failed to register the new master"); + return; } + } else { + // The slave will only receive broadcast messages + log_v("Received a unicast message from " MACSTR, MAC2STR(info->src_addr)); + log_v("Igorning the message"); + } } /* Main */ void setup() { - Serial.begin(115200); - while (!Serial) delay(10); - - // Initialize the Wi-Fi module - WiFi.mode(WIFI_STA); - WiFi.setChannel(ESPNOW_WIFI_CHANNEL); - while(!WiFi.STA.started()) delay(100); - - Serial.println("ESP-NOW Example - Broadcast Slave"); - Serial.println("Wi-Fi parameters:"); - Serial.println(" Mode: STA"); - Serial.println(" MAC Address: " + WiFi.macAddress()); - Serial.printf(" Channel: %d\n", ESPNOW_WIFI_CHANNEL); - - // Initialize the ESP-NOW protocol - if (!ESP_NOW.begin()) { - Serial.println("Failed to initialize ESP-NOW"); - Serial.println("Reeboting in 5 seconds..."); - delay(5000); - ESP.restart(); - } - - // Register the new peer callback - ESP_NOW.onNewPeer(register_new_master, NULL); - - Serial.println("Setup complete. Waiting for a master to broadcast a message..."); + Serial.begin(115200); + while (!Serial) delay(10); + + // Initialize the Wi-Fi module + WiFi.mode(WIFI_STA); + WiFi.setChannel(ESPNOW_WIFI_CHANNEL); + while (!WiFi.STA.started()) delay(100); + + Serial.println("ESP-NOW Example - Broadcast Slave"); + Serial.println("Wi-Fi parameters:"); + Serial.println(" Mode: STA"); + Serial.println(" MAC Address: " + WiFi.macAddress()); + Serial.printf(" Channel: %d\n", ESPNOW_WIFI_CHANNEL); + + // Initialize the ESP-NOW protocol + if (!ESP_NOW.begin()) { + Serial.println("Failed to initialize ESP-NOW"); + Serial.println("Reeboting in 5 seconds..."); + delay(5000); + ESP.restart(); + } + + // Register the new peer callback + ESP_NOW.onNewPeer(register_new_master, NULL); + + Serial.println("Setup complete. Waiting for a master to broadcast a message..."); } void loop() { - delay(1000); + delay(1000); } diff --git a/libraries/ESP_NOW/examples/ESP_NOW_Network/ESP_NOW_Network.ino b/libraries/ESP_NOW/examples/ESP_NOW_Network/ESP_NOW_Network.ino index b406d66a081..34e9e641b54 100644 --- a/libraries/ESP_NOW/examples/ESP_NOW_Network/ESP_NOW_Network.ino +++ b/libraries/ESP_NOW/examples/ESP_NOW_Network/ESP_NOW_Network.ino @@ -29,7 +29,7 @@ #include "ESP32_NOW.h" #include "WiFi.h" -#include // For the MAC2STR and MACSTR macros +#include // For the MAC2STR and MACSTR macros #include @@ -78,11 +78,11 @@ // The maximum size of the complete message is 250 bytes (ESP_NOW_MAX_DATA_LEN). typedef struct { - uint32_t count; - uint32_t priority; - uint32_t data; - bool ready; - char str[7]; + uint32_t count; + uint32_t priority; + uint32_t data; + bool ready; + char str[7]; } __attribute__((packed)) esp_now_data_t; /* Global Variables */ @@ -104,267 +104,264 @@ std::vector last_data(5); // Vector that will store the last 5 data r class ESP_NOW_Network_Peer : public ESP_NOW_Peer { public: - uint32_t priority; - bool peer_is_master = false; - bool peer_ready = false; + uint32_t priority; + bool peer_is_master = false; + bool peer_ready = false; - ESP_NOW_Network_Peer(const uint8_t *mac_addr, uint32_t priority = 0, const uint8_t *lmk = (const uint8_t *)ESPNOW_EXAMPLE_LMK) - : ESP_NOW_Peer(mac_addr, ESPNOW_WIFI_CHANNEL, ESPNOW_WIFI_IFACE, lmk) - , priority(priority) {} + ESP_NOW_Network_Peer(const uint8_t *mac_addr, uint32_t priority = 0, const uint8_t *lmk = (const uint8_t *)ESPNOW_EXAMPLE_LMK) + : ESP_NOW_Peer(mac_addr, ESPNOW_WIFI_CHANNEL, ESPNOW_WIFI_IFACE, lmk), priority(priority) {} - ~ESP_NOW_Network_Peer() {} + ~ESP_NOW_Network_Peer() {} - bool begin() { - // In this example the ESP-NOW protocol will already be initialized as we require it to receive broadcast messages. - if (!add()) { - log_e("Failed to initialize ESP-NOW or register the peer"); - return false; - } - return true; + bool begin() { + // In this example the ESP-NOW protocol will already be initialized as we require it to receive broadcast messages. + if (!add()) { + log_e("Failed to initialize ESP-NOW or register the peer"); + return false; } + return true; + } - bool send_message(const uint8_t *data, size_t len) { - if (data == NULL || len == 0) { - log_e("Data to be sent is NULL or has a length of 0"); - return false; - } - - // Call the parent class method to send the data - return send(data, len); + bool send_message(const uint8_t *data, size_t len) { + if (data == NULL || len == 0) { + log_e("Data to be sent is NULL or has a length of 0"); + return false; } - void onReceive(const uint8_t *data, size_t len, bool broadcast) { - esp_now_data_t *msg = (esp_now_data_t *)data; + // Call the parent class method to send the data + return send(data, len); + } - if (peer_ready == false && msg->ready == true) { - Serial.printf("Peer " MACSTR " reported ready\n", MAC2STR(addr())); - peer_ready = true; - } + void onReceive(const uint8_t *data, size_t len, bool broadcast) { + esp_now_data_t *msg = (esp_now_data_t *)data; - if (!broadcast) { - recv_msg_count++; - if (device_is_master) { - Serial.printf("Received a message from peer " MACSTR "\n", MAC2STR(addr())); - Serial.printf(" Count: %lu\n", msg->count); - Serial.printf(" Random data: %lu\n", msg->data); - last_data.push_back(msg->data); - last_data.erase(last_data.begin()); - } else if (peer_is_master) { - Serial.println("Received a message from the master"); - Serial.printf(" Average data: %lu\n", msg->data); - } - else { - Serial.printf("Peer " MACSTR " says: %s\n", MAC2STR(addr()), msg->str); - } - } + if (peer_ready == false && msg->ready == true) { + Serial.printf("Peer " MACSTR " reported ready\n", MAC2STR(addr())); + peer_ready = true; } - void onSent(bool success) { - bool broadcast = memcmp(addr(), ESP_NOW.BROADCAST_ADDR, ESP_NOW_ETH_ALEN) == 0; - if (broadcast) { - log_i("Broadcast message reported as sent %s", success ? "successfully" : "unsuccessfully"); - } - else { - log_i("Unicast message reported as sent %s to peer " MACSTR, success ? "successfully" : "unsuccessfully", MAC2STR(addr())); - } + if (!broadcast) { + recv_msg_count++; + if (device_is_master) { + Serial.printf("Received a message from peer " MACSTR "\n", MAC2STR(addr())); + Serial.printf(" Count: %lu\n", msg->count); + Serial.printf(" Random data: %lu\n", msg->data); + last_data.push_back(msg->data); + last_data.erase(last_data.begin()); + } else if (peer_is_master) { + Serial.println("Received a message from the master"); + Serial.printf(" Average data: %lu\n", msg->data); + } else { + Serial.printf("Peer " MACSTR " says: %s\n", MAC2STR(addr()), msg->str); + } } + } + + void onSent(bool success) { + bool broadcast = memcmp(addr(), ESP_NOW.BROADCAST_ADDR, ESP_NOW_ETH_ALEN) == 0; + if (broadcast) { + log_i("Broadcast message reported as sent %s", success ? "successfully" : "unsuccessfully"); + } else { + log_i("Unicast message reported as sent %s to peer " MACSTR, success ? "successfully" : "unsuccessfully", MAC2STR(addr())); + } + } }; /* Peers */ -std::vector peers; // Create a vector to store the peer pointers -ESP_NOW_Network_Peer broadcast_peer(ESP_NOW.BROADCAST_ADDR, 0, NULL); // Register the broadcast peer (no encryption support for the broadcast address) -ESP_NOW_Network_Peer *master_peer = nullptr; // Pointer to peer that is the master +std::vector peers; // Create a vector to store the peer pointers +ESP_NOW_Network_Peer broadcast_peer(ESP_NOW.BROADCAST_ADDR, 0, NULL); // Register the broadcast peer (no encryption support for the broadcast address) +ESP_NOW_Network_Peer *master_peer = nullptr; // Pointer to peer that is the master /* Helper functions */ // Function to reboot the device void fail_reboot() { - Serial.println("Rebooting in 5 seconds..."); - delay(5000); - ESP.restart(); + Serial.println("Rebooting in 5 seconds..."); + delay(5000); + ESP.restart(); } // Function to check which device has the highest priority uint32_t check_highest_priority() { - uint32_t highest_priority = 0; - for (auto &peer : peers) { - if (peer->priority > highest_priority) { - highest_priority = peer->priority; - } + uint32_t highest_priority = 0; + for (auto &peer : peers) { + if (peer->priority > highest_priority) { + highest_priority = peer->priority; } - return std::max(highest_priority, self_priority); + } + return std::max(highest_priority, self_priority); } // Function to calculate the average of the data received uint32_t calc_average() { - uint32_t avg = 0; - for (auto &d : last_data) { - avg += d; - } - avg /= last_data.size(); - return avg; + uint32_t avg = 0; + for (auto &d : last_data) { + avg += d; + } + avg /= last_data.size(); + return avg; } // Function to check if all peers are ready bool check_all_peers_ready() { - for (auto &peer : peers) { - if (!peer->peer_ready) { - return false; - } + for (auto &peer : peers) { + if (!peer->peer_ready) { + return false; } - return true; + } + return true; } /* Callbacks */ // Callback called when a new peer is found void register_new_peer(const esp_now_recv_info_t *info, const uint8_t *data, int len, void *arg) { - esp_now_data_t *msg = (esp_now_data_t *)data; - int priority = msg->priority; - - if (priority == self_priority) { - Serial.println("ERROR! Device has the same priority as this device. Unsupported behavior."); - fail_reboot(); + esp_now_data_t *msg = (esp_now_data_t *)data; + int priority = msg->priority; + + if (priority == self_priority) { + Serial.println("ERROR! Device has the same priority as this device. Unsupported behavior."); + fail_reboot(); + } + + if (current_peer_count < ESPNOW_PEER_COUNT) { + Serial.printf("New peer found: " MACSTR " with priority %d\n", MAC2STR(info->src_addr), priority); + ESP_NOW_Network_Peer *new_peer = new ESP_NOW_Network_Peer(info->src_addr, priority); + if (new_peer == nullptr || !new_peer->begin()) { + Serial.println("Failed to create or register the new peer"); + delete new_peer; + return; } - - if (current_peer_count < ESPNOW_PEER_COUNT) { - Serial.printf("New peer found: " MACSTR " with priority %d\n", MAC2STR(info->src_addr), priority); - ESP_NOW_Network_Peer *new_peer = new ESP_NOW_Network_Peer(info->src_addr, priority); - if (new_peer == nullptr || !new_peer->begin()) { - Serial.println("Failed to create or register the new peer"); - delete new_peer; - return; - } - peers.push_back(new_peer); - current_peer_count++; - if (current_peer_count == ESPNOW_PEER_COUNT) { - Serial.println("All peers have been found"); - new_msg.ready = true; - } + peers.push_back(new_peer); + current_peer_count++; + if (current_peer_count == ESPNOW_PEER_COUNT) { + Serial.println("All peers have been found"); + new_msg.ready = true; } + } } /* Main */ void setup() { - uint8_t self_mac[6]; - - Serial.begin(115200); - while (!Serial) delay(10); - - // Initialize the Wi-Fi module - WiFi.mode(WIFI_STA); - WiFi.setChannel(ESPNOW_WIFI_CHANNEL); - while(!WiFi.STA.started()) delay(100); - - Serial.println("ESP-NOW Network Example"); - Serial.println("Wi-Fi parameters:"); - Serial.println(" Mode: STA"); - Serial.println(" MAC Address: " + WiFi.macAddress()); - Serial.printf(" Channel: %d\n", ESPNOW_WIFI_CHANNEL); - - // Generate yhis device's priority based on the 3 last bytes of the MAC address - WiFi.macAddress(self_mac); - self_priority = self_mac[3] << 16 | self_mac[4] << 8 | self_mac[5]; - Serial.printf("This device's priority: %lu\n", self_priority); - - // Initialize the ESP-NOW protocol - if (!ESP_NOW.begin((const uint8_t *)ESPNOW_EXAMPLE_PMK)) { - Serial.println("Failed to initialize ESP-NOW"); - fail_reboot(); - } - - if (!broadcast_peer.begin()) { - Serial.println("Failed to initialize broadcast peer"); - fail_reboot(); - } - - // Register the callback to be called when a new peer is found - ESP_NOW.onNewPeer(register_new_peer, NULL); - - Serial.println("Setup complete. Broadcasting own priority to find the master..."); - memset(&new_msg, 0, sizeof(new_msg)); - strncpy(new_msg.str, "Hello!", sizeof(new_msg.str)); - new_msg.priority = self_priority; + uint8_t self_mac[6]; + + Serial.begin(115200); + while (!Serial) delay(10); + + // Initialize the Wi-Fi module + WiFi.mode(WIFI_STA); + WiFi.setChannel(ESPNOW_WIFI_CHANNEL); + while (!WiFi.STA.started()) delay(100); + + Serial.println("ESP-NOW Network Example"); + Serial.println("Wi-Fi parameters:"); + Serial.println(" Mode: STA"); + Serial.println(" MAC Address: " + WiFi.macAddress()); + Serial.printf(" Channel: %d\n", ESPNOW_WIFI_CHANNEL); + + // Generate yhis device's priority based on the 3 last bytes of the MAC address + WiFi.macAddress(self_mac); + self_priority = self_mac[3] << 16 | self_mac[4] << 8 | self_mac[5]; + Serial.printf("This device's priority: %lu\n", self_priority); + + // Initialize the ESP-NOW protocol + if (!ESP_NOW.begin((const uint8_t *)ESPNOW_EXAMPLE_PMK)) { + Serial.println("Failed to initialize ESP-NOW"); + fail_reboot(); + } + + if (!broadcast_peer.begin()) { + Serial.println("Failed to initialize broadcast peer"); + fail_reboot(); + } + + // Register the callback to be called when a new peer is found + ESP_NOW.onNewPeer(register_new_peer, NULL); + + Serial.println("Setup complete. Broadcasting own priority to find the master..."); + memset(&new_msg, 0, sizeof(new_msg)); + strncpy(new_msg.str, "Hello!", sizeof(new_msg.str)); + new_msg.priority = self_priority; } void loop() { - if (!master_decided) { - // Broadcast the priority to find the master - if (!broadcast_peer.send_message((const uint8_t *)&new_msg, sizeof(new_msg))) { - Serial.println("Failed to broadcast message"); - } + if (!master_decided) { + // Broadcast the priority to find the master + if (!broadcast_peer.send_message((const uint8_t *)&new_msg, sizeof(new_msg))) { + Serial.println("Failed to broadcast message"); + } - // Check if all peers have been found - if (current_peer_count == ESPNOW_PEER_COUNT) { - // Wait until all peers are ready - if (check_all_peers_ready()) { - Serial.println("All peers are ready"); - // Check which device has the highest priority - master_decided = true; - uint32_t highest_priority = check_highest_priority(); - if (highest_priority == self_priority) { - device_is_master = true; - Serial.println("This device is the master"); - } else { - for (int i = 0; i < ESPNOW_PEER_COUNT; i++) { - if (peers[i]->priority == highest_priority) { - peers[i]->peer_is_master = true; - master_peer = peers[i]; - Serial.printf("Peer " MACSTR " is the master with priority %lu\n", MAC2STR(peers[i]->addr()), highest_priority); - break; - } - } - } - Serial.println("The master has been decided"); - } else { - Serial.println("Waiting for all peers to be ready..."); + // Check if all peers have been found + if (current_peer_count == ESPNOW_PEER_COUNT) { + // Wait until all peers are ready + if (check_all_peers_ready()) { + Serial.println("All peers are ready"); + // Check which device has the highest priority + master_decided = true; + uint32_t highest_priority = check_highest_priority(); + if (highest_priority == self_priority) { + device_is_master = true; + Serial.println("This device is the master"); + } else { + for (int i = 0; i < ESPNOW_PEER_COUNT; i++) { + if (peers[i]->priority == highest_priority) { + peers[i]->peer_is_master = true; + master_peer = peers[i]; + Serial.printf("Peer " MACSTR " is the master with priority %lu\n", MAC2STR(peers[i]->addr()), highest_priority); + break; } + } } - } else { - if (!device_is_master) { - // Send a message to the master - new_msg.count = sent_msg_count + 1; - new_msg.data = random(10000); - if (!master_peer->send_message((const uint8_t *)&new_msg, sizeof(new_msg))) { - Serial.println("Failed to send message to the master"); + Serial.println("The master has been decided"); + } else { + Serial.println("Waiting for all peers to be ready..."); + } + } + } else { + if (!device_is_master) { + // Send a message to the master + new_msg.count = sent_msg_count + 1; + new_msg.data = random(10000); + if (!master_peer->send_message((const uint8_t *)&new_msg, sizeof(new_msg))) { + Serial.println("Failed to send message to the master"); + } else { + Serial.printf("Sent message to the master. Count: %lu, Data: %lu\n", new_msg.count, new_msg.data); + sent_msg_count++; + } + + // Check if it is time to report to peers + if (sent_msg_count % REPORT_INTERVAL == 0) { + // Send a message to the peers + for (auto &peer : peers) { + if (!peer->peer_is_master) { + if (!peer->send_message((const uint8_t *)&new_msg, sizeof(new_msg))) { + Serial.printf("Failed to send message to peer " MACSTR "\n", MAC2STR(peer->addr())); } else { - Serial.printf("Sent message to the master. Count: %lu, Data: %lu\n", new_msg.count, new_msg.data); - sent_msg_count++; - } - - // Check if it is time to report to peers - if (sent_msg_count % REPORT_INTERVAL == 0) { - // Send a message to the peers - for (auto &peer : peers) { - if (!peer->peer_is_master) { - if (!peer->send_message((const uint8_t *)&new_msg, sizeof(new_msg))) { - Serial.printf("Failed to send message to peer " MACSTR "\n", MAC2STR(peer->addr())); - } else { - Serial.printf("Sent message \"%s\" to peer " MACSTR "\n", new_msg.str, MAC2STR(peer->addr())); - } - } - } - } - } else { - // Check if it is time to report to peers - if (recv_msg_count % REPORT_INTERVAL == 0) { - // Report average data to the peers - uint32_t avg = calc_average(); - new_msg.data = avg; - for (auto &peer : peers) { - new_msg.count = sent_msg_count + 1; - if (!peer->send_message((const uint8_t *)&new_msg, sizeof(new_msg))) { - Serial.printf("Failed to send message to peer " MACSTR "\n", MAC2STR(peer->addr())); - } else { - Serial.printf("Sent message to peer " MACSTR ". Recv: %lu, Sent: %lu, Avg: %lu\n", MAC2STR(peer->addr()), recv_msg_count, new_msg.count, new_msg.data); - sent_msg_count++; - } - } + Serial.printf("Sent message \"%s\" to peer " MACSTR "\n", new_msg.str, MAC2STR(peer->addr())); } + } + } + } + } else { + // Check if it is time to report to peers + if (recv_msg_count % REPORT_INTERVAL == 0) { + // Report average data to the peers + uint32_t avg = calc_average(); + new_msg.data = avg; + for (auto &peer : peers) { + new_msg.count = sent_msg_count + 1; + if (!peer->send_message((const uint8_t *)&new_msg, sizeof(new_msg))) { + Serial.printf("Failed to send message to peer " MACSTR "\n", MAC2STR(peer->addr())); + } else { + Serial.printf("Sent message to peer " MACSTR ". Recv: %lu, Sent: %lu, Avg: %lu\n", MAC2STR(peer->addr()), recv_msg_count, new_msg.count, new_msg.data); + sent_msg_count++; + } } + } } + } - delay(ESPNOW_SEND_INTERVAL_MS); + delay(ESPNOW_SEND_INTERVAL_MS); } diff --git a/libraries/ESP_NOW/examples/ESP_NOW_Serial/ESP_NOW_Serial.ino b/libraries/ESP_NOW/examples/ESP_NOW_Serial/ESP_NOW_Serial.ino index c1896f6d9cb..6da3c0759cb 100644 --- a/libraries/ESP_NOW/examples/ESP_NOW_Serial/ESP_NOW_Serial.ino +++ b/libraries/ESP_NOW/examples/ESP_NOW_Serial/ESP_NOW_Serial.ino @@ -29,56 +29,53 @@ // Channel to be used by the ESP-NOW protocol #define ESPNOW_WIFI_CHANNEL 1 -#if ESPNOW_WIFI_MODE_STATION // ESP-NOW using WiFi Station mode - #define ESPNOW_WIFI_MODE WIFI_STA // WiFi Mode - #define ESPNOW_WIFI_IF WIFI_IF_STA // WiFi Interface -#else // ESP-NOW using WiFi AP mode - #define ESPNOW_WIFI_MODE WIFI_AP // WiFi Mode - #define ESPNOW_WIFI_IF WIFI_IF_AP // WiFi Interface +#if ESPNOW_WIFI_MODE_STATION // ESP-NOW using WiFi Station mode +#define ESPNOW_WIFI_MODE WIFI_STA // WiFi Mode +#define ESPNOW_WIFI_IF WIFI_IF_STA // WiFi Interface +#else // ESP-NOW using WiFi AP mode +#define ESPNOW_WIFI_MODE WIFI_AP // WiFi Mode +#define ESPNOW_WIFI_IF WIFI_IF_AP // WiFi Interface #endif // Set the MAC address of the device that will receive the data // For example: F4:12:FA:40:64:4C -const MacAddress peer_mac({0xF4, 0x12, 0xFA, 0x40, 0x64, 0x4C}); +const MacAddress peer_mac({ 0xF4, 0x12, 0xFA, 0x40, 0x64, 0x4C }); ESP_NOW_Serial_Class NowSerial(peer_mac, ESPNOW_WIFI_CHANNEL, ESPNOW_WIFI_IF); void setup() { - Serial.begin(115200); + Serial.begin(115200); - Serial.print("WiFi Mode: "); - Serial.println(ESPNOW_WIFI_MODE == WIFI_AP ? "AP" : "Station"); - WiFi.mode(ESPNOW_WIFI_MODE); + Serial.print("WiFi Mode: "); + Serial.println(ESPNOW_WIFI_MODE == WIFI_AP ? "AP" : "Station"); + WiFi.mode(ESPNOW_WIFI_MODE); - Serial.print("Channel: "); - Serial.println(ESPNOW_WIFI_CHANNEL); - WiFi.setChannel(ESPNOW_WIFI_CHANNEL, WIFI_SECOND_CHAN_NONE); + Serial.print("Channel: "); + Serial.println(ESPNOW_WIFI_CHANNEL); + WiFi.setChannel(ESPNOW_WIFI_CHANNEL, WIFI_SECOND_CHAN_NONE); - while(!(WiFi.STA.started() || WiFi.AP.started())) delay(100); + while (!(WiFi.STA.started() || WiFi.AP.started())) delay(100); - Serial.print("MAC Address: "); - Serial.println(ESPNOW_WIFI_MODE == WIFI_AP ? WiFi.softAPmacAddress() : WiFi.macAddress()); + Serial.print("MAC Address: "); + Serial.println(ESPNOW_WIFI_MODE == WIFI_AP ? WiFi.softAPmacAddress() : WiFi.macAddress()); - // Start the ESP-NOW communication - Serial.println("ESP-NOW communication starting..."); - NowSerial.begin(115200); - Serial.println("You can now send data to the peer device using the Serial Monitor.\n"); + // Start the ESP-NOW communication + Serial.println("ESP-NOW communication starting..."); + NowSerial.begin(115200); + Serial.println("You can now send data to the peer device using the Serial Monitor.\n"); } void loop() { - while (NowSerial.available()) - { - Serial.write(NowSerial.read()); + while (NowSerial.available()) { + Serial.write(NowSerial.read()); + } + + while (Serial.available() && NowSerial.availableForWrite()) { + if (NowSerial.write(Serial.read()) <= 0) { + Serial.println("Failed to send data"); + break; } + } - while (Serial.available() && NowSerial.availableForWrite()) - { - if (NowSerial.write(Serial.read()) <= 0) - { - Serial.println("Failed to send data"); - break; - } - } - - delay(1); + delay(1); } diff --git a/libraries/ESP_NOW/library.properties b/libraries/ESP_NOW/library.properties index e07c55d5aa2..d0f2b2c7783 100755 --- a/libraries/ESP_NOW/library.properties +++ b/libraries/ESP_NOW/library.properties @@ -6,4 +6,4 @@ sentence=Library for ESP_NOW paragraph=Supports ESP32 Arduino platforms. category=Sensor url=https://github.com/espressif/arduino-esp32/ -architectures=esp32 \ No newline at end of file +architectures=esp32 diff --git a/libraries/ESP_NOW/src/ESP32_NOW.cpp b/libraries/ESP_NOW/src/ESP32_NOW.cpp index 3e2329e7a8c..a27fafac15e 100644 --- a/libraries/ESP_NOW/src/ESP32_NOW.cpp +++ b/libraries/ESP_NOW/src/ESP32_NOW.cpp @@ -4,262 +4,262 @@ #include "esp32-hal.h" #include "esp_wifi.h" -static void (*new_cb)(const esp_now_recv_info_t *info, const uint8_t * data, int len, void * arg) = NULL; -static void * new_arg = NULL;// * tx_arg = NULL, * rx_arg = NULL, +static void (*new_cb)(const esp_now_recv_info_t *info, const uint8_t *data, int len, void *arg) = NULL; +static void *new_arg = NULL; // * tx_arg = NULL, * rx_arg = NULL, static bool _esp_now_has_begun = false; -static ESP_NOW_Peer * _esp_now_peers[ESP_NOW_MAX_TOTAL_PEER_NUM]; - -static esp_err_t _esp_now_add_peer(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk, ESP_NOW_Peer * _peer=NULL){ - log_v(MACSTR, MAC2STR(mac_addr)); - if (esp_now_is_peer_exist(mac_addr)) { - log_e("Peer Already Exists"); - return ESP_ERR_ESPNOW_EXIST; - } - - esp_now_peer_info_t peer; - memset(&peer, 0, sizeof(esp_now_peer_info_t)); - memcpy(peer.peer_addr, mac_addr, ESP_NOW_ETH_ALEN); - peer.channel = channel; - peer.ifidx = iface; - peer.encrypt = lmk != NULL; - if(lmk){ - memcpy(peer.lmk, lmk, ESP_NOW_KEY_LEN); - } - - esp_err_t result = esp_now_add_peer(&peer); - if(result == ESP_OK){ - if(_peer != NULL){ - for(uint8_t i=0; iaddr(), ESP_NOW_ETH_ALEN) == 0){ - _esp_now_peers[i] = NULL; - break; - } - } - return result; +static esp_err_t _esp_now_del_peer(const uint8_t *mac_addr) { + esp_err_t result = esp_now_del_peer(mac_addr); + if (result == ESP_ERR_ESPNOW_NOT_INIT) { + log_e("ESPNOW Not Init"); + } else if (result == ESP_ERR_ESPNOW_ARG) { + log_e("Invalid Argument"); + } else if (result == ESP_ERR_ESPNOW_NOT_FOUND) { + log_e("Peer Not Found"); + } + + for (uint8_t i = 0; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) { + if (_esp_now_peers[i] != NULL && memcmp(mac_addr, _esp_now_peers[i]->addr(), ESP_NOW_ETH_ALEN) == 0) { + _esp_now_peers[i] = NULL; + break; + } + } + return result; } -static esp_err_t _esp_now_modify_peer(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk){ - log_v(MACSTR, MAC2STR(mac_addr)); - if (!esp_now_is_peer_exist(mac_addr)) { - log_e("Peer not found"); - return ESP_ERR_ESPNOW_NOT_FOUND; - } - - esp_now_peer_info_t peer; - memset(&peer, 0, sizeof(esp_now_peer_info_t)); - memcpy(peer.peer_addr, mac_addr, ESP_NOW_ETH_ALEN); - peer.channel = channel; - peer.ifidx = iface; - peer.encrypt = lmk != NULL; - if(lmk){ - memcpy(peer.lmk, lmk, ESP_NOW_KEY_LEN); - } - - esp_err_t result = esp_now_mod_peer(&peer); - if (result == ESP_OK) { - return result; - } else if (result == ESP_ERR_ESPNOW_NOT_INIT) { - log_e("ESPNOW Not Init"); - } else if (result == ESP_ERR_ESPNOW_ARG) { - log_e("Invalid Argument"); - } else if (result == ESP_ERR_ESPNOW_FULL) { - log_e("Peer list full"); - } else if (result == ESP_ERR_ESPNOW_NO_MEM) { - log_e("Out of memory"); - } +static esp_err_t _esp_now_modify_peer(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk) { + log_v(MACSTR, MAC2STR(mac_addr)); + if (!esp_now_is_peer_exist(mac_addr)) { + log_e("Peer not found"); + return ESP_ERR_ESPNOW_NOT_FOUND; + } + + esp_now_peer_info_t peer; + memset(&peer, 0, sizeof(esp_now_peer_info_t)); + memcpy(peer.peer_addr, mac_addr, ESP_NOW_ETH_ALEN); + peer.channel = channel; + peer.ifidx = iface; + peer.encrypt = lmk != NULL; + if (lmk) { + memcpy(peer.lmk, lmk, ESP_NOW_KEY_LEN); + } + + esp_err_t result = esp_now_mod_peer(&peer); + if (result == ESP_OK) { return result; + } else if (result == ESP_ERR_ESPNOW_NOT_INIT) { + log_e("ESPNOW Not Init"); + } else if (result == ESP_ERR_ESPNOW_ARG) { + log_e("Invalid Argument"); + } else if (result == ESP_ERR_ESPNOW_FULL) { + log_e("Peer list full"); + } else if (result == ESP_ERR_ESPNOW_NO_MEM) { + log_e("Out of memory"); + } + return result; } -static void _esp_now_rx_cb(const esp_now_recv_info_t *info, const uint8_t *data, int len){ - bool broadcast = memcmp(info->des_addr, ESP_NOW.BROADCAST_ADDR, ESP_NOW_ETH_ALEN) == 0; - log_v("%s from " MACSTR ", data lenght : %u", broadcast ? "Broadcast" : "Unicast", MAC2STR(info->src_addr), len); - log_buf_v(data, len); - if(!esp_now_is_peer_exist(info->src_addr) && new_cb != NULL){ - log_v("Calling new_cb, peer not found."); - new_cb(info, data, len, new_arg); - return; - } - //find the peer and call it's callback - for(uint8_t i=0; iaddr())); - } - if(_esp_now_peers[i] != NULL && memcmp(info->src_addr, _esp_now_peers[i]->addr(), ESP_NOW_ETH_ALEN) == 0){ - log_v("Calling onReceive"); - _esp_now_peers[i]->onReceive(data, len, broadcast); - return; - } - } +static void _esp_now_rx_cb(const esp_now_recv_info_t *info, const uint8_t *data, int len) { + bool broadcast = memcmp(info->des_addr, ESP_NOW.BROADCAST_ADDR, ESP_NOW_ETH_ALEN) == 0; + log_v("%s from " MACSTR ", data length : %u", broadcast ? "Broadcast" : "Unicast", MAC2STR(info->src_addr), len); + log_buf_v(data, len); + if (!esp_now_is_peer_exist(info->src_addr) && new_cb != NULL) { + log_v("Calling new_cb, peer not found."); + new_cb(info, data, len, new_arg); + return; + } + //find the peer and call it's callback + for (uint8_t i = 0; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) { + if (_esp_now_peers[i] != NULL) { + log_v("Checking peer " MACSTR, MAC2STR(_esp_now_peers[i]->addr())); + } + if (_esp_now_peers[i] != NULL && memcmp(info->src_addr, _esp_now_peers[i]->addr(), ESP_NOW_ETH_ALEN) == 0) { + log_v("Calling onReceive"); + _esp_now_peers[i]->onReceive(data, len, broadcast); + return; + } + } } static void _esp_now_tx_cb(const uint8_t *mac_addr, esp_now_send_status_t status) { - log_v(MACSTR" : %s", MAC2STR(mac_addr), (status == ESP_NOW_SEND_SUCCESS)?"SUCCESS":"FAILED"); - //find the peer and call it's callback - for(uint8_t i=0; iaddr(), ESP_NOW_ETH_ALEN) == 0){ - _esp_now_peers[i]->onSent(status == ESP_NOW_SEND_SUCCESS); - return; - } - } + log_v(MACSTR " : %s", MAC2STR(mac_addr), (status == ESP_NOW_SEND_SUCCESS) ? "SUCCESS" : "FAILED"); + //find the peer and call it's callback + for (uint8_t i = 0; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) { + if (_esp_now_peers[i] != NULL && memcmp(mac_addr, _esp_now_peers[i]->addr(), ESP_NOW_ETH_ALEN) == 0) { + _esp_now_peers[i]->onSent(status == ESP_NOW_SEND_SUCCESS); + return; + } + } } -ESP_NOW_Class::ESP_NOW_Class(){} +ESP_NOW_Class::ESP_NOW_Class() {} -ESP_NOW_Class::~ESP_NOW_Class(){} +ESP_NOW_Class::~ESP_NOW_Class() {} -bool ESP_NOW_Class::begin(const uint8_t *pmk){ - if(_esp_now_has_begun){ - return true; - } +bool ESP_NOW_Class::begin(const uint8_t *pmk) { + if (_esp_now_has_begun) { + return true; + } - esp_err_t err = esp_wifi_start(); - if (err != ESP_OK) { - log_e("WiFi not started! 0x%x)", err); - return false; - } + esp_err_t err = esp_wifi_start(); + if (err != ESP_OK) { + log_e("WiFi not started! 0x%x)", err); + return false; + } - _esp_now_has_begun = true; + _esp_now_has_begun = true; - memset(_esp_now_peers, 0, sizeof(ESP_NOW_Peer *) * ESP_NOW_MAX_TOTAL_PEER_NUM); + memset(_esp_now_peers, 0, sizeof(ESP_NOW_Peer *) * ESP_NOW_MAX_TOTAL_PEER_NUM); - err = esp_now_init(); - if(err != ESP_OK){ - log_e("esp_now_init failed! 0x%x", err); - _esp_now_has_begun = false; - return false; - } + err = esp_now_init(); + if (err != ESP_OK) { + log_e("esp_now_init failed! 0x%x", err); + _esp_now_has_begun = false; + return false; + } - if(pmk){ - err = esp_now_set_pmk(pmk); - if(err != ESP_OK){ - log_e("esp_now_set_pmk failed! 0x%x", err); - _esp_now_has_begun = false; - return false; - } + if (pmk) { + err = esp_now_set_pmk(pmk); + if (err != ESP_OK) { + log_e("esp_now_set_pmk failed! 0x%x", err); + _esp_now_has_begun = false; + return false; } + } - err = esp_now_register_recv_cb(_esp_now_rx_cb); - if(err != ESP_OK){ - log_e("esp_now_register_recv_cb failed! 0x%x", err); - _esp_now_has_begun = false; - return false; - } + err = esp_now_register_recv_cb(_esp_now_rx_cb); + if (err != ESP_OK) { + log_e("esp_now_register_recv_cb failed! 0x%x", err); + _esp_now_has_begun = false; + return false; + } - err = esp_now_register_send_cb(_esp_now_tx_cb); - if(err != ESP_OK){ - log_e("esp_now_register_send_cb failed! 0x%x", err); - _esp_now_has_begun = false; - return false; - } - return true; + err = esp_now_register_send_cb(_esp_now_tx_cb); + if (err != ESP_OK) { + log_e("esp_now_register_send_cb failed! 0x%x", err); + _esp_now_has_begun = false; + return false; + } + return true; } -bool ESP_NOW_Class::end(){ - if(!_esp_now_has_begun){ - return true; - } - //remove all peers? - esp_err_t err = esp_now_deinit(); - if(err != ESP_OK){ - log_e("esp_now_deinit failed! 0x%x", err); - return false; - } - _esp_now_has_begun = false; - memset(_esp_now_peers, 0, sizeof(ESP_NOW_Peer *) * ESP_NOW_MAX_TOTAL_PEER_NUM); +bool ESP_NOW_Class::end() { + if (!_esp_now_has_begun) { return true; + } + //remove all peers? + esp_err_t err = esp_now_deinit(); + if (err != ESP_OK) { + log_e("esp_now_deinit failed! 0x%x", err); + return false; + } + _esp_now_has_begun = false; + memset(_esp_now_peers, 0, sizeof(ESP_NOW_Peer *) * ESP_NOW_MAX_TOTAL_PEER_NUM); + return true; } -int ESP_NOW_Class::getTotalPeerCount(){ - if(!_esp_now_has_begun){ - return -1; - } - esp_now_peer_num_t num; - esp_err_t err = esp_now_get_peer_num(&num); - if(err != ESP_OK){ - log_e("esp_now_get_peer_num failed! 0x%x", err); - return -1; - } - return num.total_num; +int ESP_NOW_Class::getTotalPeerCount() { + if (!_esp_now_has_begun) { + return -1; + } + esp_now_peer_num_t num; + esp_err_t err = esp_now_get_peer_num(&num); + if (err != ESP_OK) { + log_e("esp_now_get_peer_num failed! 0x%x", err); + return -1; + } + return num.total_num; } -int ESP_NOW_Class::getEncryptedPeerCount(){ - if(!_esp_now_has_begun){ - return -1; - } - esp_now_peer_num_t num; - esp_err_t err = esp_now_get_peer_num(&num); - if(err != ESP_OK){ - log_e("esp_now_get_peer_num failed! 0x%x", err); - return -1; - } - return num.encrypt_num; +int ESP_NOW_Class::getEncryptedPeerCount() { + if (!_esp_now_has_begun) { + return -1; + } + esp_now_peer_num_t num; + esp_err_t err = esp_now_get_peer_num(&num); + if (err != ESP_OK) { + log_e("esp_now_get_peer_num failed! 0x%x", err); + return -1; + } + return num.encrypt_num; } -int ESP_NOW_Class::availableForWrite(){ - return ESP_NOW_MAX_DATA_LEN; +int ESP_NOW_Class::availableForWrite() { + return ESP_NOW_MAX_DATA_LEN; } -size_t ESP_NOW_Class::write(const uint8_t * data, size_t len){ - if(!_esp_now_has_begun){ - return 0; - } - if(len > ESP_NOW_MAX_DATA_LEN){ - len = ESP_NOW_MAX_DATA_LEN; - } - esp_err_t result = esp_now_send(NULL, data, len); - if (result == ESP_OK) { - return len; - } else if (result == ESP_ERR_ESPNOW_NOT_INIT) { - log_e("ESPNOW not init."); - } else if (result == ESP_ERR_ESPNOW_ARG) { - log_e("Invalid argument"); - } else if (result == ESP_ERR_ESPNOW_INTERNAL) { - log_e("Internal Error"); - } else if (result == ESP_ERR_ESPNOW_NO_MEM) { - log_e("Our of memory"); - } else if (result == ESP_ERR_ESPNOW_NOT_FOUND) { - log_e("Peer not found."); - } else if (result == ESP_ERR_ESPNOW_IF) { - log_e("Interface does not match."); - } +size_t ESP_NOW_Class::write(const uint8_t *data, size_t len) { + if (!_esp_now_has_begun) { return 0; + } + if (len > ESP_NOW_MAX_DATA_LEN) { + len = ESP_NOW_MAX_DATA_LEN; + } + esp_err_t result = esp_now_send(NULL, data, len); + if (result == ESP_OK) { + return len; + } else if (result == ESP_ERR_ESPNOW_NOT_INIT) { + log_e("ESPNOW not init."); + } else if (result == ESP_ERR_ESPNOW_ARG) { + log_e("Invalid argument"); + } else if (result == ESP_ERR_ESPNOW_INTERNAL) { + log_e("Internal Error"); + } else if (result == ESP_ERR_ESPNOW_NO_MEM) { + log_e("Our of memory"); + } else if (result == ESP_ERR_ESPNOW_NOT_FOUND) { + log_e("Peer not found."); + } else if (result == ESP_ERR_ESPNOW_IF) { + log_e("Interface does not match."); + } + return 0; } -void ESP_NOW_Class::onNewPeer(void (*cb)(const esp_now_recv_info_t *info, const uint8_t * data, int len, void * arg), void * arg){ - new_cb = cb; - new_arg = arg; +void ESP_NOW_Class::onNewPeer(void (*cb)(const esp_now_recv_info_t *info, const uint8_t *data, int len, void *arg), void *arg) { + new_cb = cb; + new_arg = arg; } ESP_NOW_Class ESP_NOW; @@ -270,130 +270,129 @@ ESP_NOW_Class ESP_NOW; * */ -ESP_NOW_Peer::ESP_NOW_Peer(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk){ - added = false; - if(mac_addr){ - memcpy(mac, mac_addr,6); - } - chan = channel; - ifc = iface; - encrypt = lmk != NULL; - if(encrypt){ - memcpy(key, lmk, 16); - } +ESP_NOW_Peer::ESP_NOW_Peer(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk) { + added = false; + if (mac_addr) { + memcpy(mac, mac_addr, 6); + } + chan = channel; + ifc = iface; + encrypt = lmk != NULL; + if (encrypt) { + memcpy(key, lmk, 16); + } } -bool ESP_NOW_Peer::add(){ - if(!_esp_now_has_begun){ - return false; - } - if(added){ - return true; - } - if(_esp_now_add_peer(mac, chan, ifc, encrypt?key:NULL, this) != ESP_OK){ - return false; - } - log_v("Peer added - " MACSTR, MAC2STR(mac)); - added = true; +bool ESP_NOW_Peer::add() { + if (!_esp_now_has_begun) { + return false; + } + if (added) { return true; + } + if (_esp_now_add_peer(mac, chan, ifc, encrypt ? key : NULL, this) != ESP_OK) { + return false; + } + log_v("Peer added - " MACSTR, MAC2STR(mac)); + added = true; + return true; } -bool ESP_NOW_Peer::remove(){ - if(!_esp_now_has_begun){ - return false; - } - if(!added){ - return true; - } - log_v("Peer removed - " MACSTR, MAC2STR(mac)); - esp_err_t err = _esp_now_del_peer(mac); - if(err == ESP_OK){ - added = false; - return true; - } +bool ESP_NOW_Peer::remove() { + if (!_esp_now_has_begun) { return false; + } + if (!added) { + return true; + } + log_v("Peer removed - " MACSTR, MAC2STR(mac)); + esp_err_t err = _esp_now_del_peer(mac); + if (err == ESP_OK) { + added = false; + return true; + } + return false; } -const uint8_t * ESP_NOW_Peer::addr() const{ - return mac; +const uint8_t *ESP_NOW_Peer::addr() const { + return mac; } -bool ESP_NOW_Peer::addr(const uint8_t *mac_addr){ - if(!_esp_now_has_begun || !added){ - memcpy(mac, mac_addr,6); - return true; - } - return false; +bool ESP_NOW_Peer::addr(const uint8_t *mac_addr) { + if (!_esp_now_has_begun || !added) { + memcpy(mac, mac_addr, 6); + return true; + } + return false; } -uint8_t ESP_NOW_Peer::getChannel() const{ - return chan; +uint8_t ESP_NOW_Peer::getChannel() const { + return chan; } -bool ESP_NOW_Peer::setChannel(uint8_t channel){ - chan = channel; - if(!_esp_now_has_begun || !added){ - return true; - } - return _esp_now_modify_peer(mac, chan, ifc, encrypt?key:NULL) == ESP_OK; +bool ESP_NOW_Peer::setChannel(uint8_t channel) { + chan = channel; + if (!_esp_now_has_begun || !added) { + return true; + } + return _esp_now_modify_peer(mac, chan, ifc, encrypt ? key : NULL) == ESP_OK; } -wifi_interface_t ESP_NOW_Peer::getInterface() const{ - return ifc; +wifi_interface_t ESP_NOW_Peer::getInterface() const { + return ifc; } -bool ESP_NOW_Peer::setInterface(wifi_interface_t iface){ - ifc = iface; - if(!_esp_now_has_begun || !added){ - return true; - } - return _esp_now_modify_peer(mac, chan, ifc, encrypt?key:NULL) == ESP_OK; +bool ESP_NOW_Peer::setInterface(wifi_interface_t iface) { + ifc = iface; + if (!_esp_now_has_begun || !added) { + return true; + } + return _esp_now_modify_peer(mac, chan, ifc, encrypt ? key : NULL) == ESP_OK; } -bool ESP_NOW_Peer::isEncrypted() const{ - return encrypt; +bool ESP_NOW_Peer::isEncrypted() const { + return encrypt; } -bool ESP_NOW_Peer::setKey(const uint8_t *lmk){ - encrypt = lmk != NULL; - if(encrypt){ - memcpy(key, lmk, 16); - } - if(!_esp_now_has_begun || !added){ - return true; - } - return _esp_now_modify_peer(mac, chan, ifc, encrypt?key:NULL) == ESP_OK; +bool ESP_NOW_Peer::setKey(const uint8_t *lmk) { + encrypt = lmk != NULL; + if (encrypt) { + memcpy(key, lmk, 16); + } + if (!_esp_now_has_begun || !added) { + return true; + } + return _esp_now_modify_peer(mac, chan, ifc, encrypt ? key : NULL) == ESP_OK; } -size_t ESP_NOW_Peer::send(const uint8_t * data, int len){ - log_v(MACSTR", data lenght %d", MAC2STR(mac), len); - if(!_esp_now_has_begun || !added){ - log_e("Peer not added."); - return 0; - } - if(len > ESP_NOW_MAX_DATA_LEN){ - len = ESP_NOW_MAX_DATA_LEN; - } - esp_err_t result = esp_now_send(mac, data, len); - if (result == ESP_OK) { - return len; - } else if (result == ESP_ERR_ESPNOW_NOT_INIT) { - log_e("ESPNOW not init."); - } else if (result == ESP_ERR_ESPNOW_ARG) { - log_e("Invalid argument"); - } else if (result == ESP_ERR_ESPNOW_INTERNAL) { - log_e("Internal Error"); - } else if (result == ESP_ERR_ESPNOW_NO_MEM) { - log_e("Our of memory"); - } else if (result == ESP_ERR_ESPNOW_NOT_FOUND) { - log_e("Peer not found."); - } else if (result == ESP_ERR_ESPNOW_IF) { - log_e("Interface does not match."); - } +size_t ESP_NOW_Peer::send(const uint8_t *data, int len) { + log_v(MACSTR ", data length %d", MAC2STR(mac), len); + if (!_esp_now_has_begun || !added) { + log_e("Peer not added."); return 0; + } + if (len > ESP_NOW_MAX_DATA_LEN) { + len = ESP_NOW_MAX_DATA_LEN; + } + esp_err_t result = esp_now_send(mac, data, len); + if (result == ESP_OK) { + return len; + } else if (result == ESP_ERR_ESPNOW_NOT_INIT) { + log_e("ESPNOW not init."); + } else if (result == ESP_ERR_ESPNOW_ARG) { + log_e("Invalid argument"); + } else if (result == ESP_ERR_ESPNOW_INTERNAL) { + log_e("Internal Error"); + } else if (result == ESP_ERR_ESPNOW_NO_MEM) { + log_e("Our of memory"); + } else if (result == ESP_ERR_ESPNOW_NOT_FOUND) { + log_e("Peer not found."); + } else if (result == ESP_ERR_ESPNOW_IF) { + log_e("Interface does not match."); + } + return 0; } -ESP_NOW_Peer::operator bool() const -{ - return added; +ESP_NOW_Peer::operator bool() const { + return added; } diff --git a/libraries/ESP_NOW/src/ESP32_NOW.h b/libraries/ESP_NOW/src/ESP32_NOW.h index 6a144f503f0..4616ba8edee 100644 --- a/libraries/ESP_NOW/src/ESP32_NOW.h +++ b/libraries/ESP_NOW/src/ESP32_NOW.h @@ -18,14 +18,14 @@ class ESP_NOW_Peer { bool added; bool add(); bool remove(); - size_t send(const uint8_t * data, int len); + size_t send(const uint8_t *data, int len); - ESP_NOW_Peer(const uint8_t *mac_addr, uint8_t channel=0, wifi_interface_t iface=WIFI_IF_AP, const uint8_t *lmk=NULL); + ESP_NOW_Peer(const uint8_t *mac_addr, uint8_t channel = 0, wifi_interface_t iface = WIFI_IF_AP, const uint8_t *lmk = NULL); public: virtual ~ESP_NOW_Peer() {} - const uint8_t * addr() const; + const uint8_t *addr() const; bool addr(const uint8_t *mac_addr); uint8_t getChannel() const; @@ -40,7 +40,7 @@ class ESP_NOW_Peer { operator bool() const; //optional callbacks to be implemented by the upper class - virtual void onReceive(const uint8_t * data, size_t len, bool broadcast) { + virtual void onReceive(const uint8_t *data, size_t len, bool broadcast) { log_i("Received %d bytes from " MACSTR " %s", len, MAC2STR(mac), broadcast ? "(broadcast)" : ""); } @@ -51,24 +51,24 @@ class ESP_NOW_Peer { class ESP_NOW_Class : public Print { public: - const uint8_t BROADCAST_ADDR[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + const uint8_t BROADCAST_ADDR[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; ESP_NOW_Class(); ~ESP_NOW_Class(); - bool begin(const uint8_t *pmk=NULL /* 16 bytes */); + bool begin(const uint8_t *pmk = NULL /* 16 bytes */); bool end(); int getTotalPeerCount(); int getEncryptedPeerCount(); int availableForWrite(); - size_t write(const uint8_t * data, size_t len); - size_t write(uint8_t data){ return write(&data, 1); } - - void onNewPeer(void (*cb)(const esp_now_recv_info_t *info, const uint8_t * data, int len, void * arg), void * arg); + size_t write(const uint8_t *data, size_t len); + size_t write(uint8_t data) { + return write(&data, 1); + } + void onNewPeer(void (*cb)(const esp_now_recv_info_t *info, const uint8_t *data, int len, void *arg), void *arg); }; extern ESP_NOW_Class ESP_NOW; - diff --git a/libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp b/libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp index b562b893258..e4220d45675 100644 --- a/libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp +++ b/libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp @@ -12,261 +12,261 @@ */ ESP_NOW_Serial_Class::ESP_NOW_Serial_Class(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk) -: ESP_NOW_Peer(mac_addr, channel, iface, lmk){ - tx_ring_buf = NULL; - rx_queue = NULL; - tx_sem = NULL; - queued_size = 0; - queued_buff = NULL; - resend_count = 0; + : ESP_NOW_Peer(mac_addr, channel, iface, lmk) { + tx_ring_buf = NULL; + rx_queue = NULL; + tx_sem = NULL; + queued_size = 0; + queued_buff = NULL; + resend_count = 0; } -ESP_NOW_Serial_Class::~ESP_NOW_Serial_Class(){ - end(); +ESP_NOW_Serial_Class::~ESP_NOW_Serial_Class() { + end(); } -size_t ESP_NOW_Serial_Class::setTxBufferSize(size_t tx_queue_len){ - if(tx_ring_buf){ - vRingbufferDelete(tx_ring_buf); - tx_ring_buf = NULL; - } - if(!tx_queue_len){ - return 0; - } - tx_ring_buf = xRingbufferCreate(tx_queue_len, RINGBUF_TYPE_BYTEBUF); - if(!tx_ring_buf){ - return 0; - } - return tx_queue_len; +size_t ESP_NOW_Serial_Class::setTxBufferSize(size_t tx_queue_len) { + if (tx_ring_buf) { + vRingbufferDelete(tx_ring_buf); + tx_ring_buf = NULL; + } + if (!tx_queue_len) { + return 0; + } + tx_ring_buf = xRingbufferCreate(tx_queue_len, RINGBUF_TYPE_BYTEBUF); + if (!tx_ring_buf) { + return 0; + } + return tx_queue_len; } -size_t ESP_NOW_Serial_Class::setRxBufferSize(size_t rx_queue_len){ - if(rx_queue){ - vQueueDelete(rx_queue); - rx_queue = NULL; - } - if(!rx_queue_len){ - return 0; - } - rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t)); - if(!rx_queue){ - return 0; - } - return rx_queue_len; +size_t ESP_NOW_Serial_Class::setRxBufferSize(size_t rx_queue_len) { + if (rx_queue) { + vQueueDelete(rx_queue); + rx_queue = NULL; + } + if (!rx_queue_len) { + return 0; + } + rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t)); + if (!rx_queue) { + return 0; + } + return rx_queue_len; } -bool ESP_NOW_Serial_Class::begin(unsigned long baud){ - if(!ESP_NOW.begin() || !add()){ - return false; - } - if(tx_sem == NULL){ - tx_sem = xSemaphoreCreateBinary(); - //xSemaphoreTake(tx_sem, 0); - xSemaphoreGive(tx_sem); - } - setRxBufferSize(1024);//default if not preset - setTxBufferSize(1024);//default if not preset - return true; +bool ESP_NOW_Serial_Class::begin(unsigned long baud) { + if (!ESP_NOW.begin() || !add()) { + return false; + } + if (tx_sem == NULL) { + tx_sem = xSemaphoreCreateBinary(); + //xSemaphoreTake(tx_sem, 0); + xSemaphoreGive(tx_sem); + } + setRxBufferSize(1024); //default if not preset + setTxBufferSize(1024); //default if not preset + return true; } -void ESP_NOW_Serial_Class::end(){ - remove(); - setRxBufferSize(0); - setTxBufferSize(0); - if (tx_sem != NULL) { - vSemaphoreDelete(tx_sem); - tx_sem = NULL; - } +void ESP_NOW_Serial_Class::end() { + remove(); + setRxBufferSize(0); + setTxBufferSize(0); + if (tx_sem != NULL) { + vSemaphoreDelete(tx_sem); + tx_sem = NULL; + } } //Stream -int ESP_NOW_Serial_Class::available(void){ - if(rx_queue == NULL){ - return 0; - } - return uxQueueMessagesWaiting(rx_queue); +int ESP_NOW_Serial_Class::available(void) { + if (rx_queue == NULL) { + return 0; + } + return uxQueueMessagesWaiting(rx_queue); } -int ESP_NOW_Serial_Class::peek(void){ - if(rx_queue == NULL){ - return -1; - } - uint8_t c; - if(xQueuePeek(rx_queue, &c, 0)) { - return c; - } +int ESP_NOW_Serial_Class::peek(void) { + if (rx_queue == NULL) { return -1; + } + uint8_t c; + if (xQueuePeek(rx_queue, &c, 0)) { + return c; + } + return -1; } -int ESP_NOW_Serial_Class::read(void){ - if(rx_queue == NULL){ - return -1; - } - uint8_t c = 0; - if(xQueueReceive(rx_queue, &c, 0)) { - return c; - } +int ESP_NOW_Serial_Class::read(void) { + if (rx_queue == NULL) { return -1; + } + uint8_t c = 0; + if (xQueueReceive(rx_queue, &c, 0)) { + return c; + } + return -1; } -size_t ESP_NOW_Serial_Class::read(uint8_t *buffer, size_t size){ - if(rx_queue == NULL){ - return -1; - } - uint8_t c = 0; - size_t count = 0; - while(count < size && xQueueReceive(rx_queue, &c, 0)){ - buffer[count++] = c; - } - return count; +size_t ESP_NOW_Serial_Class::read(uint8_t *buffer, size_t size) { + if (rx_queue == NULL) { + return -1; + } + uint8_t c = 0; + size_t count = 0; + while (count < size && xQueueReceive(rx_queue, &c, 0)) { + buffer[count++] = c; + } + return count; } -void ESP_NOW_Serial_Class::flush(){ - if(tx_ring_buf == NULL){ - return; +void ESP_NOW_Serial_Class::flush() { + if (tx_ring_buf == NULL) { + return; + } + UBaseType_t uxItemsWaiting = 0; + vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting); + if (uxItemsWaiting) { + // Now trigger the ISR to read data from the ring buffer. + if (xSemaphoreTake(tx_sem, 0) == pdTRUE) { + checkForTxData(); } - UBaseType_t uxItemsWaiting = 0; + } + while (uxItemsWaiting) { + delay(5); vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting); - if(uxItemsWaiting){ - // Now trigger the ISR to read data from the ring buffer. - if(xSemaphoreTake(tx_sem, 0) == pdTRUE){ - checkForTxData(); - } - } - while(uxItemsWaiting){ - delay(5); - vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting); - } + } } //RX callback -void ESP_NOW_Serial_Class::onReceive(const uint8_t * data, size_t len, bool broadcast){ - if(rx_queue == NULL){ - return; - } - for(uint32_t i=0; i 0; - } - //log_d(MACSTR ": EMPTY", MAC2STR(addr())); - xSemaphoreGive(tx_sem); - return false; +bool ESP_NOW_Serial_Class::checkForTxData() { + //do we have something that failed the last time? + resend_count = 0; + if (queued_buff == NULL) { + queued_buff = (uint8_t *)xRingbufferReceiveUpTo(tx_ring_buf, &queued_size, 0, ESP_NOW_MAX_DATA_LEN); + } else { + log_d(MACSTR " : PREVIOUS", MAC2STR(addr())); + } + if (queued_buff != NULL) { + return tryToSend() > 0; + } + //log_d(MACSTR ": EMPTY", MAC2STR(addr())); + xSemaphoreGive(tx_sem); + return false; } -size_t ESP_NOW_Serial_Class::write(const uint8_t *buffer, size_t size, uint32_t timeout){ - log_v(MACSTR", size %u", MAC2STR(addr()), size); - if(tx_sem == NULL || tx_ring_buf == NULL || !added){ - return 0; - } - size_t space = availableForWrite(); - size_t left = size; +size_t ESP_NOW_Serial_Class::write(const uint8_t *buffer, size_t size, uint32_t timeout) { + log_v(MACSTR ", size %u", MAC2STR(addr()), size); + if (tx_sem == NULL || tx_ring_buf == NULL || !added) { + return 0; + } + size_t space = availableForWrite(); + size_t left = size; - if(space){ - if(left < space){ - space = left; - } - if(xRingbufferSend(tx_ring_buf, (void*) (buffer), space, 0) == pdTRUE){ - buffer += space; - left -= space; - if(xSemaphoreTake(tx_sem, 0) == pdTRUE){ - if(checkForTxData()){ - if(!left){ - //we are done - return size; - } - } else { - //send failed - return 0; - } - } + if (space) { + if (left < space) { + space = left; + } + if (xRingbufferSend(tx_ring_buf, (void *)(buffer), space, 0) == pdTRUE) { + buffer += space; + left -= space; + if (xSemaphoreTake(tx_sem, 0) == pdTRUE) { + if (checkForTxData()) { + if (!left) { + //we are done + return size; + } } else { - log_e("RingbufferFastSend Failed"); - return 0; + //send failed + return 0; } - } else if(xSemaphoreTake(tx_sem, timeout) == pdTRUE){ - checkForTxData(); - } - // Blocking method, Sending data to ringbuffer, and handle the data in ISR. - if(xRingbufferSend(tx_ring_buf, (void*) (buffer), left, timeout / portTICK_PERIOD_MS) != pdTRUE){ - log_e("RingbufferSend Failed"); - return size - left; - } - // Now trigger the ISR to read data from the ring buffer. - if(xSemaphoreTake(tx_sem, 0) == pdTRUE){ - checkForTxData(); - } - - return size; + } + } else { + log_e("RingbufferFastSend Failed"); + return 0; + } + } else if (xSemaphoreTake(tx_sem, timeout) == pdTRUE) { + checkForTxData(); + } + // Blocking method, Sending data to ringbuffer, and handle the data in ISR. + if (xRingbufferSend(tx_ring_buf, (void *)(buffer), left, timeout / portTICK_PERIOD_MS) != pdTRUE) { + log_e("RingbufferSend Failed"); + return size - left; + } + // Now trigger the ISR to read data from the ring buffer. + if (xSemaphoreTake(tx_sem, 0) == pdTRUE) { + checkForTxData(); + } + + return size; } //TX Done Callback -void ESP_NOW_Serial_Class::onSent(bool success){ - log_v(MACSTR" : %s", MAC2STR(addr()), success?"OK":"FAIL"); - if(tx_sem == NULL || tx_ring_buf == NULL || !added){ - return; - } - if(success){ - vRingbufferReturnItem(tx_ring_buf, queued_buff); - queued_buff = NULL; - //send next packet? - //log_d(MACSTR ": NEXT", MAC2STR(addr())); - checkForTxData(); +void ESP_NOW_Serial_Class::onSent(bool success) { + log_v(MACSTR " : %s", MAC2STR(addr()), success ? "OK" : "FAIL"); + if (tx_sem == NULL || tx_ring_buf == NULL || !added) { + return; + } + if (success) { + vRingbufferReturnItem(tx_ring_buf, queued_buff); + queued_buff = NULL; + //send next packet? + //log_d(MACSTR ": NEXT", MAC2STR(addr())); + checkForTxData(); + } else { + //send failed + //resend + if (resend_count < 5) { + resend_count++; + //log_d(MACSTR ": RE-SENDING[%u]", MAC2STR(addr()), resend_count); + tryToSend(); } else { - //send failed - //resend - if(resend_count < 5){ - resend_count++; - //log_d(MACSTR ": RE-SENDING[%u]", MAC2STR(addr()), resend_count); - tryToSend(); - } else { - //resend limit reached - //the data is lost in this case - vRingbufferReturnItem(tx_ring_buf, queued_buff); - queued_buff = NULL; - xSemaphoreGive(tx_sem); - end(); - log_e(MACSTR" : RE-SEND_MAX[%u]", MAC2STR(addr()), resend_count); - } - } + //resend limit reached + //the data is lost in this case + vRingbufferReturnItem(tx_ring_buf, queued_buff); + queued_buff = NULL; + xSemaphoreGive(tx_sem); + end(); + log_e(MACSTR " : RE-SEND_MAX[%u]", MAC2STR(addr()), resend_count); + } + } } diff --git a/libraries/ESP_NOW/src/ESP32_NOW_Serial.h b/libraries/ESP_NOW/src/ESP32_NOW_Serial.h index a2f97948682..5506d81dc48 100644 --- a/libraries/ESP_NOW/src/ESP32_NOW_Serial.h +++ b/libraries/ESP_NOW/src/ESP32_NOW_Serial.h @@ -11,36 +11,38 @@ class ESP_NOW_Serial_Class : public Stream, public ESP_NOW_Peer { private: - RingbufHandle_t tx_ring_buf; - QueueHandle_t rx_queue; - SemaphoreHandle_t tx_sem; - size_t queued_size; - uint8_t *queued_buff; - size_t resend_count; + RingbufHandle_t tx_ring_buf; + QueueHandle_t rx_queue; + SemaphoreHandle_t tx_sem; + size_t queued_size; + uint8_t *queued_buff; + size_t resend_count; - bool checkForTxData(); - size_t tryToSend(); + bool checkForTxData(); + size_t tryToSend(); public: - ESP_NOW_Serial_Class(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface=WIFI_IF_AP, const uint8_t *lmk=NULL); - ~ESP_NOW_Serial_Class(); - size_t setRxBufferSize(size_t); - size_t setTxBufferSize(size_t); - bool begin(unsigned long baud=0); - void end(); - //Stream - int available(); - int read(); - size_t read(uint8_t *buffer, size_t size); - int peek(); - void flush(); - //Print - int availableForWrite(); - size_t write(const uint8_t *buffer, size_t size, uint32_t timeout_ms); - size_t write(const uint8_t *buffer, size_t size){ return write(buffer, size, 1000); } - size_t write(uint8_t data){ return write(&data, 1); } - //ESP_NOW_Peer - void onReceive(const uint8_t * data, size_t len, bool broadcast); - void onSent(bool success); + ESP_NOW_Serial_Class(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface = WIFI_IF_AP, const uint8_t *lmk = NULL); + ~ESP_NOW_Serial_Class(); + size_t setRxBufferSize(size_t); + size_t setTxBufferSize(size_t); + bool begin(unsigned long baud = 0); + void end(); + //Stream + int available(); + int read(); + size_t read(uint8_t *buffer, size_t size); + int peek(); + void flush(); + //Print + int availableForWrite(); + size_t write(const uint8_t *buffer, size_t size, uint32_t timeout_ms); + size_t write(const uint8_t *buffer, size_t size) { + return write(buffer, size, 1000); + } + size_t write(uint8_t data) { + return write(&data, 1); + } + //ESP_NOW_Peer + void onReceive(const uint8_t *data, size_t len, bool broadcast); + void onSent(bool success); }; - - diff --git a/libraries/ESP_SR/examples/Basic/Basic.ino b/libraries/ESP_SR/examples/Basic/Basic.ino index c5e7641e7d8..a81708e8c4e 100644 --- a/libraries/ESP_SR/examples/Basic/Basic.ino +++ b/libraries/ESP_SR/examples/Basic/Basic.ino @@ -3,11 +3,11 @@ #include "ESP_SR.h" #define I2S_PIN_BCK 17 -#define I2S_PIN_WS 47 +#define I2S_PIN_WS 47 #define I2S_PIN_DIN 16 -#define LIGHT_PIN 40 -#define FAN_PIN 41 +#define LIGHT_PIN 40 +#define FAN_PIN 41 I2SClass i2s; @@ -20,48 +20,48 @@ enum { SR_CMD_STOP_FAN, }; static const sr_cmd_t sr_commands[] = { - { 0, "Turn on the light", "TkN nN jc LiT"}, - { 0, "Switch on the light", "SWgp nN jc LiT"}, - { 1, "Turn off the light", "TkN eF jc LiT"}, - { 1, "Switch off the light", "SWgp eF jc LiT"}, - { 1, "Go dark", "Gb DnRK"}, - { 2, "Start fan", "STnRT FaN"}, - { 3, "Stop fan", "STnP FaN"}, + { 0, "Turn on the light", "TkN nN jc LiT" }, + { 0, "Switch on the light", "SWgp nN jc LiT" }, + { 1, "Turn off the light", "TkN eF jc LiT" }, + { 1, "Switch off the light", "SWgp eF jc LiT" }, + { 1, "Go dark", "Gb DnRK" }, + { 2, "Start fan", "STnRT FaN" }, + { 3, "Stop fan", "STnP FaN" }, }; -void onSrEvent(sr_event_t event, int command_id, int phrase_id){ - switch(event){ +void onSrEvent(sr_event_t event, int command_id, int phrase_id) { + switch (event) { case SR_EVENT_WAKEWORD: Serial.println("WakeWord Detected!"); break; case SR_EVENT_WAKEWORD_CHANNEL: Serial.printf("WakeWord Channel %d Verified!\n", command_id); - ESP_SR.setMode(SR_MODE_COMMAND); // Switch to Command detection + ESP_SR.setMode(SR_MODE_COMMAND); // Switch to Command detection break; case SR_EVENT_TIMEOUT: Serial.println("Timeout Detected!"); - ESP_SR.setMode(SR_MODE_WAKEWORD); // Switch back to WakeWord detection + ESP_SR.setMode(SR_MODE_WAKEWORD); // Switch back to WakeWord detection break; case SR_EVENT_COMMAND: Serial.printf("Command %d Detected! %s\n", command_id, sr_commands[phrase_id].str); - switch(command_id){ - case SR_CMD_TURN_ON_THE_LIGHT: - digitalWrite(LIGHT_PIN, HIGH); - break; - case SR_CMD_TURN_OFF_THE_LIGHT: - digitalWrite(LIGHT_PIN, LOW); - break; - case SR_CMD_START_FAN: - digitalWrite(FAN_PIN, HIGH); - break; - case SR_CMD_STOP_FAN: - digitalWrite(FAN_PIN, LOW); - break; - default: - Serial.println("Unknown Command!"); - break; + switch (command_id) { + case SR_CMD_TURN_ON_THE_LIGHT: + digitalWrite(LIGHT_PIN, HIGH); + break; + case SR_CMD_TURN_OFF_THE_LIGHT: + digitalWrite(LIGHT_PIN, LOW); + break; + case SR_CMD_START_FAN: + digitalWrite(FAN_PIN, HIGH); + break; + case SR_CMD_STOP_FAN: + digitalWrite(FAN_PIN, LOW); + break; + default: + Serial.println("Unknown Command!"); + break; } - ESP_SR.setMode(SR_MODE_COMMAND); // Allow for more commands to be given, before timeout + ESP_SR.setMode(SR_MODE_COMMAND); // Allow for more commands to be given, before timeout // ESP_SR.setMode(SR_MODE_WAKEWORD); // Switch back to WakeWord detection break; default: @@ -70,7 +70,7 @@ void onSrEvent(sr_event_t event, int command_id, int phrase_id){ } } -void setup(){ +void setup() { Serial.begin(115200); pinMode(LIGHT_PIN, OUTPUT); @@ -87,6 +87,5 @@ void setup(){ ESP_SR.begin(i2s, sr_commands, sizeof(sr_commands) / sizeof(sr_cmd_t), SR_CHANNELS_STEREO, SR_MODE_WAKEWORD); } -void loop(){ - +void loop() { } diff --git a/libraries/ESP_SR/library.properties b/libraries/ESP_SR/library.properties index 518cc915fcf..bf029b5e0dc 100755 --- a/libraries/ESP_SR/library.properties +++ b/libraries/ESP_SR/library.properties @@ -6,4 +6,4 @@ sentence=Library for ESP Sound Recognition paragraph=Supports ESP32 Arduino platforms. category=Sound url=https://github.com/espressif/arduino-esp32/ -architectures=esp32 \ No newline at end of file +architectures=esp32 diff --git a/libraries/ESP_SR/src/ESP_SR.cpp b/libraries/ESP_SR/src/ESP_SR.cpp index f020d915f7a..d7a30d158da 100644 --- a/libraries/ESP_SR/src/ESP_SR.cpp +++ b/libraries/ESP_SR/src/ESP_SR.cpp @@ -7,66 +7,63 @@ #if CONFIG_IDF_TARGET_ESP32S3 && (CONFIG_USE_WAKENET || CONFIG_USE_MULTINET) #include "ESP_SR.h" -static esp_err_t on_sr_fill(void * arg, void * out, size_t len, size_t *bytes_read, uint32_t timeout_ms){ - return ((ESP_SR_Class*)arg)->_fill(out, len, bytes_read, timeout_ms); +static esp_err_t on_sr_fill(void *arg, void *out, size_t len, size_t *bytes_read, uint32_t timeout_ms) { + return ((ESP_SR_Class *)arg)->_fill(out, len, bytes_read, timeout_ms); } -static void on_sr_event(void * arg, sr_event_t event, int command_id, int phrase_id){ - ((ESP_SR_Class*)arg)->_sr_event(event, command_id, phrase_id); +static void on_sr_event(void *arg, sr_event_t event, int command_id, int phrase_id) { + ((ESP_SR_Class *)arg)->_sr_event(event, command_id, phrase_id); } ESP_SR_Class::ESP_SR_Class() - : cb(NULL) - , i2s(NULL) -{ - + : cb(NULL), i2s(NULL) { } -ESP_SR_Class::~ESP_SR_Class(){ - end(); +ESP_SR_Class::~ESP_SR_Class() { + end(); } -void ESP_SR_Class::onEvent(sr_cb event_cb){ - cb = event_cb; +void ESP_SR_Class::onEvent(sr_cb event_cb) { + cb = event_cb; } -bool ESP_SR_Class::begin(I2SClass & _i2s, const sr_cmd_t * sr_commands, size_t sr_commands_len, sr_channels_t rx_chan, sr_mode_t mode){ - i2s = &_i2s; - esp_err_t err = sr_start(on_sr_fill, this, rx_chan, mode, sr_commands, sr_commands_len, on_sr_event, this); - return (err == ESP_OK); +bool ESP_SR_Class::begin(I2SClass &_i2s, const sr_cmd_t *sr_commands, size_t sr_commands_len, sr_channels_t rx_chan, sr_mode_t mode) { + i2s = &_i2s; + esp_err_t err = sr_start(on_sr_fill, this, rx_chan, mode, sr_commands, sr_commands_len, on_sr_event, this); + return (err == ESP_OK); } -bool ESP_SR_Class::end(void){ - return sr_stop() == ESP_OK; +bool ESP_SR_Class::end(void) { + return sr_stop() == ESP_OK; } -bool ESP_SR_Class::setMode(sr_mode_t mode){ - return sr_set_mode(mode) == ESP_OK; +bool ESP_SR_Class::setMode(sr_mode_t mode) { + return sr_set_mode(mode) == ESP_OK; } -bool ESP_SR_Class::pause(void){ - return sr_pause() == ESP_OK; +bool ESP_SR_Class::pause(void) { + return sr_pause() == ESP_OK; } -bool ESP_SR_Class::resume(void){ - return sr_resume() == ESP_OK; +bool ESP_SR_Class::resume(void) { + return sr_resume() == ESP_OK; } -void ESP_SR_Class::_sr_event(sr_event_t event, int command_id, int phrase_id){ - if(cb){ - cb(event, command_id, phrase_id); - } +void ESP_SR_Class::_sr_event(sr_event_t event, int command_id, int phrase_id) { + if (cb) { + cb(event, command_id, phrase_id); + } } -esp_err_t ESP_SR_Class::_fill(void * out, size_t len, size_t *bytes_read, uint32_t timeout_ms){ - if(i2s == NULL){ - return ESP_FAIL; - } - i2s->setTimeout(timeout_ms); - *bytes_read = i2s->readBytes((char *)out, len); - return (esp_err_t)i2s->lastError(); +esp_err_t ESP_SR_Class::_fill(void *out, size_t len, size_t *bytes_read, uint32_t timeout_ms) { + if (i2s == NULL) { + return ESP_FAIL; + } + i2s->setTimeout(timeout_ms); + *bytes_read = i2s->readBytes((char *)out, len); + return (esp_err_t)i2s->lastError(); } ESP_SR_Class ESP_SR; -#endif // CONFIG_IDF_TARGET_ESP32S3 +#endif // CONFIG_IDF_TARGET_ESP32S3 diff --git a/libraries/ESP_SR/src/ESP_SR.h b/libraries/ESP_SR/src/ESP_SR.h index 4af4276b6e3..c063c71e3fb 100644 --- a/libraries/ESP_SR/src/ESP_SR.h +++ b/libraries/ESP_SR/src/ESP_SR.h @@ -14,25 +14,25 @@ typedef void (*sr_cb)(sr_event_t event, int command_id, int phrase_id); class ESP_SR_Class { - private: - sr_cb cb; - I2SClass * i2s; - public: - ESP_SR_Class(); - ~ESP_SR_Class(); - - void onEvent(sr_cb cb); - bool begin(I2SClass & i2s, const sr_cmd_t * sr_commands, size_t sr_commands_len, sr_channels_t rx_chan=SR_CHANNELS_STEREO, sr_mode_t mode=SR_MODE_WAKEWORD); - bool end(void); - bool setMode(sr_mode_t mode); - bool pause(void); - bool resume(void); - - void _sr_event(sr_event_t event, int command_id, int phrase_id); - esp_err_t _fill(void * out, size_t len, size_t *bytes_read, uint32_t timeout_ms); +private: + sr_cb cb; + I2SClass *i2s; +public: + ESP_SR_Class(); + ~ESP_SR_Class(); + + void onEvent(sr_cb cb); + bool begin(I2SClass &i2s, const sr_cmd_t *sr_commands, size_t sr_commands_len, sr_channels_t rx_chan = SR_CHANNELS_STEREO, sr_mode_t mode = SR_MODE_WAKEWORD); + bool end(void); + bool setMode(sr_mode_t mode); + bool pause(void); + bool resume(void); + + void _sr_event(sr_event_t event, int command_id, int phrase_id); + esp_err_t _fill(void *out, size_t len, size_t *bytes_read, uint32_t timeout_ms); }; extern ESP_SR_Class ESP_SR; -#endif // CONFIG_IDF_TARGET_ESP32S3 +#endif // CONFIG_IDF_TARGET_ESP32S3 diff --git a/libraries/ESP_SR/src/esp32-hal-sr.c b/libraries/ESP_SR/src/esp32-hal-sr.c index d33a52d1c81..1935aa98e21 100644 --- a/libraries/ESP_SR/src/esp32-hal-sr.c +++ b/libraries/ESP_SR/src/esp32-hal-sr.c @@ -39,21 +39,23 @@ #include "esp32-hal-log.h" #undef ESP_GOTO_ON_FALSE -#define ESP_GOTO_ON_FALSE(a, err_code, goto_tag, format, ...) do { \ - if (unlikely(!(a))) { \ - log_e(format, ##__VA_ARGS__); \ - ret = err_code; \ - goto goto_tag; \ - } \ - } while (0) +#define ESP_GOTO_ON_FALSE(a, err_code, goto_tag, format, ...) \ + do { \ + if (unlikely(!(a))) { \ + log_e(format, ##__VA_ARGS__); \ + ret = err_code; \ + goto goto_tag; \ + } \ + } while (0) #undef ESP_RETURN_ON_FALSE -#define ESP_RETURN_ON_FALSE(a, err_code, format, ...) do { \ - if (unlikely(!(a))) { \ - log_e(format, ##__VA_ARGS__); \ - return err_code; \ - } \ - } while(0) +#define ESP_RETURN_ON_FALSE(a, err_code, format, ...) \ + do { \ + if (unlikely(!(a))) { \ + log_e(format, ##__VA_ARGS__); \ + return err_code; \ + } \ + } while (0) #define NEED_DELETE BIT0 #define FEED_DELETED BIT1 @@ -64,29 +66,29 @@ #define RESUME_DETECT BIT6 typedef struct { - wakenet_state_t wakenet_mode; - esp_mn_state_t state; - int command_id; - int phrase_id; + wakenet_state_t wakenet_mode; + esp_mn_state_t state; + int command_id; + int phrase_id; } sr_result_t; typedef struct { - model_iface_data_t *model_data; - const esp_mn_iface_t *multinet; - const esp_afe_sr_iface_t *afe_handle; - esp_afe_sr_data_t *afe_data; - int16_t *afe_in_buffer; - sr_mode_t mode; - uint8_t i2s_rx_chan_num; - sr_event_cb user_cb; - void * user_cb_arg; - sr_fill_cb fill_cb; - void * fill_cb_arg; - TaskHandle_t feed_task; - TaskHandle_t detect_task; - TaskHandle_t handle_task; - QueueHandle_t result_que; - EventGroupHandle_t event_group; + model_iface_data_t *model_data; + const esp_mn_iface_t *multinet; + const esp_afe_sr_iface_t *afe_handle; + esp_afe_sr_data_t *afe_data; + int16_t *afe_in_buffer; + sr_mode_t mode; + uint8_t i2s_rx_chan_num; + sr_event_cb user_cb; + void *user_cb_arg; + sr_fill_cb fill_cb; + void *fill_cb_arg; + TaskHandle_t feed_task; + TaskHandle_t detect_task; + TaskHandle_t handle_task; + QueueHandle_t result_que; + EventGroupHandle_t event_group; } sr_data_t; static int SR_CHANNEL_NUM = 3; @@ -96,350 +98,341 @@ static sr_data_t *g_sr_data = NULL; esp_err_t sr_set_mode(sr_mode_t mode); -void sr_handler_task(void *pvParam) -{ - while (true) { - sr_result_t result; - if(xQueueReceive(g_sr_data->result_que, &result, portMAX_DELAY) != pdTRUE){ - continue; - } +void sr_handler_task(void *pvParam) { + while (true) { + sr_result_t result; + if (xQueueReceive(g_sr_data->result_que, &result, portMAX_DELAY) != pdTRUE) { + continue; + } - if (WAKENET_DETECTED == result.wakenet_mode) { - if(g_sr_data->user_cb){ - g_sr_data->user_cb(g_sr_data->user_cb_arg, SR_EVENT_WAKEWORD, -1, -1); - } - continue; - } + if (WAKENET_DETECTED == result.wakenet_mode) { + if (g_sr_data->user_cb) { + g_sr_data->user_cb(g_sr_data->user_cb_arg, SR_EVENT_WAKEWORD, -1, -1); + } + continue; + } - if (WAKENET_CHANNEL_VERIFIED == result.wakenet_mode) { - if(g_sr_data->user_cb){ - g_sr_data->user_cb(g_sr_data->user_cb_arg, SR_EVENT_WAKEWORD_CHANNEL, result.command_id, -1); - } - continue; - } + if (WAKENET_CHANNEL_VERIFIED == result.wakenet_mode) { + if (g_sr_data->user_cb) { + g_sr_data->user_cb(g_sr_data->user_cb_arg, SR_EVENT_WAKEWORD_CHANNEL, result.command_id, -1); + } + continue; + } - if (ESP_MN_STATE_DETECTED == result.state) { - if(g_sr_data->user_cb){ - g_sr_data->user_cb(g_sr_data->user_cb_arg, SR_EVENT_COMMAND, result.command_id, result.phrase_id); - } - continue; - } + if (ESP_MN_STATE_DETECTED == result.state) { + if (g_sr_data->user_cb) { + g_sr_data->user_cb(g_sr_data->user_cb_arg, SR_EVENT_COMMAND, result.command_id, result.phrase_id); + } + continue; + } - if (ESP_MN_STATE_TIMEOUT == result.state) { - if(g_sr_data->user_cb){ - g_sr_data->user_cb(g_sr_data->user_cb_arg, SR_EVENT_TIMEOUT, -1, -1); - } - continue; - } + if (ESP_MN_STATE_TIMEOUT == result.state) { + if (g_sr_data->user_cb) { + g_sr_data->user_cb(g_sr_data->user_cb_arg, SR_EVENT_TIMEOUT, -1, -1); + } + continue; } - vTaskDelete(NULL); + } + vTaskDelete(NULL); } -static void audio_feed_task(void *arg) -{ - size_t bytes_read = 0; - int audio_chunksize = g_sr_data->afe_handle->get_feed_chunksize(g_sr_data->afe_data); - log_i("audio_chunksize=%d, feed_channel=%d", audio_chunksize, SR_CHANNEL_NUM); - - /* Allocate audio buffer and check for result */ - int16_t *audio_buffer = heap_caps_malloc(audio_chunksize * sizeof(int16_t) * SR_CHANNEL_NUM, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); - if (NULL == audio_buffer) { - esp_system_abort("No mem for audio buffer"); +static void audio_feed_task(void *arg) { + size_t bytes_read = 0; + int audio_chunksize = g_sr_data->afe_handle->get_feed_chunksize(g_sr_data->afe_data); + log_i("audio_chunksize=%d, feed_channel=%d", audio_chunksize, SR_CHANNEL_NUM); + + /* Allocate audio buffer and check for result */ + int16_t *audio_buffer = heap_caps_malloc(audio_chunksize * sizeof(int16_t) * SR_CHANNEL_NUM, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + if (NULL == audio_buffer) { + esp_system_abort("No mem for audio buffer"); + } + g_sr_data->afe_in_buffer = audio_buffer; + + while (true) { + EventBits_t bits = xEventGroupGetBits(g_sr_data->event_group); + if (NEED_DELETE & bits) { + xEventGroupSetBits(g_sr_data->event_group, FEED_DELETED); + break; + } + if (PAUSE_FEED & bits) { + xEventGroupWaitBits(g_sr_data->event_group, PAUSE_FEED | RESUME_FEED, 1, 1, portMAX_DELAY); } - g_sr_data->afe_in_buffer = audio_buffer; - while (true) { - EventBits_t bits = xEventGroupGetBits(g_sr_data->event_group); - if (NEED_DELETE & bits) { - xEventGroupSetBits(g_sr_data->event_group, FEED_DELETED); - break; - } - if (PAUSE_FEED & bits) { - xEventGroupWaitBits(g_sr_data->event_group, PAUSE_FEED | RESUME_FEED, 1, 1, portMAX_DELAY); - } + /* Read audio data from I2S bus */ + //ToDo: handle error + if (g_sr_data->fill_cb == NULL) { + vTaskDelay(100); + continue; + } + esp_err_t err = g_sr_data->fill_cb(g_sr_data->fill_cb_arg, (char *)audio_buffer, audio_chunksize * g_sr_data->i2s_rx_chan_num * sizeof(int16_t), &bytes_read, portMAX_DELAY); + if (err != ESP_OK) { + vTaskDelay(100); + continue; + } - /* Read audio data from I2S bus */ - //ToDo: handle error - if(g_sr_data->fill_cb == NULL){ - vTaskDelay(100); - continue; - } - esp_err_t err = g_sr_data->fill_cb(g_sr_data->fill_cb_arg, (char *)audio_buffer, audio_chunksize * g_sr_data->i2s_rx_chan_num * sizeof(int16_t), &bytes_read, portMAX_DELAY); - if(err != ESP_OK){ - vTaskDelay(100); - continue; - } + /* Channel Adjust */ + if (g_sr_data->i2s_rx_chan_num == 1) { + for (int i = audio_chunksize - 1; i >= 0; i--) { + audio_buffer[i * SR_CHANNEL_NUM + 2] = 0; + audio_buffer[i * SR_CHANNEL_NUM + 1] = 0; + audio_buffer[i * SR_CHANNEL_NUM + 0] = audio_buffer[i]; + } + } else if (g_sr_data->i2s_rx_chan_num == 2) { + for (int i = audio_chunksize - 1; i >= 0; i--) { + audio_buffer[i * SR_CHANNEL_NUM + 2] = 0; + audio_buffer[i * SR_CHANNEL_NUM + 1] = audio_buffer[i * 2 + 1]; + audio_buffer[i * SR_CHANNEL_NUM + 0] = audio_buffer[i * 2 + 0]; + } + } else { + vTaskDelay(100); + continue; + } - /* Channel Adjust */ - if(g_sr_data->i2s_rx_chan_num == 1){ - for (int i = audio_chunksize - 1; i >= 0; i--) { - audio_buffer[i * SR_CHANNEL_NUM + 2] = 0; - audio_buffer[i * SR_CHANNEL_NUM + 1] = 0; - audio_buffer[i * SR_CHANNEL_NUM + 0] = audio_buffer[i]; - } - } else if(g_sr_data->i2s_rx_chan_num == 2){ - for (int i = audio_chunksize - 1; i >= 0; i--) { - audio_buffer[i * SR_CHANNEL_NUM + 2] = 0; - audio_buffer[i * SR_CHANNEL_NUM + 1] = audio_buffer[i * 2 + 1]; - audio_buffer[i * SR_CHANNEL_NUM + 0] = audio_buffer[i * 2 + 0]; - } - } else { - vTaskDelay(100); - continue; - } + /* Feed samples of an audio stream to the AFE_SR */ + g_sr_data->afe_handle->feed(g_sr_data->afe_data, audio_buffer); + } + vTaskDelete(NULL); +} - /* Feed samples of an audio stream to the AFE_SR */ - g_sr_data->afe_handle->feed(g_sr_data->afe_data, audio_buffer); +static void audio_detect_task(void *arg) { + int afe_chunksize = g_sr_data->afe_handle->get_fetch_chunksize(g_sr_data->afe_data); + int mu_chunksize = g_sr_data->multinet->get_samp_chunksize(g_sr_data->model_data); + assert(mu_chunksize == afe_chunksize); + log_i("------------detect start------------"); + + while (true) { + EventBits_t bits = xEventGroupGetBits(g_sr_data->event_group); + if (NEED_DELETE & bits) { + xEventGroupSetBits(g_sr_data->event_group, DETECT_DELETED); + break; + } + if (PAUSE_DETECT & bits) { + xEventGroupWaitBits(g_sr_data->event_group, PAUSE_DETECT | RESUME_DETECT, 1, 1, portMAX_DELAY); } - vTaskDelete(NULL); -} -static void audio_detect_task(void *arg) -{ - int afe_chunksize = g_sr_data->afe_handle->get_fetch_chunksize(g_sr_data->afe_data); - int mu_chunksize = g_sr_data->multinet->get_samp_chunksize(g_sr_data->model_data); - assert(mu_chunksize == afe_chunksize); - log_i("------------detect start------------"); - - while (true) { - EventBits_t bits = xEventGroupGetBits(g_sr_data->event_group); - if (NEED_DELETE & bits) { - xEventGroupSetBits(g_sr_data->event_group, DETECT_DELETED); - break; - } - if (PAUSE_DETECT & bits) { - xEventGroupWaitBits(g_sr_data->event_group, PAUSE_DETECT | RESUME_DETECT, 1, 1, portMAX_DELAY); - } + afe_fetch_result_t *res = g_sr_data->afe_handle->fetch(g_sr_data->afe_data); + if (!res || res->ret_value == ESP_FAIL) { + continue; + } - afe_fetch_result_t* res = g_sr_data->afe_handle->fetch(g_sr_data->afe_data); - if (!res || res->ret_value == ESP_FAIL) { - continue; - } + if (g_sr_data->mode == SR_MODE_WAKEWORD) { + if (res->wakeup_state == WAKENET_DETECTED) { + log_d("wakeword detected"); + sr_result_t result = { + .wakenet_mode = WAKENET_DETECTED, + .state = ESP_MN_STATE_DETECTING, + .command_id = 0, + .phrase_id = 0, + }; + xQueueSend(g_sr_data->result_que, &result, 0); + } else if (res->wakeup_state == WAKENET_CHANNEL_VERIFIED) { + sr_set_mode(SR_MODE_OFF); + log_d("AFE_FETCH_CHANNEL_VERIFIED, channel index: %d", res->trigger_channel_id); + sr_result_t result = { + .wakenet_mode = WAKENET_CHANNEL_VERIFIED, + .state = ESP_MN_STATE_DETECTING, + .command_id = res->trigger_channel_id, + .phrase_id = 0, + }; + xQueueSend(g_sr_data->result_que, &result, 0); + } + } - if(g_sr_data->mode == SR_MODE_WAKEWORD){ - if (res->wakeup_state == WAKENET_DETECTED) { - log_d("wakeword detected"); - sr_result_t result = { - .wakenet_mode = WAKENET_DETECTED, - .state = ESP_MN_STATE_DETECTING, - .command_id = 0, - .phrase_id = 0, - }; - xQueueSend(g_sr_data->result_que, &result, 0); - } - else if (res->wakeup_state == WAKENET_CHANNEL_VERIFIED) { - sr_set_mode(SR_MODE_OFF); - log_d("AFE_FETCH_CHANNEL_VERIFIED, channel index: %d", res->trigger_channel_id); - sr_result_t result = { - .wakenet_mode = WAKENET_CHANNEL_VERIFIED, - .state = ESP_MN_STATE_DETECTING, - .command_id = res->trigger_channel_id, - .phrase_id = 0, - }; - xQueueSend(g_sr_data->result_que, &result, 0); - } + if (g_sr_data->mode == SR_MODE_COMMAND) { + + esp_mn_state_t mn_state = ESP_MN_STATE_DETECTING; + mn_state = g_sr_data->multinet->detect(g_sr_data->model_data, res->data); + + if (ESP_MN_STATE_DETECTING == mn_state) { + continue; + } + + if (ESP_MN_STATE_TIMEOUT == mn_state) { + sr_set_mode(SR_MODE_OFF); + log_d("Time out"); + sr_result_t result = { + .wakenet_mode = WAKENET_NO_DETECT, + .state = mn_state, + .command_id = 0, + .phrase_id = 0, + }; + xQueueSend(g_sr_data->result_que, &result, 0); + continue; + } + + if (ESP_MN_STATE_DETECTED == mn_state) { + sr_set_mode(SR_MODE_OFF); + esp_mn_results_t *mn_result = g_sr_data->multinet->get_results(g_sr_data->model_data); + for (int i = 0; i < mn_result->num; i++) { + log_d("TOP %d, command_id: %d, phrase_id: %d, prob: %f", + i + 1, mn_result->command_id[i], mn_result->phrase_id[i], mn_result->prob[i]); } - if (g_sr_data->mode == SR_MODE_COMMAND) { - - esp_mn_state_t mn_state = ESP_MN_STATE_DETECTING; - mn_state = g_sr_data->multinet->detect(g_sr_data->model_data, res->data); - - if (ESP_MN_STATE_DETECTING == mn_state) { - continue; - } - - if (ESP_MN_STATE_TIMEOUT == mn_state) { - sr_set_mode(SR_MODE_OFF); - log_d("Time out"); - sr_result_t result = { - .wakenet_mode = WAKENET_NO_DETECT, - .state = mn_state, - .command_id = 0, - .phrase_id = 0, - }; - xQueueSend(g_sr_data->result_que, &result, 0); - continue; - } - - if (ESP_MN_STATE_DETECTED == mn_state) { - sr_set_mode(SR_MODE_OFF); - esp_mn_results_t *mn_result = g_sr_data->multinet->get_results(g_sr_data->model_data); - for (int i = 0; i < mn_result->num; i++) { - log_d("TOP %d, command_id: %d, phrase_id: %d, prob: %f", - i + 1, mn_result->command_id[i], mn_result->phrase_id[i], mn_result->prob[i]); - } - - int sr_command_id = mn_result->command_id[0]; - int sr_phrase_id = mn_result->phrase_id[0]; - log_d("Deteted command : %d, phrase: %d", sr_command_id, sr_phrase_id); - sr_result_t result = { - .wakenet_mode = WAKENET_NO_DETECT, - .state = mn_state, - .command_id = sr_command_id, - .phrase_id = sr_phrase_id, - }; - xQueueSend(g_sr_data->result_que, &result, 0); - continue; - } - log_e("Exception unhandled"); - } + int sr_command_id = mn_result->command_id[0]; + int sr_phrase_id = mn_result->phrase_id[0]; + log_d("Detected command : %d, phrase: %d", sr_command_id, sr_phrase_id); + sr_result_t result = { + .wakenet_mode = WAKENET_NO_DETECT, + .state = mn_state, + .command_id = sr_command_id, + .phrase_id = sr_phrase_id, + }; + xQueueSend(g_sr_data->result_que, &result, 0); + continue; + } + log_e("Exception unhandled"); } - vTaskDelete(NULL); + } + vTaskDelete(NULL); } -esp_err_t sr_set_mode(sr_mode_t mode) -{ - ESP_RETURN_ON_FALSE(NULL != g_sr_data, ESP_ERR_INVALID_STATE, "SR is not running"); - switch(mode){ - case SR_MODE_OFF: - if(g_sr_data->mode == SR_MODE_WAKEWORD){ - g_sr_data->afe_handle->disable_wakenet(g_sr_data->afe_data); - } - break; - case SR_MODE_WAKEWORD: - if(g_sr_data->mode != SR_MODE_WAKEWORD){ - g_sr_data->afe_handle->enable_wakenet(g_sr_data->afe_data); - } - break; - case SR_MODE_COMMAND: - if(g_sr_data->mode == SR_MODE_WAKEWORD){ - g_sr_data->afe_handle->disable_wakenet(g_sr_data->afe_data); - } - break; - default: - return ESP_FAIL; - } - g_sr_data->mode = mode; - return ESP_OK; +esp_err_t sr_set_mode(sr_mode_t mode) { + ESP_RETURN_ON_FALSE(NULL != g_sr_data, ESP_ERR_INVALID_STATE, "SR is not running"); + switch (mode) { + case SR_MODE_OFF: + if (g_sr_data->mode == SR_MODE_WAKEWORD) { + g_sr_data->afe_handle->disable_wakenet(g_sr_data->afe_data); + } + break; + case SR_MODE_WAKEWORD: + if (g_sr_data->mode != SR_MODE_WAKEWORD) { + g_sr_data->afe_handle->enable_wakenet(g_sr_data->afe_data); + } + break; + case SR_MODE_COMMAND: + if (g_sr_data->mode == SR_MODE_WAKEWORD) { + g_sr_data->afe_handle->disable_wakenet(g_sr_data->afe_data); + } + break; + default: + return ESP_FAIL; + } + g_sr_data->mode = mode; + return ESP_OK; } -esp_err_t sr_start(sr_fill_cb fill_cb, void * fill_cb_arg, sr_channels_t rx_chan, sr_mode_t mode, const sr_cmd_t sr_commands[], size_t cmd_number, sr_event_cb cb, void * cb_arg) -{ - esp_err_t ret = ESP_OK; - ESP_RETURN_ON_FALSE(NULL == g_sr_data, ESP_ERR_INVALID_STATE, "SR already running"); - - g_sr_data = heap_caps_calloc(1, sizeof(sr_data_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); - ESP_RETURN_ON_FALSE(NULL != g_sr_data, ESP_ERR_NO_MEM, "Failed create sr data"); - - g_sr_data->result_que = xQueueCreate(3, sizeof(sr_result_t)); - ESP_GOTO_ON_FALSE(NULL != g_sr_data->result_que, ESP_ERR_NO_MEM, err, "Failed create result queue"); - - g_sr_data->event_group = xEventGroupCreate(); - ESP_GOTO_ON_FALSE(NULL != g_sr_data->event_group, ESP_ERR_NO_MEM, err, "Failed create event_group"); - - BaseType_t ret_val; - g_sr_data->user_cb = cb; - g_sr_data->user_cb_arg = cb_arg; - g_sr_data->fill_cb = fill_cb; - g_sr_data->fill_cb_arg = fill_cb_arg; - g_sr_data->i2s_rx_chan_num = rx_chan + 1; - g_sr_data->mode = mode; - - // Init Model - log_d("init model"); - models = esp_srmodel_init("model"); - - // Load WakeWord Detection - g_sr_data->afe_handle = (esp_afe_sr_iface_t *)&ESP_AFE_SR_HANDLE; - afe_config_t afe_config = AFE_CONFIG_DEFAULT(); - afe_config.wakenet_model_name = esp_srmodel_filter(models, ESP_WN_PREFIX, "hiesp"); - afe_config.aec_init = false; - log_d("load wakenet '%s'", afe_config.wakenet_model_name); - g_sr_data->afe_data = g_sr_data->afe_handle->create_from_config(&afe_config); - - // Load Custom Command Detection - char *mn_name = esp_srmodel_filter(models, ESP_MN_PREFIX, ESP_MN_ENGLISH); - log_d("load multinet '%s'", mn_name); - g_sr_data->multinet = esp_mn_handle_from_name(mn_name); - log_d("load model_data '%s'", mn_name); - g_sr_data->model_data = g_sr_data->multinet->create(mn_name, 5760); - - - // Add commands - esp_mn_commands_alloc((esp_mn_iface_t *)g_sr_data->multinet, (model_iface_data_t *)g_sr_data->model_data); - log_i("add %d commands", cmd_number); - for (size_t i = 0; i < cmd_number; i++) { - esp_mn_commands_add(sr_commands[i].command_id, (char *)(sr_commands[i].phoneme)); - log_i(" cmd[%d] phrase[%d]:'%s'", sr_commands[i].command_id, i, sr_commands[i].str); - } - - // Load commands - esp_mn_error_t *err_id = esp_mn_commands_update(); - if(err_id){ - for (int i = 0; i < err_id->num; i++) { - log_e("err cmd id:%d", err_id->phrases[i]->command_id); - } +esp_err_t sr_start(sr_fill_cb fill_cb, void *fill_cb_arg, sr_channels_t rx_chan, sr_mode_t mode, const sr_cmd_t sr_commands[], size_t cmd_number, sr_event_cb cb, void *cb_arg) { + esp_err_t ret = ESP_OK; + ESP_RETURN_ON_FALSE(NULL == g_sr_data, ESP_ERR_INVALID_STATE, "SR already running"); + + g_sr_data = heap_caps_calloc(1, sizeof(sr_data_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + ESP_RETURN_ON_FALSE(NULL != g_sr_data, ESP_ERR_NO_MEM, "Failed create sr data"); + + g_sr_data->result_que = xQueueCreate(3, sizeof(sr_result_t)); + ESP_GOTO_ON_FALSE(NULL != g_sr_data->result_que, ESP_ERR_NO_MEM, err, "Failed create result queue"); + + g_sr_data->event_group = xEventGroupCreate(); + ESP_GOTO_ON_FALSE(NULL != g_sr_data->event_group, ESP_ERR_NO_MEM, err, "Failed create event_group"); + + BaseType_t ret_val; + g_sr_data->user_cb = cb; + g_sr_data->user_cb_arg = cb_arg; + g_sr_data->fill_cb = fill_cb; + g_sr_data->fill_cb_arg = fill_cb_arg; + g_sr_data->i2s_rx_chan_num = rx_chan + 1; + g_sr_data->mode = mode; + + // Init Model + log_d("init model"); + models = esp_srmodel_init("model"); + + // Load WakeWord Detection + g_sr_data->afe_handle = (esp_afe_sr_iface_t *)&ESP_AFE_SR_HANDLE; + afe_config_t afe_config = AFE_CONFIG_DEFAULT(); + afe_config.wakenet_model_name = esp_srmodel_filter(models, ESP_WN_PREFIX, "hiesp"); + afe_config.aec_init = false; + log_d("load wakenet '%s'", afe_config.wakenet_model_name); + g_sr_data->afe_data = g_sr_data->afe_handle->create_from_config(&afe_config); + + // Load Custom Command Detection + char *mn_name = esp_srmodel_filter(models, ESP_MN_PREFIX, ESP_MN_ENGLISH); + log_d("load multinet '%s'", mn_name); + g_sr_data->multinet = esp_mn_handle_from_name(mn_name); + log_d("load model_data '%s'", mn_name); + g_sr_data->model_data = g_sr_data->multinet->create(mn_name, 5760); + + + // Add commands + esp_mn_commands_alloc((esp_mn_iface_t *)g_sr_data->multinet, (model_iface_data_t *)g_sr_data->model_data); + log_i("add %d commands", cmd_number); + for (size_t i = 0; i < cmd_number; i++) { + esp_mn_commands_add(sr_commands[i].command_id, (char *)(sr_commands[i].phoneme)); + log_i(" cmd[%d] phrase[%d]:'%s'", sr_commands[i].command_id, i, sr_commands[i].str); + } + + // Load commands + esp_mn_error_t *err_id = esp_mn_commands_update(); + if (err_id) { + for (int i = 0; i < err_id->num; i++) { + log_e("err cmd id:%d", err_id->phrases[i]->command_id); } - - //Start tasks - log_d("start tasks"); - ret_val = xTaskCreatePinnedToCore(&audio_feed_task, "SR Feed Task", 4 * 1024, NULL, 5, &g_sr_data->feed_task, 0); - ESP_GOTO_ON_FALSE(pdPASS == ret_val, ESP_FAIL, err, "Failed create audio feed task"); - vTaskDelay(10); - ret_val = xTaskCreatePinnedToCore(&audio_detect_task, "SR Detect Task", 8 * 1024, NULL, 5, &g_sr_data->detect_task, 1); - ESP_GOTO_ON_FALSE(pdPASS == ret_val, ESP_FAIL, err, "Failed create audio detect task"); - ret_val = xTaskCreatePinnedToCore(&sr_handler_task, "SR Handler Task", 6 * 1024, NULL, configMAX_PRIORITIES - 1, &g_sr_data->handle_task, 1); - //ret_val = xTaskCreatePinnedToCore(&sr_handler_task, "SR Handler Task", 6 * 1024, NULL, configMAX_PRIORITIES - 1, &g_sr_data->handle_task, 0); - ESP_GOTO_ON_FALSE(pdPASS == ret_val, ESP_FAIL, err, "Failed create audio handler task"); - - return ESP_OK; + } + + //Start tasks + log_d("start tasks"); + ret_val = xTaskCreatePinnedToCore(&audio_feed_task, "SR Feed Task", 4 * 1024, NULL, 5, &g_sr_data->feed_task, 0); + ESP_GOTO_ON_FALSE(pdPASS == ret_val, ESP_FAIL, err, "Failed create audio feed task"); + vTaskDelay(10); + ret_val = xTaskCreatePinnedToCore(&audio_detect_task, "SR Detect Task", 8 * 1024, NULL, 5, &g_sr_data->detect_task, 1); + ESP_GOTO_ON_FALSE(pdPASS == ret_val, ESP_FAIL, err, "Failed create audio detect task"); + ret_val = xTaskCreatePinnedToCore(&sr_handler_task, "SR Handler Task", 6 * 1024, NULL, configMAX_PRIORITIES - 1, &g_sr_data->handle_task, 1); + //ret_val = xTaskCreatePinnedToCore(&sr_handler_task, "SR Handler Task", 6 * 1024, NULL, configMAX_PRIORITIES - 1, &g_sr_data->handle_task, 0); + ESP_GOTO_ON_FALSE(pdPASS == ret_val, ESP_FAIL, err, "Failed create audio handler task"); + + return ESP_OK; err: - sr_stop(); - return ret; + sr_stop(); + return ret; } -esp_err_t sr_stop(void) -{ - ESP_RETURN_ON_FALSE(NULL != g_sr_data, ESP_ERR_INVALID_STATE, "SR is not running"); +esp_err_t sr_stop(void) { + ESP_RETURN_ON_FALSE(NULL != g_sr_data, ESP_ERR_INVALID_STATE, "SR is not running"); - /** - * Waiting for all task stoped + /** + * Waiting for all task stopped * TODO: A task creation failure cannot be handled correctly now * */ - vTaskDelete(g_sr_data->handle_task); - xEventGroupSetBits(g_sr_data->event_group, NEED_DELETE); - xEventGroupWaitBits(g_sr_data->event_group, NEED_DELETE | FEED_DELETED | DETECT_DELETED, 1, 1, portMAX_DELAY); - - if (g_sr_data->result_que) { - vQueueDelete(g_sr_data->result_que); - g_sr_data->result_que = NULL; - } - - if (g_sr_data->event_group) { - vEventGroupDelete(g_sr_data->event_group); - g_sr_data->event_group = NULL; - } - - if (g_sr_data->model_data) { - g_sr_data->multinet->destroy(g_sr_data->model_data); - } - - if (g_sr_data->afe_data) { - g_sr_data->afe_handle->destroy(g_sr_data->afe_data); - } - - if (g_sr_data->afe_in_buffer) { - heap_caps_free(g_sr_data->afe_in_buffer); - } - - heap_caps_free(g_sr_data); - g_sr_data = NULL; - return ESP_OK; + vTaskDelete(g_sr_data->handle_task); + xEventGroupSetBits(g_sr_data->event_group, NEED_DELETE); + xEventGroupWaitBits(g_sr_data->event_group, NEED_DELETE | FEED_DELETED | DETECT_DELETED, 1, 1, portMAX_DELAY); + + if (g_sr_data->result_que) { + vQueueDelete(g_sr_data->result_que); + g_sr_data->result_que = NULL; + } + + if (g_sr_data->event_group) { + vEventGroupDelete(g_sr_data->event_group); + g_sr_data->event_group = NULL; + } + + if (g_sr_data->model_data) { + g_sr_data->multinet->destroy(g_sr_data->model_data); + } + + if (g_sr_data->afe_data) { + g_sr_data->afe_handle->destroy(g_sr_data->afe_data); + } + + if (g_sr_data->afe_in_buffer) { + heap_caps_free(g_sr_data->afe_in_buffer); + } + + heap_caps_free(g_sr_data); + g_sr_data = NULL; + return ESP_OK; } -esp_err_t sr_pause(void) -{ - ESP_RETURN_ON_FALSE(NULL != g_sr_data, ESP_ERR_INVALID_STATE, "SR is not running"); - xEventGroupSetBits(g_sr_data->event_group, PAUSE_FEED | PAUSE_DETECT); - return ESP_OK; +esp_err_t sr_pause(void) { + ESP_RETURN_ON_FALSE(NULL != g_sr_data, ESP_ERR_INVALID_STATE, "SR is not running"); + xEventGroupSetBits(g_sr_data->event_group, PAUSE_FEED | PAUSE_DETECT); + return ESP_OK; } -esp_err_t sr_resume(void) -{ - ESP_RETURN_ON_FALSE(NULL != g_sr_data, ESP_ERR_INVALID_STATE, "SR is not running"); - xEventGroupSetBits(g_sr_data->event_group, RESUME_FEED | RESUME_DETECT); - return ESP_OK; +esp_err_t sr_resume(void) { + ESP_RETURN_ON_FALSE(NULL != g_sr_data, ESP_ERR_INVALID_STATE, "SR is not running"); + xEventGroupSetBits(g_sr_data->event_group, RESUME_FEED | RESUME_DETECT); + return ESP_OK; } -#endif // CONFIG_IDF_TARGET_ESP32S3 +#endif // CONFIG_IDF_TARGET_ESP32S3 diff --git a/libraries/ESP_SR/src/esp32-hal-sr.h b/libraries/ESP_SR/src/esp32-hal-sr.h index 33d22a79d93..21e008e1137 100644 --- a/libraries/ESP_SR/src/esp32-hal-sr.h +++ b/libraries/ESP_SR/src/esp32-hal-sr.h @@ -18,59 +18,59 @@ extern "C" { #define SR_CMD_STR_LEN_MAX 64 #define SR_CMD_PHONEME_LEN_MAX 64 -typedef struct sr_cmd_t { + typedef struct sr_cmd_t { int command_id; char str[SR_CMD_STR_LEN_MAX]; char phoneme[SR_CMD_PHONEME_LEN_MAX]; -} sr_cmd_t; + } sr_cmd_t; -typedef enum { - SR_EVENT_WAKEWORD,//WakeWord Detected - SR_EVENT_WAKEWORD_CHANNEL,//WakeWord Channel Verified - SR_EVENT_COMMAND,//Command Detected - SR_EVENT_TIMEOUT,//Command Timeout + typedef enum { + SR_EVENT_WAKEWORD, //WakeWord Detected + SR_EVENT_WAKEWORD_CHANNEL, //WakeWord Channel Verified + SR_EVENT_COMMAND, //Command Detected + SR_EVENT_TIMEOUT, //Command Timeout SR_EVENT_MAX -} sr_event_t; + } sr_event_t; -typedef enum { - SR_MODE_OFF,//Detection Off - SR_MODE_WAKEWORD,//WakeWord Detection - SR_MODE_COMMAND,//Command Detection + typedef enum { + SR_MODE_OFF, //Detection Off + SR_MODE_WAKEWORD, //WakeWord Detection + SR_MODE_COMMAND, //Command Detection SR_MODE_MAX -} sr_mode_t; + } sr_mode_t; -typedef enum { + typedef enum { SR_CHANNELS_MONO, SR_CHANNELS_STEREO, SR_CHANNELS_MAX -} sr_channels_t; + } sr_channels_t; -typedef void (*sr_event_cb)(void * arg, sr_event_t event, int command_id, int phrase_id); -typedef esp_err_t (*sr_fill_cb)(void * arg, void * out, size_t len, size_t *bytes_read, uint32_t timeout_ms); + typedef void (*sr_event_cb)(void *arg, sr_event_t event, int command_id, int phrase_id); + typedef esp_err_t (*sr_fill_cb)(void *arg, void *out, size_t len, size_t *bytes_read, uint32_t timeout_ms); -esp_err_t sr_start(sr_fill_cb fill_cb, void * fill_cb_arg, sr_channels_t rx_chan, sr_mode_t mode, const sr_cmd_t * sr_commands, size_t cmd_number, sr_event_cb cb, void * cb_arg); -esp_err_t sr_stop(void); -esp_err_t sr_pause(void); -esp_err_t sr_resume(void); -esp_err_t sr_set_mode(sr_mode_t mode); + esp_err_t sr_start(sr_fill_cb fill_cb, void *fill_cb_arg, sr_channels_t rx_chan, sr_mode_t mode, const sr_cmd_t *sr_commands, size_t cmd_number, sr_event_cb cb, void *cb_arg); + esp_err_t sr_stop(void); + esp_err_t sr_pause(void); + esp_err_t sr_resume(void); + esp_err_t sr_set_mode(sr_mode_t mode); -// static const sr_cmd_t sr_commands[] = { -// {0, "Turn On the Light", "TkN nN jc LiT"}, -// {0, "Switch On the Light", "SWgp nN jc LiT"}, -// {1, "Switch Off the Light", "SWgp eF jc LiT"}, -// {1, "Turn Off the Light", "TkN eF jc LiT"}, -// {2, "Turn Red", "TkN RfD"}, -// {3, "Turn Green", "TkN GRmN"}, -// {4, "Turn Blue", "TkN BLo"}, -// {5, "Customize Color", "KcSTcMiZ KcLk"}, -// {6, "Sing a song", "Sgl c Sel"}, -// {7, "Play Music", "PLd MYoZgK"}, -// {8, "Next Song", "NfKST Sel"}, -// {9, "Pause Playing", "PeZ PLdgl"}, -// }; + // static const sr_cmd_t sr_commands[] = { + // {0, "Turn On the Light", "TkN nN jc LiT"}, + // {0, "Switch On the Light", "SWgp nN jc LiT"}, + // {1, "Switch Off the Light", "SWgp eF jc LiT"}, + // {1, "Turn Off the Light", "TkN eF jc LiT"}, + // {2, "Turn Red", "TkN RfD"}, + // {3, "Turn Green", "TkN GRmN"}, + // {4, "Turn Blue", "TkN BLo"}, + // {5, "Customize Color", "KcSTcMiZ KcLk"}, + // {6, "Sing a song", "Sgl c Sel"}, + // {7, "Play Music", "PLd MYoZgK"}, + // {8, "Next Song", "NfKST Sel"}, + // {9, "Pause Playing", "PeZ PLdgl"}, + // }; #ifdef __cplusplus } #endif -#endif // CONFIG_IDF_TARGET_ESP32S3 +#endif // CONFIG_IDF_TARGET_ESP32S3 diff --git a/libraries/ESP_SR/tools/gen_sr_commands.py b/libraries/ESP_SR/tools/gen_sr_commands.py index f3629b71bcb..3ac08cc6e44 100644 --- a/libraries/ESP_SR/tools/gen_sr_commands.py +++ b/libraries/ESP_SR/tools/gen_sr_commands.py @@ -2,7 +2,8 @@ from g2p_en import G2p import argparse -# python3 gen_sr_commands.py "Turn on the light,Switch on the light;Turn off the light,Switch off the light,Go dark;Start fan;Stop fan;Volume down,Turn down;Mute sound;Next song;Pause playback" +# python3 gen_sr_commands.py "Turn on the light,Switch on the light;Turn off the light,Switch off the light,Go dark;\ +# Start fan;Stop fan;Volume down,Turn down;Mute sound;Next song;Pause playback" # enum { # SR_CMD_TURN_ON_THE_LIGHT, # SR_CMD_TURN_OFF_THE_LIGHT, @@ -28,11 +29,83 @@ # { 7, "Pause playback", "PeZ PLdBaK"}, # }; + def english_g2p(text): g2p = G2p() out = "static const sr_cmd_t sr_commands[] = {\n" enum = "enum {\n" - alphabet={"AE1": "a", "N": "N", " ": " ", "OW1": "b", "V": "V", "AH0": "c", "L": "L", "F": "F", "EY1": "d", "S": "S", "B": "B", "R": "R", "AO1": "e", "D": "D", "AH1": "c", "EH1": "f", "OW0": "b", "IH0": "g", "G": "G", "HH": "h", "K": "K", "IH1": "g", "W": "W", "AY1": "i", "T": "T", "M": "M", "Z": "Z", "DH": "j", "ER0": "k", "P": "P", "NG": "l", "IY1": "m", "AA1": "n", "Y": "Y", "UW1": "o", "IY0": "m", "EH2": "f", "CH": "p", "AE0": "a", "JH": "q", "ZH": "r", "AA2": "n", "SH": "s", "AW1": "t", "OY1": "u", "AW2": "t", "IH2": "g", "AE2": "a", "EY2": "d", "ER1": "k", "TH": "v", "UH1": "w", "UW2": "o", "OW2": "b", "AY2": "i", "UW0": "o", "AH2": "c", "EH0": "f", "AW0": "t", "AO2": "e", "AO0": "e", "UH0": "w", "UH2": "w", "AA0": "n", "AY0": "i", "IY2": "m", "EY0": "d", "ER2": "k", "OY2": "u", "OY0": "u"} + alphabet = { + "AE1": "a", + "N": "N", + " ": " ", + "OW1": "b", + "V": "V", + "AH0": "c", + "L": "L", + "F": "F", + "EY1": "d", + "S": "S", + "B": "B", + "R": "R", + "AO1": "e", + "D": "D", + "AH1": "c", + "EH1": "f", + "OW0": "b", + "IH0": "g", + "G": "G", + "HH": "h", + "K": "K", + "IH1": "g", + "W": "W", + "AY1": "i", + "T": "T", + "M": "M", + "Z": "Z", + "DH": "j", + "ER0": "k", + "P": "P", + "NG": "l", + "IY1": "m", + "AA1": "n", + "Y": "Y", + "UW1": "o", + "IY0": "m", + "EH2": "f", + "CH": "p", + "AE0": "a", + "JH": "q", + "ZH": "r", + "AA2": "n", + "SH": "s", + "AW1": "t", + "OY1": "u", + "AW2": "t", + "IH2": "g", + "AE2": "a", + "EY2": "d", + "ER1": "k", + "TH": "v", + "UH1": "w", + "UW2": "o", + "OW2": "b", + "AY2": "i", + "UW0": "o", + "AH2": "c", + "EH0": "f", + "AW0": "t", + "AO2": "e", + "AO0": "e", + "UH0": "w", + "UH2": "w", + "AA0": "n", + "AY0": "i", + "IY2": "m", + "EY0": "d", + "ER2": "k", + "OY2": "u", + "OY0": "u", + } cmd_id = 0 phrase_id = 0 @@ -49,9 +122,9 @@ def english_g2p(text): continue else: phoneme += alphabet[char] - out += " { "+str(cmd_id)+", \""+phrase+"\", \""+phoneme+"\"},\n" + out += " { " + str(cmd_id) + ', "' + phrase + '", "' + phoneme + '"},\n' if phrase_id == 0: - enum += " SR_CMD_"+phrase.upper().replace(" ", "_")+",\n" + enum += " SR_CMD_" + phrase.upper().replace(" ", "_") + ",\n" phrase_id += 1 cmd_id += 1 out += "};" @@ -59,15 +132,15 @@ def english_g2p(text): # print(text) print(enum) print(out) - + return out + if __name__ == "__main__": parser = argparse.ArgumentParser(prog="English Speech Commands G2P") - parser.add_argument("text", type=str, default=None, help="input text") + parser.add_argument("text", type=str, default=None, help="input text") args = parser.parse_args() - + if args.text is not None: english_g2p(args.text) - diff --git a/libraries/ESPmDNS/examples/mDNS-SD_Extended/mDNS-SD_Extended.ino b/libraries/ESPmDNS/examples/mDNS-SD_Extended/mDNS-SD_Extended.ino index 9e582b3236a..e7a96239454 100644 --- a/libraries/ESPmDNS/examples/mDNS-SD_Extended/mDNS-SD_Extended.ino +++ b/libraries/ESPmDNS/examples/mDNS-SD_Extended/mDNS-SD_Extended.ino @@ -2,7 +2,7 @@ ESP8266 mDNS-SD responder and query sample This is an example of announcing and finding services. - + Instructions: - Update WiFi SSID and password as necessary. - Flash the sketch to two ESP8266 boards @@ -12,69 +12,69 @@ #include #include -const char* ssid = "..."; +const char* ssid = "..."; const char* password = "..."; void setup() { - Serial.begin(115200); - WiFi.begin(ssid, password); - while (WiFi.status() != WL_CONNECTED) { - delay(250); - Serial.print("."); - } - Serial.println(""); - Serial.print("Connected to "); - Serial.println(ssid); - Serial.print("IP address: "); - Serial.println(WiFi.localIP()); + Serial.begin(115200); + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(250); + Serial.print("."); + } + Serial.println(""); + Serial.print("Connected to "); + Serial.println(ssid); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); - if (!MDNS.begin("ESP32_Browser")) { - Serial.println("Error setting up MDNS responder!"); - while(1){ - delay(1000); - } + if (!MDNS.begin("ESP32_Browser")) { + Serial.println("Error setting up MDNS responder!"); + while (1) { + delay(1000); } + } } void loop() { - browseService("http", "tcp"); - delay(1000); - browseService("arduino", "tcp"); - delay(1000); - browseService("workstation", "tcp"); - delay(1000); - browseService("smb", "tcp"); - delay(1000); - browseService("afpovertcp", "tcp"); - delay(1000); - browseService("ftp", "tcp"); - delay(1000); - browseService("ipp", "tcp"); - delay(1000); - browseService("printer", "tcp"); - delay(10000); + browseService("http", "tcp"); + delay(1000); + browseService("arduino", "tcp"); + delay(1000); + browseService("workstation", "tcp"); + delay(1000); + browseService("smb", "tcp"); + delay(1000); + browseService("afpovertcp", "tcp"); + delay(1000); + browseService("ftp", "tcp"); + delay(1000); + browseService("ipp", "tcp"); + delay(1000); + browseService("printer", "tcp"); + delay(10000); } -void browseService(const char * service, const char * proto){ - Serial.printf("Browsing for service _%s._%s.local. ... ", service, proto); - int n = MDNS.queryService(service, proto); - if (n == 0) { - Serial.println("no services found"); - } else { - Serial.print(n); - Serial.println(" service(s) found"); - for (int i = 0; i < n; ++i) { - // Print details for each service found - Serial.print(" "); - Serial.print(i + 1); - Serial.print(": "); - Serial.print(MDNS.hostname(i)); - Serial.print(" ("); - Serial.print(MDNS.address(i)); - Serial.print(":"); - Serial.print(MDNS.port(i)); - Serial.println(")"); - } +void browseService(const char* service, const char* proto) { + Serial.printf("Browsing for service _%s._%s.local. ... ", service, proto); + int n = MDNS.queryService(service, proto); + if (n == 0) { + Serial.println("no services found"); + } else { + Serial.print(n); + Serial.println(" service(s) found"); + for (int i = 0; i < n; ++i) { + // Print details for each service found + Serial.print(" "); + Serial.print(i + 1); + Serial.print(": "); + Serial.print(MDNS.hostname(i)); + Serial.print(" ("); + Serial.print(MDNS.address(i)); + Serial.print(":"); + Serial.print(MDNS.port(i)); + Serial.println(")"); } - Serial.println(); + } + Serial.println(); } diff --git a/libraries/ESPmDNS/examples/mDNS_Web_Server/mDNS_Web_Server.ino b/libraries/ESPmDNS/examples/mDNS_Web_Server/mDNS_Web_Server.ino index e027cc2672e..4d6f0fae466 100644 --- a/libraries/ESPmDNS/examples/mDNS_Web_Server/mDNS_Web_Server.ino +++ b/libraries/ESPmDNS/examples/mDNS_Web_Server/mDNS_Web_Server.ino @@ -26,95 +26,89 @@ const char* password = ".............."; // TCP server at port 80 will respond to HTTP requests NetworkServer server(80); -void setup(void) -{ - Serial.begin(115200); - - // Connect to WiFi network - WiFi.begin(ssid, password); - Serial.println(""); - - // Wait for connection - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); +void setup(void) { + Serial.begin(115200); + + // Connect to WiFi network + WiFi.begin(ssid, password); + Serial.println(""); + + // Wait for connection + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println(""); + Serial.print("Connected to "); + Serial.println(ssid); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); + + // Set up mDNS responder: + // - first argument is the domain name, in this example + // the fully-qualified domain name is "esp32.local" + // - second argument is the IP address to advertise + // we send our IP address on the WiFi network + if (!MDNS.begin("esp32")) { + Serial.println("Error setting up MDNS responder!"); + while (1) { + delay(1000); } - Serial.println(""); - Serial.print("Connected to "); - Serial.println(ssid); - Serial.print("IP address: "); - Serial.println(WiFi.localIP()); - - // Set up mDNS responder: - // - first argument is the domain name, in this example - // the fully-qualified domain name is "esp32.local" - // - second argument is the IP address to advertise - // we send our IP address on the WiFi network - if (!MDNS.begin("esp32")) { - Serial.println("Error setting up MDNS responder!"); - while(1) { - delay(1000); - } - } - Serial.println("mDNS responder started"); + } + Serial.println("mDNS responder started"); - // Start TCP (HTTP) server - server.begin(); - Serial.println("TCP server started"); + // Start TCP (HTTP) server + server.begin(); + Serial.println("TCP server started"); - // Add service to MDNS-SD - MDNS.addService("http", "tcp", 80); + // Add service to MDNS-SD + MDNS.addService("http", "tcp", 80); } -void loop(void) -{ - // Check if a client has connected - NetworkClient client = server.accept(); - if (!client) { - return; - } - Serial.println(""); - Serial.println("New client"); - - // Wait for data from client to become available - while(client.connected() && !client.available()){ - delay(1); - } - - // Read the first line of HTTP request - String req = client.readStringUntil('\r'); - - // First line of HTTP request looks like "GET /path HTTP/1.1" - // Retrieve the "/path" part by finding the spaces - int addr_start = req.indexOf(' '); - int addr_end = req.indexOf(' ', addr_start + 1); - if (addr_start == -1 || addr_end == -1) { - Serial.print("Invalid request: "); - Serial.println(req); - return; - } - req = req.substring(addr_start + 1, addr_end); - Serial.print("Request: "); +void loop(void) { + // Check if a client has connected + NetworkClient client = server.accept(); + if (!client) { + return; + } + Serial.println(""); + Serial.println("New client"); + + // Wait for data from client to become available + while (client.connected() && !client.available()) { + delay(1); + } + + // Read the first line of HTTP request + String req = client.readStringUntil('\r'); + + // First line of HTTP request looks like "GET /path HTTP/1.1" + // Retrieve the "/path" part by finding the spaces + int addr_start = req.indexOf(' '); + int addr_end = req.indexOf(' ', addr_start + 1); + if (addr_start == -1 || addr_end == -1) { + Serial.print("Invalid request: "); Serial.println(req); - - String s; - if (req == "/") - { - IPAddress ip = WiFi.localIP(); - String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]); - s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\nHello from ESP32 at "; - s += ipStr; - s += "\r\n\r\n"; - Serial.println("Sending 200"); - } - else - { - s = "HTTP/1.1 404 Not Found\r\n\r\n"; - Serial.println("Sending 404"); - } - client.print(s); - - client.stop(); - Serial.println("Done with client"); + return; + } + req = req.substring(addr_start + 1, addr_end); + Serial.print("Request: "); + Serial.println(req); + + String s; + if (req == "/") { + IPAddress ip = WiFi.localIP(); + String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]); + s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\nHello from ESP32 at "; + s += ipStr; + s += "\r\n\r\n"; + Serial.println("Sending 200"); + } else { + s = "HTTP/1.1 404 Not Found\r\n\r\n"; + Serial.println("Sending 404"); + } + client.print(s); + + client.stop(); + Serial.println("Done with client"); } - diff --git a/libraries/ESPmDNS/keywords.txt b/libraries/ESPmDNS/keywords.txt index c012cb59bd7..10bdb4f9e4f 100644 --- a/libraries/ESPmDNS/keywords.txt +++ b/libraries/ESPmDNS/keywords.txt @@ -22,4 +22,3 @@ disableArduino KEYWORD2 ####################################### # Constants (LITERAL1) ####################################### - diff --git a/libraries/ESPmDNS/src/ESPmDNS.cpp b/libraries/ESPmDNS/src/ESPmDNS.cpp index 0e4f4b7b4a7..a7264e63fc3 100644 --- a/libraries/ESPmDNS/src/ESPmDNS.cpp +++ b/libraries/ESPmDNS/src/ESPmDNS.cpp @@ -4,7 +4,7 @@ ESP8266 Multicast DNS (port of CC3000 Multicast DNS library) Version 1.1 Copyright (c) 2013 Tony DiCola (tony@tonydicola.com) ESP8266 port (c) 2015 Ivan Grokhotkov (ivan@esp8266.com) -MDNS-SD Suport 2015 Hristo Gochkov (hristo@espressif.com) +MDNS-SD Support 2015 Hristo Gochkov (hristo@espressif.com) Extended MDNS-SD support 2016 Lars Englund (lars.englund@gmail.com) @@ -74,323 +74,324 @@ License (MIT license): // mdns_handle_system_event(NULL, event); // } -MDNSResponder::MDNSResponder() :results(NULL) {} +MDNSResponder::MDNSResponder() + : results(NULL) {} MDNSResponder::~MDNSResponder() { - end(); + end(); } -bool MDNSResponder::begin(const String& hostName){ - if(mdns_init()){ - log_e("Failed starting MDNS"); - return false; - } - //WiFi.onEvent(_on_sys_event); - _hostname = hostName; - _hostname.toLowerCase(); - if(mdns_hostname_set(hostName.c_str())) { - log_e("Failed setting MDNS hostname"); - return false; - } - return true; +bool MDNSResponder::begin(const String &hostName) { + if (mdns_init()) { + log_e("Failed starting MDNS"); + return false; + } + //WiFi.onEvent(_on_sys_event); + _hostname = hostName; + _hostname.toLowerCase(); + if (mdns_hostname_set(hostName.c_str())) { + log_e("Failed setting MDNS hostname"); + return false; + } + return true; } void MDNSResponder::end() { - mdns_free(); + mdns_free(); } void MDNSResponder::setInstanceName(String name) { - if (name.length() > 63) return; - if(mdns_instance_name_set(name.c_str())){ - log_e("Failed setting MDNS instance"); - return; - } + if (name.length() > 63) return; + if (mdns_instance_name_set(name.c_str())) { + log_e("Failed setting MDNS instance"); + return; + } } -void MDNSResponder::enableArduino(uint16_t port, bool auth){ - mdns_txt_item_t arduTxtData[4] = { - {(char*)"board" ,(char*)STR(ARDUINO_VARIANT)}, - {(char*)"tcp_check" ,(char*)"no"}, - {(char*)"ssh_upload" ,(char*)"no"}, - {(char*)"auth_upload" ,(char*)"no"} - }; +void MDNSResponder::enableArduino(uint16_t port, bool auth) { + mdns_txt_item_t arduTxtData[4] = { + { (char *)"board", (char *)STR(ARDUINO_VARIANT) }, + { (char *)"tcp_check", (char *)"no" }, + { (char *)"ssh_upload", (char *)"no" }, + { (char *)"auth_upload", (char *)"no" } + }; - if(mdns_service_add(NULL, "_arduino", "_tcp", port, arduTxtData, 4)) { - log_e("Failed adding Arduino service"); - } + if (mdns_service_add(NULL, "_arduino", "_tcp", port, arduTxtData, 4)) { + log_e("Failed adding Arduino service"); + } - if(auth && mdns_service_txt_item_set("_arduino", "_tcp", "auth_upload", "yes")){ - log_e("Failed setting Arduino txt item"); - } + if (auth && mdns_service_txt_item_set("_arduino", "_tcp", "auth_upload", "yes")) { + log_e("Failed setting Arduino txt item"); + } } -void MDNSResponder::disableArduino(){ - if(mdns_service_remove("_arduino", "_tcp")) { - log_w("Failed removing Arduino service"); - } +void MDNSResponder::disableArduino() { + if (mdns_service_remove("_arduino", "_tcp")) { + log_w("Failed removing Arduino service"); + } } -void MDNSResponder::enableWorkstation(esp_interface_t interface){ - char winstance[21+_hostname.length()]; - uint8_t mac[6]; +void MDNSResponder::enableWorkstation(esp_interface_t interface) { + char winstance[21 + _hostname.length()]; + uint8_t mac[6]; - esp_mac_type_t mtype = ESP_MAC_ETH; + esp_mac_type_t mtype = ESP_MAC_ETH; #if SOC_WIFI_SUPPORTED - switch(interface){ - case ESP_IF_WIFI_STA: - mtype = ESP_MAC_WIFI_STA; - break; - case ESP_IF_WIFI_AP: - mtype = ESP_MAC_WIFI_SOFTAP; - break; - default: - break; - } + switch (interface) { + case ESP_IF_WIFI_STA: + mtype = ESP_MAC_WIFI_STA; + break; + case ESP_IF_WIFI_AP: + mtype = ESP_MAC_WIFI_SOFTAP; + break; + default: + break; + } #endif - if(esp_read_mac(mac, mtype) != ESP_OK){ - log_e("Failed to read the MAC address"); - return; - } - - sprintf(winstance, "%s [%02x:%02x:%02x:%02x:%02x:%02x]", _hostname.c_str(), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - - if(mdns_service_add(NULL, "_workstation", "_tcp", 9, NULL, 0)) { - log_e("Failed adding Workstation service"); - } else if(mdns_service_instance_name_set("_workstation", "_tcp", winstance)) { - log_e("Failed setting Workstation service instance name"); - } + if (esp_read_mac(mac, mtype) != ESP_OK) { + log_e("Failed to read the MAC address"); + return; + } + + sprintf(winstance, "%s [%02x:%02x:%02x:%02x:%02x:%02x]", _hostname.c_str(), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + + if (mdns_service_add(NULL, "_workstation", "_tcp", 9, NULL, 0)) { + log_e("Failed adding Workstation service"); + } else if (mdns_service_instance_name_set("_workstation", "_tcp", winstance)) { + log_e("Failed setting Workstation service instance name"); + } } -void MDNSResponder::disableWorkstation(){ - if(mdns_service_remove("_workstation", "_tcp")) { - log_w("Failed removing Workstation service"); - } +void MDNSResponder::disableWorkstation() { + if (mdns_service_remove("_workstation", "_tcp")) { + log_w("Failed removing Workstation service"); + } } -bool MDNSResponder::addService(char *name, char *proto, uint16_t port){ - char _name[strlen(name)+2]; - char _proto[strlen(proto)+2]; - if (name[0] == '_') { - sprintf(_name, "%s", name); - } else { - sprintf(_name, "_%s", name); - } - if (proto[0] == '_') { - sprintf(_proto, "%s", proto); - } else { - sprintf(_proto, "_%s", proto); - } - - if(mdns_service_add(NULL, _name, _proto, port, NULL, 0)) { - log_e("Failed adding service %s.%s.\n", name, proto); - return false; - } - return true; +bool MDNSResponder::addService(char *name, char *proto, uint16_t port) { + char _name[strlen(name) + 2]; + char _proto[strlen(proto) + 2]; + if (name[0] == '_') { + sprintf(_name, "%s", name); + } else { + sprintf(_name, "_%s", name); + } + if (proto[0] == '_') { + sprintf(_proto, "%s", proto); + } else { + sprintf(_proto, "_%s", proto); + } + + if (mdns_service_add(NULL, _name, _proto, port, NULL, 0)) { + log_e("Failed adding service %s.%s.\n", name, proto); + return false; + } + return true; } -bool MDNSResponder::addServiceTxt(char *name, char *proto, char *key, char *value){ - char _name[strlen(name)+2]; - char _proto[strlen(proto)+2]; - if (name[0] == '_') { - sprintf(_name, "%s", name); - } else { - sprintf(_name, "_%s", name); - } - if (proto[0] == '_') { - sprintf(_proto, "%s", proto); - } else { - sprintf(_proto, "_%s", proto); - } - - if(mdns_service_txt_item_set(_name, _proto, key, value)) { - log_e("Failed setting service TXT"); - return false; - } - return true; +bool MDNSResponder::addServiceTxt(char *name, char *proto, char *key, char *value) { + char _name[strlen(name) + 2]; + char _proto[strlen(proto) + 2]; + if (name[0] == '_') { + sprintf(_name, "%s", name); + } else { + sprintf(_name, "_%s", name); + } + if (proto[0] == '_') { + sprintf(_proto, "%s", proto); + } else { + sprintf(_proto, "_%s", proto); + } + + if (mdns_service_txt_item_set(_name, _proto, key, value)) { + log_e("Failed setting service TXT"); + return false; + } + return true; } -IPAddress MDNSResponder::queryHost(char *host, uint32_t timeout){ - esp_ip4_addr_t addr; - addr.addr = 0; - - esp_err_t err = mdns_query_a(host, timeout, &addr); - if(err){ - if(err == ESP_ERR_NOT_FOUND){ - log_w("Host was not found!"); - return IPAddress(); - } - log_e("Query Failed"); - return IPAddress(); +IPAddress MDNSResponder::queryHost(char *host, uint32_t timeout) { + esp_ip4_addr_t addr; + addr.addr = 0; + + esp_err_t err = mdns_query_a(host, timeout, &addr); + if (err) { + if (err == ESP_ERR_NOT_FOUND) { + log_w("Host was not found!"); + return IPAddress(); } - return IPAddress(addr.addr); + log_e("Query Failed"); + return IPAddress(); + } + return IPAddress(addr.addr); } int MDNSResponder::queryService(char *service, char *proto) { - if(!service || !service[0] || !proto || !proto[0]){ - log_e("Bad Parameters"); - return 0; - } - - if(results){ - mdns_query_results_free(results); - results = NULL; - } - - char srv[strlen(service)+2]; - char prt[strlen(proto)+2]; - if (service[0] == '_') { - sprintf(srv, "%s", service); - } else { - sprintf(srv, "_%s", service); - } - if (proto[0] == '_') { - sprintf(prt, "%s", proto); - } else { - sprintf(prt, "_%s", proto); - } - - esp_err_t err = mdns_query_ptr(srv, prt, 3000, 20, &results); - if(err){ - log_e("Query Failed"); - return 0; - } - if(!results){ - log_w("No results found!"); - return 0; - } - - mdns_result_t * r = results; - int i = 0; - while(r){ - i++; - r = r->next; - } - return i; + if (!service || !service[0] || !proto || !proto[0]) { + log_e("Bad Parameters"); + return 0; + } + + if (results) { + mdns_query_results_free(results); + results = NULL; + } + + char srv[strlen(service) + 2]; + char prt[strlen(proto) + 2]; + if (service[0] == '_') { + sprintf(srv, "%s", service); + } else { + sprintf(srv, "_%s", service); + } + if (proto[0] == '_') { + sprintf(prt, "%s", proto); + } else { + sprintf(prt, "_%s", proto); + } + + esp_err_t err = mdns_query_ptr(srv, prt, 3000, 20, &results); + if (err) { + log_e("Query Failed"); + return 0; + } + if (!results) { + log_w("No results found!"); + return 0; + } + + mdns_result_t *r = results; + int i = 0; + while (r) { + i++; + r = r->next; + } + return i; } -mdns_result_t * MDNSResponder::_getResult(int idx){ - mdns_result_t * result = results; - int i = 0; - while(result){ - if(i == idx){ - break; - } - i++; - result = result->next; +mdns_result_t *MDNSResponder::_getResult(int idx) { + mdns_result_t *result = results; + int i = 0; + while (result) { + if (i == idx) { + break; } - return result; + i++; + result = result->next; + } + return result; } -mdns_txt_item_t * MDNSResponder::_getResultTxt(int idx, int txtIdx){ - mdns_result_t * result = _getResult(idx); - if(!result){ - log_e("Result %d not found", idx); - return NULL; - } - if (txtIdx >= result->txt_count) return NULL; - return &result->txt[txtIdx]; +mdns_txt_item_t *MDNSResponder::_getResultTxt(int idx, int txtIdx) { + mdns_result_t *result = _getResult(idx); + if (!result) { + log_e("Result %d not found", idx); + return NULL; + } + if (txtIdx >= result->txt_count) return NULL; + return &result->txt[txtIdx]; } String MDNSResponder::hostname(int idx) { - mdns_result_t * result = _getResult(idx); - if(!result){ - log_e("Result %d not found", idx); - return String(); - } - return String(result->hostname); + mdns_result_t *result = _getResult(idx); + if (!result) { + log_e("Result %d not found", idx); + return String(); + } + return String(result->hostname); } IPAddress MDNSResponder::address(int idx) { - mdns_result_t * result = _getResult(idx); - if(!result){ - log_e("Result %d not found", idx); - return IPAddress(); - } - mdns_ip_addr_t * addr = result->addr; - while(addr){ - if(addr->addr.type == MDNS_IP_PROTOCOL_V4){ - return IPAddress(addr->addr.u_addr.ip4.addr); - } - addr = addr->next; - } + mdns_result_t *result = _getResult(idx); + if (!result) { + log_e("Result %d not found", idx); return IPAddress(); + } + mdns_ip_addr_t *addr = result->addr; + while (addr) { + if (addr->addr.type == MDNS_IP_PROTOCOL_V4) { + return IPAddress(addr->addr.u_addr.ip4.addr); + } + addr = addr->next; + } + return IPAddress(); } IPAddress MDNSResponder::addressV6(int idx) { - mdns_result_t * result = _getResult(idx); - if(!result){ - log_e("Result %d not found", idx); - return IPAddress(IPv6); - } - mdns_ip_addr_t * addr = result->addr; - while(addr){ - if(addr->addr.type == MDNS_IP_PROTOCOL_V6){ - return IPAddress(IPv6, (const uint8_t *)addr->addr.u_addr.ip6.addr, addr->addr.u_addr.ip6.zone); - } - addr = addr->next; - } + mdns_result_t *result = _getResult(idx); + if (!result) { + log_e("Result %d not found", idx); return IPAddress(IPv6); + } + mdns_ip_addr_t *addr = result->addr; + while (addr) { + if (addr->addr.type == MDNS_IP_PROTOCOL_V6) { + return IPAddress(IPv6, (const uint8_t *)addr->addr.u_addr.ip6.addr, addr->addr.u_addr.ip6.zone); + } + addr = addr->next; + } + return IPAddress(IPv6); } uint16_t MDNSResponder::port(int idx) { - mdns_result_t * result = _getResult(idx); - if(!result){ - log_e("Result %d not found", idx); - return 0; - } - return result->port; + mdns_result_t *result = _getResult(idx); + if (!result) { + log_e("Result %d not found", idx); + return 0; + } + return result->port; } int MDNSResponder::numTxt(int idx) { - mdns_result_t * result = _getResult(idx); - if(!result){ - log_e("Result %d not found", idx); - return 0; - } - return result->txt_count; + mdns_result_t *result = _getResult(idx); + if (!result) { + log_e("Result %d not found", idx); + return 0; + } + return result->txt_count; } -bool MDNSResponder::hasTxt(int idx, const char * key) { - mdns_result_t * result = _getResult(idx); - if(!result){ - log_e("Result %d not found", idx); - return false; - } - int i = 0; - while(i < result->txt_count) { - if (strcmp(result->txt[i].key, key) == 0) return true; - i++; - } +bool MDNSResponder::hasTxt(int idx, const char *key) { + mdns_result_t *result = _getResult(idx); + if (!result) { + log_e("Result %d not found", idx); return false; + } + int i = 0; + while (i < result->txt_count) { + if (strcmp(result->txt[i].key, key) == 0) return true; + i++; + } + return false; } -String MDNSResponder::txt(int idx, const char * key) { - mdns_result_t * result = _getResult(idx); - if(!result){ - log_e("Result %d not found", idx); - return ""; - } - int i = 0; - while(i < result->txt_count) { - if (strcmp(result->txt[i].key, key) == 0) return result->txt[i].value; - i++; - } +String MDNSResponder::txt(int idx, const char *key) { + mdns_result_t *result = _getResult(idx); + if (!result) { + log_e("Result %d not found", idx); return ""; + } + int i = 0; + while (i < result->txt_count) { + if (strcmp(result->txt[i].key, key) == 0) return result->txt[i].value; + i++; + } + return ""; } String MDNSResponder::txt(int idx, int txtIdx) { - mdns_txt_item_t * resultTxt = _getResultTxt(idx, txtIdx); - return !resultTxt - ? "" - : resultTxt->value; + mdns_txt_item_t *resultTxt = _getResultTxt(idx, txtIdx); + return !resultTxt + ? "" + : resultTxt->value; } String MDNSResponder::txtKey(int idx, int txtIdx) { - mdns_txt_item_t * resultTxt = _getResultTxt(idx, txtIdx); - return !resultTxt - ? "" - : resultTxt->key; + mdns_txt_item_t *resultTxt = _getResultTxt(idx, txtIdx); + return !resultTxt + ? "" + : resultTxt->key; } MDNSResponder MDNS; diff --git a/libraries/ESPmDNS/src/ESPmDNS.h b/libraries/ESPmDNS/src/ESPmDNS.h index 01ca7518d2f..04ac382cfdc 100644 --- a/libraries/ESPmDNS/src/ESPmDNS.h +++ b/libraries/ESPmDNS/src/ESPmDNS.h @@ -3,12 +3,12 @@ ESP8266 Multicast DNS (port of CC3000 Multicast DNS library) Version 1.1 Copyright (c) 2013 Tony DiCola (tony@tonydicola.com) ESP8266 port (c) 2015 Ivan Grokhotkov (ivan@esp8266.com) -MDNS-SD Suport 2015 Hristo Gochkov (hristo@espressif.com) +MDNS-SD Support 2015 Hristo Gochkov (hristo@espressif.com) Extended MDNS-SD support 2016 Lars Englund (lars.englund@gmail.com) Rewritten for ESP32 by Hristo Gochkov (hristo@espressif.com) This is a simple implementation of multicast DNS query support for an Arduino -running on ESP32 chip. +running on ESP32 chip. Usage: - Include the ESP32 Multicast DNS library in the sketch. @@ -54,55 +54,55 @@ class MDNSResponder { public: MDNSResponder(); ~MDNSResponder(); - bool begin(const String& hostName); - bool begin(const char* hostName){ + bool begin(const String &hostName); + bool begin(const char *hostName) { return begin(String(hostName)); } void end(); void setInstanceName(String name); - void setInstanceName(const char * name){ + void setInstanceName(const char *name) { setInstanceName(String(name)); } - void setInstanceName(char * name){ + void setInstanceName(char *name) { setInstanceName(String(name)); } bool addService(char *service, char *proto, uint16_t port); - bool addService(const char *service, const char *proto, uint16_t port){ + bool addService(const char *service, const char *proto, uint16_t port) { return addService((char *)service, (char *)proto, port); } - bool addService(String service, String proto, uint16_t port){ + bool addService(String service, String proto, uint16_t port) { return addService(service.c_str(), proto.c_str(), port); } - - bool addServiceTxt(char *name, char *proto, char * key, char * value); - void addServiceTxt(const char *name, const char *proto, const char *key,const char * value){ + + bool addServiceTxt(char *name, char *proto, char *key, char *value); + void addServiceTxt(const char *name, const char *proto, const char *key, const char *value) { addServiceTxt((char *)name, (char *)proto, (char *)key, (char *)value); } - void addServiceTxt(String name, String proto, String key, String value){ + void addServiceTxt(String name, String proto, String key, String value) { addServiceTxt(name.c_str(), proto.c_str(), key.c_str(), value.c_str()); } - void enableArduino(uint16_t port=3232, bool auth=false); + void enableArduino(uint16_t port = 3232, bool auth = false); void disableArduino(); - void enableWorkstation(esp_interface_t interface=ESP_IF_WIFI_STA); + void enableWorkstation(esp_interface_t interface = ESP_IF_WIFI_STA); void disableWorkstation(); - IPAddress queryHost(char *host, uint32_t timeout=2000); - IPAddress queryHost(const char *host, uint32_t timeout=2000){ + IPAddress queryHost(char *host, uint32_t timeout = 2000); + IPAddress queryHost(const char *host, uint32_t timeout = 2000) { return queryHost((char *)host, timeout); } - IPAddress queryHost(String host, uint32_t timeout=2000){ + IPAddress queryHost(String host, uint32_t timeout = 2000) { return queryHost(host.c_str(), timeout); } - + int queryService(char *service, char *proto); - int queryService(const char *service, const char *proto){ + int queryService(const char *service, const char *proto) { return queryService((char *)service, (char *)proto); } - int queryService(String service, String proto){ + int queryService(String service, String proto) { return queryService(service.c_str(), proto.c_str()); } @@ -111,18 +111,18 @@ class MDNSResponder { IPAddress addressV6(int idx); uint16_t port(int idx); int numTxt(int idx); - bool hasTxt(int idx, const char * key); - String txt(int idx, const char * key); + bool hasTxt(int idx, const char *key); + String txt(int idx, const char *key); String txt(int idx, int txtIdx); String txtKey(int idx, int txtIdx); - + private: String _hostname; - mdns_result_t * results; - mdns_result_t * _getResult(int idx); - mdns_txt_item_t * _getResultTxt(int idx, int txtIdx); + mdns_result_t *results; + mdns_result_t *_getResult(int idx); + mdns_txt_item_t *_getResultTxt(int idx, int txtIdx); }; extern MDNSResponder MDNS; -#endif //ESP32MDNS_H +#endif //ESP32MDNS_H diff --git a/libraries/Ethernet/examples/ETH_LAN8720/ETH_LAN8720.ino b/libraries/Ethernet/examples/ETH_LAN8720/ETH_LAN8720.ino index 46c7c8bf686..de44b4e5e05 100644 --- a/libraries/Ethernet/examples/ETH_LAN8720/ETH_LAN8720.ino +++ b/libraries/Ethernet/examples/ETH_LAN8720/ETH_LAN8720.ino @@ -6,12 +6,12 @@ // Important to be defined BEFORE including ETH.h for ETH.begin() to work. // Example RMII LAN8720 (Olimex, etc.) #ifndef ETH_PHY_TYPE -#define ETH_PHY_TYPE ETH_PHY_LAN8720 -#define ETH_PHY_ADDR 0 -#define ETH_PHY_MDC 23 -#define ETH_PHY_MDIO 18 -#define ETH_PHY_POWER -1 -#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN +#define ETH_PHY_TYPE ETH_PHY_LAN8720 +#define ETH_PHY_ADDR 0 +#define ETH_PHY_MDC 23 +#define ETH_PHY_MDIO 18 +#define ETH_PHY_POWER -1 +#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN #endif #include @@ -19,8 +19,7 @@ static bool eth_connected = false; // WARNING: onEvent is called from a separate FreeRTOS task (thread)! -void onEvent(arduino_event_id_t event) -{ +void onEvent(arduino_event_id_t event) { switch (event) { case ARDUINO_EVENT_ETH_START: Serial.println("ETH Started"); @@ -53,8 +52,7 @@ void onEvent(arduino_event_id_t event) } } -void testClient(const char * host, uint16_t port) -{ +void testClient(const char* host, uint16_t port) { Serial.print("\nconnecting to "); Serial.println(host); @@ -64,7 +62,8 @@ void testClient(const char * host, uint16_t port) return; } client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host); - while (client.connected() && !client.available()); + while (client.connected() && !client.available()) + ; while (client.available()) { Serial.write(client.read()); } @@ -73,15 +72,13 @@ void testClient(const char * host, uint16_t port) client.stop(); } -void setup() -{ +void setup() { Serial.begin(115200); Network.onEvent(onEvent); ETH.begin(); } -void loop() -{ +void loop() { if (eth_connected) { testClient("google.com", 80); } diff --git a/libraries/Ethernet/examples/ETH_TLK110/ETH_TLK110.ino b/libraries/Ethernet/examples/ETH_TLK110/ETH_TLK110.ino index a1ab4a5745f..29c609dd13f 100644 --- a/libraries/Ethernet/examples/ETH_TLK110/ETH_TLK110.ino +++ b/libraries/Ethernet/examples/ETH_TLK110/ETH_TLK110.ino @@ -6,19 +6,18 @@ #include #ifndef ETH_PHY_TYPE -#define ETH_PHY_TYPE ETH_PHY_TLK110 -#define ETH_PHY_ADDR 31 -#define ETH_PHY_MDC 23 -#define ETH_PHY_MDIO 18 -#define ETH_PHY_POWER 17 -#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN +#define ETH_PHY_TYPE ETH_PHY_TLK110 +#define ETH_PHY_ADDR 31 +#define ETH_PHY_MDC 23 +#define ETH_PHY_MDIO 18 +#define ETH_PHY_POWER 17 +#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN #endif static bool eth_connected = false; // WARNING: onEvent is called from a separate FreeRTOS task (thread)! -void onEvent(arduino_event_id_t event) -{ +void onEvent(arduino_event_id_t event) { switch (event) { case ARDUINO_EVENT_ETH_START: Serial.println("ETH Started"); @@ -51,8 +50,7 @@ void onEvent(arduino_event_id_t event) } } -void testClient(const char * host, uint16_t port) -{ +void testClient(const char* host, uint16_t port) { Serial.print("\nconnecting to "); Serial.println(host); @@ -62,7 +60,8 @@ void testClient(const char * host, uint16_t port) return; } client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host); - while (client.connected() && !client.available()); + while (client.connected() && !client.available()) + ; while (client.available()) { Serial.write(client.read()); } @@ -71,16 +70,14 @@ void testClient(const char * host, uint16_t port) client.stop(); } -void setup() -{ +void setup() { Serial.begin(115200); Network.onEvent(onEvent); // Will call onEvent() from another thread. ETH.begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_POWER, ETH_CLK_MODE); } -void loop() -{ +void loop() { if (eth_connected) { testClient("google.com", 80); } diff --git a/libraries/Ethernet/examples/ETH_W5500_Arduino_SPI/ETH_W5500_Arduino_SPI.ino b/libraries/Ethernet/examples/ETH_W5500_Arduino_SPI/ETH_W5500_Arduino_SPI.ino index da403c9f86d..41166dce07d 100644 --- a/libraries/Ethernet/examples/ETH_W5500_Arduino_SPI/ETH_W5500_Arduino_SPI.ino +++ b/libraries/Ethernet/examples/ETH_W5500_Arduino_SPI/ETH_W5500_Arduino_SPI.ino @@ -10,34 +10,33 @@ #define USE_TWO_ETH_PORTS 0 #ifndef ETH_PHY_TYPE -#define ETH_PHY_TYPE ETH_PHY_W5500 -#define ETH_PHY_ADDR 1 -#define ETH_PHY_CS 15 -#define ETH_PHY_IRQ 4 -#define ETH_PHY_RST 5 +#define ETH_PHY_TYPE ETH_PHY_W5500 +#define ETH_PHY_ADDR 1 +#define ETH_PHY_CS 15 +#define ETH_PHY_IRQ 4 +#define ETH_PHY_RST 5 #endif // SPI pins -#define ETH_SPI_SCK 14 -#define ETH_SPI_MISO 12 -#define ETH_SPI_MOSI 13 +#define ETH_SPI_SCK 14 +#define ETH_SPI_MISO 12 +#define ETH_SPI_MOSI 13 #if USE_TWO_ETH_PORTS // Second port on shared SPI bus #ifndef ETH1_PHY_TYPE -#define ETH1_PHY_TYPE ETH_PHY_W5500 -#define ETH1_PHY_ADDR 1 -#define ETH1_PHY_CS 32 -#define ETH1_PHY_IRQ 33 -#define ETH1_PHY_RST 18 +#define ETH1_PHY_TYPE ETH_PHY_W5500 +#define ETH1_PHY_ADDR 1 +#define ETH1_PHY_CS 32 +#define ETH1_PHY_IRQ 33 +#define ETH1_PHY_RST 18 #endif ETHClass ETH1(1); #endif static bool eth_connected = false; -void onEvent(arduino_event_id_t event, arduino_event_info_t info) -{ +void onEvent(arduino_event_id_t event, arduino_event_info_t info) { switch (event) { case ARDUINO_EVENT_ETH_START: Serial.println("ETH Started"); @@ -72,8 +71,7 @@ void onEvent(arduino_event_id_t event, arduino_event_info_t info) } } -void testClient(const char * host, uint16_t port) -{ +void testClient(const char* host, uint16_t port) { Serial.print("\nconnecting to "); Serial.println(host); @@ -83,7 +81,8 @@ void testClient(const char * host, uint16_t port) return; } client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host); - while (client.connected() && !client.available()); + while (client.connected() && !client.available()) + ; while (client.available()) { Serial.write(client.read()); } @@ -92,8 +91,7 @@ void testClient(const char * host, uint16_t port) client.stop(); } -void setup() -{ +void setup() { Serial.begin(115200); Network.onEvent(onEvent); @@ -105,8 +103,7 @@ void setup() } -void loop() -{ +void loop() { if (eth_connected) { testClient("google.com", 80); } diff --git a/libraries/Ethernet/examples/ETH_W5500_IDF_SPI/ETH_W5500_IDF_SPI.ino b/libraries/Ethernet/examples/ETH_W5500_IDF_SPI/ETH_W5500_IDF_SPI.ino index 44b37233ef0..1797c1879ff 100644 --- a/libraries/Ethernet/examples/ETH_W5500_IDF_SPI/ETH_W5500_IDF_SPI.ino +++ b/libraries/Ethernet/examples/ETH_W5500_IDF_SPI/ETH_W5500_IDF_SPI.ino @@ -9,33 +9,32 @@ #define USE_TWO_ETH_PORTS 0 #ifndef ETH_PHY_TYPE -#define ETH_PHY_TYPE ETH_PHY_W5500 -#define ETH_PHY_ADDR 1 -#define ETH_PHY_CS 15 -#define ETH_PHY_IRQ 4 -#define ETH_PHY_RST 5 -#define ETH_PHY_SPI_HOST SPI2_HOST -#define ETH_PHY_SPI_SCK 14 -#define ETH_PHY_SPI_MISO 12 -#define ETH_PHY_SPI_MOSI 13 +#define ETH_PHY_TYPE ETH_PHY_W5500 +#define ETH_PHY_ADDR 1 +#define ETH_PHY_CS 15 +#define ETH_PHY_IRQ 4 +#define ETH_PHY_RST 5 +#define ETH_PHY_SPI_HOST SPI2_HOST +#define ETH_PHY_SPI_SCK 14 +#define ETH_PHY_SPI_MISO 12 +#define ETH_PHY_SPI_MOSI 13 #endif #if USE_TWO_ETH_PORTS // Second port on shared SPI bus #ifndef ETH1_PHY_TYPE -#define ETH1_PHY_TYPE ETH_PHY_W5500 -#define ETH1_PHY_ADDR 1 -#define ETH1_PHY_CS 32 -#define ETH1_PHY_IRQ 33 -#define ETH1_PHY_RST 18 +#define ETH1_PHY_TYPE ETH_PHY_W5500 +#define ETH1_PHY_ADDR 1 +#define ETH1_PHY_CS 32 +#define ETH1_PHY_IRQ 33 +#define ETH1_PHY_RST 18 #endif ETHClass ETH1(1); #endif static bool eth_connected = false; -void onEvent(arduino_event_id_t event, arduino_event_info_t info) -{ +void onEvent(arduino_event_id_t event, arduino_event_info_t info) { switch (event) { case ARDUINO_EVENT_ETH_START: Serial.println("ETH Started"); @@ -70,8 +69,7 @@ void onEvent(arduino_event_id_t event, arduino_event_info_t info) } } -void testClient(const char * host, uint16_t port) -{ +void testClient(const char* host, uint16_t port) { Serial.print("\nconnecting to "); Serial.println(host); @@ -81,7 +79,8 @@ void testClient(const char * host, uint16_t port) return; } client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host); - while (client.connected() && !client.available()); + while (client.connected() && !client.available()) + ; while (client.available()) { Serial.write(client.read()); } @@ -90,8 +89,7 @@ void testClient(const char * host, uint16_t port) client.stop(); } -void setup() -{ +void setup() { Serial.begin(115200); Network.onEvent(onEvent); ETH.begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_CS, ETH_PHY_IRQ, ETH_PHY_RST, ETH_PHY_SPI_HOST, ETH_PHY_SPI_SCK, ETH_PHY_SPI_MISO, ETH_PHY_SPI_MOSI); @@ -102,8 +100,7 @@ void setup() } -void loop() -{ +void loop() { if (eth_connected) { testClient("google.com", 80); } diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index 067ce7f3802..16db74d29ef 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -42,821 +42,808 @@ #include "esp_netif_defaults.h" #include "esp_eth_phy.h" -static ETHClass * _ethernets[3] = { NULL, NULL, NULL }; +static ETHClass *_ethernets[3] = { NULL, NULL, NULL }; static esp_event_handler_instance_t _eth_ev_instance = NULL; -static void _eth_event_cb(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { +static void _eth_event_cb(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { - if (event_base == ETH_EVENT){ - esp_eth_handle_t eth_handle = *((esp_eth_handle_t*)event_data); - for(int i = 0; i < 3; ++i){ - if(_ethernets[i] != NULL && _ethernets[i]->handle() == eth_handle){ - _ethernets[i]->_onEthEvent(event_id, event_data); - } - } + if (event_base == ETH_EVENT) { + esp_eth_handle_t eth_handle = *((esp_eth_handle_t *)event_data); + for (int i = 0; i < 3; ++i) { + if (_ethernets[i] != NULL && _ethernets[i]->handle() == eth_handle) { + _ethernets[i]->_onEthEvent(event_id, event_data); + } } + } } // This callback needs to be aware of which interface it should match against -static void onEthConnected(arduino_event_id_t event, arduino_event_info_t info) -{ - if(event == ARDUINO_EVENT_ETH_CONNECTED){ - uint8_t index = 3; - for (int i = 0; i < 3; ++i) { - if(_ethernets[i] != NULL && _ethernets[i]->handle() == info.eth_connected){ - index = i; - break; - } - } - if(index == 3){ - log_e("Could not find ETH interface with that handle!"); - return; - } - if (_ethernets[index]->getStatusBits() & ESP_NETIF_WANT_IP6_BIT){ - esp_err_t err = esp_netif_create_ip6_linklocal(_ethernets[index]->netif()); - if(err != ESP_OK){ - log_e("Failed to enable IPv6 Link Local on ETH: [%d] %s", err, esp_err_to_name(err)); - } else { - log_v("Enabled IPv6 Link Local on %s", _ethernets[index]->desc()); - } - } - } +static void onEthConnected(arduino_event_id_t event, arduino_event_info_t info) { + if (event == ARDUINO_EVENT_ETH_CONNECTED) { + uint8_t index = 3; + for (int i = 0; i < 3; ++i) { + if (_ethernets[i] != NULL && _ethernets[i]->handle() == info.eth_connected) { + index = i; + break; + } + } + if (index == 3) { + log_e("Could not find ETH interface with that handle!"); + return; + } + if (_ethernets[index]->getStatusBits() & ESP_NETIF_WANT_IP6_BIT) { + esp_err_t err = esp_netif_create_ip6_linklocal(_ethernets[index]->netif()); + if (err != ESP_OK) { + log_e("Failed to enable IPv6 Link Local on ETH: [%d] %s", err, esp_err_to_name(err)); + } else { + log_v("Enabled IPv6 Link Local on %s", _ethernets[index]->desc()); + } + } + } } esp_eth_handle_t ETHClass::handle() const { - return _eth_handle; + return _eth_handle; } -void ETHClass::_onEthEvent(int32_t event_id, void* event_data){ - arduino_event_t arduino_event; - arduino_event.event_id = ARDUINO_EVENT_MAX; - - if (event_id == ETHERNET_EVENT_CONNECTED) { - log_v("%s Connected", desc()); - arduino_event.event_id = ARDUINO_EVENT_ETH_CONNECTED; - arduino_event.event_info.eth_connected = handle(); - setStatusBits(ESP_NETIF_CONNECTED_BIT); - } else if (event_id == ETHERNET_EVENT_DISCONNECTED) { - log_v("%s Disconnected", desc()); - arduino_event.event_id = ARDUINO_EVENT_ETH_DISCONNECTED; - clearStatusBits(ESP_NETIF_CONNECTED_BIT | ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_LOCAL_IP6_BIT | ESP_NETIF_HAS_GLOBAL_IP6_BIT); - } else if (event_id == ETHERNET_EVENT_START) { - log_v("%s Started", desc()); - arduino_event.event_id = ARDUINO_EVENT_ETH_START; - setStatusBits(ESP_NETIF_STARTED_BIT); - } else if (event_id == ETHERNET_EVENT_STOP) { - log_v("%s Stopped", desc()); - arduino_event.event_id = ARDUINO_EVENT_ETH_STOP; - clearStatusBits(ESP_NETIF_STARTED_BIT | ESP_NETIF_CONNECTED_BIT | ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_LOCAL_IP6_BIT | ESP_NETIF_HAS_GLOBAL_IP6_BIT | ESP_NETIF_HAS_STATIC_IP_BIT); - } - - if(arduino_event.event_id < ARDUINO_EVENT_MAX){ - Network.postEvent(&arduino_event); - } +void ETHClass::_onEthEvent(int32_t event_id, void *event_data) { + arduino_event_t arduino_event; + arduino_event.event_id = ARDUINO_EVENT_MAX; + + if (event_id == ETHERNET_EVENT_CONNECTED) { + log_v("%s Connected", desc()); + arduino_event.event_id = ARDUINO_EVENT_ETH_CONNECTED; + arduino_event.event_info.eth_connected = handle(); + setStatusBits(ESP_NETIF_CONNECTED_BIT); + } else if (event_id == ETHERNET_EVENT_DISCONNECTED) { + log_v("%s Disconnected", desc()); + arduino_event.event_id = ARDUINO_EVENT_ETH_DISCONNECTED; + clearStatusBits(ESP_NETIF_CONNECTED_BIT | ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_LOCAL_IP6_BIT | ESP_NETIF_HAS_GLOBAL_IP6_BIT); + } else if (event_id == ETHERNET_EVENT_START) { + log_v("%s Started", desc()); + arduino_event.event_id = ARDUINO_EVENT_ETH_START; + setStatusBits(ESP_NETIF_STARTED_BIT); + } else if (event_id == ETHERNET_EVENT_STOP) { + log_v("%s Stopped", desc()); + arduino_event.event_id = ARDUINO_EVENT_ETH_STOP; + clearStatusBits(ESP_NETIF_STARTED_BIT | ESP_NETIF_CONNECTED_BIT | ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_LOCAL_IP6_BIT | ESP_NETIF_HAS_GLOBAL_IP6_BIT | ESP_NETIF_HAS_STATIC_IP_BIT); + } + + if (arduino_event.event_id < ARDUINO_EVENT_MAX) { + Network.postEvent(&arduino_event); + } } ETHClass::ETHClass(uint8_t eth_index) - :_eth_handle(NULL) - ,_eth_index(eth_index) - ,_phy_type(ETH_PHY_MAX) + : _eth_handle(NULL), _eth_index(eth_index), _phy_type(ETH_PHY_MAX) #if ETH_SPI_SUPPORTS_CUSTOM - ,_spi(NULL) + , + _spi(NULL) #endif - ,_spi_freq_mhz(20) - ,_pin_cs(-1) - ,_pin_irq(-1) - ,_pin_rst(-1) - ,_pin_sck(-1) - ,_pin_miso(-1) - ,_pin_mosi(-1) + , + _spi_freq_mhz(20), _pin_cs(-1), _pin_irq(-1), _pin_rst(-1), _pin_sck(-1), _pin_miso(-1), _pin_mosi(-1) #if CONFIG_ETH_USE_ESP32_EMAC - ,_pin_mcd(-1) - ,_pin_mdio(-1) - ,_pin_power(-1) - ,_pin_rmii_clock(-1) + , + _pin_mcd(-1), _pin_mdio(-1), _pin_power(-1), _pin_rmii_clock(-1) #endif /* CONFIG_ETH_USE_ESP32_EMAC */ -{} +{ +} -ETHClass::~ETHClass() -{} +ETHClass::~ETHClass() {} -bool ETHClass::ethDetachBus(void * bus_pointer){ - ETHClass *bus = (ETHClass *) bus_pointer; - bus->end(); - return true; +bool ETHClass::ethDetachBus(void *bus_pointer) { + ETHClass *bus = (ETHClass *)bus_pointer; + bus->end(); + return true; } #if CONFIG_ETH_USE_ESP32_EMAC -bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, int power, eth_clock_mode_t clock_mode) -{ - esp_err_t ret = ESP_OK; - if(_eth_index > 2){ - return false; - } - if(_esp_netif != NULL){ - return true; - } - if(phy_addr < ETH_PHY_ADDR_AUTO){ - log_e("Invalid PHY address: %d, set to ETH_PHY_ADDR_AUTO for auto detection", phy_addr); - return false; - } - perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_RMII, ETHClass::ethDetachBus); - perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_CLK, ETHClass::ethDetachBus); - perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_MCD, ETHClass::ethDetachBus); - perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_MDIO, ETHClass::ethDetachBus); - if(power != -1){ - perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_PWR, ETHClass::ethDetachBus); - } - - Network.begin(); - _ethernets[_eth_index] = this; - if(_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)){ - log_e("event_handler_instance_register for ETH_EVENT Failed!"); - return false; - } - - eth_esp32_emac_config_t mac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); - mac_config.clock_config.rmii.clock_mode = (clock_mode) ? EMAC_CLK_OUT : EMAC_CLK_EXT_IN; - mac_config.clock_config.rmii.clock_gpio = (1 == clock_mode) ? EMAC_APPL_CLK_OUT_GPIO : (2 == clock_mode) ? EMAC_CLK_OUT_GPIO : (3 == clock_mode) ? EMAC_CLK_OUT_180_GPIO : EMAC_CLK_IN_GPIO; - mac_config.smi_mdc_gpio_num = digitalPinToGPIONumber(mdc); - mac_config.smi_mdio_gpio_num = digitalPinToGPIONumber(mdio); - - _pin_mcd = digitalPinToGPIONumber(mdc); - _pin_mdio = digitalPinToGPIONumber(mdio); - _pin_rmii_clock = mac_config.clock_config.rmii.clock_gpio; - _pin_power = digitalPinToGPIONumber(power); - - if(!perimanClearPinBus(_pin_rmii_clock)){ return false; } - if(!perimanClearPinBus(_pin_mcd)){ return false; } - if(!perimanClearPinBus(_pin_mdio)){ return false; } - if(!perimanClearPinBus(ETH_RMII_TX_EN)){ return false; } - if(!perimanClearPinBus(ETH_RMII_TX0)){ return false; } - if(!perimanClearPinBus(ETH_RMII_TX1)){ return false; } - if(!perimanClearPinBus(ETH_RMII_RX0)){ return false; } - if(!perimanClearPinBus(ETH_RMII_RX1_EN)){ return false; } - if(!perimanClearPinBus(ETH_RMII_CRS_DV)){ return false; } - if(_pin_power != -1){ - if(!perimanClearPinBus(_pin_power)){ return false; } - } - - eth_mac_config_t eth_mac_config = ETH_MAC_DEFAULT_CONFIG(); - eth_mac_config.sw_reset_timeout_ms = 1000; - - esp_eth_mac_t * mac = esp_eth_mac_new_esp32(&mac_config, ð_mac_config); - if(mac == NULL){ - log_e("esp_eth_mac_new_esp32 failed"); - return false; - } - - eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); - phy_config.phy_addr = phy_addr; - phy_config.reset_gpio_num = _pin_power; - - esp_eth_phy_t *phy = NULL; - switch(type){ - case ETH_PHY_LAN8720: - phy = esp_eth_phy_new_lan87xx(&phy_config); - break; - case ETH_PHY_TLK110: - phy = esp_eth_phy_new_ip101(&phy_config); - break; - case ETH_PHY_RTL8201: - phy = esp_eth_phy_new_rtl8201(&phy_config); - break; - case ETH_PHY_DP83848: - phy = esp_eth_phy_new_dp83848(&phy_config); - break; - case ETH_PHY_KSZ8041: - phy = esp_eth_phy_new_ksz80xx(&phy_config); - break; - case ETH_PHY_KSZ8081: - phy = esp_eth_phy_new_ksz80xx(&phy_config); - break; - default: - log_e("Unsupported PHY %d", type); - break; - } - if(phy == NULL){ - log_e("esp_eth_phy_new failed"); - return false; - } - - _eth_handle = NULL; - esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy); - ret = esp_eth_driver_install(ð_config, &_eth_handle); - if(ret != ESP_OK){ - log_e("Ethernet driver install failed: %d", ret); - return false; - } - if(_eth_handle == NULL){ - log_e("esp_eth_driver_install failed! eth_handle is NULL"); - return false; - } - - esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH(); - - // Use ESP_NETIF_INHERENT_DEFAULT_ETH when multiple Ethernet interfaces are used and so you need to modify - // esp-netif configuration parameters for each interface (name, priority, etc.). - char if_key_str[10]; - char if_desc_str[10]; - char num_str[3]; - itoa(_eth_index, num_str, 10); - if(_eth_index == 0){ - strcpy(if_key_str, "ETH_DEF"); - } else { - strcat(strcpy(if_key_str, "ETH_"), num_str); - } - strcat(strcpy(if_desc_str, "eth"), num_str); - - esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH(); - esp_netif_config.if_key = if_key_str; - esp_netif_config.if_desc = if_desc_str; - esp_netif_config.route_prio -= _eth_index*5; - - cfg.base = &esp_netif_config; +bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, int power, eth_clock_mode_t clock_mode) { + esp_err_t ret = ESP_OK; + if (_eth_index > 2) { + return false; + } + if (_esp_netif != NULL) { + return true; + } + if (phy_addr < ETH_PHY_ADDR_AUTO) { + log_e("Invalid PHY address: %d, set to ETH_PHY_ADDR_AUTO for auto detection", phy_addr); + return false; + } + perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_RMII, ETHClass::ethDetachBus); + perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_CLK, ETHClass::ethDetachBus); + perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_MCD, ETHClass::ethDetachBus); + perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_MDIO, ETHClass::ethDetachBus); + if (power != -1) { + perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_PWR, ETHClass::ethDetachBus); + } + + Network.begin(); + _ethernets[_eth_index] = this; + if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) { + log_e("event_handler_instance_register for ETH_EVENT Failed!"); + return false; + } + + eth_esp32_emac_config_t mac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + mac_config.clock_config.rmii.clock_mode = (clock_mode) ? EMAC_CLK_OUT : EMAC_CLK_EXT_IN; + mac_config.clock_config.rmii.clock_gpio = (1 == clock_mode) ? EMAC_APPL_CLK_OUT_GPIO : (2 == clock_mode) ? EMAC_CLK_OUT_GPIO + : (3 == clock_mode) ? EMAC_CLK_OUT_180_GPIO + : EMAC_CLK_IN_GPIO; + mac_config.smi_mdc_gpio_num = digitalPinToGPIONumber(mdc); + mac_config.smi_mdio_gpio_num = digitalPinToGPIONumber(mdio); + + _pin_mcd = digitalPinToGPIONumber(mdc); + _pin_mdio = digitalPinToGPIONumber(mdio); + _pin_rmii_clock = mac_config.clock_config.rmii.clock_gpio; + _pin_power = digitalPinToGPIONumber(power); + + if (!perimanClearPinBus(_pin_rmii_clock)) { return false; } + if (!perimanClearPinBus(_pin_mcd)) { return false; } + if (!perimanClearPinBus(_pin_mdio)) { return false; } + if (!perimanClearPinBus(ETH_RMII_TX_EN)) { return false; } + if (!perimanClearPinBus(ETH_RMII_TX0)) { return false; } + if (!perimanClearPinBus(ETH_RMII_TX1)) { return false; } + if (!perimanClearPinBus(ETH_RMII_RX0)) { return false; } + if (!perimanClearPinBus(ETH_RMII_RX1_EN)) { return false; } + if (!perimanClearPinBus(ETH_RMII_CRS_DV)) { return false; } + if (_pin_power != -1) { + if (!perimanClearPinBus(_pin_power)) { return false; } + } + + eth_mac_config_t eth_mac_config = ETH_MAC_DEFAULT_CONFIG(); + eth_mac_config.sw_reset_timeout_ms = 1000; + + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config, ð_mac_config); + if (mac == NULL) { + log_e("esp_eth_mac_new_esp32 failed"); + return false; + } + + eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); + phy_config.phy_addr = phy_addr; + phy_config.reset_gpio_num = _pin_power; + + esp_eth_phy_t *phy = NULL; + switch (type) { + case ETH_PHY_LAN8720: + phy = esp_eth_phy_new_lan87xx(&phy_config); + break; + case ETH_PHY_TLK110: + phy = esp_eth_phy_new_ip101(&phy_config); + break; + case ETH_PHY_RTL8201: + phy = esp_eth_phy_new_rtl8201(&phy_config); + break; + case ETH_PHY_DP83848: + phy = esp_eth_phy_new_dp83848(&phy_config); + break; + case ETH_PHY_KSZ8041: + phy = esp_eth_phy_new_ksz80xx(&phy_config); + break; + case ETH_PHY_KSZ8081: + phy = esp_eth_phy_new_ksz80xx(&phy_config); + break; + default: + log_e("Unsupported PHY %d", type); + break; + } + if (phy == NULL) { + log_e("esp_eth_phy_new failed"); + return false; + } - _esp_netif = esp_netif_new(&cfg); + _eth_handle = NULL; + esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy); + ret = esp_eth_driver_install(ð_config, &_eth_handle); + if (ret != ESP_OK) { + log_e("Ethernet driver install failed: %d", ret); + return false; + } + if (_eth_handle == NULL) { + log_e("esp_eth_driver_install failed! eth_handle is NULL"); + return false; + } + + esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH(); + + // Use ESP_NETIF_INHERENT_DEFAULT_ETH when multiple Ethernet interfaces are used and so you need to modify + // esp-netif configuration parameters for each interface (name, priority, etc.). + char if_key_str[10]; + char if_desc_str[10]; + char num_str[3]; + itoa(_eth_index, num_str, 10); + if (_eth_index == 0) { + strcpy(if_key_str, "ETH_DEF"); + } else { + strcat(strcpy(if_key_str, "ETH_"), num_str); + } + strcat(strcpy(if_desc_str, "eth"), num_str); + + esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH(); + esp_netif_config.if_key = if_key_str; + esp_netif_config.if_desc = if_desc_str; + esp_netif_config.route_prio -= _eth_index * 5; + + cfg.base = &esp_netif_config; + + _esp_netif = esp_netif_new(&cfg); + + /* attach Ethernet driver to TCP/IP stack */ + ret = esp_netif_attach(_esp_netif, esp_eth_new_netif_glue(_eth_handle)); + if (ret != ESP_OK) { + log_e("esp_netif_attach failed: %d", ret); + return false; + } - /* attach Ethernet driver to TCP/IP stack */ - ret = esp_netif_attach(_esp_netif, esp_eth_new_netif_glue(_eth_handle)); - if(ret != ESP_OK){ - log_e("esp_netif_attach failed: %d", ret); - return false; - } + /* attach to receive events */ + initNetif((Network_Interface_ID)(ESP_NETIF_ID_ETH + _eth_index)); - /* attach to receive events */ - initNetif((Network_Interface_ID)(ESP_NETIF_ID_ETH+_eth_index)); + Network.onSysEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED); - Network.onSysEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED); - - ret = esp_eth_start(_eth_handle); - if(ret != ESP_OK){ - log_e("esp_eth_start failed: %d", ret); - return false; - } + ret = esp_eth_start(_eth_handle); + if (ret != ESP_OK) { + log_e("esp_eth_start failed: %d", ret); + return false; + } - if(!perimanSetPinBus(_pin_rmii_clock, ESP32_BUS_TYPE_ETHERNET_CLK, (void *)(this), -1, -1)){ goto err; } - if(!perimanSetPinBus(_pin_mcd, ESP32_BUS_TYPE_ETHERNET_MCD, (void *)(this), -1, -1)){ goto err; } - if(!perimanSetPinBus(_pin_mdio, ESP32_BUS_TYPE_ETHERNET_MDIO, (void *)(this), -1, -1)){ goto err; } + if (!perimanSetPinBus(_pin_rmii_clock, ESP32_BUS_TYPE_ETHERNET_CLK, (void *)(this), -1, -1)) { goto err; } + if (!perimanSetPinBus(_pin_mcd, ESP32_BUS_TYPE_ETHERNET_MCD, (void *)(this), -1, -1)) { goto err; } + if (!perimanSetPinBus(_pin_mdio, ESP32_BUS_TYPE_ETHERNET_MDIO, (void *)(this), -1, -1)) { goto err; } - if(!perimanSetPinBus(ETH_RMII_TX_EN, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)){ goto err; } - if(!perimanSetPinBus(ETH_RMII_TX0, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)){ goto err; } - if(!perimanSetPinBus(ETH_RMII_TX1, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)){ goto err; } - if(!perimanSetPinBus(ETH_RMII_RX0, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)){ goto err; } - if(!perimanSetPinBus(ETH_RMII_RX1_EN, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)){ goto err; } - if(!perimanSetPinBus(ETH_RMII_CRS_DV, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)){ goto err; } + if (!perimanSetPinBus(ETH_RMII_TX_EN, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)) { goto err; } + if (!perimanSetPinBus(ETH_RMII_TX0, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)) { goto err; } + if (!perimanSetPinBus(ETH_RMII_TX1, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)) { goto err; } + if (!perimanSetPinBus(ETH_RMII_RX0, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)) { goto err; } + if (!perimanSetPinBus(ETH_RMII_RX1_EN, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)) { goto err; } + if (!perimanSetPinBus(ETH_RMII_CRS_DV, ESP32_BUS_TYPE_ETHERNET_RMII, (void *)(this), -1, -1)) { goto err; } - if(_pin_power != -1){ - if(!perimanSetPinBus(_pin_power, ESP32_BUS_TYPE_ETHERNET_PWR, (void *)(this), -1, -1)){ goto err; } - } + if (_pin_power != -1) { + if (!perimanSetPinBus(_pin_power, ESP32_BUS_TYPE_ETHERNET_PWR, (void *)(this), -1, -1)) { goto err; } + } - // holds a few milliseconds to let DHCP start and enter into a good state - // FIX ME -- adresses issue https://github.com/espressif/arduino-esp32/issues/5733 - delay(50); + // holds a few milliseconds to let DHCP start and enter into a good state + // FIX ME -- addresses issue https://github.com/espressif/arduino-esp32/issues/5733 + delay(50); - return true; + return true; err: - log_e("Failed to set all pins bus to ETHERNET"); - ETHClass::ethDetachBus((void *)(this)); - return false; + log_e("Failed to set all pins bus to ETHERNET"); + ETHClass::ethDetachBus((void *)(this)); + return false; } #endif /* CONFIG_ETH_USE_ESP32_EMAC */ #if ETH_SPI_SUPPORTS_CUSTOM -static void *_eth_spi_init(const void *ctx){ - return (void*)ctx; +static void *_eth_spi_init(const void *ctx) { + return (void *)ctx; } -static esp_err_t _eth_spi_deinit(void *ctx){ - return ESP_OK; +static esp_err_t _eth_spi_deinit(void *ctx) { + return ESP_OK; } -esp_err_t ETHClass::_eth_spi_read(void *ctx, uint32_t cmd, uint32_t addr, void *data, uint32_t data_len){ - return ((ETHClass*)ctx)->eth_spi_read(cmd, addr, data, data_len); +esp_err_t ETHClass::_eth_spi_read(void *ctx, uint32_t cmd, uint32_t addr, void *data, uint32_t data_len) { + return ((ETHClass *)ctx)->eth_spi_read(cmd, addr, data, data_len); } -esp_err_t ETHClass::_eth_spi_write(void *ctx, uint32_t cmd, uint32_t addr, const void *data, uint32_t data_len){ - return ((ETHClass*)ctx)->eth_spi_write(cmd, addr, data, data_len); +esp_err_t ETHClass::_eth_spi_write(void *ctx, uint32_t cmd, uint32_t addr, const void *data, uint32_t data_len) { + return ((ETHClass *)ctx)->eth_spi_write(cmd, addr, data, data_len); } -esp_err_t ETHClass::eth_spi_read(uint32_t cmd, uint32_t addr, void *data, uint32_t data_len){ - if(_spi == NULL){ - return ESP_FAIL; - } - // log_i(" 0x%04lx 0x%04lx %lu", cmd, addr, data_len); - _spi->beginTransaction(SPISettings(_spi_freq_mhz * 1000 * 1000, MSBFIRST, SPI_MODE0)); - digitalWrite(_pin_cs, LOW); +esp_err_t ETHClass::eth_spi_read(uint32_t cmd, uint32_t addr, void *data, uint32_t data_len) { + if (_spi == NULL) { + return ESP_FAIL; + } + // log_i(" 0x%04lx 0x%04lx %lu", cmd, addr, data_len); + _spi->beginTransaction(SPISettings(_spi_freq_mhz * 1000 * 1000, MSBFIRST, SPI_MODE0)); + digitalWrite(_pin_cs, LOW); #if CONFIG_ETH_SPI_ETHERNET_DM9051 - if(_phy_type == ETH_PHY_DM9051){ - _spi->write(((cmd & 0x01) << 7) | (addr & 0x7F)); - } else + if (_phy_type == ETH_PHY_DM9051) { + _spi->write(((cmd & 0x01) << 7) | (addr & 0x7F)); + } else #endif #if CONFIG_ETH_SPI_ETHERNET_W5500 - if(_phy_type == ETH_PHY_W5500){ - _spi->write16(cmd); - _spi->write(addr); - } else + if (_phy_type == ETH_PHY_W5500) { + _spi->write16(cmd); + _spi->write(addr); + } else #endif #if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL - if(_phy_type == ETH_PHY_KSZ8851){ - if(cmd > 1){ - _spi->write(cmd << 6 | addr); - } else { - _spi->write16(cmd << 14 | addr); - } - } else -#endif - { - log_e("Unsupported PHY module: %d", _phy_type); - digitalWrite(_pin_cs, HIGH); - _spi->endTransaction(); - return ESP_FAIL; + if (_phy_type == ETH_PHY_KSZ8851) { + if (cmd > 1) { + _spi->write(cmd << 6 | addr); + } else { + _spi->write16(cmd << 14 | addr); } - _spi->transferBytes(NULL, (uint8_t *)data, data_len); - + } else +#endif + { + log_e("Unsupported PHY module: %d", _phy_type); digitalWrite(_pin_cs, HIGH); _spi->endTransaction(); - return ESP_OK; + return ESP_FAIL; + } + _spi->transferBytes(NULL, (uint8_t *)data, data_len); + + digitalWrite(_pin_cs, HIGH); + _spi->endTransaction(); + return ESP_OK; } -esp_err_t ETHClass::eth_spi_write(uint32_t cmd, uint32_t addr, const void *data, uint32_t data_len){ - if(_spi == NULL){ - return ESP_FAIL; - } - // log_i("0x%04lx 0x%04lx %lu", cmd, addr, data_len); - _spi->beginTransaction(SPISettings(_spi_freq_mhz * 1000 * 1000, MSBFIRST, SPI_MODE0)); - digitalWrite(_pin_cs, LOW); +esp_err_t ETHClass::eth_spi_write(uint32_t cmd, uint32_t addr, const void *data, uint32_t data_len) { + if (_spi == NULL) { + return ESP_FAIL; + } + // log_i("0x%04lx 0x%04lx %lu", cmd, addr, data_len); + _spi->beginTransaction(SPISettings(_spi_freq_mhz * 1000 * 1000, MSBFIRST, SPI_MODE0)); + digitalWrite(_pin_cs, LOW); #if CONFIG_ETH_SPI_ETHERNET_DM9051 - if(_phy_type == ETH_PHY_DM9051){ - _spi->write(((cmd & 0x01) << 7) | (addr & 0x7F)); - } else + if (_phy_type == ETH_PHY_DM9051) { + _spi->write(((cmd & 0x01) << 7) | (addr & 0x7F)); + } else #endif #if CONFIG_ETH_SPI_ETHERNET_W5500 - if(_phy_type == ETH_PHY_W5500){ - _spi->write16(cmd); - _spi->write(addr); - } else + if (_phy_type == ETH_PHY_W5500) { + _spi->write16(cmd); + _spi->write(addr); + } else #endif #if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL - if(_phy_type == ETH_PHY_KSZ8851){ - if(cmd > 1){ - _spi->write(cmd << 6 | addr); - } else { - _spi->write16(cmd << 14 | addr); - } - } else -#endif - { - log_e("Unsupported PHY module: %d", _phy_type); - digitalWrite(_pin_cs, HIGH); - _spi->endTransaction(); - return ESP_FAIL; + if (_phy_type == ETH_PHY_KSZ8851) { + if (cmd > 1) { + _spi->write(cmd << 6 | addr); + } else { + _spi->write16(cmd << 14 | addr); } - _spi->writeBytes((const uint8_t *)data, data_len); - + } else +#endif + { + log_e("Unsupported PHY module: %d", _phy_type); digitalWrite(_pin_cs, HIGH); _spi->endTransaction(); - return ESP_OK; + return ESP_FAIL; + } + _spi->writeBytes((const uint8_t *)data, data_len); + + digitalWrite(_pin_cs, HIGH); + _spi->endTransaction(); + return ESP_OK; } #endif -bool ETHClass::beginSPI(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst, +bool ETHClass::beginSPI(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst, #if ETH_SPI_SUPPORTS_CUSTOM - SPIClass *spi, + SPIClass *spi, #endif - int sck, int miso, int mosi, spi_host_device_t spi_host, uint8_t spi_freq_mhz){ - esp_err_t ret = ESP_OK; + int sck, int miso, int mosi, spi_host_device_t spi_host, uint8_t spi_freq_mhz) { + esp_err_t ret = ESP_OK; - if(_esp_netif != NULL || _eth_handle != NULL){ - log_w("ETH Already Started"); - return true; - } + if (_esp_netif != NULL || _eth_handle != NULL) { + log_w("ETH Already Started"); + return true; + } #if ETH_SPI_SUPPORTS_NO_IRQ - if(cs < 0){ - log_e("CS pin must be defined!"); + if (cs < 0) { + log_e("CS pin must be defined!"); #else - if(cs < 0 || irq < 0){ - log_e("CS and IRQ pins must be defined!"); + if (cs < 0 || irq < 0) { + log_e("CS and IRQ pins must be defined!"); #endif - return false; - } - if(phy_addr < ETH_PHY_ADDR_AUTO){ - log_e("Invalid PHY address: %d, set to ETH_PHY_ADDR_AUTO for auto detection", phy_addr); - return false; - } - - perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_SPI, ETHClass::ethDetachBus); - - if(_pin_cs != -1){ - if(!perimanClearPinBus(_pin_cs)){ return false; } - } - if(_pin_rst != -1){ - if(!perimanClearPinBus(_pin_rst)){ return false; } - } - if(_pin_irq != -1){ - if(!perimanClearPinBus(_pin_irq)){ return false; } - } - if(_pin_sck != -1){ - if(!perimanClearPinBus(_pin_sck)){ return false; } - } - if(_pin_miso != -1){ - if(!perimanClearPinBus(_pin_miso)){ return false; } - } - if(_pin_mosi != -1){ - if(!perimanClearPinBus(_pin_mosi)){ return false; } - } + return false; + } + if (phy_addr < ETH_PHY_ADDR_AUTO) { + log_e("Invalid PHY address: %d, set to ETH_PHY_ADDR_AUTO for auto detection", phy_addr); + return false; + } + + perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET_SPI, ETHClass::ethDetachBus); + + if (_pin_cs != -1) { + if (!perimanClearPinBus(_pin_cs)) { return false; } + } + if (_pin_rst != -1) { + if (!perimanClearPinBus(_pin_rst)) { return false; } + } + if (_pin_irq != -1) { + if (!perimanClearPinBus(_pin_irq)) { return false; } + } + if (_pin_sck != -1) { + if (!perimanClearPinBus(_pin_sck)) { return false; } + } + if (_pin_miso != -1) { + if (!perimanClearPinBus(_pin_miso)) { return false; } + } + if (_pin_mosi != -1) { + if (!perimanClearPinBus(_pin_mosi)) { return false; } + } #if ETH_SPI_SUPPORTS_CUSTOM - _spi = spi; + _spi = spi; #endif - if(spi_freq_mhz){ - _spi_freq_mhz = spi_freq_mhz; - } - _phy_type = type; - _pin_cs = digitalPinToGPIONumber(cs); - _pin_irq = digitalPinToGPIONumber(irq); - _pin_rst = digitalPinToGPIONumber(rst); - _pin_sck = digitalPinToGPIONumber(sck); - _pin_miso = digitalPinToGPIONumber(miso); - _pin_mosi = digitalPinToGPIONumber(mosi); + if (spi_freq_mhz) { + _spi_freq_mhz = spi_freq_mhz; + } + _phy_type = type; + _pin_cs = digitalPinToGPIONumber(cs); + _pin_irq = digitalPinToGPIONumber(irq); + _pin_rst = digitalPinToGPIONumber(rst); + _pin_sck = digitalPinToGPIONumber(sck); + _pin_miso = digitalPinToGPIONumber(miso); + _pin_mosi = digitalPinToGPIONumber(mosi); #if ETH_SPI_SUPPORTS_CUSTOM - if(_spi != NULL){ - pinMode(_pin_cs, OUTPUT); - digitalWrite(_pin_cs, HIGH); - perimanSetPinBusExtraType(_pin_cs, "ETH_CS"); - } + if (_spi != NULL) { + pinMode(_pin_cs, OUTPUT); + digitalWrite(_pin_cs, HIGH); + perimanSetPinBusExtraType(_pin_cs, "ETH_CS"); + } #endif - // Init SPI bus - if(_pin_sck >= 0 && _pin_miso >= 0 && _pin_mosi >= 0){ - spi_bus_config_t buscfg; - memset(&buscfg, 0, sizeof(spi_bus_config_t)); - buscfg.mosi_io_num = _pin_mosi; - buscfg.miso_io_num = _pin_miso; - buscfg.sclk_io_num = _pin_sck; - buscfg.quadwp_io_num = -1; - buscfg.quadhd_io_num = -1; - buscfg.data4_io_num = -1; - buscfg.data5_io_num = -1; - buscfg.data6_io_num = -1; - buscfg.data7_io_num = -1; - buscfg.max_transfer_sz = -1; - ret = spi_bus_initialize(spi_host, &buscfg, SPI_DMA_CH_AUTO); - if(ret != ESP_OK){ - log_e("SPI bus initialize failed: %d", ret); - return false; - } - } - - Network.begin(); - _ethernets[_eth_index] = this; - if(_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)){ - log_e("event_handler_instance_register for ETH_EVENT Failed!"); - return false; - } - + // Init SPI bus + if (_pin_sck >= 0 && _pin_miso >= 0 && _pin_mosi >= 0) { + spi_bus_config_t buscfg; + memset(&buscfg, 0, sizeof(spi_bus_config_t)); + buscfg.mosi_io_num = _pin_mosi; + buscfg.miso_io_num = _pin_miso; + buscfg.sclk_io_num = _pin_sck; + buscfg.quadwp_io_num = -1; + buscfg.quadhd_io_num = -1; + buscfg.data4_io_num = -1; + buscfg.data5_io_num = -1; + buscfg.data6_io_num = -1; + buscfg.data7_io_num = -1; + buscfg.max_transfer_sz = -1; + ret = spi_bus_initialize(spi_host, &buscfg, SPI_DMA_CH_AUTO); + if (ret != ESP_OK) { + log_e("SPI bus initialize failed: %d", ret); + return false; + } + } + + Network.begin(); + _ethernets[_eth_index] = this; + if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) { + log_e("event_handler_instance_register for ETH_EVENT Failed!"); + return false; + } - // Install GPIO ISR handler to be able to service SPI Eth modules interrupts - ret = gpio_install_isr_service(0); - if(ret != ESP_OK && ret != ESP_ERR_INVALID_STATE){ - log_e("GPIO ISR handler install failed: %d", ret); - return false; - } - // Init common MAC and PHY configs to default - eth_mac_config_t eth_mac_config = ETH_MAC_DEFAULT_CONFIG(); - eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); - - // Update PHY config based on board specific configuration - phy_config.phy_addr = phy_addr; - phy_config.reset_gpio_num = _pin_rst; - - // Configure SPI interface for specific SPI module - spi_device_interface_config_t spi_devcfg; - memset(&spi_devcfg, 0, sizeof(spi_device_interface_config_t)); - spi_devcfg.mode = 0; - spi_devcfg.clock_speed_hz = _spi_freq_mhz * 1000 * 1000; - spi_devcfg.input_delay_ns = 20; - spi_devcfg.spics_io_num = _pin_cs; - spi_devcfg.queue_size = 20; - - esp_eth_mac_t *mac = NULL; - esp_eth_phy_t *phy = NULL; + // Install GPIO ISR handler to be able to service SPI Eth modules interrupts + ret = gpio_install_isr_service(0); + if (ret != ESP_OK && ret != ESP_ERR_INVALID_STATE) { + log_e("GPIO ISR handler install failed: %d", ret); + return false; + } + + // Init common MAC and PHY configs to default + eth_mac_config_t eth_mac_config = ETH_MAC_DEFAULT_CONFIG(); + eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); + + // Update PHY config based on board specific configuration + phy_config.phy_addr = phy_addr; + phy_config.reset_gpio_num = _pin_rst; + + // Configure SPI interface for specific SPI module + spi_device_interface_config_t spi_devcfg; + memset(&spi_devcfg, 0, sizeof(spi_device_interface_config_t)); + spi_devcfg.mode = 0; + spi_devcfg.clock_speed_hz = _spi_freq_mhz * 1000 * 1000; + spi_devcfg.input_delay_ns = 20; + spi_devcfg.spics_io_num = _pin_cs; + spi_devcfg.queue_size = 20; + + esp_eth_mac_t *mac = NULL; + esp_eth_phy_t *phy = NULL; #if CONFIG_ETH_SPI_ETHERNET_W5500 - if(type == ETH_PHY_W5500){ - eth_w5500_config_t mac_config = ETH_W5500_DEFAULT_CONFIG(spi_host, &spi_devcfg); - mac_config.int_gpio_num = _pin_irq; + if (type == ETH_PHY_W5500) { + eth_w5500_config_t mac_config = ETH_W5500_DEFAULT_CONFIG(spi_host, &spi_devcfg); + mac_config.int_gpio_num = _pin_irq; #if ETH_SPI_SUPPORTS_NO_IRQ - if (_pin_irq < 0) { - mac_config.poll_period_ms = 10; - } + if (_pin_irq < 0) { + mac_config.poll_period_ms = 10; + } #endif #if ETH_SPI_SUPPORTS_CUSTOM - if(_spi != NULL){ - mac_config.custom_spi_driver.config = this; - mac_config.custom_spi_driver.init = _eth_spi_init; - mac_config.custom_spi_driver.deinit = _eth_spi_deinit; - mac_config.custom_spi_driver.read = _eth_spi_read; - mac_config.custom_spi_driver.write = _eth_spi_write; - } + if (_spi != NULL) { + mac_config.custom_spi_driver.config = this; + mac_config.custom_spi_driver.init = _eth_spi_init; + mac_config.custom_spi_driver.deinit = _eth_spi_deinit; + mac_config.custom_spi_driver.read = _eth_spi_read; + mac_config.custom_spi_driver.write = _eth_spi_write; + } #endif - mac = esp_eth_mac_new_w5500(&mac_config, ð_mac_config); - phy = esp_eth_phy_new_w5500(&phy_config); - } else + mac = esp_eth_mac_new_w5500(&mac_config, ð_mac_config); + phy = esp_eth_phy_new_w5500(&phy_config); + } else #endif #if CONFIG_ETH_SPI_ETHERNET_DM9051 - if(type == ETH_PHY_DM9051){ - eth_dm9051_config_t mac_config = ETH_DM9051_DEFAULT_CONFIG(spi_host, &spi_devcfg); - mac_config.int_gpio_num = _pin_irq; + if (type == ETH_PHY_DM9051) { + eth_dm9051_config_t mac_config = ETH_DM9051_DEFAULT_CONFIG(spi_host, &spi_devcfg); + mac_config.int_gpio_num = _pin_irq; #if ETH_SPI_SUPPORTS_CUSTOM - if(_spi != NULL){ - mac_config.custom_spi_driver.config = this; - mac_config.custom_spi_driver.init = _eth_spi_init; - mac_config.custom_spi_driver.deinit = _eth_spi_deinit; - mac_config.custom_spi_driver.read = _eth_spi_read; - mac_config.custom_spi_driver.write = _eth_spi_write; - } + if (_spi != NULL) { + mac_config.custom_spi_driver.config = this; + mac_config.custom_spi_driver.init = _eth_spi_init; + mac_config.custom_spi_driver.deinit = _eth_spi_deinit; + mac_config.custom_spi_driver.read = _eth_spi_read; + mac_config.custom_spi_driver.write = _eth_spi_write; + } #endif - mac = esp_eth_mac_new_dm9051(&mac_config, ð_mac_config); - phy = esp_eth_phy_new_dm9051(&phy_config); - } else + mac = esp_eth_mac_new_dm9051(&mac_config, ð_mac_config); + phy = esp_eth_phy_new_dm9051(&phy_config); + } else #endif #if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL - if(type == ETH_PHY_KSZ8851){ - eth_ksz8851snl_config_t mac_config = ETH_KSZ8851SNL_DEFAULT_CONFIG(spi_host, &spi_devcfg); - mac_config.int_gpio_num = _pin_irq; + if (type == ETH_PHY_KSZ8851) { + eth_ksz8851snl_config_t mac_config = ETH_KSZ8851SNL_DEFAULT_CONFIG(spi_host, &spi_devcfg); + mac_config.int_gpio_num = _pin_irq; #if ETH_SPI_SUPPORTS_CUSTOM - if(_spi != NULL){ - mac_config.custom_spi_driver.config = this; - mac_config.custom_spi_driver.init = _eth_spi_init; - mac_config.custom_spi_driver.deinit = _eth_spi_deinit; - mac_config.custom_spi_driver.read = _eth_spi_read; - mac_config.custom_spi_driver.write = _eth_spi_write; - } + if (_spi != NULL) { + mac_config.custom_spi_driver.config = this; + mac_config.custom_spi_driver.init = _eth_spi_init; + mac_config.custom_spi_driver.deinit = _eth_spi_deinit; + mac_config.custom_spi_driver.read = _eth_spi_read; + mac_config.custom_spi_driver.write = _eth_spi_write; + } #endif - mac = esp_eth_mac_new_ksz8851snl(&mac_config, ð_mac_config); - phy = esp_eth_phy_new_ksz8851snl(&phy_config); - } else + mac = esp_eth_mac_new_ksz8851snl(&mac_config, ð_mac_config); + phy = esp_eth_phy_new_ksz8851snl(&phy_config); + } else #endif - { - log_e("Unsupported PHY module: %d", (int)type); - return false; - } - - // Init Ethernet driver to default and install it - esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy); - ret = esp_eth_driver_install(ð_config, &_eth_handle); - if(ret != ESP_OK){ - log_e("SPI Ethernet driver install failed: %d", ret); - return false; - } - if(_eth_handle == NULL){ - log_e("esp_eth_driver_install failed! eth_handle is NULL"); - return false; - } - - // Derive a new MAC address for this interface - uint8_t base_mac_addr[ETH_ADDR_LEN]; - ret = esp_efuse_mac_get_default(base_mac_addr); - if(ret != ESP_OK){ - log_e("Get EFUSE MAC failed: %d", ret); - return false; - } - uint8_t mac_addr[ETH_ADDR_LEN]; - base_mac_addr[ETH_ADDR_LEN - 1] += _eth_index; //Increment by the ETH number - esp_derive_local_mac(mac_addr, base_mac_addr); - - ret = esp_eth_ioctl(_eth_handle, ETH_CMD_S_MAC_ADDR, mac_addr); - if(ret != ESP_OK){ - log_e("SPI Ethernet MAC address config failed: %d", ret); - return false; - } - - // Use ESP_NETIF_DEFAULT_ETH when just one Ethernet interface is used and you don't need to modify - // default esp-netif configuration parameters. - esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH(); - - // Use ESP_NETIF_INHERENT_DEFAULT_ETH when multiple Ethernet interfaces are used and so you need to modify - // esp-netif configuration parameters for each interface (name, priority, etc.). - char if_key_str[10]; - char if_desc_str[10]; - char num_str[3]; - itoa(_eth_index, num_str, 10); - if(_eth_index == 0){ - strcpy(if_key_str, "ETH_DEF"); - } else { - strcat(strcpy(if_key_str, "ETH_"), num_str); - } - strcat(strcpy(if_desc_str, "eth"), num_str); - - esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH(); - esp_netif_config.if_key = if_key_str; - esp_netif_config.if_desc = if_desc_str; - esp_netif_config.route_prio -= _eth_index*5; + { + log_e("Unsupported PHY module: %d", (int)type); + return false; + } - cfg.base = &esp_netif_config; + // Init Ethernet driver to default and install it + esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy); + ret = esp_eth_driver_install(ð_config, &_eth_handle); + if (ret != ESP_OK) { + log_e("SPI Ethernet driver install failed: %d", ret); + return false; + } + if (_eth_handle == NULL) { + log_e("esp_eth_driver_install failed! eth_handle is NULL"); + return false; + } - _esp_netif = esp_netif_new(&cfg); - if(_esp_netif == NULL){ - log_e("esp_netif_new failed"); - return false; - } - // Attach Ethernet driver to TCP/IP stack - esp_eth_netif_glue_handle_t new_netif_glue = esp_eth_new_netif_glue(_eth_handle); - if(new_netif_glue == NULL){ - log_e("esp_eth_new_netif_glue failed"); - return false; - } + // Derive a new MAC address for this interface + uint8_t base_mac_addr[ETH_ADDR_LEN]; + ret = esp_efuse_mac_get_default(base_mac_addr); + if (ret != ESP_OK) { + log_e("Get EFUSE MAC failed: %d", ret); + return false; + } + uint8_t mac_addr[ETH_ADDR_LEN]; + base_mac_addr[ETH_ADDR_LEN - 1] += _eth_index; //Increment by the ETH number + esp_derive_local_mac(mac_addr, base_mac_addr); + + ret = esp_eth_ioctl(_eth_handle, ETH_CMD_S_MAC_ADDR, mac_addr); + if (ret != ESP_OK) { + log_e("SPI Ethernet MAC address config failed: %d", ret); + return false; + } + + // Use ESP_NETIF_DEFAULT_ETH when just one Ethernet interface is used and you don't need to modify + // default esp-netif configuration parameters. + esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH(); + + // Use ESP_NETIF_INHERENT_DEFAULT_ETH when multiple Ethernet interfaces are used and so you need to modify + // esp-netif configuration parameters for each interface (name, priority, etc.). + char if_key_str[10]; + char if_desc_str[10]; + char num_str[3]; + itoa(_eth_index, num_str, 10); + if (_eth_index == 0) { + strcpy(if_key_str, "ETH_DEF"); + } else { + strcat(strcpy(if_key_str, "ETH_"), num_str); + } + strcat(strcpy(if_desc_str, "eth"), num_str); + + esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH(); + esp_netif_config.if_key = if_key_str; + esp_netif_config.if_desc = if_desc_str; + esp_netif_config.route_prio -= _eth_index * 5; + + cfg.base = &esp_netif_config; + + _esp_netif = esp_netif_new(&cfg); + if (_esp_netif == NULL) { + log_e("esp_netif_new failed"); + return false; + } + // Attach Ethernet driver to TCP/IP stack + esp_eth_netif_glue_handle_t new_netif_glue = esp_eth_new_netif_glue(_eth_handle); + if (new_netif_glue == NULL) { + log_e("esp_eth_new_netif_glue failed"); + return false; + } - ret = esp_netif_attach(_esp_netif, new_netif_glue); - if(ret != ESP_OK){ - log_e("esp_netif_attach failed: %d", ret); - return false; - } + ret = esp_netif_attach(_esp_netif, new_netif_glue); + if (ret != ESP_OK) { + log_e("esp_netif_attach failed: %d", ret); + return false; + } - /* attach to receive events */ - initNetif((Network_Interface_ID)(ESP_NETIF_ID_ETH+_eth_index)); + /* attach to receive events */ + initNetif((Network_Interface_ID)(ESP_NETIF_ID_ETH + _eth_index)); - // Start Ethernet driver state machine - ret = esp_eth_start(_eth_handle); - if(ret != ESP_OK){ - log_e("esp_eth_start failed: %d", ret); - return false; - } + // Start Ethernet driver state machine + ret = esp_eth_start(_eth_handle); + if (ret != ESP_OK) { + log_e("esp_eth_start failed: %d", ret); + return false; + } - // If Arduino's SPI is used, cs pin is in GPIO mode + // If Arduino's SPI is used, cs pin is in GPIO mode #if ETH_SPI_SUPPORTS_CUSTOM - if(_spi == NULL){ + if (_spi == NULL) { #endif - if(!perimanSetPinBus(_pin_cs, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; } + if (!perimanSetPinBus(_pin_cs, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)) { goto err; } #if ETH_SPI_SUPPORTS_CUSTOM - } + } #endif #if ETH_SPI_SUPPORTS_NO_IRQ - if(_pin_irq != -1){ + if (_pin_irq != -1) { #endif - if(!perimanSetPinBus(_pin_irq, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; } + if (!perimanSetPinBus(_pin_irq, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)) { goto err; } #if ETH_SPI_SUPPORTS_NO_IRQ - } + } #endif - if(_pin_sck != -1){ - if(!perimanSetPinBus(_pin_sck, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; } - } - if(_pin_miso != -1){ - if(!perimanSetPinBus(_pin_miso, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; } - } - if(_pin_mosi != -1){ - if(!perimanSetPinBus(_pin_mosi, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; } - } - if(_pin_rst != -1){ - if(!perimanSetPinBus(_pin_rst, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; } - } - - Network.onSysEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED); - - return true; + if (_pin_sck != -1) { + if (!perimanSetPinBus(_pin_sck, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)) { goto err; } + } + if (_pin_miso != -1) { + if (!perimanSetPinBus(_pin_miso, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)) { goto err; } + } + if (_pin_mosi != -1) { + if (!perimanSetPinBus(_pin_mosi, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)) { goto err; } + } + if (_pin_rst != -1) { + if (!perimanSetPinBus(_pin_rst, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)) { goto err; } + } + + Network.onSysEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED); + + return true; err: - log_e("Failed to set all pins bus to ETHERNET"); - ETHClass::ethDetachBus((void *)(this)); - return false; + log_e("Failed to set all pins bus to ETHERNET"); + ETHClass::ethDetachBus((void *)(this)); + return false; } #if ETH_SPI_SUPPORTS_CUSTOM -bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst, SPIClass &spi, uint8_t spi_freq_mhz){ +bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst, SPIClass &spi, uint8_t spi_freq_mhz) { - return beginSPI(type, phy_addr, cs, irq, rst, &spi, -1, -1, -1, SPI2_HOST, spi_freq_mhz); + return beginSPI(type, phy_addr, cs, irq, rst, &spi, -1, -1, -1, SPI2_HOST, spi_freq_mhz); } #endif -bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst, spi_host_device_t spi_host, int sck, int miso, int mosi, uint8_t spi_freq_mhz){ +bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst, spi_host_device_t spi_host, int sck, int miso, int mosi, uint8_t spi_freq_mhz) { - return beginSPI(type, phy_addr, cs, irq, rst, -#if ETH_SPI_SUPPORTS_CUSTOM - NULL, + return beginSPI(type, phy_addr, cs, irq, rst, +#if ETH_SPI_SUPPORTS_CUSTOM + NULL, #endif - sck, miso, mosi, spi_host, spi_freq_mhz); + sck, miso, mosi, spi_host, spi_freq_mhz); } -void ETHClass::end(void) -{ - destroyNetif(); +void ETHClass::end(void) { + destroyNetif(); - if(_eth_ev_instance != NULL){ - if(esp_event_handler_unregister(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb) == ESP_OK){ - _eth_ev_instance = NULL; - } + if (_eth_ev_instance != NULL) { + if (esp_event_handler_unregister(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb) == ESP_OK) { + _eth_ev_instance = NULL; } + } - Network.removeEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED); - - if(_eth_handle != NULL){ - if(esp_eth_stop(_eth_handle) != ESP_OK){ - log_e("Failed to stop Ethernet"); - return; - } - if(esp_eth_driver_uninstall(_eth_handle) != ESP_OK){ - log_e("Failed to stop Ethernet"); - return; - } - _eth_handle = NULL; + Network.removeEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED); + + if (_eth_handle != NULL) { + if (esp_eth_stop(_eth_handle) != ESP_OK) { + log_e("Failed to stop Ethernet"); + return; + } + if (esp_eth_driver_uninstall(_eth_handle) != ESP_OK) { + log_e("Failed to stop Ethernet"); + return; } + _eth_handle = NULL; + } #if ETH_SPI_SUPPORTS_CUSTOM - _spi = NULL; + _spi = NULL; #endif #if CONFIG_ETH_USE_ESP32_EMAC - if(_pin_rmii_clock != -1 && _pin_mcd != -1 && _pin_mdio != -1){ - perimanClearPinBus(_pin_rmii_clock); - perimanClearPinBus(_pin_mcd); - perimanClearPinBus(_pin_mdio); - - perimanClearPinBus(ETH_RMII_TX_EN); - perimanClearPinBus(ETH_RMII_TX0); - perimanClearPinBus(ETH_RMII_TX1); - perimanClearPinBus(ETH_RMII_RX0); - perimanClearPinBus(ETH_RMII_RX1_EN); - perimanClearPinBus(ETH_RMII_CRS_DV); - - _pin_rmii_clock = -1; - _pin_mcd = -1; - _pin_mdio = -1; - } - - if(_pin_power != -1){ - perimanClearPinBus(_pin_power); - _pin_power = -1; - } + if (_pin_rmii_clock != -1 && _pin_mcd != -1 && _pin_mdio != -1) { + perimanClearPinBus(_pin_rmii_clock); + perimanClearPinBus(_pin_mcd); + perimanClearPinBus(_pin_mdio); + + perimanClearPinBus(ETH_RMII_TX_EN); + perimanClearPinBus(ETH_RMII_TX0); + perimanClearPinBus(ETH_RMII_TX1); + perimanClearPinBus(ETH_RMII_RX0); + perimanClearPinBus(ETH_RMII_RX1_EN); + perimanClearPinBus(ETH_RMII_CRS_DV); + + _pin_rmii_clock = -1; + _pin_mcd = -1; + _pin_mdio = -1; + } + + if (_pin_power != -1) { + perimanClearPinBus(_pin_power); + _pin_power = -1; + } #endif /* CONFIG_ETH_USE_ESP32_EMAC */ - if(_pin_cs != -1){ - perimanClearPinBus(_pin_cs); - _pin_cs = -1; - } - if(_pin_irq != -1){ - perimanClearPinBus(_pin_irq); - _pin_irq = -1; - } - if(_pin_sck != -1){ - perimanClearPinBus(_pin_sck); - _pin_sck = -1; - } - if(_pin_miso != -1){ - perimanClearPinBus(_pin_miso); - _pin_miso = -1; - } - if(_pin_mosi != -1){ - perimanClearPinBus(_pin_mosi); - _pin_mosi = -1; - } - if(_pin_rst != -1){ - perimanClearPinBus(_pin_rst); - _pin_rst = -1; - } + if (_pin_cs != -1) { + perimanClearPinBus(_pin_cs); + _pin_cs = -1; + } + if (_pin_irq != -1) { + perimanClearPinBus(_pin_irq); + _pin_irq = -1; + } + if (_pin_sck != -1) { + perimanClearPinBus(_pin_sck); + _pin_sck = -1; + } + if (_pin_miso != -1) { + perimanClearPinBus(_pin_miso); + _pin_miso = -1; + } + if (_pin_mosi != -1) { + perimanClearPinBus(_pin_mosi); + _pin_mosi = -1; + } + if (_pin_rst != -1) { + perimanClearPinBus(_pin_rst); + _pin_rst = -1; + } } -bool ETHClass::fullDuplex() const -{ - if(_eth_handle == NULL){ - return false; - } - eth_duplex_t link_duplex; - esp_eth_ioctl(_eth_handle, ETH_CMD_G_DUPLEX_MODE, &link_duplex); - return (link_duplex == ETH_DUPLEX_FULL); +bool ETHClass::fullDuplex() const { + if (_eth_handle == NULL) { + return false; + } + eth_duplex_t link_duplex; + esp_eth_ioctl(_eth_handle, ETH_CMD_G_DUPLEX_MODE, &link_duplex); + return (link_duplex == ETH_DUPLEX_FULL); } -bool ETHClass::autoNegotiation() const -{ - if(_eth_handle == NULL){ - return false; - } - bool auto_nego; - esp_eth_ioctl(_eth_handle, ETH_CMD_G_AUTONEGO, &auto_nego); - return auto_nego; +bool ETHClass::autoNegotiation() const { + if (_eth_handle == NULL) { + return false; + } + bool auto_nego; + esp_eth_ioctl(_eth_handle, ETH_CMD_G_AUTONEGO, &auto_nego); + return auto_nego; } -uint32_t ETHClass::phyAddr() const -{ - if(_eth_handle == NULL){ - return 0; - } - uint32_t phy_addr; - esp_eth_ioctl(_eth_handle, ETH_CMD_G_PHY_ADDR, &phy_addr); - return phy_addr; +uint32_t ETHClass::phyAddr() const { + if (_eth_handle == NULL) { + return 0; + } + uint32_t phy_addr; + esp_eth_ioctl(_eth_handle, ETH_CMD_G_PHY_ADDR, &phy_addr); + return phy_addr; } -uint8_t ETHClass::linkSpeed() const -{ - if(_eth_handle == NULL){ - return 0; - } - eth_speed_t link_speed; - esp_eth_ioctl(_eth_handle, ETH_CMD_G_SPEED, &link_speed); - return (link_speed == ETH_SPEED_10M)?10:100; +uint8_t ETHClass::linkSpeed() const { + if (_eth_handle == NULL) { + return 0; + } + eth_speed_t link_speed; + esp_eth_ioctl(_eth_handle, ETH_CMD_G_SPEED, &link_speed); + return (link_speed == ETH_SPEED_10M) ? 10 : 100; } // void ETHClass::getMac(uint8_t* mac) @@ -866,19 +853,19 @@ uint8_t ETHClass::linkSpeed() const // } // } -size_t ETHClass::printDriverInfo(Print & out) const { - size_t bytes = 0; - bytes += out.print(","); - bytes += out.print(linkSpeed()); - bytes += out.print("M"); - if(fullDuplex()){ - bytes += out.print(",FULL_DUPLEX"); - } - if(autoNegotiation()){ - bytes += out.print(",AUTO"); - } - bytes += out.printf(",ADDR:0x%lX", phyAddr()); - return bytes; +size_t ETHClass::printDriverInfo(Print &out) const { + size_t bytes = 0; + bytes += out.print(","); + bytes += out.print(linkSpeed()); + bytes += out.print("M"); + if (fullDuplex()) { + bytes += out.print(",FULL_DUPLEX"); + } + if (autoNegotiation()) { + bytes += out.print(",AUTO"); + } + bytes += out.printf(",ADDR:0x%lX", phyAddr()); + return bytes; } ETHClass ETH; diff --git a/libraries/Ethernet/src/ETH.h b/libraries/Ethernet/src/ETH.h index 5ed05642360..3062bb0e5b1 100644 --- a/libraries/Ethernet/src/ETH.h +++ b/libraries/Ethernet/src/ETH.h @@ -74,12 +74,15 @@ #if CONFIG_ETH_USE_ESP32_EMAC #define ETH_PHY_IP101 ETH_PHY_TLK110 -typedef enum { ETH_CLOCK_GPIO0_IN, ETH_CLOCK_GPIO0_OUT, ETH_CLOCK_GPIO16_OUT, ETH_CLOCK_GPIO17_OUT } eth_clock_mode_t; +typedef enum { ETH_CLOCK_GPIO0_IN, + ETH_CLOCK_GPIO0_OUT, + ETH_CLOCK_GPIO16_OUT, + ETH_CLOCK_GPIO17_OUT } eth_clock_mode_t; //Dedicated GPIOs for RMII -#define ETH_RMII_TX_EN 21 -#define ETH_RMII_TX0 19 -#define ETH_RMII_TX1 22 -#define ETH_RMII_RX0 25 +#define ETH_RMII_TX_EN 21 +#define ETH_RMII_TX0 19 +#define ETH_RMII_TX1 22 +#define ETH_RMII_RX0 25 #define ETH_RMII_RX1_EN 26 #define ETH_RMII_CRS_DV 27 #endif /* CONFIG_ETH_USE_ESP32_EMAC */ @@ -90,105 +93,110 @@ typedef enum { ETH_CLOCK_GPIO0_IN, ETH_CLOCK_GPIO0_OUT, ETH_CLOCK_GPIO16_OUT, ET #define ETH_PHY_ADDR_AUTO ESP_ETH_PHY_ADDR_AUTO -typedef enum { +typedef enum { #if CONFIG_ETH_USE_ESP32_EMAC - ETH_PHY_LAN8720, ETH_PHY_TLK110, ETH_PHY_RTL8201, ETH_PHY_DP83848, ETH_PHY_KSZ8041, ETH_PHY_KSZ8081, + ETH_PHY_LAN8720, + ETH_PHY_TLK110, + ETH_PHY_RTL8201, + ETH_PHY_DP83848, + ETH_PHY_KSZ8041, + ETH_PHY_KSZ8081, #endif /* CONFIG_ETH_USE_ESP32_EMAC */ #if CONFIG_ETH_SPI_ETHERNET_DM9051 - ETH_PHY_DM9051, + ETH_PHY_DM9051, #endif #if CONFIG_ETH_SPI_ETHERNET_W5500 - ETH_PHY_W5500, + ETH_PHY_W5500, #endif #if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL - ETH_PHY_KSZ8851, + ETH_PHY_KSZ8851, #endif - ETH_PHY_MAX + ETH_PHY_MAX } eth_phy_type_t; -class ETHClass: public NetworkInterface { - public: - ETHClass(uint8_t eth_index=0); - ~ETHClass(); +class ETHClass : public NetworkInterface { +public: + ETHClass(uint8_t eth_index = 0); + ~ETHClass(); #if CONFIG_ETH_USE_ESP32_EMAC - bool begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, int power, eth_clock_mode_t clk_mode); + bool begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, int power, eth_clock_mode_t clk_mode); #endif /* CONFIG_ETH_USE_ESP32_EMAC */ #if ETH_SPI_SUPPORTS_CUSTOM - bool begin(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst, SPIClass &spi, uint8_t spi_freq_mhz=ETH_PHY_SPI_FREQ_MHZ); + bool begin(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst, SPIClass &spi, uint8_t spi_freq_mhz = ETH_PHY_SPI_FREQ_MHZ); #endif - bool begin(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst, spi_host_device_t spi_host, int sck=-1, int miso=-1, int mosi=-1, uint8_t spi_freq_mhz=ETH_PHY_SPI_FREQ_MHZ); + bool begin(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst, spi_host_device_t spi_host, int sck = -1, int miso = -1, int mosi = -1, uint8_t spi_freq_mhz = ETH_PHY_SPI_FREQ_MHZ); - bool begin(){ + bool begin() { #if defined(ETH_PHY_TYPE) && defined(ETH_PHY_ADDR) - #if defined(CONFIG_ETH_USE_ESP32_EMAC) && defined(ETH_PHY_POWER) && defined(ETH_PHY_MDC) && defined(ETH_PHY_MDIO) && defined(ETH_CLK_MODE) - return begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_POWER, ETH_CLK_MODE); - #elif defined(ETH_PHY_CS) && defined(ETH_PHY_IRQ) && defined(ETH_PHY_RST) - #if ETH_SPI_SUPPORTS_CUSTOM && defined(ETH_PHY_SPI) - return begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_CS, ETH_PHY_IRQ, ETH_PHY_RST, ETH_PHY_SPI, ETH_PHY_SPI_FREQ_MHZ); - #elif defined(ETH_PHY_SPI_HOST) && defined(ETH_PHY_SPI_SCK) && defined(ETH_PHY_SPI_MISO) && defined(ETH_PHY_SPI_MOSI) - return begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_CS, ETH_PHY_IRQ, ETH_PHY_RST, ETH_PHY_SPI_HOST, ETH_PHY_SPI_SCK, ETH_PHY_SPI_MISO, ETH_PHY_SPI_MOSI, ETH_PHY_SPI_FREQ_MHZ); - #endif - #endif +#if defined(CONFIG_ETH_USE_ESP32_EMAC) && defined(ETH_PHY_POWER) && defined(ETH_PHY_MDC) && defined(ETH_PHY_MDIO) && defined(ETH_CLK_MODE) + return begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_POWER, ETH_CLK_MODE); +#elif defined(ETH_PHY_CS) && defined(ETH_PHY_IRQ) && defined(ETH_PHY_RST) +#if ETH_SPI_SUPPORTS_CUSTOM && defined(ETH_PHY_SPI) + return begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_CS, ETH_PHY_IRQ, ETH_PHY_RST, ETH_PHY_SPI, ETH_PHY_SPI_FREQ_MHZ); +#elif defined(ETH_PHY_SPI_HOST) && defined(ETH_PHY_SPI_SCK) && defined(ETH_PHY_SPI_MISO) && defined(ETH_PHY_SPI_MOSI) + return begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_CS, ETH_PHY_IRQ, ETH_PHY_RST, ETH_PHY_SPI_HOST, ETH_PHY_SPI_SCK, ETH_PHY_SPI_MISO, ETH_PHY_SPI_MOSI, ETH_PHY_SPI_FREQ_MHZ); #endif - return false; - } +#endif +#endif + return false; + } - void end(); + void end(); - // ETH Handle APIs - bool fullDuplex() const; - uint8_t linkSpeed() const; - bool autoNegotiation() const; - uint32_t phyAddr() const; + // ETH Handle APIs + bool fullDuplex() const; + uint8_t linkSpeed() const; + bool autoNegotiation() const; + uint32_t phyAddr() const; - esp_eth_handle_t handle() const; + esp_eth_handle_t handle() const; #if ETH_SPI_SUPPORTS_CUSTOM - static esp_err_t _eth_spi_read(void *ctx, uint32_t cmd, uint32_t addr, void *data, uint32_t data_len); - static esp_err_t _eth_spi_write(void *ctx, uint32_t cmd, uint32_t addr, const void *data, uint32_t data_len); + static esp_err_t _eth_spi_read(void *ctx, uint32_t cmd, uint32_t addr, void *data, uint32_t data_len); + static esp_err_t _eth_spi_write(void *ctx, uint32_t cmd, uint32_t addr, const void *data, uint32_t data_len); #endif - protected: +protected: #if ETH_SPI_SUPPORTS_CUSTOM - esp_err_t eth_spi_read(uint32_t cmd, uint32_t addr, void *data, uint32_t data_len); - esp_err_t eth_spi_write(uint32_t cmd, uint32_t addr, const void *data, uint32_t data_len); + esp_err_t eth_spi_read(uint32_t cmd, uint32_t addr, void *data, uint32_t data_len); + esp_err_t eth_spi_write(uint32_t cmd, uint32_t addr, const void *data, uint32_t data_len); #endif - // void getMac(uint8_t* mac); - size_t printDriverInfo(Print & out) const; - // static void eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data); + // void getMac(uint8_t* mac); + size_t printDriverInfo(Print &out) const; + // static void eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data); - public: - void _onEthEvent(int32_t event_id, void* event_data); +public: + void _onEthEvent(int32_t event_id, void *event_data); - private: - esp_eth_handle_t _eth_handle; - uint8_t _eth_index; - eth_phy_type_t _phy_type; +private: + esp_eth_handle_t _eth_handle; + uint8_t _eth_index; + eth_phy_type_t _phy_type; #if ETH_SPI_SUPPORTS_CUSTOM - SPIClass * _spi; + SPIClass *_spi; #endif - uint8_t _spi_freq_mhz; - int8_t _pin_cs; - int8_t _pin_irq; - int8_t _pin_rst; - int8_t _pin_sck; - int8_t _pin_miso; - int8_t _pin_mosi; + uint8_t _spi_freq_mhz; + int8_t _pin_cs; + int8_t _pin_irq; + int8_t _pin_rst; + int8_t _pin_sck; + int8_t _pin_miso; + int8_t _pin_mosi; #if CONFIG_ETH_USE_ESP32_EMAC - int8_t _pin_mcd; - int8_t _pin_mdio; - int8_t _pin_power; - int8_t _pin_rmii_clock; + int8_t _pin_mcd; + int8_t _pin_mdio; + int8_t _pin_power; + int8_t _pin_rmii_clock; #endif /* CONFIG_ETH_USE_ESP32_EMAC */ - static bool ethDetachBus(void * bus_pointer); - bool beginSPI(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst, + static bool ethDetachBus(void *bus_pointer); + bool beginSPI(eth_phy_type_t type, int32_t phy_addr, int cs, int irq, int rst, #if ETH_SPI_SUPPORTS_CUSTOM - SPIClass * spi, + SPIClass *spi, #endif - int sck, int miso, int mosi, spi_host_device_t spi_host, uint8_t spi_freq_mhz); + int sck, int miso, int mosi, spi_host_device_t spi_host, uint8_t spi_freq_mhz); }; extern ETHClass ETH; diff --git a/libraries/FFat/examples/FFat_Test/FFat_Test.ino b/libraries/FFat/examples/FFat_Test/FFat_Test.ino index d31637af0eb..c79fe82e361 100644 --- a/libraries/FFat/examples/FFat_Test/FFat_Test.ino +++ b/libraries/FFat/examples/FFat_Test/FFat_Test.ino @@ -8,181 +8,180 @@ // You only need to format FFat the first time you run a test #define FORMAT_FFAT true -void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ - Serial.printf("Listing directory: %s\r\n", dirname); - - File root = fs.open(dirname); - if(!root){ - Serial.println("- failed to open directory"); - return; - } - if(!root.isDirectory()){ - Serial.println(" - not a directory"); - return; - } - - File file = root.openNextFile(); - while(file){ - if(file.isDirectory()){ - Serial.print(" DIR : "); - Serial.println(file.name()); - if(levels){ - listDir(fs, file.path(), levels -1); - } - } else { - Serial.print(" FILE: "); - Serial.print(file.name()); - Serial.print("\tSIZE: "); - Serial.println(file.size()); - } - file = root.openNextFile(); +void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { + Serial.printf("Listing directory: %s\r\n", dirname); + + File root = fs.open(dirname); + if (!root) { + Serial.println("- failed to open directory"); + return; + } + if (!root.isDirectory()) { + Serial.println(" - not a directory"); + return; + } + + File file = root.openNextFile(); + while (file) { + if (file.isDirectory()) { + Serial.print(" DIR : "); + Serial.println(file.name()); + if (levels) { + listDir(fs, file.path(), levels - 1); + } + } else { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print("\tSIZE: "); + Serial.println(file.size()); } + file = root.openNextFile(); + } } -void readFile(fs::FS &fs, const char * path){ - Serial.printf("Reading file: %s\r\n", path); +void readFile(fs::FS &fs, const char *path) { + Serial.printf("Reading file: %s\r\n", path); - File file = fs.open(path); - if(!file || file.isDirectory()){ - Serial.println("- failed to open file for reading"); - return; - } + File file = fs.open(path); + if (!file || file.isDirectory()) { + Serial.println("- failed to open file for reading"); + return; + } - Serial.println("- read from file:"); - while(file.available()){ - Serial.write(file.read()); - } - file.close(); + Serial.println("- read from file:"); + while (file.available()) { + Serial.write(file.read()); + } + file.close(); } -void writeFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Writing file: %s\r\n", path); - - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("- failed to open file for writing"); - return; - } - if(file.print(message)){ - Serial.println("- file written"); - } else { - Serial.println("- write failed"); - } - file.close(); +void writeFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Writing file: %s\r\n", path); + + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("- failed to open file for writing"); + return; + } + if (file.print(message)) { + Serial.println("- file written"); + } else { + Serial.println("- write failed"); + } + file.close(); } -void appendFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Appending to file: %s\r\n", path); - - File file = fs.open(path, FILE_APPEND); - if(!file){ - Serial.println("- failed to open file for appending"); - return; - } - if(file.print(message)){ - Serial.println("- message appended"); - } else { - Serial.println("- append failed"); - } - file.close(); +void appendFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Appending to file: %s\r\n", path); + + File file = fs.open(path, FILE_APPEND); + if (!file) { + Serial.println("- failed to open file for appending"); + return; + } + if (file.print(message)) { + Serial.println("- message appended"); + } else { + Serial.println("- append failed"); + } + file.close(); } -void renameFile(fs::FS &fs, const char * path1, const char * path2){ - Serial.printf("Renaming file %s to %s\r\n", path1, path2); - if (fs.rename(path1, path2)) { - Serial.println("- file renamed"); - } else { - Serial.println("- rename failed"); - } +void renameFile(fs::FS &fs, const char *path1, const char *path2) { + Serial.printf("Renaming file %s to %s\r\n", path1, path2); + if (fs.rename(path1, path2)) { + Serial.println("- file renamed"); + } else { + Serial.println("- rename failed"); + } } -void deleteFile(fs::FS &fs, const char * path){ - Serial.printf("Deleting file: %s\r\n", path); - if(fs.remove(path)){ - Serial.println("- file deleted"); - } else { - Serial.println("- delete failed"); - } +void deleteFile(fs::FS &fs, const char *path) { + Serial.printf("Deleting file: %s\r\n", path); + if (fs.remove(path)) { + Serial.println("- file deleted"); + } else { + Serial.println("- delete failed"); + } } -void testFileIO(fs::FS &fs, const char * path){ - Serial.printf("Testing file I/O with %s\r\n", path); - - static uint8_t buf[512]; - size_t len = 0; - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("- failed to open file for writing"); - return; +void testFileIO(fs::FS &fs, const char *path) { + Serial.printf("Testing file I/O with %s\r\n", path); + + static uint8_t buf[512]; + size_t len = 0; + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("- failed to open file for writing"); + return; + } + + size_t i; + Serial.print("- writing"); + uint32_t start = millis(); + for (i = 0; i < 2048; i++) { + if ((i & 0x001F) == 0x001F) { + Serial.print("."); } - - size_t i; - Serial.print("- writing" ); - uint32_t start = millis(); - for(i=0; i<2048; i++){ - if ((i & 0x001F) == 0x001F){ - Serial.print("."); - } - file.write(buf, 512); + file.write(buf, 512); + } + Serial.println(""); + uint32_t end = millis() - start; + Serial.printf(" - %u bytes written in %lu ms\r\n", 2048 * 512, end); + file.close(); + + file = fs.open(path); + start = millis(); + end = start; + i = 0; + if (file && !file.isDirectory()) { + len = file.size(); + size_t flen = len; + start = millis(); + Serial.print("- reading"); + while (len) { + size_t toRead = len; + if (toRead > 512) { + toRead = 512; + } + file.read(buf, toRead); + if ((i++ & 0x001F) == 0x001F) { + Serial.print("."); + } + len -= toRead; } Serial.println(""); - uint32_t end = millis() - start; - Serial.printf(" - %u bytes written in %lu ms\r\n", 2048 * 512, end); + end = millis() - start; + Serial.printf("- %u bytes read in %lu ms\r\n", flen, end); file.close(); - - file = fs.open(path); - start = millis(); - end = start; - i = 0; - if(file && !file.isDirectory()){ - len = file.size(); - size_t flen = len; - start = millis(); - Serial.print("- reading" ); - while(len){ - size_t toRead = len; - if(toRead > 512){ - toRead = 512; - } - file.read(buf, toRead); - if ((i++ & 0x001F) == 0x001F){ - Serial.print("."); - } - len -= toRead; - } - Serial.println(""); - end = millis() - start; - Serial.printf("- %u bytes read in %lu ms\r\n", flen, end); - file.close(); - } else { - Serial.println("- failed to open file for reading"); - } + } else { + Serial.println("- failed to open file for reading"); + } } -void setup(){ - Serial.begin(115200); - Serial.setDebugOutput(true); - if (FORMAT_FFAT) FFat.format(); - if(!FFat.begin()){ - Serial.println("FFat Mount Failed"); - return; - } - - Serial.printf("Total space: %10u\n", FFat.totalBytes()); - Serial.printf("Free space: %10u\n", FFat.freeBytes()); - listDir(FFat, "/", 0); - writeFile(FFat, "/hello.txt", "Hello "); - appendFile(FFat, "/hello.txt", "World!\r\n"); - readFile(FFat, "/hello.txt"); - renameFile(FFat, "/hello.txt", "/foo.txt"); - readFile(FFat, "/foo.txt"); - deleteFile(FFat, "/foo.txt"); - testFileIO(FFat, "/test.txt"); - Serial.printf("Free space: %10u\n", FFat.freeBytes()); - deleteFile(FFat, "/test.txt"); - Serial.println( "Test complete" ); +void setup() { + Serial.begin(115200); + Serial.setDebugOutput(true); + if (FORMAT_FFAT) FFat.format(); + if (!FFat.begin()) { + Serial.println("FFat Mount Failed"); + return; + } + + Serial.printf("Total space: %10u\n", FFat.totalBytes()); + Serial.printf("Free space: %10u\n", FFat.freeBytes()); + listDir(FFat, "/", 0); + writeFile(FFat, "/hello.txt", "Hello "); + appendFile(FFat, "/hello.txt", "World!\r\n"); + readFile(FFat, "/hello.txt"); + renameFile(FFat, "/hello.txt", "/foo.txt"); + readFile(FFat, "/foo.txt"); + deleteFile(FFat, "/foo.txt"); + testFileIO(FFat, "/test.txt"); + Serial.printf("Free space: %10u\n", FFat.freeBytes()); + deleteFile(FFat, "/test.txt"); + Serial.println("Test complete"); } -void loop(){ - +void loop() { } diff --git a/libraries/FFat/examples/FFat_time/FFat_time.ino b/libraries/FFat/examples/FFat_time/FFat_time.ino index 475cfea026b..e526380a979 100644 --- a/libraries/FFat/examples/FFat_time/FFat_time.ino +++ b/libraries/FFat/examples/FFat_time/FFat_time.ino @@ -1,177 +1,174 @@ #include "FS.h" #include "FFat.h" -#include +#include #include -const char* ssid = "your-ssid"; -const char* password = "your-password"; +const char *ssid = "your-ssid"; +const char *password = "your-password"; -long timezone = 1; +long timezone = 1; byte daysavetime = 1; -void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ - Serial.printf("Listing directory: %s\n", dirname); - - File root = fs.open(dirname); - if(!root){ - Serial.println("Failed to open directory"); - return; - } - if(!root.isDirectory()){ - Serial.println("Not a directory"); - return; - } - - File file = root.openNextFile(); - while(file){ - if(file.isDirectory()){ - Serial.print(" DIR : "); - Serial.print (file.name()); - time_t t= file.getLastWrite(); - struct tm * tmstruct = localtime(&t); - Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec); - if(levels){ - listDir(fs, file.path(), levels -1); - } - } else { - Serial.print(" FILE: "); - Serial.print(file.name()); - Serial.print(" SIZE: "); - Serial.print(file.size()); - time_t t= file.getLastWrite(); - struct tm * tmstruct = localtime(&t); - Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec); - } - file = root.openNextFile(); +void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { + Serial.printf("Listing directory: %s\n", dirname); + + File root = fs.open(dirname); + if (!root) { + Serial.println("Failed to open directory"); + return; + } + if (!root.isDirectory()) { + Serial.println("Not a directory"); + return; + } + + File file = root.openNextFile(); + while (file) { + if (file.isDirectory()) { + Serial.print(" DIR : "); + Serial.print(file.name()); + time_t t = file.getLastWrite(); + struct tm *tmstruct = localtime(&t); + Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); + if (levels) { + listDir(fs, file.path(), levels - 1); + } + } else { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print(" SIZE: "); + Serial.print(file.size()); + time_t t = file.getLastWrite(); + struct tm *tmstruct = localtime(&t); + Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); } + file = root.openNextFile(); + } } -void createDir(fs::FS &fs, const char * path){ - Serial.printf("Creating Dir: %s\n", path); - if(fs.mkdir(path)){ - Serial.println("Dir created"); - } else { - Serial.println("mkdir failed"); - } +void createDir(fs::FS &fs, const char *path) { + Serial.printf("Creating Dir: %s\n", path); + if (fs.mkdir(path)) { + Serial.println("Dir created"); + } else { + Serial.println("mkdir failed"); + } } -void removeDir(fs::FS &fs, const char * path){ - Serial.printf("Removing Dir: %s\n", path); - if(fs.rmdir(path)){ - Serial.println("Dir removed"); - } else { - Serial.println("rmdir failed"); - } +void removeDir(fs::FS &fs, const char *path) { + Serial.printf("Removing Dir: %s\n", path); + if (fs.rmdir(path)) { + Serial.println("Dir removed"); + } else { + Serial.println("rmdir failed"); + } } -void readFile(fs::FS &fs, const char * path){ - Serial.printf("Reading file: %s\n", path); +void readFile(fs::FS &fs, const char *path) { + Serial.printf("Reading file: %s\n", path); - File file = fs.open(path); - if(!file){ - Serial.println("Failed to open file for reading"); - return; - } + File file = fs.open(path); + if (!file) { + Serial.println("Failed to open file for reading"); + return; + } - Serial.print("Read from file: "); - while(file.available()){ - Serial.write(file.read()); - } - file.close(); + Serial.print("Read from file: "); + while (file.available()) { + Serial.write(file.read()); + } + file.close(); } -void writeFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Writing file: %s\n", path); - - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("Failed to open file for writing"); - return; - } - if(file.print(message)){ - Serial.println("File written"); - } else { - Serial.println("Write failed"); - } - file.close(); +void writeFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Writing file: %s\n", path); + + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("Failed to open file for writing"); + return; + } + if (file.print(message)) { + Serial.println("File written"); + } else { + Serial.println("Write failed"); + } + file.close(); } -void appendFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Appending to file: %s\n", path); - - File file = fs.open(path, FILE_APPEND); - if(!file){ - Serial.println("Failed to open file for appending"); - return; - } - if(file.print(message)){ - Serial.println("Message appended"); - } else { - Serial.println("Append failed"); - } - file.close(); +void appendFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Appending to file: %s\n", path); + + File file = fs.open(path, FILE_APPEND); + if (!file) { + Serial.println("Failed to open file for appending"); + return; + } + if (file.print(message)) { + Serial.println("Message appended"); + } else { + Serial.println("Append failed"); + } + file.close(); } -void renameFile(fs::FS &fs, const char * path1, const char * path2){ - Serial.printf("Renaming file %s to %s\n", path1, path2); - if (fs.rename(path1, path2)) { - Serial.println("File renamed"); - } else { - Serial.println("Rename failed"); - } +void renameFile(fs::FS &fs, const char *path1, const char *path2) { + Serial.printf("Renaming file %s to %s\n", path1, path2); + if (fs.rename(path1, path2)) { + Serial.println("File renamed"); + } else { + Serial.println("Rename failed"); + } } -void deleteFile(fs::FS &fs, const char * path){ - Serial.printf("Deleting file: %s\n", path); - if(fs.remove(path)){ - Serial.println("File deleted"); - } else { - Serial.println("Delete failed"); - } +void deleteFile(fs::FS &fs, const char *path) { + Serial.printf("Deleting file: %s\n", path); + if (fs.remove(path)) { + Serial.println("File deleted"); + } else { + Serial.println("Delete failed"); + } } -void setup(){ - Serial.begin(115200); - // We start by connecting to a WiFi network - Serial.println(); - Serial.println(); - Serial.print("Connecting to "); - Serial.println(ssid); - - WiFi.begin(ssid, password); - - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } - Serial.println("WiFi connected"); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println("Contacting Time Server"); - configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); - struct tm tmstruct ; - delay(2000); - tmstruct.tm_year = 0; - getLocalTime(&tmstruct, 5000); - Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct.tm_year)+1900,( tmstruct.tm_mon)+1, tmstruct.tm_mday,tmstruct.tm_hour , tmstruct.tm_min, tmstruct.tm_sec); - Serial.println(""); - - if(!FFat.begin(true)){ - Serial.println("FFat Mount Failed"); - return; - } - - listDir(FFat, "/", 0); - removeDir(FFat, "/mydir"); - createDir(FFat, "/mydir"); - deleteFile(FFat, "/hello.txt"); - writeFile(FFat, "/hello.txt", "Hello "); - appendFile(FFat, "/hello.txt", "World!\n"); - listDir(FFat, "/", 0); +void setup() { + Serial.begin(115200); + // We start by connecting to a WiFi network + Serial.println(); + Serial.println(); + Serial.print("Connecting to "); + Serial.println(ssid); + + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + Serial.println("Contacting Time Server"); + configTime(3600 * timezone, daysavetime * 3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); + struct tm tmstruct; + delay(2000); + tmstruct.tm_year = 0; + getLocalTime(&tmstruct, 5000); + Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec); + Serial.println(""); + + if (!FFat.begin(true)) { + Serial.println("FFat Mount Failed"); + return; + } + + listDir(FFat, "/", 0); + removeDir(FFat, "/mydir"); + createDir(FFat, "/mydir"); + deleteFile(FFat, "/hello.txt"); + writeFile(FFat, "/hello.txt", "Hello "); + appendFile(FFat, "/hello.txt", "World!\n"); + listDir(FFat, "/", 0); } -void loop(){ - +void loop() { } - - diff --git a/libraries/FFat/src/FFat.cpp b/libraries/FFat/src/FFat.cpp index e312e7f8f92..a1fc70a7ab4 100644 --- a/libraries/FFat/src/FFat.cpp +++ b/libraries/FFat/src/FFat.cpp @@ -24,159 +24,149 @@ extern "C" { using namespace fs; F_Fat::F_Fat(FSImplPtr impl) - : FS(impl) -{} - -const esp_partition_t *check_ffat_partition(const char* label) -{ - const esp_partition_t* ck_part = esp_partition_find_first( - ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, label); - if (!ck_part) { - log_e("No FAT partition found with label %s", label); - return NULL; - } - return ck_part; + : FS(impl) {} + +const esp_partition_t* check_ffat_partition(const char* label) { + const esp_partition_t* ck_part = esp_partition_find_first( + ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, label); + if (!ck_part) { + log_e("No FAT partition found with label %s", label); + return NULL; + } + return ck_part; } -bool F_Fat::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles, const char * partitionLabel) -{ - if(_wl_handle != WL_INVALID_HANDLE){ - log_w("Already Mounted!"); - return true; - } - - if (!check_ffat_partition(partitionLabel)){ - log_e("No fat partition found on flash"); - return false; - } - - esp_vfs_fat_mount_config_t conf = { - .format_if_mount_failed = formatOnFail, - .max_files = maxOpenFiles, - .allocation_unit_size = CONFIG_WL_SECTOR_SIZE, - .disk_status_check_enable = false - }; - esp_err_t err = esp_vfs_fat_spiflash_mount_rw_wl(basePath, partitionLabel, &conf, &_wl_handle); - if(err){ - log_e("Mounting FFat partition failed! Error: %d", err); - esp_vfs_fat_spiflash_unmount_rw_wl(basePath, _wl_handle); - _wl_handle = WL_INVALID_HANDLE; - return false; - } - _impl->mountpoint(basePath); +bool F_Fat::begin(bool formatOnFail, const char* basePath, uint8_t maxOpenFiles, const char* partitionLabel) { + if (_wl_handle != WL_INVALID_HANDLE) { + log_w("Already Mounted!"); return true; + } + + if (!check_ffat_partition(partitionLabel)) { + log_e("No fat partition found on flash"); + return false; + } + + esp_vfs_fat_mount_config_t conf = { + .format_if_mount_failed = formatOnFail, + .max_files = maxOpenFiles, + .allocation_unit_size = CONFIG_WL_SECTOR_SIZE, + .disk_status_check_enable = false + }; + esp_err_t err = esp_vfs_fat_spiflash_mount_rw_wl(basePath, partitionLabel, &conf, &_wl_handle); + if (err) { + log_e("Mounting FFat partition failed! Error: %d", err); + esp_vfs_fat_spiflash_unmount_rw_wl(basePath, _wl_handle); + _wl_handle = WL_INVALID_HANDLE; + return false; + } + _impl->mountpoint(basePath); + return true; } -void F_Fat::end() -{ - if(_wl_handle != WL_INVALID_HANDLE){ - esp_err_t err = esp_vfs_fat_spiflash_unmount_rw_wl(_impl->mountpoint(), _wl_handle); - if(err){ - log_e("Unmounting FFat partition failed! Error: %d", err); - return; - } - _wl_handle = WL_INVALID_HANDLE; - _impl->mountpoint(NULL); +void F_Fat::end() { + if (_wl_handle != WL_INVALID_HANDLE) { + esp_err_t err = esp_vfs_fat_spiflash_unmount_rw_wl(_impl->mountpoint(), _wl_handle); + if (err) { + log_e("Unmounting FFat partition failed! Error: %d", err); + return; } + _wl_handle = WL_INVALID_HANDLE; + _impl->mountpoint(NULL); + } } -bool F_Fat::format(bool full_wipe, char* partitionLabel) -{ - esp_err_t result; - bool res = true; - if(_wl_handle != WL_INVALID_HANDLE){ - log_w("Already Mounted!"); - return false; - } - wl_handle_t temp_handle; -// Attempt to mount to see if there is already data - const esp_partition_t *ffat_partition = check_ffat_partition(partitionLabel); - if (!ffat_partition){ - log_w("No partition!"); - return false; - } - result = wl_mount(ffat_partition, &temp_handle); - - if (result == ESP_OK) { -// Wipe disk- quick just wipes the FAT. Full zeroes the whole disk - uint32_t wipe_size = full_wipe ? wl_size(temp_handle) : 16384; - wl_erase_range(temp_handle, 0, wipe_size); - wl_unmount(temp_handle); - } else { - res = false; - log_w("wl_mount failed!"); - } -// Now do a mount with format_if_fail (which it will) - esp_vfs_fat_mount_config_t conf = { - .format_if_mount_failed = true, - .max_files = 1, - .allocation_unit_size = CONFIG_WL_SECTOR_SIZE, - .disk_status_check_enable = false - }; - result = esp_vfs_fat_spiflash_mount_rw_wl("/format_ffat", partitionLabel, &conf, &temp_handle); - esp_vfs_fat_spiflash_unmount_rw_wl("/format_ffat", temp_handle); - if (result != ESP_OK){ - res = false; - log_w("esp_vfs_fat_spiflash_mount_rw_wl failed!"); - } - return res; +bool F_Fat::format(bool full_wipe, char* partitionLabel) { + esp_err_t result; + bool res = true; + if (_wl_handle != WL_INVALID_HANDLE) { + log_w("Already Mounted!"); + return false; + } + wl_handle_t temp_handle; + // Attempt to mount to see if there is already data + const esp_partition_t* ffat_partition = check_ffat_partition(partitionLabel); + if (!ffat_partition) { + log_w("No partition!"); + return false; + } + result = wl_mount(ffat_partition, &temp_handle); + + if (result == ESP_OK) { + // Wipe disk- quick just wipes the FAT. Full zeroes the whole disk + uint32_t wipe_size = full_wipe ? wl_size(temp_handle) : 16384; + wl_erase_range(temp_handle, 0, wipe_size); + wl_unmount(temp_handle); + } else { + res = false; + log_w("wl_mount failed!"); + } + // Now do a mount with format_if_fail (which it will) + esp_vfs_fat_mount_config_t conf = { + .format_if_mount_failed = true, + .max_files = 1, + .allocation_unit_size = CONFIG_WL_SECTOR_SIZE, + .disk_status_check_enable = false + }; + result = esp_vfs_fat_spiflash_mount_rw_wl("/format_ffat", partitionLabel, &conf, &temp_handle); + esp_vfs_fat_spiflash_unmount_rw_wl("/format_ffat", temp_handle); + if (result != ESP_OK) { + res = false; + log_w("esp_vfs_fat_spiflash_mount_rw_wl failed!"); + } + return res; } -size_t F_Fat::totalBytes() -{ - FATFS *fs; - DWORD free_clust, tot_sect, sect_size; - - BYTE pdrv = ff_diskio_get_pdrv_wl(_wl_handle); - char drv[3] = {(char)(48+pdrv), ':', 0}; - if ( f_getfree(drv, &free_clust, &fs) != FR_OK){ - return 0; - } - tot_sect = (fs->n_fatent - 2) * fs->csize; - sect_size = CONFIG_WL_SECTOR_SIZE; - return tot_sect * sect_size; +size_t F_Fat::totalBytes() { + FATFS* fs; + DWORD free_clust, tot_sect, sect_size; + + BYTE pdrv = ff_diskio_get_pdrv_wl(_wl_handle); + char drv[3] = { (char)(48 + pdrv), ':', 0 }; + if (f_getfree(drv, &free_clust, &fs) != FR_OK) { + return 0; + } + tot_sect = (fs->n_fatent - 2) * fs->csize; + sect_size = CONFIG_WL_SECTOR_SIZE; + return tot_sect * sect_size; } -size_t F_Fat::usedBytes() -{ - FATFS *fs; - DWORD free_clust, used_sect, sect_size; - - BYTE pdrv = ff_diskio_get_pdrv_wl(_wl_handle); - char drv[3] = {(char)(48+pdrv), ':', 0}; - if ( f_getfree(drv, &free_clust, &fs) != FR_OK){ - return 0; - } - used_sect = (fs->n_fatent - 2 - free_clust) * fs->csize; - sect_size = CONFIG_WL_SECTOR_SIZE; - return used_sect * sect_size; +size_t F_Fat::usedBytes() { + FATFS* fs; + DWORD free_clust, used_sect, sect_size; + + BYTE pdrv = ff_diskio_get_pdrv_wl(_wl_handle); + char drv[3] = { (char)(48 + pdrv), ':', 0 }; + if (f_getfree(drv, &free_clust, &fs) != FR_OK) { + return 0; + } + used_sect = (fs->n_fatent - 2 - free_clust) * fs->csize; + sect_size = CONFIG_WL_SECTOR_SIZE; + return used_sect * sect_size; } -size_t F_Fat::freeBytes() -{ +size_t F_Fat::freeBytes() { - FATFS *fs; - DWORD free_clust, free_sect, sect_size; + FATFS* fs; + DWORD free_clust, free_sect, sect_size; - BYTE pdrv = ff_diskio_get_pdrv_wl(_wl_handle); - char drv[3] = {(char)(48+pdrv), ':', 0}; - if ( f_getfree(drv, &free_clust, &fs) != FR_OK){ - return 0; - } - free_sect = free_clust * fs->csize; - sect_size = CONFIG_WL_SECTOR_SIZE; - return free_sect * sect_size; + BYTE pdrv = ff_diskio_get_pdrv_wl(_wl_handle); + char drv[3] = { (char)(48 + pdrv), ':', 0 }; + if (f_getfree(drv, &free_clust, &fs) != FR_OK) { + return 0; + } + free_sect = free_clust * fs->csize; + sect_size = CONFIG_WL_SECTOR_SIZE; + return free_sect * sect_size; } -bool F_Fat::exists(const char* path) -{ - File f = open(path, "r",false); - return (f == true) && !f.isDirectory(); +bool F_Fat::exists(const char* path) { + File f = open(path, "r", false); + return (f == true) && !f.isDirectory(); } -bool F_Fat::exists(const String& path) -{ - return exists(path.c_str()); +bool F_Fat::exists(const String& path) { + return exists(path.c_str()); } diff --git a/libraries/FFat/src/FFat.h b/libraries/FFat/src/FFat.h index ed20e23b294..5c9531d7e83 100644 --- a/libraries/FFat/src/FFat.h +++ b/libraries/FFat/src/FFat.h @@ -21,24 +21,22 @@ #define FFAT_WIPE_FULL 1 #define FFAT_PARTITION_LABEL "ffat" -namespace fs -{ +namespace fs { -class F_Fat : public FS -{ +class F_Fat : public FS { public: - F_Fat(FSImplPtr impl); - bool begin(bool formatOnFail=false, const char * basePath="/ffat", uint8_t maxOpenFiles=10, const char * partitionLabel = (char*)FFAT_PARTITION_LABEL); - bool format(bool full_wipe = FFAT_WIPE_QUICK, char* partitionLabel = (char*)FFAT_PARTITION_LABEL); - size_t totalBytes(); - size_t usedBytes(); - size_t freeBytes(); - void end(); - bool exists(const char* path); - bool exists(const String& path); + F_Fat(FSImplPtr impl); + bool begin(bool formatOnFail = false, const char* basePath = "/ffat", uint8_t maxOpenFiles = 10, const char* partitionLabel = (char*)FFAT_PARTITION_LABEL); + bool format(bool full_wipe = FFAT_WIPE_QUICK, char* partitionLabel = (char*)FFAT_PARTITION_LABEL); + size_t totalBytes(); + size_t usedBytes(); + size_t freeBytes(); + void end(); + bool exists(const char* path); + bool exists(const String& path); private: - wl_handle_t _wl_handle = WL_INVALID_HANDLE; + wl_handle_t _wl_handle = WL_INVALID_HANDLE; }; } diff --git a/libraries/FS/src/FS.cpp b/libraries/FS/src/FS.cpp index e0a0a0acd28..31439da24d4 100644 --- a/libraries/FS/src/FS.cpp +++ b/libraries/FS/src/FS.cpp @@ -23,298 +23,260 @@ using namespace fs; -size_t File::write(uint8_t c) -{ - if (!*this) { - return 0; - } +size_t File::write(uint8_t c) { + if (!*this) { + return 0; + } - return _p->write(&c, 1); + return _p->write(&c, 1); } -time_t File::getLastWrite() -{ - if (!*this) { - return 0; - } +time_t File::getLastWrite() { + if (!*this) { + return 0; + } - return _p->getLastWrite(); + return _p->getLastWrite(); } -size_t File::write(const uint8_t *buf, size_t size) -{ - if (!*this) { - return 0; - } +size_t File::write(const uint8_t* buf, size_t size) { + if (!*this) { + return 0; + } - return _p->write(buf, size); + return _p->write(buf, size); } -int File::available() -{ - if (!*this) { - return false; - } +int File::available() { + if (!*this) { + return false; + } - return _p->size() - _p->position(); + return _p->size() - _p->position(); } -int File::read() -{ - if (!*this) { - return -1; - } +int File::read() { + if (!*this) { + return -1; + } - uint8_t result; - if (_p->read(&result, 1) != 1) { - return -1; - } + uint8_t result; + if (_p->read(&result, 1) != 1) { + return -1; + } - return result; + return result; } -size_t File::read(uint8_t* buf, size_t size) -{ - if (!*this) { - return -1; - } +size_t File::read(uint8_t* buf, size_t size) { + if (!*this) { + return -1; + } - return _p->read(buf, size); + return _p->read(buf, size); } -int File::peek() -{ - if (!*this) { - return -1; - } +int File::peek() { + if (!*this) { + return -1; + } - size_t curPos = _p->position(); - int result = read(); - seek(curPos, SeekSet); - return result; + size_t curPos = _p->position(); + int result = read(); + seek(curPos, SeekSet); + return result; } -void File::flush() -{ - if (!*this) { - return; - } +void File::flush() { + if (!*this) { + return; + } - _p->flush(); + _p->flush(); } -bool File::seek(uint32_t pos, SeekMode mode) -{ - if (!*this) { - return false; - } +bool File::seek(uint32_t pos, SeekMode mode) { + if (!*this) { + return false; + } - return _p->seek(pos, mode); + return _p->seek(pos, mode); } -size_t File::position() const -{ - if (!*this) { - return 0; - } +size_t File::position() const { + if (!*this) { + return 0; + } - return _p->position(); + return _p->position(); } -size_t File::size() const -{ - if (!*this) { - return 0; - } +size_t File::size() const { + if (!*this) { + return 0; + } - return _p->size(); + return _p->size(); } -bool File::setBufferSize(size_t size) -{ - if (!*this) { - return 0; - } +bool File::setBufferSize(size_t size) { + if (!*this) { + return 0; + } - return _p->setBufferSize(size); + return _p->setBufferSize(size); } -void File::close() -{ - if (_p) { - _p->close(); - _p = nullptr; - } +void File::close() { + if (_p) { + _p->close(); + _p = nullptr; + } } -File::operator bool() const -{ - return _p != nullptr && *_p != false; +File::operator bool() const { + return _p != nullptr && *_p != false; } -const char* File::path() const -{ - if (!*this) { - return nullptr; - } +const char* File::path() const { + if (!*this) { + return nullptr; + } - return _p->path(); + return _p->path(); } -const char* File::name() const -{ - if (!*this) { - return nullptr; - } +const char* File::name() const { + if (!*this) { + return nullptr; + } - return _p->name(); + return _p->name(); } //to implement -boolean File::isDirectory(void) -{ - if (!*this) { - return false; - } - return _p->isDirectory(); +boolean File::isDirectory(void) { + if (!*this) { + return false; + } + return _p->isDirectory(); } -File File::openNextFile(const char* mode) -{ - if (!*this) { - return File(); - } - return _p->openNextFile(mode); +File File::openNextFile(const char* mode) { + if (!*this) { + return File(); + } + return _p->openNextFile(mode); } -boolean File::seekDir(long position){ - if(!_p){ - return false; - } - return _p->seekDir(position); +boolean File::seekDir(long position) { + if (!_p) { + return false; + } + return _p->seekDir(position); } -String File::getNextFileName(void) -{ - if (!_p) { - return ""; - } - return _p->getNextFileName(); - +String File::getNextFileName(void) { + if (!_p) { + return ""; + } + return _p->getNextFileName(); } -String File::getNextFileName(bool *isDir) -{ - if (!_p) { - return ""; - } - return _p->getNextFileName(isDir); - +String File::getNextFileName(bool* isDir) { + if (!_p) { + return ""; + } + return _p->getNextFileName(isDir); } -void File::rewindDirectory(void) -{ - if (!*this) { - return; - } - _p->rewindDirectory(); +void File::rewindDirectory(void) { + if (!*this) { + return; + } + _p->rewindDirectory(); } -File FS::open(const String& path, const char* mode, const bool create) -{ - return open(path.c_str(), mode, create); +File FS::open(const String& path, const char* mode, const bool create) { + return open(path.c_str(), mode, create); } -File FS::open(const char* path, const char* mode, const bool create) -{ - if (!_impl) { - return File(); - } +File FS::open(const char* path, const char* mode, const bool create) { + if (!_impl) { + return File(); + } - return File(_impl->open(path, mode, create)); + return File(_impl->open(path, mode, create)); } -bool FS::exists(const char* path) -{ - if (!_impl) { - return false; - } - return _impl->exists(path); +bool FS::exists(const char* path) { + if (!_impl) { + return false; + } + return _impl->exists(path); } -bool FS::exists(const String& path) -{ - return exists(path.c_str()); +bool FS::exists(const String& path) { + return exists(path.c_str()); } -bool FS::remove(const char* path) -{ - if (!_impl) { - return false; - } - return _impl->remove(path); +bool FS::remove(const char* path) { + if (!_impl) { + return false; + } + return _impl->remove(path); } -bool FS::remove(const String& path) -{ - return remove(path.c_str()); +bool FS::remove(const String& path) { + return remove(path.c_str()); } -bool FS::rename(const char* pathFrom, const char* pathTo) -{ - if (!_impl) { - return false; - } - return _impl->rename(pathFrom, pathTo); +bool FS::rename(const char* pathFrom, const char* pathTo) { + if (!_impl) { + return false; + } + return _impl->rename(pathFrom, pathTo); } -bool FS::rename(const String& pathFrom, const String& pathTo) -{ - return rename(pathFrom.c_str(), pathTo.c_str()); +bool FS::rename(const String& pathFrom, const String& pathTo) { + return rename(pathFrom.c_str(), pathTo.c_str()); } -bool FS::mkdir(const char *path) -{ - if (!_impl) { - return false; - } - return _impl->mkdir(path); +bool FS::mkdir(const char* path) { + if (!_impl) { + return false; + } + return _impl->mkdir(path); } -bool FS::mkdir(const String &path) -{ - return mkdir(path.c_str()); +bool FS::mkdir(const String& path) { + return mkdir(path.c_str()); } -bool FS::rmdir(const char *path) -{ - if (!_impl) { - return false; - } - return _impl->rmdir(path); +bool FS::rmdir(const char* path) { + if (!_impl) { + return false; + } + return _impl->rmdir(path); } -bool FS::rmdir(const String &path) -{ - return rmdir(path.c_str()); +bool FS::rmdir(const String& path) { + return rmdir(path.c_str()); } -const char * FS::mountpoint() -{ - if (!_impl) { - return NULL; - } - return _impl->mountpoint(); +const char* FS::mountpoint() { + if (!_impl) { + return NULL; + } + return _impl->mountpoint(); } -void FSImpl::mountpoint(const char * mp) -{ - _mountpoint = mp; +void FSImpl::mountpoint(const char* mp) { + _mountpoint = mp; } -const char * FSImpl::mountpoint() -{ - return _mountpoint; +const char* FSImpl::mountpoint() { + return _mountpoint; } diff --git a/libraries/FS/src/FS.h b/libraries/FS/src/FS.h index bd04b497091..1aa8ab447d0 100644 --- a/libraries/FS/src/FS.h +++ b/libraries/FS/src/FS.h @@ -24,12 +24,11 @@ #include #include -namespace fs -{ +namespace fs { -#define FILE_READ "r" -#define FILE_WRITE "w" -#define FILE_APPEND "a" +#define FILE_READ "r" +#define FILE_WRITE "w" +#define FILE_APPEND "a" class File; @@ -39,86 +38,84 @@ class FSImpl; typedef std::shared_ptr FSImplPtr; enum SeekMode { - SeekSet = 0, - SeekCur = 1, - SeekEnd = 2 + SeekSet = 0, + SeekCur = 1, + SeekEnd = 2 }; -class File : public Stream -{ +class File : public Stream { public: - File(FileImplPtr p = FileImplPtr()) : _p(p) { - _timeout = 0; - } - - size_t write(uint8_t) override; - size_t write(const uint8_t *buf, size_t size) override; - int available() override; - int read() override; - int peek() override; - void flush() override; - size_t read(uint8_t* buf, size_t size); - size_t readBytes(char *buffer, size_t length) - { - return read((uint8_t*)buffer, length); - } - - bool seek(uint32_t pos, SeekMode mode); - bool seek(uint32_t pos) - { - return seek(pos, SeekSet); - } - size_t position() const; - size_t size() const; - bool setBufferSize(size_t size); - void close(); - operator bool() const; - time_t getLastWrite(); - const char* path() const; - const char* name() const; - - boolean isDirectory(void); - boolean seekDir(long position); - File openNextFile(const char* mode = FILE_READ); - String getNextFileName(void); - String getNextFileName(boolean *isDir); - void rewindDirectory(void); + File(FileImplPtr p = FileImplPtr()) + : _p(p) { + _timeout = 0; + } + + size_t write(uint8_t) override; + size_t write(const uint8_t* buf, size_t size) override; + int available() override; + int read() override; + int peek() override; + void flush() override; + size_t read(uint8_t* buf, size_t size); + size_t readBytes(char* buffer, size_t length) { + return read((uint8_t*)buffer, length); + } + + bool seek(uint32_t pos, SeekMode mode); + bool seek(uint32_t pos) { + return seek(pos, SeekSet); + } + size_t position() const; + size_t size() const; + bool setBufferSize(size_t size); + void close(); + operator bool() const; + time_t getLastWrite(); + const char* path() const; + const char* name() const; + + boolean isDirectory(void); + boolean seekDir(long position); + File openNextFile(const char* mode = FILE_READ); + String getNextFileName(void); + String getNextFileName(boolean* isDir); + void rewindDirectory(void); protected: - FileImplPtr _p; + FileImplPtr _p; }; -class FS -{ +class FS { public: - FS(FSImplPtr impl) : _impl(impl) { } + FS(FSImplPtr impl) + : _impl(impl) {} - File open(const char* path, const char* mode = FILE_READ, const bool create = false); - File open(const String& path, const char* mode = FILE_READ, const bool create = false); + File open(const char* path, const char* mode = FILE_READ, const bool create = false); + File open(const String& path, const char* mode = FILE_READ, const bool create = false); - bool exists(const char* path); - bool exists(const String& path); + bool exists(const char* path); + bool exists(const String& path); - bool remove(const char* path); - bool remove(const String& path); + bool remove(const char* path); + bool remove(const String& path); - bool rename(const char* pathFrom, const char* pathTo); - bool rename(const String& pathFrom, const String& pathTo); + bool rename(const char* pathFrom, const char* pathTo); + bool rename(const String& pathFrom, const String& pathTo); - bool mkdir(const char *path); - bool mkdir(const String &path); + bool mkdir(const char* path); + bool mkdir(const String& path); - bool rmdir(const char *path); - bool rmdir(const String &path); - - const char * mountpoint(); + bool rmdir(const char* path); + bool rmdir(const String& path); + + const char* mountpoint(); protected: - FSImplPtr _impl; + FSImplPtr _impl; }; -} // namespace fs +} // namespace fs #ifndef FS_NO_GLOBALS using fs::FS; @@ -127,6 +124,6 @@ using fs::SeekMode; using fs::SeekSet; using fs::SeekCur; using fs::SeekEnd; -#endif //FS_NO_GLOBALS +#endif //FS_NO_GLOBALS -#endif //FS_H +#endif //FS_H diff --git a/libraries/FS/src/FSImpl.h b/libraries/FS/src/FSImpl.h index 24fb09f9e52..4b4d2da038f 100644 --- a/libraries/FS/src/FSImpl.h +++ b/libraries/FS/src/FSImpl.h @@ -23,50 +23,48 @@ #include #include -namespace fs -{ +namespace fs { -class FileImpl -{ +class FileImpl { public: - virtual ~FileImpl() { } - virtual size_t write(const uint8_t *buf, size_t size) = 0; - virtual size_t read(uint8_t* buf, size_t size) = 0; - virtual void flush() = 0; - virtual bool seek(uint32_t pos, SeekMode mode) = 0; - virtual size_t position() const = 0; - virtual size_t size() const = 0; - virtual bool setBufferSize(size_t size) = 0; - virtual void close() = 0; - virtual time_t getLastWrite() = 0; - virtual const char* path() const = 0; - virtual const char* name() const = 0; - virtual boolean isDirectory(void) = 0; - virtual FileImplPtr openNextFile(const char* mode) = 0; - virtual boolean seekDir(long position) = 0; - virtual String getNextFileName(void) = 0; - virtual String getNextFileName(bool *isDir) = 0; - virtual void rewindDirectory(void) = 0; - virtual operator bool() = 0; + virtual ~FileImpl() {} + virtual size_t write(const uint8_t* buf, size_t size) = 0; + virtual size_t read(uint8_t* buf, size_t size) = 0; + virtual void flush() = 0; + virtual bool seek(uint32_t pos, SeekMode mode) = 0; + virtual size_t position() const = 0; + virtual size_t size() const = 0; + virtual bool setBufferSize(size_t size) = 0; + virtual void close() = 0; + virtual time_t getLastWrite() = 0; + virtual const char* path() const = 0; + virtual const char* name() const = 0; + virtual boolean isDirectory(void) = 0; + virtual FileImplPtr openNextFile(const char* mode) = 0; + virtual boolean seekDir(long position) = 0; + virtual String getNextFileName(void) = 0; + virtual String getNextFileName(bool* isDir) = 0; + virtual void rewindDirectory(void) = 0; + virtual operator bool() = 0; }; -class FSImpl -{ +class FSImpl { protected: - const char * _mountpoint; + const char* _mountpoint; public: - FSImpl() : _mountpoint(NULL) { } - virtual ~FSImpl() { } - virtual FileImplPtr open(const char* path, const char* mode, const bool create) = 0; - virtual bool exists(const char* path) = 0; - virtual bool rename(const char* pathFrom, const char* pathTo) = 0; - virtual bool remove(const char* path) = 0; - virtual bool mkdir(const char *path) = 0; - virtual bool rmdir(const char *path) = 0; - void mountpoint(const char *); - const char * mountpoint(); + FSImpl() + : _mountpoint(NULL) {} + virtual ~FSImpl() {} + virtual FileImplPtr open(const char* path, const char* mode, const bool create) = 0; + virtual bool exists(const char* path) = 0; + virtual bool rename(const char* pathFrom, const char* pathTo) = 0; + virtual bool remove(const char* path) = 0; + virtual bool mkdir(const char* path) = 0; + virtual bool rmdir(const char* path) = 0; + void mountpoint(const char*); + const char* mountpoint(); }; -} // namespace fs +} // namespace fs -#endif //FSIMPL_H +#endif //FSIMPL_H diff --git a/libraries/FS/src/vfs_api.cpp b/libraries/FS/src/vfs_api.cpp index 1dd8da94ac9..71f645cb55a 100644 --- a/libraries/FS/src/vfs_api.cpp +++ b/libraries/FS/src/vfs_api.cpp @@ -18,558 +18,520 @@ using namespace fs; #define DEFAULT_FILE_BUFFER_SIZE 4096 -FileImplPtr VFSImpl::open(const char* fpath, const char* mode, const bool create) -{ - if(!_mountpoint) { - log_e("File system is not mounted"); - return FileImplPtr(); - } +FileImplPtr VFSImpl::open(const char *fpath, const char *mode, const bool create) { + if (!_mountpoint) { + log_e("File system is not mounted"); + return FileImplPtr(); + } - if(!fpath || fpath[0] != '/') { - log_e("%s does not start with /", fpath); - return FileImplPtr(); - } + if (!fpath || fpath[0] != '/') { + log_e("%s does not start with /", fpath); + return FileImplPtr(); + } - char * temp = (char *)malloc(strlen(fpath)+strlen(_mountpoint)+2); - if(!temp) { - log_e("malloc failed"); - return FileImplPtr(); - } + char *temp = (char *)malloc(strlen(fpath) + strlen(_mountpoint) + 2); + if (!temp) { + log_e("malloc failed"); + return FileImplPtr(); + } - strcpy(temp, _mountpoint); - strcat(temp, fpath); + strcpy(temp, _mountpoint); + strcat(temp, fpath); - struct stat st; - //file found - if(!stat(temp, &st)) { - free(temp); - if (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)) { - return std::make_shared(this, fpath, mode); - } - log_e("%s has wrong mode 0x%08X", fpath, st.st_mode); - return FileImplPtr(); + struct stat st; + //file found + if (!stat(temp, &st)) { + free(temp); + if (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)) { + return std::make_shared(this, fpath, mode); } + log_e("%s has wrong mode 0x%08X", fpath, st.st_mode); + return FileImplPtr(); + } - //try to open this as directory (might be mount point) - DIR * d = opendir(temp); - if(d) { - closedir(d); - free(temp); - return std::make_shared(this, fpath, mode); - } + //try to open this as directory (might be mount point) + DIR *d = opendir(temp); + if (d) { + closedir(d); + free(temp); + return std::make_shared(this, fpath, mode); + } - //file not found but mode permits file creation without folder creation - if((mode && mode[0] != 'r') && (!create)){ - free(temp); - return std::make_shared(this, fpath, mode); - } + //file not found but mode permits file creation without folder creation + if ((mode && mode[0] != 'r') && (!create)) { + free(temp); + return std::make_shared(this, fpath, mode); + } + + ////file not found but mode permits file creation and folder creation + if ((mode && mode[0] != 'r') && create) { + + char *token; + char *folder = (char *)malloc(strlen(fpath)); + + int start_index = 0; + int end_index = 0; - ////file not found but mode permits file creation and folder creation - if((mode && mode[0] != 'r') && create){ - - char *token; - char *folder = (char *)malloc(strlen(fpath)); - - int start_index = 0; - int end_index = 0; - - token = strchr(fpath+1,'/'); - end_index = (token-fpath); - - while (token != NULL) - { - memcpy(folder,fpath + start_index, end_index-start_index); - folder[end_index-start_index] = '\0'; - - if(!VFSImpl::mkdir(folder)) - { - log_e("Creating folder: %s failed!",folder); - return FileImplPtr(); - } - - token=strchr(token+1,'/'); - if(token != NULL) - { - end_index = (token-fpath); - memset(folder, 0, strlen(folder)); - } - - } - - free(folder); - free(temp); - return std::make_shared(this, fpath, mode); + token = strchr(fpath + 1, '/'); + end_index = (token - fpath); + while (token != NULL) { + memcpy(folder, fpath + start_index, end_index - start_index); + folder[end_index - start_index] = '\0'; + + if (!VFSImpl::mkdir(folder)) { + log_e("Creating folder: %s failed!", folder); + return FileImplPtr(); + } + + token = strchr(token + 1, '/'); + if (token != NULL) { + end_index = (token - fpath); + memset(folder, 0, strlen(folder)); + } } - log_e("%s does not exist, no permits for creation", temp); + free(folder); free(temp); - return FileImplPtr(); -} + return std::make_shared(this, fpath, mode); + } -bool VFSImpl::exists(const char* fpath) -{ - if(!_mountpoint) { - log_e("File system is not mounted"); - return false; - } + log_e("%s does not exist, no permits for creation", temp); + free(temp); + return FileImplPtr(); +} - VFSFileImpl f(this, fpath, "r"); - if(f) { - f.close(); - return true; - } +bool VFSImpl::exists(const char *fpath) { + if (!_mountpoint) { + log_e("File system is not mounted"); return false; + } + + VFSFileImpl f(this, fpath, "r"); + if (f) { + f.close(); + return true; + } + return false; } -bool VFSImpl::rename(const char* pathFrom, const char* pathTo) -{ - if(!_mountpoint) { - log_e("File system is not mounted"); - return false; - } +bool VFSImpl::rename(const char *pathFrom, const char *pathTo) { + if (!_mountpoint) { + log_e("File system is not mounted"); + return false; + } - if(!pathFrom || pathFrom[0] != '/' || !pathTo || pathTo[0] != '/') { - log_e("bad arguments"); - return false; - } - if(!exists(pathFrom)) { - log_e("%s does not exists", pathFrom); - return false; - } - size_t mountpointLen = strlen(_mountpoint); - char * temp1 = (char *)malloc(strlen(pathFrom)+mountpointLen+1); - if(!temp1) { - log_e("malloc failed"); - return false; - } - char * temp2 = (char *)malloc(strlen(pathTo)+mountpointLen+1); - if(!temp2) { - free(temp1); - log_e("malloc failed"); - return false; - } + if (!pathFrom || pathFrom[0] != '/' || !pathTo || pathTo[0] != '/') { + log_e("bad arguments"); + return false; + } + if (!exists(pathFrom)) { + log_e("%s does not exists", pathFrom); + return false; + } + size_t mountpointLen = strlen(_mountpoint); + char *temp1 = (char *)malloc(strlen(pathFrom) + mountpointLen + 1); + if (!temp1) { + log_e("malloc failed"); + return false; + } + char *temp2 = (char *)malloc(strlen(pathTo) + mountpointLen + 1); + if (!temp2) { + free(temp1); + log_e("malloc failed"); + return false; + } - strcpy(temp1, _mountpoint); - strcat(temp1, pathFrom); + strcpy(temp1, _mountpoint); + strcat(temp1, pathFrom); - strcpy(temp2, _mountpoint); - strcat(temp2, pathTo); + strcpy(temp2, _mountpoint); + strcat(temp2, pathTo); - auto rc = ::rename(temp1, temp2); - free(temp1); - free(temp2); - return rc == 0; + auto rc = ::rename(temp1, temp2); + free(temp1); + free(temp2); + return rc == 0; } -bool VFSImpl::remove(const char* fpath) -{ - if(!_mountpoint) { - log_e("File system is not mounted"); - return false; - } +bool VFSImpl::remove(const char *fpath) { + if (!_mountpoint) { + log_e("File system is not mounted"); + return false; + } - if(!fpath || fpath[0] != '/') { - log_e("bad arguments"); - return false; - } + if (!fpath || fpath[0] != '/') { + log_e("bad arguments"); + return false; + } - VFSFileImpl f(this, fpath, "r"); - if(!f || f.isDirectory()) { - if(f) { - f.close(); - } - log_e("%s does not exists or is directory", fpath); - return false; + VFSFileImpl f(this, fpath, "r"); + if (!f || f.isDirectory()) { + if (f) { + f.close(); } - f.close(); + log_e("%s does not exists or is directory", fpath); + return false; + } + f.close(); - char * temp = (char *)malloc(strlen(fpath)+strlen(_mountpoint)+1); - if(!temp) { - log_e("malloc failed"); - return false; - } + char *temp = (char *)malloc(strlen(fpath) + strlen(_mountpoint) + 1); + if (!temp) { + log_e("malloc failed"); + return false; + } - strcpy(temp, _mountpoint); - strcat(temp, fpath); + strcpy(temp, _mountpoint); + strcat(temp, fpath); - auto rc = unlink(temp); - free(temp); - return rc == 0; + auto rc = unlink(temp); + free(temp); + return rc == 0; } -bool VFSImpl::mkdir(const char *fpath) -{ - if(!_mountpoint) { - log_e("File system is not mounted"); - return false; - } +bool VFSImpl::mkdir(const char *fpath) { + if (!_mountpoint) { + log_e("File system is not mounted"); + return false; + } - VFSFileImpl f(this, fpath, "r"); - if(f && f.isDirectory()) { - f.close(); - //log_w("%s already exists", fpath); - return true; - } else if(f) { - f.close(); - log_e("%s is a file", fpath); - return false; - } + VFSFileImpl f(this, fpath, "r"); + if (f && f.isDirectory()) { + f.close(); + //log_w("%s already exists", fpath); + return true; + } else if (f) { + f.close(); + log_e("%s is a file", fpath); + return false; + } - char * temp = (char *)malloc(strlen(fpath)+strlen(_mountpoint)+1); - if(!temp) { - log_e("malloc failed"); - return false; - } + char *temp = (char *)malloc(strlen(fpath) + strlen(_mountpoint) + 1); + if (!temp) { + log_e("malloc failed"); + return false; + } - strcpy(temp, _mountpoint); - strcat(temp, fpath); + strcpy(temp, _mountpoint); + strcat(temp, fpath); - auto rc = ::mkdir(temp, ACCESSPERMS); - free(temp); - return rc == 0; + auto rc = ::mkdir(temp, ACCESSPERMS); + free(temp); + return rc == 0; } -bool VFSImpl::rmdir(const char *fpath) -{ - if(!_mountpoint) { - log_e("File system is not mounted"); - return false; - } +bool VFSImpl::rmdir(const char *fpath) { + if (!_mountpoint) { + log_e("File system is not mounted"); + return false; + } - if (strcmp(_mountpoint, "/spiffs") == 0) { - log_e("rmdir is unnecessary in SPIFFS"); - return false; - } + if (strcmp(_mountpoint, "/spiffs") == 0) { + log_e("rmdir is unnecessary in SPIFFS"); + return false; + } - VFSFileImpl f(this, fpath, "r"); - if(!f || !f.isDirectory()) { - if(f) { - f.close(); - } - log_e("%s does not exists or is a file", fpath); - return false; + VFSFileImpl f(this, fpath, "r"); + if (!f || !f.isDirectory()) { + if (f) { + f.close(); } - f.close(); + log_e("%s does not exists or is a file", fpath); + return false; + } + f.close(); - char * temp = (char *)malloc(strlen(fpath)+strlen(_mountpoint)+1); - if(!temp) { - log_e("malloc failed"); - return false; - } + char *temp = (char *)malloc(strlen(fpath) + strlen(_mountpoint) + 1); + if (!temp) { + log_e("malloc failed"); + return false; + } - strcpy(temp, _mountpoint); - strcat(temp, fpath); + strcpy(temp, _mountpoint); + strcat(temp, fpath); - auto rc = ::rmdir(temp); - free(temp); - return rc == 0; + auto rc = ::rmdir(temp); + free(temp); + return rc == 0; } -VFSFileImpl::VFSFileImpl(VFSImpl* fs, const char* fpath, const char* mode) - : _fs(fs) - , _f(NULL) - , _d(NULL) - , _path(NULL) - , _isDirectory(false) - , _written(false) -{ - char * temp = (char *)malloc(strlen(fpath)+strlen(_fs->_mountpoint)+1); - if(!temp) { - return; - } +VFSFileImpl::VFSFileImpl(VFSImpl *fs, const char *fpath, const char *mode) + : _fs(fs), _f(NULL), _d(NULL), _path(NULL), _isDirectory(false), _written(false) { + char *temp = (char *)malloc(strlen(fpath) + strlen(_fs->_mountpoint) + 1); + if (!temp) { + return; + } - strcpy(temp, _fs->_mountpoint); - strcat(temp, fpath); + strcpy(temp, _fs->_mountpoint); + strcat(temp, fpath); - _path = strdup(fpath); - if(!_path) { - log_e("strdup(%s) failed", fpath); - free(temp); - return; - } + _path = strdup(fpath); + if (!_path) { + log_e("strdup(%s) failed", fpath); + free(temp); + return; + } - if(!stat(temp, &_stat)) { - //file found - if (S_ISREG(_stat.st_mode)) { - _isDirectory = false; - _f = fopen(temp, mode); - if(!_f) { - log_e("fopen(%s) failed", temp); - } - if(_f && (_stat.st_blksize == 0)) - { - setvbuf(_f,NULL,_IOFBF,DEFAULT_FILE_BUFFER_SIZE); - } - } else if(S_ISDIR(_stat.st_mode)) { - _isDirectory = true; - _d = opendir(temp); - if(!_d) { - log_e("opendir(%s) failed", temp); - } - } else { - log_e("Unknown type 0x%08X for file %s", ((_stat.st_mode)&_IFMT), temp); - } + if (!stat(temp, &_stat)) { + //file found + if (S_ISREG(_stat.st_mode)) { + _isDirectory = false; + _f = fopen(temp, mode); + if (!_f) { + log_e("fopen(%s) failed", temp); + } + if (_f && (_stat.st_blksize == 0)) { + setvbuf(_f, NULL, _IOFBF, DEFAULT_FILE_BUFFER_SIZE); + } + } else if (S_ISDIR(_stat.st_mode)) { + _isDirectory = true; + _d = opendir(temp); + if (!_d) { + log_e("opendir(%s) failed", temp); + } } else { - //file not found - if(!mode || mode[0] == 'r') { - //try to open as directory - _d = opendir(temp); - if(_d) { - _isDirectory = true; - } else { - _isDirectory = false; - //log_w("stat(%s) failed", temp); - } - } else { - //lets create this new file - _isDirectory = false; - _f = fopen(temp, mode); - if(!_f) { - log_e("fopen(%s) failed", temp); - } - if(_f && (_stat.st_blksize == 0)) - { - setvbuf(_f,NULL,_IOFBF,DEFAULT_FILE_BUFFER_SIZE); - } - } - } - free(temp); + log_e("Unknown type 0x%08X for file %s", ((_stat.st_mode) & _IFMT), temp); + } + } else { + //file not found + if (!mode || mode[0] == 'r') { + //try to open as directory + _d = opendir(temp); + if (_d) { + _isDirectory = true; + } else { + _isDirectory = false; + //log_w("stat(%s) failed", temp); + } + } else { + //lets create this new file + _isDirectory = false; + _f = fopen(temp, mode); + if (!_f) { + log_e("fopen(%s) failed", temp); + } + if (_f && (_stat.st_blksize == 0)) { + setvbuf(_f, NULL, _IOFBF, DEFAULT_FILE_BUFFER_SIZE); + } + } + } + free(temp); } -VFSFileImpl::~VFSFileImpl() -{ - close(); +VFSFileImpl::~VFSFileImpl() { + close(); } -void VFSFileImpl::close() -{ - if(_path) { - free(_path); - _path = NULL; - } - if(_isDirectory && _d) { - closedir(_d); - _d = NULL; - _isDirectory = false; - } else if(_f) { - fclose(_f); - _f = NULL; - } +void VFSFileImpl::close() { + if (_path) { + free(_path); + _path = NULL; + } + if (_isDirectory && _d) { + closedir(_d); + _d = NULL; + _isDirectory = false; + } else if (_f) { + fclose(_f); + _f = NULL; + } } -VFSFileImpl::operator bool() -{ - return (_isDirectory && _d != NULL) || _f != NULL; +VFSFileImpl::operator bool() { + return (_isDirectory && _d != NULL) || _f != NULL; } time_t VFSFileImpl::getLastWrite() { - _getStat() ; - return _stat.st_mtime; + _getStat(); + return _stat.st_mtime; } -void VFSFileImpl::_getStat() const -{ - if(!_path) { - return; - } - char * temp = (char *)malloc(strlen(_path)+strlen(_fs->_mountpoint)+1); - if(!temp) { - return; - } - - strcpy(temp, _fs->_mountpoint); - strcat(temp, _path); - - if(!stat(temp, &_stat)) { - _written = false; - } - free(temp); +void VFSFileImpl::_getStat() const { + if (!_path) { + return; + } + char *temp = (char *)malloc(strlen(_path) + strlen(_fs->_mountpoint) + 1); + if (!temp) { + return; + } + + strcpy(temp, _fs->_mountpoint); + strcat(temp, _path); + + if (!stat(temp, &_stat)) { + _written = false; + } + free(temp); } -size_t VFSFileImpl::write(const uint8_t *buf, size_t size) -{ - if(_isDirectory || !_f || !buf || !size) { - return 0; - } - _written = true; - return fwrite(buf, 1, size, _f); +size_t VFSFileImpl::write(const uint8_t *buf, size_t size) { + if (_isDirectory || !_f || !buf || !size) { + return 0; + } + _written = true; + return fwrite(buf, 1, size, _f); } -size_t VFSFileImpl::read(uint8_t* buf, size_t size) -{ - if(_isDirectory || !_f || !buf || !size) { - return 0; - } +size_t VFSFileImpl::read(uint8_t *buf, size_t size) { + if (_isDirectory || !_f || !buf || !size) { + return 0; + } - return fread(buf, 1, size, _f); + return fread(buf, 1, size, _f); } -void VFSFileImpl::flush() -{ - if(_isDirectory || !_f) { - return; - } - fflush(_f); - // workaround for https://github.com/espressif/arduino-esp32/issues/1293 - fsync(fileno(_f)); +void VFSFileImpl::flush() { + if (_isDirectory || !_f) { + return; + } + fflush(_f); + // workaround for https://github.com/espressif/arduino-esp32/issues/1293 + fsync(fileno(_f)); } -bool VFSFileImpl::seek(uint32_t pos, SeekMode mode) -{ - if(_isDirectory || !_f) { - return false; - } - auto rc = fseek(_f, pos, mode); - return rc == 0; +bool VFSFileImpl::seek(uint32_t pos, SeekMode mode) { + if (_isDirectory || !_f) { + return false; + } + auto rc = fseek(_f, pos, mode); + return rc == 0; } -size_t VFSFileImpl::position() const -{ - if(_isDirectory || !_f) { - return 0; - } - return ftell(_f); +size_t VFSFileImpl::position() const { + if (_isDirectory || !_f) { + return 0; + } + return ftell(_f); } -size_t VFSFileImpl::size() const -{ - if(_isDirectory || !_f) { - return 0; - } - if (_written) { - _getStat(); - } - return _stat.st_size; +size_t VFSFileImpl::size() const { + if (_isDirectory || !_f) { + return 0; + } + if (_written) { + _getStat(); + } + return _stat.st_size; } /* * Change size of files internal buffer used for read / write operations. * Need to be called right after opening file before any other operation! */ -bool VFSFileImpl::setBufferSize(size_t size) -{ - if(_isDirectory || !_f) { - return 0; - } - int res = setvbuf(_f,NULL,_IOFBF,size); - return res == 0; +bool VFSFileImpl::setBufferSize(size_t size) { + if (_isDirectory || !_f) { + return 0; + } + int res = setvbuf(_f, NULL, _IOFBF, size); + return res == 0; } -const char* VFSFileImpl::path() const -{ - return (const char*) _path; +const char *VFSFileImpl::path() const { + return (const char *)_path; } -const char* VFSFileImpl::name() const -{ - return pathToFileName(path()); +const char *VFSFileImpl::name() const { + return pathToFileName(path()); } //to implement -boolean VFSFileImpl::isDirectory(void) -{ - return _isDirectory; +boolean VFSFileImpl::isDirectory(void) { + return _isDirectory; } -FileImplPtr VFSFileImpl::openNextFile(const char* mode) -{ - if(!_isDirectory || !_d) { - return FileImplPtr(); - } - struct dirent *file = readdir(_d); - if(file == NULL) { - return FileImplPtr(); - } - if(file->d_type != DT_REG && file->d_type != DT_DIR) { - return openNextFile(mode); - } +FileImplPtr VFSFileImpl::openNextFile(const char *mode) { + if (!_isDirectory || !_d) { + return FileImplPtr(); + } + struct dirent *file = readdir(_d); + if (file == NULL) { + return FileImplPtr(); + } + if (file->d_type != DT_REG && file->d_type != DT_DIR) { + return openNextFile(mode); + } - size_t pathLen = strlen(_path); - size_t fileNameLen = strlen(file->d_name); - char * name = (char *)malloc(pathLen+fileNameLen+2); + size_t pathLen = strlen(_path); + size_t fileNameLen = strlen(file->d_name); + char *name = (char *)malloc(pathLen + fileNameLen + 2); - if(name == NULL) { - return FileImplPtr(); - } + if (name == NULL) { + return FileImplPtr(); + } - strcpy(name, _path); + strcpy(name, _path); - if ((file->d_name[0] != '/') && (_path[pathLen - 1] != '/')) - { - strcat(name, "/"); - } + if ((file->d_name[0] != '/') && (_path[pathLen - 1] != '/')) { + strcat(name, "/"); + } - strcat(name, file->d_name); + strcat(name, file->d_name); - FileImplPtr fileImplPtr = std::make_shared(_fs, name, mode); - free(name); - return fileImplPtr; + FileImplPtr fileImplPtr = std::make_shared(_fs, name, mode); + free(name); + return fileImplPtr; } -boolean VFSFileImpl::seekDir(long position){ - if(!_d){ - return false; - } - seekdir(_d, position); - return true; +boolean VFSFileImpl::seekDir(long position) { + if (!_d) { + return false; + } + seekdir(_d, position); + return true; } -String VFSFileImpl::getNextFileName() -{ - if (!_isDirectory || !_d) { - return ""; - } - struct dirent *file = readdir(_d); - if (file == NULL) { - return ""; - } - if (file->d_type != DT_REG && file->d_type != DT_DIR) { - return ""; - } - String fname = String(file->d_name); - String name = String(_path); - if (!fname.startsWith("/") && !name.endsWith("/")) { - name += "/"; - } - name += fname; - return name; +String VFSFileImpl::getNextFileName() { + if (!_isDirectory || !_d) { + return ""; + } + struct dirent *file = readdir(_d); + if (file == NULL) { + return ""; + } + if (file->d_type != DT_REG && file->d_type != DT_DIR) { + return ""; + } + String fname = String(file->d_name); + String name = String(_path); + if (!fname.startsWith("/") && !name.endsWith("/")) { + name += "/"; + } + name += fname; + return name; } -String VFSFileImpl::getNextFileName(bool *isDir) -{ - if (!_isDirectory || !_d) { - return ""; - } - struct dirent *file = readdir(_d); - if (file == NULL) { - return ""; - } - if (file->d_type != DT_REG && file->d_type != DT_DIR) { - return ""; - } - String fname = String(file->d_name); - String name = String(_path); - if (!fname.startsWith("/") && !name.endsWith("/")) { - name += "/"; - } - name += fname; - - // check entry is a directory - if (isDir) { - *isDir = (file->d_type == DT_DIR); - } - return name; +String VFSFileImpl::getNextFileName(bool *isDir) { + if (!_isDirectory || !_d) { + return ""; + } + struct dirent *file = readdir(_d); + if (file == NULL) { + return ""; + } + if (file->d_type != DT_REG && file->d_type != DT_DIR) { + return ""; + } + String fname = String(file->d_name); + String name = String(_path); + if (!fname.startsWith("/") && !name.endsWith("/")) { + name += "/"; + } + name += fname; + + // check entry is a directory + if (isDir) { + *isDir = (file->d_type == DT_DIR); + } + return name; } -void VFSFileImpl::rewindDirectory(void) -{ - if(!_isDirectory || !_d) { - return; - } - rewinddir(_d); +void VFSFileImpl::rewindDirectory(void) { + if (!_isDirectory || !_d) { + return; + } + rewinddir(_d); } diff --git a/libraries/FS/src/vfs_api.h b/libraries/FS/src/vfs_api.h index ae2a4d0055c..b282910418b 100644 --- a/libraries/FS/src/vfs_api.h +++ b/libraries/FS/src/vfs_api.h @@ -28,55 +28,53 @@ using namespace fs; class VFSFileImpl; -class VFSImpl : public FSImpl -{ +class VFSImpl : public FSImpl { protected: - friend class VFSFileImpl; + friend class VFSFileImpl; public: - FileImplPtr open(const char* path, const char* mode, const bool create) override; - bool exists(const char* path) override; - bool rename(const char* pathFrom, const char* pathTo) override; - bool remove(const char* path) override; - bool mkdir(const char *path) override; - bool rmdir(const char *path) override; + FileImplPtr open(const char* path, const char* mode, const bool create) override; + bool exists(const char* path) override; + bool rename(const char* pathFrom, const char* pathTo) override; + bool remove(const char* path) override; + bool mkdir(const char* path) override; + bool rmdir(const char* path) override; }; -class VFSFileImpl : public FileImpl -{ +class VFSFileImpl : public FileImpl { protected: - VFSImpl* _fs; - FILE * _f; - DIR * _d; - char * _path; - bool _isDirectory; - mutable struct stat _stat; - mutable bool _written; + VFSImpl* _fs; + FILE* _f; + DIR* _d; + char* _path; + bool _isDirectory; + mutable struct stat _stat; + mutable bool _written; - void _getStat() const; + void _getStat() const; public: - VFSFileImpl(VFSImpl* fs, const char* path, const char* mode); - ~VFSFileImpl() override; - size_t write(const uint8_t *buf, size_t size) override; - size_t read(uint8_t* buf, size_t size) override; - void flush() override; - bool seek(uint32_t pos, SeekMode mode) override; - size_t position() const override; - size_t size() const override; - bool setBufferSize(size_t size); - void close() override; - const char* path() const override; - const char* name() const override; - time_t getLastWrite() override; - boolean isDirectory(void) override; - boolean seekDir(long position) override; - String getNextFileName(void) override; - String getNextFileName(bool *isDir) override; - FileImplPtr openNextFile(const char* mode) override; - void rewindDirectory(void) override; - operator bool(); + VFSFileImpl(VFSImpl* fs, const char* path, const char* mode); + ~VFSFileImpl() override; + size_t write(const uint8_t* buf, size_t size) override; + size_t read(uint8_t* buf, size_t size) override; + void flush() override; + bool seek(uint32_t pos, SeekMode mode) override; + size_t position() const override; + size_t size() const override; + bool setBufferSize(size_t size); + void close() override; + const char* path() const override; + const char* name() const override; + time_t getLastWrite() override; + boolean isDirectory(void) override; + boolean seekDir(long position) override; + String getNextFileName(void) override; + String getNextFileName(bool* isDir) override; + FileImplPtr openNextFile(const char* mode) override; + void rewindDirectory(void) override; + operator bool(); }; #endif diff --git a/libraries/HTTPClient/examples/Authorization/Authorization.ino b/libraries/HTTPClient/examples/Authorization/Authorization.ino index 400f93cc8e1..56990956628 100644 --- a/libraries/HTTPClient/examples/Authorization/Authorization.ino +++ b/libraries/HTTPClient/examples/Authorization/Authorization.ino @@ -18,35 +18,34 @@ WiFiMulti wifiMulti; void setup() { - USE_SERIAL.begin(115200); + USE_SERIAL.begin(115200); - USE_SERIAL.println(); - USE_SERIAL.println(); - USE_SERIAL.println(); + USE_SERIAL.println(); + USE_SERIAL.println(); + USE_SERIAL.println(); - for(uint8_t t = 4; t > 0; t--) { - USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); - USE_SERIAL.flush(); - delay(1000); - } - - wifiMulti.addAP("SSID", "PASSWORD"); + for (uint8_t t = 4; t > 0; t--) { + USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); + USE_SERIAL.flush(); + delay(1000); + } + wifiMulti.addAP("SSID", "PASSWORD"); } void loop() { - // wait for WiFi connection - if((wifiMulti.run() == WL_CONNECTED)) { + // wait for WiFi connection + if ((wifiMulti.run() == WL_CONNECTED)) { - HTTPClient http; + HTTPClient http; - USE_SERIAL.print("[HTTP] begin...\n"); - // configure traged server and url + USE_SERIAL.print("[HTTP] begin...\n"); + // configure traged server and url - http.begin("http://user:password@192.168.1.12/test.html"); + http.begin("http://user:password@192.168.1.12/test.html"); - /* + /* // or http.begin("http://192.168.1.12/test.html"); http.setAuthorization("user", "password"); @@ -57,27 +56,26 @@ void loop() { */ - USE_SERIAL.print("[HTTP] GET...\n"); - // start connection and send HTTP header - int httpCode = http.GET(); - - // httpCode will be negative on error - if(httpCode > 0) { - // HTTP header has been send and Server response header has been handled - USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode); + USE_SERIAL.print("[HTTP] GET...\n"); + // start connection and send HTTP header + int httpCode = http.GET(); - // file found at server - if(httpCode == HTTP_CODE_OK) { - String payload = http.getString(); - USE_SERIAL.println(payload); - } - } else { - USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); - } + // httpCode will be negative on error + if (httpCode > 0) { + // HTTP header has been send and Server response header has been handled + USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode); - http.end(); + // file found at server + if (httpCode == HTTP_CODE_OK) { + String payload = http.getString(); + USE_SERIAL.println(payload); + } + } else { + USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); } - delay(10000); -} + http.end(); + } + delay(10000); +} diff --git a/libraries/HTTPClient/examples/BasicHttpClient/BasicHttpClient.ino b/libraries/HTTPClient/examples/BasicHttpClient/BasicHttpClient.ino index 9ee620ab5a5..e8f5be62438 100644 --- a/libraries/HTTPClient/examples/BasicHttpClient/BasicHttpClient.ino +++ b/libraries/HTTPClient/examples/BasicHttpClient/BasicHttpClient.ino @@ -17,85 +17,84 @@ WiFiMulti wifiMulti; /* -const char* ca = \ -"-----BEGIN CERTIFICATE-----\n" \ -"MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/\n" \ -"MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" \ -"DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow\n" \ -"SjELMAkGA1UEBhMCVVMxFjA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M+X+Q7UNKEkROb3N6\n" \ +"KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n" \ "-----END CERTIFICATE-----\n"; */ void setup() { - USE_SERIAL.begin(115200); + USE_SERIAL.begin(115200); - USE_SERIAL.println(); - USE_SERIAL.println(); - USE_SERIAL.println(); + USE_SERIAL.println(); + USE_SERIAL.println(); + USE_SERIAL.println(); - for(uint8_t t = 4; t > 0; t--) { - USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); - USE_SERIAL.flush(); - delay(1000); - } - - wifiMulti.addAP("SSID", "PASSWORD"); + for (uint8_t t = 4; t > 0; t--) { + USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); + USE_SERIAL.flush(); + delay(1000); + } + wifiMulti.addAP("SSID", "PASSWORD"); } void loop() { - // wait for WiFi connection - if((wifiMulti.run() == WL_CONNECTED)) { - - HTTPClient http; - - USE_SERIAL.print("[HTTP] begin...\n"); - // configure traged server and url - //http.begin("https://www.howsmyssl.com/a/check", ca); //HTTPS - http.begin("http://example.com/index.html"); //HTTP - - USE_SERIAL.print("[HTTP] GET...\n"); - // start connection and send HTTP header - int httpCode = http.GET(); - - // httpCode will be negative on error - if(httpCode > 0) { - // HTTP header has been send and Server response header has been handled - USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode); - - // file found at server - if(httpCode == HTTP_CODE_OK) { - String payload = http.getString(); - USE_SERIAL.println(payload); - } - } else { - USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); - } - - http.end(); + // wait for WiFi connection + if ((wifiMulti.run() == WL_CONNECTED)) { + + HTTPClient http; + + USE_SERIAL.print("[HTTP] begin...\n"); + // configure traged server and url + //http.begin("https://www.howsmyssl.com/a/check", ca); //HTTPS + http.begin("http://example.com/index.html"); //HTTP + + USE_SERIAL.print("[HTTP] GET...\n"); + // start connection and send HTTP header + int httpCode = http.GET(); + + // httpCode will be negative on error + if (httpCode > 0) { + // HTTP header has been send and Server response header has been handled + USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode); + + // file found at server + if (httpCode == HTTP_CODE_OK) { + String payload = http.getString(); + USE_SERIAL.println(payload); + } + } else { + USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); } - delay(5000); + http.end(); + } + + delay(5000); } diff --git a/libraries/HTTPClient/examples/BasicHttpsClient/BasicHttpsClient.ino b/libraries/HTTPClient/examples/BasicHttpsClient/BasicHttpsClient.ino index 3d56d2e9651..9c5c6186051 100644 --- a/libraries/HTTPClient/examples/BasicHttpsClient/BasicHttpsClient.ino +++ b/libraries/HTTPClient/examples/BasicHttpsClient/BasicHttpsClient.ino @@ -14,46 +14,46 @@ #include -// This is GandiStandardSSLCA2.pem, the root Certificate Authority that signed -// the server certifcate for the demo server https://jigsaw.w3.org in this +// This is GandiStandardSSLCA2.pem, the root Certificate Authority that signed +// the server certificate for the demo server https://jigsaw.w3.org in this // example. This certificate is valid until Sep 11 23:59:59 2024 GMT -const char* rootCACertificate = \ -"-----BEGIN CERTIFICATE-----\n" \ -"MIIF6TCCA9GgAwIBAgIQBeTcO5Q4qzuFl8umoZhQ4zANBgkqhkiG9w0BAQwFADCB\n" \ -"iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl\n" \ -"cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV\n" \ -"BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTQw\n" \ -"OTEyMDAwMDAwWhcNMjQwOTExMjM1OTU5WjBfMQswCQYDVQQGEwJGUjEOMAwGA1UE\n" \ -"CBMFUGFyaXMxDjAMBgNVBAcTBVBhcmlzMQ4wDAYDVQQKEwVHYW5kaTEgMB4GA1UE\n" \ -"AxMXR2FuZGkgU3RhbmRhcmQgU1NMIENBIDIwggEiMA0GCSqGSIb3DQEBAQ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WbKqaPWMcwO7lWUX\n" \ -"zi8c3ZgTopHJ7qFAbjyY1lzzsiI8Le4bpOHeICQW8owRc5E69vrOJAKHypPstLbI\n" \ -"FhfFcvwnQPYT/pOmnVHvPCvYd1ebjGU6NSU2t7WKY28HJ5OxYI2A25bUeo8tqxyI\n" \ -"yW5+1mUfr13KFj8oRtygNeX56eXVlogMT8a3d2dIhCe2H7Bo26y/d7CQuKLJHDJd\n" \ -"ArolQ4FCR7vY4Y8MDEZf7kYzawMUgtN+zY+vkNaOJH1AQrRqahfGlZfh8jjNp+20\n" \ -"J0CT33KpuMZmYzc4ZCIwojvxuch7yPspOqsactIGEk72gtQjbz7Dk+XYtsDe3CMW\n" \ -"1hMwt6CaDixVBgBwAc/qOR2A24j3pSC4W/0xJmmPLQphgzpHphNULB7j7UTKvGof\n" \ -"KA5R2d4On3XNDgOVyvnFqSot/kGkoUeuDcL5OWYzSlvhhChZbH2UF3bkRYKtcCD9\n" \ -"0m9jqNf6oDP6N8v3smWe2lBvP+Sn845dWDKXcCMu5/3EFZucJ48y7RetWIExKREa\n" \ -"m9T8bJUox04FB6b9HbwZ4ui3uRGKLXASUoWNjDNKD/yZkuBjcNqllEdjB+dYxzFf\n" \ -"BT02Vf6Dsuimrdfp5gJ0iHRc2jTbkNJtUQoj1iM=\n" \ -"-----END CERTIFICATE-----\n"; - -// Not sure if NetworkClientSecure checks the validity date of the certificate. +const char* rootCACertificate = + "-----BEGIN CERTIFICATE-----\n" + "MIIF6TCCA9GgAwIBAgIQBeTcO5Q4qzuFl8umoZhQ4zANBgkqhkiG9w0BAQwFADCB\n" + "iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl\n" + "cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV\n" + "BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTQw\n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VU0VSVHJ1c3RSU0FBZGRUcnVzdENBLmNydDAlBggrBgEFBQcwAYYZ\n" + "aHR0cDovL29jc3AudXNlcnRydXN0LmNvbTANBgkqhkiG9w0BAQwFAAOCAgEAWGf9\n" + "crJq13xhlhl+2UNG0SZ9yFP6ZrBrLafTqlb3OojQO3LJUP33WbKqaPWMcwO7lWUX\n" + "zi8c3ZgTopHJ7qFAbjyY1lzzsiI8Le4bpOHeICQW8owRc5E69vrOJAKHypPstLbI\n" + "FhfFcvwnQPYT/pOmnVHvPCvYd1ebjGU6NSU2t7WKY28HJ5OxYI2A25bUeo8tqxyI\n" + "yW5+1mUfr13KFj8oRtygNeX56eXVlogMT8a3d2dIhCe2H7Bo26y/d7CQuKLJHDJd\n" + "ArolQ4FCR7vY4Y8MDEZf7kYzawMUgtN+zY+vkNaOJH1AQrRqahfGlZfh8jjNp+20\n" + "J0CT33KpuMZmYzc4ZCIwojvxuch7yPspOqsactIGEk72gtQjbz7Dk+XYtsDe3CMW\n" + "1hMwt6CaDixVBgBwAc/qOR2A24j3pSC4W/0xJmmPLQphgzpHphNULB7j7UTKvGof\n" + "KA5R2d4On3XNDgOVyvnFqSot/kGkoUeuDcL5OWYzSlvhhChZbH2UF3bkRYKtcCD9\n" + "0m9jqNf6oDP6N8v3smWe2lBvP+Sn845dWDKXcCMu5/3EFZucJ48y7RetWIExKREa\n" + "m9T8bJUox04FB6b9HbwZ4ui3uRGKLXASUoWNjDNKD/yZkuBjcNqllEdjB+dYxzFf\n" + "BT02Vf6Dsuimrdfp5gJ0iHRc2jTbkNJtUQoj1iM=\n" + "-----END CERTIFICATE-----\n"; + +// Not sure if NetworkClientSecure checks the validity date of the certificate. // Setting clock just to be sure... void setClock() { configTime(0, 0, "pool.ntp.org"); @@ -96,29 +96,29 @@ void setup() { } Serial.println(" connected"); - setClock(); + setClock(); } void loop() { - NetworkClientSecure *client = new NetworkClientSecure; - if(client) { - client -> setCACert(rootCACertificate); + NetworkClientSecure* client = new NetworkClientSecure; + if (client) { + client->setCACert(rootCACertificate); { - // Add a scoping block for HTTPClient https to make sure it is destroyed before NetworkClientSecure *client is + // Add a scoping block for HTTPClient https to make sure it is destroyed before NetworkClientSecure *client is HTTPClient https; - + Serial.print("[HTTPS] begin...\n"); if (https.begin(*client, "https://jigsaw.w3.org/HTTP/connection.html")) { // HTTPS Serial.print("[HTTPS] GET...\n"); // start connection and send HTTP header int httpCode = https.GET(); - + // httpCode will be negative on error if (httpCode > 0) { // HTTP header has been send and Server response header has been handled Serial.printf("[HTTPS] GET... code: %d\n", httpCode); - + // file found at server if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) { String payload = https.getString(); @@ -127,7 +127,7 @@ void loop() { } else { Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str()); } - + https.end(); } else { Serial.printf("[HTTPS] Unable to connect\n"); @@ -135,7 +135,7 @@ void loop() { // End extra scoping block } - + delete client; } else { Serial.println("Unable to create client"); diff --git a/libraries/HTTPClient/examples/HTTPClientEnterprise/HTTPClientEnterprise.ino b/libraries/HTTPClient/examples/HTTPClientEnterprise/HTTPClientEnterprise.ino index c6b9e7d36ab..390bc32d490 100644 --- a/libraries/HTTPClient/examples/HTTPClientEnterprise/HTTPClientEnterprise.ino +++ b/libraries/HTTPClient/examples/HTTPClientEnterprise/HTTPClientEnterprise.ino @@ -5,39 +5,39 @@ /*|----------------------------------------------------------|*/ #include #include -#if __has_include ("esp_eap_client.h") +#if __has_include("esp_eap_client.h") #include "esp_eap_client.h" #else #include "esp_wpa2.h" #endif #include -#define EAP_IDENTITY "identity" //if connecting from another corporation, use identity@organisation.domain in Eduroam -#define EAP_PASSWORD "password" //your Eduroam password -const char* ssid = "eduroam"; // Eduroam SSID +#define EAP_IDENTITY "identity" //if connecting from another corporation, use identity@organization.domain in Eduroam +#define EAP_PASSWORD "password" //your Eduroam password +const char *ssid = "eduroam"; // Eduroam SSID int counter = 0; -const char* test_root_ca= \ -"-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rgT1eXkIoyQY/Esr\n" \ -"hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg\n" \ -"06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF\n" \ -"PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls\n" \ -"YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk\n" \ -"CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=\n" \ -"-----END CERTIFICATE-----\n"; +const char *test_root_ca = + "-----BEGIN CERTIFICATE-----\n" + "MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh\n" + "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" + "d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD\n" + "QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT\n" + "MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n" + "b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG\n" + "9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB\n" + "CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97\n" + "nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt\n" + "43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P\n" + "T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4\n" + "gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO\n" + "BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR\n" + "TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw\n" + "DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr\n" + "hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg\n" + "06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF\n" + "PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls\n" + "YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk\n" + "CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=\n" + "-----END CERTIFICATE-----\n"; void setup() { Serial.begin(115200); delay(10); @@ -45,64 +45,64 @@ void setup() { Serial.print("Connecting to network: "); Serial.println(ssid); WiFi.disconnect(true); //disconnect form wifi to set new wifi connection - WiFi.mode(WIFI_STA); //init wifi mode -#if __has_include ("esp_eap_client.h") - esp_eap_client_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide identity - esp_eap_client_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username - esp_eap_client_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password + WiFi.mode(WIFI_STA); //init wifi mode +#if __has_include("esp_eap_client.h") + esp_eap_client_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide identity + esp_eap_client_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username + esp_eap_client_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password esp_wifi_sta_enterprise_enable(); #else - esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide identity - esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username --> identity and username is same - esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password + esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide identity + esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username --> identity and username is same + esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password esp_wifi_sta_wpa2_ent_enable(); #endif - WiFi.begin(ssid); //connect to wifi + WiFi.begin(ssid); //connect to wifi while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); counter++; - if(counter>=60){ //after 30 seconds timeout - reset board + if (counter >= 60) { //after 30 seconds timeout - reset board ESP.restart(); } } Serial.println(""); Serial.println("WiFi connected"); - Serial.println("IP address set: "); - Serial.println(WiFi.localIP()); //print LAN IP + Serial.println("IP address set: "); + Serial.println(WiFi.localIP()); //print LAN IP } void loop() { - if (WiFi.status() == WL_CONNECTED) { //if we are connected to Eduroam network - counter = 0; //reset counter - Serial.println("Wifi is still connected with IP: "); - Serial.println(WiFi.localIP()); //inform user about his IP address - }else if (WiFi.status() != WL_CONNECTED) { //if we lost connection, retry - WiFi.begin(ssid); + if (WiFi.status() == WL_CONNECTED) { //if we are connected to Eduroam network + counter = 0; //reset counter + Serial.println("Wifi is still connected with IP: "); + Serial.println(WiFi.localIP()); //inform user about his IP address + } else if (WiFi.status() != WL_CONNECTED) { //if we lost connection, retry + WiFi.begin(ssid); } - while (WiFi.status() != WL_CONNECTED) { //during lost connection, print dots + while (WiFi.status() != WL_CONNECTED) { //during lost connection, print dots delay(500); Serial.print("."); counter++; - if(counter>=60){ //30 seconds timeout - reset board - ESP.restart(); + if (counter >= 60) { //30 seconds timeout - reset board + ESP.restart(); } } Serial.print("Connecting to website: "); - HTTPClient http; - http.begin("https://arduino.php5.sk/rele/rele1.txt", test_root_ca); //HTTPS example connection - //http.begin("http://www.arduino.php5.sk/rele/rele1.txt"); //HTTP example connection - //if uncomment HTTP example, you can comment root CA certificate too! - int httpCode = http.GET(); - if(httpCode > 0) { - Serial.printf("[HTTP] GET... code: %d\n", httpCode); - //file found at server --> on unsucessful connection code will be -1 - if(httpCode == HTTP_CODE_OK) { - String payload = http.getString(); - Serial.println(payload); - } - }else{ - Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); - } - http.end(); + HTTPClient http; + http.begin("https://arduino.php5.sk/rele/rele1.txt", test_root_ca); //HTTPS example connection + //http.begin("http://www.arduino.php5.sk/rele/rele1.txt"); //HTTP example connection + //if uncomment HTTP example, you can comment root CA certificate too! + int httpCode = http.GET(); + if (httpCode > 0) { + Serial.printf("[HTTP] GET... code: %d\n", httpCode); + //file found at server --> on unsuccessful connection code will be -1 + if (httpCode == HTTP_CODE_OK) { + String payload = http.getString(); + Serial.println(payload); + } + } else { + Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); + } + http.end(); delay(2000); } diff --git a/libraries/HTTPClient/examples/ReuseConnection/ReuseConnection.ino b/libraries/HTTPClient/examples/ReuseConnection/ReuseConnection.ino index d3bcefbeb17..7bb1f9a5f11 100644 --- a/libraries/HTTPClient/examples/ReuseConnection/ReuseConnection.ino +++ b/libraries/HTTPClient/examples/ReuseConnection/ReuseConnection.ino @@ -21,48 +21,45 @@ HTTPClient http; void setup() { - USE_SERIAL.begin(115200); + USE_SERIAL.begin(115200); - USE_SERIAL.println(); - USE_SERIAL.println(); - USE_SERIAL.println(); + USE_SERIAL.println(); + USE_SERIAL.println(); + USE_SERIAL.println(); - for(uint8_t t = 4; t > 0; t--) { - USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); - USE_SERIAL.flush(); - delay(1000); - } + for (uint8_t t = 4; t > 0; t--) { + USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); + USE_SERIAL.flush(); + delay(1000); + } - wifiMulti.addAP("SSID", "PASSWORD"); + wifiMulti.addAP("SSID", "PASSWORD"); - // allow reuse (if server supports it) - http.setReuse(true); + // allow reuse (if server supports it) + http.setReuse(true); } void loop() { - // wait for WiFi connection - if((wifiMulti.run() == WL_CONNECTED)) { - - http.begin("http://192.168.1.12/test.html"); - //http.begin("192.168.1.12", 80, "/test.html"); - - int httpCode = http.GET(); - if(httpCode > 0) { - USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode); - - // file found at server - if(httpCode == HTTP_CODE_OK) { - http.writeToStream(&USE_SERIAL); - } - } else { - USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); - } - - http.end(); + // wait for WiFi connection + if ((wifiMulti.run() == WL_CONNECTED)) { + + http.begin("http://192.168.1.12/test.html"); + //http.begin("192.168.1.12", 80, "/test.html"); + + int httpCode = http.GET(); + if (httpCode > 0) { + USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode); + + // file found at server + if (httpCode == HTTP_CODE_OK) { + http.writeToStream(&USE_SERIAL); + } + } else { + USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); } - delay(1000); -} - - + http.end(); + } + delay(1000); +} diff --git a/libraries/HTTPClient/examples/StreamHttpClient/StreamHttpClient.ino b/libraries/HTTPClient/examples/StreamHttpClient/StreamHttpClient.ino index 823702ad770..cae3d5ee3d4 100644 --- a/libraries/HTTPClient/examples/StreamHttpClient/StreamHttpClient.ino +++ b/libraries/HTTPClient/examples/StreamHttpClient/StreamHttpClient.ino @@ -18,83 +18,80 @@ WiFiMulti wifiMulti; void setup() { - USE_SERIAL.begin(115200); + USE_SERIAL.begin(115200); - USE_SERIAL.println(); - USE_SERIAL.println(); - USE_SERIAL.println(); + USE_SERIAL.println(); + USE_SERIAL.println(); + USE_SERIAL.println(); - for(uint8_t t = 4; t > 0; t--) { - USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); - USE_SERIAL.flush(); - delay(1000); - } - - wifiMulti.addAP("SSID", "PASSWORD"); + for (uint8_t t = 4; t > 0; t--) { + USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); + USE_SERIAL.flush(); + delay(1000); + } + wifiMulti.addAP("SSID", "PASSWORD"); } void loop() { - // wait for WiFi connection - if((wifiMulti.run() == WL_CONNECTED)) { - - HTTPClient http; + // wait for WiFi connection + if ((wifiMulti.run() == WL_CONNECTED)) { - USE_SERIAL.print("[HTTP] begin...\n"); + HTTPClient http; - // configure server and url - http.begin("http://192.168.1.12/test.html"); - //http.begin("192.168.1.12", 80, "/test.html"); + USE_SERIAL.print("[HTTP] begin...\n"); - USE_SERIAL.print("[HTTP] GET...\n"); - // start connection and send HTTP header - int httpCode = http.GET(); - if(httpCode > 0) { - // HTTP header has been send and Server response header has been handled - USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode); + // configure server and url + http.begin("http://192.168.1.12/test.html"); + //http.begin("192.168.1.12", 80, "/test.html"); - // file found at server - if(httpCode == HTTP_CODE_OK) { + USE_SERIAL.print("[HTTP] GET...\n"); + // start connection and send HTTP header + int httpCode = http.GET(); + if (httpCode > 0) { + // HTTP header has been send and Server response header has been handled + USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode); - // get length of document (is -1 when Server sends no Content-Length header) - int len = http.getSize(); + // file found at server + if (httpCode == HTTP_CODE_OK) { - // create buffer for read - uint8_t buff[128] = { 0 }; + // get length of document (is -1 when Server sends no Content-Length header) + int len = http.getSize(); - // get tcp stream - NetworkClient * stream = http.getStreamPtr(); + // create buffer for read + uint8_t buff[128] = { 0 }; - // read all data from server - while(http.connected() && (len > 0 || len == -1)) { - // get available data size - size_t size = stream->available(); + // get tcp stream + NetworkClient* stream = http.getStreamPtr(); - if(size) { - // read up to 128 byte - int c = stream->readBytes(buff, ((size > sizeof(buff)) ? sizeof(buff) : size)); + // read all data from server + while (http.connected() && (len > 0 || len == -1)) { + // get available data size + size_t size = stream->available(); - // write it to Serial - USE_SERIAL.write(buff, c); + if (size) { + // read up to 128 byte + int c = stream->readBytes(buff, ((size > sizeof(buff)) ? sizeof(buff) : size)); - if(len > 0) { - len -= c; - } - } - delay(1); - } - - USE_SERIAL.println(); - USE_SERIAL.print("[HTTP] connection closed or file end.\n"); + // write it to Serial + USE_SERIAL.write(buff, c); + if (len > 0) { + len -= c; } - } else { - USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); + } + delay(1); } - http.end(); + USE_SERIAL.println(); + USE_SERIAL.print("[HTTP] connection closed or file end.\n"); + } + } else { + USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); } - delay(10000); -} + http.end(); + } + delay(10000); +} diff --git a/libraries/HTTPClient/src/HTTPClient.cpp b/libraries/HTTPClient/src/HTTPClient.cpp index d20ad6570c3..b6a5d49cbbd 100644 --- a/libraries/HTTPClient/src/HTTPClient.cpp +++ b/libraries/HTTPClient/src/HTTPClient.cpp @@ -6,8 +6,8 @@ * * Copyright (c) 2015 Markus Sattler. All rights reserved. * This file is part of the HTTPClient for Arduino. - * Port to ESP32 by Evandro Luis Copercini (2017), - * changed fingerprints to CA verification. + * Port to ESP32 by Evandro Luis Copercini (2017), + * changed fingerprints to CA verification. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -27,7 +27,7 @@ */ #include -#include +#include #ifdef HTTPCLIENT_1_1_COMPATIBLE #include @@ -43,88 +43,77 @@ #include #ifdef HTTPCLIENT_1_1_COMPATIBLE -class TransportTraits -{ +class TransportTraits { public: - virtual ~TransportTraits() - { - } + virtual ~TransportTraits() { + } - virtual std::unique_ptr create() - { - return std::unique_ptr(new NetworkClient()); - } + virtual std::unique_ptr create() { + return std::unique_ptr(new NetworkClient()); + } - virtual bool verify(NetworkClient& client, const char* host) - { - return true; - } + virtual bool verify(NetworkClient& client, const char* host) { + return true; + } }; -class TLSTraits : public TransportTraits -{ +class TLSTraits : public TransportTraits { public: - TLSTraits(const char* CAcert, const char* clicert = nullptr, const char* clikey = nullptr) : - _cacert(CAcert), _clicert(clicert), _clikey(clikey) - { - } - - std::unique_ptr create() override - { - return std::unique_ptr(new NetworkClientSecure()); - } - - bool verify(NetworkClient& client, const char* host) override - { - NetworkClientSecure& wcs = static_cast(client); - if (_cacert == nullptr) { - wcs.setInsecure(); - } else { - wcs.setCACert(_cacert); - wcs.setCertificate(_clicert); - wcs.setPrivateKey(_clikey); - } - return true; + TLSTraits(const char* CAcert, const char* clicert = nullptr, const char* clikey = nullptr) + : _cacert(CAcert), _clicert(clicert), _clikey(clikey) { + } + + std::unique_ptr create() override { + return std::unique_ptr(new NetworkClientSecure()); + } + + bool verify(NetworkClient& client, const char* host) override { + NetworkClientSecure& wcs = static_cast(client); + if (_cacert == nullptr) { + wcs.setInsecure(); + } else { + wcs.setCACert(_cacert); + wcs.setCertificate(_clicert); + wcs.setPrivateKey(_clikey); } + return true; + } protected: - const char* _cacert; - const char* _clicert; - const char* _clikey; + const char* _cacert; + const char* _clicert; + const char* _clikey; }; -#endif // HTTPCLIENT_1_1_COMPATIBLE +#endif // HTTPCLIENT_1_1_COMPATIBLE /** * constructor */ -HTTPClient::HTTPClient() -{ +HTTPClient::HTTPClient() { } /** * destructor */ -HTTPClient::~HTTPClient() -{ - if(_client) { - _client->stop(); - } - if(_currentHeaders) { - delete[] _currentHeaders; - } - if(_tcpDeprecated) { - _tcpDeprecated.reset(nullptr); - } - if(_transportTraits) { - _transportTraits.reset(nullptr); - } +HTTPClient::~HTTPClient() { + if (_client) { + _client->stop(); + } + if (_currentHeaders) { + delete[] _currentHeaders; + } + if (_tcpDeprecated) { + _tcpDeprecated.reset(nullptr); + } + if (_transportTraits) { + _transportTraits.reset(nullptr); + } } -void HTTPClient::clear() -{ - _returnCode = 0; - _size = -1; - _headers = ""; +void HTTPClient::clear() { + _returnCode = 0; + _size = -1; + _headers = ""; } @@ -135,33 +124,33 @@ void HTTPClient::clear() * @param https bool * @return success bool */ -bool HTTPClient::begin(NetworkClient &client, String url) { +bool HTTPClient::begin(NetworkClient& client, String url) { #ifdef HTTPCLIENT_1_1_COMPATIBLE - if(_tcpDeprecated) { - log_d("mix up of new and deprecated api"); - _canReuse = false; - end(); - } + if (_tcpDeprecated) { + log_d("mix up of new and deprecated api"); + _canReuse = false; + end(); + } #endif - _client = &client; + _client = &client; - // check for : (http: or https:) - int index = url.indexOf(':'); - if(index < 0) { - log_d("failed to parse protocol"); - return false; - } + // check for : (http: or https:) + int index = url.indexOf(':'); + if (index < 0) { + log_d("failed to parse protocol"); + return false; + } - String protocol = url.substring(0, index); - if(protocol != "http" && protocol != "https") { - log_d("unknown protocol '%s'", protocol.c_str()); - return false; - } + String protocol = url.substring(0, index); + if (protocol != "http" && protocol != "https") { + log_d("unknown protocol '%s'", protocol.c_str()); + return false; + } - _port = (protocol == "https" ? 443 : 80); - _secure = (protocol == "https"); - return beginInternal(url, protocol.c_str()); + _port = (protocol == "https" ? 443 : 80); + _secure = (protocol == "https"); + return beginInternal(url, protocol.c_str()); } @@ -174,205 +163,197 @@ bool HTTPClient::begin(NetworkClient &client, String url) { * @param https bool * @return success bool */ -bool HTTPClient::begin(NetworkClient &client, String host, uint16_t port, String uri, bool https) -{ +bool HTTPClient::begin(NetworkClient& client, String host, uint16_t port, String uri, bool https) { #ifdef HTTPCLIENT_1_1_COMPATIBLE - if(_tcpDeprecated) { - log_d("mix up of new and deprecated api"); - _canReuse = false; - end(); - } + if (_tcpDeprecated) { + log_d("mix up of new and deprecated api"); + _canReuse = false; + end(); + } #endif - _client = &client; + _client = &client; - clear(); - _host = host; - _port = port; - _uri = uri; - _protocol = (https ? "https" : "http"); - _secure = https; - return true; + clear(); + _host = host; + _port = port; + _uri = uri; + _protocol = (https ? "https" : "http"); + _secure = https; + return true; } #ifdef HTTPCLIENT_1_1_COMPATIBLE -bool HTTPClient::begin(String url, const char* CAcert) -{ - if(_client && !_tcpDeprecated) { - log_d("mix up of new and deprecated api"); - _canReuse = false; - end(); - } - - clear(); - _port = 443; - if (!beginInternal(url, "https")) { - return false; - } - _secure = true; - _transportTraits = TransportTraitsPtr(new TLSTraits(CAcert)); - if(!_transportTraits) { - log_e("could not create transport traits"); - return false; - } +bool HTTPClient::begin(String url, const char* CAcert) { + if (_client && !_tcpDeprecated) { + log_d("mix up of new and deprecated api"); + _canReuse = false; + end(); + } + + clear(); + _port = 443; + if (!beginInternal(url, "https")) { + return false; + } + _secure = true; + _transportTraits = TransportTraitsPtr(new TLSTraits(CAcert)); + if (!_transportTraits) { + log_e("could not create transport traits"); + return false; + } - return true; + return true; } /** * parsing the url for all needed parameters * @param url String */ -bool HTTPClient::begin(String url) -{ - if(_client && !_tcpDeprecated) { - log_d("mix up of new and deprecated api"); - _canReuse = false; - end(); - } - - clear(); - _port = 80; - if (!beginInternal(url, "http")) { - return begin(url, (const char*)NULL); - } - _transportTraits = TransportTraitsPtr(new TransportTraits()); - if(!_transportTraits) { - log_e("could not create transport traits"); - return false; - } +bool HTTPClient::begin(String url) { + if (_client && !_tcpDeprecated) { + log_d("mix up of new and deprecated api"); + _canReuse = false; + end(); + } + + clear(); + _port = 80; + if (!beginInternal(url, "http")) { + return begin(url, (const char*)NULL); + } + _transportTraits = TransportTraitsPtr(new TransportTraits()); + if (!_transportTraits) { + log_e("could not create transport traits"); + return false; + } - return true; + return true; } -#endif // HTTPCLIENT_1_1_COMPATIBLE - -bool HTTPClient::beginInternal(String url, const char* expectedProtocol) -{ - log_v("url: %s", url.c_str()); - - // check for : (http: or https: - int index = url.indexOf(':'); - if(index < 0) { - log_e("failed to parse protocol"); - return false; - } - - _protocol = url.substring(0, index); - if (_protocol != expectedProtocol) { - log_d("unexpected protocol: %s, expected %s", _protocol.c_str(), expectedProtocol); - return false; - } +#endif // HTTPCLIENT_1_1_COMPATIBLE - url.remove(0, (index + 3)); // remove http:// or https:// +bool HTTPClient::beginInternal(String url, const char* expectedProtocol) { + log_v("url: %s", url.c_str()); - index = url.indexOf('/'); - if (index == -1) { - index = url.length(); - url += '/'; - } - String host = url.substring(0, index); - url.remove(0, index); // remove host part - - // get Authorization - index = host.indexOf('@'); - if(index >= 0) { - // auth info - String auth = host.substring(0, index); - host.remove(0, index + 1); // remove auth part including @ - _base64Authorization = base64::encode(auth); - } + // check for : (http: or https: + int index = url.indexOf(':'); + if (index < 0) { + log_e("failed to parse protocol"); + return false; + } - // get port - index = host.indexOf(':'); - String the_host; - if(index >= 0) { - the_host = host.substring(0, index); // hostname - host.remove(0, (index + 1)); // remove hostname + : - _port = host.toInt(); // get port - } else { - the_host = host; - } - if(_host != the_host && connected()){ - log_d("switching host from '%s' to '%s'. disconnecting first", _host.c_str(), the_host.c_str()); - _canReuse = false; - disconnect(true); - } - _host = the_host; - _uri = url; - log_d("protocol: %s, host: %s port: %d url: %s", _protocol.c_str(), _host.c_str(), _port, _uri.c_str()); - return true; + _protocol = url.substring(0, index); + if (_protocol != expectedProtocol) { + log_d("unexpected protocol: %s, expected %s", _protocol.c_str(), expectedProtocol); + return false; + } + + url.remove(0, (index + 3)); // remove http:// or https:// + + index = url.indexOf('/'); + if (index == -1) { + index = url.length(); + url += '/'; + } + String host = url.substring(0, index); + url.remove(0, index); // remove host part + + // get Authorization + index = host.indexOf('@'); + if (index >= 0) { + // auth info + String auth = host.substring(0, index); + host.remove(0, index + 1); // remove auth part including @ + _base64Authorization = base64::encode(auth); + } + + // get port + index = host.indexOf(':'); + String the_host; + if (index >= 0) { + the_host = host.substring(0, index); // hostname + host.remove(0, (index + 1)); // remove hostname + : + _port = host.toInt(); // get port + } else { + the_host = host; + } + if (_host != the_host && connected()) { + log_d("switching host from '%s' to '%s'. disconnecting first", _host.c_str(), the_host.c_str()); + _canReuse = false; + disconnect(true); + } + _host = the_host; + _uri = url; + log_d("protocol: %s, host: %s port: %d url: %s", _protocol.c_str(), _host.c_str(), _port, _uri.c_str()); + return true; } #ifdef HTTPCLIENT_1_1_COMPATIBLE -bool HTTPClient::begin(String host, uint16_t port, String uri) -{ - if(_client && !_tcpDeprecated) { - log_d("mix up of new and deprecated api"); - _canReuse = false; - end(); - } - - clear(); - _host = host; - _port = port; - _uri = uri; - _transportTraits = TransportTraitsPtr(new TransportTraits()); - log_d("host: %s port: %d uri: %s", host.c_str(), port, uri.c_str()); - return true; +bool HTTPClient::begin(String host, uint16_t port, String uri) { + if (_client && !_tcpDeprecated) { + log_d("mix up of new and deprecated api"); + _canReuse = false; + end(); + } + + clear(); + _host = host; + _port = port; + _uri = uri; + _transportTraits = TransportTraitsPtr(new TransportTraits()); + log_d("host: %s port: %d uri: %s", host.c_str(), port, uri.c_str()); + return true; } -bool HTTPClient::begin(String host, uint16_t port, String uri, const char* CAcert) -{ - if(_client && !_tcpDeprecated) { - log_d("mix up of new and deprecated api"); - _canReuse = false; - end(); - } +bool HTTPClient::begin(String host, uint16_t port, String uri, const char* CAcert) { + if (_client && !_tcpDeprecated) { + log_d("mix up of new and deprecated api"); + _canReuse = false; + end(); + } - clear(); - _host = host; - _port = port; - _uri = uri; + clear(); + _host = host; + _port = port; + _uri = uri; - if (strlen(CAcert) == 0) { - return false; - } - _secure = true; - _transportTraits = TransportTraitsPtr(new TLSTraits(CAcert)); - return true; + if (strlen(CAcert) == 0) { + return false; + } + _secure = true; + _transportTraits = TransportTraitsPtr(new TLSTraits(CAcert)); + return true; } -bool HTTPClient::begin(String host, uint16_t port, String uri, const char* CAcert, const char* cli_cert, const char* cli_key) -{ - if(_client && !_tcpDeprecated) { - log_d("mix up of new and deprecated api"); - _canReuse = false; - end(); - } +bool HTTPClient::begin(String host, uint16_t port, String uri, const char* CAcert, const char* cli_cert, const char* cli_key) { + if (_client && !_tcpDeprecated) { + log_d("mix up of new and deprecated api"); + _canReuse = false; + end(); + } - clear(); - _host = host; - _port = port; - _uri = uri; + clear(); + _host = host; + _port = port; + _uri = uri; - if (strlen(CAcert) == 0) { - return false; - } - _secure = true; - _transportTraits = TransportTraitsPtr(new TLSTraits(CAcert, cli_cert, cli_key)); - return true; + if (strlen(CAcert) == 0) { + return false; + } + _secure = true; + _transportTraits = TransportTraitsPtr(new TLSTraits(CAcert, cli_cert, cli_key)); + return true; } -#endif // HTTPCLIENT_1_1_COMPATIBLE +#endif // HTTPCLIENT_1_1_COMPATIBLE /** * end * called after the payload is handled */ -void HTTPClient::end(void) -{ - disconnect(false); - clear(); +void HTTPClient::end(void) { + disconnect(false); + clear(); } @@ -381,32 +362,31 @@ void HTTPClient::end(void) * disconnect * close the TCP socket */ -void HTTPClient::disconnect(bool preserveClient) -{ - if(connected()) { - if(_client->available() > 0) { - log_d("still data in buffer (%d), clean up.\n", _client->available()); - _client->flush(); - } +void HTTPClient::disconnect(bool preserveClient) { + if (connected()) { + if (_client->available() > 0) { + log_d("still data in buffer (%d), clean up.\n", _client->available()); + _client->flush(); + } - if(_reuse && _canReuse) { - log_d("tcp keep open for reuse"); - } else { - log_d("tcp stop"); - _client->stop(); - if(!preserveClient) { - _client = nullptr; + if (_reuse && _canReuse) { + log_d("tcp keep open for reuse"); + } else { + log_d("tcp stop"); + _client->stop(); + if (!preserveClient) { + _client = nullptr; #ifdef HTTPCLIENT_1_1_COMPATIBLE - if(_tcpDeprecated) { - _transportTraits.reset(nullptr); - _tcpDeprecated.reset(nullptr); - } -#endif - } + if (_tcpDeprecated) { + _transportTraits.reset(nullptr); + _tcpDeprecated.reset(nullptr); } - } else { - log_d("tcp is closed\n"); +#endif + } } + } else { + log_d("tcp is closed\n"); + } } @@ -414,12 +394,11 @@ void HTTPClient::disconnect(bool preserveClient) * connected * @return connected status */ -bool HTTPClient::connected() -{ - if(_client) { - return ((_client->available() > 0) || _client->connected()); - } - return false; +bool HTTPClient::connected() { + if (_client) { + return ((_client->available() > 0) || _client->connected()); + } + return false; } /** @@ -427,18 +406,16 @@ bool HTTPClient::connected() * keep-alive * @param reuse bool */ -void HTTPClient::setReuse(bool reuse) -{ - _reuse = reuse; +void HTTPClient::setReuse(bool reuse) { + _reuse = reuse; } /** * set User Agent * @param userAgent const char * */ -void HTTPClient::setUserAgent(const String& userAgent) -{ - _userAgent = userAgent; +void HTTPClient::setUserAgent(const String& userAgent) { + _userAgent = userAgent; } /** @@ -446,76 +423,69 @@ void HTTPClient::setUserAgent(const String& userAgent) * @param user const char * * @param password const char * */ -void HTTPClient::setAuthorization(const char * user, const char * password) -{ - if(user && password) { - String auth = user; - auth += ":"; - auth += password; - _base64Authorization = base64::encode(auth); - } +void HTTPClient::setAuthorization(const char* user, const char* password) { + if (user && password) { + String auth = user; + auth += ":"; + auth += password; + _base64Authorization = base64::encode(auth); + } } /** * set the Authorizatio for the http request * @param auth const char * base64 */ -void HTTPClient::setAuthorization(const char * auth) -{ - if(auth) { - _base64Authorization = auth; - } +void HTTPClient::setAuthorization(const char* auth) { + if (auth) { + _base64Authorization = auth; + } } /** * set the Authorization type for the http request * @param authType const char * */ -void HTTPClient::setAuthorizationType(const char * authType) -{ - if(authType) { - _authorizationType = authType; - } +void HTTPClient::setAuthorizationType(const char* authType) { + if (authType) { + _authorizationType = authType; + } } /** * set the timeout (ms) for establishing a connection to the server * @param connectTimeout int32_t */ -void HTTPClient::setConnectTimeout(int32_t connectTimeout) -{ - _connectTimeout = connectTimeout; +void HTTPClient::setConnectTimeout(int32_t connectTimeout) { + _connectTimeout = connectTimeout; } /** * set the timeout for the TCP connection * @param timeout unsigned int */ -void HTTPClient::setTimeout(uint16_t timeout) -{ - _tcpTimeout = timeout; - if(connected()) { - _client->setTimeout(timeout); - } +void HTTPClient::setTimeout(uint16_t timeout) { + _tcpTimeout = timeout; + if (connected()) { + _client->setTimeout(timeout); + } } /** * use HTTP1.0 * @param use */ -void HTTPClient::useHTTP10(bool useHTTP10) -{ - _useHTTP10 = useHTTP10; - _reuse = !useHTTP10; +void HTTPClient::useHTTP10(bool useHTTP10) { + _useHTTP10 = useHTTP10; + _reuse = !useHTTP10; } /** * send a GET request * @return http code */ -int HTTPClient::GET() -{ - return sendRequest("GET"); +int HTTPClient::GET() { + return sendRequest("GET"); } /** @@ -524,14 +494,12 @@ int HTTPClient::GET() * @param size size_t * @return http code */ -int HTTPClient::POST(uint8_t * payload, size_t size) -{ - return sendRequest("POST", payload, size); +int HTTPClient::POST(uint8_t* payload, size_t size) { + return sendRequest("POST", payload, size); } -int HTTPClient::POST(String payload) -{ - return POST((uint8_t *) payload.c_str(), payload.length()); +int HTTPClient::POST(String payload) { + return POST((uint8_t*)payload.c_str(), payload.length()); } /** @@ -540,14 +508,12 @@ int HTTPClient::POST(String payload) * @param size size_t * @return http code */ -int HTTPClient::PATCH(uint8_t * payload, size_t size) -{ - return sendRequest("PATCH", payload, size); +int HTTPClient::PATCH(uint8_t* payload, size_t size) { + return sendRequest("PATCH", payload, size); } -int HTTPClient::PATCH(String payload) -{ - return PATCH((uint8_t *) payload.c_str(), payload.length()); +int HTTPClient::PATCH(String payload) { + return PATCH((uint8_t*)payload.c_str(), payload.length()); } /** @@ -556,12 +522,12 @@ int HTTPClient::PATCH(String payload) * @param size size_t * @return http code */ -int HTTPClient::PUT(uint8_t * payload, size_t size) { - return sendRequest("PUT", payload, size); +int HTTPClient::PUT(uint8_t* payload, size_t size) { + return sendRequest("PUT", payload, size); } int HTTPClient::PUT(String payload) { - return PUT((uint8_t *) payload.c_str(), payload.length()); + return PUT((uint8_t*)payload.c_str(), payload.length()); } /** @@ -570,9 +536,8 @@ int HTTPClient::PUT(String payload) { * @param payload String data for the message body * @return */ -int HTTPClient::sendRequest(const char * type, String payload) -{ - return sendRequest(type, (uint8_t *) payload.c_str(), payload.length()); +int HTTPClient::sendRequest(const char* type, String payload) { + return sendRequest(type, (uint8_t*)payload.c_str(), payload.length()); } /** @@ -582,128 +547,124 @@ int HTTPClient::sendRequest(const char * type, String payload) * @param size size_t size for the message body if 0 not send * @return -1 if no info or > 0 when Content-Length is set by server */ -int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size) -{ - int code; - bool redirect = false; - uint16_t redirectCount = 0; - do { - // wipe out any existing headers from previous request - for(size_t i = 0; i < _headerKeysCount; i++) { - if (_currentHeaders[i].value.length() > 0) { - _currentHeaders[i].value.clear(); - } - } +int HTTPClient::sendRequest(const char* type, uint8_t* payload, size_t size) { + int code; + bool redirect = false; + uint16_t redirectCount = 0; + do { + // wipe out any existing headers from previous request + for (size_t i = 0; i < _headerKeysCount; i++) { + if (_currentHeaders[i].value.length() > 0) { + _currentHeaders[i].value.clear(); + } + } - log_d("request type: '%s' redirCount: %d\n", type, redirectCount); - - // connect to server - if(!connect()) { - return returnError(HTTPC_ERROR_CONNECTION_REFUSED); - } + log_d("request type: '%s' redirCount: %d\n", type, redirectCount); - if(payload && size > 0) { - addHeader(F("Content-Length"), String(size)); - } + // connect to server + if (!connect()) { + return returnError(HTTPC_ERROR_CONNECTION_REFUSED); + } - // add cookies to header, if present - String cookie_string; - if(generateCookieString(&cookie_string)) { - addHeader("Cookie", cookie_string); - } + if (payload && size > 0) { + addHeader(F("Content-Length"), String(size)); + } - // send Header - if(!sendHeader(type)) { - return returnError(HTTPC_ERROR_SEND_HEADER_FAILED); - } + // add cookies to header, if present + String cookie_string; + if (generateCookieString(&cookie_string)) { + addHeader("Cookie", cookie_string); + } - // send Payload if needed - if(payload && size > 0) { - size_t sent_bytes = 0; - while(sent_bytes < size){ - size_t sent = _client->write(&payload[sent_bytes], size - sent_bytes); - if (sent == 0){ - log_w("Failed to send chunk! Lets wait a bit"); - delay(100); - sent = _client->write(&payload[sent_bytes], size - sent_bytes); - if (sent == 0){ - log_e("Failed to send chunk!"); - break; - } - } - sent_bytes += sent; - } - if(sent_bytes != size){ - return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); - } + // send Header + if (!sendHeader(type)) { + return returnError(HTTPC_ERROR_SEND_HEADER_FAILED); + } + + // send Payload if needed + if (payload && size > 0) { + size_t sent_bytes = 0; + while (sent_bytes < size) { + size_t sent = _client->write(&payload[sent_bytes], size - sent_bytes); + if (sent == 0) { + log_w("Failed to send chunk! Lets wait a bit"); + delay(100); + sent = _client->write(&payload[sent_bytes], size - sent_bytes); + if (sent == 0) { + log_e("Failed to send chunk!"); + break; + } } - - code = handleHeaderResponse(); - log_d("sendRequest code=%d\n", code); - - // Handle redirections as stated in RFC document: - // https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html - // - // Implementing HTTP_CODE_FOUND as redirection with GET method, - // to follow most of existing user agent implementations. - // - redirect = false; - if ( - _followRedirects != HTTPC_DISABLE_FOLLOW_REDIRECTS && - redirectCount < _redirectLimit && - _location.length() > 0 - ) { - switch (code) { - // redirecting using the same method - case HTTP_CODE_MOVED_PERMANENTLY: - case HTTP_CODE_TEMPORARY_REDIRECT: { - if ( - // allow to force redirections on other methods - // (the RFC require user to accept the redirection) - _followRedirects == HTTPC_FORCE_FOLLOW_REDIRECTS || - // allow GET and HEAD methods without force - !strcmp(type, "GET") || - !strcmp(type, "HEAD") - ) { - redirectCount += 1; - log_d("following redirect (the same method): '%s' redirCount: %d\n", _location.c_str(), redirectCount); - if (!setURL(_location)) { - log_d("failed setting URL for redirection\n"); - // no redirection - break; - } - // redirect using the same request method and payload, diffrent URL - redirect = true; - } - break; - } - // redirecting with method dropped to GET or HEAD - // note: it does not need `HTTPC_FORCE_FOLLOW_REDIRECTS` for any method - case HTTP_CODE_FOUND: - case HTTP_CODE_SEE_OTHER: { - redirectCount += 1; - log_d("following redirect (dropped to GET/HEAD): '%s' redirCount: %d\n", _location.c_str(), redirectCount); - if (!setURL(_location)) { - log_d("failed setting URL for redirection\n"); - // no redirection - break; - } - // redirect after changing method to GET/HEAD and dropping payload - type = "GET"; - payload = nullptr; - size = 0; - redirect = true; - break; - } - - default: - break; + sent_bytes += sent; + } + if (sent_bytes != size) { + return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); + } + } + + code = handleHeaderResponse(); + log_d("sendRequest code=%d\n", code); + + // Handle redirections as stated in RFC document: + // https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html + // + // Implementing HTTP_CODE_FOUND as redirection with GET method, + // to follow most of existing user agent implementations. + // + redirect = false; + if ( + _followRedirects != HTTPC_DISABLE_FOLLOW_REDIRECTS && redirectCount < _redirectLimit && _location.length() > 0) { + switch (code) { + // redirecting using the same method + case HTTP_CODE_MOVED_PERMANENTLY: + case HTTP_CODE_TEMPORARY_REDIRECT: + { + if ( + // allow to force redirections on other methods + // (the RFC require user to accept the redirection) + _followRedirects == HTTPC_FORCE_FOLLOW_REDIRECTS || + // allow GET and HEAD methods without force + !strcmp(type, "GET") || !strcmp(type, "HEAD")) { + redirectCount += 1; + log_d("following redirect (the same method): '%s' redirCount: %d\n", _location.c_str(), redirectCount); + if (!setURL(_location)) { + log_d("failed setting URL for redirection\n"); + // no redirection + break; + } + // redirect using the same request method and payload, different URL + redirect = true; } - } - - } while (redirect); - // handle Server Response (Header) - return returnError(code); + break; + } + // redirecting with method dropped to GET or HEAD + // note: it does not need `HTTPC_FORCE_FOLLOW_REDIRECTS` for any method + case HTTP_CODE_FOUND: + case HTTP_CODE_SEE_OTHER: + { + redirectCount += 1; + log_d("following redirect (dropped to GET/HEAD): '%s' redirCount: %d\n", _location.c_str(), redirectCount); + if (!setURL(_location)) { + log_d("failed setting URL for redirection\n"); + // no redirection + break; + } + // redirect after changing method to GET/HEAD and dropping payload + type = "GET"; + payload = nullptr; + size = 0; + redirect = true; + break; + } + + default: + break; + } + } + + } while (redirect); + // handle Server Response (Header) + return returnError(code); } /** @@ -713,180 +674,176 @@ int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size) * @param size size_t size for the message body if 0 not Content-Length is send * @return -1 if no info or > 0 when Content-Length is set by server */ -int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) -{ +int HTTPClient::sendRequest(const char* type, Stream* stream, size_t size) { - if(!stream) { - return returnError(HTTPC_ERROR_NO_STREAM); - } + if (!stream) { + return returnError(HTTPC_ERROR_NO_STREAM); + } - // connect to server - if(!connect()) { - return returnError(HTTPC_ERROR_CONNECTION_REFUSED); - } + // connect to server + if (!connect()) { + return returnError(HTTPC_ERROR_CONNECTION_REFUSED); + } - if(size > 0) { - addHeader("Content-Length", String(size)); - } - - // add cookies to header, if present - String cookie_string; - if(generateCookieString(&cookie_string)) { - addHeader("Cookie", cookie_string); - } + if (size > 0) { + addHeader("Content-Length", String(size)); + } - // send Header - if(!sendHeader(type)) { - return returnError(HTTPC_ERROR_SEND_HEADER_FAILED); - } + // add cookies to header, if present + String cookie_string; + if (generateCookieString(&cookie_string)) { + addHeader("Cookie", cookie_string); + } - int buff_size = HTTP_TCP_TX_BUFFER_SIZE; + // send Header + if (!sendHeader(type)) { + return returnError(HTTPC_ERROR_SEND_HEADER_FAILED); + } - int len = size; - int bytesWritten = 0; + int buff_size = HTTP_TCP_TX_BUFFER_SIZE; - if(len == 0) { - len = -1; - } + int len = size; + int bytesWritten = 0; - // if possible create smaller buffer then HTTP_TCP_TX_BUFFER_SIZE - if((len > 0) && (len < buff_size)) { - buff_size = len; - } + if (len == 0) { + len = -1; + } - // create buffer for read - uint8_t * buff = (uint8_t *) malloc(buff_size); + // if possible create smaller buffer then HTTP_TCP_TX_BUFFER_SIZE + if ((len > 0) && (len < buff_size)) { + buff_size = len; + } - if(buff) { - // read all data from stream and send it to server - while(connected() && (stream->available() > -1) && (len > 0 || len == -1)) { + // create buffer for read + uint8_t* buff = (uint8_t*)malloc(buff_size); - // get available data size - int sizeAvailable = stream->available(); + if (buff) { + // read all data from stream and send it to server + while (connected() && (stream->available() > -1) && (len > 0 || len == -1)) { - if(sizeAvailable) { + // get available data size + int sizeAvailable = stream->available(); - int readBytes = sizeAvailable; + if (sizeAvailable) { - // read only the asked bytes - if(len > 0 && readBytes > len) { - readBytes = len; - } + int readBytes = sizeAvailable; - // not read more the buffer can handle - if(readBytes > buff_size) { - readBytes = buff_size; - } + // read only the asked bytes + if (len > 0 && readBytes > len) { + readBytes = len; + } - // read data - int bytesRead = stream->readBytes(buff, readBytes); + // not read more the buffer can handle + if (readBytes > buff_size) { + readBytes = buff_size; + } - // write it to Stream - int bytesWrite = _client->write((const uint8_t *) buff, bytesRead); - bytesWritten += bytesWrite; + // read data + int bytesRead = stream->readBytes(buff, readBytes); - // are all Bytes a writen to stream ? - if(bytesWrite != bytesRead) { - log_d("short write, asked for %d but got %d retry...", bytesRead, bytesWrite); + // write it to Stream + int bytesWrite = _client->write((const uint8_t*)buff, bytesRead); + bytesWritten += bytesWrite; - // check for write error - if(_client->getWriteError()) { - log_d("stream write error %d", _client->getWriteError()); + // are all Bytes a written to stream ? + if (bytesWrite != bytesRead) { + log_d("short write, asked for %d but got %d retry...", bytesRead, bytesWrite); - //reset write error for retry - _client->clearWriteError(); - } + // check for write error + if (_client->getWriteError()) { + log_d("stream write error %d", _client->getWriteError()); - // some time for the stream - delay(1); + //reset write error for retry + _client->clearWriteError(); + } - int leftBytes = (readBytes - bytesWrite); + // some time for the stream + delay(1); - // retry to send the missed bytes - bytesWrite = _client->write((const uint8_t *) (buff + bytesWrite), leftBytes); - bytesWritten += bytesWrite; + int leftBytes = (readBytes - bytesWrite); - if(bytesWrite != leftBytes) { - // failed again - log_d("short write, asked for %d but got %d failed.", leftBytes, bytesWrite); - free(buff); - return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); - } - } + // retry to send the missed bytes + bytesWrite = _client->write((const uint8_t*)(buff + bytesWrite), leftBytes); + bytesWritten += bytesWrite; - // check for write error - if(_client->getWriteError()) { - log_d("stream write error %d", _client->getWriteError()); - free(buff); - return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); - } + if (bytesWrite != leftBytes) { + // failed again + log_d("short write, asked for %d but got %d failed.", leftBytes, bytesWrite); + free(buff); + return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); + } + } - // count bytes to read left - if(len > 0) { - len -= readBytes; - } + // check for write error + if (_client->getWriteError()) { + log_d("stream write error %d", _client->getWriteError()); + free(buff); + return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); + } - delay(0); - } else { - delay(1); - } + // count bytes to read left + if (len > 0) { + len -= readBytes; } - free(buff); + delay(0); + } else { + delay(1); + } + } - if(size && (int) size != bytesWritten) { - log_d("Stream payload bytesWritten %d and size %d mismatch!.", bytesWritten, size); - log_d("ERROR SEND PAYLOAD FAILED!"); - return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); - } else { - log_d("Stream payload written: %d", bytesWritten); - } + free(buff); + if (size && (int)size != bytesWritten) { + log_d("Stream payload bytesWritten %d and size %d mismatch!.", bytesWritten, size); + log_d("ERROR SEND PAYLOAD FAILED!"); + return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); } else { - log_d("too less ram! need %d", buff_size); - return returnError(HTTPC_ERROR_TOO_LESS_RAM); + log_d("Stream payload written: %d", bytesWritten); } - // handle Server Response (Header) - return returnError(handleHeaderResponse()); + } else { + log_d("too less ram! need %d", buff_size); + return returnError(HTTPC_ERROR_TOO_LESS_RAM); + } + + // handle Server Response (Header) + return returnError(handleHeaderResponse()); } /** * size of message body / payload * @return -1 if no info or > 0 when Content-Length is set by server */ -int HTTPClient::getSize(void) -{ - return _size; +int HTTPClient::getSize(void) { + return _size; } /** * returns the stream of the tcp connection * @return NetworkClient */ -NetworkClient& HTTPClient::getStream(void) -{ - if (connected()) { - return *_client; - } - - log_w("getStream: not connected"); - static NetworkClient empty; - return empty; +NetworkClient& HTTPClient::getStream(void) { + if (connected()) { + return *_client; + } + + log_w("getStream: not connected"); + static NetworkClient empty; + return empty; } /** * returns a pointer to the stream of the tcp connection * @return NetworkClient* */ -NetworkClient* HTTPClient::getStreamPtr(void) -{ - if(connected()) { - return _client; - } +NetworkClient* HTTPClient::getStreamPtr(void) { + if (connected()) { + return _client; + } - log_w("getStreamPtr: not connected"); - return nullptr; + log_w("getStreamPtr: not connected"); + return nullptr; } /** @@ -894,106 +851,104 @@ NetworkClient* HTTPClient::getStreamPtr(void) * @param stream Stream * * @return bytes written ( negative values are error codes ) */ -int HTTPClient::writeToStream(Stream * stream) -{ - - if(!stream) { - return returnError(HTTPC_ERROR_NO_STREAM); - } - - if(!connected()) { - return returnError(HTTPC_ERROR_NOT_CONNECTED); - } - - // get length of document (is -1 when Server sends no Content-Length header) - int len = _size; - int ret = 0; - - if(_transferEncoding == HTTPC_TE_IDENTITY) { - ret = writeToStreamDataBlock(stream, len); - - // have we an error? - if(ret < 0) { - return returnError(ret); +int HTTPClient::writeToStream(Stream* stream) { + + if (!stream) { + return returnError(HTTPC_ERROR_NO_STREAM); + } + + if (!connected()) { + return returnError(HTTPC_ERROR_NOT_CONNECTED); + } + + // get length of document (is -1 when Server sends no Content-Length header) + int len = _size; + int ret = 0; + + if (_transferEncoding == HTTPC_TE_IDENTITY) { + ret = writeToStreamDataBlock(stream, len); + + // have we an error? + if (ret < 0) { + return returnError(ret); + } + } else if (_transferEncoding == HTTPC_TE_CHUNKED) { + int size = 0; + while (1) { + if (!connected()) { + return returnError(HTTPC_ERROR_CONNECTION_LOST); + } + String chunkHeader = _client->readStringUntil('\n'); + + if (chunkHeader.length() <= 0) { + return returnError(HTTPC_ERROR_READ_TIMEOUT); + } + + chunkHeader.trim(); // remove \r + + // read size of chunk + len = (uint32_t)strtol((const char*)chunkHeader.c_str(), NULL, 16); + size += len; + log_v(" read chunk len: %d", len); + + // data left? + if (len > 0) { + int r = writeToStreamDataBlock(stream, len); + if (r < 0) { + // error in writeToStreamDataBlock + return returnError(r); } - } else if(_transferEncoding == HTTPC_TE_CHUNKED) { - int size = 0; - while(1) { - if(!connected()) { - return returnError(HTTPC_ERROR_CONNECTION_LOST); - } - String chunkHeader = _client->readStringUntil('\n'); + ret += r; + } else { - if(chunkHeader.length() <= 0) { - return returnError(HTTPC_ERROR_READ_TIMEOUT); - } + // if no length Header use global chunk size + if (_size <= 0) { + _size = size; + } - chunkHeader.trim(); // remove \r - - // read size of chunk - len = (uint32_t) strtol((const char *) chunkHeader.c_str(), NULL, 16); - size += len; - log_v(" read chunk len: %d", len); - - // data left? - if(len > 0) { - int r = writeToStreamDataBlock(stream, len); - if(r < 0) { - // error in writeToStreamDataBlock - return returnError(r); - } - ret += r; - } else { - - // if no length Header use global chunk size - if(_size <= 0) { - _size = size; - } - - // check if we have write all data out - if(ret != _size) { - return returnError(HTTPC_ERROR_STREAM_WRITE); - } - break; - } + // check if we have write all data out + if (ret != _size) { + return returnError(HTTPC_ERROR_STREAM_WRITE); + } + break; + } - // read trailing \r\n at the end of the chunk - char buf[2]; - auto trailing_seq_len = _client->readBytes((uint8_t*)buf, 2); - if (trailing_seq_len != 2 || buf[0] != '\r' || buf[1] != '\n') { - return returnError(HTTPC_ERROR_READ_TIMEOUT); - } + // read trailing \r\n at the end of the chunk + char buf[2]; + auto trailing_seq_len = _client->readBytes((uint8_t*)buf, 2); + if (trailing_seq_len != 2 || buf[0] != '\r' || buf[1] != '\n') { + return returnError(HTTPC_ERROR_READ_TIMEOUT); + } - delay(0); - } - } else { - return returnError(HTTPC_ERROR_ENCODING); + delay(0); } + } else { + return returnError(HTTPC_ERROR_ENCODING); + } -// end(); - disconnect(true); - return ret; + // end(); + disconnect(true); + return ret; } /** * return all payload as String (may need lot of ram or trigger out of memory!) * @return String */ -String HTTPClient::getString(void) -{ - // _size can be -1 when Server sends no Content-Length header - if(_size > 0 || _size == -1) { - StreamString sstring; - // try to reserve needed memory (noop if _size == -1) - if(sstring.reserve((_size + 1))) { - writeToStream(&sstring); - return sstring; - } else { - log_d("not enough memory to reserve a string! need: %d", (_size + 1)); - } +String HTTPClient::getString(void) { + // _size can be -1 when Server sends no Content-Length header + if (_size > 0 || _size == -1) { + StreamString sstring; + // try to reserve needed memory (noop if _size == -1) + if (sstring.reserve((_size + 1))) { + writeToStream(&sstring); + return sstring; + } else { + log_d("not enough memory to reserve a string! need: %d", (_size + 1)); } + } - return ""; + return ""; } /** @@ -1001,34 +956,33 @@ String HTTPClient::getString(void) * @param error int * @return String */ -String HTTPClient::errorToString(int error) -{ - switch(error) { +String HTTPClient::errorToString(int error) { + switch (error) { case HTTPC_ERROR_CONNECTION_REFUSED: - return F("connection refused"); + return F("connection refused"); case HTTPC_ERROR_SEND_HEADER_FAILED: - return F("send header failed"); + return F("send header failed"); case HTTPC_ERROR_SEND_PAYLOAD_FAILED: - return F("send payload failed"); + return F("send payload failed"); case HTTPC_ERROR_NOT_CONNECTED: - return F("not connected"); + return F("not connected"); case HTTPC_ERROR_CONNECTION_LOST: - return F("connection lost"); + return F("connection lost"); case HTTPC_ERROR_NO_STREAM: - return F("no stream"); + return F("no stream"); case HTTPC_ERROR_NO_HTTP_SERVER: - return F("no HTTP server"); + return F("no HTTP server"); case HTTPC_ERROR_TOO_LESS_RAM: - return F("too less ram"); + return F("too less ram"); case HTTPC_ERROR_ENCODING: - return F("Transfer-Encoding not supported"); + return F("Transfer-Encoding not supported"); case HTTPC_ERROR_STREAM_WRITE: - return F("Stream write error"); + return F("Stream write error"); case HTTPC_ERROR_READ_TIMEOUT: - return F("read Timeout"); + return F("read Timeout"); default: - return String(); - } + return String(); + } } /** @@ -1037,145 +991,134 @@ String HTTPClient::errorToString(int error) * @param value * @param first */ -void HTTPClient::addHeader(const String& name, const String& value, bool first, bool replace) -{ - // not allow set of Header handled by code - if(!name.equalsIgnoreCase(F("Connection")) && - !name.equalsIgnoreCase(F("User-Agent")) && - !name.equalsIgnoreCase(F("Host")) && - !(name.equalsIgnoreCase(F("Authorization")) && _base64Authorization.length())){ - - String headerLine = name; - headerLine += ": "; - - if (replace) { - int headerStart = _headers.indexOf(headerLine); - if (headerStart != -1 && (headerStart == 0 || _headers[headerStart - 1] == '\n')) { - int headerEnd = _headers.indexOf('\n', headerStart); - _headers = _headers.substring(0, headerStart) + _headers.substring(headerEnd + 1); - } - } +void HTTPClient::addHeader(const String& name, const String& value, bool first, bool replace) { + // not allow set of Header handled by code + if (!name.equalsIgnoreCase(F("Connection")) && !name.equalsIgnoreCase(F("User-Agent")) && !name.equalsIgnoreCase(F("Host")) && !(name.equalsIgnoreCase(F("Authorization")) && _base64Authorization.length())) { - headerLine += value; - headerLine += "\r\n"; - if(first) { - _headers = headerLine + _headers; - } else { - _headers += headerLine; - } - } -} + String headerLine = name; + headerLine += ": "; -void HTTPClient::collectHeaders(const char* headerKeys[], const size_t headerKeysCount) -{ - _headerKeysCount = headerKeysCount; - if(_currentHeaders) { - delete[] _currentHeaders; + if (replace) { + int headerStart = _headers.indexOf(headerLine); + if (headerStart != -1 && (headerStart == 0 || _headers[headerStart - 1] == '\n')) { + int headerEnd = _headers.indexOf('\n', headerStart); + _headers = _headers.substring(0, headerStart) + _headers.substring(headerEnd + 1); + } } - _currentHeaders = new RequestArgument[_headerKeysCount]; - for(size_t i = 0; i < _headerKeysCount; i++) { - _currentHeaders[i].key = headerKeys[i]; + + headerLine += value; + headerLine += "\r\n"; + if (first) { + _headers = headerLine + _headers; + } else { + _headers += headerLine; } + } } -String HTTPClient::header(const char* name) -{ - for(size_t i = 0; i < _headerKeysCount; ++i) { - if(_currentHeaders[i].key.equalsIgnoreCase(name)) { - return _currentHeaders[i].value; - } - } - return String(); +void HTTPClient::collectHeaders(const char* headerKeys[], const size_t headerKeysCount) { + _headerKeysCount = headerKeysCount; + if (_currentHeaders) { + delete[] _currentHeaders; + } + _currentHeaders = new RequestArgument[_headerKeysCount]; + for (size_t i = 0; i < _headerKeysCount; i++) { + _currentHeaders[i].key = headerKeys[i]; + } } -String HTTPClient::header(size_t i) -{ - if(i < _headerKeysCount) { - return _currentHeaders[i].value; +String HTTPClient::header(const char* name) { + for (size_t i = 0; i < _headerKeysCount; ++i) { + if (_currentHeaders[i].key.equalsIgnoreCase(name)) { + return _currentHeaders[i].value; } - return String(); + } + return String(); } -String HTTPClient::headerName(size_t i) -{ - if(i < _headerKeysCount) { - return _currentHeaders[i].key; - } - return String(); +String HTTPClient::header(size_t i) { + if (i < _headerKeysCount) { + return _currentHeaders[i].value; + } + return String(); } -int HTTPClient::headers() -{ - return _headerKeysCount; +String HTTPClient::headerName(size_t i) { + if (i < _headerKeysCount) { + return _currentHeaders[i].key; + } + return String(); } -bool HTTPClient::hasHeader(const char* name) -{ - for(size_t i = 0; i < _headerKeysCount; ++i) { - if((_currentHeaders[i].key.equalsIgnoreCase(name)) && (_currentHeaders[i].value.length() > 0)) { - return true; - } +int HTTPClient::headers() { + return _headerKeysCount; +} + +bool HTTPClient::hasHeader(const char* name) { + for (size_t i = 0; i < _headerKeysCount; ++i) { + if ((_currentHeaders[i].key.equalsIgnoreCase(name)) && (_currentHeaders[i].value.length() > 0)) { + return true; } - return false; + } + return false; } /** * init TCP connection and handle ssl verify if needed * @return true if connection is ok */ -bool HTTPClient::connect(void) -{ - if(connected()) { - if(_reuse) { - log_d("already connected, reusing connection"); - } else { - log_d("already connected, try reuse!"); - } - while(_client->available() > 0) { - _client->read(); - } - return true; +bool HTTPClient::connect(void) { + if (connected()) { + if (_reuse) { + log_d("already connected, reusing connection"); + } else { + log_d("already connected, try reuse!"); } + while (_client->available() > 0) { + _client->read(); + } + return true; + } #ifdef HTTPCLIENT_1_1_COMPATIBLE - if(_transportTraits && !_client) { - _tcpDeprecated = _transportTraits->create(); - if(!_tcpDeprecated) { - log_e("failed to create client"); - return false; - } - _client = _tcpDeprecated.get(); - } + if (_transportTraits && !_client) { + _tcpDeprecated = _transportTraits->create(); + if (!_tcpDeprecated) { + log_e("failed to create client"); + return false; + } + _client = _tcpDeprecated.get(); + } #endif - if (!_client) { - log_d("HTTPClient::begin was not called or returned error"); - return false; - } + if (!_client) { + log_d("HTTPClient::begin was not called or returned error"); + return false; + } #ifdef HTTPCLIENT_1_1_COMPATIBLE - if (_tcpDeprecated && !_transportTraits->verify(*_client, _host.c_str())) { - log_d("transport level verify failed"); - _client->stop(); - return false; - } + if (_tcpDeprecated && !_transportTraits->verify(*_client, _host.c_str())) { + log_d("transport level verify failed"); + _client->stop(); + return false; + } #endif - if(!_client->connect(_host.c_str(), _port, _connectTimeout)) { - log_d("failed connect to %s:%u", _host.c_str(), _port); - return false; - } + if (!_client->connect(_host.c_str(), _port, _connectTimeout)) { + log_d("failed connect to %s:%u", _host.c_str(), _port); + return false; + } - // set Timeout for NetworkClient and for Stream::readBytesUntil() and Stream::readStringUntil() - _client->setTimeout(_tcpTimeout); + // set Timeout for NetworkClient and for Stream::readBytesUntil() and Stream::readStringUntil() + _client->setTimeout(_tcpTimeout); - log_d(" connected to %s:%u", _host.c_str(), _port); + log_d(" connected to %s:%u", _host.c_str(), _port); -/* + /* #ifdef ESP8266 _client->setNoDelay(true); #endif */ - return connected(); + return connected(); } /** @@ -1183,529 +1126,510 @@ bool HTTPClient::connect(void) * @param type (GET, POST, ...) * @return status */ -bool HTTPClient::sendHeader(const char * type) -{ - if(!connected()) { - return false; - } - - String header = String(type) + " " + _uri + F(" HTTP/1."); - - if(_useHTTP10) { - header += "0"; - } else { - header += "1"; - } - - header += String(F("\r\nHost: ")) + _host; - if (_port != 80 && _port != 443) - { - header += ':'; - header += String(_port); - } - header += String(F("\r\nUser-Agent: ")) + _userAgent + - F("\r\nConnection: "); - - if(_reuse) { - header += F("keep-alive"); - } else { - header += F("close"); - } +bool HTTPClient::sendHeader(const char* type) { + if (!connected()) { + return false; + } + + String header = String(type) + " " + _uri + F(" HTTP/1."); + + if (_useHTTP10) { + header += "0"; + } else { + header += "1"; + } + + header += String(F("\r\nHost: ")) + _host; + if (_port != 80 && _port != 443) { + header += ':'; + header += String(_port); + } + header += String(F("\r\nUser-Agent: ")) + _userAgent + F("\r\nConnection: "); + + if (_reuse) { + header += F("keep-alive"); + } else { + header += F("close"); + } + header += "\r\n"; + + if (!_useHTTP10) { + header += F("Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0\r\n"); + } + + if (_base64Authorization.length()) { + _base64Authorization.replace("\n", ""); + header += F("Authorization: "); + header += _authorizationType; + header += " "; + header += _base64Authorization; header += "\r\n"; + } - if(!_useHTTP10) { - header += F("Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0\r\n"); - } - - if(_base64Authorization.length()) { - _base64Authorization.replace("\n", ""); - header += F("Authorization: "); - header += _authorizationType; - header += " "; - header += _base64Authorization; - header += "\r\n"; - } - - header += _headers + "\r\n"; + header += _headers + "\r\n"; - return (_client->write((const uint8_t *) header.c_str(), header.length()) == header.length()); + return (_client->write((const uint8_t*)header.c_str(), header.length()) == header.length()); } /** * reads the response from the server * @return int http code */ -int HTTPClient::handleHeaderResponse() -{ +int HTTPClient::handleHeaderResponse() { - if(!connected()) { - return HTTPC_ERROR_NOT_CONNECTED; - } + if (!connected()) { + return HTTPC_ERROR_NOT_CONNECTED; + } - _returnCode = 0; - _size = -1; - _canReuse = _reuse; - - String transferEncoding; - - _transferEncoding = HTTPC_TE_IDENTITY; - unsigned long lastDataTime = millis(); - bool firstLine = true; - String date; - - while(connected()) { - size_t len = _client->available(); - if(len > 0) { - String headerLine = _client->readStringUntil('\n'); - headerLine.trim(); // remove \r - - lastDataTime = millis(); - - log_v("RX: '%s'", headerLine.c_str()); - - if(firstLine) { - firstLine = false; - if(_canReuse && headerLine.startsWith("HTTP/1.")) { - _canReuse = (headerLine[sizeof "HTTP/1." - 1] != '0'); - } - int codePos = headerLine.indexOf(' ') + 1; - _returnCode = headerLine.substring(codePos, headerLine.indexOf(' ', codePos)).toInt(); - } else if(headerLine.indexOf(':')) { - String headerName = headerLine.substring(0, headerLine.indexOf(':')); - String headerValue = headerLine.substring(headerLine.indexOf(':') + 1); - headerValue.trim(); - - if(headerName.equalsIgnoreCase("Date")) { - date = headerValue; - } - - if(headerName.equalsIgnoreCase("Content-Length")) { - _size = headerValue.toInt(); - } - - if(_canReuse && headerName.equalsIgnoreCase("Connection")) { - if(headerValue.indexOf("close") >= 0 && headerValue.indexOf("keep-alive") < 0) { - _canReuse = false; - } - } - - if(headerName.equalsIgnoreCase("Transfer-Encoding")) { - transferEncoding = headerValue; - } - - if (headerName.equalsIgnoreCase("Location")) { - _location = headerValue; - } - - if (headerName.equalsIgnoreCase("Set-Cookie")) { - setCookie(date, headerValue); - } - - for (size_t i = 0; i < _headerKeysCount; i++) { - if (_currentHeaders[i].key.equalsIgnoreCase(headerName)) { - // Uncomment the following lines if you need to add support for multiple headers with the same key: - // if (!_currentHeaders[i].value.isEmpty()) { - // // Existing value, append this one with a comma - // _currentHeaders[i].value += ','; - // _currentHeaders[i].value += headerValue; - // } else { - _currentHeaders[i].value = headerValue; - // } - break; // We found a match, stop looking - } - } + _returnCode = 0; + _size = -1; + _canReuse = _reuse; - } + String transferEncoding; - if(headerLine == "") { - log_d("code: %d", _returnCode); - - if(_size > 0) { - log_d("size: %d", _size); - } - - if(transferEncoding.length() > 0) { - log_d("Transfer-Encoding: %s", transferEncoding.c_str()); - if(transferEncoding.equalsIgnoreCase("chunked")) { - _transferEncoding = HTTPC_TE_CHUNKED; - } else if(transferEncoding.equalsIgnoreCase("identity")) { - _transferEncoding = HTTPC_TE_IDENTITY; - } else { - return HTTPC_ERROR_ENCODING; - } - } else { - _transferEncoding = HTTPC_TE_IDENTITY; - } - - if(_returnCode) { - return _returnCode; - } else { - log_d("Remote host is not an HTTP Server!"); - return HTTPC_ERROR_NO_HTTP_SERVER; - } - } + _transferEncoding = HTTPC_TE_IDENTITY; + unsigned long lastDataTime = millis(); + bool firstLine = true; + String date; - } else { - if((millis() - lastDataTime) > _tcpTimeout) { - return HTTPC_ERROR_READ_TIMEOUT; - } - delay(10); + while (connected()) { + size_t len = _client->available(); + if (len > 0) { + String headerLine = _client->readStringUntil('\n'); + headerLine.trim(); // remove \r + + lastDataTime = millis(); + + log_v("RX: '%s'", headerLine.c_str()); + + if (firstLine) { + firstLine = false; + if (_canReuse && headerLine.startsWith("HTTP/1.")) { + _canReuse = (headerLine[sizeof "HTTP/1." - 1] != '0'); + } + int codePos = headerLine.indexOf(' ') + 1; + _returnCode = headerLine.substring(codePos, headerLine.indexOf(' ', codePos)).toInt(); + } else if (headerLine.indexOf(':')) { + String headerName = headerLine.substring(0, headerLine.indexOf(':')); + String headerValue = headerLine.substring(headerLine.indexOf(':') + 1); + headerValue.trim(); + + if (headerName.equalsIgnoreCase("Date")) { + date = headerValue; } - } - return HTTPC_ERROR_CONNECTION_LOST; -} + if (headerName.equalsIgnoreCase("Content-Length")) { + _size = headerValue.toInt(); + } -/** - * write one Data Block to Stream - * @param stream Stream * - * @param size int - * @return < 0 = error >= 0 = size written - */ -int HTTPClient::writeToStreamDataBlock(Stream * stream, int size) -{ - int buff_size = HTTP_TCP_RX_BUFFER_SIZE; - int len = size; - int bytesWritten = 0; - - // if possible create smaller buffer then HTTP_TCP_RX_BUFFER_SIZE - if((len > 0) && (len < buff_size)) { - buff_size = len; - } + if (_canReuse && headerName.equalsIgnoreCase("Connection")) { + if (headerValue.indexOf("close") >= 0 && headerValue.indexOf("keep-alive") < 0) { + _canReuse = false; + } + } - // create buffer for read - uint8_t * buff = (uint8_t *) malloc(buff_size); + if (headerName.equalsIgnoreCase("Transfer-Encoding")) { + transferEncoding = headerValue; + } - if(buff) { - // read all data from server - while(connected() && (len > 0 || len == -1)) { + if (headerName.equalsIgnoreCase("Location")) { + _location = headerValue; + } - // get available data size - size_t sizeAvailable = buff_size; - if(len < 0){ - sizeAvailable = _client->available(); - } + if (headerName.equalsIgnoreCase("Set-Cookie")) { + setCookie(date, headerValue); + } - if(sizeAvailable) { - - int readBytes = sizeAvailable; - - // read only the asked bytes - if(len > 0 && readBytes > len) { - readBytes = len; - } - - // not read more the buffer can handle - if(readBytes > buff_size) { - readBytes = buff_size; - } - - // stop if no more reading - if (readBytes == 0) - break; - - // read data - int bytesRead = _client->readBytes(buff, readBytes); - - // write it to Stream - int bytesWrite = stream->write(buff, bytesRead); - bytesWritten += bytesWrite; - - // are all Bytes a writen to stream ? - if(bytesWrite != bytesRead) { - log_d("short write asked for %d but got %d retry...", bytesRead, bytesWrite); - - // check for write error - if(stream->getWriteError()) { - log_d("stream write error %d", stream->getWriteError()); - - //reset write error for retry - stream->clearWriteError(); - } - - // some time for the stream - delay(1); - - int leftBytes = (readBytes - bytesWrite); - - // retry to send the missed bytes - bytesWrite = stream->write((buff + bytesWrite), leftBytes); - bytesWritten += bytesWrite; - - if(bytesWrite != leftBytes) { - // failed again - log_w("short write asked for %d but got %d failed.", leftBytes, bytesWrite); - free(buff); - return HTTPC_ERROR_STREAM_WRITE; - } - } - - // check for write error - if(stream->getWriteError()) { - log_w("stream write error %d", stream->getWriteError()); - free(buff); - return HTTPC_ERROR_STREAM_WRITE; - } - - // count bytes to read left - if(len > 0) { - len -= readBytes; - } - - delay(0); - } else { - delay(1); - } + for (size_t i = 0; i < _headerKeysCount; i++) { + if (_currentHeaders[i].key.equalsIgnoreCase(headerName)) { + // Uncomment the following lines if you need to add support for multiple headers with the same key: + // if (!_currentHeaders[i].value.isEmpty()) { + // // Existing value, append this one with a comma + // _currentHeaders[i].value += ','; + // _currentHeaders[i].value += headerValue; + // } else { + _currentHeaders[i].value = headerValue; + // } + break; // We found a match, stop looking + } } + } - free(buff); + if (headerLine == "") { + log_d("code: %d", _returnCode); - log_v("connection closed or file end (written: %d).", bytesWritten); + if (_size > 0) { + log_d("size: %d", _size); + } - if((size > 0) && (size != bytesWritten)) { - log_d("bytesWritten %d and size %d mismatch!.", bytesWritten, size); - return HTTPC_ERROR_STREAM_WRITE; + if (transferEncoding.length() > 0) { + log_d("Transfer-Encoding: %s", transferEncoding.c_str()); + if (transferEncoding.equalsIgnoreCase("chunked")) { + _transferEncoding = HTTPC_TE_CHUNKED; + } else if (transferEncoding.equalsIgnoreCase("identity")) { + _transferEncoding = HTTPC_TE_IDENTITY; + } else { + return HTTPC_ERROR_ENCODING; + } + } else { + _transferEncoding = HTTPC_TE_IDENTITY; + } + + if (_returnCode) { + return _returnCode; + } else { + log_d("Remote host is not an HTTP Server!"); + return HTTPC_ERROR_NO_HTTP_SERVER; } + } } else { - log_w("too less ram! need %d", buff_size); - return HTTPC_ERROR_TOO_LESS_RAM; + if ((millis() - lastDataTime) > _tcpTimeout) { + return HTTPC_ERROR_READ_TIMEOUT; + } + delay(10); } + } - return bytesWritten; + return HTTPC_ERROR_CONNECTION_LOST; } /** - * called to handle error return, may disconnect the connection if still exists - * @param error - * @return error + * write one Data Block to Stream + * @param stream Stream * + * @param size int + * @return < 0 = error >= 0 = size written */ -int HTTPClient::returnError(int error) -{ - if(error < 0) { - log_w("error(%d): %s", error, errorToString(error).c_str()); - if(connected()) { - log_d("tcp stop"); - _client->stop(); - } - } - return error; -} +int HTTPClient::writeToStreamDataBlock(Stream* stream, int size) { + int buff_size = HTTP_TCP_RX_BUFFER_SIZE; + int len = size; + int bytesWritten = 0; -void HTTPClient::setFollowRedirects(followRedirects_t follow) -{ - _followRedirects = follow; -} + // if possible create smaller buffer then HTTP_TCP_RX_BUFFER_SIZE + if ((len > 0) && (len < buff_size)) { + buff_size = len; + } -void HTTPClient::setRedirectLimit(uint16_t limit) -{ - _redirectLimit = limit; -} + // create buffer for read + uint8_t* buff = (uint8_t*)malloc(buff_size); -/** - * set the URL to a new value. Handy for following redirects. - * @param url - */ -bool HTTPClient::setURL(const String& url) -{ - // if the new location is only a path then only update the URI - if (url && url[0] == '/') { - _uri = url; - clear(); - return true; - } + if (buff) { + // read all data from server + while (connected() && (len > 0 || len == -1)) { - if (!url.startsWith(_protocol + ':')) { - log_d("new URL not the same protocol, expected '%s', URL: '%s'\n", _protocol.c_str(), url.c_str()); - return false; - } + // get available data size + size_t sizeAvailable = buff_size; + if (len < 0) { + sizeAvailable = _client->available(); + } - // check if the port is specified - int indexPort = url.indexOf(':', 6); // find the first ':' excluding the one from the protocol - int indexURI = url.indexOf('/', 7); // find where the URI starts to make sure the ':' is not part of it - if (indexPort == -1 || indexPort > indexURI) { - // the port is not specified - _port = (_protocol == "https" ? 443 : 80); - } + if (sizeAvailable) { - // disconnect but preserve _client. - // Also have to keep the connection otherwise it will free some of the memory used by _client - // and will blow up later when trying to do _client->available() or similar - _canReuse = true; - disconnect(true); - return beginInternal(url, _protocol.c_str()); -} + int readBytes = sizeAvailable; -const String &HTTPClient::getLocation(void) -{ - return _location; -} + // read only the asked bytes + if (len > 0 && readBytes > len) { + readBytes = len; + } -void HTTPClient::setCookieJar(CookieJar* cookieJar) -{ - _cookieJar = cookieJar; -} + // not read more the buffer can handle + if (readBytes > buff_size) { + readBytes = buff_size; + } -void HTTPClient::resetCookieJar() -{ - _cookieJar = nullptr; -} + // stop if no more reading + if (readBytes == 0) + break; -void HTTPClient::clearAllCookies() -{ - if (_cookieJar) _cookieJar->clear(); -} + // read data + int bytesRead = _client->readBytes(buff, readBytes); -void HTTPClient::setCookie(String date, String headerValue) -{ - if (!_cookieJar) - { - return; - } - #define HTTP_TIME_PATTERN "%a, %d %b %Y %H:%M:%S" + // write it to Stream + int bytesWrite = stream->write(buff, bytesRead); + bytesWritten += bytesWrite; - Cookie cookie; - String value; - int pos1, pos2; + // are all Bytes a written to stream ? + if (bytesWrite != bytesRead) { + log_d("short write asked for %d but got %d retry...", bytesRead, bytesWrite); - struct tm tm; - strptime(date.c_str(), HTTP_TIME_PATTERN, &tm); - cookie.date = mktime(&tm); + // check for write error + if (stream->getWriteError()) { + log_d("stream write error %d", stream->getWriteError()); - pos1 = headerValue.indexOf('='); - pos2 = headerValue.indexOf(';'); + //reset write error for retry + stream->clearWriteError(); + } - if (pos1 >= 0 && pos2 > pos1){ - cookie.name = headerValue.substring(0, pos1); - cookie.value = headerValue.substring(pos1 + 1, pos2); - } else { - return; // invalid cookie header - } + // some time for the stream + delay(1); + + int leftBytes = (readBytes - bytesWrite); - // only Cookie Attributes are case insensitive from this point on - headerValue.toLowerCase(); + // retry to send the missed bytes + bytesWrite = stream->write((buff + bytesWrite), leftBytes); + bytesWritten += bytesWrite; - // expires - if (headerValue.indexOf("expires=") >= 0){ - pos1 = headerValue.indexOf("expires=") + strlen("expires="); - pos2 = headerValue.indexOf(';', pos1); + if (bytesWrite != leftBytes) { + // failed again + log_w("short write asked for %d but got %d failed.", leftBytes, bytesWrite); + free(buff); + return HTTPC_ERROR_STREAM_WRITE; + } + } + + // check for write error + if (stream->getWriteError()) { + log_w("stream write error %d", stream->getWriteError()); + free(buff); + return HTTPC_ERROR_STREAM_WRITE; + } - if (pos2 > pos1) - value = headerValue.substring(pos1, pos2); - else - value = headerValue.substring(pos1); + // count bytes to read left + if (len > 0) { + len -= readBytes; + } - strptime(value.c_str(), HTTP_TIME_PATTERN, &tm); - cookie.expires.date = mktime(&tm); - cookie.expires.valid = true; + delay(0); + } else { + delay(1); + } } - // max-age - if (headerValue.indexOf("max-age=") >= 0){ - pos1 = headerValue.indexOf("max-age=") + strlen("max-age="); - pos2 = headerValue.indexOf(';', pos1); + free(buff); - if (pos2 > pos1) - value = headerValue.substring(pos1, pos2); - else - value = headerValue.substring(pos1); + log_v("connection closed or file end (written: %d).", bytesWritten); - cookie.max_age.duration = value.toInt(); - cookie.max_age.valid = true; + if ((size > 0) && (size != bytesWritten)) { + log_d("bytesWritten %d and size %d mismatch!.", bytesWritten, size); + return HTTPC_ERROR_STREAM_WRITE; } - // domain - if (headerValue.indexOf("domain=") >= 0){ - pos1 = headerValue.indexOf("domain=") + strlen("domain="); - pos2 = headerValue.indexOf(';', pos1); - - if (pos2 > pos1) - value = headerValue.substring(pos1, pos2); - else - value = headerValue.substring(pos1); + } else { + log_w("too less ram! need %d", buff_size); + return HTTPC_ERROR_TOO_LESS_RAM; + } - if (value.startsWith(".")) value.remove(0, 1); + return bytesWritten; +} - if (_host.indexOf(value) >= 0) { - cookie.domain = value; - } else { - return; // server tries to set a cookie on a different domain; ignore it - } - } else { - pos1 = _host.lastIndexOf('.', _host.lastIndexOf('.') - 1); - if (pos1 >= 0) - cookie.domain = _host.substring(pos1 + 1); - else - cookie.domain = _host; +/** + * called to handle error return, may disconnect the connection if still exists + * @param error + * @return error + */ +int HTTPClient::returnError(int error) { + if (error < 0) { + log_w("error(%d): %s", error, errorToString(error).c_str()); + if (connected()) { + log_d("tcp stop"); + _client->stop(); } + } + return error; +} - // path - if (headerValue.indexOf("path=") >= 0){ - pos1 = headerValue.indexOf("path=") + strlen("path="); - pos2 = headerValue.indexOf(';', pos1); +void HTTPClient::setFollowRedirects(followRedirects_t follow) { + _followRedirects = follow; +} - if (pos2 > pos1) - cookie.path = headerValue.substring(pos1, pos2); - else - cookie.path = headerValue.substring(pos1); - } +void HTTPClient::setRedirectLimit(uint16_t limit) { + _redirectLimit = limit; +} - // HttpOnly - cookie.http_only = (headerValue.indexOf("httponly") >= 0); +/** + * set the URL to a new value. Handy for following redirects. + * @param url + */ +bool HTTPClient::setURL(const String& url) { + // if the new location is only a path then only update the URI + if (url && url[0] == '/') { + _uri = url; + clear(); + return true; + } - // secure - cookie.secure = (headerValue.indexOf("secure") >= 0); + if (!url.startsWith(_protocol + ':')) { + log_d("new URL not the same protocol, expected '%s', URL: '%s'\n", _protocol.c_str(), url.c_str()); + return false; + } + + // check if the port is specified + int indexPort = url.indexOf(':', 6); // find the first ':' excluding the one from the protocol + int indexURI = url.indexOf('/', 7); // find where the URI starts to make sure the ':' is not part of it + if (indexPort == -1 || indexPort > indexURI) { + // the port is not specified + _port = (_protocol == "https" ? 443 : 80); + } + + // disconnect but preserve _client. + // Also have to keep the connection otherwise it will free some of the memory used by _client + // and will blow up later when trying to do _client->available() or similar + _canReuse = true; + disconnect(true); + return beginInternal(url, _protocol.c_str()); +} - // overwrite or delete cookie in/from cookie jar - time_t now_local = time(NULL); - time_t now_gmt = mktime(gmtime(&now_local)); +const String& HTTPClient::getLocation(void) { + return _location; +} - bool found = false; +void HTTPClient::setCookieJar(CookieJar* cookieJar) { + _cookieJar = cookieJar; +} - for (auto c = _cookieJar->begin(); c != _cookieJar->end(); ++c) { - if (c->domain == cookie.domain && c->name == cookie.name) { - // when evaluating, max-age takes precedence over expires if both are defined - if ((cookie.max_age.valid && ((cookie.date + cookie.max_age.duration) < now_gmt)) || cookie.max_age.duration <= 0 - || (!cookie.max_age.valid && cookie.expires.valid && cookie.expires.date < now_gmt)) { - _cookieJar->erase(c); - c--; - } else { - *c = cookie; - } - found = true; - } - } +void HTTPClient::resetCookieJar() { + _cookieJar = nullptr; +} - // add cookie to jar - if (!found && !(cookie.max_age.valid && cookie.max_age.duration <= 0)) - _cookieJar->push_back(cookie); +void HTTPClient::clearAllCookies() { + if (_cookieJar) _cookieJar->clear(); +} +void HTTPClient::setCookie(String date, String headerValue) { + if (!_cookieJar) { + return; + } +#define HTTP_TIME_PATTERN "%a, %d %b %Y %H:%M:%S" + + Cookie cookie; + String value; + int pos1, pos2; + + struct tm tm; + strptime(date.c_str(), HTTP_TIME_PATTERN, &tm); + cookie.date = mktime(&tm); + + pos1 = headerValue.indexOf('='); + pos2 = headerValue.indexOf(';'); + + if (pos1 >= 0 && pos2 > pos1) { + cookie.name = headerValue.substring(0, pos1); + cookie.value = headerValue.substring(pos1 + 1, pos2); + } else { + return; // invalid cookie header + } + + // only Cookie Attributes are case insensitive from this point on + headerValue.toLowerCase(); + + // expires + if (headerValue.indexOf("expires=") >= 0) { + pos1 = headerValue.indexOf("expires=") + strlen("expires="); + pos2 = headerValue.indexOf(';', pos1); + + if (pos2 > pos1) + value = headerValue.substring(pos1, pos2); + else + value = headerValue.substring(pos1); + + strptime(value.c_str(), HTTP_TIME_PATTERN, &tm); + cookie.expires.date = mktime(&tm); + cookie.expires.valid = true; + } + + // max-age + if (headerValue.indexOf("max-age=") >= 0) { + pos1 = headerValue.indexOf("max-age=") + strlen("max-age="); + pos2 = headerValue.indexOf(';', pos1); + + if (pos2 > pos1) + value = headerValue.substring(pos1, pos2); + else + value = headerValue.substring(pos1); + + cookie.max_age.duration = value.toInt(); + cookie.max_age.valid = true; + } + + // domain + if (headerValue.indexOf("domain=") >= 0) { + pos1 = headerValue.indexOf("domain=") + strlen("domain="); + pos2 = headerValue.indexOf(';', pos1); + + if (pos2 > pos1) + value = headerValue.substring(pos1, pos2); + else + value = headerValue.substring(pos1); + + if (value.startsWith(".")) value.remove(0, 1); + + if (_host.indexOf(value) >= 0) { + cookie.domain = value; + } else { + return; // server tries to set a cookie on a different domain; ignore it + } + } else { + pos1 = _host.lastIndexOf('.', _host.lastIndexOf('.') - 1); + if (pos1 >= 0) + cookie.domain = _host.substring(pos1 + 1); + else + cookie.domain = _host; + } + + // path + if (headerValue.indexOf("path=") >= 0) { + pos1 = headerValue.indexOf("path=") + strlen("path="); + pos2 = headerValue.indexOf(';', pos1); + + if (pos2 > pos1) + cookie.path = headerValue.substring(pos1, pos2); + else + cookie.path = headerValue.substring(pos1); + } + + // HttpOnly + cookie.http_only = (headerValue.indexOf("httponly") >= 0); + + // secure + cookie.secure = (headerValue.indexOf("secure") >= 0); + + // overwrite or delete cookie in/from cookie jar + time_t now_local = time(NULL); + time_t now_gmt = mktime(gmtime(&now_local)); + + bool found = false; + + for (auto c = _cookieJar->begin(); c != _cookieJar->end(); ++c) { + if (c->domain == cookie.domain && c->name == cookie.name) { + // when evaluating, max-age takes precedence over expires if both are defined + if ((cookie.max_age.valid && ((cookie.date + cookie.max_age.duration) < now_gmt)) || cookie.max_age.duration <= 0 + || (!cookie.max_age.valid && cookie.expires.valid && cookie.expires.date < now_gmt)) { + _cookieJar->erase(c); + c--; + } else { + *c = cookie; + } + found = true; + } + } + + // add cookie to jar + if (!found && !(cookie.max_age.valid && cookie.max_age.duration <= 0)) + _cookieJar->push_back(cookie); } -bool HTTPClient::generateCookieString(String *cookieString) -{ - time_t now_local = time(NULL); - time_t now_gmt = mktime(gmtime(&now_local)); +bool HTTPClient::generateCookieString(String* cookieString) { + time_t now_local = time(NULL); + time_t now_gmt = mktime(gmtime(&now_local)); - *cookieString = ""; - bool found = false; + *cookieString = ""; + bool found = false; - if (!_cookieJar) - { - return false; - } - for (auto c = _cookieJar->begin(); c != _cookieJar->end(); ++c) { - if ((c->max_age.valid && ((c->date + c->max_age.duration) < now_gmt)) || (!c->max_age.valid && c->expires.valid && c->expires.date < now_gmt)) { - _cookieJar->erase(c); - c--; - } else if (_host.indexOf(c->domain) >= 0 && (!c->secure || _secure) ) { - if (*cookieString == "") - *cookieString = c->name + "=" + c->value; - else - *cookieString += " ;" + c->name + "=" + c->value; - found = true; - } - } - - return found; + if (!_cookieJar) { + return false; + } + for (auto c = _cookieJar->begin(); c != _cookieJar->end(); ++c) { + if ((c->max_age.valid && ((c->date + c->max_age.duration) < now_gmt)) || (!c->max_age.valid && c->expires.valid && c->expires.date < now_gmt)) { + _cookieJar->erase(c); + c--; + } else if (_host.indexOf(c->domain) >= 0 && (!c->secure || _secure)) { + if (*cookieString == "") + *cookieString = c->name + "=" + c->value; + else + *cookieString += " ;" + c->name + "=" + c->value; + found = true; + } + } + + return found; } diff --git a/libraries/HTTPClient/src/HTTPClient.h b/libraries/HTTPClient/src/HTTPClient.h index 0d586916e24..f9558e575d6 100644 --- a/libraries/HTTPClient/src/HTTPClient.h +++ b/libraries/HTTPClient/src/HTTPClient.h @@ -5,8 +5,8 @@ * * Copyright (c) 2015 Markus Sattler. All rights reserved. * This file is part of the HTTPClient for Arduino. - * Port to ESP32 by Evandro Luis Copercini (2017), - * changed fingerprints to CA verification. + * Port to ESP32 by Evandro Luis Copercini (2017), + * changed fingerprints to CA verification. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -42,17 +42,17 @@ #define HTTPCLIENT_DEFAULT_TCP_TIMEOUT (5000) /// HTTP client errors -#define HTTPC_ERROR_CONNECTION_REFUSED (-1) -#define HTTPC_ERROR_SEND_HEADER_FAILED (-2) +#define HTTPC_ERROR_CONNECTION_REFUSED (-1) +#define HTTPC_ERROR_SEND_HEADER_FAILED (-2) #define HTTPC_ERROR_SEND_PAYLOAD_FAILED (-3) -#define HTTPC_ERROR_NOT_CONNECTED (-4) -#define HTTPC_ERROR_CONNECTION_LOST (-5) -#define HTTPC_ERROR_NO_STREAM (-6) -#define HTTPC_ERROR_NO_HTTP_SERVER (-7) -#define HTTPC_ERROR_TOO_LESS_RAM (-8) -#define HTTPC_ERROR_ENCODING (-9) -#define HTTPC_ERROR_STREAM_WRITE (-10) -#define HTTPC_ERROR_READ_TIMEOUT (-11) +#define HTTPC_ERROR_NOT_CONNECTED (-4) +#define HTTPC_ERROR_CONNECTION_LOST (-5) +#define HTTPC_ERROR_NO_STREAM (-6) +#define HTTPC_ERROR_NO_HTTP_SERVER (-7) +#define HTTPC_ERROR_TOO_LESS_RAM (-8) +#define HTTPC_ERROR_ENCODING (-9) +#define HTTPC_ERROR_STREAM_WRITE (-10) +#define HTTPC_ERROR_READ_TIMEOUT (-11) /// size for the stream handling #define HTTP_TCP_RX_BUFFER_SIZE (4096) @@ -60,69 +60,69 @@ /// HTTP codes see RFC7231 typedef enum { - HTTP_CODE_CONTINUE = 100, - HTTP_CODE_SWITCHING_PROTOCOLS = 101, - HTTP_CODE_PROCESSING = 102, - HTTP_CODE_OK = 200, - HTTP_CODE_CREATED = 201, - HTTP_CODE_ACCEPTED = 202, - HTTP_CODE_NON_AUTHORITATIVE_INFORMATION = 203, - HTTP_CODE_NO_CONTENT = 204, - HTTP_CODE_RESET_CONTENT = 205, - HTTP_CODE_PARTIAL_CONTENT = 206, - HTTP_CODE_MULTI_STATUS = 207, - HTTP_CODE_ALREADY_REPORTED = 208, - HTTP_CODE_IM_USED = 226, - HTTP_CODE_MULTIPLE_CHOICES = 300, - HTTP_CODE_MOVED_PERMANENTLY = 301, - HTTP_CODE_FOUND = 302, - HTTP_CODE_SEE_OTHER = 303, - HTTP_CODE_NOT_MODIFIED = 304, - HTTP_CODE_USE_PROXY = 305, - HTTP_CODE_TEMPORARY_REDIRECT = 307, - HTTP_CODE_PERMANENT_REDIRECT = 308, - HTTP_CODE_BAD_REQUEST = 400, - HTTP_CODE_UNAUTHORIZED = 401, - HTTP_CODE_PAYMENT_REQUIRED = 402, - HTTP_CODE_FORBIDDEN = 403, - HTTP_CODE_NOT_FOUND = 404, - HTTP_CODE_METHOD_NOT_ALLOWED = 405, - HTTP_CODE_NOT_ACCEPTABLE = 406, - HTTP_CODE_PROXY_AUTHENTICATION_REQUIRED = 407, - HTTP_CODE_REQUEST_TIMEOUT = 408, - HTTP_CODE_CONFLICT = 409, - HTTP_CODE_GONE = 410, - HTTP_CODE_LENGTH_REQUIRED = 411, - HTTP_CODE_PRECONDITION_FAILED = 412, - HTTP_CODE_PAYLOAD_TOO_LARGE = 413, - HTTP_CODE_URI_TOO_LONG = 414, - HTTP_CODE_UNSUPPORTED_MEDIA_TYPE = 415, - HTTP_CODE_RANGE_NOT_SATISFIABLE = 416, - HTTP_CODE_EXPECTATION_FAILED = 417, - HTTP_CODE_MISDIRECTED_REQUEST = 421, - HTTP_CODE_UNPROCESSABLE_ENTITY = 422, - HTTP_CODE_LOCKED = 423, - HTTP_CODE_FAILED_DEPENDENCY = 424, - HTTP_CODE_UPGRADE_REQUIRED = 426, - HTTP_CODE_PRECONDITION_REQUIRED = 428, - HTTP_CODE_TOO_MANY_REQUESTS = 429, - HTTP_CODE_REQUEST_HEADER_FIELDS_TOO_LARGE = 431, - HTTP_CODE_INTERNAL_SERVER_ERROR = 500, - HTTP_CODE_NOT_IMPLEMENTED = 501, - HTTP_CODE_BAD_GATEWAY = 502, - HTTP_CODE_SERVICE_UNAVAILABLE = 503, - HTTP_CODE_GATEWAY_TIMEOUT = 504, - HTTP_CODE_HTTP_VERSION_NOT_SUPPORTED = 505, - HTTP_CODE_VARIANT_ALSO_NEGOTIATES = 506, - HTTP_CODE_INSUFFICIENT_STORAGE = 507, - HTTP_CODE_LOOP_DETECTED = 508, - HTTP_CODE_NOT_EXTENDED = 510, - HTTP_CODE_NETWORK_AUTHENTICATION_REQUIRED = 511 + HTTP_CODE_CONTINUE = 100, + HTTP_CODE_SWITCHING_PROTOCOLS = 101, + HTTP_CODE_PROCESSING = 102, + HTTP_CODE_OK = 200, + HTTP_CODE_CREATED = 201, + HTTP_CODE_ACCEPTED = 202, + HTTP_CODE_NON_AUTHORITATIVE_INFORMATION = 203, + HTTP_CODE_NO_CONTENT = 204, + HTTP_CODE_RESET_CONTENT = 205, + HTTP_CODE_PARTIAL_CONTENT = 206, + HTTP_CODE_MULTI_STATUS = 207, + HTTP_CODE_ALREADY_REPORTED = 208, + HTTP_CODE_IM_USED = 226, + HTTP_CODE_MULTIPLE_CHOICES = 300, + HTTP_CODE_MOVED_PERMANENTLY = 301, + HTTP_CODE_FOUND = 302, + HTTP_CODE_SEE_OTHER = 303, + HTTP_CODE_NOT_MODIFIED = 304, + HTTP_CODE_USE_PROXY = 305, + HTTP_CODE_TEMPORARY_REDIRECT = 307, + HTTP_CODE_PERMANENT_REDIRECT = 308, + HTTP_CODE_BAD_REQUEST = 400, + HTTP_CODE_UNAUTHORIZED = 401, + HTTP_CODE_PAYMENT_REQUIRED = 402, + HTTP_CODE_FORBIDDEN = 403, + HTTP_CODE_NOT_FOUND = 404, + HTTP_CODE_METHOD_NOT_ALLOWED = 405, + HTTP_CODE_NOT_ACCEPTABLE = 406, + HTTP_CODE_PROXY_AUTHENTICATION_REQUIRED = 407, + HTTP_CODE_REQUEST_TIMEOUT = 408, + HTTP_CODE_CONFLICT = 409, + HTTP_CODE_GONE = 410, + HTTP_CODE_LENGTH_REQUIRED = 411, + HTTP_CODE_PRECONDITION_FAILED = 412, + HTTP_CODE_PAYLOAD_TOO_LARGE = 413, + HTTP_CODE_URI_TOO_LONG = 414, + HTTP_CODE_UNSUPPORTED_MEDIA_TYPE = 415, + HTTP_CODE_RANGE_NOT_SATISFIABLE = 416, + HTTP_CODE_EXPECTATION_FAILED = 417, + HTTP_CODE_MISDIRECTED_REQUEST = 421, + HTTP_CODE_UNPROCESSABLE_ENTITY = 422, + HTTP_CODE_LOCKED = 423, + HTTP_CODE_FAILED_DEPENDENCY = 424, + HTTP_CODE_UPGRADE_REQUIRED = 426, + HTTP_CODE_PRECONDITION_REQUIRED = 428, + HTTP_CODE_TOO_MANY_REQUESTS = 429, + HTTP_CODE_REQUEST_HEADER_FIELDS_TOO_LARGE = 431, + HTTP_CODE_INTERNAL_SERVER_ERROR = 500, + HTTP_CODE_NOT_IMPLEMENTED = 501, + HTTP_CODE_BAD_GATEWAY = 502, + HTTP_CODE_SERVICE_UNAVAILABLE = 503, + HTTP_CODE_GATEWAY_TIMEOUT = 504, + HTTP_CODE_HTTP_VERSION_NOT_SUPPORTED = 505, + HTTP_CODE_VARIANT_ALSO_NEGOTIATES = 506, + HTTP_CODE_INSUFFICIENT_STORAGE = 507, + HTTP_CODE_LOOP_DETECTED = 508, + HTTP_CODE_NOT_EXTENDED = 510, + HTTP_CODE_NETWORK_AUTHENTICATION_REQUIRED = 511 } t_http_codes; typedef enum { - HTTPC_TE_IDENTITY, - HTTPC_TE_CHUNKED + HTTPC_TE_IDENTITY, + HTTPC_TE_CHUNKED } transferEncoding_t; /** @@ -137,9 +137,9 @@ typedef enum { * In the sense of the RFC, it's just like every redirection is confirmed. */ typedef enum { - HTTPC_DISABLE_FOLLOW_REDIRECTS, - HTTPC_STRICT_FOLLOW_REDIRECTS, - HTTPC_FORCE_FOLLOW_REDIRECTS + HTTPC_DISABLE_FOLLOW_REDIRECTS, + HTTPC_STRICT_FOLLOW_REDIRECTS, + HTTPC_FORCE_FOLLOW_REDIRECTS } followRedirects_t; @@ -149,162 +149,160 @@ typedef std::unique_ptr TransportTraitsPtr; #endif // cookie jar support -typedef struct { - String host; // host which tries to set the cookie - time_t date; // timestamp of the response that set the cookie - String name; - String value; - String domain; - String path = ""; - struct { - time_t date = 0; - bool valid = false; - } expires; - struct { - time_t duration = 0; - bool valid = false; - } max_age; - bool http_only = false; - bool secure = false; +typedef struct { + String host; // host which tries to set the cookie + time_t date; // timestamp of the response that set the cookie + String name; + String value; + String domain; + String path = ""; + struct { + time_t date = 0; + bool valid = false; + } expires; + struct { + time_t duration = 0; + bool valid = false; + } max_age; + bool http_only = false; + bool secure = false; } Cookie; typedef std::vector CookieJar; -class HTTPClient -{ +class HTTPClient { public: - HTTPClient(); - ~HTTPClient(); + HTTPClient(); + ~HTTPClient(); -/* - * Since both begin() functions take a reference to client as a parameter, you need to + /* + * Since both begin() functions take a reference to client as a parameter, you need to * ensure the client object lives the entire time of the HTTPClient */ - bool begin(NetworkClient &client, String url); - bool begin(NetworkClient &client, String host, uint16_t port, String uri = "/", bool https = false); + bool begin(NetworkClient& client, String url); + bool begin(NetworkClient& client, String host, uint16_t port, String uri = "/", bool https = false); #ifdef HTTPCLIENT_1_1_COMPATIBLE - bool begin(String url); - bool begin(String url, const char* CAcert); - bool begin(String host, uint16_t port, String uri = "/"); - bool begin(String host, uint16_t port, String uri, const char* CAcert); - bool begin(String host, uint16_t port, String uri, const char* CAcert, const char* cli_cert, const char* cli_key); + bool begin(String url); + bool begin(String url, const char* CAcert); + bool begin(String host, uint16_t port, String uri = "/"); + bool begin(String host, uint16_t port, String uri, const char* CAcert); + bool begin(String host, uint16_t port, String uri, const char* CAcert, const char* cli_cert, const char* cli_key); #endif - void end(void); + void end(void); - bool connected(void); + bool connected(void); - void setReuse(bool reuse); /// keep-alive - void setUserAgent(const String& userAgent); - void setAuthorization(const char * user, const char * password); - void setAuthorization(const char * auth); - void setAuthorizationType(const char * authType); - void setConnectTimeout(int32_t connectTimeout); - void setTimeout(uint16_t timeout); + void setReuse(bool reuse); /// keep-alive + void setUserAgent(const String& userAgent); + void setAuthorization(const char* user, const char* password); + void setAuthorization(const char* auth); + void setAuthorizationType(const char* authType); + void setConnectTimeout(int32_t connectTimeout); + void setTimeout(uint16_t timeout); - // Redirections - void setFollowRedirects(followRedirects_t follow); - void setRedirectLimit(uint16_t limit); // max redirects to follow for a single request + // Redirections + void setFollowRedirects(followRedirects_t follow); + void setRedirectLimit(uint16_t limit); // max redirects to follow for a single request - bool setURL(const String &url); - void useHTTP10(bool usehttp10 = true); + bool setURL(const String& url); + void useHTTP10(bool usehttp10 = true); - /// request handling - int GET(); - int PATCH(uint8_t * payload, size_t size); - int PATCH(String payload); - int POST(uint8_t * payload, size_t size); - int POST(String payload); - int PUT(uint8_t * payload, size_t size); - int PUT(String payload); - int sendRequest(const char * type, String payload); - int sendRequest(const char * type, uint8_t * payload = NULL, size_t size = 0); - int sendRequest(const char * type, Stream * stream, size_t size = 0); + /// request handling + int GET(); + int PATCH(uint8_t* payload, size_t size); + int PATCH(String payload); + int POST(uint8_t* payload, size_t size); + int POST(String payload); + int PUT(uint8_t* payload, size_t size); + int PUT(String payload); + int sendRequest(const char* type, String payload); + int sendRequest(const char* type, uint8_t* payload = NULL, size_t size = 0); + int sendRequest(const char* type, Stream* stream, size_t size = 0); - void addHeader(const String& name, const String& value, bool first = false, bool replace = true); + void addHeader(const String& name, const String& value, bool first = false, bool replace = true); - /// Response handling - void collectHeaders(const char* headerKeys[], const size_t headerKeysCount); - String header(const char* name); // get request header value by name - String header(size_t i); // get request header value by number - String headerName(size_t i); // get request header name by number - int headers(); // get header count - bool hasHeader(const char* name); // check if header exists + /// Response handling + void collectHeaders(const char* headerKeys[], const size_t headerKeysCount); + String header(const char* name); // get request header value by name + String header(size_t i); // get request header value by number + String headerName(size_t i); // get request header name by number + int headers(); // get header count + bool hasHeader(const char* name); // check if header exists - int getSize(void); - const String &getLocation(void); + int getSize(void); + const String& getLocation(void); - NetworkClient& getStream(void); - NetworkClient* getStreamPtr(void); - int writeToStream(Stream* stream); - String getString(void); + NetworkClient& getStream(void); + NetworkClient* getStreamPtr(void); + int writeToStream(Stream* stream); + String getString(void); - static String errorToString(int error); + static String errorToString(int error); - /// Cookie jar support - void setCookieJar(CookieJar* cookieJar); - void resetCookieJar(); - void clearAllCookies(); + /// Cookie jar support + void setCookieJar(CookieJar* cookieJar); + void resetCookieJar(); + void clearAllCookies(); protected: - struct RequestArgument { - String key; - String value; - }; - - bool beginInternal(String url, const char* expectedProtocol); - void disconnect(bool preserveClient = false); - void clear(); - int returnError(int error); - bool connect(void); - bool sendHeader(const char * type); - int handleHeaderResponse(); - int writeToStreamDataBlock(Stream * stream, int len); - - /// Cookie jar support - void setCookie(String date, String headerValue); - bool generateCookieString(String *cookieString); + struct RequestArgument { + String key; + String value; + }; + + bool beginInternal(String url, const char* expectedProtocol); + void disconnect(bool preserveClient = false); + void clear(); + int returnError(int error); + bool connect(void); + bool sendHeader(const char* type); + int handleHeaderResponse(); + int writeToStreamDataBlock(Stream* stream, int len); + + /// Cookie jar support + void setCookie(String date, String headerValue); + bool generateCookieString(String* cookieString); #ifdef HTTPCLIENT_1_1_COMPATIBLE - TransportTraitsPtr _transportTraits; - std::unique_ptr _tcpDeprecated; + TransportTraitsPtr _transportTraits; + std::unique_ptr _tcpDeprecated; #endif - NetworkClient* _client = nullptr; - - /// request handling - String _host; - uint16_t _port = 0; - int32_t _connectTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT; - bool _reuse = true; - uint16_t _tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT; - bool _useHTTP10 = false; - bool _secure = false; - - String _uri; - String _protocol; - String _headers; - String _userAgent = "ESP32HTTPClient"; - String _base64Authorization; - String _authorizationType = "Basic"; - - /// Response handling - RequestArgument* _currentHeaders = nullptr; - size_t _headerKeysCount = 0; - - int _returnCode = 0; - int _size = -1; - bool _canReuse = false; - followRedirects_t _followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS; - uint16_t _redirectLimit = 10; - String _location; - transferEncoding_t _transferEncoding = HTTPC_TE_IDENTITY; - - /// Cookie jar support - CookieJar* _cookieJar = nullptr; - + NetworkClient* _client = nullptr; + + /// request handling + String _host; + uint16_t _port = 0; + int32_t _connectTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT; + bool _reuse = true; + uint16_t _tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT; + bool _useHTTP10 = false; + bool _secure = false; + + String _uri; + String _protocol; + String _headers; + String _userAgent = "ESP32HTTPClient"; + String _base64Authorization; + String _authorizationType = "Basic"; + + /// Response handling + RequestArgument* _currentHeaders = nullptr; + size_t _headerKeysCount = 0; + + int _returnCode = 0; + int _size = -1; + bool _canReuse = false; + followRedirects_t _followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS; + uint16_t _redirectLimit = 10; + String _location; + transferEncoding_t _transferEncoding = HTTPC_TE_IDENTITY; + + /// Cookie jar support + CookieJar* _cookieJar = nullptr; }; diff --git a/libraries/HTTPUpdate/examples/httpUpdate/httpUpdate.ino b/libraries/HTTPUpdate/examples/httpUpdate/httpUpdate.ino index 47b73acc8bc..4e7acddb176 100644 --- a/libraries/HTTPUpdate/examples/httpUpdate/httpUpdate.ino +++ b/libraries/HTTPUpdate/examples/httpUpdate/httpUpdate.ino @@ -32,8 +32,6 @@ void setup() { WiFi.mode(WIFI_STA); WiFiMulti.addAP("SSID", "PASSWORD"); - - } void update_started() { @@ -90,4 +88,3 @@ void loop() { } } } - diff --git a/libraries/HTTPUpdate/examples/httpUpdateSPIFFS/httpUpdateSPIFFS.ino b/libraries/HTTPUpdate/examples/httpUpdateSPIFFS/httpUpdateSPIFFS.ino index ec834f85c19..284763b9139 100644 --- a/libraries/HTTPUpdate/examples/httpUpdateSPIFFS/httpUpdateSPIFFS.ino +++ b/libraries/HTTPUpdate/examples/httpUpdateSPIFFS/httpUpdateSPIFFS.ino @@ -32,7 +32,6 @@ void setup() { WiFi.mode(WIFI_STA); WiFiMulti.addAP("SSID", "PASSWORD"); - } void loop() { @@ -72,4 +71,3 @@ void loop() { } } } - diff --git a/libraries/HTTPUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino b/libraries/HTTPUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino index 6c98b9a3755..f6c5a89a796 100644 --- a/libraries/HTTPUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino +++ b/libraries/HTTPUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino @@ -38,34 +38,34 @@ void setClock() { /** * This is lets-encrypt-x3-cross-signed.p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FoAUxKexpHsscfrb4UuQdf/EFWCFiRAw\n" \ -"VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC\n" \ -"ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz\n" \ -"MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu\n" \ -"Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF\n" \ -"AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo\n" \ -"uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/\n" \ -"wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu\n" \ -"X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG\n" \ -"PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n" \ -"KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n" \ -"-----END CERTIFICATE-----\n"; +const char* rootCACertificate = + "-----BEGIN CERTIFICATE-----\n" + "MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/\n" + "MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" + "DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow\n" + "SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT\n" + "GkxldCdzIEVuY3J5cHQgQXV0aG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"uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/\n" + "wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu\n" + "X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG\n" + "PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n" + "KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n" + "-----END CERTIFICATE-----\n"; void setup() { @@ -96,7 +96,7 @@ void loop() { client.setCACert(rootCACertificate); // Reading data over SSL may be slow, use an adequate timeout - client.setTimeout(12000); // timeout argument is defined in miliseconds for setTimeout + client.setTimeout(12000); // timeout argument is defined in milliseconds for setTimeout // The line below is optional. It can be used to blink the LED on the board during flashing // The LED will be on during download of one buffer of data from the network. The LED will @@ -106,7 +106,7 @@ void loop() { // value is used to put the LED on. If the LED is on with HIGH, that value should be passed // httpUpdate.setLedPin(LED_BUILTIN, HIGH); - t_httpUpdate_return ret = httpUpdate.update(client, "https://server/file.bin", "", [](HTTPClient *client) { + t_httpUpdate_return ret = httpUpdate.update(client, "https://server/file.bin", "", [](HTTPClient* client) { client->setAuthorization("test", "password"); }); // Or: diff --git a/libraries/HTTPUpdate/src/HTTPUpdate.cpp b/libraries/HTTPUpdate/src/HTTPUpdate.cpp index cc93ef82937..004ca333758 100644 --- a/libraries/HTTPUpdate/src/HTTPUpdate.cpp +++ b/libraries/HTTPUpdate/src/HTTPUpdate.cpp @@ -30,140 +30,127 @@ #endif #include -#include // get running partition +#include // get running partition // To do extern "C" uint32_t _SPIFFS_start; // To do extern "C" uint32_t _SPIFFS_end; HTTPUpdate::HTTPUpdate(void) - : HTTPUpdate(8000) -{ + : HTTPUpdate(8000) { } HTTPUpdate::HTTPUpdate(int httpClientTimeout) - : _httpClientTimeout(httpClientTimeout), _ledPin(-1) -{ - _followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS; - _md5Sum = String(); - _user = String(); - _password = String(); - _auth = String(); + : _httpClientTimeout(httpClientTimeout), _ledPin(-1) { + _followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS; + _md5Sum = String(); + _user = String(); + _password = String(); + _auth = String(); } -HTTPUpdate::~HTTPUpdate(void) -{ +HTTPUpdate::~HTTPUpdate(void) { } -HTTPUpdateResult HTTPUpdate::update(NetworkClient& client, const String& url, const String& currentVersion, HTTPUpdateRequestCB requestCB) -{ - HTTPClient http; - if(!http.begin(client, url)) - { - return HTTP_UPDATE_FAILED; - } - return handleUpdate(http, currentVersion, false, requestCB); +HTTPUpdateResult HTTPUpdate::update(NetworkClient& client, const String& url, const String& currentVersion, HTTPUpdateRequestCB requestCB) { + HTTPClient http; + if (!http.begin(client, url)) { + return HTTP_UPDATE_FAILED; + } + return handleUpdate(http, currentVersion, false, requestCB); } -HTTPUpdateResult HTTPUpdate::updateSpiffs(HTTPClient& httpClient, const String& currentVersion, HTTPUpdateRequestCB requestCB) -{ - return handleUpdate(httpClient, currentVersion, true, requestCB); +HTTPUpdateResult HTTPUpdate::updateSpiffs(HTTPClient& httpClient, const String& currentVersion, HTTPUpdateRequestCB requestCB) { + return handleUpdate(httpClient, currentVersion, true, requestCB); } -HTTPUpdateResult HTTPUpdate::updateSpiffs(NetworkClient& client, const String& url, const String& currentVersion, HTTPUpdateRequestCB requestCB) -{ - HTTPClient http; - if(!http.begin(client, url)) - { - return HTTP_UPDATE_FAILED; - } - return handleUpdate(http, currentVersion, true, requestCB); +HTTPUpdateResult HTTPUpdate::updateSpiffs(NetworkClient& client, const String& url, const String& currentVersion, HTTPUpdateRequestCB requestCB) { + HTTPClient http; + if (!http.begin(client, url)) { + return HTTP_UPDATE_FAILED; + } + return handleUpdate(http, currentVersion, true, requestCB); } HTTPUpdateResult HTTPUpdate::update(HTTPClient& httpClient, - const String& currentVersion, HTTPUpdateRequestCB requestCB) -{ - return handleUpdate(httpClient, currentVersion, false, requestCB); + const String& currentVersion, HTTPUpdateRequestCB requestCB) { + return handleUpdate(httpClient, currentVersion, false, requestCB); } HTTPUpdateResult HTTPUpdate::update(NetworkClient& client, const String& host, uint16_t port, const String& uri, - const String& currentVersion, HTTPUpdateRequestCB requestCB) -{ - HTTPClient http; - if(!http.begin(client, host, port, uri)) - { - return HTTP_UPDATE_FAILED; - } - return handleUpdate(http, currentVersion, false, requestCB); + const String& currentVersion, HTTPUpdateRequestCB requestCB) { + HTTPClient http; + if (!http.begin(client, host, port, uri)) { + return HTTP_UPDATE_FAILED; + } + return handleUpdate(http, currentVersion, false, requestCB); } /** * return error code as int * @return int error code */ -int HTTPUpdate::getLastError(void) -{ - return _lastError; +int HTTPUpdate::getLastError(void) { + return _lastError; } /** * return error code as String * @return String error */ -String HTTPUpdate::getLastErrorString(void) -{ +String HTTPUpdate::getLastErrorString(void) { - if(_lastError == 0) { - return String(); // no error - } + if (_lastError == 0) { + return String(); // no error + } - // error from Update class - if(_lastError > 0) { - StreamString error; - Update.printError(error); - error.trim(); // remove line ending - return String("Update error: ") + error; - } + // error from Update class + if (_lastError > 0) { + StreamString error; + Update.printError(error); + error.trim(); // remove line ending + return String("Update error: ") + error; + } - // error from http client - if(_lastError > -100) { - return String("HTTP error: ") + HTTPClient::errorToString(_lastError); - } + // error from http client + if (_lastError > -100) { + return String("HTTP error: ") + HTTPClient::errorToString(_lastError); + } - switch(_lastError) { + switch (_lastError) { case HTTP_UE_TOO_LESS_SPACE: - return "Not Enough space"; + return "Not Enough space"; case HTTP_UE_SERVER_NOT_REPORT_SIZE: - return "Server Did Not Report Size"; + return "Server Did Not Report Size"; case HTTP_UE_SERVER_FILE_NOT_FOUND: - return "File Not Found (404)"; + return "File Not Found (404)"; case HTTP_UE_SERVER_FORBIDDEN: - return "Forbidden (403)"; + return "Forbidden (403)"; case HTTP_UE_SERVER_WRONG_HTTP_CODE: - return "Wrong HTTP Code"; + return "Wrong HTTP Code"; case HTTP_UE_SERVER_FAULTY_MD5: - return "Wrong MD5"; + return "Wrong MD5"; case HTTP_UE_BIN_VERIFY_HEADER_FAILED: - return "Verify Bin Header Failed"; + return "Verify Bin Header Failed"; case HTTP_UE_BIN_FOR_WRONG_FLASH: - return "New Binary Does Not Fit Flash Size"; + return "New Binary Does Not Fit Flash Size"; case HTTP_UE_NO_PARTITION: - return "Partition Could Not be Found"; - } + return "Partition Could Not be Found"; + } - return String(); + return String(); } String getSketchSHA256() { - const size_t HASH_LEN = 32; // SHA-256 digest length + const size_t HASH_LEN = 32; // SHA-256 digest length uint8_t sha_256[HASH_LEN] = { 0 }; -// get sha256 digest for running partition - if(esp_partition_get_sha256(esp_ota_get_running_partition(), sha_256) == 0) { + // get sha256 digest for running partition + if (esp_partition_get_sha256(esp_ota_get_running_partition(), sha_256) == 0) { char buffer[2 * HASH_LEN + 1]; - for(size_t index = 0; index < HASH_LEN; index++) { + for (size_t index = 0; index < HASH_LEN; index++) { uint8_t nibble = (sha_256[index] & 0xf0) >> 4; buffer[2 * index] = nibble < 10 ? char(nibble + '0') : char(nibble - 10 + 'A'); @@ -186,154 +173,153 @@ String getSketchSHA256() { * @param currentVersion const char * * @return HTTPUpdateResult */ -HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& currentVersion, bool spiffs, HTTPUpdateRequestCB requestCB) -{ - - HTTPUpdateResult ret = HTTP_UPDATE_FAILED; - - // use HTTP/1.0 for update since the update handler not support any transfer Encoding - http.useHTTP10(true); - http.setTimeout(_httpClientTimeout); - http.setFollowRedirects(_followRedirects); - http.setUserAgent("ESP32-http-Update"); - http.addHeader("Cache-Control", "no-cache"); - http.addHeader("x-ESP32-BASE-MAC", Network.macAddress()); +HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& currentVersion, bool spiffs, HTTPUpdateRequestCB requestCB) { + + HTTPUpdateResult ret = HTTP_UPDATE_FAILED; + + // use HTTP/1.0 for update since the update handler not support any transfer Encoding + http.useHTTP10(true); + http.setTimeout(_httpClientTimeout); + http.setFollowRedirects(_followRedirects); + http.setUserAgent("ESP32-http-Update"); + http.addHeader("Cache-Control", "no-cache"); + http.addHeader("x-ESP32-BASE-MAC", Network.macAddress()); #if SOC_WIFI_SUPPORTED - http.addHeader("x-ESP32-STA-MAC", WiFi.macAddress()); - http.addHeader("x-ESP32-AP-MAC", WiFi.softAPmacAddress()); + http.addHeader("x-ESP32-STA-MAC", WiFi.macAddress()); + http.addHeader("x-ESP32-AP-MAC", WiFi.softAPmacAddress()); #endif - http.addHeader("x-ESP32-free-space", String(ESP.getFreeSketchSpace())); - http.addHeader("x-ESP32-sketch-size", String(ESP.getSketchSize())); - String sketchMD5 = ESP.getSketchMD5(); - if(sketchMD5.length() != 0) { - http.addHeader("x-ESP32-sketch-md5", sketchMD5); - } - // Add also a SHA256 - String sketchSHA256 = getSketchSHA256(); - if(sketchSHA256.length() != 0) { - http.addHeader("x-ESP32-sketch-sha256", sketchSHA256); - } - http.addHeader("x-ESP32-chip-size", String(ESP.getFlashChipSize())); - http.addHeader("x-ESP32-sdk-version", ESP.getSdkVersion()); + http.addHeader("x-ESP32-free-space", String(ESP.getFreeSketchSpace())); + http.addHeader("x-ESP32-sketch-size", String(ESP.getSketchSize())); + String sketchMD5 = ESP.getSketchMD5(); + if (sketchMD5.length() != 0) { + http.addHeader("x-ESP32-sketch-md5", sketchMD5); + } + // Add also a SHA256 + String sketchSHA256 = getSketchSHA256(); + if (sketchSHA256.length() != 0) { + http.addHeader("x-ESP32-sketch-sha256", sketchSHA256); + } + http.addHeader("x-ESP32-chip-size", String(ESP.getFlashChipSize())); + http.addHeader("x-ESP32-sdk-version", ESP.getSdkVersion()); - if(spiffs) { - http.addHeader("x-ESP32-mode", "spiffs"); - } else { - http.addHeader("x-ESP32-mode", "sketch"); - } + if (spiffs) { + http.addHeader("x-ESP32-mode", "spiffs"); + } else { + http.addHeader("x-ESP32-mode", "sketch"); + } - if(currentVersion && currentVersion[0] != 0x00) { - http.addHeader("x-ESP32-version", currentVersion); - } - if (requestCB) { - requestCB(&http); - } + if (currentVersion && currentVersion[0] != 0x00) { + http.addHeader("x-ESP32-version", currentVersion); + } + if (requestCB) { + requestCB(&http); + } - if (!_user.isEmpty() && !_password.isEmpty()) { - http.setAuthorization(_user.c_str(), _password.c_str()); - } + if (!_user.isEmpty() && !_password.isEmpty()) { + http.setAuthorization(_user.c_str(), _password.c_str()); + } - if (!_auth.isEmpty()) { - http.setAuthorization(_auth.c_str()); - } + if (!_auth.isEmpty()) { + http.setAuthorization(_auth.c_str()); + } - const char * headerkeys[] = { "x-MD5" }; - size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*); + const char* headerkeys[] = { "x-MD5" }; + size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*); - // track these headers - http.collectHeaders(headerkeys, headerkeyssize); + // track these headers + http.collectHeaders(headerkeys, headerkeyssize); - int code = http.GET(); - int len = http.getSize(); + int code = http.GET(); + int len = http.getSize(); - if(code <= 0) { - log_e("HTTP error: %s\n", http.errorToString(code).c_str()); - _lastError = code; - http.end(); - return HTTP_UPDATE_FAILED; - } + if (code <= 0) { + log_e("HTTP error: %s\n", http.errorToString(code).c_str()); + _lastError = code; + http.end(); + return HTTP_UPDATE_FAILED; + } - log_d("Header read fin.\n"); - log_d("Server header:\n"); - log_d(" - code: %d\n", code); - log_d(" - len: %d\n", len); + log_d("Header read fin.\n"); + log_d("Server header:\n"); + log_d(" - code: %d\n", code); + log_d(" - len: %d\n", len); - String md5; - if (_md5Sum.length()) { - md5 = _md5Sum; - } else if(http.hasHeader("x-MD5")) { - md5 = http.header("x-MD5"); - } - if(md5.length()) { - log_d(" - MD5: %s\n",md5.c_str()); - } + String md5; + if (_md5Sum.length()) { + md5 = _md5Sum; + } else if (http.hasHeader("x-MD5")) { + md5 = http.header("x-MD5"); + } + if (md5.length()) { + log_d(" - MD5: %s\n", md5.c_str()); + } - log_d("ESP32 info:\n"); - log_d(" - free Space: %d\n", ESP.getFreeSketchSpace()); - log_d(" - current Sketch Size: %d\n", ESP.getSketchSize()); + log_d("ESP32 info:\n"); + log_d(" - free Space: %d\n", ESP.getFreeSketchSpace()); + log_d(" - current Sketch Size: %d\n", ESP.getSketchSize()); - if(currentVersion && currentVersion[0] != 0x00) { - log_d(" - current version: %s\n", currentVersion.c_str() ); - } + if (currentVersion && currentVersion[0] != 0x00) { + log_d(" - current version: %s\n", currentVersion.c_str()); + } - switch(code) { + switch (code) { case HTTP_CODE_OK: ///< OK (Start Update) - if(len > 0) { - bool startUpdate = true; - if(spiffs) { - const esp_partition_t* _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL); - if(!_partition){ - _lastError = HTTP_UE_NO_PARTITION; - return HTTP_UPDATE_FAILED; - } - - if(len > _partition->size) { - log_e("spiffsSize to low (%d) needed: %d\n", _partition->size, len); - startUpdate = false; - } - } else { - int sketchFreeSpace = ESP.getFreeSketchSpace(); - if(!sketchFreeSpace){ - _lastError = HTTP_UE_NO_PARTITION; - return HTTP_UPDATE_FAILED; - } - - if(len > sketchFreeSpace) { - log_e("FreeSketchSpace to low (%d) needed: %d\n", sketchFreeSpace, len); - startUpdate = false; - } - } + if (len > 0) { + bool startUpdate = true; + if (spiffs) { + const esp_partition_t* _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL); + if (!_partition) { + _lastError = HTTP_UE_NO_PARTITION; + return HTTP_UPDATE_FAILED; + } + + if (len > _partition->size) { + log_e("spiffsSize to low (%d) needed: %d\n", _partition->size, len); + startUpdate = false; + } + } else { + int sketchFreeSpace = ESP.getFreeSketchSpace(); + if (!sketchFreeSpace) { + _lastError = HTTP_UE_NO_PARTITION; + return HTTP_UPDATE_FAILED; + } + + if (len > sketchFreeSpace) { + log_e("FreeSketchSpace to low (%d) needed: %d\n", sketchFreeSpace, len); + startUpdate = false; + } + } - if(!startUpdate) { - _lastError = HTTP_UE_TOO_LESS_SPACE; - ret = HTTP_UPDATE_FAILED; - } else { - // Warn main app we're starting up... - if (_cbStart) { - _cbStart(); - } + if (!startUpdate) { + _lastError = HTTP_UE_TOO_LESS_SPACE; + ret = HTTP_UPDATE_FAILED; + } else { + // Warn main app we're starting up... + if (_cbStart) { + _cbStart(); + } - NetworkClient * tcp = http.getStreamPtr(); + NetworkClient* tcp = http.getStreamPtr(); -// To do? NetworkUDP::stopAll(); -// To do? NetworkClient::stopAllExcept(tcp); + // To do? NetworkUDP::stopAll(); + // To do? NetworkClient::stopAllExcept(tcp); - delay(100); + delay(100); - int command; + int command; - if(spiffs) { - command = U_SPIFFS; - log_d("runUpdate spiffs...\n"); - } else { - command = U_FLASH; - log_d("runUpdate flash...\n"); - } + if (spiffs) { + command = U_SPIFFS; + log_d("runUpdate spiffs...\n"); + } else { + command = U_FLASH; + log_d("runUpdate flash...\n"); + } - if(!spiffs) { -/* To do + if (!spiffs) { + /* To do uint8_t buf[4]; if(tcp->peekBytes(&buf[0], 4) != 4) { log_e("peekBytes magic header failed\n"); @@ -343,16 +329,15 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren } */ - // check for valid first magic byte -// if(buf[0] != 0xE9) { - if(tcp->peek() != 0xE9) { - log_e("Magic header does not start with 0xE9\n"); - _lastError = HTTP_UE_BIN_VERIFY_HEADER_FAILED; - http.end(); - return HTTP_UPDATE_FAILED; - - } -/* To do + // check for valid first magic byte + // if(buf[0] != 0xE9) { + if (tcp->peek() != 0xE9) { + log_e("Magic header does not start with 0xE9\n"); + _lastError = HTTP_UE_BIN_VERIFY_HEADER_FAILED; + http.end(); + return HTTP_UPDATE_FAILED; + } + /* To do uint32_t bin_flash_size = ESP.magicFlashChipSize((buf[3] & 0xf0) >> 4); // check if new bin fits to SPI flash @@ -363,52 +348,52 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren return HTTP_UPDATE_FAILED; } */ - } - if(runUpdate(*tcp, len, md5, command)) { - ret = HTTP_UPDATE_OK; - log_d("Update ok\n"); - http.end(); - // Warn main app we're all done - if (_cbEnd) { - _cbEnd(); - } - - if(_rebootOnUpdate && !spiffs) { - ESP.restart(); - } + } + if (runUpdate(*tcp, len, md5, command)) { + ret = HTTP_UPDATE_OK; + log_d("Update ok\n"); + http.end(); + // Warn main app we're all done + if (_cbEnd) { + _cbEnd(); + } - } else { - ret = HTTP_UPDATE_FAILED; - log_e("Update failed\n"); - } + if (_rebootOnUpdate && !spiffs) { + ESP.restart(); } - } else { - _lastError = HTTP_UE_SERVER_NOT_REPORT_SIZE; + + } else { ret = HTTP_UPDATE_FAILED; - log_e("Content-Length was 0 or wasn't set by Server?!\n"); + log_e("Update failed\n"); + } } - break; + } else { + _lastError = HTTP_UE_SERVER_NOT_REPORT_SIZE; + ret = HTTP_UPDATE_FAILED; + log_e("Content-Length was 0 or wasn't set by Server?!\n"); + } + break; case HTTP_CODE_NOT_MODIFIED: - ///< Not Modified (No updates) - ret = HTTP_UPDATE_NO_UPDATES; - break; + ///< Not Modified (No updates) + ret = HTTP_UPDATE_NO_UPDATES; + break; case HTTP_CODE_NOT_FOUND: - _lastError = HTTP_UE_SERVER_FILE_NOT_FOUND; - ret = HTTP_UPDATE_FAILED; - break; + _lastError = HTTP_UE_SERVER_FILE_NOT_FOUND; + ret = HTTP_UPDATE_FAILED; + break; case HTTP_CODE_FORBIDDEN: - _lastError = HTTP_UE_SERVER_FORBIDDEN; - ret = HTTP_UPDATE_FAILED; - break; + _lastError = HTTP_UE_SERVER_FORBIDDEN; + ret = HTTP_UPDATE_FAILED; + break; default: - _lastError = HTTP_UE_SERVER_WRONG_HTTP_CODE; - ret = HTTP_UPDATE_FAILED; - log_e("HTTP Code is (%d)\n", code); - break; - } + _lastError = HTTP_UE_SERVER_WRONG_HTTP_CODE; + ret = HTTP_UPDATE_FAILED; + log_e("HTTP Code is (%d)\n", code); + break; + } - http.end(); - return ret; + http.end(); + return ret; } /** @@ -418,58 +403,57 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren * @param md5 String * @return true if Update ok */ -bool HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5, int command) -{ +bool HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5, int command) { - StreamString error; + StreamString error; - if (_cbProgress) { - Update.onProgress(_cbProgress); - } + if (_cbProgress) { + Update.onProgress(_cbProgress); + } - if(!Update.begin(size, command, _ledPin, _ledOn)) { - _lastError = Update.getError(); - Update.printError(error); - error.trim(); // remove line ending - log_e("Update.begin failed! (%s)\n", error.c_str()); - return false; - } + if (!Update.begin(size, command, _ledPin, _ledOn)) { + _lastError = Update.getError(); + Update.printError(error); + error.trim(); // remove line ending + log_e("Update.begin failed! (%s)\n", error.c_str()); + return false; + } - if (_cbProgress) { - _cbProgress(0, size); - } + if (_cbProgress) { + _cbProgress(0, size); + } - if(md5.length()) { - if(!Update.setMD5(md5.c_str())) { - _lastError = HTTP_UE_SERVER_FAULTY_MD5; - log_e("Update.setMD5 failed! (%s)\n", md5.c_str()); - return false; - } + if (md5.length()) { + if (!Update.setMD5(md5.c_str())) { + _lastError = HTTP_UE_SERVER_FAULTY_MD5; + log_e("Update.setMD5 failed! (%s)\n", md5.c_str()); + return false; } + } -// To do: the SHA256 could be checked if the server sends it + // To do: the SHA256 could be checked if the server sends it - if(Update.writeStream(in) != size) { - _lastError = Update.getError(); - Update.printError(error); - error.trim(); // remove line ending - log_e("Update.writeStream failed! (%s)\n", error.c_str()); - return false; - } + if (Update.writeStream(in) != size) { + _lastError = Update.getError(); + Update.printError(error); + error.trim(); // remove line ending + log_e("Update.writeStream failed! (%s)\n", error.c_str()); + return false; + } - if (_cbProgress) { - _cbProgress(size, size); - } + if (_cbProgress) { + _cbProgress(size, size); + } - if(!Update.end()) { - _lastError = Update.getError(); - Update.printError(error); - error.trim(); // remove line ending - log_e("Update.end failed! (%s)\n", error.c_str()); - return false; - } + if (!Update.end()) { + _lastError = Update.getError(); + Update.printError(error); + error.trim(); // remove line ending + log_e("Update.end failed! (%s)\n", error.c_str()); + return false; + } - return true; + return true; } #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_HTTPUPDATE) diff --git a/libraries/HTTPUpdate/src/HTTPUpdate.h b/libraries/HTTPUpdate/src/HTTPUpdate.h index b915bb0a8bd..8620af39837 100644 --- a/libraries/HTTPUpdate/src/HTTPUpdate.h +++ b/libraries/HTTPUpdate/src/HTTPUpdate.h @@ -32,23 +32,23 @@ #include /// note we use HTTP client errors too so we start at 100 -#define HTTP_UE_TOO_LESS_SPACE (-100) -#define HTTP_UE_SERVER_NOT_REPORT_SIZE (-101) -#define HTTP_UE_SERVER_FILE_NOT_FOUND (-102) -#define HTTP_UE_SERVER_FORBIDDEN (-103) -#define HTTP_UE_SERVER_WRONG_HTTP_CODE (-104) -#define HTTP_UE_SERVER_FAULTY_MD5 (-105) -#define HTTP_UE_BIN_VERIFY_HEADER_FAILED (-106) -#define HTTP_UE_BIN_FOR_WRONG_FLASH (-107) -#define HTTP_UE_NO_PARTITION (-108) +#define HTTP_UE_TOO_LESS_SPACE (-100) +#define HTTP_UE_SERVER_NOT_REPORT_SIZE (-101) +#define HTTP_UE_SERVER_FILE_NOT_FOUND (-102) +#define HTTP_UE_SERVER_FORBIDDEN (-103) +#define HTTP_UE_SERVER_WRONG_HTTP_CODE (-104) +#define HTTP_UE_SERVER_FAULTY_MD5 (-105) +#define HTTP_UE_BIN_VERIFY_HEADER_FAILED (-106) +#define HTTP_UE_BIN_FOR_WRONG_FLASH (-107) +#define HTTP_UE_NO_PARTITION (-108) enum HTTPUpdateResult { - HTTP_UPDATE_FAILED, - HTTP_UPDATE_NO_UPDATES, - HTTP_UPDATE_OK + HTTP_UPDATE_FAILED, + HTTP_UPDATE_NO_UPDATES, + HTTP_UPDATE_OK }; -typedef HTTPUpdateResult t_httpUpdate_return; // backward compatibility +typedef HTTPUpdateResult t_httpUpdate_return; // backward compatibility using HTTPUpdateStartCB = std::function; using HTTPUpdateRequestCB = std::function; @@ -56,100 +56,101 @@ using HTTPUpdateEndCB = std::function; using HTTPUpdateErrorCB = std::function; using HTTPUpdateProgressCB = std::function; -class HTTPUpdate -{ +class HTTPUpdate { public: - HTTPUpdate(void); - HTTPUpdate(int httpClientTimeout); - ~HTTPUpdate(void); + HTTPUpdate(void); + HTTPUpdate(int httpClientTimeout); + ~HTTPUpdate(void); - void rebootOnUpdate(bool reboot) - { - _rebootOnUpdate = reboot; - } - - /** - * set redirect follow mode. See `followRedirects_t` enum for avaliable modes. + void rebootOnUpdate(bool reboot) { + _rebootOnUpdate = reboot; + } + + /** + * set redirect follow mode. See `followRedirects_t` enum for available modes. * @param follow */ - void setFollowRedirects(followRedirects_t follow) - { - _followRedirects = follow; - } - - void setLedPin(int ledPin = -1, uint8_t ledOn = HIGH) - { - _ledPin = ledPin; - _ledOn = ledOn; - } - - void setMD5sum(const String &md5Sum) - { - _md5Sum = md5Sum; - } - - void setAuthorization(const String& user, const String& password) - { - _user = user; - _password = password; - } - - void setAuthorization(const String& auth) - { - _auth = auth; - } - - t_httpUpdate_return update(NetworkClient& client, const String& url, const String& currentVersion = "", HTTPUpdateRequestCB requestCB = NULL); - - t_httpUpdate_return update(NetworkClient& client, const String& host, uint16_t port, const String& uri = "/", - const String& currentVersion = "", HTTPUpdateRequestCB requestCB = NULL); - - t_httpUpdate_return updateSpiffs(NetworkClient& client, const String& url, const String& currentVersion = "", HTTPUpdateRequestCB requestCB = NULL); - - t_httpUpdate_return update(HTTPClient& httpClient, - const String& currentVersion = "", - HTTPUpdateRequestCB requestCB = NULL); - - t_httpUpdate_return updateSpiffs(HTTPClient &httpClient, const String ¤tVersion = "", HTTPUpdateRequestCB requestCB = NULL); - - // Notification callbacks - void onStart(HTTPUpdateStartCB cbOnStart) { _cbStart = cbOnStart; } - void onEnd(HTTPUpdateEndCB cbOnEnd) { _cbEnd = cbOnEnd; } - void onError(HTTPUpdateErrorCB cbOnError) { _cbError = cbOnError; } - void onProgress(HTTPUpdateProgressCB cbOnProgress) { _cbProgress = cbOnProgress; } - - int getLastError(void); - String getLastErrorString(void); + void setFollowRedirects(followRedirects_t follow) { + _followRedirects = follow; + } + + void setLedPin(int ledPin = -1, uint8_t ledOn = HIGH) { + _ledPin = ledPin; + _ledOn = ledOn; + } + + void setMD5sum(const String& md5Sum) { + _md5Sum = md5Sum; + } + + void setAuthorization(const String& user, const String& password) { + _user = user; + _password = password; + } + + void setAuthorization(const String& auth) { + _auth = auth; + } + + t_httpUpdate_return update(NetworkClient& client, const String& url, const String& currentVersion = "", HTTPUpdateRequestCB requestCB = NULL); + + t_httpUpdate_return update(NetworkClient& client, const String& host, uint16_t port, const String& uri = "/", + const String& currentVersion = "", HTTPUpdateRequestCB requestCB = NULL); + + t_httpUpdate_return updateSpiffs(NetworkClient& client, const String& url, const String& currentVersion = "", HTTPUpdateRequestCB requestCB = NULL); + + t_httpUpdate_return update(HTTPClient& httpClient, + const String& currentVersion = "", + HTTPUpdateRequestCB requestCB = NULL); + + t_httpUpdate_return updateSpiffs(HTTPClient& httpClient, const String& currentVersion = "", HTTPUpdateRequestCB requestCB = NULL); + + // Notification callbacks + void onStart(HTTPUpdateStartCB cbOnStart) { + _cbStart = cbOnStart; + } + void onEnd(HTTPUpdateEndCB cbOnEnd) { + _cbEnd = cbOnEnd; + } + void onError(HTTPUpdateErrorCB cbOnError) { + _cbError = cbOnError; + } + void onProgress(HTTPUpdateProgressCB cbOnProgress) { + _cbProgress = cbOnProgress; + } + + int getLastError(void); + String getLastErrorString(void); protected: - t_httpUpdate_return handleUpdate(HTTPClient& http, const String& currentVersion, bool spiffs = false, HTTPUpdateRequestCB requestCB = NULL); - bool runUpdate(Stream& in, uint32_t size, String md5, int command = U_FLASH); - - // Set the error and potentially use a CB to notify the application - void _setLastError(int err) { - _lastError = err; - if (_cbError) { - _cbError(err); - } + t_httpUpdate_return handleUpdate(HTTPClient& http, const String& currentVersion, bool spiffs = false, HTTPUpdateRequestCB requestCB = NULL); + bool runUpdate(Stream& in, uint32_t size, String md5, int command = U_FLASH); + + // Set the error and potentially use a CB to notify the application + void _setLastError(int err) { + _lastError = err; + if (_cbError) { + _cbError(err); } - int _lastError; - bool _rebootOnUpdate = true; + } + int _lastError; + bool _rebootOnUpdate = true; private: - int _httpClientTimeout; - followRedirects_t _followRedirects; - String _user; - String _password; - String _auth; - String _md5Sum; - - // Callbacks - HTTPUpdateStartCB _cbStart; - HTTPUpdateEndCB _cbEnd; - HTTPUpdateErrorCB _cbError; - HTTPUpdateProgressCB _cbProgress; - - int _ledPin; - uint8_t _ledOn; + int _httpClientTimeout; + followRedirects_t _followRedirects; + String _user; + String _password; + String _auth; + String _md5Sum; + + // Callbacks + HTTPUpdateStartCB _cbStart; + HTTPUpdateEndCB _cbEnd; + HTTPUpdateErrorCB _cbError; + HTTPUpdateProgressCB _cbProgress; + + int _ledPin; + uint8_t _ledOn; }; #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_HTTPUPDATE) diff --git a/libraries/HTTPUpdateServer/examples/WebUpdater/WebUpdater.ino b/libraries/HTTPUpdateServer/examples/WebUpdater/WebUpdater.ino index 54fe6a102fc..1e3cd3afe7b 100644 --- a/libraries/HTTPUpdateServer/examples/WebUpdater/WebUpdater.ino +++ b/libraries/HTTPUpdateServer/examples/WebUpdater/WebUpdater.ino @@ -10,7 +10,7 @@ #ifndef STASSID #define STASSID "your-ssid" -#define STAPSK "your-password" +#define STAPSK "your-password" #endif const char* host = "esp32-webupdate"; @@ -47,4 +47,4 @@ void setup(void) { void loop(void) { httpServer.handleClient(); -} \ No newline at end of file +} diff --git a/libraries/HTTPUpdateServer/keywords.txt b/libraries/HTTPUpdateServer/keywords.txt index a6f8a0c191c..210c80ac9c0 100644 --- a/libraries/HTTPUpdateServer/keywords.txt +++ b/libraries/HTTPUpdateServer/keywords.txt @@ -17,4 +17,4 @@ setup KEYWORD2 ####################################### # Constants (LITERAL1) -####################################### \ No newline at end of file +####################################### diff --git a/libraries/HTTPUpdateServer/library.properties b/libraries/HTTPUpdateServer/library.properties index a1e448c906f..e700659fa0a 100644 --- a/libraries/HTTPUpdateServer/library.properties +++ b/libraries/HTTPUpdateServer/library.properties @@ -6,4 +6,4 @@ sentence=Simple HTTP Update server based on the WebServer paragraph=The library accepts HTTP post requests to the /update url, and updates the ESP32 firmware. category=Communication url= -architectures=esp32 \ No newline at end of file +architectures=esp32 diff --git a/libraries/HTTPUpdateServer/src/HTTPUpdateServer.h b/libraries/HTTPUpdateServer/src/HTTPUpdateServer.h index aa53ce6b0fe..16def2cf7f0 100644 --- a/libraries/HTTPUpdateServer/src/HTTPUpdateServer.h +++ b/libraries/HTTPUpdateServer/src/HTTPUpdateServer.h @@ -1,14 +1,14 @@ #ifndef __HTTP_UPDATE_SERVER_H #define __HTTP_UPDATE_SERVER_H -#include +#include #include #include #include static const char serverIndex[] PROGMEM = -R"( + R"( @@ -28,139 +28,128 @@ R"( )"; static const char successResponse[] PROGMEM = -"Update Success! Rebooting..."; + "Update Success! Rebooting..."; -class HTTPUpdateServer -{ +class HTTPUpdateServer { public: - HTTPUpdateServer(bool serial_debug=false) { - _serial_output = serial_debug; - _server = NULL; - _username = emptyString; - _password = emptyString; - _authenticated = false; - } - - void setup(WebServer *server) - { - setup(server, emptyString, emptyString); - } - - void setup(WebServer *server, const String& path) - { - setup(server, path, emptyString, emptyString); - } - - void setup(WebServer *server, const String& username, const String& password) - { - setup(server, "/update", username, password); - } - - void setup(WebServer *server, const String& path, const String& username, const String& password) - { - - _server = server; - _username = username; - _password = password; - - // handler for the /update form page - _server->on(path.c_str(), HTTP_GET, [&]() { - if (_username != emptyString && _password != emptyString && !_server->authenticate(_username.c_str(), _password.c_str())) - return _server->requestAuthentication(); - _server->send_P(200, PSTR("text/html"), serverIndex); - }); - - // handler for the /update form POST (once file upload finishes) - _server->on(path.c_str(), HTTP_POST, [&]() { - if (!_authenticated) - return _server->requestAuthentication(); - if (Update.hasError()) { - _server->send(200, F("text/html"), String(F("Update error: ")) + _updaterError); + HTTPUpdateServer(bool serial_debug = false) { + _serial_output = serial_debug; + _server = NULL; + _username = emptyString; + _password = emptyString; + _authenticated = false; + } + + void setup(WebServer* server) { + setup(server, emptyString, emptyString); + } + + void setup(WebServer* server, const String& path) { + setup(server, path, emptyString, emptyString); + } + + void setup(WebServer* server, const String& username, const String& password) { + setup(server, "/update", username, password); + } + + void setup(WebServer* server, const String& path, const String& username, const String& password) { + + _server = server; + _username = username; + _password = password; + + // handler for the /update form page + _server->on(path.c_str(), HTTP_GET, [&]() { + if (_username != emptyString && _password != emptyString && !_server->authenticate(_username.c_str(), _password.c_str())) + return _server->requestAuthentication(); + _server->send_P(200, PSTR("text/html"), serverIndex); + }); + + // handler for the /update form POST (once file upload finishes) + _server->on( + path.c_str(), HTTP_POST, [&]() { + if (!_authenticated) + return _server->requestAuthentication(); + if (Update.hasError()) { + _server->send(200, F("text/html"), String(F("Update error: ")) + _updaterError); + } else { + _server->client().setNoDelay(true); + _server->send_P(200, PSTR("text/html"), successResponse); + delay(100); + _server->client().stop(); + ESP.restart(); + } + }, + [&]() { + // handler for the file upload, gets the sketch bytes, and writes + // them through the Update object + HTTPUpload& upload = _server->upload(); + + if (upload.status == UPLOAD_FILE_START) { + _updaterError.clear(); + if (_serial_output) + Serial.setDebugOutput(true); + + _authenticated = (_username == emptyString || _password == emptyString || _server->authenticate(_username.c_str(), _password.c_str())); + if (!_authenticated) { + if (_serial_output) + Serial.printf("Unauthenticated Update\n"); + return; + } + + if (_serial_output) + Serial.printf("Update: %s\n", upload.filename.c_str()); + if (upload.name == "filesystem") { + if (!Update.begin(SPIFFS.totalBytes(), U_SPIFFS)) { //start with max available size + if (_serial_output) Update.printError(Serial); } - else { - _server->client().setNoDelay(true); - _server->send_P(200, PSTR("text/html"), successResponse); - delay(100); - _server->client().stop(); - ESP.restart(); + } else { + uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; + if (!Update.begin(maxSketchSpace, U_FLASH)) { //start with max available size + _setUpdaterError(); } - }, [&]() { - // handler for the file upload, get's the sketch bytes, and writes - // them through the Update object - HTTPUpload& upload = _server->upload(); - - if (upload.status == UPLOAD_FILE_START) { - _updaterError.clear(); - if (_serial_output) - Serial.setDebugOutput(true); - - _authenticated = (_username == emptyString || _password == emptyString || _server->authenticate(_username.c_str(), _password.c_str())); - if (!_authenticated) { - if (_serial_output) - Serial.printf("Unauthenticated Update\n"); - return; - } - - if (_serial_output) - Serial.printf("Update: %s\n", upload.filename.c_str()); - if (upload.name == "filesystem") { - if (!Update.begin(SPIFFS.totalBytes(), U_SPIFFS)) {//start with max available size - if (_serial_output) Update.printError(Serial); - } - } - else { - uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; - if (!Update.begin(maxSketchSpace, U_FLASH)) {//start with max available size - _setUpdaterError(); - } - } - } - else if (_authenticated && upload.status == UPLOAD_FILE_WRITE && !_updaterError.length()) { - if (_serial_output) Serial.printf("."); - if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) { - _setUpdaterError(); - } - } - else if (_authenticated && upload.status == UPLOAD_FILE_END && !_updaterError.length()) { - if (Update.end(true)) { //true to set the size to the current progress - if (_serial_output) Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize); - } - else { - _setUpdaterError(); - } - if (_serial_output) Serial.setDebugOutput(false); - } - else if (_authenticated && upload.status == UPLOAD_FILE_ABORTED) { - Update.end(); - if (_serial_output) Serial.println("Update was aborted"); - } - delay(0); - }); - } - - void updateCredentials(const String& username, const String& password) - { - _username = username; - _password = password; - } + } + } else if (_authenticated && upload.status == UPLOAD_FILE_WRITE && !_updaterError.length()) { + if (_serial_output) Serial.printf("."); + if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) { + _setUpdaterError(); + } + } else if (_authenticated && upload.status == UPLOAD_FILE_END && !_updaterError.length()) { + if (Update.end(true)) { //true to set the size to the current progress + if (_serial_output) Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize); + } else { + _setUpdaterError(); + } + if (_serial_output) Serial.setDebugOutput(false); + } else if (_authenticated && upload.status == UPLOAD_FILE_ABORTED) { + Update.end(); + if (_serial_output) Serial.println("Update was aborted"); + } + delay(0); + }); + } + + void updateCredentials(const String& username, const String& password) { + _username = username; + _password = password; + } protected: - void _setUpdaterError() - { - if (_serial_output) Update.printError(Serial); - StreamString str; - Update.printError(str); - _updaterError = str.c_str(); - } + void _setUpdaterError() { + if (_serial_output) Update.printError(Serial); + StreamString str; + Update.printError(str); + _updaterError = str.c_str(); + } private: - bool _serial_output; - WebServer *_server; - String _username; - String _password; - bool _authenticated; - String _updaterError; + bool _serial_output; + WebServer* _server; + String _username; + String _password; + bool _authenticated; + String _updaterError; }; -#endif \ No newline at end of file +#endif diff --git a/libraries/Insights/examples/DiagnosticsSmokeTest/DiagnosticsSmokeTest.ino b/libraries/Insights/examples/DiagnosticsSmokeTest/DiagnosticsSmokeTest.ino index 535409f7075..a672fdf610e 100644 --- a/libraries/Insights/examples/DiagnosticsSmokeTest/DiagnosticsSmokeTest.ino +++ b/libraries/Insights/examples/DiagnosticsSmokeTest/DiagnosticsSmokeTest.ino @@ -6,93 +6,90 @@ const char insights_auth_key[] = ""; -#define WIFI_SSID "" +#define WIFI_SSID "" #define WIFI_PASSPHRASE "" -#define MAX_CRASHES 5 -#define MAX_PTRS 30 -#define TAG "sketch" +#define MAX_CRASHES 5 +#define MAX_PTRS 30 +#define TAG "sketch" RTC_NOINIT_ATTR static uint32_t s_reset_count; static void *s_ptrs[MAX_PTRS]; -static void smoke_test() -{ - int dice; - int count = 0; - bool allocating = false; +static void smoke_test() { + int dice; + int count = 0; + bool allocating = false; - while (1) { - dice = esp_random() % 500; - log_i("dice=%d", dice); - if (dice > 0 && dice < 150) { - log_e("[count][%d]", count); - } else if (dice > 150 && dice < 300) { - log_w("[count][%d]", count); - } else if (dice > 300 && dice < 470) { - Insights.event(TAG, "[count][%d]", count); - } else { - /* 30 in 500 probability to crash */ - if (s_reset_count > MAX_CRASHES) { - Insights.event(TAG, "[count][%d]", count); - } else { - log_e("[count][%d] [crash_count][%" PRIu32 "] [excvaddr][0x0f] Crashing...", count, s_reset_count); - *(int *)0x0F = 0x10; - } - } - - Insights.metrics.dumpHeap(); - if (count % MAX_PTRS == 0) { - allocating = !allocating; - log_i("Allocating:%s\n", allocating ? "true" : "false"); - } - if (allocating) { - uint32_t size = 1024 * (esp_random() % 8); - void *p = malloc(size); - if (p) { - memset(p, size, 'A' + (esp_random() % 26)); - log_i("Allocated %" PRIu32 " bytes", size); - } - s_ptrs[count % MAX_PTRS] = p; - } else { - free(s_ptrs[count % MAX_PTRS]); - s_ptrs[count % MAX_PTRS] = NULL; - log_i("Freeing some memory..."); - } - - count++; - delay(1000); + while (1) { + dice = esp_random() % 500; + log_i("dice=%d", dice); + if (dice > 0 && dice < 150) { + log_e("[count][%d]", count); + } else if (dice > 150 && dice < 300) { + log_w("[count][%d]", count); + } else if (dice > 300 && dice < 470) { + Insights.event(TAG, "[count][%d]", count); + } else { + /* 30 in 500 probability to crash */ + if (s_reset_count > MAX_CRASHES) { + Insights.event(TAG, "[count][%d]", count); + } else { + log_e("[count][%d] [crash_count][%" PRIu32 "] [excvaddr][0x0f] Crashing...", count, s_reset_count); + *(int *)0x0F = 0x10; + } } -} -void setup() -{ - Serial.begin(115200); - WiFi.mode(WIFI_STA); - WiFi.begin(WIFI_SSID, WIFI_PASSPHRASE); - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); + Insights.metrics.dumpHeap(); + if (count % MAX_PTRS == 0) { + allocating = !allocating; + log_i("Allocating:%s\n", allocating ? "true" : "false"); } - Serial.println(""); - Serial.println("WiFi connected"); - - if(!Insights.begin(insights_auth_key)){ - return; + if (allocating) { + uint32_t size = 1024 * (esp_random() % 8); + void *p = malloc(size); + if (p) { + memset(p, size, 'A' + (esp_random() % 26)); + log_i("Allocated %" PRIu32 " bytes", size); + } + s_ptrs[count % MAX_PTRS] = p; + } else { + free(s_ptrs[count % MAX_PTRS]); + s_ptrs[count % MAX_PTRS] = NULL; + log_i("Freeing some memory..."); } - Serial.println("========================================="); - Serial.printf("ESP Insights enabled Node ID %s\n", Insights.nodeID()); - Serial.println("========================================="); - if (esp_reset_reason() == ESP_RST_POWERON) { - s_reset_count = 1; - } else { - s_reset_count++; - } + count++; + delay(1000); + } +} + +void setup() { + Serial.begin(115200); + WiFi.mode(WIFI_STA); + WiFi.begin(WIFI_SSID, WIFI_PASSPHRASE); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println(""); + Serial.println("WiFi connected"); + + if (!Insights.begin(insights_auth_key)) { + return; + } + Serial.println("========================================="); + Serial.printf("ESP Insights enabled Node ID %s\n", Insights.nodeID()); + Serial.println("========================================="); + + if (esp_reset_reason() == ESP_RST_POWERON) { + s_reset_count = 1; + } else { + s_reset_count++; + } } -void loop() -{ - smoke_test(); - delay(100); +void loop() { + smoke_test(); + delay(100); } diff --git a/libraries/Insights/examples/DiagnosticsSmokeTest/README.md b/libraries/Insights/examples/DiagnosticsSmokeTest/README.md index 9094eeca5d2..3938a9d1f6c 100644 --- a/libraries/Insights/examples/DiagnosticsSmokeTest/README.md +++ b/libraries/Insights/examples/DiagnosticsSmokeTest/README.md @@ -42,4 +42,4 @@ E (75826) diag_smoke: [count][7] [crash_count][1] [excvaddr][0x0f] Crashing... * Select the node-id printed on the console, look for the below log. It is printed early when device boots up ``` ESP Insights enabled for Node ID ----- wx3vEoGgJPk7Rn5JvRUFs9 -``` \ No newline at end of file +``` diff --git a/libraries/Insights/examples/MinimalDiagnostics/MinimalDiagnostics.ino b/libraries/Insights/examples/MinimalDiagnostics/MinimalDiagnostics.ino index 39cac0c13a5..e9c0670102f 100644 --- a/libraries/Insights/examples/MinimalDiagnostics/MinimalDiagnostics.ino +++ b/libraries/Insights/examples/MinimalDiagnostics/MinimalDiagnostics.ino @@ -3,29 +3,27 @@ const char insights_auth_key[] = ""; -#define WIFI_SSID "" +#define WIFI_SSID "" #define WIFI_PASSPHRASE "" -void setup() -{ - Serial.begin(115200); - WiFi.mode(WIFI_STA); - WiFi.begin(WIFI_SSID, WIFI_PASSPHRASE); - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } - Serial.println(""); - Serial.println("WiFi connected"); - if(!Insights.begin(insights_auth_key)){ - return; - } - Serial.println("========================================="); - Serial.printf("ESP Insights enabled Node ID %s\n", Insights.nodeID()); - Serial.println("========================================="); +void setup() { + Serial.begin(115200); + WiFi.mode(WIFI_STA); + WiFi.begin(WIFI_SSID, WIFI_PASSPHRASE); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println(""); + Serial.println("WiFi connected"); + if (!Insights.begin(insights_auth_key)) { + return; + } + Serial.println("========================================="); + Serial.printf("ESP Insights enabled Node ID %s\n", Insights.nodeID()); + Serial.println("========================================="); } -void loop() -{ - delay(1000); +void loop() { + delay(1000); } diff --git a/libraries/Insights/library.properties b/libraries/Insights/library.properties index 489aa298618..8d7237cd626 100644 --- a/libraries/Insights/library.properties +++ b/libraries/Insights/library.properties @@ -3,6 +3,6 @@ version=1.0.0 author=Sanket Wadekar maintainer=Sanket Wadekar sentence=ESP Insights -paragraph=With this library you can remotely monitor your device error logs, Network variables, WiFi/Heap Metrics, and also custom varibles / metrics. +paragraph=With this library you can remotely monitor your device error logs, Network variables, WiFi/Heap Metrics, and also custom variables / metrics. url=https://insights.espressif.com architectures=esp32 diff --git a/libraries/Insights/src/Insights.cpp b/libraries/Insights/src/Insights.cpp index 49de5b2035a..bdd5d84b206 100644 --- a/libraries/Insights/src/Insights.cpp +++ b/libraries/Insights/src/Insights.cpp @@ -12,275 +12,276 @@ #include "esp_diagnostics_variables.h" #include "esp_diagnostics_network_variables.h" -const char * ERROR_INSIGHTS_NOT_INIT = "ESP Insights not initialized"; - -#define BOOL_FN_OR_ERROR(f,e) \ - if(!initialized){ \ - log_e("%s",ERROR_INSIGHTS_NOT_INIT); \ - return false; \ - } \ - esp_err_t err = f; \ - if (err != ESP_OK) { \ - log_e("ESP Insights " e ", err:0x%x", err); \ - } \ - return err == ESP_OK; - -#define BOOL_FN_OR_ERROR_ARG(f,e,a) \ - if(!initialized){ \ - log_e("%s",ERROR_INSIGHTS_NOT_INIT); \ - return false; \ - } \ - esp_err_t err = f; \ - if (err != ESP_OK) { \ - log_e("ESP Insights " e ", err:0x%x", a, err); \ - } \ - return err == ESP_OK; +const char *ERROR_INSIGHTS_NOT_INIT = "ESP Insights not initialized"; + +#define BOOL_FN_OR_ERROR(f, e) \ + if (!initialized) { \ + log_e("%s", ERROR_INSIGHTS_NOT_INIT); \ + return false; \ + } \ + esp_err_t err = f; \ + if (err != ESP_OK) { \ + log_e("ESP Insights " e ", err:0x%x", err); \ + } \ + return err == ESP_OK; + +#define BOOL_FN_OR_ERROR_ARG(f, e, a) \ + if (!initialized) { \ + log_e("%s", ERROR_INSIGHTS_NOT_INIT); \ + return false; \ + } \ + esp_err_t err = f; \ + if (err != ESP_OK) { \ + log_e("ESP Insights " e ", err:0x%x", a, err); \ + } \ + return err == ESP_OK; #define VOID_FN_OR_ERROR(f) \ - if(!initialized){ \ - log_e("%s",ERROR_INSIGHTS_NOT_INIT); \ - return; \ - } \ - f; - -ESPInsightsClass::ESPInsightsClass(): initialized(false){} - -ESPInsightsClass::~ESPInsightsClass(){ - end(); -} - -bool ESPInsightsClass::begin(const char *auth_key, const char *node_id, uint32_t log_type, bool alloc_ext_ram, bool use_default_transport){ - if(!initialized){ - if(log_type == 0xFFFFFFFF){ - log_type = (ESP_DIAG_LOG_TYPE_ERROR | ESP_DIAG_LOG_TYPE_WARNING | ESP_DIAG_LOG_TYPE_EVENT); - } - esp_insights_config_t config = {.log_type = log_type, .node_id = node_id, .auth_key = auth_key, .alloc_ext_ram = alloc_ext_ram}; - esp_err_t err = ESP_OK; - if (use_default_transport) { - err = esp_insights_init(&config); - } else { - err = esp_insights_enable(&config); - } - if (err != ESP_OK) { - log_e("Failed to initialize ESP Insights, err:0x%x", err); - } - initialized = err == ESP_OK; - metrics.setInitialized(initialized); - variables.setInitialized(initialized); - } else { - log_i("ESP Insights already initialized"); - } - return initialized; -} + if (!initialized) { \ + log_e("%s", ERROR_INSIGHTS_NOT_INIT); \ + return; \ + } \ + f; -void ESPInsightsClass::end(){ - if(initialized){ - esp_insights_deinit(); - initialized = false; - metrics.setInitialized(initialized); - variables.setInitialized(initialized); - } -} +ESPInsightsClass::ESPInsightsClass() + : initialized(false) {} -const char * ESPInsightsClass::nodeID(){ - if(!initialized){ - log_e("%s",ERROR_INSIGHTS_NOT_INIT); - return ""; - } - return esp_insights_get_node_id(); +ESPInsightsClass::~ESPInsightsClass() { + end(); } -bool ESPInsightsClass::event(const char *tag, const char *format, ...){ - if(!initialized){ - log_e("%s",ERROR_INSIGHTS_NOT_INIT); - return false; +bool ESPInsightsClass::begin(const char *auth_key, const char *node_id, uint32_t log_type, bool alloc_ext_ram, bool use_default_transport) { + if (!initialized) { + if (log_type == 0xFFFFFFFF) { + log_type = (ESP_DIAG_LOG_TYPE_ERROR | ESP_DIAG_LOG_TYPE_WARNING | ESP_DIAG_LOG_TYPE_EVENT); } - - char loc_buf[64]; - char * temp = loc_buf; - va_list arg; - va_list copy; - va_start(arg, format); - va_copy(copy, arg); - int len = vsnprintf(temp, sizeof(loc_buf), format, copy); - va_end(copy); - if(len < 0) { - va_end(arg); - return false; - }; - if(len >= (int)sizeof(loc_buf)){ // comparation of same sign type for the compiler - temp = (char*) malloc(len+1); - if(temp == NULL) { - va_end(arg); - return false; - } - len = vsnprintf(temp, len+1, format, arg); - } - va_end(arg); - esp_err_t err = esp_diag_log_event(tag, "%s", temp); - if(temp != loc_buf){ - free(temp); + esp_insights_config_t config = { .log_type = log_type, .node_id = node_id, .auth_key = auth_key, .alloc_ext_ram = alloc_ext_ram }; + esp_err_t err = ESP_OK; + if (use_default_transport) { + err = esp_insights_init(&config); + } else { + err = esp_insights_enable(&config); } if (err != ESP_OK) { - log_e("Failed to send ESP Insights event, err:0x%x", err); + log_e("Failed to initialize ESP Insights, err:0x%x", err); + } + initialized = err == ESP_OK; + metrics.setInitialized(initialized); + variables.setInitialized(initialized); + } else { + log_i("ESP Insights already initialized"); + } + return initialized; +} + +void ESPInsightsClass::end() { + if (initialized) { + esp_insights_deinit(); + initialized = false; + metrics.setInitialized(initialized); + variables.setInitialized(initialized); + } +} + +const char *ESPInsightsClass::nodeID() { + if (!initialized) { + log_e("%s", ERROR_INSIGHTS_NOT_INIT); + return ""; + } + return esp_insights_get_node_id(); +} + +bool ESPInsightsClass::event(const char *tag, const char *format, ...) { + if (!initialized) { + log_e("%s", ERROR_INSIGHTS_NOT_INIT); + return false; + } + + char loc_buf[64]; + char *temp = loc_buf; + va_list arg; + va_list copy; + va_start(arg, format); + va_copy(copy, arg); + int len = vsnprintf(temp, sizeof(loc_buf), format, copy); + va_end(copy); + if (len < 0) { + va_end(arg); + return false; + }; + if (len >= (int)sizeof(loc_buf)) { // comparison of same sign type for the compiler + temp = (char *)malloc(len + 1); + if (temp == NULL) { + va_end(arg); + return false; } - return err == ESP_OK; + len = vsnprintf(temp, len + 1, format, arg); + } + va_end(arg); + esp_err_t err = esp_diag_log_event(tag, "%s", temp); + if (temp != loc_buf) { + free(temp); + } + if (err != ESP_OK) { + log_e("Failed to send ESP Insights event, err:0x%x", err); + } + return err == ESP_OK; } -bool ESPInsightsClass::send(){ - BOOL_FN_OR_ERROR(esp_insights_send_data(),"Failed to send"); +bool ESPInsightsClass::send() { + BOOL_FN_OR_ERROR(esp_insights_send_data(), "Failed to send"); } -void ESPInsightsClass::dumpTasksStatus(){ - VOID_FN_OR_ERROR(esp_diag_task_snapshot_dump()); +void ESPInsightsClass::dumpTasksStatus() { + VOID_FN_OR_ERROR(esp_diag_task_snapshot_dump()); } // ESPInsightsMetricsClass -bool ESPInsightsMetricsClass::addBool(const char *tag, const char *key, const char *label, const char *path){ - BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_BOOL),"Failed to add metric '%s'",key); +bool ESPInsightsMetricsClass::addBool(const char *tag, const char *key, const char *label, const char *path) { + BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_BOOL), "Failed to add metric '%s'", key); } -bool ESPInsightsMetricsClass::addInt(const char *tag, const char *key, const char *label, const char *path){ - BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_INT),"Failed to add metric '%s'",key); +bool ESPInsightsMetricsClass::addInt(const char *tag, const char *key, const char *label, const char *path) { + BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_INT), "Failed to add metric '%s'", key); } -bool ESPInsightsMetricsClass::addUint(const char *tag, const char *key, const char *label, const char *path){ - BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_UINT),"Failed to add metric '%s'",key); +bool ESPInsightsMetricsClass::addUint(const char *tag, const char *key, const char *label, const char *path) { + BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_UINT), "Failed to add metric '%s'", key); } -bool ESPInsightsMetricsClass::addFloat(const char *tag, const char *key, const char *label, const char *path){ - BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_FLOAT),"Failed to add metric '%s'",key); +bool ESPInsightsMetricsClass::addFloat(const char *tag, const char *key, const char *label, const char *path) { + BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_FLOAT), "Failed to add metric '%s'", key); } -bool ESPInsightsMetricsClass::addString(const char *tag, const char *key, const char *label, const char *path){ - BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_STR),"Failed to add metric '%s'",key); +bool ESPInsightsMetricsClass::addString(const char *tag, const char *key, const char *label, const char *path) { + BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_STR), "Failed to add metric '%s'", key); } -bool ESPInsightsMetricsClass::addIPv4(const char *tag, const char *key, const char *label, const char *path){ - BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_IPv4),"Failed to add metric '%s'",key); +bool ESPInsightsMetricsClass::addIPv4(const char *tag, const char *key, const char *label, const char *path) { + BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_IPv4), "Failed to add metric '%s'", key); } -bool ESPInsightsMetricsClass::addMAC(const char *tag, const char *key, const char *label, const char *path){ - BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_MAC),"Failed to add metric '%s'",key); +bool ESPInsightsMetricsClass::addMAC(const char *tag, const char *key, const char *label, const char *path) { + BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_MAC), "Failed to add metric '%s'", key); } -bool ESPInsightsMetricsClass::setBool(const char *key, bool b){ - BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_add_bool(key, b),"Failed to set metric '%s'",key); +bool ESPInsightsMetricsClass::setBool(const char *key, bool b) { + BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_add_bool(key, b), "Failed to set metric '%s'", key); } -bool ESPInsightsMetricsClass::setInt(const char *key, int32_t i){ - BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_add_int(key, i),"Failed to set metric '%s'",key); +bool ESPInsightsMetricsClass::setInt(const char *key, int32_t i) { + BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_add_int(key, i), "Failed to set metric '%s'", key); } -bool ESPInsightsMetricsClass::setUint(const char *key, uint32_t u){ - BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_add_uint(key, u),"Failed to set metric '%s'",key); +bool ESPInsightsMetricsClass::setUint(const char *key, uint32_t u) { + BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_add_uint(key, u), "Failed to set metric '%s'", key); } -bool ESPInsightsMetricsClass::setFloat(const char *key, float f){ - BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_add_float(key, f),"Failed to set metric '%s'",key); +bool ESPInsightsMetricsClass::setFloat(const char *key, float f) { + BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_add_float(key, f), "Failed to set metric '%s'", key); } -bool ESPInsightsMetricsClass::setString(const char *key, const char *str){ - BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_add_str(key, str),"Failed to set metric '%s'",key); +bool ESPInsightsMetricsClass::setString(const char *key, const char *str) { + BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_add_str(key, str), "Failed to set metric '%s'", key); } -bool ESPInsightsMetricsClass::setIPv4(const char *key, uint32_t ip){ - BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_add_ipv4(key, ip),"Failed to set metric '%s'",key); +bool ESPInsightsMetricsClass::setIPv4(const char *key, uint32_t ip) { + BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_add_ipv4(key, ip), "Failed to set metric '%s'", key); } -bool ESPInsightsMetricsClass::setMAC(const char *key, uint8_t *mac){ - BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_add_mac(key, mac),"Failed to set metric '%s'",key); +bool ESPInsightsMetricsClass::setMAC(const char *key, uint8_t *mac) { + BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_add_mac(key, mac), "Failed to set metric '%s'", key); } -bool ESPInsightsMetricsClass::remove(const char *key){ - BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_unregister(key),"Failed to remove metric '%s'",key); +bool ESPInsightsMetricsClass::remove(const char *key) { + BOOL_FN_OR_ERROR_ARG(esp_diag_metrics_unregister(key), "Failed to remove metric '%s'", key); } -bool ESPInsightsMetricsClass::removeAll(){ - BOOL_FN_OR_ERROR(esp_diag_metrics_unregister_all(),"Failed to remove metrics"); +bool ESPInsightsMetricsClass::removeAll() { + BOOL_FN_OR_ERROR(esp_diag_metrics_unregister_all(), "Failed to remove metrics"); } -void ESPInsightsMetricsClass::setHeapPeriod(uint32_t seconds){ - VOID_FN_OR_ERROR(esp_diag_heap_metrics_reset_interval(seconds)); +void ESPInsightsMetricsClass::setHeapPeriod(uint32_t seconds) { + VOID_FN_OR_ERROR(esp_diag_heap_metrics_reset_interval(seconds)); } -bool ESPInsightsMetricsClass::dumpHeap(){ - BOOL_FN_OR_ERROR(esp_diag_heap_metrics_dump(),"Failed to send heap metrics"); +bool ESPInsightsMetricsClass::dumpHeap() { + BOOL_FN_OR_ERROR(esp_diag_heap_metrics_dump(), "Failed to send heap metrics"); } -void ESPInsightsMetricsClass::setWiFiPeriod(uint32_t seconds){ - VOID_FN_OR_ERROR(esp_diag_wifi_metrics_reset_interval(seconds)); +void ESPInsightsMetricsClass::setWiFiPeriod(uint32_t seconds) { + VOID_FN_OR_ERROR(esp_diag_wifi_metrics_reset_interval(seconds)); } -bool ESPInsightsMetricsClass::dumpWiFi(){ - BOOL_FN_OR_ERROR(esp_diag_wifi_metrics_dump(),"Failed to send wifi metrics"); +bool ESPInsightsMetricsClass::dumpWiFi() { + BOOL_FN_OR_ERROR(esp_diag_wifi_metrics_dump(), "Failed to send wifi metrics"); } // ESPInsightsVariablesClass -bool ESPInsightsVariablesClass::addBool(const char *tag, const char *key, const char *label, const char *path){ - BOOL_FN_OR_ERROR_ARG(esp_diag_variable_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_BOOL),"Failed to add variable '%s'",key); +bool ESPInsightsVariablesClass::addBool(const char *tag, const char *key, const char *label, const char *path) { + BOOL_FN_OR_ERROR_ARG(esp_diag_variable_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_BOOL), "Failed to add variable '%s'", key); } -bool ESPInsightsVariablesClass::addInt(const char *tag, const char *key, const char *label, const char *path){ - BOOL_FN_OR_ERROR_ARG(esp_diag_variable_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_INT),"Failed to add variable '%s'",key); +bool ESPInsightsVariablesClass::addInt(const char *tag, const char *key, const char *label, const char *path) { + BOOL_FN_OR_ERROR_ARG(esp_diag_variable_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_INT), "Failed to add variable '%s'", key); } -bool ESPInsightsVariablesClass::addUint(const char *tag, const char *key, const char *label, const char *path){ - BOOL_FN_OR_ERROR_ARG(esp_diag_variable_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_UINT),"Failed to add variable '%s'",key); +bool ESPInsightsVariablesClass::addUint(const char *tag, const char *key, const char *label, const char *path) { + BOOL_FN_OR_ERROR_ARG(esp_diag_variable_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_UINT), "Failed to add variable '%s'", key); } -bool ESPInsightsVariablesClass::addFloat(const char *tag, const char *key, const char *label, const char *path){ - BOOL_FN_OR_ERROR_ARG(esp_diag_variable_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_FLOAT),"Failed to add variable '%s'",key); +bool ESPInsightsVariablesClass::addFloat(const char *tag, const char *key, const char *label, const char *path) { + BOOL_FN_OR_ERROR_ARG(esp_diag_variable_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_FLOAT), "Failed to add variable '%s'", key); } -bool ESPInsightsVariablesClass::addString(const char *tag, const char *key, const char *label, const char *path){ - BOOL_FN_OR_ERROR_ARG(esp_diag_variable_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_STR),"Failed to add variable '%s'",key); +bool ESPInsightsVariablesClass::addString(const char *tag, const char *key, const char *label, const char *path) { + BOOL_FN_OR_ERROR_ARG(esp_diag_variable_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_STR), "Failed to add variable '%s'", key); } -bool ESPInsightsVariablesClass::addIPv4(const char *tag, const char *key, const char *label, const char *path){ - BOOL_FN_OR_ERROR_ARG(esp_diag_variable_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_IPv4),"Failed to add variable '%s'",key); +bool ESPInsightsVariablesClass::addIPv4(const char *tag, const char *key, const char *label, const char *path) { + BOOL_FN_OR_ERROR_ARG(esp_diag_variable_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_IPv4), "Failed to add variable '%s'", key); } -bool ESPInsightsVariablesClass::addMAC(const char *tag, const char *key, const char *label, const char *path){ - BOOL_FN_OR_ERROR_ARG(esp_diag_variable_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_MAC),"Failed to add variable '%s'",key); +bool ESPInsightsVariablesClass::addMAC(const char *tag, const char *key, const char *label, const char *path) { + BOOL_FN_OR_ERROR_ARG(esp_diag_variable_register(tag, key, label, path, ESP_DIAG_DATA_TYPE_MAC), "Failed to add variable '%s'", key); } -bool ESPInsightsVariablesClass::setBool(const char *key, bool b){ - BOOL_FN_OR_ERROR_ARG(esp_diag_variable_add_bool(key, b),"Failed to set variable '%s'",key); +bool ESPInsightsVariablesClass::setBool(const char *key, bool b) { + BOOL_FN_OR_ERROR_ARG(esp_diag_variable_add_bool(key, b), "Failed to set variable '%s'", key); } -bool ESPInsightsVariablesClass::setInt(const char *key, int32_t i){ - BOOL_FN_OR_ERROR_ARG(esp_diag_variable_add_int(key, i),"Failed to set variable '%s'",key); +bool ESPInsightsVariablesClass::setInt(const char *key, int32_t i) { + BOOL_FN_OR_ERROR_ARG(esp_diag_variable_add_int(key, i), "Failed to set variable '%s'", key); } -bool ESPInsightsVariablesClass::setUint(const char *key, uint32_t u){ - BOOL_FN_OR_ERROR_ARG(esp_diag_variable_add_uint(key, u),"Failed to set variable '%s'",key); +bool ESPInsightsVariablesClass::setUint(const char *key, uint32_t u) { + BOOL_FN_OR_ERROR_ARG(esp_diag_variable_add_uint(key, u), "Failed to set variable '%s'", key); } -bool ESPInsightsVariablesClass::setFloat(const char *key, float f){ - BOOL_FN_OR_ERROR_ARG(esp_diag_variable_add_float(key, f),"Failed to set variable '%s'",key); +bool ESPInsightsVariablesClass::setFloat(const char *key, float f) { + BOOL_FN_OR_ERROR_ARG(esp_diag_variable_add_float(key, f), "Failed to set variable '%s'", key); } -bool ESPInsightsVariablesClass::setString(const char *key, const char *str){ - BOOL_FN_OR_ERROR_ARG(esp_diag_variable_add_str(key, str),"Failed to set variable '%s'",key); +bool ESPInsightsVariablesClass::setString(const char *key, const char *str) { + BOOL_FN_OR_ERROR_ARG(esp_diag_variable_add_str(key, str), "Failed to set variable '%s'", key); } -bool ESPInsightsVariablesClass::setIPv4(const char *key, uint32_t ip){ - BOOL_FN_OR_ERROR_ARG(esp_diag_variable_add_ipv4(key, ip),"Failed to set variable '%s'",key); +bool ESPInsightsVariablesClass::setIPv4(const char *key, uint32_t ip) { + BOOL_FN_OR_ERROR_ARG(esp_diag_variable_add_ipv4(key, ip), "Failed to set variable '%s'", key); } -bool ESPInsightsVariablesClass::setMAC(const char *key, uint8_t *mac){ - BOOL_FN_OR_ERROR_ARG(esp_diag_variable_add_mac(key, mac),"Failed to set variable '%s'",key); +bool ESPInsightsVariablesClass::setMAC(const char *key, uint8_t *mac) { + BOOL_FN_OR_ERROR_ARG(esp_diag_variable_add_mac(key, mac), "Failed to set variable '%s'", key); } -bool ESPInsightsVariablesClass::remove(const char *key){ - BOOL_FN_OR_ERROR_ARG(esp_diag_variable_unregister(key),"Failed to remove variable '%s'",key); +bool ESPInsightsVariablesClass::remove(const char *key) { + BOOL_FN_OR_ERROR_ARG(esp_diag_variable_unregister(key), "Failed to remove variable '%s'", key); } -bool ESPInsightsVariablesClass::removeAll(){ - BOOL_FN_OR_ERROR(esp_diag_variable_unregister_all(),"Failed to remove variables"); +bool ESPInsightsVariablesClass::removeAll() { + BOOL_FN_OR_ERROR(esp_diag_variable_unregister_all(), "Failed to remove variables"); } ESPInsightsClass Insights; diff --git a/libraries/Insights/src/Insights.h b/libraries/Insights/src/Insights.h index d572c35a012..42285660cce 100644 --- a/libraries/Insights/src/Insights.h +++ b/libraries/Insights/src/Insights.h @@ -10,106 +10,109 @@ #ifdef __cplusplus -class ESPInsightsMetricsClass -{ - private: - bool initialized; - - public: - ESPInsightsMetricsClass():initialized(false){} - - bool addBool(const char *tag, const char *key, const char *label, const char *path); - bool addInt(const char *tag, const char *key, const char *label, const char *path); - bool addUint(const char *tag, const char *key, const char *label, const char *path); - bool addFloat(const char *tag, const char *key, const char *label, const char *path); - bool addString(const char *tag, const char *key, const char *label, const char *path); - bool addIPv4(const char *tag, const char *key, const char *label, const char *path); - bool addMAC(const char *tag, const char *key, const char *label, const char *path); - - bool setBool(const char *key, bool b); - bool setInt(const char *key, int32_t i); - bool setUint(const char *key, uint32_t u); - bool setFloat(const char *key, float f); - bool setString(const char *key, const char *str); - bool setIPv4(const char *key, uint32_t ip); - bool setMAC(const char *key, uint8_t *mac); - - bool remove(const char *key); - bool removeAll(); - - void setHeapPeriod(uint32_t seconds); - void setWiFiPeriod(uint32_t seconds); - - bool dumpHeap(); - bool dumpWiFi(); - - //internal use - void setInitialized(bool init){ initialized = init; } +class ESPInsightsMetricsClass { +private: + bool initialized; + +public: + ESPInsightsMetricsClass() + : initialized(false) {} + + bool addBool(const char *tag, const char *key, const char *label, const char *path); + bool addInt(const char *tag, const char *key, const char *label, const char *path); + bool addUint(const char *tag, const char *key, const char *label, const char *path); + bool addFloat(const char *tag, const char *key, const char *label, const char *path); + bool addString(const char *tag, const char *key, const char *label, const char *path); + bool addIPv4(const char *tag, const char *key, const char *label, const char *path); + bool addMAC(const char *tag, const char *key, const char *label, const char *path); + + bool setBool(const char *key, bool b); + bool setInt(const char *key, int32_t i); + bool setUint(const char *key, uint32_t u); + bool setFloat(const char *key, float f); + bool setString(const char *key, const char *str); + bool setIPv4(const char *key, uint32_t ip); + bool setMAC(const char *key, uint8_t *mac); + + bool remove(const char *key); + bool removeAll(); + + void setHeapPeriod(uint32_t seconds); + void setWiFiPeriod(uint32_t seconds); + + bool dumpHeap(); + bool dumpWiFi(); + + //internal use + void setInitialized(bool init) { + initialized = init; + } }; -class ESPInsightsVariablesClass -{ - private: - bool initialized; - - public: - ESPInsightsVariablesClass():initialized(false){} - - bool addBool(const char *tag, const char *key, const char *label, const char *path); - bool addInt(const char *tag, const char *key, const char *label, const char *path); - bool addUint(const char *tag, const char *key, const char *label, const char *path); - bool addFloat(const char *tag, const char *key, const char *label, const char *path); - bool addString(const char *tag, const char *key, const char *label, const char *path); - bool addIPv4(const char *tag, const char *key, const char *label, const char *path); - bool addMAC(const char *tag, const char *key, const char *label, const char *path); - - bool setBool(const char *key, bool b); - bool setInt(const char *key, int32_t i); - bool setUint(const char *key, uint32_t u); - bool setFloat(const char *key, float f); - bool setString(const char *key, const char *str); - bool setIPv4(const char *key, uint32_t ip); - bool setMAC(const char *key, uint8_t *mac); - - bool remove(const char *key); - bool removeAll(); - - //internal use - void setInitialized(bool init){ initialized = init; } +class ESPInsightsVariablesClass { +private: + bool initialized; + +public: + ESPInsightsVariablesClass() + : initialized(false) {} + + bool addBool(const char *tag, const char *key, const char *label, const char *path); + bool addInt(const char *tag, const char *key, const char *label, const char *path); + bool addUint(const char *tag, const char *key, const char *label, const char *path); + bool addFloat(const char *tag, const char *key, const char *label, const char *path); + bool addString(const char *tag, const char *key, const char *label, const char *path); + bool addIPv4(const char *tag, const char *key, const char *label, const char *path); + bool addMAC(const char *tag, const char *key, const char *label, const char *path); + + bool setBool(const char *key, bool b); + bool setInt(const char *key, int32_t i); + bool setUint(const char *key, uint32_t u); + bool setFloat(const char *key, float f); + bool setString(const char *key, const char *str); + bool setIPv4(const char *key, uint32_t ip); + bool setMAC(const char *key, uint8_t *mac); + + bool remove(const char *key); + bool removeAll(); + + //internal use + void setInitialized(bool init) { + initialized = init; + } }; -class ESPInsightsClass -{ - private: - bool initialized; - - public: - ESPInsightsMetricsClass metrics; - ESPInsightsVariablesClass variables; - - ESPInsightsClass(); - ~ESPInsightsClass(); - - bool begin(const char *auth_key, const char *node_id = NULL, uint32_t log_type = 0xFFFFFFFF, bool alloc_ext_ram = false, bool use_default_transport = true); - void end(); - bool send(); - const char * nodeID(); - - void dumpTasksStatus(); - - bool event(const char *tag, const char *format, ...); +class ESPInsightsClass { +private: + bool initialized; + +public: + ESPInsightsMetricsClass metrics; + ESPInsightsVariablesClass variables; + + ESPInsightsClass(); + ~ESPInsightsClass(); + + bool begin(const char *auth_key, const char *node_id = NULL, uint32_t log_type = 0xFFFFFFFF, bool alloc_ext_ram = false, bool use_default_transport = true); + void end(); + bool send(); + const char *nodeID(); + + void dumpTasksStatus(); + + bool event(const char *tag, const char *format, ...); }; extern ESPInsightsClass Insights; -extern "C" -{ +extern "C" { #endif #include "esp_err.h" #include "esp_log.h" -esp_err_t esp_diag_log_event(const char *tag, const char *format, ...) __attribute__ ((format (printf, 2, 3))); -#define insightsEvent(tag, format, ...) {esp_diag_log_event(tag, "EV (%" PRIu32 ") %s: " format, esp_log_timestamp(), tag, ##__VA_ARGS__);} + esp_err_t esp_diag_log_event(const char *tag, const char *format, ...) __attribute__((format(printf, 2, 3))); +#define insightsEvent(tag, format, ...) \ + { esp_diag_log_event(tag, "EV (%" PRIu32 ") %s: " format, esp_log_timestamp(), tag, ##__VA_ARGS__); } #ifdef __cplusplus } diff --git a/libraries/LittleFS/examples/LITTLEFS_PlatformIO/.gitignore b/libraries/LittleFS/examples/LITTLEFS_PlatformIO/.gitignore index 87515a62463..653e92272d5 100644 --- a/libraries/LittleFS/examples/LITTLEFS_PlatformIO/.gitignore +++ b/libraries/LittleFS/examples/LITTLEFS_PlatformIO/.gitignore @@ -1,4 +1,4 @@ .pio .vscode mklittlefs.exe -mklittlefs \ No newline at end of file +mklittlefs diff --git a/libraries/LittleFS/examples/LITTLEFS_PlatformIO/README.md b/libraries/LittleFS/examples/LITTLEFS_PlatformIO/README.md index 773445b6d49..e3cecc6d2fe 100644 --- a/libraries/LittleFS/examples/LITTLEFS_PlatformIO/README.md +++ b/libraries/LittleFS/examples/LITTLEFS_PlatformIO/README.md @@ -1,8 +1,8 @@ # How to run on PlatformIO IDE -- Download and extract to this project root a **mklittlefs** executable for your OS [from a zipped binary here](https://github.com/earlephilhower/mklittlefs/releases) +- Download and extract to this project root a **mklittlefs** executable for your OS [from a zipped binary here](https://github.com/earlephilhower/mklittlefs/releases) - Open **LITTLEFS_PlatformIO** folder -- Run PlatformIO project task: **Upload Filesystem Image** +- Run PlatformIO project task: **Upload Filesystem Image** - Run PlatformIO project task: **Upload and Monitor** - You will see a Serial output like: ``` @@ -65,4 +65,4 @@ Deleting file: /test.txt - file deleted Test complete ``` -- If you have a module with more than 4MB flash, you can uncomment **partitions_custom.csv** in **platformio.ini** and modify the csv file accordingly \ No newline at end of file +- If you have a module with more than 4MB flash, you can uncomment **partitions_custom.csv** in **platformio.ini** and modify the csv file accordingly diff --git a/libraries/LittleFS/examples/LITTLEFS_PlatformIO/data/file1.txt b/libraries/LittleFS/examples/LITTLEFS_PlatformIO/data/file1.txt index 7c4a013e52c..72943a16fb2 100644 --- a/libraries/LittleFS/examples/LITTLEFS_PlatformIO/data/file1.txt +++ b/libraries/LittleFS/examples/LITTLEFS_PlatformIO/data/file1.txt @@ -1 +1 @@ -aaa \ No newline at end of file +aaa diff --git a/libraries/LittleFS/examples/LITTLEFS_PlatformIO/data/testfolder/test2.txt b/libraries/LittleFS/examples/LITTLEFS_PlatformIO/data/testfolder/test2.txt index 01f02e32ce8..f761ec192d9 100644 --- a/libraries/LittleFS/examples/LITTLEFS_PlatformIO/data/testfolder/test2.txt +++ b/libraries/LittleFS/examples/LITTLEFS_PlatformIO/data/testfolder/test2.txt @@ -1 +1 @@ -bbb \ No newline at end of file +bbb diff --git a/libraries/LittleFS/examples/LITTLEFS_PlatformIO/src/main.cpp b/libraries/LittleFS/examples/LITTLEFS_PlatformIO/src/main.cpp index 0fc275fcbf5..9b1ae7f32ed 100644 --- a/libraries/LittleFS/examples/LITTLEFS_PlatformIO/src/main.cpp +++ b/libraries/LittleFS/examples/LITTLEFS_PlatformIO/src/main.cpp @@ -6,277 +6,276 @@ /* You only need to format LittleFS the first time you run a test or else use the LITTLEFS plugin to create a partition https://github.com/lorol/arduino-esp32littlefs-plugin */ - + #define FORMAT_LITTLEFS_IF_FAILED true -void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ - Serial.printf("Listing directory: %s\r\n", dirname); +void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { + Serial.printf("Listing directory: %s\r\n", dirname); - File root = fs.open(dirname); - if(!root){ - Serial.println("- failed to open directory"); - return; - } - if(!root.isDirectory()){ - Serial.println(" - not a directory"); - return; - } + File root = fs.open(dirname); + if (!root) { + Serial.println("- failed to open directory"); + return; + } + if (!root.isDirectory()) { + Serial.println(" - not a directory"); + return; + } - File file = root.openNextFile(); - while(file){ - if(file.isDirectory()){ - Serial.print(" DIR : "); - - Serial.print(file.name()); - time_t t= file.getLastWrite(); - struct tm * tmstruct = localtime(&t); - Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec); - - if(levels){ - listDir(fs, file.name(), levels -1); - } - } else { - Serial.print(" FILE: "); - Serial.print(file.name()); - Serial.print(" SIZE: "); - - Serial.print(file.size()); - time_t t= file.getLastWrite(); - struct tm * tmstruct = localtime(&t); - Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec); - } - file = root.openNextFile(); - } -} + File file = root.openNextFile(); + while (file) { + if (file.isDirectory()) { + Serial.print(" DIR : "); + + Serial.print(file.name()); + time_t t = file.getLastWrite(); + struct tm *tmstruct = localtime(&t); + Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); -void createDir(fs::FS &fs, const char * path){ - Serial.printf("Creating Dir: %s\n", path); - if(fs.mkdir(path)){ - Serial.println("Dir created"); + if (levels) { + listDir(fs, file.name(), levels - 1); + } } else { - Serial.println("mkdir failed"); + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print(" SIZE: "); + + Serial.print(file.size()); + time_t t = file.getLastWrite(); + struct tm *tmstruct = localtime(&t); + Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); } + file = root.openNextFile(); + } } -void removeDir(fs::FS &fs, const char * path){ - Serial.printf("Removing Dir: %s\n", path); - if(fs.rmdir(path)){ - Serial.println("Dir removed"); - } else { - Serial.println("rmdir failed"); - } +void createDir(fs::FS &fs, const char *path) { + Serial.printf("Creating Dir: %s\n", path); + if (fs.mkdir(path)) { + Serial.println("Dir created"); + } else { + Serial.println("mkdir failed"); + } } -void readFile(fs::FS &fs, const char * path){ - Serial.printf("Reading file: %s\r\n", path); +void removeDir(fs::FS &fs, const char *path) { + Serial.printf("Removing Dir: %s\n", path); + if (fs.rmdir(path)) { + Serial.println("Dir removed"); + } else { + Serial.println("rmdir failed"); + } +} - File file = fs.open(path); - if(!file || file.isDirectory()){ - Serial.println("- failed to open file for reading"); - return; - } +void readFile(fs::FS &fs, const char *path) { + Serial.printf("Reading file: %s\r\n", path); - Serial.println("- read from file:"); - while(file.available()){ - Serial.write(file.read()); - } - file.close(); + File file = fs.open(path); + if (!file || file.isDirectory()) { + Serial.println("- failed to open file for reading"); + return; + } + + Serial.println("- read from file:"); + while (file.available()) { + Serial.write(file.read()); + } + file.close(); } -void writeFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Writing file: %s\r\n", path); +void writeFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Writing file: %s\r\n", path); - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("- failed to open file for writing"); - return; - } - if(file.print(message)){ - Serial.println("- file written"); - } else { - Serial.println("- write failed"); - } - file.close(); + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("- failed to open file for writing"); + return; + } + if (file.print(message)) { + Serial.println("- file written"); + } else { + Serial.println("- write failed"); + } + file.close(); } -void appendFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Appending to file: %s\r\n", path); +void appendFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Appending to file: %s\r\n", path); - File file = fs.open(path, FILE_APPEND); - if(!file){ - Serial.println("- failed to open file for appending"); - return; - } - if(file.print(message)){ - Serial.println("- message appended"); - } else { - Serial.println("- append failed"); - } - file.close(); + File file = fs.open(path, FILE_APPEND); + if (!file) { + Serial.println("- failed to open file for appending"); + return; + } + if (file.print(message)) { + Serial.println("- message appended"); + } else { + Serial.println("- append failed"); + } + file.close(); } -void renameFile(fs::FS &fs, const char * path1, const char * path2){ - Serial.printf("Renaming file %s to %s\r\n", path1, path2); - if (fs.rename(path1, path2)) { - Serial.println("- file renamed"); - } else { - Serial.println("- rename failed"); - } +void renameFile(fs::FS &fs, const char *path1, const char *path2) { + Serial.printf("Renaming file %s to %s\r\n", path1, path2); + if (fs.rename(path1, path2)) { + Serial.println("- file renamed"); + } else { + Serial.println("- rename failed"); + } } -void deleteFile(fs::FS &fs, const char * path){ - Serial.printf("Deleting file: %s\r\n", path); - if(fs.remove(path)){ - Serial.println("- file deleted"); - } else { - Serial.println("- delete failed"); - } +void deleteFile(fs::FS &fs, const char *path) { + Serial.printf("Deleting file: %s\r\n", path); + if (fs.remove(path)) { + Serial.println("- file deleted"); + } else { + Serial.println("- delete failed"); + } } // SPIFFS-like write and delete file // See: https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.cpp#L60 -void writeFile2(fs::FS &fs, const char * path, const char * message){ - if(!fs.exists(path)){ - if (strchr(path, '/')) { - Serial.printf("Create missing folders of: %s\r\n", path); - char *pathStr = strdup(path); - if (pathStr) { - char *ptr = strchr(pathStr, '/'); - while (ptr) { - *ptr = 0; - fs.mkdir(pathStr); - *ptr = '/'; - ptr = strchr(ptr+1, '/'); - } - } - free(pathStr); - } +void writeFile2(fs::FS &fs, const char *path, const char *message) { + if (!fs.exists(path)) { + if (strchr(path, '/')) { + Serial.printf("Create missing folders of: %s\r\n", path); + char *pathStr = strdup(path); + if (pathStr) { + char *ptr = strchr(pathStr, '/'); + while (ptr) { + *ptr = 0; + fs.mkdir(pathStr); + *ptr = '/'; + ptr = strchr(ptr + 1, '/'); + } + } + free(pathStr); } + } - Serial.printf("Writing file to: %s\r\n", path); - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("- failed to open file for writing"); - return; - } - if(file.print(message)){ - Serial.println("- file written"); - } else { - Serial.println("- write failed"); - } - file.close(); + Serial.printf("Writing file to: %s\r\n", path); + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("- failed to open file for writing"); + return; + } + if (file.print(message)) { + Serial.println("- file written"); + } else { + Serial.println("- write failed"); + } + file.close(); } // See: https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.h#L149 -void deleteFile2(fs::FS &fs, const char * path){ - Serial.printf("Deleting file and empty folders on path: %s\r\n", path); +void deleteFile2(fs::FS &fs, const char *path) { + Serial.printf("Deleting file and empty folders on path: %s\r\n", path); - if(fs.remove(path)){ - Serial.println("- file deleted"); - } else { - Serial.println("- delete failed"); - } + if (fs.remove(path)) { + Serial.println("- file deleted"); + } else { + Serial.println("- delete failed"); + } - char *pathStr = strdup(path); - if (pathStr) { - char *ptr = strrchr(pathStr, '/'); - if (ptr) { - Serial.printf("Removing all empty folders on path: %s\r\n", path); - } - while (ptr) { - *ptr = 0; - fs.rmdir(pathStr); - ptr = strrchr(pathStr, '/'); - } - free(pathStr); + char *pathStr = strdup(path); + if (pathStr) { + char *ptr = strrchr(pathStr, '/'); + if (ptr) { + Serial.printf("Removing all empty folders on path: %s\r\n", path); + } + while (ptr) { + *ptr = 0; + fs.rmdir(pathStr); + ptr = strrchr(pathStr, '/'); } + free(pathStr); + } } -void testFileIO(fs::FS &fs, const char * path){ - Serial.printf("Testing file I/O with %s\r\n", path); +void testFileIO(fs::FS &fs, const char *path) { + Serial.printf("Testing file I/O with %s\r\n", path); - static uint8_t buf[512]; - size_t len = 0; - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("- failed to open file for writing"); - return; - } + static uint8_t buf[512]; + size_t len = 0; + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("- failed to open file for writing"); + return; + } - size_t i; - Serial.print("- writing" ); - uint32_t start = millis(); - for(i=0; i<2048; i++){ - if ((i & 0x001F) == 0x001F){ - Serial.print("."); - } - file.write(buf, 512); + size_t i; + Serial.print("- writing"); + uint32_t start = millis(); + for (i = 0; i < 2048; i++) { + if ((i & 0x001F) == 0x001F) { + Serial.print("."); } - Serial.println(""); - uint32_t end = millis() - start; - Serial.printf(" - %u bytes written in %u ms\r\n", 2048 * 512, end); - file.close(); + file.write(buf, 512); + } + Serial.println(""); + uint32_t end = millis() - start; + Serial.printf(" - %u bytes written in %u ms\r\n", 2048 * 512, end); + file.close(); - file = fs.open(path); + file = fs.open(path); + start = millis(); + end = start; + i = 0; + if (file && !file.isDirectory()) { + len = file.size(); + size_t flen = len; start = millis(); - end = start; - i = 0; - if(file && !file.isDirectory()){ - len = file.size(); - size_t flen = len; - start = millis(); - Serial.print("- reading" ); - while(len){ - size_t toRead = len; - if(toRead > 512){ - toRead = 512; - } - file.read(buf, toRead); - if ((i++ & 0x001F) == 0x001F){ - Serial.print("."); - } - len -= toRead; - } - Serial.println(""); - end = millis() - start; - Serial.printf("- %u bytes read in %u ms\r\n", flen, end); - file.close(); - } else { - Serial.println("- failed to open file for reading"); + Serial.print("- reading"); + while (len) { + size_t toRead = len; + if (toRead > 512) { + toRead = 512; + } + file.read(buf, toRead); + if ((i++ & 0x001F) == 0x001F) { + Serial.print("."); + } + len -= toRead; } + Serial.println(""); + end = millis() - start; + Serial.printf("- %u bytes read in %u ms\r\n", flen, end); + file.close(); + } else { + Serial.println("- failed to open file for reading"); + } } -void setup(){ - Serial.begin(115200); - if(!LittleFS.begin(FORMAT_LITTLEFS_IF_FAILED)){ - Serial.println("LittleFS Mount Failed"); - return; - } - - listDir(LittleFS, "/", 0); - createDir(LittleFS, "/mydir"); - writeFile(LittleFS, "/mydir/hello2.txt", "Hello2"); +void setup() { + Serial.begin(115200); + if (!LittleFS.begin(FORMAT_LITTLEFS_IF_FAILED)) { + Serial.println("LittleFS Mount Failed"); + return; + } + + listDir(LittleFS, "/", 0); + createDir(LittleFS, "/mydir"); + writeFile(LittleFS, "/mydir/hello2.txt", "Hello2"); //writeFile(LittleFS, "/mydir/newdir2/newdir3/hello3.txt", "Hello3"); - writeFile2(LittleFS, "/mydir/newdir2/newdir3/hello3.txt", "Hello3"); - listDir(LittleFS, "/", 3); - deleteFile(LittleFS, "/mydir/hello2.txt"); + writeFile2(LittleFS, "/mydir/newdir2/newdir3/hello3.txt", "Hello3"); + listDir(LittleFS, "/", 3); + deleteFile(LittleFS, "/mydir/hello2.txt"); //deleteFile(LittleFS, "/mydir/newdir2/newdir3/hello3.txt"); - deleteFile2(LittleFS, "/mydir/newdir2/newdir3/hello3.txt"); - removeDir(LittleFS, "/mydir"); - listDir(LittleFS, "/", 3); - writeFile(LittleFS, "/hello.txt", "Hello "); - appendFile(LittleFS, "/hello.txt", "World!\r\n"); - readFile(LittleFS, "/hello.txt"); - renameFile(LittleFS, "/hello.txt", "/foo.txt"); - readFile(LittleFS, "/foo.txt"); - deleteFile(LittleFS, "/foo.txt"); - testFileIO(LittleFS, "/test.txt"); - deleteFile(LittleFS, "/test.txt"); - - Serial.println( "Test complete" ); -} + deleteFile2(LittleFS, "/mydir/newdir2/newdir3/hello3.txt"); + removeDir(LittleFS, "/mydir"); + listDir(LittleFS, "/", 3); + writeFile(LittleFS, "/hello.txt", "Hello "); + appendFile(LittleFS, "/hello.txt", "World!\r\n"); + readFile(LittleFS, "/hello.txt"); + renameFile(LittleFS, "/hello.txt", "/foo.txt"); + readFile(LittleFS, "/foo.txt"); + deleteFile(LittleFS, "/foo.txt"); + testFileIO(LittleFS, "/test.txt"); + deleteFile(LittleFS, "/test.txt"); -void loop(){ + Serial.println("Test complete"); +} +void loop() { } diff --git a/libraries/LittleFS/examples/LITTLEFS_test/LITTLEFS_test.ino b/libraries/LittleFS/examples/LITTLEFS_test/LITTLEFS_test.ino index 5c3ca4b2f9c..bddeb748851 100644 --- a/libraries/LittleFS/examples/LITTLEFS_test/LITTLEFS_test.ino +++ b/libraries/LittleFS/examples/LITTLEFS_test/LITTLEFS_test.ino @@ -5,7 +5,7 @@ /* You only need to format LittleFS the first time you run a test or else use the LITTLEFS plugin to create a partition https://github.com/lorol/arduino-esp32littlefs-plugin - + If you test two partitions, you need to use a custom partition.csv file, see in the sketch folder */ @@ -13,276 +13,275 @@ #define FORMAT_LITTLEFS_IF_FAILED true -void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ - Serial.printf("Listing directory: %s\r\n", dirname); - - File root = fs.open(dirname); - if(!root){ - Serial.println("- failed to open directory"); - return; - } - if(!root.isDirectory()){ - Serial.println(" - not a directory"); - return; - } +void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { + Serial.printf("Listing directory: %s\r\n", dirname); - File file = root.openNextFile(); - while(file){ - if(file.isDirectory()){ - Serial.print(" DIR : "); - Serial.println(file.name()); - if(levels){ - listDir(fs, file.path(), levels -1); - } - } else { - Serial.print(" FILE: "); - Serial.print(file.name()); - Serial.print("\tSIZE: "); - Serial.println(file.size()); - } - file = root.openNextFile(); + File root = fs.open(dirname); + if (!root) { + Serial.println("- failed to open directory"); + return; + } + if (!root.isDirectory()) { + Serial.println(" - not a directory"); + return; + } + + File file = root.openNextFile(); + while (file) { + if (file.isDirectory()) { + Serial.print(" DIR : "); + Serial.println(file.name()); + if (levels) { + listDir(fs, file.path(), levels - 1); + } + } else { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print("\tSIZE: "); + Serial.println(file.size()); } + file = root.openNextFile(); + } } -void createDir(fs::FS &fs, const char * path){ - Serial.printf("Creating Dir: %s\n", path); - if(fs.mkdir(path)){ - Serial.println("Dir created"); - } else { - Serial.println("mkdir failed"); - } +void createDir(fs::FS &fs, const char *path) { + Serial.printf("Creating Dir: %s\n", path); + if (fs.mkdir(path)) { + Serial.println("Dir created"); + } else { + Serial.println("mkdir failed"); + } } -void removeDir(fs::FS &fs, const char * path){ - Serial.printf("Removing Dir: %s\n", path); - if(fs.rmdir(path)){ - Serial.println("Dir removed"); - } else { - Serial.println("rmdir failed"); - } +void removeDir(fs::FS &fs, const char *path) { + Serial.printf("Removing Dir: %s\n", path); + if (fs.rmdir(path)) { + Serial.println("Dir removed"); + } else { + Serial.println("rmdir failed"); + } } -void readFile(fs::FS &fs, const char * path){ - Serial.printf("Reading file: %s\r\n", path); +void readFile(fs::FS &fs, const char *path) { + Serial.printf("Reading file: %s\r\n", path); - File file = fs.open(path); - if(!file || file.isDirectory()){ - Serial.println("- failed to open file for reading"); - return; - } + File file = fs.open(path); + if (!file || file.isDirectory()) { + Serial.println("- failed to open file for reading"); + return; + } - Serial.println("- read from file:"); - while(file.available()){ - Serial.write(file.read()); - } - file.close(); + Serial.println("- read from file:"); + while (file.available()) { + Serial.write(file.read()); + } + file.close(); } -void writeFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Writing file: %s\r\n", path); +void writeFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Writing file: %s\r\n", path); - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("- failed to open file for writing"); - return; - } - if(file.print(message)){ - Serial.println("- file written"); - } else { - Serial.println("- write failed"); - } - file.close(); + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("- failed to open file for writing"); + return; + } + if (file.print(message)) { + Serial.println("- file written"); + } else { + Serial.println("- write failed"); + } + file.close(); } -void appendFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Appending to file: %s\r\n", path); +void appendFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Appending to file: %s\r\n", path); - File file = fs.open(path, FILE_APPEND); - if(!file){ - Serial.println("- failed to open file for appending"); - return; - } - if(file.print(message)){ - Serial.println("- message appended"); - } else { - Serial.println("- append failed"); - } - file.close(); + File file = fs.open(path, FILE_APPEND); + if (!file) { + Serial.println("- failed to open file for appending"); + return; + } + if (file.print(message)) { + Serial.println("- message appended"); + } else { + Serial.println("- append failed"); + } + file.close(); } -void renameFile(fs::FS &fs, const char * path1, const char * path2){ - Serial.printf("Renaming file %s to %s\r\n", path1, path2); - if (fs.rename(path1, path2)) { - Serial.println("- file renamed"); - } else { - Serial.println("- rename failed"); - } +void renameFile(fs::FS &fs, const char *path1, const char *path2) { + Serial.printf("Renaming file %s to %s\r\n", path1, path2); + if (fs.rename(path1, path2)) { + Serial.println("- file renamed"); + } else { + Serial.println("- rename failed"); + } } -void deleteFile(fs::FS &fs, const char * path){ - Serial.printf("Deleting file: %s\r\n", path); - if(fs.remove(path)){ - Serial.println("- file deleted"); - } else { - Serial.println("- delete failed"); - } +void deleteFile(fs::FS &fs, const char *path) { + Serial.printf("Deleting file: %s\r\n", path); + if (fs.remove(path)) { + Serial.println("- file deleted"); + } else { + Serial.println("- delete failed"); + } } // SPIFFS-like write and delete file, better use #define CONFIG_LITTLEFS_SPIFFS_COMPAT 1 -void writeFile2(fs::FS &fs, const char * path, const char * message){ - if(!fs.exists(path)){ - if (strchr(path, '/')) { - Serial.printf("Create missing folders of: %s\r\n", path); - char *pathStr = strdup(path); - if (pathStr) { - char *ptr = strchr(pathStr, '/'); - while (ptr) { - *ptr = 0; - fs.mkdir(pathStr); - *ptr = '/'; - ptr = strchr(ptr+1, '/'); - } - } - free(pathStr); - } +void writeFile2(fs::FS &fs, const char *path, const char *message) { + if (!fs.exists(path)) { + if (strchr(path, '/')) { + Serial.printf("Create missing folders of: %s\r\n", path); + char *pathStr = strdup(path); + if (pathStr) { + char *ptr = strchr(pathStr, '/'); + while (ptr) { + *ptr = 0; + fs.mkdir(pathStr); + *ptr = '/'; + ptr = strchr(ptr + 1, '/'); + } + } + free(pathStr); } + } - Serial.printf("Writing file to: %s\r\n", path); - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("- failed to open file for writing"); - return; - } - if(file.print(message)){ - Serial.println("- file written"); - } else { - Serial.println("- write failed"); - } - file.close(); + Serial.printf("Writing file to: %s\r\n", path); + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("- failed to open file for writing"); + return; + } + if (file.print(message)) { + Serial.println("- file written"); + } else { + Serial.println("- write failed"); + } + file.close(); } -void deleteFile2(fs::FS &fs, const char * path){ - Serial.printf("Deleting file and empty folders on path: %s\r\n", path); +void deleteFile2(fs::FS &fs, const char *path) { + Serial.printf("Deleting file and empty folders on path: %s\r\n", path); - if(fs.remove(path)){ - Serial.println("- file deleted"); - } else { - Serial.println("- delete failed"); - } + if (fs.remove(path)) { + Serial.println("- file deleted"); + } else { + Serial.println("- delete failed"); + } - char *pathStr = strdup(path); - if (pathStr) { - char *ptr = strrchr(pathStr, '/'); - if (ptr) { - Serial.printf("Removing all empty folders on path: %s\r\n", path); - } - while (ptr) { - *ptr = 0; - fs.rmdir(pathStr); - ptr = strrchr(pathStr, '/'); - } - free(pathStr); + char *pathStr = strdup(path); + if (pathStr) { + char *ptr = strrchr(pathStr, '/'); + if (ptr) { + Serial.printf("Removing all empty folders on path: %s\r\n", path); } + while (ptr) { + *ptr = 0; + fs.rmdir(pathStr); + ptr = strrchr(pathStr, '/'); + } + free(pathStr); + } } -void testFileIO(fs::FS &fs, const char * path){ - Serial.printf("Testing file I/O with %s\r\n", path); +void testFileIO(fs::FS &fs, const char *path) { + Serial.printf("Testing file I/O with %s\r\n", path); - static uint8_t buf[512]; - size_t len = 0; - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("- failed to open file for writing"); - return; + static uint8_t buf[512]; + size_t len = 0; + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("- failed to open file for writing"); + return; + } + + size_t i; + Serial.print("- writing"); + uint32_t start = millis(); + for (i = 0; i < 2048; i++) { + if ((i & 0x001F) == 0x001F) { + Serial.print("."); } - - size_t i; - Serial.print("- writing" ); - uint32_t start = millis(); - for(i=0; i<2048; i++){ - if ((i & 0x001F) == 0x001F){ - Serial.print("."); - } - file.write(buf, 512); + file.write(buf, 512); + } + Serial.println(""); + uint32_t end = millis() - start; + Serial.printf(" - %u bytes written in %lu ms\r\n", 2048 * 512, end); + file.close(); + + file = fs.open(path); + start = millis(); + end = start; + i = 0; + if (file && !file.isDirectory()) { + len = file.size(); + size_t flen = len; + start = millis(); + Serial.print("- reading"); + while (len) { + size_t toRead = len; + if (toRead > 512) { + toRead = 512; + } + file.read(buf, toRead); + if ((i++ & 0x001F) == 0x001F) { + Serial.print("."); + } + len -= toRead; } Serial.println(""); - uint32_t end = millis() - start; - Serial.printf(" - %u bytes written in %lu ms\r\n", 2048 * 512, end); + end = millis() - start; + Serial.printf("- %u bytes read in %lu ms\r\n", flen, end); file.close(); - - file = fs.open(path); - start = millis(); - end = start; - i = 0; - if(file && !file.isDirectory()){ - len = file.size(); - size_t flen = len; - start = millis(); - Serial.print("- reading" ); - while(len){ - size_t toRead = len; - if(toRead > 512){ - toRead = 512; - } - file.read(buf, toRead); - if ((i++ & 0x001F) == 0x001F){ - Serial.print("."); - } - len -= toRead; - } - Serial.println(""); - end = millis() - start; - Serial.printf("- %u bytes read in %lu ms\r\n", flen, end); - file.close(); - } else { - Serial.println("- failed to open file for reading"); - } + } else { + Serial.println("- failed to open file for reading"); + } } -void setup(){ - Serial.begin(115200); +void setup() { + Serial.begin(115200); #ifdef TWOPART - if(!LittleFS.begin(FORMAT_LITTLEFS_IF_FAILED, "/lfs2", 5, "part2")){ + if (!LittleFS.begin(FORMAT_LITTLEFS_IF_FAILED, "/lfs2", 5, "part2")) { Serial.println("part2 Mount Failed"); return; - } - appendFile(LittleFS, "/hello0.txt", "World0!\r\n"); - readFile(LittleFS, "/hello0.txt"); - LittleFS.end(); + } + appendFile(LittleFS, "/hello0.txt", "World0!\r\n"); + readFile(LittleFS, "/hello0.txt"); + LittleFS.end(); - Serial.println( "Done with part2, work with the first lfs partition..." ); + Serial.println("Done with part2, work with the first lfs partition..."); #endif - if(!LittleFS.begin(FORMAT_LITTLEFS_IF_FAILED)){ - Serial.println("LittleFS Mount Failed"); - return; - } - Serial.println( "SPIFFS-like write file to new path and delete it w/folders" ); - writeFile2(LittleFS, "/new1/new2/new3/hello3.txt", "Hello3"); - listDir(LittleFS, "/", 3); - deleteFile2(LittleFS, "/new1/new2/new3/hello3.txt"); - - listDir(LittleFS, "/", 3); - createDir(LittleFS, "/mydir"); - writeFile(LittleFS, "/mydir/hello2.txt", "Hello2"); - listDir(LittleFS, "/", 1); - deleteFile(LittleFS, "/mydir/hello2.txt"); - removeDir(LittleFS, "/mydir"); - listDir(LittleFS, "/", 1); - writeFile(LittleFS, "/hello.txt", "Hello "); - appendFile(LittleFS, "/hello.txt", "World!\r\n"); - readFile(LittleFS, "/hello.txt"); - renameFile(LittleFS, "/hello.txt", "/foo.txt"); - readFile(LittleFS, "/foo.txt"); - deleteFile(LittleFS, "/foo.txt"); - testFileIO(LittleFS, "/test.txt"); - deleteFile(LittleFS, "/test.txt"); - - Serial.println( "Test complete" ); + if (!LittleFS.begin(FORMAT_LITTLEFS_IF_FAILED)) { + Serial.println("LittleFS Mount Failed"); + return; + } + Serial.println("SPIFFS-like write file to new path and delete it w/folders"); + writeFile2(LittleFS, "/new1/new2/new3/hello3.txt", "Hello3"); + listDir(LittleFS, "/", 3); + deleteFile2(LittleFS, "/new1/new2/new3/hello3.txt"); + + listDir(LittleFS, "/", 3); + createDir(LittleFS, "/mydir"); + writeFile(LittleFS, "/mydir/hello2.txt", "Hello2"); + listDir(LittleFS, "/", 1); + deleteFile(LittleFS, "/mydir/hello2.txt"); + removeDir(LittleFS, "/mydir"); + listDir(LittleFS, "/", 1); + writeFile(LittleFS, "/hello.txt", "Hello "); + appendFile(LittleFS, "/hello.txt", "World!\r\n"); + readFile(LittleFS, "/hello.txt"); + renameFile(LittleFS, "/hello.txt", "/foo.txt"); + readFile(LittleFS, "/foo.txt"); + deleteFile(LittleFS, "/foo.txt"); + testFileIO(LittleFS, "/test.txt"); + deleteFile(LittleFS, "/test.txt"); + + Serial.println("Test complete"); } -void loop(){ - +void loop() { } diff --git a/libraries/LittleFS/examples/LITTLEFS_test/partitions.csv b/libraries/LittleFS/examples/LITTLEFS_test/partitions.csv index bf492891c47..04f4a78a11f 100644 --- a/libraries/LittleFS/examples/LITTLEFS_test/partitions.csv +++ b/libraries/LittleFS/examples/LITTLEFS_test/partitions.csv @@ -5,4 +5,4 @@ app0, app, ota_0, 0x10000, 0x100000, app1, app, ota_1, ,0x100000, spiffs, data, spiffs, ,0x1D0000, part2, data, spiffs, ,0x20000, -#1048576 \ No newline at end of file +#1048576 diff --git a/libraries/LittleFS/examples/LITTLEFS_time/LITTLEFS_time.ino b/libraries/LittleFS/examples/LITTLEFS_time/LITTLEFS_time.ino index 038261b1127..72c5b4058c5 100644 --- a/libraries/LittleFS/examples/LITTLEFS_time/LITTLEFS_time.ino +++ b/libraries/LittleFS/examples/LITTLEFS_time/LITTLEFS_time.ino @@ -1,214 +1,212 @@ #include "FS.h" -//#include "SPIFFS.h" +//#include "SPIFFS.h" #include "LittleFS.h" -#include +#include #include #define SPIFFS LittleFS -/* This examples uses "quick re-define" of SPIFFS to run +/* This examples uses "quick re-define" of SPIFFS to run an existing sketch with LittleFS instead of SPIFFS You only need to format LittleFS the first time you run a test or else use the LittleFS plugin to create a partition https://github.com/lorol/arduino-esp32littlefs-plugin */ - + #define FORMAT_LITTLEFS_IF_FAILED true -const char* ssid = "yourssid"; -const char* password = "yourpass"; +const char *ssid = "yourssid"; +const char *password = "yourpass"; -long timezone = 1; +long timezone = 1; byte daysavetime = 1; -void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ - Serial.printf("Listing directory: %s\n", dirname); - - File root = fs.open(dirname); - if(!root){ - Serial.println("Failed to open directory"); - return; - } - if(!root.isDirectory()){ - Serial.println("Not a directory"); - return; - } - - File file = root.openNextFile(); - while(file){ - if(file.isDirectory()){ - Serial.print(" DIR : "); - Serial.print (file.name()); - time_t t= file.getLastWrite(); - struct tm * tmstruct = localtime(&t); - Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec); - if(levels){ - listDir(fs, file.path(), levels -1); - } - } else { - Serial.print(" FILE: "); - Serial.print(file.name()); - Serial.print(" SIZE: "); - Serial.print(file.size()); - time_t t= file.getLastWrite(); - struct tm * tmstruct = localtime(&t); - Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec); - } - file = root.openNextFile(); +void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { + Serial.printf("Listing directory: %s\n", dirname); + + File root = fs.open(dirname); + if (!root) { + Serial.println("Failed to open directory"); + return; + } + if (!root.isDirectory()) { + Serial.println("Not a directory"); + return; + } + + File file = root.openNextFile(); + while (file) { + if (file.isDirectory()) { + Serial.print(" DIR : "); + Serial.print(file.name()); + time_t t = file.getLastWrite(); + struct tm *tmstruct = localtime(&t); + Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); + if (levels) { + listDir(fs, file.path(), levels - 1); + } + } else { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print(" SIZE: "); + Serial.print(file.size()); + time_t t = file.getLastWrite(); + struct tm *tmstruct = localtime(&t); + Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); } + file = root.openNextFile(); + } } -void createDir(fs::FS &fs, const char * path){ - Serial.printf("Creating Dir: %s\n", path); - if(fs.mkdir(path)){ - Serial.println("Dir created"); - } else { - Serial.println("mkdir failed"); - } +void createDir(fs::FS &fs, const char *path) { + Serial.printf("Creating Dir: %s\n", path); + if (fs.mkdir(path)) { + Serial.println("Dir created"); + } else { + Serial.println("mkdir failed"); + } } -void removeDir(fs::FS &fs, const char * path){ - Serial.printf("Removing Dir: %s\n", path); - if(fs.rmdir(path)){ - Serial.println("Dir removed"); - } else { - Serial.println("rmdir failed"); - } +void removeDir(fs::FS &fs, const char *path) { + Serial.printf("Removing Dir: %s\n", path); + if (fs.rmdir(path)) { + Serial.println("Dir removed"); + } else { + Serial.println("rmdir failed"); + } } -void readFile(fs::FS &fs, const char * path){ - Serial.printf("Reading file: %s\n", path); +void readFile(fs::FS &fs, const char *path) { + Serial.printf("Reading file: %s\n", path); - File file = fs.open(path); - if(!file){ - Serial.println("Failed to open file for reading"); - return; - } + File file = fs.open(path); + if (!file) { + Serial.println("Failed to open file for reading"); + return; + } - Serial.print("Read from file: "); - while(file.available()){ - Serial.write(file.read()); - } - file.close(); + Serial.print("Read from file: "); + while (file.available()) { + Serial.write(file.read()); + } + file.close(); } -void writeFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Writing file: %s\n", path); - - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("Failed to open file for writing"); - return; - } - if(file.print(message)){ - Serial.println("File written"); - } else { - Serial.println("Write failed"); - } - file.close(); +void writeFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Writing file: %s\n", path); + + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("Failed to open file for writing"); + return; + } + if (file.print(message)) { + Serial.println("File written"); + } else { + Serial.println("Write failed"); + } + file.close(); } -void appendFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Appending to file: %s\n", path); - - File file = fs.open(path, FILE_APPEND); - if(!file){ - Serial.println("Failed to open file for appending"); - return; - } - if(file.print(message)){ - Serial.println("Message appended"); - } else { - Serial.println("Append failed"); - } - file.close(); +void appendFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Appending to file: %s\n", path); + + File file = fs.open(path, FILE_APPEND); + if (!file) { + Serial.println("Failed to open file for appending"); + return; + } + if (file.print(message)) { + Serial.println("Message appended"); + } else { + Serial.println("Append failed"); + } + file.close(); } -void renameFile(fs::FS &fs, const char * path1, const char * path2){ - Serial.printf("Renaming file %s to %s\n", path1, path2); - if (fs.rename(path1, path2)) { - Serial.println("File renamed"); - } else { - Serial.println("Rename failed"); - } +void renameFile(fs::FS &fs, const char *path1, const char *path2) { + Serial.printf("Renaming file %s to %s\n", path1, path2); + if (fs.rename(path1, path2)) { + Serial.println("File renamed"); + } else { + Serial.println("Rename failed"); + } } -void deleteFile(fs::FS &fs, const char * path){ - Serial.printf("Deleting file: %s\n", path); - if(fs.remove(path)){ - Serial.println("File deleted"); - } else { - Serial.println("Delete failed"); - } +void deleteFile(fs::FS &fs, const char *path) { + Serial.printf("Deleting file: %s\n", path); + if (fs.remove(path)) { + Serial.println("File deleted"); + } else { + Serial.println("Delete failed"); + } } -void setup(){ - Serial.begin(115200); - // We start by connecting to a WiFi network - Serial.println(); - Serial.println(); - Serial.print("Connecting to "); - Serial.println(ssid); - - WiFi.begin(ssid, password); - - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } - Serial.println("WiFi connected"); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println("Contacting Time Server"); - configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); - struct tm tmstruct ; - delay(2000); - tmstruct.tm_year = 0; - getLocalTime(&tmstruct, 5000); - Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct.tm_year)+1900,( tmstruct.tm_mon)+1, tmstruct.tm_mday,tmstruct.tm_hour , tmstruct.tm_min, tmstruct.tm_sec); - Serial.println(""); - - if(!SPIFFS.begin(FORMAT_LITTLEFS_IF_FAILED)){ - Serial.println("LittleFS Mount Failed"); - return; - } - - Serial.println("----list 1----"); - listDir(SPIFFS, "/", 1); - - Serial.println("----remove old dir----"); - removeDir(SPIFFS, "/mydir"); - - Serial.println("----create a new dir----"); - createDir(SPIFFS, "/mydir"); - - Serial.println("----remove the new dir----"); - removeDir(SPIFFS, "/mydir"); - - Serial.println("----create the new again----"); - createDir(SPIFFS, "/mydir"); - - Serial.println("----create and work with file----"); - writeFile(SPIFFS, "/mydir/hello.txt", "Hello "); - appendFile(SPIFFS, "/mydir/hello.txt", "World!\n"); - - Serial.println("----list 2----"); - listDir(SPIFFS, "/", 1); - - Serial.println("----attempt to remove dir w/ file----"); - removeDir(SPIFFS, "/mydir"); - - Serial.println("----remove dir after deleting file----"); - deleteFile(SPIFFS, "/mydir/hello.txt"); - removeDir(SPIFFS, "/mydir"); - - Serial.println("----list 3----"); - listDir(SPIFFS, "/", 1); - - Serial.println( "Test complete" ); - +void setup() { + Serial.begin(115200); + // We start by connecting to a WiFi network + Serial.println(); + Serial.println(); + Serial.print("Connecting to "); + Serial.println(ssid); + + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + Serial.println("Contacting Time Server"); + configTime(3600 * timezone, daysavetime * 3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); + struct tm tmstruct; + delay(2000); + tmstruct.tm_year = 0; + getLocalTime(&tmstruct, 5000); + Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec); + Serial.println(""); + + if (!SPIFFS.begin(FORMAT_LITTLEFS_IF_FAILED)) { + Serial.println("LittleFS Mount Failed"); + return; + } + + Serial.println("----list 1----"); + listDir(SPIFFS, "/", 1); + + Serial.println("----remove old dir----"); + removeDir(SPIFFS, "/mydir"); + + Serial.println("----create a new dir----"); + createDir(SPIFFS, "/mydir"); + + Serial.println("----remove the new dir----"); + removeDir(SPIFFS, "/mydir"); + + Serial.println("----create the new again----"); + createDir(SPIFFS, "/mydir"); + + Serial.println("----create and work with file----"); + writeFile(SPIFFS, "/mydir/hello.txt", "Hello "); + appendFile(SPIFFS, "/mydir/hello.txt", "World!\n"); + + Serial.println("----list 2----"); + listDir(SPIFFS, "/", 1); + + Serial.println("----attempt to remove dir w/ file----"); + removeDir(SPIFFS, "/mydir"); + + Serial.println("----remove dir after deleting file----"); + deleteFile(SPIFFS, "/mydir/hello.txt"); + removeDir(SPIFFS, "/mydir"); + + Serial.println("----list 3----"); + listDir(SPIFFS, "/", 1); + + Serial.println("Test complete"); } -void loop(){ - +void loop() { } diff --git a/libraries/LittleFS/src/LittleFS.cpp b/libraries/LittleFS/src/LittleFS.cpp index f20b4f16b4c..e1ee1a57ba9 100644 --- a/libraries/LittleFS/src/LittleFS.cpp +++ b/libraries/LittleFS/src/LittleFS.cpp @@ -26,122 +26,113 @@ extern "C" { #ifdef CONFIG_LITTLEFS_PAGE_SIZE extern "C" { - #include "esp_littlefs.h" +#include "esp_littlefs.h" } using namespace fs; -class LittleFSImpl : public VFSImpl -{ +class LittleFSImpl : public VFSImpl { public: - LittleFSImpl(); - virtual ~LittleFSImpl() { } - virtual bool exists(const char* path); + LittleFSImpl(); + virtual ~LittleFSImpl() {} + virtual bool exists(const char* path); }; -LittleFSImpl::LittleFSImpl() -{ +LittleFSImpl::LittleFSImpl() { } -bool LittleFSImpl::exists(const char* path) -{ - File f = open(path, "r",false); - return (f == true); +bool LittleFSImpl::exists(const char* path) { + File f = open(path, "r", false); + return (f == true); } -LittleFSFS::LittleFSFS() : FS(FSImplPtr(new LittleFSImpl())), partitionLabel_(NULL) -{ +LittleFSFS::LittleFSFS() + : FS(FSImplPtr(new LittleFSImpl())), partitionLabel_(NULL) { } -LittleFSFS::~LittleFSFS() -{ - if (partitionLabel_){ - free(partitionLabel_); - partitionLabel_ = NULL; - } +LittleFSFS::~LittleFSFS() { + if (partitionLabel_) { + free(partitionLabel_); + partitionLabel_ = NULL; + } } -bool LittleFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles, const char * partitionLabel) -{ - - if (partitionLabel_){ - free(partitionLabel_); - partitionLabel_ = NULL; - } +bool LittleFSFS::begin(bool formatOnFail, const char* basePath, uint8_t maxOpenFiles, const char* partitionLabel) { - if (partitionLabel){ - partitionLabel_ = strdup(partitionLabel); - } + if (partitionLabel_) { + free(partitionLabel_); + partitionLabel_ = NULL; + } - if(esp_littlefs_mounted(partitionLabel_)){ - log_w("LittleFS Already Mounted!"); - return true; - } + if (partitionLabel) { + partitionLabel_ = strdup(partitionLabel); + } - esp_vfs_littlefs_conf_t conf = { - .base_path = basePath, - .partition_label = partitionLabel_, - .partition = NULL, - .format_if_mount_failed = false, - .read_only = false, - .dont_mount = false, - .grow_on_mount = true - }; - - esp_err_t err = esp_vfs_littlefs_register(&conf); - if(err == ESP_FAIL && formatOnFail){ - if(format()){ - err = esp_vfs_littlefs_register(&conf); - } - } - if(err != ESP_OK){ - log_e("Mounting LittleFS failed! Error: %d", err); - return false; - } - _impl->mountpoint(basePath); + if (esp_littlefs_mounted(partitionLabel_)) { + log_w("LittleFS Already Mounted!"); return true; + } + + esp_vfs_littlefs_conf_t conf = { + .base_path = basePath, + .partition_label = partitionLabel_, + .partition = NULL, + .format_if_mount_failed = false, + .read_only = false, + .dont_mount = false, + .grow_on_mount = true + }; + + esp_err_t err = esp_vfs_littlefs_register(&conf); + if (err == ESP_FAIL && formatOnFail) { + if (format()) { + err = esp_vfs_littlefs_register(&conf); + } + } + if (err != ESP_OK) { + log_e("Mounting LittleFS failed! Error: %d", err); + return false; + } + _impl->mountpoint(basePath); + return true; } -void LittleFSFS::end() -{ - if(esp_littlefs_mounted(partitionLabel_)){ - esp_err_t err = esp_vfs_littlefs_unregister(partitionLabel_); - if(err){ - log_e("Unmounting LittleFS failed! Error: %d", err); - return; - } - _impl->mountpoint(NULL); +void LittleFSFS::end() { + if (esp_littlefs_mounted(partitionLabel_)) { + esp_err_t err = esp_vfs_littlefs_unregister(partitionLabel_); + if (err) { + log_e("Unmounting LittleFS failed! Error: %d", err); + return; } + _impl->mountpoint(NULL); + } } -bool LittleFSFS::format() -{ - disableCore0WDT(); - esp_err_t err = esp_littlefs_format(partitionLabel_); - enableCore0WDT(); - if(err){ - log_e("Formatting LittleFS failed! Error: %d", err); - return false; - } - return true; +bool LittleFSFS::format() { + disableCore0WDT(); + esp_err_t err = esp_littlefs_format(partitionLabel_); + enableCore0WDT(); + if (err) { + log_e("Formatting LittleFS failed! Error: %d", err); + return false; + } + return true; } -size_t LittleFSFS::totalBytes() -{ - size_t total,used; - if(esp_littlefs_info(partitionLabel_, &total, &used)){ - return 0; - } - return total; +size_t LittleFSFS::totalBytes() { + size_t total, used; + if (esp_littlefs_info(partitionLabel_, &total, &used)) { + return 0; + } + return total; } -size_t LittleFSFS::usedBytes() -{ - size_t total,used; - if(esp_littlefs_info(partitionLabel_, &total, &used)){ - return 0; - } - return used; +size_t LittleFSFS::usedBytes() { + size_t total, used; + if (esp_littlefs_info(partitionLabel_, &total, &used)) { + return 0; + } + return used; } LittleFSFS LittleFS; diff --git a/libraries/LittleFS/src/LittleFS.h b/libraries/LittleFS/src/LittleFS.h index dbe45cb98c2..61f62bc1feb 100644 --- a/libraries/LittleFS/src/LittleFS.h +++ b/libraries/LittleFS/src/LittleFS.h @@ -16,22 +16,20 @@ #include "FS.h" -namespace fs -{ +namespace fs { -class LittleFSFS : public FS -{ +class LittleFSFS : public FS { public: - LittleFSFS(); - ~LittleFSFS(); - bool begin(bool formatOnFail=false, const char * basePath="/littlefs", uint8_t maxOpenFiles=10, const char * partitionLabel="spiffs"); - bool format(); - size_t totalBytes(); - size_t usedBytes(); - void end(); + LittleFSFS(); + ~LittleFSFS(); + bool begin(bool formatOnFail = false, const char* basePath = "/littlefs", uint8_t maxOpenFiles = 10, const char* partitionLabel = "spiffs"); + bool format(); + size_t totalBytes(); + size_t usedBytes(); + void end(); private: - char * partitionLabel_; + char* partitionLabel_; }; } diff --git a/libraries/NetBIOS/examples/ESP_NBNST/ESP_NBNST.ino b/libraries/NetBIOS/examples/ESP_NBNST/ESP_NBNST.ino old mode 100755 new mode 100644 index 0f49e5aad6c..172ead6598c --- a/libraries/NetBIOS/examples/ESP_NBNST/ESP_NBNST.ino +++ b/libraries/NetBIOS/examples/ESP_NBNST/ESP_NBNST.ino @@ -27,5 +27,4 @@ void setup() { } void loop() { - } diff --git a/libraries/NetBIOS/src/NetBIOS.cpp b/libraries/NetBIOS/src/NetBIOS.cpp old mode 100755 new mode 100644 index 5442d8722b4..f84523ef7cd --- a/libraries/NetBIOS/src/NetBIOS.cpp +++ b/libraries/NetBIOS/src/NetBIOS.cpp @@ -1,131 +1,133 @@ -#include "NetBIOS.h" -#include - -#define NBNS_PORT 137 -#define NBNS_MAX_HOSTNAME_LEN 32 - -typedef struct { - uint16_t id; - uint8_t flags1; - uint8_t flags2; - uint16_t qcount; - uint16_t acount; - uint16_t nscount; - uint16_t adcount; - uint8_t name_len; - char name[NBNS_MAX_HOSTNAME_LEN + 1]; - uint16_t type; - uint16_t clas; -} __attribute__((packed)) nbns_question_t; - -typedef struct { - uint16_t id; - uint8_t flags1; - uint8_t flags2; - uint16_t qcount; - uint16_t acount; - uint16_t nscount; - uint16_t adcount; - uint8_t name_len; - char name[NBNS_MAX_HOSTNAME_LEN + 1]; - uint16_t type; - uint16_t clas; - uint32_t ttl; - uint16_t data_len; - uint16_t flags; - uint32_t addr; -} __attribute__((packed)) nbns_answer_t; - -static void _getnbname(const char *nbname, char *name, uint8_t maxlen){ - uint8_t b; - uint8_t c = 0; - - while ((*nbname) && (c < maxlen)) { - b = (*nbname++ - 'A') << 4; - c++; - if (*nbname) { - b |= *nbname++ - 'A'; - c++; - } - if(!b || b == ' '){ - break; - } - *name++ = b; - } - *name = 0; -} - -static void append_16(void * dst, uint16_t value){ - uint8_t * d = (uint8_t *)dst; - *d++ = (value >> 8) & 0xFF; - *d++ = value & 0xFF; -} - -static void append_32(void * dst, uint32_t value){ - uint8_t * d = (uint8_t *)dst; - *d++ = (value >> 24) & 0xFF; - *d++ = (value >> 16) & 0xFF; - *d++ = (value >> 8) & 0xFF; - *d++ = value & 0xFF; -} - -void NetBIOS::_onPacket(AsyncUDPPacket& packet){ - if (packet.length() >= sizeof(nbns_question_t)) { - nbns_question_t * question = (nbns_question_t *)packet.data(); - if (0 == (question->flags1 & 0x80)) { - char name[ NBNS_MAX_HOSTNAME_LEN + 1 ]; - _getnbname(&question->name[0], (char *)&name, question->name_len); - if (_name.equals(name)) { - nbns_answer_t nbnsa; - nbnsa.id = question->id; - nbnsa.flags1 = 0x85; - nbnsa.flags2 = 0; - append_16((void *)&nbnsa.qcount, 0); - append_16((void *)&nbnsa.acount, 1); - append_16((void *)&nbnsa.nscount, 0); - append_16((void *)&nbnsa.adcount, 0); - nbnsa.name_len = question->name_len; - memcpy(&nbnsa.name[0], &question->name[0], question->name_len + 1); - append_16((void *)&nbnsa.type, 0x20); - append_16((void *)&nbnsa.clas, 1); - append_32((void *)&nbnsa.ttl, 300000); - append_16((void *)&nbnsa.data_len, 6); - append_16((void *)&nbnsa.flags, 0); - nbnsa.addr = packet.localIP(); - _udp.writeTo((uint8_t *)&nbnsa, sizeof(nbnsa), packet.remoteIP(), NBNS_PORT); - } - } - } -} - -NetBIOS::NetBIOS(){ - -} - -NetBIOS::~NetBIOS(){ - end(); -} - -bool NetBIOS::begin(const char *name){ - _name = name; - _name.toUpperCase(); - - if(_udp.connected()){ - return true; - } - - _udp.onPacket([](void * arg, AsyncUDPPacket& packet){ ((NetBIOS*)(arg))->_onPacket(packet); }, this); - return _udp.listen(NBNS_PORT); -} - -void NetBIOS::end(){ - if(_udp.connected()){ - _udp.close(); - } -} - -#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_NETBIOS) -NetBIOS NBNS; -#endif - -// EOF +#include "NetBIOS.h" +#include + +#define NBNS_PORT 137 +#define NBNS_MAX_HOSTNAME_LEN 32 + +typedef struct { + uint16_t id; + uint8_t flags1; + uint8_t flags2; + uint16_t qcount; + uint16_t acount; + uint16_t nscount; + uint16_t adcount; + uint8_t name_len; + char name[NBNS_MAX_HOSTNAME_LEN + 1]; + uint16_t type; + uint16_t clas; +} __attribute__((packed)) nbns_question_t; + +typedef struct { + uint16_t id; + uint8_t flags1; + uint8_t flags2; + uint16_t qcount; + uint16_t acount; + uint16_t nscount; + uint16_t adcount; + uint8_t name_len; + char name[NBNS_MAX_HOSTNAME_LEN + 1]; + uint16_t type; + uint16_t clas; + uint32_t ttl; + uint16_t data_len; + uint16_t flags; + uint32_t addr; +} __attribute__((packed)) nbns_answer_t; + +static void _getnbname(const char *nbname, char *name, uint8_t maxlen) { + uint8_t b; + uint8_t c = 0; + + while ((*nbname) && (c < maxlen)) { + b = (*nbname++ - 'A') << 4; + c++; + if (*nbname) { + b |= *nbname++ - 'A'; + c++; + } + if (!b || b == ' ') { + break; + } + *name++ = b; + } + *name = 0; +} + +static void append_16(void *dst, uint16_t value) { + uint8_t *d = (uint8_t *)dst; + *d++ = (value >> 8) & 0xFF; + *d++ = value & 0xFF; +} + +static void append_32(void *dst, uint32_t value) { + uint8_t *d = (uint8_t *)dst; + *d++ = (value >> 24) & 0xFF; + *d++ = (value >> 16) & 0xFF; + *d++ = (value >> 8) & 0xFF; + *d++ = value & 0xFF; +} + +void NetBIOS::_onPacket(AsyncUDPPacket &packet) { + if (packet.length() >= sizeof(nbns_question_t)) { + nbns_question_t *question = (nbns_question_t *)packet.data(); + if (0 == (question->flags1 & 0x80)) { + char name[NBNS_MAX_HOSTNAME_LEN + 1]; + _getnbname(&question->name[0], (char *)&name, question->name_len); + if (_name.equals(name)) { + nbns_answer_t nbnsa; + nbnsa.id = question->id; + nbnsa.flags1 = 0x85; + nbnsa.flags2 = 0; + append_16((void *)&nbnsa.qcount, 0); + append_16((void *)&nbnsa.acount, 1); + append_16((void *)&nbnsa.nscount, 0); + append_16((void *)&nbnsa.adcount, 0); + nbnsa.name_len = question->name_len; + memcpy(&nbnsa.name[0], &question->name[0], question->name_len + 1); + append_16((void *)&nbnsa.type, 0x20); + append_16((void *)&nbnsa.clas, 1); + append_32((void *)&nbnsa.ttl, 300000); + append_16((void *)&nbnsa.data_len, 6); + append_16((void *)&nbnsa.flags, 0); + nbnsa.addr = packet.localIP(); + _udp.writeTo((uint8_t *)&nbnsa, sizeof(nbnsa), packet.remoteIP(), NBNS_PORT); + } + } + } +} + +NetBIOS::NetBIOS() { +} + +NetBIOS::~NetBIOS() { + end(); +} + +bool NetBIOS::begin(const char *name) { + _name = name; + _name.toUpperCase(); + + if (_udp.connected()) { + return true; + } + + _udp.onPacket([](void *arg, AsyncUDPPacket &packet) { + ((NetBIOS *)(arg))->_onPacket(packet); + }, + this); + return _udp.listen(NBNS_PORT); +} + +void NetBIOS::end() { + if (_udp.connected()) { + _udp.close(); + } +} + +#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_NETBIOS) +NetBIOS NBNS; +#endif + +// EOF diff --git a/libraries/NetBIOS/src/NetBIOS.h b/libraries/NetBIOS/src/NetBIOS.h old mode 100755 new mode 100644 index 248f4ed3255..7fc5f348176 --- a/libraries/NetBIOS/src/NetBIOS.h +++ b/libraries/NetBIOS/src/NetBIOS.h @@ -1,26 +1,25 @@ -// -#ifndef __ESPNBNS_h__ -#define __ESPNBNS_h__ - -#include "Arduino.h" -#include "AsyncUDP.h" - -class NetBIOS -{ -protected: - AsyncUDP _udp; - String _name; - void _onPacket(AsyncUDPPacket& packet); - -public: - NetBIOS(); - ~NetBIOS(); - bool begin(const char *name); - void end(); -}; - -#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_NETBIOS) -extern NetBIOS NBNS; -#endif - -#endif +// +#ifndef __ESPNBNS_h__ +#define __ESPNBNS_h__ + +#include "Arduino.h" +#include "AsyncUDP.h" + +class NetBIOS { +protected: + AsyncUDP _udp; + String _name; + void _onPacket(AsyncUDPPacket& packet); + +public: + NetBIOS(); + ~NetBIOS(); + bool begin(const char* name); + void end(); +}; + +#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_NETBIOS) +extern NetBIOS NBNS; +#endif + +#endif diff --git a/libraries/Network/library.properties b/libraries/Network/library.properties index 65f278952f1..8143c8045bc 100644 --- a/libraries/Network/library.properties +++ b/libraries/Network/library.properties @@ -6,4 +6,4 @@ sentence=General network management library. paragraph=This library holds all common functionality of the different network interfaces. category=Communication url= -architectures=esp32 \ No newline at end of file +architectures=esp32 diff --git a/libraries/Network/src/Network.h b/libraries/Network/src/Network.h index 2b10ae10c64..935cd1a275c 100644 --- a/libraries/Network/src/Network.h +++ b/libraries/Network/src/Network.h @@ -11,4 +11,4 @@ #include "NetworkClient.h" #include "NetworkServer.h" -#include "NetworkUdp.h" \ No newline at end of file +#include "NetworkUdp.h" diff --git a/libraries/Network/src/NetworkClient.cpp b/libraries/Network/src/NetworkClient.cpp index 5b2bd61bc5c..667cc2b31d4 100644 --- a/libraries/Network/src/NetworkClient.cpp +++ b/libraries/Network/src/NetworkClient.cpp @@ -24,14 +24,14 @@ #include #define IN6_IS_ADDR_V4MAPPED(a) \ - ((((__const uint32_t *) (a))[0] == 0) \ - && (((__const uint32_t *) (a))[1] == 0) \ - && (((__const uint32_t *) (a))[2] == htonl (0xffff))) + ((((__const uint32_t *)(a))[0] == 0) \ + && (((__const uint32_t *)(a))[1] == 0) \ + && (((__const uint32_t *)(a))[2] == htonl(0xffff))) -#define WIFI_CLIENT_DEF_CONN_TIMEOUT_MS (3000) -#define WIFI_CLIENT_MAX_WRITE_RETRY (10) -#define WIFI_CLIENT_SELECT_TIMEOUT_US (1000000) -#define WIFI_CLIENT_FLUSH_BUFFER_SIZE (1024) +#define WIFI_CLIENT_DEF_CONN_TIMEOUT_MS (3000) +#define WIFI_CLIENT_MAX_WRITE_RETRY (10) +#define WIFI_CLIENT_SELECT_TIMEOUT_US (1000000) +#define WIFI_CLIENT_FLUSH_BUFFER_SIZE (1024) #undef connect #undef write @@ -39,639 +39,591 @@ class NetworkClientRxBuffer { private: - size_t _size; - uint8_t *_buffer; - size_t _pos; - size_t _fill; - int _fd; - bool _failed; - - size_t r_available() - { - if(_fd < 0){ - return 0; - } - int count; + size_t _size; + uint8_t *_buffer; + size_t _pos; + size_t _fill; + int _fd; + bool _failed; + + size_t r_available() { + if (_fd < 0) { + return 0; + } + int count; #ifdef ESP_IDF_VERSION_MAJOR - int res = lwip_ioctl(_fd, FIONREAD, &count); + int res = lwip_ioctl(_fd, FIONREAD, &count); #else - int res = lwip_ioctl_r(_fd, FIONREAD, &count); + int res = lwip_ioctl_r(_fd, FIONREAD, &count); #endif - if(res < 0) { - _failed = true; - return 0; - } - return count; - } - - size_t fillBuffer() - { - if(!_buffer){ - _buffer = (uint8_t *)malloc(_size); - if(!_buffer) { - log_e("Not enough memory to allocate buffer"); - _failed = true; - return 0; - } - } - if(_fill && _pos == _fill){ - _fill = 0; - _pos = 0; - } - if(!_buffer || _size <= _fill || !r_available()) { - return 0; - } - int res = recv(_fd, _buffer + _fill, _size - _fill, MSG_DONTWAIT); - if(res < 0) { - if(errno != EWOULDBLOCK) { - _failed = true; - } - return 0; - } - _fill += res; - return res; - } - -public: - NetworkClientRxBuffer(int fd, size_t size=1436) - :_size(size) - ,_buffer(NULL) - ,_pos(0) - ,_fill(0) - ,_fd(fd) - ,_failed(false) - { - //_buffer = (uint8_t *)malloc(_size); - } - - ~NetworkClientRxBuffer() - { - free(_buffer); - } - - bool failed(){ - return _failed; + if (res < 0) { + _failed = true; + return 0; + } + return count; + } + + size_t fillBuffer() { + if (!_buffer) { + _buffer = (uint8_t *)malloc(_size); + if (!_buffer) { + log_e("Not enough memory to allocate buffer"); + _failed = true; + return 0; + } } - - int read(uint8_t * dst, size_t len){ - if(!dst || !len || (_pos == _fill && !fillBuffer())){ - return _failed ? -1 : 0; - } - size_t a = _fill - _pos; - if(len <= a || ((len - a) <= (_size - _fill) && fillBuffer() >= (len - a))){ - if(len == 1){ - *dst = _buffer[_pos]; - } else { - memcpy(dst, _buffer + _pos, len); - } - _pos += len; - return len; - } - size_t left = len; - size_t toRead = a; - uint8_t * buf = dst; - memcpy(buf, _buffer + _pos, toRead); - _pos += toRead; - left -= toRead; - buf += toRead; - while(left){ - if(!fillBuffer()){ - return len - left; - } - a = _fill - _pos; - toRead = (a > left)?left:a; - memcpy(buf, _buffer + _pos, toRead); - _pos += toRead; - left -= toRead; - buf += toRead; - } - return len; + if (_fill && _pos == _fill) { + _fill = 0; + _pos = 0; } - - int peek(){ - if(_pos == _fill && !fillBuffer()){ - return -1; - } - return _buffer[_pos]; + if (!_buffer || _size <= _fill || !r_available()) { + return 0; } - - size_t available(){ - return _fill - _pos + r_available(); + int res = recv(_fd, _buffer + _fill, _size - _fill, MSG_DONTWAIT); + if (res < 0) { + if (errno != EWOULDBLOCK) { + _failed = true; + } + return 0; } + _fill += res; + return res; + } - void clear(){ - if(r_available()){ - fillBuffer(); - } - _pos = _fill; - } +public: + NetworkClientRxBuffer(int fd, size_t size = 1436) + : _size(size), _buffer(NULL), _pos(0), _fill(0), _fd(fd), _failed(false) { + //_buffer = (uint8_t *)malloc(_size); + } + + ~NetworkClientRxBuffer() { + free(_buffer); + } + + bool failed() { + return _failed; + } + + int read(uint8_t *dst, size_t len) { + if (!dst || !len || (_pos == _fill && !fillBuffer())) { + return _failed ? -1 : 0; + } + size_t a = _fill - _pos; + if (len <= a || ((len - a) <= (_size - _fill) && fillBuffer() >= (len - a))) { + if (len == 1) { + *dst = _buffer[_pos]; + } else { + memcpy(dst, _buffer + _pos, len); + } + _pos += len; + return len; + } + size_t left = len; + size_t toRead = a; + uint8_t *buf = dst; + memcpy(buf, _buffer + _pos, toRead); + _pos += toRead; + left -= toRead; + buf += toRead; + while (left) { + if (!fillBuffer()) { + return len - left; + } + a = _fill - _pos; + toRead = (a > left) ? left : a; + memcpy(buf, _buffer + _pos, toRead); + _pos += toRead; + left -= toRead; + buf += toRead; + } + return len; + } + + int peek() { + if (_pos == _fill && !fillBuffer()) { + return -1; + } + return _buffer[_pos]; + } + + size_t available() { + return _fill - _pos + r_available(); + } + + void clear() { + if (r_available()) { + fillBuffer(); + } + _pos = _fill; + } }; class NetworkClientSocketHandle { private: - int sockfd; + int sockfd; public: - NetworkClientSocketHandle(int fd):sockfd(fd) - { - } + NetworkClientSocketHandle(int fd) + : sockfd(fd) { + } - ~NetworkClientSocketHandle() - { - close(sockfd); - } + ~NetworkClientSocketHandle() { + close(sockfd); + } - int fd() - { - return sockfd; - } + int fd() { + return sockfd; + } }; -NetworkClient::NetworkClient():_rxBuffer(nullptr),_connected(false),_sse(false),_timeout(WIFI_CLIENT_DEF_CONN_TIMEOUT_MS),next(NULL) -{ +NetworkClient::NetworkClient() + : _rxBuffer(nullptr), _connected(false), _sse(false), _timeout(WIFI_CLIENT_DEF_CONN_TIMEOUT_MS), next(NULL) { } -NetworkClient::NetworkClient(int fd):_connected(true),_timeout(WIFI_CLIENT_DEF_CONN_TIMEOUT_MS),next(NULL) -{ - clientSocketHandle.reset(new NetworkClientSocketHandle(fd)); - _rxBuffer.reset(new NetworkClientRxBuffer(fd)); +NetworkClient::NetworkClient(int fd) + : _connected(true), _timeout(WIFI_CLIENT_DEF_CONN_TIMEOUT_MS), next(NULL) { + clientSocketHandle.reset(new NetworkClientSocketHandle(fd)); + _rxBuffer.reset(new NetworkClientRxBuffer(fd)); } -NetworkClient::~NetworkClient() -{ - stop(); +NetworkClient::~NetworkClient() { + stop(); } -void NetworkClient::stop() -{ - clientSocketHandle = NULL; - _rxBuffer = NULL; - _connected = false; - _lastReadTimeout = 0; - _lastWriteTimeout = 0; +void NetworkClient::stop() { + clientSocketHandle = NULL; + _rxBuffer = NULL; + _connected = false; + _lastReadTimeout = 0; + _lastWriteTimeout = 0; } -int NetworkClient::connect(IPAddress ip, uint16_t port) -{ - return connect(ip,port,_timeout); +int NetworkClient::connect(IPAddress ip, uint16_t port) { + return connect(ip, port, _timeout); } -int NetworkClient::connect(IPAddress ip, uint16_t port, int32_t timeout_ms) -{ - struct sockaddr_storage serveraddr = {}; - _timeout = timeout_ms; - int sockfd = -1; +int NetworkClient::connect(IPAddress ip, uint16_t port, int32_t timeout_ms) { + struct sockaddr_storage serveraddr = {}; + _timeout = timeout_ms; + int sockfd = -1; - if (ip.type() == IPv6) { - struct sockaddr_in6 *tmpaddr = (struct sockaddr_in6 *)&serveraddr; - sockfd = socket(AF_INET6, SOCK_STREAM, 0); - tmpaddr->sin6_family = AF_INET6; - memcpy(tmpaddr->sin6_addr.un.u8_addr, &ip[0], 16); - tmpaddr->sin6_port = htons(port); - tmpaddr->sin6_scope_id = ip.zone(); - } else { - struct sockaddr_in *tmpaddr = (struct sockaddr_in *)&serveraddr; - sockfd = socket(AF_INET, SOCK_STREAM, 0); - tmpaddr->sin_family = AF_INET; - tmpaddr->sin_addr.s_addr = ip; - tmpaddr->sin_port = htons(port); - } - if (sockfd < 0) { - log_e("socket: %d", errno); - return 0; - } - fcntl( sockfd, F_SETFL, fcntl( sockfd, F_GETFL, 0 ) | O_NONBLOCK ); + if (ip.type() == IPv6) { + struct sockaddr_in6 *tmpaddr = (struct sockaddr_in6 *)&serveraddr; + sockfd = socket(AF_INET6, SOCK_STREAM, 0); + tmpaddr->sin6_family = AF_INET6; + memcpy(tmpaddr->sin6_addr.un.u8_addr, &ip[0], 16); + tmpaddr->sin6_port = htons(port); + tmpaddr->sin6_scope_id = ip.zone(); + } else { + struct sockaddr_in *tmpaddr = (struct sockaddr_in *)&serveraddr; + sockfd = socket(AF_INET, SOCK_STREAM, 0); + tmpaddr->sin_family = AF_INET; + tmpaddr->sin_addr.s_addr = ip; + tmpaddr->sin_port = htons(port); + } + if (sockfd < 0) { + log_e("socket: %d", errno); + return 0; + } + fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL, 0) | O_NONBLOCK); - fd_set fdset; - struct timeval tv; - FD_ZERO(&fdset); - FD_SET(sockfd, &fdset); - tv.tv_sec = _timeout / 1000; - tv.tv_usec = (_timeout % 1000) * 1000; + fd_set fdset; + struct timeval tv; + FD_ZERO(&fdset); + FD_SET(sockfd, &fdset); + tv.tv_sec = _timeout / 1000; + tv.tv_usec = (_timeout % 1000) * 1000; #ifdef ESP_IDF_VERSION_MAJOR - int res = lwip_connect(sockfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr)); + int res = lwip_connect(sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)); #else - int res = lwip_connect_r(sockfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr)); + int res = lwip_connect_r(sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)); #endif - if (res < 0 && errno != EINPROGRESS) { - log_e("connect on fd %d, errno: %d, \"%s\"", sockfd, errno, strerror(errno)); - close(sockfd); - return 0; - } + if (res < 0 && errno != EINPROGRESS) { + log_e("connect on fd %d, errno: %d, \"%s\"", sockfd, errno, strerror(errno)); + close(sockfd); + return 0; + } + + res = select(sockfd + 1, nullptr, &fdset, nullptr, _timeout < 0 ? nullptr : &tv); + if (res < 0) { + log_e("select on fd %d, errno: %d, \"%s\"", sockfd, errno, strerror(errno)); + close(sockfd); + return 0; + } else if (res == 0) { + log_i("select returned due to timeout %d ms for fd %d", _timeout, sockfd); + close(sockfd); + return 0; + } else { + int sockerr; + socklen_t len = (socklen_t)sizeof(int); + res = getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &sockerr, &len); - res = select(sockfd + 1, nullptr, &fdset, nullptr, _timeout<0 ? nullptr : &tv); if (res < 0) { - log_e("select on fd %d, errno: %d, \"%s\"", sockfd, errno, strerror(errno)); - close(sockfd); - return 0; - } else if (res == 0) { - log_i("select returned due to timeout %d ms for fd %d", _timeout, sockfd); - close(sockfd); - return 0; - } else { - int sockerr; - socklen_t len = (socklen_t)sizeof(int); - res = getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &sockerr, &len); - - if (res < 0) { - log_e("getsockopt on fd %d, errno: %d, \"%s\"", sockfd, errno, strerror(errno)); - close(sockfd); - return 0; - } + log_e("getsockopt on fd %d, errno: %d, \"%s\"", sockfd, errno, strerror(errno)); + close(sockfd); + return 0; + } - if (sockerr != 0) { - log_e("socket error on fd %d, errno: %d, \"%s\"", sockfd, sockerr, strerror(sockerr)); - close(sockfd); - return 0; - } + if (sockerr != 0) { + log_e("socket error on fd %d, errno: %d, \"%s\"", sockfd, sockerr, strerror(sockerr)); + close(sockfd); + return 0; } + } -#define ROE_WIFICLIENT(x,msg) { if (((x)<0)) { log_e("Setsockopt '" msg "'' on fd %d failed. errno: %d, \"%s\"", sockfd, errno, strerror(errno)); return 0; }} - ROE_WIFICLIENT(setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)),"SO_SNDTIMEO"); - ROE_WIFICLIENT(setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)),"SO_RCVTIMEO"); +#define ROE_WIFICLIENT(x, msg) \ + { \ + if (((x) < 0)) { \ + log_e("Setsockopt '" msg "'' on fd %d failed. errno: %d, \"%s\"", sockfd, errno, strerror(errno)); \ + return 0; \ + } \ + } + ROE_WIFICLIENT(setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)), "SO_SNDTIMEO"); + ROE_WIFICLIENT(setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)), "SO_RCVTIMEO"); - // These are also set in NetworkClientSecure, should be set here too? - //ROE_WIFICLIENT(setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable)),"TCP_NODELAY"); - //ROE_WIFICLIENT (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable)),"SO_KEEPALIVE"); + // These are also set in NetworkClientSecure, should be set here too? + //ROE_WIFICLIENT(setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable)),"TCP_NODELAY"); + //ROE_WIFICLIENT (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable)),"SO_KEEPALIVE"); - fcntl( sockfd, F_SETFL, fcntl( sockfd, F_GETFL, 0 ) & (~O_NONBLOCK) ); - clientSocketHandle.reset(new NetworkClientSocketHandle(sockfd)); - _rxBuffer.reset(new NetworkClientRxBuffer(sockfd)); + fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL, 0) & (~O_NONBLOCK)); + clientSocketHandle.reset(new NetworkClientSocketHandle(sockfd)); + _rxBuffer.reset(new NetworkClientRxBuffer(sockfd)); - _connected = true; - return 1; + _connected = true; + return 1; } -int NetworkClient::connect(const char *host, uint16_t port) -{ - return connect(host,port,_timeout); +int NetworkClient::connect(const char *host, uint16_t port) { + return connect(host, port, _timeout); } -int NetworkClient::connect(const char *host, uint16_t port, int32_t timeout_ms) -{ - IPAddress srv((uint32_t)0); - if(!Network.hostByName(host, srv)){ - return 0; - } - return connect(srv, port, timeout_ms); +int NetworkClient::connect(const char *host, uint16_t port, int32_t timeout_ms) { + IPAddress srv((uint32_t)0); + if (!Network.hostByName(host, srv)) { + return 0; + } + return connect(srv, port, timeout_ms); } -int NetworkClient::setSocketOption(int option, char* value, size_t len) -{ - return setSocketOption(SOL_SOCKET, option, (const void*)value, len); +int NetworkClient::setSocketOption(int option, char *value, size_t len) { + return setSocketOption(SOL_SOCKET, option, (const void *)value, len); } -int NetworkClient::setSocketOption(int level, int option, const void* value, size_t len) -{ - int res = setsockopt(fd(), level, option, value, len); - if(res < 0) { - log_e("fail on %d, errno: %d, \"%s\"", fd(), errno, strerror(errno)); - } - return res; +int NetworkClient::setSocketOption(int level, int option, const void *value, size_t len) { + int res = setsockopt(fd(), level, option, value, len); + if (res < 0) { + log_e("fail on %d, errno: %d, \"%s\"", fd(), errno, strerror(errno)); + } + return res; } -int NetworkClient::getSocketOption(int level, int option, const void* value, size_t size) -{ - int res = getsockopt(fd(), level, option, (char *)value, (socklen_t*)&size); - if(res < 0) { - log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno)); - } - return res; +int NetworkClient::getSocketOption(int level, int option, const void *value, size_t size) { + int res = getsockopt(fd(), level, option, (char *)value, (socklen_t *)&size); + if (res < 0) { + log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno)); + } + return res; } -int NetworkClient::setOption(int option, int *value) -{ - return setSocketOption(IPPROTO_TCP, option, (const void*)value, sizeof(int)); +int NetworkClient::setOption(int option, int *value) { + return setSocketOption(IPPROTO_TCP, option, (const void *)value, sizeof(int)); } -int NetworkClient::getOption(int option, int *value) -{ - socklen_t size = sizeof(int); - int res = getsockopt(fd(), IPPROTO_TCP, option, (char *)value, &size); - if(res < 0) { - log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno)); - } - return res; +int NetworkClient::getOption(int option, int *value) { + socklen_t size = sizeof(int); + int res = getsockopt(fd(), IPPROTO_TCP, option, (char *)value, &size); + if (res < 0) { + log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno)); + } + return res; } -void NetworkClient::setConnectionTimeout(uint32_t milliseconds) -{ - _timeout = milliseconds; +void NetworkClient::setConnectionTimeout(uint32_t milliseconds) { + _timeout = milliseconds; } -int NetworkClient::setNoDelay(bool nodelay) -{ - int flag = nodelay; - return setOption(TCP_NODELAY, &flag); +int NetworkClient::setNoDelay(bool nodelay) { + int flag = nodelay; + return setOption(TCP_NODELAY, &flag); } -bool NetworkClient::getNoDelay() -{ - int flag = 0; - getOption(TCP_NODELAY, &flag); - return flag; +bool NetworkClient::getNoDelay() { + int flag = 0; + getOption(TCP_NODELAY, &flag); + return flag; } -size_t NetworkClient::write(uint8_t data) -{ - return write(&data, 1); +size_t NetworkClient::write(uint8_t data) { + return write(&data, 1); } -int NetworkClient::read() -{ - uint8_t data = 0; - int res = read(&data, 1); - if(res < 0) { - return res; - } - if (res == 0) { // No data available. - return -1; - } - return data; +int NetworkClient::read() { + uint8_t data = 0; + int res = read(&data, 1); + if (res < 0) { + return res; + } + if (res == 0) { // No data available. + return -1; + } + return data; } -void NetworkClient::flush() -{ - +void NetworkClient::flush() { } -size_t NetworkClient::write(const uint8_t *buf, size_t size) -{ - int res =0; - int retry = WIFI_CLIENT_MAX_WRITE_RETRY; - int socketFileDescriptor = fd(); - size_t totalBytesSent = 0; - size_t bytesRemaining = size; - - if(!_connected || (socketFileDescriptor < 0)) { - return 0; - } - - while(retry) { - //use select to make sure the socket is ready for writing - fd_set set; - struct timeval tv; - FD_ZERO(&set); // empties the set - FD_SET(socketFileDescriptor, &set); // adds FD to the set - tv.tv_sec = 0; - tv.tv_usec = WIFI_CLIENT_SELECT_TIMEOUT_US; - retry--; - - if(_lastWriteTimeout != _timeout){ - if(fd() >= 0){ - struct timeval timeout_tv; - timeout_tv.tv_sec = _timeout / 1000; - timeout_tv.tv_usec = (_timeout % 1000) * 1000; - if(setSocketOption(SO_SNDTIMEO, (char *)&timeout_tv, sizeof(struct timeval)) >= 0) - { - _lastWriteTimeout = _timeout; - } - } - } - - if(select(socketFileDescriptor + 1, NULL, &set, NULL, &tv) < 0) { - return 0; - } - - if(FD_ISSET(socketFileDescriptor, &set)) { - res = send(socketFileDescriptor, (void*) buf, bytesRemaining, MSG_DONTWAIT); - if(res > 0) { - totalBytesSent += res; - if (totalBytesSent >= size) { - //completed successfully - retry = 0; - } else { - buf += res; - bytesRemaining -= res; - retry = WIFI_CLIENT_MAX_WRITE_RETRY; - } - } - else if(res < 0) { - log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno)); - if(errno != EAGAIN) { - //if resource was busy, can try again, otherwise give up - stop(); - res = 0; - retry = 0; - } - } - else { - // Try again - } - } - } - return totalBytesSent; -} +size_t NetworkClient::write(const uint8_t *buf, size_t size) { + int res = 0; + int retry = WIFI_CLIENT_MAX_WRITE_RETRY; + int socketFileDescriptor = fd(); + size_t totalBytesSent = 0; + size_t bytesRemaining = size; -size_t NetworkClient::write_P(PGM_P buf, size_t size) -{ - return write(buf, size); -} + if (!_connected || (socketFileDescriptor < 0)) { + return 0; + } -size_t NetworkClient::write(Stream &stream) -{ - uint8_t * buf = (uint8_t *)malloc(1360); - if(!buf){ - return 0; - } - size_t toRead = 0, toWrite = 0, written = 0; - size_t available = stream.available(); - while(available){ - toRead = (available > 1360)?1360:available; - toWrite = stream.readBytes(buf, toRead); - written += write(buf, toWrite); - available = stream.available(); - } - free(buf); - return written; -} - -int NetworkClient::read(uint8_t *buf, size_t size) -{ - if(_lastReadTimeout != _timeout){ - if(fd() >= 0){ - struct timeval timeout_tv; - timeout_tv.tv_sec = _timeout / 1000; - timeout_tv.tv_usec = (_timeout % 1000) * 1000; - if(setSocketOption(SO_RCVTIMEO, (char *)&timeout_tv, sizeof(struct timeval)) >= 0) - { - _lastReadTimeout = _timeout; - } + while (retry) { + //use select to make sure the socket is ready for writing + fd_set set; + struct timeval tv; + FD_ZERO(&set); // empties the set + FD_SET(socketFileDescriptor, &set); // adds FD to the set + tv.tv_sec = 0; + tv.tv_usec = WIFI_CLIENT_SELECT_TIMEOUT_US; + retry--; + + if (_lastWriteTimeout != _timeout) { + if (fd() >= 0) { + struct timeval timeout_tv; + timeout_tv.tv_sec = _timeout / 1000; + timeout_tv.tv_usec = (_timeout % 1000) * 1000; + if (setSocketOption(SO_SNDTIMEO, (char *)&timeout_tv, sizeof(struct timeval)) >= 0) { + _lastWriteTimeout = _timeout; } + } } - int res = -1; - if (_rxBuffer) { - res = _rxBuffer->read(buf, size); - if(_rxBuffer->failed()) { - log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno)); - stop(); - } + if (select(socketFileDescriptor + 1, NULL, &set, NULL, &tv) < 0) { + return 0; } - return res; -} -int NetworkClient::peek() -{ - int res = -1; - if (_rxBuffer) { - res = _rxBuffer->peek(); - if(_rxBuffer->failed()) { - log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno)); - stop(); + if (FD_ISSET(socketFileDescriptor, &set)) { + res = send(socketFileDescriptor, (void *)buf, bytesRemaining, MSG_DONTWAIT); + if (res > 0) { + totalBytesSent += res; + if (totalBytesSent >= size) { + //completed successfully + retry = 0; + } else { + buf += res; + bytesRemaining -= res; + retry = WIFI_CLIENT_MAX_WRITE_RETRY; } - } - return res; -} - -int NetworkClient::available() -{ - if(!_rxBuffer) - { - return 0; - } - int res = _rxBuffer->available(); - if(_rxBuffer->failed()) { + } else if (res < 0) { log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno)); - stop(); - } - return res; + if (errno != EAGAIN) { + //if resource was busy, can try again, otherwise give up + stop(); + res = 0; + retry = 0; + } + } else { + // Try again + } + } + } + return totalBytesSent; +} + +size_t NetworkClient::write_P(PGM_P buf, size_t size) { + return write(buf, size); +} + +size_t NetworkClient::write(Stream &stream) { + uint8_t *buf = (uint8_t *)malloc(1360); + if (!buf) { + return 0; + } + size_t toRead = 0, toWrite = 0, written = 0; + size_t available = stream.available(); + while (available) { + toRead = (available > 1360) ? 1360 : available; + toWrite = stream.readBytes(buf, toRead); + written += write(buf, toWrite); + available = stream.available(); + } + free(buf); + return written; +} + +int NetworkClient::read(uint8_t *buf, size_t size) { + if (_lastReadTimeout != _timeout) { + if (fd() >= 0) { + struct timeval timeout_tv; + timeout_tv.tv_sec = _timeout / 1000; + timeout_tv.tv_usec = (_timeout % 1000) * 1000; + if (setSocketOption(SO_RCVTIMEO, (char *)&timeout_tv, sizeof(struct timeval)) >= 0) { + _lastReadTimeout = _timeout; + } + } + } + + int res = -1; + if (_rxBuffer) { + res = _rxBuffer->read(buf, size); + if (_rxBuffer->failed()) { + log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno)); + stop(); + } + } + return res; +} + +int NetworkClient::peek() { + int res = -1; + if (_rxBuffer) { + res = _rxBuffer->peek(); + if (_rxBuffer->failed()) { + log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno)); + stop(); + } + } + return res; +} + +int NetworkClient::available() { + if (!_rxBuffer) { + return 0; + } + int res = _rxBuffer->available(); + if (_rxBuffer->failed()) { + log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno)); + stop(); + } + return res; } void NetworkClient::clear() { - if (_rxBuffer != nullptr) { - _rxBuffer->clear(); - } -} - -uint8_t NetworkClient::connected() -{ - if (_connected) { - uint8_t dummy; - int res = recv(fd(), &dummy, 0, MSG_DONTWAIT); - // avoid unused var warning by gcc - (void)res; - // recv only sets errno if res is <= 0 - if (res <= 0){ - switch (errno) { - case EWOULDBLOCK: - case ENOENT: //caused by vfs - _connected = true; - break; - case ENOTCONN: - case EPIPE: - case ECONNRESET: - case ECONNREFUSED: - case ECONNABORTED: - _connected = false; - log_d("Disconnected: RES: %d, ERR: %d", res, errno); - break; - default: - log_i("Unexpected: RES: %d, ERR: %d", res, errno); - _connected = true; - break; - } - } else { + if (_rxBuffer != nullptr) { + _rxBuffer->clear(); + } +} + +uint8_t NetworkClient::connected() { + if (_connected) { + uint8_t dummy; + int res = recv(fd(), &dummy, 0, MSG_DONTWAIT); + // avoid unused var warning by gcc + (void)res; + // recv only sets errno if res is <= 0 + if (res <= 0) { + switch (errno) { + case EWOULDBLOCK: + case ENOENT: //caused by vfs _connected = true; - } + break; + case ENOTCONN: + case EPIPE: + case ECONNRESET: + case ECONNREFUSED: + case ECONNABORTED: + _connected = false; + log_d("Disconnected: RES: %d, ERR: %d", res, errno); + break; + default: + log_i("Unexpected: RES: %d, ERR: %d", res, errno); + _connected = true; + break; + } + } else { + _connected = true; } - return _connected; + } + return _connected; } -IPAddress NetworkClient::remoteIP(int fd) const -{ - struct sockaddr_storage addr; - socklen_t len = sizeof addr; - getpeername(fd, (struct sockaddr*)&addr, &len); +IPAddress NetworkClient::remoteIP(int fd) const { + struct sockaddr_storage addr; + socklen_t len = sizeof addr; + getpeername(fd, (struct sockaddr *)&addr, &len); - // IPv4 socket, old way - if (((struct sockaddr*)&addr)->sa_family == AF_INET) { - struct sockaddr_in *s = (struct sockaddr_in *)&addr; - return IPAddress((uint32_t)(s->sin_addr.s_addr)); - } + // IPv4 socket, old way + if (((struct sockaddr *)&addr)->sa_family == AF_INET) { + struct sockaddr_in *s = (struct sockaddr_in *)&addr; + return IPAddress((uint32_t)(s->sin_addr.s_addr)); + } - // IPv6, but it might be IPv4 mapped address - if (((struct sockaddr*)&addr)->sa_family == AF_INET6) { - struct sockaddr_in6 *saddr6 = (struct sockaddr_in6 *)&addr; - if (IN6_IS_ADDR_V4MAPPED(saddr6->sin6_addr.un.u32_addr)) { - return IPAddress(IPv4, (uint8_t*)saddr6->sin6_addr.s6_addr+IPADDRESS_V4_BYTES_INDEX); - } else { - return IPAddress(IPv6, (uint8_t*)(saddr6->sin6_addr.s6_addr), saddr6->sin6_scope_id); - } + // IPv6, but it might be IPv4 mapped address + if (((struct sockaddr *)&addr)->sa_family == AF_INET6) { + struct sockaddr_in6 *saddr6 = (struct sockaddr_in6 *)&addr; + if (IN6_IS_ADDR_V4MAPPED(saddr6->sin6_addr.un.u32_addr)) { + return IPAddress(IPv4, (uint8_t *)saddr6->sin6_addr.s6_addr + IPADDRESS_V4_BYTES_INDEX); + } else { + return IPAddress(IPv6, (uint8_t *)(saddr6->sin6_addr.s6_addr), saddr6->sin6_scope_id); } - log_e("NetworkClient::remoteIP Not AF_INET or AF_INET6?"); - return (IPAddress(0,0,0,0)); + } + log_e("NetworkClient::remoteIP Not AF_INET or AF_INET6?"); + return (IPAddress(0, 0, 0, 0)); } -uint16_t NetworkClient::remotePort(int fd) const -{ - struct sockaddr_storage addr; - socklen_t len = sizeof addr; - getpeername(fd, (struct sockaddr*)&addr, &len); - struct sockaddr_in *s = (struct sockaddr_in *)&addr; - return ntohs(s->sin_port); +uint16_t NetworkClient::remotePort(int fd) const { + struct sockaddr_storage addr; + socklen_t len = sizeof addr; + getpeername(fd, (struct sockaddr *)&addr, &len); + struct sockaddr_in *s = (struct sockaddr_in *)&addr; + return ntohs(s->sin_port); } -IPAddress NetworkClient::remoteIP() const -{ - return remoteIP(fd()); +IPAddress NetworkClient::remoteIP() const { + return remoteIP(fd()); } -uint16_t NetworkClient::remotePort() const -{ - return remotePort(fd()); +uint16_t NetworkClient::remotePort() const { + return remotePort(fd()); } -IPAddress NetworkClient::localIP(int fd) const -{ - struct sockaddr_storage addr; - socklen_t len = sizeof addr; - getsockname(fd, (struct sockaddr*)&addr, &len); - struct sockaddr_in *s = (struct sockaddr_in *)&addr; - return IPAddress((uint32_t)(s->sin_addr.s_addr)); +IPAddress NetworkClient::localIP(int fd) const { + struct sockaddr_storage addr; + socklen_t len = sizeof addr; + getsockname(fd, (struct sockaddr *)&addr, &len); + struct sockaddr_in *s = (struct sockaddr_in *)&addr; + return IPAddress((uint32_t)(s->sin_addr.s_addr)); } -uint16_t NetworkClient::localPort(int fd) const -{ - struct sockaddr_storage addr; - socklen_t len = sizeof addr; - getsockname(fd, (struct sockaddr*)&addr, &len); - struct sockaddr_in *s = (struct sockaddr_in *)&addr; - return ntohs(s->sin_port); +uint16_t NetworkClient::localPort(int fd) const { + struct sockaddr_storage addr; + socklen_t len = sizeof addr; + getsockname(fd, (struct sockaddr *)&addr, &len); + struct sockaddr_in *s = (struct sockaddr_in *)&addr; + return ntohs(s->sin_port); } -IPAddress NetworkClient::localIP() const -{ - return localIP(fd()); +IPAddress NetworkClient::localIP() const { + return localIP(fd()); } -uint16_t NetworkClient::localPort() const -{ - return localPort(fd()); +uint16_t NetworkClient::localPort() const { + return localPort(fd()); } -bool NetworkClient::operator==(const NetworkClient& rhs) -{ - return clientSocketHandle == rhs.clientSocketHandle && remotePort() == rhs.remotePort() && remoteIP() == rhs.remoteIP(); +bool NetworkClient::operator==(const NetworkClient &rhs) { + return clientSocketHandle == rhs.clientSocketHandle && remotePort() == rhs.remotePort() && remoteIP() == rhs.remoteIP(); } -int NetworkClient::fd() const -{ - if (clientSocketHandle == NULL) { - return -1; - } else { - return clientSocketHandle->fd(); - } +int NetworkClient::fd() const { + if (clientSocketHandle == NULL) { + return -1; + } else { + return clientSocketHandle->fd(); + } } -void NetworkClient::setSSE(bool sse) -{ - _sse = sse; +void NetworkClient::setSSE(bool sse) { + _sse = sse; } -bool NetworkClient::isSSE() -{ - return _sse; +bool NetworkClient::isSSE() { + return _sse; } - diff --git a/libraries/Network/src/NetworkClient.h b/libraries/Network/src/NetworkClient.h index 848ac61f870..0c8567a9b80 100644 --- a/libraries/Network/src/NetworkClient.h +++ b/libraries/Network/src/NetworkClient.h @@ -27,88 +27,81 @@ class NetworkClientSocketHandle; class NetworkClientRxBuffer; -class ESPLwIPClient : public Client -{ +class ESPLwIPClient : public Client { public: - virtual int connect(IPAddress ip, uint16_t port, int32_t timeout) = 0; - virtual int connect(const char *host, uint16_t port, int32_t timeout) = 0; - virtual void setConnectionTimeout(uint32_t milliseconds) = 0; + virtual int connect(IPAddress ip, uint16_t port, int32_t timeout) = 0; + virtual int connect(const char *host, uint16_t port, int32_t timeout) = 0; + virtual void setConnectionTimeout(uint32_t milliseconds) = 0; }; -class NetworkClient : public ESPLwIPClient -{ +class NetworkClient : public ESPLwIPClient { protected: - std::shared_ptr clientSocketHandle; - std::shared_ptr _rxBuffer; - bool _connected; - bool _sse; - int _timeout; - int _lastWriteTimeout; - int _lastReadTimeout; + std::shared_ptr clientSocketHandle; + std::shared_ptr _rxBuffer; + bool _connected; + bool _sse; + int _timeout; + int _lastWriteTimeout; + int _lastReadTimeout; public: - NetworkClient *next; - NetworkClient(); - NetworkClient(int fd); - ~NetworkClient(); - int connect(IPAddress ip, uint16_t port); - int connect(IPAddress ip, uint16_t port, int32_t timeout_ms); - int connect(const char *host, uint16_t port); - int connect(const char *host, uint16_t port, int32_t timeout_ms); - size_t write(uint8_t data); - size_t write(const uint8_t *buf, size_t size); - size_t write_P(PGM_P buf, size_t size); - size_t write(Stream &stream); - void flush(); // Print::flush tx - int available(); - int read(); - int read(uint8_t *buf, size_t size); - int peek(); - void clear(); // clear rx - void stop(); - uint8_t connected(); - void setSSE(bool sse); - bool isSSE(); - - operator bool() - { - return connected(); - } - bool operator==(const bool value) - { - return bool() == value; - } - bool operator!=(const bool value) - { - return bool() != value; - } - bool operator==(const NetworkClient&); - bool operator!=(const NetworkClient& rhs) - { - return !this->operator==(rhs); - }; - - virtual int fd() const; - - int setSocketOption(int option, char* value, size_t len); - int setSocketOption(int level, int option, const void* value, size_t len); - int getSocketOption(int level, int option, const void* value, size_t size); - int setOption(int option, int *value); - int getOption(int option, int *value); - void setConnectionTimeout(uint32_t milliseconds); - int setNoDelay(bool nodelay); - bool getNoDelay(); - - IPAddress remoteIP() const; - IPAddress remoteIP(int fd) const; - uint16_t remotePort() const; - uint16_t remotePort(int fd) const; - IPAddress localIP() const; - IPAddress localIP(int fd) const; - uint16_t localPort() const; - uint16_t localPort(int fd) const; - - //friend class NetworkServer; - using Print::write; + NetworkClient *next; + NetworkClient(); + NetworkClient(int fd); + ~NetworkClient(); + int connect(IPAddress ip, uint16_t port); + int connect(IPAddress ip, uint16_t port, int32_t timeout_ms); + int connect(const char *host, uint16_t port); + int connect(const char *host, uint16_t port, int32_t timeout_ms); + size_t write(uint8_t data); + size_t write(const uint8_t *buf, size_t size); + size_t write_P(PGM_P buf, size_t size); + size_t write(Stream &stream); + void flush(); // Print::flush tx + int available(); + int read(); + int read(uint8_t *buf, size_t size); + int peek(); + void clear(); // clear rx + void stop(); + uint8_t connected(); + void setSSE(bool sse); + bool isSSE(); + + operator bool() { + return connected(); + } + bool operator==(const bool value) { + return bool() == value; + } + bool operator!=(const bool value) { + return bool() != value; + } + bool operator==(const NetworkClient &); + bool operator!=(const NetworkClient &rhs) { + return !this->operator==(rhs); + }; + + virtual int fd() const; + + int setSocketOption(int option, char *value, size_t len); + int setSocketOption(int level, int option, const void *value, size_t len); + int getSocketOption(int level, int option, const void *value, size_t size); + int setOption(int option, int *value); + int getOption(int option, int *value); + void setConnectionTimeout(uint32_t milliseconds); + int setNoDelay(bool nodelay); + bool getNoDelay(); + + IPAddress remoteIP() const; + IPAddress remoteIP(int fd) const; + uint16_t remotePort() const; + uint16_t remotePort(int fd) const; + IPAddress localIP() const; + IPAddress localIP(int fd) const; + uint16_t localPort() const; + uint16_t localPort(int fd) const; + + //friend class NetworkServer; + using Print::write; }; - diff --git a/libraries/Network/src/NetworkEvents.cpp b/libraries/Network/src/NetworkEvents.cpp index 5f24e23a894..a7955ee6cf2 100644 --- a/libraries/Network/src/NetworkEvents.cpp +++ b/libraries/Network/src/NetworkEvents.cpp @@ -9,313 +9,300 @@ #include "esp32-hal.h" typedef struct NetworkEventCbList { - static network_event_handle_t current_id; - network_event_handle_t id; - NetworkEventCb cb; - NetworkEventFuncCb fcb; - NetworkEventSysCb scb; - arduino_event_id_t event; - - NetworkEventCbList() : id(current_id++), cb(NULL), fcb(NULL), scb(NULL), event(ARDUINO_EVENT_NONE) {} + static network_event_handle_t current_id; + network_event_handle_t id; + NetworkEventCb cb; + NetworkEventFuncCb fcb; + NetworkEventSysCb scb; + arduino_event_id_t event; + + NetworkEventCbList() + : id(current_id++), cb(NULL), fcb(NULL), scb(NULL), event(ARDUINO_EVENT_NONE) {} } NetworkEventCbList_t; network_event_handle_t NetworkEventCbList::current_id = 1; // arduino dont like std::vectors move static here static std::vector cbEventList; -static void _network_event_task(void * arg){ - for (;;) { - ((NetworkEvents*)arg)->checkForEvent(); - } - vTaskDelete(NULL); +static void _network_event_task(void *arg) { + for (;;) { + ((NetworkEvents *)arg)->checkForEvent(); + } + vTaskDelete(NULL); } NetworkEvents::NetworkEvents() - : _arduino_event_group(NULL) - , _arduino_event_queue(NULL) - , _arduino_event_task_handle(NULL) -{} - -NetworkEvents::~NetworkEvents(){ - if(_arduino_event_task_handle != NULL){ - vTaskDelete(_arduino_event_task_handle); - _arduino_event_task_handle = NULL; - } - if(_arduino_event_group != NULL){ - vEventGroupDelete(_arduino_event_group); - _arduino_event_group = NULL; - } - if(_arduino_event_queue != NULL){ - arduino_event_t *event = NULL; - while(xQueueReceive(_arduino_event_queue, &event, 0) == pdTRUE){ - free(event); - } - vQueueDelete(_arduino_event_queue); - _arduino_event_queue = NULL; - } + : _arduino_event_group(NULL), _arduino_event_queue(NULL), _arduino_event_task_handle(NULL) {} + +NetworkEvents::~NetworkEvents() { + if (_arduino_event_task_handle != NULL) { + vTaskDelete(_arduino_event_task_handle); + _arduino_event_task_handle = NULL; + } + if (_arduino_event_group != NULL) { + vEventGroupDelete(_arduino_event_group); + _arduino_event_group = NULL; + } + if (_arduino_event_queue != NULL) { + arduino_event_t *event = NULL; + while (xQueueReceive(_arduino_event_queue, &event, 0) == pdTRUE) { + free(event); + } + vQueueDelete(_arduino_event_queue); + _arduino_event_queue = NULL; + } } static uint32_t _initial_bits = 0; -bool NetworkEvents::initNetworkEvents(){ - if(!_arduino_event_group){ - _arduino_event_group = xEventGroupCreate(); - if(!_arduino_event_group){ - log_e("Network Event Group Create Failed!"); - return false; - } - xEventGroupSetBits(_arduino_event_group, _initial_bits); +bool NetworkEvents::initNetworkEvents() { + if (!_arduino_event_group) { + _arduino_event_group = xEventGroupCreate(); + if (!_arduino_event_group) { + log_e("Network Event Group Create Failed!"); + return false; } - - if(!_arduino_event_queue){ - _arduino_event_queue = xQueueCreate(32, sizeof(arduino_event_t*)); - if(!_arduino_event_queue){ - log_e("Network Event Queue Create Failed!"); - return false; - } + xEventGroupSetBits(_arduino_event_group, _initial_bits); + } + + if (!_arduino_event_queue) { + _arduino_event_queue = xQueueCreate(32, sizeof(arduino_event_t *)); + if (!_arduino_event_queue) { + log_e("Network Event Queue Create Failed!"); + return false; } - - esp_err_t err = esp_event_loop_create_default(); - if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) { - log_e("esp_event_loop_create_default failed!"); - return err; + } + + esp_err_t err = esp_event_loop_create_default(); + if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) { + log_e("esp_event_loop_create_default failed!"); + return err; + } + + if (!_arduino_event_task_handle) { + xTaskCreateUniversal(_network_event_task, "arduino_events", 4096, this, ESP_TASKD_EVENT_PRIO - 1, &_arduino_event_task_handle, ARDUINO_EVENT_RUNNING_CORE); + if (!_arduino_event_task_handle) { + log_e("Network Event Task Start Failed!"); + return false; } + } - if(!_arduino_event_task_handle){ - xTaskCreateUniversal(_network_event_task, "arduino_events", 4096, this, ESP_TASKD_EVENT_PRIO - 1, &_arduino_event_task_handle, ARDUINO_EVENT_RUNNING_CORE); - if(!_arduino_event_task_handle){ - log_e("Network Event Task Start Failed!"); - return false; - } - } - - return true; + return true; } -bool NetworkEvents::postEvent(arduino_event_t *data) -{ - if(data == NULL || _arduino_event_queue == NULL){ - return false; - } - arduino_event_t * event = (arduino_event_t*)malloc(sizeof(arduino_event_t)); - if(event == NULL){ - log_e("Arduino Event Malloc Failed!"); - return false; - } - memcpy(event, data, sizeof(arduino_event_t)); - if (xQueueSend(_arduino_event_queue, &event, portMAX_DELAY) != pdPASS) { - log_e("Arduino Event Send Failed!"); - return false; - } - return true; +bool NetworkEvents::postEvent(arduino_event_t *data) { + if (data == NULL || _arduino_event_queue == NULL) { + return false; + } + arduino_event_t *event = (arduino_event_t *)malloc(sizeof(arduino_event_t)); + if (event == NULL) { + log_e("Arduino Event Malloc Failed!"); + return false; + } + memcpy(event, data, sizeof(arduino_event_t)); + if (xQueueSend(_arduino_event_queue, &event, portMAX_DELAY) != pdPASS) { + log_e("Arduino Event Send Failed!"); + return false; + } + return true; } -void NetworkEvents::checkForEvent() -{ - arduino_event_t *event = NULL; - if(_arduino_event_queue == NULL){ - return; - } - if(xQueueReceive(_arduino_event_queue, &event, portMAX_DELAY) != pdTRUE){ - return; - } - if(event == NULL){ - return; - } - log_v("Network Event: %d - %s", event->event_id, eventName(event->event_id)); - for(uint32_t i = 0; i < cbEventList.size(); i++) { - NetworkEventCbList_t entry = cbEventList[i]; - if(entry.cb || entry.fcb || entry.scb) { - if(entry.event == (arduino_event_id_t) event->event_id || entry.event == ARDUINO_EVENT_MAX) { - if(entry.cb) { - entry.cb((arduino_event_id_t) event->event_id); - } else if(entry.fcb) { - entry.fcb((arduino_event_id_t) event->event_id, (arduino_event_info_t) event->event_info); - } else { - entry.scb(event); - } - } +void NetworkEvents::checkForEvent() { + arduino_event_t *event = NULL; + if (_arduino_event_queue == NULL) { + return; + } + if (xQueueReceive(_arduino_event_queue, &event, portMAX_DELAY) != pdTRUE) { + return; + } + if (event == NULL) { + return; + } + log_v("Network Event: %d - %s", event->event_id, eventName(event->event_id)); + for (uint32_t i = 0; i < cbEventList.size(); i++) { + NetworkEventCbList_t entry = cbEventList[i]; + if (entry.cb || entry.fcb || entry.scb) { + if (entry.event == (arduino_event_id_t)event->event_id || entry.event == ARDUINO_EVENT_MAX) { + if (entry.cb) { + entry.cb((arduino_event_id_t)event->event_id); + } else if (entry.fcb) { + entry.fcb((arduino_event_id_t)event->event_id, (arduino_event_info_t)event->event_info); + } else { + entry.scb(event); } + } } - free(event); + } + free(event); } -network_event_handle_t NetworkEvents::onEvent(NetworkEventCb cbEvent, arduino_event_id_t event) -{ - if(!cbEvent) { - return 0; - } - NetworkEventCbList_t newEventHandler; - newEventHandler.cb = cbEvent; - newEventHandler.fcb = NULL; - newEventHandler.scb = NULL; - newEventHandler.event = event; - cbEventList.push_back(newEventHandler); - return newEventHandler.id; +network_event_handle_t NetworkEvents::onEvent(NetworkEventCb cbEvent, arduino_event_id_t event) { + if (!cbEvent) { + return 0; + } + NetworkEventCbList_t newEventHandler; + newEventHandler.cb = cbEvent; + newEventHandler.fcb = NULL; + newEventHandler.scb = NULL; + newEventHandler.event = event; + cbEventList.push_back(newEventHandler); + return newEventHandler.id; } -network_event_handle_t NetworkEvents::onEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event) -{ - if(!cbEvent) { - return 0; - } - NetworkEventCbList_t newEventHandler; - newEventHandler.cb = NULL; - newEventHandler.fcb = cbEvent; - newEventHandler.scb = NULL; - newEventHandler.event = event; - cbEventList.push_back(newEventHandler); - return newEventHandler.id; +network_event_handle_t NetworkEvents::onEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event) { + if (!cbEvent) { + return 0; + } + NetworkEventCbList_t newEventHandler; + newEventHandler.cb = NULL; + newEventHandler.fcb = cbEvent; + newEventHandler.scb = NULL; + newEventHandler.event = event; + cbEventList.push_back(newEventHandler); + return newEventHandler.id; } -network_event_handle_t NetworkEvents::onEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event) -{ - if(!cbEvent) { - return 0; - } - NetworkEventCbList_t newEventHandler; - newEventHandler.cb = NULL; - newEventHandler.fcb = NULL; - newEventHandler.scb = cbEvent; - newEventHandler.event = event; - cbEventList.push_back(newEventHandler); - return newEventHandler.id; +network_event_handle_t NetworkEvents::onEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event) { + if (!cbEvent) { + return 0; + } + NetworkEventCbList_t newEventHandler; + newEventHandler.cb = NULL; + newEventHandler.fcb = NULL; + newEventHandler.scb = cbEvent; + newEventHandler.event = event; + cbEventList.push_back(newEventHandler); + return newEventHandler.id; } -network_event_handle_t NetworkEvents::onSysEvent(NetworkEventCb cbEvent, arduino_event_id_t event) -{ - if(!cbEvent) { - return 0; - } - NetworkEventCbList_t newEventHandler; - newEventHandler.cb = cbEvent; - newEventHandler.fcb = NULL; - newEventHandler.scb = NULL; - newEventHandler.event = event; - cbEventList.insert(cbEventList.begin(), newEventHandler); - return newEventHandler.id; +network_event_handle_t NetworkEvents::onSysEvent(NetworkEventCb cbEvent, arduino_event_id_t event) { + if (!cbEvent) { + return 0; + } + NetworkEventCbList_t newEventHandler; + newEventHandler.cb = cbEvent; + newEventHandler.fcb = NULL; + newEventHandler.scb = NULL; + newEventHandler.event = event; + cbEventList.insert(cbEventList.begin(), newEventHandler); + return newEventHandler.id; } -network_event_handle_t NetworkEvents::onSysEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event) -{ - if(!cbEvent) { - return 0; - } - NetworkEventCbList_t newEventHandler; - newEventHandler.cb = NULL; - newEventHandler.fcb = cbEvent; - newEventHandler.scb = NULL; - newEventHandler.event = event; - cbEventList.insert(cbEventList.begin(), newEventHandler); - return newEventHandler.id; +network_event_handle_t NetworkEvents::onSysEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event) { + if (!cbEvent) { + return 0; + } + NetworkEventCbList_t newEventHandler; + newEventHandler.cb = NULL; + newEventHandler.fcb = cbEvent; + newEventHandler.scb = NULL; + newEventHandler.event = event; + cbEventList.insert(cbEventList.begin(), newEventHandler); + return newEventHandler.id; } -network_event_handle_t NetworkEvents::onSysEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event) -{ - if(!cbEvent) { - return 0; - } - NetworkEventCbList_t newEventHandler; - newEventHandler.cb = NULL; - newEventHandler.fcb = NULL; - newEventHandler.scb = cbEvent; - newEventHandler.event = event; - cbEventList.insert(cbEventList.begin(), newEventHandler); - return newEventHandler.id; +network_event_handle_t NetworkEvents::onSysEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event) { + if (!cbEvent) { + return 0; + } + NetworkEventCbList_t newEventHandler; + newEventHandler.cb = NULL; + newEventHandler.fcb = NULL; + newEventHandler.scb = cbEvent; + newEventHandler.event = event; + cbEventList.insert(cbEventList.begin(), newEventHandler); + return newEventHandler.id; } -void NetworkEvents::removeEvent(NetworkEventCb cbEvent, arduino_event_id_t event) -{ - if(!cbEvent) { - return; - } +void NetworkEvents::removeEvent(NetworkEventCb cbEvent, arduino_event_id_t event) { + if (!cbEvent) { + return; + } - for(uint32_t i = 0; i < cbEventList.size(); i++) { - NetworkEventCbList_t entry = cbEventList[i]; - if(entry.cb == cbEvent && entry.event == event) { - cbEventList.erase(cbEventList.begin() + i); - } + for (uint32_t i = 0; i < cbEventList.size(); i++) { + NetworkEventCbList_t entry = cbEventList[i]; + if (entry.cb == cbEvent && entry.event == event) { + cbEventList.erase(cbEventList.begin() + i); } + } } template static size_t getStdFunctionAddress(std::function f) { - typedef T(fnType)(U...); - fnType ** fnPointer = f.template target(); - return (size_t) *fnPointer; + typedef T(fnType)(U...); + fnType **fnPointer = f.template target(); + return (size_t)*fnPointer; } -void NetworkEvents::removeEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event) -{ - if(!cbEvent) { - return; - } +void NetworkEvents::removeEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event) { + if (!cbEvent) { + return; + } - for(uint32_t i = 0; i < cbEventList.size(); i++) { - NetworkEventCbList_t entry = cbEventList[i]; - if(getStdFunctionAddress(entry.fcb) == getStdFunctionAddress(cbEvent) && entry.event == event) { - cbEventList.erase(cbEventList.begin() + i); - } + for (uint32_t i = 0; i < cbEventList.size(); i++) { + NetworkEventCbList_t entry = cbEventList[i]; + if (getStdFunctionAddress(entry.fcb) == getStdFunctionAddress(cbEvent) && entry.event == event) { + cbEventList.erase(cbEventList.begin() + i); } + } } -void NetworkEvents::removeEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event) -{ - if(!cbEvent) { - return; - } +void NetworkEvents::removeEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event) { + if (!cbEvent) { + return; + } - for(uint32_t i = 0; i < cbEventList.size(); i++) { - NetworkEventCbList_t entry = cbEventList[i]; - if(entry.scb == cbEvent && entry.event == event) { - cbEventList.erase(cbEventList.begin() + i); - } + for (uint32_t i = 0; i < cbEventList.size(); i++) { + NetworkEventCbList_t entry = cbEventList[i]; + if (entry.scb == cbEvent && entry.event == event) { + cbEventList.erase(cbEventList.begin() + i); } + } } -void NetworkEvents::removeEvent(network_event_handle_t id) -{ - for(uint32_t i = 0; i < cbEventList.size(); i++) { - NetworkEventCbList_t entry = cbEventList[i]; - if(entry.id == id) { - cbEventList.erase(cbEventList.begin() + i); - } +void NetworkEvents::removeEvent(network_event_handle_t id) { + for (uint32_t i = 0; i < cbEventList.size(); i++) { + NetworkEventCbList_t entry = cbEventList[i]; + if (entry.id == id) { + cbEventList.erase(cbEventList.begin() + i); } + } } -int NetworkEvents::setStatusBits(int bits){ - if(!_arduino_event_group){ - _initial_bits |= bits; - return _initial_bits; - } - return xEventGroupSetBits(_arduino_event_group, bits); +int NetworkEvents::setStatusBits(int bits) { + if (!_arduino_event_group) { + _initial_bits |= bits; + return _initial_bits; + } + return xEventGroupSetBits(_arduino_event_group, bits); } -int NetworkEvents::clearStatusBits(int bits){ - if(!_arduino_event_group){ - _initial_bits &= ~bits; - return _initial_bits; - } - return xEventGroupClearBits(_arduino_event_group, bits); +int NetworkEvents::clearStatusBits(int bits) { + if (!_arduino_event_group) { + _initial_bits &= ~bits; + return _initial_bits; + } + return xEventGroupClearBits(_arduino_event_group, bits); } -int NetworkEvents::getStatusBits(){ - if(!_arduino_event_group){ - return _initial_bits; - } - return xEventGroupGetBits(_arduino_event_group); +int NetworkEvents::getStatusBits() { + if (!_arduino_event_group) { + return _initial_bits; + } + return xEventGroupGetBits(_arduino_event_group); } -int NetworkEvents::waitStatusBits(int bits, uint32_t timeout_ms){ - if(!_arduino_event_group){ - return 0; - } - return xEventGroupWaitBits( - _arduino_event_group, // The event group being tested. - bits, // The bits within the event group to wait for. - pdFALSE, // bits should be cleared before returning. - pdTRUE, // Don't wait for all bits, any bit will do. - timeout_ms / portTICK_PERIOD_MS ) & bits; // Wait a maximum of timeout_ms for any bit to be set. +int NetworkEvents::waitStatusBits(int bits, uint32_t timeout_ms) { + if (!_arduino_event_group) { + return 0; + } + return xEventGroupWaitBits( + _arduino_event_group, // The event group being tested. + bits, // The bits within the event group to wait for. + pdFALSE, // bits should be cleared before returning. + pdTRUE, // Don't wait for all bits, any bit will do. + timeout_ms / portTICK_PERIOD_MS) + & bits; // Wait a maximum of timeout_ms for any bit to be set. } /** @@ -324,60 +311,61 @@ int NetworkEvents::waitStatusBits(int bits, uint32_t timeout_ms){ * @return A string representation of the event id. * @note: arduino_event_id_t values as of Mar 2023 (arduino-esp32 r2.0.7) are: 0-39 (ARDUINO_EVENT_MAX=40) and are defined in WiFiGeneric.h. */ -const char * NetworkEvents::eventName(arduino_event_id_t id) { - switch(id) { - case ARDUINO_EVENT_ETH_START: return "ETH_START"; - case ARDUINO_EVENT_ETH_STOP: return "ETH_STOP"; - case ARDUINO_EVENT_ETH_CONNECTED: return "ETH_CONNECTED"; - case ARDUINO_EVENT_ETH_DISCONNECTED: return "ETH_DISCONNECTED"; - case ARDUINO_EVENT_ETH_GOT_IP: return "ETH_GOT_IP"; - case ARDUINO_EVENT_ETH_LOST_IP: return "ETH_LOST_IP"; - case ARDUINO_EVENT_ETH_GOT_IP6: return "ETH_GOT_IP6"; - - // case ARDUINO_EVENT_PPP_START: return "PPP_START"; - // case ARDUINO_EVENT_PPP_STOP: return "PPP_STOP"; - // case ARDUINO_EVENT_PPP_CONNECTED: return "PPP_CONNECTED"; - // case ARDUINO_EVENT_PPP_DISCONNECTED: return "PPP_DISCONNECTED"; - // case ARDUINO_EVENT_PPP_GOT_IP: return "PPP_GOT_IP"; - // case ARDUINO_EVENT_PPP_LOST_IP: return "PPP_LOST_IP"; - // case ARDUINO_EVENT_PPP_GOT_IP6: return "PPP_GOT_IP6"; +const char *NetworkEvents::eventName(arduino_event_id_t id) { + switch (id) { + case ARDUINO_EVENT_ETH_START: return "ETH_START"; + case ARDUINO_EVENT_ETH_STOP: return "ETH_STOP"; + case ARDUINO_EVENT_ETH_CONNECTED: return "ETH_CONNECTED"; + case ARDUINO_EVENT_ETH_DISCONNECTED: return "ETH_DISCONNECTED"; + case ARDUINO_EVENT_ETH_GOT_IP: return "ETH_GOT_IP"; + case ARDUINO_EVENT_ETH_LOST_IP: return "ETH_LOST_IP"; + case ARDUINO_EVENT_ETH_GOT_IP6: + return "ETH_GOT_IP6"; + + // case ARDUINO_EVENT_PPP_START: return "PPP_START"; + // case ARDUINO_EVENT_PPP_STOP: return "PPP_STOP"; + // case ARDUINO_EVENT_PPP_CONNECTED: return "PPP_CONNECTED"; + // case ARDUINO_EVENT_PPP_DISCONNECTED: return "PPP_DISCONNECTED"; + // case ARDUINO_EVENT_PPP_GOT_IP: return "PPP_GOT_IP"; + // case ARDUINO_EVENT_PPP_LOST_IP: return "PPP_LOST_IP"; + // case ARDUINO_EVENT_PPP_GOT_IP6: return "PPP_GOT_IP6"; #if SOC_WIFI_SUPPORTED - case ARDUINO_EVENT_WIFI_OFF: return "WIFI_OFF"; - case ARDUINO_EVENT_WIFI_READY: return "WIFI_READY"; - case ARDUINO_EVENT_WIFI_SCAN_DONE: return "SCAN_DONE"; - case ARDUINO_EVENT_WIFI_STA_START: return "STA_START"; - case ARDUINO_EVENT_WIFI_STA_STOP: return "STA_STOP"; - case ARDUINO_EVENT_WIFI_STA_CONNECTED: return "STA_CONNECTED"; - case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: return "STA_DISCONNECTED"; - case ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE: return "STA_AUTHMODE_CHANGE"; - case ARDUINO_EVENT_WIFI_STA_GOT_IP: return "STA_GOT_IP"; - case ARDUINO_EVENT_WIFI_STA_GOT_IP6: return "STA_GOT_IP6"; - case ARDUINO_EVENT_WIFI_STA_LOST_IP: return "STA_LOST_IP"; - case ARDUINO_EVENT_WIFI_AP_START: return "AP_START"; - case ARDUINO_EVENT_WIFI_AP_STOP: return "AP_STOP"; - case ARDUINO_EVENT_WIFI_AP_STACONNECTED: return "AP_STACONNECTED"; - case ARDUINO_EVENT_WIFI_AP_STADISCONNECTED: return "AP_STADISCONNECTED"; - case ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED: return "AP_STAIPASSIGNED"; - case ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED: return "AP_PROBEREQRECVED"; - case ARDUINO_EVENT_WIFI_AP_GOT_IP6: return "AP_GOT_IP6"; - case ARDUINO_EVENT_WIFI_FTM_REPORT: return "FTM_REPORT"; - case ARDUINO_EVENT_WPS_ER_SUCCESS: return "WPS_ER_SUCCESS"; - case ARDUINO_EVENT_WPS_ER_FAILED: return "WPS_ER_FAILED"; - case ARDUINO_EVENT_WPS_ER_TIMEOUT: return "WPS_ER_TIMEOUT"; - case ARDUINO_EVENT_WPS_ER_PIN: return "WPS_ER_PIN"; - case ARDUINO_EVENT_WPS_ER_PBC_OVERLAP: return "WPS_ER_PBC_OVERLAP"; - case ARDUINO_EVENT_SC_SCAN_DONE: return "SC_SCAN_DONE"; - case ARDUINO_EVENT_SC_FOUND_CHANNEL: return "SC_FOUND_CHANNEL"; - case ARDUINO_EVENT_SC_GOT_SSID_PSWD: return "SC_GOT_SSID_PSWD"; - case ARDUINO_EVENT_SC_SEND_ACK_DONE: return "SC_SEND_ACK_DONE"; - case ARDUINO_EVENT_PROV_INIT: return "PROV_INIT"; - case ARDUINO_EVENT_PROV_DEINIT: return "PROV_DEINIT"; - case ARDUINO_EVENT_PROV_START: return "PROV_START"; - case ARDUINO_EVENT_PROV_END: return "PROV_END"; - case ARDUINO_EVENT_PROV_CRED_RECV: return "PROV_CRED_RECV"; - case ARDUINO_EVENT_PROV_CRED_FAIL: return "PROV_CRED_FAIL"; - case ARDUINO_EVENT_PROV_CRED_SUCCESS: return "PROV_CRED_SUCCESS"; + case ARDUINO_EVENT_WIFI_OFF: return "WIFI_OFF"; + case ARDUINO_EVENT_WIFI_READY: return "WIFI_READY"; + case ARDUINO_EVENT_WIFI_SCAN_DONE: return "SCAN_DONE"; + case ARDUINO_EVENT_WIFI_STA_START: return "STA_START"; + case ARDUINO_EVENT_WIFI_STA_STOP: return "STA_STOP"; + case ARDUINO_EVENT_WIFI_STA_CONNECTED: return "STA_CONNECTED"; + case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: return "STA_DISCONNECTED"; + case ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE: return "STA_AUTHMODE_CHANGE"; + case ARDUINO_EVENT_WIFI_STA_GOT_IP: return "STA_GOT_IP"; + case ARDUINO_EVENT_WIFI_STA_GOT_IP6: return "STA_GOT_IP6"; + case ARDUINO_EVENT_WIFI_STA_LOST_IP: return "STA_LOST_IP"; + case ARDUINO_EVENT_WIFI_AP_START: return "AP_START"; + case ARDUINO_EVENT_WIFI_AP_STOP: return "AP_STOP"; + case ARDUINO_EVENT_WIFI_AP_STACONNECTED: return "AP_STACONNECTED"; + case ARDUINO_EVENT_WIFI_AP_STADISCONNECTED: return "AP_STADISCONNECTED"; + case ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED: return "AP_STAIPASSIGNED"; + case ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED: return "AP_PROBEREQRECVED"; + case ARDUINO_EVENT_WIFI_AP_GOT_IP6: return "AP_GOT_IP6"; + case ARDUINO_EVENT_WIFI_FTM_REPORT: return "FTM_REPORT"; + case ARDUINO_EVENT_WPS_ER_SUCCESS: return "WPS_ER_SUCCESS"; + case ARDUINO_EVENT_WPS_ER_FAILED: return "WPS_ER_FAILED"; + case ARDUINO_EVENT_WPS_ER_TIMEOUT: return "WPS_ER_TIMEOUT"; + case ARDUINO_EVENT_WPS_ER_PIN: return "WPS_ER_PIN"; + case ARDUINO_EVENT_WPS_ER_PBC_OVERLAP: return "WPS_ER_PBC_OVERLAP"; + case ARDUINO_EVENT_SC_SCAN_DONE: return "SC_SCAN_DONE"; + case ARDUINO_EVENT_SC_FOUND_CHANNEL: return "SC_FOUND_CHANNEL"; + case ARDUINO_EVENT_SC_GOT_SSID_PSWD: return "SC_GOT_SSID_PSWD"; + case ARDUINO_EVENT_SC_SEND_ACK_DONE: return "SC_SEND_ACK_DONE"; + case ARDUINO_EVENT_PROV_INIT: return "PROV_INIT"; + case ARDUINO_EVENT_PROV_DEINIT: return "PROV_DEINIT"; + case ARDUINO_EVENT_PROV_START: return "PROV_START"; + case ARDUINO_EVENT_PROV_END: return "PROV_END"; + case ARDUINO_EVENT_PROV_CRED_RECV: return "PROV_CRED_RECV"; + case ARDUINO_EVENT_PROV_CRED_FAIL: return "PROV_CRED_FAIL"; + case ARDUINO_EVENT_PROV_CRED_SUCCESS: return "PROV_CRED_SUCCESS"; #endif - default: return ""; - } + default: return ""; + } } diff --git a/libraries/Network/src/NetworkEvents.h b/libraries/Network/src/NetworkEvents.h index eaee117d0fc..2d6042461fc 100644 --- a/libraries/Network/src/NetworkEvents.h +++ b/libraries/Network/src/NetworkEvents.h @@ -25,7 +25,7 @@ #if SOC_WIFI_SUPPORTED static const int WIFI_SCANNING_BIT = BIT0; -static const int WIFI_SCAN_DONE_BIT= BIT1; +static const int WIFI_SCAN_DONE_BIT = BIT1; #endif #define NET_HAS_IP6_GLOBAL_BIT 0 @@ -33,86 +33,86 @@ static const int WIFI_SCAN_DONE_BIT= BIT1; ESP_EVENT_DECLARE_BASE(ARDUINO_EVENTS); typedef enum { - ARDUINO_EVENT_NONE, - ARDUINO_EVENT_ETH_START, - ARDUINO_EVENT_ETH_STOP, - ARDUINO_EVENT_ETH_CONNECTED, - ARDUINO_EVENT_ETH_DISCONNECTED, - ARDUINO_EVENT_ETH_GOT_IP, - ARDUINO_EVENT_ETH_LOST_IP, - ARDUINO_EVENT_ETH_GOT_IP6, + ARDUINO_EVENT_NONE, + ARDUINO_EVENT_ETH_START, + ARDUINO_EVENT_ETH_STOP, + ARDUINO_EVENT_ETH_CONNECTED, + ARDUINO_EVENT_ETH_DISCONNECTED, + ARDUINO_EVENT_ETH_GOT_IP, + ARDUINO_EVENT_ETH_LOST_IP, + ARDUINO_EVENT_ETH_GOT_IP6, #if SOC_WIFI_SUPPORTED - ARDUINO_EVENT_WIFI_OFF, - ARDUINO_EVENT_WIFI_READY, - ARDUINO_EVENT_WIFI_SCAN_DONE, - ARDUINO_EVENT_WIFI_STA_START, - ARDUINO_EVENT_WIFI_STA_STOP, - ARDUINO_EVENT_WIFI_STA_CONNECTED, - ARDUINO_EVENT_WIFI_STA_DISCONNECTED, - ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE, - ARDUINO_EVENT_WIFI_STA_GOT_IP, - ARDUINO_EVENT_WIFI_STA_GOT_IP6, - ARDUINO_EVENT_WIFI_STA_LOST_IP, - ARDUINO_EVENT_WIFI_AP_START, - ARDUINO_EVENT_WIFI_AP_STOP, - ARDUINO_EVENT_WIFI_AP_STACONNECTED, - ARDUINO_EVENT_WIFI_AP_STADISCONNECTED, - ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED, - ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED, - ARDUINO_EVENT_WIFI_AP_GOT_IP6, - ARDUINO_EVENT_WIFI_FTM_REPORT, - ARDUINO_EVENT_WPS_ER_SUCCESS, - ARDUINO_EVENT_WPS_ER_FAILED, - ARDUINO_EVENT_WPS_ER_TIMEOUT, - ARDUINO_EVENT_WPS_ER_PIN, - ARDUINO_EVENT_WPS_ER_PBC_OVERLAP, - ARDUINO_EVENT_SC_SCAN_DONE, - ARDUINO_EVENT_SC_FOUND_CHANNEL, - ARDUINO_EVENT_SC_GOT_SSID_PSWD, - ARDUINO_EVENT_SC_SEND_ACK_DONE, - ARDUINO_EVENT_PROV_INIT, - ARDUINO_EVENT_PROV_DEINIT, - ARDUINO_EVENT_PROV_START, - ARDUINO_EVENT_PROV_END, - ARDUINO_EVENT_PROV_CRED_RECV, - ARDUINO_EVENT_PROV_CRED_FAIL, - ARDUINO_EVENT_PROV_CRED_SUCCESS, + ARDUINO_EVENT_WIFI_OFF, + ARDUINO_EVENT_WIFI_READY, + ARDUINO_EVENT_WIFI_SCAN_DONE, + ARDUINO_EVENT_WIFI_STA_START, + ARDUINO_EVENT_WIFI_STA_STOP, + ARDUINO_EVENT_WIFI_STA_CONNECTED, + ARDUINO_EVENT_WIFI_STA_DISCONNECTED, + ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE, + ARDUINO_EVENT_WIFI_STA_GOT_IP, + ARDUINO_EVENT_WIFI_STA_GOT_IP6, + ARDUINO_EVENT_WIFI_STA_LOST_IP, + ARDUINO_EVENT_WIFI_AP_START, + ARDUINO_EVENT_WIFI_AP_STOP, + ARDUINO_EVENT_WIFI_AP_STACONNECTED, + ARDUINO_EVENT_WIFI_AP_STADISCONNECTED, + ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED, + ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED, + ARDUINO_EVENT_WIFI_AP_GOT_IP6, + ARDUINO_EVENT_WIFI_FTM_REPORT, + ARDUINO_EVENT_WPS_ER_SUCCESS, + ARDUINO_EVENT_WPS_ER_FAILED, + ARDUINO_EVENT_WPS_ER_TIMEOUT, + ARDUINO_EVENT_WPS_ER_PIN, + ARDUINO_EVENT_WPS_ER_PBC_OVERLAP, + ARDUINO_EVENT_SC_SCAN_DONE, + ARDUINO_EVENT_SC_FOUND_CHANNEL, + ARDUINO_EVENT_SC_GOT_SSID_PSWD, + ARDUINO_EVENT_SC_SEND_ACK_DONE, + ARDUINO_EVENT_PROV_INIT, + ARDUINO_EVENT_PROV_DEINIT, + ARDUINO_EVENT_PROV_START, + ARDUINO_EVENT_PROV_END, + ARDUINO_EVENT_PROV_CRED_RECV, + ARDUINO_EVENT_PROV_CRED_FAIL, + ARDUINO_EVENT_PROV_CRED_SUCCESS, #endif - // ARDUINO_EVENT_PPP_START, - // ARDUINO_EVENT_PPP_STOP, - // ARDUINO_EVENT_PPP_CONNECTED, - // ARDUINO_EVENT_PPP_DISCONNECTED, - // ARDUINO_EVENT_PPP_GOT_IP, - // ARDUINO_EVENT_PPP_LOST_IP, - // ARDUINO_EVENT_PPP_GOT_IP6, - ARDUINO_EVENT_MAX + // ARDUINO_EVENT_PPP_START, + // ARDUINO_EVENT_PPP_STOP, + // ARDUINO_EVENT_PPP_CONNECTED, + // ARDUINO_EVENT_PPP_DISCONNECTED, + // ARDUINO_EVENT_PPP_GOT_IP, + // ARDUINO_EVENT_PPP_LOST_IP, + // ARDUINO_EVENT_PPP_GOT_IP6, + ARDUINO_EVENT_MAX } arduino_event_id_t; typedef union { - ip_event_ap_staipassigned_t wifi_ap_staipassigned; - ip_event_got_ip_t got_ip; - ip_event_got_ip6_t got_ip6; - esp_eth_handle_t eth_connected; + ip_event_ap_staipassigned_t wifi_ap_staipassigned; + ip_event_got_ip_t got_ip; + ip_event_got_ip6_t got_ip6; + esp_eth_handle_t eth_connected; #if SOC_WIFI_SUPPORTED - wifi_event_sta_scan_done_t wifi_scan_done; - wifi_event_sta_authmode_change_t wifi_sta_authmode_change; - wifi_event_sta_connected_t wifi_sta_connected; - wifi_event_sta_disconnected_t wifi_sta_disconnected; - wifi_event_sta_wps_er_pin_t wps_er_pin; - wifi_event_sta_wps_fail_reason_t wps_fail_reason; - wifi_event_ap_probe_req_rx_t wifi_ap_probereqrecved; - wifi_event_ap_staconnected_t wifi_ap_staconnected; - wifi_event_ap_stadisconnected_t wifi_ap_stadisconnected; - wifi_event_ftm_report_t wifi_ftm_report; - wifi_sta_config_t prov_cred_recv; - wifi_prov_sta_fail_reason_t prov_fail_reason; - smartconfig_event_got_ssid_pswd_t sc_got_ssid_pswd; + wifi_event_sta_scan_done_t wifi_scan_done; + wifi_event_sta_authmode_change_t wifi_sta_authmode_change; + wifi_event_sta_connected_t wifi_sta_connected; + wifi_event_sta_disconnected_t wifi_sta_disconnected; + wifi_event_sta_wps_er_pin_t wps_er_pin; + wifi_event_sta_wps_fail_reason_t wps_fail_reason; + wifi_event_ap_probe_req_rx_t wifi_ap_probereqrecved; + wifi_event_ap_staconnected_t wifi_ap_staconnected; + wifi_event_ap_stadisconnected_t wifi_ap_stadisconnected; + wifi_event_ftm_report_t wifi_ftm_report; + wifi_sta_config_t prov_cred_recv; + wifi_prov_sta_fail_reason_t prov_fail_reason; + smartconfig_event_got_ssid_pswd_t sc_got_ssid_pswd; #endif } arduino_event_info_t; -typedef struct{ - arduino_event_id_t event_id; - arduino_event_info_t event_info; +typedef struct { + arduino_event_id_t event_id; + arduino_event_info_t event_info; } arduino_event_t; typedef void (*NetworkEventCb)(arduino_event_id_t event); @@ -123,44 +123,42 @@ typedef size_t network_event_handle_t; class NetworkEvents { public: - NetworkEvents(); - ~NetworkEvents(); + NetworkEvents(); + ~NetworkEvents(); - network_event_handle_t onEvent(NetworkEventCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); - network_event_handle_t onEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); - network_event_handle_t onEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); - void removeEvent(NetworkEventCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); - void removeEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); - void removeEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); - void removeEvent(network_event_handle_t event_handle); + network_event_handle_t onEvent(NetworkEventCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); + network_event_handle_t onEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); + network_event_handle_t onEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); + void removeEvent(NetworkEventCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); + void removeEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); + void removeEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); + void removeEvent(network_event_handle_t event_handle); - const char * eventName(arduino_event_id_t id); + const char *eventName(arduino_event_id_t id); - void checkForEvent(); - bool postEvent(arduino_event_t *event); + void checkForEvent(); + bool postEvent(arduino_event_t *event); - int getStatusBits(); - int waitStatusBits(int bits, uint32_t timeout_ms); - int setStatusBits(int bits); - int clearStatusBits(int bits); + int getStatusBits(); + int waitStatusBits(int bits, uint32_t timeout_ms); + int setStatusBits(int bits); + int clearStatusBits(int bits); - friend class ESP_NetworkInterface; - friend class ETHClass; + friend class ESP_NetworkInterface; + friend class ETHClass; #if SOC_WIFI_SUPPORTED - friend class STAClass; - friend class APClass; - friend class WiFiGenericClass; + friend class STAClass; + friend class APClass; + friend class WiFiGenericClass; #endif protected: - bool initNetworkEvents(); - network_event_handle_t onSysEvent(NetworkEventCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); - network_event_handle_t onSysEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); - network_event_handle_t onSysEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); + bool initNetworkEvents(); + network_event_handle_t onSysEvent(NetworkEventCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); + network_event_handle_t onSysEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); + network_event_handle_t onSysEvent(NetworkEventSysCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX); private: - EventGroupHandle_t _arduino_event_group; - QueueHandle_t _arduino_event_queue; - TaskHandle_t _arduino_event_task_handle; + EventGroupHandle_t _arduino_event_group; + QueueHandle_t _arduino_event_queue; + TaskHandle_t _arduino_event_task_handle; }; - - diff --git a/libraries/Network/src/NetworkInterface.cpp b/libraries/Network/src/NetworkInterface.cpp index 99896d9060c..37e30900804 100644 --- a/libraries/Network/src/NetworkInterface.cpp +++ b/libraries/Network/src/NetworkInterface.cpp @@ -15,813 +15,784 @@ #include "dhcpserver/dhcpserver_options.h" #include "esp32-hal-log.h" -static NetworkInterface * _interfaces[ESP_NETIF_ID_MAX] = { NULL, NULL, NULL, NULL, NULL, NULL}; +static NetworkInterface* _interfaces[ESP_NETIF_ID_MAX] = { NULL, NULL, NULL, NULL, NULL, NULL }; static esp_event_handler_instance_t _ip_ev_instance = NULL; -static NetworkInterface * getNetifByEspNetif(esp_netif_t *esp_netif){ - for (int i = 0; i < ESP_NETIF_ID_MAX; ++i){ - if(_interfaces[i] != NULL && _interfaces[i]->netif() == esp_netif){ - return _interfaces[i]; - } +static NetworkInterface* getNetifByEspNetif(esp_netif_t* esp_netif) { + for (int i = 0; i < ESP_NETIF_ID_MAX; ++i) { + if (_interfaces[i] != NULL && _interfaces[i]->netif() == esp_netif) { + return _interfaces[i]; } - return NULL; + } + return NULL; } -NetworkInterface * getNetifByID(Network_Interface_ID id){ - if(id < ESP_NETIF_ID_MAX){ - return _interfaces[id]; - } - return NULL; +NetworkInterface* getNetifByID(Network_Interface_ID id) { + if (id < ESP_NETIF_ID_MAX) { + return _interfaces[id]; + } + return NULL; } static void _ip_event_cb(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { - if (event_base == IP_EVENT){ - NetworkInterface * netif = NULL; - if(event_id == IP_EVENT_STA_GOT_IP || event_id == IP_EVENT_ETH_GOT_IP || event_id == IP_EVENT_PPP_GOT_IP){ - ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; - netif = getNetifByEspNetif(event->esp_netif); - } else if(event_id == IP_EVENT_STA_LOST_IP || event_id == IP_EVENT_PPP_LOST_IP || event_id == IP_EVENT_ETH_LOST_IP){ - ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; - netif = getNetifByEspNetif(event->esp_netif); - } else if(event_id == IP_EVENT_GOT_IP6){ - ip_event_got_ip6_t* event = (ip_event_got_ip6_t*) event_data; - netif = getNetifByEspNetif(event->esp_netif); - } else if(event_id == IP_EVENT_AP_STAIPASSIGNED){ - ip_event_ap_staipassigned_t* event = (ip_event_ap_staipassigned_t*) event_data; - netif = getNetifByEspNetif(event->esp_netif); - } - if(netif != NULL){ - netif->_onIpEvent(event_id, event_data); - } - } -} - -void NetworkInterface::_onIpEvent(int32_t event_id, void* event_data){ - arduino_event_t arduino_event; - arduino_event.event_id = ARDUINO_EVENT_MAX; - if(event_id == _got_ip_event_id){ - setStatusBits(ESP_NETIF_HAS_IP_BIT); + if (event_base == IP_EVENT) { + NetworkInterface* netif = NULL; + if (event_id == IP_EVENT_STA_GOT_IP || event_id == IP_EVENT_ETH_GOT_IP || event_id == IP_EVENT_PPP_GOT_IP) { + ip_event_got_ip_t* event = (ip_event_got_ip_t*)event_data; + netif = getNetifByEspNetif(event->esp_netif); + } else if (event_id == IP_EVENT_STA_LOST_IP || event_id == IP_EVENT_PPP_LOST_IP || event_id == IP_EVENT_ETH_LOST_IP) { + ip_event_got_ip_t* event = (ip_event_got_ip_t*)event_data; + netif = getNetifByEspNetif(event->esp_netif); + } else if (event_id == IP_EVENT_GOT_IP6) { + ip_event_got_ip6_t* event = (ip_event_got_ip6_t*)event_data; + netif = getNetifByEspNetif(event->esp_netif); + } else if (event_id == IP_EVENT_AP_STAIPASSIGNED) { + ip_event_ap_staipassigned_t* event = (ip_event_ap_staipassigned_t*)event_data; + netif = getNetifByEspNetif(event->esp_netif); + } + if (netif != NULL) { + netif->_onIpEvent(event_id, event_data); + } + } +} + +void NetworkInterface::_onIpEvent(int32_t event_id, void* event_data) { + arduino_event_t arduino_event; + arduino_event.event_id = ARDUINO_EVENT_MAX; + if (event_id == _got_ip_event_id) { + setStatusBits(ESP_NETIF_HAS_IP_BIT); #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE - ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; - log_v("%s Got %sIP: " IPSTR " MASK: " IPSTR " GW: " IPSTR, desc(), event->ip_changed?"New ":"Same ", IP2STR(&event->ip_info.ip), IP2STR(&event->ip_info.netmask), IP2STR(&event->ip_info.gw)); + ip_event_got_ip_t* event = (ip_event_got_ip_t*)event_data; + log_v("%s Got %sIP: " IPSTR " MASK: " IPSTR " GW: " IPSTR, desc(), event->ip_changed ? "New " : "Same ", IP2STR(&event->ip_info.ip), IP2STR(&event->ip_info.netmask), IP2STR(&event->ip_info.gw)); #endif - memcpy(&arduino_event.event_info.got_ip, event_data, sizeof(ip_event_got_ip_t)); + memcpy(&arduino_event.event_info.got_ip, event_data, sizeof(ip_event_got_ip_t)); #if SOC_WIFI_SUPPORTED - if(_interface_id == ESP_NETIF_ID_STA){ - arduino_event.event_id = ARDUINO_EVENT_WIFI_STA_GOT_IP; - } else + if (_interface_id == ESP_NETIF_ID_STA) { + arduino_event.event_id = ARDUINO_EVENT_WIFI_STA_GOT_IP; + } else #endif - // if(_interface_id == ESP_NETIF_ID_PPP){ - // arduino_event.event_id = ARDUINO_EVENT_PPP_GOT_IP; - // } else - if(_interface_id >= ESP_NETIF_ID_ETH && _interface_id < ESP_NETIF_ID_MAX){ - arduino_event.event_id = ARDUINO_EVENT_ETH_GOT_IP; - } - } else if(event_id == _lost_ip_event_id){ - clearStatusBits(ESP_NETIF_HAS_IP_BIT); + // if(_interface_id == ESP_NETIF_ID_PPP){ + // arduino_event.event_id = ARDUINO_EVENT_PPP_GOT_IP; + // } else + if (_interface_id >= ESP_NETIF_ID_ETH && _interface_id < ESP_NETIF_ID_MAX) { + arduino_event.event_id = ARDUINO_EVENT_ETH_GOT_IP; + } + } else if (event_id == _lost_ip_event_id) { + clearStatusBits(ESP_NETIF_HAS_IP_BIT); #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE - log_v("%s Lost IP", desc()); + log_v("%s Lost IP", desc()); #endif #if SOC_WIFI_SUPPORTED - if(_interface_id == ESP_NETIF_ID_STA){ - arduino_event.event_id = ARDUINO_EVENT_WIFI_STA_LOST_IP; - } else + if (_interface_id == ESP_NETIF_ID_STA) { + arduino_event.event_id = ARDUINO_EVENT_WIFI_STA_LOST_IP; + } else #endif - // if(_interface_id == ESP_NETIF_ID_PPP){ - // arduino_event.event_id = ARDUINO_EVENT_PPP_LOST_IP; - // } else - if(_interface_id >= ESP_NETIF_ID_ETH && _interface_id < ESP_NETIF_ID_MAX){ - arduino_event.event_id = ARDUINO_EVENT_ETH_LOST_IP; - } - } else if(event_id == IP_EVENT_GOT_IP6){ - ip_event_got_ip6_t* event = (ip_event_got_ip6_t*) event_data; - esp_ip6_addr_type_t addr_type = esp_netif_ip6_get_addr_type(&event->ip6_info.ip); - if(addr_type == ESP_IP6_ADDR_IS_GLOBAL){ - setStatusBits(ESP_NETIF_HAS_GLOBAL_IP6_BIT); - } else if(addr_type == ESP_IP6_ADDR_IS_LINK_LOCAL){ - setStatusBits(ESP_NETIF_HAS_LOCAL_IP6_BIT); - } -#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE - char if_name[NETIF_NAMESIZE] = {0,}; - netif_index_to_name(event->ip6_info.ip.zone, if_name); - static const char * addr_types[] = { "UNKNOWN", "GLOBAL", "LINK_LOCAL", "SITE_LOCAL", "UNIQUE_LOCAL", "IPV4_MAPPED_IPV6" }; - log_v("IF %s Got IPv6: Interface: %d, IP Index: %d, Type: %s, Zone: %d (%s), Address: " IPV6STR, desc(), _interface_id, event->ip_index, addr_types[addr_type], event->ip6_info.ip.zone, if_name, IPV62STR(event->ip6_info.ip)); + // if(_interface_id == ESP_NETIF_ID_PPP){ + // arduino_event.event_id = ARDUINO_EVENT_PPP_LOST_IP; + // } else + if (_interface_id >= ESP_NETIF_ID_ETH && _interface_id < ESP_NETIF_ID_MAX) { + arduino_event.event_id = ARDUINO_EVENT_ETH_LOST_IP; + } + } else if (event_id == IP_EVENT_GOT_IP6) { + ip_event_got_ip6_t* event = (ip_event_got_ip6_t*)event_data; + esp_ip6_addr_type_t addr_type = esp_netif_ip6_get_addr_type(&event->ip6_info.ip); + if (addr_type == ESP_IP6_ADDR_IS_GLOBAL) { + setStatusBits(ESP_NETIF_HAS_GLOBAL_IP6_BIT); + } else if (addr_type == ESP_IP6_ADDR_IS_LINK_LOCAL) { + setStatusBits(ESP_NETIF_HAS_LOCAL_IP6_BIT); + } +#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE + char if_name[NETIF_NAMESIZE] = { + 0, + }; + netif_index_to_name(event->ip6_info.ip.zone, if_name); + static const char* addr_types[] = { "UNKNOWN", "GLOBAL", "LINK_LOCAL", "SITE_LOCAL", "UNIQUE_LOCAL", "IPV4_MAPPED_IPV6" }; + log_v("IF %s Got IPv6: Interface: %d, IP Index: %d, Type: %s, Zone: %d (%s), Address: " IPV6STR, desc(), _interface_id, event->ip_index, addr_types[addr_type], event->ip6_info.ip.zone, if_name, IPV62STR(event->ip6_info.ip)); #endif - memcpy(&arduino_event.event_info.got_ip6, event_data, sizeof(ip_event_got_ip6_t)); + memcpy(&arduino_event.event_info.got_ip6, event_data, sizeof(ip_event_got_ip6_t)); #if SOC_WIFI_SUPPORTED - if(_interface_id == ESP_NETIF_ID_STA){ - arduino_event.event_id = ARDUINO_EVENT_WIFI_STA_GOT_IP6; - } else if(_interface_id == ESP_NETIF_ID_AP){ - arduino_event.event_id = ARDUINO_EVENT_WIFI_AP_GOT_IP6; - } else + if (_interface_id == ESP_NETIF_ID_STA) { + arduino_event.event_id = ARDUINO_EVENT_WIFI_STA_GOT_IP6; + } else if (_interface_id == ESP_NETIF_ID_AP) { + arduino_event.event_id = ARDUINO_EVENT_WIFI_AP_GOT_IP6; + } else #endif - // if(_interface_id == ESP_NETIF_ID_PPP){ - // arduino_event.event_id = ARDUINO_EVENT_PPP_GOT_IP6; - // } else - if(_interface_id >= ESP_NETIF_ID_ETH && _interface_id < ESP_NETIF_ID_MAX){ - arduino_event.event_id = ARDUINO_EVENT_ETH_GOT_IP6; - } + // if(_interface_id == ESP_NETIF_ID_PPP){ + // arduino_event.event_id = ARDUINO_EVENT_PPP_GOT_IP6; + // } else + if (_interface_id >= ESP_NETIF_ID_ETH && _interface_id < ESP_NETIF_ID_MAX) { + arduino_event.event_id = ARDUINO_EVENT_ETH_GOT_IP6; + } #if SOC_WIFI_SUPPORTED - } else if(event_id == IP_EVENT_AP_STAIPASSIGNED && _interface_id == ESP_NETIF_ID_AP){ - setStatusBits(ESP_NETIF_HAS_IP_BIT); + } else if (event_id == IP_EVENT_AP_STAIPASSIGNED && _interface_id == ESP_NETIF_ID_AP) { + setStatusBits(ESP_NETIF_HAS_IP_BIT); #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE - ip_event_ap_staipassigned_t* event = (ip_event_ap_staipassigned_t*) event_data; - log_v("%s Assigned IP: " IPSTR " to MAC: %02X:%02X:%02X:%02X:%02X:%02X", desc(), IP2STR(&event->ip), event->mac[0], event->mac[1], event->mac[2], event->mac[3], event->mac[4], event->mac[5]); + ip_event_ap_staipassigned_t* event = (ip_event_ap_staipassigned_t*)event_data; + log_v("%s Assigned IP: " IPSTR " to MAC: %02X:%02X:%02X:%02X:%02X:%02X", desc(), IP2STR(&event->ip), event->mac[0], event->mac[1], event->mac[2], event->mac[3], event->mac[4], event->mac[5]); #endif - arduino_event.event_id = ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED; - memcpy(&arduino_event.event_info.wifi_ap_staipassigned, event_data, sizeof(ip_event_ap_staipassigned_t)); + arduino_event.event_id = ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED; + memcpy(&arduino_event.event_info.wifi_ap_staipassigned, event_data, sizeof(ip_event_ap_staipassigned_t)); #endif - } - - if(arduino_event.event_id < ARDUINO_EVENT_MAX){ - Network.postEvent(&arduino_event); - } + } + + if (arduino_event.event_id < ARDUINO_EVENT_MAX) { + Network.postEvent(&arduino_event); + } } NetworkInterface::NetworkInterface() - : _esp_netif(NULL) - , _interface_event_group(NULL) - , _initial_bits(0) - , _got_ip_event_id(-1) - , _lost_ip_event_id(-1) - , _interface_id(ESP_NETIF_ID_MAX) -{} + : _esp_netif(NULL), _interface_event_group(NULL), _initial_bits(0), _got_ip_event_id(-1), _lost_ip_event_id(-1), _interface_id(ESP_NETIF_ID_MAX) {} -NetworkInterface::~NetworkInterface(){ - destroyNetif(); +NetworkInterface::~NetworkInterface() { + destroyNetif(); } IPAddress NetworkInterface::calculateNetworkID(IPAddress ip, IPAddress subnet) const { - IPAddress networkID; + IPAddress networkID; - for (size_t i = 0; i < 4; i++) - networkID[i] = subnet[i] & ip[i]; + for (size_t i = 0; i < 4; i++) + networkID[i] = subnet[i] & ip[i]; - return networkID; + return networkID; } IPAddress NetworkInterface::calculateBroadcast(IPAddress ip, IPAddress subnet) const { - IPAddress broadcastIp; - - for (int i = 0; i < 4; i++) - broadcastIp[i] = ~subnet[i] | ip[i]; + IPAddress broadcastIp; + + for (int i = 0; i < 4; i++) + broadcastIp[i] = ~subnet[i] | ip[i]; - return broadcastIp; + return broadcastIp; } uint8_t NetworkInterface::calculateSubnetCIDR(IPAddress subnetMask) const { - uint8_t CIDR = 0; - - for (uint8_t i = 0; i < 4; i++) { - if (subnetMask[i] == 0x80) // 128 - CIDR += 1; - else if (subnetMask[i] == 0xC0) // 192 - CIDR += 2; - else if (subnetMask[i] == 0xE0) // 224 - CIDR += 3; - else if (subnetMask[i] == 0xF0) // 242 - CIDR += 4; - else if (subnetMask[i] == 0xF8) // 248 - CIDR += 5; - else if (subnetMask[i] == 0xFC) // 252 - CIDR += 6; - else if (subnetMask[i] == 0xFE) // 254 - CIDR += 7; - else if (subnetMask[i] == 0xFF) // 255 - CIDR += 8; - } - - return CIDR; + uint8_t CIDR = 0; + + for (uint8_t i = 0; i < 4; i++) { + if (subnetMask[i] == 0x80) // 128 + CIDR += 1; + else if (subnetMask[i] == 0xC0) // 192 + CIDR += 2; + else if (subnetMask[i] == 0xE0) // 224 + CIDR += 3; + else if (subnetMask[i] == 0xF0) // 242 + CIDR += 4; + else if (subnetMask[i] == 0xF8) // 248 + CIDR += 5; + else if (subnetMask[i] == 0xFC) // 252 + CIDR += 6; + else if (subnetMask[i] == 0xFE) // 254 + CIDR += 7; + else if (subnetMask[i] == 0xFF) // 255 + CIDR += 8; + } + + return CIDR; } int NetworkInterface::setStatusBits(int bits) { - if(!_interface_event_group){ - _initial_bits |= bits; - return _initial_bits; - } - return xEventGroupSetBits(_interface_event_group, bits); + if (!_interface_event_group) { + _initial_bits |= bits; + return _initial_bits; + } + return xEventGroupSetBits(_interface_event_group, bits); } int NetworkInterface::clearStatusBits(int bits) { - if(!_interface_event_group){ - _initial_bits &= ~bits; - return _initial_bits; - } - return xEventGroupClearBits(_interface_event_group, bits) ; + if (!_interface_event_group) { + _initial_bits &= ~bits; + return _initial_bits; + } + return xEventGroupClearBits(_interface_event_group, bits); } int NetworkInterface::getStatusBits() const { - if(!_interface_event_group){ - return _initial_bits; - } - return xEventGroupGetBits(_interface_event_group); + if (!_interface_event_group) { + return _initial_bits; + } + return xEventGroupGetBits(_interface_event_group); } int NetworkInterface::waitStatusBits(int bits, uint32_t timeout_ms) const { - if(!_interface_event_group){ - return 0; - } - bits = xEventGroupWaitBits( - _interface_event_group, // The event group being tested. - bits, // The bits within the event group to wait for. - pdFALSE, // bits should be cleared before returning. - pdTRUE, // Don't wait for all bits, any bit will do. - timeout_ms / portTICK_PERIOD_MS ) & bits; // Wait a maximum of timeout_ms for any bit to be set. - return bits; + if (!_interface_event_group) { + return 0; + } + bits = xEventGroupWaitBits( + _interface_event_group, // The event group being tested. + bits, // The bits within the event group to wait for. + pdFALSE, // bits should be cleared before returning. + pdTRUE, // Don't wait for all bits, any bit will do. + timeout_ms / portTICK_PERIOD_MS) + & bits; // Wait a maximum of timeout_ms for any bit to be set. + return bits; } void NetworkInterface::destroyNetif() { - if(_ip_ev_instance != NULL){ - esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, &_ip_event_cb); - _ip_ev_instance = NULL; - } - if(_esp_netif != NULL){ - esp_netif_destroy(_esp_netif); - _esp_netif = NULL; - } - if(_interface_event_group != NULL){ - vEventGroupDelete(_interface_event_group); - _interface_event_group = NULL; - _initial_bits = 0; - } + if (_ip_ev_instance != NULL) { + esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, &_ip_event_cb); + _ip_ev_instance = NULL; + } + if (_esp_netif != NULL) { + esp_netif_destroy(_esp_netif); + _esp_netif = NULL; + } + if (_interface_event_group != NULL) { + vEventGroupDelete(_interface_event_group); + _interface_event_group = NULL; + _initial_bits = 0; + } } bool NetworkInterface::initNetif(Network_Interface_ID interface_id) { - if(_esp_netif == NULL || interface_id >= ESP_NETIF_ID_MAX){ - return false; - } - _interface_id = interface_id; - _got_ip_event_id = esp_netif_get_event_id(_esp_netif, ESP_NETIF_IP_EVENT_GOT_IP); - _lost_ip_event_id = esp_netif_get_event_id(_esp_netif, ESP_NETIF_IP_EVENT_LOST_IP); - _interfaces[_interface_id] = this; - - if(_interface_event_group == NULL){ - _interface_event_group = xEventGroupCreate(); - if(!_interface_event_group){ - log_e("Interface Event Group Create Failed!"); - return false; - } - setStatusBits(_initial_bits); - } - - if(_ip_ev_instance == NULL && esp_event_handler_instance_register(IP_EVENT, ESP_EVENT_ANY_ID, &_ip_event_cb, NULL, &_ip_ev_instance)){ - log_e("event_handler_instance_register for IP_EVENT Failed!"); - return false; - } - return true; + if (_esp_netif == NULL || interface_id >= ESP_NETIF_ID_MAX) { + return false; + } + _interface_id = interface_id; + _got_ip_event_id = esp_netif_get_event_id(_esp_netif, ESP_NETIF_IP_EVENT_GOT_IP); + _lost_ip_event_id = esp_netif_get_event_id(_esp_netif, ESP_NETIF_IP_EVENT_LOST_IP); + _interfaces[_interface_id] = this; + + if (_interface_event_group == NULL) { + _interface_event_group = xEventGroupCreate(); + if (!_interface_event_group) { + log_e("Interface Event Group Create Failed!"); + return false; + } + setStatusBits(_initial_bits); + } + + if (_ip_ev_instance == NULL && esp_event_handler_instance_register(IP_EVENT, ESP_EVENT_ANY_ID, &_ip_event_cb, NULL, &_ip_ev_instance)) { + log_e("event_handler_instance_register for IP_EVENT Failed!"); + return false; + } + return true; } bool NetworkInterface::started() const { - return (getStatusBits() & ESP_NETIF_STARTED_BIT) != 0; + return (getStatusBits() & ESP_NETIF_STARTED_BIT) != 0; } bool NetworkInterface::connected() const { - return (getStatusBits() & ESP_NETIF_CONNECTED_BIT) != 0; + return (getStatusBits() & ESP_NETIF_CONNECTED_BIT) != 0; } bool NetworkInterface::hasIP() const { - return (getStatusBits() & (ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_STATIC_IP_BIT)) != 0; + return (getStatusBits() & (ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_STATIC_IP_BIT)) != 0; } bool NetworkInterface::hasLinkLocalIPv6() const { - return (getStatusBits() & ESP_NETIF_HAS_LOCAL_IP6_BIT) != 0; + return (getStatusBits() & ESP_NETIF_HAS_LOCAL_IP6_BIT) != 0; } bool NetworkInterface::hasGlobalIPv6() const { - return (getStatusBits() & ESP_NETIF_HAS_GLOBAL_IP6_BIT) != 0; -} - -bool NetworkInterface::enableIPv6(bool en) -{ - if (en) { - setStatusBits(ESP_NETIF_WANT_IP6_BIT); - } else { - clearStatusBits(ESP_NETIF_WANT_IP6_BIT); - } - return true; -} - -bool NetworkInterface::dnsIP(uint8_t dns_no, IPAddress ip) -{ - if(_esp_netif == NULL || dns_no > 2){ - return false; - } - esp_netif_flags_t flags = esp_netif_get_flags(_esp_netif); - if(flags & ESP_NETIF_DHCP_SERVER && dns_no > 0){ - log_e("Server interfaces can have only one DNS server."); + return (getStatusBits() & ESP_NETIF_HAS_GLOBAL_IP6_BIT) != 0; +} + +bool NetworkInterface::enableIPv6(bool en) { + if (en) { + setStatusBits(ESP_NETIF_WANT_IP6_BIT); + } else { + clearStatusBits(ESP_NETIF_WANT_IP6_BIT); + } + return true; +} + +bool NetworkInterface::dnsIP(uint8_t dns_no, IPAddress ip) { + if (_esp_netif == NULL || dns_no > 2) { + return false; + } + esp_netif_flags_t flags = esp_netif_get_flags(_esp_netif); + if (flags & ESP_NETIF_DHCP_SERVER && dns_no > 0) { + log_e("Server interfaces can have only one DNS server."); + return false; + } + esp_netif_dns_info_t d; + // ToDo: can this work with IPv6 addresses? + d.ip.type = IPADDR_TYPE_V4; + if (static_cast(ip) != 0) { + d.ip.u_addr.ip4.addr = static_cast(ip); + } else { + d.ip.u_addr.ip4.addr = 0; + } + if (esp_netif_set_dns_info(_esp_netif, (esp_netif_dns_type_t)dns_no, &d) != ESP_OK) { + return false; + } + return true; +} + +bool NetworkInterface::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2, IPAddress dns3) { + if (_esp_netif == NULL) { + return false; + } + esp_err_t err = ESP_OK; + esp_netif_ip_info_t info; + esp_netif_dns_info_t d1; + esp_netif_dns_info_t d2; + esp_netif_dns_info_t d3; + d1.ip.type = IPADDR_TYPE_V4; + d2.ip.type = IPADDR_TYPE_V4; + d3.ip.type = IPADDR_TYPE_V4; + + if (static_cast(local_ip) != 0) { + info.ip.addr = static_cast(local_ip); + info.gw.addr = static_cast(gateway); + info.netmask.addr = static_cast(subnet); + d1.ip.u_addr.ip4.addr = static_cast(dns1); + d2.ip.u_addr.ip4.addr = static_cast(dns2); + d3.ip.u_addr.ip4.addr = static_cast(dns3); + } else { + info.ip.addr = 0; + info.gw.addr = 0; + info.netmask.addr = 0; + d1.ip.u_addr.ip4.addr = 0; + d2.ip.u_addr.ip4.addr = 0; + d3.ip.u_addr.ip4.addr = 0; + } + + esp_netif_flags_t flags = esp_netif_get_flags(_esp_netif); + if (flags & ESP_NETIF_DHCP_SERVER) { + + // Set DNS Server + if (d2.ip.u_addr.ip4.addr != 0) { + err = esp_netif_set_dns_info(_esp_netif, ESP_NETIF_DNS_MAIN, &d2); + if (err) { + log_e("Netif Set DNS Info Failed! 0x%04x: %s", err, esp_err_to_name(err)); return false; - } - esp_netif_dns_info_t d; - // ToDo: can this work with IPv6 addresses? - d.ip.type = IPADDR_TYPE_V4; - if(static_cast(ip) != 0){ - d.ip.u_addr.ip4.addr = static_cast(ip); - } else { - d.ip.u_addr.ip4.addr = 0; - } - if(esp_netif_set_dns_info(_esp_netif, (esp_netif_dns_type_t)dns_no, &d) != ESP_OK){ + } + } + + // Stop DHCPS + err = esp_netif_dhcps_stop(_esp_netif); + if (err && err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED) { + log_e("DHCPS Stop Failed! 0x%04x: %s", err, esp_err_to_name(err)); + return false; + } + + // Set IPv4, Netmask, Gateway + err = esp_netif_set_ip_info(_esp_netif, &info); + if (err) { + log_e("Netif Set IP Failed! 0x%04x: %s", err, esp_err_to_name(err)); + return false; + } + + dhcps_lease_t lease; + lease.enable = true; + uint8_t CIDR = calculateSubnetCIDR(subnet); + log_v("SoftAP: %s | Gateway: %s | DHCP Start: %s | Netmask: %s", local_ip.toString().c_str(), gateway.toString().c_str(), dns1.toString().c_str(), subnet.toString().c_str()); + // netmask must have room for at least 12 IP addresses (AP + GW + 10 DHCP Leasing addresses) + // netmask also must be limited to the last 8 bits of IPv4, otherwise this function won't work + // IDF NETIF checks netmask for the 3rd byte: https://github.com/espressif/esp-idf/blob/master/components/esp_netif/lwip/esp_netif_lwip.c#L1857-L1862 + if (CIDR > 28 || CIDR < 24) { + log_e("Bad netmask. It must be from /24 to /28 (255.255.255. 0<->240)"); + return false; // ESP_FAIL if initializing failed + } +#define _byte_swap32(num) (((num >> 24) & 0xff) | ((num << 8) & 0xff0000) | ((num >> 8) & 0xff00) | ((num << 24) & 0xff000000)) + // The code below is ready for any netmask, not limited to 255.255.255.0 + uint32_t netmask = _byte_swap32(info.netmask.addr); + uint32_t ap_ipaddr = _byte_swap32(info.ip.addr); + uint32_t dhcp_ipaddr = _byte_swap32(static_cast(dns1)); + dhcp_ipaddr = dhcp_ipaddr == 0 ? ap_ipaddr + 1 : dhcp_ipaddr; + uint32_t leaseStartMax = ~netmask - 10; + // there will be 10 addresses for DHCP to lease + lease.start_ip.addr = dhcp_ipaddr; + lease.end_ip.addr = lease.start_ip.addr + 10; + // Check if local_ip is in the same subnet as the dhcp leasing range initial address + if ((ap_ipaddr & netmask) != (dhcp_ipaddr & netmask)) { + log_e("The AP IP address (%s) and the DHCP start address (%s) must be in the same subnet", + local_ip.toString().c_str(), IPAddress(_byte_swap32(dhcp_ipaddr)).toString().c_str()); + return false; // ESP_FAIL if initializing failed + } + // prevents DHCP lease range to overflow subnet range + if ((dhcp_ipaddr & ~netmask) >= leaseStartMax) { + // make first DHCP lease addr stay in the beginning of the netmask range + lease.start_ip.addr = (dhcp_ipaddr & netmask) + 1; + lease.end_ip.addr = lease.start_ip.addr + 10; + log_w("DHCP Lease out of range - Changing DHCP leasing start to %s", IPAddress(_byte_swap32(lease.start_ip.addr)).toString().c_str()); + } + // Check if local_ip is within DHCP range + if (ap_ipaddr >= lease.start_ip.addr && ap_ipaddr <= lease.end_ip.addr) { + log_e("The AP IP address (%s) can't be within the DHCP range (%s -- %s)", + local_ip.toString().c_str(), IPAddress(_byte_swap32(lease.start_ip.addr)).toString().c_str(), IPAddress(_byte_swap32(lease.end_ip.addr)).toString().c_str()); + return false; // ESP_FAIL if initializing failed + } + // Check if gateway is within DHCP range + uint32_t gw_ipaddr = _byte_swap32(info.gw.addr); + bool gw_in_same_subnet = (gw_ipaddr & netmask) == (ap_ipaddr & netmask); + if (gw_in_same_subnet && gw_ipaddr >= lease.start_ip.addr && gw_ipaddr <= lease.end_ip.addr) { + log_e("The GatewayP address (%s) can't be within the DHCP range (%s -- %s)", + gateway.toString().c_str(), IPAddress(_byte_swap32(lease.start_ip.addr)).toString().c_str(), IPAddress(_byte_swap32(lease.end_ip.addr)).toString().c_str()); + return false; // ESP_FAIL if initializing failed + } + // all done, just revert back byte order of DHCP lease range + lease.start_ip.addr = _byte_swap32(lease.start_ip.addr); + lease.end_ip.addr = _byte_swap32(lease.end_ip.addr); + log_v("DHCP Server Range: %s to %s", IPAddress(lease.start_ip.addr).toString().c_str(), IPAddress(lease.end_ip.addr).toString().c_str()); + err = esp_netif_dhcps_option( + _esp_netif, + ESP_NETIF_OP_SET, + ESP_NETIF_REQUESTED_IP_ADDRESS, + (void*)&lease, sizeof(dhcps_lease_t)); + if (err) { + log_e("DHCPS Set Lease Failed! 0x%04x: %s", err, esp_err_to_name(err)); + return false; + } + + // Offer DNS to DHCP clients + if (d2.ip.u_addr.ip4.addr != 0) { + dhcps_offer_t dhcps_dns_value = OFFER_DNS; + err = esp_netif_dhcps_option(_esp_netif, ESP_NETIF_OP_SET, ESP_NETIF_DOMAIN_NAME_SERVER, &dhcps_dns_value, sizeof(dhcps_dns_value)); + if (err) { + log_e("Netif Set DHCP Option Failed! 0x%04x: %s", err, esp_err_to_name(err)); return false; + } } - return true; -} -bool NetworkInterface::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2, IPAddress dns3) -{ - if(_esp_netif == NULL){ - return false; + // Start DHCPS + err = esp_netif_dhcps_start(_esp_netif); + if (err) { + log_e("DHCPS Start Failed! 0x%04x: %s", err, esp_err_to_name(err)); + return false; } - esp_err_t err = ESP_OK; - esp_netif_ip_info_t info; - esp_netif_dns_info_t d1; - esp_netif_dns_info_t d2; - esp_netif_dns_info_t d3; - d1.ip.type = IPADDR_TYPE_V4; - d2.ip.type = IPADDR_TYPE_V4; - d3.ip.type = IPADDR_TYPE_V4; - - if(static_cast(local_ip) != 0){ - info.ip.addr = static_cast(local_ip); - info.gw.addr = static_cast(gateway); - info.netmask.addr = static_cast(subnet); - d1.ip.u_addr.ip4.addr = static_cast(dns1); - d2.ip.u_addr.ip4.addr = static_cast(dns2); - d3.ip.u_addr.ip4.addr = static_cast(dns3); - } else { - info.ip.addr = 0; - info.gw.addr = 0; - info.netmask.addr = 0; - d1.ip.u_addr.ip4.addr = 0; - d2.ip.u_addr.ip4.addr = 0; - d3.ip.u_addr.ip4.addr = 0; - } - - esp_netif_flags_t flags = esp_netif_get_flags(_esp_netif); - if(flags & ESP_NETIF_DHCP_SERVER){ - - // Set DNS Server - if(d2.ip.u_addr.ip4.addr != 0){ - err = esp_netif_set_dns_info(_esp_netif, ESP_NETIF_DNS_MAIN, &d2); - if(err){ - log_e("Netif Set DNS Info Failed! 0x%04x: %s", err, esp_err_to_name(err)); - return false; - } - } - - // Stop DHCPS - err = esp_netif_dhcps_stop(_esp_netif); - if(err && err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED){ - log_e("DHCPS Stop Failed! 0x%04x: %s", err, esp_err_to_name(err)); - return false; - } - - // Set IPv4, Netmask, Gateway - err = esp_netif_set_ip_info(_esp_netif, &info); - if(err){ - log_e("Netif Set IP Failed! 0x%04x: %s", err, esp_err_to_name(err)); - return false; - } - - dhcps_lease_t lease; - lease.enable = true; - uint8_t CIDR = calculateSubnetCIDR(subnet); - log_v("SoftAP: %s | Gateway: %s | DHCP Start: %s | Netmask: %s", local_ip.toString().c_str(), gateway.toString().c_str(), dns1.toString().c_str(), subnet.toString().c_str()); - // netmask must have room for at least 12 IP addresses (AP + GW + 10 DHCP Leasing addresses) - // netmask also must be limited to the last 8 bits of IPv4, otherwise this function won't work - // IDF NETIF checks netmask for the 3rd byte: https://github.com/espressif/esp-idf/blob/master/components/esp_netif/lwip/esp_netif_lwip.c#L1857-L1862 - if (CIDR > 28 || CIDR < 24) { - log_e("Bad netmask. It must be from /24 to /28 (255.255.255. 0<->240)"); - return false; // ESP_FAIL if initializing failed - } - #define _byte_swap32(num) (((num>>24)&0xff) | ((num<<8)&0xff0000) | ((num>>8)&0xff00) | ((num<<24)&0xff000000)) - // The code below is ready for any netmask, not limited to 255.255.255.0 - uint32_t netmask = _byte_swap32(info.netmask.addr); - uint32_t ap_ipaddr = _byte_swap32(info.ip.addr); - uint32_t dhcp_ipaddr = _byte_swap32(static_cast(dns1)); - dhcp_ipaddr = dhcp_ipaddr == 0 ? ap_ipaddr + 1 : dhcp_ipaddr; - uint32_t leaseStartMax = ~netmask - 10; - // there will be 10 addresses for DHCP to lease - lease.start_ip.addr = dhcp_ipaddr; - lease.end_ip.addr = lease.start_ip.addr + 10; - // Check if local_ip is in the same subnet as the dhcp leasing range initial address - if ((ap_ipaddr & netmask) != (dhcp_ipaddr & netmask)) { - log_e("The AP IP address (%s) and the DHCP start address (%s) must be in the same subnet", - local_ip.toString().c_str(), IPAddress(_byte_swap32(dhcp_ipaddr)).toString().c_str()); - return false; // ESP_FAIL if initializing failed - } - // prevents DHCP lease range to overflow subnet range - if ((dhcp_ipaddr & ~netmask) >= leaseStartMax) { - // make first DHCP lease addr stay in the begining of the netmask range - lease.start_ip.addr = (dhcp_ipaddr & netmask) + 1; - lease.end_ip.addr = lease.start_ip.addr + 10; - log_w("DHCP Lease out of range - Changing DHCP leasing start to %s", IPAddress(_byte_swap32(lease.start_ip.addr)).toString().c_str()); - } - // Check if local_ip is within DHCP range - if (ap_ipaddr >= lease.start_ip.addr && ap_ipaddr <= lease.end_ip.addr) { - log_e("The AP IP address (%s) can't be within the DHCP range (%s -- %s)", - local_ip.toString().c_str(), IPAddress(_byte_swap32(lease.start_ip.addr)).toString().c_str(), IPAddress(_byte_swap32(lease.end_ip.addr)).toString().c_str()); - return false; // ESP_FAIL if initializing failed - } - // Check if gateway is within DHCP range - uint32_t gw_ipaddr = _byte_swap32(info.gw.addr); - bool gw_in_same_subnet = (gw_ipaddr & netmask) == (ap_ipaddr & netmask); - if (gw_in_same_subnet && gw_ipaddr >= lease.start_ip.addr && gw_ipaddr <= lease.end_ip.addr) { - log_e("The GatewayP address (%s) can't be within the DHCP range (%s -- %s)", - gateway.toString().c_str(), IPAddress(_byte_swap32(lease.start_ip.addr)).toString().c_str(), IPAddress(_byte_swap32(lease.end_ip.addr)).toString().c_str()); - return false; // ESP_FAIL if initializing failed - } - // all done, just revert back byte order of DHCP lease range - lease.start_ip.addr = _byte_swap32(lease.start_ip.addr); - lease.end_ip.addr = _byte_swap32(lease.end_ip.addr); - log_v("DHCP Server Range: %s to %s", IPAddress(lease.start_ip.addr).toString().c_str(), IPAddress(lease.end_ip.addr).toString().c_str()); - err = esp_netif_dhcps_option( - _esp_netif, - ESP_NETIF_OP_SET, - ESP_NETIF_REQUESTED_IP_ADDRESS, - (void*)&lease, sizeof(dhcps_lease_t) - ); - if(err){ - log_e("DHCPS Set Lease Failed! 0x%04x: %s", err, esp_err_to_name(err)); - return false; - } - - // Offer DNS to DHCP clients - if(d2.ip.u_addr.ip4.addr != 0){ - dhcps_offer_t dhcps_dns_value = OFFER_DNS; - err = esp_netif_dhcps_option(_esp_netif, ESP_NETIF_OP_SET, ESP_NETIF_DOMAIN_NAME_SERVER, &dhcps_dns_value, sizeof(dhcps_dns_value)); - if(err){ - log_e("Netif Set DHCP Option Failed! 0x%04x: %s", err, esp_err_to_name(err)); - return false; - } - } - - // Start DHCPS - err = esp_netif_dhcps_start(_esp_netif); - if(err){ - log_e("DHCPS Start Failed! 0x%04x: %s", err, esp_err_to_name(err)); - return false; - } - } else { - // Stop DHCPC - err = esp_netif_dhcpc_stop(_esp_netif); - if(err != ESP_OK && err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED){ - log_e("DHCP could not be stopped! Error: 0x%04x: %s", err, esp_err_to_name(err)); - return false; - } - - clearStatusBits(ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_STATIC_IP_BIT); - - // Set IPv4, Netmask, Gateway - err = esp_netif_set_ip_info(_esp_netif, &info); - if(err != ERR_OK){ - log_e("ETH IP could not be configured! Error: 0x%04x: %s", err, esp_err_to_name(err)); - return false; - } - - // Set DNS Servers - esp_netif_set_dns_info(_esp_netif, ESP_NETIF_DNS_MAIN, &d1); - esp_netif_set_dns_info(_esp_netif, ESP_NETIF_DNS_BACKUP, &d2); - esp_netif_set_dns_info(_esp_netif, ESP_NETIF_DNS_FALLBACK, &d3); - - // Start DHCPC if static IP was set - if(info.ip.addr == 0){ - err = esp_netif_dhcpc_start(_esp_netif); - if(err != ESP_OK && err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED){ - log_w("DHCP could not be started! Error: 0x%04x: %s", err, esp_err_to_name(err)); - return false; - } - } else { - setStatusBits(ESP_NETIF_HAS_STATIC_IP_BIT); - } + } else { + // Stop DHCPC + err = esp_netif_dhcpc_stop(_esp_netif); + if (err != ESP_OK && err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED) { + log_e("DHCP could not be stopped! Error: 0x%04x: %s", err, esp_err_to_name(err)); + return false; } - return true; -} + clearStatusBits(ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_STATIC_IP_BIT); -const char * NetworkInterface::getHostname() const -{ - if(_esp_netif == NULL){ - return ""; + // Set IPv4, Netmask, Gateway + err = esp_netif_set_ip_info(_esp_netif, &info); + if (err != ERR_OK) { + log_e("ETH IP could not be configured! Error: 0x%04x: %s", err, esp_err_to_name(err)); + return false; } - const char * hostname; - if(esp_netif_get_hostname(_esp_netif, &hostname)){ - return NULL; - } - return hostname; -} -bool NetworkInterface::setHostname(const char * hostname) const -{ - if(_esp_netif == NULL){ - return false; - } - return esp_netif_set_hostname(_esp_netif, hostname) == 0; -} + // Set DNS Servers + esp_netif_set_dns_info(_esp_netif, ESP_NETIF_DNS_MAIN, &d1); + esp_netif_set_dns_info(_esp_netif, ESP_NETIF_DNS_BACKUP, &d2); + esp_netif_set_dns_info(_esp_netif, ESP_NETIF_DNS_FALLBACK, &d3); -bool NetworkInterface::linkUp() const -{ - if(_esp_netif == NULL){ + // Start DHCPC if static IP was set + if (info.ip.addr == 0) { + err = esp_netif_dhcpc_start(_esp_netif); + if (err != ESP_OK && err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED) { + log_w("DHCP could not be started! Error: 0x%04x: %s", err, esp_err_to_name(err)); return false; + } + } else { + setStatusBits(ESP_NETIF_HAS_STATIC_IP_BIT); } - return esp_netif_is_netif_up(_esp_netif); -} - -const char * NetworkInterface::ifkey(void) const -{ - if(_esp_netif == NULL){ - return ""; - } - return esp_netif_get_ifkey(_esp_netif); -} - -const char * NetworkInterface::desc(void) const -{ - if(_esp_netif == NULL){ - return ""; - } - return esp_netif_get_desc(_esp_netif); -} - -String NetworkInterface::impl_name(void) const -{ - if(_esp_netif == NULL){ - return String(""); - } - char netif_name[8]; - esp_err_t err = esp_netif_get_netif_impl_name(_esp_netif, netif_name); - if(err != ESP_OK){ - log_e("Failed to get netif impl_name: %d", err); - return String(""); - } - return String(netif_name); -} - -int NetworkInterface::impl_index() const -{ - if(_esp_netif == NULL){ - return -1; - } - return esp_netif_get_netif_impl_index(_esp_netif); -} + } -int NetworkInterface::route_prio() const -{ - if(_esp_netif == NULL){ - return -1; - } - return esp_netif_get_route_prio(_esp_netif); + return true; } -bool NetworkInterface::setDefault() -{ - if(_esp_netif == NULL){ - return false; - } - esp_err_t err = esp_netif_set_default_netif(_esp_netif); - if(err != ESP_OK){ - log_e("Failed to set default netif: %d", err); - return false; - } - return true; +const char* NetworkInterface::getHostname() const { + if (_esp_netif == NULL) { + return ""; + } + const char* hostname; + if (esp_netif_get_hostname(_esp_netif, &hostname)) { + return NULL; + } + return hostname; } -bool NetworkInterface::isDefault() const -{ - if(_esp_netif == NULL){ - return false; - } - return esp_netif_get_default_netif() == _esp_netif; +bool NetworkInterface::setHostname(const char* hostname) const { + if (_esp_netif == NULL) { + return false; + } + return esp_netif_set_hostname(_esp_netif, hostname) == 0; } -uint8_t * NetworkInterface::macAddress(uint8_t* mac) const -{ - if(!mac || _esp_netif == NULL){ - return NULL; - } - esp_err_t err = esp_netif_get_mac(_esp_netif, mac); - if(err != ESP_OK){ - log_e("Failed to get netif mac: %d", err); - return NULL; - } - // getMac(mac); - return mac; +bool NetworkInterface::linkUp() const { + if (_esp_netif == NULL) { + return false; + } + return esp_netif_is_netif_up(_esp_netif); } -String NetworkInterface::macAddress(void) const -{ - uint8_t mac[6] = {0,0,0,0,0,0}; - char macStr[18] = { 0 }; - macAddress(mac); - sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - return String(macStr); +const char* NetworkInterface::ifkey(void) const { + if (_esp_netif == NULL) { + return ""; + } + return esp_netif_get_ifkey(_esp_netif); } -IPAddress NetworkInterface::localIP() const -{ - if(_esp_netif == NULL){ - return IPAddress(); - } - esp_netif_ip_info_t ip; - if(esp_netif_get_ip_info(_esp_netif, &ip)){ - return IPAddress(); - } - return IPAddress(ip.ip.addr); +const char* NetworkInterface::desc(void) const { + if (_esp_netif == NULL) { + return ""; + } + return esp_netif_get_desc(_esp_netif); } -IPAddress NetworkInterface::subnetMask() const -{ - if(_esp_netif == NULL){ - return IPAddress(); - } - esp_netif_ip_info_t ip; - if(esp_netif_get_ip_info(_esp_netif, &ip)){ - return IPAddress(); - } - return IPAddress(ip.netmask.addr); +String NetworkInterface::impl_name(void) const { + if (_esp_netif == NULL) { + return String(""); + } + char netif_name[8]; + esp_err_t err = esp_netif_get_netif_impl_name(_esp_netif, netif_name); + if (err != ESP_OK) { + log_e("Failed to get netif impl_name: %d", err); + return String(""); + } + return String(netif_name); } -IPAddress NetworkInterface::gatewayIP() const -{ - if(_esp_netif == NULL){ - return IPAddress(); - } - esp_netif_ip_info_t ip; - if(esp_netif_get_ip_info(_esp_netif, &ip)){ - return IPAddress(); - } - return IPAddress(ip.gw.addr); +int NetworkInterface::impl_index() const { + if (_esp_netif == NULL) { + return -1; + } + return esp_netif_get_netif_impl_index(_esp_netif); } -IPAddress NetworkInterface::dnsIP(uint8_t dns_no) const -{ - if(_esp_netif == NULL){ - return IPAddress(); - } - esp_netif_dns_info_t d; - if(esp_netif_get_dns_info(_esp_netif, dns_no?ESP_NETIF_DNS_BACKUP:ESP_NETIF_DNS_MAIN, &d) != ESP_OK){ - return IPAddress(); - } - if (d.ip.type == ESP_IPADDR_TYPE_V6){ - // IPv6 from 4x uint32_t; byte order based on IPV62STR() in esp_netif_ip_addr.h - // log_v("DNS got IPv6: " IPV6STR, IPV62STR(d.ip.u_addr.ip6)); - uint32_t addr0 esp_netif_htonl(d.ip.u_addr.ip6.addr[0]); - uint32_t addr1 esp_netif_htonl(d.ip.u_addr.ip6.addr[1]); - uint32_t addr2 esp_netif_htonl(d.ip.u_addr.ip6.addr[2]); - uint32_t addr3 esp_netif_htonl(d.ip.u_addr.ip6.addr[3]); - return IPAddress( - (uint8_t)(addr0 >> 24) & 0xFF, - (uint8_t)(addr0 >> 16) & 0xFF, - (uint8_t)(addr0 >> 8) & 0xFF, - (uint8_t)addr0 & 0xFF, - (uint8_t)(addr1 >> 24) & 0xFF, - (uint8_t)(addr1 >> 16) & 0xFF, - (uint8_t)(addr1 >> 8) & 0xFF, - (uint8_t)addr1 & 0xFF, - (uint8_t)(addr2 >> 24) & 0xFF, - (uint8_t)(addr2 >> 16) & 0xFF, - (uint8_t)(addr2 >> 8) & 0xFF, - (uint8_t)addr2 & 0xFF, - (uint8_t)(addr3 >> 24) & 0xFF, - (uint8_t)(addr3 >> 16) & 0xFF, - (uint8_t)(addr3 >> 8) & 0xFF, - (uint8_t)addr3 & 0xFF, - d.ip.u_addr.ip6.zone - ); - } - // IPv4 from single uint32_t - // log_v("DNS IPv4: " IPSTR, IP2STR(&d.ip.u_addr.ip4)); - return IPAddress(d.ip.u_addr.ip4.addr); +int NetworkInterface::route_prio() const { + if (_esp_netif == NULL) { + return -1; + } + return esp_netif_get_route_prio(_esp_netif); } -IPAddress NetworkInterface::broadcastIP() const -{ - if(_esp_netif == NULL){ - return IPAddress(); - } - esp_netif_ip_info_t ip; - if(esp_netif_get_ip_info(_esp_netif, &ip)){ - return IPAddress(); - } - return calculateBroadcast(IPAddress(ip.gw.addr), IPAddress(ip.netmask.addr)); +bool NetworkInterface::setDefault() { + if (_esp_netif == NULL) { + return false; + } + esp_err_t err = esp_netif_set_default_netif(_esp_netif); + if (err != ESP_OK) { + log_e("Failed to set default netif: %d", err); + return false; + } + return true; } -IPAddress NetworkInterface::networkID() const -{ - if(_esp_netif == NULL){ - return IPAddress(); - } - esp_netif_ip_info_t ip; - if(esp_netif_get_ip_info(_esp_netif, &ip)){ - return IPAddress(); - } - return calculateNetworkID(IPAddress(ip.gw.addr), IPAddress(ip.netmask.addr)); +bool NetworkInterface::isDefault() const { + if (_esp_netif == NULL) { + return false; + } + return esp_netif_get_default_netif() == _esp_netif; } -uint8_t NetworkInterface::subnetCIDR() const -{ - if(_esp_netif == NULL){ - return (uint8_t)0; - } - esp_netif_ip_info_t ip; - if(esp_netif_get_ip_info(_esp_netif, &ip)){ - return (uint8_t)0; - } - return calculateSubnetCIDR(IPAddress(ip.netmask.addr)); -} - -IPAddress NetworkInterface::linkLocalIPv6() const -{ - if(_esp_netif == NULL){ - return IPAddress(IPv6); - } - static esp_ip6_addr_t addr; - if(esp_netif_get_ip6_linklocal(_esp_netif, &addr)){ - return IPAddress(IPv6); - } - return IPAddress(IPv6, (const uint8_t *)addr.addr, addr.zone); -} - -IPAddress NetworkInterface::globalIPv6() const -{ - if(_esp_netif == NULL){ - return IPAddress(IPv6); - } - static esp_ip6_addr_t addr; - if(esp_netif_get_ip6_global(_esp_netif, &addr)){ - return IPAddress(IPv6); - } - return IPAddress(IPv6, (const uint8_t *)addr.addr, addr.zone); -} - -size_t NetworkInterface::printTo(Print & out) const { - size_t bytes = 0; - if(_esp_netif == NULL){ - return bytes; - } - if(isDefault()){ - bytes += out.print("*"); - } - const char * dscr = esp_netif_get_desc(_esp_netif); - if(dscr != NULL){ - bytes += out.print(dscr); - } - bytes += out.print(":"); - if(esp_netif_is_netif_up(_esp_netif)){ - bytes += out.print(" "); - - bytes += out.print(" ("); - esp_netif_flags_t flags = esp_netif_get_flags(_esp_netif); - if(flags & ESP_NETIF_DHCP_CLIENT){ - bytes += out.print("DHCPC"); - if(getStatusBits() & ESP_NETIF_HAS_STATIC_IP_BIT){ - bytes += out.print("_OFF"); - } - } - if(flags & ESP_NETIF_DHCP_SERVER) bytes += out.print("DHCPS"); - if(flags & ESP_NETIF_FLAG_AUTOUP) bytes += out.print(",AUTOUP"); - if(flags & ESP_NETIF_FLAG_GARP) bytes += out.print(",GARP"); - if(flags & ESP_NETIF_FLAG_EVENT_IP_MODIFIED) bytes += out.print(",IP_MOD"); - if(flags & ESP_NETIF_FLAG_IS_PPP) bytes += out.print(",PPP"); - if(flags & ESP_NETIF_FLAG_IS_BRIDGE) bytes += out.print(",BRIDGE"); - if(flags & ESP_NETIF_FLAG_MLDV6_REPORT) bytes += out.print(",V6_REP"); - bytes += out.println(")"); - - bytes += out.print(" "); - bytes += out.print("ether "); - bytes += out.print(macAddress()); - bytes += out.println(); - - bytes += out.print(" "); - bytes += out.print("inet "); - bytes += out.print(localIP()); - bytes += out.print(" netmask "); - bytes += out.print(subnetMask()); - bytes += out.print(" broadcast "); - bytes += out.print(broadcastIP()); - bytes += out.println(); - +uint8_t* NetworkInterface::macAddress(uint8_t* mac) const { + if (!mac || _esp_netif == NULL) { + return NULL; + } + esp_err_t err = esp_netif_get_mac(_esp_netif, mac); + if (err != ESP_OK) { + log_e("Failed to get netif mac: %d", err); + return NULL; + } + // getMac(mac); + return mac; +} + +String NetworkInterface::macAddress(void) const { + uint8_t mac[6] = { 0, 0, 0, 0, 0, 0 }; + char macStr[18] = { 0 }; + macAddress(mac); + sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + return String(macStr); +} + +IPAddress NetworkInterface::localIP() const { + if (_esp_netif == NULL) { + return IPAddress(); + } + esp_netif_ip_info_t ip; + if (esp_netif_get_ip_info(_esp_netif, &ip)) { + return IPAddress(); + } + return IPAddress(ip.ip.addr); +} + +IPAddress NetworkInterface::subnetMask() const { + if (_esp_netif == NULL) { + return IPAddress(); + } + esp_netif_ip_info_t ip; + if (esp_netif_get_ip_info(_esp_netif, &ip)) { + return IPAddress(); + } + return IPAddress(ip.netmask.addr); +} + +IPAddress NetworkInterface::gatewayIP() const { + if (_esp_netif == NULL) { + return IPAddress(); + } + esp_netif_ip_info_t ip; + if (esp_netif_get_ip_info(_esp_netif, &ip)) { + return IPAddress(); + } + return IPAddress(ip.gw.addr); +} + +IPAddress NetworkInterface::dnsIP(uint8_t dns_no) const { + if (_esp_netif == NULL) { + return IPAddress(); + } + esp_netif_dns_info_t d; + if (esp_netif_get_dns_info(_esp_netif, dns_no ? ESP_NETIF_DNS_BACKUP : ESP_NETIF_DNS_MAIN, &d) != ESP_OK) { + return IPAddress(); + } + if (d.ip.type == ESP_IPADDR_TYPE_V6) { + // IPv6 from 4x uint32_t; byte order based on IPV62STR() in esp_netif_ip_addr.h + // log_v("DNS got IPv6: " IPV6STR, IPV62STR(d.ip.u_addr.ip6)); + uint32_t addr0 esp_netif_htonl(d.ip.u_addr.ip6.addr[0]); + uint32_t addr1 esp_netif_htonl(d.ip.u_addr.ip6.addr[1]); + uint32_t addr2 esp_netif_htonl(d.ip.u_addr.ip6.addr[2]); + uint32_t addr3 esp_netif_htonl(d.ip.u_addr.ip6.addr[3]); + return IPAddress( + (uint8_t)(addr0 >> 24) & 0xFF, + (uint8_t)(addr0 >> 16) & 0xFF, + (uint8_t)(addr0 >> 8) & 0xFF, + (uint8_t)addr0 & 0xFF, + (uint8_t)(addr1 >> 24) & 0xFF, + (uint8_t)(addr1 >> 16) & 0xFF, + (uint8_t)(addr1 >> 8) & 0xFF, + (uint8_t)addr1 & 0xFF, + (uint8_t)(addr2 >> 24) & 0xFF, + (uint8_t)(addr2 >> 16) & 0xFF, + (uint8_t)(addr2 >> 8) & 0xFF, + (uint8_t)addr2 & 0xFF, + (uint8_t)(addr3 >> 24) & 0xFF, + (uint8_t)(addr3 >> 16) & 0xFF, + (uint8_t)(addr3 >> 8) & 0xFF, + (uint8_t)addr3 & 0xFF, + d.ip.u_addr.ip6.zone); + } + // IPv4 from single uint32_t + // log_v("DNS IPv4: " IPSTR, IP2STR(&d.ip.u_addr.ip4)); + return IPAddress(d.ip.u_addr.ip4.addr); +} + +IPAddress NetworkInterface::broadcastIP() const { + if (_esp_netif == NULL) { + return IPAddress(); + } + esp_netif_ip_info_t ip; + if (esp_netif_get_ip_info(_esp_netif, &ip)) { + return IPAddress(); + } + return calculateBroadcast(IPAddress(ip.gw.addr), IPAddress(ip.netmask.addr)); +} + +IPAddress NetworkInterface::networkID() const { + if (_esp_netif == NULL) { + return IPAddress(); + } + esp_netif_ip_info_t ip; + if (esp_netif_get_ip_info(_esp_netif, &ip)) { + return IPAddress(); + } + return calculateNetworkID(IPAddress(ip.gw.addr), IPAddress(ip.netmask.addr)); +} + +uint8_t NetworkInterface::subnetCIDR() const { + if (_esp_netif == NULL) { + return (uint8_t)0; + } + esp_netif_ip_info_t ip; + if (esp_netif_get_ip_info(_esp_netif, &ip)) { + return (uint8_t)0; + } + return calculateSubnetCIDR(IPAddress(ip.netmask.addr)); +} + +IPAddress NetworkInterface::linkLocalIPv6() const { + if (_esp_netif == NULL) { + return IPAddress(IPv6); + } + static esp_ip6_addr_t addr; + if (esp_netif_get_ip6_linklocal(_esp_netif, &addr)) { + return IPAddress(IPv6); + } + return IPAddress(IPv6, (const uint8_t*)addr.addr, addr.zone); +} + +IPAddress NetworkInterface::globalIPv6() const { + if (_esp_netif == NULL) { + return IPAddress(IPv6); + } + static esp_ip6_addr_t addr; + if (esp_netif_get_ip6_global(_esp_netif, &addr)) { + return IPAddress(IPv6); + } + return IPAddress(IPv6, (const uint8_t*)addr.addr, addr.zone); +} + +size_t NetworkInterface::printTo(Print& out) const { + size_t bytes = 0; + if (_esp_netif == NULL) { + return bytes; + } + if (isDefault()) { + bytes += out.print("*"); + } + const char* dscr = esp_netif_get_desc(_esp_netif); + if (dscr != NULL) { + bytes += out.print(dscr); + } + bytes += out.print(":"); + if (esp_netif_is_netif_up(_esp_netif)) { + bytes += out.print(" "); + + bytes += out.print(" ("); + esp_netif_flags_t flags = esp_netif_get_flags(_esp_netif); + if (flags & ESP_NETIF_DHCP_CLIENT) { + bytes += out.print("DHCPC"); + if (getStatusBits() & ESP_NETIF_HAS_STATIC_IP_BIT) { + bytes += out.print("_OFF"); + } + } + if (flags & ESP_NETIF_DHCP_SERVER) bytes += out.print("DHCPS"); + if (flags & ESP_NETIF_FLAG_AUTOUP) bytes += out.print(",AUTOUP"); + if (flags & ESP_NETIF_FLAG_GARP) bytes += out.print(",GARP"); + if (flags & ESP_NETIF_FLAG_EVENT_IP_MODIFIED) bytes += out.print(",IP_MOD"); + if (flags & ESP_NETIF_FLAG_IS_PPP) bytes += out.print(",PPP"); + if (flags & ESP_NETIF_FLAG_IS_BRIDGE) bytes += out.print(",BRIDGE"); + if (flags & ESP_NETIF_FLAG_MLDV6_REPORT) bytes += out.print(",V6_REP"); + bytes += out.println(")"); + + bytes += out.print(" "); + bytes += out.print("ether "); + bytes += out.print(macAddress()); + bytes += out.println(); + + bytes += out.print(" "); + bytes += out.print("inet "); + bytes += out.print(localIP()); + bytes += out.print(" netmask "); + bytes += out.print(subnetMask()); + bytes += out.print(" broadcast "); + bytes += out.print(broadcastIP()); + bytes += out.println(); + + bytes += out.print(" "); + bytes += out.print("gateway "); + bytes += out.print(gatewayIP()); + bytes += out.print(" dns "); + bytes += out.print(dnsIP()); + bytes += out.println(); + + static const char* types[] = { "UNKNOWN", "GLOBAL", "LINK_LOCAL", "SITE_LOCAL", "UNIQUE_LOCAL", "IPV4_MAPPED_IPV6" }; + esp_ip6_addr_t if_ip6[CONFIG_LWIP_IPV6_NUM_ADDRESSES]; + int v6addrs = esp_netif_get_all_ip6(_esp_netif, if_ip6); + for (int i = 0; i < v6addrs; ++i) { bytes += out.print(" "); - bytes += out.print("gateway "); - bytes += out.print(gatewayIP()); - bytes += out.print(" dns "); - bytes += out.print(dnsIP()); + bytes += out.print("inet6 "); + bytes += IPAddress(IPv6, (const uint8_t*)if_ip6[i].addr, if_ip6[i].zone).printTo(out, true); + bytes += out.print(" type "); + bytes += out.print(types[esp_netif_ip6_get_addr_type(&if_ip6[i])]); bytes += out.println(); + } - static const char * types[] = { "UNKNOWN", "GLOBAL", "LINK_LOCAL", "SITE_LOCAL", "UNIQUE_LOCAL", "IPV4_MAPPED_IPV6" }; - esp_ip6_addr_t if_ip6[CONFIG_LWIP_IPV6_NUM_ADDRESSES]; - int v6addrs = esp_netif_get_all_ip6(_esp_netif, if_ip6); - for (int i = 0; i < v6addrs; ++i){ - bytes += out.print(" "); - bytes += out.print("inet6 "); - bytes += IPAddress(IPv6, (const uint8_t *)if_ip6[i].addr, if_ip6[i].zone).printTo(out, true); - bytes += out.print(" type "); - bytes += out.print(types[esp_netif_ip6_get_addr_type(&if_ip6[i])]); - bytes += out.println(); - } - - return bytes; + return bytes; } diff --git a/libraries/Network/src/NetworkInterface.h b/libraries/Network/src/NetworkInterface.h index 64e606b0849..fe08cb24ece 100644 --- a/libraries/Network/src/NetworkInterface.h +++ b/libraries/Network/src/NetworkInterface.h @@ -11,92 +11,94 @@ #include "Printable.h" typedef enum { - ESP_NETIF_ID_STA, - ESP_NETIF_ID_AP, - ESP_NETIF_ID_PPP, - ESP_NETIF_ID_ETH0, - ESP_NETIF_ID_ETH1, - ESP_NETIF_ID_ETH2, - ESP_NETIF_ID_MAX + ESP_NETIF_ID_STA, + ESP_NETIF_ID_AP, + ESP_NETIF_ID_PPP, + ESP_NETIF_ID_ETH0, + ESP_NETIF_ID_ETH1, + ESP_NETIF_ID_ETH2, + ESP_NETIF_ID_MAX } Network_Interface_ID; -static const int ESP_NETIF_STARTED_BIT = BIT0; -static const int ESP_NETIF_CONNECTED_BIT = BIT1; -static const int ESP_NETIF_HAS_IP_BIT = BIT2; -static const int ESP_NETIF_HAS_LOCAL_IP6_BIT = BIT3; -static const int ESP_NETIF_HAS_GLOBAL_IP6_BIT = BIT4; -static const int ESP_NETIF_WANT_IP6_BIT = BIT5; -static const int ESP_NETIF_HAS_STATIC_IP_BIT = BIT6; +static const int ESP_NETIF_STARTED_BIT = BIT0; +static const int ESP_NETIF_CONNECTED_BIT = BIT1; +static const int ESP_NETIF_HAS_IP_BIT = BIT2; +static const int ESP_NETIF_HAS_LOCAL_IP6_BIT = BIT3; +static const int ESP_NETIF_HAS_GLOBAL_IP6_BIT = BIT4; +static const int ESP_NETIF_WANT_IP6_BIT = BIT5; +static const int ESP_NETIF_HAS_STATIC_IP_BIT = BIT6; #define ESP_NETIF_ID_ETH ESP_NETIF_ID_ETH0 -class NetworkInterface: public Printable { - public: - NetworkInterface(); - virtual ~NetworkInterface(); - - // For server interfaces (WiFi AP), dns1 is the DHCP lease range start and dns2 is the DNS. dns3 is not used - bool config(IPAddress local_ip = (uint32_t)0x00000000, IPAddress gateway = (uint32_t)0x00000000, IPAddress subnet = (uint32_t)0x00000000, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000, IPAddress dns3 = (uint32_t)0x00000000); - bool dnsIP(uint8_t dns_no, IPAddress ip); - - const char * getHostname() const; - bool setHostname(const char * hostname) const; - - bool started() const; - bool connected() const; - bool hasIP() const; - bool hasLinkLocalIPv6() const; - bool hasGlobalIPv6() const; - bool enableIPv6(bool en=true); - - bool linkUp() const; - const char * ifkey() const; - const char * desc() const; - String impl_name() const; - int impl_index() const; - int route_prio() const; - bool setDefault(); - bool isDefault() const; - - uint8_t * macAddress(uint8_t* mac) const; - String macAddress() const; - IPAddress localIP() const; - IPAddress subnetMask() const; - IPAddress gatewayIP() const; - IPAddress dnsIP(uint8_t dns_no = 0) const; - IPAddress broadcastIP() const; - IPAddress networkID() const; - uint8_t subnetCIDR() const; - IPAddress linkLocalIPv6() const; - IPAddress globalIPv6() const; - - size_t printTo(Print & out) const; - - esp_netif_t * netif(){ return _esp_netif; } - int getStatusBits() const; - int waitStatusBits(int bits, uint32_t timeout_ms) const; - - protected: - esp_netif_t *_esp_netif; - EventGroupHandle_t _interface_event_group; - int _initial_bits; - int32_t _got_ip_event_id; - int32_t _lost_ip_event_id; - Network_Interface_ID _interface_id; - - bool initNetif(Network_Interface_ID interface_id); - void destroyNetif(); - int setStatusBits(int bits); - int clearStatusBits(int bits); - - // virtual void getMac(uint8_t* mac) = 0; - virtual size_t printDriverInfo(Print & out) const = 0; - - public: - void _onIpEvent(int32_t event_id, void* event_data); - - private: - IPAddress calculateNetworkID(IPAddress ip, IPAddress subnet) const; - IPAddress calculateBroadcast(IPAddress ip, IPAddress subnet) const; - uint8_t calculateSubnetCIDR(IPAddress subnetMask) const; +class NetworkInterface : public Printable { +public: + NetworkInterface(); + virtual ~NetworkInterface(); + + // For server interfaces (WiFi AP), dns1 is the DHCP lease range start and dns2 is the DNS. dns3 is not used + bool config(IPAddress local_ip = (uint32_t)0x00000000, IPAddress gateway = (uint32_t)0x00000000, IPAddress subnet = (uint32_t)0x00000000, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000, IPAddress dns3 = (uint32_t)0x00000000); + bool dnsIP(uint8_t dns_no, IPAddress ip); + + const char* getHostname() const; + bool setHostname(const char* hostname) const; + + bool started() const; + bool connected() const; + bool hasIP() const; + bool hasLinkLocalIPv6() const; + bool hasGlobalIPv6() const; + bool enableIPv6(bool en = true); + + bool linkUp() const; + const char* ifkey() const; + const char* desc() const; + String impl_name() const; + int impl_index() const; + int route_prio() const; + bool setDefault(); + bool isDefault() const; + + uint8_t* macAddress(uint8_t* mac) const; + String macAddress() const; + IPAddress localIP() const; + IPAddress subnetMask() const; + IPAddress gatewayIP() const; + IPAddress dnsIP(uint8_t dns_no = 0) const; + IPAddress broadcastIP() const; + IPAddress networkID() const; + uint8_t subnetCIDR() const; + IPAddress linkLocalIPv6() const; + IPAddress globalIPv6() const; + + size_t printTo(Print& out) const; + + esp_netif_t* netif() { + return _esp_netif; + } + int getStatusBits() const; + int waitStatusBits(int bits, uint32_t timeout_ms) const; + +protected: + esp_netif_t* _esp_netif; + EventGroupHandle_t _interface_event_group; + int _initial_bits; + int32_t _got_ip_event_id; + int32_t _lost_ip_event_id; + Network_Interface_ID _interface_id; + + bool initNetif(Network_Interface_ID interface_id); + void destroyNetif(); + int setStatusBits(int bits); + int clearStatusBits(int bits); + + // virtual void getMac(uint8_t* mac) = 0; + virtual size_t printDriverInfo(Print& out) const = 0; + +public: + void _onIpEvent(int32_t event_id, void* event_data); + +private: + IPAddress calculateNetworkID(IPAddress ip, IPAddress subnet) const; + IPAddress calculateBroadcast(IPAddress ip, IPAddress subnet) const; + uint8_t calculateSubnetCIDR(IPAddress subnetMask) const; }; diff --git a/libraries/Network/src/NetworkManager.cpp b/libraries/Network/src/NetworkManager.cpp index 90e185d5964..da49497bcb9 100644 --- a/libraries/Network/src/NetworkManager.cpp +++ b/libraries/Network/src/NetworkManager.cpp @@ -10,31 +10,30 @@ #include "esp_mac.h" #include "netdb.h" -NetworkManager::NetworkManager(){ - +NetworkManager::NetworkManager() { } -NetworkInterface * getNetifByID(Network_Interface_ID id); +NetworkInterface *getNetifByID(Network_Interface_ID id); -bool NetworkManager::begin(){ - static bool initialized = false; - if(!initialized){ - initialized = true; +bool NetworkManager::begin() { + static bool initialized = false; + if (!initialized) { + initialized = true; #if CONFIG_IDF_TARGET_ESP32 - uint8_t mac[8]; - if(esp_efuse_mac_get_default(mac) == ESP_OK){ - esp_base_mac_addr_set(mac); - } -#endif - initialized = esp_netif_init() == ESP_OK; - if(!initialized){ - log_e("esp_netif_init failed!"); - } + uint8_t mac[8]; + if (esp_efuse_mac_get_default(mac) == ESP_OK) { + esp_base_mac_addr_set(mac); } - if(initialized){ - initNetworkEvents(); +#endif + initialized = esp_netif_init() == ESP_OK; + if (!initialized) { + log_e("esp_netif_init failed!"); } - return initialized; + } + if (initialized) { + initNetworkEvents(); + } + return initialized; } /** @@ -44,161 +43,153 @@ bool NetworkManager::begin(){ * @return 1 if aIPAddrString was successfully converted to an IP address, * else error code */ -int NetworkManager::hostByName(const char* aHostname, IPAddress& aResult) -{ - static bool hasGlobalV6 = false; - static bool hasGlobalV4 = false; - err_t err = ERR_OK; - const char *servname = "0"; - struct addrinfo *res; - - aResult = static_cast(0); - - // First check if the host parses as a literal address - if (aResult.fromString(aHostname)) { - return 1; +int NetworkManager::hostByName(const char *aHostname, IPAddress &aResult) { + static bool hasGlobalV6 = false; + static bool hasGlobalV4 = false; + err_t err = ERR_OK; + const char *servname = "0"; + struct addrinfo *res; + + aResult = static_cast(0); + + // First check if the host parses as a literal address + if (aResult.fromString(aHostname)) { + return 1; + } + + // This should generally check if we have a global address assigned to one of the interfaces. + // If such address is not assigned, there is no point in trying to get V6 from DNS as we will not be able to reach it. + bool hasGlobalV6Now = false; + bool hasGlobalV4Now = false; + for (int i = 0; i < ESP_NETIF_ID_MAX; ++i) { + NetworkInterface *iface = getNetifByID((Network_Interface_ID)i); + if (iface != NULL) { + if (iface->hasGlobalIPv6()) { + hasGlobalV6Now = true; + } + if (iface->hasIP()) { + hasGlobalV4Now = true; + } } - - // This should generally check if we have a global address assigned to one of the interfaces. - // If such address is not assigned, there is no point in trying to get V6 from DNS as we will not be able to reach it. - bool hasGlobalV6Now = false; - bool hasGlobalV4Now = false; - for (int i = 0; i < ESP_NETIF_ID_MAX; ++i){ - NetworkInterface * iface = getNetifByID((Network_Interface_ID)i); - if(iface != NULL) { - if(iface->hasGlobalIPv6()) { - hasGlobalV6Now = true; - } - if(iface->hasIP()) { - hasGlobalV4Now = true; - } - } - if (hasGlobalV6Now && hasGlobalV4Now){ - break; - } + if (hasGlobalV6Now && hasGlobalV4Now) { + break; } + } + + // If the state of IP addresses has changed, clear the DNS cache + if (hasGlobalV6 != hasGlobalV6Now || hasGlobalV4 != hasGlobalV4Now) { + hasGlobalV6 = hasGlobalV6Now; + hasGlobalV4 = hasGlobalV4Now; + dns_clear_cache(); + log_d("Clearing DNS cache"); + } + + struct addrinfo hints; + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_STREAM; + + // **Workaround** + // LWIP AF_UNSPEC always prefers IPv4 and doesn't check what network is + // available. See https://github.com/espressif/esp-idf/issues/13255 + // Until that is fixed, as a work around if we have a global scope IPv6, + // then we check IPv6 only first. + if (hasGlobalV6) { + hints.ai_family = AF_INET6; + err = lwip_getaddrinfo(aHostname, servname, &hints, &res); - // If the state of IP addresses has changed, clear the DNS cache - if(hasGlobalV6 != hasGlobalV6Now || hasGlobalV4 != hasGlobalV4Now){ - hasGlobalV6 = hasGlobalV6Now; - hasGlobalV4 = hasGlobalV4Now; - dns_clear_cache(); - log_d("Clearing DNS cache"); + if (err == ERR_OK) { + struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)res->ai_addr; + // As an array of u8_t + aResult = IPAddress(IPv6, ipv6->sin6_addr.s6_addr); + log_d("DNS found IPv6 first %s", aResult.toString().c_str()); + lwip_freeaddrinfo(res); + return 1; } - - struct addrinfo hints; - memset(&hints, 0, sizeof(hints)); - hints.ai_socktype = SOCK_STREAM; - - // **Workaround** - // LWIP AF_UNSPEC always prefers IPv4 and doesn't check what network is - // available. See https://github.com/espressif/esp-idf/issues/13255 - // Until that is fixed, as a work around if we have a global scope IPv6, - // then we check IPv6 only first. - if (hasGlobalV6) { - hints.ai_family = AF_INET6; - err = lwip_getaddrinfo(aHostname, servname, &hints, &res); - - if (err == ERR_OK) - { - struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)res->ai_addr; - // As an array of u8_t - aResult = IPAddress(IPv6, ipv6->sin6_addr.s6_addr); - log_d("DNS found IPv6 first %s", aResult.toString().c_str()); - lwip_freeaddrinfo(res); - return 1; - } + } + // **End Workaround** + + hints.ai_family = AF_UNSPEC; + err = lwip_getaddrinfo(aHostname, servname, &hints, &res); + + if (err == ERR_OK) { + if (res->ai_family == AF_INET6) { + struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)res->ai_addr; + // As an array of u8_t + aResult = IPAddress(IPv6, ipv6->sin6_addr.s6_addr); + log_d("DNS found IPv6 %s", aResult.toString().c_str()); + } else { + struct sockaddr_in *ipv4 = (struct sockaddr_in *)res->ai_addr; + // As a single u32_t + aResult = IPAddress(ipv4->sin_addr.s_addr); + log_d("DNS found IPv4 %s", aResult.toString().c_str()); } - // **End Workaround** - hints.ai_family = AF_UNSPEC; - err = lwip_getaddrinfo(aHostname, servname, &hints, &res); - - if (err == ERR_OK) - { - if (res->ai_family == AF_INET6) - { - struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)res->ai_addr; - // As an array of u8_t - aResult = IPAddress(IPv6, ipv6->sin6_addr.s6_addr); - log_d("DNS found IPv6 %s", aResult.toString().c_str()); - } - else - { - struct sockaddr_in *ipv4 = (struct sockaddr_in *)res->ai_addr; - // As a single u32_t - aResult = IPAddress(ipv4->sin_addr.s_addr); - log_d("DNS found IPv4 %s", aResult.toString().c_str()); - } - - lwip_freeaddrinfo(res); - return 1; - } + lwip_freeaddrinfo(res); + return 1; + } - log_e("DNS Failed for '%s' with error '%d'", aHostname, err); - return err; + log_e("DNS Failed for '%s' with error '%d'", aHostname, err); + return err; } -uint8_t * NetworkManager::macAddress(uint8_t * mac){ - esp_base_mac_addr_get(mac); - return mac; +uint8_t *NetworkManager::macAddress(uint8_t *mac) { + esp_base_mac_addr_get(mac); + return mac; } -String NetworkManager::macAddress(void){ - uint8_t mac[6]; - char macStr[18] = { 0 }; - macAddress(mac); - sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - return String(macStr); +String NetworkManager::macAddress(void) { + uint8_t mac[6]; + char macStr[18] = { 0 }; + macAddress(mac); + sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + return String(macStr); } -static char default_hostname[32] = {0,}; - -const char * NetworkManager::getHostname() -{ - if(default_hostname[0] == 0){ - uint8_t eth_mac[6]; - esp_base_mac_addr_get(eth_mac); - snprintf(default_hostname, 32, "%s%02X%02X%02X", CONFIG_IDF_TARGET "-", eth_mac[3], eth_mac[4], eth_mac[5]); - } - return (const char *)default_hostname; +static char default_hostname[32] = { + 0, +}; + +const char *NetworkManager::getHostname() { + if (default_hostname[0] == 0) { + uint8_t eth_mac[6]; + esp_base_mac_addr_get(eth_mac); + snprintf(default_hostname, 32, "%s%02X%02X%02X", CONFIG_IDF_TARGET "-", eth_mac[3], eth_mac[4], eth_mac[5]); + } + return (const char *)default_hostname; } -bool NetworkManager::setHostname(const char * name) -{ - if(name){ - snprintf(default_hostname, 32, "%s", name); - } - return true; +bool NetworkManager::setHostname(const char *name) { + if (name) { + snprintf(default_hostname, 32, "%s", name); + } + return true; } -bool NetworkManager::setDefaultInterface(NetworkInterface & ifc) -{ - return ifc.setDefault(); +bool NetworkManager::setDefaultInterface(NetworkInterface &ifc) { + return ifc.setDefault(); } -NetworkInterface * NetworkManager::getDefaultInterface() -{ - esp_netif_t * netif = esp_netif_get_default_netif(); - for (int i = 0; i < ESP_NETIF_ID_MAX; ++i){ - NetworkInterface * iface = getNetifByID((Network_Interface_ID)i); - if(iface != NULL && iface->netif() == netif){ - return iface; - } +NetworkInterface *NetworkManager::getDefaultInterface() { + esp_netif_t *netif = esp_netif_get_default_netif(); + for (int i = 0; i < ESP_NETIF_ID_MAX; ++i) { + NetworkInterface *iface = getNetifByID((Network_Interface_ID)i); + if (iface != NULL && iface->netif() == netif) { + return iface; } - return NULL; + } + return NULL; } -size_t NetworkManager::printTo(Print & out) const { - size_t bytes = 0; +size_t NetworkManager::printTo(Print &out) const { + size_t bytes = 0; - for (int i = 0; i < ESP_NETIF_ID_MAX; ++i){ - NetworkInterface * iface = getNetifByID((Network_Interface_ID)i); - if(iface != NULL && iface->netif() != NULL){ - bytes += out.println(*iface); - } + for (int i = 0; i < ESP_NETIF_ID_MAX; ++i) { + NetworkInterface *iface = getNetifByID((Network_Interface_ID)i); + if (iface != NULL && iface->netif() != NULL) { + bytes += out.println(*iface); } - return bytes; + } + return bytes; } diff --git a/libraries/Network/src/NetworkManager.h b/libraries/Network/src/NetworkManager.h index 10f42aab25a..6b9d5e16cfc 100644 --- a/libraries/Network/src/NetworkManager.h +++ b/libraries/Network/src/NetworkManager.h @@ -12,21 +12,23 @@ class NetworkManager : public NetworkEvents, public Printable { public: - NetworkManager(); + NetworkManager(); - bool begin(); - int hostByName(const char *aHostname, IPAddress &aResult); - uint8_t * macAddress(uint8_t * mac); - String macAddress(); + bool begin(); + int hostByName(const char *aHostname, IPAddress &aResult); + uint8_t *macAddress(uint8_t *mac); + String macAddress(); - bool setDefaultInterface(NetworkInterface & ifc); - NetworkInterface * getDefaultInterface(); + bool setDefaultInterface(NetworkInterface &ifc); + NetworkInterface *getDefaultInterface(); - size_t printTo(Print & out) const; + size_t printTo(Print &out) const; - static const char * getHostname(); - static bool setHostname(const char * hostname); - static bool hostname(const String& aHostname) { return setHostname(aHostname.c_str()); } + static const char *getHostname(); + static bool setHostname(const char *hostname); + static bool hostname(const String &aHostname) { + return setHostname(aHostname.c_str()); + } }; extern NetworkManager Network; diff --git a/libraries/Network/src/NetworkServer.cpp b/libraries/Network/src/NetworkServer.cpp index a8a15c5cbe5..c4369c57ef0 100644 --- a/libraries/Network/src/NetworkServer.cpp +++ b/libraries/Network/src/NetworkServer.cpp @@ -23,75 +23,74 @@ #undef write #undef close -int NetworkServer::setTimeout(uint32_t seconds){ +int NetworkServer::setTimeout(uint32_t seconds) { struct timeval tv; tv.tv_sec = seconds; tv.tv_usec = 0; - if(setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0) + if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0) return -1; return setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval)); } -NetworkClient NetworkServer::available(){ +NetworkClient NetworkServer::available() { return accept(); } -NetworkClient NetworkServer::accept(){ - if(!_listening) +NetworkClient NetworkServer::accept() { + if (!_listening) return NetworkClient(); int client_sock; if (_accepted_sockfd >= 0) { client_sock = _accepted_sockfd; _accepted_sockfd = -1; - } - else { - struct sockaddr_in6 _client; - int cs = sizeof(struct sockaddr_in6); + } else { + struct sockaddr_in6 _client; + int cs = sizeof(struct sockaddr_in6); #ifdef ESP_IDF_VERSION_MAJOR - client_sock = lwip_accept(sockfd, (struct sockaddr *)&_client, (socklen_t*)&cs); + client_sock = lwip_accept(sockfd, (struct sockaddr *)&_client, (socklen_t *)&cs); #else - client_sock = lwip_accept_r(sockfd, (struct sockaddr *)&_client, (socklen_t*)&cs); + client_sock = lwip_accept_r(sockfd, (struct sockaddr *)&_client, (socklen_t *)&cs); #endif } - if(client_sock >= 0){ + if (client_sock >= 0) { int val = 1; - if(setsockopt(client_sock, SOL_SOCKET, SO_KEEPALIVE, (char*)&val, sizeof(int)) == ESP_OK) { + if (setsockopt(client_sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&val, sizeof(int)) == ESP_OK) { val = _noDelay; - if(setsockopt(client_sock, IPPROTO_TCP, TCP_NODELAY, (char*)&val, sizeof(int)) == ESP_OK) + if (setsockopt(client_sock, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(int)) == ESP_OK) return NetworkClient(client_sock); } } return NetworkClient(); } -void NetworkServer::begin(uint16_t port){ - begin(port, 1); +void NetworkServer::begin(uint16_t port) { + begin(port, 1); } -void NetworkServer::begin(uint16_t port, int enable){ - if(_listening) +void NetworkServer::begin(uint16_t port, int enable) { + if (_listening) return; - if(port){ - _port = port; + if (port) { + _port = port; } struct sockaddr_in6 server; - sockfd = socket(AF_INET6 , SOCK_STREAM, 0); + sockfd = socket(AF_INET6, SOCK_STREAM, 0); if (sockfd < 0) return; setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)); server.sin6_family = AF_INET6; if (_addr.type() == IPv4) { - memcpy(server.sin6_addr.s6_addr+11, (uint8_t*)&_addr[0], 4); + memcpy(server.sin6_addr.s6_addr + 11, (uint8_t *)&_addr[0], 4); server.sin6_addr.s6_addr[10] = 0xFF; server.sin6_addr.s6_addr[11] = 0xFF; } else { - memcpy(server.sin6_addr.s6_addr, (uint8_t*)&_addr[0], 16); + memcpy(server.sin6_addr.s6_addr, (uint8_t *)&_addr[0], 16); } memset(server.sin6_addr.s6_addr, 0x0, 16); server.sin6_port = htons(_port); - if(bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0) + if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0) return; - if(listen(sockfd , _max_clients) < 0) + if (listen(sockfd, _max_clients) < 0) return; fcntl(sockfd, F_SETFL, O_NONBLOCK); _listening = true; @@ -100,31 +99,31 @@ void NetworkServer::begin(uint16_t port, int enable){ } void NetworkServer::setNoDelay(bool nodelay) { - _noDelay = nodelay; + _noDelay = nodelay; } bool NetworkServer::getNoDelay() { - return _noDelay; + return _noDelay; } bool NetworkServer::hasClient() { - if (_accepted_sockfd >= 0) { - return true; - } - struct sockaddr_in6 _client; - int cs = sizeof(struct sockaddr_in6); + if (_accepted_sockfd >= 0) { + return true; + } + struct sockaddr_in6 _client; + int cs = sizeof(struct sockaddr_in6); #ifdef ESP_IDF_VERSION_MAJOR - _accepted_sockfd = lwip_accept(sockfd, (struct sockaddr *)&_client, (socklen_t*)&cs); + _accepted_sockfd = lwip_accept(sockfd, (struct sockaddr *)&_client, (socklen_t *)&cs); #else - _accepted_sockfd = lwip_accept_r(sockfd, (struct sockaddr *)&_client, (socklen_t*)&cs); + _accepted_sockfd = lwip_accept_r(sockfd, (struct sockaddr *)&_client, (socklen_t *)&cs); #endif - if (_accepted_sockfd >= 0) { - return true; - } - return false; + if (_accepted_sockfd >= 0) { + return true; + } + return false; } -void NetworkServer::end(){ +void NetworkServer::end() { #ifdef ESP_IDF_VERSION_MAJOR lwip_close(sockfd); #else @@ -134,10 +133,10 @@ void NetworkServer::end(){ _listening = false; } -void NetworkServer::close(){ +void NetworkServer::close() { end(); } -void NetworkServer::stop(){ +void NetworkServer::stop() { end(); } diff --git a/libraries/Network/src/NetworkServer.h b/libraries/Network/src/NetworkServer.h index ce9bd2be47d..dcb9279c9be 100644 --- a/libraries/Network/src/NetworkServer.h +++ b/libraries/Network/src/NetworkServer.h @@ -24,37 +24,42 @@ #include "IPAddress.h" class NetworkServer { - private: - int sockfd; - int _accepted_sockfd = -1; - IPAddress _addr; - uint16_t _port; - uint8_t _max_clients; - bool _listening; - bool _noDelay = false; - - public: - void listenOnLocalhost(){} - - NetworkServer(uint16_t port=80, uint8_t max_clients=4):sockfd(-1),_accepted_sockfd(-1),_addr(),_port(port),_max_clients(max_clients),_listening(false),_noDelay(false) { - log_v("NetworkServer::NetworkServer(port=%d, ...)", port); - } - NetworkServer(const IPAddress& addr, uint16_t port=80, uint8_t max_clients=4):sockfd(-1),_accepted_sockfd(-1),_addr(addr),_port(port),_max_clients(max_clients),_listening(false),_noDelay(false) { - log_v("NetworkServer::NetworkServer(addr=%s, port=%d, ...)", addr.toString().c_str(), port); - } - ~NetworkServer(){ end();} - NetworkClient available() __attribute__((deprecated("Renamed to accept()."))); - NetworkClient accept(); - void begin(uint16_t port=0); - void begin(uint16_t port, int reuse_enable); - void setNoDelay(bool nodelay); - bool getNoDelay(); - bool hasClient(); - - void end(); - void close(); - void stop(); - operator bool(){return _listening;} - int setTimeout(uint32_t seconds); -}; +private: + int sockfd; + int _accepted_sockfd = -1; + IPAddress _addr; + uint16_t _port; + uint8_t _max_clients; + bool _listening; + bool _noDelay = false; + +public: + void listenOnLocalhost() {} + NetworkServer(uint16_t port = 80, uint8_t max_clients = 4) + : sockfd(-1), _accepted_sockfd(-1), _addr(), _port(port), _max_clients(max_clients), _listening(false), _noDelay(false) { + log_v("NetworkServer::NetworkServer(port=%d, ...)", port); + } + NetworkServer(const IPAddress& addr, uint16_t port = 80, uint8_t max_clients = 4) + : sockfd(-1), _accepted_sockfd(-1), _addr(addr), _port(port), _max_clients(max_clients), _listening(false), _noDelay(false) { + log_v("NetworkServer::NetworkServer(addr=%s, port=%d, ...)", addr.toString().c_str(), port); + } + ~NetworkServer() { + end(); + } + NetworkClient available() __attribute__((deprecated("Renamed to accept()."))); + NetworkClient accept(); + void begin(uint16_t port = 0); + void begin(uint16_t port, int reuse_enable); + void setNoDelay(bool nodelay); + bool getNoDelay(); + bool hasClient(); + + void end(); + void close(); + void stop(); + operator bool() { + return _listening; + } + int setTimeout(uint32_t seconds); +}; diff --git a/libraries/Network/src/NetworkUdp.cpp b/libraries/Network/src/NetworkUdp.cpp index 4d3cf04d3bf..aeb45caec7a 100644 --- a/libraries/Network/src/NetworkUdp.cpp +++ b/libraries/Network/src/NetworkUdp.cpp @@ -27,44 +27,38 @@ #undef read NetworkUDP::NetworkUDP() -: udp_server(-1) -, server_port(0) -, remote_port(0) -, tx_buffer(0) -, tx_buffer_len(0) -, rx_buffer(0) -{} - -NetworkUDP::~NetworkUDP(){ - stop(); + : udp_server(-1), server_port(0), remote_port(0), tx_buffer(0), tx_buffer_len(0), rx_buffer(0) {} + +NetworkUDP::~NetworkUDP() { + stop(); } -uint8_t NetworkUDP::begin(IPAddress address, uint16_t port){ +uint8_t NetworkUDP::begin(IPAddress address, uint16_t port) { stop(); server_port = port; tx_buffer = (char *)malloc(1460); - if(!tx_buffer){ + if (!tx_buffer) { log_e("could not create tx buffer: %d", errno); return 0; } tx_buffer_len = 0; #if LWIP_IPV6 - if ((udp_server=socket((address.type() == IPv6) ? AF_INET6 : AF_INET, SOCK_DGRAM, 0)) == -1){ + if ((udp_server = socket((address.type() == IPv6) ? AF_INET6 : AF_INET, SOCK_DGRAM, 0)) == -1) { #else - if ((udp_server=socket(AF_INET, SOCK_DGRAM, 0)) == -1){ + if ((udp_server = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { #endif log_e("could not create socket: %d", errno); return 0; } int yes = 1; - if (setsockopt(udp_server,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)) < 0) { - log_e("could not set socket option: %d", errno); - stop(); - return 0; + if (setsockopt(udp_server, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) { + log_e("could not set socket option: %d", errno); + stop(); + return 0; } struct sockaddr_storage serveraddr = {}; @@ -74,7 +68,7 @@ uint8_t NetworkUDP::begin(IPAddress address, uint16_t port){ struct sockaddr_in6 *tmpaddr = (struct sockaddr_in6 *)&serveraddr; ip_addr_t addr; address.to_ip_addr_t(&addr); - memset((char *) tmpaddr, 0, sizeof(struct sockaddr_in)); + memset((char *)tmpaddr, 0, sizeof(struct sockaddr_in)); tmpaddr->sin6_family = AF_INET6; tmpaddr->sin6_port = htons(server_port); tmpaddr->sin6_scope_id = addr.u_addr.ip6.zone; @@ -85,13 +79,13 @@ uint8_t NetworkUDP::begin(IPAddress address, uint16_t port){ #endif { struct sockaddr_in *tmpaddr = (struct sockaddr_in *)&serveraddr; - memset((char *) tmpaddr, 0, sizeof(struct sockaddr_in)); + memset((char *)tmpaddr, 0, sizeof(struct sockaddr_in)); tmpaddr->sin_family = AF_INET; tmpaddr->sin_port = htons(server_port); tmpaddr->sin_addr.s_addr = (in_addr_t)address; sock_size = sizeof(sockaddr_in); } - if(bind(udp_server , (sockaddr*)&serveraddr, sock_size) == -1){ + if (bind(udp_server, (sockaddr *)&serveraddr, sock_size) == -1) { log_e("could not bind socket: %d", errno); stop(); return 0; @@ -100,12 +94,12 @@ uint8_t NetworkUDP::begin(IPAddress address, uint16_t port){ return 1; } -uint8_t NetworkUDP::begin(uint16_t p){ +uint8_t NetworkUDP::begin(uint16_t p) { return begin(IPAddress(), p); } -uint8_t NetworkUDP::beginMulticast(IPAddress address, uint16_t p){ - if(begin(IPAddress(), p)){ +uint8_t NetworkUDP::beginMulticast(IPAddress address, uint16_t p) { + if (begin(IPAddress(), p)) { ip_addr_t addr; address.to_ip_addr_t(&addr); if (ip_addr_ismulticast(&addr)) { @@ -116,9 +110,9 @@ uint8_t NetworkUDP::beginMulticast(IPAddress address, uint16_t p){ inet6_addr_from_ip6addr(&mreq.ipv6mr_multiaddr, ip_2_ip6(&addr)); // iterate on each interface - for (netif* intf = netif_list; intf != nullptr; intf = intf->next) { + for (netif *intf = netif_list; intf != nullptr; intf = intf->next) { mreq.ipv6mr_interface = intf->num + 1; - if (intf->name[0] != 'l' || intf->name[1] != 'o') { // skip 'lo' local interface + if (intf->name[0] != 'l' || intf->name[1] != 'o') { // skip 'lo' local interface int ret = setsockopt(udp_server, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)); if (ret >= 0) { joined = true; } } @@ -135,9 +129,9 @@ uint8_t NetworkUDP::beginMulticast(IPAddress address, uint16_t p){ mreq.imr_multiaddr.s_addr = (in_addr_t)address; mreq.imr_interface.s_addr = INADDR_ANY; if (setsockopt(udp_server, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) { - log_e("could not join igmp: %d", errno); - stop(); - return 0; + log_e("could not join igmp: %d", errno); + stop(); + return 0; } } multicast_ip = address; @@ -147,18 +141,18 @@ uint8_t NetworkUDP::beginMulticast(IPAddress address, uint16_t p){ return 0; } -void NetworkUDP::stop(){ - if(tx_buffer){ +void NetworkUDP::stop() { + if (tx_buffer) { free(tx_buffer); tx_buffer = NULL; } tx_buffer_len = 0; - if(rx_buffer){ + if (rx_buffer) { cbuf *b = rx_buffer; rx_buffer = NULL; delete b; } - if(udp_server == -1) + if (udp_server == -1) return; ip_addr_t addr; multicast_ip.to_ip_addr_t(&addr); @@ -169,9 +163,9 @@ void NetworkUDP::stop(){ inet6_addr_from_ip6addr(&mreq.ipv6mr_multiaddr, ip_2_ip6(&addr)); // iterate on each interface - for (netif* intf = netif_list; intf != nullptr; intf = intf->next) { + for (netif *intf = netif_list; intf != nullptr; intf = intf->next) { mreq.ipv6mr_interface = intf->num + 1; - if (intf->name[0] != 'l' || intf->name[1] != 'o') { // skip 'lo' local interface + if (intf->name[0] != 'l' || intf->name[1] != 'o') { // skip 'lo' local interface setsockopt(udp_server, IPPROTO_IPV6, IPV6_LEAVE_GROUP, &mreq, sizeof(mreq)); } } @@ -190,22 +184,22 @@ void NetworkUDP::stop(){ udp_server = -1; } -int NetworkUDP::beginMulticastPacket(){ - if(!server_port || multicast_ip == IPAddress()) +int NetworkUDP::beginMulticastPacket() { + if (!server_port || multicast_ip == IPAddress()) return 0; remote_ip = multicast_ip; remote_port = server_port; return beginPacket(); } -int NetworkUDP::beginPacket(){ - if(!remote_port) +int NetworkUDP::beginPacket() { + if (!remote_port) return 0; // allocate tx_buffer if is necessary - if(!tx_buffer){ + if (!tx_buffer) { tx_buffer = (char *)malloc(1460); - if(!tx_buffer){ + if (!tx_buffer) { log_e("could not create tx buffer: %d", errno); return 0; } @@ -216,7 +210,7 @@ int NetworkUDP::beginPacket(){ if (udp_server != -1) return 1; - if ((udp_server=socket(AF_INET, SOCK_DGRAM, 0)) == -1){ + if ((udp_server = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { log_e("could not create socket: %d", errno); return 0; } @@ -226,23 +220,23 @@ int NetworkUDP::beginPacket(){ return 1; } -int NetworkUDP::beginPacket(IPAddress ip, uint16_t port){ +int NetworkUDP::beginPacket(IPAddress ip, uint16_t port) { remote_ip = ip; remote_port = port; return beginPacket(); } -int NetworkUDP::beginPacket(const char *host, uint16_t port){ +int NetworkUDP::beginPacket(const char *host, uint16_t port) { struct hostent *server; server = gethostbyname(host); - if (server == NULL){ + if (server == NULL) { log_e("could not get host from dns: %d", errno); return 0; } return beginPacket(IPAddress((const uint8_t *)(server->h_addr_list[0])), port); } -int NetworkUDP::endPacket(){ +int NetworkUDP::endPacket() { ip_addr_t addr; remote_ip.to_ip_addr_t(&addr); @@ -251,20 +245,20 @@ int NetworkUDP::endPacket(){ recipient.sin_addr.s_addr = (uint32_t)remote_ip; recipient.sin_family = AF_INET; recipient.sin_port = htons(remote_port); - int sent = sendto(udp_server, tx_buffer, tx_buffer_len, 0, (struct sockaddr*) &recipient, sizeof(recipient)); - if(sent < 0){ + int sent = sendto(udp_server, tx_buffer, tx_buffer_len, 0, (struct sockaddr *)&recipient, sizeof(recipient)); + if (sent < 0) { log_e("could not send data: %d", errno); return 0; } } else { struct sockaddr_in6 recipient; recipient.sin6_flowinfo = 0; - recipient.sin6_addr = *(in6_addr*)(ip_addr_t*)(&addr); + recipient.sin6_addr = *(in6_addr *)(ip_addr_t *)(&addr); recipient.sin6_family = AF_INET6; recipient.sin6_port = htons(remote_port); recipient.sin6_scope_id = remote_ip.zone(); - int sent = sendto(udp_server, tx_buffer, tx_buffer_len, 0, (struct sockaddr*) &recipient, sizeof(recipient)); - if(sent < 0){ + int sent = sendto(udp_server, tx_buffer, tx_buffer_len, 0, (struct sockaddr *)&recipient, sizeof(recipient)); + if (sent < 0) { log_e("could not send data: %d", errno); return 0; } @@ -272,8 +266,8 @@ int NetworkUDP::endPacket(){ return 1; } -size_t NetworkUDP::write(uint8_t data){ - if(tx_buffer_len == 1460){ +size_t NetworkUDP::write(uint8_t data) { + if (tx_buffer_len == 1460) { endPacket(); tx_buffer_len = 0; } @@ -281,45 +275,43 @@ size_t NetworkUDP::write(uint8_t data){ return 1; } -size_t NetworkUDP::write(const uint8_t *buffer, size_t size){ +size_t NetworkUDP::write(const uint8_t *buffer, size_t size) { size_t i; - for(i=0;i 0) { - rx_buffer = new(std::nothrow) cbuf(len); + rx_buffer = new (std::nothrow) cbuf(len); rx_buffer->write(buf, len); } free(buf); return len; } -int NetworkUDP::available(){ - if(!rx_buffer) return 0; +int NetworkUDP::available() { + if (!rx_buffer) return 0; return rx_buffer->available(); } -int NetworkUDP::read(){ - if(!rx_buffer) return -1; +int NetworkUDP::read() { + if (!rx_buffer) return -1; int out = rx_buffer->read(); - if(!rx_buffer->available()){ + if (!rx_buffer->available()) { cbuf *b = rx_buffer; rx_buffer = 0; delete b; @@ -359,14 +351,14 @@ int NetworkUDP::read(){ return out; } -int NetworkUDP::read(unsigned char* buffer, size_t len){ +int NetworkUDP::read(unsigned char *buffer, size_t len) { return read((char *)buffer, len); } -int NetworkUDP::read(char* buffer, size_t len){ - if(!rx_buffer) return 0; +int NetworkUDP::read(char *buffer, size_t len) { + if (!rx_buffer) return 0; int out = rx_buffer->read(buffer, len); - if(!rx_buffer->available()){ + if (!rx_buffer->available()) { cbuf *b = rx_buffer; rx_buffer = 0; delete b; @@ -374,22 +366,22 @@ int NetworkUDP::read(char* buffer, size_t len){ return out; } -int NetworkUDP::peek(){ - if(!rx_buffer) return -1; +int NetworkUDP::peek() { + if (!rx_buffer) return -1; return rx_buffer->peek(); } -void NetworkUDP::clear(){ - if(!rx_buffer) return; +void NetworkUDP::clear() { + if (!rx_buffer) return; cbuf *b = rx_buffer; rx_buffer = 0; delete b; } -IPAddress NetworkUDP::remoteIP(){ +IPAddress NetworkUDP::remoteIP() { return remote_ip; } -uint16_t NetworkUDP::remotePort(){ +uint16_t NetworkUDP::remotePort() { return remote_port; } diff --git a/libraries/Network/src/NetworkUdp.h b/libraries/Network/src/NetworkUdp.h index 92c10152b93..2546ac12d0e 100644 --- a/libraries/Network/src/NetworkUdp.h +++ b/libraries/Network/src/NetworkUdp.h @@ -46,9 +46,9 @@ class NetworkUDP : public UDP { IPAddress remote_ip; uint16_t server_port; uint16_t remote_port; - char * tx_buffer; + char* tx_buffer; size_t tx_buffer_len; - cbuf * rx_buffer; + cbuf* rx_buffer; public: NetworkUDP(); ~NetworkUDP(); @@ -59,18 +59,18 @@ class NetworkUDP : public UDP { int beginMulticastPacket(); int beginPacket(); int beginPacket(IPAddress ip, uint16_t port); - int beginPacket(const char *host, uint16_t port); + int beginPacket(const char* host, uint16_t port); int endPacket(); size_t write(uint8_t); - size_t write(const uint8_t *buffer, size_t size); - void flush(); // Print::flush tx + size_t write(const uint8_t* buffer, size_t size); + void flush(); // Print::flush tx int parsePacket(); int available(); int read(); int read(unsigned char* buffer, size_t len); int read(char* buffer, size_t len); int peek(); - void clear(); // clear rx + void clear(); // clear rx IPAddress remoteIP(); uint16_t remotePort(); }; diff --git a/libraries/NetworkClientSecure/README.md b/libraries/NetworkClientSecure/README.md index d7645a6026f..0710d3f5b80 100644 --- a/libraries/NetworkClientSecure/README.md +++ b/libraries/NetworkClientSecure/README.md @@ -26,15 +26,15 @@ Then: Please see the NetworkClientSecure example. -Using a bundle of root certificate authority certificates +Using a bundle of root certificate authority certificates --------------------------------------------------------- -This method is similar to the single root certificate verfication above, but it uses a standard set of -root certificates from Mozilla to authenticate against, while the previous method only accepts a single +This method is similar to the single root certificate verification above, but it uses a standard set of +root certificates from Mozilla to authenticate against, while the previous method only accepts a single certificate for a given server. This allows the client to connect to all public SSL servers. To use this feature in PlatformIO: 1. create a certificate bundle as described in the document below, or obtain a pre-built one you trust: -https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/protocols/esp_crt_bundle.html +https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/protocols/esp_crt_bundle.html (gen_crt_bundle.py can be found in the /tools folder) a. note: the full bundle will take up around 64k of flash space, but has minimal RAM usage, as only the index of the certificates is kept in RAM @@ -96,11 +96,11 @@ Please see the NetworkClientPSK example. Specifying the ALPN Protocol ---------------------------- -Application-Layer Protocol Negotiation (ALPN) is a Transport Layer Security (TLS) extension that allows -the application layer to negotiate which protocol should be performed over a secure connection in a manner +Application-Layer Protocol Negotiation (ALPN) is a Transport Layer Security (TLS) extension that allows +the application layer to negotiate which protocol should be performed over a secure connection in a manner that avoids additional round trips and which is independent of the application-layer protocols. -For example, this is used with AWS IoT Custom Authorizers where an MQTT client must set the ALPN protocol to ```mqtt```: +For example, this is used with AWS IoT Custom Authorizers where an MQTT client must set the ALPN protocol to ```mqtt```: ``` const char *aws_protos[] = {"mqtt", NULL}; @@ -130,4 +130,4 @@ and establishing a secure HTTPS connection with an external server (for example Example of a establishing a secure connection and then showing the fingerprint of the certificate. This can be useful in an IoT setting to know for sure that you are connecting to the right server. Especially in situations where you cannot hardcode a trusted root certificate for long -periods of time (as they tend to get replaced more often than the lifecycle of IoT hardware). \ No newline at end of file +periods of time (as they tend to get replaced more often than the lifecycle of IoT hardware). diff --git a/libraries/NetworkClientSecure/examples/WiFiClientInsecure/WiFiClientInsecure.ino b/libraries/NetworkClientSecure/examples/WiFiClientInsecure/WiFiClientInsecure.ino index 107bde570f2..da7fa8858d9 100644 --- a/libraries/NetworkClientSecure/examples/WiFiClientInsecure/WiFiClientInsecure.ino +++ b/libraries/NetworkClientSecure/examples/WiFiClientInsecure/WiFiClientInsecure.ino @@ -3,16 +3,16 @@ /* This is a very INSECURE approach. * If for some reason the secure, proper example NetworkClientSecure - * does not work for you; then you may want to check the - * NetworkClientTrustOnFirstUse example first. It is less secure than + * does not work for you; then you may want to check the + * NetworkClientTrustOnFirstUse example first. It is less secure than * NetworkClientSecure, but a lot better than this totally insecure * approach shown below. */ -const char* ssid = "your-ssid"; // your network SSID (name of wifi network) -const char* password = "your-password"; // your network password +const char* ssid = "your-ssid"; // your network SSID (name of wifi network) +const char* password = "your-password"; // your network password -const char* server = "www.howsmyssl.com"; // Server URL +const char* server = "www.howsmyssl.com"; // Server URL NetworkClientSecure client; @@ -36,7 +36,7 @@ void setup() { Serial.println(ssid); Serial.println("\nStarting connection to server..."); - client.setInsecure();//skip verification + client.setInsecure(); //skip verification if (!client.connect(server, 443)) Serial.println("Connection failed!"); else { diff --git a/libraries/NetworkClientSecure/examples/WiFiClientPSK/WiFiClientPSK.ino b/libraries/NetworkClientSecure/examples/WiFiClientPSK/WiFiClientPSK.ino index f9a9b11ba1c..f1e0b618ab6 100644 --- a/libraries/NetworkClientSecure/examples/WiFiClientPSK/WiFiClientPSK.ino +++ b/libraries/NetworkClientSecure/examples/WiFiClientPSK/WiFiClientPSK.ino @@ -17,16 +17,16 @@ const char* ssid = "your-ssid"; // your network SSID (name of wifi network) const char* password = "your-password"; // your network password #else -const char* ssid = "test"; // your network SSID (name of wifi network) -const char* password = "securetest"; // your network password +const char* ssid = "test"; // your network SSID (name of wifi network) +const char* password = "securetest"; // your network password #endif //const char* server = "server.local"; // Server hostname const IPAddress server = IPAddress(192, 168, 0, 14); // Server IP address -const int port = 8443; // server's port (8883 for MQTT) +const int port = 8443; // server's port (8883 for MQTT) -const char* pskIdent = "Client_identity"; // PSK identity (sometimes called key hint) -const char* psKey = "1a2b3c4d"; // PSK Key (must be hex string without 0x) +const char* pskIdent = "Client_identity"; // PSK identity (sometimes called key hint) +const char* psKey = "1a2b3c4d"; // PSK Key (must be hex string without 0x) NetworkClientSecure client; diff --git a/libraries/NetworkClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino b/libraries/NetworkClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino index d65d8196767..e20be29c162 100644 --- a/libraries/NetworkClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino +++ b/libraries/NetworkClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino @@ -1,7 +1,7 @@ /* Wifi secure connection example for ESP32 Running on TLS 1.2 using mbedTLS - Suporting the following chipersuites: + Supporting the following ciphersuites: "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384","TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384","TLS_DHE_RSA_WITH_AES_256_GCM_SHA384","TLS_ECDHE_ECDSA_WITH_AES_256_CCM","TLS_DHE_RSA_WITH_AES_256_CCM","TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384","TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384","TLS_DHE_RSA_WITH_AES_256_CBC_SHA256","TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA","TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","TLS_DHE_RSA_WITH_AES_256_CBC_SHA","TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8","TLS_DHE_RSA_WITH_AES_256_CCM_8","TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384","TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384","TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384","TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384","TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384","TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256","TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA","TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256","TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256","TLS_DHE_RSA_WITH_AES_128_GCM_SHA256","TLS_ECDHE_ECDSA_WITH_AES_128_CCM","TLS_DHE_RSA_WITH_AES_128_CCM","TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256","TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256","TLS_DHE_RSA_WITH_AES_128_CBC_SHA256","TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA","TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA","TLS_DHE_RSA_WITH_AES_128_CBC_SHA","TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8","TLS_DHE_RSA_WITH_AES_128_CCM_8","TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256","TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256","TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256","TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256","TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256","TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256","TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA","TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA","TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA","TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA","TLS_DHE_PSK_WITH_AES_256_GCM_SHA384","TLS_DHE_PSK_WITH_AES_256_CCM","TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384","TLS_DHE_PSK_WITH_AES_256_CBC_SHA384","TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA","TLS_DHE_PSK_WITH_AES_256_CBC_SHA","TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384","TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384","TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384","TLS_PSK_DHE_WITH_AES_256_CCM_8","TLS_DHE_PSK_WITH_AES_128_GCM_SHA256","TLS_DHE_PSK_WITH_AES_128_CCM","TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256","TLS_DHE_PSK_WITH_AES_128_CBC_SHA256","TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA","TLS_DHE_PSK_WITH_AES_128_CBC_SHA","TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256","TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256","TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256","TLS_PSK_DHE_WITH_AES_128_CCM_8","TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA","TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA","TLS_RSA_WITH_AES_256_GCM_SHA384","TLS_RSA_WITH_AES_256_CCM","TLS_RSA_WITH_AES_256_CBC_SHA256","TLS_RSA_WITH_AES_256_CBC_SHA","TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384","TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384","TLS_ECDH_RSA_WITH_AES_256_CBC_SHA","TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384","TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384","TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA","TLS_RSA_WITH_AES_256_CCM_8","TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384","TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256","TLS_RSA_WITH_CAMELLIA_256_CBC_SHA","TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384","TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384","TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384","TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384","TLS_RSA_WITH_AES_128_GCM_SHA256","TLS_RSA_WITH_AES_128_CCM","TLS_RSA_WITH_AES_128_CBC_SHA256","TLS_RSA_WITH_AES_128_CBC_SHA","TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256","TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256","TLS_ECDH_RSA_WITH_AES_128_CBC_SHA","TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256","TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256","TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA","TLS_RSA_WITH_AES_128_CCM_8","TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256","TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256","TLS_RSA_WITH_CAMELLIA_128_CBC_SHA","TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256","TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256","TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256","TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256","TLS_RSA_WITH_3DES_EDE_CBC_SHA","TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA","TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA","TLS_RSA_PSK_WITH_AES_256_GCM_SHA384","TLS_RSA_PSK_WITH_AES_256_CBC_SHA384","TLS_RSA_PSK_WITH_AES_256_CBC_SHA","TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384","TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384","TLS_RSA_PSK_WITH_AES_128_GCM_SHA256","TLS_RSA_PSK_WITH_AES_128_CBC_SHA256","TLS_RSA_PSK_WITH_AES_128_CBC_SHA","TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256","TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256","TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA","TLS_PSK_WITH_AES_256_GCM_SHA384","TLS_PSK_WITH_AES_256_CCM","TLS_PSK_WITH_AES_256_CBC_SHA384","TLS_PSK_WITH_AES_256_CBC_SHA","TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384","TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384","TLS_PSK_WITH_AES_256_CCM_8","TLS_PSK_WITH_AES_128_GCM_SHA256","TLS_PSK_WITH_AES_128_CCM","TLS_PSK_WITH_AES_128_CBC_SHA256","TLS_PSK_WITH_AES_128_CBC_SHA","TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256","TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256","TLS_PSK_WITH_AES_128_CCM_8","TLS_PSK_WITH_3DES_EDE_CBC_SHA","TLS_EMPTY_RENEGOTIATION_INFO_SCSV"] 2017 - Evandro Copercini - Apache 2.0 License. */ @@ -9,36 +9,36 @@ #include #include -const char* ssid = "your-ssid"; // your network SSID (name of wifi network) -const char* password = "your-password"; // your network password +const char* ssid = "your-ssid"; // your network SSID (name of wifi network) +const char* password = "your-password"; // your network password -const char* server = "www.howsmyssl.com"; // Server URL +const char* server = "www.howsmyssl.com"; // Server URL // www.howsmyssl.com root certificate authority, to verify the server // change it to your server root CA // SHA1 fingerprint is broken now! -const char* test_root_ca= \ - "-----BEGIN CERTIFICATE-----\n" \ - "MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/\n" \ - "MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" \ - "DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow\n" \ - "PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD\n" \ - "Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB\n" \ - "AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O\n" \ - "rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq\n" \ - "OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b\n" \ - "xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw\n" \ - "7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD\n" \ - "aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV\n" \ - "HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG\n" \ - "SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69\n" \ - "ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr\n" \ - "AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz\n" \ - "R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5\n" \ - "JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo\n" \ - "Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ\n" \ - "-----END CERTIFICATE-----\n"; +const char* test_root_ca = + "-----BEGIN CERTIFICATE-----\n" + "MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/\n" + "MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" + "DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow\n" + "PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD\n" + "Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB\n" + "AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O\n" + "rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq\n" + "OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b\n" + "xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw\n" + "7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD\n" + "aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV\n" + "HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG\n" + "SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69\n" + "ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr\n" + "AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz\n" + "R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5\n" + "JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo\n" + "Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ\n" + "-----END CERTIFICATE-----\n"; // You can use x.509 client certificates if you want //const char* test_client_key = ""; //to verify the client diff --git a/libraries/NetworkClientSecure/examples/WiFiClientSecureEnterprise/WiFiClientSecureEnterprise.ino b/libraries/NetworkClientSecure/examples/WiFiClientSecureEnterprise/WiFiClientSecureEnterprise.ino index 9da03d1ed17..ce9929388de 100644 --- a/libraries/NetworkClientSecure/examples/WiFiClientSecureEnterprise/WiFiClientSecureEnterprise.ino +++ b/libraries/NetworkClientSecure/examples/WiFiClientSecureEnterprise/WiFiClientSecureEnterprise.ino @@ -15,47 +15,47 @@ #include #include -#if __has_include ("esp_eap_client.h") +#if __has_include("esp_eap_client.h") #include "esp_eap_client.h" #else #include "esp_wpa2.h" #endif #include -#define EAP_ANONYMOUS_IDENTITY "anonymous@example.com" //anonymous identity -#define EAP_IDENTITY "id@example.com" //user identity -#define EAP_PASSWORD "password" //eduroam user password -const char* ssid = "eduroam"; // eduroam SSID -const char* host = "arduino.php5.sk"; //external server domain for HTTPS connection +#define EAP_ANONYMOUS_IDENTITY "anonymous@example.com" //anonymous identity +#define EAP_IDENTITY "id@example.com" //user identity +#define EAP_PASSWORD "password" //eduroam user password +const char* ssid = "eduroam"; // eduroam SSID +const char* host = "arduino.php5.sk"; //external server domain for HTTPS connection int counter = 0; -const char* test_root_ca = \ - "-----BEGIN CERTIFICATE-----\n" \ - "MIIEsTCCA5mgAwIBAgIQCKWiRs1LXIyD1wK0u6tTSTANBgkqhkiG9w0BAQsFADBh\n" \ - "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" \ - "d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD\n" \ - "QTAeFw0xNzExMDYxMjIzMzNaFw0yNzExMDYxMjIzMzNaMF4xCzAJBgNVBAYTAlVT\n" \ - "MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n" \ - "b20xHTAbBgNVBAMTFFJhcGlkU1NMIFJTQSBDQSAyMDE4MIIBIjANBgkqhkiG9w0B\n" \ - "AQEFAAOCAQ8AMIIBCgKCAQEA5S2oihEo9nnpezoziDtx4WWLLCll/e0t1EYemE5n\n" \ - "+MgP5viaHLy+VpHP+ndX5D18INIuuAV8wFq26KF5U0WNIZiQp6mLtIWjUeWDPA28\n" \ - "OeyhTlj9TLk2beytbtFU6ypbpWUltmvY5V8ngspC7nFRNCjpfnDED2kRyJzO8yoK\n" \ - "MFz4J4JE8N7NA1uJwUEFMUvHLs0scLoPZkKcewIRm1RV2AxmFQxJkdf7YN9Pckki\n" \ - "f2Xgm3b48BZn0zf0qXsSeGu84ua9g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cBAQQo\n" + "MCYwJAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmRpZ2ljZXJ0LmNvbTBCBgNVHR8E\n" + "OzA5MDegNaAzhjFodHRwOi8vY3JsMy5kaWdpY2VydC5jb20vRGlnaUNlcnRHbG9i\n" + "YWxSb290Q0EuY3JsMGMGA1UdIARcMFowNwYJYIZIAYb9bAECMCowKAYIKwYBBQUH\n" + "AgEWHGh0dHBzOi8vd3d3LmRpZ2ljZXJ0LmNvbS9DUFMwCwYJYIZIAYb9bAEBMAgG\n" + "BmeBDAECATAIBgZngQwBAgIwDQYJKoZIhvcNAQELBQADggEBAH4jx/LKNW5ZklFc\n" + "YWs8Ejbm0nyzKeZC2KOVYR7P8gevKyslWm4Xo4BSzKr235FsJ4aFt6yAiv1eY0tZ\n" + "/ZN18bOGSGStoEc/JE4ocIzr8P5Mg11kRYHbmgYnr1Rxeki5mSeb39DGxTpJD4kG\n" + "hs5lXNoo4conUiiJwKaqH7vh2baryd8pMISag83JUqyVGc2tWPpO0329/CWq2kry\n" + "qv66OSMjwulUz0dXf4OHQasR7CNfIr+4KScc6ABlQ5RDF86PGeE6kdwSQkFiB/cQ\n" + "ysNyq0jEDQTkfa2pjmuWtMCNbBnhFXBYejfubIhaUbEv2FOQB3dCav+FPg5eEveX\n" + "TVyMnGo=\n" + "-----END CERTIFICATE-----\n"; // You can use x.509 client certificates if you want //const char* test_client_key = ""; //to verify the client //const char* test_client_cert = ""; //to verify the client @@ -67,24 +67,24 @@ void setup() { Serial.print("Connecting to network: "); Serial.println(ssid); WiFi.disconnect(true); //disconnect form wifi to set new wifi connection - WiFi.mode(WIFI_STA); //init wifi mode -#if __has_include ("esp_eap_client.h") - esp_eap_client_set_identity((uint8_t *)EAP_ANONYMOUS_IDENTITY, strlen(EAP_ANONYMOUS_IDENTITY)); //provide identity - esp_eap_client_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username - esp_eap_client_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password + WiFi.mode(WIFI_STA); //init wifi mode +#if __has_include("esp_eap_client.h") + esp_eap_client_set_identity((uint8_t*)EAP_ANONYMOUS_IDENTITY, strlen(EAP_ANONYMOUS_IDENTITY)); //provide identity + esp_eap_client_set_username((uint8_t*)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username + esp_eap_client_set_password((uint8_t*)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password esp_wifi_sta_enterprise_enable(); #else - esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_ANONYMOUS_IDENTITY, strlen(EAP_ANONYMOUS_IDENTITY)); //provide identity - esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username - esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password + esp_wifi_sta_wpa2_ent_set_identity((uint8_t*)EAP_ANONYMOUS_IDENTITY, strlen(EAP_ANONYMOUS_IDENTITY)); //provide identity + esp_wifi_sta_wpa2_ent_set_username((uint8_t*)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username + esp_wifi_sta_wpa2_ent_set_password((uint8_t*)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password esp_wifi_sta_wpa2_ent_enable(); #endif - WiFi.begin(ssid); //connect to wifi + WiFi.begin(ssid); //connect to wifi while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); counter++; - if (counter >= 60) { //after 30 seconds timeout - reset board (on unsucessful connection) + if (counter >= 60) { //after 30 seconds timeout - reset board (on unsuccessful connection) ESP.restart(); } } @@ -94,21 +94,21 @@ void setup() { Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address set: "); - Serial.println(WiFi.localIP()); //print LAN IP + Serial.println(WiFi.localIP()); //print LAN IP } void loop() { - if (WiFi.status() == WL_CONNECTED) { //if we are connected to eduroam network - counter = 0; //reset counter + if (WiFi.status() == WL_CONNECTED) { //if we are connected to eduroam network + counter = 0; //reset counter Serial.println("Wifi is still connected with IP: "); - Serial.println(WiFi.localIP()); //inform user about his IP address - } else if (WiFi.status() != WL_CONNECTED) { //if we lost connection, retry + Serial.println(WiFi.localIP()); //inform user about his IP address + } else if (WiFi.status() != WL_CONNECTED) { //if we lost connection, retry WiFi.begin(ssid); } - while (WiFi.status() != WL_CONNECTED) { //during lost connection, print dots + while (WiFi.status() != WL_CONNECTED) { //during lost connection, print dots delay(500); Serial.print("."); counter++; - if (counter >= 60) { //30 seconds timeout - reset board + if (counter >= 60) { //30 seconds timeout - reset board ESP.restart(); } } @@ -127,7 +127,7 @@ void loop() { String line = client.readStringUntil('\n'); Serial.println(line); } else { - Serial.println("Connection unsucessful"); + Serial.println("Connection unsuccessful"); } delay(5000); } diff --git a/libraries/NetworkClientSecure/examples/WiFiClientSecureProtocolUpgrade/WiFiClientSecureProtocolUpgrade.ino b/libraries/NetworkClientSecure/examples/WiFiClientSecureProtocolUpgrade/WiFiClientSecureProtocolUpgrade.ino index ddf00895357..318db998cb8 100644 --- a/libraries/NetworkClientSecure/examples/WiFiClientSecureProtocolUpgrade/WiFiClientSecureProtocolUpgrade.ino +++ b/libraries/NetworkClientSecure/examples/WiFiClientSecureProtocolUpgrade/WiFiClientSecureProtocolUpgrade.ino @@ -2,11 +2,11 @@ Inline upgrading from a clear-text connection to an SSL/TLS connection. - Some protocols such as SMTP, XMPP, Mysql, Postgress and others allow, or require, + Some protocols such as SMTP, XMPP, Mysql, Postgresql and others allow, or require, that you start the connection without encryption; and then send a command to switch over to encryption. - E.g. a typical SMTP submission would entail a dialogue such as this: + E.g. a typical SMTP submission would entail a dialog such as this: 1. client connects to server in the clear 2. server says hello @@ -46,13 +46,13 @@ #endif #ifndef SMTP_PORT -#define SMTP_PORT (587) // Standard (plaintext) submission port +#define SMTP_PORT (587) // Standard (plaintext) submission port #endif -const char* ssid = WIFI_NETWORK; // your network SSID (name of wifi network) -const char* password = WIFI_PASSWD; // your network password -const char* server = SMTP_HOST; // Server URL -const int submission_port = SMTP_PORT; // submission port. +const char* ssid = WIFI_NETWORK; // your network SSID (name of wifi network) +const char* password = WIFI_PASSWD; // your network password +const char* server = SMTP_HOST; // Server URL +const int submission_port = SMTP_PORT; // submission port. NetworkClientSecure client; @@ -108,7 +108,7 @@ void setup() { if (!readAllSMTPLines()) goto err; Serial.println("Upgrading connection to TLS"); - if ((ret=client.startTLS()) <= 0) { + if ((ret = client.startTLS()) <= 0) { Serial.printf("Upgrade connection failed: err %d\n", ret); goto err; } @@ -120,7 +120,7 @@ void setup() { // normally, as this point - we'd be authenticating and then be submitting // an email. This has been left out of this example. - + Serial.println("Sending : QUIT\t\t\tover the now encrypted connection"); client.print("QUIT\r\n"); @@ -142,7 +142,7 @@ static bool readAllSMTPLines() { // of a NetworkClientSecure read; as it is non // blocking. const unsigned long timeout = 15 * 1000; - unsigned long start = millis(); // the timeout is for the entire CMD block response; not per character/line. + unsigned long start = millis(); // the timeout is for the entire CMD block response; not per character/line. while (1) { while ((i = client.available()) == 0 && millis() - start < timeout) { /* .. wait */ @@ -174,4 +174,3 @@ static bool readAllSMTPLines() { void loop() { // do nothing } - diff --git a/libraries/NetworkClientSecure/examples/WiFiClientShowPeerCredentials/WiFiClientShowPeerCredentials.ino b/libraries/NetworkClientSecure/examples/WiFiClientShowPeerCredentials/WiFiClientShowPeerCredentials.ino index 9ec50ab57e1..59129738c1a 100644 --- a/libraries/NetworkClientSecure/examples/WiFiClientShowPeerCredentials/WiFiClientShowPeerCredentials.ino +++ b/libraries/NetworkClientSecure/examples/WiFiClientShowPeerCredentials/WiFiClientShowPeerCredentials.ino @@ -3,7 +3,7 @@ // Example of a establishing a secure connection and then // showing the fingerprint of the certificate. This can // be useful in an IoT setting to know for sure that you -// are connecting to the right server. Especally in +// are connecting to the right server. Especially in // situations where you cannot hardcode a trusted root // certificate for long periods of time (as they tend to // get replaced more often than the lifecycle of IoT @@ -25,11 +25,11 @@ #define URL "https://arduino.cc" void demo() { - NetworkClientSecure *client = new NetworkClientSecure; - client->setInsecure(); // + NetworkClientSecure* client = new NetworkClientSecure; + client->setInsecure(); // HTTPClient https; - if (!https.begin(*client, URL )) { + if (!https.begin(*client, URL)) { Serial.println("HTTPS setup failed"); return; }; @@ -48,7 +48,7 @@ void demo() { // Show general output / certificate information // char buf[1024]; - int l = mbedtls_x509_crt_info (buf, sizeof(buf), "", peer); + int l = mbedtls_x509_crt_info(buf, sizeof(buf), "", peer); if (l <= 0) { Serial.println("Peer conversion to printable buffer failed"); return; @@ -63,7 +63,7 @@ void demo() { } // Fingerprint late 2021 Serial.println("Expecting Fingerprint (SHA256): 70 CF A4 B7 5D 09 E9 2A 52 A8 B6 85 B5 0B D6 BE 83 47 83 5B 3A 4D 3C 3E 32 30 EC 1D 61 98 D7 0F"); - Serial.print( " Received Fingerprint (SHA256): "); + Serial.print(" Received Fingerprint (SHA256): "); for (int i = 0; i < 32; i++) { Serial.print(fingerprint_remote[i], HEX); diff --git a/libraries/NetworkClientSecure/examples/WiFiClientTrustOnFirstUse/WiFiClientTrustOnFirstUse.ino b/libraries/NetworkClientSecure/examples/WiFiClientTrustOnFirstUse/WiFiClientTrustOnFirstUse.ino index 497f456d53f..5807157defa 100644 --- a/libraries/NetworkClientSecure/examples/WiFiClientTrustOnFirstUse/WiFiClientTrustOnFirstUse.ino +++ b/libraries/NetworkClientSecure/examples/WiFiClientTrustOnFirstUse/WiFiClientTrustOnFirstUse.ino @@ -7,7 +7,7 @@ https://medium.com/@munteanu210/ssl-certificates-vs-man-in-the-middle-attacks-3fb7846fa5db for some background on this. - Unfortunatley this means that one needs to hardcode a server + Unfortunately this means that one needs to hardcode a server public key, certificate or some cryptographically strong hash thereoff into the code, to verify that you are indeed talking to the right server. This is sometimes somewhat impractical. Especially @@ -48,8 +48,8 @@ #define WIFI_PASSWD "your-secret-wifi-password" #endif -const char* ssid = WIFI_NETWORK; // your network SSID (name of wifi network) -const char* password = WIFI_PASSWD; // your network password +const char* ssid = WIFI_NETWORK; // your network SSID (name of wifi network) +const char* password = WIFI_PASSWD; // your network password const char* server = "www.howsmyssl.com"; // Server to test with. const int TOFU_RESET_BUTTON = 35; /* Trust reset button wired between GPIO 35 and GND (pulldown) */ @@ -58,21 +58,22 @@ const int TOFU_RESET_BUTTON = 35; /* Trust reset button wired between GPIO 35 an #include #include -/* Set aside some persistant memory (i.e. memory that is preserved on reboots and +/* Set aside some persistent memory (i.e. memory that is preserved on reboots and power cycling; and will generally survive software updates as well. */ EEPROMClass TOFU("tofu0"); -// Utility function; checks if a given buffer is entirly +// Utility function; checks if a given buffer is entirely // with with 0 bytes over its full length. Returns 0 on -// succes; a non zero value on fail. +// success; a non zero value on fail. // -static int memcmpzero(unsigned char * ptr, size_t len) { - while (len--) if (0xff != *ptr++) return -1; +static int memcmpzero(unsigned char* ptr, size_t len) { + while (len--) + if (0xff != *ptr++) return -1; return 0; }; -static void printSHA256(unsigned char * ptr) { +static void printSHA256(unsigned char* ptr) { for (int i = 0; i < 32; i++) Serial.printf("%s%02x", i ? ":" : "", ptr[i]); Serial.println(""); }; @@ -80,7 +81,7 @@ static void printSHA256(unsigned char * ptr) { NetworkClientSecure client; bool get_tofu(); -bool doTOFU_Protected_Connection(uint8_t * fingerprint_tofu); +bool doTOFU_Protected_Connection(uint8_t* fingerprint_tofu); void setup() { bool tofu_reset = false; @@ -119,7 +120,7 @@ void setup() { Serial.print("TOFU pegged to fingerprint: SHA256="); printSHA256(fingerprint_tofu); Serial.print("Note: You can check this fingerprint by going to the URL\n" - " and then click on the lock icon.\n"); }; @@ -156,7 +157,7 @@ void setup() { bool get_tofu() { Serial.println("\nStarting our insecure connection to server..."); - client.setInsecure();//skip verification + client.setInsecure(); //skip verification if (!client.connect(server, 443)) { Serial.println("Connection failed!"); @@ -190,9 +191,7 @@ bool get_tofu() { return false; } if ( - (32 != TOFU.writeBytes(0, fingerprint_remote, 32)) || - (!TOFU.commit()) - ) { + (32 != TOFU.writeBytes(0, fingerprint_remote, 32)) || (!TOFU.commit())) { Serial.println("Could not write the fingerprint to the EEPROM"); client.stop(); return false; @@ -206,12 +205,12 @@ bool get_tofu() { return true; }; -bool doTOFU_Protected_Connection(uint8_t * fingerprint_tofu) { +bool doTOFU_Protected_Connection(uint8_t* fingerprint_tofu) { // As we're not using a (CA) certificate to check the // connection; but the hash of the peer - we need to initially // allow the connection to be set up without the CA check. - client.setInsecure();//skip verification + client.setInsecure(); //skip verification if (!client.connect(server, 443)) { Serial.println("Connection failed!"); @@ -244,7 +243,8 @@ bool doTOFU_Protected_Connection(uint8_t * fingerprint_tofu) { "when you set up TOFU. So we can now do a GET.\n\n"); client.println("GET /a/check HTTP/1.0"); - client.print("Host: " ); client.println(server); + client.print("Host: "); + client.println(server); client.println("Connection: close"); client.println(); diff --git a/libraries/NetworkClientSecure/src/NetworkClientSecure.cpp b/libraries/NetworkClientSecure/src/NetworkClientSecure.cpp index 83af76867db..3570ed2a904 100644 --- a/libraries/NetworkClientSecure/src/NetworkClientSecure.cpp +++ b/libraries/NetworkClientSecure/src/NetworkClientSecure.cpp @@ -29,346 +29,320 @@ #undef read -NetworkClientSecure::NetworkClientSecure() -{ - _connected = false; - _timeout = 30000; // Same default as ssl_client - - sslclient = new sslclient_context; - ssl_init(sslclient); - sslclient->socket = -1; - sslclient->handshake_timeout = 120000; - _use_insecure = false; - _CA_cert = NULL; - _cert = NULL; - _private_key = NULL; - _pskIdent = NULL; - _psKey = NULL; - next = NULL; - _alpn_protos = NULL; - _use_ca_bundle = false; -} - - -NetworkClientSecure::NetworkClientSecure(int sock) -{ - _connected = false; - _timeout = 30000; // Same default as ssl_client - _lastReadTimeout = 0; - _lastWriteTimeout = 0; - - sslclient = new sslclient_context; - ssl_init(sslclient); - sslclient->socket = sock; - sslclient->handshake_timeout = 120000; - - if (sock >= 0) { - _connected = true; - } +NetworkClientSecure::NetworkClientSecure() { + _connected = false; + _timeout = 30000; // Same default as ssl_client + + sslclient = new sslclient_context; + ssl_init(sslclient); + sslclient->socket = -1; + sslclient->handshake_timeout = 120000; + _use_insecure = false; + _CA_cert = NULL; + _cert = NULL; + _private_key = NULL; + _pskIdent = NULL; + _psKey = NULL; + next = NULL; + _alpn_protos = NULL; + _use_ca_bundle = false; +} + + +NetworkClientSecure::NetworkClientSecure(int sock) { + _connected = false; + _timeout = 30000; // Same default as ssl_client + _lastReadTimeout = 0; + _lastWriteTimeout = 0; + + sslclient = new sslclient_context; + ssl_init(sslclient); + sslclient->socket = sock; + sslclient->handshake_timeout = 120000; + + if (sock >= 0) { + _connected = true; + } - _CA_cert = NULL; - _cert = NULL; - _private_key = NULL; - _pskIdent = NULL; - _psKey = NULL; - next = NULL; - _alpn_protos = NULL; + _CA_cert = NULL; + _cert = NULL; + _private_key = NULL; + _pskIdent = NULL; + _psKey = NULL; + next = NULL; + _alpn_protos = NULL; } -NetworkClientSecure::~NetworkClientSecure() -{ - stop(); - delete sslclient; +NetworkClientSecure::~NetworkClientSecure() { + stop(); + delete sslclient; } -NetworkClientSecure &NetworkClientSecure::operator=(const NetworkClientSecure &other) -{ - stop(); - sslclient->socket = other.sslclient->socket; - _connected = other._connected; - return *this; +NetworkClientSecure &NetworkClientSecure::operator=(const NetworkClientSecure &other) { + stop(); + sslclient->socket = other.sslclient->socket; + _connected = other._connected; + return *this; } -void NetworkClientSecure::stop() -{ - stop_ssl_socket(sslclient, _CA_cert, _cert, _private_key); +void NetworkClientSecure::stop() { + stop_ssl_socket(sslclient, _CA_cert, _cert, _private_key); - _connected = false; - _peek = -1; - _lastReadTimeout = 0; - _lastWriteTimeout = 0; + _connected = false; + _peek = -1; + _lastReadTimeout = 0; + _lastWriteTimeout = 0; } -int NetworkClientSecure::connect(IPAddress ip, uint16_t port) -{ - if (_pskIdent && _psKey) - return connect(ip, port, _pskIdent, _psKey); - return connect(ip, port, _CA_cert, _cert, _private_key); +int NetworkClientSecure::connect(IPAddress ip, uint16_t port) { + if (_pskIdent && _psKey) + return connect(ip, port, _pskIdent, _psKey); + return connect(ip, port, _CA_cert, _cert, _private_key); } -int NetworkClientSecure::connect(IPAddress ip, uint16_t port, int32_t timeout){ - _timeout = timeout; - return connect(ip, port); +int NetworkClientSecure::connect(IPAddress ip, uint16_t port, int32_t timeout) { + _timeout = timeout; + return connect(ip, port); } -int NetworkClientSecure::connect(const char *host, uint16_t port) -{ - if (_pskIdent && _psKey) - return connect(host, port, _pskIdent, _psKey); - return connect(host, port, _CA_cert, _cert, _private_key); +int NetworkClientSecure::connect(const char *host, uint16_t port) { + if (_pskIdent && _psKey) + return connect(host, port, _pskIdent, _psKey); + return connect(host, port, _CA_cert, _cert, _private_key); } -int NetworkClientSecure::connect(const char *host, uint16_t port, int32_t timeout){ - _timeout = timeout; - return connect(host, port); +int NetworkClientSecure::connect(const char *host, uint16_t port, int32_t timeout) { + _timeout = timeout; + return connect(host, port); } -int NetworkClientSecure::connect(IPAddress ip, uint16_t port, const char *CA_cert, const char *cert, const char *private_key) -{ - return connect(ip, port, NULL, CA_cert, cert, private_key); +int NetworkClientSecure::connect(IPAddress ip, uint16_t port, const char *CA_cert, const char *cert, const char *private_key) { + return connect(ip, port, NULL, CA_cert, cert, private_key); } -int NetworkClientSecure::connect(const char *host, uint16_t port, const char *CA_cert, const char *cert, const char *private_key) -{ - IPAddress address; - if (!Network.hostByName(host, address)) - return 0; +int NetworkClientSecure::connect(const char *host, uint16_t port, const char *CA_cert, const char *cert, const char *private_key) { + IPAddress address; + if (!Network.hostByName(host, address)) + return 0; - return connect(address, port, host, CA_cert, cert, private_key); + return connect(address, port, host, CA_cert, cert, private_key); } -int NetworkClientSecure::connect(IPAddress ip, uint16_t port, const char *host, const char *CA_cert, const char *cert, const char *private_key) -{ - int ret = start_ssl_client(sslclient, ip, port, host, _timeout, CA_cert, _use_ca_bundle, cert, private_key, NULL, NULL, _use_insecure, _alpn_protos); +int NetworkClientSecure::connect(IPAddress ip, uint16_t port, const char *host, const char *CA_cert, const char *cert, const char *private_key) { + int ret = start_ssl_client(sslclient, ip, port, host, _timeout, CA_cert, _use_ca_bundle, cert, private_key, NULL, NULL, _use_insecure, _alpn_protos); - if (ret >=0 && ! _stillinPlainStart) - ret = ssl_starttls_handshake(sslclient); - else - log_i("Actual TLS start posponed."); + if (ret >= 0 && !_stillinPlainStart) + ret = ssl_starttls_handshake(sslclient); + else + log_i("Actual TLS start postponed."); - _lastError = ret; + _lastError = ret; + if (ret < 0) { + log_e("start_ssl_client: connect failed: %d", ret); + stop(); + return 0; + } + _connected = true; + return 1; +} + +int NetworkClientSecure::startTLS() { + int ret = 1; + if (_stillinPlainStart) { + log_i("startTLS: starting TLS/SSL on this dplain connection"); + ret = ssl_starttls_handshake(sslclient); if (ret < 0) { - log_e("start_ssl_client: connect failed: %d", ret); - stop(); - return 0; - } - _connected = true; - return 1; -} - -int NetworkClientSecure::startTLS() -{ - int ret = 1; - if (_stillinPlainStart) { - log_i("startTLS: starting TLS/SSL on this dplain connection"); - ret = ssl_starttls_handshake(sslclient); - if (ret < 0) { - log_e("startTLS: %d", ret); - stop(); - return 0; - }; - _stillinPlainStart = false; - } else - log_i("startTLS: ignoring StartTLS - as we should be secure already"); - return 1; + log_e("startTLS: %d", ret); + stop(); + return 0; + }; + _stillinPlainStart = false; + } else + log_i("startTLS: ignoring StartTLS - as we should be secure already"); + return 1; } int NetworkClientSecure::connect(IPAddress ip, uint16_t port, const char *pskIdent, const char *psKey) { - return connect(ip.toString().c_str(), port, pskIdent, psKey); + return connect(ip.toString().c_str(), port, pskIdent, psKey); } int NetworkClientSecure::connect(const char *host, uint16_t port, const char *pskIdent, const char *psKey) { - log_v("start_ssl_client with PSK"); + log_v("start_ssl_client with PSK"); - IPAddress address; - if (!Network.hostByName(host, address)) - return 0; + IPAddress address; + if (!Network.hostByName(host, address)) + return 0; - int ret = start_ssl_client(sslclient, address, port, host, _timeout, NULL, false, NULL, NULL, pskIdent, psKey, _use_insecure, _alpn_protos); - _lastError = ret; - if (ret < 0) { - log_e("start_ssl_client: connect failed %d", ret); - stop(); - return 0; - } - _connected = true; - return 1; + int ret = start_ssl_client(sslclient, address, port, host, _timeout, NULL, false, NULL, NULL, pskIdent, psKey, _use_insecure, _alpn_protos); + _lastError = ret; + if (ret < 0) { + log_e("start_ssl_client: connect failed %d", ret); + stop(); + return 0; + } + _connected = true; + return 1; } -int NetworkClientSecure::peek(){ - if(_peek >= 0){ - return _peek; - } - _peek = timedRead(); +int NetworkClientSecure::peek() { + if (_peek >= 0) { return _peek; + } + _peek = timedRead(); + return _peek; } -size_t NetworkClientSecure::write(uint8_t data) -{ - return write(&data, 1); +size_t NetworkClientSecure::write(uint8_t data) { + return write(&data, 1); } -int NetworkClientSecure::read() -{ - uint8_t data = -1; - int res = read(&data, 1); - return res < 0 ? res: data; +int NetworkClientSecure::read() { + uint8_t data = -1; + int res = read(&data, 1); + return res < 0 ? res : data; } -size_t NetworkClientSecure::write(const uint8_t *buf, size_t size) -{ - if (!_connected) { - return 0; - } +size_t NetworkClientSecure::write(const uint8_t *buf, size_t size) { + if (!_connected) { + return 0; + } - if (_stillinPlainStart) - return send_net_data(sslclient, buf, size); - - if(_lastWriteTimeout != _timeout){ - struct timeval timeout_tv; - timeout_tv.tv_sec = _timeout / 1000; - timeout_tv.tv_usec = (_timeout % 1000) * 1000; - if(setSocketOption(SO_SNDTIMEO, (char *)&timeout_tv, sizeof(struct timeval)) >= 0) - { - _lastWriteTimeout = _timeout; - } - } - int res = send_ssl_data(sslclient, buf, size); - if (res < 0) { - log_e("Closing connection on failed write"); - stop(); - res = 0; - } - return res; -} - -int NetworkClientSecure::read(uint8_t *buf, size_t size) -{ - if(_stillinPlainStart) - return get_net_receive(sslclient, buf, size); - - if(_lastReadTimeout != _timeout){ - if(fd() >= 0){ - struct timeval timeout_tv; - timeout_tv.tv_sec = _timeout / 1000; - timeout_tv.tv_usec = (_timeout % 1000) * 1000; - if(setSocketOption(SO_RCVTIMEO, (char *)&timeout_tv, sizeof(struct timeval)) >= 0) - { - _lastReadTimeout = _timeout; - } - } - } + if (_stillinPlainStart) + return send_net_data(sslclient, buf, size); - int peeked = 0, res = -1; - int avail = available(); - if ((!buf && size) || avail <= 0) { - return -1; - } - if(!size){ - return 0; + if (_lastWriteTimeout != _timeout) { + struct timeval timeout_tv; + timeout_tv.tv_sec = _timeout / 1000; + timeout_tv.tv_usec = (_timeout % 1000) * 1000; + if (setSocketOption(SO_SNDTIMEO, (char *)&timeout_tv, sizeof(struct timeval)) >= 0) { + _lastWriteTimeout = _timeout; } - if(_peek >= 0){ - buf[0] = _peek; - _peek = -1; - size--; - avail--; - if(!size || !avail){ - return 1; - } - buf++; - peeked = 1; + } + int res = send_ssl_data(sslclient, buf, size); + if (res < 0) { + log_e("Closing connection on failed write"); + stop(); + res = 0; + } + return res; +} + +int NetworkClientSecure::read(uint8_t *buf, size_t size) { + if (_stillinPlainStart) + return get_net_receive(sslclient, buf, size); + + if (_lastReadTimeout != _timeout) { + if (fd() >= 0) { + struct timeval timeout_tv; + timeout_tv.tv_sec = _timeout / 1000; + timeout_tv.tv_usec = (_timeout % 1000) * 1000; + if (setSocketOption(SO_RCVTIMEO, (char *)&timeout_tv, sizeof(struct timeval)) >= 0) { + _lastReadTimeout = _timeout; + } } - res = get_ssl_receive(sslclient, buf, size); + } - if (res < 0) { - log_e("Closing connection on failed read"); - stop(); - return peeked?peeked:res; + int peeked = 0, res = -1; + int avail = available(); + if ((!buf && size) || avail <= 0) { + return -1; + } + if (!size) { + return 0; + } + if (_peek >= 0) { + buf[0] = _peek; + _peek = -1; + size--; + avail--; + if (!size || !avail) { + return 1; } - return res + peeked; + buf++; + peeked = 1; + } + res = get_ssl_receive(sslclient, buf, size); + + if (res < 0) { + log_e("Closing connection on failed read"); + stop(); + return peeked ? peeked : res; + } + return res + peeked; } -int NetworkClientSecure::available() -{ - if (_stillinPlainStart) - return peek_net_receive(sslclient,0); +int NetworkClientSecure::available() { + if (_stillinPlainStart) + return peek_net_receive(sslclient, 0); - int peeked = (_peek >= 0), res = -1; - if (!_connected) { - return peeked; - } - res = data_to_read(sslclient); + int peeked = (_peek >= 0), res = -1; + if (!_connected) { + return peeked; + } + res = data_to_read(sslclient); - if (res < 0 && !_stillinPlainStart) { - log_e("Closing connection on failed available check"); - stop(); - return peeked?peeked:res; - } - return res+peeked; + if (res < 0 && !_stillinPlainStart) { + log_e("Closing connection on failed available check"); + stop(); + return peeked ? peeked : res; + } + return res + peeked; } -uint8_t NetworkClientSecure::connected() -{ - uint8_t dummy = 0; - read(&dummy, 0); +uint8_t NetworkClientSecure::connected() { + uint8_t dummy = 0; + read(&dummy, 0); - return _connected; + return _connected; } -void NetworkClientSecure::setInsecure() -{ - _CA_cert = NULL; - _cert = NULL; - _private_key = NULL; - _pskIdent = NULL; - _psKey = NULL; - _use_insecure = true; +void NetworkClientSecure::setInsecure() { + _CA_cert = NULL; + _cert = NULL; + _private_key = NULL; + _pskIdent = NULL; + _psKey = NULL; + _use_insecure = true; } -void NetworkClientSecure::setCACert (const char *rootCA) -{ - _CA_cert = rootCA; - _use_insecure = false; +void NetworkClientSecure::setCACert(const char *rootCA) { + _CA_cert = rootCA; + _use_insecure = false; } - void NetworkClientSecure::setCACertBundle(const uint8_t * bundle) - { - if (bundle != NULL) - { - esp_crt_bundle_set(bundle, sizeof(bundle)); - _use_ca_bundle = true; - } else { - esp_crt_bundle_detach(NULL); - _use_ca_bundle = false; - } - } +void NetworkClientSecure::setCACertBundle(const uint8_t *bundle) { + if (bundle != NULL) { + esp_crt_bundle_set(bundle, sizeof(bundle)); + _use_ca_bundle = true; + } else { + esp_crt_bundle_detach(NULL); + _use_ca_bundle = false; + } +} -void NetworkClientSecure::setCertificate (const char *client_ca) -{ - _cert = client_ca; +void NetworkClientSecure::setCertificate(const char *client_ca) { + _cert = client_ca; } -void NetworkClientSecure::setPrivateKey (const char *private_key) -{ - _private_key = private_key; +void NetworkClientSecure::setPrivateKey(const char *private_key) { + _private_key = private_key; } void NetworkClientSecure::setPreSharedKey(const char *pskIdent, const char *psKey) { - _pskIdent = pskIdent; - _psKey = psKey; + _pskIdent = pskIdent; + _psKey = psKey; } -bool NetworkClientSecure::verify(const char* fp, const char* domain_name) -{ - if (!sslclient) - return false; +bool NetworkClientSecure::verify(const char *fp, const char *domain_name) { + if (!sslclient) + return false; - return verify_ssl_fingerprint(sslclient, fp, domain_name); + return verify_ssl_fingerprint(sslclient, fp, domain_name); } -char *NetworkClientSecure::_streamLoad(Stream& stream, size_t size) { - char *dest = (char*)malloc(size+1); +char *NetworkClientSecure::_streamLoad(Stream &stream, size_t size) { + char *dest = (char *)malloc(size + 1); if (!dest) { return nullptr; } @@ -381,8 +355,8 @@ char *NetworkClientSecure::_streamLoad(Stream& stream, size_t size) { return dest; } -bool NetworkClientSecure::loadCACert(Stream& stream, size_t size) { - if (_CA_cert != NULL) free(const_cast(_CA_cert)); +bool NetworkClientSecure::loadCACert(Stream &stream, size_t size) { + if (_CA_cert != NULL) free(const_cast(_CA_cert)); char *dest = _streamLoad(stream, size); bool ret = false; if (dest) { @@ -392,8 +366,8 @@ bool NetworkClientSecure::loadCACert(Stream& stream, size_t size) { return ret; } -bool NetworkClientSecure::loadCertificate(Stream& stream, size_t size) { - if (_cert != NULL) free(const_cast(_cert)); +bool NetworkClientSecure::loadCertificate(Stream &stream, size_t size) { + if (_cert != NULL) free(const_cast(_cert)); char *dest = _streamLoad(stream, size); bool ret = false; if (dest) { @@ -403,8 +377,8 @@ bool NetworkClientSecure::loadCertificate(Stream& stream, size_t size) { return ret; } -bool NetworkClientSecure::loadPrivateKey(Stream& stream, size_t size) { - if (_private_key != NULL) free(const_cast(_private_key)); +bool NetworkClientSecure::loadPrivateKey(Stream &stream, size_t size) { + if (_private_key != NULL) free(const_cast(_private_key)); char *dest = _streamLoad(stream, size); bool ret = false; if (dest) { @@ -414,27 +388,22 @@ bool NetworkClientSecure::loadPrivateKey(Stream& stream, size_t size) { return ret; } -int NetworkClientSecure::lastError(char *buf, const size_t size) -{ - if (!_lastError) { - return 0; - } - mbedtls_strerror(_lastError, buf, size); - return _lastError; +int NetworkClientSecure::lastError(char *buf, const size_t size) { + if (!_lastError) { + return 0; + } + mbedtls_strerror(_lastError, buf, size); + return _lastError; } -void NetworkClientSecure::setHandshakeTimeout(unsigned long handshake_timeout) -{ - sslclient->handshake_timeout = handshake_timeout * 1000; +void NetworkClientSecure::setHandshakeTimeout(unsigned long handshake_timeout) { + sslclient->handshake_timeout = handshake_timeout * 1000; } -void NetworkClientSecure::setAlpnProtocols(const char **alpn_protos) -{ - _alpn_protos = alpn_protos; +void NetworkClientSecure::setAlpnProtocols(const char **alpn_protos) { + _alpn_protos = alpn_protos; } -int NetworkClientSecure::fd() const -{ - return sslclient->socket; +int NetworkClientSecure::fd() const { + return sslclient->socket; } - diff --git a/libraries/NetworkClientSecure/src/NetworkClientSecure.h b/libraries/NetworkClientSecure/src/NetworkClientSecure.h index e6ce9e9f290..17240820b77 100644 --- a/libraries/NetworkClientSecure/src/NetworkClientSecure.h +++ b/libraries/NetworkClientSecure/src/NetworkClientSecure.h @@ -25,104 +25,106 @@ #include "Network.h" #include "ssl_client.h" -class NetworkClientSecure : public NetworkClient -{ +class NetworkClientSecure : public NetworkClient { protected: - sslclient_context *sslclient; - - int _lastError = 0; - int _peek = -1; - int _timeout; - bool _use_insecure; - bool _stillinPlainStart = false; - const char *_CA_cert; - const char *_cert; - const char *_private_key; - const char *_pskIdent; // identity for PSK cipher suites - const char *_psKey; // key in hex for PSK cipher suites - const char **_alpn_protos; - bool _use_ca_bundle; + sslclient_context *sslclient; + + int _lastError = 0; + int _peek = -1; + int _timeout; + bool _use_insecure; + bool _stillinPlainStart = false; + const char *_CA_cert; + const char *_cert; + const char *_private_key; + const char *_pskIdent; // identity for PSK cipher suites + const char *_psKey; // key in hex for PSK cipher suites + const char **_alpn_protos; + bool _use_ca_bundle; public: - NetworkClientSecure *next; - NetworkClientSecure(); - NetworkClientSecure(int socket); - ~NetworkClientSecure(); - int connect(IPAddress ip, uint16_t port); - int connect(IPAddress ip, uint16_t port, int32_t timeout); - int connect(const char *host, uint16_t port); - int connect(const char *host, uint16_t port, int32_t timeout); - int connect(IPAddress ip, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key); - int connect(const char *host, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key); - int connect(IPAddress ip, uint16_t port, const char *pskIdent, const char *psKey); - int connect(const char *host, uint16_t port, const char *pskIdent, const char *psKey); - int connect(IPAddress ip, uint16_t port, const char *host, const char *CA_cert, const char *cert, const char *private_key); - int peek(); - size_t write(uint8_t data); - size_t write(const uint8_t *buf, size_t size); - int available(); - int read(); - int read(uint8_t *buf, size_t size); - void flush() {} - void stop(); - uint8_t connected(); - int lastError(char *buf, const size_t size); - void setInsecure(); // Don't validate the chain, just accept whatever is given. VERY INSECURE! - void setPreSharedKey(const char *pskIdent, const char *psKey); // psKey in Hex - void setCACert(const char *rootCA); - void setCertificate(const char *client_ca); - void setPrivateKey (const char *private_key); - bool loadCACert(Stream& stream, size_t size); - void setCACertBundle(const uint8_t * bundle); - bool loadCertificate(Stream& stream, size_t size); - bool loadPrivateKey(Stream& stream, size_t size); - bool verify(const char* fingerprint, const char* domain_name); - void setHandshakeTimeout(unsigned long handshake_timeout); - void setAlpnProtocols(const char **alpn_protos); + NetworkClientSecure *next; + NetworkClientSecure(); + NetworkClientSecure(int socket); + ~NetworkClientSecure(); + int connect(IPAddress ip, uint16_t port); + int connect(IPAddress ip, uint16_t port, int32_t timeout); + int connect(const char *host, uint16_t port); + int connect(const char *host, uint16_t port, int32_t timeout); + int connect(IPAddress ip, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key); + int connect(const char *host, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key); + int connect(IPAddress ip, uint16_t port, const char *pskIdent, const char *psKey); + int connect(const char *host, uint16_t port, const char *pskIdent, const char *psKey); + int connect(IPAddress ip, uint16_t port, const char *host, const char *CA_cert, const char *cert, const char *private_key); + int peek(); + size_t write(uint8_t data); + size_t write(const uint8_t *buf, size_t size); + int available(); + int read(); + int read(uint8_t *buf, size_t size); + void flush() {} + void stop(); + uint8_t connected(); + int lastError(char *buf, const size_t size); + void setInsecure(); // Don't validate the chain, just accept whatever is given. VERY INSECURE! + void setPreSharedKey(const char *pskIdent, const char *psKey); // psKey in Hex + void setCACert(const char *rootCA); + void setCertificate(const char *client_ca); + void setPrivateKey(const char *private_key); + bool loadCACert(Stream &stream, size_t size); + void setCACertBundle(const uint8_t *bundle); + bool loadCertificate(Stream &stream, size_t size); + bool loadPrivateKey(Stream &stream, size_t size); + bool verify(const char *fingerprint, const char *domain_name); + void setHandshakeTimeout(unsigned long handshake_timeout); + void setAlpnProtocols(const char **alpn_protos); + + // Certain protocols start in plain-text; and then have the client + // give some STARTSSL command to `upgrade' the connection to TLS + // or SSL. Setting PlainStart to true (the default is false) enables + // this. It is up to the application code to then call 'startTLS()' + // at the right point to initialize the SSL or TLS upgrade. - // Certain protocols start in plain-text; and then have the client - // give some STARTSSL command to `upgrade' the connection to TLS - // or SSL. Setting PlainStart to true (the default is false) enables - // this. It is up to the application code to then call 'startTLS()' - // at the right point to initialise the SSL or TLS upgrade. - - void setPlainStart() { _stillinPlainStart = true; }; - bool stillInPlainStart() { return _stillinPlainStart; }; - int startTLS(); + void setPlainStart() { + _stillinPlainStart = true; + }; + bool stillInPlainStart() { + return _stillinPlainStart; + }; + int startTLS(); - const mbedtls_x509_crt* getPeerCertificate() { return mbedtls_ssl_get_peer_cert(&sslclient->ssl_ctx); }; - bool getFingerprintSHA256(uint8_t sha256_result[32]) { return get_peer_fingerprint(sslclient, sha256_result); }; - int fd() const; + const mbedtls_x509_crt *getPeerCertificate() { + return mbedtls_ssl_get_peer_cert(&sslclient->ssl_ctx); + }; + bool getFingerprintSHA256(uint8_t sha256_result[32]) { + return get_peer_fingerprint(sslclient, sha256_result); + }; + int fd() const; - operator bool() - { - return connected(); - } - NetworkClientSecure &operator=(const NetworkClientSecure &other); - bool operator==(const bool value) - { - return bool() == value; - } - bool operator!=(const bool value) - { - return bool() != value; - } - bool operator==(const NetworkClientSecure &); - bool operator!=(const NetworkClientSecure &rhs) - { - return !this->operator==(rhs); - }; + operator bool() { + return connected(); + } + NetworkClientSecure &operator=(const NetworkClientSecure &other); + bool operator==(const bool value) { + return bool() == value; + } + bool operator!=(const bool value) { + return bool() != value; + } + bool operator==(const NetworkClientSecure &); + bool operator!=(const NetworkClientSecure &rhs) { + return !this->operator==(rhs); + }; - int socket() - { - return sslclient->socket = -1; - } + int socket() { + return sslclient->socket = -1; + } private: - char *_streamLoad(Stream& stream, size_t size); + char *_streamLoad(Stream &stream, size_t size); - //friend class NetworkServer; - using Print::write; + //friend class NetworkServer; + using Print::write; }; #endif /* _WIFICLIENT_H_ */ diff --git a/libraries/NetworkClientSecure/src/ssl_client.cpp b/libraries/NetworkClientSecure/src/ssl_client.cpp index 787dd69b311..644f058513a 100644 --- a/libraries/NetworkClientSecure/src/ssl_client.cpp +++ b/libraries/NetworkClientSecure/src/ssl_client.cpp @@ -20,392 +20,392 @@ #include "esp_crt_bundle.h" #if !defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED) -# warning "Please call `idf.py menuconfig` then go to Component config -> mbedTLS -> TLS Key Exchange Methods -> Enable pre-shared-key ciphersuites and then check `Enable PSK based cyphersuite modes`. Save and Quit." +#warning "Please call `idf.py menuconfig` then go to Component config -> mbedTLS -> TLS Key Exchange Methods -> Enable pre-shared-key ciphersuites and then check `Enable PSK based ciphersuite modes`. Save and Quit." #else const char *pers = "esp32-tls"; -static int _handle_error(int err, const char * function, int line) -{ - if(err == -30848){ - return err; - } +static int _handle_error(int err, const char *function, int line) { + if (err == -30848) { + return err; + } #ifdef MBEDTLS_ERROR_C - char error_buf[100]; - mbedtls_strerror(err, error_buf, 100); - log_e("[%s():%d]: (%d) %s", function, line, err, error_buf); + char error_buf[100]; + mbedtls_strerror(err, error_buf, 100); + log_e("[%s():%d]: (%d) %s", function, line, err, error_buf); #else - log_e("[%s():%d]: code %d", function, line, err); + log_e("[%s():%d]: code %d", function, line, err); #endif - return err; + return err; } #define handle_error(e) _handle_error(e, __FUNCTION__, __LINE__) -void ssl_init(sslclient_context *ssl_client) -{ - // reset embedded pointers to zero - memset(ssl_client, 0, sizeof(sslclient_context)); - mbedtls_ssl_init(&ssl_client->ssl_ctx); - mbedtls_ssl_config_init(&ssl_client->ssl_conf); - mbedtls_ctr_drbg_init(&ssl_client->drbg_ctx); +void ssl_init(sslclient_context *ssl_client) { + // reset embedded pointers to zero + memset(ssl_client, 0, sizeof(sslclient_context)); + mbedtls_ssl_init(&ssl_client->ssl_ctx); + mbedtls_ssl_config_init(&ssl_client->ssl_conf); + mbedtls_ctr_drbg_init(&ssl_client->drbg_ctx); } -int start_ssl_client(sslclient_context *ssl_client, const IPAddress& ip, uint32_t port, const char* hostname, int timeout, const char *rootCABuff, bool useRootCABundle, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure, const char **alpn_protos) -{ - int ret; - int enable = 1; - log_v("Free internal heap before TLS %u", ESP.getFreeHeap()); +int start_ssl_client(sslclient_context *ssl_client, const IPAddress &ip, uint32_t port, const char *hostname, int timeout, const char *rootCABuff, bool useRootCABundle, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure, const char **alpn_protos) { + int ret; + int enable = 1; + log_v("Free internal heap before TLS %u", ESP.getFreeHeap()); + + if (rootCABuff == NULL && pskIdent == NULL && psKey == NULL && !insecure && !useRootCABundle) { + return -1; + } + + int domain = ip.type() == IPv6 ? AF_INET6 : AF_INET; + log_v("Starting socket (domain %d)", domain); + ssl_client->socket = -1; - if (rootCABuff == NULL && pskIdent == NULL && psKey == NULL && !insecure && !useRootCABundle) { - return -1; + ssl_client->socket = lwip_socket(domain, SOCK_STREAM, IPPROTO_TCP); + if (ssl_client->socket < 0) { + log_e("ERROR opening socket"); + return ssl_client->socket; + } + + fcntl(ssl_client->socket, F_SETFL, fcntl(ssl_client->socket, F_GETFL, 0) | O_NONBLOCK); + struct sockaddr_storage serv_addr = {}; + if (domain == AF_INET6) { + struct sockaddr_in6 *tmpaddr = (struct sockaddr_in6 *)&serv_addr; + tmpaddr->sin6_family = AF_INET6; + for (int index = 0; index < 16; index++) { + tmpaddr->sin6_addr.s6_addr[index] = ip[index]; } + tmpaddr->sin6_port = htons(port); + tmpaddr->sin6_scope_id = ip.zone(); + } else { + struct sockaddr_in *tmpaddr = (struct sockaddr_in *)&serv_addr; + tmpaddr->sin_family = AF_INET; + tmpaddr->sin_addr.s_addr = ip; + tmpaddr->sin_port = htons(port); + } + + if (timeout <= 0) { + timeout = 30000; // Milli seconds. + } + + ssl_client->socket_timeout = timeout; + + fd_set fdset; + struct timeval tv; + FD_ZERO(&fdset); + FD_SET(ssl_client->socket, &fdset); + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout % 1000) * 1000; + + int res = lwip_connect(ssl_client->socket, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); + if (res < 0 && errno != EINPROGRESS) { + log_e("connect on fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno)); + lwip_close(ssl_client->socket); + ssl_client->socket = -1; + return -1; + } - int domain = ip.type() == IPv6 ? AF_INET6 : AF_INET; - log_v("Starting socket (domain %d)", domain); + res = select(ssl_client->socket + 1, nullptr, &fdset, nullptr, timeout < 0 ? nullptr : &tv); + if (res < 0) { + log_e("select on fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno)); + lwip_close(ssl_client->socket); + ssl_client->socket = -1; + return -1; + } else if (res == 0) { + log_i("select returned due to timeout %d ms for fd %d", timeout, ssl_client->socket); + lwip_close(ssl_client->socket); ssl_client->socket = -1; + return -1; + } else { + int sockerr; + socklen_t len = (socklen_t)sizeof(int); + res = getsockopt(ssl_client->socket, SOL_SOCKET, SO_ERROR, &sockerr, &len); - ssl_client->socket = lwip_socket(domain, SOCK_STREAM, IPPROTO_TCP); - if (ssl_client->socket < 0) { - log_e("ERROR opening socket"); - return ssl_client->socket; + if (res < 0) { + log_e("getsockopt on fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno)); + lwip_close(ssl_client->socket); + ssl_client->socket = -1; + return -1; } - fcntl( ssl_client->socket, F_SETFL, fcntl( ssl_client->socket, F_GETFL, 0 ) | O_NONBLOCK ); - struct sockaddr_storage serv_addr = {}; - if (domain == AF_INET6) { - struct sockaddr_in6 *tmpaddr = (struct sockaddr_in6 *)&serv_addr; - tmpaddr->sin6_family = AF_INET6; - for (int index = 0; index < 16; index++) { - tmpaddr->sin6_addr.s6_addr[index] = ip[index]; - } - tmpaddr->sin6_port = htons(port); - tmpaddr->sin6_scope_id = ip.zone(); - } else { - struct sockaddr_in *tmpaddr = (struct sockaddr_in *)&serv_addr; - tmpaddr->sin_family = AF_INET; - tmpaddr->sin_addr.s_addr = ip; - tmpaddr->sin_port = htons(port); + if (sockerr != 0) { + log_e("socket error on fd %d, errno: %d, \"%s\"", ssl_client->socket, sockerr, strerror(sockerr)); + lwip_close(ssl_client->socket); + ssl_client->socket = -1; + return -1; } + } - if(timeout <= 0){ - timeout = 30000; // Milli seconds. - } - ssl_client->socket_timeout = timeout; - - fd_set fdset; - struct timeval tv; - FD_ZERO(&fdset); - FD_SET(ssl_client->socket, &fdset); - tv.tv_sec = timeout / 1000; - tv.tv_usec = (timeout % 1000) * 1000; - - int res = lwip_connect(ssl_client->socket, (struct sockaddr*)&serv_addr, sizeof(serv_addr)); - if (res < 0 && errno != EINPROGRESS) { - log_e("connect on fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno)); - lwip_close(ssl_client->socket); - ssl_client->socket = -1; - return -1; - } +#define ROE(x, msg) \ + { \ + if (((x) < 0)) { \ + log_e("LWIP Socket config of " msg " failed."); \ + return -1; \ + } \ + } + ROE(lwip_setsockopt(ssl_client->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)), "SO_RCVTIMEO"); + ROE(lwip_setsockopt(ssl_client->socket, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)), "SO_SNDTIMEO"); - res = select(ssl_client->socket + 1, nullptr, &fdset, nullptr, timeout<0 ? nullptr : &tv); - if (res < 0) { - log_e("select on fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno)); - lwip_close(ssl_client->socket); - ssl_client->socket = -1; - return -1; - } else if (res == 0) { - log_i("select returned due to timeout %d ms for fd %d", timeout, ssl_client->socket); - lwip_close(ssl_client->socket); - ssl_client->socket = -1; - return -1; - } else { - int sockerr; - socklen_t len = (socklen_t)sizeof(int); - res = getsockopt(ssl_client->socket, SOL_SOCKET, SO_ERROR, &sockerr, &len); - - if (res < 0) { - log_e("getsockopt on fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno)); - lwip_close(ssl_client->socket); - ssl_client->socket = -1; - return -1; - } - - if (sockerr != 0) { - log_e("socket error on fd %d, errno: %d, \"%s\"", ssl_client->socket, sockerr, strerror(sockerr)); - lwip_close(ssl_client->socket); - ssl_client->socket = -1; - return -1; - } - } + ROE(lwip_setsockopt(ssl_client->socket, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable)), "TCP_NODELAY"); + ROE(lwip_setsockopt(ssl_client->socket, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable)), "SO_KEEPALIVE"); -#define ROE(x,msg) { if (((x)<0)) { log_e("LWIP Socket config of " msg " failed."); return -1; }} - ROE(lwip_setsockopt(ssl_client->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)),"SO_RCVTIMEO"); - ROE(lwip_setsockopt(ssl_client->socket, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)),"SO_SNDTIMEO"); - ROE(lwip_setsockopt(ssl_client->socket, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable)),"TCP_NODELAY"); - ROE(lwip_setsockopt(ssl_client->socket, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable)),"SO_KEEPALIVE"); + log_v("Seeding the random number generator"); + mbedtls_entropy_init(&ssl_client->entropy_ctx); + ret = mbedtls_ctr_drbg_seed(&ssl_client->drbg_ctx, mbedtls_entropy_func, + &ssl_client->entropy_ctx, (const unsigned char *)pers, strlen(pers)); + if (ret < 0) { + return handle_error(ret); + } + log_v("Setting up the SSL/TLS structure..."); - log_v("Seeding the random number generator"); - mbedtls_entropy_init(&ssl_client->entropy_ctx); + if ((ret = mbedtls_ssl_config_defaults(&ssl_client->ssl_conf, + MBEDTLS_SSL_IS_CLIENT, + MBEDTLS_SSL_TRANSPORT_STREAM, + MBEDTLS_SSL_PRESET_DEFAULT)) + != 0) { + return handle_error(ret); + } - ret = mbedtls_ctr_drbg_seed(&ssl_client->drbg_ctx, mbedtls_entropy_func, - &ssl_client->entropy_ctx, (const unsigned char *) pers, strlen(pers)); + if (alpn_protos != NULL) { + log_v("Setting ALPN protocols"); + if ((ret = mbedtls_ssl_conf_alpn_protocols(&ssl_client->ssl_conf, alpn_protos)) != 0) { + return handle_error(ret); + } + } + + // MBEDTLS_SSL_VERIFY_REQUIRED if a CA certificate is defined on Arduino IDE and + // MBEDTLS_SSL_VERIFY_NONE if not. + + if (insecure) { + mbedtls_ssl_conf_authmode(&ssl_client->ssl_conf, MBEDTLS_SSL_VERIFY_NONE); + log_d("WARNING: Skipping SSL Verification. INSECURE!"); + } else if (rootCABuff != NULL) { + log_v("Loading CA cert"); + mbedtls_x509_crt_init(&ssl_client->ca_cert); + mbedtls_ssl_conf_authmode(&ssl_client->ssl_conf, MBEDTLS_SSL_VERIFY_REQUIRED); + ret = mbedtls_x509_crt_parse(&ssl_client->ca_cert, (const unsigned char *)rootCABuff, strlen(rootCABuff) + 1); + mbedtls_ssl_conf_ca_chain(&ssl_client->ssl_conf, &ssl_client->ca_cert, NULL); + //mbedtls_ssl_conf_verify(&ssl_client->ssl_ctx, my_verify, NULL ); if (ret < 0) { - return handle_error(ret); + // free the ca_cert in the case parse failed, otherwise, the old ca_cert still in the heap memory, that lead to "out of memory" crash. + mbedtls_x509_crt_free(&ssl_client->ca_cert); + return handle_error(ret); } + } else if (useRootCABundle) { + log_v("Attaching root CA cert bundle"); + ret = esp_crt_bundle_attach(&ssl_client->ssl_conf); - log_v("Setting up the SSL/TLS structure..."); - - if ((ret = mbedtls_ssl_config_defaults(&ssl_client->ssl_conf, - MBEDTLS_SSL_IS_CLIENT, - MBEDTLS_SSL_TRANSPORT_STREAM, - MBEDTLS_SSL_PRESET_DEFAULT)) != 0) { - return handle_error(ret); + if (ret < 0) { + return handle_error(ret); } - - if (alpn_protos != NULL) { - log_v("Setting ALPN protocols"); - if ((ret = mbedtls_ssl_conf_alpn_protocols(&ssl_client->ssl_conf, alpn_protos) ) != 0) { - return handle_error(ret); - } + } else if (pskIdent != NULL && psKey != NULL) { + log_v("Setting up PSK"); + // convert PSK from hex to binary + if ((strlen(psKey) & 1) != 0 || strlen(psKey) > 2 * MBEDTLS_PSK_MAX_LEN) { + log_e("pre-shared key not valid hex or too long"); + return -1; } - - // MBEDTLS_SSL_VERIFY_REQUIRED if a CA certificate is defined on Arduino IDE and - // MBEDTLS_SSL_VERIFY_NONE if not. - - if (insecure) { - mbedtls_ssl_conf_authmode(&ssl_client->ssl_conf, MBEDTLS_SSL_VERIFY_NONE); - log_d("WARNING: Skipping SSL Verification. INSECURE!"); - } else if (rootCABuff != NULL) { - log_v("Loading CA cert"); - mbedtls_x509_crt_init(&ssl_client->ca_cert); - mbedtls_ssl_conf_authmode(&ssl_client->ssl_conf, MBEDTLS_SSL_VERIFY_REQUIRED); - ret = mbedtls_x509_crt_parse(&ssl_client->ca_cert, (const unsigned char *)rootCABuff, strlen(rootCABuff) + 1); - mbedtls_ssl_conf_ca_chain(&ssl_client->ssl_conf, &ssl_client->ca_cert, NULL); - //mbedtls_ssl_conf_verify(&ssl_client->ssl_ctx, my_verify, NULL ); - if (ret < 0) { - // free the ca_cert in the case parse failed, otherwise, the old ca_cert still in the heap memory, that lead to "out of memory" crash. - mbedtls_x509_crt_free(&ssl_client->ca_cert); - return handle_error(ret); - } - } else if (useRootCABundle) { - log_v("Attaching root CA cert bundle"); - ret = esp_crt_bundle_attach(&ssl_client->ssl_conf); - - if (ret < 0) { - return handle_error(ret); - } - } else if (pskIdent != NULL && psKey != NULL) { - log_v("Setting up PSK"); - // convert PSK from hex to binary - if ((strlen(psKey) & 1) != 0 || strlen(psKey) > 2*MBEDTLS_PSK_MAX_LEN) { - log_e("pre-shared key not valid hex or too long"); - return -1; - } - unsigned char psk[MBEDTLS_PSK_MAX_LEN]; - size_t psk_len = strlen(psKey)/2; - for (int j=0; j= '0' && c <= '9') c -= '0'; - else if (c >= 'A' && c <= 'F') c -= 'A' - 10; - else if (c >= 'a' && c <= 'f') c -= 'a' - 10; - else return -1; - psk[j/2] = c<<4; - c = psKey[j+1]; - if (c >= '0' && c <= '9') c -= '0'; - else if (c >= 'A' && c <= 'F') c -= 'A' - 10; - else if (c >= 'a' && c <= 'f') c -= 'a' - 10; - else return -1; - psk[j/2] |= c; - } - // set mbedtls config - ret = mbedtls_ssl_conf_psk(&ssl_client->ssl_conf, psk, psk_len, - (const unsigned char *)pskIdent, strlen(pskIdent)); - if (ret != 0) { - log_e("mbedtls_ssl_conf_psk returned %d", ret); - return handle_error(ret); - } - } else { - return -1; + unsigned char psk[MBEDTLS_PSK_MAX_LEN]; + size_t psk_len = strlen(psKey) / 2; + for (int j = 0; j < strlen(psKey); j += 2) { + char c = psKey[j]; + if (c >= '0' && c <= '9') c -= '0'; + else if (c >= 'A' && c <= 'F') c -= 'A' - 10; + else if (c >= 'a' && c <= 'f') c -= 'a' - 10; + else return -1; + psk[j / 2] = c << 4; + c = psKey[j + 1]; + if (c >= '0' && c <= '9') c -= '0'; + else if (c >= 'A' && c <= 'F') c -= 'A' - 10; + else if (c >= 'a' && c <= 'f') c -= 'a' - 10; + else return -1; + psk[j / 2] |= c; } - - // Note - this check for BOTH key and cert is relied on - // later during cleanup. - - if (!insecure && cli_cert != NULL && cli_key != NULL) { - mbedtls_x509_crt_init(&ssl_client->client_cert); - mbedtls_pk_init(&ssl_client->client_key); - - log_v("Loading CRT cert"); - - ret = mbedtls_x509_crt_parse(&ssl_client->client_cert, (const unsigned char *)cli_cert, strlen(cli_cert) + 1); - if (ret < 0) { - // free the client_cert in the case parse failed, otherwise, the old client_cert still in the heap memory, that lead to "out of memory" crash. - mbedtls_x509_crt_free(&ssl_client->client_cert); - return handle_error(ret); - } - - log_v("Loading private key"); - mbedtls_ctr_drbg_context ctr_drbg; - mbedtls_ctr_drbg_init( &ctr_drbg ); - ret = mbedtls_pk_parse_key(&ssl_client->client_key, (const unsigned char *)cli_key, strlen(cli_key) + 1, NULL, 0, mbedtls_ctr_drbg_random, &ctr_drbg); - mbedtls_ctr_drbg_free( &ctr_drbg ); - - if (ret != 0) { - mbedtls_x509_crt_free(&ssl_client->client_cert); // cert+key are free'd in pair - return handle_error(ret); - } - - mbedtls_ssl_conf_own_cert(&ssl_client->ssl_conf, &ssl_client->client_cert, &ssl_client->client_key); + // set mbedtls config + ret = mbedtls_ssl_conf_psk(&ssl_client->ssl_conf, psk, psk_len, + (const unsigned char *)pskIdent, strlen(pskIdent)); + if (ret != 0) { + log_e("mbedtls_ssl_conf_psk returned %d", ret); + return handle_error(ret); } + } else { + return -1; + } - log_v("Setting hostname for TLS session..."); + // Note - this check for BOTH key and cert is relied on + // later during cleanup. - // Hostname set here should match CN in server certificate - if((ret = mbedtls_ssl_set_hostname(&ssl_client->ssl_ctx, hostname != NULL ? hostname : ip.toString().c_str())) != 0){ - return handle_error(ret); - } + if (!insecure && cli_cert != NULL && cli_key != NULL) { + mbedtls_x509_crt_init(&ssl_client->client_cert); + mbedtls_pk_init(&ssl_client->client_key); - mbedtls_ssl_conf_rng(&ssl_client->ssl_conf, mbedtls_ctr_drbg_random, &ssl_client->drbg_ctx); + log_v("Loading CRT cert"); - if ((ret = mbedtls_ssl_setup(&ssl_client->ssl_ctx, &ssl_client->ssl_conf)) != 0) { - return handle_error(ret); + ret = mbedtls_x509_crt_parse(&ssl_client->client_cert, (const unsigned char *)cli_cert, strlen(cli_cert) + 1); + if (ret < 0) { + // free the client_cert in the case parse failed, otherwise, the old client_cert still in the heap memory, that lead to "out of memory" crash. + mbedtls_x509_crt_free(&ssl_client->client_cert); + return handle_error(ret); } - mbedtls_ssl_set_bio(&ssl_client->ssl_ctx, &ssl_client->socket, mbedtls_net_send, mbedtls_net_recv, NULL ); - return ssl_client->socket; -} + log_v("Loading private key"); + mbedtls_ctr_drbg_context ctr_drbg; + mbedtls_ctr_drbg_init(&ctr_drbg); + ret = mbedtls_pk_parse_key(&ssl_client->client_key, (const unsigned char *)cli_key, strlen(cli_key) + 1, NULL, 0, mbedtls_ctr_drbg_random, &ctr_drbg); + mbedtls_ctr_drbg_free(&ctr_drbg); -int ssl_starttls_handshake(sslclient_context *ssl_client) -{ - char buf[512]; - int ret, flags; - - log_v("Performing the SSL/TLS handshake..."); - unsigned long handshake_start_time=millis(); - while ((ret = mbedtls_ssl_handshake(&ssl_client->ssl_ctx)) != 0) { - if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) { - return handle_error(ret); - } - if((millis()-handshake_start_time)>ssl_client->handshake_timeout) - return -1; - vTaskDelay(2);//2 ticks + if (ret != 0) { + mbedtls_x509_crt_free(&ssl_client->client_cert); // cert+key are free'd in pair + return handle_error(ret); } + mbedtls_ssl_conf_own_cert(&ssl_client->ssl_conf, &ssl_client->client_cert, &ssl_client->client_key); + } + + log_v("Setting hostname for TLS session..."); + + // Hostname set here should match CN in server certificate + if ((ret = mbedtls_ssl_set_hostname(&ssl_client->ssl_ctx, hostname != NULL ? hostname : ip.toString().c_str())) != 0) { + return handle_error(ret); + } + + mbedtls_ssl_conf_rng(&ssl_client->ssl_conf, mbedtls_ctr_drbg_random, &ssl_client->drbg_ctx); + + if ((ret = mbedtls_ssl_setup(&ssl_client->ssl_ctx, &ssl_client->ssl_conf)) != 0) { + return handle_error(ret); + } - if (ssl_client->client_cert.version) { - log_d("Protocol is %s Ciphersuite is %s", mbedtls_ssl_get_version(&ssl_client->ssl_ctx), mbedtls_ssl_get_ciphersuite(&ssl_client->ssl_ctx)); - if ((ret = mbedtls_ssl_get_record_expansion(&ssl_client->ssl_ctx)) >= 0) { - log_d("Record expansion is %d", ret); - } else { - log_w("Record expansion is unknown (compression)"); - } + mbedtls_ssl_set_bio(&ssl_client->ssl_ctx, &ssl_client->socket, mbedtls_net_send, mbedtls_net_recv, NULL); + return ssl_client->socket; +} + +int ssl_starttls_handshake(sslclient_context *ssl_client) { + char buf[512]; + int ret, flags; + + log_v("Performing the SSL/TLS handshake..."); + unsigned long handshake_start_time = millis(); + while ((ret = mbedtls_ssl_handshake(&ssl_client->ssl_ctx)) != 0) { + if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) { + return handle_error(ret); } + if ((millis() - handshake_start_time) > ssl_client->handshake_timeout) + return -1; + vTaskDelay(2); //2 ticks + } - log_v("Verifying peer X.509 certificate..."); - if ((flags = mbedtls_ssl_get_verify_result(&ssl_client->ssl_ctx)) != 0) { - memset(buf, 0, sizeof(buf)); - mbedtls_x509_crt_verify_info(buf, sizeof(buf), " ! ", flags); - log_e("Failed to verify peer certificate! verification info: %s", buf); - return handle_error(ret); + if (ssl_client->client_cert.version) { + log_d("Protocol is %s Ciphersuite is %s", mbedtls_ssl_get_version(&ssl_client->ssl_ctx), mbedtls_ssl_get_ciphersuite(&ssl_client->ssl_ctx)); + if ((ret = mbedtls_ssl_get_record_expansion(&ssl_client->ssl_ctx)) >= 0) { + log_d("Record expansion is %d", ret); } else { - log_v("Certificate verified."); + log_w("Record expansion is unknown (compression)"); } - - if (ssl_client->ca_cert.version) { - mbedtls_x509_crt_free(&ssl_client->ca_cert); - } - - // We know that we always have a client cert/key pair -- and we - // cannot look into the private client_key pk struct for newer - // versions of mbedtls. So rely on a public field of the cert - // and infer that there is a key too. - if (ssl_client->client_cert.version) { - mbedtls_x509_crt_free(&ssl_client->client_cert); - mbedtls_pk_free(&ssl_client->client_key); - } + } + + log_v("Verifying peer X.509 certificate..."); + + if ((flags = mbedtls_ssl_get_verify_result(&ssl_client->ssl_ctx)) != 0) { + memset(buf, 0, sizeof(buf)); + mbedtls_x509_crt_verify_info(buf, sizeof(buf), " ! ", flags); + log_e("Failed to verify peer certificate! verification info: %s", buf); + return handle_error(ret); + } else { + log_v("Certificate verified."); + } + + if (ssl_client->ca_cert.version) { + mbedtls_x509_crt_free(&ssl_client->ca_cert); + } + + // We know that we always have a client cert/key pair -- and we + // cannot look into the private client_key pk struct for newer + // versions of mbedtls. So rely on a public field of the cert + // and infer that there is a key too. + if (ssl_client->client_cert.version) { + mbedtls_x509_crt_free(&ssl_client->client_cert); + mbedtls_pk_free(&ssl_client->client_key); + } + + log_v("Free internal heap after TLS %u", ESP.getFreeHeap()); + + return ssl_client->socket; +} - log_v("Free internal heap after TLS %u", ESP.getFreeHeap()); +void stop_ssl_socket(sslclient_context *ssl_client, const char *rootCABuff, const char *cli_cert, const char *cli_key) { + log_v("Cleaning SSL connection."); - return ssl_client->socket; + if (ssl_client->socket >= 0) { + lwip_close(ssl_client->socket); + ssl_client->socket = -1; + } + + // avoid memory leak if ssl connection attempt failed + // if (ssl_client->ssl_conf.ca_chain != NULL) { + mbedtls_x509_crt_free(&ssl_client->ca_cert); + // } + // if (ssl_client->ssl_conf.key_cert != NULL) { + mbedtls_x509_crt_free(&ssl_client->client_cert); + mbedtls_pk_free(&ssl_client->client_key); + // } + mbedtls_ssl_free(&ssl_client->ssl_ctx); + mbedtls_ssl_config_free(&ssl_client->ssl_conf); + mbedtls_ctr_drbg_free(&ssl_client->drbg_ctx); + mbedtls_entropy_free(&ssl_client->entropy_ctx); + + // save only interesting fields + int handshake_timeout = ssl_client->handshake_timeout; + int socket_timeout = ssl_client->socket_timeout; + + // reset embedded pointers to zero + memset(ssl_client, 0, sizeof(sslclient_context)); + + ssl_client->handshake_timeout = handshake_timeout; + ssl_client->socket_timeout = socket_timeout; } -void stop_ssl_socket(sslclient_context *ssl_client, const char *rootCABuff, const char *cli_cert, const char *cli_key) -{ - log_v("Cleaning SSL connection."); - if (ssl_client->socket >= 0) { - lwip_close(ssl_client->socket); - ssl_client->socket = -1; - } +int data_to_read(sslclient_context *ssl_client) { + int ret, res; + ret = mbedtls_ssl_read(&ssl_client->ssl_ctx, NULL, 0); + //log_e("RET: %i",ret); //for low level debug + res = mbedtls_ssl_get_bytes_avail(&ssl_client->ssl_ctx); + //log_e("RES: %i",res); //for low level debug + if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE && ret < 0) { + return handle_error(ret); + } - // avoid memory leak if ssl connection attempt failed - // if (ssl_client->ssl_conf.ca_chain != NULL) { - mbedtls_x509_crt_free(&ssl_client->ca_cert); - // } - // if (ssl_client->ssl_conf.key_cert != NULL) { - mbedtls_x509_crt_free(&ssl_client->client_cert); - mbedtls_pk_free(&ssl_client->client_key); - // } - mbedtls_ssl_free(&ssl_client->ssl_ctx); - mbedtls_ssl_config_free(&ssl_client->ssl_conf); - mbedtls_ctr_drbg_free(&ssl_client->drbg_ctx); - mbedtls_entropy_free(&ssl_client->entropy_ctx); - - // save only interesting fields - int handshake_timeout = ssl_client->handshake_timeout; - int socket_timeout = ssl_client->socket_timeout; - - // reset embedded pointers to zero - memset(ssl_client, 0, sizeof(sslclient_context)); - - ssl_client->handshake_timeout = handshake_timeout; - ssl_client->socket_timeout = socket_timeout; + return res; } +int send_ssl_data(sslclient_context *ssl_client, const uint8_t *data, size_t len) { + unsigned long write_start_time = millis(); + int ret = -1; -int data_to_read(sslclient_context *ssl_client) -{ - int ret, res; - ret = mbedtls_ssl_read(&ssl_client->ssl_ctx, NULL, 0); - //log_e("RET: %i",ret); //for low level debug - res = mbedtls_ssl_get_bytes_avail(&ssl_client->ssl_ctx); - //log_e("RES: %i",res); //for low level debug - if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE && ret < 0) { - return handle_error(ret); + while ((ret = mbedtls_ssl_write(&ssl_client->ssl_ctx, data, len)) <= 0) { + if ((millis() - write_start_time) > ssl_client->socket_timeout) { + log_v("SSL write timed out."); + return -1; } - return res; -} - -int send_ssl_data(sslclient_context *ssl_client, const uint8_t *data, size_t len) -{ - unsigned long write_start_time=millis(); - int ret = -1; - - while ((ret = mbedtls_ssl_write(&ssl_client->ssl_ctx, data, len)) <= 0) { - if((millis()-write_start_time)>ssl_client->socket_timeout) { - log_v("SSL write timed out."); - return -1; - } - - if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE && ret < 0) { - log_v("Handling error %d", ret); //for low level debug - return handle_error(ret); - } - - //wait for space to become available - vTaskDelay(2); + if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE && ret < 0) { + log_v("Handling error %d", ret); //for low level debug + return handle_error(ret); } - return ret; + //wait for space to become available + vTaskDelay(2); + } + + return ret; } // Some protocols, such as SMTP, XMPP, MySQL/Posgress and various others @@ -417,204 +417,195 @@ int send_ssl_data(sslclient_context *ssl_client, const uint8_t *data, size_t len // int peek_net_receive(sslclient_context *ssl_client, int timeout) { #if MBEDTLS_FIXED_LINKING_NET_POLL - int ret = mbedtls_net_poll((mbedtls_net_context*)ssl_client, MBEDTLS_NET_POLL_READ, timeout); - ret == MBEDTLS_NET_POLL_READ ? 1 : ret; + int ret = mbedtls_net_poll((mbedtls_net_context *)ssl_client, MBEDTLS_NET_POLL_READ, timeout); + ret == MBEDTLS_NET_POLL_READ ? 1 : ret; #else - // We should be using mbedtls_net_poll(); which is part of mbedtls and - // included in the EspressifSDK. Unfortunately - it did not make it into - // the statically linked library file. So, for now, we replace it by - // substancially similar code. - // - struct timeval tv = { .tv_sec = timeout / 1000, .tv_usec = (timeout % 1000) * 1000 }; - - fd_set fdset; - FD_SET(ssl_client->socket, &fdset); - - int ret = select(ssl_client->socket + 1, &fdset, nullptr, nullptr, timeout<0 ? nullptr : &tv); - if (ret < 0) { - log_e("select on read fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno)); - lwip_close(ssl_client->socket); - ssl_client->socket = -1; - return -1; - }; + // We should be using mbedtls_net_poll(); which is part of mbedtls and + // included in the EspressifSDK. Unfortunately - it did not make it into + // the statically linked library file. So, for now, we replace it by + // substancially similar code. + // + struct timeval tv = { .tv_sec = timeout / 1000, .tv_usec = (timeout % 1000) * 1000 }; + + fd_set fdset; + FD_SET(ssl_client->socket, &fdset); + + int ret = select(ssl_client->socket + 1, &fdset, nullptr, nullptr, timeout < 0 ? nullptr : &tv); + if (ret < 0) { + log_e("select on read fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno)); + lwip_close(ssl_client->socket); + ssl_client->socket = -1; + return -1; + }; #endif - return ret; + return ret; }; -int get_net_receive(sslclient_context *ssl_client, uint8_t *data, int length) -{ - int ret = peek_net_receive(ssl_client,ssl_client->socket_timeout); - if (ret > 0) - ret = mbedtls_net_recv(ssl_client, data, length); +int get_net_receive(sslclient_context *ssl_client, uint8_t *data, int length) { + int ret = peek_net_receive(ssl_client, ssl_client->socket_timeout); + if (ret > 0) + ret = mbedtls_net_recv(ssl_client, data, length); - // log_v( "%d bytes NET read of %d", ret, length); //for low level debug - return ret; + // log_v( "%d bytes NET read of %d", ret, length); //for low level debug + return ret; } int send_net_data(sslclient_context *ssl_client, const uint8_t *data, size_t len) { - int ret = mbedtls_net_send(ssl_client, data, len); - // log_v("Net sending %d btes->ret %d", len, ret); //for low level debug - return ret; + int ret = mbedtls_net_send(ssl_client, data, len); + // log_v("Net sending %d btes->ret %d", len, ret); //for low level debug + return ret; } -int get_ssl_receive(sslclient_context *ssl_client, uint8_t *data, int length) -{ - int ret = mbedtls_ssl_read(&ssl_client->ssl_ctx, data, length); - // log_v( "%d bytes SSL read", ret); //for low level debug - return ret; +int get_ssl_receive(sslclient_context *ssl_client, uint8_t *data, int length) { + int ret = mbedtls_ssl_read(&ssl_client->ssl_ctx, data, length); + // log_v( "%d bytes SSL read", ret); //for low level debug + return ret; } -static bool parseHexNibble(char pb, uint8_t* res) -{ - if (pb >= '0' && pb <= '9') { - *res = (uint8_t) (pb - '0'); return true; - } else if (pb >= 'a' && pb <= 'f') { - *res = (uint8_t) (pb - 'a' + 10); return true; - } else if (pb >= 'A' && pb <= 'F') { - *res = (uint8_t) (pb - 'A' + 10); return true; - } - return false; +static bool parseHexNibble(char pb, uint8_t *res) { + if (pb >= '0' && pb <= '9') { + *res = (uint8_t)(pb - '0'); + return true; + } else if (pb >= 'a' && pb <= 'f') { + *res = (uint8_t)(pb - 'a' + 10); + return true; + } else if (pb >= 'A' && pb <= 'F') { + *res = (uint8_t)(pb - 'A' + 10); + return true; + } + return false; } // Compare a name from certificate and domain name, return true if they match -static bool matchName(const std::string& name, const std::string& domainName) -{ - size_t wildcardPos = name.find('*'); - if (wildcardPos == std::string::npos) { - // Not a wildcard, expect an exact match - return name == domainName; - } - - size_t firstDotPos = name.find('.'); - if (wildcardPos > firstDotPos) { - // Wildcard is not part of leftmost component of domain name - // Do not attempt to match (rfc6125 6.4.3.1) - return false; - } - if (wildcardPos != 0 || firstDotPos != 1) { - // Matching of wildcards such as baz*.example.com and b*z.example.com - // is optional. Maybe implement this in the future? - return false; - } - size_t domainNameFirstDotPos = domainName.find('.'); - if (domainNameFirstDotPos == std::string::npos) { - return false; - } - return domainName.substr(domainNameFirstDotPos) == name.substr(firstDotPos); +static bool matchName(const std::string &name, const std::string &domainName) { + size_t wildcardPos = name.find('*'); + if (wildcardPos == std::string::npos) { + // Not a wildcard, expect an exact match + return name == domainName; + } + + size_t firstDotPos = name.find('.'); + if (wildcardPos > firstDotPos) { + // Wildcard is not part of leftmost component of domain name + // Do not attempt to match (rfc6125 6.4.3.1) + return false; + } + if (wildcardPos != 0 || firstDotPos != 1) { + // Matching of wildcards such as baz*.example.com and b*z.example.com + // is optional. Maybe implement this in the future? + return false; + } + size_t domainNameFirstDotPos = domainName.find('.'); + if (domainNameFirstDotPos == std::string::npos) { + return false; + } + return domainName.substr(domainNameFirstDotPos) == name.substr(firstDotPos); } // Verifies certificate provided by the peer to match specified SHA256 fingerprint -bool verify_ssl_fingerprint(sslclient_context *ssl_client, const char* fp, const char* domain_name) -{ - // Convert hex string to byte array - uint8_t fingerprint_local[32]; - int len = strlen(fp); - int pos = 0; - for (size_t i = 0; i < sizeof(fingerprint_local); ++i) { - while (pos < len && ((fp[pos] == ' ') || (fp[pos] == ':'))) { - ++pos; - } - if (pos > len - 2) { - log_d("pos:%d len:%d fingerprint too short", pos, len); - return false; - } - uint8_t high, low; - if (!parseHexNibble(fp[pos], &high) || !parseHexNibble(fp[pos+1], &low)) { - log_d("pos:%d len:%d invalid hex sequence: %c%c", pos, len, fp[pos], fp[pos+1]); - return false; - } - pos += 2; - fingerprint_local[i] = low | (high << 4); +bool verify_ssl_fingerprint(sslclient_context *ssl_client, const char *fp, const char *domain_name) { + // Convert hex string to byte array + uint8_t fingerprint_local[32]; + int len = strlen(fp); + int pos = 0; + for (size_t i = 0; i < sizeof(fingerprint_local); ++i) { + while (pos < len && ((fp[pos] == ' ') || (fp[pos] == ':'))) { + ++pos; + } + if (pos > len - 2) { + log_d("pos:%d len:%d fingerprint too short", pos, len); + return false; + } + uint8_t high, low; + if (!parseHexNibble(fp[pos], &high) || !parseHexNibble(fp[pos + 1], &low)) { + log_d("pos:%d len:%d invalid hex sequence: %c%c", pos, len, fp[pos], fp[pos + 1]); + return false; } + pos += 2; + fingerprint_local[i] = low | (high << 4); + } - // Calculate certificate's SHA256 fingerprint - uint8_t fingerprint_remote[32]; - if(!get_peer_fingerprint(ssl_client, fingerprint_remote)) - return false; + // Calculate certificate's SHA256 fingerprint + uint8_t fingerprint_remote[32]; + if (!get_peer_fingerprint(ssl_client, fingerprint_remote)) + return false; - // Check if fingerprints match - if (memcmp(fingerprint_local, fingerprint_remote, 32)) - { - log_d("fingerprint doesn't match"); - return false; - } + // Check if fingerprints match + if (memcmp(fingerprint_local, fingerprint_remote, 32)) { + log_d("fingerprint doesn't match"); + return false; + } - // Additionally check if certificate has domain name if provided - if (domain_name) - return verify_ssl_dn(ssl_client, domain_name); - else - return true; + // Additionally check if certificate has domain name if provided + if (domain_name) + return verify_ssl_dn(ssl_client, domain_name); + else + return true; } -bool get_peer_fingerprint(sslclient_context *ssl_client, uint8_t sha256[32]) -{ - if (!ssl_client) { - log_d("Invalid ssl_client pointer"); - return false; - }; - - const mbedtls_x509_crt* crt = mbedtls_ssl_get_peer_cert(&ssl_client->ssl_ctx); - if (!crt) { - log_d("Failed to get peer cert."); - return false; - }; - - mbedtls_sha256_context sha256_ctx; - mbedtls_sha256_init(&sha256_ctx); - mbedtls_sha256_starts(&sha256_ctx, false); - mbedtls_sha256_update(&sha256_ctx, crt->raw.p, crt->raw.len); - mbedtls_sha256_finish(&sha256_ctx, sha256); +bool get_peer_fingerprint(sslclient_context *ssl_client, uint8_t sha256[32]) { + if (!ssl_client) { + log_d("Invalid ssl_client pointer"); + return false; + }; - return true; + const mbedtls_x509_crt *crt = mbedtls_ssl_get_peer_cert(&ssl_client->ssl_ctx); + if (!crt) { + log_d("Failed to get peer cert."); + return false; + }; + + mbedtls_sha256_context sha256_ctx; + mbedtls_sha256_init(&sha256_ctx); + mbedtls_sha256_starts(&sha256_ctx, false); + mbedtls_sha256_update(&sha256_ctx, crt->raw.p, crt->raw.len); + mbedtls_sha256_finish(&sha256_ctx, sha256); + + return true; } // Checks if peer certificate has specified domain in CN or SANs -bool verify_ssl_dn(sslclient_context *ssl_client, const char* domain_name) -{ - log_d("domain name: '%s'", (domain_name)?domain_name:"(null)"); - std::string domain_name_str(domain_name); - std::transform(domain_name_str.begin(), domain_name_str.end(), domain_name_str.begin(), ::tolower); +bool verify_ssl_dn(sslclient_context *ssl_client, const char *domain_name) { + log_d("domain name: '%s'", (domain_name) ? domain_name : "(null)"); + std::string domain_name_str(domain_name); + std::transform(domain_name_str.begin(), domain_name_str.end(), domain_name_str.begin(), ::tolower); - // Get certificate provided by the peer - const mbedtls_x509_crt* crt = mbedtls_ssl_get_peer_cert(&ssl_client->ssl_ctx); + // Get certificate provided by the peer + const mbedtls_x509_crt *crt = mbedtls_ssl_get_peer_cert(&ssl_client->ssl_ctx); - // Check for domain name in SANs - const mbedtls_x509_sequence* san = &crt->subject_alt_names; - while (san != nullptr) - { - std::string san_str((const char*)san->buf.p, san->buf.len); - std::transform(san_str.begin(), san_str.end(), san_str.begin(), ::tolower); + // Check for domain name in SANs + const mbedtls_x509_sequence *san = &crt->subject_alt_names; + while (san != nullptr) { + std::string san_str((const char *)san->buf.p, san->buf.len); + std::transform(san_str.begin(), san_str.end(), san_str.begin(), ::tolower); - if (matchName(san_str, domain_name_str)) - return true; + if (matchName(san_str, domain_name_str)) + return true; - log_d("SAN '%s': no match", san_str.c_str()); - - // Fetch next SAN - san = san->next; - } + log_d("SAN '%s': no match", san_str.c_str()); - // Check for domain name in CN - const mbedtls_asn1_named_data* common_name = &crt->subject; - while (common_name != nullptr) - { - // While iterating through DN objects, check for CN object - if (!MBEDTLS_OID_CMP(MBEDTLS_OID_AT_CN, &common_name->oid)) - { - std::string common_name_str((const char*)common_name->val.p, common_name->val.len); + // Fetch next SAN + san = san->next; + } - if (matchName(common_name_str, domain_name_str)) - return true; + // Check for domain name in CN + const mbedtls_asn1_named_data *common_name = &crt->subject; + while (common_name != nullptr) { + // While iterating through DN objects, check for CN object + if (!MBEDTLS_OID_CMP(MBEDTLS_OID_AT_CN, &common_name->oid)) { + std::string common_name_str((const char *)common_name->val.p, common_name->val.len); - log_d("CN '%s': not match", common_name_str.c_str()); - } + if (matchName(common_name_str, domain_name_str)) + return true; - // Fetch next DN object - common_name = common_name->next; + log_d("CN '%s': not match", common_name_str.c_str()); } - return false; + // Fetch next DN object + common_name = common_name->next; + } + + return false; } #endif - diff --git a/libraries/NetworkClientSecure/src/ssl_client.h b/libraries/NetworkClientSecure/src/ssl_client.h index f42ad534139..bd46288c743 100644 --- a/libraries/NetworkClientSecure/src/ssl_client.h +++ b/libraries/NetworkClientSecure/src/ssl_client.h @@ -13,24 +13,24 @@ #include "mbedtls/error.h" typedef struct sslclient_context { - int socket; - mbedtls_ssl_context ssl_ctx; - mbedtls_ssl_config ssl_conf; + int socket; + mbedtls_ssl_context ssl_ctx; + mbedtls_ssl_config ssl_conf; - mbedtls_ctr_drbg_context drbg_ctx; - mbedtls_entropy_context entropy_ctx; + mbedtls_ctr_drbg_context drbg_ctx; + mbedtls_entropy_context entropy_ctx; - mbedtls_x509_crt ca_cert; - mbedtls_x509_crt client_cert; - mbedtls_pk_context client_key; + mbedtls_x509_crt ca_cert; + mbedtls_x509_crt client_cert; + mbedtls_pk_context client_key; - unsigned long socket_timeout; - unsigned long handshake_timeout; + unsigned long socket_timeout; + unsigned long handshake_timeout; } sslclient_context; void ssl_init(sslclient_context *ssl_client); -int start_ssl_client(sslclient_context *ssl_client, const IPAddress& ip, uint32_t port, const char* hostname, int timeout, const char *rootCABuff, bool useRootCABundle, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure, const char **alpn_protos); +int start_ssl_client(sslclient_context *ssl_client, const IPAddress &ip, uint32_t port, const char *hostname, int timeout, const char *rootCABuff, bool useRootCABundle, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure, const char **alpn_protos); int ssl_starttls_handshake(sslclient_context *ssl_client); void stop_ssl_socket(sslclient_context *ssl_client, const char *rootCABuff, const char *cli_cert, const char *cli_key); int data_to_read(sslclient_context *ssl_client); @@ -39,7 +39,7 @@ int get_ssl_receive(sslclient_context *ssl_client, uint8_t *data, int length); int send_net_data(sslclient_context *ssl_client, const uint8_t *data, size_t len); int get_net_receive(sslclient_context *ssl_client, uint8_t *data, int length); int peek_net_receive(sslclient_context *ssl_client, int timeout); -bool verify_ssl_fingerprint(sslclient_context *ssl_client, const char* fp, const char* domain_name); -bool verify_ssl_dn(sslclient_context *ssl_client, const char* domain_name); +bool verify_ssl_fingerprint(sslclient_context *ssl_client, const char *fp, const char *domain_name); +bool verify_ssl_dn(sslclient_context *ssl_client, const char *domain_name); bool get_peer_fingerprint(sslclient_context *ssl_client, uint8_t sha256[32]); #endif diff --git a/libraries/Preferences/examples/Prefs2Struct/Prefs2Struct.ino b/libraries/Preferences/examples/Prefs2Struct/Prefs2Struct.ino index 7ed2a73bcbe..8357dac8b59 100644 --- a/libraries/Preferences/examples/Prefs2Struct/Prefs2Struct.ino +++ b/libraries/Preferences/examples/Prefs2Struct/Prefs2Struct.ino @@ -1,9 +1,9 @@ /* This example shows how to use Preferences (nvs) to store a structure. Note that the maximum size of a putBytes is 496K -or 97% of the nvs partition size. nvs has signifcant overhead, +or 97% of the nvs partition size. nvs has significant overhead, so should not be used for data that will change often. -*/ +*/ #include Preferences prefs; @@ -16,28 +16,28 @@ typedef struct { void setup() { Serial.begin(115200); - prefs.begin("schedule"); // use "schedule" namespace - uint8_t content[] = {9, 30, 235, 255, 20, 15, 0, 1}; // two entries + prefs.begin("schedule"); // use "schedule" namespace + uint8_t content[] = { 9, 30, 235, 255, 20, 15, 0, 1 }; // two entries prefs.putBytes("schedule", content, sizeof(content)); size_t schLen = prefs.getBytesLength("schedule"); - char buffer[schLen]; // prepare a buffer for the data + char buffer[schLen]; // prepare a buffer for the data prefs.getBytes("schedule", buffer, schLen); - if (schLen % sizeof(schedule_t)) { // simple check that data fits + if (schLen % sizeof(schedule_t)) { // simple check that data fits log_e("Data is not correct size!"); return; } - schedule_t *schedule = (schedule_t *) buffer; // cast the bytes into a struct ptr - Serial.printf("%02d:%02d %d/%d\n", - schedule[1].hour, schedule[1].minute, - schedule[1].setting1, schedule[1].setting2); - schedule[2] = {8, 30, 20, 21}; // add a third entry (unsafely) -// force the struct array into a byte array - prefs.putBytes("schedule", schedule, 3*sizeof(schedule_t)); + schedule_t *schedule = (schedule_t *)buffer; // cast the bytes into a struct ptr + Serial.printf("%02d:%02d %d/%d\n", + schedule[1].hour, schedule[1].minute, + schedule[1].setting1, schedule[1].setting2); + schedule[2] = { 8, 30, 20, 21 }; // add a third entry (unsafely) + // force the struct array into a byte array + prefs.putBytes("schedule", schedule, 3 * sizeof(schedule_t)); schLen = prefs.getBytesLength("schedule"); char buffer2[schLen]; prefs.getBytes("schedule", buffer2, schLen); - for (int x=0; xESP_ERR_NVS_BASE)?nvs_errors[(e)&~(ESP_ERR_NVS_BASE)]:nvs_errors[0]) +const char* nvs_errors[] = { "OTHER", "NOT_INITIALIZED", "NOT_FOUND", "TYPE_MISMATCH", "READ_ONLY", "NOT_ENOUGH_SPACE", "INVALID_NAME", "INVALID_HANDLE", "REMOVE_FAILED", "KEY_TOO_LONG", "PAGE_FULL", "INVALID_STATE", "INVALID_LENGTH" }; +#define nvs_error(e) (((e) > ESP_ERR_NVS_BASE) ? nvs_errors[(e) & ~(ESP_ERR_NVS_BASE)] : nvs_errors[0]) Preferences::Preferences() - :_handle(0) - ,_started(false) - ,_readOnly(false) -{} - -Preferences::~Preferences(){ - end(); -} - -bool Preferences::begin(const char * name, bool readOnly, const char* partition_label){ - if(_started){ - return false; - } - _readOnly = readOnly; - esp_err_t err = ESP_OK; - if (partition_label != NULL) { - err = nvs_flash_init_partition(partition_label); - if (err) { - log_e("nvs_flash_init_partition failed: %s", nvs_error(err)); - return false; - } - err = nvs_open_from_partition(partition_label, name, readOnly ? NVS_READONLY : NVS_READWRITE, &_handle); - } else { - err = nvs_open(name, readOnly ? NVS_READONLY : NVS_READWRITE, &_handle); - } - if(err){ - log_e("nvs_open failed: %s", nvs_error(err)); - return false; - } - _started = true; - return true; -} - -void Preferences::end(){ - if(!_started){ - return; - } - nvs_close(_handle); - _started = false; + : _handle(0), _started(false), _readOnly(false) {} + +Preferences::~Preferences() { + end(); +} + +bool Preferences::begin(const char* name, bool readOnly, const char* partition_label) { + if (_started) { + return false; + } + _readOnly = readOnly; + esp_err_t err = ESP_OK; + if (partition_label != NULL) { + err = nvs_flash_init_partition(partition_label); + if (err) { + log_e("nvs_flash_init_partition failed: %s", nvs_error(err)); + return false; + } + err = nvs_open_from_partition(partition_label, name, readOnly ? NVS_READONLY : NVS_READWRITE, &_handle); + } else { + err = nvs_open(name, readOnly ? NVS_READONLY : NVS_READWRITE, &_handle); + } + if (err) { + log_e("nvs_open failed: %s", nvs_error(err)); + return false; + } + _started = true; + return true; +} + +void Preferences::end() { + if (!_started) { + return; + } + nvs_close(_handle); + _started = false; } /* * Clear all keys in opened preferences * */ -bool Preferences::clear(){ - if(!_started || _readOnly){ - return false; - } - esp_err_t err = nvs_erase_all(_handle); - if(err){ - log_e("nvs_erase_all fail: %s", nvs_error(err)); - return false; - } - err = nvs_commit(_handle); - if(err){ - log_e("nvs_commit fail: %s", nvs_error(err)); - return false; - } - return true; +bool Preferences::clear() { + if (!_started || _readOnly) { + return false; + } + esp_err_t err = nvs_erase_all(_handle); + if (err) { + log_e("nvs_erase_all fail: %s", nvs_error(err)); + return false; + } + err = nvs_commit(_handle); + if (err) { + log_e("nvs_commit fail: %s", nvs_error(err)); + return false; + } + return true; } /* * Remove a key * */ -bool Preferences::remove(const char * key){ - if(!_started || !key || _readOnly){ - return false; - } - esp_err_t err = nvs_erase_key(_handle, key); - if(err){ - log_e("nvs_erase_key fail: %s %s", key, nvs_error(err)); - return false; - } - err = nvs_commit(_handle); - if(err){ - log_e("nvs_commit fail: %s %s", key, nvs_error(err)); - return false; - } - return true; +bool Preferences::remove(const char* key) { + if (!_started || !key || _readOnly) { + return false; + } + esp_err_t err = nvs_erase_key(_handle, key); + if (err) { + log_e("nvs_erase_key fail: %s %s", key, nvs_error(err)); + return false; + } + err = nvs_commit(_handle); + if (err) { + log_e("nvs_commit fail: %s %s", key, nvs_error(err)); + return false; + } + return true; } /* * Put a key value * */ -size_t Preferences::putChar(const char* key, int8_t value){ - if(!_started || !key || _readOnly){ - return 0; - } - esp_err_t err = nvs_set_i8(_handle, key, value); - if(err){ - log_e("nvs_set_i8 fail: %s %s", key, nvs_error(err)); - return 0; - } - err = nvs_commit(_handle); - if(err){ - log_e("nvs_commit fail: %s %s", key, nvs_error(err)); - return 0; - } - return 1; -} - -size_t Preferences::putUChar(const char* key, uint8_t value){ - if(!_started || !key || _readOnly){ - return 0; - } - esp_err_t err = nvs_set_u8(_handle, key, value); - if(err){ - log_e("nvs_set_u8 fail: %s %s", key, nvs_error(err)); - return 0; - } - err = nvs_commit(_handle); - if(err){ - log_e("nvs_commit fail: %s %s", key, nvs_error(err)); - return 0; - } - return 1; -} - -size_t Preferences::putShort(const char* key, int16_t value){ - if(!_started || !key || _readOnly){ - return 0; - } - esp_err_t err = nvs_set_i16(_handle, key, value); - if(err){ - log_e("nvs_set_i16 fail: %s %s", key, nvs_error(err)); - return 0; - } - err = nvs_commit(_handle); - if(err){ - log_e("nvs_commit fail: %s %s", key, nvs_error(err)); - return 0; - } - return 2; -} - -size_t Preferences::putUShort(const char* key, uint16_t value){ - if(!_started || !key || _readOnly){ - return 0; - } - esp_err_t err = nvs_set_u16(_handle, key, value); - if(err){ - log_e("nvs_set_u16 fail: %s %s", key, nvs_error(err)); - return 0; - } - err = nvs_commit(_handle); - if(err){ - log_e("nvs_commit fail: %s %s", key, nvs_error(err)); - return 0; - } - return 2; -} - -size_t Preferences::putInt(const char* key, int32_t value){ - if(!_started || !key || _readOnly){ - return 0; - } - esp_err_t err = nvs_set_i32(_handle, key, value); - if(err){ - log_e("nvs_set_i32 fail: %s %s", key, nvs_error(err)); - return 0; - } - err = nvs_commit(_handle); - if(err){ - log_e("nvs_commit fail: %s %s", key, nvs_error(err)); - return 0; - } - return 4; -} - -size_t Preferences::putUInt(const char* key, uint32_t value){ - if(!_started || !key || _readOnly){ - return 0; - } - esp_err_t err = nvs_set_u32(_handle, key, value); - if(err){ - log_e("nvs_set_u32 fail: %s %s", key, nvs_error(err)); - return 0; - } - err = nvs_commit(_handle); - if(err){ - log_e("nvs_commit fail: %s %s", key, nvs_error(err)); - return 0; - } - return 4; -} - -size_t Preferences::putLong(const char* key, int32_t value){ - return putInt(key, value); -} - -size_t Preferences::putULong(const char* key, uint32_t value){ - return putUInt(key, value); -} - -size_t Preferences::putLong64(const char* key, int64_t value){ - if(!_started || !key || _readOnly){ - return 0; - } - esp_err_t err = nvs_set_i64(_handle, key, value); - if(err){ - log_e("nvs_set_i64 fail: %s %s", key, nvs_error(err)); - return 0; - } - err = nvs_commit(_handle); - if(err){ - log_e("nvs_commit fail: %s %s", key, nvs_error(err)); - return 0; - } - return 8; -} - -size_t Preferences::putULong64(const char* key, uint64_t value){ - if(!_started || !key || _readOnly){ - return 0; - } - esp_err_t err = nvs_set_u64(_handle, key, value); - if(err){ - log_e("nvs_set_u64 fail: %s %s", key, nvs_error(err)); - return 0; - } - err = nvs_commit(_handle); - if(err){ - log_e("nvs_commit fail: %s %s", key, nvs_error(err)); - return 0; - } - return 8; -} - -size_t Preferences::putFloat(const char* key, const float_t value){ - return putBytes(key, (void*)&value, sizeof(float_t)); -} - -size_t Preferences::putDouble(const char* key, const double_t value){ - return putBytes(key, (void*)&value, sizeof(double_t)); -} - -size_t Preferences::putBool(const char* key, const bool value){ - return putUChar(key, (uint8_t) (value ? 1 : 0)); -} - -size_t Preferences::putString(const char* key, const char* value){ - if(!_started || !key || !value || _readOnly){ - return 0; - } - esp_err_t err = nvs_set_str(_handle, key, value); - if(err){ - log_e("nvs_set_str fail: %s %s", key, nvs_error(err)); - return 0; - } - err = nvs_commit(_handle); - if(err){ - log_e("nvs_commit fail: %s %s", key, nvs_error(err)); - return 0; - } - return strlen(value); -} - -size_t Preferences::putString(const char* key, const String value){ - return putString(key, value.c_str()); -} - -size_t Preferences::putBytes(const char* key, const void* value, size_t len){ - if(!_started || !key || !value || !len || _readOnly){ - return 0; - } - esp_err_t err = nvs_set_blob(_handle, key, value, len); - if(err){ - log_e("nvs_set_blob fail: %s %s", key, nvs_error(err)); - return 0; - } - err = nvs_commit(_handle); - if(err){ - log_e("nvs_commit fail: %s %s", key, nvs_error(err)); - return 0; - } - return len; +size_t Preferences::putChar(const char* key, int8_t value) { + if (!_started || !key || _readOnly) { + return 0; + } + esp_err_t err = nvs_set_i8(_handle, key, value); + if (err) { + log_e("nvs_set_i8 fail: %s %s", key, nvs_error(err)); + return 0; + } + err = nvs_commit(_handle); + if (err) { + log_e("nvs_commit fail: %s %s", key, nvs_error(err)); + return 0; + } + return 1; +} + +size_t Preferences::putUChar(const char* key, uint8_t value) { + if (!_started || !key || _readOnly) { + return 0; + } + esp_err_t err = nvs_set_u8(_handle, key, value); + if (err) { + log_e("nvs_set_u8 fail: %s %s", key, nvs_error(err)); + return 0; + } + err = nvs_commit(_handle); + if (err) { + log_e("nvs_commit fail: %s %s", key, nvs_error(err)); + return 0; + } + return 1; +} + +size_t Preferences::putShort(const char* key, int16_t value) { + if (!_started || !key || _readOnly) { + return 0; + } + esp_err_t err = nvs_set_i16(_handle, key, value); + if (err) { + log_e("nvs_set_i16 fail: %s %s", key, nvs_error(err)); + return 0; + } + err = nvs_commit(_handle); + if (err) { + log_e("nvs_commit fail: %s %s", key, nvs_error(err)); + return 0; + } + return 2; +} + +size_t Preferences::putUShort(const char* key, uint16_t value) { + if (!_started || !key || _readOnly) { + return 0; + } + esp_err_t err = nvs_set_u16(_handle, key, value); + if (err) { + log_e("nvs_set_u16 fail: %s %s", key, nvs_error(err)); + return 0; + } + err = nvs_commit(_handle); + if (err) { + log_e("nvs_commit fail: %s %s", key, nvs_error(err)); + return 0; + } + return 2; +} + +size_t Preferences::putInt(const char* key, int32_t value) { + if (!_started || !key || _readOnly) { + return 0; + } + esp_err_t err = nvs_set_i32(_handle, key, value); + if (err) { + log_e("nvs_set_i32 fail: %s %s", key, nvs_error(err)); + return 0; + } + err = nvs_commit(_handle); + if (err) { + log_e("nvs_commit fail: %s %s", key, nvs_error(err)); + return 0; + } + return 4; +} + +size_t Preferences::putUInt(const char* key, uint32_t value) { + if (!_started || !key || _readOnly) { + return 0; + } + esp_err_t err = nvs_set_u32(_handle, key, value); + if (err) { + log_e("nvs_set_u32 fail: %s %s", key, nvs_error(err)); + return 0; + } + err = nvs_commit(_handle); + if (err) { + log_e("nvs_commit fail: %s %s", key, nvs_error(err)); + return 0; + } + return 4; +} + +size_t Preferences::putLong(const char* key, int32_t value) { + return putInt(key, value); +} + +size_t Preferences::putULong(const char* key, uint32_t value) { + return putUInt(key, value); +} + +size_t Preferences::putLong64(const char* key, int64_t value) { + if (!_started || !key || _readOnly) { + return 0; + } + esp_err_t err = nvs_set_i64(_handle, key, value); + if (err) { + log_e("nvs_set_i64 fail: %s %s", key, nvs_error(err)); + return 0; + } + err = nvs_commit(_handle); + if (err) { + log_e("nvs_commit fail: %s %s", key, nvs_error(err)); + return 0; + } + return 8; +} + +size_t Preferences::putULong64(const char* key, uint64_t value) { + if (!_started || !key || _readOnly) { + return 0; + } + esp_err_t err = nvs_set_u64(_handle, key, value); + if (err) { + log_e("nvs_set_u64 fail: %s %s", key, nvs_error(err)); + return 0; + } + err = nvs_commit(_handle); + if (err) { + log_e("nvs_commit fail: %s %s", key, nvs_error(err)); + return 0; + } + return 8; +} + +size_t Preferences::putFloat(const char* key, const float_t value) { + return putBytes(key, (void*)&value, sizeof(float_t)); +} + +size_t Preferences::putDouble(const char* key, const double_t value) { + return putBytes(key, (void*)&value, sizeof(double_t)); +} + +size_t Preferences::putBool(const char* key, const bool value) { + return putUChar(key, (uint8_t)(value ? 1 : 0)); +} + +size_t Preferences::putString(const char* key, const char* value) { + if (!_started || !key || !value || _readOnly) { + return 0; + } + esp_err_t err = nvs_set_str(_handle, key, value); + if (err) { + log_e("nvs_set_str fail: %s %s", key, nvs_error(err)); + return 0; + } + err = nvs_commit(_handle); + if (err) { + log_e("nvs_commit fail: %s %s", key, nvs_error(err)); + return 0; + } + return strlen(value); +} + +size_t Preferences::putString(const char* key, const String value) { + return putString(key, value.c_str()); +} + +size_t Preferences::putBytes(const char* key, const void* value, size_t len) { + if (!_started || !key || !value || !len || _readOnly) { + return 0; + } + esp_err_t err = nvs_set_blob(_handle, key, value, len); + if (err) { + log_e("nvs_set_blob fail: %s %s", key, nvs_error(err)); + return 0; + } + err = nvs_commit(_handle); + if (err) { + log_e("nvs_commit fail: %s %s", key, nvs_error(err)); + return 0; + } + return len; } PreferenceType Preferences::getType(const char* key) { - if(!_started || !key || strlen(key)>15){ - return PT_INVALID; - } - int8_t mt1; uint8_t mt2; int16_t mt3; uint16_t mt4; - int32_t mt5; uint32_t mt6; int64_t mt7; uint64_t mt8; - size_t len = 0; - if(nvs_get_i8(_handle, key, &mt1) == ESP_OK) return PT_I8; - if(nvs_get_u8(_handle, key, &mt2) == ESP_OK) return PT_U8; - if(nvs_get_i16(_handle, key, &mt3) == ESP_OK) return PT_I16; - if(nvs_get_u16(_handle, key, &mt4) == ESP_OK) return PT_U16; - if(nvs_get_i32(_handle, key, &mt5) == ESP_OK) return PT_I32; - if(nvs_get_u32(_handle, key, &mt6) == ESP_OK) return PT_U32; - if(nvs_get_i64(_handle, key, &mt7) == ESP_OK) return PT_I64; - if(nvs_get_u64(_handle, key, &mt8) == ESP_OK) return PT_U64; - if(nvs_get_str(_handle, key, NULL, &len) == ESP_OK) return PT_STR; - if(nvs_get_blob(_handle, key, NULL, &len) == ESP_OK) return PT_BLOB; + if (!_started || !key || strlen(key) > 15) { return PT_INVALID; + } + int8_t mt1; + uint8_t mt2; + int16_t mt3; + uint16_t mt4; + int32_t mt5; + uint32_t mt6; + int64_t mt7; + uint64_t mt8; + size_t len = 0; + if (nvs_get_i8(_handle, key, &mt1) == ESP_OK) return PT_I8; + if (nvs_get_u8(_handle, key, &mt2) == ESP_OK) return PT_U8; + if (nvs_get_i16(_handle, key, &mt3) == ESP_OK) return PT_I16; + if (nvs_get_u16(_handle, key, &mt4) == ESP_OK) return PT_U16; + if (nvs_get_i32(_handle, key, &mt5) == ESP_OK) return PT_I32; + if (nvs_get_u32(_handle, key, &mt6) == ESP_OK) return PT_U32; + if (nvs_get_i64(_handle, key, &mt7) == ESP_OK) return PT_I64; + if (nvs_get_u64(_handle, key, &mt8) == ESP_OK) return PT_U64; + if (nvs_get_str(_handle, key, NULL, &len) == ESP_OK) return PT_STR; + if (nvs_get_blob(_handle, key, NULL, &len) == ESP_OK) return PT_BLOB; + return PT_INVALID; } bool Preferences::isKey(const char* key) { - return getType(key) != PT_INVALID; + return getType(key) != PT_INVALID; } /* * Get a key value * */ -int8_t Preferences::getChar(const char* key, const int8_t defaultValue){ - int8_t value = defaultValue; - if(!_started || !key){ - return value; - } - esp_err_t err = nvs_get_i8(_handle, key, &value); - if(err){ - log_v("nvs_get_i8 fail: %s %s", key, nvs_error(err)); - } +int8_t Preferences::getChar(const char* key, const int8_t defaultValue) { + int8_t value = defaultValue; + if (!_started || !key) { return value; + } + esp_err_t err = nvs_get_i8(_handle, key, &value); + if (err) { + log_v("nvs_get_i8 fail: %s %s", key, nvs_error(err)); + } + return value; } -uint8_t Preferences::getUChar(const char* key, const uint8_t defaultValue){ - uint8_t value = defaultValue; - if(!_started || !key){ - return value; - } - esp_err_t err = nvs_get_u8(_handle, key, &value); - if(err){ - log_v("nvs_get_u8 fail: %s %s", key, nvs_error(err)); - } +uint8_t Preferences::getUChar(const char* key, const uint8_t defaultValue) { + uint8_t value = defaultValue; + if (!_started || !key) { return value; + } + esp_err_t err = nvs_get_u8(_handle, key, &value); + if (err) { + log_v("nvs_get_u8 fail: %s %s", key, nvs_error(err)); + } + return value; } -int16_t Preferences::getShort(const char* key, const int16_t defaultValue){ - int16_t value = defaultValue; - if(!_started || !key){ - return value; - } - esp_err_t err = nvs_get_i16(_handle, key, &value); - if(err){ - log_v("nvs_get_i16 fail: %s %s", key, nvs_error(err)); - } +int16_t Preferences::getShort(const char* key, const int16_t defaultValue) { + int16_t value = defaultValue; + if (!_started || !key) { return value; + } + esp_err_t err = nvs_get_i16(_handle, key, &value); + if (err) { + log_v("nvs_get_i16 fail: %s %s", key, nvs_error(err)); + } + return value; } -uint16_t Preferences::getUShort(const char* key, const uint16_t defaultValue){ - uint16_t value = defaultValue; - if(!_started || !key){ - return value; - } - esp_err_t err = nvs_get_u16(_handle, key, &value); - if(err){ - log_v("nvs_get_u16 fail: %s %s", key, nvs_error(err)); - } +uint16_t Preferences::getUShort(const char* key, const uint16_t defaultValue) { + uint16_t value = defaultValue; + if (!_started || !key) { return value; + } + esp_err_t err = nvs_get_u16(_handle, key, &value); + if (err) { + log_v("nvs_get_u16 fail: %s %s", key, nvs_error(err)); + } + return value; } -int32_t Preferences::getInt(const char* key, const int32_t defaultValue){ - int32_t value = defaultValue; - if(!_started || !key){ - return value; - } - esp_err_t err = nvs_get_i32(_handle, key, &value); - if(err){ - log_v("nvs_get_i32 fail: %s %s", key, nvs_error(err)); - } +int32_t Preferences::getInt(const char* key, const int32_t defaultValue) { + int32_t value = defaultValue; + if (!_started || !key) { return value; + } + esp_err_t err = nvs_get_i32(_handle, key, &value); + if (err) { + log_v("nvs_get_i32 fail: %s %s", key, nvs_error(err)); + } + return value; } -uint32_t Preferences::getUInt(const char* key, const uint32_t defaultValue){ - uint32_t value = defaultValue; - if(!_started || !key){ - return value; - } - esp_err_t err = nvs_get_u32(_handle, key, &value); - if(err){ - log_v("nvs_get_u32 fail: %s %s", key, nvs_error(err)); - } +uint32_t Preferences::getUInt(const char* key, const uint32_t defaultValue) { + uint32_t value = defaultValue; + if (!_started || !key) { return value; + } + esp_err_t err = nvs_get_u32(_handle, key, &value); + if (err) { + log_v("nvs_get_u32 fail: %s %s", key, nvs_error(err)); + } + return value; } -int32_t Preferences::getLong(const char* key, const int32_t defaultValue){ - return getInt(key, defaultValue); +int32_t Preferences::getLong(const char* key, const int32_t defaultValue) { + return getInt(key, defaultValue); } -uint32_t Preferences::getULong(const char* key, const uint32_t defaultValue){ - return getUInt(key, defaultValue); +uint32_t Preferences::getULong(const char* key, const uint32_t defaultValue) { + return getUInt(key, defaultValue); } -int64_t Preferences::getLong64(const char* key, const int64_t defaultValue){ - int64_t value = defaultValue; - if(!_started || !key){ - return value; - } - esp_err_t err = nvs_get_i64(_handle, key, &value); - if(err){ - log_v("nvs_get_i64 fail: %s %s", key, nvs_error(err)); - } +int64_t Preferences::getLong64(const char* key, const int64_t defaultValue) { + int64_t value = defaultValue; + if (!_started || !key) { return value; + } + esp_err_t err = nvs_get_i64(_handle, key, &value); + if (err) { + log_v("nvs_get_i64 fail: %s %s", key, nvs_error(err)); + } + return value; } -uint64_t Preferences::getULong64(const char* key, const uint64_t defaultValue){ - uint64_t value = defaultValue; - if(!_started || !key){ - return value; - } - esp_err_t err = nvs_get_u64(_handle, key, &value); - if(err){ - log_v("nvs_get_u64 fail: %s %s", key, nvs_error(err)); - } +uint64_t Preferences::getULong64(const char* key, const uint64_t defaultValue) { + uint64_t value = defaultValue; + if (!_started || !key) { return value; + } + esp_err_t err = nvs_get_u64(_handle, key, &value); + if (err) { + log_v("nvs_get_u64 fail: %s %s", key, nvs_error(err)); + } + return value; } float_t Preferences::getFloat(const char* key, const float_t defaultValue) { - float_t value = defaultValue; - getBytes(key, (void*) &value, sizeof(float_t)); - return value; + float_t value = defaultValue; + getBytes(key, (void*)&value, sizeof(float_t)); + return value; } double_t Preferences::getDouble(const char* key, const double_t defaultValue) { - double_t value = defaultValue; - getBytes(key, (void*) &value, sizeof(double_t)); - return value; + double_t value = defaultValue; + getBytes(key, (void*)&value, sizeof(double_t)); + return value; } bool Preferences::getBool(const char* key, const bool defaultValue) { - return getUChar(key, defaultValue ? 1 : 0) == 1; -} - -size_t Preferences::getString(const char* key, char* value, const size_t maxLen){ - size_t len = 0; - if(!_started || !key || !value || !maxLen){ - return 0; - } - esp_err_t err = nvs_get_str(_handle, key, NULL, &len); - if(err){ - log_e("nvs_get_str len fail: %s %s", key, nvs_error(err)); - return 0; - } - if(len > maxLen){ - log_e("not enough space in value: %u < %u", maxLen, len); - return 0; - } - err = nvs_get_str(_handle, key, value, &len); - if(err){ - log_e("nvs_get_str fail: %s %s", key, nvs_error(err)); - return 0; - } - return len; -} - -String Preferences::getString(const char* key, const String defaultValue){ - char * value = NULL; - size_t len = 0; - if(!_started || !key){ - return String(defaultValue); - } - esp_err_t err = nvs_get_str(_handle, key, value, &len); - if(err){ - log_e("nvs_get_str len fail: %s %s", key, nvs_error(err)); - return String(defaultValue); - } - char buf[len]; - value = buf; - err = nvs_get_str(_handle, key, value, &len); - if(err){ - log_e("nvs_get_str fail: %s %s", key, nvs_error(err)); - return String(defaultValue); - } - return String(buf); -} - -size_t Preferences::getBytesLength(const char* key){ - size_t len = 0; - if(!_started || !key){ - return 0; - } - esp_err_t err = nvs_get_blob(_handle, key, NULL, &len); - if(err){ - log_e("nvs_get_blob len fail: %s %s", key, nvs_error(err)); - return 0; - } - return len; -} - -size_t Preferences::getBytes(const char* key, void * buf, size_t maxLen){ - size_t len = getBytesLength(key); - if(!len || !buf || !maxLen){ - return len; - } - if(len > maxLen){ - log_e("not enough space in buffer: %u < %u", maxLen, len); - return 0; - } - esp_err_t err = nvs_get_blob(_handle, key, buf, &len); - if(err){ - log_e("nvs_get_blob fail: %s %s", key, nvs_error(err)); - return 0; - } + return getUChar(key, defaultValue ? 1 : 0) == 1; +} + +size_t Preferences::getString(const char* key, char* value, const size_t maxLen) { + size_t len = 0; + if (!_started || !key || !value || !maxLen) { + return 0; + } + esp_err_t err = nvs_get_str(_handle, key, NULL, &len); + if (err) { + log_e("nvs_get_str len fail: %s %s", key, nvs_error(err)); + return 0; + } + if (len > maxLen) { + log_e("not enough space in value: %u < %u", maxLen, len); + return 0; + } + err = nvs_get_str(_handle, key, value, &len); + if (err) { + log_e("nvs_get_str fail: %s %s", key, nvs_error(err)); + return 0; + } + return len; +} + +String Preferences::getString(const char* key, const String defaultValue) { + char* value = NULL; + size_t len = 0; + if (!_started || !key) { + return String(defaultValue); + } + esp_err_t err = nvs_get_str(_handle, key, value, &len); + if (err) { + log_e("nvs_get_str len fail: %s %s", key, nvs_error(err)); + return String(defaultValue); + } + char buf[len]; + value = buf; + err = nvs_get_str(_handle, key, value, &len); + if (err) { + log_e("nvs_get_str fail: %s %s", key, nvs_error(err)); + return String(defaultValue); + } + return String(buf); +} + +size_t Preferences::getBytesLength(const char* key) { + size_t len = 0; + if (!_started || !key) { + return 0; + } + esp_err_t err = nvs_get_blob(_handle, key, NULL, &len); + if (err) { + log_e("nvs_get_blob len fail: %s %s", key, nvs_error(err)); + return 0; + } + return len; +} + +size_t Preferences::getBytes(const char* key, void* buf, size_t maxLen) { + size_t len = getBytesLength(key); + if (!len || !buf || !maxLen) { return len; + } + if (len > maxLen) { + log_e("not enough space in buffer: %u < %u", maxLen, len); + return 0; + } + esp_err_t err = nvs_get_blob(_handle, key, buf, &len); + if (err) { + log_e("nvs_get_blob fail: %s %s", key, nvs_error(err)); + return 0; + } + return len; } size_t Preferences::freeEntries() { - nvs_stats_t nvs_stats; - esp_err_t err = nvs_get_stats(NULL, &nvs_stats); - if(err){ - log_e("Failed to get nvs statistics"); - return 0; - } - return nvs_stats.free_entries; + nvs_stats_t nvs_stats; + esp_err_t err = nvs_get_stats(NULL, &nvs_stats); + if (err) { + log_e("Failed to get nvs statistics"); + return 0; + } + return nvs_stats.free_entries; } diff --git a/libraries/Preferences/src/Preferences.h b/libraries/Preferences/src/Preferences.h index 5dbcbd4cb4f..b5c45d16cbf 100644 --- a/libraries/Preferences/src/Preferences.h +++ b/libraries/Preferences/src/Preferences.h @@ -17,61 +17,71 @@ #include "Arduino.h" typedef enum { - PT_I8, PT_U8, PT_I16, PT_U16, PT_I32, PT_U32, PT_I64, PT_U64, PT_STR, PT_BLOB, PT_INVALID + PT_I8, + PT_U8, + PT_I16, + PT_U16, + PT_I32, + PT_U32, + PT_I64, + PT_U64, + PT_STR, + PT_BLOB, + PT_INVALID } PreferenceType; class Preferences { - protected: - uint32_t _handle; - bool _started; - bool _readOnly; - public: - Preferences(); - ~Preferences(); +protected: + uint32_t _handle; + bool _started; + bool _readOnly; +public: + Preferences(); + ~Preferences(); - bool begin(const char * name, bool readOnly=false, const char* partition_label=NULL); - void end(); + bool begin(const char* name, bool readOnly = false, const char* partition_label = NULL); + void end(); - bool clear(); - bool remove(const char * key); + bool clear(); + bool remove(const char* key); - size_t putChar(const char* key, int8_t value); - size_t putUChar(const char* key, uint8_t value); - size_t putShort(const char* key, int16_t value); - size_t putUShort(const char* key, uint16_t value); - size_t putInt(const char* key, int32_t value); - size_t putUInt(const char* key, uint32_t value); - size_t putLong(const char* key, int32_t value); - size_t putULong(const char* key, uint32_t value); - size_t putLong64(const char* key, int64_t value); - size_t putULong64(const char* key, uint64_t value); - size_t putFloat(const char* key, float_t value); - size_t putDouble(const char* key, double_t value); - size_t putBool(const char* key, bool value); - size_t putString(const char* key, const char* value); - size_t putString(const char* key, String value); - size_t putBytes(const char* key, const void* value, size_t len); + size_t putChar(const char* key, int8_t value); + size_t putUChar(const char* key, uint8_t value); + size_t putShort(const char* key, int16_t value); + size_t putUShort(const char* key, uint16_t value); + size_t putInt(const char* key, int32_t value); + size_t putUInt(const char* key, uint32_t value); + size_t putLong(const char* key, int32_t value); + size_t putULong(const char* key, uint32_t value); + size_t putLong64(const char* key, int64_t value); + size_t putULong64(const char* key, uint64_t value); + size_t putFloat(const char* key, float_t value); + size_t putDouble(const char* key, double_t value); + size_t putBool(const char* key, bool value); + size_t putString(const char* key, const char* value); + size_t putString(const char* key, String value); + size_t putBytes(const char* key, const void* value, size_t len); - bool isKey(const char* key); - PreferenceType getType(const char* key); - int8_t getChar(const char* key, int8_t defaultValue = 0); - uint8_t getUChar(const char* key, uint8_t defaultValue = 0); - int16_t getShort(const char* key, int16_t defaultValue = 0); - uint16_t getUShort(const char* key, uint16_t defaultValue = 0); - int32_t getInt(const char* key, int32_t defaultValue = 0); - uint32_t getUInt(const char* key, uint32_t defaultValue = 0); - int32_t getLong(const char* key, int32_t defaultValue = 0); - uint32_t getULong(const char* key, uint32_t defaultValue = 0); - int64_t getLong64(const char* key, int64_t defaultValue = 0); - uint64_t getULong64(const char* key, uint64_t defaultValue = 0); - float_t getFloat(const char* key, float_t defaultValue = NAN); - double_t getDouble(const char* key, double_t defaultValue = NAN); - bool getBool(const char* key, bool defaultValue = false); - size_t getString(const char* key, char* value, size_t maxLen); - String getString(const char* key, String defaultValue = String()); - size_t getBytesLength(const char* key); - size_t getBytes(const char* key, void * buf, size_t maxLen); - size_t freeEntries(); + bool isKey(const char* key); + PreferenceType getType(const char* key); + int8_t getChar(const char* key, int8_t defaultValue = 0); + uint8_t getUChar(const char* key, uint8_t defaultValue = 0); + int16_t getShort(const char* key, int16_t defaultValue = 0); + uint16_t getUShort(const char* key, uint16_t defaultValue = 0); + int32_t getInt(const char* key, int32_t defaultValue = 0); + uint32_t getUInt(const char* key, uint32_t defaultValue = 0); + int32_t getLong(const char* key, int32_t defaultValue = 0); + uint32_t getULong(const char* key, uint32_t defaultValue = 0); + int64_t getLong64(const char* key, int64_t defaultValue = 0); + uint64_t getULong64(const char* key, uint64_t defaultValue = 0); + float_t getFloat(const char* key, float_t defaultValue = NAN); + double_t getDouble(const char* key, double_t defaultValue = NAN); + bool getBool(const char* key, bool defaultValue = false); + size_t getString(const char* key, char* value, size_t maxLen); + String getString(const char* key, String defaultValue = String()); + size_t getBytesLength(const char* key); + size_t getBytes(const char* key, void* buf, size_t maxLen); + size_t freeEntries(); }; #endif diff --git a/libraries/RainMaker/README.md b/libraries/RainMaker/README.md index f12bef3c208..b9eb5e6cded 100644 --- a/libraries/RainMaker/README.md +++ b/libraries/RainMaker/README.md @@ -138,7 +138,7 @@ char * getNodeID() 1. `char * ` : Pointer to a NULL terminated node_id string. ### my_node.getNodeInfo() -It returns pointer to the node_info_t as configured during node initialisation. +It returns pointer to the node_info_t as configured during node initialization. ``` node_info_t * getNodeInfo(); ``` @@ -407,7 +407,7 @@ Add a UI type to the parameter. This will be used by the Phone apps (or other cl ``` esp_err_t addUIType(const char *ui_type); ``` -* **Paramter** +* **Parameter** 1. `ui_type` : String describing the UI Type. * Standard UI Types * ESP_RMAKER_UI_TOGGLE @@ -449,7 +449,7 @@ esp_err_t updateAndReport(param_val_t val); > NOTE : > - This API should always be called inside device write callback, if you aimed at updating n reporting parameter values, changed via RainMaker Client (Phone App), to the ESP RainMaker cloud. -> - If not called then paramter values will not be updated to the ESP RainMaker cloud. +> - If not called then parameter values will not be updated to the ESP RainMaker cloud. ### printQR() This API displays QR code, which is used in provisioning. @@ -458,7 +458,7 @@ printQR(const char *serv_name, const char *pop, const char *transport); ``` * **Parameters** 1. `name` : Service name used in provisioning API. -2. `pop` : Proof of posession used in provisioning API. +2. `pop` : Proof of possession used in provisioning API. 3. `transport` : 1. `softap` : In case of provisioning using SOFTAP. 2. `ble` : In case of provisioning using BLE. diff --git a/libraries/RainMaker/examples/README.md b/libraries/RainMaker/examples/README.md index 0b978040085..fde16de13e8 100644 --- a/libraries/RainMaker/examples/README.md +++ b/libraries/RainMaker/examples/README.md @@ -10,4 +10,3 @@ While building any examples for ESP RainMaker, take care of the following: - ESP32-S3 Board: BLE Provisioning - ESP32-S2 Board: SoftAP Provisioning 4. Set debug level to Info (Tools -> Core Debug Level -> Info). This is recommended debug level but not mandatory to run RainMaker. - diff --git a/libraries/RainMaker/examples/RMakerCustom/README.md b/libraries/RainMaker/examples/RMakerCustom/README.md index 42c998d49c4..b6b17052827 100644 --- a/libraries/RainMaker/examples/RMakerCustom/README.md +++ b/libraries/RainMaker/examples/RMakerCustom/README.md @@ -1,6 +1,6 @@ # ESP RainMaker Custom Device -This example demonstrates how to build a custom device to be used with ESP RainMaker. +This example demonstrates how to build a custom device to be used with ESP RainMaker. ## What to expect in this example? @@ -13,7 +13,7 @@ This example demonstrates how to build a custom device to be used with ESP RainM ### Output ``` -[ 87][I][RMaker.cpp:13] event_handler(): RainMaker Initialised. +[ 87][I][RMaker.cpp:13] event_handler(): RainMaker Initialized. [ 94][I][WiFiProv.cpp:158] beginProvision(): Already Provisioned [ 95][I][WiFiProv.cpp:162] beginProvision(): Attempting connect to AP: Viking007_2GEXT diff --git a/libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino b/libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino index c7c63c51ed8..f968a808a5d 100644 --- a/libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino +++ b/libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino @@ -25,124 +25,120 @@ bool dimmer_state = true; static Device *my_device = NULL; // WARNING: sysProvEvent is called from a separate FreeRTOS task (thread)! -void sysProvEvent(arduino_event_t *sys_event) -{ - switch (sys_event->event_id) { +void sysProvEvent(arduino_event_t *sys_event) { + switch (sys_event->event_id) { case ARDUINO_EVENT_PROV_START: #if CONFIG_IDF_TARGET_ESP32S2 - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); - printQR(service_name, pop, "softap"); + Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); + printQR(service_name, pop, "softap"); #else - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); - printQR(service_name, pop, "ble"); + Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); + printQR(service_name, pop, "ble"); #endif - break; + break; case ARDUINO_EVENT_PROV_INIT: - wifi_prov_mgr_disable_auto_stop(10000); - break; + wifi_prov_mgr_disable_auto_stop(10000); + break; case ARDUINO_EVENT_PROV_CRED_SUCCESS: - wifi_prov_mgr_stop_provisioning(); - break; + wifi_prov_mgr_stop_provisioning(); + break; default:; - } + } } -void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx) -{ - const char *device_name = device->getDeviceName(); - const char *param_name = param->getParamName(); - - if (strcmp(param_name, "Power") == 0) { - Serial.printf("Received value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name); - dimmer_state = val.val.b; - (dimmer_state == false) ? digitalWrite(gpio_dimmer, LOW) : digitalWrite(gpio_dimmer, HIGH); - param->updateAndReport(val); - } else if (strcmp(param_name, "Level") == 0) { - Serial.printf("\nReceived value = %d for %s - %s\n", val.val.i, device_name, param_name); - param->updateAndReport(val); - } +void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx) { + const char *device_name = device->getDeviceName(); + const char *param_name = param->getParamName(); + + if (strcmp(param_name, "Power") == 0) { + Serial.printf("Received value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name); + dimmer_state = val.val.b; + (dimmer_state == false) ? digitalWrite(gpio_dimmer, LOW) : digitalWrite(gpio_dimmer, HIGH); + param->updateAndReport(val); + } else if (strcmp(param_name, "Level") == 0) { + Serial.printf("\nReceived value = %d for %s - %s\n", val.val.i, device_name, param_name); + param->updateAndReport(val); + } } -void setup() -{ - Serial.begin(115200); - pinMode(gpio_0, INPUT); - pinMode(gpio_dimmer, OUTPUT); - digitalWrite(gpio_dimmer, DEFAULT_POWER_MODE); - - Node my_node; - my_node = RMaker.initNode("ESP RainMaker Node"); - my_device = new Device("Dimmer", "custom.device.dimmer", &gpio_dimmer); - if (!my_device) { - return; - } - //Create custom dimmer device - my_device->addNameParam(); - my_device->addPowerParam(DEFAULT_POWER_MODE); - my_device->assignPrimaryParam(my_device->getParamByName(ESP_RMAKER_DEF_POWER_NAME)); - - //Create and add a custom level parameter - Param level_param("Level", "custom.param.level", value(DEFAULT_DIMMER_LEVEL), PROP_FLAG_READ | PROP_FLAG_WRITE); - level_param.addBounds(value(0), value(100), value(1)); - level_param.addUIType(ESP_RMAKER_UI_SLIDER); - my_device->addParam(level_param); - - my_device->addCb(write_callback); - - //Add custom dimmer device to the node - my_node.addDevice(*my_device); - - //This is optional - RMaker.enableOTA(OTA_USING_TOPICS); - //If you want to enable scheduling, set time zone for your region using setTimeZone(). - //The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html - // RMaker.setTimeZone("Asia/Shanghai"); - // Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone - RMaker.enableTZService(); - - RMaker.enableSchedule(); - - RMaker.enableScenes(); - - RMaker.start(); - - WiFi.onEvent(sysProvEvent); // Will call sysProvEvent() from another thread. +void setup() { + Serial.begin(115200); + pinMode(gpio_0, INPUT); + pinMode(gpio_dimmer, OUTPUT); + digitalWrite(gpio_dimmer, DEFAULT_POWER_MODE); + + Node my_node; + my_node = RMaker.initNode("ESP RainMaker Node"); + my_device = new Device("Dimmer", "custom.device.dimmer", &gpio_dimmer); + if (!my_device) { + return; + } + //Create custom dimmer device + my_device->addNameParam(); + my_device->addPowerParam(DEFAULT_POWER_MODE); + my_device->assignPrimaryParam(my_device->getParamByName(ESP_RMAKER_DEF_POWER_NAME)); + + //Create and add a custom level parameter + Param level_param("Level", "custom.param.level", value(DEFAULT_DIMMER_LEVEL), PROP_FLAG_READ | PROP_FLAG_WRITE); + level_param.addBounds(value(0), value(100), value(1)); + level_param.addUIType(ESP_RMAKER_UI_SLIDER); + my_device->addParam(level_param); + + my_device->addCb(write_callback); + + //Add custom dimmer device to the node + my_node.addDevice(*my_device); + + //This is optional + RMaker.enableOTA(OTA_USING_TOPICS); + //If you want to enable scheduling, set time zone for your region using setTimeZone(). + //The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html + // RMaker.setTimeZone("Asia/Shanghai"); + // Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone + RMaker.enableTZService(); + + RMaker.enableSchedule(); + + RMaker.enableScenes(); + + RMaker.start(); + + WiFi.onEvent(sysProvEvent); // Will call sysProvEvent() from another thread. #if CONFIG_IDF_TARGET_ESP32S2 - WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name); + WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name); #else - WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name); + WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name); #endif } -void loop() -{ - if (digitalRead(gpio_0) == LOW) { //Push button pressed - - // Key debounce handling - delay(100); - int startTime = millis(); - while (digitalRead(gpio_0) == LOW) { - delay(50); - } - int endTime = millis(); - - if ((endTime - startTime) > 10000) { - // If key pressed for more than 10secs, reset all - Serial.printf("Reset to factory.\n"); - RMakerFactoryReset(2); - } else if ((endTime - startTime) > 3000) { - Serial.printf("Reset Wi-Fi.\n"); - // If key pressed for more than 3secs, but less than 10, reset Wi-Fi - RMakerWiFiReset(2); - } else { - // Toggle device state - dimmer_state = !dimmer_state; - Serial.printf("Toggle State to %s.\n", dimmer_state ? "true" : "false"); - if (my_device) { - my_device->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, dimmer_state); - } - (dimmer_state == false) ? digitalWrite(gpio_dimmer, LOW) : digitalWrite(gpio_dimmer, HIGH); - } - } +void loop() { + if (digitalRead(gpio_0) == LOW) { //Push button pressed + + // Key debounce handling delay(100); + int startTime = millis(); + while (digitalRead(gpio_0) == LOW) { + delay(50); + } + int endTime = millis(); + + if ((endTime - startTime) > 10000) { + // If key pressed for more than 10secs, reset all + Serial.printf("Reset to factory.\n"); + RMakerFactoryReset(2); + } else if ((endTime - startTime) > 3000) { + Serial.printf("Reset Wi-Fi.\n"); + // If key pressed for more than 3secs, but less than 10, reset Wi-Fi + RMakerWiFiReset(2); + } else { + // Toggle device state + dimmer_state = !dimmer_state; + Serial.printf("Toggle State to %s.\n", dimmer_state ? "true" : "false"); + if (my_device) { + my_device->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, dimmer_state); + } + (dimmer_state == false) ? digitalWrite(gpio_dimmer, LOW) : digitalWrite(gpio_dimmer, HIGH); + } + } + delay(100); } diff --git a/libraries/RainMaker/examples/RMakerCustomAirCooler/README.md b/libraries/RainMaker/examples/RMakerCustomAirCooler/README.md index 7b30b0ae051..2f20e45bfec 100644 --- a/libraries/RainMaker/examples/RMakerCustomAirCooler/README.md +++ b/libraries/RainMaker/examples/RMakerCustomAirCooler/README.md @@ -1,6 +1,6 @@ # ESP RainMaker Custom Device -This example demonstrates how to build a custom device to be used with ESP RainMaker using Mode, Range and Toggle Parameters. +This example demonstrates how to build a custom device to be used with ESP RainMaker using Mode, Range and Toggle Parameters. ## What to expect in this example? diff --git a/libraries/RainMaker/examples/RMakerCustomAirCooler/RMakerCustomAirCooler.ino b/libraries/RainMaker/examples/RMakerCustomAirCooler/RMakerCustomAirCooler.ino index 75c2e1daf90..08f23aedc3f 100644 --- a/libraries/RainMaker/examples/RMakerCustomAirCooler/RMakerCustomAirCooler.ino +++ b/libraries/RainMaker/examples/RMakerCustomAirCooler/RMakerCustomAirCooler.ino @@ -41,173 +41,169 @@ bool power_state = true; static Device *my_device = NULL; // WARNING: sysProvEvent is called from a separate FreeRTOS task (thread)! -void sysProvEvent(arduino_event_t *sys_event) -{ - switch (sys_event->event_id) { +void sysProvEvent(arduino_event_t *sys_event) { + switch (sys_event->event_id) { case ARDUINO_EVENT_PROV_START: #if CONFIG_IDF_TARGET_ESP32S2 - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); - printQR(service_name, pop, "softap"); + Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); + printQR(service_name, pop, "softap"); #else - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); - printQR(service_name, pop, "ble"); + Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); + printQR(service_name, pop, "ble"); #endif - break; + break; case ARDUINO_EVENT_PROV_INIT: - wifi_prov_mgr_disable_auto_stop(10000); - break; + wifi_prov_mgr_disable_auto_stop(10000); + break; case ARDUINO_EVENT_PROV_CRED_SUCCESS: - wifi_prov_mgr_stop_provisioning(); - break; + wifi_prov_mgr_stop_provisioning(); + break; default:; - } + } } -void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx) -{ - const char *device_name = device->getDeviceName(); - const char *param_name = param->getParamName(); - - if (strcmp(param_name, "Power") == 0) { - Serial.printf("Received value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name); - power_state = val.val.b; - (power_state == false) ? digitalWrite(gpio_power, LOW) : digitalWrite(gpio_power, HIGH); - param->updateAndReport(val); - } else if (strcmp(param_name, "Swing") == 0) { - Serial.printf("\nReceived value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name); - bool swing = val.val.b; - (swing == false) ? digitalWrite(gpio_swing, LOW) : digitalWrite(gpio_swing, HIGH); - param->updateAndReport(val); - } else if (strcmp(param_name, "Speed") == 0) { - Serial.printf("\nReceived value = %d for %s - %s\n", val.val.i, device_name, param_name); - int speed = val.val.i; - analogWrite(gpio_speed, speed); - param->updateAndReport(val); - } else if (strcmp(param_name, "Mode") == 0) { - const char *mode = val.val.s; - if (strcmp(mode, "Auto") == 0) { - digitalWrite(gpio_mode_auto, HIGH); - digitalWrite(gpio_mode_heat, LOW); - digitalWrite(gpio_mode_cool, LOW); - } else if (strcmp(mode, "Heat") == 0) { - digitalWrite(gpio_mode_auto, LOW); - digitalWrite(gpio_mode_heat, HIGH); - digitalWrite(gpio_mode_cool, LOW); - } else if (strcmp(mode, "Cool") == 0) { - digitalWrite(gpio_mode_auto, LOW); - digitalWrite(gpio_mode_heat, LOW); - digitalWrite(gpio_mode_cool, HIGH); - } - Serial.printf("\nReceived value = %s for %s - %s\n", val.val.s, device_name, param_name); - param->updateAndReport(val); +void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx) { + const char *device_name = device->getDeviceName(); + const char *param_name = param->getParamName(); + + if (strcmp(param_name, "Power") == 0) { + Serial.printf("Received value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name); + power_state = val.val.b; + (power_state == false) ? digitalWrite(gpio_power, LOW) : digitalWrite(gpio_power, HIGH); + param->updateAndReport(val); + } else if (strcmp(param_name, "Swing") == 0) { + Serial.printf("\nReceived value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name); + bool swing = val.val.b; + (swing == false) ? digitalWrite(gpio_swing, LOW) : digitalWrite(gpio_swing, HIGH); + param->updateAndReport(val); + } else if (strcmp(param_name, "Speed") == 0) { + Serial.printf("\nReceived value = %d for %s - %s\n", val.val.i, device_name, param_name); + int speed = val.val.i; + analogWrite(gpio_speed, speed); + param->updateAndReport(val); + } else if (strcmp(param_name, "Mode") == 0) { + const char *mode = val.val.s; + if (strcmp(mode, "Auto") == 0) { + digitalWrite(gpio_mode_auto, HIGH); + digitalWrite(gpio_mode_heat, LOW); + digitalWrite(gpio_mode_cool, LOW); + } else if (strcmp(mode, "Heat") == 0) { + digitalWrite(gpio_mode_auto, LOW); + digitalWrite(gpio_mode_heat, HIGH); + digitalWrite(gpio_mode_cool, LOW); + } else if (strcmp(mode, "Cool") == 0) { + digitalWrite(gpio_mode_auto, LOW); + digitalWrite(gpio_mode_heat, LOW); + digitalWrite(gpio_mode_cool, HIGH); } + Serial.printf("\nReceived value = %s for %s - %s\n", val.val.s, device_name, param_name); + param->updateAndReport(val); + } } -void setup() -{ - Serial.begin(115200); - pinMode(gpio_reset, INPUT_PULLUP); - pinMode(gpio_power, OUTPUT); - digitalWrite(gpio_power, DEFAULT_POWER_MODE); - pinMode(gpio_swing, OUTPUT); - digitalWrite(gpio_swing, DEFAULT_SWING); - pinMode(gpio_mode_auto, OUTPUT); - if (strcmp(DEFAULT_MODE, "Auto") == 0) { - digitalWrite(gpio_mode_auto, HIGH); - } - pinMode(gpio_mode_cool, OUTPUT); - if (strcmp(DEFAULT_MODE, "Cool") == 0) { - digitalWrite(gpio_mode_auto, HIGH); - } - pinMode(gpio_mode_heat, OUTPUT); - if (strcmp(DEFAULT_MODE, "Heat") == 0) { - digitalWrite(gpio_mode_auto, HIGH); - } - pinMode(gpio_speed, OUTPUT); - analogWrite(gpio_speed, DEFAULT_SPEED); - - Node my_node; - my_node = RMaker.initNode("ESP RainMaker Node"); - my_device = new Device("Air Cooler", "my.device.air-cooler", NULL); - if (!my_device) { - return; - } - //Create custom air cooler device - my_device->addNameParam(); - my_device->addPowerParam(DEFAULT_POWER_MODE); - my_device->assignPrimaryParam(my_device->getParamByName(ESP_RMAKER_DEF_POWER_NAME)); - - Param swing("Swing", ESP_RMAKER_PARAM_TOGGLE, value(DEFAULT_SWING), PROP_FLAG_READ | PROP_FLAG_WRITE); - swing.addUIType(ESP_RMAKER_UI_TOGGLE); - my_device->addParam(swing); - - Param speed("Speed", ESP_RMAKER_PARAM_RANGE, value(DEFAULT_SPEED), PROP_FLAG_READ | PROP_FLAG_WRITE); - speed.addUIType(ESP_RMAKER_UI_SLIDER); - speed.addBounds(value(0), value(255), value(1)); - my_device->addParam(speed); - - static const char *modes[] = { "Auto", "Cool", "Heat" }; - Param mode_param("Mode", ESP_RMAKER_PARAM_MODE, value("Auto"), PROP_FLAG_READ | PROP_FLAG_WRITE); - mode_param.addValidStrList(modes, 3); - mode_param.addUIType(ESP_RMAKER_UI_DROPDOWN); - my_device->addParam(mode_param); - - my_device->addCb(write_callback); - - //Add custom Air Cooler device to the node - my_node.addDevice(*my_device); - - //This is optional - // RMaker.enableOTA(OTA_USING_TOPICS); - //If you want to enable scheduling, set time zone for your region using setTimeZone(). - //The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html - // RMaker.setTimeZone("Asia/Shanghai"); - //Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone - // RMaker.enableTZService(); - - RMaker.enableSchedule(); - - RMaker.enableScenes(); - - RMaker.start(); - - WiFi.onEvent(sysProvEvent); // Will call sysProvEvent() from another thread. +void setup() { + Serial.begin(115200); + pinMode(gpio_reset, INPUT_PULLUP); + pinMode(gpio_power, OUTPUT); + digitalWrite(gpio_power, DEFAULT_POWER_MODE); + pinMode(gpio_swing, OUTPUT); + digitalWrite(gpio_swing, DEFAULT_SWING); + pinMode(gpio_mode_auto, OUTPUT); + if (strcmp(DEFAULT_MODE, "Auto") == 0) { + digitalWrite(gpio_mode_auto, HIGH); + } + pinMode(gpio_mode_cool, OUTPUT); + if (strcmp(DEFAULT_MODE, "Cool") == 0) { + digitalWrite(gpio_mode_auto, HIGH); + } + pinMode(gpio_mode_heat, OUTPUT); + if (strcmp(DEFAULT_MODE, "Heat") == 0) { + digitalWrite(gpio_mode_auto, HIGH); + } + pinMode(gpio_speed, OUTPUT); + analogWrite(gpio_speed, DEFAULT_SPEED); + + Node my_node; + my_node = RMaker.initNode("ESP RainMaker Node"); + my_device = new Device("Air Cooler", "my.device.air-cooler", NULL); + if (!my_device) { + return; + } + //Create custom air cooler device + my_device->addNameParam(); + my_device->addPowerParam(DEFAULT_POWER_MODE); + my_device->assignPrimaryParam(my_device->getParamByName(ESP_RMAKER_DEF_POWER_NAME)); + + Param swing("Swing", ESP_RMAKER_PARAM_TOGGLE, value(DEFAULT_SWING), PROP_FLAG_READ | PROP_FLAG_WRITE); + swing.addUIType(ESP_RMAKER_UI_TOGGLE); + my_device->addParam(swing); + + Param speed("Speed", ESP_RMAKER_PARAM_RANGE, value(DEFAULT_SPEED), PROP_FLAG_READ | PROP_FLAG_WRITE); + speed.addUIType(ESP_RMAKER_UI_SLIDER); + speed.addBounds(value(0), value(255), value(1)); + my_device->addParam(speed); + + static const char *modes[] = { "Auto", "Cool", "Heat" }; + Param mode_param("Mode", ESP_RMAKER_PARAM_MODE, value("Auto"), PROP_FLAG_READ | PROP_FLAG_WRITE); + mode_param.addValidStrList(modes, 3); + mode_param.addUIType(ESP_RMAKER_UI_DROPDOWN); + my_device->addParam(mode_param); + + my_device->addCb(write_callback); + + //Add custom Air Cooler device to the node + my_node.addDevice(*my_device); + + //This is optional + // RMaker.enableOTA(OTA_USING_TOPICS); + //If you want to enable scheduling, set time zone for your region using setTimeZone(). + //The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html + // RMaker.setTimeZone("Asia/Shanghai"); + //Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone + // RMaker.enableTZService(); + + RMaker.enableSchedule(); + + RMaker.enableScenes(); + + RMaker.start(); + + WiFi.onEvent(sysProvEvent); // Will call sysProvEvent() from another thread. #if CONFIG_IDF_TARGET_ESP32S2 - WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name); + WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name); #else - WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name); + WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name); #endif } -void loop() -{ - if (digitalRead(gpio_reset) == LOW) { //Push button pressed - - // Key debounce handling - delay(100); - int startTime = millis(); - while (digitalRead(gpio_reset) == LOW) { - delay(50); - } - int press_duration = millis() - startTime; - - if (press_duration > 10000) { - // If key pressed for more than 10secs, reset all - Serial.printf("Reset to factory.\n"); - RMakerFactoryReset(2); - } else if (press_duration > 3000) { - Serial.printf("Reset Wi-Fi.\n"); - // If key pressed for more than 3secs, but less than 10, reset Wi-Fi - RMakerWiFiReset(2); - } else { - // Toggle device state - power_state = !power_state; - Serial.printf("Toggle power state to %s.\n", power_state ? "true" : "false"); - if (my_device) { - my_device->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, power_state); - } - (power_state == false) ? digitalWrite(gpio_power, LOW) : digitalWrite(gpio_power, HIGH); - } - } +void loop() { + if (digitalRead(gpio_reset) == LOW) { //Push button pressed + + // Key debounce handling delay(100); + int startTime = millis(); + while (digitalRead(gpio_reset) == LOW) { + delay(50); + } + int press_duration = millis() - startTime; + + if (press_duration > 10000) { + // If key pressed for more than 10secs, reset all + Serial.printf("Reset to factory.\n"); + RMakerFactoryReset(2); + } else if (press_duration > 3000) { + Serial.printf("Reset Wi-Fi.\n"); + // If key pressed for more than 3secs, but less than 10, reset Wi-Fi + RMakerWiFiReset(2); + } else { + // Toggle device state + power_state = !power_state; + Serial.printf("Toggle power state to %s.\n", power_state ? "true" : "false"); + if (my_device) { + my_device->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, power_state); + } + (power_state == false) ? digitalWrite(gpio_power, LOW) : digitalWrite(gpio_power, HIGH); + } + } + delay(100); } diff --git a/libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino b/libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino index 082388dd64d..d19a5d7cc92 100644 --- a/libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino +++ b/libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino @@ -22,198 +22,191 @@ bool switch_state_ch2 = true; static uint8_t gpio_led = 13; struct LightSwitch { - const uint8_t pin; - bool pressed; + const uint8_t pin; + bool pressed; }; // Define the light switches for channel 1 and 2 -LightSwitch switch_ch1 = {gpio_switch1, false}; -LightSwitch switch_ch2 = {gpio_switch2, false}; +LightSwitch switch_ch1 = { gpio_switch1, false }; +LightSwitch switch_ch2 = { gpio_switch2, false }; //The framework provides some standard device types like switch, lightbulb, fan, temperature sensor. static Switch *my_switch1 = NULL; static Switch *my_switch2 = NULL; // WARNING: sysProvEvent is called from a separate FreeRTOS task (thread)! -void sysProvEvent(arduino_event_t *sys_event) -{ - switch (sys_event->event_id) { +void sysProvEvent(arduino_event_t *sys_event) { + switch (sys_event->event_id) { case ARDUINO_EVENT_PROV_START: #if CONFIG_IDF_TARGET_ESP32 - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); - printQR(service_name, pop, "ble"); + Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); + printQR(service_name, pop, "ble"); #else - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); - printQR(service_name, pop, "softap"); + Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); + printQR(service_name, pop, "softap"); #endif - break; + break; case ARDUINO_EVENT_WIFI_STA_CONNECTED: - Serial.printf("\nConnected to Wi-Fi!\n"); - digitalWrite(gpio_led, true); - break; + Serial.printf("\nConnected to Wi-Fi!\n"); + digitalWrite(gpio_led, true); + break; case ARDUINO_EVENT_PROV_INIT: - wifi_prov_mgr_disable_auto_stop(10000); - break; + wifi_prov_mgr_disable_auto_stop(10000); + break; case ARDUINO_EVENT_PROV_CRED_SUCCESS: - wifi_prov_mgr_stop_provisioning(); - break; + wifi_prov_mgr_stop_provisioning(); + break; default:; - } + } } -void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx) -{ - const char *device_name = device->getDeviceName(); - const char *param_name = param->getParamName(); - - if (strcmp(device_name, "Switch_ch1") == 0) { +void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx) { + const char *device_name = device->getDeviceName(); + const char *param_name = param->getParamName(); - Serial.printf("Lightbulb = %s\n", val.val.b ? "true" : "false"); + if (strcmp(device_name, "Switch_ch1") == 0) { - if (strcmp(param_name, "Power") == 0) { - Serial.printf("Received value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name); - switch_state_ch1 = val.val.b; - (switch_state_ch1 == false) ? digitalWrite(gpio_relay1, LOW) : digitalWrite(gpio_relay1, HIGH); - param->updateAndReport(val); - } + Serial.printf("Lightbulb = %s\n", val.val.b ? "true" : "false"); - } else if (strcmp(device_name, "Switch_ch2") == 0) { + if (strcmp(param_name, "Power") == 0) { + Serial.printf("Received value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name); + switch_state_ch1 = val.val.b; + (switch_state_ch1 == false) ? digitalWrite(gpio_relay1, LOW) : digitalWrite(gpio_relay1, HIGH); + param->updateAndReport(val); + } - Serial.printf("Switch value = %s\n", val.val.b ? "true" : "false"); + } else if (strcmp(device_name, "Switch_ch2") == 0) { - if (strcmp(param_name, "Power") == 0) { - Serial.printf("Received value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name); - switch_state_ch2 = val.val.b; - (switch_state_ch2 == false) ? digitalWrite(gpio_relay2, LOW) : digitalWrite(gpio_relay2, HIGH); - param->updateAndReport(val); - } + Serial.printf("Switch value = %s\n", val.val.b ? "true" : "false"); + if (strcmp(param_name, "Power") == 0) { + Serial.printf("Received value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name); + switch_state_ch2 = val.val.b; + (switch_state_ch2 == false) ? digitalWrite(gpio_relay2, LOW) : digitalWrite(gpio_relay2, HIGH); + param->updateAndReport(val); } - + } } -void ARDUINO_ISR_ATTR isr(void *arg) -{ - LightSwitch *s = static_cast(arg); - s->pressed = true; +void ARDUINO_ISR_ATTR isr(void *arg) { + LightSwitch *s = static_cast(arg); + s->pressed = true; } -void setup() -{ - - uint32_t chipId = 0; - - Serial.begin(115200); - - // Configure the input GPIOs - pinMode(gpio_reset, INPUT); - pinMode(switch_ch1.pin, INPUT_PULLUP); - attachInterruptArg(switch_ch1.pin, isr, &switch_ch1, CHANGE); - pinMode(switch_ch2.pin, INPUT_PULLUP); - attachInterruptArg(switch_ch2.pin, isr, &switch_ch2, CHANGE); - - // Set the Relays GPIOs as output mode - pinMode(gpio_relay1, OUTPUT); - pinMode(gpio_relay2, OUTPUT); - pinMode(gpio_led, OUTPUT); - // Write to the GPIOs the default state on booting - digitalWrite(gpio_relay1, DEFAULT_POWER_MODE); - digitalWrite(gpio_relay2, DEFAULT_POWER_MODE); - digitalWrite(gpio_led, false); - - Node my_node; - my_node = RMaker.initNode("Sonoff Dual R3"); - - //Initialize switch device - my_switch1 = new Switch("Switch_ch1", &gpio_relay1); - my_switch2 = new Switch("Switch_ch2", &gpio_relay2); - - if (!my_switch1 || !my_switch2) { - return; - } - //Standard switch device - my_switch1->addCb(write_callback); - my_switch2->addCb(write_callback); - - //Add switch device to the node - my_node.addDevice(*my_switch1); - my_node.addDevice(*my_switch2); - - //This is optional - RMaker.enableOTA(OTA_USING_TOPICS); - //If you want to enable scheduling, set time zone for your region using setTimeZone(). - //The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html - // RMaker.setTimeZone("Asia/Shanghai"); - // Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone - RMaker.enableTZService(); - RMaker.enableSchedule(); - RMaker.enableScenes(); - - //Service Name - for (int i = 0; i < 17; i = i + 8) { - chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i; - } - - Serial.printf("\nChip ID: %lu Service Name: %s\n", chipId, service_name); - - Serial.printf("\nStarting ESP-RainMaker\n"); - RMaker.start(); - - WiFi.onEvent(sysProvEvent); // Will call sysProvEvent() from another thread. +void setup() { + + uint32_t chipId = 0; + + Serial.begin(115200); + + // Configure the input GPIOs + pinMode(gpio_reset, INPUT); + pinMode(switch_ch1.pin, INPUT_PULLUP); + attachInterruptArg(switch_ch1.pin, isr, &switch_ch1, CHANGE); + pinMode(switch_ch2.pin, INPUT_PULLUP); + attachInterruptArg(switch_ch2.pin, isr, &switch_ch2, CHANGE); + + // Set the Relays GPIOs as output mode + pinMode(gpio_relay1, OUTPUT); + pinMode(gpio_relay2, OUTPUT); + pinMode(gpio_led, OUTPUT); + // Write to the GPIOs the default state on booting + digitalWrite(gpio_relay1, DEFAULT_POWER_MODE); + digitalWrite(gpio_relay2, DEFAULT_POWER_MODE); + digitalWrite(gpio_led, false); + + Node my_node; + my_node = RMaker.initNode("Sonoff Dual R3"); + + //Initialize switch device + my_switch1 = new Switch("Switch_ch1", &gpio_relay1); + my_switch2 = new Switch("Switch_ch2", &gpio_relay2); + + if (!my_switch1 || !my_switch2) { + return; + } + //Standard switch device + my_switch1->addCb(write_callback); + my_switch2->addCb(write_callback); + + //Add switch device to the node + my_node.addDevice(*my_switch1); + my_node.addDevice(*my_switch2); + + //This is optional + RMaker.enableOTA(OTA_USING_TOPICS); + //If you want to enable scheduling, set time zone for your region using setTimeZone(). + //The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html + // RMaker.setTimeZone("Asia/Shanghai"); + // Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone + RMaker.enableTZService(); + RMaker.enableSchedule(); + RMaker.enableScenes(); + + //Service Name + for (int i = 0; i < 17; i = i + 8) { + chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i; + } + + Serial.printf("\nChip ID: %lu Service Name: %s\n", chipId, service_name); + + Serial.printf("\nStarting ESP-RainMaker\n"); + RMaker.start(); + + WiFi.onEvent(sysProvEvent); // Will call sysProvEvent() from another thread. #if CONFIG_IDF_TARGET_ESP32 - WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name); + WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name); #else - WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name); + WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name); #endif } -void loop() -{ - - if (switch_ch1.pressed) { - Serial.printf("Switch 1 has been changed\n"); - switch_ch1.pressed = false; - // Toggle switch 1 device state - switch_state_ch1 = !switch_state_ch1; - Serial.printf("Toggle State to %s.\n", switch_state_ch1 ? "true" : "false"); - if (my_switch1) { - my_switch1->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, switch_state_ch1); - } - (switch_state_ch1 == false) ? digitalWrite(gpio_relay1, LOW) : digitalWrite(gpio_relay1, HIGH); - } else if (switch_ch2.pressed) { - Serial.printf("Switch 2 has been changed\n"); - switch_ch2.pressed = false; - // Toggle switch 2 device state - switch_state_ch2 = !switch_state_ch2; - Serial.printf("Toggle State to %s.\n", switch_state_ch2 ? "true" : "false"); - if (my_switch2) { - my_switch2->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, switch_state_ch2); - } - (switch_state_ch2 == false) ? digitalWrite(gpio_relay2, LOW) : digitalWrite(gpio_relay2, HIGH); - } +void loop() { - // Read GPIO0 (external button to reset device - if (digitalRead(gpio_reset) == LOW) { //Push button pressed - Serial.printf("Reset Button Pressed!\n"); - // Key debounce handling - delay(100); - int startTime = millis(); - while (digitalRead(gpio_reset) == LOW) { - delay(50); - } - int endTime = millis(); - - if ((endTime - startTime) > 10000) { - // If key pressed for more than 10secs, reset all - Serial.printf("Reset to factory.\n"); - RMakerFactoryReset(2); - } else if ((endTime - startTime) > 3000) { - Serial.printf("Reset Wi-Fi.\n"); - // If key pressed for more than 3secs, but less than 10, reset Wi-Fi - RMakerWiFiReset(2); - } + if (switch_ch1.pressed) { + Serial.printf("Switch 1 has been changed\n"); + switch_ch1.pressed = false; + // Toggle switch 1 device state + switch_state_ch1 = !switch_state_ch1; + Serial.printf("Toggle State to %s.\n", switch_state_ch1 ? "true" : "false"); + if (my_switch1) { + my_switch1->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, switch_state_ch1); + } + (switch_state_ch1 == false) ? digitalWrite(gpio_relay1, LOW) : digitalWrite(gpio_relay1, HIGH); + } else if (switch_ch2.pressed) { + Serial.printf("Switch 2 has been changed\n"); + switch_ch2.pressed = false; + // Toggle switch 2 device state + switch_state_ch2 = !switch_state_ch2; + Serial.printf("Toggle State to %s.\n", switch_state_ch2 ? "true" : "false"); + if (my_switch2) { + my_switch2->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, switch_state_ch2); } + (switch_state_ch2 == false) ? digitalWrite(gpio_relay2, LOW) : digitalWrite(gpio_relay2, HIGH); + } + + // Read GPIO0 (external button to reset device + if (digitalRead(gpio_reset) == LOW) { //Push button pressed + Serial.printf("Reset Button Pressed!\n"); + // Key debounce handling delay(100); + int startTime = millis(); + while (digitalRead(gpio_reset) == LOW) { + delay(50); + } + int endTime = millis(); + + if ((endTime - startTime) > 10000) { + // If key pressed for more than 10secs, reset all + Serial.printf("Reset to factory.\n"); + RMakerFactoryReset(2); + } else if ((endTime - startTime) > 3000) { + Serial.printf("Reset Wi-Fi.\n"); + // If key pressed for more than 3secs, but less than 10, reset Wi-Fi + RMakerWiFiReset(2); + } + } + delay(100); } diff --git a/libraries/RainMaker/examples/RMakerSwitch/README.md b/libraries/RainMaker/examples/RMakerSwitch/README.md index 55b5ab1ed41..4d8a38d8ad0 100644 --- a/libraries/RainMaker/examples/RMakerSwitch/README.md +++ b/libraries/RainMaker/examples/RMakerSwitch/README.md @@ -12,7 +12,7 @@ This example demonstrates how to build a switch device to be used with ESP RainM ### Output ``` -[ 63][I][RMaker.cpp:13] event_handler(): RainMaker Initialised. +[ 63][I][RMaker.cpp:13] event_handler(): RainMaker Initialized. [ 69][I][WiFiProv.cpp:158] beginProvision(): Already Provisioned [ 69][I][WiFiProv.cpp:162] beginProvision(): Attempting connect to AP: Viking007_2GEXT diff --git a/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino b/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino index 270612774cd..047df8c321a 100644 --- a/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino +++ b/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino @@ -26,129 +26,125 @@ bool switch_state = true; static Switch *my_switch = NULL; // WARNING: sysProvEvent is called from a separate FreeRTOS task (thread)! -void sysProvEvent(arduino_event_t *sys_event) -{ - switch (sys_event->event_id) { +void sysProvEvent(arduino_event_t *sys_event) { + switch (sys_event->event_id) { case ARDUINO_EVENT_PROV_START: #if CONFIG_IDF_TARGET_ESP32S2 - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", - service_name, pop); - printQR(service_name, pop, "softap"); + Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", + service_name, pop); + printQR(service_name, pop, "softap"); #else - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", - service_name, pop); - printQR(service_name, pop, "ble"); + Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", + service_name, pop); + printQR(service_name, pop, "ble"); #endif - break; + break; case ARDUINO_EVENT_PROV_INIT: - wifi_prov_mgr_disable_auto_stop(10000); - break; + wifi_prov_mgr_disable_auto_stop(10000); + break; case ARDUINO_EVENT_PROV_CRED_SUCCESS: - wifi_prov_mgr_stop_provisioning(); - break; + wifi_prov_mgr_stop_provisioning(); + break; default:; - } + } } void write_callback(Device *device, Param *param, const param_val_t val, - void *priv_data, write_ctx_t *ctx) -{ - const char *device_name = device->getDeviceName(); - const char *param_name = param->getParamName(); - - if (strcmp(param_name, "Power") == 0) { - Serial.printf("Received value = %s for %s - %s\n", - val.val.b ? "true" : "false", device_name, param_name); - switch_state = val.val.b; - (switch_state == false) ? digitalWrite(gpio_switch, LOW) - : digitalWrite(gpio_switch, HIGH); - param->updateAndReport(val); - } + void *priv_data, write_ctx_t *ctx) { + const char *device_name = device->getDeviceName(); + const char *param_name = param->getParamName(); + + if (strcmp(param_name, "Power") == 0) { + Serial.printf("Received value = %s for %s - %s\n", + val.val.b ? "true" : "false", device_name, param_name); + switch_state = val.val.b; + (switch_state == false) ? digitalWrite(gpio_switch, LOW) + : digitalWrite(gpio_switch, HIGH); + param->updateAndReport(val); + } } -void setup() -{ - Serial.begin(115200); - pinMode(gpio_0, INPUT); - pinMode(gpio_switch, OUTPUT); - digitalWrite(gpio_switch, DEFAULT_POWER_MODE); +void setup() { + Serial.begin(115200); + pinMode(gpio_0, INPUT); + pinMode(gpio_switch, OUTPUT); + digitalWrite(gpio_switch, DEFAULT_POWER_MODE); - Node my_node; - my_node = RMaker.initNode("ESP RainMaker Node"); + Node my_node; + my_node = RMaker.initNode("ESP RainMaker Node"); - // Initialize switch device - my_switch = new Switch("Switch", &gpio_switch); - if (!my_switch) { - return; - } - // Standard switch device - my_switch->addCb(write_callback); + // Initialize switch device + my_switch = new Switch("Switch", &gpio_switch); + if (!my_switch) { + return; + } + // Standard switch device + my_switch->addCb(write_callback); - // Add switch device to the node - my_node.addDevice(*my_switch); + // Add switch device to the node + my_node.addDevice(*my_switch); - // This is optional - RMaker.enableOTA(OTA_USING_TOPICS); - // If you want to enable scheduling, set time zone for your region using - // setTimeZone(). The list of available values are provided here - // https://rainmaker.espressif.com/docs/time-service.html - // RMaker.setTimeZone("Asia/Shanghai"); - // Alternatively, enable the Timezone service and let the phone apps set the - // appropriate timezone - RMaker.enableTZService(); + // This is optional + RMaker.enableOTA(OTA_USING_TOPICS); + // If you want to enable scheduling, set time zone for your region using + // setTimeZone(). The list of available values are provided here + // https://rainmaker.espressif.com/docs/time-service.html + // RMaker.setTimeZone("Asia/Shanghai"); + // Alternatively, enable the Timezone service and let the phone apps set the + // appropriate timezone + RMaker.enableTZService(); - RMaker.enableSchedule(); + RMaker.enableSchedule(); - RMaker.enableScenes(); - // Enable ESP Insights. Insteads of using the default http transport, this function will - // reuse the existing MQTT connection of Rainmaker, thereby saving memory space. - initAppInsights(); + RMaker.enableScenes(); + // Enable ESP Insights. Insteads of using the default http transport, this function will + // reuse the existing MQTT connection of Rainmaker, thereby saving memory space. + initAppInsights(); - RMaker.enableSystemService(SYSTEM_SERV_FLAGS_ALL, 2, 2, 2); + RMaker.enableSystemService(SYSTEM_SERV_FLAGS_ALL, 2, 2, 2); - RMaker.start(); + RMaker.start(); - WiFi.onEvent(sysProvEvent); // Will call sysProvEvent() from another thread. + WiFi.onEvent(sysProvEvent); // Will call sysProvEvent() from another thread. #if CONFIG_IDF_TARGET_ESP32S2 - WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, - WIFI_PROV_SECURITY_1, pop, service_name); + WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, + WIFI_PROV_SECURITY_1, pop, service_name); #else - WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, - WIFI_PROV_SECURITY_1, pop, service_name); + WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, + WIFI_PROV_SECURITY_1, pop, service_name); #endif } -void loop() -{ - if (digitalRead(gpio_0) == LOW) { // Push button pressed - - // Key debounce handling - delay(100); - int startTime = millis(); - while (digitalRead(gpio_0) == LOW) { - delay(50); - } - int endTime = millis(); - - if ((endTime - startTime) > 10000) { - // If key pressed for more than 10secs, reset all - Serial.printf("Reset to factory.\n"); - RMakerFactoryReset(2); - } else if ((endTime - startTime) > 3000) { - Serial.printf("Reset Wi-Fi.\n"); - // If key pressed for more than 3secs, but less than 10, reset Wi-Fi - RMakerWiFiReset(2); - } else { - // Toggle device state - switch_state = !switch_state; - Serial.printf("Toggle State to %s.\n", switch_state ? "true" : "false"); - if (my_switch) { - my_switch->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, - switch_state); - } - (switch_state == false) ? digitalWrite(gpio_switch, LOW) - : digitalWrite(gpio_switch, HIGH); - } - } +void loop() { + if (digitalRead(gpio_0) == LOW) { // Push button pressed + + // Key debounce handling delay(100); + int startTime = millis(); + while (digitalRead(gpio_0) == LOW) { + delay(50); + } + int endTime = millis(); + + if ((endTime - startTime) > 10000) { + // If key pressed for more than 10secs, reset all + Serial.printf("Reset to factory.\n"); + RMakerFactoryReset(2); + } else if ((endTime - startTime) > 3000) { + Serial.printf("Reset Wi-Fi.\n"); + // If key pressed for more than 3secs, but less than 10, reset Wi-Fi + RMakerWiFiReset(2); + } else { + // Toggle device state + switch_state = !switch_state; + Serial.printf("Toggle State to %s.\n", switch_state ? "true" : "false"); + if (my_switch) { + my_switch->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, + switch_state); + } + (switch_state == false) ? digitalWrite(gpio_switch, LOW) + : digitalWrite(gpio_switch, HIGH); + } + } + delay(100); } diff --git a/libraries/RainMaker/src/AppInsights.cpp b/libraries/RainMaker/src/AppInsights.cpp index 591f5e65dcc..a203bdab165 100644 --- a/libraries/RainMaker/src/AppInsights.cpp +++ b/libraries/RainMaker/src/AppInsights.cpp @@ -17,65 +17,61 @@ #include extern "C" { - bool esp_rmaker_mqtt_is_budget_available(); + bool esp_rmaker_mqtt_is_budget_available(); } -#define INSIGHTS_TOPIC_SUFFIX "diagnostics/from-node" -#define INSIGHTS_TOPIC_RULE "insights_message_delivery" +#define INSIGHTS_TOPIC_SUFFIX "diagnostics/from-node" +#define INSIGHTS_TOPIC_RULE "insights_message_delivery" -static void _rmakerCommonEventHandler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) -{ - if (event_base != RMAKER_COMMON_EVENT) { - return; - } - esp_insights_transport_event_data_t data; - switch(event_id) { - case RMAKER_MQTT_EVENT_PUBLISHED: - memset(&data, 0, sizeof(data)); - data.msg_id = *(int *)event_data; - esp_event_post(INSIGHTS_EVENT, INSIGHTS_EVENT_TRANSPORT_SEND_SUCCESS, &data, sizeof(data), portMAX_DELAY); - break; - default: - break; - } +static void _rmakerCommonEventHandler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { + if (event_base != RMAKER_COMMON_EVENT) { + return; + } + esp_insights_transport_event_data_t data; + switch (event_id) { + case RMAKER_MQTT_EVENT_PUBLISHED: + memset(&data, 0, sizeof(data)); + data.msg_id = *(int *)event_data; + esp_event_post(INSIGHTS_EVENT, INSIGHTS_EVENT_TRANSPORT_SEND_SUCCESS, &data, sizeof(data), portMAX_DELAY); + break; + default: + break; + } } -static int _appInsightsDataSend(void *data, size_t len) -{ - char topic[128]; - int msg_id = -1; - if (data == NULL) { - return 0; - } - char *node_id = esp_rmaker_get_node_id(); - if (!node_id) { - return -1; - } - if (esp_rmaker_mqtt_is_budget_available() == false) { - return ESP_FAIL; - } - esp_rmaker_create_mqtt_topic(topic, sizeof(topic), INSIGHTS_TOPIC_SUFFIX, INSIGHTS_TOPIC_RULE); - esp_rmaker_mqtt_publish(topic, data, len, RMAKER_MQTT_QOS1, &msg_id); - return msg_id; +static int _appInsightsDataSend(void *data, size_t len) { + char topic[128]; + int msg_id = -1; + if (data == NULL) { + return 0; + } + char *node_id = esp_rmaker_get_node_id(); + if (!node_id) { + return -1; + } + if (esp_rmaker_mqtt_is_budget_available() == false) { + return ESP_FAIL; + } + esp_rmaker_create_mqtt_topic(topic, sizeof(topic), INSIGHTS_TOPIC_SUFFIX, INSIGHTS_TOPIC_RULE); + esp_rmaker_mqtt_publish(topic, data, len, RMAKER_MQTT_QOS1, &msg_id); + return msg_id; } -bool initAppInsights(uint32_t log_type, bool alloc_ext_ram) -{ - char *node_id = esp_rmaker_get_node_id(); - esp_insights_transport_config_t transport; - transport.userdata = NULL; - transport.callbacks.data_send = _appInsightsDataSend; - transport.callbacks.init = NULL; - transport.callbacks.deinit = NULL; - transport.callbacks.connect = NULL; - transport.callbacks.disconnect = NULL; - esp_insights_transport_register(&transport); - esp_event_handler_register(RMAKER_COMMON_EVENT, ESP_EVENT_ANY_ID, _rmakerCommonEventHandler, NULL); - return Insights.begin(NULL, node_id, log_type, alloc_ext_ram, false); +bool initAppInsights(uint32_t log_type, bool alloc_ext_ram) { + char *node_id = esp_rmaker_get_node_id(); + esp_insights_transport_config_t transport; + transport.userdata = NULL; + transport.callbacks.data_send = _appInsightsDataSend; + transport.callbacks.init = NULL; + transport.callbacks.deinit = NULL; + transport.callbacks.connect = NULL; + transport.callbacks.disconnect = NULL; + esp_insights_transport_register(&transport); + esp_event_handler_register(RMAKER_COMMON_EVENT, ESP_EVENT_ANY_ID, _rmakerCommonEventHandler, NULL); + return Insights.begin(NULL, node_id, log_type, alloc_ext_ram, false); } #else -bool initAppInsights(uint32_t log_type, bool alloc_ext_ram) -{ - return false; +bool initAppInsights(uint32_t log_type, bool alloc_ext_ram) { + return false; } #endif diff --git a/libraries/RainMaker/src/RMaker.cpp b/libraries/RainMaker/src/RMaker.cpp index dab002c8aba..7c1b93b7841 100644 --- a/libraries/RainMaker/src/RMaker.cpp +++ b/libraries/RainMaker/src/RMaker.cpp @@ -7,166 +7,156 @@ bool wifiLowLevelInit(bool persistent); static esp_err_t err; -extern "C" bool verifyRollbackLater() { return true; } +extern "C" bool verifyRollbackLater() { + return true; +} -static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) -{ - if (event_base == RMAKER_EVENT) { - switch (event_id) { - case RMAKER_EVENT_INIT_DONE: - log_i("RainMaker Initialised."); - break; - case RMAKER_EVENT_CLAIM_STARTED: - log_i("RainMaker Claim Started."); - break; - case RMAKER_EVENT_CLAIM_SUCCESSFUL: - log_i("RainMaker Claim Successful."); - break; - case RMAKER_EVENT_CLAIM_FAILED: - log_i("RainMaker Claim Failed."); - break; - default: - log_i("Unhandled RainMaker Event:"); - } - } else if (event_base == RMAKER_OTA_EVENT) { - if (event_data == NULL) { - event_data = (void*)""; - } - switch(event_id) { - case RMAKER_OTA_EVENT_STARTING: - log_i("Starting OTA"); - break; - case RMAKER_OTA_EVENT_IN_PROGRESS: - log_i("OTA in progress : %s", (char*)event_data); - break; - case RMAKER_OTA_EVENT_SUCCESSFUL: - log_i("OTA Successful : %s", (char*)event_data); - break; - case RMAKER_OTA_EVENT_FAILED: - log_i("OTA Failed : %s", (char*)event_data); - break; - case RMAKER_OTA_EVENT_DELAYED: - log_i("OTA Delayed : %s", (char*)event_data); - break; - case RMAKER_OTA_EVENT_REJECTED: - log_i("OTA Rejected : %s", (char*)event_data); - break; - default: - log_i("Unhandled OTA Event"); - break; - } +static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { + if (event_base == RMAKER_EVENT) { + switch (event_id) { + case RMAKER_EVENT_INIT_DONE: + log_i("RainMaker Initialized."); + break; + case RMAKER_EVENT_CLAIM_STARTED: + log_i("RainMaker Claim Started."); + break; + case RMAKER_EVENT_CLAIM_SUCCESSFUL: + log_i("RainMaker Claim Successful."); + break; + case RMAKER_EVENT_CLAIM_FAILED: + log_i("RainMaker Claim Failed."); + break; + default: + log_i("Unhandled RainMaker Event:"); + } + } else if (event_base == RMAKER_OTA_EVENT) { + if (event_data == NULL) { + event_data = (void *)""; + } + switch (event_id) { + case RMAKER_OTA_EVENT_STARTING: + log_i("Starting OTA"); + break; + case RMAKER_OTA_EVENT_IN_PROGRESS: + log_i("OTA in progress : %s", (char *)event_data); + break; + case RMAKER_OTA_EVENT_SUCCESSFUL: + log_i("OTA Successful : %s", (char *)event_data); + break; + case RMAKER_OTA_EVENT_FAILED: + log_i("OTA Failed : %s", (char *)event_data); + break; + case RMAKER_OTA_EVENT_DELAYED: + log_i("OTA Delayed : %s", (char *)event_data); + break; + case RMAKER_OTA_EVENT_REJECTED: + log_i("OTA Rejected : %s", (char *)event_data); + break; + default: + log_i("Unhandled OTA Event"); + break; } + } } -void RMakerClass::setTimeSync(bool val) -{ - rainmaker_cfg.enable_time_sync = val; +void RMakerClass::setTimeSync(bool val) { + rainmaker_cfg.enable_time_sync = val; } -Node RMakerClass::initNode(const char *name, const char *type) -{ - wifiLowLevelInit(true); - Node node; - esp_rmaker_node_t *rnode = NULL; - esp_event_handler_register(RMAKER_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL); - esp_event_handler_register(RMAKER_OTA_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL); - rnode = esp_rmaker_node_init(&rainmaker_cfg, name, type); - if (!rnode){ - log_e("Node init failed"); - return node; - } - node.setNodeHandle(rnode); +Node RMakerClass::initNode(const char *name, const char *type) { + wifiLowLevelInit(true); + Node node; + esp_rmaker_node_t *rnode = NULL; + esp_event_handler_register(RMAKER_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL); + esp_event_handler_register(RMAKER_OTA_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL); + rnode = esp_rmaker_node_init(&rainmaker_cfg, name, type); + if (!rnode) { + log_e("Node init failed"); return node; + } + node.setNodeHandle(rnode); + return node; } -esp_err_t RMakerClass::start() -{ - err = esp_rmaker_start(); - if(err != ESP_OK){ - log_e("ESP RainMaker core task failed"); - } - return err; +esp_err_t RMakerClass::start() { + err = esp_rmaker_start(); + if (err != ESP_OK) { + log_e("ESP RainMaker core task failed"); + } + return err; } -esp_err_t RMakerClass::stop() -{ - err = esp_rmaker_stop(); - if(err != ESP_OK) { - log_e("ESP RainMaker stop error"); - } - return err; +esp_err_t RMakerClass::stop() { + err = esp_rmaker_stop(); + if (err != ESP_OK) { + log_e("ESP RainMaker stop error"); + } + return err; } -esp_err_t RMakerClass::deinitNode(Node rnode) -{ - err = esp_rmaker_node_deinit(rnode.getNodeHandle()); - if(err != ESP_OK) { - log_e("Node deinit failed"); - } - return err; +esp_err_t RMakerClass::deinitNode(Node rnode) { + err = esp_rmaker_node_deinit(rnode.getNodeHandle()); + if (err != ESP_OK) { + log_e("Node deinit failed"); + } + return err; } -esp_err_t RMakerClass::setTimeZone(const char *tz) -{ - err = esp_rmaker_time_set_timezone(tz); - if(err != ESP_OK) { - log_e("Setting time zone error"); - } - return err; +esp_err_t RMakerClass::setTimeZone(const char *tz) { + err = esp_rmaker_time_set_timezone(tz); + if (err != ESP_OK) { + log_e("Setting time zone error"); + } + return err; } -esp_err_t RMakerClass::enableSchedule() -{ - err = esp_rmaker_schedule_enable(); - if(err != ESP_OK) { - log_e("Schedule enable failed"); - } - return err; +esp_err_t RMakerClass::enableSchedule() { + err = esp_rmaker_schedule_enable(); + if (err != ESP_OK) { + log_e("Schedule enable failed"); + } + return err; } -esp_err_t RMakerClass::enableTZService() -{ - err = esp_rmaker_timezone_service_enable(); - if(err != ESP_OK) { - log_e("Timezone service enable failed"); - } - return err; +esp_err_t RMakerClass::enableTZService() { + err = esp_rmaker_timezone_service_enable(); + if (err != ESP_OK) { + log_e("Timezone service enable failed"); + } + return err; } -esp_err_t RMakerClass::enableOTA(ota_type_t type, const char *cert) -{ - esp_rmaker_ota_config_t ota_config = { - .ota_cb = NULL, - .ota_diag = NULL, - .server_cert = cert, - .priv = NULL - }; - err = esp_rmaker_ota_enable(&ota_config, type); - if(err != ESP_OK) { - log_e("OTA enable failed"); - } - return err; +esp_err_t RMakerClass::enableOTA(ota_type_t type, const char *cert) { + esp_rmaker_ota_config_t ota_config = { + .ota_cb = NULL, + .ota_diag = NULL, + .server_cert = cert, + .priv = NULL + }; + err = esp_rmaker_ota_enable(&ota_config, type); + if (err != ESP_OK) { + log_e("OTA enable failed"); + } + return err; } -esp_err_t RMakerClass::enableScenes() -{ - err = esp_rmaker_scenes_enable(); - if (err != ESP_OK) { - log_e("Scenes enable failed"); - } - return err; +esp_err_t RMakerClass::enableScenes() { + err = esp_rmaker_scenes_enable(); + if (err != ESP_OK) { + log_e("Scenes enable failed"); + } + return err; } -esp_err_t RMakerClass::enableSystemService(uint16_t flags, int8_t reboot_seconds, int8_t reset_seconds, int8_t reset_reboot_seconds) -{ - esp_rmaker_system_serv_config_t config = { - .flags = flags, - .reboot_seconds = reboot_seconds, - .reset_seconds = reset_seconds, - .reset_reboot_seconds = reset_reboot_seconds - }; - err = esp_rmaker_system_service_enable(&config); - return err; +esp_err_t RMakerClass::enableSystemService(uint16_t flags, int8_t reboot_seconds, int8_t reset_seconds, int8_t reset_reboot_seconds) { + esp_rmaker_system_serv_config_t config = { + .flags = flags, + .reboot_seconds = reboot_seconds, + .reset_seconds = reset_seconds, + .reset_reboot_seconds = reset_reboot_seconds + }; + err = esp_rmaker_system_service_enable(&config); + return err; } RMakerClass RMaker; diff --git a/libraries/RainMaker/src/RMaker.h b/libraries/RainMaker/src/RMaker.h index 0d6420c446e..b33cd3f2df3 100644 --- a/libraries/RainMaker/src/RMaker.h +++ b/libraries/RainMaker/src/RMaker.h @@ -21,25 +21,24 @@ #include "RMakerUtils.h" #include -class RMakerClass -{ - private: - esp_rmaker_config_t rainmaker_cfg = {false}; +class RMakerClass { +private: + esp_rmaker_config_t rainmaker_cfg = { false }; - public: +public: - void setTimeSync(bool val); - Node initNode(const char *name, const char *type = "ESP RainMaker with Arduino"); - esp_err_t deinitNode(Node node); - esp_err_t setTimeZone(const char *tz = "Asia/Shanghai"); - esp_err_t enableSchedule(); - esp_err_t enableTZService(); - esp_err_t enableOTA(ota_type_t type, const char *cert = ESP_RMAKER_OTA_DEFAULT_SERVER_CERT); - esp_err_t enableScenes(); - esp_err_t enableSystemService(uint16_t flags, int8_t reboot_seconds = 2, int8_t reset_seconds = 2, int8_t reset_reboot_seconds = 2); - esp_err_t start(); - esp_err_t stop(); + void setTimeSync(bool val); + Node initNode(const char *name, const char *type = "ESP RainMaker with Arduino"); + esp_err_t deinitNode(Node node); + esp_err_t setTimeZone(const char *tz = "Asia/Shanghai"); + esp_err_t enableSchedule(); + esp_err_t enableTZService(); + esp_err_t enableOTA(ota_type_t type, const char *cert = ESP_RMAKER_OTA_DEFAULT_SERVER_CERT); + esp_err_t enableScenes(); + esp_err_t enableSystemService(uint16_t flags, int8_t reboot_seconds = 2, int8_t reset_seconds = 2, int8_t reset_reboot_seconds = 2); + esp_err_t start(); + esp_err_t stop(); }; extern RMakerClass RMaker; -#endif \ No newline at end of file +#endif diff --git a/libraries/RainMaker/src/RMakerDevice.cpp b/libraries/RainMaker/src/RMakerDevice.cpp index c042e0d22b7..efeafac874a 100644 --- a/libraries/RainMaker/src/RMakerDevice.cpp +++ b/libraries/RainMaker/src/RMakerDevice.cpp @@ -3,211 +3,188 @@ #include "RMakerDevice.h" static esp_err_t err; -typedef void (*deviceWriteCb)(Device*, Param*, const param_val_t val, void *priv_data, write_ctx_t *ctx); -typedef void (*deviceReadCb)(Device*, Param*, void *priv_data, read_ctx_t *ctx); +typedef void (*deviceWriteCb)(Device *, Param *, const param_val_t val, void *priv_data, write_ctx_t *ctx); +typedef void (*deviceReadCb)(Device *, Param *, void *priv_data, read_ctx_t *ctx); typedef struct { - void *priv_data; - deviceWriteCb write_cb; - deviceReadCb read_cb; + void *priv_data; + deviceWriteCb write_cb; + deviceReadCb read_cb; } RMakerDevicePrivT; -static esp_err_t write_callback(const device_handle_t *dev_handle, const param_handle_t *par_handle, const param_val_t val, void *priv_data, write_ctx_t *ctx) -{ - Device device; - Param param; - device.setDeviceHandle(dev_handle); - param.setParamHandle(par_handle); - deviceWriteCb cb = ((RMakerDevicePrivT *)priv_data)->write_cb; - cb(&device, ¶m, val, ((RMakerDevicePrivT *)priv_data)->priv_data, ctx); - return ESP_OK; -} - -static esp_err_t read_callback(const device_handle_t *dev_handle, const param_handle_t *par_handle, void *priv_data, read_ctx_t *ctx) -{ - Device device; - Param param; - device.setDeviceHandle(dev_handle); - param.setParamHandle(par_handle); - deviceReadCb cb = ((RMakerDevicePrivT *)priv_data)->read_cb; - cb(&device, ¶m, ((RMakerDevicePrivT *)priv_data)->priv_data, ctx); - return ESP_OK; -} - -esp_err_t Device::deleteDevice() -{ - err = esp_rmaker_device_delete(getDeviceHandle()); - if(err != ESP_OK) { - log_e("Failed to delete device"); - return err; - } - return ESP_OK; -} - -void Device::addCb(deviceWriteCb writeCb, deviceReadCb readCb) -{ - this->private_data.write_cb = writeCb; - this->private_data.read_cb = readCb; - err = esp_rmaker_device_add_cb(getDeviceHandle(), write_callback, read_callback); - if(err != ESP_OK) { - log_e("Failed to register callback"); - } -} - -esp_err_t Device::addDeviceAttr(const char *attr_name, const char *val) -{ - err = esp_rmaker_device_add_attribute(getDeviceHandle(), attr_name, val); - if(err != ESP_OK) { - log_e("Failed to add attriute to the device"); - return err; - } - return ESP_OK; +static esp_err_t write_callback(const device_handle_t *dev_handle, const param_handle_t *par_handle, const param_val_t val, void *priv_data, write_ctx_t *ctx) { + Device device; + Param param; + device.setDeviceHandle(dev_handle); + param.setParamHandle(par_handle); + deviceWriteCb cb = ((RMakerDevicePrivT *)priv_data)->write_cb; + cb(&device, ¶m, val, ((RMakerDevicePrivT *)priv_data)->priv_data, ctx); + return ESP_OK; +} + +static esp_err_t read_callback(const device_handle_t *dev_handle, const param_handle_t *par_handle, void *priv_data, read_ctx_t *ctx) { + Device device; + Param param; + device.setDeviceHandle(dev_handle); + param.setParamHandle(par_handle); + deviceReadCb cb = ((RMakerDevicePrivT *)priv_data)->read_cb; + cb(&device, ¶m, ((RMakerDevicePrivT *)priv_data)->priv_data, ctx); + return ESP_OK; +} + +esp_err_t Device::deleteDevice() { + err = esp_rmaker_device_delete(getDeviceHandle()); + if (err != ESP_OK) { + log_e("Failed to delete device"); + return err; + } + return ESP_OK; +} + +void Device::addCb(deviceWriteCb writeCb, deviceReadCb readCb) { + this->private_data.write_cb = writeCb; + this->private_data.read_cb = readCb; + err = esp_rmaker_device_add_cb(getDeviceHandle(), write_callback, read_callback); + if (err != ESP_OK) { + log_e("Failed to register callback"); + } +} + +esp_err_t Device::addDeviceAttr(const char *attr_name, const char *val) { + err = esp_rmaker_device_add_attribute(getDeviceHandle(), attr_name, val); + if (err != ESP_OK) { + log_e("Failed to add attriute to the device"); + return err; + } + return ESP_OK; } //Generic Parameter -esp_err_t Device::addParam(Param parameter) -{ - err = esp_rmaker_device_add_param(getDeviceHandle(), parameter.getParamHandle()); - if(err != ESP_OK) { - log_e("Failed to add custom parameter"); - return err; - } - return ESP_OK; +esp_err_t Device::addParam(Param parameter) { + err = esp_rmaker_device_add_param(getDeviceHandle(), parameter.getParamHandle()); + if (err != ESP_OK) { + log_e("Failed to add custom parameter"); + return err; + } + return ESP_OK; } //Standard Device Parameter -esp_err_t Device::addNameParam(const char *param_name) -{ - param_handle_t *param = esp_rmaker_name_param_create(param_name, getDeviceName()); - return esp_rmaker_device_add_param(getDeviceHandle(), param); +esp_err_t Device::addNameParam(const char *param_name) { + param_handle_t *param = esp_rmaker_name_param_create(param_name, getDeviceName()); + return esp_rmaker_device_add_param(getDeviceHandle(), param); } -esp_err_t Device::addPowerParam(bool val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_power_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); +esp_err_t Device::addPowerParam(bool val, const char *param_name) { + param_handle_t *param = esp_rmaker_power_param_create(param_name, val); + return esp_rmaker_device_add_param(getDeviceHandle(), param); } -esp_err_t Device::addBrightnessParam(int val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_brightness_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); +esp_err_t Device::addBrightnessParam(int val, const char *param_name) { + param_handle_t *param = esp_rmaker_brightness_param_create(param_name, val); + return esp_rmaker_device_add_param(getDeviceHandle(), param); } -esp_err_t Device::addHueParam(int val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_hue_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); +esp_err_t Device::addHueParam(int val, const char *param_name) { + param_handle_t *param = esp_rmaker_hue_param_create(param_name, val); + return esp_rmaker_device_add_param(getDeviceHandle(), param); } -esp_err_t Device::addSaturationParam(int val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_saturation_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); +esp_err_t Device::addSaturationParam(int val, const char *param_name) { + param_handle_t *param = esp_rmaker_saturation_param_create(param_name, val); + return esp_rmaker_device_add_param(getDeviceHandle(), param); } -esp_err_t Device::addIntensityParam(int val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_intensity_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); +esp_err_t Device::addIntensityParam(int val, const char *param_name) { + param_handle_t *param = esp_rmaker_intensity_param_create(param_name, val); + return esp_rmaker_device_add_param(getDeviceHandle(), param); } -esp_err_t Device::addCCTParam(int val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_cct_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); +esp_err_t Device::addCCTParam(int val, const char *param_name) { + param_handle_t *param = esp_rmaker_cct_param_create(param_name, val); + return esp_rmaker_device_add_param(getDeviceHandle(), param); } -esp_err_t Device::addDirectionParam(int val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_direction_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); +esp_err_t Device::addDirectionParam(int val, const char *param_name) { + param_handle_t *param = esp_rmaker_direction_param_create(param_name, val); + return esp_rmaker_device_add_param(getDeviceHandle(), param); } -esp_err_t Device::addSpeedParam(int val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_speed_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); +esp_err_t Device::addSpeedParam(int val, const char *param_name) { + param_handle_t *param = esp_rmaker_speed_param_create(param_name, val); + return esp_rmaker_device_add_param(getDeviceHandle(), param); } -esp_err_t Device::addTemperatureParam(float val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_temperature_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); +esp_err_t Device::addTemperatureParam(float val, const char *param_name) { + param_handle_t *param = esp_rmaker_temperature_param_create(param_name, val); + return esp_rmaker_device_add_param(getDeviceHandle(), param); } -param_handle_t *Device::getParamByName(const char *param_name) -{ - return esp_rmaker_device_get_param_by_name(getDeviceHandle(), param_name); +param_handle_t *Device::getParamByName(const char *param_name) { + return esp_rmaker_device_get_param_by_name(getDeviceHandle(), param_name); } -esp_err_t Device::assignPrimaryParam(param_handle_t *param) -{ - err = esp_rmaker_device_assign_primary_param(getDeviceHandle(), param); - if(err != ESP_OK){ - log_e("Failed to assign primary parameter"); - } - return err; +esp_err_t Device::assignPrimaryParam(param_handle_t *param) { + err = esp_rmaker_device_assign_primary_param(getDeviceHandle(), param); + if (err != ESP_OK) { + log_e("Failed to assign primary parameter"); + } + return err; +} + +const param_handle_t *getParamHandlebyName(const esp_rmaker_device_t *device_handle, const char *param_name) { + const param_handle_t *param = esp_rmaker_device_get_param_by_name(device_handle, param_name); + return param; } -const param_handle_t* getParamHandlebyName(const esp_rmaker_device_t *device_handle, const char *param_name) -{ - const param_handle_t *param = esp_rmaker_device_get_param_by_name(device_handle, param_name); - return param; -} - -esp_err_t Device::updateAndReportParam(const char *param_name, bool my_val) -{ - const param_handle_t *param = getParamHandlebyName(getDeviceHandle(), param_name); - param_val_t val = esp_rmaker_bool(my_val); - err = esp_rmaker_param_update_and_report(param, val); - if(err != ESP_OK) { - log_e("Update parameter failed"); - return err; - }else { - log_i("Device : %s, Param Name : %s, Val : %s", getDeviceName(), param_name, my_val ? "true" : "false"); - } - return ESP_OK; -} - -esp_err_t Device::updateAndReportParam(const char *param_name, int my_val) -{ - const param_handle_t *param = getParamHandlebyName(getDeviceHandle(), param_name); - param_val_t val = esp_rmaker_int(my_val); - esp_err_t err = esp_rmaker_param_update_and_report(param, val); - if(err != ESP_OK) { - log_e("Update parameter failed"); - return err; - }else { - log_i("Device : %s, Param Name : %s, Val : %d", getDeviceName(), param_name, my_val); - } - return ESP_OK; -} - -esp_err_t Device::updateAndReportParam(const char *param_name, float my_val) -{ - const param_handle_t *param = getParamHandlebyName(getDeviceHandle(), param_name); - param_val_t val = esp_rmaker_float(my_val); - esp_err_t err = esp_rmaker_param_update_and_report(param, val); - if(err != ESP_OK) { - log_e("Update parameter failed"); - return err; - }else { - log_i("Device : %s, Param Name : %s, Val : %f", getDeviceName(), param_name, my_val); - } - return ESP_OK; -} - -esp_err_t Device::updateAndReportParam(const char *param_name, const char *my_val) -{ - const param_handle_t *param = getParamHandlebyName(getDeviceHandle(), param_name); - param_val_t val = esp_rmaker_str(my_val); - esp_err_t err = esp_rmaker_param_update_and_report(param, val); - if(err != ESP_OK) { - log_e("Update parameter failed"); - return err; - }else { - log_i("Device : %s, Param Name : %s, Val : %s", getDeviceName(), param_name, my_val); - } - return ESP_OK; +esp_err_t Device::updateAndReportParam(const char *param_name, bool my_val) { + const param_handle_t *param = getParamHandlebyName(getDeviceHandle(), param_name); + param_val_t val = esp_rmaker_bool(my_val); + err = esp_rmaker_param_update_and_report(param, val); + if (err != ESP_OK) { + log_e("Update parameter failed"); + return err; + } else { + log_i("Device : %s, Param Name : %s, Val : %s", getDeviceName(), param_name, my_val ? "true" : "false"); + } + return ESP_OK; +} + +esp_err_t Device::updateAndReportParam(const char *param_name, int my_val) { + const param_handle_t *param = getParamHandlebyName(getDeviceHandle(), param_name); + param_val_t val = esp_rmaker_int(my_val); + esp_err_t err = esp_rmaker_param_update_and_report(param, val); + if (err != ESP_OK) { + log_e("Update parameter failed"); + return err; + } else { + log_i("Device : %s, Param Name : %s, Val : %d", getDeviceName(), param_name, my_val); + } + return ESP_OK; +} + +esp_err_t Device::updateAndReportParam(const char *param_name, float my_val) { + const param_handle_t *param = getParamHandlebyName(getDeviceHandle(), param_name); + param_val_t val = esp_rmaker_float(my_val); + esp_err_t err = esp_rmaker_param_update_and_report(param, val); + if (err != ESP_OK) { + log_e("Update parameter failed"); + return err; + } else { + log_i("Device : %s, Param Name : %s, Val : %f", getDeviceName(), param_name, my_val); + } + return ESP_OK; +} + +esp_err_t Device::updateAndReportParam(const char *param_name, const char *my_val) { + const param_handle_t *param = getParamHandlebyName(getDeviceHandle(), param_name); + param_val_t val = esp_rmaker_str(my_val); + esp_err_t err = esp_rmaker_param_update_and_report(param, val); + if (err != ESP_OK) { + log_e("Update parameter failed"); + return err; + } else { + log_i("Device : %s, Param Name : %s, Val : %s", getDeviceName(), param_name, my_val); + } + return ESP_OK; } #endif diff --git a/libraries/RainMaker/src/RMakerDevice.h b/libraries/RainMaker/src/RMakerDevice.h index cba498c2cb8..c0198cd2724 100644 --- a/libraries/RainMaker/src/RMakerDevice.h +++ b/libraries/RainMaker/src/RMakerDevice.h @@ -19,174 +19,150 @@ #include #include -class Device -{ - public: - typedef void (*deviceWriteCb)(Device*, Param*, const param_val_t val, void *priv_data, write_ctx_t *ctx); - typedef void (*deviceReadCb)(Device*, Param*, void *priv_data, read_ctx_t *ctx); - typedef struct { - void *priv_data; - deviceWriteCb write_cb; - deviceReadCb read_cb; - } RMakerDevicePrivT; - private: - const device_handle_t *device_handle; - RMakerDevicePrivT private_data; +class Device { +public: + typedef void (*deviceWriteCb)(Device *, Param *, const param_val_t val, void *priv_data, write_ctx_t *ctx); + typedef void (*deviceReadCb)(Device *, Param *, void *priv_data, read_ctx_t *ctx); + typedef struct { + void *priv_data; + deviceWriteCb write_cb; + deviceReadCb read_cb; + } RMakerDevicePrivT; +private: + const device_handle_t *device_handle; + RMakerDevicePrivT private_data; - protected: - void setPrivateData(void *priv_data) { - this->private_data.priv_data = priv_data; - } - - const RMakerDevicePrivT* getDevicePrivateData() - { - return &this->private_data; - } - public: - Device() - { - device_handle = NULL; - this->private_data.priv_data = NULL; - this->private_data.write_cb = NULL; - this->private_data.read_cb = NULL; - } +protected: + void setPrivateData(void *priv_data) { + this->private_data.priv_data = priv_data; + } - Device(const char *dev_name, const char *dev_type = NULL, void *priv_data = NULL) - { - this->private_data.priv_data = priv_data; - this->private_data.write_cb = NULL; - this->private_data.read_cb = NULL; - device_handle = esp_rmaker_device_create(dev_name, dev_type, &this->private_data); - if(device_handle == NULL){ - log_e("Device create error"); - } - } - void setDeviceHandle(const esp_rmaker_device_t *device_handle) - { - this->device_handle = device_handle; - } - const char *getDeviceName() - { - return esp_rmaker_device_get_name(device_handle); - } - const esp_rmaker_device_t *getDeviceHandle() - { - return device_handle; - } + const RMakerDevicePrivT *getDevicePrivateData() { + return &this->private_data; + } +public: + Device() { + device_handle = NULL; + this->private_data.priv_data = NULL; + this->private_data.write_cb = NULL; + this->private_data.read_cb = NULL; + } - esp_err_t deleteDevice(); - void addCb(deviceWriteCb write_cb, deviceReadCb read_cb = NULL); - esp_err_t addDeviceAttr(const char *attr_name, const char *val); - param_handle_t *getParamByName(const char *param_name); - esp_err_t assignPrimaryParam(param_handle_t *param); - - //Generic Device Parameter - esp_err_t addParam(Param parameter); + Device(const char *dev_name, const char *dev_type = NULL, void *priv_data = NULL) { + this->private_data.priv_data = priv_data; + this->private_data.write_cb = NULL; + this->private_data.read_cb = NULL; + device_handle = esp_rmaker_device_create(dev_name, dev_type, &this->private_data); + if (device_handle == NULL) { + log_e("Device create error"); + } + } + void setDeviceHandle(const esp_rmaker_device_t *device_handle) { + this->device_handle = device_handle; + } + const char *getDeviceName() { + return esp_rmaker_device_get_name(device_handle); + } + const esp_rmaker_device_t *getDeviceHandle() { + return device_handle; + } - //Standard Device Parameter - esp_err_t addNameParam(const char *param_name = ESP_RMAKER_DEF_NAME_PARAM); - esp_err_t addPowerParam(bool val, const char *param_name = ESP_RMAKER_DEF_POWER_NAME); - esp_err_t addBrightnessParam(int val, const char *param_name = ESP_RMAKER_DEF_BRIGHTNESS_NAME); - esp_err_t addHueParam(int val, const char *param_name = ESP_RMAKER_DEF_HUE_NAME); - esp_err_t addSaturationParam(int val, const char *param_name = ESP_RMAKER_DEF_SATURATION_NAME); - esp_err_t addIntensityParam(int val, const char *param_name = ESP_RMAKER_DEF_INTENSITY_NAME); - esp_err_t addCCTParam(int val, const char *param_name = ESP_RMAKER_DEF_CCT_NAME); - esp_err_t addDirectionParam(int val, const char *param_name = ESP_RMAKER_DEF_DIRECTION_NAME); - esp_err_t addSpeedParam(int val, const char *param_name = ESP_RMAKER_DEF_SPEED_NAME); - esp_err_t addTemperatureParam(float val, const char *param_name = ESP_RMAKER_DEF_TEMPERATURE_NAME); - - //Update Parameter - esp_err_t updateAndReportParam(const char *param_name, bool val); - esp_err_t updateAndReportParam(const char *param_name, int val); - esp_err_t updateAndReportParam(const char *param_name, float val); - esp_err_t updateAndReportParam(const char *param_name, const char *val); + esp_err_t deleteDevice(); + void addCb(deviceWriteCb write_cb, deviceReadCb read_cb = NULL); + esp_err_t addDeviceAttr(const char *attr_name, const char *val); + param_handle_t *getParamByName(const char *param_name); + esp_err_t assignPrimaryParam(param_handle_t *param); + //Generic Device Parameter + esp_err_t addParam(Param parameter); + + //Standard Device Parameter + esp_err_t addNameParam(const char *param_name = ESP_RMAKER_DEF_NAME_PARAM); + esp_err_t addPowerParam(bool val, const char *param_name = ESP_RMAKER_DEF_POWER_NAME); + esp_err_t addBrightnessParam(int val, const char *param_name = ESP_RMAKER_DEF_BRIGHTNESS_NAME); + esp_err_t addHueParam(int val, const char *param_name = ESP_RMAKER_DEF_HUE_NAME); + esp_err_t addSaturationParam(int val, const char *param_name = ESP_RMAKER_DEF_SATURATION_NAME); + esp_err_t addIntensityParam(int val, const char *param_name = ESP_RMAKER_DEF_INTENSITY_NAME); + esp_err_t addCCTParam(int val, const char *param_name = ESP_RMAKER_DEF_CCT_NAME); + esp_err_t addDirectionParam(int val, const char *param_name = ESP_RMAKER_DEF_DIRECTION_NAME); + esp_err_t addSpeedParam(int val, const char *param_name = ESP_RMAKER_DEF_SPEED_NAME); + esp_err_t addTemperatureParam(float val, const char *param_name = ESP_RMAKER_DEF_TEMPERATURE_NAME); + + //Update Parameter + esp_err_t updateAndReportParam(const char *param_name, bool val); + esp_err_t updateAndReportParam(const char *param_name, int val); + esp_err_t updateAndReportParam(const char *param_name, float val); + esp_err_t updateAndReportParam(const char *param_name, const char *val); }; -class Switch : public Device -{ - public: - Switch() - { - standardSwitchDevice("Switch", NULL, true); - } - Switch(const char *dev_name, void *priv_data = NULL, bool power = true) - { - standardSwitchDevice(dev_name, priv_data, power); - } - void standardSwitchDevice(const char *dev_name, void *priv_data, bool power) - { - this->setPrivateData(priv_data); - esp_rmaker_device_t *dev_handle = esp_rmaker_switch_device_create(dev_name, (void *)this->getDevicePrivateData(), power); - setDeviceHandle(dev_handle); - if(dev_handle == NULL){ - log_e("Switch device not created"); - } - } +class Switch : public Device { +public: + Switch() { + standardSwitchDevice("Switch", NULL, true); + } + Switch(const char *dev_name, void *priv_data = NULL, bool power = true) { + standardSwitchDevice(dev_name, priv_data, power); + } + void standardSwitchDevice(const char *dev_name, void *priv_data, bool power) { + this->setPrivateData(priv_data); + esp_rmaker_device_t *dev_handle = esp_rmaker_switch_device_create(dev_name, (void *)this->getDevicePrivateData(), power); + setDeviceHandle(dev_handle); + if (dev_handle == NULL) { + log_e("Switch device not created"); + } + } }; -class LightBulb : public Device -{ - public: - LightBulb() - { - standardLightBulbDevice("Light", NULL, true); - } - LightBulb(const char *dev_name, void *priv_data = NULL, bool power = true) - { - standardLightBulbDevice(dev_name, priv_data, power); - } - void standardLightBulbDevice(const char *dev_name, void *priv_data, bool power) - { - this->setPrivateData(priv_data); - esp_rmaker_device_t *dev_handle = esp_rmaker_lightbulb_device_create(dev_name, (void *)this->getDevicePrivateData(), power); - setDeviceHandle(dev_handle); - if(dev_handle == NULL){ - log_e("Light device not created"); - } - } -}; +class LightBulb : public Device { +public: + LightBulb() { + standardLightBulbDevice("Light", NULL, true); + } + LightBulb(const char *dev_name, void *priv_data = NULL, bool power = true) { + standardLightBulbDevice(dev_name, priv_data, power); + } + void standardLightBulbDevice(const char *dev_name, void *priv_data, bool power) { + this->setPrivateData(priv_data); + esp_rmaker_device_t *dev_handle = esp_rmaker_lightbulb_device_create(dev_name, (void *)this->getDevicePrivateData(), power); + setDeviceHandle(dev_handle); + if (dev_handle == NULL) { + log_e("Light device not created"); + } + } +}; -class Fan : public Device -{ - public: - Fan() - { - standardFanDevice("Fan", NULL, true); - } - Fan(const char *dev_name, void *priv_data = NULL, bool power = true) - { - standardFanDevice(dev_name, priv_data, power); - } - void standardFanDevice(const char *dev_name, void *priv_data, bool power) - { - esp_rmaker_device_t *dev_handle = esp_rmaker_fan_device_create(dev_name, priv_data, power); - setDeviceHandle(dev_handle); - if(dev_handle == NULL){ - log_e("Fan device not created"); - } - } +class Fan : public Device { +public: + Fan() { + standardFanDevice("Fan", NULL, true); + } + Fan(const char *dev_name, void *priv_data = NULL, bool power = true) { + standardFanDevice(dev_name, priv_data, power); + } + void standardFanDevice(const char *dev_name, void *priv_data, bool power) { + esp_rmaker_device_t *dev_handle = esp_rmaker_fan_device_create(dev_name, priv_data, power); + setDeviceHandle(dev_handle); + if (dev_handle == NULL) { + log_e("Fan device not created"); + } + } }; -class TemperatureSensor : public Device -{ - public: - TemperatureSensor() - { - standardTemperatureSensorDevice("Temperature-Sensor", NULL, 25.0); - } - TemperatureSensor(const char *dev_name, void *priv_data = NULL, float temp = 25.0) - { - standardTemperatureSensorDevice(dev_name, priv_data, temp); - } - void standardTemperatureSensorDevice(const char *dev_name, void *priv_data, float temp) - { - this->setPrivateData(priv_data); - esp_rmaker_device_t *dev_handle = esp_rmaker_temp_sensor_device_create(dev_name, (void *)this->getDevicePrivateData(), temp); - setDeviceHandle(dev_handle); - if(dev_handle == NULL){ - log_e("Temperature Sensor device not created"); - } - } +class TemperatureSensor : public Device { +public: + TemperatureSensor() { + standardTemperatureSensorDevice("Temperature-Sensor", NULL, 25.0); + } + TemperatureSensor(const char *dev_name, void *priv_data = NULL, float temp = 25.0) { + standardTemperatureSensorDevice(dev_name, priv_data, temp); + } + void standardTemperatureSensorDevice(const char *dev_name, void *priv_data, float temp) { + this->setPrivateData(priv_data); + esp_rmaker_device_t *dev_handle = esp_rmaker_temp_sensor_device_create(dev_name, (void *)this->getDevicePrivateData(), temp); + setDeviceHandle(dev_handle); + if (dev_handle == NULL) { + log_e("Temperature Sensor device not created"); + } + } }; -#endif \ No newline at end of file +#endif diff --git a/libraries/RainMaker/src/RMakerNode.cpp b/libraries/RainMaker/src/RMakerNode.cpp index 5cae9e8dea9..9c237fa5999 100644 --- a/libraries/RainMaker/src/RMakerNode.cpp +++ b/libraries/RainMaker/src/RMakerNode.cpp @@ -3,40 +3,35 @@ #include "RMakerNode.h" static esp_err_t err; -esp_err_t Node::addDevice(Device device) -{ - err = esp_rmaker_node_add_device(node, device.getDeviceHandle()); - if(err != ESP_OK){ - log_e("Device was not added to the Node"); - } - return err; +esp_err_t Node::addDevice(Device device) { + err = esp_rmaker_node_add_device(node, device.getDeviceHandle()); + if (err != ESP_OK) { + log_e("Device was not added to the Node"); + } + return err; } -esp_err_t Node::removeDevice(Device device) -{ - err = esp_rmaker_node_remove_device(node, device.getDeviceHandle()); - if(err != ESP_OK){ - log_e("Device was not removed from the Node"); - } - return err; +esp_err_t Node::removeDevice(Device device) { + err = esp_rmaker_node_remove_device(node, device.getDeviceHandle()); + if (err != ESP_OK) { + log_e("Device was not removed from the Node"); + } + return err; } -char *Node::getNodeID() -{ - return esp_rmaker_get_node_id(); +char *Node::getNodeID() { + return esp_rmaker_get_node_id(); } -node_info_t *Node::getNodeInfo() -{ - return esp_rmaker_node_get_info(node); +node_info_t *Node::getNodeInfo() { + return esp_rmaker_node_get_info(node); } -esp_err_t Node::addNodeAttr(const char *attr_name, const char *val) -{ - err = esp_rmaker_node_add_attribute(node, attr_name, val); - if(err != ESP_OK) { - log_e("Failed to add attribute to the Node"); - } - return err; +esp_err_t Node::addNodeAttr(const char *attr_name, const char *val) { + err = esp_rmaker_node_add_attribute(node, attr_name, val); + if (err != ESP_OK) { + log_e("Failed to add attribute to the Node"); + } + return err; } -#endif \ No newline at end of file +#endif diff --git a/libraries/RainMaker/src/RMakerNode.h b/libraries/RainMaker/src/RMakerNode.h index d169870f591..a2236a6f7c4 100644 --- a/libraries/RainMaker/src/RMakerNode.h +++ b/libraries/RainMaker/src/RMakerNode.h @@ -17,30 +17,26 @@ #include "esp_system.h" #include "RMakerDevice.h" -class Node -{ - private: - esp_rmaker_node_t *node; - - public: - Node() - { - node = NULL; - } - void setNodeHandle(esp_rmaker_node_t *rnode) - { - node = rnode; - } - esp_rmaker_node_t *getNodeHandle() - { - return node; - } - - esp_err_t addDevice(Device device); - esp_err_t removeDevice(Device device); +class Node { +private: + esp_rmaker_node_t *node; - char *getNodeID(); - node_info_t *getNodeInfo(); - esp_err_t addNodeAttr(const char *attr_name, const char *val); +public: + Node() { + node = NULL; + } + void setNodeHandle(esp_rmaker_node_t *rnode) { + node = rnode; + } + esp_rmaker_node_t *getNodeHandle() { + return node; + } + + esp_err_t addDevice(Device device); + esp_err_t removeDevice(Device device); + + char *getNodeID(); + node_info_t *getNodeInfo(); + esp_err_t addNodeAttr(const char *attr_name, const char *val); }; -#endif \ No newline at end of file +#endif diff --git a/libraries/RainMaker/src/RMakerParam.cpp b/libraries/RainMaker/src/RMakerParam.cpp index f5f132f33f2..1b30a77782e 100644 --- a/libraries/RainMaker/src/RMakerParam.cpp +++ b/libraries/RainMaker/src/RMakerParam.cpp @@ -4,38 +4,35 @@ static esp_err_t err; -esp_err_t Param::addUIType(const char *ui_type) -{ - err = esp_rmaker_param_add_ui_type(param_handle, ui_type); - if(err != ESP_OK) { - log_e("Add UI type error"); - } - return err; +esp_err_t Param::addUIType(const char *ui_type) { + err = esp_rmaker_param_add_ui_type(param_handle, ui_type); + if (err != ESP_OK) { + log_e("Add UI type error"); + } + return err; } -esp_err_t Param::addBounds(param_val_t min, param_val_t max, param_val_t step) -{ - err = esp_rmaker_param_add_bounds(param_handle, min, max, step); - if(err != ESP_OK) { - log_e("Add Bounds error"); - } - return err; +esp_err_t Param::addBounds(param_val_t min, param_val_t max, param_val_t step) { + err = esp_rmaker_param_add_bounds(param_handle, min, max, step); + if (err != ESP_OK) { + log_e("Add Bounds error"); + } + return err; } -esp_err_t Param::updateAndReport(param_val_t val) -{ - err = esp_rmaker_param_update_and_report(getParamHandle(), val); - if(err != ESP_OK){ - log_e("Update and Report param failed"); - } - return err; +esp_err_t Param::updateAndReport(param_val_t val) { + err = esp_rmaker_param_update_and_report(getParamHandle(), val); + if (err != ESP_OK) { + log_e("Update and Report param failed"); + } + return err; } esp_err_t Param::addValidStrList(const char **string_list, uint8_t count) { - esp_err_t err = esp_rmaker_param_add_valid_str_list(getParamHandle(), string_list, count); - if (err != ESP_OK) { - log_e("Add valid string list error"); - } - return err; + esp_err_t err = esp_rmaker_param_add_valid_str_list(getParamHandle(), string_list, count); + if (err != ESP_OK) { + log_e("Add valid string list error"); + } + return err; } #endif diff --git a/libraries/RainMaker/src/RMakerParam.h b/libraries/RainMaker/src/RMakerParam.h index 64785d9b37c..55bb03cb6ec 100644 --- a/libraries/RainMaker/src/RMakerParam.h +++ b/libraries/RainMaker/src/RMakerParam.h @@ -17,36 +17,30 @@ #include "esp_system.h" #include "RMakerType.h" -class Param -{ - private: - const param_handle_t *param_handle; - - public: - Param() - { - param_handle = NULL; - } - Param(const char *param_name, const char *param_type, param_val_t val, uint8_t properties) - { - param_handle = esp_rmaker_param_create(param_name, param_type, val, properties); - } - void setParamHandle(const param_handle_t *param_handle) - { - this->param_handle = param_handle; - } - const char *getParamName() - { - return esp_rmaker_param_get_name(param_handle); - } - const param_handle_t *getParamHandle() - { - return param_handle; - } - - esp_err_t addUIType(const char *ui_type); - esp_err_t addBounds(param_val_t min, param_val_t max, param_val_t step); - esp_err_t updateAndReport(param_val_t val); - esp_err_t addValidStrList(const char **string_list, uint8_t count); +class Param { +private: + const param_handle_t *param_handle; + +public: + Param() { + param_handle = NULL; + } + Param(const char *param_name, const char *param_type, param_val_t val, uint8_t properties) { + param_handle = esp_rmaker_param_create(param_name, param_type, val, properties); + } + void setParamHandle(const param_handle_t *param_handle) { + this->param_handle = param_handle; + } + const char *getParamName() { + return esp_rmaker_param_get_name(param_handle); + } + const param_handle_t *getParamHandle() { + return param_handle; + } + + esp_err_t addUIType(const char *ui_type); + esp_err_t addBounds(param_val_t min, param_val_t max, param_val_t step); + esp_err_t updateAndReport(param_val_t val); + esp_err_t addValidStrList(const char **string_list, uint8_t count); }; -#endif \ No newline at end of file +#endif diff --git a/libraries/RainMaker/src/RMakerQR.cpp b/libraries/RainMaker/src/RMakerQR.cpp index 903332f4b0f..fc04dcba8d8 100644 --- a/libraries/RainMaker/src/RMakerQR.cpp +++ b/libraries/RainMaker/src/RMakerQR.cpp @@ -1,23 +1,22 @@ #include "RMakerQR.h" #ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK -void printQR(const char *name, const char *pop, const char *transport) -{ - if (!name || !pop || !transport) { - log_w("Cannot generate QR code payload. Data missing."); - return; - } - char payload[150] = {0}; - snprintf(payload, sizeof(payload), "{\"ver\":\"%s\",\"name\":\"%s\"" \ - ",\"pop\":\"%s\",\"transport\":\"%s\"}", - PROV_QR_VERSION, name, pop, transport); - if(Serial){ - Serial.printf("Scan this QR code from the ESP RainMaker phone app.\n"); - } - //qrcode_display(payload); // deprecated! - esp_qrcode_config_t cfg = ESP_QRCODE_CONFIG_DEFAULT(); - esp_qrcode_generate(&cfg, payload); - if(Serial){ - Serial.printf("If QR code is not visible, copy paste the below URL in a browser.\n%s?data=%s\n", QRCODE_BASE_URL, payload); - } +void printQR(const char *name, const char *pop, const char *transport) { + if (!name || !pop || !transport) { + log_w("Cannot generate QR code payload. Data missing."); + return; + } + char payload[150] = { 0 }; + snprintf(payload, sizeof(payload), "{\"ver\":\"%s\",\"name\":\"%s\"" + ",\"pop\":\"%s\",\"transport\":\"%s\"}", + PROV_QR_VERSION, name, pop, transport); + if (Serial) { + Serial.printf("Scan this QR code from the ESP RainMaker phone app.\n"); + } + //qrcode_display(payload); // deprecated! + esp_qrcode_config_t cfg = ESP_QRCODE_CONFIG_DEFAULT(); + esp_qrcode_generate(&cfg, payload); + if (Serial) { + Serial.printf("If QR code is not visible, copy paste the below URL in a browser.\n%s?data=%s\n", QRCODE_BASE_URL, payload); + } } -#endif \ No newline at end of file +#endif diff --git a/libraries/RainMaker/src/RMakerQR.h b/libraries/RainMaker/src/RMakerQR.h index cb282a2e9d4..a2e12e410d2 100644 --- a/libraries/RainMaker/src/RMakerQR.h +++ b/libraries/RainMaker/src/RMakerQR.h @@ -19,7 +19,7 @@ #include #define PROV_QR_VERSION "v1" -#define QRCODE_BASE_URL "https://rainmaker.espressif.com/qrcode.html" +#define QRCODE_BASE_URL "https://rainmaker.espressif.com/qrcode.html" void printQR(const char *name, const char *pop, const char *transport); -#endif \ No newline at end of file +#endif diff --git a/libraries/RainMaker/src/RMakerType.cpp b/libraries/RainMaker/src/RMakerType.cpp index 536e90df053..9ed458e6a9c 100644 --- a/libraries/RainMaker/src/RMakerType.cpp +++ b/libraries/RainMaker/src/RMakerType.cpp @@ -2,28 +2,23 @@ #ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK #include "RMakerType.h" -param_val_t value(int ival) -{ - return esp_rmaker_int(ival); +param_val_t value(int ival) { + return esp_rmaker_int(ival); } -param_val_t value(bool bval) -{ - return esp_rmaker_bool(bval); +param_val_t value(bool bval) { + return esp_rmaker_bool(bval); } -param_val_t value(char *sval) -{ - return esp_rmaker_str(sval); +param_val_t value(char* sval) { + return esp_rmaker_str(sval); } -param_val_t value(float fval) -{ - return esp_rmaker_float(fval); +param_val_t value(float fval) { + return esp_rmaker_float(fval); } -param_val_t value(const char* sval) -{ - return esp_rmaker_str(sval); +param_val_t value(const char* sval) { + return esp_rmaker_str(sval); } -#endif \ No newline at end of file +#endif diff --git a/libraries/RainMaker/src/RMakerType.h b/libraries/RainMaker/src/RMakerType.h index aa100b8bf48..4c79171c4f9 100644 --- a/libraries/RainMaker/src/RMakerType.h +++ b/libraries/RainMaker/src/RMakerType.h @@ -31,7 +31,7 @@ typedef esp_rmaker_ota_type_t ota_type_t; param_val_t value(int); param_val_t value(bool); -param_val_t value(char *); +param_val_t value(char*); param_val_t value(float); param_val_t value(const char*); -#endif \ No newline at end of file +#endif diff --git a/libraries/RainMaker/src/RMakerUtils.cpp b/libraries/RainMaker/src/RMakerUtils.cpp index b8af2187c1a..7027686fb14 100644 --- a/libraries/RainMaker/src/RMakerUtils.cpp +++ b/libraries/RainMaker/src/RMakerUtils.cpp @@ -1,13 +1,11 @@ #include "RMakerUtils.h" #ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK #define RESET_DELAY_SEC 2 -void RMakerFactoryReset(int reboot_seconds) -{ - esp_rmaker_factory_reset(RESET_DELAY_SEC, reboot_seconds); +void RMakerFactoryReset(int reboot_seconds) { + esp_rmaker_factory_reset(RESET_DELAY_SEC, reboot_seconds); } -void RMakerWiFiReset(int reboot_seconds) -{ - esp_rmaker_wifi_reset(RESET_DELAY_SEC, reboot_seconds); +void RMakerWiFiReset(int reboot_seconds) { + esp_rmaker_wifi_reset(RESET_DELAY_SEC, reboot_seconds); } -#endif \ No newline at end of file +#endif diff --git a/libraries/RainMaker/src/RMakerUtils.h b/libraries/RainMaker/src/RMakerUtils.h index 17b7533d6be..5896a825b9f 100644 --- a/libraries/RainMaker/src/RMakerUtils.h +++ b/libraries/RainMaker/src/RMakerUtils.h @@ -20,4 +20,4 @@ void RMakerFactoryReset(int seconds); void RMakerWiFiReset(int seconds); -#endif \ No newline at end of file +#endif diff --git a/libraries/SD/examples/SD_Test/SD_Test.ino b/libraries/SD/examples/SD_Test/SD_Test.ino index 2d7d5bf1dd4..5495ccfacb9 100644 --- a/libraries/SD/examples/SD_Test/SD_Test.ino +++ b/libraries/SD/examples/SD_Test/SD_Test.ino @@ -51,213 +51,212 @@ int mosi = -1; int cs = -1; */ -void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ - Serial.printf("Listing directory: %s\n", dirname); +void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { + Serial.printf("Listing directory: %s\n", dirname); - File root = fs.open(dirname); - if(!root){ - Serial.println("Failed to open directory"); - return; - } - if(!root.isDirectory()){ - Serial.println("Not a directory"); - return; - } + File root = fs.open(dirname); + if (!root) { + Serial.println("Failed to open directory"); + return; + } + if (!root.isDirectory()) { + Serial.println("Not a directory"); + return; + } - File file = root.openNextFile(); - while(file){ - if(file.isDirectory()){ - Serial.print(" DIR : "); - Serial.println(file.name()); - if(levels){ - listDir(fs, file.path(), levels -1); - } - } else { - Serial.print(" FILE: "); - Serial.print(file.name()); - Serial.print(" SIZE: "); - Serial.println(file.size()); - } - file = root.openNextFile(); + File file = root.openNextFile(); + while (file) { + if (file.isDirectory()) { + Serial.print(" DIR : "); + Serial.println(file.name()); + if (levels) { + listDir(fs, file.path(), levels - 1); + } + } else { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print(" SIZE: "); + Serial.println(file.size()); } + file = root.openNextFile(); + } } -void createDir(fs::FS &fs, const char * path){ - Serial.printf("Creating Dir: %s\n", path); - if(fs.mkdir(path)){ - Serial.println("Dir created"); - } else { - Serial.println("mkdir failed"); - } +void createDir(fs::FS &fs, const char *path) { + Serial.printf("Creating Dir: %s\n", path); + if (fs.mkdir(path)) { + Serial.println("Dir created"); + } else { + Serial.println("mkdir failed"); + } } -void removeDir(fs::FS &fs, const char * path){ - Serial.printf("Removing Dir: %s\n", path); - if(fs.rmdir(path)){ - Serial.println("Dir removed"); - } else { - Serial.println("rmdir failed"); - } +void removeDir(fs::FS &fs, const char *path) { + Serial.printf("Removing Dir: %s\n", path); + if (fs.rmdir(path)) { + Serial.println("Dir removed"); + } else { + Serial.println("rmdir failed"); + } } -void readFile(fs::FS &fs, const char * path){ - Serial.printf("Reading file: %s\n", path); +void readFile(fs::FS &fs, const char *path) { + Serial.printf("Reading file: %s\n", path); - File file = fs.open(path); - if(!file){ - Serial.println("Failed to open file for reading"); - return; - } + File file = fs.open(path); + if (!file) { + Serial.println("Failed to open file for reading"); + return; + } - Serial.print("Read from file: "); - while(file.available()){ - Serial.write(file.read()); - } - file.close(); + Serial.print("Read from file: "); + while (file.available()) { + Serial.write(file.read()); + } + file.close(); } -void writeFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Writing file: %s\n", path); +void writeFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Writing file: %s\n", path); - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("Failed to open file for writing"); - return; - } - if(file.print(message)){ - Serial.println("File written"); - } else { - Serial.println("Write failed"); - } - file.close(); + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("Failed to open file for writing"); + return; + } + if (file.print(message)) { + Serial.println("File written"); + } else { + Serial.println("Write failed"); + } + file.close(); } -void appendFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Appending to file: %s\n", path); +void appendFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Appending to file: %s\n", path); - File file = fs.open(path, FILE_APPEND); - if(!file){ - Serial.println("Failed to open file for appending"); - return; - } - if(file.print(message)){ - Serial.println("Message appended"); - } else { - Serial.println("Append failed"); - } - file.close(); + File file = fs.open(path, FILE_APPEND); + if (!file) { + Serial.println("Failed to open file for appending"); + return; + } + if (file.print(message)) { + Serial.println("Message appended"); + } else { + Serial.println("Append failed"); + } + file.close(); } -void renameFile(fs::FS &fs, const char * path1, const char * path2){ - Serial.printf("Renaming file %s to %s\n", path1, path2); - if (fs.rename(path1, path2)) { - Serial.println("File renamed"); - } else { - Serial.println("Rename failed"); - } +void renameFile(fs::FS &fs, const char *path1, const char *path2) { + Serial.printf("Renaming file %s to %s\n", path1, path2); + if (fs.rename(path1, path2)) { + Serial.println("File renamed"); + } else { + Serial.println("Rename failed"); + } } -void deleteFile(fs::FS &fs, const char * path){ - Serial.printf("Deleting file: %s\n", path); - if(fs.remove(path)){ - Serial.println("File deleted"); - } else { - Serial.println("Delete failed"); - } +void deleteFile(fs::FS &fs, const char *path) { + Serial.printf("Deleting file: %s\n", path); + if (fs.remove(path)) { + Serial.println("File deleted"); + } else { + Serial.println("Delete failed"); + } } -void testFileIO(fs::FS &fs, const char * path){ - File file = fs.open(path); - static uint8_t buf[512]; - size_t len = 0; - uint32_t start = millis(); - uint32_t end = start; - if(file){ - len = file.size(); - size_t flen = len; - start = millis(); - while(len){ - size_t toRead = len; - if(toRead > 512){ - toRead = 512; - } - file.read(buf, toRead); - len -= toRead; - } - end = millis() - start; - Serial.printf("%u bytes read for %lu ms\n", flen, end); - file.close(); - } else { - Serial.println("Failed to open file for reading"); - } - - - file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("Failed to open file for writing"); - return; - } - - size_t i; +void testFileIO(fs::FS &fs, const char *path) { + File file = fs.open(path); + static uint8_t buf[512]; + size_t len = 0; + uint32_t start = millis(); + uint32_t end = start; + if (file) { + len = file.size(); + size_t flen = len; start = millis(); - for(i=0; i<2048; i++){ - file.write(buf, 512); + while (len) { + size_t toRead = len; + if (toRead > 512) { + toRead = 512; + } + file.read(buf, toRead); + len -= toRead; } end = millis() - start; - Serial.printf("%u bytes written for %lu ms\n", 2048 * 512, end); + Serial.printf("%u bytes read for %lu ms\n", flen, end); file.close(); + } else { + Serial.println("Failed to open file for reading"); + } + + + file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("Failed to open file for writing"); + return; + } + + size_t i; + start = millis(); + for (i = 0; i < 2048; i++) { + file.write(buf, 512); + } + end = millis() - start; + Serial.printf("%u bytes written for %lu ms\n", 2048 * 512, end); + file.close(); } -void setup(){ - Serial.begin(115200); - while(!Serial) { delay (10); } +void setup() { + Serial.begin(115200); + while (!Serial) { delay(10); } #ifdef REASSIGN_PINS - SPI.begin(sck, miso, mosi, cs); - if(!SD.begin(cs)){ + SPI.begin(sck, miso, mosi, cs); + if (!SD.begin(cs)) { #else - if(!SD.begin()){ + if (!SD.begin()) { #endif - Serial.println("Card Mount Failed"); - return; - } - uint8_t cardType = SD.cardType(); + Serial.println("Card Mount Failed"); + return; + } + uint8_t cardType = SD.cardType(); - if(cardType == CARD_NONE){ - Serial.println("No SD card attached"); - return; - } + if (cardType == CARD_NONE) { + Serial.println("No SD card attached"); + return; + } - Serial.print("SD Card Type: "); - if(cardType == CARD_MMC){ - Serial.println("MMC"); - } else if(cardType == CARD_SD){ - Serial.println("SDSC"); - } else if(cardType == CARD_SDHC){ - Serial.println("SDHC"); - } else { - Serial.println("UNKNOWN"); - } + Serial.print("SD Card Type: "); + if (cardType == CARD_MMC) { + Serial.println("MMC"); + } else if (cardType == CARD_SD) { + Serial.println("SDSC"); + } else if (cardType == CARD_SDHC) { + Serial.println("SDHC"); + } else { + Serial.println("UNKNOWN"); + } - uint64_t cardSize = SD.cardSize() / (1024 * 1024); - Serial.printf("SD Card Size: %lluMB\n", cardSize); + uint64_t cardSize = SD.cardSize() / (1024 * 1024); + Serial.printf("SD Card Size: %lluMB\n", cardSize); - listDir(SD, "/", 0); - createDir(SD, "/mydir"); - listDir(SD, "/", 0); - removeDir(SD, "/mydir"); - listDir(SD, "/", 2); - writeFile(SD, "/hello.txt", "Hello "); - appendFile(SD, "/hello.txt", "World!\n"); - readFile(SD, "/hello.txt"); - deleteFile(SD, "/foo.txt"); - renameFile(SD, "/hello.txt", "/foo.txt"); - readFile(SD, "/foo.txt"); - testFileIO(SD, "/test.txt"); - Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024)); - Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024)); + listDir(SD, "/", 0); + createDir(SD, "/mydir"); + listDir(SD, "/", 0); + removeDir(SD, "/mydir"); + listDir(SD, "/", 2); + writeFile(SD, "/hello.txt", "Hello "); + appendFile(SD, "/hello.txt", "World!\n"); + readFile(SD, "/hello.txt"); + deleteFile(SD, "/foo.txt"); + renameFile(SD, "/hello.txt", "/foo.txt"); + readFile(SD, "/foo.txt"); + testFileIO(SD, "/test.txt"); + Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024)); + Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024)); } -void loop(){ - +void loop() { } diff --git a/libraries/SD/examples/SD_time/SD_time.ino b/libraries/SD/examples/SD_time/SD_time.ino index 79f6edb0952..1716163145d 100644 --- a/libraries/SD/examples/SD_time/SD_time.ino +++ b/libraries/SD/examples/SD_time/SD_time.ino @@ -41,13 +41,13 @@ #include "FS.h" #include "SD.h" #include "SPI.h" -#include +#include #include -const char* ssid = "your-ssid"; -const char* password = "your-password"; +const char *ssid = "your-ssid"; +const char *password = "your-password"; -long timezone = 1; +long timezone = 1; byte daysavetime = 1; /* @@ -59,194 +59,191 @@ int mosi = -1; int cs = -1; */ -void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ - Serial.printf("Listing directory: %s\n", dirname); - - File root = fs.open(dirname); - if(!root){ - Serial.println("Failed to open directory"); - return; - } - if(!root.isDirectory()){ - Serial.println("Not a directory"); - return; - } - - File file = root.openNextFile(); - while(file){ - if(file.isDirectory()){ - Serial.print(" DIR : "); - Serial.print (file.name()); - time_t t= file.getLastWrite(); - struct tm * tmstruct = localtime(&t); - Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec); - if(levels){ - listDir(fs, file.path(), levels -1); - } - } else { - Serial.print(" FILE: "); - Serial.print(file.name()); - Serial.print(" SIZE: "); - Serial.print(file.size()); - time_t t= file.getLastWrite(); - struct tm * tmstruct = localtime(&t); - Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec); - } - file = root.openNextFile(); - } +void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { + Serial.printf("Listing directory: %s\n", dirname); + + File root = fs.open(dirname); + if (!root) { + Serial.println("Failed to open directory"); + return; + } + if (!root.isDirectory()) { + Serial.println("Not a directory"); + return; + } + + File file = root.openNextFile(); + while (file) { + if (file.isDirectory()) { + Serial.print(" DIR : "); + Serial.print(file.name()); + time_t t = file.getLastWrite(); + struct tm *tmstruct = localtime(&t); + Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); + if (levels) { + listDir(fs, file.path(), levels - 1); + } + } else { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print(" SIZE: "); + Serial.print(file.size()); + time_t t = file.getLastWrite(); + struct tm *tmstruct = localtime(&t); + Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); + } + file = root.openNextFile(); + } } -void createDir(fs::FS &fs, const char * path){ - Serial.printf("Creating Dir: %s\n", path); - if(fs.mkdir(path)){ - Serial.println("Dir created"); - } else { - Serial.println("mkdir failed"); - } +void createDir(fs::FS &fs, const char *path) { + Serial.printf("Creating Dir: %s\n", path); + if (fs.mkdir(path)) { + Serial.println("Dir created"); + } else { + Serial.println("mkdir failed"); + } } -void removeDir(fs::FS &fs, const char * path){ - Serial.printf("Removing Dir: %s\n", path); - if(fs.rmdir(path)){ - Serial.println("Dir removed"); - } else { - Serial.println("rmdir failed"); - } +void removeDir(fs::FS &fs, const char *path) { + Serial.printf("Removing Dir: %s\n", path); + if (fs.rmdir(path)) { + Serial.println("Dir removed"); + } else { + Serial.println("rmdir failed"); + } } -void readFile(fs::FS &fs, const char * path){ - Serial.printf("Reading file: %s\n", path); +void readFile(fs::FS &fs, const char *path) { + Serial.printf("Reading file: %s\n", path); - File file = fs.open(path); - if(!file){ - Serial.println("Failed to open file for reading"); - return; - } + File file = fs.open(path); + if (!file) { + Serial.println("Failed to open file for reading"); + return; + } - Serial.print("Read from file: "); - while(file.available()){ - Serial.write(file.read()); - } - file.close(); + Serial.print("Read from file: "); + while (file.available()) { + Serial.write(file.read()); + } + file.close(); } -void writeFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Writing file: %s\n", path); - - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("Failed to open file for writing"); - return; - } - if(file.print(message)){ - Serial.println("File written"); - } else { - Serial.println("Write failed"); - } - file.close(); +void writeFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Writing file: %s\n", path); + + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("Failed to open file for writing"); + return; + } + if (file.print(message)) { + Serial.println("File written"); + } else { + Serial.println("Write failed"); + } + file.close(); } -void appendFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Appending to file: %s\n", path); - - File file = fs.open(path, FILE_APPEND); - if(!file){ - Serial.println("Failed to open file for appending"); - return; - } - if(file.print(message)){ - Serial.println("Message appended"); - } else { - Serial.println("Append failed"); - } - file.close(); +void appendFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Appending to file: %s\n", path); + + File file = fs.open(path, FILE_APPEND); + if (!file) { + Serial.println("Failed to open file for appending"); + return; + } + if (file.print(message)) { + Serial.println("Message appended"); + } else { + Serial.println("Append failed"); + } + file.close(); } -void renameFile(fs::FS &fs, const char * path1, const char * path2){ - Serial.printf("Renaming file %s to %s\n", path1, path2); - if (fs.rename(path1, path2)) { - Serial.println("File renamed"); - } else { - Serial.println("Rename failed"); - } +void renameFile(fs::FS &fs, const char *path1, const char *path2) { + Serial.printf("Renaming file %s to %s\n", path1, path2); + if (fs.rename(path1, path2)) { + Serial.println("File renamed"); + } else { + Serial.println("Rename failed"); + } } -void deleteFile(fs::FS &fs, const char * path){ - Serial.printf("Deleting file: %s\n", path); - if(fs.remove(path)){ - Serial.println("File deleted"); - } else { - Serial.println("Delete failed"); - } +void deleteFile(fs::FS &fs, const char *path) { + Serial.printf("Deleting file: %s\n", path); + if (fs.remove(path)) { + Serial.println("File deleted"); + } else { + Serial.println("Delete failed"); + } } -void setup(){ - Serial.begin(115200); - // We start by connecting to a WiFi network - Serial.println(); - Serial.println(); - Serial.print("Connecting to "); - Serial.println(ssid); +void setup() { + Serial.begin(115200); + // We start by connecting to a WiFi network + Serial.println(); + Serial.println(); + Serial.print("Connecting to "); + Serial.println(ssid); + + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + Serial.println("Contacting Time Server"); + configTime(3600 * timezone, daysavetime * 3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); + struct tm tmstruct; + delay(2000); + tmstruct.tm_year = 0; + getLocalTime(&tmstruct, 5000); + Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec); + Serial.println(""); - WiFi.begin(ssid, password); - - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } - Serial.println("WiFi connected"); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println("Contacting Time Server"); - configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); - struct tm tmstruct ; - delay(2000); - tmstruct.tm_year = 0; - getLocalTime(&tmstruct, 5000); - Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct.tm_year)+1900,( tmstruct.tm_mon)+1, tmstruct.tm_mday,tmstruct.tm_hour , tmstruct.tm_min, tmstruct.tm_sec); - Serial.println(""); - #ifdef REASSIGN_PINS - SPI.begin(sck, miso, mosi, cs); - if(!SD.begin(cs)){ + SPI.begin(sck, miso, mosi, cs); + if (!SD.begin(cs)) { #else - if(!SD.begin()){ + if (!SD.begin()) { #endif - Serial.println("Card Mount Failed"); - return; - } - uint8_t cardType = SD.cardType(); - - if(cardType == CARD_NONE){ - Serial.println("No SD card attached"); - return; - } - - Serial.print("SD Card Type: "); - if(cardType == CARD_MMC){ - Serial.println("MMC"); - } else if(cardType == CARD_SD){ - Serial.println("SDSC"); - } else if(cardType == CARD_SDHC){ - Serial.println("SDHC"); - } else { - Serial.println("UNKNOWN"); - } - - uint64_t cardSize = SD.cardSize() / (1024 * 1024); - Serial.printf("SD Card Size: %lluMB\n", cardSize); - - listDir(SD, "/", 0); - removeDir(SD, "/mydir"); - createDir(SD, "/mydir"); - deleteFile(SD, "/hello.txt"); - writeFile(SD, "/hello.txt", "Hello "); - appendFile(SD, "/hello.txt", "World!\n"); - listDir(SD, "/", 0); + Serial.println("Card Mount Failed"); + return; + } + uint8_t cardType = SD.cardType(); + + if (cardType == CARD_NONE) { + Serial.println("No SD card attached"); + return; + } + + Serial.print("SD Card Type: "); + if (cardType == CARD_MMC) { + Serial.println("MMC"); + } else if (cardType == CARD_SD) { + Serial.println("SDSC"); + } else if (cardType == CARD_SDHC) { + Serial.println("SDHC"); + } else { + Serial.println("UNKNOWN"); + } + + uint64_t cardSize = SD.cardSize() / (1024 * 1024); + Serial.printf("SD Card Size: %lluMB\n", cardSize); + + listDir(SD, "/", 0); + removeDir(SD, "/mydir"); + createDir(SD, "/mydir"); + deleteFile(SD, "/hello.txt"); + writeFile(SD, "/hello.txt", "Hello "); + appendFile(SD, "/hello.txt", "World!\n"); + listDir(SD, "/", 0); } -void loop(){ - +void loop() { } - - diff --git a/libraries/SD/src/SD.cpp b/libraries/SD/src/SD.cpp index 75f9e235c9e..33f3f10c7af 100644 --- a/libraries/SD/src/SD.cpp +++ b/libraries/SD/src/SD.cpp @@ -20,115 +20,106 @@ using namespace fs; -SDFS::SDFS(FSImplPtr impl): FS(impl), _pdrv(0xFF) {} +SDFS::SDFS(FSImplPtr impl) + : FS(impl), _pdrv(0xFF) {} -bool SDFS::begin(uint8_t ssPin, SPIClass &spi, uint32_t frequency, const char * mountpoint, uint8_t max_files, bool format_if_empty) -{ - if(_pdrv != 0xFF) { - return true; - } +bool SDFS::begin(uint8_t ssPin, SPIClass& spi, uint32_t frequency, const char* mountpoint, uint8_t max_files, bool format_if_empty) { + if (_pdrv != 0xFF) { + return true; + } - spi.begin(); + spi.begin(); - _pdrv = sdcard_init(ssPin, &spi, frequency); - if(_pdrv == 0xFF) { - return false; - } + _pdrv = sdcard_init(ssPin, &spi, frequency); + if (_pdrv == 0xFF) { + return false; + } - if(!sdcard_mount(_pdrv, mountpoint, max_files, format_if_empty)){ - sdcard_unmount(_pdrv); - sdcard_uninit(_pdrv); - _pdrv = 0xFF; - return false; - } + if (!sdcard_mount(_pdrv, mountpoint, max_files, format_if_empty)) { + sdcard_unmount(_pdrv); + sdcard_uninit(_pdrv); + _pdrv = 0xFF; + return false; + } - _impl->mountpoint(mountpoint); - return true; + _impl->mountpoint(mountpoint); + return true; } -void SDFS::end() -{ - if(_pdrv != 0xFF) { - _impl->mountpoint(NULL); - sdcard_unmount(_pdrv); +void SDFS::end() { + if (_pdrv != 0xFF) { + _impl->mountpoint(NULL); + sdcard_unmount(_pdrv); - sdcard_uninit(_pdrv); - _pdrv = 0xFF; - } + sdcard_uninit(_pdrv); + _pdrv = 0xFF; + } } -sdcard_type_t SDFS::cardType() -{ - if(_pdrv == 0xFF) { - return CARD_NONE; - } - return sdcard_type(_pdrv); +sdcard_type_t SDFS::cardType() { + if (_pdrv == 0xFF) { + return CARD_NONE; + } + return sdcard_type(_pdrv); } -uint64_t SDFS::cardSize() -{ - if(_pdrv == 0xFF) { - return 0; - } - size_t sectors = sdcard_num_sectors(_pdrv); - size_t sectorSize = sdcard_sector_size(_pdrv); - return (uint64_t)sectors * sectorSize; +uint64_t SDFS::cardSize() { + if (_pdrv == 0xFF) { + return 0; + } + size_t sectors = sdcard_num_sectors(_pdrv); + size_t sectorSize = sdcard_sector_size(_pdrv); + return (uint64_t)sectors * sectorSize; } -size_t SDFS::numSectors() -{ - if(_pdrv == 0xFF) { - return 0; - } - return sdcard_num_sectors(_pdrv); +size_t SDFS::numSectors() { + if (_pdrv == 0xFF) { + return 0; + } + return sdcard_num_sectors(_pdrv); } -size_t SDFS::sectorSize() -{ - if(_pdrv == 0xFF) { - return 0; - } - return sdcard_sector_size(_pdrv); +size_t SDFS::sectorSize() { + if (_pdrv == 0xFF) { + return 0; + } + return sdcard_sector_size(_pdrv); } -uint64_t SDFS::totalBytes() -{ - FATFS* fsinfo; - DWORD fre_clust; - char drv[3] = {(char)(48+_pdrv), ':', 0}; - if(f_getfree(drv,&fre_clust,&fsinfo)!= 0) return 0; - uint64_t size = ((uint64_t)(fsinfo->csize))*(fsinfo->n_fatent - 2) +uint64_t SDFS::totalBytes() { + FATFS* fsinfo; + DWORD fre_clust; + char drv[3] = { (char)(48 + _pdrv), ':', 0 }; + if (f_getfree(drv, &fre_clust, &fsinfo) != 0) return 0; + uint64_t size = ((uint64_t)(fsinfo->csize)) * (fsinfo->n_fatent - 2) #if _MAX_SS != 512 - *(fsinfo->ssize); + * (fsinfo->ssize); #else - *512; + * 512; #endif - return size; + return size; } -uint64_t SDFS::usedBytes() -{ - FATFS* fsinfo; - DWORD fre_clust; - char drv[3] = {(char)(48+_pdrv), ':', 0}; - if(f_getfree(drv,&fre_clust,&fsinfo)!= 0) return 0; - uint64_t size = ((uint64_t)(fsinfo->csize))*((fsinfo->n_fatent - 2) - (fsinfo->free_clst)) +uint64_t SDFS::usedBytes() { + FATFS* fsinfo; + DWORD fre_clust; + char drv[3] = { (char)(48 + _pdrv), ':', 0 }; + if (f_getfree(drv, &fre_clust, &fsinfo) != 0) return 0; + uint64_t size = ((uint64_t)(fsinfo->csize)) * ((fsinfo->n_fatent - 2) - (fsinfo->free_clst)) #if _MAX_SS != 512 - *(fsinfo->ssize); + * (fsinfo->ssize); #else - *512; + * 512; #endif - return size; + return size; } -bool SDFS::readRAW(uint8_t* buffer, uint32_t sector) -{ - return sd_read_raw(_pdrv, buffer, sector); +bool SDFS::readRAW(uint8_t* buffer, uint32_t sector) { + return sd_read_raw(_pdrv, buffer, sector); } -bool SDFS::writeRAW(uint8_t* buffer, uint32_t sector) -{ - return sd_write_raw(_pdrv, buffer, sector); +bool SDFS::writeRAW(uint8_t* buffer, uint32_t sector) { + return sd_write_raw(_pdrv, buffer, sector); } diff --git a/libraries/SD/src/SD.h b/libraries/SD/src/SD.h index a5548579bd7..1799b67eaf0 100644 --- a/libraries/SD/src/SD.h +++ b/libraries/SD/src/SD.h @@ -18,26 +18,24 @@ #include "SPI.h" #include "sd_defines.h" -namespace fs -{ +namespace fs { -class SDFS : public FS -{ +class SDFS : public FS { protected: - uint8_t _pdrv; + uint8_t _pdrv; public: - SDFS(FSImplPtr impl); - bool begin(uint8_t ssPin=SS, SPIClass &spi=SPI, uint32_t frequency=4000000, const char * mountpoint="/sd", uint8_t max_files=5, bool format_if_empty=false); - void end(); - sdcard_type_t cardType(); - uint64_t cardSize(); - size_t numSectors(); - size_t sectorSize(); - uint64_t totalBytes(); - uint64_t usedBytes(); - bool readRAW(uint8_t* buffer, uint32_t sector); - bool writeRAW(uint8_t* buffer, uint32_t sector); + SDFS(FSImplPtr impl); + bool begin(uint8_t ssPin = SS, SPIClass& spi = SPI, uint32_t frequency = 4000000, const char* mountpoint = "/sd", uint8_t max_files = 5, bool format_if_empty = false); + void end(); + sdcard_type_t cardType(); + uint64_t cardSize(); + size_t numSectors(); + size_t sectorSize(); + uint64_t totalBytes(); + uint64_t usedBytes(); + bool readRAW(uint8_t* buffer, uint32_t sector); + bool writeRAW(uint8_t* buffer, uint32_t sector); }; } @@ -45,8 +43,8 @@ class SDFS : public FS extern fs::SDFS SD; using namespace fs; -typedef fs::File SDFile; -typedef fs::SDFS SDFileSystemClass; -#define SDFileSystem SD +typedef fs::File SDFile; +typedef fs::SDFS SDFileSystemClass; +#define SDFileSystem SD #endif /* _SD_H_ */ diff --git a/libraries/SD/src/sd_defines.h b/libraries/SD/src/sd_defines.h index 6e42855ac61..9a6b8399165 100644 --- a/libraries/SD/src/sd_defines.h +++ b/libraries/SD/src/sd_defines.h @@ -15,11 +15,11 @@ #define _SD_DEFINES_H_ typedef enum { - CARD_NONE, - CARD_MMC, - CARD_SD, - CARD_SDHC, - CARD_UNKNOWN + CARD_NONE, + CARD_MMC, + CARD_SD, + CARD_SDHC, + CARD_UNKNOWN } sdcard_type_t; #endif /* _SD_DISKIO_H_ */ diff --git a/libraries/SD/src/sd_diskio.cpp b/libraries/SD/src/sd_diskio.cpp index 39432ef7857..245c3c33d38 100644 --- a/libraries/SD/src/sd_diskio.cpp +++ b/libraries/SD/src/sd_diskio.cpp @@ -20,76 +20,76 @@ #include "esp32-hal-periman.h" extern "C" { - #include "ff.h" - #include "diskio.h" +#include "ff.h" +#include "diskio.h" #if ESP_IDF_VERSION_MAJOR > 3 - #include "diskio_impl.h" +#include "diskio_impl.h" #endif - //#include "esp_vfs.h" - #include "esp_vfs_fat.h" - char CRC7(const char* data, int length); - unsigned short CRC16(const char* data, int length); +//#include "esp_vfs.h" +#include "esp_vfs_fat.h" + char CRC7(const char* data, int length); + unsigned short CRC16(const char* data, int length); } typedef enum { - GO_IDLE_STATE = 0, - SEND_OP_COND = 1, - SEND_CID = 2, - SEND_RELATIVE_ADDR = 3, - SEND_SWITCH_FUNC = 6, - SEND_IF_COND = 8, - SEND_CSD = 9, - STOP_TRANSMISSION = 12, - SEND_STATUS = 13, - SET_BLOCKLEN = 16, - READ_BLOCK_SINGLE = 17, - READ_BLOCK_MULTIPLE = 18, - SEND_NUM_WR_BLOCKS = 22, - SET_WR_BLK_ERASE_COUNT = 23, - WRITE_BLOCK_SINGLE = 24, - WRITE_BLOCK_MULTIPLE = 25, - APP_OP_COND = 41, - APP_CLR_CARD_DETECT = 42, - APP_CMD = 55, - READ_OCR = 58, - CRC_ON_OFF = 59 + GO_IDLE_STATE = 0, + SEND_OP_COND = 1, + SEND_CID = 2, + SEND_RELATIVE_ADDR = 3, + SEND_SWITCH_FUNC = 6, + SEND_IF_COND = 8, + SEND_CSD = 9, + STOP_TRANSMISSION = 12, + SEND_STATUS = 13, + SET_BLOCKLEN = 16, + READ_BLOCK_SINGLE = 17, + READ_BLOCK_MULTIPLE = 18, + SEND_NUM_WR_BLOCKS = 22, + SET_WR_BLK_ERASE_COUNT = 23, + WRITE_BLOCK_SINGLE = 24, + WRITE_BLOCK_MULTIPLE = 25, + APP_OP_COND = 41, + APP_CLR_CARD_DETECT = 42, + APP_CMD = 55, + READ_OCR = 58, + CRC_ON_OFF = 59 } ardu_sdcard_command_t; typedef struct { - uint8_t ssPin; - SPIClass * spi; - int frequency; - char * base_path; - sdcard_type_t type; - unsigned long sectors; - bool supports_crc; - int status; + uint8_t ssPin; + SPIClass* spi; + int frequency; + char* base_path; + sdcard_type_t type; + unsigned long sectors; + bool supports_crc; + int status; } ardu_sdcard_t; static ardu_sdcard_t* s_cards[FF_VOLUMES] = { NULL }; #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR -const char * fferr2str[] = { - "(0) Succeeded", - "(1) A hard error occurred in the low level disk I/O layer", - "(2) Assertion failed", - "(3) The physical drive cannot work", - "(4) Could not find the file", - "(5) Could not find the path", - "(6) The path name format is invalid", - "(7) Access denied due to prohibited access or directory full", - "(8) Access denied due to prohibited access", - "(9) The file/directory object is invalid", - "(10) The physical drive is write protected", - "(11) The logical drive number is invalid", - "(12) The volume has no work area", - "(13) There is no valid FAT volume", - "(14) The f_mkfs() aborted due to any problem", - "(15) Could not get a grant to access the volume within defined period", - "(16) The operation is rejected according to the file sharing policy", - "(17) LFN working buffer could not be allocated", - "(18) Number of open files > FF_FS_LOCK", - "(19) Given parameter is invalid" +const char* fferr2str[] = { + "(0) Succeeded", + "(1) A hard error occurred in the low level disk I/O layer", + "(2) Assertion failed", + "(3) The physical drive cannot work", + "(4) Could not find the file", + "(5) Could not find the path", + "(6) The path name format is invalid", + "(7) Access denied due to prohibited access or directory full", + "(8) Access denied due to prohibited access", + "(9) The file/directory object is invalid", + "(10) The physical drive is write protected", + "(11) The logical drive number is invalid", + "(12) The volume has no work area", + "(13) There is no valid FAT volume", + "(14) The f_mkfs() aborted due to any problem", + "(15) Could not get a grant to access the volume within defined period", + "(16) The operation is rejected according to the file sharing policy", + "(17) LFN working buffer could not be allocated", + "(18) Number of open files > FF_FS_LOCK", + "(19) Given parameter is invalid" }; #endif @@ -97,394 +97,374 @@ const char * fferr2str[] = { * SD SPI * */ -bool sdWait(uint8_t pdrv, int timeout) -{ - char resp; - uint32_t start = millis(); +bool sdWait(uint8_t pdrv, int timeout) { + char resp; + uint32_t start = millis(); - do { - resp = s_cards[pdrv]->spi->transfer(0xFF); - } while (resp == 0x00 && (millis() - start) < (unsigned int)timeout); + do { + resp = s_cards[pdrv]->spi->transfer(0xFF); + } while (resp == 0x00 && (millis() - start) < (unsigned int)timeout); - if (!resp) { - log_w("Wait Failed"); - } - return (resp > 0x00); + if (!resp) { + log_w("Wait Failed"); + } + return (resp > 0x00); } -void sdStop(uint8_t pdrv) -{ - s_cards[pdrv]->spi->write(0xFD); +void sdStop(uint8_t pdrv) { + s_cards[pdrv]->spi->write(0xFD); } -void sdDeselectCard(uint8_t pdrv) -{ - ardu_sdcard_t * card = s_cards[pdrv]; - digitalWrite(card->ssPin, HIGH); +void sdDeselectCard(uint8_t pdrv) { + ardu_sdcard_t* card = s_cards[pdrv]; + digitalWrite(card->ssPin, HIGH); } -bool sdSelectCard(uint8_t pdrv) -{ - ardu_sdcard_t * card = s_cards[pdrv]; - digitalWrite(card->ssPin, LOW); - bool s = sdWait(pdrv, 500); - if (!s) { - log_e("Select Failed"); - digitalWrite(card->ssPin, HIGH); - return false; - } - return true; +bool sdSelectCard(uint8_t pdrv) { + ardu_sdcard_t* card = s_cards[pdrv]; + digitalWrite(card->ssPin, LOW); + bool s = sdWait(pdrv, 500); + if (!s) { + log_e("Select Failed"); + digitalWrite(card->ssPin, HIGH); + return false; + } + return true; } -char sdCommand(uint8_t pdrv, char cmd, unsigned int arg, unsigned int* resp) -{ - char token; - ardu_sdcard_t * card = s_cards[pdrv]; - - for (int f = 0; f < 3; f++) { - if (cmd == SEND_NUM_WR_BLOCKS || cmd == SET_WR_BLK_ERASE_COUNT || cmd == APP_OP_COND || cmd == APP_CLR_CARD_DETECT) { - token = sdCommand(pdrv, APP_CMD, 0, NULL); - sdDeselectCard(pdrv); - if (token > 1) { - break; - } - if(!sdSelectCard(pdrv)) { - token = 0xFF; - break; - } - } - - char cmdPacket[7]; - cmdPacket[0] = cmd | 0x40; - cmdPacket[1] = arg >> 24; - cmdPacket[2] = arg >> 16; - cmdPacket[3] = arg >> 8; - cmdPacket[4] = arg; - if(card->supports_crc || cmd == GO_IDLE_STATE || cmd == SEND_IF_COND) { - cmdPacket[5] = (CRC7(cmdPacket, 5) << 1) | 0x01; - } else { - cmdPacket[5] = 0x01; - } - cmdPacket[6] = 0xFF; - - card->spi->writeBytes((uint8_t*)cmdPacket, (cmd == STOP_TRANSMISSION)?7:6); +char sdCommand(uint8_t pdrv, char cmd, unsigned int arg, unsigned int* resp) { + char token; + ardu_sdcard_t* card = s_cards[pdrv]; - for (int i = 0; i < 9; i++) { - token = card->spi->transfer(0xFF); - if (!(token & 0x80)) { - break; - } - } + for (int f = 0; f < 3; f++) { + if (cmd == SEND_NUM_WR_BLOCKS || cmd == SET_WR_BLK_ERASE_COUNT || cmd == APP_OP_COND || cmd == APP_CLR_CARD_DETECT) { + token = sdCommand(pdrv, APP_CMD, 0, NULL); + sdDeselectCard(pdrv); + if (token > 1) { + break; + } + if (!sdSelectCard(pdrv)) { + token = 0xFF; + break; + } + } - if (token == 0xFF) { - log_w("no token received"); - sdDeselectCard(pdrv); - delay(100); - sdSelectCard(pdrv); - continue; - } else if (token & 0x08) { - log_w("crc error"); - sdDeselectCard(pdrv); - delay(100); - sdSelectCard(pdrv); - continue; - } else if (token > 1) { - log_w("token error [%u] 0x%x", cmd, token); - break; - } + char cmdPacket[7]; + cmdPacket[0] = cmd | 0x40; + cmdPacket[1] = arg >> 24; + cmdPacket[2] = arg >> 16; + cmdPacket[3] = arg >> 8; + cmdPacket[4] = arg; + if (card->supports_crc || cmd == GO_IDLE_STATE || cmd == SEND_IF_COND) { + cmdPacket[5] = (CRC7(cmdPacket, 5) << 1) | 0x01; + } else { + cmdPacket[5] = 0x01; + } + cmdPacket[6] = 0xFF; - if (cmd == SEND_STATUS && resp) { - *resp = card->spi->transfer(0xFF); - } else if ((cmd == SEND_IF_COND || cmd == READ_OCR) && resp) { - *resp = card->spi->transfer32(0xFFFFFFFF); - } + card->spi->writeBytes((uint8_t*)cmdPacket, (cmd == STOP_TRANSMISSION) ? 7 : 6); + for (int i = 0; i < 9; i++) { + token = card->spi->transfer(0xFF); + if (!(token & 0x80)) { break; + } } + if (token == 0xFF) { - log_e("Card Failed! cmd: 0x%02x", cmd); - card->status = STA_NOINIT; - } - return token; + log_w("no token received"); + sdDeselectCard(pdrv); + delay(100); + sdSelectCard(pdrv); + continue; + } else if (token & 0x08) { + log_w("crc error"); + sdDeselectCard(pdrv); + delay(100); + sdSelectCard(pdrv); + continue; + } else if (token > 1) { + log_w("token error [%u] 0x%x", cmd, token); + break; + } + + if (cmd == SEND_STATUS && resp) { + *resp = card->spi->transfer(0xFF); + } else if ((cmd == SEND_IF_COND || cmd == READ_OCR) && resp) { + *resp = card->spi->transfer32(0xFFFFFFFF); + } + + break; + } + if (token == 0xFF) { + log_e("Card Failed! cmd: 0x%02x", cmd); + card->status = STA_NOINIT; + } + return token; } -bool sdReadBytes(uint8_t pdrv, char* buffer, int length) -{ - char token; - unsigned short crc; - ardu_sdcard_t * card = s_cards[pdrv]; +bool sdReadBytes(uint8_t pdrv, char* buffer, int length) { + char token; + unsigned short crc; + ardu_sdcard_t* card = s_cards[pdrv]; - uint32_t start = millis(); - do { - token = card->spi->transfer(0xFF); - } while (token == 0xFF && (millis() - start) < 500); + uint32_t start = millis(); + do { + token = card->spi->transfer(0xFF); + } while (token == 0xFF && (millis() - start) < 500); - if (token != 0xFE) { - return false; - } + if (token != 0xFE) { + return false; + } - card->spi->transferBytes(NULL, (uint8_t*)buffer, length); - crc = card->spi->transfer16(0xFFFF); - return (!card->supports_crc || crc == CRC16(buffer, length)); + card->spi->transferBytes(NULL, (uint8_t*)buffer, length); + crc = card->spi->transfer16(0xFFFF); + return (!card->supports_crc || crc == CRC16(buffer, length)); } -char sdWriteBytes(uint8_t pdrv, const char* buffer, char token) -{ - ardu_sdcard_t * card = s_cards[pdrv]; - unsigned short crc = (card->supports_crc)?CRC16(buffer, 512):0xFFFF; - if (!sdWait(pdrv, 500)) { - return 0; - } +char sdWriteBytes(uint8_t pdrv, const char* buffer, char token) { + ardu_sdcard_t* card = s_cards[pdrv]; + unsigned short crc = (card->supports_crc) ? CRC16(buffer, 512) : 0xFFFF; + if (!sdWait(pdrv, 500)) { + return 0; + } - card->spi->write(token); - card->spi->writeBytes((uint8_t*)buffer, 512); - card->spi->write16(crc); - return (card->spi->transfer(0xFF) & 0x1F); + card->spi->write(token); + card->spi->writeBytes((uint8_t*)buffer, 512); + card->spi->write16(crc); + return (card->spi->transfer(0xFF) & 0x1F); } /* * SPI SDCARD Communication * */ -char sdTransaction(uint8_t pdrv, char cmd, unsigned int arg, unsigned int* resp) -{ - if(!sdSelectCard(pdrv)) { - return 0xFF; - } - char token = sdCommand(pdrv, cmd, arg, resp); - sdDeselectCard(pdrv); - return token; +char sdTransaction(uint8_t pdrv, char cmd, unsigned int arg, unsigned int* resp) { + if (!sdSelectCard(pdrv)) { + return 0xFF; + } + char token = sdCommand(pdrv, cmd, arg, resp); + sdDeselectCard(pdrv); + return token; } -bool sdReadSector(uint8_t pdrv, char* buffer, unsigned long long sector) -{ - for (int f = 0; f < 3; f++) { - if(!sdSelectCard(pdrv)) { - return false; - } - if (!sdCommand(pdrv, READ_BLOCK_SINGLE, (s_cards[pdrv]->type == CARD_SDHC) ? sector : sector << 9, NULL)) { - bool success = sdReadBytes(pdrv, buffer, 512); - sdDeselectCard(pdrv); - if (success) { - return true; - } - } else { - break; - } +bool sdReadSector(uint8_t pdrv, char* buffer, unsigned long long sector) { + for (int f = 0; f < 3; f++) { + if (!sdSelectCard(pdrv)) { + return false; + } + if (!sdCommand(pdrv, READ_BLOCK_SINGLE, (s_cards[pdrv]->type == CARD_SDHC) ? sector : sector << 9, NULL)) { + bool success = sdReadBytes(pdrv, buffer, 512); + sdDeselectCard(pdrv); + if (success) { + return true; + } + } else { + break; } - sdDeselectCard(pdrv); - return false; + } + sdDeselectCard(pdrv); + return false; } -bool sdReadSectors(uint8_t pdrv, char* buffer, unsigned long long sector, int count) -{ - for (int f = 0; f < 3;) { - if(!sdSelectCard(pdrv)) { - return false; +bool sdReadSectors(uint8_t pdrv, char* buffer, unsigned long long sector, int count) { + for (int f = 0; f < 3;) { + if (!sdSelectCard(pdrv)) { + return false; + } + + if (!sdCommand(pdrv, READ_BLOCK_MULTIPLE, (s_cards[pdrv]->type == CARD_SDHC) ? sector : sector << 9, NULL)) { + do { + if (!sdReadBytes(pdrv, buffer, 512)) { + f++; + break; } - if (!sdCommand(pdrv, READ_BLOCK_MULTIPLE, (s_cards[pdrv]->type == CARD_SDHC) ? sector : sector << 9, NULL)) { - do { - if (!sdReadBytes(pdrv, buffer, 512)) { - f++; - break; - } - - sector++; - buffer += 512; - f = 0; - } while (--count); - - if (sdCommand(pdrv, STOP_TRANSMISSION, 0, NULL)) { - log_e("command failed"); - break; - } + sector++; + buffer += 512; + f = 0; + } while (--count); - sdDeselectCard(pdrv); - if (count == 0) { - return true; - } - } else { - break; - } + if (sdCommand(pdrv, STOP_TRANSMISSION, 0, NULL)) { + log_e("command failed"); + break; + } + + sdDeselectCard(pdrv); + if (count == 0) { + return true; + } + } else { + break; } - sdDeselectCard(pdrv); - return false; + } + sdDeselectCard(pdrv); + return false; } -bool sdWriteSector(uint8_t pdrv, const char* buffer, unsigned long long sector) -{ - for (int f = 0; f < 3; f++) { - if(!sdSelectCard(pdrv)) { - return false; - } - if (!sdCommand(pdrv, WRITE_BLOCK_SINGLE, (s_cards[pdrv]->type == CARD_SDHC) ? sector : sector << 9, NULL)) { - char token = sdWriteBytes(pdrv, buffer, 0xFE); - sdDeselectCard(pdrv); +bool sdWriteSector(uint8_t pdrv, const char* buffer, unsigned long long sector) { + for (int f = 0; f < 3; f++) { + if (!sdSelectCard(pdrv)) { + return false; + } + if (!sdCommand(pdrv, WRITE_BLOCK_SINGLE, (s_cards[pdrv]->type == CARD_SDHC) ? sector : sector << 9, NULL)) { + char token = sdWriteBytes(pdrv, buffer, 0xFE); + sdDeselectCard(pdrv); - if (token == 0x0A) { - continue; - } else if (token == 0x0C) { - return false; - } + if (token == 0x0A) { + continue; + } else if (token == 0x0C) { + return false; + } - unsigned int resp; - if (sdTransaction(pdrv, SEND_STATUS, 0, &resp) || resp) { - return false; - } - return true; - } else { - break; - } + unsigned int resp; + if (sdTransaction(pdrv, SEND_STATUS, 0, &resp) || resp) { + return false; + } + return true; + } else { + break; } - sdDeselectCard(pdrv); - return false; + } + sdDeselectCard(pdrv); + return false; } -bool sdWriteSectors(uint8_t pdrv, const char* buffer, unsigned long long sector, int count) -{ - char token; - const char* currentBuffer = buffer; - unsigned long long currentSector = sector; - int currentCount = count; - ardu_sdcard_t * card = s_cards[pdrv]; - - for (int f = 0; f < 3;) { - if (card->type != CARD_MMC) { - if (sdTransaction(pdrv, SET_WR_BLK_ERASE_COUNT, currentCount, NULL)) { - return false; - } - } +bool sdWriteSectors(uint8_t pdrv, const char* buffer, unsigned long long sector, int count) { + char token; + const char* currentBuffer = buffer; + unsigned long long currentSector = sector; + int currentCount = count; + ardu_sdcard_t* card = s_cards[pdrv]; - if(!sdSelectCard(pdrv)) { - return false; + for (int f = 0; f < 3;) { + if (card->type != CARD_MMC) { + if (sdTransaction(pdrv, SET_WR_BLK_ERASE_COUNT, currentCount, NULL)) { + return false; + } + } + + if (!sdSelectCard(pdrv)) { + return false; + } + + if (!sdCommand(pdrv, WRITE_BLOCK_MULTIPLE, (card->type == CARD_SDHC) ? currentSector : currentSector << 9, NULL)) { + do { + token = sdWriteBytes(pdrv, currentBuffer, 0xFC); + if (token != 0x05) { + f++; + break; } + currentBuffer += 512; + f = 0; + } while (--currentCount); - if (!sdCommand(pdrv, WRITE_BLOCK_MULTIPLE, (card->type == CARD_SDHC) ? currentSector : currentSector << 9, NULL)) { - do { - token = sdWriteBytes(pdrv, currentBuffer, 0xFC); - if (token != 0x05) { - f++; - break; - } - currentBuffer += 512; - f = 0; - } while (--currentCount); - - if (!sdWait(pdrv, 500)) { - break; - } + if (!sdWait(pdrv, 500)) { + break; + } + + if (currentCount == 0) { + sdStop(pdrv); + sdDeselectCard(pdrv); - if (currentCount == 0) { - sdStop(pdrv); - sdDeselectCard(pdrv); - - unsigned int resp; - if (sdTransaction(pdrv, SEND_STATUS, 0, &resp) || resp) { - return false; - } - return true; - } else { - if (sdCommand(pdrv, STOP_TRANSMISSION, 0, NULL)) { - break; - } - - if (token == 0x0A) { - sdDeselectCard(pdrv); - unsigned int writtenBlocks = 0; - if (card->type != CARD_MMC && sdSelectCard(pdrv)) { - if (!sdCommand(pdrv, SEND_NUM_WR_BLOCKS, 0, NULL)) { - char acmdData[4]; - if (sdReadBytes(pdrv, acmdData, 4)) { - writtenBlocks = acmdData[0] << 24; - writtenBlocks |= acmdData[1] << 16; - writtenBlocks |= acmdData[2] << 8; - writtenBlocks |= acmdData[3]; - } - } - sdDeselectCard(pdrv); - } - currentBuffer = buffer + (writtenBlocks << 9); - currentSector = sector + writtenBlocks; - currentCount = count - writtenBlocks; - continue; - } else { - break; - } + unsigned int resp; + if (sdTransaction(pdrv, SEND_STATUS, 0, &resp) || resp) { + return false; + } + return true; + } else { + if (sdCommand(pdrv, STOP_TRANSMISSION, 0, NULL)) { + break; + } + + if (token == 0x0A) { + sdDeselectCard(pdrv); + unsigned int writtenBlocks = 0; + if (card->type != CARD_MMC && sdSelectCard(pdrv)) { + if (!sdCommand(pdrv, SEND_NUM_WR_BLOCKS, 0, NULL)) { + char acmdData[4]; + if (sdReadBytes(pdrv, acmdData, 4)) { + writtenBlocks = acmdData[0] << 24; + writtenBlocks |= acmdData[1] << 16; + writtenBlocks |= acmdData[2] << 8; + writtenBlocks |= acmdData[3]; + } } + sdDeselectCard(pdrv); + } + currentBuffer = buffer + (writtenBlocks << 9); + currentSector = sector + writtenBlocks; + currentCount = count - writtenBlocks; + continue; } else { - break; + break; } + } + } else { + break; } - sdDeselectCard(pdrv); - return false; + } + sdDeselectCard(pdrv); + return false; } -unsigned long sdGetSectorsCount(uint8_t pdrv) -{ - for (int f = 0; f < 3; f++) { - if(!sdSelectCard(pdrv)) { - return 0; - } - - if (!sdCommand(pdrv, SEND_CSD, 0, NULL)) { - char csd[16]; - bool success = sdReadBytes(pdrv, csd, 16); - sdDeselectCard(pdrv); - if (success) { - if ((csd[0] >> 6) == 0x01) { - unsigned long size = ( - ((unsigned long)(csd[7] & 0x3F) << 16) - | ((unsigned long)csd[8] << 8) - | csd[9] - ) + 1; - return size << 10; - } - unsigned long size = ( - ((unsigned long)(csd[6] & 0x03) << 10) - | ((unsigned long)csd[7] << 2) - | ((csd[8] & 0xC0) >> 6) - ) + 1; - size <<= (( - ((csd[9] & 0x03) << 1) - | ((csd[10] & 0x80) >> 7) - ) + 2); - size <<= (csd[5] & 0x0F); - return size >> 9; - } - } else { - break; +unsigned long sdGetSectorsCount(uint8_t pdrv) { + for (int f = 0; f < 3; f++) { + if (!sdSelectCard(pdrv)) { + return 0; + } + + if (!sdCommand(pdrv, SEND_CSD, 0, NULL)) { + char csd[16]; + bool success = sdReadBytes(pdrv, csd, 16); + sdDeselectCard(pdrv); + if (success) { + if ((csd[0] >> 6) == 0x01) { + unsigned long size = (((unsigned long)(csd[7] & 0x3F) << 16) + | ((unsigned long)csd[8] << 8) + | csd[9]) + + 1; + return size << 10; } + unsigned long size = (((unsigned long)(csd[6] & 0x03) << 10) + | ((unsigned long)csd[7] << 2) + | ((csd[8] & 0xC0) >> 6)) + + 1; + size <<= (( + ((csd[9] & 0x03) << 1) + | ((csd[10] & 0x80) >> 7)) + + 2); + size <<= (csd[5] & 0x0F); + return size >> 9; + } + } else { + break; } + } - sdDeselectCard(pdrv); - return 0; + sdDeselectCard(pdrv); + return 0; } -namespace -{ - -struct AcquireSPI -{ - ardu_sdcard_t *card; - explicit AcquireSPI(ardu_sdcard_t* card) - : card(card) - { - card->spi->beginTransaction(SPISettings(card->frequency, MSBFIRST, SPI_MODE0)); - } - AcquireSPI(ardu_sdcard_t* card, int frequency) - : card(card) - { - card->spi->beginTransaction(SPISettings(frequency, MSBFIRST, SPI_MODE0)); - } - ~AcquireSPI() - { - card->spi->endTransaction(); - } +namespace { + +struct AcquireSPI { + ardu_sdcard_t* card; + explicit AcquireSPI(ardu_sdcard_t* card) + : card(card) { + card->spi->beginTransaction(SPISettings(card->frequency, MSBFIRST, SPI_MODE0)); + } + AcquireSPI(ardu_sdcard_t* card, int frequency) + : card(card) { + card->spi->beginTransaction(SPISettings(frequency, MSBFIRST, SPI_MODE0)); + } + ~AcquireSPI() { + card->spi->endTransaction(); + } private: - AcquireSPI(AcquireSPI const&); - AcquireSPI& operator=(AcquireSPI const&); + AcquireSPI(AcquireSPI const&); + AcquireSPI& operator=(AcquireSPI const&); }; } @@ -494,376 +474,361 @@ struct AcquireSPI * FATFS API * */ -DSTATUS ff_sd_initialize(uint8_t pdrv) -{ - char token; - unsigned int resp; - unsigned int start; - ardu_sdcard_t * card = s_cards[pdrv]; +DSTATUS ff_sd_initialize(uint8_t pdrv) { + char token; + unsigned int resp; + unsigned int start; + ardu_sdcard_t* card = s_cards[pdrv]; - if (!(card->status & STA_NOINIT)) { - return card->status; - } + if (!(card->status & STA_NOINIT)) { + return card->status; + } - AcquireSPI card_locked(card, 400000); + AcquireSPI card_locked(card, 400000); - digitalWrite(card->ssPin, HIGH); - for (uint8_t i = 0; i < 20; i++) { - card->spi->transfer(0XFF); - } + digitalWrite(card->ssPin, HIGH); + for (uint8_t i = 0; i < 20; i++) { + card->spi->transfer(0XFF); + } - // Fix mount issue - sdWait fail ignored before command GO_IDLE_STATE - digitalWrite(card->ssPin, LOW); - if(!sdWait(pdrv, 500)){ - log_w("sdWait fail ignored, card initialize continues"); - } - if (sdCommand(pdrv, GO_IDLE_STATE, 0, NULL) != 1){ - sdDeselectCard(pdrv); - log_w("GO_IDLE_STATE failed"); - goto unknown_card; - } + // Fix mount issue - sdWait fail ignored before command GO_IDLE_STATE + digitalWrite(card->ssPin, LOW); + if (!sdWait(pdrv, 500)) { + log_w("sdWait fail ignored, card initialize continues"); + } + if (sdCommand(pdrv, GO_IDLE_STATE, 0, NULL) != 1) { sdDeselectCard(pdrv); + log_w("GO_IDLE_STATE failed"); + goto unknown_card; + } + sdDeselectCard(pdrv); - token = sdTransaction(pdrv, CRC_ON_OFF, 1, NULL); - if (token == 0x5) { - //old card maybe - card->supports_crc = false; - } else if (token != 1) { - log_w("CRC_ON_OFF failed: %u", token); - goto unknown_card; - } + token = sdTransaction(pdrv, CRC_ON_OFF, 1, NULL); + if (token == 0x5) { + //old card maybe + card->supports_crc = false; + } else if (token != 1) { + log_w("CRC_ON_OFF failed: %u", token); + goto unknown_card; + } - if (sdTransaction(pdrv, SEND_IF_COND, 0x1AA, &resp) == 1) { - if ((resp & 0xFFF) != 0x1AA) { - log_w("SEND_IF_COND failed: %03X", resp & 0xFFF); - goto unknown_card; - } + if (sdTransaction(pdrv, SEND_IF_COND, 0x1AA, &resp) == 1) { + if ((resp & 0xFFF) != 0x1AA) { + log_w("SEND_IF_COND failed: %03X", resp & 0xFFF); + goto unknown_card; + } - if (sdTransaction(pdrv, READ_OCR, 0, &resp) != 1 || !(resp & (1 << 20))) { - log_w("READ_OCR failed: %X", resp); - goto unknown_card; - } + if (sdTransaction(pdrv, READ_OCR, 0, &resp) != 1 || !(resp & (1 << 20))) { + log_w("READ_OCR failed: %X", resp); + goto unknown_card; + } - start = millis(); - do { - token = sdTransaction(pdrv, APP_OP_COND, 0x40100000, NULL); - } while (token == 1 && (millis() - start) < 1000); + start = millis(); + do { + token = sdTransaction(pdrv, APP_OP_COND, 0x40100000, NULL); + } while (token == 1 && (millis() - start) < 1000); - if (token) { - log_w("APP_OP_COND failed: %u", token); - goto unknown_card; - } + if (token) { + log_w("APP_OP_COND failed: %u", token); + goto unknown_card; + } - if (!sdTransaction(pdrv, READ_OCR, 0, &resp)) { - if (resp & (1 << 30)) { - card->type = CARD_SDHC; - } else { - card->type = CARD_SD; - } - } else { - log_w("READ_OCR failed: %X", resp); - goto unknown_card; - } + if (!sdTransaction(pdrv, READ_OCR, 0, &resp)) { + if (resp & (1 << 30)) { + card->type = CARD_SDHC; + } else { + card->type = CARD_SD; + } } else { - if (sdTransaction(pdrv, READ_OCR, 0, &resp) != 1 || !(resp & (1 << 20))) { - log_w("READ_OCR failed: %X", resp); - goto unknown_card; - } + log_w("READ_OCR failed: %X", resp); + goto unknown_card; + } + } else { + if (sdTransaction(pdrv, READ_OCR, 0, &resp) != 1 || !(resp & (1 << 20))) { + log_w("READ_OCR failed: %X", resp); + goto unknown_card; + } - start = millis(); - do { - token = sdTransaction(pdrv, APP_OP_COND, 0x100000, NULL); - } while (token == 0x01 && (millis() - start) < 1000); + start = millis(); + do { + token = sdTransaction(pdrv, APP_OP_COND, 0x100000, NULL); + } while (token == 0x01 && (millis() - start) < 1000); - if (!token) { - card->type = CARD_SD; - } else { - start = millis(); - do { - token = sdTransaction(pdrv, SEND_OP_COND, 0x100000, NULL); - } while (token != 0x00 && (millis() - start) < 1000); - - if (token == 0x00) { - card->type = CARD_MMC; - } else { - log_w("SEND_OP_COND failed: %u", token); - goto unknown_card; - } - } + if (!token) { + card->type = CARD_SD; + } else { + start = millis(); + do { + token = sdTransaction(pdrv, SEND_OP_COND, 0x100000, NULL); + } while (token != 0x00 && (millis() - start) < 1000); + + if (token == 0x00) { + card->type = CARD_MMC; + } else { + log_w("SEND_OP_COND failed: %u", token); + goto unknown_card; + } } + } - if (card->type != CARD_MMC) { - if (sdTransaction(pdrv, APP_CLR_CARD_DETECT, 0, NULL)) { - log_w("APP_CLR_CARD_DETECT failed"); - goto unknown_card; - } + if (card->type != CARD_MMC) { + if (sdTransaction(pdrv, APP_CLR_CARD_DETECT, 0, NULL)) { + log_w("APP_CLR_CARD_DETECT failed"); + goto unknown_card; } + } - if (card->type != CARD_SDHC) { - if (sdTransaction(pdrv, SET_BLOCKLEN, 512, NULL) != 0x00) { - log_w("SET_BLOCKLEN failed"); - goto unknown_card; - } + if (card->type != CARD_SDHC) { + if (sdTransaction(pdrv, SET_BLOCKLEN, 512, NULL) != 0x00) { + log_w("SET_BLOCKLEN failed"); + goto unknown_card; } + } - card->sectors = sdGetSectorsCount(pdrv); + card->sectors = sdGetSectorsCount(pdrv); - if (card->frequency > 25000000) { - card->frequency = 25000000; - } + if (card->frequency > 25000000) { + card->frequency = 25000000; + } - card->status &= ~STA_NOINIT; - return card->status; + card->status &= ~STA_NOINIT; + return card->status; unknown_card: - card->type = CARD_UNKNOWN; - return card->status; -} - -DSTATUS ff_sd_status(uint8_t pdrv) -{ - ardu_sdcard_t * card = s_cards[pdrv]; - AcquireSPI lock(card); - - if(sdTransaction(pdrv, SEND_STATUS, 0, NULL)) - { - log_e("Check status failed"); - return STA_NOINIT; - } - return s_cards[pdrv]->status; + card->type = CARD_UNKNOWN; + return card->status; } -DRESULT ff_sd_read(uint8_t pdrv, uint8_t* buffer, DWORD sector, UINT count) -{ - ardu_sdcard_t * card = s_cards[pdrv]; - if (card->status & STA_NOINIT) { - return RES_NOTRDY; - } - DRESULT res = RES_OK; - - AcquireSPI lock(card); +DSTATUS ff_sd_status(uint8_t pdrv) { + ardu_sdcard_t* card = s_cards[pdrv]; + AcquireSPI lock(card); - if (count > 1) { - res = sdReadSectors(pdrv, (char*)buffer, sector, count) ? RES_OK : RES_ERROR; - } else { - res = sdReadSector(pdrv, (char*)buffer, sector) ? RES_OK : RES_ERROR; - } - return res; + if (sdTransaction(pdrv, SEND_STATUS, 0, NULL)) { + log_e("Check status failed"); + return STA_NOINIT; + } + return s_cards[pdrv]->status; } -DRESULT ff_sd_write(uint8_t pdrv, const uint8_t* buffer, DWORD sector, UINT count) -{ - ardu_sdcard_t * card = s_cards[pdrv]; - if (card->status & STA_NOINIT) { - return RES_NOTRDY; - } - - if (card->status & STA_PROTECT) { - return RES_WRPRT; - } - DRESULT res = RES_OK; - - AcquireSPI lock(card); +DRESULT ff_sd_read(uint8_t pdrv, uint8_t* buffer, DWORD sector, UINT count) { + ardu_sdcard_t* card = s_cards[pdrv]; + if (card->status & STA_NOINIT) { + return RES_NOTRDY; + } + DRESULT res = RES_OK; + + AcquireSPI lock(card); + + if (count > 1) { + res = sdReadSectors(pdrv, (char*)buffer, sector, count) ? RES_OK : RES_ERROR; + } else { + res = sdReadSector(pdrv, (char*)buffer, sector) ? RES_OK : RES_ERROR; + } + return res; +} - if (count > 1) { - res = sdWriteSectors(pdrv, (const char*)buffer, sector, count) ? RES_OK : RES_ERROR; - } else { - res = sdWriteSector(pdrv, (const char*)buffer, sector) ? RES_OK : RES_ERROR; - } - return res; +DRESULT ff_sd_write(uint8_t pdrv, const uint8_t* buffer, DWORD sector, UINT count) { + ardu_sdcard_t* card = s_cards[pdrv]; + if (card->status & STA_NOINIT) { + return RES_NOTRDY; + } + + if (card->status & STA_PROTECT) { + return RES_WRPRT; + } + DRESULT res = RES_OK; + + AcquireSPI lock(card); + + if (count > 1) { + res = sdWriteSectors(pdrv, (const char*)buffer, sector, count) ? RES_OK : RES_ERROR; + } else { + res = sdWriteSector(pdrv, (const char*)buffer, sector) ? RES_OK : RES_ERROR; + } + return res; } -DRESULT ff_sd_ioctl(uint8_t pdrv, uint8_t cmd, void* buff) -{ - switch(cmd) { +DRESULT ff_sd_ioctl(uint8_t pdrv, uint8_t cmd, void* buff) { + switch (cmd) { case CTRL_SYNC: - { - AcquireSPI lock(s_cards[pdrv]); - if (sdSelectCard(pdrv)) { - sdDeselectCard(pdrv); - return RES_OK; - } + { + AcquireSPI lock(s_cards[pdrv]); + if (sdSelectCard(pdrv)) { + sdDeselectCard(pdrv); + return RES_OK; } - return RES_ERROR; + } + return RES_ERROR; case GET_SECTOR_COUNT: - *((unsigned long*) buff) = s_cards[pdrv]->sectors; - return RES_OK; + *((unsigned long*)buff) = s_cards[pdrv]->sectors; + return RES_OK; case GET_SECTOR_SIZE: - *((WORD*) buff) = 512; - return RES_OK; + *((WORD*)buff) = 512; + return RES_OK; case GET_BLOCK_SIZE: - *((uint32_t*)buff) = 1; - return RES_OK; - } - return RES_PARERR; + *((uint32_t*)buff) = 1; + return RES_OK; + } + return RES_PARERR; } -bool sd_read_raw(uint8_t pdrv, uint8_t* buffer, DWORD sector) -{ - return ff_sd_read(pdrv, buffer, sector, 1) == ESP_OK; +bool sd_read_raw(uint8_t pdrv, uint8_t* buffer, DWORD sector) { + return ff_sd_read(pdrv, buffer, sector, 1) == ESP_OK; } -bool sd_write_raw(uint8_t pdrv, uint8_t* buffer, DWORD sector) -{ - return ff_sd_write(pdrv, buffer, sector, 1) == ESP_OK; +bool sd_write_raw(uint8_t pdrv, uint8_t* buffer, DWORD sector) { + return ff_sd_write(pdrv, buffer, sector, 1) == ESP_OK; } /* * Public methods * */ -uint8_t sdcard_uninit(uint8_t pdrv) -{ - ardu_sdcard_t * card = s_cards[pdrv]; - if (pdrv >= FF_VOLUMES || card == NULL) { - return 1; - } - AcquireSPI lock(card); - sdTransaction(pdrv, GO_IDLE_STATE, 0, NULL); - ff_diskio_register(pdrv, NULL); - s_cards[pdrv] = NULL; - esp_err_t err = ESP_OK; - if (card->base_path) { - err = esp_vfs_fat_unregister_path(card->base_path); - free(card->base_path); - } - free(card); - return err; +uint8_t sdcard_uninit(uint8_t pdrv) { + ardu_sdcard_t* card = s_cards[pdrv]; + if (pdrv >= FF_VOLUMES || card == NULL) { + return 1; + } + AcquireSPI lock(card); + sdTransaction(pdrv, GO_IDLE_STATE, 0, NULL); + ff_diskio_register(pdrv, NULL); + s_cards[pdrv] = NULL; + esp_err_t err = ESP_OK; + if (card->base_path) { + err = esp_vfs_fat_unregister_path(card->base_path); + free(card->base_path); + } + free(card); + return err; } -uint8_t sdcard_init(uint8_t cs, SPIClass * spi, int hz) -{ - - uint8_t pdrv = 0xFF; - if (ff_diskio_get_drive(&pdrv) != ESP_OK || pdrv == 0xFF) { - return pdrv; - } - - ardu_sdcard_t * card = (ardu_sdcard_t *)malloc(sizeof(ardu_sdcard_t)); - if (!card) { - return 0xFF; - } - - card->base_path = NULL; - card->frequency = hz; - card->spi = spi; - card->ssPin = digitalPinToGPIONumber(cs); - - card->supports_crc = true; - card->type = CARD_NONE; - card->status = STA_NOINIT; - - pinMode(card->ssPin, OUTPUT); - digitalWrite(card->ssPin, HIGH); - perimanSetPinBusExtraType(card->ssPin, "SD_SS"); - - s_cards[pdrv] = card; - - static const ff_diskio_impl_t sd_impl = { - .init = &ff_sd_initialize, - .status = &ff_sd_status, - .read = &ff_sd_read, - .write = &ff_sd_write, - .ioctl = &ff_sd_ioctl - }; - ff_diskio_register(pdrv, &sd_impl); +uint8_t sdcard_init(uint8_t cs, SPIClass* spi, int hz) { + uint8_t pdrv = 0xFF; + if (ff_diskio_get_drive(&pdrv) != ESP_OK || pdrv == 0xFF) { return pdrv; + } + + ardu_sdcard_t* card = (ardu_sdcard_t*)malloc(sizeof(ardu_sdcard_t)); + if (!card) { + return 0xFF; + } + + card->base_path = NULL; + card->frequency = hz; + card->spi = spi; + card->ssPin = digitalPinToGPIONumber(cs); + + card->supports_crc = true; + card->type = CARD_NONE; + card->status = STA_NOINIT; + + pinMode(card->ssPin, OUTPUT); + digitalWrite(card->ssPin, HIGH); + perimanSetPinBusExtraType(card->ssPin, "SD_SS"); + + s_cards[pdrv] = card; + + static const ff_diskio_impl_t sd_impl = { + .init = &ff_sd_initialize, + .status = &ff_sd_status, + .read = &ff_sd_read, + .write = &ff_sd_write, + .ioctl = &ff_sd_ioctl + }; + ff_diskio_register(pdrv, &sd_impl); + + return pdrv; } -uint8_t sdcard_unmount(uint8_t pdrv) -{ - ardu_sdcard_t * card = s_cards[pdrv]; - if (pdrv >= FF_VOLUMES || card == NULL) { - return 1; - } - card->status |= STA_NOINIT; - card->type = CARD_NONE; - - char drv[3] = {(char)('0' + pdrv), ':', 0}; - f_mount(NULL, drv, 0); - return 0; +uint8_t sdcard_unmount(uint8_t pdrv) { + ardu_sdcard_t* card = s_cards[pdrv]; + if (pdrv >= FF_VOLUMES || card == NULL) { + return 1; + } + card->status |= STA_NOINIT; + card->type = CARD_NONE; + + char drv[3] = { (char)('0' + pdrv), ':', 0 }; + f_mount(NULL, drv, 0); + return 0; } -bool sdcard_mount(uint8_t pdrv, const char* path, uint8_t max_files, bool format_if_empty) -{ - ardu_sdcard_t * card = s_cards[pdrv]; - if(pdrv >= FF_VOLUMES || card == NULL){ - return false; - } - - if(card->base_path){ - free(card->base_path); - } - card->base_path = strdup(path); - - FATFS* fs; - char drv[3] = {(char)('0' + pdrv), ':', 0}; - esp_err_t err = esp_vfs_fat_register(path, drv, max_files, &fs); - if (err == ESP_ERR_INVALID_STATE) { - log_e("esp_vfs_fat_register failed 0x(%x): SD is registered.", err); +bool sdcard_mount(uint8_t pdrv, const char* path, uint8_t max_files, bool format_if_empty) { + ardu_sdcard_t* card = s_cards[pdrv]; + if (pdrv >= FF_VOLUMES || card == NULL) { + return false; + } + + if (card->base_path) { + free(card->base_path); + } + card->base_path = strdup(path); + + FATFS* fs; + char drv[3] = { (char)('0' + pdrv), ':', 0 }; + esp_err_t err = esp_vfs_fat_register(path, drv, max_files, &fs); + if (err == ESP_ERR_INVALID_STATE) { + log_e("esp_vfs_fat_register failed 0x(%x): SD is registered.", err); + return false; + } else if (err != ESP_OK) { + log_e("esp_vfs_fat_register failed 0x(%x)", err); + return false; + } + + FRESULT res = f_mount(fs, drv, 1); + if (res != FR_OK) { + log_e("f_mount failed: %s", fferr2str[res]); + if (res == 13 && format_if_empty) { + BYTE* work = (BYTE*)malloc(sizeof(BYTE) * FF_MAX_SS); + if (!work) { + log_e("alloc for f_mkfs failed"); return false; - } else if (err != ESP_OK) { - log_e("esp_vfs_fat_register failed 0x(%x)", err); + } + //FRESULT f_mkfs (const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len); + const MKFS_PARM opt = { (BYTE)FM_ANY, 0, 0, 0, 0 }; + res = f_mkfs(drv, &opt, work, sizeof(BYTE) * FF_MAX_SS); + free(work); + if (res != FR_OK) { + log_e("f_mkfs failed: %s", fferr2str[res]); + esp_vfs_fat_unregister_path(path); return false; - } - - FRESULT res = f_mount(fs, drv, 1); - if (res != FR_OK) { + } + res = f_mount(fs, drv, 1); + if (res != FR_OK) { log_e("f_mount failed: %s", fferr2str[res]); - if(res == 13 && format_if_empty){ - BYTE* work = (BYTE*) malloc(sizeof(BYTE) * FF_MAX_SS); - if (!work) { - log_e("alloc for f_mkfs failed"); - return false; - } - //FRESULT f_mkfs (const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len); - const MKFS_PARM opt = {(BYTE)FM_ANY, 0, 0, 0, 0}; - res = f_mkfs(drv, &opt, work, sizeof(BYTE) * FF_MAX_SS); - free(work); - if (res != FR_OK) { - log_e("f_mkfs failed: %s", fferr2str[res]); - esp_vfs_fat_unregister_path(path); - return false; - } - res = f_mount(fs, drv, 1); - if (res != FR_OK) { - log_e("f_mount failed: %s", fferr2str[res]); - esp_vfs_fat_unregister_path(path); - return false; - } - } else { - esp_vfs_fat_unregister_path(path); - return false; - } + esp_vfs_fat_unregister_path(path); + return false; + } + } else { + esp_vfs_fat_unregister_path(path); + return false; } - AcquireSPI lock(card); - card->sectors = sdGetSectorsCount(pdrv); - return true; + } + AcquireSPI lock(card); + card->sectors = sdGetSectorsCount(pdrv); + return true; } -uint32_t sdcard_num_sectors(uint8_t pdrv) -{ - ardu_sdcard_t * card = s_cards[pdrv]; - if(pdrv >= FF_VOLUMES || card == NULL){ - return 0; - } - return card->sectors; +uint32_t sdcard_num_sectors(uint8_t pdrv) { + ardu_sdcard_t* card = s_cards[pdrv]; + if (pdrv >= FF_VOLUMES || card == NULL) { + return 0; + } + return card->sectors; } -uint32_t sdcard_sector_size(uint8_t pdrv) -{ - if(pdrv >= FF_VOLUMES || s_cards[pdrv] == NULL){ - return 0; - } - return 512; +uint32_t sdcard_sector_size(uint8_t pdrv) { + if (pdrv >= FF_VOLUMES || s_cards[pdrv] == NULL) { + return 0; + } + return 512; } -sdcard_type_t sdcard_type(uint8_t pdrv) -{ - ardu_sdcard_t * card = s_cards[pdrv]; - if(pdrv >= FF_VOLUMES || card == NULL){ - return CARD_NONE; - } - return card->type; +sdcard_type_t sdcard_type(uint8_t pdrv) { + ardu_sdcard_t* card = s_cards[pdrv]; + if (pdrv >= FF_VOLUMES || card == NULL) { + return CARD_NONE; + } + return card->type; } diff --git a/libraries/SD/src/sd_diskio.h b/libraries/SD/src/sd_diskio.h index 06a861b8d13..45b1d7f16f9 100644 --- a/libraries/SD/src/sd_diskio.h +++ b/libraries/SD/src/sd_diskio.h @@ -19,7 +19,7 @@ #include "sd_defines.h" // #include "diskio.h" -uint8_t sdcard_init(uint8_t cs, SPIClass * spi, int hz); +uint8_t sdcard_init(uint8_t cs, SPIClass* spi, int hz); uint8_t sdcard_uninit(uint8_t pdrv); bool sdcard_mount(uint8_t pdrv, const char* path, uint8_t max_files, bool format_if_empty); diff --git a/libraries/SD/src/sd_diskio_crc.c b/libraries/SD/src/sd_diskio_crc.c index 0372df82d09..7060ae93a01 100644 --- a/libraries/SD/src/sd_diskio_crc.c +++ b/libraries/SD/src/sd_diskio_crc.c @@ -15,89 +15,87 @@ */ const char m_CRC7Table[] = { - 0x00, 0x09, 0x12, 0x1B, 0x24, 0x2D, 0x36, 0x3F, - 0x48, 0x41, 0x5A, 0x53, 0x6C, 0x65, 0x7E, 0x77, - 0x19, 0x10, 0x0B, 0x02, 0x3D, 0x34, 0x2F, 0x26, - 0x51, 0x58, 0x43, 0x4A, 0x75, 0x7C, 0x67, 0x6E, - 0x32, 0x3B, 0x20, 0x29, 0x16, 0x1F, 0x04, 0x0D, - 0x7A, 0x73, 0x68, 0x61, 0x5E, 0x57, 0x4C, 0x45, - 0x2B, 0x22, 0x39, 0x30, 0x0F, 0x06, 0x1D, 0x14, - 0x63, 0x6A, 0x71, 0x78, 0x47, 0x4E, 0x55, 0x5C, - 0x64, 0x6D, 0x76, 0x7F, 0x40, 0x49, 0x52, 0x5B, - 0x2C, 0x25, 0x3E, 0x37, 0x08, 0x01, 0x1A, 0x13, - 0x7D, 0x74, 0x6F, 0x66, 0x59, 0x50, 0x4B, 0x42, - 0x35, 0x3C, 0x27, 0x2E, 0x11, 0x18, 0x03, 0x0A, - 0x56, 0x5F, 0x44, 0x4D, 0x72, 0x7B, 0x60, 0x69, - 0x1E, 0x17, 0x0C, 0x05, 0x3A, 0x33, 0x28, 0x21, - 0x4F, 0x46, 0x5D, 0x54, 0x6B, 0x62, 0x79, 0x70, - 0x07, 0x0E, 0x15, 0x1C, 0x23, 0x2A, 0x31, 0x38, - 0x41, 0x48, 0x53, 0x5A, 0x65, 0x6C, 0x77, 0x7E, - 0x09, 0x00, 0x1B, 0x12, 0x2D, 0x24, 0x3F, 0x36, - 0x58, 0x51, 0x4A, 0x43, 0x7C, 0x75, 0x6E, 0x67, - 0x10, 0x19, 0x02, 0x0B, 0x34, 0x3D, 0x26, 0x2F, - 0x73, 0x7A, 0x61, 0x68, 0x57, 0x5E, 0x45, 0x4C, - 0x3B, 0x32, 0x29, 0x20, 0x1F, 0x16, 0x0D, 0x04, - 0x6A, 0x63, 0x78, 0x71, 0x4E, 0x47, 0x5C, 0x55, - 0x22, 0x2B, 0x30, 0x39, 0x06, 0x0F, 0x14, 0x1D, - 0x25, 0x2C, 0x37, 0x3E, 0x01, 0x08, 0x13, 0x1A, - 0x6D, 0x64, 0x7F, 0x76, 0x49, 0x40, 0x5B, 0x52, - 0x3C, 0x35, 0x2E, 0x27, 0x18, 0x11, 0x0A, 0x03, - 0x74, 0x7D, 0x66, 0x6F, 0x50, 0x59, 0x42, 0x4B, - 0x17, 0x1E, 0x05, 0x0C, 0x33, 0x3A, 0x21, 0x28, - 0x5F, 0x56, 0x4D, 0x44, 0x7B, 0x72, 0x69, 0x60, - 0x0E, 0x07, 0x1C, 0x15, 0x2A, 0x23, 0x38, 0x31, - 0x46, 0x4F, 0x54, 0x5D, 0x62, 0x6B, 0x70, 0x79 + 0x00, 0x09, 0x12, 0x1B, 0x24, 0x2D, 0x36, 0x3F, + 0x48, 0x41, 0x5A, 0x53, 0x6C, 0x65, 0x7E, 0x77, + 0x19, 0x10, 0x0B, 0x02, 0x3D, 0x34, 0x2F, 0x26, + 0x51, 0x58, 0x43, 0x4A, 0x75, 0x7C, 0x67, 0x6E, + 0x32, 0x3B, 0x20, 0x29, 0x16, 0x1F, 0x04, 0x0D, + 0x7A, 0x73, 0x68, 0x61, 0x5E, 0x57, 0x4C, 0x45, + 0x2B, 0x22, 0x39, 0x30, 0x0F, 0x06, 0x1D, 0x14, + 0x63, 0x6A, 0x71, 0x78, 0x47, 0x4E, 0x55, 0x5C, + 0x64, 0x6D, 0x76, 0x7F, 0x40, 0x49, 0x52, 0x5B, + 0x2C, 0x25, 0x3E, 0x37, 0x08, 0x01, 0x1A, 0x13, + 0x7D, 0x74, 0x6F, 0x66, 0x59, 0x50, 0x4B, 0x42, + 0x35, 0x3C, 0x27, 0x2E, 0x11, 0x18, 0x03, 0x0A, + 0x56, 0x5F, 0x44, 0x4D, 0x72, 0x7B, 0x60, 0x69, + 0x1E, 0x17, 0x0C, 0x05, 0x3A, 0x33, 0x28, 0x21, + 0x4F, 0x46, 0x5D, 0x54, 0x6B, 0x62, 0x79, 0x70, + 0x07, 0x0E, 0x15, 0x1C, 0x23, 0x2A, 0x31, 0x38, + 0x41, 0x48, 0x53, 0x5A, 0x65, 0x6C, 0x77, 0x7E, + 0x09, 0x00, 0x1B, 0x12, 0x2D, 0x24, 0x3F, 0x36, + 0x58, 0x51, 0x4A, 0x43, 0x7C, 0x75, 0x6E, 0x67, + 0x10, 0x19, 0x02, 0x0B, 0x34, 0x3D, 0x26, 0x2F, + 0x73, 0x7A, 0x61, 0x68, 0x57, 0x5E, 0x45, 0x4C, + 0x3B, 0x32, 0x29, 0x20, 0x1F, 0x16, 0x0D, 0x04, + 0x6A, 0x63, 0x78, 0x71, 0x4E, 0x47, 0x5C, 0x55, + 0x22, 0x2B, 0x30, 0x39, 0x06, 0x0F, 0x14, 0x1D, + 0x25, 0x2C, 0x37, 0x3E, 0x01, 0x08, 0x13, 0x1A, + 0x6D, 0x64, 0x7F, 0x76, 0x49, 0x40, 0x5B, 0x52, + 0x3C, 0x35, 0x2E, 0x27, 0x18, 0x11, 0x0A, 0x03, + 0x74, 0x7D, 0x66, 0x6F, 0x50, 0x59, 0x42, 0x4B, + 0x17, 0x1E, 0x05, 0x0C, 0x33, 0x3A, 0x21, 0x28, + 0x5F, 0x56, 0x4D, 0x44, 0x7B, 0x72, 0x69, 0x60, + 0x0E, 0x07, 0x1C, 0x15, 0x2A, 0x23, 0x38, 0x31, + 0x46, 0x4F, 0x54, 0x5D, 0x62, 0x6B, 0x70, 0x79 }; -char CRC7(const char* data, int length) -{ - char crc = 0; - for (int i = 0; i < length; i++) { - crc = m_CRC7Table[(crc << 1) ^ data[i]]; - } - return crc; +char CRC7(const char* data, int length) { + char crc = 0; + for (int i = 0; i < length; i++) { + crc = m_CRC7Table[(crc << 1) ^ data[i]]; + } + return crc; } const unsigned short m_CRC16Table[256] = { - 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, - 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, - 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, - 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, - 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, - 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, - 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, - 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, - 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, - 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, - 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, - 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, - 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, - 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, - 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, - 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, - 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, - 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, - 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, - 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, - 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, - 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, - 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, - 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, - 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, - 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, - 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, - 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, - 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, - 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, - 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, - 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, + 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, + 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, + 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, + 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, + 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, + 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, + 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, + 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, + 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, + 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, + 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, + 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, + 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, + 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, + 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, + 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, + 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, + 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, + 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, + 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, + 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, + 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 }; -unsigned short CRC16(const char* data, int length) -{ - unsigned short crc = 0; - for (int i = 0; i < length; i++) { - crc = (crc << 8) ^ m_CRC16Table[((crc >> 8) ^ data[i]) & 0x00FF]; - } - return crc; +unsigned short CRC16(const char* data, int length) { + unsigned short crc = 0; + for (int i = 0; i < length; i++) { + crc = (crc << 8) ^ m_CRC16Table[((crc >> 8) ^ data[i]) & 0x00FF]; + } + return crc; } diff --git a/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino b/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino index 70545f88d10..4a199cca15d 100644 --- a/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino +++ b/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino @@ -50,169 +50,169 @@ // Note: if it's ok to use default pins, you do not need to call the setPins int clk = 36; int cmd = 35; -int d0 = 37; -int d1 = 38; -int d2 = 33; -int d3 = 39; // GPIO 34 is not broken-out on ESP32-S3-DevKitC-1 v1.1 +int d0 = 37; +int d1 = 38; +int d2 = 33; +int d3 = 39; // GPIO 34 is not broken-out on ESP32-S3-DevKitC-1 v1.1 -void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ - Serial.printf("Listing directory: %s\n", dirname); +void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { + Serial.printf("Listing directory: %s\n", dirname); - File root = fs.open(dirname); - if(!root){ - Serial.println("Failed to open directory"); - return; - } - if(!root.isDirectory()){ - Serial.println("Not a directory"); - return; - } + File root = fs.open(dirname); + if (!root) { + Serial.println("Failed to open directory"); + return; + } + if (!root.isDirectory()) { + Serial.println("Not a directory"); + return; + } - File file = root.openNextFile(); - while(file){ - if(file.isDirectory()){ - Serial.print(" DIR : "); - Serial.println(file.name()); - if(levels){ - listDir(fs, file.path(), levels -1); - } - } else { - Serial.print(" FILE: "); - Serial.print(file.name()); - Serial.print(" SIZE: "); - Serial.println(file.size()); - } - file = root.openNextFile(); + File file = root.openNextFile(); + while (file) { + if (file.isDirectory()) { + Serial.print(" DIR : "); + Serial.println(file.name()); + if (levels) { + listDir(fs, file.path(), levels - 1); + } + } else { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print(" SIZE: "); + Serial.println(file.size()); } + file = root.openNextFile(); + } } -void createDir(fs::FS &fs, const char * path){ - Serial.printf("Creating Dir: %s\n", path); - if(fs.mkdir(path)){ - Serial.println("Dir created"); - } else { - Serial.println("mkdir failed"); - } +void createDir(fs::FS &fs, const char *path) { + Serial.printf("Creating Dir: %s\n", path); + if (fs.mkdir(path)) { + Serial.println("Dir created"); + } else { + Serial.println("mkdir failed"); + } } -void removeDir(fs::FS &fs, const char * path){ - Serial.printf("Removing Dir: %s\n", path); - if(fs.rmdir(path)){ - Serial.println("Dir removed"); - } else { - Serial.println("rmdir failed"); - } +void removeDir(fs::FS &fs, const char *path) { + Serial.printf("Removing Dir: %s\n", path); + if (fs.rmdir(path)) { + Serial.println("Dir removed"); + } else { + Serial.println("rmdir failed"); + } } -void readFile(fs::FS &fs, const char * path){ - Serial.printf("Reading file: %s\n", path); +void readFile(fs::FS &fs, const char *path) { + Serial.printf("Reading file: %s\n", path); - File file = fs.open(path); - if(!file){ - Serial.println("Failed to open file for reading"); - return; - } + File file = fs.open(path); + if (!file) { + Serial.println("Failed to open file for reading"); + return; + } - Serial.print("Read from file: "); - while(file.available()){ - Serial.write(file.read()); - } + Serial.print("Read from file: "); + while (file.available()) { + Serial.write(file.read()); + } } -void writeFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Writing file: %s\n", path); +void writeFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Writing file: %s\n", path); - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("Failed to open file for writing"); - return; - } - if(file.print(message)){ - Serial.println("File written"); - } else { - Serial.println("Write failed"); - } + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("Failed to open file for writing"); + return; + } + if (file.print(message)) { + Serial.println("File written"); + } else { + Serial.println("Write failed"); + } } -void appendFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Appending to file: %s\n", path); +void appendFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Appending to file: %s\n", path); - File file = fs.open(path, FILE_APPEND); - if(!file){ - Serial.println("Failed to open file for appending"); - return; - } - if(file.print(message)){ - Serial.println("Message appended"); - } else { - Serial.println("Append failed"); - } + File file = fs.open(path, FILE_APPEND); + if (!file) { + Serial.println("Failed to open file for appending"); + return; + } + if (file.print(message)) { + Serial.println("Message appended"); + } else { + Serial.println("Append failed"); + } } -void renameFile(fs::FS &fs, const char * path1, const char * path2){ - Serial.printf("Renaming file %s to %s\n", path1, path2); - if (fs.rename(path1, path2)) { - Serial.println("File renamed"); - } else { - Serial.println("Rename failed"); - } +void renameFile(fs::FS &fs, const char *path1, const char *path2) { + Serial.printf("Renaming file %s to %s\n", path1, path2); + if (fs.rename(path1, path2)) { + Serial.println("File renamed"); + } else { + Serial.println("Rename failed"); + } } -void deleteFile(fs::FS &fs, const char * path){ - Serial.printf("Deleting file: %s\n", path); - if(fs.remove(path)){ - Serial.println("File deleted"); - } else { - Serial.println("Delete failed"); - } +void deleteFile(fs::FS &fs, const char *path) { + Serial.printf("Deleting file: %s\n", path); + if (fs.remove(path)) { + Serial.println("File deleted"); + } else { + Serial.println("Delete failed"); + } } -void testFileIO(fs::FS &fs, const char * path){ - File file = fs.open(path); - static uint8_t buf[512]; - size_t len = 0; - uint32_t start = millis(); - uint32_t end = start; - if(file){ - len = file.size(); - size_t flen = len; - start = millis(); - while(len){ - size_t toRead = len; - if(toRead > 512){ - toRead = 512; - } - file.read(buf, toRead); - len -= toRead; - } - end = millis() - start; - Serial.printf("%u bytes read for %lu ms\n", flen, end); - file.close(); - } else { - Serial.println("Failed to open file for reading"); - } - - - file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("Failed to open file for writing"); - return; - } - - size_t i; +void testFileIO(fs::FS &fs, const char *path) { + File file = fs.open(path); + static uint8_t buf[512]; + size_t len = 0; + uint32_t start = millis(); + uint32_t end = start; + if (file) { + len = file.size(); + size_t flen = len; start = millis(); - for(i=0; i<2048; i++){ - file.write(buf, 512); + while (len) { + size_t toRead = len; + if (toRead > 512) { + toRead = 512; + } + file.read(buf, toRead); + len -= toRead; } end = millis() - start; - Serial.printf("%u bytes written for %lu ms\n", 2048 * 512, end); + Serial.printf("%u bytes read for %lu ms\n", flen, end); file.close(); + } else { + Serial.println("Failed to open file for reading"); + } + + + file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("Failed to open file for writing"); + return; + } + + size_t i; + start = millis(); + for (i = 0; i < 2048; i++) { + file.write(buf, 512); + } + end = millis() - start; + Serial.printf("%u bytes written for %lu ms\n", 2048 * 512, end); + file.close(); } -void setup(){ - Serial.begin(115200); - /* - // If you want to change the pin assigment on ESP32-S3 uncomment this block and the appropriate +void setup() { + Serial.begin(115200); + /* + // If you want to change the pin assignment on ESP32-S3 uncomment this block and the appropriate // line depending if you want to use 1-bit or 4-bit line. // Please note that ESP32 does not allow pin change and will always fail. //if(! setPins(clk, cmd, d0)){ @@ -222,47 +222,46 @@ void setup(){ } */ - if(!SD_MMC.begin()){ - Serial.println("Card Mount Failed"); - return; - } - uint8_t cardType = SD_MMC.cardType(); + if (!SD_MMC.begin()) { + Serial.println("Card Mount Failed"); + return; + } + uint8_t cardType = SD_MMC.cardType(); - if(cardType == CARD_NONE){ - Serial.println("No SD_MMC card attached"); - return; - } + if (cardType == CARD_NONE) { + Serial.println("No SD_MMC card attached"); + return; + } - Serial.print("SD_MMC Card Type: "); - if(cardType == CARD_MMC){ - Serial.println("MMC"); - } else if(cardType == CARD_SD){ - Serial.println("SDSC"); - } else if(cardType == CARD_SDHC){ - Serial.println("SDHC"); - } else { - Serial.println("UNKNOWN"); - } + Serial.print("SD_MMC Card Type: "); + if (cardType == CARD_MMC) { + Serial.println("MMC"); + } else if (cardType == CARD_SD) { + Serial.println("SDSC"); + } else if (cardType == CARD_SDHC) { + Serial.println("SDHC"); + } else { + Serial.println("UNKNOWN"); + } - uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024); - Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize); + uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024); + Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize); - listDir(SD_MMC, "/", 0); - createDir(SD_MMC, "/mydir"); - listDir(SD_MMC, "/", 0); - removeDir(SD_MMC, "/mydir"); - listDir(SD_MMC, "/", 2); - writeFile(SD_MMC, "/hello.txt", "Hello "); - appendFile(SD_MMC, "/hello.txt", "World!\n"); - readFile(SD_MMC, "/hello.txt"); - deleteFile(SD_MMC, "/foo.txt"); - renameFile(SD_MMC, "/hello.txt", "/foo.txt"); - readFile(SD_MMC, "/foo.txt"); - testFileIO(SD_MMC, "/test.txt"); - Serial.printf("Total space: %lluMB\n", SD_MMC.totalBytes() / (1024 * 1024)); - Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024)); + listDir(SD_MMC, "/", 0); + createDir(SD_MMC, "/mydir"); + listDir(SD_MMC, "/", 0); + removeDir(SD_MMC, "/mydir"); + listDir(SD_MMC, "/", 2); + writeFile(SD_MMC, "/hello.txt", "Hello "); + appendFile(SD_MMC, "/hello.txt", "World!\n"); + readFile(SD_MMC, "/hello.txt"); + deleteFile(SD_MMC, "/foo.txt"); + renameFile(SD_MMC, "/hello.txt", "/foo.txt"); + readFile(SD_MMC, "/foo.txt"); + testFileIO(SD_MMC, "/test.txt"); + Serial.printf("Total space: %lluMB\n", SD_MMC.totalBytes() / (1024 * 1024)); + Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024)); } -void loop(){ - +void loop() { } diff --git a/libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino b/libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino index cf21e6db669..dd1a1742970 100644 --- a/libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino +++ b/libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino @@ -31,13 +31,13 @@ #include "FS.h" #include "SD_MMC.h" #include "SPI.h" -#include +#include #include -const char* ssid = "your-ssid"; -const char* password = "your-password"; +const char *ssid = "your-ssid"; +const char *password = "your-password"; -long timezone = 1; +long timezone = 1; byte daysavetime = 1; // Default pins for ESP-S3 @@ -50,225 +50,222 @@ byte daysavetime = 1; // from left to right when facing the pins down (when connected to a breadboard) #if defined(SOC_SDMMC_USE_GPIO_MATRIX) && not defined(BOARD_HAS_SDMMC) - int d1 = 21; // SD pin 8 - Add a 10k Ohm pull-up resistor to 3.3V if using 4-bit mode (use_1_bit_mode = false) - int d0 = 47; // SD pin 7 - Add a 10k Ohm pull-up resistor to 3.3V - // GND pin - SD pin 6 - int clk = 39; // SD pin 5 - Add a 10k Ohm pull-up resistor to 3.3V - // 3.3V pin - SD pin 4 - // GND pin - SD pin 3 - int cmd = 40; // SD pin 2 - Add a 10k Ohm pull-up resistor to 3.3V - int d3 = 41; // SD pin 1 - Add a 10k Ohm pull-up resistor to 3.3V to card's pin even when using 1-bit mode - int d2 = 42; // SD pin 9 - Add a 10k Ohm pull-up resistor to 3.3V if using 4-bit mode (use_1_bit_mode = false) +int d1 = 21; // SD pin 8 - Add a 10k Ohm pull-up resistor to 3.3V if using 4-bit mode (use_1_bit_mode = false) +int d0 = 47; // SD pin 7 - Add a 10k Ohm pull-up resistor to 3.3V +// GND pin - SD pin 6 +int clk = 39; // SD pin 5 - Add a 10k Ohm pull-up resistor to 3.3V +// 3.3V pin - SD pin 4 +// GND pin - SD pin 3 +int cmd = 40; // SD pin 2 - Add a 10k Ohm pull-up resistor to 3.3V +int d3 = 41; // SD pin 1 - Add a 10k Ohm pull-up resistor to 3.3V to card's pin even when using 1-bit mode +int d2 = 42; // SD pin 9 - Add a 10k Ohm pull-up resistor to 3.3V if using 4-bit mode (use_1_bit_mode = false) #endif -bool use_1_bit_mode = false; // Change the value to `true` to use 1-bit mode instead of the 4-bit mode - -void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ - Serial.printf("Listing directory: %s\n", dirname); - - File root = fs.open(dirname); - if(!root){ - Serial.println("Failed to open directory"); - return; - } - if(!root.isDirectory()){ - Serial.println("Not a directory"); - return; - } - - File file = root.openNextFile(); - while(file){ - if(file.isDirectory()){ - Serial.print(" DIR : "); - Serial.print (file.name()); - time_t t= file.getLastWrite(); - struct tm * tmstruct = localtime(&t); - Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec); - if(levels){ - listDir(fs, file.path(), levels -1); - } - } else { - Serial.print(" FILE: "); - Serial.print(file.name()); - Serial.print(" SIZE: "); - Serial.print(file.size()); - time_t t= file.getLastWrite(); - struct tm * tmstruct = localtime(&t); - Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec); - } - file = root.openNextFile(); +bool use_1_bit_mode = false; // Change the value to `true` to use 1-bit mode instead of the 4-bit mode + +void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { + Serial.printf("Listing directory: %s\n", dirname); + + File root = fs.open(dirname); + if (!root) { + Serial.println("Failed to open directory"); + return; + } + if (!root.isDirectory()) { + Serial.println("Not a directory"); + return; + } + + File file = root.openNextFile(); + while (file) { + if (file.isDirectory()) { + Serial.print(" DIR : "); + Serial.print(file.name()); + time_t t = file.getLastWrite(); + struct tm *tmstruct = localtime(&t); + Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); + if (levels) { + listDir(fs, file.path(), levels - 1); + } + } else { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print(" SIZE: "); + Serial.print(file.size()); + time_t t = file.getLastWrite(); + struct tm *tmstruct = localtime(&t); + Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); } + file = root.openNextFile(); + } } -void createDir(fs::FS &fs, const char * path){ - Serial.printf("Creating Dir: %s\n", path); - if(fs.mkdir(path)){ - Serial.println("Dir created"); - } else { - Serial.println("mkdir failed"); - } +void createDir(fs::FS &fs, const char *path) { + Serial.printf("Creating Dir: %s\n", path); + if (fs.mkdir(path)) { + Serial.println("Dir created"); + } else { + Serial.println("mkdir failed"); + } } -void removeDir(fs::FS &fs, const char * path){ - Serial.printf("Removing Dir: %s\n", path); - if(fs.rmdir(path)){ - Serial.println("Dir removed"); - } else { - Serial.println("rmdir failed"); - } +void removeDir(fs::FS &fs, const char *path) { + Serial.printf("Removing Dir: %s\n", path); + if (fs.rmdir(path)) { + Serial.println("Dir removed"); + } else { + Serial.println("rmdir failed"); + } } -void readFile(fs::FS &fs, const char * path){ - Serial.printf("Reading file: %s\n", path); +void readFile(fs::FS &fs, const char *path) { + Serial.printf("Reading file: %s\n", path); - File file = fs.open(path); - if(!file){ - Serial.println("Failed to open file for reading"); - return; - } + File file = fs.open(path); + if (!file) { + Serial.println("Failed to open file for reading"); + return; + } - Serial.print("Read from file: "); - while(file.available()){ - Serial.write(file.read()); - } - file.close(); + Serial.print("Read from file: "); + while (file.available()) { + Serial.write(file.read()); + } + file.close(); } -void writeFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Writing file: %s\n", path); - - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("Failed to open file for writing"); - return; - } - if(file.print(message)){ - Serial.println("File written"); - } else { - Serial.println("Write failed"); - } - file.close(); +void writeFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Writing file: %s\n", path); + + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("Failed to open file for writing"); + return; + } + if (file.print(message)) { + Serial.println("File written"); + } else { + Serial.println("Write failed"); + } + file.close(); } -void appendFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Appending to file: %s\n", path); - - File file = fs.open(path, FILE_APPEND); - if(!file){ - Serial.println("Failed to open file for appending"); - return; - } - if(file.print(message)){ - Serial.println("Message appended"); - } else { - Serial.println("Append failed"); - } - file.close(); +void appendFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Appending to file: %s\n", path); + + File file = fs.open(path, FILE_APPEND); + if (!file) { + Serial.println("Failed to open file for appending"); + return; + } + if (file.print(message)) { + Serial.println("Message appended"); + } else { + Serial.println("Append failed"); + } + file.close(); } -void renameFile(fs::FS &fs, const char * path1, const char * path2){ - Serial.printf("Renaming file %s to %s\n", path1, path2); - if (fs.rename(path1, path2)) { - Serial.println("File renamed"); - } else { - Serial.println("Rename failed"); - } +void renameFile(fs::FS &fs, const char *path1, const char *path2) { + Serial.printf("Renaming file %s to %s\n", path1, path2); + if (fs.rename(path1, path2)) { + Serial.println("File renamed"); + } else { + Serial.println("Rename failed"); + } } -void deleteFile(fs::FS &fs, const char * path){ - Serial.printf("Deleting file: %s\n", path); - if(fs.remove(path)){ - Serial.println("File deleted"); - } else { - Serial.println("Delete failed"); - } +void deleteFile(fs::FS &fs, const char *path) { + Serial.printf("Deleting file: %s\n", path); + if (fs.remove(path)) { + Serial.println("File deleted"); + } else { + Serial.println("Delete failed"); + } } -void setup(){ - Serial.begin(115200); - // We start by connecting to a WiFi network - Serial.println(); - Serial.println(); - Serial.print("Connecting to "); - Serial.println(ssid); - - WiFi.begin(ssid, password); - - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } - Serial.println("WiFi connected"); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println("Contacting Time Server"); - configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); - struct tm tmstruct ; - delay(2000); - tmstruct.tm_year = 0; - getLocalTime(&tmstruct, 5000); - Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct.tm_year)+1900,( tmstruct.tm_mon)+1, tmstruct.tm_mday,tmstruct.tm_hour , tmstruct.tm_min, tmstruct.tm_sec); - Serial.println(""); - - // If you are using any other ESP32-S3 board than ESP32-S3-USB-OTG which has preset default pins, you will - // need to specify the pins with the following example of SD_MMC.setPins() - // If you want to use only 1-bit mode, you can use the line with only one data pin (d0) begin changed. - // Please note that ESP32 does not allow pin changes and will fail unless you enter the same pin config as is the hardwired. +void setup() { + Serial.begin(115200); + // We start by connecting to a WiFi network + Serial.println(); + Serial.println(); + Serial.print("Connecting to "); + Serial.println(ssid); + + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + Serial.println("Contacting Time Server"); + configTime(3600 * timezone, daysavetime * 3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); + struct tm tmstruct; + delay(2000); + tmstruct.tm_year = 0; + getLocalTime(&tmstruct, 5000); + Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec); + Serial.println(""); + + // If you are using any other ESP32-S3 board than ESP32-S3-USB-OTG which has preset default pins, you will + // need to specify the pins with the following example of SD_MMC.setPins() + // If you want to use only 1-bit mode, you can use the line with only one data pin (d0) begin changed. + // Please note that ESP32 does not allow pin changes and will fail unless you enter the same pin config as is the hardwired. #if defined(SOC_SDMMC_USE_GPIO_MATRIX) && not defined(BOARD_HAS_SDMMC) - if(use_1_bit_mode){ - if(! SD_MMC.setPins(clk, cmd, d0)){ // 1-bit line version - Serial.println("Pin change failed!"); - return; - } - } else { - if(! SD_MMC.setPins(clk, cmd, d0, d1, d2, d3)){ // 4-bit line version - Serial.println("Pin change failed!"); - return; - } + if (use_1_bit_mode) { + if (!SD_MMC.setPins(clk, cmd, d0)) { // 1-bit line version + Serial.println("Pin change failed!"); + return; } + } else { + if (!SD_MMC.setPins(clk, cmd, d0, d1, d2, d3)) { // 4-bit line version + Serial.println("Pin change failed!"); + return; + } + } #endif - if(!SD_MMC.begin("/sdcard", use_1_bit_mode)){ - Serial.println("Card Mount Failed."); - Serial.println("Increase log level to see more info: Tools > Core Debug Level > Verbose"); - Serial.println("Make sure that all data pins have a 10k Ohm pull-up resistor to 3.3V"); + if (!SD_MMC.begin("/sdcard", use_1_bit_mode)) { + Serial.println("Card Mount Failed."); + Serial.println("Increase log level to see more info: Tools > Core Debug Level > Verbose"); + Serial.println("Make sure that all data pins have a 10k Ohm pull-up resistor to 3.3V"); #ifdef SOC_SDMMC_USE_GPIO_MATRIX - Serial.println("Make sure that when using generic ESP32-S3 board the pins are setup using SD_MMC.setPins()"); + Serial.println("Make sure that when using generic ESP32-S3 board the pins are setup using SD_MMC.setPins()"); #endif - return; - } - uint8_t cardType = SD_MMC.cardType(); - - if(cardType == CARD_NONE){ - Serial.println("No SD card attached"); - return; - } - - Serial.print("SD Card Type: "); - if(cardType == CARD_MMC){ - Serial.println("MMC"); - } else if(cardType == CARD_SD){ - Serial.println("SDSC"); - } else if(cardType == CARD_SDHC){ - Serial.println("SDHC"); - } else { - Serial.println("UNKNOWN"); - } - - uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024); - Serial.printf("SD Card Size: %lluMB\n", cardSize); - - listDir(SD_MMC, "/", 0); - removeDir(SD_MMC, "/mydir"); - createDir(SD_MMC, "/mydir"); - deleteFile(SD_MMC, "/hello.txt"); - writeFile(SD_MMC, "/hello.txt", "Hello "); - appendFile(SD_MMC, "/hello.txt", "World!\n"); - listDir(SD_MMC, "/", 0); + return; + } + uint8_t cardType = SD_MMC.cardType(); + + if (cardType == CARD_NONE) { + Serial.println("No SD card attached"); + return; + } + + Serial.print("SD Card Type: "); + if (cardType == CARD_MMC) { + Serial.println("MMC"); + } else if (cardType == CARD_SD) { + Serial.println("SDSC"); + } else if (cardType == CARD_SDHC) { + Serial.println("SDHC"); + } else { + Serial.println("UNKNOWN"); + } + + uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024); + Serial.printf("SD Card Size: %lluMB\n", cardSize); + + listDir(SD_MMC, "/", 0); + removeDir(SD_MMC, "/mydir"); + createDir(SD_MMC, "/mydir"); + deleteFile(SD_MMC, "/hello.txt"); + writeFile(SD_MMC, "/hello.txt", "Hello "); + appendFile(SD_MMC, "/hello.txt", "World!\n"); + listDir(SD_MMC, "/", 0); } -void loop(){ - +void loop() { } - - diff --git a/libraries/SD_MMC/src/SD_MMC.cpp b/libraries/SD_MMC/src/SD_MMC.cpp index 8ab5dec14b2..f80f93d1142 100644 --- a/libraries/SD_MMC/src/SD_MMC.cpp +++ b/libraries/SD_MMC/src/SD_MMC.cpp @@ -33,241 +33,226 @@ using namespace fs; SDMMCFS::SDMMCFS(FSImplPtr impl) - : FS(impl), _card(nullptr) -{ + : FS(impl), _card(nullptr) { #if defined(SOC_SDMMC_USE_GPIO_MATRIX) && defined(BOARD_HAS_SDMMC) - _pin_clk = SDMMC_CLK; - _pin_cmd = SDMMC_CMD; - _pin_d0 = SDMMC_D0; + _pin_clk = SDMMC_CLK; + _pin_cmd = SDMMC_CMD; + _pin_d0 = SDMMC_D0; #ifndef BOARD_HAS_1BIT_SDMMC - _pin_d1 = SDMMC_D1; - _pin_d2 = SDMMC_D2; - _pin_d3 = SDMMC_D3; -#endif // BOARD_HAS_1BIT_SDMMC + _pin_d1 = SDMMC_D1; + _pin_d2 = SDMMC_D2; + _pin_d3 = SDMMC_D3; +#endif // BOARD_HAS_1BIT_SDMMC #elif SOC_SDMMC_USE_IOMUX - _pin_clk = SDMMC_SLOT1_IOMUX_PIN_NUM_CLK; - _pin_cmd = SDMMC_SLOT1_IOMUX_PIN_NUM_CMD; - _pin_d0 = SDMMC_SLOT1_IOMUX_PIN_NUM_D0; + _pin_clk = SDMMC_SLOT1_IOMUX_PIN_NUM_CLK; + _pin_cmd = SDMMC_SLOT1_IOMUX_PIN_NUM_CMD; + _pin_d0 = SDMMC_SLOT1_IOMUX_PIN_NUM_D0; #ifndef BOARD_HAS_1BIT_SDMMC - _pin_d1 = SDMMC_SLOT1_IOMUX_PIN_NUM_D1; - _pin_d2 = SDMMC_SLOT1_IOMUX_PIN_NUM_D2; - _pin_d3 = SDMMC_SLOT1_IOMUX_PIN_NUM_D3; -#endif // BOARD_HAS_1BIT_SDMMC + _pin_d1 = SDMMC_SLOT1_IOMUX_PIN_NUM_D1; + _pin_d2 = SDMMC_SLOT1_IOMUX_PIN_NUM_D2; + _pin_d3 = SDMMC_SLOT1_IOMUX_PIN_NUM_D3; +#endif // BOARD_HAS_1BIT_SDMMC #endif } -bool SDMMCFS::sdmmcDetachBus(void * bus_pointer){ - SDMMCFS *bus = (SDMMCFS *) bus_pointer; - if(bus->_card) { - bus->end(); - } - return true; +bool SDMMCFS::sdmmcDetachBus(void *bus_pointer) { + SDMMCFS *bus = (SDMMCFS *)bus_pointer; + if (bus->_card) { + bus->end(); + } + return true; } -bool SDMMCFS::setPins(int clk, int cmd, int d0) -{ - return setPins(clk, cmd, d0, GPIO_NUM_NC, GPIO_NUM_NC, GPIO_NUM_NC); +bool SDMMCFS::setPins(int clk, int cmd, int d0) { + return setPins(clk, cmd, d0, GPIO_NUM_NC, GPIO_NUM_NC, GPIO_NUM_NC); } -bool SDMMCFS::setPins(int clk, int cmd, int d0, int d1, int d2, int d3) -{ - if (_card != nullptr) { - log_e("SD_MMC.setPins must be called before SD_MMC.begin"); - return false; - } +bool SDMMCFS::setPins(int clk, int cmd, int d0, int d1, int d2, int d3) { + if (_card != nullptr) { + log_e("SD_MMC.setPins must be called before SD_MMC.begin"); + return false; + } - // map logical pins to GPIO numbers - clk = digitalPinToGPIONumber(clk); - cmd = digitalPinToGPIONumber(cmd); - d0 = digitalPinToGPIONumber(d0); - d1 = digitalPinToGPIONumber(d1); - d2 = digitalPinToGPIONumber(d2); - d3 = digitalPinToGPIONumber(d3); + // map logical pins to GPIO numbers + clk = digitalPinToGPIONumber(clk); + cmd = digitalPinToGPIONumber(cmd); + d0 = digitalPinToGPIONumber(d0); + d1 = digitalPinToGPIONumber(d1); + d2 = digitalPinToGPIONumber(d2); + d3 = digitalPinToGPIONumber(d3); #ifdef SOC_SDMMC_USE_GPIO_MATRIX - // SoC supports SDMMC pin configuration via GPIO matrix. Save the pins for later use in SDMMCFS::begin. - _pin_clk = (int8_t) clk; - _pin_cmd = (int8_t) cmd; - _pin_d0 = (int8_t) d0; - _pin_d1 = (int8_t) d1; - _pin_d2 = (int8_t) d2; - _pin_d3 = (int8_t) d3; - return true; + // SoC supports SDMMC pin configuration via GPIO matrix. Save the pins for later use in SDMMCFS::begin. + _pin_clk = (int8_t)clk; + _pin_cmd = (int8_t)cmd; + _pin_d0 = (int8_t)d0; + _pin_d1 = (int8_t)d1; + _pin_d2 = (int8_t)d2; + _pin_d3 = (int8_t)d3; + return true; #elif CONFIG_IDF_TARGET_ESP32 - // ESP32 doesn't support SDMMC pin configuration via GPIO matrix. - // Since SDMMCFS::begin hardcodes the usage of slot 1, only check if - // the pins match slot 1 pins. - bool pins_ok = (clk == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_CLK) && - (cmd == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_CMD) && - (d0 == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_D0) && - (((d1 == -1) && (d2 == -1) && (d3 == -1)) || - ((d1 == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_D1) && - (d2 == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_D2) && - (d3 == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_D3))); - if (!pins_ok) { - log_e("SDMMCFS: specified pins are not supported by this chip."); - return false; - } - return true; + // ESP32 doesn't support SDMMC pin configuration via GPIO matrix. + // Since SDMMCFS::begin hardcodes the usage of slot 1, only check if + // the pins match slot 1 pins. + bool pins_ok = (clk == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_CLK) && (cmd == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_CMD) && (d0 == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_D0) && (((d1 == -1) && (d2 == -1) && (d3 == -1)) || ((d1 == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_D1) && (d2 == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_D2) && (d3 == (int)SDMMC_SLOT1_IOMUX_PIN_NUM_D3))); + if (!pins_ok) { + log_e("SDMMCFS: specified pins are not supported by this chip."); + return false; + } + return true; #else #error SoC not supported #endif } -bool SDMMCFS::begin(const char * mountpoint, bool mode1bit, bool format_if_mount_failed, int sdmmc_frequency, uint8_t maxOpenFiles) -{ - if(_card) { - return true; - } - perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_CLK, SDMMCFS::sdmmcDetachBus); - perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_CMD, SDMMCFS::sdmmcDetachBus); - perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_D0, SDMMCFS::sdmmcDetachBus); - if(!mode1bit) { - perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_D1, SDMMCFS::sdmmcDetachBus); - perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_D2, SDMMCFS::sdmmcDetachBus); - perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_D3, SDMMCFS::sdmmcDetachBus); - } - //mount - sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); +bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_failed, int sdmmc_frequency, uint8_t maxOpenFiles) { + if (_card) { + return true; + } + perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_CLK, SDMMCFS::sdmmcDetachBus); + perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_CMD, SDMMCFS::sdmmcDetachBus); + perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_D0, SDMMCFS::sdmmcDetachBus); + if (!mode1bit) { + perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_D1, SDMMCFS::sdmmcDetachBus); + perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_D2, SDMMCFS::sdmmcDetachBus); + perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_D3, SDMMCFS::sdmmcDetachBus); + } + //mount + sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); #ifdef SOC_SDMMC_USE_GPIO_MATRIX - // SoC supports SDMMC pin configuration via GPIO matrix. - // Check that the pins have been set either in the constructor or setPins function. - if (_pin_cmd == -1 || _pin_clk == -1 || _pin_d0 == -1 - || (!mode1bit && (_pin_d1 == -1 || _pin_d2 == -1 || _pin_d3 == -1))) { - log_e("SDMMCFS: some SD pins are not set"); - return false; - } + // SoC supports SDMMC pin configuration via GPIO matrix. + // Check that the pins have been set either in the constructor or setPins function. + if (_pin_cmd == -1 || _pin_clk == -1 || _pin_d0 == -1 + || (!mode1bit && (_pin_d1 == -1 || _pin_d2 == -1 || _pin_d3 == -1))) { + log_e("SDMMCFS: some SD pins are not set"); + return false; + } - slot_config.clk = (gpio_num_t) _pin_clk; - slot_config.cmd = (gpio_num_t) _pin_cmd; - slot_config.d0 = (gpio_num_t) _pin_d0; - slot_config.d1 = (gpio_num_t) _pin_d1; - slot_config.d2 = (gpio_num_t) _pin_d2; - slot_config.d3 = (gpio_num_t) _pin_d3; - slot_config.width = 4; -#endif // SOC_SDMMC_USE_GPIO_MATRIX + slot_config.clk = (gpio_num_t)_pin_clk; + slot_config.cmd = (gpio_num_t)_pin_cmd; + slot_config.d0 = (gpio_num_t)_pin_d0; + slot_config.d1 = (gpio_num_t)_pin_d1; + slot_config.d2 = (gpio_num_t)_pin_d2; + slot_config.d3 = (gpio_num_t)_pin_d3; + slot_config.width = 4; +#endif // SOC_SDMMC_USE_GPIO_MATRIX - if(!perimanClearPinBus(_pin_cmd)){ return false; } - if(!perimanClearPinBus(_pin_clk)){ return false; } - if(!perimanClearPinBus(_pin_d0)){ return false; } - if(!mode1bit) { - if(!perimanClearPinBus(_pin_d1)){ return false; } - if(!perimanClearPinBus(_pin_d2)){ return false; } - if(!perimanClearPinBus(_pin_d3)){ return false; } - } - - sdmmc_host_t host = SDMMC_HOST_DEFAULT(); - host.flags = SDMMC_HOST_FLAG_4BIT; - host.slot = SDMMC_HOST_SLOT_1; - host.max_freq_khz = sdmmc_frequency; + if (!perimanClearPinBus(_pin_cmd)) { return false; } + if (!perimanClearPinBus(_pin_clk)) { return false; } + if (!perimanClearPinBus(_pin_d0)) { return false; } + if (!mode1bit) { + if (!perimanClearPinBus(_pin_d1)) { return false; } + if (!perimanClearPinBus(_pin_d2)) { return false; } + if (!perimanClearPinBus(_pin_d3)) { return false; } + } + + sdmmc_host_t host = SDMMC_HOST_DEFAULT(); + host.flags = SDMMC_HOST_FLAG_4BIT; + host.slot = SDMMC_HOST_SLOT_1; + host.max_freq_khz = sdmmc_frequency; #ifdef BOARD_HAS_1BIT_SDMMC - mode1bit = true; + mode1bit = true; #endif - if(mode1bit) { - host.flags = SDMMC_HOST_FLAG_1BIT; //use 1-line SD mode - slot_config.width = 1; - } - _mode1bit = mode1bit; + if (mode1bit) { + host.flags = SDMMC_HOST_FLAG_1BIT; //use 1-line SD mode + slot_config.width = 1; + } + _mode1bit = mode1bit; - esp_vfs_fat_sdmmc_mount_config_t mount_config = { - .format_if_mount_failed = format_if_mount_failed, - .max_files = maxOpenFiles, - .allocation_unit_size = 0, - .disk_status_check_enable = false - }; + esp_vfs_fat_sdmmc_mount_config_t mount_config = { + .format_if_mount_failed = format_if_mount_failed, + .max_files = maxOpenFiles, + .allocation_unit_size = 0, + .disk_status_check_enable = false + }; - esp_err_t ret = esp_vfs_fat_sdmmc_mount(mountpoint, &host, &slot_config, &mount_config, &_card); - if (ret != ESP_OK) { - if (ret == ESP_FAIL) { - log_e("Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true."); - } else if (ret == ESP_ERR_INVALID_STATE) { - _impl->mountpoint(mountpoint); - log_w("SD Already mounted"); - return true; - } else { - log_e("Failed to initialize the card (0x%x). Make sure SD card lines have pull-up resistors in place.", ret); - } - _card = NULL; - return false; + esp_err_t ret = esp_vfs_fat_sdmmc_mount(mountpoint, &host, &slot_config, &mount_config, &_card); + if (ret != ESP_OK) { + if (ret == ESP_FAIL) { + log_e("Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true."); + } else if (ret == ESP_ERR_INVALID_STATE) { + _impl->mountpoint(mountpoint); + log_w("SD Already mounted"); + return true; + } else { + log_e("Failed to initialize the card (0x%x). Make sure SD card lines have pull-up resistors in place.", ret); } - _impl->mountpoint(mountpoint); + _card = NULL; + return false; + } + _impl->mountpoint(mountpoint); - if(!perimanSetPinBus(_pin_cmd, ESP32_BUS_TYPE_SDMMC_CMD, (void *)(this), -1, -1)){ goto err; } - if(!perimanSetPinBus(_pin_clk, ESP32_BUS_TYPE_SDMMC_CLK, (void *)(this), -1, -1)){ goto err; } - if(!perimanSetPinBus(_pin_d0, ESP32_BUS_TYPE_SDMMC_D0, (void *)(this), -1, -1)){ goto err; } - if(!mode1bit) { - if(!perimanSetPinBus(_pin_d1, ESP32_BUS_TYPE_SDMMC_D1, (void *)(this), -1, -1)){ goto err; } - if(!perimanSetPinBus(_pin_d2, ESP32_BUS_TYPE_SDMMC_D2, (void *)(this), -1, -1)){ goto err; } - if(!perimanSetPinBus(_pin_d3, ESP32_BUS_TYPE_SDMMC_D3, (void *)(this), -1, -1)){ goto err; } - } - return true; + if (!perimanSetPinBus(_pin_cmd, ESP32_BUS_TYPE_SDMMC_CMD, (void *)(this), -1, -1)) { goto err; } + if (!perimanSetPinBus(_pin_clk, ESP32_BUS_TYPE_SDMMC_CLK, (void *)(this), -1, -1)) { goto err; } + if (!perimanSetPinBus(_pin_d0, ESP32_BUS_TYPE_SDMMC_D0, (void *)(this), -1, -1)) { goto err; } + if (!mode1bit) { + if (!perimanSetPinBus(_pin_d1, ESP32_BUS_TYPE_SDMMC_D1, (void *)(this), -1, -1)) { goto err; } + if (!perimanSetPinBus(_pin_d2, ESP32_BUS_TYPE_SDMMC_D2, (void *)(this), -1, -1)) { goto err; } + if (!perimanSetPinBus(_pin_d3, ESP32_BUS_TYPE_SDMMC_D3, (void *)(this), -1, -1)) { goto err; } + } + return true; err: - log_e("Failed to set all pins bus to SDMMC"); - SDMMCFS::sdmmcDetachBus((void *)(this)); - return false; + log_e("Failed to set all pins bus to SDMMC"); + SDMMCFS::sdmmcDetachBus((void *)(this)); + return false; } -void SDMMCFS::end() -{ - if(_card) { - esp_vfs_fat_sdcard_unmount(_impl->mountpoint(), _card); - _impl->mountpoint(NULL); - _card = NULL; - perimanClearPinBus(_pin_cmd); - perimanClearPinBus(_pin_clk); - perimanClearPinBus(_pin_d0); - if(!_mode1bit) { - perimanClearPinBus(_pin_d1); - perimanClearPinBus(_pin_d2); - perimanClearPinBus(_pin_d3); - } +void SDMMCFS::end() { + if (_card) { + esp_vfs_fat_sdcard_unmount(_impl->mountpoint(), _card); + _impl->mountpoint(NULL); + _card = NULL; + perimanClearPinBus(_pin_cmd); + perimanClearPinBus(_pin_clk); + perimanClearPinBus(_pin_d0); + if (!_mode1bit) { + perimanClearPinBus(_pin_d1); + perimanClearPinBus(_pin_d2); + perimanClearPinBus(_pin_d3); } + } } -sdcard_type_t SDMMCFS::cardType() -{ - if(!_card) { - return CARD_NONE; - } - return (_card->ocr & SD_OCR_SDHC_CAP)?CARD_SDHC:CARD_SD; +sdcard_type_t SDMMCFS::cardType() { + if (!_card) { + return CARD_NONE; + } + return (_card->ocr & SD_OCR_SDHC_CAP) ? CARD_SDHC : CARD_SD; } -uint64_t SDMMCFS::cardSize() -{ - if(!_card) { - return 0; - } - return (uint64_t)_card->csd.capacity * _card->csd.sector_size; +uint64_t SDMMCFS::cardSize() { + if (!_card) { + return 0; + } + return (uint64_t)_card->csd.capacity * _card->csd.sector_size; } -uint64_t SDMMCFS::totalBytes() -{ - FATFS* fsinfo; - DWORD fre_clust; - if(f_getfree("0:",&fre_clust,&fsinfo)!= 0) return 0; - uint64_t size = ((uint64_t)(fsinfo->csize))*(fsinfo->n_fatent - 2) +uint64_t SDMMCFS::totalBytes() { + FATFS *fsinfo; + DWORD fre_clust; + if (f_getfree("0:", &fre_clust, &fsinfo) != 0) return 0; + uint64_t size = ((uint64_t)(fsinfo->csize)) * (fsinfo->n_fatent - 2) #if _MAX_SS != 512 - *(fsinfo->ssize); + * (fsinfo->ssize); #else - *512; + * 512; #endif - return size; + return size; } -uint64_t SDMMCFS::usedBytes() -{ - FATFS* fsinfo; - DWORD fre_clust; - if(f_getfree("0:",&fre_clust,&fsinfo)!= 0) return 0; - uint64_t size = ((uint64_t)(fsinfo->csize))*((fsinfo->n_fatent - 2) - (fsinfo->free_clst)) +uint64_t SDMMCFS::usedBytes() { + FATFS *fsinfo; + DWORD fre_clust; + if (f_getfree("0:", &fre_clust, &fsinfo) != 0) return 0; + uint64_t size = ((uint64_t)(fsinfo->csize)) * ((fsinfo->n_fatent - 2) - (fsinfo->free_clst)) #if _MAX_SS != 512 - *(fsinfo->ssize); + * (fsinfo->ssize); #else - *512; + * 512; #endif - return size; + return size; } SDMMCFS SD_MMC = SDMMCFS(FSImplPtr(new VFSImpl())); diff --git a/libraries/SD_MMC/src/SD_MMC.h b/libraries/SD_MMC/src/SD_MMC.h index ed0165dabb0..88583536999 100644 --- a/libraries/SD_MMC/src/SD_MMC.h +++ b/libraries/SD_MMC/src/SD_MMC.h @@ -22,41 +22,39 @@ #include "driver/sdmmc_types.h" #include "sd_defines.h" -// If reading/writing to the SD card is unstable, -// you can define BOARD_MAX_SDMMC_FREQ with lower value (Ex. SDMMC_FREQ_DEFAULT) +// If reading/writing to the SD card is unstable, +// you can define BOARD_MAX_SDMMC_FREQ with lower value (Ex. SDMMC_FREQ_DEFAULT) // in pins_arduino.h for your board variant. #ifndef BOARD_MAX_SDMMC_FREQ #define BOARD_MAX_SDMMC_FREQ SDMMC_FREQ_HIGHSPEED #endif -namespace fs -{ +namespace fs { -class SDMMCFS : public FS -{ +class SDMMCFS : public FS { protected: - sdmmc_card_t* _card; - int8_t _pin_clk = -1; - int8_t _pin_cmd = -1; - int8_t _pin_d0 = -1; - int8_t _pin_d1 = -1; - int8_t _pin_d2 = -1; - int8_t _pin_d3 = -1; - bool _mode1bit = false; + sdmmc_card_t* _card; + int8_t _pin_clk = -1; + int8_t _pin_cmd = -1; + int8_t _pin_d0 = -1; + int8_t _pin_d1 = -1; + int8_t _pin_d2 = -1; + int8_t _pin_d3 = -1; + bool _mode1bit = false; public: - SDMMCFS(FSImplPtr impl); - bool setPins(int clk, int cmd, int d0); - bool setPins(int clk, int cmd, int d0, int d1, int d2, int d3); - bool begin(const char * mountpoint="/sdcard", bool mode1bit=false, bool format_if_mount_failed=false, int sdmmc_frequency=BOARD_MAX_SDMMC_FREQ, uint8_t maxOpenFiles = 5); - void end(); - sdcard_type_t cardType(); - uint64_t cardSize(); - uint64_t totalBytes(); - uint64_t usedBytes(); - + SDMMCFS(FSImplPtr impl); + bool setPins(int clk, int cmd, int d0); + bool setPins(int clk, int cmd, int d0, int d1, int d2, int d3); + bool begin(const char* mountpoint = "/sdcard", bool mode1bit = false, bool format_if_mount_failed = false, int sdmmc_frequency = BOARD_MAX_SDMMC_FREQ, uint8_t maxOpenFiles = 5); + void end(); + sdcard_type_t cardType(); + uint64_t cardSize(); + uint64_t totalBytes(); + uint64_t usedBytes(); + private: - static bool sdmmcDetachBus(void * bus_pointer); + static bool sdmmcDetachBus(void* bus_pointer); }; } diff --git a/libraries/SD_MMC/src/sd_defines.h b/libraries/SD_MMC/src/sd_defines.h index 6e42855ac61..9a6b8399165 100644 --- a/libraries/SD_MMC/src/sd_defines.h +++ b/libraries/SD_MMC/src/sd_defines.h @@ -15,11 +15,11 @@ #define _SD_DEFINES_H_ typedef enum { - CARD_NONE, - CARD_MMC, - CARD_SD, - CARD_SDHC, - CARD_UNKNOWN + CARD_NONE, + CARD_MMC, + CARD_SD, + CARD_SDHC, + CARD_UNKNOWN } sdcard_type_t; #endif /* _SD_DISKIO_H_ */ diff --git a/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino b/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino index b0991d5fe3f..ccce658474c 100644 --- a/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino +++ b/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino @@ -1,16 +1,16 @@ /* The ESP32 has four SPi buses, however as of right now only two of - * them are available to use, HSPI and VSPI. Simply using the SPI API + * them are available to use, HSPI and VSPI. Simply using the SPI API * as illustrated in Arduino examples will use VSPI, leaving HSPI unused. - * - * However if we simply intialise two instance of the SPI class for both + * + * However if we simply initialize two instance of the SPI class for both * of these buses both can be used. However when just using these the Arduino * way only will actually be outputting at a time. - * - * Logic analyser capture is in the same folder as this example as + * + * Logic analyzer capture is in the same folder as this example as * "multiple_bus_output.png" - * + * * created 30/04/2018 by Alistair Symonds */ #include @@ -18,73 +18,72 @@ // Define ALTERNATE_PINS to use non-standard GPIO pins for SPI bus #ifdef ALTERNATE_PINS - #define VSPI_MISO 2 - #define VSPI_MOSI 4 - #define VSPI_SCLK 0 - #define VSPI_SS 33 - - #define HSPI_MISO 26 - #define HSPI_MOSI 27 - #define HSPI_SCLK 25 - #define HSPI_SS 32 +#define VSPI_MISO 2 +#define VSPI_MOSI 4 +#define VSPI_SCLK 0 +#define VSPI_SS 33 + +#define HSPI_MISO 26 +#define HSPI_MOSI 27 +#define HSPI_SCLK 25 +#define HSPI_SS 32 #else - #define VSPI_MISO MISO - #define VSPI_MOSI MOSI - #define VSPI_SCLK SCK - #define VSPI_SS SS - - #define HSPI_MISO 12 - #define HSPI_MOSI 13 - #define HSPI_SCLK 14 - #define HSPI_SS 15 +#define VSPI_MISO MISO +#define VSPI_MOSI MOSI +#define VSPI_SCLK SCK +#define VSPI_SS SS + +#define HSPI_MISO 12 +#define HSPI_MOSI 13 +#define HSPI_SCLK 14 +#define HSPI_SS 15 #endif #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 #define VSPI FSPI #endif -static const int spiClk = 1000000; // 1 MHz +static const int spiClk = 1000000; // 1 MHz -//uninitalised pointers to SPI objects -SPIClass * vspi = NULL; -SPIClass * hspi = NULL; +//uninitialised pointers to SPI objects +SPIClass *vspi = NULL; +SPIClass *hspi = NULL; void setup() { - //initialise two instances of the SPIClass attached to VSPI and HSPI respectively + //initialize two instances of the SPIClass attached to VSPI and HSPI respectively vspi = new SPIClass(VSPI); hspi = new SPIClass(HSPI); - + //clock miso mosi ss #ifndef ALTERNATE_PINS - //initialise vspi with default pins + //initialize vspi with default pins //SCLK = 18, MISO = 19, MOSI = 23, SS = 5 vspi->begin(); #else //alternatively route through GPIO pins of your choice - vspi->begin(VSPI_SCLK, VSPI_MISO, VSPI_MOSI, VSPI_SS); //SCLK, MISO, MOSI, SS + vspi->begin(VSPI_SCLK, VSPI_MISO, VSPI_MOSI, VSPI_SS); //SCLK, MISO, MOSI, SS #endif #ifndef ALTERNATE_PINS - //initialise hspi with default pins + //initialize hspi with default pins //SCLK = 14, MISO = 12, MOSI = 13, SS = 15 hspi->begin(); #else //alternatively route through GPIO pins - hspi->begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_SS); //SCLK, MISO, MOSI, SS + hspi->begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_SS); //SCLK, MISO, MOSI, SS #endif //set up slave select pins as outputs as the Arduino API //doesn't handle automatically pulling SS low - pinMode(vspi->pinSS(), OUTPUT); //VSPI SS - pinMode(hspi->pinSS(), OUTPUT); //HSPI SS - + pinMode(vspi->pinSS(), OUTPUT); //VSPI SS + pinMode(hspi->pinSS(), OUTPUT); //HSPI SS } // the loop function runs over and over again until power down or reset void loop() { //use the SPI buses - spiCommand(vspi, 0b01010101); // junk data to illustrate usage + spiCommand(vspi, 0b01010101); // junk data to illustrate usage spiCommand(hspi, 0b11001100); delay(100); } @@ -92,8 +91,8 @@ void loop() { void spiCommand(SPIClass *spi, byte data) { //use it as you would the regular arduino SPI API spi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0)); - digitalWrite(spi->pinSS(), LOW); //pull SS slow to prep other end for transfer + digitalWrite(spi->pinSS(), LOW); //pull SS slow to prep other end for transfer spi->transfer(data); - digitalWrite(spi->pinSS(), HIGH); //pull ss high to signify end of data transfer + digitalWrite(spi->pinSS(), HIGH); //pull ss high to signify end of data transfer spi->endTransaction(); } diff --git a/libraries/SPI/keywords.txt b/libraries/SPI/keywords.txt index fa7616581aa..492c2647781 100644 --- a/libraries/SPI/keywords.txt +++ b/libraries/SPI/keywords.txt @@ -33,4 +33,4 @@ SPI_CLOCK_DIV64 LITERAL1 SPI_MODE0 LITERAL1 SPI_MODE1 LITERAL1 SPI_MODE2 LITERAL1 -SPI_MODE3 LITERAL1 \ No newline at end of file +SPI_MODE3 LITERAL1 diff --git a/libraries/SPI/library.properties b/libraries/SPI/library.properties index cf6458fd4e6..e32675a8828 100644 --- a/libraries/SPI/library.properties +++ b/libraries/SPI/library.properties @@ -2,7 +2,7 @@ name=SPI version=2.0.0 author=Hristo Gochkov maintainer=Hristo Gochkov -sentence=Enables the communication with devices that use the Serial Peripheral Interface (SPI) Bus. For all Arduino boards, BUT Arduino DUE. +sentence=Enables the communication with devices that use the Serial Peripheral Interface (SPI) Bus. For all Arduino boards, BUT Arduino DUE. paragraph= category=Signal Input/Output url=http://arduino.cc/en/Reference/SPI diff --git a/libraries/SPI/src/SPI.cpp b/libraries/SPI/src/SPI.cpp index 17142b38c60..3bbc783bbc1 100644 --- a/libraries/SPI/src/SPI.cpp +++ b/libraries/SPI/src/SPI.cpp @@ -1,9 +1,9 @@ -/* +/* SPI.cpp - SPI library for esp8266 Copyright (c) 2015 Hristo Gochkov. All rights reserved. This file is part of the esp8266 core for Arduino environment. - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either @@ -26,274 +26,246 @@ #include "esp32-hal-log.h" #if !CONFIG_DISABLE_HAL_LOCKS -#define SPI_PARAM_LOCK() do {} while (xSemaphoreTake(paramLock, portMAX_DELAY) != pdPASS) -#define SPI_PARAM_UNLOCK() xSemaphoreGive(paramLock) +#define SPI_PARAM_LOCK() \ + do { \ + } while (xSemaphoreTake(paramLock, portMAX_DELAY) != pdPASS) +#define SPI_PARAM_UNLOCK() xSemaphoreGive(paramLock) #else #define SPI_PARAM_LOCK() #define SPI_PARAM_UNLOCK() #endif SPIClass::SPIClass(uint8_t spi_bus) - :_spi_num(spi_bus) - ,_spi(NULL) - ,_use_hw_ss(false) - ,_sck(-1) - ,_miso(-1) - ,_mosi(-1) - ,_ss(-1) - ,_div(0) - ,_freq(1000000) - ,_inTransaction(false) + : _spi_num(spi_bus), _spi(NULL), _use_hw_ss(false), _sck(-1), _miso(-1), _mosi(-1), _ss(-1), _div(0), _freq(1000000), _inTransaction(false) #if !CONFIG_DISABLE_HAL_LOCKS - ,paramLock(NULL) -{ - if(paramLock==NULL){ - paramLock = xSemaphoreCreateMutex(); - if(paramLock==NULL){ - log_e("xSemaphoreCreateMutex failed"); - return; - } + , + paramLock(NULL) { + if (paramLock == NULL) { + paramLock = xSemaphoreCreateMutex(); + if (paramLock == NULL) { + log_e("xSemaphoreCreateMutex failed"); + return; } + } } #else -{} +{ +} #endif -SPIClass::~SPIClass() -{ - end(); +SPIClass::~SPIClass() { + end(); #if !CONFIG_DISABLE_HAL_LOCKS - if(paramLock!=NULL){ - vSemaphoreDelete(paramLock); - paramLock = NULL; - } + if (paramLock != NULL) { + vSemaphoreDelete(paramLock); + paramLock = NULL; + } #endif } -void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) -{ - if(_spi) { - return; - } +void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) { + if (_spi) { + return; + } - if(!_div) { - _div = spiFrequencyToClockDiv(_freq); - } + if (!_div) { + _div = spiFrequencyToClockDiv(_freq); + } - _spi = spiStartBus(_spi_num, _div, SPI_MODE0, SPI_MSBFIRST); - if(!_spi) { - return; - } + _spi = spiStartBus(_spi_num, _div, SPI_MODE0, SPI_MSBFIRST); + if (!_spi) { + return; + } - if(sck == -1 && miso == -1 && mosi == -1 && ss == -1) { + if (sck == -1 && miso == -1 && mosi == -1 && ss == -1) { #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 - _sck = (_spi_num == FSPI) ? SCK : -1; - _miso = (_spi_num == FSPI) ? MISO : -1; - _mosi = (_spi_num == FSPI) ? MOSI : -1; - _ss = (_spi_num == FSPI) ? SS : -1; + _sck = (_spi_num == FSPI) ? SCK : -1; + _miso = (_spi_num == FSPI) ? MISO : -1; + _mosi = (_spi_num == FSPI) ? MOSI : -1; + _ss = (_spi_num == FSPI) ? SS : -1; #elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - _sck = SCK; - _miso = MISO; - _mosi = MOSI; - _ss = SS; + _sck = SCK; + _miso = MISO; + _mosi = MOSI; + _ss = SS; #else - _sck = (_spi_num == VSPI) ? SCK : 14; - _miso = (_spi_num == VSPI) ? MISO : 12; - _mosi = (_spi_num == VSPI) ? MOSI : 13; - _ss = (_spi_num == VSPI) ? SS : 15; + _sck = (_spi_num == VSPI) ? SCK : 14; + _miso = (_spi_num == VSPI) ? MISO : 12; + _mosi = (_spi_num == VSPI) ? MOSI : 13; + _ss = (_spi_num == VSPI) ? SS : 15; #endif - } else { - _sck = sck; - _miso = miso; - _mosi = mosi; - _ss = ss; - } - - if(!spiAttachSCK(_spi, _sck)){ goto err; } - if(_miso >= 0 && !spiAttachMISO(_spi, _miso)){ goto err; } - if(_mosi >= 0 && !spiAttachMOSI(_spi, _mosi)){ goto err; } - return; + } else { + _sck = sck; + _miso = miso; + _mosi = mosi; + _ss = ss; + } + + if (!spiAttachSCK(_spi, _sck)) { goto err; } + if (_miso >= 0 && !spiAttachMISO(_spi, _miso)) { goto err; } + if (_mosi >= 0 && !spiAttachMOSI(_spi, _mosi)) { goto err; } + return; err: - log_e("Attaching pins to SPI failed."); - + log_e("Attaching pins to SPI failed."); } -void SPIClass::end() -{ - if(!_spi) { - return; - } - spiDetachSCK(_spi); - spiDetachMISO(_spi); - spiDetachMOSI(_spi); - setHwCs(false); - if(spiGetClockDiv(_spi) != 0) { - spiStopBus(_spi); - } - _spi = NULL; +void SPIClass::end() { + if (!_spi) { + return; + } + spiDetachSCK(_spi); + spiDetachMISO(_spi); + spiDetachMOSI(_spi); + setHwCs(false); + if (spiGetClockDiv(_spi) != 0) { + spiStopBus(_spi); + } + _spi = NULL; } -void SPIClass::setHwCs(bool use) -{ - if(_ss < 0){ - return; - } - if(use && !_use_hw_ss) { - spiAttachSS(_spi, 0, _ss); - spiSSEnable(_spi); - } else if(!use && _use_hw_ss) { - spiSSDisable(_spi); - spiDetachSS(_spi); - } - _use_hw_ss = use; +void SPIClass::setHwCs(bool use) { + if (_ss < 0) { + return; + } + if (use && !_use_hw_ss) { + spiAttachSS(_spi, 0, _ss); + spiSSEnable(_spi); + } else if (!use && _use_hw_ss) { + spiSSDisable(_spi); + spiDetachSS(_spi); + } + _use_hw_ss = use; } -void SPIClass::setFrequency(uint32_t freq) -{ - SPI_PARAM_LOCK(); - //check if last freq changed - uint32_t cdiv = spiGetClockDiv(_spi); - if(_freq != freq || _div != cdiv) { - _freq = freq; - _div = spiFrequencyToClockDiv(_freq); - spiSetClockDiv(_spi, _div); - } - SPI_PARAM_UNLOCK(); +void SPIClass::setFrequency(uint32_t freq) { + SPI_PARAM_LOCK(); + //check if last freq changed + uint32_t cdiv = spiGetClockDiv(_spi); + if (_freq != freq || _div != cdiv) { + _freq = freq; + _div = spiFrequencyToClockDiv(_freq); + spiSetClockDiv(_spi, _div); + } + SPI_PARAM_UNLOCK(); } -void SPIClass::setClockDivider(uint32_t clockDiv) -{ - SPI_PARAM_LOCK(); - _div = clockDiv; - spiSetClockDiv(_spi, _div); - SPI_PARAM_UNLOCK(); +void SPIClass::setClockDivider(uint32_t clockDiv) { + SPI_PARAM_LOCK(); + _div = clockDiv; + spiSetClockDiv(_spi, _div); + SPI_PARAM_UNLOCK(); } -uint32_t SPIClass::getClockDivider() -{ - return spiGetClockDiv(_spi); +uint32_t SPIClass::getClockDivider() { + return spiGetClockDiv(_spi); } -void SPIClass::setDataMode(uint8_t dataMode) -{ - spiSetDataMode(_spi, dataMode); +void SPIClass::setDataMode(uint8_t dataMode) { + spiSetDataMode(_spi, dataMode); } -void SPIClass::setBitOrder(uint8_t bitOrder) -{ - spiSetBitOrder(_spi, bitOrder); +void SPIClass::setBitOrder(uint8_t bitOrder) { + spiSetBitOrder(_spi, bitOrder); } -void SPIClass::beginTransaction(SPISettings settings) -{ - SPI_PARAM_LOCK(); - //check if last freq changed - uint32_t cdiv = spiGetClockDiv(_spi); - if(_freq != settings._clock || _div != cdiv) { - _freq = settings._clock; - _div = spiFrequencyToClockDiv(_freq); - } - spiTransaction(_spi, _div, settings._dataMode, settings._bitOrder); - _inTransaction = true; +void SPIClass::beginTransaction(SPISettings settings) { + SPI_PARAM_LOCK(); + //check if last freq changed + uint32_t cdiv = spiGetClockDiv(_spi); + if (_freq != settings._clock || _div != cdiv) { + _freq = settings._clock; + _div = spiFrequencyToClockDiv(_freq); + } + spiTransaction(_spi, _div, settings._dataMode, settings._bitOrder); + _inTransaction = true; } -void SPIClass::endTransaction() -{ - if(_inTransaction){ - _inTransaction = false; - spiEndTransaction(_spi); - SPI_PARAM_UNLOCK(); // <-- Im not sure should it be here or right after spiTransaction() - } +void SPIClass::endTransaction() { + if (_inTransaction) { + _inTransaction = false; + spiEndTransaction(_spi); + SPI_PARAM_UNLOCK(); // <-- Im not sure should it be here or right after spiTransaction() + } } -void SPIClass::write(uint8_t data) -{ - if(_inTransaction){ - return spiWriteByteNL(_spi, data); - } - spiWriteByte(_spi, data); +void SPIClass::write(uint8_t data) { + if (_inTransaction) { + return spiWriteByteNL(_spi, data); + } + spiWriteByte(_spi, data); } -uint8_t SPIClass::transfer(uint8_t data) -{ - if(_inTransaction){ - return spiTransferByteNL(_spi, data); - } - return spiTransferByte(_spi, data); +uint8_t SPIClass::transfer(uint8_t data) { + if (_inTransaction) { + return spiTransferByteNL(_spi, data); + } + return spiTransferByte(_spi, data); } -void SPIClass::write16(uint16_t data) -{ - if(_inTransaction){ - return spiWriteShortNL(_spi, data); - } - spiWriteWord(_spi, data); +void SPIClass::write16(uint16_t data) { + if (_inTransaction) { + return spiWriteShortNL(_spi, data); + } + spiWriteWord(_spi, data); } -uint16_t SPIClass::transfer16(uint16_t data) -{ - if(_inTransaction){ - return spiTransferShortNL(_spi, data); - } - return spiTransferWord(_spi, data); +uint16_t SPIClass::transfer16(uint16_t data) { + if (_inTransaction) { + return spiTransferShortNL(_spi, data); + } + return spiTransferWord(_spi, data); } -void SPIClass::write32(uint32_t data) -{ - if(_inTransaction){ - return spiWriteLongNL(_spi, data); - } - spiWriteLong(_spi, data); +void SPIClass::write32(uint32_t data) { + if (_inTransaction) { + return spiWriteLongNL(_spi, data); + } + spiWriteLong(_spi, data); } -uint32_t SPIClass::transfer32(uint32_t data) -{ - if(_inTransaction){ - return spiTransferLongNL(_spi, data); - } - return spiTransferLong(_spi, data); +uint32_t SPIClass::transfer32(uint32_t data) { + if (_inTransaction) { + return spiTransferLongNL(_spi, data); + } + return spiTransferLong(_spi, data); } -void SPIClass::transferBits(uint32_t data, uint32_t * out, uint8_t bits) -{ - if(_inTransaction){ - return spiTransferBitsNL(_spi, data, out, bits); - } - spiTransferBits(_spi, data, out, bits); +void SPIClass::transferBits(uint32_t data, uint32_t *out, uint8_t bits) { + if (_inTransaction) { + return spiTransferBitsNL(_spi, data, out, bits); + } + spiTransferBits(_spi, data, out, bits); } /** * @param data uint8_t * * @param size uint32_t */ -void SPIClass::writeBytes(const uint8_t * data, uint32_t size) -{ - if(_inTransaction){ - return spiWriteNL(_spi, data, size); - } - spiSimpleTransaction(_spi); - spiWriteNL(_spi, data, size); - spiEndTransaction(_spi); +void SPIClass::writeBytes(const uint8_t *data, uint32_t size) { + if (_inTransaction) { + return spiWriteNL(_spi, data, size); + } + spiSimpleTransaction(_spi); + spiWriteNL(_spi, data, size); + spiEndTransaction(_spi); } -void SPIClass::transfer(void * data, uint32_t size) -{ - transferBytes((const uint8_t *)data, (uint8_t *)data, size); +void SPIClass::transfer(void *data, uint32_t size) { + transferBytes((const uint8_t *)data, (uint8_t *)data, size); } /** * @param data void * * @param size uint32_t */ -void SPIClass::writePixels(const void * data, uint32_t size) -{ - if(_inTransaction){ - return spiWritePixelsNL(_spi, data, size); - } - spiSimpleTransaction(_spi); - spiWritePixelsNL(_spi, data, size); - spiEndTransaction(_spi); +void SPIClass::writePixels(const void *data, uint32_t size) { + if (_inTransaction) { + return spiWritePixelsNL(_spi, data, size); + } + spiSimpleTransaction(_spi); + spiWritePixelsNL(_spi, data, size); + spiEndTransaction(_spi); } /** @@ -301,12 +273,11 @@ void SPIClass::writePixels(const void * data, uint32_t size) * @param out uint8_t * output buffer. can be NULL for Write Only operation * @param size uint32_t */ -void SPIClass::transferBytes(const uint8_t * data, uint8_t * out, uint32_t size) -{ - if(_inTransaction){ - return spiTransferBytesNL(_spi, data, out, size); - } - spiTransferBytes(_spi, data, out, size); +void SPIClass::transferBytes(const uint8_t *data, uint8_t *out, uint32_t size) { + if (_inTransaction) { + return spiTransferBytesNL(_spi, data, out, size); + } + spiTransferBytes(_spi, data, out, size); } /** @@ -314,45 +285,43 @@ void SPIClass::transferBytes(const uint8_t * data, uint8_t * out, uint32_t size) * @param size uint8_t max for size is 64Byte * @param repeat uint32_t */ -void SPIClass::writePattern(const uint8_t * data, uint8_t size, uint32_t repeat) -{ - if(size > 64) { - return; //max Hardware FIFO - } - - uint32_t byte = (size * repeat); - uint8_t r = (64 / size); - const uint8_t max_bytes_FIFO = r * size; // Max number of whole patterns (in bytes) that can fit into the hardware FIFO - - while(byte) { - if(byte > max_bytes_FIFO) { - writePattern_(data, size, r); - byte -= max_bytes_FIFO; - } else { - writePattern_(data, size, (byte / size)); - byte = 0; - } +void SPIClass::writePattern(const uint8_t *data, uint8_t size, uint32_t repeat) { + if (size > 64) { + return; //max Hardware FIFO + } + + uint32_t byte = (size * repeat); + uint8_t r = (64 / size); + const uint8_t max_bytes_FIFO = r * size; // Max number of whole patterns (in bytes) that can fit into the hardware FIFO + + while (byte) { + if (byte > max_bytes_FIFO) { + writePattern_(data, size, r); + byte -= max_bytes_FIFO; + } else { + writePattern_(data, size, (byte / size)); + byte = 0; } + } } -void SPIClass::writePattern_(const uint8_t * data, uint8_t size, uint8_t repeat) -{ - uint8_t bytes = (size * repeat); - uint8_t buffer[64]; - uint8_t * bufferPtr = &buffer[0]; - const uint8_t * dataPtr; - uint8_t dataSize = bytes; - for(uint8_t i = 0; i < repeat; i++) { - dataSize = size; - dataPtr = data; - while(dataSize--) { - *bufferPtr = *dataPtr; - dataPtr++; - bufferPtr++; - } +void SPIClass::writePattern_(const uint8_t *data, uint8_t size, uint8_t repeat) { + uint8_t bytes = (size * repeat); + uint8_t buffer[64]; + uint8_t *bufferPtr = &buffer[0]; + const uint8_t *dataPtr; + uint8_t dataSize = bytes; + for (uint8_t i = 0; i < repeat; i++) { + dataSize = size; + dataPtr = data; + while (dataSize--) { + *bufferPtr = *dataPtr; + dataPtr++; + bufferPtr++; } + } - writeBytes(&buffer[0], bytes); + writeBytes(&buffer[0], bytes); } #if CONFIG_IDF_TARGET_ESP32 diff --git a/libraries/SPI/src/SPI.h b/libraries/SPI/src/SPI.h index 70cc28a0d27..8d391123a1e 100644 --- a/libraries/SPI/src/SPI.h +++ b/libraries/SPI/src/SPI.h @@ -1,9 +1,9 @@ -/* +/* SPI.h - SPI library for esp32 Copyright (c) 2015 Hristo Gochkov. All rights reserved. This file is part of the esp8266 core for Arduino environment. - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either @@ -32,67 +32,71 @@ #define SPI_HAS_TRANSACTION -class SPISettings -{ +class SPISettings { public: - SPISettings() :_clock(1000000), _bitOrder(SPI_MSBFIRST), _dataMode(SPI_MODE0) {} - SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) :_clock(clock), _bitOrder(bitOrder), _dataMode(dataMode) {} - uint32_t _clock; - uint8_t _bitOrder; - uint8_t _dataMode; + SPISettings() + : _clock(1000000), _bitOrder(SPI_MSBFIRST), _dataMode(SPI_MODE0) {} + SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) + : _clock(clock), _bitOrder(bitOrder), _dataMode(dataMode) {} + uint32_t _clock; + uint8_t _bitOrder; + uint8_t _dataMode; }; -class SPIClass -{ +class SPIClass { private: - int8_t _spi_num; - spi_t * _spi; - bool _use_hw_ss; - int8_t _sck; - int8_t _miso; - int8_t _mosi; - int8_t _ss; - uint32_t _div; - uint32_t _freq; - bool _inTransaction; + int8_t _spi_num; + spi_t* _spi; + bool _use_hw_ss; + int8_t _sck; + int8_t _miso; + int8_t _mosi; + int8_t _ss; + uint32_t _div; + uint32_t _freq; + bool _inTransaction; #if !CONFIG_DISABLE_HAL_LOCKS - SemaphoreHandle_t paramLock=NULL; + SemaphoreHandle_t paramLock = NULL; #endif - void writePattern_(const uint8_t * data, uint8_t size, uint8_t repeat); + void writePattern_(const uint8_t* data, uint8_t size, uint8_t repeat); public: - SPIClass(uint8_t spi_bus=HSPI); - ~SPIClass(); - void begin(int8_t sck=-1, int8_t miso=-1, int8_t mosi=-1, int8_t ss=-1); - void end(); - - void setHwCs(bool use); - void setBitOrder(uint8_t bitOrder); - void setDataMode(uint8_t dataMode); - void setFrequency(uint32_t freq); - void setClockDivider(uint32_t clockDiv); - - uint32_t getClockDivider(); - - void beginTransaction(SPISettings settings); - void endTransaction(void); - void transfer(void * data, uint32_t size); - uint8_t transfer(uint8_t data); - uint16_t transfer16(uint16_t data); - uint32_t transfer32(uint32_t data); - - void transferBytes(const uint8_t * data, uint8_t * out, uint32_t size); - void transferBits(uint32_t data, uint32_t * out, uint8_t bits); - - void write(uint8_t data); - void write16(uint16_t data); - void write32(uint32_t data); - void writeBytes(const uint8_t * data, uint32_t size); - void writePixels(const void * data, uint32_t size);//ili9341 compatible - void writePattern(const uint8_t * data, uint8_t size, uint32_t repeat); - - spi_t * bus(){ return _spi; } - int8_t pinSS() { return _ss; } + SPIClass(uint8_t spi_bus = HSPI); + ~SPIClass(); + void begin(int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1, int8_t ss = -1); + void end(); + + void setHwCs(bool use); + void setBitOrder(uint8_t bitOrder); + void setDataMode(uint8_t dataMode); + void setFrequency(uint32_t freq); + void setClockDivider(uint32_t clockDiv); + + uint32_t getClockDivider(); + + void beginTransaction(SPISettings settings); + void endTransaction(void); + void transfer(void* data, uint32_t size); + uint8_t transfer(uint8_t data); + uint16_t transfer16(uint16_t data); + uint32_t transfer32(uint32_t data); + + void transferBytes(const uint8_t* data, uint8_t* out, uint32_t size); + void transferBits(uint32_t data, uint32_t* out, uint8_t bits); + + void write(uint8_t data); + void write16(uint16_t data); + void write32(uint32_t data); + void writeBytes(const uint8_t* data, uint32_t size); + void writePixels(const void* data, uint32_t size); //ili9341 compatible + void writePattern(const uint8_t* data, uint8_t size, uint32_t repeat); + + spi_t* bus() { + return _spi; + } + int8_t pinSS() { + return _ss; + } }; extern SPIClass SPI; diff --git a/libraries/SPIFFS/examples/SPIFFS_Test/SPIFFS_Test.ino b/libraries/SPIFFS/examples/SPIFFS_Test/SPIFFS_Test.ino index 3b19be5eaee..1de1b5b6c31 100644 --- a/libraries/SPIFFS/examples/SPIFFS_Test/SPIFFS_Test.ino +++ b/libraries/SPIFFS/examples/SPIFFS_Test/SPIFFS_Test.ino @@ -6,176 +6,175 @@ https://github.com/me-no-dev/arduino-esp32fs-plugin */ #define FORMAT_SPIFFS_IF_FAILED true -void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ - Serial.printf("Listing directory: %s\r\n", dirname); - - File root = fs.open(dirname); - if(!root){ - Serial.println("- failed to open directory"); - return; - } - if(!root.isDirectory()){ - Serial.println(" - not a directory"); - return; - } - - File file = root.openNextFile(); - while(file){ - if(file.isDirectory()){ - Serial.print(" DIR : "); - Serial.println(file.name()); - if(levels){ - listDir(fs, file.path(), levels -1); - } - } else { - Serial.print(" FILE: "); - Serial.print(file.name()); - Serial.print("\tSIZE: "); - Serial.println(file.size()); - } - file = root.openNextFile(); +void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { + Serial.printf("Listing directory: %s\r\n", dirname); + + File root = fs.open(dirname); + if (!root) { + Serial.println("- failed to open directory"); + return; + } + if (!root.isDirectory()) { + Serial.println(" - not a directory"); + return; + } + + File file = root.openNextFile(); + while (file) { + if (file.isDirectory()) { + Serial.print(" DIR : "); + Serial.println(file.name()); + if (levels) { + listDir(fs, file.path(), levels - 1); + } + } else { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print("\tSIZE: "); + Serial.println(file.size()); } + file = root.openNextFile(); + } } -void readFile(fs::FS &fs, const char * path){ - Serial.printf("Reading file: %s\r\n", path); +void readFile(fs::FS &fs, const char *path) { + Serial.printf("Reading file: %s\r\n", path); - File file = fs.open(path); - if(!file || file.isDirectory()){ - Serial.println("- failed to open file for reading"); - return; - } + File file = fs.open(path); + if (!file || file.isDirectory()) { + Serial.println("- failed to open file for reading"); + return; + } - Serial.println("- read from file:"); - while(file.available()){ - Serial.write(file.read()); - } - file.close(); + Serial.println("- read from file:"); + while (file.available()) { + Serial.write(file.read()); + } + file.close(); } -void writeFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Writing file: %s\r\n", path); - - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("- failed to open file for writing"); - return; - } - if(file.print(message)){ - Serial.println("- file written"); - } else { - Serial.println("- write failed"); - } - file.close(); +void writeFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Writing file: %s\r\n", path); + + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("- failed to open file for writing"); + return; + } + if (file.print(message)) { + Serial.println("- file written"); + } else { + Serial.println("- write failed"); + } + file.close(); } -void appendFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Appending to file: %s\r\n", path); - - File file = fs.open(path, FILE_APPEND); - if(!file){ - Serial.println("- failed to open file for appending"); - return; - } - if(file.print(message)){ - Serial.println("- message appended"); - } else { - Serial.println("- append failed"); - } - file.close(); +void appendFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Appending to file: %s\r\n", path); + + File file = fs.open(path, FILE_APPEND); + if (!file) { + Serial.println("- failed to open file for appending"); + return; + } + if (file.print(message)) { + Serial.println("- message appended"); + } else { + Serial.println("- append failed"); + } + file.close(); } -void renameFile(fs::FS &fs, const char * path1, const char * path2){ - Serial.printf("Renaming file %s to %s\r\n", path1, path2); - if (fs.rename(path1, path2)) { - Serial.println("- file renamed"); - } else { - Serial.println("- rename failed"); - } +void renameFile(fs::FS &fs, const char *path1, const char *path2) { + Serial.printf("Renaming file %s to %s\r\n", path1, path2); + if (fs.rename(path1, path2)) { + Serial.println("- file renamed"); + } else { + Serial.println("- rename failed"); + } } -void deleteFile(fs::FS &fs, const char * path){ - Serial.printf("Deleting file: %s\r\n", path); - if(fs.remove(path)){ - Serial.println("- file deleted"); - } else { - Serial.println("- delete failed"); - } +void deleteFile(fs::FS &fs, const char *path) { + Serial.printf("Deleting file: %s\r\n", path); + if (fs.remove(path)) { + Serial.println("- file deleted"); + } else { + Serial.println("- delete failed"); + } } -void testFileIO(fs::FS &fs, const char * path){ - Serial.printf("Testing file I/O with %s\r\n", path); - - static uint8_t buf[512]; - size_t len = 0; - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("- failed to open file for writing"); - return; +void testFileIO(fs::FS &fs, const char *path) { + Serial.printf("Testing file I/O with %s\r\n", path); + + static uint8_t buf[512]; + size_t len = 0; + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("- failed to open file for writing"); + return; + } + + size_t i; + Serial.print("- writing"); + uint32_t start = millis(); + for (i = 0; i < 2048; i++) { + if ((i & 0x001F) == 0x001F) { + Serial.print("."); } - - size_t i; - Serial.print("- writing" ); - uint32_t start = millis(); - for(i=0; i<2048; i++){ - if ((i & 0x001F) == 0x001F){ - Serial.print("."); - } - file.write(buf, 512); + file.write(buf, 512); + } + Serial.println(""); + uint32_t end = millis() - start; + Serial.printf(" - %u bytes written in %lu ms\r\n", 2048 * 512, end); + file.close(); + + file = fs.open(path); + start = millis(); + end = start; + i = 0; + if (file && !file.isDirectory()) { + len = file.size(); + size_t flen = len; + start = millis(); + Serial.print("- reading"); + while (len) { + size_t toRead = len; + if (toRead > 512) { + toRead = 512; + } + file.read(buf, toRead); + if ((i++ & 0x001F) == 0x001F) { + Serial.print("."); + } + len -= toRead; } Serial.println(""); - uint32_t end = millis() - start; - Serial.printf(" - %u bytes written in %lu ms\r\n", 2048 * 512, end); + end = millis() - start; + Serial.printf("- %u bytes read in %lu ms\r\n", flen, end); file.close(); - - file = fs.open(path); - start = millis(); - end = start; - i = 0; - if(file && !file.isDirectory()){ - len = file.size(); - size_t flen = len; - start = millis(); - Serial.print("- reading" ); - while(len){ - size_t toRead = len; - if(toRead > 512){ - toRead = 512; - } - file.read(buf, toRead); - if ((i++ & 0x001F) == 0x001F){ - Serial.print("."); - } - len -= toRead; - } - Serial.println(""); - end = millis() - start; - Serial.printf("- %u bytes read in %lu ms\r\n", flen, end); - file.close(); - } else { - Serial.println("- failed to open file for reading"); - } + } else { + Serial.println("- failed to open file for reading"); + } } -void setup(){ - Serial.begin(115200); - if(!SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED)){ - Serial.println("SPIFFS Mount Failed"); - return; - } - - listDir(SPIFFS, "/", 0); - writeFile(SPIFFS, "/hello.txt", "Hello "); - appendFile(SPIFFS, "/hello.txt", "World!\r\n"); - readFile(SPIFFS, "/hello.txt"); - renameFile(SPIFFS, "/hello.txt", "/foo.txt"); - readFile(SPIFFS, "/foo.txt"); - deleteFile(SPIFFS, "/foo.txt"); - testFileIO(SPIFFS, "/test.txt"); - deleteFile(SPIFFS, "/test.txt"); - Serial.println( "Test complete" ); +void setup() { + Serial.begin(115200); + if (!SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED)) { + Serial.println("SPIFFS Mount Failed"); + return; + } + + listDir(SPIFFS, "/", 0); + writeFile(SPIFFS, "/hello.txt", "Hello "); + appendFile(SPIFFS, "/hello.txt", "World!\r\n"); + readFile(SPIFFS, "/hello.txt"); + renameFile(SPIFFS, "/hello.txt", "/foo.txt"); + readFile(SPIFFS, "/foo.txt"); + deleteFile(SPIFFS, "/foo.txt"); + testFileIO(SPIFFS, "/test.txt"); + deleteFile(SPIFFS, "/test.txt"); + Serial.println("Test complete"); } -void loop(){ - +void loop() { } diff --git a/libraries/SPIFFS/examples/SPIFFS_time/SPIFFS_time.ino b/libraries/SPIFFS/examples/SPIFFS_time/SPIFFS_time.ino index a86759693a9..5a3eae8918a 100644 --- a/libraries/SPIFFS/examples/SPIFFS_time/SPIFFS_time.ino +++ b/libraries/SPIFFS/examples/SPIFFS_time/SPIFFS_time.ino @@ -1,177 +1,174 @@ #include "FS.h" #include "SPIFFS.h" -#include +#include #include -const char* ssid = "your-ssid"; -const char* password = "your-password"; +const char *ssid = "your-ssid"; +const char *password = "your-password"; -long timezone = 1; +long timezone = 1; byte daysavetime = 1; -void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ - Serial.printf("Listing directory: %s\n", dirname); - - File root = fs.open(dirname); - if(!root){ - Serial.println("Failed to open directory"); - return; - } - if(!root.isDirectory()){ - Serial.println("Not a directory"); - return; - } - - File file = root.openNextFile(); - while(file){ - if(file.isDirectory()){ - Serial.print(" DIR : "); - Serial.print (file.name()); - time_t t= file.getLastWrite(); - struct tm * tmstruct = localtime(&t); - Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec); - if(levels){ - listDir(fs, file.path(), levels -1); - } - } else { - Serial.print(" FILE: "); - Serial.print(file.name()); - Serial.print(" SIZE: "); - Serial.print(file.size()); - time_t t= file.getLastWrite(); - struct tm * tmstruct = localtime(&t); - Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec); - } - file = root.openNextFile(); +void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { + Serial.printf("Listing directory: %s\n", dirname); + + File root = fs.open(dirname); + if (!root) { + Serial.println("Failed to open directory"); + return; + } + if (!root.isDirectory()) { + Serial.println("Not a directory"); + return; + } + + File file = root.openNextFile(); + while (file) { + if (file.isDirectory()) { + Serial.print(" DIR : "); + Serial.print(file.name()); + time_t t = file.getLastWrite(); + struct tm *tmstruct = localtime(&t); + Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); + if (levels) { + listDir(fs, file.path(), levels - 1); + } + } else { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print(" SIZE: "); + Serial.print(file.size()); + time_t t = file.getLastWrite(); + struct tm *tmstruct = localtime(&t); + Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); } + file = root.openNextFile(); + } } -void createDir(fs::FS &fs, const char * path){ - Serial.printf("Creating Dir: %s\n", path); - if(fs.mkdir(path)){ - Serial.println("Dir created"); - } else { - Serial.println("mkdir failed"); - } +void createDir(fs::FS &fs, const char *path) { + Serial.printf("Creating Dir: %s\n", path); + if (fs.mkdir(path)) { + Serial.println("Dir created"); + } else { + Serial.println("mkdir failed"); + } } -void removeDir(fs::FS &fs, const char * path){ - Serial.printf("Removing Dir: %s\n", path); - if(fs.rmdir(path)){ - Serial.println("Dir removed"); - } else { - Serial.println("rmdir failed"); - } +void removeDir(fs::FS &fs, const char *path) { + Serial.printf("Removing Dir: %s\n", path); + if (fs.rmdir(path)) { + Serial.println("Dir removed"); + } else { + Serial.println("rmdir failed"); + } } -void readFile(fs::FS &fs, const char * path){ - Serial.printf("Reading file: %s\n", path); +void readFile(fs::FS &fs, const char *path) { + Serial.printf("Reading file: %s\n", path); - File file = fs.open(path); - if(!file){ - Serial.println("Failed to open file for reading"); - return; - } + File file = fs.open(path); + if (!file) { + Serial.println("Failed to open file for reading"); + return; + } - Serial.print("Read from file: "); - while(file.available()){ - Serial.write(file.read()); - } - file.close(); + Serial.print("Read from file: "); + while (file.available()) { + Serial.write(file.read()); + } + file.close(); } -void writeFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Writing file: %s\n", path); - - File file = fs.open(path, FILE_WRITE); - if(!file){ - Serial.println("Failed to open file for writing"); - return; - } - if(file.print(message)){ - Serial.println("File written"); - } else { - Serial.println("Write failed"); - } - file.close(); +void writeFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Writing file: %s\n", path); + + File file = fs.open(path, FILE_WRITE); + if (!file) { + Serial.println("Failed to open file for writing"); + return; + } + if (file.print(message)) { + Serial.println("File written"); + } else { + Serial.println("Write failed"); + } + file.close(); } -void appendFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Appending to file: %s\n", path); - - File file = fs.open(path, FILE_APPEND); - if(!file){ - Serial.println("Failed to open file for appending"); - return; - } - if(file.print(message)){ - Serial.println("Message appended"); - } else { - Serial.println("Append failed"); - } - file.close(); +void appendFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Appending to file: %s\n", path); + + File file = fs.open(path, FILE_APPEND); + if (!file) { + Serial.println("Failed to open file for appending"); + return; + } + if (file.print(message)) { + Serial.println("Message appended"); + } else { + Serial.println("Append failed"); + } + file.close(); } -void renameFile(fs::FS &fs, const char * path1, const char * path2){ - Serial.printf("Renaming file %s to %s\n", path1, path2); - if (fs.rename(path1, path2)) { - Serial.println("File renamed"); - } else { - Serial.println("Rename failed"); - } +void renameFile(fs::FS &fs, const char *path1, const char *path2) { + Serial.printf("Renaming file %s to %s\n", path1, path2); + if (fs.rename(path1, path2)) { + Serial.println("File renamed"); + } else { + Serial.println("Rename failed"); + } } -void deleteFile(fs::FS &fs, const char * path){ - Serial.printf("Deleting file: %s\n", path); - if(fs.remove(path)){ - Serial.println("File deleted"); - } else { - Serial.println("Delete failed"); - } +void deleteFile(fs::FS &fs, const char *path) { + Serial.printf("Deleting file: %s\n", path); + if (fs.remove(path)) { + Serial.println("File deleted"); + } else { + Serial.println("Delete failed"); + } } -void setup(){ - Serial.begin(115200); - // We start by connecting to a WiFi network - Serial.println(); - Serial.println(); - Serial.print("Connecting to "); - Serial.println(ssid); - - WiFi.begin(ssid, password); - - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } - Serial.println("WiFi connected"); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Serial.println("Contacting Time Server"); - configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); - struct tm tmstruct ; - delay(2000); - tmstruct.tm_year = 0; - getLocalTime(&tmstruct, 5000); - Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct.tm_year)+1900,( tmstruct.tm_mon)+1, tmstruct.tm_mday,tmstruct.tm_hour , tmstruct.tm_min, tmstruct.tm_sec); - Serial.println(""); - - if(!SPIFFS.begin()){ - Serial.println("Card Mount Failed"); - return; - } - - listDir(SPIFFS, "/", 0); - removeDir(SPIFFS, "/mydir"); - createDir(SPIFFS, "/mydir"); - deleteFile(SPIFFS, "/hello.txt"); - writeFile(SPIFFS, "/hello.txt", "Hello "); - appendFile(SPIFFS, "/hello.txt", "World!\n"); - listDir(SPIFFS, "/", 0); +void setup() { + Serial.begin(115200); + // We start by connecting to a WiFi network + Serial.println(); + Serial.println(); + Serial.print("Connecting to "); + Serial.println(ssid); + + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + Serial.println("Contacting Time Server"); + configTime(3600 * timezone, daysavetime * 3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); + struct tm tmstruct; + delay(2000); + tmstruct.tm_year = 0; + getLocalTime(&tmstruct, 5000); + Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec); + Serial.println(""); + + if (!SPIFFS.begin()) { + Serial.println("Card Mount Failed"); + return; + } + + listDir(SPIFFS, "/", 0); + removeDir(SPIFFS, "/mydir"); + createDir(SPIFFS, "/mydir"); + deleteFile(SPIFFS, "/hello.txt"); + writeFile(SPIFFS, "/hello.txt", "Hello "); + appendFile(SPIFFS, "/hello.txt", "World!\n"); + listDir(SPIFFS, "/", 0); } -void loop(){ - +void loop() { } - - diff --git a/libraries/SPIFFS/src/SPIFFS.cpp b/libraries/SPIFFS/src/SPIFFS.cpp index 0fb2eff08af..681da67485c 100644 --- a/libraries/SPIFFS/src/SPIFFS.cpp +++ b/libraries/SPIFFS/src/SPIFFS.cpp @@ -25,115 +25,104 @@ extern "C" { using namespace fs; -class SPIFFSImpl : public VFSImpl -{ +class SPIFFSImpl : public VFSImpl { public: - SPIFFSImpl(); - virtual ~SPIFFSImpl() { } - virtual bool exists(const char* path); + SPIFFSImpl(); + virtual ~SPIFFSImpl() {} + virtual bool exists(const char* path); }; -SPIFFSImpl::SPIFFSImpl() -{ +SPIFFSImpl::SPIFFSImpl() { } -bool SPIFFSImpl::exists(const char* path) -{ - File f = open(path, "r",false); - return (f == true) && !f.isDirectory(); +bool SPIFFSImpl::exists(const char* path) { + File f = open(path, "r", false); + return (f == true) && !f.isDirectory(); } -SPIFFSFS::SPIFFSFS() : FS(FSImplPtr(new SPIFFSImpl())), partitionLabel_(NULL) -{ - +SPIFFSFS::SPIFFSFS() + : FS(FSImplPtr(new SPIFFSImpl())), partitionLabel_(NULL) { } -SPIFFSFS::~SPIFFSFS() -{ - if (partitionLabel_){ - free(partitionLabel_); - partitionLabel_ = NULL; - } +SPIFFSFS::~SPIFFSFS() { + if (partitionLabel_) { + free(partitionLabel_); + partitionLabel_ = NULL; + } } -bool SPIFFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles, const char * partitionLabel) -{ - if (partitionLabel_){ - free(partitionLabel_); - partitionLabel_ = NULL; - } +bool SPIFFSFS::begin(bool formatOnFail, const char* basePath, uint8_t maxOpenFiles, const char* partitionLabel) { + if (partitionLabel_) { + free(partitionLabel_); + partitionLabel_ = NULL; + } - if (partitionLabel){ - partitionLabel_ = strdup(partitionLabel); - } + if (partitionLabel) { + partitionLabel_ = strdup(partitionLabel); + } - if(esp_spiffs_mounted(partitionLabel_)){ - log_w("SPIFFS Already Mounted!"); - return true; - } - - esp_vfs_spiffs_conf_t conf = { - .base_path = basePath, - .partition_label = partitionLabel_, - .max_files = maxOpenFiles, - .format_if_mount_failed = false - }; - - esp_err_t err = esp_vfs_spiffs_register(&conf); - if(err == ESP_FAIL && formatOnFail){ - if(format()){ - err = esp_vfs_spiffs_register(&conf); - } - } - if(err != ESP_OK){ - log_e("Mounting SPIFFS failed! Error: %d", err); - return false; - } - _impl->mountpoint(basePath); + if (esp_spiffs_mounted(partitionLabel_)) { + log_w("SPIFFS Already Mounted!"); return true; + } + + esp_vfs_spiffs_conf_t conf = { + .base_path = basePath, + .partition_label = partitionLabel_, + .max_files = maxOpenFiles, + .format_if_mount_failed = false + }; + + esp_err_t err = esp_vfs_spiffs_register(&conf); + if (err == ESP_FAIL && formatOnFail) { + if (format()) { + err = esp_vfs_spiffs_register(&conf); + } + } + if (err != ESP_OK) { + log_e("Mounting SPIFFS failed! Error: %d", err); + return false; + } + _impl->mountpoint(basePath); + return true; } -void SPIFFSFS::end() -{ - if(esp_spiffs_mounted(partitionLabel_)){ - esp_err_t err = esp_vfs_spiffs_unregister(partitionLabel_); - if(err){ - log_e("Unmounting SPIFFS failed! Error: %d", err); - return; - } - _impl->mountpoint(NULL); +void SPIFFSFS::end() { + if (esp_spiffs_mounted(partitionLabel_)) { + esp_err_t err = esp_vfs_spiffs_unregister(partitionLabel_); + if (err) { + log_e("Unmounting SPIFFS failed! Error: %d", err); + return; } + _impl->mountpoint(NULL); + } } -bool SPIFFSFS::format() -{ - disableCore0WDT(); - esp_err_t err = esp_spiffs_format(partitionLabel_); - enableCore0WDT(); - if(err){ - log_e("Formatting SPIFFS failed! Error: %d", err); - return false; - } - return true; +bool SPIFFSFS::format() { + disableCore0WDT(); + esp_err_t err = esp_spiffs_format(partitionLabel_); + enableCore0WDT(); + if (err) { + log_e("Formatting SPIFFS failed! Error: %d", err); + return false; + } + return true; } -size_t SPIFFSFS::totalBytes() -{ - size_t total,used; - if(esp_spiffs_info(partitionLabel_, &total, &used)){ - return 0; - } - return total; +size_t SPIFFSFS::totalBytes() { + size_t total, used; + if (esp_spiffs_info(partitionLabel_, &total, &used)) { + return 0; + } + return total; } -size_t SPIFFSFS::usedBytes() -{ - size_t total,used; - if(esp_spiffs_info(partitionLabel_, &total, &used)){ - return 0; - } - return used; +size_t SPIFFSFS::usedBytes() { + size_t total, used; + if (esp_spiffs_info(partitionLabel_, &total, &used)) { + return 0; + } + return used; } SPIFFSFS SPIFFS; - diff --git a/libraries/SPIFFS/src/SPIFFS.h b/libraries/SPIFFS/src/SPIFFS.h index 4d7eb5da688..b330802e9f7 100644 --- a/libraries/SPIFFS/src/SPIFFS.h +++ b/libraries/SPIFFS/src/SPIFFS.h @@ -16,22 +16,20 @@ #include "FS.h" -namespace fs -{ +namespace fs { -class SPIFFSFS : public FS -{ +class SPIFFSFS : public FS { public: - SPIFFSFS(); - ~SPIFFSFS(); - bool begin(bool formatOnFail=false, const char * basePath="/spiffs", uint8_t maxOpenFiles=10, const char * partitionLabel=NULL); - bool format(); - size_t totalBytes(); - size_t usedBytes(); - void end(); + SPIFFSFS(); + ~SPIFFSFS(); + bool begin(bool formatOnFail = false, const char* basePath = "/spiffs", uint8_t maxOpenFiles = 10, const char* partitionLabel = NULL); + bool format(); + size_t totalBytes(); + size_t usedBytes(); + void end(); private: - char * partitionLabel_; + char* partitionLabel_; }; } diff --git a/libraries/SimpleBLE/examples/SimpleBleDevice/SimpleBleDevice.ino b/libraries/SimpleBLE/examples/SimpleBleDevice/SimpleBleDevice.ino index 3a9825a6b84..5d56cc03ba8 100644 --- a/libraries/SimpleBLE/examples/SimpleBleDevice/SimpleBleDevice.ino +++ b/libraries/SimpleBLE/examples/SimpleBleDevice/SimpleBleDevice.ino @@ -24,29 +24,29 @@ SimpleBLE ble; -void onButton(){ - String out = "BLE32 name: "; - out += String(millis() / 1000); - Serial.println(out); - ble.begin(out); +void onButton() { + String out = "BLE32 name: "; + out += String(millis() / 1000); + Serial.println(out); + ble.begin(out); } void setup() { - Serial.begin(115200); - Serial.setDebugOutput(true); - pinMode(0, INPUT_PULLUP); - Serial.print("ESP32 SDK: "); - Serial.println(ESP.getSdkVersion()); - ble.begin("ESP32 SimpleBLE"); - Serial.println("Press the button to change the device's name"); + Serial.begin(115200); + Serial.setDebugOutput(true); + pinMode(0, INPUT_PULLUP); + Serial.print("ESP32 SDK: "); + Serial.println(ESP.getSdkVersion()); + ble.begin("ESP32 SimpleBLE"); + Serial.println("Press the button to change the device's name"); } void loop() { - static uint8_t lastPinState = 1; - uint8_t pinState = digitalRead(0); - if(!pinState && lastPinState){ - onButton(); - } - lastPinState = pinState; - while(Serial.available()) Serial.write(Serial.read()); + static uint8_t lastPinState = 1; + uint8_t pinState = digitalRead(0); + if (!pinState && lastPinState) { + onButton(); + } + lastPinState = pinState; + while (Serial.available()) Serial.write(Serial.read()); } diff --git a/libraries/SimpleBLE/src/SimpleBLE.cpp b/libraries/SimpleBLE/src/SimpleBLE.cpp index d30a177fdf2..9ddc2a34218 100644 --- a/libraries/SimpleBLE/src/SimpleBLE.cpp +++ b/libraries/SimpleBLE/src/SimpleBLE.cpp @@ -26,79 +26,80 @@ #include "esp_bt_main.h" static esp_ble_adv_data_t _adv_config = { - .set_scan_rsp = false, - .include_name = true, - .include_txpower = true, - .min_interval = 512, - .max_interval = 1024, - .appearance = 0, - .manufacturer_len = 0, - .p_manufacturer_data = NULL, - .service_data_len = 0, - .p_service_data = NULL, - .service_uuid_len = 0, - .p_service_uuid = NULL, - .flag = (ESP_BLE_ADV_FLAG_GEN_DISC|ESP_BLE_ADV_FLAG_BREDR_NOT_SPT) + .set_scan_rsp = false, + .include_name = true, + .include_txpower = true, + .min_interval = 512, + .max_interval = 1024, + .appearance = 0, + .manufacturer_len = 0, + .p_manufacturer_data = NULL, + .service_data_len = 0, + .p_service_data = NULL, + .service_uuid_len = 0, + .p_service_uuid = NULL, + .flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT) }; static esp_ble_adv_params_t _adv_params = { - .adv_int_min = 512, - .adv_int_max = 1024, - .adv_type = ADV_TYPE_NONCONN_IND, - .own_addr_type = BLE_ADDR_TYPE_PUBLIC, - .peer_addr = {0x00, }, - .peer_addr_type = BLE_ADDR_TYPE_PUBLIC, - .channel_map = ADV_CHNL_ALL, - .adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, + .adv_int_min = 512, + .adv_int_max = 1024, + .adv_type = ADV_TYPE_NONCONN_IND, + .own_addr_type = BLE_ADDR_TYPE_PUBLIC, + .peer_addr = { + 0x00, + }, + .peer_addr_type = BLE_ADDR_TYPE_PUBLIC, + .channel_map = ADV_CHNL_ALL, + .adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, }; -static void _on_gap(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param){ - if(event == ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT){ - esp_ble_gap_start_advertising(&_adv_params); - } +static void _on_gap(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) { + if (event == ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT) { + esp_ble_gap_start_advertising(&_adv_params); + } } -static bool _init_gap(const char * name){ - if(!btStarted() && !btStart()){ - log_e("btStart failed"); - return false; - } - esp_bluedroid_status_t bt_state = esp_bluedroid_get_status(); - if(bt_state == ESP_BLUEDROID_STATUS_UNINITIALIZED){ - if (esp_bluedroid_init()) { - log_e("esp_bluedroid_init failed"); - return false; - } - } - if(bt_state != ESP_BLUEDROID_STATUS_ENABLED){ - if (esp_bluedroid_enable()) { - log_e("esp_bluedroid_enable failed"); - return false; - } - } - if(esp_ble_gap_set_device_name(name)){ - log_e("gap_set_device_name failed"); - return false; +static bool _init_gap(const char *name) { + if (!btStarted() && !btStart()) { + log_e("btStart failed"); + return false; + } + esp_bluedroid_status_t bt_state = esp_bluedroid_get_status(); + if (bt_state == ESP_BLUEDROID_STATUS_UNINITIALIZED) { + if (esp_bluedroid_init()) { + log_e("esp_bluedroid_init failed"); + return false; } - if(esp_ble_gap_config_adv_data(&_adv_config)){ - log_e("gap_config_adv_data failed"); - return false; + } + if (bt_state != ESP_BLUEDROID_STATUS_ENABLED) { + if (esp_bluedroid_enable()) { + log_e("esp_bluedroid_enable failed"); + return false; } - if(esp_ble_gap_register_callback(_on_gap)){ - log_e("gap_register_callback failed"); - return false; - } - return true; + } + if (esp_ble_gap_set_device_name(name)) { + log_e("gap_set_device_name failed"); + return false; + } + if (esp_ble_gap_config_adv_data(&_adv_config)) { + log_e("gap_config_adv_data failed"); + return false; + } + if (esp_ble_gap_register_callback(_on_gap)) { + log_e("gap_register_callback failed"); + return false; + } + return true; } -static bool _stop_gap() -{ - if(btStarted()){ - esp_bluedroid_disable(); - esp_bluedroid_deinit(); - btStop(); - } - return true; +static bool _stop_gap() { + if (btStarted()) { + esp_bluedroid_disable(); + esp_bluedroid_deinit(); + btStop(); + } + return true; } /* @@ -106,27 +107,23 @@ static bool _stop_gap() * * */ -SimpleBLE::SimpleBLE() -{ - local_name = "esp32"; +SimpleBLE::SimpleBLE() { + local_name = "esp32"; } -SimpleBLE::~SimpleBLE(void) -{ - _stop_gap(); +SimpleBLE::~SimpleBLE(void) { + _stop_gap(); } -bool SimpleBLE::begin(String localName) -{ - if(localName.length()){ - local_name = localName; - } - return _init_gap(local_name.c_str()); +bool SimpleBLE::begin(String localName) { + if (localName.length()) { + local_name = localName; + } + return _init_gap(local_name.c_str()); } -void SimpleBLE::end() -{ - _stop_gap(); +void SimpleBLE::end() { + _stop_gap(); } #endif diff --git a/libraries/SimpleBLE/src/SimpleBLE.h b/libraries/SimpleBLE/src/SimpleBLE.h index 6e7b702da5a..5ac958ff70e 100644 --- a/libraries/SimpleBLE/src/SimpleBLE.h +++ b/libraries/SimpleBLE/src/SimpleBLE.h @@ -32,12 +32,12 @@ struct ble_gap_adv_params_s; class SimpleBLE { - public: +public: - SimpleBLE(void); - ~SimpleBLE(void); + SimpleBLE(void); + ~SimpleBLE(void); - /** + /** * Start BLE Advertising * * @param[in] localName local name to advertise @@ -45,19 +45,18 @@ class SimpleBLE { * @return true on success * */ - bool begin(String localName=String()); + bool begin(String localName = String()); - /** + /** * Stop BLE Advertising * * @return none */ - void end(void); - - private: - String local_name; - private: + void end(void); +private: + String local_name; +private: }; #endif diff --git a/libraries/TFLiteMicro/examples/hello_world/hello_world.ino b/libraries/TFLiteMicro/examples/hello_world/hello_world.ino index 04fdd064a48..91a335c7b80 100644 --- a/libraries/TFLiteMicro/examples/hello_world/hello_world.ino +++ b/libraries/TFLiteMicro/examples/hello_world/hello_world.ino @@ -42,7 +42,8 @@ void setup() { model = tflite::GetModel(g_model); if (model->version() != TFLITE_SCHEMA_VERSION) { MicroPrintf("Model provided is schema version %d not equal to supported " - "version %d.", model->version(), TFLITE_SCHEMA_VERSION); + "version %d.", + model->version(), TFLITE_SCHEMA_VERSION); return; } @@ -54,7 +55,7 @@ void setup() { // Build an interpreter to run the model with. static tflite::MicroInterpreter static_interpreter( - model, resolver, tensor_arena, kTensorArenaSize); + model, resolver, tensor_arena, kTensorArenaSize); interpreter = &static_interpreter; // Allocate memory from the tensor_arena for the model's tensors. @@ -78,8 +79,7 @@ void loop() { // inference_count to the number of inferences per cycle to determine // our position within the range of possible x values the model was // trained on, and use this to calculate a value. - float position = static_cast(inference_count) / - static_cast(kInferencesPerCycle); + float position = static_cast(inference_count) / static_cast(kInferencesPerCycle); float x = position * kXrange; // Quantize the input from floating-point to integer @@ -91,7 +91,7 @@ void loop() { TfLiteStatus invoke_status = interpreter->Invoke(); if (invoke_status != kTfLiteOk) { MicroPrintf("Invoke failed on x: %f\n", - static_cast(x)); + static_cast(x)); return; } diff --git a/libraries/TFLiteMicro/examples/hello_world/model.cpp b/libraries/TFLiteMicro/examples/hello_world/model.cpp index f04a9f661c6..b72426c7089 100644 --- a/libraries/TFLiteMicro/examples/hello_world/model.cpp +++ b/libraries/TFLiteMicro/examples/hello_world/model.cpp @@ -26,212 +26,213 @@ limitations under the License. // Keep model aligned to 8 bytes to guarantee aligned 64-bit accesses. alignas(8) const unsigned char g_model[] = { - 0x1c, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x14, 0x00, 0x20, 0x00, - 0x1c, 0x00, 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, - 0x98, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00, - 0x2c, 0x03, 0x00, 0x00, 0x30, 0x09, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x60, 0xf7, 0xff, 0xff, - 0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, - 0x44, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x73, 0x65, 0x72, 0x76, - 0x65, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x73, 0x65, 0x72, 0x76, - 0x69, 0x6e, 0x67, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xbc, 0xff, 0xff, 0xff, - 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, - 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x34, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x76, 0xfd, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x5f, - 0x69, 0x6e, 0x70, 0x75, 0x74, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x13, 0x00, 0x00, 0x00, 0x6d, 0x69, 0x6e, 0x5f, 0x72, 0x75, 0x6e, 0x74, - 0x69, 0x6d, 0x65, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x50, 0x02, 0x00, 0x00, 0x48, 0x02, 0x00, 0x00, - 0x34, 0x02, 0x00, 0x00, 0xdc, 0x01, 0x00, 0x00, 0x8c, 0x01, 0x00, 0x00, - 0x6c, 0x01, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0xfa, 0xfd, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x31, 0x2e, 0x35, 0x2e, 0x30, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0xfd, 0xff, 0xff, - 0x88, 0xfd, 0xff, 0xff, 0x8c, 0xfd, 0xff, 0xff, 0x22, 0xfe, 0xff, 0xff, - 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x21, 0xa5, 0x8b, 0xca, - 0x5e, 0x1d, 0xce, 0x42, 0x9d, 0xce, 0x1f, 0xb0, 0xdf, 0x54, 0x2f, 0x81, - 0x3e, 0xfe, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, - 0xee, 0xfc, 0x00, 0xec, 0x05, 0x17, 0xef, 0xec, 0xe6, 0xf8, 0x03, 0x01, - 0x00, 0xfa, 0xf8, 0xf5, 0xdc, 0xeb, 0x27, 0x14, 0xf1, 0xde, 0xe2, 0xdb, - 0xf0, 0xde, 0x31, 0x06, 0x02, 0xe6, 0xee, 0xf9, 0x00, 0x16, 0x07, 0xe0, - 0xfe, 0xff, 0xe9, 0x06, 0xe7, 0xef, 0x81, 0x1b, 0x18, 0xea, 0xc9, 0x01, - 0x0f, 0x00, 0xda, 0xf7, 0x0e, 0xec, 0x13, 0x1f, 0x04, 0x13, 0xb4, 0xe6, - 0xfd, 0x06, 0xb9, 0xe0, 0x0d, 0xec, 0xf0, 0xde, 0xeb, 0xf7, 0x05, 0x26, - 0x1a, 0xe4, 0x6f, 0x1a, 0xea, 0x1e, 0x35, 0xdf, 0x1a, 0xf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00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x75, 0x1c, 0x11, 0xe1, 0x0c, 0x81, 0xa5, 0x42, - 0xfe, 0xd5, 0xd4, 0xb2, 0x61, 0x78, 0x19, 0xdf, 0x66, 0xff, 0xff, 0xff, - 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x77, 0x0b, 0x00, 0x00, 0x53, 0xf6, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x77, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xd3, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x72, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x07, 0x00, 0x00, - 0x67, 0xf5, 0xff, 0xff, 0x34, 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, - 0xb2, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xb5, 0x04, 0x00, 0x00, 0x78, 0x0a, 0x00, 0x00, - 0x2d, 0x06, 0x00, 0x00, 0x71, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x9a, 0x0a, 0x00, 0x00, 0xfe, 0xf7, 0xff, 0xff, 0x0e, 0x05, 0x00, 0x00, - 0xd4, 0x09, 0x00, 0x00, 0x47, 0xfe, 0xff, 0xff, 0xb6, 0x04, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xac, 0xf7, 0xff, 0xff, 0x4b, 0xf9, 0xff, 0xff, - 0x4a, 0x05, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x8c, 0xef, 0xff, 0xff, 0x84, 0xff, 0xff, 0xff, 0x88, 0xff, 0xff, 0xff, - 0x0f, 0x00, 0x00, 0x00, 0x4d, 0x4c, 0x49, 0x52, 0x20, 0x43, 0x6f, 0x6e, - 0x76, 0x65, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, - 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00, - 0xe0, 0x00, 0x00, 0x00, 0xe4, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x84, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x96, 0xff, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, - 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0xca, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, - 0xba, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, - 0x16, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x04, 0x00, - 0x0e, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, - 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, - 0x08, 0x00, 0x07, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x4c, 0x04, 0x00, 0x00, - 0xd0, 0x03, 0x00, 0x00, 0x68, 0x03, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, 0x24, 0x02, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, - 0x24, 0x01, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0xf0, 0xfb, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, - 0x54, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, - 0x6c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0x01, 0x00, 0x00, 0x00, 0xdc, 0xfb, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, - 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x4a, 0xce, 0x0a, 0x3c, 0x01, 0x00, 0x00, 0x00, - 0x34, 0x84, 0x85, 0x3f, 0x01, 0x00, 0x00, 0x00, 0xc5, 0x02, 0x8f, 0xbf, - 0x1e, 0x00, 0x00, 0x00, 0x53, 0x74, 0x61, 0x74, 0x65, 0x66, 0x75, 0x6c, - 0x50, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x65, 0x64, 0x43, - 0x61, 0x6c, 0x6c, 0x3a, 0x30, 0x5f, 0x69, 0x6e, 0x74, 0x38, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x80, 0xfc, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, - 0x54, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, - 0x64, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0x10, 0x00, 0x00, 0x00, 0x6c, 0xfc, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, - 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x01, 0x00, 0x00, 0x00, 0x93, 0xd0, 0xc0, 0x3b, 0x01, 0x00, 0x00, 0x00, - 0xc2, 0x0f, 0xc0, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x14, 0x00, 0x00, 0x00, 0x74, 0x66, 0x6c, 0x2e, 0x66, 0x75, 0x6c, 0x6c, - 0x79, 0x5f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x31, - 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x08, 0xfd, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, 0x64, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0xf4, 0xfc, 0xff, 0xff, - 0x10, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, - 0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xe0, 0xdb, 0x47, 0x3c, 0x01, 0x00, 0x00, 0x00, 0x04, 0x14, 0x47, 0x40, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, - 0x74, 0x66, 0x6c, 0x2e, 0x66, 0x75, 0x6c, 0x6c, 0x79, 0x5f, 0x63, 0x6f, - 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x02, 0xfe, 0xff, 0xff, - 0x14, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, 0x50, 0x00, 0x00, 0x00, 0x6c, 0xfd, 0xff, 0xff, - 0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xfb, 0x4b, 0x0b, 0x3c, - 0x01, 0x00, 0x00, 0x00, 0x40, 0x84, 0x4b, 0x3f, 0x01, 0x00, 0x00, 0x00, - 0x63, 0x35, 0x8a, 0xbf, 0x0d, 0x00, 0x00, 0x00, 0x73, 0x74, 0x64, 0x2e, - 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x32, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x72, 0xfe, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x50, 0x00, 0x00, 0x00, - 0xdc, 0xfd, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x60, 0x01, 0x4f, 0x3c, 0x01, 0x00, 0x00, 0x00, 0x47, 0x6d, 0xb3, 0x3f, - 0x01, 0x00, 0x00, 0x00, 0x5d, 0x63, 0xcd, 0xbf, 0x0d, 0x00, 0x00, 0x00, - 0x73, 0x74, 0x64, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, - 0x31, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0xe2, 0xfe, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, - 0x48, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, - 0x50, 0x00, 0x00, 0x00, 0x4c, 0xfe, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, - 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0xd5, 0x6b, 0x8a, 0x3b, 0x01, 0x00, 0x00, 0x00, - 0xab, 0x49, 0x01, 0x3f, 0x01, 0x00, 0x00, 0x00, 0xfd, 0x56, 0x09, 0xbf, - 0x0c, 0x00, 0x00, 0x00, 0x73, 0x74, 0x64, 0x2e, 0x63, 0x6f, 0x6e, 0x73, - 0x74, 0x61, 0x6e, 0x74, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x52, 0xff, 0xff, 0xff, - 0x14, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x02, 0x3c, 0x00, 0x00, 0x00, 0x44, 0xff, 0xff, 0xff, - 0x08, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x28, 0xb3, 0xd9, 0x38, 0x0c, 0x00, 0x00, 0x00, - 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x2f, 0x62, 0x69, 0x61, 0x73, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0xaa, 0xff, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x38, 0x00, 0x00, 0x00, - 0x9c, 0xff, 0xff, 0xff, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0xdd, 0x9b, 0x21, 0x39, 0x0c, 0x00, 0x00, 0x00, - 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x33, 0x2f, 0x62, 0x69, 0x61, 0x73, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, 0x13, 0x00, 0x0c, 0x00, - 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x48, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xf4, 0xd4, 0x51, 0x38, 0x0c, 0x00, 0x00, 0x00, 0x64, 0x65, 0x6e, 0x73, - 0x65, 0x5f, 0x34, 0x2f, 0x62, 0x69, 0x61, 0x73, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x1c, 0x00, - 0x18, 0x00, 0x17, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, - 0x2c, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, 0x84, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, - 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, - 0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x5d, 0x4f, 0xc9, 0x3c, 0x01, 0x00, 0x00, 0x00, 0x0e, 0x86, 0xc8, 0x40, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, - 0x73, 0x65, 0x72, 0x76, 0x69, 0x6e, 0x67, 0x5f, 0x64, 0x65, 0x66, 0x61, - 0x75, 0x6c, 0x74, 0x5f, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x5f, - 0x69, 0x6e, 0x70, 0x75, 0x74, 0x3a, 0x30, 0x5f, 0x69, 0x6e, 0x74, 0x38, - 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, - 0x24, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd8, 0xff, 0xff, 0xff, - 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, - 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, - 0x0c, 0x00, 0x10, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09}; + 0x1c, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x14, 0x00, 0x20, 0x00, + 0x1c, 0x00, 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x98, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00, + 0x2c, 0x03, 0x00, 0x00, 0x30, 0x09, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x60, 0xf7, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, + 0x44, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x73, 0x65, 0x72, 0x76, + 0x65, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x73, 0x65, 0x72, 0x76, + 0x69, 0x6e, 0x67, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xbc, 0xff, 0xff, 0xff, + 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x34, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x76, 0xfd, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x0d, 0x00, 0x00, 0x00, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x5f, + 0x69, 0x6e, 0x70, 0x75, 0x74, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x13, 0x00, 0x00, 0x00, 0x6d, 0x69, 0x6e, 0x5f, 0x72, 0x75, 0x6e, 0x74, + 0x69, 0x6d, 0x65, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x50, 0x02, 0x00, 0x00, 0x48, 0x02, 0x00, 0x00, + 0x34, 0x02, 0x00, 0x00, 0xdc, 0x01, 0x00, 0x00, 0x8c, 0x01, 0x00, 0x00, + 0x6c, 0x01, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xfa, 0xfd, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x31, 0x2e, 0x35, 0x2e, 0x30, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0xfd, 0xff, 0xff, + 0x88, 0xfd, 0xff, 0xff, 0x8c, 0xfd, 0xff, 0xff, 0x22, 0xfe, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x21, 0xa5, 0x8b, 0xca, + 0x5e, 0x1d, 0xce, 0x42, 0x9d, 0xce, 0x1f, 0xb0, 0xdf, 0x54, 0x2f, 0x81, + 0x3e, 0xfe, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0xee, 0xfc, 0x00, 0xec, 0x05, 0x17, 0xef, 0xec, 0xe6, 0xf8, 0x03, 0x01, + 0x00, 0xfa, 0xf8, 0xf5, 0xdc, 0xeb, 0x27, 0x14, 0xf1, 0xde, 0xe2, 0xdb, + 0xf0, 0xde, 0x31, 0x06, 0x02, 0xe6, 0xee, 0xf9, 0x00, 0x16, 0x07, 0xe0, + 0xfe, 0xff, 0xe9, 0x06, 0xe7, 0xef, 0x81, 0x1b, 0x18, 0xea, 0xc9, 0x01, + 0x0f, 0x00, 0xda, 0xf7, 0x0e, 0xec, 0x13, 0x1f, 0x04, 0x13, 0xb4, 0xe6, + 0xfd, 0x06, 0xb9, 0xe0, 0x0d, 0xec, 0xf0, 0xde, 0xeb, 0xf7, 0x05, 0x26, + 0x1a, 0xe4, 0x6f, 0x1a, 0xea, 0x1e, 0x35, 0xdf, 0x1a, 0xf3, 0xf1, 0x19, + 0x0f, 0x03, 0x1b, 0xe1, 0xde, 0x13, 0xf6, 0x19, 0xff, 0xf6, 0x1b, 0x18, + 0xf0, 0x1c, 0xda, 0x1b, 0x1b, 0x20, 0xe5, 0x1a, 0xf5, 0xff, 0x96, 0x0b, + 0x00, 0x01, 0xcd, 0xde, 0x0d, 0xf6, 0x16, 0xe3, 0xed, 0xfc, 0x0e, 0xe9, + 0xfa, 0xeb, 0x5c, 0xfc, 0x1d, 0x02, 0x5b, 0xe2, 0xe1, 0xf5, 0x15, 0xec, + 0xf4, 0x00, 0x13, 0x05, 0xec, 0x0c, 0x1d, 0x14, 0x0e, 0xe7, 0x0b, 0xf4, + 0x19, 0x00, 0xd7, 0x05, 0x27, 0x02, 0x15, 0xea, 0xea, 0x02, 0x9b, 0x00, + 0x0c, 0xfa, 0xe8, 0xea, 0xfd, 0x00, 0x14, 0xfd, 0x0b, 0x02, 0xef, 0xee, + 0x06, 0xee, 0x01, 0x0d, 0x06, 0xe6, 0xf7, 0x11, 0xf7, 0x09, 0xf8, 0xf1, + 0x21, 0xff, 0x0e, 0xf3, 0xec, 0x12, 0x26, 0x1d, 0xf2, 0xe9, 0x28, 0x18, + 0xe0, 0xfb, 0xf3, 0xf4, 0x05, 0x1d, 0x1d, 0xfb, 0xfd, 0x1e, 0xfc, 0x11, + 0xe8, 0x07, 0x09, 0x03, 0x12, 0xf2, 0x36, 0xfb, 0xdc, 0x1c, 0xf9, 0xef, + 0xf3, 0xe7, 0x6f, 0x0c, 0x1d, 0x00, 0x45, 0xfd, 0x0e, 0xf0, 0x0b, 0x19, + 0x1a, 0xfa, 0xe0, 0x19, 0x1f, 0x13, 0x36, 0x1c, 0x12, 0xeb, 0x3b, 0x0c, + 0xb4, 0xcb, 0xe6, 0x13, 0xfa, 0xeb, 0xf1, 0x06, 0x1c, 0xfa, 0x18, 0xe5, + 0xeb, 0xcb, 0x0c, 0xf4, 0x4a, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x75, 0x1c, 0x11, 0xe1, 0x0c, 0x81, 0xa5, 0x42, + 0xfe, 0xd5, 0xd4, 0xb2, 0x61, 0x78, 0x19, 0xdf, 0x66, 0xff, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x77, 0x0b, 0x00, 0x00, 0x53, 0xf6, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x77, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xd3, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x72, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x07, 0x00, 0x00, + 0x67, 0xf5, 0xff, 0xff, 0x34, 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0xb2, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xb5, 0x04, 0x00, 0x00, 0x78, 0x0a, 0x00, 0x00, + 0x2d, 0x06, 0x00, 0x00, 0x71, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x9a, 0x0a, 0x00, 0x00, 0xfe, 0xf7, 0xff, 0xff, 0x0e, 0x05, 0x00, 0x00, + 0xd4, 0x09, 0x00, 0x00, 0x47, 0xfe, 0xff, 0xff, 0xb6, 0x04, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xac, 0xf7, 0xff, 0xff, 0x4b, 0xf9, 0xff, 0xff, + 0x4a, 0x05, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x8c, 0xef, 0xff, 0xff, 0x84, 0xff, 0xff, 0xff, 0x88, 0xff, 0xff, 0xff, + 0x0f, 0x00, 0x00, 0x00, 0x4d, 0x4c, 0x49, 0x52, 0x20, 0x43, 0x6f, 0x6e, + 0x76, 0x65, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00, + 0xe0, 0x00, 0x00, 0x00, 0xe4, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x84, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x96, 0xff, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xca, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0xba, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x04, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, + 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, + 0x08, 0x00, 0x07, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x4c, 0x04, 0x00, 0x00, + 0xd0, 0x03, 0x00, 0x00, 0x68, 0x03, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, + 0x98, 0x02, 0x00, 0x00, 0x24, 0x02, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, + 0x24, 0x01, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xf0, 0xfb, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x54, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, + 0x6c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0xdc, 0xfb, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x4a, 0xce, 0x0a, 0x3c, 0x01, 0x00, 0x00, 0x00, + 0x34, 0x84, 0x85, 0x3f, 0x01, 0x00, 0x00, 0x00, 0xc5, 0x02, 0x8f, 0xbf, + 0x1e, 0x00, 0x00, 0x00, 0x53, 0x74, 0x61, 0x74, 0x65, 0x66, 0x75, 0x6c, + 0x50, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x65, 0x64, 0x43, + 0x61, 0x6c, 0x6c, 0x3a, 0x30, 0x5f, 0x69, 0x6e, 0x74, 0x38, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x80, 0xfc, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x54, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, + 0x64, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x6c, 0xfc, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x93, 0xd0, 0xc0, 0x3b, 0x01, 0x00, 0x00, 0x00, + 0xc2, 0x0f, 0xc0, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x74, 0x66, 0x6c, 0x2e, 0x66, 0x75, 0x6c, 0x6c, + 0x79, 0x5f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x31, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x08, 0xfd, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x09, 0x64, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0xf4, 0xfc, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xe0, 0xdb, 0x47, 0x3c, 0x01, 0x00, 0x00, 0x00, 0x04, 0x14, 0x47, 0x40, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, + 0x74, 0x66, 0x6c, 0x2e, 0x66, 0x75, 0x6c, 0x6c, 0x79, 0x5f, 0x63, 0x6f, + 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x02, 0xfe, 0xff, 0xff, + 0x14, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x09, 0x50, 0x00, 0x00, 0x00, 0x6c, 0xfd, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xfb, 0x4b, 0x0b, 0x3c, + 0x01, 0x00, 0x00, 0x00, 0x40, 0x84, 0x4b, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0x63, 0x35, 0x8a, 0xbf, 0x0d, 0x00, 0x00, 0x00, 0x73, 0x74, 0x64, 0x2e, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x32, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x72, 0xfe, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x50, 0x00, 0x00, 0x00, + 0xdc, 0xfd, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x60, 0x01, 0x4f, 0x3c, 0x01, 0x00, 0x00, 0x00, 0x47, 0x6d, 0xb3, 0x3f, + 0x01, 0x00, 0x00, 0x00, 0x5d, 0x63, 0xcd, 0xbf, 0x0d, 0x00, 0x00, 0x00, + 0x73, 0x74, 0x64, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, + 0x31, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0xe2, 0xfe, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, + 0x48, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, + 0x50, 0x00, 0x00, 0x00, 0x4c, 0xfe, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xd5, 0x6b, 0x8a, 0x3b, 0x01, 0x00, 0x00, 0x00, + 0xab, 0x49, 0x01, 0x3f, 0x01, 0x00, 0x00, 0x00, 0xfd, 0x56, 0x09, 0xbf, + 0x0c, 0x00, 0x00, 0x00, 0x73, 0x74, 0x64, 0x2e, 0x63, 0x6f, 0x6e, 0x73, + 0x74, 0x61, 0x6e, 0x74, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x52, 0xff, 0xff, 0xff, + 0x14, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x3c, 0x00, 0x00, 0x00, 0x44, 0xff, 0xff, 0xff, + 0x08, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x28, 0xb3, 0xd9, 0x38, 0x0c, 0x00, 0x00, 0x00, + 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x2f, 0x62, 0x69, 0x61, 0x73, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0xaa, 0xff, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x38, 0x00, 0x00, 0x00, + 0x9c, 0xff, 0xff, 0xff, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xdd, 0x9b, 0x21, 0x39, 0x0c, 0x00, 0x00, 0x00, + 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x33, 0x2f, 0x62, 0x69, 0x61, 0x73, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, 0x13, 0x00, 0x0c, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x48, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xf4, 0xd4, 0x51, 0x38, 0x0c, 0x00, 0x00, 0x00, 0x64, 0x65, 0x6e, 0x73, + 0x65, 0x5f, 0x34, 0x2f, 0x62, 0x69, 0x61, 0x73, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x1c, 0x00, + 0x18, 0x00, 0x17, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x2c, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x09, 0x84, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x5d, 0x4f, 0xc9, 0x3c, 0x01, 0x00, 0x00, 0x00, 0x0e, 0x86, 0xc8, 0x40, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x73, 0x65, 0x72, 0x76, 0x69, 0x6e, 0x67, 0x5f, 0x64, 0x65, 0x66, 0x61, + 0x75, 0x6c, 0x74, 0x5f, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x5f, + 0x69, 0x6e, 0x70, 0x75, 0x74, 0x3a, 0x30, 0x5f, 0x69, 0x6e, 0x74, 0x38, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd8, 0xff, 0xff, 0xff, + 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, + 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, + 0x0c, 0x00, 0x10, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x09 +}; const int g_model_len = 2488; diff --git a/libraries/TFLiteMicro/examples/micro_speech/audio_provider.cpp b/libraries/TFLiteMicro/examples/micro_speech/audio_provider.cpp index a1f8c75c4ee..261c95d82d4 100644 --- a/libraries/TFLiteMicro/examples/micro_speech/audio_provider.cpp +++ b/libraries/TFLiteMicro/examples/micro_speech/audio_provider.cpp @@ -35,9 +35,7 @@ limitations under the License. using namespace std; -#define NO_I2S_SUPPORT CONFIG_IDF_TARGET_ESP32C2 || \ - (CONFIG_IDF_TARGET_ESP32C3 \ - && (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 4, 0))) +#define NO_I2S_SUPPORT CONFIG_IDF_TARGET_ESP32C2 || (CONFIG_IDF_TARGET_ESP32C3 && (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 4, 0))) static const char* TAG = "TF_LITE_AUDIO_PROVIDER"; /* ringbuffer to hold the incoming audio data */ @@ -47,12 +45,11 @@ volatile int32_t g_latest_audio_timestamp = 0; * each time , storing old data in the histrory buffer , { * history_samples_to_keep = 10 * 16 } */ constexpr int32_t history_samples_to_keep = - ((kFeatureSliceDurationMs - kFeatureSliceStrideMs) * - (kAudioSampleFrequency / 1000)); + ((kFeatureSliceDurationMs - kFeatureSliceStrideMs) * (kAudioSampleFrequency / 1000)); /* new samples to get each time from ringbuffer, { new_samples_to_get = 20 * 16 * } */ constexpr int32_t new_samples_to_get = - (kFeatureSliceStrideMs * (kAudioSampleFrequency / 1000)); + (kFeatureSliceStrideMs * (kAudioSampleFrequency / 1000)); namespace { int16_t g_audio_output_buffer[kMaxAudioSampleSize]; @@ -64,28 +61,28 @@ const int32_t kAudioCaptureBufferSize = 80000; const int32_t i2s_bytes_to_read = 3200; #if NO_I2S_SUPPORT - // nothing to be done here +// nothing to be done here #else static void i2s_init(void) { // Start listening for audio: MONO @ 16KHz i2s_config_t i2s_config = { - .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_TX), - .sample_rate = 16000, - .bits_per_sample = (i2s_bits_per_sample_t)16, - .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, - .communication_format = I2S_COMM_FORMAT_I2S, - .intr_alloc_flags = 0, - .dma_buf_count = 3, - .dma_buf_len = 300, - .use_apll = false, - .tx_desc_auto_clear = false, - .fixed_mclk = -1, + .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_TX), + .sample_rate = 16000, + .bits_per_sample = (i2s_bits_per_sample_t)16, + .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, + .communication_format = I2S_COMM_FORMAT_I2S, + .intr_alloc_flags = 0, + .dma_buf_count = 3, + .dma_buf_len = 300, + .use_apll = false, + .tx_desc_auto_clear = false, + .fixed_mclk = -1, }; i2s_pin_config_t pin_config = { - .bck_io_num = 26, // IIS_SCLK - .ws_io_num = 32, // IIS_LCLK - .data_out_num = -1, // IIS_DSIN - .data_in_num = 33, // IIS_DOUT + .bck_io_num = 26, // IIS_SCLK + .ws_io_num = 32, // IIS_LCLK + .data_out_num = -1, // IIS_DSIN + .data_in_num = 33, // IIS_DOUT }; esp_err_t ret = 0; ret = i2s_driver_install((i2s_port_t)1, &i2s_config, 0, NULL); @@ -127,8 +124,7 @@ static void CaptureSamples(void* arg) { (uint8_t*)i2s_read_buffer, bytes_read, pdMS_TO_TICKS(100)); /* update the timestamp (in ms) to let the model know that new data has * arrived */ - g_latest_audio_timestamp = g_latest_audio_timestamp + - ((1000 * (bytes_written / 2)) / kAudioSampleFrequency); + g_latest_audio_timestamp = g_latest_audio_timestamp + ((1000 * (bytes_written / 2)) / kAudioSampleFrequency); if (bytes_written <= 0) { ESP_LOGE(TAG, "Could Not Write in Ring Buffer: %d ", bytes_written); } else if (bytes_written < bytes_read) { @@ -150,7 +146,7 @@ TfLiteStatus InitAudioRecording() { * in the ring buffer */ xTaskCreate(CaptureSamples, "CaptureSamples", 1024 * 32, NULL, 10, NULL); while (!g_latest_audio_timestamp) { - vTaskDelay(1); // one tick delay to avoid watchdog + vTaskDelay(1); // one tick delay to avoid watchdog } ESP_LOGI(TAG, "Audio Recording started"); return kTfLiteOk; @@ -172,9 +168,9 @@ TfLiteStatus GetAudioSamples(int start_ms, int duration_ms, /* copy 320 samples (640 bytes) from rb at ( int16_t*(g_audio_output_buffer) + * 160 ), first 160 samples (320 bytes) will be from history */ int bytes_read = - rb_read(g_audio_capture_buffer, - ((uint8_t*)(g_audio_output_buffer + history_samples_to_keep)), - new_samples_to_get * sizeof(int16_t), pdMS_TO_TICKS(100)); + rb_read(g_audio_capture_buffer, + ((uint8_t*)(g_audio_output_buffer + history_samples_to_keep)), + new_samples_to_get * sizeof(int16_t), pdMS_TO_TICKS(100)); if (bytes_read < 0) { ESP_LOGE(TAG, " Model Could not read data from Ring Buffer"); } else if (bytes_read < new_samples_to_get * sizeof(int16_t)) { @@ -182,7 +178,7 @@ TfLiteStatus GetAudioSamples(int start_ms, int duration_ms, rb_filled(g_audio_capture_buffer)); ESP_LOGD(TAG, " Partial Read of Data by Model "); ESP_LOGV(TAG, " Could only read %d bytes when required %d bytes ", - bytes_read, (int) (new_samples_to_get * sizeof(int16_t))); + bytes_read, (int)(new_samples_to_get * sizeof(int16_t))); } /* copy 320 bytes from output_buff into history */ @@ -195,4 +191,6 @@ TfLiteStatus GetAudioSamples(int start_ms, int duration_ms, return kTfLiteOk; } -int32_t LatestAudioTimestamp() { return g_latest_audio_timestamp; } +int32_t LatestAudioTimestamp() { + return g_latest_audio_timestamp; +} diff --git a/libraries/TFLiteMicro/examples/micro_speech/feature_provider.cpp b/libraries/TFLiteMicro/examples/micro_speech/feature_provider.cpp index 1e698f8befa..7685f1a30ea 100644 --- a/libraries/TFLiteMicro/examples/micro_speech/feature_provider.cpp +++ b/libraries/TFLiteMicro/examples/micro_speech/feature_provider.cpp @@ -21,9 +21,9 @@ limitations under the License. #include "tensorflow/lite/micro/micro_log.h" FeatureProvider::FeatureProvider(int feature_size, int8_t* feature_data) - : feature_size_(feature_size), - feature_data_(feature_data), - is_first_run_(true) { + : feature_size_(feature_size), + feature_data_(feature_data), + is_first_run_(true) { // Initialize the feature data to default values. for (int n = 0; n < feature_size_; ++n) { feature_data_[n] = 0; @@ -33,7 +33,7 @@ FeatureProvider::FeatureProvider(int feature_size, int8_t* feature_data) FeatureProvider::~FeatureProvider() {} TfLiteStatus FeatureProvider::PopulateFeatureData( - int32_t last_time_in_ms, int32_t time_in_ms, int* how_many_new_slices) { + int32_t last_time_in_ms, int32_t time_in_ms, int* how_many_new_slices) { if (feature_size_ != kFeatureElementCount) { MicroPrintf("Requested feature_data_ size %d doesn't match %d", feature_size_, kFeatureElementCount); @@ -77,10 +77,10 @@ TfLiteStatus FeatureProvider::PopulateFeatureData( if (slices_to_keep > 0) { for (int dest_slice = 0; dest_slice < slices_to_keep; ++dest_slice) { int8_t* dest_slice_data = - feature_data_ + (dest_slice * kFeatureSliceSize); + feature_data_ + (dest_slice * kFeatureSliceSize); const int src_slice = dest_slice + slices_to_drop; const int8_t* src_slice_data = - feature_data_ + (src_slice * kFeatureSliceSize); + feature_data_ + (src_slice * kFeatureSliceSize); for (int i = 0; i < kFeatureSliceSize; ++i) { dest_slice_data[i] = src_slice_data[i]; } @@ -107,8 +107,8 @@ TfLiteStatus FeatureProvider::PopulateFeatureData( int8_t* new_slice_data = feature_data_ + (new_slice * kFeatureSliceSize); size_t num_samples_read; TfLiteStatus generate_status = GenerateMicroFeatures( - audio_samples, audio_samples_size, kFeatureSliceSize, - new_slice_data, &num_samples_read); + audio_samples, audio_samples_size, kFeatureSliceSize, + new_slice_data, &num_samples_read); if (generate_status != kTfLiteOk) { return generate_status; } diff --git a/libraries/TFLiteMicro/examples/micro_speech/feature_provider.h b/libraries/TFLiteMicro/examples/micro_speech/feature_provider.h index 2a2ef8f4b31..d1eb7ea0b7f 100644 --- a/libraries/TFLiteMicro/examples/micro_speech/feature_provider.h +++ b/libraries/TFLiteMicro/examples/micro_speech/feature_provider.h @@ -26,7 +26,7 @@ limitations under the License. // on top of each other to form a spectrogram showing how those frequencies // changed over time. class FeatureProvider { - public: +public: // Create the provider, and bind it to an area of memory. This memory should // remain accessible for the lifetime of the provider object, since subsequent // calls will fill it with feature data. The provider does no memory @@ -39,7 +39,7 @@ class FeatureProvider { TfLiteStatus PopulateFeatureData(int32_t last_time_in_ms, int32_t time_in_ms, int* how_many_new_slices); - private: +private: int feature_size_; int8_t* feature_data_; // Make sure we don't try to use cached information if this is the first call diff --git a/libraries/TFLiteMicro/examples/micro_speech/micro_features_generator.cpp b/libraries/TFLiteMicro/examples/micro_speech/micro_features_generator.cpp index 4f3f06ce95f..6081dde7b80 100644 --- a/libraries/TFLiteMicro/examples/micro_speech/micro_features_generator.cpp +++ b/libraries/TFLiteMicro/examples/micro_speech/micro_features_generator.cpp @@ -79,7 +79,7 @@ TfLiteStatus GenerateMicroFeatures(const int16_t* input, int input_size, frontend_input = input + 160; } FrontendOutput frontend_output = FrontendProcessSamples( - &g_micro_features_state, frontend_input, input_size, num_samples_read); + &g_micro_features_state, frontend_input, input_size, num_samples_read); for (size_t i = 0; i < frontend_output.size; ++i) { // These scaling values are derived from those used in input_data.py in the @@ -100,8 +100,7 @@ TfLiteStatus GenerateMicroFeatures(const int16_t* input, int input_size, constexpr int32_t value_scale = 256; constexpr int32_t value_div = static_cast((25.6f * 26.0f) + 0.5f); int32_t value = - ((frontend_output.values[i] * value_scale) + (value_div / 2)) / - value_div; + ((frontend_output.values[i] * value_scale) + (value_div / 2)) / value_div; value -= 128; if (value < -128) { value = -128; diff --git a/libraries/TFLiteMicro/examples/micro_speech/micro_model_settings.cpp b/libraries/TFLiteMicro/examples/micro_speech/micro_model_settings.cpp index 8cc02f6543a..1e5f8fd7353 100644 --- a/libraries/TFLiteMicro/examples/micro_speech/micro_model_settings.cpp +++ b/libraries/TFLiteMicro/examples/micro_speech/micro_model_settings.cpp @@ -16,8 +16,8 @@ limitations under the License. #include "micro_model_settings.h" const char* kCategoryLabels[kCategoryCount] = { - "silence", - "unknown", - "yes", - "no", + "silence", + "unknown", + "yes", + "no", }; diff --git a/libraries/TFLiteMicro/examples/micro_speech/micro_speech.ino b/libraries/TFLiteMicro/examples/micro_speech/micro_speech.ino index 6bedf4b793a..99f26cca3fd 100644 --- a/libraries/TFLiteMicro/examples/micro_speech/micro_speech.ino +++ b/libraries/TFLiteMicro/examples/micro_speech/micro_speech.ino @@ -50,7 +50,8 @@ void setup() { model = tflite::GetModel(g_model); if (model->version() != TFLITE_SCHEMA_VERSION) { MicroPrintf("Model provided is schema version %d not equal to supported " - "version %d.", model->version(), TFLITE_SCHEMA_VERSION); + "version %d.", + model->version(), TFLITE_SCHEMA_VERSION); return; } @@ -78,7 +79,7 @@ void setup() { // Build an interpreter to run the model with. static tflite::MicroInterpreter static_interpreter( - model, micro_op_resolver, tensor_arena, kTensorArenaSize); + model, micro_op_resolver, tensor_arena, kTensorArenaSize); interpreter = &static_interpreter; // Allocate memory from the tensor_arena for the model's tensors. @@ -90,10 +91,7 @@ void setup() { // Get information about the memory area to use for the model's input. model_input = interpreter->input(0); - if ((model_input->dims->size != 2) || (model_input->dims->data[0] != 1) || - (model_input->dims->data[1] != - (kFeatureSliceCount * kFeatureSliceSize)) || - (model_input->type != kTfLiteInt8)) { + if ((model_input->dims->size != 2) || (model_input->dims->data[0] != 1) || (model_input->dims->data[1] != (kFeatureSliceCount * kFeatureSliceSize)) || (model_input->type != kTfLiteInt8)) { MicroPrintf("Bad input tensor parameters in model"); return; } @@ -118,9 +116,9 @@ void loop() { const int32_t current_time = LatestAudioTimestamp(); int how_many_new_slices = 0; TfLiteStatus feature_status = feature_provider->PopulateFeatureData( - previous_time, current_time, &how_many_new_slices); + previous_time, current_time, &how_many_new_slices); if (feature_status != kTfLiteOk) { - MicroPrintf( "Feature generation failed"); + MicroPrintf("Feature generation failed"); return; } previous_time = current_time; @@ -138,7 +136,7 @@ void loop() { // Run the model on the spectrogram input and make sure it succeeds. TfLiteStatus invoke_status = interpreter->Invoke(); if (invoke_status != kTfLiteOk) { - MicroPrintf( "Invoke failed"); + MicroPrintf("Invoke failed"); return; } @@ -149,7 +147,7 @@ void loop() { uint8_t score = 0; bool is_new_command = false; TfLiteStatus process_status = recognizer->ProcessLatestResults( - output, current_time, &found_command, &score, &is_new_command); + output, current_time, &found_command, &score, &is_new_command); if (process_status != kTfLiteOk) { MicroPrintf("RecognizeCommands::ProcessLatestResults() failed"); return; diff --git a/libraries/TFLiteMicro/examples/micro_speech/model.cpp b/libraries/TFLiteMicro/examples/micro_speech/model.cpp index 0490e7d9de8..b9e3456d54b 100644 --- a/libraries/TFLiteMicro/examples/micro_speech/model.cpp +++ b/libraries/TFLiteMicro/examples/micro_speech/model.cpp @@ -33,1564 +33,1565 @@ limitations under the License. #endif const unsigned char g_model[] DATA_ALIGN_ATTRIBUTE = { - 0x20, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x12, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, - 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x00, 0x12, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x94, 0x48, 0x00, 0x00, 0x34, 0x42, 0x00, 0x00, - 0x1c, 0x42, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, - 0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x0b, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x6d, 0x69, 0x6e, 0x5f, - 0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x76, 0x65, 0x72, 0x73, - 0x69, 0x6f, 0x6e, 0x00, 0x0c, 0x00, 0x00, 0x00, 0xd4, 0x41, 0x00, 0x00, - 0xb4, 0x41, 0x00, 0x00, 0x24, 0x03, 0x00, 0x00, 0xf4, 0x02, 0x00, 0x00, - 0xec, 0x02, 0x00, 0x00, 0xe4, 0x02, 0x00, 0x00, 0xc4, 0x02, 0x00, 0x00, - 0xbc, 0x02, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x16, 0xbd, 0xff, 0xff, - 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x31, 0x2e, 0x35, 0x2e, - 0x30, 0x00, 0x00, 0x00, 0x94, 0xba, 0xff, 0xff, 0x98, 0xba, 0xff, 0xff, - 0x32, 0xbd, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, - 0xfa, 0xee, 0x28, 0xc4, 0xee, 0xfe, 0xcf, 0x0f, 0x1e, 0xf7, 0x1f, 0x06, - 0x0d, 0xed, 0xe9, 0x83, 0x5c, 0xc9, 0x18, 0xe3, 0xf9, 0x14, 0x28, 0x2a, - 0x09, 0xf2, 0x18, 0x34, 0x62, 0xea, 0xef, 0xd6, 0x36, 0xb7, 0x1e, 0xf7, - 0x3b, 0x22, 0x28, 0x39, 0xc2, 0x9d, 0xf1, 0x07, 0x5e, 0x0b, 0x1e, 0x2c, - 0x07, 0xdd, 0xfd, 0xc3, 0xd8, 0x4a, 0xf3, 0x28, 0xa7, 0x16, 0xd5, 0xf1, - 0xc3, 0x05, 0xfd, 0x27, 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2a, 0x81, 0xd7, 0xcf, 0xc0, 0x04, 0xeb, 0x24, 0xcc, - 0xc9, 0x95, 0x33, 0x81, 0xf7, 0xad, 0x1c, 0x9c, 0xa4, 0xd6, 0xf9, 0xe6, - 0x3d, 0x84, 0x7f, 0xcc, 0xd4, 0xb0, 0xf4, 0xa2, 0xe9, 0x3c, 0x36, 0xee, - 0xd5, 0xcf, 0xcd, 0x2d, 0x28, 0xbd, 0xff, 0xff, 0xc2, 0xbf, 0xff, 0xff, - 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0x31, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x48, 0xbd, 0xff, 0xff, 0x4c, 0xbd, 0xff, 0xff, 0xe6, 0xbf, 0xff, 0xff, - 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x8a, 0xfe, 0xff, 0xff, - 0xa9, 0x00, 0x00, 0x00, 0xd0, 0xff, 0xff, 0xff, 0xd0, 0x00, 0x00, 0x00, - 0x52, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x4f, 0xfb, 0xff, 0xff, - 0x4a, 0xfd, 0xff, 0xff, 0x12, 0xc0, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, - 0x80, 0x3e, 0x00, 0x00, 0xff, 0xf9, 0xfd, 0x0a, 0x07, 0x08, 0x07, 0x03, - 0x07, 0xf2, 0xd1, 0x09, 0xf0, 0xe9, 0x28, 0x09, 0xdf, 0x05, 0xfa, 0xf0, - 0xe8, 0xe3, 0x13, 0x0e, 0x08, 0xef, 0xd3, 0xee, 0x0f, 0xe8, 0xeb, 0x14, - 0xf7, 0xed, 0xfd, 0x1f, 0xe8, 0xd5, 0xeb, 0xfc, 0x0e, 0xf4, 0xf7, 0x07, - 0x05, 0xea, 0xf6, 0x1f, 0xf8, 0xdb, 0xdc, 0x0b, 0x03, 0x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f8, 0xf5, 0x04, 0xea, 0x08, 0x12, 0x06, 0x0d, - 0x0f, 0x10, 0x40, 0x28, 0xc0, 0xfb, 0x3f, 0x08, 0x1d, 0x09, 0x1b, 0x3d, - 0xee, 0xf4, 0x29, 0x13, 0x20, 0xfc, 0x11, 0x4c, 0xdb, 0x02, 0x15, 0x05, - 0xec, 0xeb, 0x0a, 0x22, 0xe7, 0x00, 0x02, 0x01, 0xd4, 0xea, 0x0a, 0xf3, - 0xe3, 0xf8, 0xf5, 0xfa, 0x01, 0x0d, 0x19, 0x06, 0x24, 0x13, 0x02, 0xf5, - 0xf1, 0xf1, 0x1b, 0x0f, 0x19, 0x04, 0xe3, 0xf9, 0xe7, 0x02, 0x29, 0xfc, - 0x29, 0xec, 0xe9, 0x04, 0xdc, 0x22, 0x1d, 0xfd, 0x1f, 0x01, 0xec, 0xe8, - 0xf5, 0x14, 0x1b, 0x19, 0x06, 0x0e, 0x02, 0x0d, 0xf9, 0x06, 0xfc, 0x15, - 0x07, 0xfa, 0x0c, 0xe1, 0x18, 0x1a, 0xe8, 0x1b, 0xe9, 0xef, 0x0a, 0x18, - 0xfc, 0x05, 0xf9, 0x14, 0xdc, 0x04, 0x01, 0xff, 0x07, 0xfd, 0xf0, 0x2c, - 0xf2, 0xec, 0x0e, 0xe7, 0x1a, 0x05, 0xe8, 0x35, 0x13, 0x09, 0xf9, 0x07, - 0xfe, 0xfa, 0x0d, 0x40, 0x0c, 0xea, 0xf4, 0x04, 0x01, 0x11, 0xfc, 0x23, - 0xeb, 0xf4, 0xe9, 0x04, 0xeb, 0xe7, 0x07, 0x09, 0xfb, 0xf1, 0xf6, 0xfd, - 0x02, 0xfa, 0x02, 0xff, 0x00, 0xff, 0xf1, 0xf1, 0x1a, 0xe9, 0x10, 0xe3, - 0x0b, 0x0c, 0x08, 0x04, 0x1b, 0x0a, 0x2b, 0x10, 0xe1, 0x01, 0x1f, 0x06, - 0x04, 0xec, 0x19, 0x49, 0xee, 0xf8, 0x22, 0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x0b, - 0x36, 0x08, 0xe9, 0xf6, 0xe2, 0x13, 0x21, 0xfe, 0x12, 0xed, 0xdd, 0xfb, - 0xf8, 0x05, 0x0f, 0x03, 0x1c, 0x04, 0xfc, 0xf2, 0x23, 0x0e, 0x03, 0xfc, - 0xf9, 0x18, 0xf7, 0x01, 0x1b, 0x03, 0xf5, 0xfd, 0xde, 0xf3, 0x19, 0xfc, - 0x11, 0x02, 0xe7, 0x13, 0xde, 0xd8, 0xf2, 0x05, 0x28, 0x02, 0x02, 0x27, - 0x07, 0x08, 0xff, 0x07, 0x27, 0x0e, 0x19, 0x40, 0xfb, 0x02, 0x0c, 0xf6, - 0x0d, 0x07, 0x0f, 0x47, 0xf8, 0x05, 0x0e, 0xfd, 0x03, 0x1e, 0x07, 0x32, - 0xe7, 0xf6, 0x24, 0x01, 0x01, 0x02, 0x0a, 0xff, 0xf6, 0x26, 0x15, 0xf0, - 0x04, 0x13, 0x03, 0xfa, 0xfe, 0xf6, 0xf1, 0x09, 0x2a, 0xe6, 0xea, 0xf6, - 0x17, 0x13, 0xeb, 0xff, 0x15, 0xeb, 0x23, 0x06, 0xc8, 0xf6, 0x33, 0xeb, - 0xf4, 0xe7, 0x12, 0x2a, 0xe3, 0xe6, 0x32, 0xfa, 0x16, 0x15, 0x17, 0x40, - 0xf1, 0x08, 0x1a, 0xf3, 0xf6, 0x0c, 0x0c, 0x11, 0xd0, 0x22, 0x02, 0xee, - 0xea, 0xf4, 0xf8, 0xf9, 0x13, 0x10, 0x17, 0xf5, 0xf1, 0x0a, 0x0e, 0xfd, - 0x32, 0xda, 0xf1, 0xe2, 0xdb, 0xf2, 0x34, 0x1f, 0x53, 0xfc, 0xe4, 0xf2, - 0xf6, 0xf2, 0x1d, 0x04, 0x4a, 0xec, 0xee, 0x06, 0xdf, 0x01, 0x1a, 0x04, - 0x27, 0xfc, 0xe6, 0xfd, 0xd9, 0xfd, 0x0e, 0x00, 0x0c, 0x16, 0xf3, 0x03, - 0xf7, 0xfc, 0x0e, 0x0f, 0x09, 0x06, 0x06, 0x04, 0x08, 0x02, 0xed, 0xf5, - 0xe4, 0xe6, 0x07, 0x06, 0x03, 0x18, 0xea, 0x13, 0xe2, 0xfa, 0x10, 0xf2, - 0x02, 0xec, 0x03, 0x3c, 0xf6, 0xf6, 0x0a, 0x10, 0x09, 0xf8, 0x15, 0x24, - 0xfd, 0x0d, 0x09, 0x01, 0x00, 0xff, 0x00, 0x1a, 0xf0, 0xee, 0x08, 0x03, - 0x1d, 0x05, 0x16, 0x46, 0xe6, 0xf8, 0x08, 0x00, 0x09, 0x09, 0xff, 0x01, - 0xfc, 0x20, 0xfc, 0xec, 0x05, 0x1b, 0x03, 0xf1, 0x12, 0xe4, 0xfa, 0x24, - 0x1c, 0xf5, 0xf2, 0x05, 0x11, 0xe7, 0xfa, 0x02, 0x20, 0xea, 0x31, 0x10, - 0xcf, 0xd8, 0x33, 0xee, 0xff, 0x09, 0x20, 0x3f, 0xe2, 0x0a, 0x29, 0xee, - 0x3a, 0xf2, 0x1e, 0x39, 0x02, 0x1e, 0xfe, 0xf2, 0xef, 0xe2, 0x0d, 0x0f, - 0xf1, 0x19, 0x02, 0xe7, 0xec, 0xff, 0xfe, 0xe4, 0xfe, 0xfb, 0x02, 0xf6, - 0xf1, 0xf4, 0x07, 0x1a, 0x2a, 0xf9, 0x06, 0xf9, 0xda, 0xf4, 0x22, 0x02, - 0x4f, 0x0a, 0xf3, 0xfc, 0xf3, 0xf6, 0x25, 0x0a, 0x28, 0x01, 0xf7, 0x09, - 0xe6, 0x05, 0x28, 0xf7, 0x1e, 0xf2, 0xee, 0x13, 0xee, 0x05, 0x0f, 0x0a, - 0x09, 0xe8, 0xe8, 0x0e, 0x05, 0x12, 0x0f, 0x15, 0x02, 0xec, 0xf8, 0x02, - 0xf7, 0x05, 0xf8, 0xff, 0xdc, 0x00, 0x01, 0x00, 0x12, 0x17, 0xec, 0x19, - 0xfa, 0x09, 0xfa, 0xf3, 0x1d, 0x0b, 0x07, 0x25, 0xea, 0x0c, 0xf5, 0xfa, - 0x04, 0xf7, 0xfe, 0x33, 0xfe, 0x14, 0xef, 0x04, 0xf0, 0x00, 0x00, 0x3a, - 0xea, 0xfa, 0x10, 0x01, 0xe4, 0x00, 0xff, 0x23, 0xe9, 0x26, 0x15, 0x10, - 0x04, 0x14, 0x0d, 0x08, 0xf8, 0xfd, 0x10, 0xfb, 0x00, 0x21, 0x06, 0xfa, - 0x0f, 0x08, 0xf1, 0x09, 0x28, 0xf0, 0xd8, 0x0d, 0x08, 0x09, 0x02, 0xfb, - 0x12, 0x03, 0x0e, 0xfb, 0xce, 0xf0, 0x39, 0xe5, 0x09, 0xf6, 0x1f, 0x35, - 0xdd, 0x1c, 0x25, 0xef, 0x17, 0x0c, 0xf6, 0x3e, 0xf0, 0x21, 0x08, 0xff, - 0xd7, 0xfc, 0xfd, 0x1f, 0xe5, 0x18, 0x12, 0xe9, 0xf5, 0xe9, 0x12, 0xf6, - 0x02, 0x13, 0xf4, 0x0a, 0xfd, 0x03, 0x09, 0x08, 0x2f, 0x07, 0xee, 0xfd, - 0xd7, 0x00, 0x2b, 0x29, 0x3b, 0xdb, 0xde, 0xf1, 0xe1, 0xf7, 0x47, 0x12, - 0x35, 0x0c, 0xe4, 0x09, 0xef, 0x17, 0x2b, 0xea, 0x2d, 0xf8, 0xe8, 0x18, - 0xef, 0x03, 0x11, 0x0a, 0x10, 0xff, 0xe8, 0x07, 0x0c, 0x07, 0x03, 0x18, - 0x05, 0x08, 0xf8, 0xf8, 0x06, 0x18, 0xe9, 0xf9, 0xe0, 0x0f, 0x0d, 0x18, - 0x04, 0x01, 0xf0, 0x1c, 0xf6, 0x14, 0xfd, 0x12, 0x0c, 0x0c, 0x02, 0x34, - 0xf6, 0xe6, 0xfd, 0xf9, 0xf9, 0xfd, 0x00, 0x2a, 0xfc, 0xf9, 0xff, 0x0a, - 0xfe, 0x1b, 0xf5, 0x34, 0xdc, 0xf9, 0x15, 0x13, 0xe7, 0x1b, 0xf7, 0x25, - 0xfd, 0x09, 0x08, 0x0a, 0xf0, 0x17, 0x0f, 0x04, 0xf4, 0xe9, 0x06, 0x07, - 0xf5, 0x02, 0xfc, 0xf5, 0x09, 0xee, 0xf1, 0x07, 0x38, 0x03, 0x05, 0x0f, - 0x16, 0x0f, 0xed, 0xff, 0x21, 0xf8, 0x34, 0x07, 0xd1, 0xf9, 0x27, 0x00, - 0x0c, 0x21, 0x18, 0x42, 0xe6, 0x02, 0x1a, 0xf1, 0x2f, 0xf1, 0x0e, 0x3b, - 0xee, 0xf8, 0x08, 0xea, 0xfe, 0xf9, 0x03, 0x18, 0xf5, 0xf8, 0x0d, 0xeb, - 0x01, 0x10, 0x09, 0x02, 0x15, 0xfb, 0xf1, 0x0b, 0xf2, 0x06, 0x08, 0x09, - 0x2f, 0x19, 0x02, 0xfe, 0xe4, 0x06, 0x1f, 0x17, 0x49, 0xf2, 0xe2, 0x02, - 0xef, 0x04, 0x26, 0x16, 0x3f, 0x08, 0xf1, 0x0a, 0xfd, 0xf9, 0x28, 0x01, - 0x15, 0x0b, 0xf9, 0x10, 0xdc, 0x02, 0x20, 0xf7, 0x16, 0xe6, 0x09, 0x03, - 0xf1, 0xf5, 0x12, 0x1c, 0xfb, 0x2a, 0x08, 0xfa, 0x0a, 0x16, 0xf6, 0x15, - 0xf0, 0x06, 0x11, 0xfd, 0x0e, 0xf9, 0xf6, 0x12, 0xed, 0xf3, 0xfd, 0x1f, - 0x0b, 0xfa, 0x08, 0x30, 0xf8, 0xff, 0x0b, 0xeb, 0x10, 0xff, 0x07, 0x22, - 0x0d, 0x07, 0x09, 0x03, 0xf6, 0xf8, 0xfc, 0x26, 0xf8, 0xee, 0x11, 0x02, - 0x03, 0x0a, 0xef, 0x38, 0xfe, 0x13, 0x1b, 0x09, 0xfe, 0x06, 0x05, 0xf3, - 0x04, 0xdf, 0xfc, 0x00, 0xe7, 0x15, 0xec, 0xf1, 0xf8, 0xfc, 0xed, 0x05, - 0x0e, 0xf3, 0x15, 0x09, 0x01, 0x0d, 0xfd, 0x00, 0x24, 0xe2, 0x31, 0x13, - 0xd5, 0x1b, 0x2b, 0xe8, 0x03, 0x08, 0x1d, 0x33, 0xdc, 0xfd, 0x24, 0xe4, - 0x20, 0x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 0x0c, 0xf2, 0x0b, 0xff, 0xfe, - 0x01, 0xd8, 0xfa, 0x0e, 0xf5, 0x14, 0xf9, 0x01, 0x04, 0xf8, 0xfa, 0x02, - 0xe8, 0xf9, 0xf9, 0xea, 0xf1, 0x07, 0xff, 0x1e, 0x01, 0x0b, 0xf7, 0x0a, - 0xf7, 0x0c, 0xfd, 0xec, 0xf3, 0x05, 0xf8, 0xda, 0x0b, 0x15, 0xf6, 0xee, - 0xf9, 0x10, 0xfa, 0xfe, 0x08, 0xf0, 0xe6, 0xec, 0x05, 0xff, 0x15, 0x19, - 0x1f, 0x11, 0xfc, 0x09, 0x08, 0x01, 0x06, 0xfe, 0x04, 0x08, 0xfb, 0xfb, - 0x08, 0xf4, 0xf6, 0x28, 0x10, 0xf9, 0x28, 0x0b, 0xf8, 0x0d, 0x01, 0x00, - 0xff, 0x02, 0x05, 0x08, 0xea, 0xe9, 0xf4, 0xf6, 0x01, 0xea, 0xdf, 0x1f, - 0xfe, 0x0a, 0xf9, 0xf7, 0x0c, 0x1b, 0x06, 0xed, 0xf6, 0xf2, 0x03, 0x03, - 0xfd, 0x04, 0xf5, 0x10, 0x0a, 0x0b, 0xf4, 0xf8, 0xf1, 0xe7, 0x05, 0xfe, - 0xe7, 0x0b, 0xf1, 0xec, 0xf4, 0xec, 0x06, 0xee, 0xde, 0x05, 0x1b, 0xfe, - 0x13, 0xf3, 0xd9, 0xea, 0x04, 0x10, 0x05, 0xed, 0x15, 0x02, 0x0b, 0x10, - 0xfa, 0x02, 0x05, 0x0b, 0x02, 0x07, 0xfc, 0xf5, 0x15, 0x14, 0x05, 0xf7, - 0x0c, 0xfe, 0xf6, 0xf4, 0xfa, 0x06, 0xfc, 0x13, 0xdc, 0xe4, 0x09, 0xfa, - 0x02, 0x23, 0xec, 0x06, 0x11, 0x13, 0xf8, 0xfa, 0x27, 0x28, 0x0b, 0x23, - 0xec, 0xf1, 0x09, 0x17, 0x0f, 0x13, 0xff, 0xf2, 0xfc, 0x0a, 0xf5, 0x0d, - 0x03, 0x26, 0x01, 0x0f, 0xfe, 0xf1, 0xfb, 0xe6, 0xf0, 0x02, 0xf2, 0xff, - 0x02, 0x11, 0xff, 0xfd, 0x1c, 0x02, 0x0b, 0xf6, 0x14, 0x0c, 0x0b, 0x21, - 0x28, 0xf0, 0x11, 0x05, 0x06, 0xed, 0xf9, 0x0a, 0xf2, 0xef, 0xf8, 0xf1, - 0xfe, 0x0d, 0xf9, 0xf7, 0xea, 0x00, 0x08, 0xdb, 0x02, 0x0f, 0xfe, 0x04, - 0xef, 0x20, 0x16, 0x01, 0xe8, 0xed, 0xe4, 0x22, 0xf6, 0x19, 0x00, 0x04, - 0x01, 0x13, 0xeb, 0x0d, 0xec, 0x01, 0x08, 0x05, 0x0c, 0x0e, 0xfe, 0x02, - 0x12, 0xf7, 0x27, 0xf9, 0xfd, 0x18, 0xfe, 0x24, 0xf7, 0x13, 0xed, 0x1e, - 0x09, 0xff, 0xd8, 0xf4, 0x12, 0xf8, 0x04, 0x0c, 0x1c, 0x11, 0xfd, 0x17, - 0x1d, 0x01, 0x13, 0xee, 0x11, 0xf3, 0xf8, 0x06, 0xf6, 0x16, 0xfe, 0x15, - 0x16, 0xdc, 0x1f, 0x00, 0x25, 0xee, 0xff, 0xf7, 0xf6, 0x02, 0xdd, 0x15, - 0xf1, 0x14, 0x08, 0xe8, 0xe5, 0x21, 0xea, 0xf0, 0x1a, 0x07, 0xea, 0x08, - 0xea, 0xe4, 0x1e, 0x00, 0x13, 0x17, 0xec, 0x11, 0xd6, 0x11, 0x18, 0x17, - 0x04, 0x15, 0x03, 0x3a, 0xd6, 0x02, 0x07, 0x04, 0xe6, 0xe5, 0xfe, 0x0e, - 0xff, 0xed, 0xfc, 0xfb, 0xff, 0x1c, 0x06, 0x0a, 0xfb, 0xf9, 0xea, 0x1a, - 0x21, 0xf5, 0x04, 0x06, 0x0a, 0xe3, 0x16, 0xea, 0x04, 0xe2, 0xf9, 0xf9, - 0xe6, 0xfb, 0x0f, 0xfc, 0x06, 0xfb, 0x10, 0x07, 0x07, 0x13, 0x07, 0xfc, - 0x16, 0xef, 0x07, 0xdc, 0x12, 0x1f, 0x08, 0xf4, 0xe9, 0x14, 0x06, 0xf7, - 0xf1, 0x0c, 0x01, 0x0c, 0xe6, 0x04, 0xf3, 0xf2, 0xe5, 0xf3, 0xef, 0x1d, - 0xf6, 0x20, 0x07, 0xfe, 0xf4, 0x05, 0xee, 0x10, 0xfd, 0x0e, 0x0b, 0x02, - 0x0d, 0xd8, 0x07, 0xfb, 0x26, 0x0a, 0x1c, 0x21, 0x06, 0x1f, 0xf4, 0x06, - 0x37, 0x18, 0xfa, 0x16, 0x1e, 0x24, 0xfb, 0xf0, 0x12, 0xf9, 0x02, 0x09, - 0x17, 0x16, 0xf3, 0xf9, 0x17, 0xf2, 0x02, 0x0a, 0x2d, 0xe7, 0xe3, 0x25, - 0xf0, 0xf9, 0x0f, 0xdd, 0x15, 0xe6, 0x04, 0xfc, 0xf1, 0x17, 0x0a, 0xea, - 0x24, 0x07, 0xf1, 0x11, 0x13, 0x29, 0xf4, 0xc5, 0xfb, 0x07, 0xef, 0x13, - 0x0b, 0xe1, 0xf1, 0xeb, 0xf8, 0x1b, 0x09, 0x08, 0x1f, 0x15, 0xf2, 0x05, - 0x02, 0xdd, 0x09, 0x0f, 0x16, 0x10, 0x01, 0x30, 0xf2, 0xe0, 0x27, 0xfe, - 0xf1, 0x0e, 0x0e, 0x07, 0xe6, 0x07, 0x0b, 0x18, 0xfe, 0x0f, 0x01, 0x07, - 0xf4, 0x07, 0x10, 0xe7, 0xfb, 0xf3, 0xf7, 0x0b, 0xf9, 0x15, 0x18, 0x25, - 0x0c, 0x14, 0x02, 0x08, 0x0a, 0x0f, 0x10, 0xec, 0xee, 0x1a, 0x03, 0x14, - 0x0f, 0xfa, 0x25, 0xff, 0x18, 0x0d, 0x0b, 0xea, 0x1f, 0x28, 0x10, 0x0c, - 0xe7, 0xee, 0xf7, 0xfa, 0x03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0x00, 0xeb, 0xe7, 0x1b, 0xfc, 0x09, 0x00, 0xf2, 0x04, - 0xf9, 0xe5, 0x1a, 0x0e, 0x08, 0x12, 0xf8, 0xfe, 0x09, 0x0f, 0x0d, 0xea, - 0x03, 0xe1, 0xfe, 0xf2, 0xec, 0x0d, 0x02, 0xdb, 0x04, 0x1d, 0xd4, 0x01, - 0xca, 0x13, 0x29, 0xca, 0x28, 0x04, 0xe2, 0xf1, 0xdb, 0x0b, 0x2c, 0xcd, - 0x44, 0x00, 0xe7, 0xf4, 0xd0, 0x12, 0x15, 0xff, 0x42, 0x11, 0x05, 0xfd, - 0xd9, 0x11, 0x1c, 0xf4, 0x15, 0xec, 0xf2, 0x24, 0xd6, 0x1d, 0xec, 0xda, - 0xf5, 0xec, 0xe5, 0x22, 0xf2, 0x0b, 0xbd, 0xd0, 0xeb, 0x05, 0x07, 0x1b, - 0x01, 0xed, 0xf5, 0x02, 0xcf, 0x08, 0x15, 0xfd, 0x1c, 0xe5, 0x04, 0x19, - 0xc7, 0x25, 0x22, 0xf3, 0xde, 0xfb, 0xfb, 0x20, 0xf6, 0xeb, 0x25, 0xfe, - 0xf5, 0x08, 0xf5, 0x17, 0x0e, 0x04, 0x1c, 0xf9, 0xee, 0xec, 0xe1, 0x06, - 0x12, 0xff, 0x2a, 0x13, 0xed, 0xfe, 0x05, 0x18, 0x25, 0x20, 0x09, 0x13, - 0xea, 0xd7, 0x05, 0x06, 0x33, 0x25, 0xff, 0x0a, 0xf0, 0xea, 0x17, 0xe1, - 0x30, 0xfa, 0x0d, 0x0a, 0x04, 0x00, 0x0e, 0xe9, 0x16, 0x20, 0x0d, 0x02, - 0xe8, 0xed, 0x07, 0xe8, 0x3c, 0xf1, 0xd9, 0xfa, 0xe1, 0xed, 0x18, 0xfc, - 0xf0, 0x09, 0xe3, 0x05, 0xfe, 0xd1, 0x0b, 0x0e, 0xf5, 0x25, 0xfd, 0xfb, - 0x30, 0x1e, 0x08, 0xfc, 0x0c, 0x21, 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 0x0d, 0xf7, 0xf1, 0xf7, 0xe6, 0xfb, - 0x04, 0x04, 0x07, 0x02, 0x04, 0x09, 0xf5, 0xfc, 0x5f, 0xd6, 0xe7, 0x2a, - 0x23, 0xf4, 0x1b, 0x06, 0x01, 0xea, 0xe7, 0x05, 0x25, 0xe3, 0x25, 0x07, - 0xea, 0xfb, 0xfb, 0x09, 0x25, 0xde, 0x37, 0x04, 0x07, 0xe5, 0xff, 0x14, - 0x2f, 0x0a, 0x30, 0x23, 0x04, 0xf0, 0x23, 0xfe, 0x1c, 0xd2, 0x2b, 0x55, - 0x01, 0xe5, 0x26, 0xfe, 0x14, 0xed, 0x24, 0x46, 0xe6, 0xee, 0x0f, 0xfd, - 0xed, 0xef, 0x0e, 0x1e, 0x05, 0x0a, 0x12, 0xff, 0xe4, 0xf5, 0x0c, 0xed, - 0xfd, 0xea, 0x0d, 0x13, 0x1a, 0xe5, 0xfc, 0xc2, 0xef, 0x0a, 0xe2, 0x0f, - 0xfe, 0xff, 0x0c, 0xf0, 0xff, 0xdf, 0xea, 0x00, 0xf6, 0xe1, 0x04, 0xd8, - 0x26, 0x20, 0xdc, 0xf4, 0x19, 0x06, 0xe8, 0xd2, 0x10, 0x04, 0xf1, 0x02, - 0x0c, 0x06, 0xf0, 0xf0, 0x04, 0x1f, 0xf4, 0xf5, 0xed, 0xf1, 0xfa, 0xf1, - 0x04, 0x02, 0xf8, 0xfb, 0x04, 0xf1, 0xe5, 0xe4, 0x0a, 0xf0, 0xfe, 0xef, - 0x1c, 0xe3, 0xeb, 0xf3, 0x00, 0x17, 0x01, 0x13, 0x19, 0xda, 0xf8, 0x06, - 0xde, 0x11, 0xea, 0xf7, 0xf4, 0xef, 0x03, 0x04, 0x0b, 0xe8, 0x08, 0x0e, - 0xe2, 0xee, 0xde, 0x06, 0x0e, 0x29, 0xfb, 0xfa, 0x00, 0x02, 0xec, 0x1b, - 0x52, 0xff, 0xde, 0x3a, 0x2f, 0x13, 0x30, 0xe9, 0xff, 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0b, - 0x08, 0xfe, 0x13, 0x1a, 0xf4, 0xf8, 0xfe, 0x08, 0xfc, 0xe9, 0xfe, 0xeb, - 0xe6, 0xf6, 0x02, 0x18, 0x02, 0xe8, 0xfb, 0xf3, 0x01, 0x08, 0xd7, 0x13, - 0x04, 0xe6, 0x02, 0xe6, 0xd7, 0x01, 0xd4, 0xf0, 0x0e, 0x05, 0x18, 0xe5, - 0x08, 0xe5, 0xd2, 0x16, 0x12, 0xfe, 0x0e, 0xd3, 0xfc, 0x1f, 0xe9, 0xf8, - 0x11, 0x06, 0xf3, 0xd5, 0xf8, 0xff, 0xf0, 0x04, 0x0a, 0xd9, 0xf8, 0xfd, - 0xf5, 0x12, 0xff, 0x06, 0x1b, 0xe6, 0xfe, 0xfe, 0xde, 0xee, 0xf6, 0x18, - 0xf1, 0xf8, 0x06, 0xf3, 0x02, 0xea, 0x04, 0x14, 0xfc, 0xee, 0xe6, 0x09, - 0xf9, 0xee, 0xe3, 0xe7, 0xfc, 0xd9, 0xef, 0xfc, 0x0a, 0x0c, 0x03, 0xf6, - 0xe2, 0x11, 0x0f, 0x19, 0x18, 0x10, 0xef, 0xe5, 0x22, 0xf5, 0xe5, 0xe9, - 0x4b, 0xf7, 0xdb, 0x0c, 0x4f, 0xde, 0x22, 0x16, 0x09, 0x16, 0xd1, 0xf8, - 0x19, 0xe0, 0x24, 0xfe, 0xb8, 0xfb, 0xe5, 0x12, 0x1c, 0xe3, 0x22, 0x09, - 0x05, 0x29, 0xf7, 0x10, 0x31, 0xe1, 0x33, 0x3f, 0xfd, 0xed, 0x04, 0x03, - 0x2e, 0xed, 0x30, 0x36, 0xee, 0x16, 0x2f, 0xf5, 0x1b, 0xdc, 0x3a, 0x56, - 0xe5, 0xef, 0x26, 0xff, 0x03, 0xd7, 0x31, 0x16, 0xef, 0xf1, 0x08, 0x13, - 0x01, 0x02, 0x03, 0xf1, 0xf2, 0x08, 0xff, 0x05, 0x12, 0xf2, 0xee, 0xda, - 0xed, 0xec,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0xdc, 0x20, 0x2e, 0xe0, 0xf5, 0x30, 0xe4, - 0x09, 0xf8, 0x3c, 0x45, 0xd3, 0x08, 0x23, 0xd8, 0x09, 0xe4, 0x35, 0x30, - 0xe4, 0xfe, 0x07, 0xf6, 0x05, 0x01, 0x05, 0xff, 0xf6, 0x0d, 0x02, 0xfd, - 0x03, 0x05, 0x0d, 0x00, 0xf5, 0xd6, 0xcf, 0x19, 0x06, 0xee, 0x0d, 0xf2, - 0x01, 0x18, 0xef, 0x12, 0x04, 0x02, 0x21, 0xd9, 0x02, 0x0d, 0xeb, 0xe9, - 0x13, 0x08, 0x15, 0xf0, 0xee, 0x03, 0xec, 0x06, 0x17, 0xed, 0x00, 0x1a, - 0xee, 0xf2, 0xfc, 0x09, 0xec, 0xf8, 0xf8, 0x18, 0xf4, 0x13, 0x04, 0xf6, - 0x02, 0xf0, 0xfc, 0xfe, 0xe3, 0x01, 0x0a, 0x1c, 0x1b, 0xec, 0x0e, 0x01, - 0xfb, 0x08, 0x11, 0xf5, 0x00, 0x14, 0xe6, 0x12, 0x07, 0xf4, 0x15, 0x07, - 0xfc, 0xfb, 0xf5, 0xf1, 0x01, 0x21, 0x01, 0xe9, 0xe8, 0xef, 0xdb, 0xdf, - 0x1f, 0x0a, 0xdd, 0xd1, 0x16, 0x04, 0xfd, 0xe1, 0x24, 0xf0, 0xec, 0xf4, - 0x38, 0xe1, 0x16, 0xfd, 0xe0, 0xec, 0xe7, 0x0c, 0x2a, 0x04, 0x0c, 0x17, - 0xdc, 0xe8, 0xf2, 0x03, 0xec, 0xfd, 0x19, 0xfe, 0xf3, 0xf0, 0xf3, 0xfb, - 0x18, 0xdf, 0x1c, 0x00, 0x09, 0xf4, 0x18, 0x0b, 0x1f, 0xf6, 0x34, 0x22, - 0xf4, 0x22, 0x45, 0xeb, 0x23, 0xcf, 0x32, 0x34, 0xf2, 0xf9, 0x29, 0xd4, - 0xf7, 0x0b, 0x38, 0x2a, 0x09, 0xe6, 0x05, 0x01, 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, 0xf2, - 0x0b, 0x08, 0x38, 0x01, 0x07, 0xfd, 0xd8, 0x06, 0xd9, 0xf0, 0x16, 0x1f, - 0xff, 0xf7, 0xe0, 0xd8, 0xf3, 0xf7, 0x12, 0x08, 0x0e, 0x05, 0xf6, 0x03, - 0xef, 0x1b, 0x12, 0xf4, 0xe8, 0x0f, 0x02, 0xfd, 0xf2, 0x16, 0x26, 0x22, - 0xe0, 0x07, 0xf7, 0xe6, 0xeb, 0x16, 0x22, 0x1a, 0x0b, 0x01, 0xf5, 0xea, - 0xd2, 0x22, 0x0f, 0x13, 0x15, 0x08, 0xf0, 0xfb, 0xed, 0x11, 0xf3, 0xe9, - 0xff, 0xde, 0x0a, 0x18, 0x0f, 0x02, 0xfb, 0xf9, 0xfb, 0xe8, 0x12, 0x18, - 0x01, 0xf4, 0xf6, 0xf8, 0xf0, 0x1f, 0x24, 0x15, 0xf5, 0x00, 0x1c, 0xf9, - 0x01, 0x0a, 0x11, 0xd5, 0x01, 0x12, 0x02, 0xec, 0xfd, 0x07, 0xf2, 0xea, - 0xf9, 0xff, 0xf7, 0xfb, 0x15, 0xec, 0xe5, 0x01, 0xeb, 0x05, 0xf9, 0x10, - 0xfe, 0x28, 0xe5, 0x0a, 0xeb, 0x1b, 0x0e, 0xf9, 0xde, 0x02, 0x15, 0x0a, - 0xff, 0xfe, 0x11, 0x24, 0x03, 0xf8, 0x00, 0x08, 0xfd, 0x0e, 0xeb, 0xf3, - 0xf6, 0xf7, 0x14, 0x0e, 0xfc, 0xf5, 0xde, 0xf5, 0x9e, 0xfe, 0xff, 0xff, - 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xab, 0x01, 0x00, 0x00, - 0xfa, 0xfd, 0xff, 0xff, 0xa2, 0xff, 0xff, 0xff, 0xba, 0x00, 0x00, 0x00, - 0x24, 0xfc, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x54, 0x4f, 0x43, 0x4f, - 0x20, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x24, 0xfb, 0xff, 0xff, - 0x68, 0x01, 0x00, 0x00, 0x5c, 0x01, 0x00, 0x00, 0x50, 0x01, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xf4, 0x00, 0x00, 0x00, - 0x90, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0xce, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0x03, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x1a, 0xff, 0xff, 0xff, 0x00, 0x00, 0x80, 0x3f, 0x01, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, - 0x07, 0x00, 0x14, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, - 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0xc4, 0xfc, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, - 0x16, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x10, 0x00, - 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x38, 0x00, 0x00, 0x00, - 0x2c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, - 0x14, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x07, 0x00, - 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, - 0x1a, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x07, 0x00, 0x14, 0x00, - 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x02, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0x31, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x00, 0x00, 0x34, 0x04, 0x00, 0x00, 0xcc, 0x03, 0x00, 0x00, - 0x4c, 0x03, 0x00, 0x00, 0xdc, 0x02, 0x00, 0x00, 0x60, 0x02, 0x00, 0x00, - 0x20, 0x02, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x44, 0x01, 0x00, 0x00, - 0x70, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0xfc, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x09, 0x44, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, - 0x28, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xf4, 0xfb, 0xff, 0xff, - 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3b, 0x0e, 0x00, 0x00, 0x00, 0x6c, 0x61, 0x62, 0x65, - 0x6c, 0x73, 0x5f, 0x73, 0x6f, 0x66, 0x74, 0x6d, 0x61, 0x78, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x0e, 0x00, 0x1a, 0x00, 0x08, 0x00, 0x07, 0x00, 0x0c, 0x00, - 0x10, 0x00, 0x14, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, - 0xb4, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, - 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, - 0x12, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x11, 0x1e, 0x23, 0x3a, 0x9e, 0xa1, 0x15, 0x39, - 0x23, 0x69, 0x45, 0x3a, 0x09, 0xe4, 0xe4, 0x39, 0x65, 0xd7, 0x13, 0x3a, - 0xe0, 0xb2, 0xfd, 0x39, 0x1b, 0xc1, 0x53, 0x3a, 0xc2, 0x50, 0x2d, 0x3a, - 0x12, 0x00, 0x00, 0x00, 0x66, 0x69, 0x72, 0x73, 0x74, 0x5f, 0x77, 0x65, - 0x69, 0x67, 0x68, 0x74, 0x73, 0x2f, 0x72, 0x65, 0x61, 0x64, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3a, 0xfd, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x09, 0x54, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x28, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x2c, 0xfd, 0xff, 0xff, - 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xb5, 0xfa, 0xfa, 0x39, 0x1f, 0x00, 0x00, 0x00, 0x66, 0x69, 0x6e, 0x61, - 0x6c, 0x5f, 0x66, 0x63, 0x5f, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x73, - 0x2f, 0x72, 0x65, 0x61, 0x64, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, - 0x6f, 0x73, 0x65, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0xa0, 0x0f, 0x00, 0x00, 0xa2, 0xfd, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, - 0x58, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x74, 0xfe, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, - 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xf2, 0xdd, 0xbb, 0x3d, - 0x01, 0x00, 0x00, 0x00, 0x32, 0xa3, 0x25, 0x41, 0x01, 0x00, 0x00, 0x00, - 0xf6, 0xa0, 0x50, 0xc1, 0x05, 0x00, 0x00, 0x00, 0x61, 0x64, 0x64, 0x5f, - 0x31, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x0e, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, - 0x2c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, 0x52, 0x65, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, - 0x32, 0x2f, 0x73, 0x68, 0x61, 0x70, 0x65, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x4a, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, - 0x5c, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x1c, 0xff, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, - 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x50, 0x50, 0xd0, 0x3d, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0xcf, 0x41, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x52, 0x65, 0x73, 0x68, - 0x61, 0x70, 0x65, 0x5f, 0x32, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0xc2, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, - 0x58, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x94, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x01, 0x00, 0x00, 0x00, 0x50, 0x50, 0xd0, 0x3d, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x80, 0xcf, 0x41, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x52, 0x65, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, - 0x31, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xa8, 0x07, 0x00, 0x00, 0x2e, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, - 0x60, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, 0x04, 0x00, 0x08, 0x00, - 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x01, 0x00, 0x00, 0x00, 0x3a, 0x6a, 0xac, 0x3d, 0x01, 0x00, 0x00, 0x00, - 0xd0, 0xbd, 0xab, 0x41, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x52, 0x65, 0x6c, 0x75, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, - 0x14, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xaa, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x02, 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x2c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x9c, 0xff, 0xff, 0xff, - 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x96, 0x08, 0x29, 0x38, 0x0b, 0x00, 0x00, 0x00, - 0x4d, 0x61, 0x74, 0x4d, 0x75, 0x6c, 0x5f, 0x62, 0x69, 0x61, 0x73, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, - 0x18, 0x00, 0x08, 0x00, 0x07, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, - 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xa0, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x9a, 0xbb, 0x84, 0x38, 0x83, 0x84, 0x73, 0x37, 0x5b, 0xa3, 0xa0, 0x38, - 0x16, 0x41, 0x3a, 0x38, 0xc7, 0x9a, 0x70, 0x38, 0xed, 0x70, 0x4e, 0x38, - 0x54, 0x4f, 0xac, 0x38, 0xfd, 0x07, 0x8d, 0x38, 0x0b, 0x00, 0x00, 0x00, - 0x43, 0x6f, 0x6e, 0x76, 0x32, 0x44, 0x5f, 0x62, 0x69, 0x61, 0x73, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x4c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0xe6, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x19, - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x06, 0x00, 0x05, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x00, 0x16, 0x0a, 0x00, 0x0e, 0x00, 0x07, 0x00, - 0x00, 0x00, 0x08, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, - 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x07, 0x00, - 0x00, 0x00, 0x08, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, - 0x03, 0x00, 0x00, 0x00}; + 0x20, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x12, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, + 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x00, 0x12, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x94, 0x48, 0x00, 0x00, 0x34, 0x42, 0x00, 0x00, + 0x1c, 0x42, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, + 0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x6d, 0x69, 0x6e, 0x5f, + 0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x76, 0x65, 0x72, 0x73, + 0x69, 0x6f, 0x6e, 0x00, 0x0c, 0x00, 0x00, 0x00, 0xd4, 0x41, 0x00, 0x00, + 0xb4, 0x41, 0x00, 0x00, 0x24, 0x03, 0x00, 0x00, 0xf4, 0x02, 0x00, 0x00, + 0xec, 0x02, 0x00, 0x00, 0xe4, 0x02, 0x00, 0x00, 0xc4, 0x02, 0x00, 0x00, + 0xbc, 0x02, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x16, 0xbd, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x31, 0x2e, 0x35, 0x2e, + 0x30, 0x00, 0x00, 0x00, 0x94, 0xba, 0xff, 0xff, 0x98, 0xba, 0xff, 0xff, + 0x32, 0xbd, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, + 0xfa, 0xee, 0x28, 0xc4, 0xee, 0xfe, 0xcf, 0x0f, 0x1e, 0xf7, 0x1f, 0x06, + 0x0d, 0xed, 0xe9, 0x83, 0x5c, 0xc9, 0x18, 0xe3, 0xf9, 0x14, 0x28, 0x2a, + 0x09, 0xf2, 0x18, 0x34, 0x62, 0xea, 0xef, 0xd6, 0x36, 0xb7, 0x1e, 0xf7, + 0x3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0x9d, 0x01, 0xe0, 0xe0, 0xaf, 0x9c, 0x46, 0xd8, 0xaf, 0xe8, 0xce, 0x02, + 0x8a, 0xbb, 0xe4, 0xf6, 0xf3, 0x36, 0x07, 0xca, 0xcb, 0x87, 0x6e, 0xcc, + 0xd6, 0x9e, 0x0a, 0x2a, 0x81, 0xd7, 0xcf, 0xc0, 0x04, 0xeb, 0x24, 0xcc, + 0xc9, 0x95, 0x33, 0x81, 0xf7, 0xad, 0x1c, 0x9c, 0xa4, 0xd6, 0xf9, 0xe6, + 0x3d, 0x84, 0x7f, 0xcc, 0xd4, 0xb0, 0xf4, 0xa2, 0xe9, 0x3c, 0x36, 0xee, + 0xd5, 0xcf, 0xcd, 0x2d, 0x28, 0xbd, 0xff, 0xff, 0xc2, 0xbf, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x31, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x48, 0xbd, 0xff, 0xff, 0x4c, 0xbd, 0xff, 0xff, 0xe6, 0xbf, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x8a, 0xfe, 0xff, 0xff, + 0xa9, 0x00, 0x00, 0x00, 0xd0, 0xff, 0xff, 0xff, 0xd0, 0x00, 0x00, 0x00, + 0x52, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x4f, 0xfb, 0xff, 0xff, + 0x4a, 0xfd, 0xff, 0xff, 0x12, 0xc0, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x80, 0x3e, 0x00, 0x00, 0xff, 0xf9, 0xfd, 0x0a, 0x07, 0x08, 0x07, 0x03, + 0x07, 0xf2, 0xd1, 0x09, 0xf0, 0xe9, 0x28, 0x09, 0xdf, 0x05, 0xfa, 0xf0, + 0xe8, 0xe3, 0x13, 0x0e, 0x08, 0xef, 0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0x03, 0xe5, + 0x29, 0x07, 0x09, 0x24, 0xf9, 0xe3, 0xf8, 0xde, 0x2d, 0xf4, 0xf5, 0x40, + 0xed, 0xdf, 0x07, 0xef, 0x0f, 0x0a, 0x0b, 0x32, 0x0d, 0xe8, 0x00, 0xe6, + 0xf6, 0xfc, 0xfd, 0x19, 0x11, 0x09, 0xf3, 0x03, 0xea, 0xf1, 0xfb, 0x02, + 0xfd, 0x06, 0xff, 0xfe, 0x09, 0xec, 0x06, 0x0c, 0x15, 0xf9, 0x06, 0xd7, + 0xe3, 0xf7, 0xed, 0x01, 0x03, 0xfd, 0x14, 0x01, 0x0e, 0xe0, 0x37, 0x0d, + 0xd2, 0x18, 0x2f, 0xea, 0x12, 0x0d, 0x05, 0x3a, 0xd5, 0x07, 0x1e, 0xf2, + 0x21, 0x11, 0xf9, 0x36, 0xd3, 0xf5, 0x12, 0xf6, 0xfb, 0xf6, 0x06, 0x0f, + 0xde, 0xf9, 0x06, 0x09, 0xdf, 0xff, 0x0b, 0xf3, 0xf5, 0x01, 0xf1, 0xea, + 0xf2, 0x02, 0x12, 0xfc, 0x0e, 0xee, 0xf8, 0xeb, 0x00, 0xef, 0x21, 0x0f, + 0x09, 0xef, 0xeb, 0x1e, 0xef, 0xf2, 0x26, 0xf9, 0x17, 0xf1, 0xf1, 0xf0, + 0x0c, 0x10, 0x1d, 0xff, 0x1d, 0x06, 0x03, 0xf6, 0xfb, 0x14, 0x1b, 0x03, + 0x22, 0xfd, 0xec, 0x03, 0xfa, 0xf8, 0x01, 0x2b, 0x1e, 0x1b, 0x09, 0x09, + 0x07, 0xff, 0xf0, 0x20, 0xee, 0x14, 0xfb, 0xf6, 0xf8, 0x11, 0xd9, 0x29, + 0xf4, 0xfa, 0x07, 0xef, 0x20, 0xf9, 0xf2, 0x30, 0xee, 0xf0, 0xf3, 0xd6, + 0x0d, 0xfe, 0x03, 0x36, 0xf5, 0xd7, 0x01, 0xe6, 0x04, 0xf0, 0x05, 0x1f, + 0x0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0xfd, 0xd4, 0xf6, 0x12, 0x0e, + 0xed, 0x01, 0xf0, 0xf3, 0xfd, 0xff, 0x18, 0xf3, 0x36, 0xda, 0xf6, 0xef, + 0xe8, 0xef, 0x37, 0x27, 0x4e, 0xf8, 0xf4, 0xff, 0xe5, 0xf3, 0x32, 0x0b, + 0x36, 0x08, 0xe9, 0xf6, 0xe2, 0x13, 0x21, 0xfe, 0x12, 0xed, 0xdd, 0xfb, + 0xf8, 0x05, 0x0f, 0x03, 0x1c, 0x04, 0xfc, 0xf2, 0x23, 0x0e, 0x03, 0xfc, + 0xf9, 0x18, 0xf7, 0x01, 0x1b, 0x03, 0xf5, 0xfd, 0xde, 0xf3, 0x19, 0xfc, + 0x11, 0x02, 0xe7, 0x13, 0xde, 0xd8, 0xf2, 0x05, 0x28, 0x02, 0x02, 0x27, + 0x07, 0x08, 0xff, 0x07, 0x27, 0x0e, 0x19, 0x40, 0xfb, 0x02, 0x0c, 0xf6, + 0x0d, 0x07, 0x0f, 0x47, 0xf8, 0x05, 0x0e, 0xfd, 0x03, 0x1e, 0x07, 0x32, + 0xe7, 0xf6, 0x24, 0x01, 0x01, 0x02, 0x0a, 0xff, 0xf6, 0x26, 0x15, 0xf0, + 0x04, 0x13, 0x03, 0xfa, 0xfe, 0xf6, 0xf1, 0x09, 0x2a, 0xe6, 0xea, 0xf6, + 0x17, 0x13, 0xeb, 0xff, 0x15, 0xeb, 0x23, 0x06, 0xc8, 0xf6, 0x33, 0xeb, + 0xf4, 0xe7, 0x12, 0x2a, 0xe3, 0xe6, 0x32, 0xfa, 0x16, 0x15, 0x17, 0x40, + 0xf1, 0x08, 0x1a, 0xf3, 0xf6, 0x0c, 0x0c, 0x11, 0xd0, 0x22, 0x02, 0xee, + 0xea, 0xf4, 0xf8, 0xf9, 0x13, 0x10, 0x17, 0xf5, 0xf1, 0x0a, 0x0e, 0xfd, + 0x32, 0xda, 0xf1, 0xe2, 0xdb, 0xf2, 0x34, 0x1f, 0x53, 0xfc, 0xe4, 0xf2, + 0xf6, 0xf2, 0x1d, 0x04, 0x4a, 0xec, 0xee, 0x06, 0xdf, 0x01, 0x1a, 0x04, + 0x27, 0xfc, 0xe6, 0xfd, 0xd9, 0xfd, 0x0e, 0x00, 0x0c, 0x16, 0xf3, 0x03, + 0xf7, 0xfc, 0x0e, 0x0f, 0x09, 0x06, 0x06, 0x04, 0x08, 0x02, 0xed, 0xf5, + 0xe4, 0xe6, 0x07, 0x06, 0x03, 0x18, 0xea, 0x13, 0xe2, 0xfa, 0x10, 0xf2, + 0x02, 0xec, 0x03, 0x3c, 0xf6, 0xf6, 0x0a, 0x10, 0x09, 0xf8, 0x15, 0x24, + 0xfd, 0x0d, 0x09, 0x01, 0x00, 0xff, 0x00, 0x1a, 0xf0, 0xee, 0x08, 0x03, + 0x1d, 0x05, 0x16, 0x46, 0xe6, 0xf8, 0x08, 0x00, 0x09, 0x09, 0xff, 0x01, + 0xfc, 0x20, 0xfc, 0xec, 0x05, 0x1b, 0x03, 0xf1, 0x12, 0xe4, 0xfa, 0x24, + 0x1c, 0xf5, 0xf2, 0x05, 0x11, 0xe7, 0xfa, 0x02, 0x20, 0xea, 0x31, 0x10, + 0xcf, 0xd8, 0x33, 0xee, 0xff, 0x09, 0x20, 0x3f, 0xe2, 0x0a, 0x29, 0xee, + 0x3a, 0xf2, 0x1e, 0x39, 0x02, 0x1e, 0xfe, 0xf2, 0xef, 0xe2, 0x0d, 0x0f, + 0xf1, 0x19, 0x02, 0xe7, 0xec, 0xff, 0xfe, 0xe4, 0xfe, 0xfb, 0x02, 0xf6, + 0xf1, 0xf4, 0x07, 0x1a, 0x2a, 0xf9, 0x06, 0xf9, 0xda, 0xf4, 0x22, 0x02, + 0x4f, 0x0a, 0xf3, 0xfc, 0xf3, 0xf6, 0x25, 0x0a, 0x28, 0x01, 0xf7, 0x09, + 0xe6, 0x05, 0x28, 0xf7, 0x1e, 0xf2, 0xee, 0x13, 0xee, 0x05, 0x0f, 0x0a, + 0x09, 0xe8, 0xe8, 0x0e, 0x05, 0x12, 0x0f, 0x15, 0x02, 0xec, 0xf8, 0x02, + 0xf7, 0x05, 0xf8, 0xff, 0xdc, 0x00, 0x01, 0x00, 0x12, 0x17, 0xec, 0x19, + 0xfa, 0x09, 0xfa, 0xf3, 0x1d, 0x0b, 0x07, 0x25, 0xea, 0x0c, 0xf5, 0xfa, + 0x04, 0xf7, 0xfe, 0x33, 0xfe, 0x14, 0xef, 0x04, 0xf0, 0x00, 0x00, 0x3a, + 0xea, 0xfa, 0x10, 0x01, 0xe4, 0x00, 0xff, 0x23, 0xe9, 0x26, 0x15, 0x10, + 0x04, 0x14, 0x0d, 0x08, 0xf8, 0xfd, 0x10, 0xfb, 0x00, 0x21, 0x06, 0xfa, + 0x0f, 0x08, 0xf1, 0x09, 0x28, 0xf0, 0xd8, 0x0d, 0x08, 0x09, 0x02, 0xfb, + 0x12, 0x03, 0x0e, 0xfb, 0xce, 0xf0, 0x39, 0xe5, 0x09, 0xf6, 0x1f, 0x35, + 0xdd, 0x1c, 0x25, 0xef, 0x17, 0x0c, 0xf6, 0x3e, 0xf0, 0x21, 0x08, 0xff, + 0xd7, 0xfc, 0xfd, 0x1f, 0xe5, 0x18, 0x12, 0xe9, 0xf5, 0xe9, 0x12, 0xf6, + 0x02, 0x13, 0xf4, 0x0a, 0xfd, 0x03, 0x09, 0x08, 0x2f, 0x07, 0xee, 0xfd, + 0xd7, 0x00, 0x2b, 0x29, 0x3b, 0xdb, 0xde, 0xf1, 0xe1, 0xf7, 0x47, 0x12, + 0x35, 0x0c, 0xe4, 0x09, 0xef, 0x17, 0x2b, 0xea, 0x2d, 0xf8, 0xe8, 0x18, + 0xef, 0x03, 0x11, 0x0a, 0x10, 0xff, 0xe8, 0x07, 0x0c, 0x07, 0x03, 0x18, + 0x05, 0x08, 0xf8, 0xf8, 0x06, 0x18, 0xe9, 0xf9, 0xe0, 0x0f, 0x0d, 0x18, + 0x04, 0x01, 0xf0, 0x1c, 0xf6, 0x14, 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8, 0xee, 0x11, 0x02, + 0x03, 0x0a, 0xef, 0x38, 0xfe, 0x13, 0x1b, 0x09, 0xfe, 0x06, 0x05, 0xf3, + 0x04, 0xdf, 0xfc, 0x00, 0xe7, 0x15, 0xec, 0xf1, 0xf8, 0xfc, 0xed, 0x05, + 0x0e, 0xf3, 0x15, 0x09, 0x01, 0x0d, 0xfd, 0x00, 0x24, 0xe2, 0x31, 0x13, + 0xd5, 0x1b, 0x2b, 0xe8, 0x03, 0x08, 0x1d, 0x33, 0xdc, 0xfd, 0x24, 0xe4, + 0x20, 0xfa, 0x07, 0x33, 0x01, 0x12, 0x06, 0xf5, 0xef, 0xf7, 0xfa, 0x13, + 0x01, 0xec, 0xee, 0xe0, 0xfd, 0x0d, 0xff, 0x09, 0xf6, 0x00, 0xed, 0x07, + 0xea, 0x0e, 0xff, 0x0e, 0x26, 0xfc, 0xf0, 0xe7, 0xe7, 0xfe, 0x30, 0xff, + 0x24, 0x04, 0x06, 0xf4, 0xf5, 0xf8, 0x23, 0x0e, 0x3d, 0xf2, 0xfd, 0x04, + 0xe8, 0xfb, 0x23, 0xfe, 0x33, 0xe1, 0x01, 0xfd, 0xdc, 0xfb, 0x0e, 0xfa, + 0x22, 0xfb, 0x11, 0xfa, 0xff, 0x08, 0x21, 0x30, 0x13, 0x03, 0xf2, 0x03, + 0xf8, 0x0f, 0xec, 0x0d, 0xef, 0x0f, 0x10, 0x10, 0x0f, 0xf6, 0xf9, 0x1e, + 0xf7, 0xe5, 0x08, 0xfa, 0x09, 0xff, 0x00, 0x15, 0x02, 0x00, 0x08, 0xfe, + 0xfb, 0x0e, 0x15, 0x28, 0xfa, 0xfb, 0x13, 0x06, 0xfb, 0x05, 0xf6, 0x11, + 0xf6, 0x0b, 0x06, 0x15, 0xe1, 0x00, 0xe9, 0x0f, 0xe1, 0x1d, 0x18, 0xfd, + 0x0b, 0x0f, 0xff, 0xf2, 0xf5, 0xfd, 0x14, 0xff, 0xf4, 0xfe, 0xe2, 0xf8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, + 0x14, 0xe1, 0x03, 0xfa, 0xf9, 0xda, 0xe9, 0xfc, 0xf3, 0xff, 0x12, 0x04, + 0xf7, 0xfc, 0x17, 0x0f, 0xfc, 0x29, 0x03, 0xe5, 0xf2, 0xee, 0x1e, 0xfa, + 0x04, 0xed, 0x25, 0xf4, 0xe1, 0x15, 0x10, 0x1e, 0xef, 0x1c, 0x04, 0xde, + 0xe5, 0x08, 0x21, 0xfd, 0xfd, 0xea, 0x03, 0xca, 0xda, 0x26, 0x00, 0x0a, + 0xfd, 0x05, 0xf0, 0xd4, 0xe1, 0x1a, 0xe4, 0xf5, 0x07, 0xe7, 0xfa, 0xdf, + 0xd4, 0x03, 0xf0, 0x10, 0x15, 0x0c, 0xf4, 0xed, 0xe3, 0xfb, 0x0f, 0x1e, + 0x16, 0x09, 0x00, 0xec, 0xea, 0x13, 0x16, 0x0b, 0x01, 0xfb, 0xff, 0x00, + 0xfb, 0x07, 0x13, 0x08, 0xf4, 0xe4, 0x12, 0x00, 0xfb, 0xfa, 0xfc, 0x08, + 0xeb, 0x19, 0x02, 0x1c, 0xe8, 0x26, 0xf3, 0x10, 0x09, 0x0f, 0x19, 0x02, + 0xfb, 0xec, 0xf7, 0xe2, 0xfb, 0xfa, 0x11, 0xf3, 0x0b, 0x08, 0xff, 0xd9, + 0xf8, 0x12, 0x18, 0x06, 0x07, 0x22, 0xff, 0x19, 0xf5, 0x0b, 0x0a, 0x13, + 0xf2, 0xfa, 0x02, 0x21, 0xeb, 0x11, 0x17, 0x17, 0xec, 0xe1, 0x0e, 0xf7, + 0xe8, 0xd8, 0x0e, 0x01, 0xf1, 0xed, 0xed, 0xf0, 0x09, 0xf7, 0xe7, 0xfd, + 0xf0, 0xf9, 0xdb, 0xee, 0xdc, 0xfb, 0xf8, 0x0a, 0xf5, 0x0b, 0xd4, 0xd7, + 0x08, 0x06, 0x18, 0x06, 0x0c, 0x13, 0xfd, 0x09, 0x13, 0x26, 0x12, 0xf4, + 0xef, 0x00, 0xf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x04, 0x10, 0x05, 0xed, 0x15, 0x02, 0x0b, 0x10, + 0xfa, 0x02, 0x05, 0x0b, 0x02, 0x07, 0xfc, 0xf5, 0x15, 0x14, 0x05, 0xf7, + 0x0c, 0xfe, 0xf6, 0xf4, 0xfa, 0x06, 0xfc, 0x13, 0xdc, 0xe4, 0x09, 0xfa, + 0x02, 0x23, 0xec, 0x06, 0x11, 0x13, 0xf8, 0xfa, 0x27, 0x28, 0x0b, 0x23, + 0xec, 0xf1, 0x09, 0x17, 0x0f, 0x13, 0xff, 0xf2, 0xfc, 0x0a, 0xf5, 0x0d, + 0x03, 0x26, 0x01, 0x0f, 0xfe, 0xf1, 0xfb, 0xe6, 0xf0, 0x02, 0xf2, 0xff, + 0x02, 0x11, 0xff, 0xfd, 0x1c, 0x02, 0x0b, 0xf6, 0x14, 0x0c, 0x0b, 0x21, + 0x28, 0xf0, 0x11, 0x05, 0x06, 0xed, 0xf9, 0x0a, 0xf2, 0xef, 0xf8, 0xf1, + 0xfe, 0x0d, 0xf9, 0xf7, 0xea, 0x00, 0x08, 0xdb, 0x02, 0x0f, 0xfe, 0x04, + 0xef, 0x20, 0x16, 0x01, 0xe8, 0xed, 0xe4, 0x22, 0xf6, 0x19, 0x00, 0x04, + 0x01, 0x13, 0xeb, 0x0d, 0xec, 0x01, 0x08, 0x05, 0x0c, 0x0e, 0xfe, 0x02, + 0x12, 0xf7, 0x27, 0xf9, 0xfd, 0x18, 0xfe, 0x24, 0xf7, 0x13, 0xed, 0x1e, + 0x09, 0xff, 0xd8, 0xf4, 0x12, 0xf8, 0x04, 0x0c, 0x1c, 0x11, 0xfd, 0x17, + 0x1d, 0x01, 0x13, 0xee, 0x11, 0xf3, 0xf8, 0x06, 0xf6, 0x16, 0xfe, 0x15, + 0x16, 0xdc, 0x1f, 0x00, 0x25, 0xee, 0xff, 0xf7, 0xf6, 0x02, 0xdd, 0x15, + 0xf1, 0x14, 0x08, 0xe8, 0xe5, 0x21, 0xea, 0xf0, 0x1a, 0x07, 0xea, 0x08, + 0xea, 0xe4, 0x1e, 0x00, 0x13, 0x17, 0xec, 0x11, 0xd6, 0x11, 0x18, 0x17, + 0x04, 0x15, 0x03, 0x3a, 0xd6, 0x02, 0x07, 0x04, 0xe6, 0xe5, 0xfe, 0x0e, + 0xff, 0xed, 0xfc, 0xfb, 0xff, 0x1c, 0x06, 0x0a, 0xfb, 0xf9, 0xea, 0x1a, + 0x21, 0xf5, 0x04, 0x06, 0x0a, 0xe3, 0x16, 0xea, 0x04, 0xe2, 0xf9, 0xf9, + 0xe6, 0xfb, 0x0f, 0xfc, 0x06, 0xfb, 0x10, 0x07, 0x07, 0x13, 0x07, 0xfc, + 0x16, 0xef, 0x07, 0xdc, 0x12, 0x1f, 0x08, 0xf4, 0xe9, 0x14, 0x06, 0xf7, + 0xf1, 0x0c, 0x01, 0x0c, 0xe6, 0x04, 0xf3, 0xf2, 0xe5, 0xf3, 0xef, 0x1d, + 0xf6, 0x20, 0x07, 0xfe, 0xf4, 0x05, 0xee, 0x10, 0xfd, 0x0e, 0x0b, 0x02, + 0x0d, 0xd8, 0x07, 0xfb, 0x26, 0x0a, 0x1c, 0x21, 0x06, 0x1f, 0xf4, 0x06, + 0x37, 0x18, 0xfa, 0x16, 0x1e, 0x24, 0xfb, 0xf0, 0x12, 0xf9, 0x02, 0x09, + 0x17, 0x16, 0xf3, 0xf9, 0x17, 0xf2, 0x02, 0x0a, 0x2d, 0xe7, 0xe3, 0x25, + 0xf0, 0xf9, 0x0f, 0xdd, 0x15, 0xe6, 0x04, 0xfc, 0xf1, 0x17, 0x0a, 0xea, + 0x24, 0x07, 0xf1, 0x11, 0x13, 0x29, 0xf4, 0xc5, 0xfb, 0x07, 0xef, 0x13, + 0x0b, 0xe1, 0xf1, 0xeb, 0xf8, 0x1b, 0x09, 0x08, 0x1f, 0x15, 0xf2, 0x05, + 0x02, 0xdd, 0x09, 0x0f, 0x16, 0x10, 0x01, 0x30, 0xf2, 0xe0, 0x27, 0xfe, + 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 0x1f, + 0x11, 0x00, 0x18, 0x03, 0xf7, 0xe4, 0xff, 0x07, 0x09, 0x1a, 0x18, 0xff, + 0xea, 0xec, 0xfd, 0x13, 0x2b, 0xf8, 0x0c, 0xfa, 0xdf, 0xf6, 0x11, 0xda, + 0x2a, 0xdc, 0xfc, 0xff, 0xff, 0xec, 0x12, 0xe1, 0x37, 0xfd, 0xeb, 0xfe, + 0xea, 0xd1, 0x12, 0xfa, 0x28, 0x1a, 0x0d, 0xf0, 0xf7, 0xe0, 0x0c, 0xeb, + 0x35, 0x14, 0xeb, 0x00, 0xeb, 0xe7, 0x1b, 0xfc, 0x09, 0x00, 0xf2, 0x04, + 0xf9, 0xe5, 0x1a, 0x0e, 0x08, 0x12, 0xf8, 0xfe, 0x09, 0x0f, 0x0d, 0xea, + 0x03, 0xe1, 0xfe, 0xf2, 0xec, 0x0d, 0x02, 0xdb, 0x04, 0x1d, 0xd4, 0x01, + 0xca, 0x13, 0x29, 0xca, 0x28, 0x04, 0xe2, 0xf1, 0xdb, 0x0b, 0x2c, 0xcd, + 0x44, 0x00, 0xe7, 0xf4, 0xd0, 0x12, 0x15, 0xff, 0x42, 0x11, 0x05, 0xfd, + 0xd9, 0x11, 0x1c, 0xf4, 0x15, 0xec, 0xf2, 0x24, 0xd6, 0x1d, 0xec, 0xda, + 0xf5, 0xec, 0xe5, 0x22, 0xf2, 0x0b, 0xbd, 0xd0, 0xeb, 0x05, 0x07, 0x1b, + 0x01, 0xed, 0xf5, 0x02, 0xcf, 0x08, 0x15, 0xfd, 0x1c, 0xe5, 0x04, 0x19, + 0xc7, 0x25, 0x22, 0xf3, 0xde, 0xfb, 0xfb, 0x20, 0xf6, 0xeb, 0x25, 0xfe, + 0xf5, 0x08, 0xf5, 0x17, 0x0e, 0x04, 0x1c, 0xf9, 0xee, 0xec, 0xe1, 0x06, + 0x12, 0xff, 0x2a, 0x13, 0xed, 0xfe, 0x05, 0x18, 0x25, 0x20, 0x09, 0x13, + 0xea, 0xd7,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 0x0e, 0xeb, 0xf3, + 0xf6, 0xf7, 0x14, 0x0e, 0xfc, 0xf5, 0xde, 0xf5, 0x9e, 0xfe, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xab, 0x01, 0x00, 0x00, + 0xfa, 0xfd, 0xff, 0xff, 0xa2, 0xff, 0xff, 0xff, 0xba, 0x00, 0x00, 0x00, + 0x24, 0xfc, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x54, 0x4f, 0x43, 0x4f, + 0x20, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x24, 0xfb, 0xff, 0xff, + 0x68, 0x01, 0x00, 0x00, 0x5c, 0x01, 0x00, 0x00, 0x50, 0x01, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xf4, 0x00, 0x00, 0x00, + 0x90, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xce, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0x03, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1a, 0xff, 0xff, 0xff, 0x00, 0x00, 0x80, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, + 0x07, 0x00, 0x14, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, + 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xc4, 0xfc, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x10, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x38, 0x00, 0x00, 0x00, + 0x2c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x07, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x1a, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x07, 0x00, 0x14, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x02, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x31, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x34, 0x04, 0x00, 0x00, 0xcc, 0x03, 0x00, 0x00, + 0x4c, 0x03, 0x00, 0x00, 0xdc, 0x02, 0x00, 0x00, 0x60, 0x02, 0x00, 0x00, + 0x20, 0x02, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x44, 0x01, 0x00, 0x00, + 0x70, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0xfc, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x09, 0x44, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xf4, 0xfb, 0xff, 0xff, + 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x3b, 0x0e, 0x00, 0x00, 0x00, 0x6c, 0x61, 0x62, 0x65, + 0x6c, 0x73, 0x5f, 0x73, 0x6f, 0x66, 0x74, 0x6d, 0x61, 0x78, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0e, 0x00, 0x1a, 0x00, 0x08, 0x00, 0x07, 0x00, 0x0c, 0x00, + 0x10, 0x00, 0x14, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, + 0xb4, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, + 0x12, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x11, 0x1e, 0x23, 0x3a, 0x9e, 0xa1, 0x15, 0x39, + 0x23, 0x69, 0x45, 0x3a, 0x09, 0xe4, 0xe4, 0x39, 0x65, 0xd7, 0x13, 0x3a, + 0xe0, 0xb2, 0xfd, 0x39, 0x1b, 0xc1, 0x53, 0x3a, 0xc2, 0x50, 0x2d, 0x3a, + 0x12, 0x00, 0x00, 0x00, 0x66, 0x69, 0x72, 0x73, 0x74, 0x5f, 0x77, 0x65, + 0x69, 0x67, 0x68, 0x74, 0x73, 0x2f, 0x72, 0x65, 0x61, 0x64, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3a, 0xfd, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x09, 0x54, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x2c, 0xfd, 0xff, 0xff, + 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xb5, 0xfa, 0xfa, 0x39, 0x1f, 0x00, 0x00, 0x00, 0x66, 0x69, 0x6e, 0x61, + 0x6c, 0x5f, 0x66, 0x63, 0x5f, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x73, + 0x2f, 0x72, 0x65, 0x61, 0x64, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, + 0x6f, 0x73, 0x65, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xa0, 0x0f, 0x00, 0x00, 0xa2, 0xfd, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x58, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x74, 0xfe, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xf2, 0xdd, 0xbb, 0x3d, + 0x01, 0x00, 0x00, 0x00, 0x32, 0xa3, 0x25, 0x41, 0x01, 0x00, 0x00, 0x00, + 0xf6, 0xa0, 0x50, 0xc1, 0x05, 0x00, 0x00, 0x00, 0x61, 0x64, 0x64, 0x5f, + 0x31, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x0e, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, + 0x2c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x0f, 0x00, 0x00, 0x00, 0x52, 0x65, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, + 0x32, 0x2f, 0x73, 0x68, 0x61, 0x70, 0x65, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x4a, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x5c, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x1c, 0xff, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x50, 0x50, 0xd0, 0x3d, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0xcf, 0x41, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x52, 0x65, 0x73, 0x68, + 0x61, 0x70, 0x65, 0x5f, 0x32, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xc2, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x58, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x94, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x50, 0x50, 0xd0, 0x3d, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x80, 0xcf, 0x41, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x52, 0x65, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, + 0x31, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xa8, 0x07, 0x00, 0x00, 0x2e, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x60, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, 0x04, 0x00, 0x08, 0x00, + 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x3a, 0x6a, 0xac, 0x3d, 0x01, 0x00, 0x00, 0x00, + 0xd0, 0xbd, 0xab, 0x41, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x52, 0x65, 0x6c, 0x75, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xaa, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x02, 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x2c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x9c, 0xff, 0xff, 0xff, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x96, 0x08, 0x29, 0x38, 0x0b, 0x00, 0x00, 0x00, + 0x4d, 0x61, 0x74, 0x4d, 0x75, 0x6c, 0x5f, 0x62, 0x69, 0x61, 0x73, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x18, 0x00, 0x08, 0x00, 0x07, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xa0, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x9a, 0xbb, 0x84, 0x38, 0x83, 0x84, 0x73, 0x37, 0x5b, 0xa3, 0xa0, 0x38, + 0x16, 0x41, 0x3a, 0x38, 0xc7, 0x9a, 0x70, 0x38, 0xed, 0x70, 0x4e, 0x38, + 0x54, 0x4f, 0xac, 0x38, 0xfd, 0x07, 0x8d, 0x38, 0x0b, 0x00, 0x00, 0x00, + 0x43, 0x6f, 0x6e, 0x76, 0x32, 0x44, 0x5f, 0x62, 0x69, 0x61, 0x73, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x4c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xe6, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x19, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x06, 0x00, 0x05, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x16, 0x0a, 0x00, 0x0e, 0x00, 0x07, 0x00, + 0x00, 0x00, 0x08, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x07, 0x00, + 0x00, 0x00, 0x08, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, + 0x03, 0x00, 0x00, 0x00 +}; const int g_model_len = 18712; diff --git a/libraries/TFLiteMicro/examples/micro_speech/recognize_commands.cpp b/libraries/TFLiteMicro/examples/micro_speech/recognize_commands.cpp index 9c6c1caeb01..5b5737ddbdd 100644 --- a/libraries/TFLiteMicro/examples/micro_speech/recognize_commands.cpp +++ b/libraries/TFLiteMicro/examples/micro_speech/recognize_commands.cpp @@ -21,52 +21,48 @@ RecognizeCommands::RecognizeCommands(int32_t average_window_duration_ms, uint8_t detection_threshold, int32_t suppression_ms, int32_t minimum_count) - : average_window_duration_ms_(average_window_duration_ms), - detection_threshold_(detection_threshold), - suppression_ms_(suppression_ms), - minimum_count_(minimum_count), - previous_results_() { + : average_window_duration_ms_(average_window_duration_ms), + detection_threshold_(detection_threshold), + suppression_ms_(suppression_ms), + minimum_count_(minimum_count), + previous_results_() { previous_top_label_ = "silence"; previous_top_label_time_ = std::numeric_limits::min(); } TfLiteStatus RecognizeCommands::ProcessLatestResults( - const TfLiteTensor* latest_results, const int32_t current_time_ms, - const char** found_command, uint8_t* score, bool* is_new_command) { - if ((latest_results->dims->size != 2) || - (latest_results->dims->data[0] != 1) || - (latest_results->dims->data[1] != kCategoryCount)) { + const TfLiteTensor* latest_results, const int32_t current_time_ms, + const char** found_command, uint8_t* score, bool* is_new_command) { + if ((latest_results->dims->size != 2) || (latest_results->dims->data[0] != 1) || (latest_results->dims->data[1] != kCategoryCount)) { MicroPrintf( - "The results for recognition should contain %d elements, but there are " - "%d in an %d-dimensional shape", - kCategoryCount, latest_results->dims->data[1], - latest_results->dims->size); + "The results for recognition should contain %d elements, but there are " + "%d in an %d-dimensional shape", + kCategoryCount, latest_results->dims->data[1], + latest_results->dims->size); return kTfLiteError; } if (latest_results->type != kTfLiteInt8) { MicroPrintf( - "The results for recognition should be int8_t elements, but are %d", - latest_results->type); + "The results for recognition should be int8_t elements, but are %d", + latest_results->type); return kTfLiteError; } - if ((!previous_results_.empty()) && - (current_time_ms < previous_results_.front().time_)) { + if ((!previous_results_.empty()) && (current_time_ms < previous_results_.front().time_)) { MicroPrintf( - "Results must be fed in increasing time order, but received a " - "timestamp of %d that was earlier than the previous one of %d", - current_time_ms, previous_results_.front().time_); + "Results must be fed in increasing time order, but received a " + "timestamp of %d that was earlier than the previous one of %d", + current_time_ms, previous_results_.front().time_); return kTfLiteError; } // Add the latest results to the head of the queue. - previous_results_.push_back({current_time_ms, latest_results->data.int8}); + previous_results_.push_back({ current_time_ms, latest_results->data.int8 }); // Prune any earlier results that are too old for the averaging window. const int64_t time_limit = current_time_ms - average_window_duration_ms_; - while ((!previous_results_.empty()) && - previous_results_.front().time_ < time_limit) { + while ((!previous_results_.empty()) && previous_results_.front().time_ < time_limit) { previous_results_.pop_front(); } @@ -75,8 +71,7 @@ TfLiteStatus RecognizeCommands::ProcessLatestResults( const int64_t how_many_results = previous_results_.size(); const int64_t earliest_time = previous_results_.front().time_; const int64_t samples_duration = current_time_ms - earliest_time; - if ((how_many_results < minimum_count_) || - (samples_duration < (average_window_duration_ms_ / 4))) { + if ((how_many_results < minimum_count_) || (samples_duration < (average_window_duration_ms_ / 4))) { *found_command = previous_top_label_; *score = 0; *is_new_command = false; @@ -87,7 +82,7 @@ TfLiteStatus RecognizeCommands::ProcessLatestResults( int32_t average_scores[kCategoryCount]; for (int offset = 0; offset < previous_results_.size(); ++offset) { PreviousResultsQueue::Result previous_result = - previous_results_.from_front(offset); + previous_results_.from_front(offset); const int8_t* scores = previous_result.scores; for (int i = 0; i < kCategoryCount; ++i) { if (offset == 0) { @@ -115,15 +110,12 @@ TfLiteStatus RecognizeCommands::ProcessLatestResults( // If we've recently had another label trigger, assume one that occurs too // soon afterwards is a bad result. int64_t time_since_last_top; - if ((previous_top_label_ == kCategoryLabels[0]) || - (previous_top_label_time_ == std::numeric_limits::min())) { + if ((previous_top_label_ == kCategoryLabels[0]) || (previous_top_label_time_ == std::numeric_limits::min())) { time_since_last_top = std::numeric_limits::max(); } else { time_since_last_top = current_time_ms - previous_top_label_time_; } - if ((current_top_score > detection_threshold_) && - ((current_top_label != previous_top_label_) || - (time_since_last_top > suppression_ms_))) { + if ((current_top_score > detection_threshold_) && ((current_top_label != previous_top_label_) || (time_since_last_top > suppression_ms_))) { previous_top_label_ = current_top_label; previous_top_label_time_ = current_time_ms; *is_new_command = true; diff --git a/libraries/TFLiteMicro/examples/micro_speech/recognize_commands.h b/libraries/TFLiteMicro/examples/micro_speech/recognize_commands.h index ec3c32b2a85..4ebbc50590f 100644 --- a/libraries/TFLiteMicro/examples/micro_speech/recognize_commands.h +++ b/libraries/TFLiteMicro/examples/micro_speech/recognize_commands.h @@ -29,14 +29,17 @@ limitations under the License. // so it's a better fit for microcontroller applications, but this does mean // there are hard limits on the number of results it can store. class PreviousResultsQueue { - public: - PreviousResultsQueue() : front_index_(0), size_(0) {} +public: + PreviousResultsQueue() + : front_index_(0), size_(0) {} // Data structure that holds an inference result, and the time when it // was recorded. struct Result { - Result() : time_(0), scores() {} - Result(int32_t time, int8_t* input_scores) : time_(time) { + Result() + : time_(0), scores() {} + Result(int32_t time, int8_t* input_scores) + : time_(time) { for (int i = 0; i < kCategoryCount; ++i) { scores[i] = input_scores[i]; } @@ -45,9 +48,15 @@ class PreviousResultsQueue { int8_t scores[kCategoryCount]; }; - int size() { return size_; } - bool empty() { return size_ == 0; } - Result& front() { return results_[front_index_]; } + int size() { + return size_; + } + bool empty() { + return size_ == 0; + } + Result& front() { + return results_[front_index_]; + } Result& back() { int back_index = front_index_ + (size_ - 1); if (back_index >= kMaxResults) { @@ -94,7 +103,7 @@ class PreviousResultsQueue { return results_[index]; } - private: +private: static constexpr int kMaxResults = 50; Result results_[kMaxResults]; @@ -113,7 +122,7 @@ class PreviousResultsQueue { // increasing from the previous, since the class is designed to process a stream // of data over time. class RecognizeCommands { - public: +public: // labels should be a list of the strings associated with each one-hot score. // The window duration controls the smoothing. Longer durations will give a // higher confidence that the results are correct, but may miss some commands. @@ -135,7 +144,7 @@ class RecognizeCommands { const char** found_command, uint8_t* score, bool* is_new_command); - private: +private: // Configuration int32_t average_window_duration_ms_; uint8_t detection_threshold_; diff --git a/libraries/TFLiteMicro/examples/micro_speech/ringbuf.c b/libraries/TFLiteMicro/examples/micro_speech/ringbuf.c index c02528b9494..0c81f1c9a77 100644 --- a/libraries/TFLiteMicro/examples/micro_speech/ringbuf.c +++ b/libraries/TFLiteMicro/examples/micro_speech/ringbuf.c @@ -42,8 +42,7 @@ ringbuf_t* rb_init(const char* name, uint32_t size) { r = malloc(sizeof(ringbuf_t)); assert(r); -#if (CONFIG_SPIRAM_SUPPORT && \ - (CONFIG_SPIRAM_USE_CAPS_ALLOC || CONFIG_SPIRAM_USE_MALLOC)) +#if (CONFIG_SPIRAM_SUPPORT && (CONFIG_SPIRAM_USE_CAPS_ALLOC || CONFIG_SPIRAM_USE_MALLOC)) buf = heap_caps_calloc(1, size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); #else buf = calloc(1, size); @@ -85,7 +84,9 @@ void rb_cleanup(ringbuf_t* rb) { /* * @brief: get the number of filled bytes in the buffer */ -ssize_t rb_filled(ringbuf_t* rb) { return rb->fill_cnt; } +ssize_t rb_filled(ringbuf_t* rb) { + return rb->fill_cnt; +} /* * @brief: get the number of empty bytes available in the buffer @@ -259,7 +260,9 @@ static void _rb_reset(ringbuf_t* rb, int abort_read, int abort_write) { xSemaphoreGive(rb->lock); } -void rb_reset(ringbuf_t* rb) { _rb_reset(rb, 0, 0); } +void rb_reset(ringbuf_t* rb) { + _rb_reset(rb, 0, 0); +} void rb_abort_read(ringbuf_t* rb) { if (rb == NULL) { diff --git a/libraries/TFLiteMicro/examples/micro_speech/ringbuf.h b/libraries/TFLiteMicro/examples/micro_speech/ringbuf.h index f39ccbe2121..0f3a4a7708e 100644 --- a/libraries/TFLiteMicro/examples/micro_speech/ringbuf.h +++ b/libraries/TFLiteMicro/examples/micro_speech/ringbuf.h @@ -41,43 +41,43 @@ extern "C" { #endif #endif -typedef struct ringbuf { - char* name; - uint8_t* base; /**< Original pointer */ - /* XXX: these need to be volatile? */ - uint8_t* volatile readptr; /**< Read pointer */ - uint8_t* volatile writeptr; /**< Write pointer */ - volatile ssize_t fill_cnt; /**< Number of filled slots */ - ssize_t size; /**< Buffer size */ - xSemaphoreHandle can_read; - xSemaphoreHandle can_write; - xSemaphoreHandle lock; - int abort_read; - int abort_write; - int writer_finished; // to prevent infinite blocking for buffer read - int reader_unblock; -} ringbuf_t; + typedef struct ringbuf { + char* name; + uint8_t* base; /**< Original pointer */ + /* XXX: these need to be volatile? */ + uint8_t* volatile readptr; /**< Read pointer */ + uint8_t* volatile writeptr; /**< Write pointer */ + volatile ssize_t fill_cnt; /**< Number of filled slots */ + ssize_t size; /**< Buffer size */ + xSemaphoreHandle can_read; + xSemaphoreHandle can_write; + xSemaphoreHandle lock; + int abort_read; + int abort_write; + int writer_finished; // to prevent infinite blocking for buffer read + int reader_unblock; + } ringbuf_t; -ringbuf_t* rb_init(const char* rb_name, uint32_t size); -void rb_abort_read(ringbuf_t* rb); -void rb_abort_write(ringbuf_t* rb); -void rb_abort(ringbuf_t* rb); -void rb_reset(ringbuf_t* rb); -/** + ringbuf_t* rb_init(const char* rb_name, uint32_t size); + void rb_abort_read(ringbuf_t* rb); + void rb_abort_write(ringbuf_t* rb); + void rb_abort(ringbuf_t* rb); + void rb_reset(ringbuf_t* rb); + /** * @brief Special function to reset the buffer while keeping rb_write aborted. * This rb needs to be reset again before being useful. */ -void rb_reset_and_abort_write(ringbuf_t* rb); -void rb_stat(ringbuf_t* rb); -ssize_t rb_filled(ringbuf_t* rb); -ssize_t rb_available(ringbuf_t* rb); -int rb_read(ringbuf_t* rb, uint8_t* buf, int len, uint32_t ticks_to_wait); -int rb_write(ringbuf_t* rb, const uint8_t* buf, int len, - uint32_t ticks_to_wait); -void rb_cleanup(ringbuf_t* rb); -void rb_signal_writer_finished(ringbuf_t* rb); -void rb_wakeup_reader(ringbuf_t* rb); -int rb_is_writer_finished(ringbuf_t* rb); + void rb_reset_and_abort_write(ringbuf_t* rb); + void rb_stat(ringbuf_t* rb); + ssize_t rb_filled(ringbuf_t* rb); + ssize_t rb_available(ringbuf_t* rb); + int rb_read(ringbuf_t* rb, uint8_t* buf, int len, uint32_t ticks_to_wait); + int rb_write(ringbuf_t* rb, const uint8_t* buf, int len, + uint32_t ticks_to_wait); + void rb_cleanup(ringbuf_t* rb); + void rb_signal_writer_finished(ringbuf_t* rb); + void rb_wakeup_reader(ringbuf_t* rb); + int rb_is_writer_finished(ringbuf_t* rb); #ifdef __cplusplus } diff --git a/libraries/TFLiteMicro/src/TFLIteMicro.h b/libraries/TFLiteMicro/src/TFLIteMicro.h index 3b3a0f380cf..4f278f65879 100644 --- a/libraries/TFLiteMicro/src/TFLIteMicro.h +++ b/libraries/TFLiteMicro/src/TFLIteMicro.h @@ -3,4 +3,4 @@ * * SPDX-License-Identifier: Apache-2.0 */ -// This header file is kept to avoid Invalid libary error prints while compiling TFLite Micro examples. +// This header file is kept to avoid Invalid library error prints while compiling TFLite Micro examples. diff --git a/libraries/Ticker/examples/Blinker/Blinker.ino b/libraries/Ticker/examples/Blinker/Blinker.ino index aca1f450cca..50ff35c43fd 100644 --- a/libraries/Ticker/examples/Blinker/Blinker.ino +++ b/libraries/Ticker/examples/Blinker/Blinker.ino @@ -7,8 +7,8 @@ Ticker blinker; Ticker toggler; Ticker changer; -float blinkerPace = 0.1; //seconds -const float togglePeriod = 5; //seconds +float blinkerPace = 0.1; //seconds +const float togglePeriod = 5; //seconds void change() { blinkerPace = 0.5; @@ -23,8 +23,7 @@ void toggle() { if (isBlinking) { blinker.detach(); isBlinking = false; - } - else { + } else { blinker.attach(blinkerPace, blink); isBlinking = true; } @@ -38,5 +37,4 @@ void setup() { } void loop() { - } diff --git a/libraries/Ticker/examples/TickerBasic/TickerBasic.ino b/libraries/Ticker/examples/TickerBasic/TickerBasic.ino index 8de5a1282ad..a387b554b71 100644 --- a/libraries/Ticker/examples/TickerBasic/TickerBasic.ino +++ b/libraries/Ticker/examples/TickerBasic/TickerBasic.ino @@ -23,26 +23,26 @@ Ticker flipper; int count = 0; void flip() { - int state = digitalRead(LED_BUILTIN); // get the current state of GPIO1 pin - digitalWrite(LED_BUILTIN, !state); // set pin to the opposite state - - ++count; - // when the counter reaches a certain value, start blinking like crazy - if (count == 20) { - flipper.attach(0.1, flip); - } - // when the counter reaches yet another value, stop blinking - else if (count == 120) { - flipper.detach(); - } + int state = digitalRead(LED_BUILTIN); // get the current state of GPIO1 pin + digitalWrite(LED_BUILTIN, !state); // set pin to the opposite state + + ++count; + // when the counter reaches a certain value, start blinking like crazy + if (count == 20) { + flipper.attach(0.1, flip); + } + // when the counter reaches yet another value, stop blinking + else if (count == 120) { + flipper.detach(); + } } void setup() { - pinMode(LED_BUILTIN, OUTPUT); - digitalWrite(LED_BUILTIN, LOW); + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LOW); - // flip the pin every 0.3s - flipper.attach(0.3, flip); + // flip the pin every 0.3s + flipper.attach(0.3, flip); } void loop() { diff --git a/libraries/Ticker/examples/TickerParameter/TickerParameter.ino b/libraries/Ticker/examples/TickerParameter/TickerParameter.ino index ceb79e32f54..89da1c1633b 100644 --- a/libraries/Ticker/examples/TickerParameter/TickerParameter.ino +++ b/libraries/Ticker/examples/TickerParameter/TickerParameter.ino @@ -1,5 +1,5 @@ /* - Passing paramters to Ticker callbacks + Passing parameters to Ticker callbacks Apart from void(void) functions, the Ticker library supports functions taking one argument. This argument's size has to be less or @@ -22,32 +22,32 @@ Ticker tickerSetHigh; Ticker tickerSetChar; void setPinLow() { - digitalWrite(LED_BUILTIN, 0); + digitalWrite(LED_BUILTIN, 0); } void setPinHigh() { - digitalWrite(LED_BUILTIN, 1); + digitalWrite(LED_BUILTIN, 1); } void setPin(int state) { - digitalWrite(LED_BUILTIN, state); + digitalWrite(LED_BUILTIN, state); } void setPinChar(char state) { - digitalWrite(LED_BUILTIN, state); + digitalWrite(LED_BUILTIN, state); } void setup() { - pinMode(LED_BUILTIN, OUTPUT); + pinMode(LED_BUILTIN, OUTPUT); - // every 25 ms, call setPinLow() - tickerSetLow.attach_ms(25, setPinLow); + // every 25 ms, call setPinLow() + tickerSetLow.attach_ms(25, setPinLow); - // every 26 ms, call setPinHigh() - tickerSetHigh.attach_ms(26, setPinHigh); + // every 26 ms, call setPinHigh() + tickerSetHigh.attach_ms(26, setPinHigh); - // every 54 ms, call setPinChar(1) - tickerSetChar.attach_ms(26, setPinChar, (char)1); + // every 54 ms, call setPinChar(1) + tickerSetChar.attach_ms(26, setPinChar, (char)1); } void loop() { diff --git a/libraries/Ticker/src/Ticker.cpp b/libraries/Ticker/src/Ticker.cpp index 6c996ed56b3..ae9abe00ab4 100644 --- a/libraries/Ticker/src/Ticker.cpp +++ b/libraries/Ticker/src/Ticker.cpp @@ -1,8 +1,8 @@ -/* +/* Ticker.cpp - esp32 library that calls functions periodically Copyright (c) 2017 Bert Melis. All rights reserved. - + Based on the original work of: Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. The original version is part of the esp8266 core for Arduino environment. @@ -24,8 +24,8 @@ #include "Ticker.h" -Ticker::Ticker() : - _timer(nullptr) {} +Ticker::Ticker() + : _timer(nullptr) {} Ticker::~Ticker() { detach(); @@ -63,10 +63,8 @@ bool Ticker::active() const { return esp_timer_is_active(_timer); } -void Ticker::_static_callback(void* arg) -{ +void Ticker::_static_callback(void* arg) { Ticker* _this = reinterpret_cast(arg); if (_this && _this->_callback_function) _this->_callback_function(); } - diff --git a/libraries/Ticker/src/Ticker.h b/libraries/Ticker/src/Ticker.h index 50ab424c275..255e84bafba 100644 --- a/libraries/Ticker/src/Ticker.h +++ b/libraries/Ticker/src/Ticker.h @@ -1,8 +1,8 @@ -/* +/* Ticker.h - esp32 library that calls functions periodically Copyright (c) 2017 Bert Melis. All rights reserved. - + Based on the original work of: Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. The original version is part of the esp8266 core for Arduino environment. @@ -26,12 +26,11 @@ #define TICKER_H extern "C" { - #include "esp_timer.h" +#include "esp_timer.h" } #include -class Ticker -{ +class Ticker { public: Ticker(); ~Ticker(); @@ -39,27 +38,23 @@ class Ticker typedef void (*callback_with_arg_t)(void*); typedef std::function callback_function_t; - void attach(float seconds, callback_function_t callback) - { + void attach(float seconds, callback_function_t callback) { _callback_function = std::move(callback); _attach_us(1000000ULL * seconds, true, _static_callback, this); } - void attach_ms(uint64_t milliseconds, callback_function_t callback) - { + void attach_ms(uint64_t milliseconds, callback_function_t callback) { _callback_function = std::move(callback); _attach_us(1000ULL * milliseconds, true, _static_callback, this); } - void attach_us(uint64_t micros, callback_function_t callback) - { + void attach_us(uint64_t micros, callback_function_t callback) { _callback_function = std::move(callback); _attach_us(micros, true, _static_callback, this); } template - void attach(float seconds, void (*callback)(TArg), TArg arg) - { + void attach(float seconds, void (*callback)(TArg), TArg arg) { static_assert(sizeof(TArg) <= sizeof(void*), "attach() callback argument size must be <= sizeof(void*)"); // C-cast serves two purposes: // static_cast for smaller integer types, @@ -68,54 +63,46 @@ class Ticker } template - void attach_ms(uint64_t milliseconds, void (*callback)(TArg), TArg arg) - { + void attach_ms(uint64_t milliseconds, void (*callback)(TArg), TArg arg) { static_assert(sizeof(TArg) <= sizeof(void*), "attach() callback argument size must be <= sizeof(void*)"); _attach_us(1000ULL * milliseconds, true, reinterpret_cast(callback), reinterpret_cast(arg)); } template - void attach_us(uint64_t micros, void (*callback)(TArg), TArg arg) - { + void attach_us(uint64_t micros, void (*callback)(TArg), TArg arg) { static_assert(sizeof(TArg) <= sizeof(void*), "attach() callback argument size must be <= sizeof(void*)"); _attach_us(micros, true, reinterpret_cast(callback), reinterpret_cast(arg)); } - void once(float seconds, callback_function_t callback) - { + void once(float seconds, callback_function_t callback) { _callback_function = std::move(callback); _attach_us(1000000ULL * seconds, false, _static_callback, this); } - void once_ms(uint64_t milliseconds, callback_function_t callback) - { + void once_ms(uint64_t milliseconds, callback_function_t callback) { _callback_function = std::move(callback); _attach_us(1000ULL * milliseconds, false, _static_callback, this); } - void once_us(uint64_t micros, callback_function_t callback) - { + void once_us(uint64_t micros, callback_function_t callback) { _callback_function = std::move(callback); _attach_us(micros, false, _static_callback, this); } template - void once(float seconds, void (*callback)(TArg), TArg arg) - { + void once(float seconds, void (*callback)(TArg), TArg arg) { static_assert(sizeof(TArg) <= sizeof(void*), "attach() callback argument size must be <= sizeof(void*)"); _attach_us(1000000ULL * seconds, false, reinterpret_cast(callback), reinterpret_cast(arg)); } template - void once_ms(uint64_t milliseconds, void (*callback)(TArg), TArg arg) - { + void once_ms(uint64_t milliseconds, void (*callback)(TArg), TArg arg) { static_assert(sizeof(TArg) <= sizeof(void*), "attach() callback argument size must be <= sizeof(void*)"); _attach_us(1000ULL * milliseconds, false, reinterpret_cast(callback), reinterpret_cast(arg)); } template - void once_us(uint64_t micros, void (*callback)(TArg), TArg arg) - { + void once_us(uint64_t micros, void (*callback)(TArg), TArg arg) { static_assert(sizeof(TArg) <= sizeof(void*), "attach() callback argument size must be <= sizeof(void*)"); _attach_us(micros, false, reinterpret_cast(callback), reinterpret_cast(arg)); } @@ -123,7 +110,7 @@ class Ticker void detach(); bool active() const; -protected: +protected: static void _static_callback(void* arg); callback_function_t _callback_function = nullptr; diff --git a/libraries/USB/examples/CompositeDevice/CompositeDevice.ino b/libraries/USB/examples/CompositeDevice/CompositeDevice.ino index e8711feb34e..f0fce40b6bd 100644 --- a/libraries/USB/examples/CompositeDevice/CompositeDevice.ino +++ b/libraries/USB/examples/CompositeDevice/CompositeDevice.ino @@ -2,8 +2,8 @@ #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 1 #warning This sketch should be used when USB is in OTG mode -void setup(){} -void loop(){} +void setup() {} +void loop() {} #else #include "USB.h" #include "USBHIDMouse.h" @@ -33,10 +33,10 @@ USBHIDVendor Vendor; const int buttonPin = 0; int previousButtonState = HIGH; -static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data){ - if(event_base == ARDUINO_USB_EVENTS){ - arduino_usb_event_data_t * data = (arduino_usb_event_data_t*)event_data; - switch (event_id){ +static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { + if (event_base == ARDUINO_USB_EVENTS) { + arduino_usb_event_data_t* data = (arduino_usb_event_data_t*)event_data; + switch (event_id) { case ARDUINO_USB_STARTED_EVENT: Serial.println("USB PLUGGED"); break; @@ -49,13 +49,13 @@ static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t eve case ARDUINO_USB_RESUME_EVENT: Serial.println("USB RESUMED"); break; - + default: break; } - } else if(event_base == ARDUINO_USB_CDC_EVENTS){ - arduino_usb_cdc_event_data_t * data = (arduino_usb_cdc_event_data_t*)event_data; - switch (event_id){ + } else if (event_base == ARDUINO_USB_CDC_EVENTS) { + arduino_usb_cdc_event_data_t* data = (arduino_usb_cdc_event_data_t*)event_data; + switch (event_id) { case ARDUINO_USB_CDC_CONNECTED_EVENT: Serial.println("CDC CONNECTED"); break; @@ -71,9 +71,9 @@ static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t eve case ARDUINO_USB_CDC_RX_EVENT: Serial.printf("CDC RX [%u]:", data->rx.len); { - uint8_t buf[data->rx.len]; - size_t len = USBSerial.read(buf, data->rx.len); - Serial.write(buf, len); + uint8_t buf[data->rx.len]; + size_t len = USBSerial.read(buf, data->rx.len); + Serial.write(buf, len); } Serial.println(); break; @@ -84,9 +84,9 @@ static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t eve default: break; } - } else if(event_base == ARDUINO_FIRMWARE_MSC_EVENTS){ - arduino_firmware_msc_event_data_t * data = (arduino_firmware_msc_event_data_t*)event_data; - switch (event_id){ + } else if (event_base == ARDUINO_FIRMWARE_MSC_EVENTS) { + arduino_firmware_msc_event_data_t* data = (arduino_firmware_msc_event_data_t*)event_data; + switch (event_id) { case ARDUINO_FIRMWARE_MSC_START_EVENT: Serial.println("MSC Update Start"); break; @@ -103,58 +103,58 @@ static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t eve case ARDUINO_FIRMWARE_MSC_POWER_EVENT: Serial.printf("MSC Update Power: power: %u, start: %u, eject: %u\n", data->power.power_condition, data->power.start, data->power.load_eject); break; - + default: break; } - } else if(event_base == ARDUINO_USB_HID_EVENTS){ - arduino_usb_hid_event_data_t * data = (arduino_usb_hid_event_data_t*)event_data; - switch (event_id){ + } else if (event_base == ARDUINO_USB_HID_EVENTS) { + arduino_usb_hid_event_data_t* data = (arduino_usb_hid_event_data_t*)event_data; + switch (event_id) { case ARDUINO_USB_HID_SET_PROTOCOL_EVENT: - Serial.printf("HID SET PROTOCOL: %s\n", data->set_protocol.protocol?"REPORT":"BOOT"); + Serial.printf("HID SET PROTOCOL: %s\n", data->set_protocol.protocol ? "REPORT" : "BOOT"); break; case ARDUINO_USB_HID_SET_IDLE_EVENT: Serial.printf("HID SET IDLE: %u\n", data->set_idle.idle_rate); break; - + default: break; } - } else if(event_base == ARDUINO_USB_HID_KEYBOARD_EVENTS){ - arduino_usb_hid_keyboard_event_data_t * data = (arduino_usb_hid_keyboard_event_data_t*)event_data; - switch (event_id){ + } else if (event_base == ARDUINO_USB_HID_KEYBOARD_EVENTS) { + arduino_usb_hid_keyboard_event_data_t* data = (arduino_usb_hid_keyboard_event_data_t*)event_data; + switch (event_id) { case ARDUINO_USB_HID_KEYBOARD_LED_EVENT: Serial.printf("HID KEYBOARD LED: NumLock:%u, CapsLock:%u, ScrollLock:%u\n", data->numlock, data->capslock, data->scrolllock); break; - + default: break; } - } else if(event_base == ARDUINO_USB_HID_VENDOR_EVENTS){ - arduino_usb_hid_vendor_event_data_t * data = (arduino_usb_hid_vendor_event_data_t*)event_data; - switch (event_id){ + } else if (event_base == ARDUINO_USB_HID_VENDOR_EVENTS) { + arduino_usb_hid_vendor_event_data_t* data = (arduino_usb_hid_vendor_event_data_t*)event_data; + switch (event_id) { case ARDUINO_USB_HID_VENDOR_GET_FEATURE_EVENT: Serial.printf("HID VENDOR GET FEATURE: len:%u\n", data->len); - for(uint16_t i=0; ilen; i++){ - Serial.write(data->buffer[i]?data->buffer[i]:'.'); + for (uint16_t i = 0; i < data->len; i++) { + Serial.write(data->buffer[i] ? data->buffer[i] : '.'); } Serial.println(); break; case ARDUINO_USB_HID_VENDOR_SET_FEATURE_EVENT: Serial.printf("HID VENDOR SET FEATURE: len:%u\n", data->len); - for(uint16_t i=0; ilen; i++){ - Serial.write(data->buffer[i]?data->buffer[i]:'.'); + for (uint16_t i = 0; i < data->len; i++) { + Serial.write(data->buffer[i] ? data->buffer[i] : '.'); } Serial.println(); break; case ARDUINO_USB_HID_VENDOR_OUTPUT_EVENT: Serial.printf("HID VENDOR OUTPUT: len:%u\n", data->len); - for(uint16_t i=0; ilen; i++){ + for (uint16_t i = 0; i < data->len; i++) { Serial.write(Vendor.read()); } Serial.println(); break; - + default: break; } @@ -164,16 +164,16 @@ static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t eve void setup() { Serial.begin(115200); Serial.setDebugOutput(true); - + pinMode(buttonPin, INPUT_PULLUP); - + USB.onEvent(usbEventCallback); USBSerial.onEvent(usbEventCallback); MSC_Update.onEvent(usbEventCallback); HID.onEvent(usbEventCallback); Keyboard.onEvent(usbEventCallback); Vendor.onEvent(usbEventCallback); - + USBSerial.begin(); MSC_Update.begin(); Vendor.begin(); @@ -193,14 +193,14 @@ void loop() { if (Serial != USBSerial) Serial.println("Button Pressed"); USBSerial.println("Button Pressed"); Vendor.println("Button Pressed"); - Mouse.move(10,10); + Mouse.move(10, 10); Keyboard.pressRaw(HID_KEY_CAPS_LOCK); - Gamepad.leftStick(100,100); + Gamepad.leftStick(100, 100); ConsumerControl.press(CONSUMER_CONTROL_VOLUME_INCREMENT); //SystemControl.press(SYSTEM_CONTROL_POWER_OFF); } else { Keyboard.releaseRaw(HID_KEY_CAPS_LOCK); - Gamepad.leftStick(0,0); + Gamepad.leftStick(0, 0); ConsumerControl.release(); //SystemControl.release(); Vendor.println("Button Released"); @@ -209,14 +209,14 @@ void loop() { } delay(100); } - - while(Serial.available()){ + + while (Serial.available()) { size_t l = Serial.available(); uint8_t b[l]; l = Serial.read(b, l); USBSerial.write(b, l); - if(HID.ready()){ - Vendor.write(b,l); + if (HID.ready()) { + Vendor.write(b, l); } } } diff --git a/libraries/USB/examples/ConsumerControl/ConsumerControl.ino b/libraries/USB/examples/ConsumerControl/ConsumerControl.ino index 24297b0de7a..11b4d2c6af2 100644 --- a/libraries/USB/examples/ConsumerControl/ConsumerControl.ino +++ b/libraries/USB/examples/ConsumerControl/ConsumerControl.ino @@ -2,8 +2,8 @@ #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 1 #warning This sketch should be used when USB is in OTG mode -void setup(){} -void loop(){} +void setup() {} +void loop() {} #else #include "USB.h" #include "USBHIDConsumerControl.h" diff --git a/libraries/USB/examples/CustomHIDDevice/CustomHIDDevice.ino b/libraries/USB/examples/CustomHIDDevice/CustomHIDDevice.ino index 2ccd88e1bbb..740580c1b87 100644 --- a/libraries/USB/examples/CustomHIDDevice/CustomHIDDevice.ino +++ b/libraries/USB/examples/CustomHIDDevice/CustomHIDDevice.ino @@ -2,56 +2,57 @@ #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 1 #warning This sketch should be used when USB is in OTG mode - void setup(){} - void loop(){} +void setup() {} +void loop() {} #else - #include "USB.h" - #include "USBHID.h" - USBHID HID; +#include "USB.h" +#include "USBHID.h" +USBHID HID; -static const uint8_t report_descriptor[] = { // 8 axis - 0x05, 0x01, // Usage Page (Generic Desktop Ctrls) - 0x09, 0x04, // Usage (Joystick) - 0xa1, 0x01, // Collection (Application) - 0xa1, 0x00, // Collection (Physical) - 0x05, 0x01, // Usage Page (Generic Desktop Ctrls) - 0x09, 0x30, // Usage (X) - 0x09, 0x31, // Usage (Y) - 0x09, 0x32, // Usage (Z) - 0x09, 0x33, // Usage (Rx) - 0x09, 0x34, // Usage (Ry) - 0x09, 0x35, // Usage (Rz) - 0x09, 0x36, // Usage (Slider) - 0x09, 0x36, // Usage (Slider) - 0x15, 0x81, // Logical Minimum (-127) - 0x25, 0x7f, // Logical Maximum (127) - 0x75, 0x08, // Report Size (8) - 0x95, 0x08, // Report Count (8) - 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) - 0xC0, // End Collection - 0xC0, // End Collection +static const uint8_t report_descriptor[] = { + // 8 axis + 0x05, 0x01, // Usage Page (Generic Desktop Ctrls) + 0x09, 0x04, // Usage (Joystick) + 0xa1, 0x01, // Collection (Application) + 0xa1, 0x00, // Collection (Physical) + 0x05, 0x01, // Usage Page (Generic Desktop Ctrls) + 0x09, 0x30, // Usage (X) + 0x09, 0x31, // Usage (Y) + 0x09, 0x32, // Usage (Z) + 0x09, 0x33, // Usage (Rx) + 0x09, 0x34, // Usage (Ry) + 0x09, 0x35, // Usage (Rz) + 0x09, 0x36, // Usage (Slider) + 0x09, 0x36, // Usage (Slider) + 0x15, 0x81, // Logical Minimum (-127) + 0x25, 0x7f, // Logical Maximum (127) + 0x75, 0x08, // Report Size (8) + 0x95, 0x08, // Report Count (8) + 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) + 0xC0, // End Collection + 0xC0, // End Collection }; -class CustomHIDDevice: public USBHIDDevice { +class CustomHIDDevice : public USBHIDDevice { public: - CustomHIDDevice(void){ + CustomHIDDevice(void) { static bool initialized = false; - if(!initialized){ + if (!initialized) { initialized = true; HID.addDevice(this, sizeof(report_descriptor)); } } - - void begin(void){ + + void begin(void) { HID.begin(); } - - uint16_t _onGetDescriptor(uint8_t* buffer){ + + uint16_t _onGetDescriptor(uint8_t* buffer) { memcpy(buffer, report_descriptor, sizeof(report_descriptor)); return sizeof(report_descriptor); } - bool send(uint8_t * value){ + bool send(uint8_t* value) { return HID.SendReport(0, value, 8); } }; @@ -84,4 +85,4 @@ void loop() { delay(100); } } -#endif /* ARDUINO_USB_MODE */ \ No newline at end of file +#endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/FirmwareMSC/FirmwareMSC.ino b/libraries/USB/examples/FirmwareMSC/FirmwareMSC.ino index 3259c702030..b4a6e3b0c88 100644 --- a/libraries/USB/examples/FirmwareMSC/FirmwareMSC.ino +++ b/libraries/USB/examples/FirmwareMSC/FirmwareMSC.ino @@ -2,8 +2,8 @@ #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 1 #warning This sketch should be used when USB is in OTG mode -void setup(){} -void loop(){} +void setup() {} +void loop() {} #else #include "USB.h" #include "FirmwareMSC.h" @@ -12,10 +12,10 @@ void loop(){} FirmwareMSC MSC_Update; #endif -static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data){ - if(event_base == ARDUINO_USB_EVENTS){ - arduino_usb_event_data_t * data = (arduino_usb_event_data_t*)event_data; - switch (event_id){ +static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { + if (event_base == ARDUINO_USB_EVENTS) { + arduino_usb_event_data_t* data = (arduino_usb_event_data_t*)event_data; + switch (event_id) { case ARDUINO_USB_STARTED_EVENT: Serial.println("USB PLUGGED"); break; @@ -28,13 +28,13 @@ static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t eve case ARDUINO_USB_RESUME_EVENT: Serial.println("USB RESUMED"); break; - + default: break; } - } else if(event_base == ARDUINO_FIRMWARE_MSC_EVENTS){ - arduino_firmware_msc_event_data_t * data = (arduino_firmware_msc_event_data_t*)event_data; - switch (event_id){ + } else if (event_base == ARDUINO_FIRMWARE_MSC_EVENTS) { + arduino_firmware_msc_event_data_t* data = (arduino_firmware_msc_event_data_t*)event_data; + switch (event_id) { case ARDUINO_FIRMWARE_MSC_START_EVENT: Serial.println("MSC Update Start"); break; @@ -51,7 +51,7 @@ static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t eve case ARDUINO_FIRMWARE_MSC_POWER_EVENT: Serial.printf("MSC Update Power: power: %u, start: %u, eject: %u", data->power.power_condition, data->power.start, data->power.load_eject); break; - + default: break; } diff --git a/libraries/USB/examples/Gamepad/Gamepad.ino b/libraries/USB/examples/Gamepad/Gamepad.ino index 778a8766955..395f068580b 100644 --- a/libraries/USB/examples/Gamepad/Gamepad.ino +++ b/libraries/USB/examples/Gamepad/Gamepad.ino @@ -2,8 +2,8 @@ #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 1 #warning This sketch should be used when USB is in OTG mode -void setup(){} -void loop(){} +void setup() {} +void loop() {} #else #include "USB.h" #include "USBHIDGamepad.h" @@ -26,16 +26,16 @@ void setup() { void loop() { static uint8_t padID = 0; static long lastPress = 0; - + int buttonState = digitalRead(buttonPin); if (buttonState != previousButtonState) { - if (buttonState == LOW) { // BOOT Button pressed - Gamepad.pressButton(padID); // Buttons 1 to 32 - Gamepad.leftStick(padID << 3, padID << 3); // X Axis, Y Axis - Gamepad.rightStick(-(padID << 2), padID << 2); // Z Axis, Z Rotation - Gamepad.leftTrigger(padID << 4); // X Rotation - Gamepad.rightTrigger(-(padID << 4)); // Y Rotation - Gamepad.hat((padID & 0x7) + 1); // Point of View Hat + if (buttonState == LOW) { // BOOT Button pressed + Gamepad.pressButton(padID); // Buttons 1 to 32 + Gamepad.leftStick(padID << 3, padID << 3); // X Axis, Y Axis + Gamepad.rightStick(-(padID << 2), padID << 2); // Z Axis, Z Rotation + Gamepad.leftTrigger(padID << 4); // X Rotation + Gamepad.rightTrigger(-(padID << 4)); // Y Rotation + Gamepad.hat((padID & 0x7) + 1); // Point of View Hat log_d("Pressed PadID [%d]", padID); lastPress = millis(); } else { @@ -44,7 +44,7 @@ void loop() { Gamepad.rightStick(0, 0); Gamepad.leftTrigger(0); Gamepad.rightTrigger(0); - Gamepad.hat(HAT_CENTER); + Gamepad.hat(HAT_CENTER); log_d("Released PadID [%d]\n", padID); if (millis() - lastPress > 300) { padID = (padID + 1) & 0x1F; diff --git a/libraries/USB/examples/HIDVendor/HIDVendor.ino b/libraries/USB/examples/HIDVendor/HIDVendor.ino index e3a847f7c48..e3bb3c03c0a 100644 --- a/libraries/USB/examples/HIDVendor/HIDVendor.ino +++ b/libraries/USB/examples/HIDVendor/HIDVendor.ino @@ -2,8 +2,8 @@ #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 1 #warning This sketch should be used when USB is in OTG mode -void setup(){} -void loop(){} +void setup() {} +void loop() {} #else #include "USB.h" #include "USBHIDVendor.h" @@ -12,17 +12,17 @@ USBHIDVendor Vendor; const int buttonPin = 0; int previousButtonState = HIGH; -static void vendorEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data){ - if(event_base == ARDUINO_USB_HID_VENDOR_EVENTS){ - arduino_usb_hid_vendor_event_data_t * data = (arduino_usb_hid_vendor_event_data_t*)event_data; - switch (event_id){ +static void vendorEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { + if (event_base == ARDUINO_USB_HID_VENDOR_EVENTS) { + arduino_usb_hid_vendor_event_data_t* data = (arduino_usb_hid_vendor_event_data_t*)event_data; + switch (event_id) { case ARDUINO_USB_HID_VENDOR_GET_FEATURE_EVENT: Serial.printf("HID VENDOR GET FEATURE: len:%u\n", data->len); break; case ARDUINO_USB_HID_VENDOR_SET_FEATURE_EVENT: Serial.printf("HID VENDOR SET FEATURE: len:%u\n", data->len); - for(uint16_t i=0; ilen; i++){ - Serial.printf("0x%02X ",*(data->buffer)); + for (uint16_t i = 0; i < data->len; i++) { + Serial.printf("0x%02X ", *(data->buffer)); } Serial.println(); break; @@ -32,7 +32,7 @@ static void vendorEventCallback(void* arg, esp_event_base_t event_base, int32_t // Serial.write(Vendor.read()); // } break; - + default: break; } @@ -53,7 +53,7 @@ void loop() { Vendor.println("Hello World!"); } previousButtonState = buttonState; - while(Vendor.available()){ + while (Vendor.available()) { Serial.write(Vendor.read()); } } diff --git a/libraries/USB/examples/Keyboard/KeyboardLogout/KeyboardLogout.ino b/libraries/USB/examples/Keyboard/KeyboardLogout/KeyboardLogout.ino index 9e168223e21..30754bb2b6f 100644 --- a/libraries/USB/examples/Keyboard/KeyboardLogout/KeyboardLogout.ino +++ b/libraries/USB/examples/Keyboard/KeyboardLogout/KeyboardLogout.ino @@ -28,8 +28,8 @@ #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 1 #warning This sketch should be used when USB is in OTG mode -void setup(){} -void loop(){} +void setup() {} +void loop() {} #else #define OSX 0 @@ -43,7 +43,7 @@ USBHIDKeyboard Keyboard; // change this to match your platform: int platform = OSX; -const int buttonPin = 0; // input pin for pushbutton +const int buttonPin = 0; // input pin for pushbutton void setup() { // make pin 0 an input and turn on the pull-up resistor so it goes high unless diff --git a/libraries/USB/examples/Keyboard/KeyboardMessage/KeyboardMessage.ino b/libraries/USB/examples/Keyboard/KeyboardMessage/KeyboardMessage.ino index 713f369717a..359e9c52834 100644 --- a/libraries/USB/examples/Keyboard/KeyboardMessage/KeyboardMessage.ino +++ b/libraries/USB/examples/Keyboard/KeyboardMessage/KeyboardMessage.ino @@ -23,17 +23,17 @@ #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 1 #warning This sketch should be used when USB is in OTG mode -void setup(){} -void loop(){} +void setup() {} +void loop() {} #else #include "USB.h" #include "USBHIDKeyboard.h" USBHIDKeyboard Keyboard; -const int buttonPin = 0; // input pin for pushbutton -int previousButtonState = HIGH; // for checking the state of a pushButton -int counter = 0; // button push counter +const int buttonPin = 0; // input pin for pushbutton +int previousButtonState = HIGH; // for checking the state of a pushButton +int counter = 0; // button push counter void setup() { // make the pushButton pin an input: diff --git a/libraries/USB/examples/Keyboard/KeyboardReprogram/KeyboardReprogram.ino b/libraries/USB/examples/Keyboard/KeyboardReprogram/KeyboardReprogram.ino index 91bf27b81e9..9ea50887536 100644 --- a/libraries/USB/examples/Keyboard/KeyboardReprogram/KeyboardReprogram.ino +++ b/libraries/USB/examples/Keyboard/KeyboardReprogram/KeyboardReprogram.ino @@ -28,15 +28,15 @@ #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 1 #warning This sketch should be used when USB is in OTG mode -void setup(){} -void loop(){} +void setup() {} +void loop() {} #else #include "USB.h" #include "USBHIDKeyboard.h" USBHIDKeyboard Keyboard; -const int buttonPin = 0; // input pin for pushbutton +const int buttonPin = 0; // input pin for pushbutton // use this option for OSX. // Comment it out if using Windows or Linux: @@ -111,6 +111,6 @@ void loop() { Keyboard.releaseAll(); // wait for the sweet oblivion of reprogramming: - while (true)delay(1000); + while (true) delay(1000); } #endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/Keyboard/KeyboardSerial/KeyboardSerial.ino b/libraries/USB/examples/Keyboard/KeyboardSerial/KeyboardSerial.ino index aab262df3ca..46da87d2ce3 100644 --- a/libraries/USB/examples/Keyboard/KeyboardSerial/KeyboardSerial.ino +++ b/libraries/USB/examples/Keyboard/KeyboardSerial/KeyboardSerial.ino @@ -20,8 +20,8 @@ #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 1 #warning This sketch should be used when USB is in OTG mode -void setup(){} -void loop(){} +void setup() {} +void loop() {} #else #include "USB.h" diff --git a/libraries/USB/examples/KeyboardAndMouseControl/KeyboardAndMouseControl.ino b/libraries/USB/examples/KeyboardAndMouseControl/KeyboardAndMouseControl.ino index 3168bc72ab9..02cb4f57da5 100644 --- a/libraries/USB/examples/KeyboardAndMouseControl/KeyboardAndMouseControl.ino +++ b/libraries/USB/examples/KeyboardAndMouseControl/KeyboardAndMouseControl.ino @@ -22,8 +22,8 @@ #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 1 #warning This sketch should be used when USB is in OTG mode -void setup(){} -void loop(){} +void setup() {} +void loop() {} #else #include "USB.h" @@ -39,7 +39,7 @@ const int leftButton = 14; const int rightButton = 15; const int mouseButton = 0; -void setup() { // initialize the buttons' inputs: +void setup() { // initialize the buttons' inputs: pinMode(upButton, INPUT_PULLUP); pinMode(downButton, INPUT_PULLUP); pinMode(leftButton, INPUT_PULLUP); diff --git a/libraries/USB/examples/MIDI/MidiController/MidiController.ino b/libraries/USB/examples/MIDI/MidiController/MidiController.ino index a140f3831a7..a7b7f785054 100644 --- a/libraries/USB/examples/MIDI/MidiController/MidiController.ino +++ b/libraries/USB/examples/MIDI/MidiController/MidiController.ino @@ -35,19 +35,19 @@ USBMIDI MIDI; static double controllerInputValue = 0; void updateControllerInputValue() { - controllerInputValue = - (controllerInputValue * (SMOOTHING_VALUE - 1) + analogRead(CONTROLLER_PIN)) / SMOOTHING_VALUE; + controllerInputValue = + (controllerInputValue * (SMOOTHING_VALUE - 1) + analogRead(CONTROLLER_PIN)) / SMOOTHING_VALUE; } void primeControllerInputValue() { - for (int i = 0; i < SMOOTHING_VALUE; i++) { - updateControllerInputValue(); - } + for (int i = 0; i < SMOOTHING_VALUE; i++) { + updateControllerInputValue(); + } } uint16_t readControllerValue() { - // Lower ADC input amplitude to get a stable value - return round(controllerInputValue / 12); + // Lower ADC input amplitude to get a stable value + return round(controllerInputValue / 12); } ///// Button Handling ///// @@ -59,60 +59,60 @@ uint16_t readControllerValue() { #define PRESSED 0xff00 #define RELEASED 0xfe1f uint16_t getButtonEvent() { - static uint16_t state = 0; - state = (state << 1) | digitalRead(BUTTON_PIN) | 0xfe00; - return state; + static uint16_t state = 0; + state = (state << 1) | digitalRead(BUTTON_PIN) | 0xfe00; + return state; } ///// Arduino Hooks ///// void setup() { - Serial.begin(115200); - MIDI.begin(); - USB.begin(); + Serial.begin(115200); + MIDI.begin(); + USB.begin(); - primeControllerInputValue(); + primeControllerInputValue(); } void loop() { - uint16_t newControllerValue = readControllerValue(); - static uint16_t lastControllerValue = 0; - - // Auto-calibrate the controller range - static uint16_t maxControllerValue = 0; - static uint16_t minControllerValue = 0xFFFF; - - if (newControllerValue < minControllerValue) { - minControllerValue = newControllerValue; - } - if (newControllerValue > maxControllerValue) { - maxControllerValue = newControllerValue; - } - - // Send update if the controller value has changed - if (lastControllerValue != newControllerValue) { - lastControllerValue = newControllerValue; - - // Can't map if the range is zero - if (minControllerValue != maxControllerValue) { - MIDI.controlChange(MIDI_CC_CUTOFF, - map(newControllerValue, minControllerValue, maxControllerValue, 0, 127)); - } - } - - updateControllerInputValue(); - - // Hook Button0 to a MIDI note so that we can observe - // the CC effect without the need for a MIDI keyboard. - switch (getButtonEvent()) { - case PRESSED: - MIDI.noteOn(MIDI_NOTE_C4, 64); - break; - case RELEASED: - MIDI.noteOff(MIDI_NOTE_C4, 0); - break; - default: - break; + uint16_t newControllerValue = readControllerValue(); + static uint16_t lastControllerValue = 0; + + // Auto-calibrate the controller range + static uint16_t maxControllerValue = 0; + static uint16_t minControllerValue = 0xFFFF; + + if (newControllerValue < minControllerValue) { + minControllerValue = newControllerValue; + } + if (newControllerValue > maxControllerValue) { + maxControllerValue = newControllerValue; + } + + // Send update if the controller value has changed + if (lastControllerValue != newControllerValue) { + lastControllerValue = newControllerValue; + + // Can't map if the range is zero + if (minControllerValue != maxControllerValue) { + MIDI.controlChange(MIDI_CC_CUTOFF, + map(newControllerValue, minControllerValue, maxControllerValue, 0, 127)); } + } + + updateControllerInputValue(); + + // Hook Button0 to a MIDI note so that we can observe + // the CC effect without the need for a MIDI keyboard. + switch (getButtonEvent()) { + case PRESSED: + MIDI.noteOn(MIDI_NOTE_C4, 64); + break; + case RELEASED: + MIDI.noteOff(MIDI_NOTE_C4, 0); + break; + default: + break; + } } #endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/MIDI/MidiInterface/MidiInterface.ino b/libraries/USB/examples/MIDI/MidiInterface/MidiInterface.ino index 6fb99d8ab95..e91a6cf904e 100644 --- a/libraries/USB/examples/MIDI/MidiInterface/MidiInterface.ino +++ b/libraries/USB/examples/MIDI/MidiInterface/MidiInterface.ino @@ -32,39 +32,39 @@ USBMIDI MIDI; #define MIDI_TX 40 void setup() { - // USBCDC Serial - Serial.begin(115200); + // USBCDC Serial + Serial.begin(115200); - // HW UART Serial - Serial1.begin(31250, SERIAL_8N1, MIDI_RX, MIDI_TX); + // HW UART Serial + Serial1.begin(31250, SERIAL_8N1, MIDI_RX, MIDI_TX); - MIDI.begin(); - USB.begin(); + MIDI.begin(); + USB.begin(); } void loop() { - // MIDI Serial 1.0 to USB MIDI 1.0 - if (Serial1.available()) { - byte data = Serial1.read(); - MIDI.write(data); - } + // MIDI Serial 1.0 to USB MIDI 1.0 + if (Serial1.available()) { + byte data = Serial1.read(); + MIDI.write(data); + } - // USB MIDI 1.0 to MIDI Serial 1.0 - midiEventPacket_t midi_packet_in = {0}; - // See Chapter 4: USB-MIDI Event Packets (page 16) of the spec. - int8_t cin_to_midix_size[16] = {-1, -1, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1}; + // USB MIDI 1.0 to MIDI Serial 1.0 + midiEventPacket_t midi_packet_in = { 0 }; + // See Chapter 4: USB-MIDI Event Packets (page 16) of the spec. + int8_t cin_to_midix_size[16] = { -1, -1, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1 }; - if (MIDI.readPacket(&midi_packet_in)) { - midi_code_index_number_t code_index_num = MIDI_EP_HEADER_CIN_GET(midi_packet_in.header); - int8_t midix_size = cin_to_midix_size[code_index_num]; + if (MIDI.readPacket(&midi_packet_in)) { + midi_code_index_number_t code_index_num = MIDI_EP_HEADER_CIN_GET(midi_packet_in.header); + int8_t midix_size = cin_to_midix_size[code_index_num]; - // We skip Misc and Cable Events for simplicity - if (code_index_num >= 0x2) { - for (int i = 0; i < midix_size; i++) { - Serial1.write(((uint8_t *)&midi_packet_in)[i + 1]); - } - Serial1.flush(); - } + // We skip Misc and Cable Events for simplicity + if (code_index_num >= 0x2) { + for (int i = 0; i < midix_size; i++) { + Serial1.write(((uint8_t *)&midi_packet_in)[i + 1]); + } + Serial1.flush(); } + } } #endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/MIDI/MidiMusicBox/MidiMusicBox.ino b/libraries/USB/examples/MIDI/MidiMusicBox/MidiMusicBox.ino index 1d540324943..f2f33b156d9 100644 --- a/libraries/USB/examples/MIDI/MidiMusicBox/MidiMusicBox.ino +++ b/libraries/USB/examples/MIDI/MidiMusicBox/MidiMusicBox.ino @@ -21,39 +21,39 @@ void loop() {} USBMIDI MIDI; #define END_OF_SONG 255 -uint8_t notes[] = {END_OF_SONG, 71, 76, 79, 78, 76, 83, 81, 78, 76, 79, 78, 75, 77, 71}; -uint8_t noteIndex = 0; // From 0 to sizeof(notes) -#define SONG_LENGTH (sizeof(notes) - 1) // END_OF_SONG does not attribute to the length. +uint8_t notes[] = { END_OF_SONG, 71, 76, 79, 78, 76, 83, 81, 78, 76, 79, 78, 75, 77, 71 }; +uint8_t noteIndex = 0; // From 0 to sizeof(notes) +#define SONG_LENGTH (sizeof(notes) - 1) // END_OF_SONG does not attribute to the length. #define BUTTON_PIN 0 // Simple button press check with debounce // (See also: https://tinyurl.com/simple-debounce) bool isButtonPressed() { - static uint16_t state = 0; - state = (state << 1) | digitalRead(BUTTON_PIN) | 0xfe00; - return (state == 0xff00); + static uint16_t state = 0; + state = (state << 1) | digitalRead(BUTTON_PIN) | 0xfe00; + return (state == 0xff00); } void setup() { - Serial.begin(115200); - // Make the BUTTON_PIN an input: - pinMode(BUTTON_PIN, INPUT_PULLUP); + Serial.begin(115200); + // Make the BUTTON_PIN an input: + pinMode(BUTTON_PIN, INPUT_PULLUP); - MIDI.begin(); - USB.begin(); + MIDI.begin(); + USB.begin(); } void loop() { - if (isButtonPressed()) { - // Stop current note - MIDI.noteOff(notes[noteIndex]); - - // Play next note - noteIndex = noteIndex < SONG_LENGTH ? noteIndex + 1 : 0; - if (notes[noteIndex] != END_OF_SONG) { - MIDI.noteOn(notes[noteIndex], 64); - } + if (isButtonPressed()) { + // Stop current note + MIDI.noteOff(notes[noteIndex]); + + // Play next note + noteIndex = noteIndex < SONG_LENGTH ? noteIndex + 1 : 0; + if (notes[noteIndex] != END_OF_SONG) { + MIDI.noteOn(notes[noteIndex], 64); } + } } #endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/MIDI/ReceiveMidi/ReceiveMidi.ino b/libraries/USB/examples/MIDI/ReceiveMidi/ReceiveMidi.ino index 4f1bf4273e2..d33c24cd1f5 100644 --- a/libraries/USB/examples/MIDI/ReceiveMidi/ReceiveMidi.ino +++ b/libraries/USB/examples/MIDI/ReceiveMidi/ReceiveMidi.ino @@ -21,84 +21,84 @@ void loop() {} USBMIDI MIDI; void setup() { - Serial.begin(115200); + Serial.begin(115200); - MIDI.begin(); - USB.begin(); + MIDI.begin(); + USB.begin(); } void loop() { - midiEventPacket_t midi_packet_in = {0}; + midiEventPacket_t midi_packet_in = { 0 }; - if (MIDI.readPacket(&midi_packet_in)) { - printDetails(midi_packet_in); - } + if (MIDI.readPacket(&midi_packet_in)) { + printDetails(midi_packet_in); + } } void printDetails(midiEventPacket_t &midi_packet_in) { - // See Chapter 4: USB-MIDI Event Packets (page 16) of the spec. - uint8_t cable_num = MIDI_EP_HEADER_CN_GET(midi_packet_in.header); - midi_code_index_number_t code_index_num = MIDI_EP_HEADER_CIN_GET(midi_packet_in.header); + // See Chapter 4: USB-MIDI Event Packets (page 16) of the spec. + uint8_t cable_num = MIDI_EP_HEADER_CN_GET(midi_packet_in.header); + midi_code_index_number_t code_index_num = MIDI_EP_HEADER_CIN_GET(midi_packet_in.header); - Serial.println("Received a USB MIDI packet:"); - Serial.println(".----.-----.--------.--------.--------."); - Serial.println("| CN | CIN | STATUS | DATA 0 | DATA 1 |"); - Serial.println("+----+-----+--------+--------+--------+"); - Serial.printf("| %d | %X | %X | %X | %X |\n", cable_num, code_index_num, - midi_packet_in.byte1, midi_packet_in.byte2, midi_packet_in.byte3); - Serial.println("'----'-----'--------.--------'--------'\n"); - Serial.print("Description: "); + Serial.println("Received a USB MIDI packet:"); + Serial.println(".----.-----.--------.--------.--------."); + Serial.println("| CN | CIN | STATUS | DATA 0 | DATA 1 |"); + Serial.println("+----+-----+--------+--------+--------+"); + Serial.printf("| %d | %X | %X | %X | %X |\n", cable_num, code_index_num, + midi_packet_in.byte1, midi_packet_in.byte2, midi_packet_in.byte3); + Serial.println("'----'-----'--------.--------'--------'\n"); + Serial.print("Description: "); - switch (code_index_num) { - case MIDI_CIN_MISC: - Serial.println("This a Miscellaneous event"); - break; - case MIDI_CIN_CABLE_EVENT: - Serial.println("This a Cable event"); - break; - case MIDI_CIN_SYSCOM_2BYTE: // 2 byte system common message e.g MTC, SongSelect - case MIDI_CIN_SYSCOM_3BYTE: // 3 byte system common message e.g SPP - Serial.println("This a System Common (SysCom) event"); - break; - case MIDI_CIN_SYSEX_START: // SysEx starts or continue - case MIDI_CIN_SYSEX_END_1BYTE: // SysEx ends with 1 data, or 1 byte system common message - case MIDI_CIN_SYSEX_END_2BYTE: // SysEx ends with 2 data - case MIDI_CIN_SYSEX_END_3BYTE: // SysEx ends with 3 data - Serial.println("This a system exclusive (SysEx) event"); - break; - case MIDI_CIN_NOTE_ON: - Serial.printf("This a Note-On event of Note %d with a Velocity of %d\n", - midi_packet_in.byte2, midi_packet_in.byte3); - break; - case MIDI_CIN_NOTE_OFF: - Serial.printf("This a Note-Off event of Note %d with a Velocity of %d\n", - midi_packet_in.byte2, midi_packet_in.byte3); - break; - case MIDI_CIN_POLY_KEYPRESS: - Serial.printf("This a Poly Aftertouch event for Note %d and Value %d\n", - midi_packet_in.byte2, midi_packet_in.byte3); - break; - case MIDI_CIN_CONTROL_CHANGE: - Serial.printf("This a Control Change/Continuous Controller (CC) event of Controller %d " - "with a Value of %d\n", - midi_packet_in.byte2, midi_packet_in.byte3); - break; - case MIDI_CIN_PROGRAM_CHANGE: - Serial.printf("This a Program Change event with a Value of %d\n", midi_packet_in.byte2); - break; - case MIDI_CIN_CHANNEL_PRESSURE: - Serial.printf("This a Channel Pressure event with a Value of %d\n", midi_packet_in.byte2); - break; - case MIDI_CIN_PITCH_BEND_CHANGE: - Serial.printf("This a Pitch Bend Change event with a Value of %d\n", - ((uint16_t)midi_packet_in.byte2) << 7 | midi_packet_in.byte3); - break; - case MIDI_CIN_1BYTE_DATA: - Serial.printf("This an embedded Serial MIDI event byte with Value %X\n", - midi_packet_in.byte1); - break; - } + switch (code_index_num) { + case MIDI_CIN_MISC: + Serial.println("This a Miscellaneous event"); + break; + case MIDI_CIN_CABLE_EVENT: + Serial.println("This a Cable event"); + break; + case MIDI_CIN_SYSCOM_2BYTE: // 2 byte system common message e.g MTC, SongSelect + case MIDI_CIN_SYSCOM_3BYTE: // 3 byte system common message e.g SPP + Serial.println("This a System Common (SysCom) event"); + break; + case MIDI_CIN_SYSEX_START: // SysEx starts or continue + case MIDI_CIN_SYSEX_END_1BYTE: // SysEx ends with 1 data, or 1 byte system common message + case MIDI_CIN_SYSEX_END_2BYTE: // SysEx ends with 2 data + case MIDI_CIN_SYSEX_END_3BYTE: // SysEx ends with 3 data + Serial.println("This a system exclusive (SysEx) event"); + break; + case MIDI_CIN_NOTE_ON: + Serial.printf("This a Note-On event of Note %d with a Velocity of %d\n", + midi_packet_in.byte2, midi_packet_in.byte3); + break; + case MIDI_CIN_NOTE_OFF: + Serial.printf("This a Note-Off event of Note %d with a Velocity of %d\n", + midi_packet_in.byte2, midi_packet_in.byte3); + break; + case MIDI_CIN_POLY_KEYPRESS: + Serial.printf("This a Poly Aftertouch event for Note %d and Value %d\n", + midi_packet_in.byte2, midi_packet_in.byte3); + break; + case MIDI_CIN_CONTROL_CHANGE: + Serial.printf("This a Control Change/Continuous Controller (CC) event of Controller %d " + "with a Value of %d\n", + midi_packet_in.byte2, midi_packet_in.byte3); + break; + case MIDI_CIN_PROGRAM_CHANGE: + Serial.printf("This a Program Change event with a Value of %d\n", midi_packet_in.byte2); + break; + case MIDI_CIN_CHANNEL_PRESSURE: + Serial.printf("This a Channel Pressure event with a Value of %d\n", midi_packet_in.byte2); + break; + case MIDI_CIN_PITCH_BEND_CHANGE: + Serial.printf("This a Pitch Bend Change event with a Value of %d\n", + ((uint16_t)midi_packet_in.byte2) << 7 | midi_packet_in.byte3); + break; + case MIDI_CIN_1BYTE_DATA: + Serial.printf("This an embedded Serial MIDI event byte with Value %X\n", + midi_packet_in.byte1); + break; + } - Serial.println(); + Serial.println(); } #endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/examples/Mouse/ButtonMouseControl/ButtonMouseControl.ino b/libraries/USB/examples/Mouse/ButtonMouseControl/ButtonMouseControl.ino index 7475d201ffb..88bc5263c90 100644 --- a/libraries/USB/examples/Mouse/ButtonMouseControl/ButtonMouseControl.ino +++ b/libraries/USB/examples/Mouse/ButtonMouseControl/ButtonMouseControl.ino @@ -24,8 +24,8 @@ #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 1 #warning This sketch should be used when USB is in OTG mode -void setup(){} -void loop(){} +void setup() {} +void loop() {} #else #include "USB.h" @@ -40,8 +40,8 @@ const int leftButton = 14; const int rightButton = 15; const int mouseButton = 0; -int range = 5; // output range of X or Y movement; affects movement speed -int responseDelay = 10; // response delay of the mouse, in ms +int range = 5; // output range of X or Y movement; affects movement speed +int responseDelay = 10; // response delay of the mouse, in ms void setup() { @@ -65,8 +65,8 @@ void loop() { int clickState = digitalRead(mouseButton); // calculate the movement distance based on the button states: - int xDistance = (leftState - rightState) * range; - int yDistance = (upState - downState) * range; + int xDistance = (leftState - rightState) * range; + int yDistance = (upState - downState) * range; // if X or Y is non-zero, move: if ((xDistance != 0) || (yDistance != 0)) { diff --git a/libraries/USB/examples/SystemControl/SystemControl.ino b/libraries/USB/examples/SystemControl/SystemControl.ino index e0d394b5f43..019ed032812 100644 --- a/libraries/USB/examples/SystemControl/SystemControl.ino +++ b/libraries/USB/examples/SystemControl/SystemControl.ino @@ -2,8 +2,8 @@ #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 1 #warning This sketch should be used when USB is in OTG mode -void setup(){} -void loop(){} +void setup() {} +void loop() {} #else #include "USB.h" #include "USBHIDSystemControl.h" diff --git a/libraries/USB/examples/USBMSC/USBMSC.ino b/libraries/USB/examples/USBMSC/USBMSC.ino index e19822449bd..c4085c98c66 100644 --- a/libraries/USB/examples/USBMSC/USBMSC.ino +++ b/libraries/USB/examples/USBMSC/USBMSC.ino @@ -2,53 +2,52 @@ #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 1 #warning This sketch should be used when USB is in OTG mode -void setup(){} -void loop(){} +void setup() {} +void loop() {} #else #include "USB.h" #include "USBMSC.h" USBMSC MSC; -#define FAT_U8(v) ((v) & 0xFF) +#define FAT_U8(v) ((v)&0xFF) #define FAT_U16(v) FAT_U8(v), FAT_U8((v) >> 8) #define FAT_U32(v) FAT_U8(v), FAT_U8((v) >> 8), FAT_U8((v) >> 16), FAT_U8((v) >> 24) -#define FAT_MS2B(s,ms) FAT_U8(((((s) & 0x1) * 1000) + (ms)) / 10) -#define FAT_HMS2B(h,m,s) FAT_U8(((s) >> 1)|(((m) & 0x7) << 5)), FAT_U8((((m) >> 3) & 0x7)|((h) << 3)) -#define FAT_YMD2B(y,m,d) FAT_U8(((d) & 0x1F)|(((m) & 0x7) << 5)), FAT_U8((((m) >> 3) & 0x1)|((((y) - 1980) & 0x7F) << 1)) -#define FAT_TBL2B(l,h) FAT_U8(l), FAT_U8(((l >> 8) & 0xF) | ((h << 4) & 0xF0)), FAT_U8(h >> 4) +#define FAT_MS2B(s, ms) FAT_U8(((((s)&0x1) * 1000) + (ms)) / 10) +#define FAT_HMS2B(h, m, s) FAT_U8(((s) >> 1) | (((m)&0x7) << 5)), FAT_U8((((m) >> 3) & 0x7) | ((h) << 3)) +#define FAT_YMD2B(y, m, d) FAT_U8(((d)&0x1F) | (((m)&0x7) << 5)), FAT_U8((((m) >> 3) & 0x1) | ((((y)-1980) & 0x7F) << 1)) +#define FAT_TBL2B(l, h) FAT_U8(l), FAT_U8(((l >> 8) & 0xF) | ((h << 4) & 0xF0)), FAT_U8(h >> 4) #define README_CONTENTS "This is tinyusb's MassStorage Class demo.\r\n\r\nIf you find any bugs or get any questions, feel free to file an\r\nissue at github.com/hathach/tinyusb" -static const uint32_t DISK_SECTOR_COUNT = 2 * 8; // 8KB is the smallest size that windows allow to mount -static const uint16_t DISK_SECTOR_SIZE = 512; // Should be 512 -static const uint16_t DISC_SECTORS_PER_TABLE = 1; //each table sector can fit 170KB (340 sectors) +static const uint32_t DISK_SECTOR_COUNT = 2 * 8; // 8KB is the smallest size that windows allow to mount +static const uint16_t DISK_SECTOR_SIZE = 512; // Should be 512 +static const uint16_t DISC_SECTORS_PER_TABLE = 1; //each table sector can fit 170KB (340 sectors) -static uint8_t msc_disk[DISK_SECTOR_COUNT][DISK_SECTOR_SIZE] = -{ +static uint8_t msc_disk[DISK_SECTOR_COUNT][DISK_SECTOR_SIZE] = { //------------- Block0: Boot Sector -------------// { // Header (62 bytes) - 0xEB, 0x3C, 0x90, //jump_instruction - 'M' , 'S' , 'D' , 'O' , 'S' , '5' , '.' , '0' , //oem_name - FAT_U16(DISK_SECTOR_SIZE), //bytes_per_sector - FAT_U8(1), //sectors_per_cluster - FAT_U16(1), //reserved_sectors_count - FAT_U8(1), //file_alloc_tables_num - FAT_U16(16), //max_root_dir_entries - FAT_U16(DISK_SECTOR_COUNT), //fat12_sector_num - 0xF8, //media_descriptor - FAT_U16(DISC_SECTORS_PER_TABLE), //sectors_per_alloc_table;//FAT12 and FAT16 - FAT_U16(1), //sectors_per_track;//A value of 0 may indicate LBA-only access - FAT_U16(1), //num_heads - FAT_U32(0), //hidden_sectors_count - FAT_U32(0), //total_sectors_32 - 0x00, //physical_drive_number;0x00 for (first) removable media, 0x80 for (first) fixed disk - 0x00, //reserved - 0x29, //extended_boot_signature;//should be 0x29 - FAT_U32(0x1234), //serial_number: 0x1234 => 1234 - 'T' , 'i' , 'n' , 'y' , 'U' , 'S' , 'B' , ' ' , 'M' , 'S' , 'C' , //volume_label padded with spaces (0x20) - 'F' , 'A' , 'T' , '1' , '2' , ' ' , ' ' , ' ' , //file_system_type padded with spaces (0x20) + 0xEB, 0x3C, 0x90, //jump_instruction + 'M', 'S', 'D', 'O', 'S', '5', '.', '0', //oem_name + FAT_U16(DISK_SECTOR_SIZE), //bytes_per_sector + FAT_U8(1), //sectors_per_cluster + FAT_U16(1), //reserved_sectors_count + FAT_U8(1), //file_alloc_tables_num + FAT_U16(16), //max_root_dir_entries + FAT_U16(DISK_SECTOR_COUNT), //fat12_sector_num + 0xF8, //media_descriptor + FAT_U16(DISC_SECTORS_PER_TABLE), //sectors_per_alloc_table;//FAT12 and FAT16 + FAT_U16(1), //sectors_per_track;//A value of 0 may indicate LBA-only access + FAT_U16(1), //num_heads + FAT_U32(0), //hidden_sectors_count + FAT_U32(0), //total_sectors_32 + 0x00, //physical_drive_number;0x00 for (first) removable media, 0x80 for (first) fixed disk + 0x00, //reserved + 0x29, //extended_boot_signature;//should be 0x29 + FAT_U32(0x1234), //serial_number: 0x1234 => 1234 + 'T', 'i', 'n', 'y', 'U', 'S', 'B', ' ', 'M', 'S', 'C', //volume_label padded with spaces (0x20) + 'F', 'A', 'T', '1', '2', ' ', ' ', ' ', //file_system_type padded with spaces (0x20) // Zero up to 2 last bytes of FAT magic code (448 bytes) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -83,73 +82,72 @@ static uint8_t msc_disk[DISK_SECTOR_COUNT][DISK_SECTOR_SIZE] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //boot signature (2 bytes) - 0x55, 0xAA - }, + //boot signature (2 bytes) + 0x55, 0xAA }, //------------- Block1: FAT12 Table -------------// { - FAT_TBL2B(0xFF8, 0xFFF), FAT_TBL2B(0xFFF, 0x000) // first 2 entries must be 0xFF8 0xFFF, third entry is cluster end of readme file + FAT_TBL2B(0xFF8, 0xFFF), FAT_TBL2B(0xFFF, 0x000) // first 2 entries must be 0xFF8 0xFFF, third entry is cluster end of readme file }, //------------- Block2: Root Directory -------------// { // first entry is volume label - 'E' , 'S' , 'P' , '3' , '2' , 'S' , '2' , ' ' , - 'M' , 'S' , 'C' , - 0x08, //FILE_ATTR_VOLUME_LABEL - 0x00, - FAT_MS2B(0,0), - FAT_HMS2B(0,0,0), - FAT_YMD2B(0,0,0), - FAT_YMD2B(0,0,0), - FAT_U16(0), - FAT_HMS2B(13,42,30), //last_modified_hms - FAT_YMD2B(2018,11,5), //last_modified_ymd - FAT_U16(0), + 'E', 'S', 'P', '3', '2', 'S', '2', ' ', + 'M', 'S', 'C', + 0x08, //FILE_ATTR_VOLUME_LABEL + 0x00, + FAT_MS2B(0, 0), + FAT_HMS2B(0, 0, 0), + FAT_YMD2B(0, 0, 0), + FAT_YMD2B(0, 0, 0), + FAT_U16(0), + FAT_HMS2B(13, 42, 30), //last_modified_hms + FAT_YMD2B(2018, 11, 5), //last_modified_ymd + FAT_U16(0), FAT_U32(0), - + // second entry is readme file - 'R' , 'E' , 'A' , 'D' , 'M' , 'E' , ' ' , ' ' ,//file_name[8]; padded with spaces (0x20) - 'T' , 'X' , 'T' , //file_extension[3]; padded with spaces (0x20) - 0x20, //file attributes: FILE_ATTR_ARCHIVE - 0x00, //ignore - FAT_MS2B(1,980), //creation_time_10_ms (max 199x10 = 1s 990ms) - FAT_HMS2B(13,42,36), //create_time_hms [5:6:5] => h:m:(s/2) - FAT_YMD2B(2018,11,5), //create_time_ymd [7:4:5] => (y+1980):m:d - FAT_YMD2B(2020,11,5), //last_access_ymd - FAT_U16(0), //extended_attributes - FAT_HMS2B(13,44,16), //last_modified_hms - FAT_YMD2B(2019,11,5), //last_modified_ymd - FAT_U16(2), //start of file in cluster - FAT_U32(sizeof(README_CONTENTS) - 1) //file size + 'R', 'E', 'A', 'D', 'M', 'E', ' ', ' ', //file_name[8]; padded with spaces (0x20) + 'T', 'X', 'T', //file_extension[3]; padded with spaces (0x20) + 0x20, //file attributes: FILE_ATTR_ARCHIVE + 0x00, //ignore + FAT_MS2B(1, 980), //creation_time_10_ms (max 199x10 = 1s 990ms) + FAT_HMS2B(13, 42, 36), //create_time_hms [5:6:5] => h:m:(s/2) + FAT_YMD2B(2018, 11, 5), //create_time_ymd [7:4:5] => (y+1980):m:d + FAT_YMD2B(2020, 11, 5), //last_access_ymd + FAT_U16(0), //extended_attributes + FAT_HMS2B(13, 44, 16), //last_modified_hms + FAT_YMD2B(2019, 11, 5), //last_modified_ymd + FAT_U16(2), //start of file in cluster + FAT_U32(sizeof(README_CONTENTS) - 1) //file size }, //------------- Block3: Readme Content -------------// README_CONTENTS }; -static int32_t onWrite(uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize){ +static int32_t onWrite(uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize) { Serial.printf("MSC WRITE: lba: %lu, offset: %lu, bufsize: %lu\n", lba, offset, bufsize); memcpy(msc_disk[lba] + offset, buffer, bufsize); return bufsize; } -static int32_t onRead(uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize){ +static int32_t onRead(uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize) { Serial.printf("MSC READ: lba: %lu, offset: %lu, bufsize: %lu\n", lba, offset, bufsize); memcpy(buffer, msc_disk[lba] + offset, bufsize); return bufsize; } -static bool onStartStop(uint8_t power_condition, bool start, bool load_eject){ +static bool onStartStop(uint8_t power_condition, bool start, bool load_eject) { Serial.printf("MSC START/STOP: power: %u, start: %u, eject: %u\n", power_condition, start, load_eject); return true; } -static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data){ - if(event_base == ARDUINO_USB_EVENTS){ - arduino_usb_event_data_t * data = (arduino_usb_event_data_t*)event_data; - switch (event_id){ +static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { + if (event_base == ARDUINO_USB_EVENTS) { + arduino_usb_event_data_t* data = (arduino_usb_event_data_t*)event_data; + switch (event_id) { case ARDUINO_USB_STARTED_EVENT: Serial.println("USB PLUGGED"); break; @@ -162,7 +160,7 @@ static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t eve case ARDUINO_USB_RESUME_EVENT: Serial.println("USB RESUMED"); break; - + default: break; } @@ -174,9 +172,9 @@ void setup() { Serial.setDebugOutput(true); USB.onEvent(usbEventCallback); - MSC.vendorID("ESP32");//max 8 chars - MSC.productID("USB_MSC");//max 16 chars - MSC.productRevision("1.0");//max 4 chars + MSC.vendorID("ESP32"); //max 8 chars + MSC.productID("USB_MSC"); //max 16 chars + MSC.productRevision("1.0"); //max 4 chars MSC.onStartStop(onStartStop); MSC.onRead(onRead); MSC.onWrite(onWrite); diff --git a/libraries/USB/examples/USBSerial/USBSerial.ino b/libraries/USB/examples/USBSerial/USBSerial.ino index 0dcc4fc3ff6..775aeb3fe25 100644 --- a/libraries/USB/examples/USBSerial/USBSerial.ino +++ b/libraries/USB/examples/USBSerial/USBSerial.ino @@ -2,8 +2,8 @@ #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 1 #warning This sketch should be used when USB is in OTG mode -void setup(){} -void loop(){} +void setup() {} +void loop() {} #else #include "USB.h" @@ -11,10 +11,10 @@ void loop(){} USBCDC USBSerial; #endif -static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data){ - if(event_base == ARDUINO_USB_EVENTS){ - arduino_usb_event_data_t * data = (arduino_usb_event_data_t*)event_data; - switch (event_id){ +static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { + if (event_base == ARDUINO_USB_EVENTS) { + arduino_usb_event_data_t* data = (arduino_usb_event_data_t*)event_data; + switch (event_id) { case ARDUINO_USB_STARTED_EVENT: Serial.println("USB PLUGGED"); break; @@ -27,13 +27,13 @@ static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t eve case ARDUINO_USB_RESUME_EVENT: Serial.println("USB RESUMED"); break; - + default: break; } - } else if(event_base == ARDUINO_USB_CDC_EVENTS){ - arduino_usb_cdc_event_data_t * data = (arduino_usb_cdc_event_data_t*)event_data; - switch (event_id){ + } else if (event_base == ARDUINO_USB_CDC_EVENTS) { + arduino_usb_cdc_event_data_t* data = (arduino_usb_cdc_event_data_t*)event_data; + switch (event_id) { case ARDUINO_USB_CDC_CONNECTED_EVENT: Serial.println("CDC CONNECTED"); break; @@ -49,16 +49,16 @@ static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t eve case ARDUINO_USB_CDC_RX_EVENT: Serial.printf("CDC RX [%u]:", data->rx.len); { - uint8_t buf[data->rx.len]; - size_t len = USBSerial.read(buf, data->rx.len); - Serial.write(buf, len); + uint8_t buf[data->rx.len]; + size_t len = USBSerial.read(buf, data->rx.len); + Serial.write(buf, len); } Serial.println(); break; - case ARDUINO_USB_CDC_RX_OVERFLOW_EVENT: + case ARDUINO_USB_CDC_RX_OVERFLOW_EVENT: Serial.printf("CDC RX Overflow of %d bytes", data->rx_overflow.dropped_bytes); break; - + default: break; } @@ -68,16 +68,16 @@ static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t eve void setup() { Serial.begin(115200); Serial.setDebugOutput(true); - + USB.onEvent(usbEventCallback); USBSerial.onEvent(usbEventCallback); - + USBSerial.begin(); USB.begin(); } void loop() { - while(Serial.available()){ + while (Serial.available()) { size_t l = Serial.available(); uint8_t b[l]; l = Serial.read(b, l); diff --git a/libraries/USB/examples/USBVendor/USBVendor.ino b/libraries/USB/examples/USBVendor/USBVendor.ino index 350c532b50d..9b3bdbc544d 100644 --- a/libraries/USB/examples/USBVendor/USBVendor.ino +++ b/libraries/USB/examples/USBVendor/USBVendor.ino @@ -2,8 +2,8 @@ #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 1 #warning This sketch should be used when USB is in OTG mode -void setup(){} -void loop(){} +void setup() {} +void loop() {} #else #include "USB.h" #include "USBVendor.h" @@ -17,14 +17,14 @@ const int buttonPin = 0; #define REQUEST_SET_CONTROL_LINE_STATE 0x22 //CDC Line Coding Control Request Structure -typedef struct __attribute__ ((packed)) { +typedef struct __attribute__((packed)) { uint32_t bit_rate; - uint8_t stop_bits; //0: 1 stop bit, 1: 1.5 stop bits, 2: 2 stop bits - uint8_t parity; //0: None, 1: Odd, 2: Even, 3: Mark, 4: Space - uint8_t data_bits; //5, 6, 7, 8 or 16 + uint8_t stop_bits; //0: 1 stop bit, 1: 1.5 stop bits, 2: 2 stop bits + uint8_t parity; //0: None, 1: Odd, 2: Even, 3: Mark, 4: Space + uint8_t data_bits; //5, 6, 7, 8 or 16 } request_line_coding_t; -static request_line_coding_t vendor_line_coding = {9600, 0, 0, 8}; +static request_line_coding_t vendor_line_coding = { 9600, 0, 0, 8 }; // Bit 0: DTR (Data Terminal Ready), Bit 1: RTS (Request to Send) static uint8_t vendor_line_state = 0; @@ -32,7 +32,7 @@ static uint8_t vendor_line_state = 0; //USB and Vendor events static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { if (event_base == ARDUINO_USB_EVENTS) { - arduino_usb_event_data_t * data = (arduino_usb_event_data_t*)event_data; + arduino_usb_event_data_t* data = (arduino_usb_event_data_t*)event_data; switch (event_id) { case ARDUINO_USB_STARTED_EVENT: Serial.println("USB PLUGGED"); @@ -51,7 +51,7 @@ static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t eve break; } } else if (event_base == ARDUINO_USB_VENDOR_EVENTS) { - arduino_usb_vendor_event_data_t * data = (arduino_usb_vendor_event_data_t*)event_data; + arduino_usb_vendor_event_data_t* data = (arduino_usb_vendor_event_data_t*)event_data; switch (event_id) { case ARDUINO_USB_VENDOR_DATA_EVENT: Serial.printf("Vendor RX: len:%u\n", data->data.len); @@ -67,27 +67,23 @@ static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t eve } } -static const char * strRequestDirections[] = {"OUT", "IN"}; -static const char * strRequestTypes[] = {"STANDARD", "CLASS", "VENDOR", "INVALID"}; -static const char * strRequestRecipients[] = {"DEVICE", "INTERFACE", "ENDPOINT", "OTHER"}; -static const char * strRequestStages[] = {"SETUP", "DATA", "ACK"}; +static const char* strRequestDirections[] = { "OUT", "IN" }; +static const char* strRequestTypes[] = { "STANDARD", "CLASS", "VENDOR", "INVALID" }; +static const char* strRequestRecipients[] = { "DEVICE", "INTERFACE", "ENDPOINT", "OTHER" }; +static const char* strRequestStages[] = { "SETUP", "DATA", "ACK" }; //Handle USB requests to the vendor interface -bool vendorRequestCallback(uint8_t rhport, uint8_t requestStage, arduino_usb_control_request_t const * request) { - Serial.printf("Vendor Request: Stage: %5s, Direction: %3s, Type: %8s, Recipient: %9s, bRequest: 0x%02x, wValue: 0x%04x, wIndex: %u, wLength: %u\n", - strRequestStages[requestStage], - strRequestDirections[request->bmRequestDirection], - strRequestTypes[request->bmRequestType], - strRequestRecipients[request->bmRequestRecipient], - request->bRequest, request->wValue, request->wIndex, request->wLength); +bool vendorRequestCallback(uint8_t rhport, uint8_t requestStage, arduino_usb_control_request_t const* request) { + Serial.printf("Vendor Request: Stage: %5s, Direction: %3s, Type: %8s, Recipient: %9s, bRequest: 0x%02x, wValue: 0x%04x, wIndex: %u, wLength: %u\n", + strRequestStages[requestStage], + strRequestDirections[request->bmRequestDirection], + strRequestTypes[request->bmRequestType], + strRequestRecipients[request->bmRequestRecipient], + request->bRequest, request->wValue, request->wIndex, request->wLength); bool result = false; - if (request->bmRequestDirection == REQUEST_DIRECTION_OUT && - request->bmRequestType == REQUEST_TYPE_STANDARD && - request->bmRequestRecipient == REQUEST_RECIPIENT_INTERFACE && - request->bRequest == 0x0b - ) { + if (request->bmRequestDirection == REQUEST_DIRECTION_OUT && request->bmRequestType == REQUEST_TYPE_STANDARD && request->bmRequestRecipient == REQUEST_RECIPIENT_INTERFACE && request->bRequest == 0x0b) { if (requestStage == REQUEST_STAGE_SETUP) { // response with status OK result = Vendor.sendResponse(rhport, request); @@ -99,14 +95,14 @@ bool vendorRequestCallback(uint8_t rhport, uint8_t requestStage, arduino_usb_con if (request->bmRequestType == REQUEST_TYPE_CLASS && request->bmRequestRecipient == REQUEST_RECIPIENT_DEVICE) { switch (request->bRequest) { - case REQUEST_SET_LINE_CODING: //0x20 + case REQUEST_SET_LINE_CODING: //0x20 // Accept only direction OUT with data size 7 if (request->wLength != sizeof(request_line_coding_t) || request->bmRequestDirection != REQUEST_DIRECTION_OUT) { break; } if (requestStage == REQUEST_STAGE_SETUP) { //Send the response in setup stage (it will write the data to vendor_line_coding in the DATA stage) - result = Vendor.sendResponse(rhport, request, (void*) &vendor_line_coding, sizeof(request_line_coding_t)); + result = Vendor.sendResponse(rhport, request, (void*)&vendor_line_coding, sizeof(request_line_coding_t)); } else if (requestStage == REQUEST_STAGE_ACK) { //In the ACK stage the response is complete Serial.printf("Vendor Line Coding: bit_rate: %lu, data_bits: %u, stop_bits: %u, parity: %u\n", vendor_line_coding.bit_rate, vendor_line_coding.data_bits, vendor_line_coding.stop_bits, vendor_line_coding.parity); @@ -114,19 +110,19 @@ bool vendorRequestCallback(uint8_t rhport, uint8_t requestStage, arduino_usb_con result = true; break; - case REQUEST_GET_LINE_CODING: //0x21 + case REQUEST_GET_LINE_CODING: //0x21 // Accept only direction IN with data size 7 if (request->wLength != sizeof(request_line_coding_t) || request->bmRequestDirection != REQUEST_DIRECTION_IN) { break; } if (requestStage == REQUEST_STAGE_SETUP) { //Send the response in setup stage (it will write the data to vendor_line_coding in the DATA stage) - result = Vendor.sendResponse(rhport, request, (void*) &vendor_line_coding, sizeof(request_line_coding_t)); + result = Vendor.sendResponse(rhport, request, (void*)&vendor_line_coding, sizeof(request_line_coding_t)); } result = true; break; - case REQUEST_SET_CONTROL_LINE_STATE: //0x22 + case REQUEST_SET_CONTROL_LINE_STATE: //0x22 // Accept only direction OUT with data size 0 if (request->wLength != 0 || request->bmRequestDirection != REQUEST_DIRECTION_OUT) { break; @@ -177,11 +173,11 @@ void loop() { if (buttonState == LOW) { Serial.println("Button Pressed"); Vendor.println("Button Pressed"); - Vendor.flush(); //Without flushing the data will only be sent when the buffer is full (64 bytes) + Vendor.flush(); //Without flushing the data will only be sent when the buffer is full (64 bytes) } else { Serial.println("Button Released"); Vendor.println("Button Released"); - Vendor.flush(); //Without flushing the data will only be sent when the buffer is full (64 bytes) + Vendor.flush(); //Without flushing the data will only be sent when the buffer is full (64 bytes) } delay(100); } @@ -191,7 +187,7 @@ void loop() { uint8_t b[l]; l = Serial.read(b, l); Vendor.write(b, l); - Vendor.flush(); //Without flushing the data will only be sent when the buffer is full (64 bytes) + Vendor.flush(); //Without flushing the data will only be sent when the buffer is full (64 bytes) } } #endif /* ARDUINO_USB_MODE */ diff --git a/libraries/USB/keywords.txt b/libraries/USB/keywords.txt index 932f72efece..e7ebc8fee2c 100644 --- a/libraries/USB/keywords.txt +++ b/libraries/USB/keywords.txt @@ -30,4 +30,3 @@ onWrite KEYWORD2 ####################################### # Constants (LITERAL1) ####################################### - diff --git a/libraries/USB/src/USBHID.cpp b/libraries/USB/src/USBHID.cpp index c48f0fc214a..6f30b48d657 100644 --- a/libraries/USB/src/USBHID.cpp +++ b/libraries/USB/src/USBHID.cpp @@ -23,13 +23,13 @@ #define USB_HID_DEVICES_MAX 10 ESP_EVENT_DEFINE_BASE(ARDUINO_USB_HID_EVENTS); -esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, TickType_t ticks_to_wait); -esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg); +esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void* event_data, size_t event_data_size, TickType_t ticks_to_wait); +esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void* event_handler_arg); typedef struct { - USBHIDDevice * device; - uint8_t reports_num; - uint8_t * report_ids; + USBHIDDevice* device; + uint8_t reports_num; + uint8_t* report_ids; } tinyusb_hid_device_t; static tinyusb_hid_device_t tinyusb_hid_devices[USB_HID_DEVICES_MAX]; @@ -43,179 +43,176 @@ static bool tinyusb_hid_is_initialized = false; static hid_interface_protocol_enum_t tinyusb_interface_protocol = HID_ITF_PROTOCOL_NONE; static uint8_t tinyusb_loaded_hid_devices_num = 0; static uint16_t tinyusb_hid_device_descriptor_len = 0; -static uint8_t * tinyusb_hid_device_descriptor = NULL; +static uint8_t* tinyusb_hid_device_descriptor = NULL; #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG - static const char * tinyusb_hid_device_report_types[4] = {"INVALID", "INPUT", "OUTPUT", "FEATURE"}; +static const char* tinyusb_hid_device_report_types[4] = { "INVALID", "INPUT", "OUTPUT", "FEATURE" }; #endif -static bool tinyusb_enable_hid_device(uint16_t descriptor_len, USBHIDDevice * device){ - if(tinyusb_hid_is_initialized){ - log_e("TinyUSB HID has already started! Device not enabled"); - return false; - } - if(tinyusb_loaded_hid_devices_num >= USB_HID_DEVICES_MAX){ - log_e("Maximum devices already enabled! Device not enabled"); - return false; - } - tinyusb_hid_device_descriptor_len += descriptor_len; - tinyusb_hid_devices[tinyusb_loaded_hid_devices_num++].device = device; +static bool tinyusb_enable_hid_device(uint16_t descriptor_len, USBHIDDevice* device) { + if (tinyusb_hid_is_initialized) { + log_e("TinyUSB HID has already started! Device not enabled"); + return false; + } + if (tinyusb_loaded_hid_devices_num >= USB_HID_DEVICES_MAX) { + log_e("Maximum devices already enabled! Device not enabled"); + return false; + } + tinyusb_hid_device_descriptor_len += descriptor_len; + tinyusb_hid_devices[tinyusb_loaded_hid_devices_num++].device = device; - log_d("Device[%u] len: %u", tinyusb_loaded_hid_devices_num-1, descriptor_len); - return true; + log_d("Device[%u] len: %u", tinyusb_loaded_hid_devices_num - 1, descriptor_len); + return true; } -USBHIDDevice * tinyusb_get_device_by_report_id(uint8_t report_id){ - for(uint8_t i=0; idevice && device->reports_num){ - for(uint8_t r=0; rreports_num; r++){ - if(report_id == device->report_ids[r]){ - return device->device; - } - } +USBHIDDevice* tinyusb_get_device_by_report_id(uint8_t report_id) { + for (uint8_t i = 0; i < tinyusb_loaded_hid_devices_num; i++) { + tinyusb_hid_device_t* device = &tinyusb_hid_devices[i]; + if (device->device && device->reports_num) { + for (uint8_t r = 0; r < device->reports_num; r++) { + if (report_id == device->report_ids[r]) { + return device->device; } + } } - return NULL; + } + return NULL; } -static uint16_t tinyusb_on_get_feature(uint8_t report_id, uint8_t* buffer, uint16_t reqlen){ - USBHIDDevice * device = tinyusb_get_device_by_report_id(report_id); - if(device){ - return device->_onGetFeature(report_id, buffer, reqlen); - } - return 0; +static uint16_t tinyusb_on_get_feature(uint8_t report_id, uint8_t* buffer, uint16_t reqlen) { + USBHIDDevice* device = tinyusb_get_device_by_report_id(report_id); + if (device) { + return device->_onGetFeature(report_id, buffer, reqlen); + } + return 0; } -static bool tinyusb_on_set_feature(uint8_t report_id, const uint8_t* buffer, uint16_t reqlen){ - USBHIDDevice * device = tinyusb_get_device_by_report_id(report_id); - if(device){ - device->_onSetFeature(report_id, buffer, reqlen); - return true; - } - return false; +static bool tinyusb_on_set_feature(uint8_t report_id, const uint8_t* buffer, uint16_t reqlen) { + USBHIDDevice* device = tinyusb_get_device_by_report_id(report_id); + if (device) { + device->_onSetFeature(report_id, buffer, reqlen); + return true; + } + return false; } -static bool tinyusb_on_set_output(uint8_t report_id, const uint8_t* buffer, uint16_t reqlen){ - USBHIDDevice * device = tinyusb_get_device_by_report_id(report_id); - if(device){ - device->_onOutput(report_id, buffer, reqlen); - return true; - } - return false; +static bool tinyusb_on_set_output(uint8_t report_id, const uint8_t* buffer, uint16_t reqlen) { + USBHIDDevice* device = tinyusb_get_device_by_report_id(report_id); + if (device) { + device->_onOutput(report_id, buffer, reqlen); + return true; + } + return false; } -static uint16_t tinyusb_on_add_descriptor(uint8_t device_index, uint8_t * dst){ - uint16_t res = 0; - uint8_t report_id = 0, reports_num = 0; - tinyusb_hid_device_t * device = &tinyusb_hid_devices[device_index]; - if(device->device){ - res = device->device->_onGetDescriptor(dst); - if(res){ - - esp_hid_report_map_t *hid_report_map = esp_hid_parse_report_map(dst, res); - if(hid_report_map){ - if(device->report_ids){ - free(device->report_ids); - } - device->reports_num = hid_report_map->reports_len; - device->report_ids = (uint8_t*)malloc(device->reports_num); - memset(device->report_ids, 0, device->reports_num); - reports_num = device->reports_num; - - for(uint8_t i=0; ireports_num; i++){ - if(hid_report_map->reports[i].protocol_mode == ESP_HID_PROTOCOL_MODE_REPORT){ - report_id = hid_report_map->reports[i].report_id; - for(uint8_t r=0; rreports_num; r++){ - if(!report_id){ - //todo: handle better when device has no report ID set - break; - } else if(report_id == device->report_ids[r]){ - //already added - reports_num--; - break; - } else if(!device->report_ids[r]){ - //empty slot - device->report_ids[r] = report_id; - break; - } - } - } else { - reports_num--; - } - } - device->reports_num = reports_num; - esp_hid_free_report_map(hid_report_map); +static uint16_t tinyusb_on_add_descriptor(uint8_t device_index, uint8_t* dst) { + uint16_t res = 0; + uint8_t report_id = 0, reports_num = 0; + tinyusb_hid_device_t* device = &tinyusb_hid_devices[device_index]; + if (device->device) { + res = device->device->_onGetDescriptor(dst); + if (res) { + + esp_hid_report_map_t* hid_report_map = esp_hid_parse_report_map(dst, res); + if (hid_report_map) { + if (device->report_ids) { + free(device->report_ids); + } + device->reports_num = hid_report_map->reports_len; + device->report_ids = (uint8_t*)malloc(device->reports_num); + memset(device->report_ids, 0, device->reports_num); + reports_num = device->reports_num; + + for (uint8_t i = 0; i < device->reports_num; i++) { + if (hid_report_map->reports[i].protocol_mode == ESP_HID_PROTOCOL_MODE_REPORT) { + report_id = hid_report_map->reports[i].report_id; + for (uint8_t r = 0; r < device->reports_num; r++) { + if (!report_id) { + //todo: handle better when device has no report ID set + break; + } else if (report_id == device->report_ids[r]) { + //already added + reports_num--; + break; + } else if (!device->report_ids[r]) { + //empty slot + device->report_ids[r] = report_id; + break; + } } - + } else { + reports_num--; + } } + device->reports_num = reports_num; + esp_hid_free_report_map(hid_report_map); + } } - return res; + } + return res; } -static bool tinyusb_load_enabled_hid_devices(){ - if(tinyusb_hid_device_descriptor != NULL){ - return true; - } - tinyusb_hid_device_descriptor = (uint8_t *)malloc(tinyusb_hid_device_descriptor_len); - if (tinyusb_hid_device_descriptor == NULL) { - log_e("HID Descriptor Malloc Failed"); - return false; - } - uint8_t * dst = tinyusb_hid_device_descriptor; - - for(uint8_t i=0; ireports_len; i++){ - if(hid_report_map->reports[i].protocol_mode == ESP_HID_PROTOCOL_MODE_REPORT){ - log_d(" ID: %3u, Type: %7s, Size: %2u, Usage: %8s", - hid_report_map->reports[i].report_id, - esp_hid_report_type_str(hid_report_map->reports[i].report_type), - hid_report_map->reports[i].value_len, - esp_hid_usage_str(hid_report_map->reports[i].usage) - ); - } - } - esp_hid_free_report_map(hid_report_map); + for (uint8_t i = 0; i < tinyusb_loaded_hid_devices_num; i++) { + uint16_t len = tinyusb_on_add_descriptor(i, dst); + if (!len) { + break; } else { - log_e("Failed to parse the hid report descriptor!"); - return false; + dst += len; + } + } + + esp_hid_report_map_t* hid_report_map = esp_hid_parse_report_map(tinyusb_hid_device_descriptor, tinyusb_hid_device_descriptor_len); + if (hid_report_map) { + log_d("Loaded HID Descriptor with the following reports:"); + for (uint8_t i = 0; i < hid_report_map->reports_len; i++) { + if (hid_report_map->reports[i].protocol_mode == ESP_HID_PROTOCOL_MODE_REPORT) { + log_d(" ID: %3u, Type: %7s, Size: %2u, Usage: %8s", + hid_report_map->reports[i].report_id, + esp_hid_report_type_str(hid_report_map->reports[i].report_type), + hid_report_map->reports[i].value_len, + esp_hid_usage_str(hid_report_map->reports[i].usage)); + } } + esp_hid_free_report_map(hid_report_map); + } else { + log_e("Failed to parse the hid report descriptor!"); + return false; + } - return true; + return true; } -extern "C" uint16_t tusb_hid_load_descriptor(uint8_t * dst, uint8_t * itf) -{ - if(tinyusb_hid_is_initialized){ - return 0; - } - tinyusb_hid_is_initialized = true; - - uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB HID"); - // For keyboard boot protocol, we've already called tinyusb_enable_interface2(reserve_endpoints=true) - uint8_t ep_in = tinyusb_interface_protocol == HID_ITF_PROTOCOL_KEYBOARD ? 1 : tinyusb_get_free_in_endpoint(); - TU_VERIFY (ep_in != 0); - uint8_t ep_out = tinyusb_interface_protocol == HID_ITF_PROTOCOL_KEYBOARD ? 1 : tinyusb_get_free_out_endpoint(); - TU_VERIFY (ep_out != 0); - uint8_t descriptor[TUD_HID_INOUT_DESC_LEN] = { - // HID Input & Output descriptor - // Interface number, string index, protocol, report descriptor len, EP OUT & IN address, size & polling interval - TUD_HID_INOUT_DESCRIPTOR(*itf, str_index, tinyusb_interface_protocol, tinyusb_hid_device_descriptor_len, ep_out, (uint8_t)(0x80 | ep_in), 64, 1) - }; - *itf+=1; - memcpy(dst, descriptor, TUD_HID_INOUT_DESC_LEN); - return TUD_HID_INOUT_DESC_LEN; +extern "C" uint16_t tusb_hid_load_descriptor(uint8_t* dst, uint8_t* itf) { + if (tinyusb_hid_is_initialized) { + return 0; + } + tinyusb_hid_is_initialized = true; + + uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB HID"); + // For keyboard boot protocol, we've already called tinyusb_enable_interface2(reserve_endpoints=true) + uint8_t ep_in = tinyusb_interface_protocol == HID_ITF_PROTOCOL_KEYBOARD ? 1 : tinyusb_get_free_in_endpoint(); + TU_VERIFY(ep_in != 0); + uint8_t ep_out = tinyusb_interface_protocol == HID_ITF_PROTOCOL_KEYBOARD ? 1 : tinyusb_get_free_out_endpoint(); + TU_VERIFY(ep_out != 0); + uint8_t descriptor[TUD_HID_INOUT_DESC_LEN] = { + // HID Input & Output descriptor + // Interface number, string index, protocol, report descriptor len, EP OUT & IN address, size & polling interval + TUD_HID_INOUT_DESCRIPTOR(*itf, str_index, tinyusb_interface_protocol, tinyusb_hid_device_descriptor_len, ep_out, (uint8_t)(0x80 | ep_in), 64, 1) + }; + *itf += 1; + memcpy(dst, descriptor, TUD_HID_INOUT_DESC_LEN); + return TUD_HID_INOUT_DESC_LEN; } @@ -223,173 +220,172 @@ extern "C" uint16_t tusb_hid_load_descriptor(uint8_t * dst, uint8_t * itf) // Invoked when received GET HID REPORT DESCRIPTOR request // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete -uint8_t const * tud_hid_descriptor_report_cb(uint8_t instance){ - log_v("instance: %u", instance); - if(!tinyusb_load_enabled_hid_devices()){ - return NULL; - } - return tinyusb_hid_device_descriptor; +uint8_t const* tud_hid_descriptor_report_cb(uint8_t instance) { + log_v("instance: %u", instance); + if (!tinyusb_load_enabled_hid_devices()) { + return NULL; + } + return tinyusb_hid_device_descriptor; } // Invoked when received SET_PROTOCOL request // protocol is either HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1) -void tud_hid_set_protocol_cb(uint8_t instance, uint8_t protocol){ - log_v("instance: %u, protocol:%u", instance, protocol); - arduino_usb_hid_event_data_t p; - p.instance = instance; - p.set_protocol.protocol = protocol; - arduino_usb_event_post(ARDUINO_USB_HID_EVENTS, ARDUINO_USB_HID_SET_PROTOCOL_EVENT, &p, sizeof(arduino_usb_hid_event_data_t), portMAX_DELAY); +void tud_hid_set_protocol_cb(uint8_t instance, uint8_t protocol) { + log_v("instance: %u, protocol:%u", instance, protocol); + arduino_usb_hid_event_data_t p; + p.instance = instance; + p.set_protocol.protocol = protocol; + arduino_usb_event_post(ARDUINO_USB_HID_EVENTS, ARDUINO_USB_HID_SET_PROTOCOL_EVENT, &p, sizeof(arduino_usb_hid_event_data_t), portMAX_DELAY); } // Invoked when received SET_IDLE request. return false will stall the request // - Idle Rate = 0 : only send report if there is changes, i.e skip duplication // - Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms). -bool tud_hid_set_idle_cb(uint8_t instance, uint8_t idle_rate){ - log_v("instance: %u, idle_rate:%u", instance, idle_rate); - arduino_usb_hid_event_data_t p; - p.instance = instance; - p.set_idle.idle_rate = idle_rate; - arduino_usb_event_post(ARDUINO_USB_HID_EVENTS, ARDUINO_USB_HID_SET_IDLE_EVENT, &p, sizeof(arduino_usb_hid_event_data_t), portMAX_DELAY); - return true; +bool tud_hid_set_idle_cb(uint8_t instance, uint8_t idle_rate) { + log_v("instance: %u, idle_rate:%u", instance, idle_rate); + arduino_usb_hid_event_data_t p; + p.instance = instance; + p.set_idle.idle_rate = idle_rate; + arduino_usb_event_post(ARDUINO_USB_HID_EVENTS, ARDUINO_USB_HID_SET_IDLE_EVENT, &p, sizeof(arduino_usb_hid_event_data_t), portMAX_DELAY); + return true; } // Invoked when received GET_REPORT control request // Application must fill buffer report's content and return its length. // Return zero will cause the stack to STALL request -uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen){ - uint16_t res = tinyusb_on_get_feature(report_id, buffer, reqlen); - if(!res){ - log_d("instance: %u, report_id: %u, report_type: %s, reqlen: %u", instance, report_id, tinyusb_hid_device_report_types[report_type], reqlen); - } - return res; +uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) { + uint16_t res = tinyusb_on_get_feature(report_id, buffer, reqlen); + if (!res) { + log_d("instance: %u, report_id: %u, report_type: %s, reqlen: %u", instance, report_id, tinyusb_hid_device_report_types[report_type], reqlen); + } + return res; } // Invoked when received SET_REPORT control request or // received data on OUT endpoint ( Report ID = 0, Type = 0 ) -void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize){ - if(!report_id && !report_type){ - if(!tinyusb_on_set_output(0, buffer, bufsize) && !tinyusb_on_set_output(buffer[0], buffer+1, bufsize-1)){ - log_d("instance: %u, report_id: %u, report_type: %s, bufsize: %u", instance, buffer[0], tinyusb_hid_device_report_types[HID_REPORT_TYPE_OUTPUT], bufsize-1); - } - } else { - if(!tinyusb_on_set_feature(report_id, buffer, bufsize)){ - log_d("instance: %u, report_id: %u, report_type: %s, bufsize: %u", instance, report_id, tinyusb_hid_device_report_types[report_type], bufsize); - } +void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) { + if (!report_id && !report_type) { + if (!tinyusb_on_set_output(0, buffer, bufsize) && !tinyusb_on_set_output(buffer[0], buffer + 1, bufsize - 1)) { + log_d("instance: %u, report_id: %u, report_type: %s, bufsize: %u", instance, buffer[0], tinyusb_hid_device_report_types[HID_REPORT_TYPE_OUTPUT], bufsize - 1); + } + } else { + if (!tinyusb_on_set_feature(report_id, buffer, bufsize)) { + log_d("instance: %u, report_id: %u, report_type: %s, bufsize: %u", instance, report_id, tinyusb_hid_device_report_types[report_type], bufsize); } + } } -USBHID::USBHID(hid_interface_protocol_enum_t itf_protocol){ - if(!tinyusb_hid_devices_is_initialized){ - tinyusb_hid_devices_is_initialized = true; - for(uint8_t i=0; i struct ArgType; +template struct ArgType; -template -struct ArgType { - typedef T1 type1; - typedef T2 type2; - typedef T3 type3; +template +struct ArgType { + typedef T1 type1; + typedef T2 type2; + typedef T3 type3; }; typedef ArgType::type3 tud_hid_report_complete_cb_len_t; -void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, tud_hid_report_complete_cb_len_t len){ - if (tinyusb_hid_device_input_sem) { - xSemaphoreGive(tinyusb_hid_device_input_sem); - } +void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, tud_hid_report_complete_cb_len_t len) { + if (tinyusb_hid_device_input_sem) { + xSemaphoreGive(tinyusb_hid_device_input_sem); + } } -bool USBHID::SendReport(uint8_t id, const void* data, size_t len, uint32_t timeout_ms){ - if(!tinyusb_hid_device_input_sem || !tinyusb_hid_device_input_mutex){ - log_e("TX Semaphore is NULL. You must call USBHID::begin() before you can send reports"); - return false; - } - - if(xSemaphoreTake(tinyusb_hid_device_input_mutex, timeout_ms / portTICK_PERIOD_MS) != pdTRUE){ - log_e("report %u mutex failed", id); - return false; - } - - // If we're configured to support boot protocol, and the host has requested boot protocol, prevent - // sending of report ID, by passing report ID of 0 to tud_hid_n_report(). - uint8_t effective_id = ((tinyusb_interface_protocol != HID_ITF_PROTOCOL_NONE) && - (tud_hid_n_get_protocol(0) == HID_PROTOCOL_BOOT)) ? 0 : id; +bool USBHID::SendReport(uint8_t id, const void* data, size_t len, uint32_t timeout_ms) { + if (!tinyusb_hid_device_input_sem || !tinyusb_hid_device_input_mutex) { + log_e("TX Semaphore is NULL. You must call USBHID::begin() before you can send reports"); + return false; + } - bool res = ready(); - if(!res){ - log_e("not ready"); + if (xSemaphoreTake(tinyusb_hid_device_input_mutex, timeout_ms / portTICK_PERIOD_MS) != pdTRUE) { + log_e("report %u mutex failed", id); + return false; + } + + // If we're configured to support boot protocol, and the host has requested boot protocol, prevent + // sending of report ID, by passing report ID of 0 to tud_hid_n_report(). + uint8_t effective_id = ((tinyusb_interface_protocol != HID_ITF_PROTOCOL_NONE) && (tud_hid_n_get_protocol(0) == HID_PROTOCOL_BOOT)) ? 0 : id; + + bool res = ready(); + if (!res) { + log_e("not ready"); + } else { + // The semaphore may be given if the last SendReport() timed out waiting for the report to + // be sent. Or, tud_hid_report_complete_cb() may be called an extra time, causing the + // semaphore to be given. In these cases, take the semaphore to clear its state so that + // we can wait for it to be given after calling tud_hid_n_report(). + xSemaphoreTake(tinyusb_hid_device_input_sem, 0); + + res = tud_hid_n_report(0, effective_id, data, len); + if (!res) { + log_e("report %u failed", id); } else { - // The semaphore may be given if the last SendReport() timed out waiting for the report to - // be sent. Or, tud_hid_report_complete_cb() may be called an extra time, causing the - // semaphore to be given. In these cases, take the semaphore to clear its state so that - // we can wait for it to be given after calling tud_hid_n_report(). - xSemaphoreTake(tinyusb_hid_device_input_sem, 0); - - res = tud_hid_n_report(0, effective_id, data, len); - if(!res){ - log_e("report %u failed", id); - } else { - if(xSemaphoreTake(tinyusb_hid_device_input_sem, timeout_ms / portTICK_PERIOD_MS) != pdTRUE){ - log_e("report %u wait failed", id); - res = false; - } - } + if (xSemaphoreTake(tinyusb_hid_device_input_sem, timeout_ms / portTICK_PERIOD_MS) != pdTRUE) { + log_e("report %u wait failed", id); + res = false; + } } + } - xSemaphoreGive(tinyusb_hid_device_input_mutex); - return res; + xSemaphoreGive(tinyusb_hid_device_input_mutex); + return res; } -bool USBHID::addDevice(USBHIDDevice * device, uint16_t descriptor_len){ - if(device && tinyusb_loaded_hid_devices_num < USB_HID_DEVICES_MAX){ - if(!tinyusb_enable_hid_device(descriptor_len, device)){ - return false; - } - return true; +bool USBHID::addDevice(USBHIDDevice* device, uint16_t descriptor_len) { + if (device && tinyusb_loaded_hid_devices_num < USB_HID_DEVICES_MAX) { + if (!tinyusb_enable_hid_device(descriptor_len, device)) { + return false; } - return false; + return true; + } + return false; } -void USBHID::onEvent(esp_event_handler_t callback){ - onEvent(ARDUINO_USB_HID_ANY_EVENT, callback); +void USBHID::onEvent(esp_event_handler_t callback) { + onEvent(ARDUINO_USB_HID_ANY_EVENT, callback); } -void USBHID::onEvent(arduino_usb_hid_event_t event, esp_event_handler_t callback){ - arduino_usb_event_handler_register_with(ARDUINO_USB_HID_EVENTS, event, callback, this); +void USBHID::onEvent(arduino_usb_hid_event_t event, esp_event_handler_t callback) { + arduino_usb_event_handler_register_with(ARDUINO_USB_HID_EVENTS, event, callback, this); } #endif /* CONFIG_TINYUSB_HID_ENABLED */ diff --git a/libraries/USB/src/USBHID.h b/libraries/USB/src/USBHID.h index cce3865f5a1..5e7c6f21d7c 100644 --- a/libraries/USB/src/USBHID.h +++ b/libraries/USB/src/USBHID.h @@ -28,56 +28,58 @@ // Used by the included TinyUSB drivers enum { - HID_REPORT_ID_NONE, - HID_REPORT_ID_KEYBOARD, - HID_REPORT_ID_MOUSE, - HID_REPORT_ID_GAMEPAD, - HID_REPORT_ID_CONSUMER_CONTROL, - HID_REPORT_ID_SYSTEM_CONTROL, - HID_REPORT_ID_VENDOR + HID_REPORT_ID_NONE, + HID_REPORT_ID_KEYBOARD, + HID_REPORT_ID_MOUSE, + HID_REPORT_ID_GAMEPAD, + HID_REPORT_ID_CONSUMER_CONTROL, + HID_REPORT_ID_SYSTEM_CONTROL, + HID_REPORT_ID_VENDOR }; ESP_EVENT_DECLARE_BASE(ARDUINO_USB_HID_EVENTS); typedef enum { - ARDUINO_USB_HID_ANY_EVENT = ESP_EVENT_ANY_ID, - ARDUINO_USB_HID_SET_PROTOCOL_EVENT = 0, - ARDUINO_USB_HID_SET_IDLE_EVENT, - ARDUINO_USB_HID_MAX_EVENT, + ARDUINO_USB_HID_ANY_EVENT = ESP_EVENT_ANY_ID, + ARDUINO_USB_HID_SET_PROTOCOL_EVENT = 0, + ARDUINO_USB_HID_SET_IDLE_EVENT, + ARDUINO_USB_HID_MAX_EVENT, } arduino_usb_hid_event_t; typedef struct { - uint8_t instance; - union { - struct { - uint8_t protocol; - } set_protocol; - struct { - uint8_t idle_rate; - } set_idle; - }; + uint8_t instance; + union { + struct { + uint8_t protocol; + } set_protocol; + struct { + uint8_t idle_rate; + } set_idle; + }; } arduino_usb_hid_event_data_t; -class USBHIDDevice -{ +class USBHIDDevice { public: - virtual uint16_t _onGetDescriptor(uint8_t* buffer){return 0;} - virtual uint16_t _onGetFeature(uint8_t report_id, uint8_t* buffer, uint16_t len){return 0;} - virtual void _onSetFeature(uint8_t report_id, const uint8_t* buffer, uint16_t len){} - virtual void _onOutput(uint8_t report_id, const uint8_t* buffer, uint16_t len){} + virtual uint16_t _onGetDescriptor(uint8_t* buffer) { + return 0; + } + virtual uint16_t _onGetFeature(uint8_t report_id, uint8_t* buffer, uint16_t len) { + return 0; + } + virtual void _onSetFeature(uint8_t report_id, const uint8_t* buffer, uint16_t len) {} + virtual void _onOutput(uint8_t report_id, const uint8_t* buffer, uint16_t len) {} }; -class USBHID -{ +class USBHID { public: - USBHID(hid_interface_protocol_enum_t itf_protocol = HID_ITF_PROTOCOL_NONE); - void begin(void); - void end(void); - bool ready(void); - bool SendReport(uint8_t report_id, const void* data, size_t len, uint32_t timeout_ms = 100); - void onEvent(esp_event_handler_t callback); - void onEvent(arduino_usb_hid_event_t event, esp_event_handler_t callback); - static bool addDevice(USBHIDDevice * device, uint16_t descriptor_len); + USBHID(hid_interface_protocol_enum_t itf_protocol = HID_ITF_PROTOCOL_NONE); + void begin(void); + void end(void); + bool ready(void); + bool SendReport(uint8_t report_id, const void* data, size_t len, uint32_t timeout_ms = 100); + void onEvent(esp_event_handler_t callback); + void onEvent(arduino_usb_hid_event_t event, esp_event_handler_t callback); + static bool addDevice(USBHIDDevice* device, uint16_t descriptor_len); }; #endif /* CONFIG_TINYUSB_HID_ENABLED */ diff --git a/libraries/USB/src/USBHIDConsumerControl.cpp b/libraries/USB/src/USBHIDConsumerControl.cpp index 69530e24be2..80507283769 100644 --- a/libraries/USB/src/USBHIDConsumerControl.cpp +++ b/libraries/USB/src/USBHIDConsumerControl.cpp @@ -19,39 +19,40 @@ #include "USBHIDConsumerControl.h" static const uint8_t report_descriptor[] = { - TUD_HID_REPORT_DESC_CONSUMER(HID_REPORT_ID(HID_REPORT_ID_CONSUMER_CONTROL)) + TUD_HID_REPORT_DESC_CONSUMER(HID_REPORT_ID(HID_REPORT_ID_CONSUMER_CONTROL)) }; -USBHIDConsumerControl::USBHIDConsumerControl(): hid(){ - static bool initialized = false; - if(!initialized){ - initialized = true; - hid.addDevice(this, sizeof(report_descriptor)); - } +USBHIDConsumerControl::USBHIDConsumerControl() + : hid() { + static bool initialized = false; + if (!initialized) { + initialized = true; + hid.addDevice(this, sizeof(report_descriptor)); + } } -uint16_t USBHIDConsumerControl::_onGetDescriptor(uint8_t* dst){ - memcpy(dst, report_descriptor, sizeof(report_descriptor)); - return sizeof(report_descriptor); +uint16_t USBHIDConsumerControl::_onGetDescriptor(uint8_t* dst) { + memcpy(dst, report_descriptor, sizeof(report_descriptor)); + return sizeof(report_descriptor); } -void USBHIDConsumerControl::begin(){ - hid.begin(); +void USBHIDConsumerControl::begin() { + hid.begin(); } -void USBHIDConsumerControl::end(){ +void USBHIDConsumerControl::end() { } -bool USBHIDConsumerControl::send(uint16_t value){ - return hid.SendReport(HID_REPORT_ID_CONSUMER_CONTROL, &value, 2); +bool USBHIDConsumerControl::send(uint16_t value) { + return hid.SendReport(HID_REPORT_ID_CONSUMER_CONTROL, &value, 2); } -size_t USBHIDConsumerControl::press(uint16_t k){ - return send(k); +size_t USBHIDConsumerControl::press(uint16_t k) { + return send(k); } -size_t USBHIDConsumerControl::release(){ - return send(0); +size_t USBHIDConsumerControl::release() { + return send(0); } diff --git a/libraries/USB/src/USBHIDConsumerControl.h b/libraries/USB/src/USBHIDConsumerControl.h index 54377d287e5..fcae50f75b4 100644 --- a/libraries/USB/src/USBHIDConsumerControl.h +++ b/libraries/USB/src/USBHIDConsumerControl.h @@ -21,69 +21,69 @@ #if CONFIG_TINYUSB_HID_ENABLED // Power Control -#define CONSUMER_CONTROL_POWER 0x0030 -#define CONSUMER_CONTROL_RESET 0x0031 -#define CONSUMER_CONTROL_SLEEP 0x0032 +#define CONSUMER_CONTROL_POWER 0x0030 +#define CONSUMER_CONTROL_RESET 0x0031 +#define CONSUMER_CONTROL_SLEEP 0x0032 // Screen Brightness -#define CONSUMER_CONTROL_BRIGHTNESS_INCREMENT 0x006F -#define CONSUMER_CONTROL_BRIGHTNESS_DECREMENT 0x0070 +#define CONSUMER_CONTROL_BRIGHTNESS_INCREMENT 0x006F +#define CONSUMER_CONTROL_BRIGHTNESS_DECREMENT 0x0070 // These HID usages operate only on mobile systems (battery powered) and // require Windows 8 (build 8302 or greater). -#define CONSUMER_CONTROL_WIRELESS_RADIO_CONTROLS 0x000C -#define CONSUMER_CONTROL_WIRELESS_RADIO_BUTTONS 0x00C6 -#define CONSUMER_CONTROL_WIRELESS_RADIO_LED 0x00C7 -#define CONSUMER_CONTROL_WIRELESS_RADIO_SLIDER_SWITCH 0x00C8 +#define CONSUMER_CONTROL_WIRELESS_RADIO_CONTROLS 0x000C +#define CONSUMER_CONTROL_WIRELESS_RADIO_BUTTONS 0x00C6 +#define CONSUMER_CONTROL_WIRELESS_RADIO_LED 0x00C7 +#define CONSUMER_CONTROL_WIRELESS_RADIO_SLIDER_SWITCH 0x00C8 // Media Control -#define CONSUMER_CONTROL_PLAY_PAUSE 0x00CD -#define CONSUMER_CONTROL_SCAN_NEXT 0x00B5 -#define CONSUMER_CONTROL_SCAN_PREVIOUS 0x00B6 -#define CONSUMER_CONTROL_STOP 0x00B7 -#define CONSUMER_CONTROL_VOLUME 0x00E0 -#define CONSUMER_CONTROL_MUTE 0x00E2 -#define CONSUMER_CONTROL_BASS 0x00E3 -#define CONSUMER_CONTROL_TREBLE 0x00E4 -#define CONSUMER_CONTROL_BASS_BOOST 0x00E5 -#define CONSUMER_CONTROL_VOLUME_INCREMENT 0x00E9 -#define CONSUMER_CONTROL_VOLUME_DECREMENT 0x00EA -#define CONSUMER_CONTROL_BASS_INCREMENT 0x0152 -#define CONSUMER_CONTROL_BASS_DECREMENT 0x0153 -#define CONSUMER_CONTROL_TREBLE_INCREMENT 0x0154 -#define CONSUMER_CONTROL_TREBLE_DECREMENT 0x0155 +#define CONSUMER_CONTROL_PLAY_PAUSE 0x00CD +#define CONSUMER_CONTROL_SCAN_NEXT 0x00B5 +#define CONSUMER_CONTROL_SCAN_PREVIOUS 0x00B6 +#define CONSUMER_CONTROL_STOP 0x00B7 +#define CONSUMER_CONTROL_VOLUME 0x00E0 +#define CONSUMER_CONTROL_MUTE 0x00E2 +#define CONSUMER_CONTROL_BASS 0x00E3 +#define CONSUMER_CONTROL_TREBLE 0x00E4 +#define CONSUMER_CONTROL_BASS_BOOST 0x00E5 +#define CONSUMER_CONTROL_VOLUME_INCREMENT 0x00E9 +#define CONSUMER_CONTROL_VOLUME_DECREMENT 0x00EA +#define CONSUMER_CONTROL_BASS_INCREMENT 0x0152 +#define CONSUMER_CONTROL_BASS_DECREMENT 0x0153 +#define CONSUMER_CONTROL_TREBLE_INCREMENT 0x0154 +#define CONSUMER_CONTROL_TREBLE_DECREMENT 0x0155 // Application Launcher -#define CONSUMER_CONTROL_CONFIGURATION 0x0183 -#define CONSUMER_CONTROL_EMAIL_READER 0x018A -#define CONSUMER_CONTROL_CALCULATOR 0x0192 -#define CONSUMER_CONTROL_LOCAL_BROWSER 0x0194 +#define CONSUMER_CONTROL_CONFIGURATION 0x0183 +#define CONSUMER_CONTROL_EMAIL_READER 0x018A +#define CONSUMER_CONTROL_CALCULATOR 0x0192 +#define CONSUMER_CONTROL_LOCAL_BROWSER 0x0194 // Browser/Explorer Specific -#define CONSUMER_CONTROL_SEARCH 0x0221 -#define CONSUMER_CONTROL_HOME 0x0223 -#define CONSUMER_CONTROL_BACK 0x0224 -#define CONSUMER_CONTROL_FORWARD 0x0225 -#define CONSUMER_CONTROL_BR_STOP 0x0226 -#define CONSUMER_CONTROL_REFRESH 0x0227 -#define CONSUMER_CONTROL_BOOKMARKS 0x022A +#define CONSUMER_CONTROL_SEARCH 0x0221 +#define CONSUMER_CONTROL_HOME 0x0223 +#define CONSUMER_CONTROL_BACK 0x0224 +#define CONSUMER_CONTROL_FORWARD 0x0225 +#define CONSUMER_CONTROL_BR_STOP 0x0226 +#define CONSUMER_CONTROL_REFRESH 0x0227 +#define CONSUMER_CONTROL_BOOKMARKS 0x022A // Mouse Horizontal scroll -#define CONSUMER_CONTROL_PAN 0x0238 +#define CONSUMER_CONTROL_PAN 0x0238 -class USBHIDConsumerControl: public USBHIDDevice { +class USBHIDConsumerControl : public USBHIDDevice { private: - USBHID hid; - bool send(uint16_t value); + USBHID hid; + bool send(uint16_t value); public: - USBHIDConsumerControl(void); - void begin(void); - void end(void); - size_t press(uint16_t k); - size_t release(); + USBHIDConsumerControl(void); + void begin(void); + void end(void); + size_t press(uint16_t k); + size_t release(); - // internal use - uint16_t _onGetDescriptor(uint8_t* buffer); + // internal use + uint16_t _onGetDescriptor(uint8_t* buffer); }; #endif /* CONFIG_TINYUSB_HID_ENABLED */ diff --git a/libraries/USB/src/USBHIDGamepad.cpp b/libraries/USB/src/USBHIDGamepad.cpp index 0377065cd4e..46842d7a6a6 100644 --- a/libraries/USB/src/USBHIDGamepad.cpp +++ b/libraries/USB/src/USBHIDGamepad.cpp @@ -19,103 +19,103 @@ #include "USBHIDGamepad.h" static const uint8_t report_descriptor[] = { - TUD_HID_REPORT_DESC_GAMEPAD(HID_REPORT_ID(HID_REPORT_ID_GAMEPAD)) + TUD_HID_REPORT_DESC_GAMEPAD(HID_REPORT_ID(HID_REPORT_ID_GAMEPAD)) }; -USBHIDGamepad::USBHIDGamepad(): hid(), _x(0), _y(0), _z(0), _rz(0), _rx(0), _ry(0), _hat(0), _buttons(0){ - static bool initialized = false; - if(!initialized){ - initialized = true; - hid.addDevice(this, sizeof(report_descriptor)); - } +USBHIDGamepad::USBHIDGamepad() + : hid(), _x(0), _y(0), _z(0), _rz(0), _rx(0), _ry(0), _hat(0), _buttons(0) { + static bool initialized = false; + if (!initialized) { + initialized = true; + hid.addDevice(this, sizeof(report_descriptor)); + } } -uint16_t USBHIDGamepad::_onGetDescriptor(uint8_t* dst){ - memcpy(dst, report_descriptor, sizeof(report_descriptor)); - return sizeof(report_descriptor); +uint16_t USBHIDGamepad::_onGetDescriptor(uint8_t* dst) { + memcpy(dst, report_descriptor, sizeof(report_descriptor)); + return sizeof(report_descriptor); } -void USBHIDGamepad::begin(){ - hid.begin(); +void USBHIDGamepad::begin() { + hid.begin(); } -void USBHIDGamepad::end(){ - +void USBHIDGamepad::end() { } -bool USBHIDGamepad::write(){ - hid_gamepad_report_t report = { - .x = _x, - .y = _y, - .z = _z, - .rz = _rz, - .rx = _rx, - .ry = _ry, - .hat = _hat, - .buttons = _buttons - }; - return hid.SendReport(HID_REPORT_ID_GAMEPAD, &report, sizeof(report)); +bool USBHIDGamepad::write() { + hid_gamepad_report_t report = { + .x = _x, + .y = _y, + .z = _z, + .rz = _rz, + .rx = _rx, + .ry = _ry, + .hat = _hat, + .buttons = _buttons + }; + return hid.SendReport(HID_REPORT_ID_GAMEPAD, &report, sizeof(report)); } -bool USBHIDGamepad::leftStick(int8_t x, int8_t y){ - _x = x; - _y = y; - return write(); +bool USBHIDGamepad::leftStick(int8_t x, int8_t y) { + _x = x; + _y = y; + return write(); } -bool USBHIDGamepad::rightStick(int8_t z, int8_t rz){ - _z = z; - _rz = rz; - return write(); +bool USBHIDGamepad::rightStick(int8_t z, int8_t rz) { + _z = z; + _rz = rz; + return write(); } -bool USBHIDGamepad::leftTrigger(int8_t rx){ - _rx = rx; - return write(); +bool USBHIDGamepad::leftTrigger(int8_t rx) { + _rx = rx; + return write(); } -bool USBHIDGamepad::rightTrigger(int8_t ry){ - _ry = ry; - return write(); +bool USBHIDGamepad::rightTrigger(int8_t ry) { + _ry = ry; + return write(); } -bool USBHIDGamepad::hat(uint8_t hat){ - if(hat > 9){ - return false; - } - _hat = hat; - return write(); +bool USBHIDGamepad::hat(uint8_t hat) { + if (hat > 9) { + return false; + } + _hat = hat; + return write(); } -bool USBHIDGamepad::pressButton(uint8_t button){ - if(button > 31){ - return false; - } - _buttons |= (1 << button); - return write(); +bool USBHIDGamepad::pressButton(uint8_t button) { + if (button > 31) { + return false; + } + _buttons |= (1 << button); + return write(); } -bool USBHIDGamepad::releaseButton(uint8_t button){ - if(button > 31){ - return false; - } - _buttons &= ~(1 << button); - return write(); +bool USBHIDGamepad::releaseButton(uint8_t button) { + if (button > 31) { + return false; + } + _buttons &= ~(1 << button); + return write(); } -bool USBHIDGamepad::send(int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons){ - if(hat > 9){ - return false; - } - _x = x; - _y = y; - _z = z; - _rz = rz; - _rx = rx; - _ry = ry; - _hat = hat; - _buttons = buttons; - return write(); +bool USBHIDGamepad::send(int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons) { + if (hat > 9) { + return false; + } + _x = x; + _y = y; + _z = z; + _rz = rz; + _rx = rx; + _ry = ry; + _hat = hat; + _buttons = buttons; + return write(); } #endif /* CONFIG_TINYUSB_HID_ENABLED */ diff --git a/libraries/USB/src/USBHIDGamepad.h b/libraries/USB/src/USBHIDGamepad.h index c86865d781d..e11dbf3768e 100644 --- a/libraries/USB/src/USBHIDGamepad.h +++ b/libraries/USB/src/USBHIDGamepad.h @@ -22,70 +22,70 @@ /// Standard Gamepad Buttons Naming from Linux input event codes /// https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h -#define BUTTON_A 0 -#define BUTTON_B 1 -#define BUTTON_C 2 -#define BUTTON_X 3 -#define BUTTON_Y 4 -#define BUTTON_Z 5 -#define BUTTON_TL 6 -#define BUTTON_TR 7 -#define BUTTON_TL2 8 -#define BUTTON_TR2 9 -#define BUTTON_SELECT 10 -#define BUTTON_START 11 -#define BUTTON_MODE 12 -#define BUTTON_THUMBL 13 -#define BUTTON_THUMBR 14 +#define BUTTON_A 0 +#define BUTTON_B 1 +#define BUTTON_C 2 +#define BUTTON_X 3 +#define BUTTON_Y 4 +#define BUTTON_Z 5 +#define BUTTON_TL 6 +#define BUTTON_TR 7 +#define BUTTON_TL2 8 +#define BUTTON_TR2 9 +#define BUTTON_SELECT 10 +#define BUTTON_START 11 +#define BUTTON_MODE 12 +#define BUTTON_THUMBL 13 +#define BUTTON_THUMBR 14 -#define BUTTON_SOUTH BUTTON_A -#define BUTTON_EAST BUTTON_B -#define BUTTON_NORTH BUTTON_X -#define BUTTON_WEST BUTTON_Y +#define BUTTON_SOUTH BUTTON_A +#define BUTTON_EAST BUTTON_B +#define BUTTON_NORTH BUTTON_X +#define BUTTON_WEST BUTTON_Y /// Standard Gamepad HAT/DPAD Buttons (from Linux input event codes) -#define HAT_CENTER 0 -#define HAT_UP 1 -#define HAT_UP_RIGHT 2 -#define HAT_RIGHT 3 +#define HAT_CENTER 0 +#define HAT_UP 1 +#define HAT_UP_RIGHT 2 +#define HAT_RIGHT 3 #define HAT_DOWN_RIGHT 4 -#define HAT_DOWN 5 -#define HAT_DOWN_LEFT 6 -#define HAT_LEFT 7 -#define HAT_UP_LEFT 8 +#define HAT_DOWN 5 +#define HAT_DOWN_LEFT 6 +#define HAT_LEFT 7 +#define HAT_UP_LEFT 8 -class USBHIDGamepad: public USBHIDDevice { +class USBHIDGamepad : public USBHIDDevice { private: - USBHID hid; - int8_t _x; ///< Delta x movement of left analog-stick - int8_t _y; ///< Delta y movement of left analog-stick - int8_t _z; ///< Delta z movement of right analog-joystick - int8_t _rz; ///< Delta Rz movement of right analog-joystick - int8_t _rx; ///< Delta Rx movement of analog left trigger - int8_t _ry; ///< Delta Ry movement of analog right trigger - uint8_t _hat; ///< Buttons mask for currently pressed buttons in the DPad/hat - uint32_t _buttons; ///< Buttons mask for currently pressed buttons - bool write(); + USBHID hid; + int8_t _x; ///< Delta x movement of left analog-stick + int8_t _y; ///< Delta y movement of left analog-stick + int8_t _z; ///< Delta z movement of right analog-joystick + int8_t _rz; ///< Delta Rz movement of right analog-joystick + int8_t _rx; ///< Delta Rx movement of analog left trigger + int8_t _ry; ///< Delta Ry movement of analog right trigger + uint8_t _hat; ///< Buttons mask for currently pressed buttons in the DPad/hat + uint32_t _buttons; ///< Buttons mask for currently pressed buttons + bool write(); public: - USBHIDGamepad(void); - void begin(void); - void end(void); + USBHIDGamepad(void); + void begin(void); + void end(void); - bool leftStick(int8_t x, int8_t y); - bool rightStick(int8_t z, int8_t rz); + bool leftStick(int8_t x, int8_t y); + bool rightStick(int8_t z, int8_t rz); - bool leftTrigger(int8_t rx); - bool rightTrigger(int8_t ry); + bool leftTrigger(int8_t rx); + bool rightTrigger(int8_t ry); - bool hat(uint8_t hat); + bool hat(uint8_t hat); - bool pressButton(uint8_t button); - bool releaseButton(uint8_t button); + bool pressButton(uint8_t button); + bool releaseButton(uint8_t button); - bool send(int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons); + bool send(int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons); - // internal use - uint16_t _onGetDescriptor(uint8_t* buffer); + // internal use + uint16_t _onGetDescriptor(uint8_t* buffer); }; #endif /* CONFIG_TINYUSB_HID_ENABLED */ diff --git a/libraries/USB/src/USBHIDKeyboard.cpp b/libraries/USB/src/USBHIDKeyboard.cpp index 737191b017c..8eda39eb563 100644 --- a/libraries/USB/src/USBHIDKeyboard.cpp +++ b/libraries/USB/src/USBHIDKeyboard.cpp @@ -26,340 +26,330 @@ #include "USBHIDKeyboard.h" ESP_EVENT_DEFINE_BASE(ARDUINO_USB_HID_KEYBOARD_EVENTS); -esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, TickType_t ticks_to_wait); -esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg); +esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void* event_data, size_t event_data_size, TickType_t ticks_to_wait); +esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void* event_handler_arg); static const uint8_t report_descriptor[] = { - TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(HID_REPORT_ID_KEYBOARD)) + TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(HID_REPORT_ID_KEYBOARD)) }; -USBHIDKeyboard::USBHIDKeyboard(): hid(HID_ITF_PROTOCOL_KEYBOARD), shiftKeyReports(true){ - static bool initialized = false; - if(!initialized){ - initialized = true; - memset(&_keyReport, 0, sizeof(KeyReport)); - hid.addDevice(this, sizeof(report_descriptor)); - } +USBHIDKeyboard::USBHIDKeyboard() + : hid(HID_ITF_PROTOCOL_KEYBOARD), shiftKeyReports(true) { + static bool initialized = false; + if (!initialized) { + initialized = true; + memset(&_keyReport, 0, sizeof(KeyReport)); + hid.addDevice(this, sizeof(report_descriptor)); + } } -uint16_t USBHIDKeyboard::_onGetDescriptor(uint8_t* dst){ - memcpy(dst, report_descriptor, sizeof(report_descriptor)); - return sizeof(report_descriptor); +uint16_t USBHIDKeyboard::_onGetDescriptor(uint8_t* dst) { + memcpy(dst, report_descriptor, sizeof(report_descriptor)); + return sizeof(report_descriptor); } -void USBHIDKeyboard::begin(){ - hid.begin(); +void USBHIDKeyboard::begin() { + hid.begin(); } -void USBHIDKeyboard::end(){ +void USBHIDKeyboard::end() { } -void USBHIDKeyboard::onEvent(esp_event_handler_t callback){ - onEvent(ARDUINO_USB_HID_KEYBOARD_ANY_EVENT, callback); +void USBHIDKeyboard::onEvent(esp_event_handler_t callback) { + onEvent(ARDUINO_USB_HID_KEYBOARD_ANY_EVENT, callback); } -void USBHIDKeyboard::onEvent(arduino_usb_hid_keyboard_event_t event, esp_event_handler_t callback){ - arduino_usb_event_handler_register_with(ARDUINO_USB_HID_KEYBOARD_EVENTS, event, callback, this); +void USBHIDKeyboard::onEvent(arduino_usb_hid_keyboard_event_t event, esp_event_handler_t callback) { + arduino_usb_event_handler_register_with(ARDUINO_USB_HID_KEYBOARD_EVENTS, event, callback, this); } -void USBHIDKeyboard::_onOutput(uint8_t report_id, const uint8_t* buffer, uint16_t len){ - if(report_id == HID_REPORT_ID_KEYBOARD){ - arduino_usb_hid_keyboard_event_data_t p; - p.leds = buffer[0]; - arduino_usb_event_post(ARDUINO_USB_HID_KEYBOARD_EVENTS, ARDUINO_USB_HID_KEYBOARD_LED_EVENT, &p, sizeof(arduino_usb_hid_keyboard_event_data_t), portMAX_DELAY); - } +void USBHIDKeyboard::_onOutput(uint8_t report_id, const uint8_t* buffer, uint16_t len) { + if (report_id == HID_REPORT_ID_KEYBOARD) { + arduino_usb_hid_keyboard_event_data_t p; + p.leds = buffer[0]; + arduino_usb_event_post(ARDUINO_USB_HID_KEYBOARD_EVENTS, ARDUINO_USB_HID_KEYBOARD_LED_EVENT, &p, sizeof(arduino_usb_hid_keyboard_event_data_t), portMAX_DELAY); + } } -void USBHIDKeyboard::sendReport(KeyReport* keys) -{ - hid_keyboard_report_t report; - report.reserved = 0; - report.modifier = keys->modifiers; - memcpy(report.keycode, keys->keys, 6); - hid.SendReport(HID_REPORT_ID_KEYBOARD, &report, sizeof(report)); +void USBHIDKeyboard::sendReport(KeyReport* keys) { + hid_keyboard_report_t report; + report.reserved = 0; + report.modifier = keys->modifiers; + memcpy(report.keycode, keys->keys, 6); + hid.SendReport(HID_REPORT_ID_KEYBOARD, &report, sizeof(report)); } -void USBHIDKeyboard::setShiftKeyReports(bool set) -{ - shiftKeyReports = set; +void USBHIDKeyboard::setShiftKeyReports(bool set) { + shiftKeyReports = set; } #define SHIFT 0x80 -const uint8_t _asciimap[128] = -{ - 0x00, // NUL - 0x00, // SOH - 0x00, // STX - 0x00, // ETX - 0x00, // EOT - 0x00, // ENQ - 0x00, // ACK - 0x00, // BEL - 0x2a, // BS Backspace - 0x2b, // TAB Tab - 0x28, // LF Enter - 0x00, // VT - 0x00, // FF - 0x00, // CR - 0x00, // SO - 0x00, // SI - 0x00, // DEL - 0x00, // DC1 - 0x00, // DC2 - 0x00, // DC3 - 0x00, // DC4 - 0x00, // NAK - 0x00, // SYN - 0x00, // ETB - 0x00, // CAN - 0x00, // EM - 0x00, // SUB - 0x00, // ESC - 0x00, // FS - 0x00, // GS - 0x00, // RS - 0x00, // US +const uint8_t _asciimap[128] = { + 0x00, // NUL + 0x00, // SOH + 0x00, // STX + 0x00, // ETX + 0x00, // EOT + 0x00, // ENQ + 0x00, // ACK + 0x00, // BEL + 0x2a, // BS Backspace + 0x2b, // TAB Tab + 0x28, // LF Enter + 0x00, // VT + 0x00, // FF + 0x00, // CR + 0x00, // SO + 0x00, // SI + 0x00, // DEL + 0x00, // DC1 + 0x00, // DC2 + 0x00, // DC3 + 0x00, // DC4 + 0x00, // NAK + 0x00, // SYN + 0x00, // ETB + 0x00, // CAN + 0x00, // EM + 0x00, // SUB + 0x00, // ESC + 0x00, // FS + 0x00, // GS + 0x00, // RS + 0x00, // US - 0x2c, // ' ' - 0x1e|SHIFT, // ! - 0x34|SHIFT, // " - 0x20|SHIFT, // # - 0x21|SHIFT, // $ - 0x22|SHIFT, // % - 0x24|SHIFT, // & - 0x34, // ' - 0x26|SHIFT, // ( - 0x27|SHIFT, // ) - 0x25|SHIFT, // * - 0x2e|SHIFT, // + - 0x36, // , - 0x2d, // - - 0x37, // . - 0x38, // / - 0x27, // 0 - 0x1e, // 1 - 0x1f, // 2 - 0x20, // 3 - 0x21, // 4 - 0x22, // 5 - 0x23, // 6 - 0x24, // 7 - 0x25, // 8 - 0x26, // 9 - 0x33|SHIFT, // : - 0x33, // ; - 0x36|SHIFT, // < - 0x2e, // = - 0x37|SHIFT, // > - 0x38|SHIFT, // ? - 0x1f|SHIFT, // @ - 0x04|SHIFT, // A - 0x05|SHIFT, // B - 0x06|SHIFT, // C - 0x07|SHIFT, // D - 0x08|SHIFT, // E - 0x09|SHIFT, // F - 0x0a|SHIFT, // G - 0x0b|SHIFT, // H - 0x0c|SHIFT, // I - 0x0d|SHIFT, // J - 0x0e|SHIFT, // K - 0x0f|SHIFT, // L - 0x10|SHIFT, // M - 0x11|SHIFT, // N - 0x12|SHIFT, // O - 0x13|SHIFT, // P - 0x14|SHIFT, // Q - 0x15|SHIFT, // R - 0x16|SHIFT, // S - 0x17|SHIFT, // T - 0x18|SHIFT, // U - 0x19|SHIFT, // V - 0x1a|SHIFT, // W - 0x1b|SHIFT, // X - 0x1c|SHIFT, // Y - 0x1d|SHIFT, // Z - 0x2f, // [ - 0x31, // bslash - 0x30, // ] - 0x23|SHIFT, // ^ - 0x2d|SHIFT, // _ - 0x35, // ` - 0x04, // a - 0x05, // b - 0x06, // c - 0x07, // d - 0x08, // e - 0x09, // f - 0x0a, // g - 0x0b, // h - 0x0c, // i - 0x0d, // j - 0x0e, // k - 0x0f, // l - 0x10, // m - 0x11, // n - 0x12, // o - 0x13, // p - 0x14, // q - 0x15, // r - 0x16, // s - 0x17, // t - 0x18, // u - 0x19, // v - 0x1a, // w - 0x1b, // x - 0x1c, // y - 0x1d, // z - 0x2f|SHIFT, // { - 0x31|SHIFT, // | - 0x30|SHIFT, // } - 0x35|SHIFT, // ~ - 0 // DEL + 0x2c, // ' ' + 0x1e | SHIFT, // ! + 0x34 | SHIFT, // " + 0x20 | SHIFT, // # + 0x21 | SHIFT, // $ + 0x22 | SHIFT, // % + 0x24 | SHIFT, // & + 0x34, // ' + 0x26 | SHIFT, // ( + 0x27 | SHIFT, // ) + 0x25 | SHIFT, // * + 0x2e | SHIFT, // + + 0x36, // , + 0x2d, // - + 0x37, // . + 0x38, // / + 0x27, // 0 + 0x1e, // 1 + 0x1f, // 2 + 0x20, // 3 + 0x21, // 4 + 0x22, // 5 + 0x23, // 6 + 0x24, // 7 + 0x25, // 8 + 0x26, // 9 + 0x33 | SHIFT, // : + 0x33, // ; + 0x36 | SHIFT, // < + 0x2e, // = + 0x37 | SHIFT, // > + 0x38 | SHIFT, // ? + 0x1f | SHIFT, // @ + 0x04 | SHIFT, // A + 0x05 | SHIFT, // B + 0x06 | SHIFT, // C + 0x07 | SHIFT, // D + 0x08 | SHIFT, // E + 0x09 | SHIFT, // F + 0x0a | SHIFT, // G + 0x0b | SHIFT, // H + 0x0c | SHIFT, // I + 0x0d | SHIFT, // J + 0x0e | SHIFT, // K + 0x0f | SHIFT, // L + 0x10 | SHIFT, // M + 0x11 | SHIFT, // N + 0x12 | SHIFT, // O + 0x13 | SHIFT, // P + 0x14 | SHIFT, // Q + 0x15 | SHIFT, // R + 0x16 | SHIFT, // S + 0x17 | SHIFT, // T + 0x18 | SHIFT, // U + 0x19 | SHIFT, // V + 0x1a | SHIFT, // W + 0x1b | SHIFT, // X + 0x1c | SHIFT, // Y + 0x1d | SHIFT, // Z + 0x2f, // [ + 0x31, // bslash + 0x30, // ] + 0x23 | SHIFT, // ^ + 0x2d | SHIFT, // _ + 0x35, // ` + 0x04, // a + 0x05, // b + 0x06, // c + 0x07, // d + 0x08, // e + 0x09, // f + 0x0a, // g + 0x0b, // h + 0x0c, // i + 0x0d, // j + 0x0e, // k + 0x0f, // l + 0x10, // m + 0x11, // n + 0x12, // o + 0x13, // p + 0x14, // q + 0x15, // r + 0x16, // s + 0x17, // t + 0x18, // u + 0x19, // v + 0x1a, // w + 0x1b, // x + 0x1c, // y + 0x1d, // z + 0x2f | SHIFT, // { + 0x31 | SHIFT, // | + 0x30 | SHIFT, // } + 0x35 | SHIFT, // ~ + 0 // DEL }; -size_t USBHIDKeyboard::pressRaw(uint8_t k) -{ - uint8_t i; - if (k >= 0xE0 && k < 0xE8) { - // it's a modifier key - _keyReport.modifiers |= (1<<(k-0xE0)); - } else if (k && k < 0xA5) { - // Add k to the key report only if it's not already present - // and if there is an empty slot. - if (_keyReport.keys[0] != k && _keyReport.keys[1] != k && - _keyReport.keys[2] != k && _keyReport.keys[3] != k && - _keyReport.keys[4] != k && _keyReport.keys[5] != k) { - - for (i=0; i<6; i++) { - if (_keyReport.keys[i] == 0x00) { - _keyReport.keys[i] = k; - break; - } - } - if (i == 6) { - return 0; - } +size_t USBHIDKeyboard::pressRaw(uint8_t k) { + uint8_t i; + if (k >= 0xE0 && k < 0xE8) { + // it's a modifier key + _keyReport.modifiers |= (1 << (k - 0xE0)); + } else if (k && k < 0xA5) { + // Add k to the key report only if it's not already present + // and if there is an empty slot. + if (_keyReport.keys[0] != k && _keyReport.keys[1] != k && _keyReport.keys[2] != k && _keyReport.keys[3] != k && _keyReport.keys[4] != k && _keyReport.keys[5] != k) { + + for (i = 0; i < 6; i++) { + if (_keyReport.keys[i] == 0x00) { + _keyReport.keys[i] = k; + break; } - } else { - //not a modifier and not a key + } + if (i == 6) { return 0; + } } - sendReport(&_keyReport); - return 1; + } else { + //not a modifier and not a key + return 0; + } + sendReport(&_keyReport); + return 1; } -size_t USBHIDKeyboard::releaseRaw(uint8_t k) -{ - uint8_t i; - if (k >= 0xE0 && k < 0xE8) { - // it's a modifier key - _keyReport.modifiers &= ~(1<<(k-0xE0)); - } else if (k && k < 0xA5) { - // Test the key report to see if k is present. Clear it if it exists. - // Check all positions in case the key is present more than once (which it shouldn't be) - for (i=0; i<6; i++) { - if (0 != k && _keyReport.keys[i] == k) { - _keyReport.keys[i] = 0x00; - } - } - } else { - //not a modifier and not a key - return 0; +size_t USBHIDKeyboard::releaseRaw(uint8_t k) { + uint8_t i; + if (k >= 0xE0 && k < 0xE8) { + // it's a modifier key + _keyReport.modifiers &= ~(1 << (k - 0xE0)); + } else if (k && k < 0xA5) { + // Test the key report to see if k is present. Clear it if it exists. + // Check all positions in case the key is present more than once (which it shouldn't be) + for (i = 0; i < 6; i++) { + if (0 != k && _keyReport.keys[i] == k) { + _keyReport.keys[i] = 0x00; + } } + } else { + //not a modifier and not a key + return 0; + } - sendReport(&_keyReport); - return 1; + sendReport(&_keyReport); + return 1; } // press() adds the specified key (printing, non-printing, or modifier) -// to the persistent key report and sends the report. Because of the way -// USB HID works, the host acts like the key remains pressed until we +// to the persistent key report and sends the report. Because of the way +// USB HID works, the host acts like the key remains pressed until we // call release(), releaseAll(), or otherwise clear the report and resend. -size_t USBHIDKeyboard::press(uint8_t k) -{ - if (k >= 0x88) { // it's a non-printing key (not a modifier) - k = k - 0x88; - } else if (k >= 0x80) { // it's a modifier key - _keyReport.modifiers |= (1<<(k-0x80)); - k = 0; - } else { // it's a printing key - k = _asciimap[k]; - if (!k) { - return 0; - } - if (k & 0x80) { // it's a capital letter or other character reached with shift - // At boot, some PCs need a separate report with the shift key down like a real keyboard. - if (shiftKeyReports) { - pressRaw(HID_KEY_SHIFT_LEFT); - } else { - _keyReport.modifiers |= 0x02; // the left shift modifier - } - k &= 0x7F; - } +size_t USBHIDKeyboard::press(uint8_t k) { + if (k >= 0x88) { // it's a non-printing key (not a modifier) + k = k - 0x88; + } else if (k >= 0x80) { // it's a modifier key + _keyReport.modifiers |= (1 << (k - 0x80)); + k = 0; + } else { // it's a printing key + k = _asciimap[k]; + if (!k) { + return 0; + } + if (k & 0x80) { // it's a capital letter or other character reached with shift + // At boot, some PCs need a separate report with the shift key down like a real keyboard. + if (shiftKeyReports) { + pressRaw(HID_KEY_SHIFT_LEFT); + } else { + _keyReport.modifiers |= 0x02; // the left shift modifier + } + k &= 0x7F; } - return pressRaw(k); + } + return pressRaw(k); } // release() takes the specified key out of the persistent key report and // sends the report. This tells the OS the key is no longer pressed and that // it shouldn't be repeated any more. -size_t USBHIDKeyboard::release(uint8_t k) -{ - if (k >= 0x88) { // it's a non-printing key (not a modifier) - k = k - 0x88; - } else if (k >= 0x80) { // it's a modifier key - _keyReport.modifiers &= ~(1<<(k-0x80)); - k = 0; - } else { // it's a printing key - k = _asciimap[k]; - if (!k) { - return 0; - } - if (k & 0x80) { // it's a capital letter or other character reached with shift - if (shiftKeyReports) { - releaseRaw(k & 0x7F); // Release key without shift modifier - k = HID_KEY_SHIFT_LEFT; // Below, release shift modifier - } else { - _keyReport.modifiers &= ~(0x02); // the left shift modifier - k &= 0x7F; - } - } +size_t USBHIDKeyboard::release(uint8_t k) { + if (k >= 0x88) { // it's a non-printing key (not a modifier) + k = k - 0x88; + } else if (k >= 0x80) { // it's a modifier key + _keyReport.modifiers &= ~(1 << (k - 0x80)); + k = 0; + } else { // it's a printing key + k = _asciimap[k]; + if (!k) { + return 0; + } + if (k & 0x80) { // it's a capital letter or other character reached with shift + if (shiftKeyReports) { + releaseRaw(k & 0x7F); // Release key without shift modifier + k = HID_KEY_SHIFT_LEFT; // Below, release shift modifier + } else { + _keyReport.modifiers &= ~(0x02); // the left shift modifier + k &= 0x7F; + } } - return releaseRaw(k); + } + return releaseRaw(k); } -void USBHIDKeyboard::releaseAll(void) -{ - _keyReport.keys[0] = 0; - _keyReport.keys[1] = 0; - _keyReport.keys[2] = 0; - _keyReport.keys[3] = 0; - _keyReport.keys[4] = 0; - _keyReport.keys[5] = 0; - _keyReport.modifiers = 0; - sendReport(&_keyReport); +void USBHIDKeyboard::releaseAll(void) { + _keyReport.keys[0] = 0; + _keyReport.keys[1] = 0; + _keyReport.keys[2] = 0; + _keyReport.keys[3] = 0; + _keyReport.keys[4] = 0; + _keyReport.keys[5] = 0; + _keyReport.modifiers = 0; + sendReport(&_keyReport); } -size_t USBHIDKeyboard::write(uint8_t c) -{ - uint8_t p = press(c); // Keydown - release(c); // Keyup - return p; // just return the result of press() since release() almost always returns 1 +size_t USBHIDKeyboard::write(uint8_t c) { + uint8_t p = press(c); // Keydown + release(c); // Keyup + return p; // just return the result of press() since release() almost always returns 1 } -size_t USBHIDKeyboard::write(const uint8_t *buffer, size_t size) { - size_t n = 0; - while (size--) { - if (*buffer != '\r') { - if (write(*buffer)) { - n++; - } else { - break; - } - } - buffer++; +size_t USBHIDKeyboard::write(const uint8_t* buffer, size_t size) { + size_t n = 0; + while (size--) { + if (*buffer != '\r') { + if (write(*buffer)) { + n++; + } else { + break; + } } - return n; + buffer++; + } + return n; } #endif /* CONFIG_TINYUSB_HID_ENABLED */ diff --git a/libraries/USB/src/USBHIDKeyboard.h b/libraries/USB/src/USBHIDKeyboard.h index 0c75c7dcfc9..a2198a80453 100644 --- a/libraries/USB/src/USBHIDKeyboard.h +++ b/libraries/USB/src/USBHIDKeyboard.h @@ -33,83 +33,83 @@ ESP_EVENT_DECLARE_BASE(ARDUINO_USB_HID_KEYBOARD_EVENTS); typedef enum { - ARDUINO_USB_HID_KEYBOARD_ANY_EVENT = ESP_EVENT_ANY_ID, - ARDUINO_USB_HID_KEYBOARD_LED_EVENT = 0, - ARDUINO_USB_HID_KEYBOARD_MAX_EVENT, + ARDUINO_USB_HID_KEYBOARD_ANY_EVENT = ESP_EVENT_ANY_ID, + ARDUINO_USB_HID_KEYBOARD_LED_EVENT = 0, + ARDUINO_USB_HID_KEYBOARD_MAX_EVENT, } arduino_usb_hid_keyboard_event_t; typedef union { - struct { - uint8_t numlock:1; - uint8_t capslock:1; - uint8_t scrolllock:1; - uint8_t compose:1; - uint8_t kana:1; - uint8_t reserved:3; - }; - uint8_t leds; + struct { + uint8_t numlock : 1; + uint8_t capslock : 1; + uint8_t scrolllock : 1; + uint8_t compose : 1; + uint8_t kana : 1; + uint8_t reserved : 3; + }; + uint8_t leds; } arduino_usb_hid_keyboard_event_data_t; -#define KEY_LEFT_CTRL 0x80 -#define KEY_LEFT_SHIFT 0x81 -#define KEY_LEFT_ALT 0x82 -#define KEY_LEFT_GUI 0x83 -#define KEY_RIGHT_CTRL 0x84 +#define KEY_LEFT_CTRL 0x80 +#define KEY_LEFT_SHIFT 0x81 +#define KEY_LEFT_ALT 0x82 +#define KEY_LEFT_GUI 0x83 +#define KEY_RIGHT_CTRL 0x84 #define KEY_RIGHT_SHIFT 0x85 -#define KEY_RIGHT_ALT 0x86 -#define KEY_RIGHT_GUI 0x87 +#define KEY_RIGHT_ALT 0x86 +#define KEY_RIGHT_GUI 0x87 -#define KEY_UP_ARROW 0xDA -#define KEY_DOWN_ARROW 0xD9 -#define KEY_LEFT_ARROW 0xD8 +#define KEY_UP_ARROW 0xDA +#define KEY_DOWN_ARROW 0xD9 +#define KEY_LEFT_ARROW 0xD8 #define KEY_RIGHT_ARROW 0xD7 -#define KEY_MENU 0xFE -#define KEY_SPACE 0x20 -#define KEY_BACKSPACE 0xB2 -#define KEY_TAB 0xB3 -#define KEY_RETURN 0xB0 -#define KEY_ESC 0xB1 -#define KEY_INSERT 0xD1 -#define KEY_DELETE 0xD4 -#define KEY_PAGE_UP 0xD3 -#define KEY_PAGE_DOWN 0xD6 -#define KEY_HOME 0xD2 -#define KEY_END 0xD5 -#define KEY_NUM_LOCK 0xDB -#define KEY_CAPS_LOCK 0xC1 -#define KEY_F1 0xC2 -#define KEY_F2 0xC3 -#define KEY_F3 0xC4 -#define KEY_F4 0xC5 -#define KEY_F5 0xC6 -#define KEY_F6 0xC7 -#define KEY_F7 0xC8 -#define KEY_F8 0xC9 -#define KEY_F9 0xCA -#define KEY_F10 0xCB -#define KEY_F11 0xCC -#define KEY_F12 0xCD -#define KEY_F13 0xF0 -#define KEY_F14 0xF1 -#define KEY_F15 0xF2 -#define KEY_F16 0xF3 -#define KEY_F17 0xF4 -#define KEY_F18 0xF5 -#define KEY_F19 0xF6 -#define KEY_F20 0xF7 -#define KEY_F21 0xF8 -#define KEY_F22 0xF9 -#define KEY_F23 0xFA -#define KEY_F24 0xFB +#define KEY_MENU 0xFE +#define KEY_SPACE 0x20 +#define KEY_BACKSPACE 0xB2 +#define KEY_TAB 0xB3 +#define KEY_RETURN 0xB0 +#define KEY_ESC 0xB1 +#define KEY_INSERT 0xD1 +#define KEY_DELETE 0xD4 +#define KEY_PAGE_UP 0xD3 +#define KEY_PAGE_DOWN 0xD6 +#define KEY_HOME 0xD2 +#define KEY_END 0xD5 +#define KEY_NUM_LOCK 0xDB +#define KEY_CAPS_LOCK 0xC1 +#define KEY_F1 0xC2 +#define KEY_F2 0xC3 +#define KEY_F3 0xC4 +#define KEY_F4 0xC5 +#define KEY_F5 0xC6 +#define KEY_F6 0xC7 +#define KEY_F7 0xC8 +#define KEY_F8 0xC9 +#define KEY_F9 0xCA +#define KEY_F10 0xCB +#define KEY_F11 0xCC +#define KEY_F12 0xCD +#define KEY_F13 0xF0 +#define KEY_F14 0xF1 +#define KEY_F15 0xF2 +#define KEY_F16 0xF3 +#define KEY_F17 0xF4 +#define KEY_F18 0xF5 +#define KEY_F19 0xF6 +#define KEY_F20 0xF7 +#define KEY_F21 0xF8 +#define KEY_F22 0xF9 +#define KEY_F23 0xFA +#define KEY_F24 0xFB #define KEY_PRINT_SCREEN 0xCE #define KEY_SCROLL_LOCK 0xCF -#define KEY_PAUSE 0xD0 +#define KEY_PAUSE 0xD0 -#define LED_NUMLOCK 0x01 -#define LED_CAPSLOCK 0x02 -#define LED_SCROLLLOCK 0x04 -#define LED_COMPOSE 0x08 -#define LED_KANA 0x10 +#define LED_NUMLOCK 0x01 +#define LED_CAPSLOCK 0x02 +#define LED_SCROLLLOCK 0x04 +#define LED_COMPOSE 0x08 +#define LED_KANA 0x10 // Low level key report: up to 6 keys and shift, ctrl etc at once typedef struct @@ -119,34 +119,33 @@ typedef struct uint8_t keys[6]; } KeyReport; -class USBHIDKeyboard: public USBHIDDevice, public Print -{ +class USBHIDKeyboard : public USBHIDDevice, public Print { private: - USBHID hid; - KeyReport _keyReport; - bool shiftKeyReports; + USBHID hid; + KeyReport _keyReport; + bool shiftKeyReports; public: - USBHIDKeyboard(void); - void begin(void); - void end(void); - size_t write(uint8_t k); - size_t write(const uint8_t *buffer, size_t size); - size_t press(uint8_t k); - size_t release(uint8_t k); - void releaseAll(void); - void sendReport(KeyReport* keys); - void setShiftKeyReports(bool set); - - //raw functions work with TinyUSB's HID_KEY_* macros - size_t pressRaw(uint8_t k); - size_t releaseRaw(uint8_t k); - - void onEvent(esp_event_handler_t callback); - void onEvent(arduino_usb_hid_keyboard_event_t event, esp_event_handler_t callback); - - // internal use - uint16_t _onGetDescriptor(uint8_t* buffer); - void _onOutput(uint8_t report_id, const uint8_t* buffer, uint16_t len); + USBHIDKeyboard(void); + void begin(void); + void end(void); + size_t write(uint8_t k); + size_t write(const uint8_t* buffer, size_t size); + size_t press(uint8_t k); + size_t release(uint8_t k); + void releaseAll(void); + void sendReport(KeyReport* keys); + void setShiftKeyReports(bool set); + + //raw functions work with TinyUSB's HID_KEY_* macros + size_t pressRaw(uint8_t k); + size_t releaseRaw(uint8_t k); + + void onEvent(esp_event_handler_t callback); + void onEvent(arduino_usb_hid_keyboard_event_t event, esp_event_handler_t callback); + + // internal use + uint16_t _onGetDescriptor(uint8_t* buffer); + void _onOutput(uint8_t report_id, const uint8_t* buffer, uint16_t len); }; #endif /* CONFIG_TINYUSB_HID_ENABLED */ diff --git a/libraries/USB/src/USBHIDMouse.cpp b/libraries/USB/src/USBHIDMouse.cpp index 5e031768ffa..92fe0abddea 100644 --- a/libraries/USB/src/USBHIDMouse.cpp +++ b/libraries/USB/src/USBHIDMouse.cpp @@ -25,132 +25,119 @@ #include "USBHIDMouse.h" -USBHIDMouseBase::USBHIDMouseBase(HIDMouseType_t *type) : hid(), _buttons(0), _type(type) -{ - static bool initialized = false; - if(!initialized){ - initialized = true; - hid.addDevice(this, _type->descriptor_size); - } +USBHIDMouseBase::USBHIDMouseBase(HIDMouseType_t* type) + : hid(), _buttons(0), _type(type) { + static bool initialized = false; + if (!initialized) { + initialized = true; + hid.addDevice(this, _type->descriptor_size); + } }; -uint16_t USBHIDMouseBase::_onGetDescriptor(uint8_t* dst) -{ - memcpy(dst, _type->report_descriptor, _type->descriptor_size); - return _type->descriptor_size; +uint16_t USBHIDMouseBase::_onGetDescriptor(uint8_t* dst) { + memcpy(dst, _type->report_descriptor, _type->descriptor_size); + return _type->descriptor_size; } -void USBHIDMouseBase::buttons(uint8_t b) -{ - if (b != _buttons){ - _buttons = b; - } +void USBHIDMouseBase::buttons(uint8_t b) { + if (b != _buttons) { + _buttons = b; + } } -void USBHIDMouseBase::begin() -{ - hid.begin(); +void USBHIDMouseBase::begin() { + hid.begin(); } -void USBHIDMouseBase::end() -{ +void USBHIDMouseBase::end() { } -void USBHIDMouseBase::press(uint8_t b) -{ - this->buttons(_buttons | b); +void USBHIDMouseBase::press(uint8_t b) { + this->buttons(_buttons | b); } -void USBHIDMouseBase::release(uint8_t b) -{ - this->buttons(_buttons & ~b); +void USBHIDMouseBase::release(uint8_t b) { + this->buttons(_buttons & ~b); } -bool USBHIDMouseBase::isPressed(uint8_t b) -{ - if ((b & _buttons) > 0) { - return true; - } - return false; +bool USBHIDMouseBase::isPressed(uint8_t b) { + if ((b & _buttons) > 0) { + return true; + } + return false; } static const uint8_t abs_mouse_report_descriptor[] = { - TUD_HID_REPORT_DESC_ABSMOUSE(HID_REPORT_ID(HID_REPORT_ID_MOUSE)) + TUD_HID_REPORT_DESC_ABSMOUSE(HID_REPORT_ID(HID_REPORT_ID_MOUSE)) }; HIDMouseType_t HIDMouseAbs = { HID_MOUSE_ABSOLUTE, abs_mouse_report_descriptor, sizeof(abs_mouse_report_descriptor), sizeof(hid_abs_mouse_report_t) }; -void USBHIDAbsoluteMouse::move(int16_t x, int16_t y, int8_t wheel, int8_t pan) -{ - hid_abs_mouse_report_t report; - report.buttons = _buttons; - report.x = _lastx = x; - report.y = _lasty = y; - report.wheel = wheel; - report.pan = pan; - sendReport(report); +void USBHIDAbsoluteMouse::move(int16_t x, int16_t y, int8_t wheel, int8_t pan) { + hid_abs_mouse_report_t report; + report.buttons = _buttons; + report.x = _lastx = x; + report.y = _lasty = y; + report.wheel = wheel; + report.pan = pan; + sendReport(report); } -void USBHIDAbsoluteMouse::click(uint8_t b) -{ - _buttons = b; - move(_lastx,_lasty); - _buttons = 0; - move(_lastx,_lasty); +void USBHIDAbsoluteMouse::click(uint8_t b) { + _buttons = b; + move(_lastx, _lasty); + _buttons = 0; + move(_lastx, _lasty); } -void USBHIDAbsoluteMouse::buttons(uint8_t b) -{ - if (b != _buttons){ - _buttons = b; - move(_lastx,_lasty); - } +void USBHIDAbsoluteMouse::buttons(uint8_t b) { + if (b != _buttons) { + _buttons = b; + move(_lastx, _lasty); + } } static const uint8_t rel_mouse_report_descriptor[] = { - TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(HID_REPORT_ID_MOUSE)) + TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(HID_REPORT_ID_MOUSE)) }; HIDMouseType_t HIDMouseRel = { HID_MOUSE_RELATIVE, rel_mouse_report_descriptor, sizeof(rel_mouse_report_descriptor), sizeof(hid_mouse_report_t) }; -void USBHIDRelativeMouse::move(int8_t x, int8_t y, int8_t wheel, int8_t pan) -{ - hid_mouse_report_t report = { - .buttons = _buttons, - .x = x, - .y = y, - .wheel = wheel, - .pan = pan - }; - sendReport(report); +void USBHIDRelativeMouse::move(int8_t x, int8_t y, int8_t wheel, int8_t pan) { + hid_mouse_report_t report = { + .buttons = _buttons, + .x = x, + .y = y, + .wheel = wheel, + .pan = pan + }; + sendReport(report); } -void USBHIDRelativeMouse::click(uint8_t b) -{ - _buttons = b; - move(0,0); - _buttons = 0; - move(0,0); +void USBHIDRelativeMouse::click(uint8_t b) { + _buttons = b; + move(0, 0); + _buttons = 0; + move(0, 0); } -void USBHIDRelativeMouse::buttons(uint8_t b) -{ - if (b != _buttons){ - _buttons = b; - move(0,0); - } +void USBHIDRelativeMouse::buttons(uint8_t b) { + if (b != _buttons) { + _buttons = b; + move(0, 0); + } } diff --git a/libraries/USB/src/USBHIDMouse.h b/libraries/USB/src/USBHIDMouse.h index 3bf31b46685..e9f8a727309 100644 --- a/libraries/USB/src/USBHIDMouse.h +++ b/libraries/USB/src/USBHIDMouse.h @@ -27,23 +27,21 @@ #include "USBHID.h" #if CONFIG_TINYUSB_HID_ENABLED -#define MOUSE_LEFT 0x01 -#define MOUSE_RIGHT 0x02 -#define MOUSE_MIDDLE 0x04 -#define MOUSE_BACKWARD 0x08 -#define MOUSE_FORWARD 0x10 -#define MOUSE_ALL 0x1F +#define MOUSE_LEFT 0x01 +#define MOUSE_RIGHT 0x02 +#define MOUSE_MIDDLE 0x04 +#define MOUSE_BACKWARD 0x08 +#define MOUSE_FORWARD 0x10 +#define MOUSE_ALL 0x1F #include "./tusb_hid_mouse.h" -enum MousePositioning_t -{ +enum MousePositioning_t { HID_MOUSE_RELATIVE, HID_MOUSE_ABSOLUTE }; -struct HIDMouseType_t -{ +struct HIDMouseType_t { MousePositioning_t positioning; const uint8_t* report_descriptor; size_t descriptor_size; @@ -54,44 +52,48 @@ extern HIDMouseType_t HIDMouseRel; extern HIDMouseType_t HIDMouseAbs; -class USBHIDMouseBase: public USBHIDDevice { +class USBHIDMouseBase : public USBHIDDevice { public: - USBHIDMouseBase(HIDMouseType_t *type); - void begin(void); - void end(void); - void press(uint8_t b = MOUSE_LEFT); // press LEFT by default - void release(uint8_t b = MOUSE_LEFT); // release LEFT by default - bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default - template bool sendReport(T report) { return hid.SendReport( HID_REPORT_ID_MOUSE, &report, _type->report_size ); }; - // internal use - uint16_t _onGetDescriptor(uint8_t* buffer); - virtual void click(uint8_t b) = 0; - virtual void buttons(uint8_t b) = 0; + USBHIDMouseBase(HIDMouseType_t* type); + void begin(void); + void end(void); + void press(uint8_t b = MOUSE_LEFT); // press LEFT by default + void release(uint8_t b = MOUSE_LEFT); // release LEFT by default + bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default + template bool sendReport(T report) { + return hid.SendReport(HID_REPORT_ID_MOUSE, &report, _type->report_size); + }; + // internal use + uint16_t _onGetDescriptor(uint8_t* buffer); + virtual void click(uint8_t b) = 0; + virtual void buttons(uint8_t b) = 0; protected: - USBHID hid; - uint8_t _buttons; - HIDMouseType_t *_type; + USBHID hid; + uint8_t _buttons; + HIDMouseType_t* _type; }; -class USBHIDRelativeMouse: public USBHIDMouseBase { +class USBHIDRelativeMouse : public USBHIDMouseBase { public: - USBHIDRelativeMouse(void): USBHIDMouseBase(&HIDMouseRel) { } - void move(int8_t x, int8_t y, int8_t wheel = 0, int8_t pan = 0); - void click(uint8_t b = MOUSE_LEFT) override; - void buttons(uint8_t b) override; + USBHIDRelativeMouse(void) + : USBHIDMouseBase(&HIDMouseRel) {} + void move(int8_t x, int8_t y, int8_t wheel = 0, int8_t pan = 0); + void click(uint8_t b = MOUSE_LEFT) override; + void buttons(uint8_t b) override; }; -class USBHIDAbsoluteMouse: public USBHIDMouseBase { +class USBHIDAbsoluteMouse : public USBHIDMouseBase { public: - USBHIDAbsoluteMouse(void): USBHIDMouseBase(&HIDMouseAbs) { } - void move(int16_t x, int16_t y, int8_t wheel = 0, int8_t pan = 0); - void click(uint8_t b = MOUSE_LEFT) override; - void buttons(uint8_t b) override; + USBHIDAbsoluteMouse(void) + : USBHIDMouseBase(&HIDMouseAbs) {} + void move(int16_t x, int16_t y, int8_t wheel = 0, int8_t pan = 0); + void click(uint8_t b = MOUSE_LEFT) override; + void buttons(uint8_t b) override; private: - int16_t _lastx = 0; - int16_t _lasty = 0; + int16_t _lastx = 0; + int16_t _lasty = 0; }; diff --git a/libraries/USB/src/USBHIDSystemControl.cpp b/libraries/USB/src/USBHIDSystemControl.cpp index 086d9bd627c..2fa21321830 100644 --- a/libraries/USB/src/USBHIDSystemControl.cpp +++ b/libraries/USB/src/USBHIDSystemControl.cpp @@ -19,42 +19,43 @@ #include "USBHIDSystemControl.h" static const uint8_t report_descriptor[] = { - TUD_HID_REPORT_DESC_SYSTEM_CONTROL(HID_REPORT_ID(HID_REPORT_ID_SYSTEM_CONTROL)) + TUD_HID_REPORT_DESC_SYSTEM_CONTROL(HID_REPORT_ID(HID_REPORT_ID_SYSTEM_CONTROL)) }; -USBHIDSystemControl::USBHIDSystemControl(): hid(){ - static bool initialized = false; - if(!initialized){ - initialized = true; - hid.addDevice(this, sizeof(report_descriptor)); - } +USBHIDSystemControl::USBHIDSystemControl() + : hid() { + static bool initialized = false; + if (!initialized) { + initialized = true; + hid.addDevice(this, sizeof(report_descriptor)); + } } -uint16_t USBHIDSystemControl::_onGetDescriptor(uint8_t* dst){ - memcpy(dst, report_descriptor, sizeof(report_descriptor)); - return sizeof(report_descriptor); +uint16_t USBHIDSystemControl::_onGetDescriptor(uint8_t* dst) { + memcpy(dst, report_descriptor, sizeof(report_descriptor)); + return sizeof(report_descriptor); } -void USBHIDSystemControl::begin(){ - hid.begin(); +void USBHIDSystemControl::begin() { + hid.begin(); } -void USBHIDSystemControl::end(){ +void USBHIDSystemControl::end() { } -bool USBHIDSystemControl::send(uint8_t value){ - return hid.SendReport(HID_REPORT_ID_SYSTEM_CONTROL, &value, 1); +bool USBHIDSystemControl::send(uint8_t value) { + return hid.SendReport(HID_REPORT_ID_SYSTEM_CONTROL, &value, 1); } -size_t USBHIDSystemControl::press(uint8_t k){ - if(k > 3){ - return 0; - } - return send(k); +size_t USBHIDSystemControl::press(uint8_t k) { + if (k > 3) { + return 0; + } + return send(k); } -size_t USBHIDSystemControl::release(){ - return send(0); +size_t USBHIDSystemControl::release() { + return send(0); } #endif /* CONFIG_TINYUSB_HID_ENABLED */ diff --git a/libraries/USB/src/USBHIDSystemControl.h b/libraries/USB/src/USBHIDSystemControl.h index 84ef40ff1c6..31e434f16e2 100644 --- a/libraries/USB/src/USBHIDSystemControl.h +++ b/libraries/USB/src/USBHIDSystemControl.h @@ -20,24 +20,24 @@ #include "USBHID.h" #if CONFIG_TINYUSB_HID_ENABLED -#define SYSTEM_CONTROL_NONE 0 -#define SYSTEM_CONTROL_POWER_OFF 1 -#define SYSTEM_CONTROL_STANDBY 2 -#define SYSTEM_CONTROL_WAKE_HOST 3 +#define SYSTEM_CONTROL_NONE 0 +#define SYSTEM_CONTROL_POWER_OFF 1 +#define SYSTEM_CONTROL_STANDBY 2 +#define SYSTEM_CONTROL_WAKE_HOST 3 -class USBHIDSystemControl: public USBHIDDevice { +class USBHIDSystemControl : public USBHIDDevice { private: - USBHID hid; - bool send(uint8_t value); + USBHID hid; + bool send(uint8_t value); public: - USBHIDSystemControl(void); - void begin(void); - void end(void); - size_t press(uint8_t k); - size_t release(); + USBHIDSystemControl(void); + void begin(void); + void end(void); + size_t press(uint8_t k); + size_t release(); - // internal use - uint16_t _onGetDescriptor(uint8_t* buffer); + // internal use + uint16_t _onGetDescriptor(uint8_t* buffer); }; #endif /* CONFIG_TINYUSB_HID_ENABLED */ diff --git a/libraries/USB/src/USBHIDVendor.cpp b/libraries/USB/src/USBHIDVendor.cpp index 5eab6571d7e..7dcb59b3882 100644 --- a/libraries/USB/src/USBHIDVendor.cpp +++ b/libraries/USB/src/USBHIDVendor.cpp @@ -20,40 +20,36 @@ #include "USBHIDVendor.h" ESP_EVENT_DEFINE_BASE(ARDUINO_USB_HID_VENDOR_EVENTS); -esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, TickType_t ticks_to_wait); -esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg); +esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void* event_data, size_t event_data_size, TickType_t ticks_to_wait); +esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void* event_handler_arg); // HID Generic Input, Output & Feature // - 1st parameter is report size (mandatory) // - 2nd parameter is report id HID_REPORT_ID(n) (optional) #define TUD_HID_REPORT_DESC_GENERIC_INOUT_FEATURE(report_size, ...) \ - HID_USAGE_PAGE_N ( HID_USAGE_PAGE_VENDOR, 2 ),\ - HID_USAGE ( 0x01 ),\ - HID_COLLECTION ( HID_COLLECTION_APPLICATION ),\ - /* Report ID if any */\ - __VA_ARGS__ \ - /* Input */ \ - HID_USAGE ( 0x02 ),\ - HID_LOGICAL_MIN ( 0x00 ),\ - HID_LOGICAL_MAX ( 0xff ),\ - HID_REPORT_SIZE ( 8 ),\ - HID_REPORT_COUNT( report_size ),\ - HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),\ - /* Output */ \ - HID_USAGE ( 0x03 ),\ - HID_LOGICAL_MIN ( 0x00 ),\ - HID_LOGICAL_MAX ( 0xff ),\ - HID_REPORT_SIZE ( 8 ),\ - HID_REPORT_COUNT( report_size ),\ - HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),\ - /* Feature */ \ - HID_USAGE ( 0x04 ),\ - HID_LOGICAL_MIN ( 0x00 ),\ - HID_LOGICAL_MAX ( 0xff ),\ - HID_REPORT_SIZE ( 8 ),\ - HID_REPORT_COUNT( report_size ),\ - HID_FEATURE ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),\ - HID_COLLECTION_END \ + HID_USAGE_PAGE_N(HID_USAGE_PAGE_VENDOR, 2), \ + HID_USAGE(0x01), \ + HID_COLLECTION(HID_COLLECTION_APPLICATION), /* Report ID if any */ \ + __VA_ARGS__ /* Input */ \ + HID_USAGE(0x02), \ + HID_LOGICAL_MIN(0x00), \ + HID_LOGICAL_MAX(0xff), \ + HID_REPORT_SIZE(8), \ + HID_REPORT_COUNT(report_size), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), /* Output */ \ + HID_USAGE(0x03), \ + HID_LOGICAL_MIN(0x00), \ + HID_LOGICAL_MAX(0xff), \ + HID_REPORT_SIZE(8), \ + HID_REPORT_COUNT(report_size), \ + HID_OUTPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), /* Feature */ \ + HID_USAGE(0x04), \ + HID_LOGICAL_MIN(0x00), \ + HID_LOGICAL_MAX(0xff), \ + HID_REPORT_SIZE(8), \ + HID_REPORT_COUNT(report_size), \ + HID_FEATURE(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \ + HID_COLLECTION_END #define TUD_HID_REPORT_DESC_GENERIC_INOUT_FEATURE_LEN 46 @@ -63,175 +59,176 @@ static uint8_t feature[64]; static QueueHandle_t rx_queue = NULL; static bool prepend_size = false; -USBHIDVendor::USBHIDVendor(uint8_t report_size, bool prepend): hid(){ - static bool initialized = false; - if(!initialized){ - initialized = true; - hid.addDevice(this, TUD_HID_REPORT_DESC_GENERIC_INOUT_FEATURE_LEN); - memset(feature, 0, 64); - if(report_size < 64){ - HID_VENDOR_REPORT_SIZE = report_size; - } - prepend_size = prepend; +USBHIDVendor::USBHIDVendor(uint8_t report_size, bool prepend) + : hid() { + static bool initialized = false; + if (!initialized) { + initialized = true; + hid.addDevice(this, TUD_HID_REPORT_DESC_GENERIC_INOUT_FEATURE_LEN); + memset(feature, 0, 64); + if (report_size < 64) { + HID_VENDOR_REPORT_SIZE = report_size; } + prepend_size = prepend; + } } -uint16_t USBHIDVendor::_onGetDescriptor(uint8_t* dst){ - uint8_t report_descriptor[] = { - TUD_HID_REPORT_DESC_GENERIC_INOUT_FEATURE(HID_VENDOR_REPORT_SIZE, HID_REPORT_ID(HID_REPORT_ID_VENDOR)) - }; - memcpy(dst, report_descriptor, sizeof(report_descriptor)); - return sizeof(report_descriptor); +uint16_t USBHIDVendor::_onGetDescriptor(uint8_t* dst) { + uint8_t report_descriptor[] = { + TUD_HID_REPORT_DESC_GENERIC_INOUT_FEATURE(HID_VENDOR_REPORT_SIZE, HID_REPORT_ID(HID_REPORT_ID_VENDOR)) + }; + memcpy(dst, report_descriptor, sizeof(report_descriptor)); + return sizeof(report_descriptor); } -void USBHIDVendor::prependInputPacketsWithSize(bool enable){ - prepend_size = enable; +void USBHIDVendor::prependInputPacketsWithSize(bool enable) { + prepend_size = enable; } -size_t USBHIDVendor::setRxBufferSize(size_t rx_queue_len){ - if(rx_queue){ - if(!rx_queue_len){ - vQueueDelete(rx_queue); - rx_queue = NULL; - } - return 0; +size_t USBHIDVendor::setRxBufferSize(size_t rx_queue_len) { + if (rx_queue) { + if (!rx_queue_len) { + vQueueDelete(rx_queue); + rx_queue = NULL; } - rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t)); - if(!rx_queue){ - return 0; - } - return rx_queue_len; + return 0; + } + rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t)); + if (!rx_queue) { + return 0; + } + return rx_queue_len; } -void USBHIDVendor::begin(){ - hid.begin(); - setRxBufferSize(256);//default if not preset +void USBHIDVendor::begin() { + hid.begin(); + setRxBufferSize(256); //default if not preset } -void USBHIDVendor::end(){ - setRxBufferSize(0); +void USBHIDVendor::end() { + setRxBufferSize(0); } -void USBHIDVendor::onEvent(esp_event_handler_t callback){ - onEvent(ARDUINO_USB_HID_VENDOR_ANY_EVENT, callback); +void USBHIDVendor::onEvent(esp_event_handler_t callback) { + onEvent(ARDUINO_USB_HID_VENDOR_ANY_EVENT, callback); } -void USBHIDVendor::onEvent(arduino_usb_hid_vendor_event_t event, esp_event_handler_t callback){ - arduino_usb_event_handler_register_with(ARDUINO_USB_HID_VENDOR_EVENTS, event, callback, this); +void USBHIDVendor::onEvent(arduino_usb_hid_vendor_event_t event, esp_event_handler_t callback) { + arduino_usb_event_handler_register_with(ARDUINO_USB_HID_VENDOR_EVENTS, event, callback, this); } -uint16_t USBHIDVendor::_onGetFeature(uint8_t report_id, uint8_t* buffer, uint16_t len){ - if(report_id != HID_REPORT_ID_VENDOR){ - return 0; - } - memcpy(buffer, feature, len); - arduino_usb_hid_vendor_event_data_t p; - p.buffer = feature; - p.len = len; - arduino_usb_event_post(ARDUINO_USB_HID_VENDOR_EVENTS, ARDUINO_USB_HID_VENDOR_GET_FEATURE_EVENT, &p, sizeof(arduino_usb_hid_vendor_event_data_t), portMAX_DELAY); - return len; +uint16_t USBHIDVendor::_onGetFeature(uint8_t report_id, uint8_t* buffer, uint16_t len) { + if (report_id != HID_REPORT_ID_VENDOR) { + return 0; + } + memcpy(buffer, feature, len); + arduino_usb_hid_vendor_event_data_t p; + p.buffer = feature; + p.len = len; + arduino_usb_event_post(ARDUINO_USB_HID_VENDOR_EVENTS, ARDUINO_USB_HID_VENDOR_GET_FEATURE_EVENT, &p, sizeof(arduino_usb_hid_vendor_event_data_t), portMAX_DELAY); + return len; } -void USBHIDVendor::_onSetFeature(uint8_t report_id, const uint8_t* buffer, uint16_t len){ - if(report_id != HID_REPORT_ID_VENDOR){ - return; - } - memcpy(feature, buffer, len); - arduino_usb_hid_vendor_event_data_t p; - p.buffer = feature; - p.len = len; - arduino_usb_event_post(ARDUINO_USB_HID_VENDOR_EVENTS, ARDUINO_USB_HID_VENDOR_SET_FEATURE_EVENT, &p, sizeof(arduino_usb_hid_vendor_event_data_t), portMAX_DELAY); +void USBHIDVendor::_onSetFeature(uint8_t report_id, const uint8_t* buffer, uint16_t len) { + if (report_id != HID_REPORT_ID_VENDOR) { + return; + } + memcpy(feature, buffer, len); + arduino_usb_hid_vendor_event_data_t p; + p.buffer = feature; + p.len = len; + arduino_usb_event_post(ARDUINO_USB_HID_VENDOR_EVENTS, ARDUINO_USB_HID_VENDOR_SET_FEATURE_EVENT, &p, sizeof(arduino_usb_hid_vendor_event_data_t), portMAX_DELAY); } -void USBHIDVendor::_onOutput(uint8_t report_id, const uint8_t* buffer, uint16_t len){ - if(report_id != HID_REPORT_ID_VENDOR){ - return; +void USBHIDVendor::_onOutput(uint8_t report_id, const uint8_t* buffer, uint16_t len) { + if (report_id != HID_REPORT_ID_VENDOR) { + return; + } + for (uint32_t i = 0; i < len; i++) { + if (rx_queue == NULL || !xQueueSend(rx_queue, buffer + i, 0)) { + len = i + 1; + log_e("RX Queue Overflow"); + break; + } + } + arduino_usb_hid_vendor_event_data_t p; + p.buffer = buffer; + p.len = len; + arduino_usb_event_post(ARDUINO_USB_HID_VENDOR_EVENTS, ARDUINO_USB_HID_VENDOR_OUTPUT_EVENT, &p, sizeof(arduino_usb_hid_vendor_event_data_t), portMAX_DELAY); +} + +size_t USBHIDVendor::write(const uint8_t* buffer, size_t len) { + uint8_t hid_in[HID_VENDOR_REPORT_SIZE]; + const uint8_t* data = (const uint8_t*)buffer; + uint8_t size_offset = prepend_size ? 1 : 0; + size_t to_send = len, max_send = HID_VENDOR_REPORT_SIZE - size_offset, will_send = 0; + while (to_send) { + will_send = to_send; + if (will_send > max_send) { + will_send = max_send; } - for(uint32_t i=0; i max_send){ - will_send = max_send; - } - if(prepend_size){ - hid_in[0] = will_send; - } - // We can get INPUT only when data length equals the input report size - memcpy(hid_in + size_offset, data, will_send); - // pad with zeroes - memset(hid_in + size_offset + will_send, 0, max_send - will_send); - if(!hid.SendReport(HID_REPORT_ID_VENDOR, hid_in, HID_VENDOR_REPORT_SIZE)){ - return len - to_send; - } - to_send -= will_send; - data += will_send; + // We can get INPUT only when data length equals the input report size + memcpy(hid_in + size_offset, data, will_send); + // pad with zeroes + memset(hid_in + size_offset + will_send, 0, max_send - will_send); + if (!hid.SendReport(HID_REPORT_ID_VENDOR, hid_in, HID_VENDOR_REPORT_SIZE)) { + return len - to_send; } - return len; + to_send -= will_send; + data += will_send; + } + return len; } -size_t USBHIDVendor::write(uint8_t c){ - return write(&c, 1); +size_t USBHIDVendor::write(uint8_t c) { + return write(&c, 1); } -int USBHIDVendor::available(void){ - if(rx_queue == NULL){ - return -1; - } - return uxQueueMessagesWaiting(rx_queue); +int USBHIDVendor::available(void) { + if (rx_queue == NULL) { + return -1; + } + return uxQueueMessagesWaiting(rx_queue); } -int USBHIDVendor::peek(void){ - if(rx_queue == NULL){ - return -1; - } - uint8_t c; - if(xQueuePeek(rx_queue, &c, 0)) { - return c; - } +int USBHIDVendor::peek(void) { + if (rx_queue == NULL) { return -1; + } + uint8_t c; + if (xQueuePeek(rx_queue, &c, 0)) { + return c; + } + return -1; } -int USBHIDVendor::read(void){ - if(rx_queue == NULL){ - return -1; - } - uint8_t c = 0; - if(xQueueReceive(rx_queue, &c, 0)) { - return c; - } +int USBHIDVendor::read(void) { + if (rx_queue == NULL) { return -1; + } + uint8_t c = 0; + if (xQueueReceive(rx_queue, &c, 0)) { + return c; + } + return -1; } -size_t USBHIDVendor::read(uint8_t *buffer, size_t size){ - if(rx_queue == NULL){ - return -1; - } - uint8_t c = 0; - size_t count = 0; - while(count < size && xQueueReceive(rx_queue, &c, 0)){ - buffer[count++] = c; - } - return count; +size_t USBHIDVendor::read(uint8_t* buffer, size_t size) { + if (rx_queue == NULL) { + return -1; + } + uint8_t c = 0; + size_t count = 0; + while (count < size && xQueueReceive(rx_queue, &c, 0)) { + buffer[count++] = c; + } + return count; } -void USBHIDVendor::flush(void){} +void USBHIDVendor::flush(void) {} #endif /* CONFIG_TINYUSB_HID_ENABLED */ diff --git a/libraries/USB/src/USBHIDVendor.h b/libraries/USB/src/USBHIDVendor.h index 714d3ab9b15..74980dbb7a3 100644 --- a/libraries/USB/src/USBHIDVendor.h +++ b/libraries/USB/src/USBHIDVendor.h @@ -24,48 +24,48 @@ ESP_EVENT_DECLARE_BASE(ARDUINO_USB_HID_VENDOR_EVENTS); typedef enum { - ARDUINO_USB_HID_VENDOR_ANY_EVENT = ESP_EVENT_ANY_ID, - ARDUINO_USB_HID_VENDOR_SET_FEATURE_EVENT = 0, - ARDUINO_USB_HID_VENDOR_GET_FEATURE_EVENT, - ARDUINO_USB_HID_VENDOR_OUTPUT_EVENT, - ARDUINO_USB_HID_VENDOR_MAX_EVENT, + ARDUINO_USB_HID_VENDOR_ANY_EVENT = ESP_EVENT_ANY_ID, + ARDUINO_USB_HID_VENDOR_SET_FEATURE_EVENT = 0, + ARDUINO_USB_HID_VENDOR_GET_FEATURE_EVENT, + ARDUINO_USB_HID_VENDOR_OUTPUT_EVENT, + ARDUINO_USB_HID_VENDOR_MAX_EVENT, } arduino_usb_hid_vendor_event_t; typedef struct { - const uint8_t* buffer; - uint16_t len; + const uint8_t* buffer; + uint16_t len; } arduino_usb_hid_vendor_event_data_t; -class USBHIDVendor: public USBHIDDevice, public Stream { +class USBHIDVendor : public USBHIDDevice, public Stream { private: - USBHID hid; + USBHID hid; public: - // Max report size is 64, but we need one byte for report ID, so in reality max is 63. - // Because input packets are always with length equal to the report size - // it will not be known how many bytes actually matter. Setting 'prepend_size' to 'true' will - // make the first byte of each packet to be the length of data in that packet. - // This comes with penalty of one byte, but is very useful when using Vendor for streaming - USBHIDVendor(uint8_t report_size=63, bool prepend_size=false); - void begin(void); - void end(void); - void prependInputPacketsWithSize(bool enable); - size_t setRxBufferSize(size_t); - size_t write(const uint8_t* buffer, size_t len); - size_t write(uint8_t); - int available(void); - int peek(void); - int read(void); - size_t read(uint8_t *buffer, size_t size); - void flush(void); - - void onEvent(esp_event_handler_t callback); - void onEvent(arduino_usb_hid_vendor_event_t event, esp_event_handler_t callback); + // Max report size is 64, but we need one byte for report ID, so in reality max is 63. + // Because input packets are always with length equal to the report size + // it will not be known how many bytes actually matter. Setting 'prepend_size' to 'true' will + // make the first byte of each packet to be the length of data in that packet. + // This comes with penalty of one byte, but is very useful when using Vendor for streaming + USBHIDVendor(uint8_t report_size = 63, bool prepend_size = false); + void begin(void); + void end(void); + void prependInputPacketsWithSize(bool enable); + size_t setRxBufferSize(size_t); + size_t write(const uint8_t* buffer, size_t len); + size_t write(uint8_t); + int available(void); + int peek(void); + int read(void); + size_t read(uint8_t* buffer, size_t size); + void flush(void); - // internal use - uint16_t _onGetDescriptor(uint8_t* buffer); - uint16_t _onGetFeature(uint8_t report_id, uint8_t* buffer, uint16_t len); - void _onSetFeature(uint8_t report_id, const uint8_t* buffer, uint16_t len); - void _onOutput(uint8_t report_id, const uint8_t* buffer, uint16_t len); + void onEvent(esp_event_handler_t callback); + void onEvent(arduino_usb_hid_vendor_event_t event, esp_event_handler_t callback); + + // internal use + uint16_t _onGetDescriptor(uint8_t* buffer); + uint16_t _onGetFeature(uint8_t report_id, uint8_t* buffer, uint16_t len); + void _onSetFeature(uint8_t report_id, const uint8_t* buffer, uint16_t len); + void _onOutput(uint8_t report_id, const uint8_t* buffer, uint16_t len); }; #endif /* CONFIG_TINYUSB_HID_ENABLED */ diff --git a/libraries/USB/src/USBMIDI.cpp b/libraries/USB/src/USBMIDI.cpp index b29b6fefe5d..1354b39f779 100644 --- a/libraries/USB/src/USBMIDI.cpp +++ b/libraries/USB/src/USBMIDI.cpp @@ -13,32 +13,32 @@ static bool tinyusb_midi_descriptor_loaded = false; static bool tinyusb_midi_interface_enabled = false; extern "C" uint16_t tusb_midi_load_descriptor(uint8_t *dst, uint8_t *itf) { - if (tinyusb_midi_descriptor_loaded) { - return 0; - } - tinyusb_midi_descriptor_loaded = true; - - uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB MIDI"); - uint8_t ep_in = tinyusb_get_free_in_endpoint(); - TU_VERIFY(ep_in != 0); - uint8_t ep_out = tinyusb_get_free_out_endpoint(); - TU_VERIFY(ep_out != 0); - uint8_t descriptor[TUD_MIDI_DESC_LEN] = { - TUD_MIDI_DESCRIPTOR(*itf, str_index, ep_out, (uint8_t)(0x80 | ep_in), 64), - }; - *itf += 2; - memcpy(dst, descriptor, TUD_MIDI_DESC_LEN); - - return TUD_MIDI_DESC_LEN; + if (tinyusb_midi_descriptor_loaded) { + return 0; + } + tinyusb_midi_descriptor_loaded = true; + + uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB MIDI"); + uint8_t ep_in = tinyusb_get_free_in_endpoint(); + TU_VERIFY(ep_in != 0); + uint8_t ep_out = tinyusb_get_free_out_endpoint(); + TU_VERIFY(ep_out != 0); + uint8_t descriptor[TUD_MIDI_DESC_LEN] = { + TUD_MIDI_DESCRIPTOR(*itf, str_index, ep_out, (uint8_t)(0x80 | ep_in), 64), + }; + *itf += 2; + memcpy(dst, descriptor, TUD_MIDI_DESC_LEN); + + return TUD_MIDI_DESC_LEN; } USBMIDI::USBMIDI() { - if (!tinyusb_midi_interface_enabled) { - tinyusb_midi_interface_enabled = true; - tinyusb_enable_interface(USB_INTERFACE_MIDI, TUD_MIDI_DESC_LEN, tusb_midi_load_descriptor); - } else { - log_e("USBMIDI: Multiple instances of USBMIDI not supported!"); - } + if (!tinyusb_midi_interface_enabled) { + tinyusb_midi_interface_enabled = true; + tinyusb_enable_interface(USB_INTERFACE_MIDI, TUD_MIDI_DESC_LEN, tusb_midi_load_descriptor); + } else { + log_e("USBMIDI: Multiple instances of USBMIDI not supported!"); + } } void USBMIDI::begin() {} @@ -47,8 +47,8 @@ void USBMIDI::end() {} // uint compatible version of constrain #define uconstrain(amt, low, high) ((amt) <= (low) ? (low) : ((amt) > (high) ? (high) : (amt))) -#define STATUS(CIN, CHANNEL) \ - static_cast(((CIN & 0x7F) << 4) | (uconstrain(CHANNEL - 1, 0, 15) & 0x7F)) +#define STATUS(CIN, CHANNEL) \ + static_cast(((CIN & 0x7F) << 4) | (uconstrain(CHANNEL - 1, 0, 15) & 0x7F)) // Note: All the user-level API calls do extensive input constraining to prevent easy to make mistakes. // (You can thank me later.) @@ -56,86 +56,86 @@ void USBMIDI::end() {} // Note On void USBMIDI::noteOn(uint8_t note, uint8_t velocity, uint8_t channel) { - midiEventPacket_t event = {MIDI_CIN_NOTE_ON, STATUS(MIDI_CIN_NOTE_ON, channel), _(note), - _(velocity)}; - writePacket(&event); + midiEventPacket_t event = { MIDI_CIN_NOTE_ON, STATUS(MIDI_CIN_NOTE_ON, channel), _(note), + _(velocity) }; + writePacket(&event); } // Note Off void USBMIDI::noteOff(uint8_t note, uint8_t velocity, uint8_t channel) { - midiEventPacket_t event = {MIDI_CIN_NOTE_OFF, STATUS(MIDI_CIN_NOTE_OFF, channel), _(note), - _(velocity)}; - writePacket(&event); + midiEventPacket_t event = { MIDI_CIN_NOTE_OFF, STATUS(MIDI_CIN_NOTE_OFF, channel), _(note), + _(velocity) }; + writePacket(&event); } // Program Change void USBMIDI::programChange(uint8_t program, uint8_t channel) { - midiEventPacket_t event = {MIDI_CIN_PROGRAM_CHANGE, STATUS(MIDI_CIN_PROGRAM_CHANGE, channel), - _(program), 0x0}; - writePacket(&event); + midiEventPacket_t event = { MIDI_CIN_PROGRAM_CHANGE, STATUS(MIDI_CIN_PROGRAM_CHANGE, channel), + _(program), 0x0 }; + writePacket(&event); } // Control Change (Continuous Controller) void USBMIDI::controlChange(uint8_t control, uint8_t value, uint8_t channel) { - midiEventPacket_t event = {MIDI_CIN_CONTROL_CHANGE, STATUS(MIDI_CIN_CONTROL_CHANGE, channel), - _(control), _(value)}; - writePacket(&event); + midiEventPacket_t event = { MIDI_CIN_CONTROL_CHANGE, STATUS(MIDI_CIN_CONTROL_CHANGE, channel), + _(control), _(value) }; + writePacket(&event); } // Polyphonic Key Pressure (Aftertouch) void USBMIDI::polyPressure(uint8_t note, uint8_t pressure, uint8_t channel) { - midiEventPacket_t event = {MIDI_CIN_POLY_KEYPRESS, STATUS(MIDI_CIN_POLY_KEYPRESS, channel), _(note), - _(pressure)}; - writePacket(&event); + midiEventPacket_t event = { MIDI_CIN_POLY_KEYPRESS, STATUS(MIDI_CIN_POLY_KEYPRESS, channel), _(note), + _(pressure) }; + writePacket(&event); } // Channel Pressure (Aftertouch) void USBMIDI::channelPressure(uint8_t pressure, uint8_t channel) { - midiEventPacket_t event = {MIDI_CIN_CHANNEL_PRESSURE, STATUS(MIDI_CIN_CHANNEL_PRESSURE, channel), - _(pressure), 0x0}; - writePacket(&event); + midiEventPacket_t event = { MIDI_CIN_CHANNEL_PRESSURE, STATUS(MIDI_CIN_CHANNEL_PRESSURE, channel), + _(pressure), 0x0 }; + writePacket(&event); } // Pitch Bend Change [-8192,0,8191] void USBMIDI::pitchBend(int16_t value, uint8_t channel) { - uint16_t pitchBendValue = constrain(value, -8192, 8191) + 8192; - pitchBend(pitchBendValue); + uint16_t pitchBendValue = constrain(value, -8192, 8191) + 8192; + pitchBend(pitchBendValue); } // Pitch Bend Change [0,8192,16383] void USBMIDI::pitchBend(uint16_t value, uint8_t channel) { - uint16_t pitchBendValue = static_cast(uconstrain(value, 0, 16383)); - // Split the 14-bit integer into two 7-bit values - uint8_t lsb = pitchBendValue & 0x7F; // Lower 7 bits - uint8_t msb = (pitchBendValue >> 7) & 0x7F; // Upper 7 bits - - midiEventPacket_t event = {MIDI_CIN_PITCH_BEND_CHANGE, STATUS(MIDI_CIN_PITCH_BEND_CHANGE, channel), - lsb, msb}; - writePacket(&event); + uint16_t pitchBendValue = static_cast(uconstrain(value, 0, 16383)); + // Split the 14-bit integer into two 7-bit values + uint8_t lsb = pitchBendValue & 0x7F; // Lower 7 bits + uint8_t msb = (pitchBendValue >> 7) & 0x7F; // Upper 7 bits + + midiEventPacket_t event = { MIDI_CIN_PITCH_BEND_CHANGE, STATUS(MIDI_CIN_PITCH_BEND_CHANGE, channel), + lsb, msb }; + writePacket(&event); } // Pitch Bend Change [-1.0,0,1.0] void USBMIDI::pitchBend(double value, uint8_t channel) { - // Multiply by 8191 and round to nearest integer - int16_t pitchBendValue = static_cast(round(constrain(value, -1.0, 1.0) * 8191.0)); + // Multiply by 8191 and round to nearest integer + int16_t pitchBendValue = static_cast(round(constrain(value, -1.0, 1.0) * 8191.0)); - pitchBend(pitchBendValue, channel); + pitchBend(pitchBendValue, channel); } bool USBMIDI::readPacket(midiEventPacket_t *packet) { - return tud_midi_packet_read((uint8_t *)packet); + return tud_midi_packet_read((uint8_t *)packet); } bool USBMIDI::writePacket(midiEventPacket_t *packet) { - return tud_midi_packet_write((uint8_t *)packet); + return tud_midi_packet_write((uint8_t *)packet); } size_t USBMIDI::write(uint8_t c) { - // MIDI_CIN_1BYTE_DATA => Verbatim MIDI byte-stream copy - // (See also Table 4-1 of USB MIDI spec 1.0) - midiEventPacket_t packet = {DEFAULT_CN | MIDI_CIN_1BYTE_DATA, c, 0, 0}; + // MIDI_CIN_1BYTE_DATA => Verbatim MIDI byte-stream copy + // (See also Table 4-1 of USB MIDI spec 1.0) + midiEventPacket_t packet = { DEFAULT_CN | MIDI_CIN_1BYTE_DATA, c, 0, 0 }; - return tud_midi_packet_write((uint8_t *)&packet); + return tud_midi_packet_write((uint8_t *)&packet); } #endif /* CONFIG_TINYUSB_MIDI_ENABLED */ diff --git a/libraries/USB/src/USBMIDI.h b/libraries/USB/src/USBMIDI.h index 44253fda51d..5a0f331cc86 100644 --- a/libraries/USB/src/USBMIDI.h +++ b/libraries/USB/src/USBMIDI.h @@ -11,50 +11,50 @@ #define MIDI_EP_HEADER_CIN_GET(x) ((midi_code_index_number_t)((x)&0xF)) typedef struct { - uint8_t header; - uint8_t byte1; - uint8_t byte2; - uint8_t byte3; + uint8_t header; + uint8_t byte1; + uint8_t byte2; + uint8_t byte3; } midiEventPacket_t; class USBMIDI { public: - USBMIDI(void); - void begin(void); - void end(void); - - /* User-level API */ - - // Note On - void noteOn(uint8_t note, uint8_t velocity = 0, uint8_t channel = 1); - // Note Off - void noteOff(uint8_t note, uint8_t velocity = 0, uint8_t channel = 1); - // Program Change - void programChange(uint8_t inProgramNumber, uint8_t channel = 1); - // Control Change (Continuous Controller) - void controlChange(uint8_t inControlNumber, uint8_t inControlValue = 0, uint8_t channel = 1); - // Polyphonic Key Pressure (Aftertouch) - void polyPressure(uint8_t note, uint8_t pressure, uint8_t channel = 1); - // Channel Pressure (Aftertouch) - void channelPressure(uint8_t pressure, uint8_t channel = 1); - // Pitch Bend Change [-8192,0,8191] - void pitchBend(int16_t pitchBendValue, uint8_t channel = 1); - // Pitch Bend Change [0,8192,16383] - void pitchBend(uint16_t pitchBendValue, uint8_t channel = 1); - // Pitch Bend Change [-1.0,0,1.0] - void pitchBend(double pitchBendValue, uint8_t channel = 1); - - /* USB MIDI 1.0 interface */ - - // Attempt to read a USB MIDI packet from the USB Bus - bool readPacket(midiEventPacket_t *packet); - // Attempt to write a USB MIDI packet to the USB Bus - bool writePacket(midiEventPacket_t *packet); - - /* Serial MIDI 1.0 interface */ - - // Write a Serial MIDI byte (status or data) to the USB Bus - size_t write(uint8_t c); + USBMIDI(void); + void begin(void); + void end(void); + + /* User-level API */ + + // Note On + void noteOn(uint8_t note, uint8_t velocity = 0, uint8_t channel = 1); + // Note Off + void noteOff(uint8_t note, uint8_t velocity = 0, uint8_t channel = 1); + // Program Change + void programChange(uint8_t inProgramNumber, uint8_t channel = 1); + // Control Change (Continuous Controller) + void controlChange(uint8_t inControlNumber, uint8_t inControlValue = 0, uint8_t channel = 1); + // Polyphonic Key Pressure (Aftertouch) + void polyPressure(uint8_t note, uint8_t pressure, uint8_t channel = 1); + // Channel Pressure (Aftertouch) + void channelPressure(uint8_t pressure, uint8_t channel = 1); + // Pitch Bend Change [-8192,0,8191] + void pitchBend(int16_t pitchBendValue, uint8_t channel = 1); + // Pitch Bend Change [0,8192,16383] + void pitchBend(uint16_t pitchBendValue, uint8_t channel = 1); + // Pitch Bend Change [-1.0,0,1.0] + void pitchBend(double pitchBendValue, uint8_t channel = 1); + + /* USB MIDI 1.0 interface */ + + // Attempt to read a USB MIDI packet from the USB Bus + bool readPacket(midiEventPacket_t *packet); + // Attempt to write a USB MIDI packet to the USB Bus + bool writePacket(midiEventPacket_t *packet); + + /* Serial MIDI 1.0 interface */ + + // Write a Serial MIDI byte (status or data) to the USB Bus + size_t write(uint8_t c); }; #endif /* CONFIG_TINYUSB_MIDI_ENABLED */ diff --git a/libraries/USB/src/USBVendor.cpp b/libraries/USB/src/USBVendor.cpp index d5dbd616b40..ce1c5bd44cb 100644 --- a/libraries/USB/src/USBVendor.cpp +++ b/libraries/USB/src/USBVendor.cpp @@ -22,198 +22,198 @@ ESP_EVENT_DEFINE_BASE(ARDUINO_USB_VENDOR_EVENTS); esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, TickType_t ticks_to_wait); esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg); -static USBVendor * _Vendor = NULL; +static USBVendor *_Vendor = NULL; static QueueHandle_t rx_queue = NULL; static uint8_t USB_VENDOR_ENDPOINT_SIZE = 64; -uint16_t tusb_vendor_load_descriptor(uint8_t * dst, uint8_t * itf) -{ - uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB Vendor"); - uint8_t ep_num = tinyusb_get_free_duplex_endpoint(); - TU_VERIFY (ep_num != 0); - uint8_t descriptor[TUD_VENDOR_DESC_LEN] = { - // Interface number, string index, EP Out & IN address, EP size - TUD_VENDOR_DESCRIPTOR(*itf, str_index, ep_num, (uint8_t)(0x80 | ep_num), USB_VENDOR_ENDPOINT_SIZE) - }; - *itf+=1; - memcpy(dst, descriptor, TUD_VENDOR_DESC_LEN); - return TUD_VENDOR_DESC_LEN; -} - -void tud_vendor_rx_cb(uint8_t itf){ - size_t len = tud_vendor_n_available(itf); - log_v("%u", len); - if(len){ - uint8_t buffer[len]; - len = tud_vendor_n_read(itf, buffer, len); - log_buf_v(buffer, len); - if(_Vendor) { - _Vendor->_onRX(buffer, len); - } - } else { - if(_Vendor) { - _Vendor->_onRX(NULL, len); - } - } -} - -extern "C" bool tinyusb_vendor_control_request_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request){ - log_v("Port: %u, Stage: %u, Direction: %u, Type: %u, Recipient: %u, bRequest: 0x%x, wValue: %u, wIndex: %u, wLength: %u", - rhport, stage, request->bmRequestType_bit.direction, - request->bmRequestType_bit.type, request->bmRequestType_bit.recipient, +uint16_t tusb_vendor_load_descriptor(uint8_t *dst, uint8_t *itf) { + uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB Vendor"); + uint8_t ep_num = tinyusb_get_free_duplex_endpoint(); + TU_VERIFY(ep_num != 0); + uint8_t descriptor[TUD_VENDOR_DESC_LEN] = { + // Interface number, string index, EP Out & IN address, EP size + TUD_VENDOR_DESCRIPTOR(*itf, str_index, ep_num, (uint8_t)(0x80 | ep_num), USB_VENDOR_ENDPOINT_SIZE) + }; + *itf += 1; + memcpy(dst, descriptor, TUD_VENDOR_DESC_LEN); + return TUD_VENDOR_DESC_LEN; +} + +void tud_vendor_rx_cb(uint8_t itf) { + size_t len = tud_vendor_n_available(itf); + log_v("%u", len); + if (len) { + uint8_t buffer[len]; + len = tud_vendor_n_read(itf, buffer, len); + log_buf_v(buffer, len); + if (_Vendor) { + _Vendor->_onRX(buffer, len); + } + } else { + if (_Vendor) { + _Vendor->_onRX(NULL, len); + } + } +} + +extern "C" bool tinyusb_vendor_control_request_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request) { + log_v("Port: %u, Stage: %u, Direction: %u, Type: %u, Recipient: %u, bRequest: 0x%x, wValue: %u, wIndex: %u, wLength: %u", + rhport, stage, request->bmRequestType_bit.direction, + request->bmRequestType_bit.type, request->bmRequestType_bit.recipient, request->bRequest, request->wValue, request->wIndex, request->wLength); - if(_Vendor) { - return _Vendor->_onRequest(rhport, stage, (arduino_usb_control_request_t const *)request); - } - return false; + if (_Vendor) { + return _Vendor->_onRequest(rhport, stage, (arduino_usb_control_request_t const *)request); + } + return false; } -USBVendor::USBVendor(uint8_t endpoint_size):itf(0), cb(NULL){ - if(!_Vendor){ - _Vendor = this; - if(endpoint_size <= 64){ - USB_VENDOR_ENDPOINT_SIZE = endpoint_size; - } - tinyusb_enable_interface(USB_INTERFACE_VENDOR, TUD_VENDOR_DESC_LEN, tusb_vendor_load_descriptor); - } else { - itf = _Vendor->itf; - cb = _Vendor->cb; +USBVendor::USBVendor(uint8_t endpoint_size) + : itf(0), cb(NULL) { + if (!_Vendor) { + _Vendor = this; + if (endpoint_size <= 64) { + USB_VENDOR_ENDPOINT_SIZE = endpoint_size; } + tinyusb_enable_interface(USB_INTERFACE_VENDOR, TUD_VENDOR_DESC_LEN, tusb_vendor_load_descriptor); + } else { + itf = _Vendor->itf; + cb = _Vendor->cb; + } } -size_t USBVendor::setRxBufferSize(size_t rx_queue_len){ - if(rx_queue){ - if(!rx_queue_len){ - vQueueDelete(rx_queue); - rx_queue = NULL; - } - return 0; - } - rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t)); - if(!rx_queue){ - return 0; +size_t USBVendor::setRxBufferSize(size_t rx_queue_len) { + if (rx_queue) { + if (!rx_queue_len) { + vQueueDelete(rx_queue); + rx_queue = NULL; } - return rx_queue_len; + return 0; + } + rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t)); + if (!rx_queue) { + return 0; + } + return rx_queue_len; } -void USBVendor::begin(){ - setRxBufferSize(256);//default if not preset +void USBVendor::begin() { + setRxBufferSize(256); //default if not preset } -void USBVendor::end(){ - setRxBufferSize(0); +void USBVendor::end() { + setRxBufferSize(0); } -void USBVendor::onEvent(esp_event_handler_t callback){ - onEvent(ARDUINO_USB_VENDOR_ANY_EVENT, callback); +void USBVendor::onEvent(esp_event_handler_t callback) { + onEvent(ARDUINO_USB_VENDOR_ANY_EVENT, callback); } -void USBVendor::onEvent(arduino_usb_vendor_event_t event, esp_event_handler_t callback){ - arduino_usb_event_handler_register_with(ARDUINO_USB_VENDOR_EVENTS, event, callback, this); +void USBVendor::onEvent(arduino_usb_vendor_event_t event, esp_event_handler_t callback) { + arduino_usb_event_handler_register_with(ARDUINO_USB_VENDOR_EVENTS, event, callback, this); } -bool USBVendor::mounted(){ - return tud_vendor_n_mounted(itf); +bool USBVendor::mounted() { + return tud_vendor_n_mounted(itf); } -bool USBVendor::sendResponse(uint8_t rhport, arduino_usb_control_request_t const * request, void * data, size_t len){ - if(!request){ - return false; - } - if(!data || !len){ - return tud_control_status(rhport, (tusb_control_request_t const *)request); - } else { - return tud_control_xfer(rhport, (tusb_control_request_t const *)request, data, len); - } +bool USBVendor::sendResponse(uint8_t rhport, arduino_usb_control_request_t const *request, void *data, size_t len) { + if (!request) { + return false; + } + if (!data || !len) { + return tud_control_status(rhport, (tusb_control_request_t const *)request); + } else { + return tud_control_xfer(rhport, (tusb_control_request_t const *)request, data, len); + } } -void USBVendor::onRequest(arduino_usb_vendor_control_request_handler_t handler){ - cb = handler; +void USBVendor::onRequest(arduino_usb_vendor_control_request_handler_t handler) { + cb = handler; } -bool USBVendor::_onRequest(uint8_t rhport, uint8_t stage, arduino_usb_control_request_t const * request){ - if(cb){ - return cb(rhport, stage, request); - } - return false; +bool USBVendor::_onRequest(uint8_t rhport, uint8_t stage, arduino_usb_control_request_t const *request) { + if (cb) { + return cb(rhport, stage, request); + } + return false; } -void USBVendor::_onRX(const uint8_t* buffer, size_t len){ - for(uint32_t i=0; i max_len){ - len = max_len; - } - if(len){ - return tud_vendor_n_write(itf, buffer, len); - } - return len; +size_t USBVendor::write(const uint8_t *buffer, size_t len) { + if (!mounted()) { + log_e("not mounted"); + return 0; + } + size_t max_len = tud_vendor_n_write_available(itf); + if (len > max_len) { + len = max_len; + } + if (len) { + return tud_vendor_n_write(itf, buffer, len); + } + return len; } -size_t USBVendor::write(uint8_t c){ - return write(&c, 1); +size_t USBVendor::write(uint8_t c) { + return write(&c, 1); } -int USBVendor::available(void){ - if(rx_queue == NULL){ - return -1; - } - return uxQueueMessagesWaiting(rx_queue); +int USBVendor::available(void) { + if (rx_queue == NULL) { + return -1; + } + return uxQueueMessagesWaiting(rx_queue); } -int USBVendor::peek(void){ - if(rx_queue == NULL){ - return -1; - } - uint8_t c; - if(xQueuePeek(rx_queue, &c, 0)) { - return c; - } +int USBVendor::peek(void) { + if (rx_queue == NULL) { return -1; + } + uint8_t c; + if (xQueuePeek(rx_queue, &c, 0)) { + return c; + } + return -1; } -int USBVendor::read(void){ - if(rx_queue == NULL){ - return -1; - } - uint8_t c = 0; - if(xQueueReceive(rx_queue, &c, 0)) { - return c; - } +int USBVendor::read(void) { + if (rx_queue == NULL) { return -1; + } + uint8_t c = 0; + if (xQueueReceive(rx_queue, &c, 0)) { + return c; + } + return -1; } -size_t USBVendor::read(uint8_t *buffer, size_t size){ - if(rx_queue == NULL){ - return -1; - } - uint8_t c = 0; - size_t count = 0; - while(count < size && xQueueReceive(rx_queue, &c, 0)){ - buffer[count++] = c; - } - return count; +size_t USBVendor::read(uint8_t *buffer, size_t size) { + if (rx_queue == NULL) { + return -1; + } + uint8_t c = 0; + size_t count = 0; + while (count < size && xQueueReceive(rx_queue, &c, 0)) { + buffer[count++] = c; + } + return count; } -void USBVendor::flush(void){ - tud_vendor_n_write_flush(itf); +void USBVendor::flush(void) { + tud_vendor_n_write_flush(itf); } #endif /* CONFIG_TINYUSB_VENDOR_ENABLED */ diff --git a/libraries/USB/src/USBVendor.h b/libraries/USB/src/USBVendor.h index 6be0c7a5888..be9b25b1171 100644 --- a/libraries/USB/src/USBVendor.h +++ b/libraries/USB/src/USBVendor.h @@ -25,74 +25,74 @@ ESP_EVENT_DECLARE_BASE(ARDUINO_USB_VENDOR_EVENTS); -#define REQUEST_STAGE_SETUP 0 -#define REQUEST_STAGE_DATA 1 -#define REQUEST_STAGE_ACK 2 +#define REQUEST_STAGE_SETUP 0 +#define REQUEST_STAGE_DATA 1 +#define REQUEST_STAGE_ACK 2 -#define REQUEST_TYPE_STANDARD 0 -#define REQUEST_TYPE_CLASS 1 -#define REQUEST_TYPE_VENDOR 2 -#define REQUEST_TYPE_INVALID 3 +#define REQUEST_TYPE_STANDARD 0 +#define REQUEST_TYPE_CLASS 1 +#define REQUEST_TYPE_VENDOR 2 +#define REQUEST_TYPE_INVALID 3 -#define REQUEST_RECIPIENT_DEVICE 0 +#define REQUEST_RECIPIENT_DEVICE 0 #define REQUEST_RECIPIENT_INTERFACE 1 -#define REQUEST_RECIPIENT_ENDPOINT 2 -#define REQUEST_RECIPIENT_OTHER 3 - -#define REQUEST_DIRECTION_OUT 0 -#define REQUEST_DIRECTION_IN 1 - -typedef struct __attribute__ ((packed)) { - struct __attribute__ ((packed)) { - uint8_t bmRequestRecipient : 5; - uint8_t bmRequestType : 2; - uint8_t bmRequestDirection : 1; - }; - uint8_t bRequest; - uint16_t wValue; - uint16_t wIndex; - uint16_t wLength; +#define REQUEST_RECIPIENT_ENDPOINT 2 +#define REQUEST_RECIPIENT_OTHER 3 + +#define REQUEST_DIRECTION_OUT 0 +#define REQUEST_DIRECTION_IN 1 + +typedef struct __attribute__((packed)) { + struct __attribute__((packed)) { + uint8_t bmRequestRecipient : 5; + uint8_t bmRequestType : 2; + uint8_t bmRequestDirection : 1; + }; + uint8_t bRequest; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; } arduino_usb_control_request_t; typedef enum { - ARDUINO_USB_VENDOR_ANY_EVENT = ESP_EVENT_ANY_ID, - ARDUINO_USB_VENDOR_DATA_EVENT, - ARDUINO_USB_VENDOR_MAX_EVENT, + ARDUINO_USB_VENDOR_ANY_EVENT = ESP_EVENT_ANY_ID, + ARDUINO_USB_VENDOR_DATA_EVENT, + ARDUINO_USB_VENDOR_MAX_EVENT, } arduino_usb_vendor_event_t; typedef union { - struct { - uint16_t len; - } data; + struct { + uint16_t len; + } data; } arduino_usb_vendor_event_data_t; -typedef bool (*arduino_usb_vendor_control_request_handler_t)(uint8_t rhport, uint8_t stage, arduino_usb_control_request_t const * request); +typedef bool (*arduino_usb_vendor_control_request_handler_t)(uint8_t rhport, uint8_t stage, arduino_usb_control_request_t const* request); -class USBVendor: public Stream { +class USBVendor : public Stream { private: - uint8_t itf; - arduino_usb_vendor_control_request_handler_t cb; + uint8_t itf; + arduino_usb_vendor_control_request_handler_t cb; public: - USBVendor(uint8_t endpoint_size=64); - void begin(void); - void end(void); - size_t setRxBufferSize(size_t); - bool mounted(void); - size_t write(const uint8_t* buffer, size_t len); - size_t write(uint8_t); - int available(void); - int peek(void); - int read(void); - size_t read(uint8_t *buffer, size_t size); - void flush(void); - - void onEvent(esp_event_handler_t callback); - void onEvent(arduino_usb_vendor_event_t event, esp_event_handler_t callback); - void onRequest(arduino_usb_vendor_control_request_handler_t handler); - bool sendResponse(uint8_t rhport, arduino_usb_control_request_t const * request, void * data=NULL, size_t len=0); - - bool _onRequest(uint8_t rhport, uint8_t stage, arduino_usb_control_request_t const * request); - void _onRX(const uint8_t* buffer, size_t len); + USBVendor(uint8_t endpoint_size = 64); + void begin(void); + void end(void); + size_t setRxBufferSize(size_t); + bool mounted(void); + size_t write(const uint8_t* buffer, size_t len); + size_t write(uint8_t); + int available(void); + int peek(void); + int read(void); + size_t read(uint8_t* buffer, size_t size); + void flush(void); + + void onEvent(esp_event_handler_t callback); + void onEvent(arduino_usb_vendor_event_t event, esp_event_handler_t callback); + void onRequest(arduino_usb_vendor_control_request_handler_t handler); + bool sendResponse(uint8_t rhport, arduino_usb_control_request_t const* request, void* data = NULL, size_t len = 0); + + bool _onRequest(uint8_t rhport, uint8_t stage, arduino_usb_control_request_t const* request); + void _onRX(const uint8_t* buffer, size_t len); }; #endif /* CONFIG_TINYUSB_VENDOR_ENABLED */ diff --git a/libraries/USB/src/tusb_hid_mouse.h b/libraries/USB/src/tusb_hid_mouse.h index 6cf35c4aa6f..f863cbf3874 100644 --- a/libraries/USB/src/tusb_hid_mouse.h +++ b/libraries/USB/src/tusb_hid_mouse.h @@ -3,96 +3,85 @@ #include "class/hid/hid_device.h" #if !defined TUD_HID_REPORT_DESC_ABSMOUSE - // This version of arduino-esp32 does not handle absolute mouse natively. - // Let's throw a minimalistic implementation of absmouse driver. - // See: https://github.com/hathach/tinyusb/pull/1363 - // Also see: https://github.com/espressif/arduino-esp32/pull/6331 +// This version of arduino-esp32 does not handle absolute mouse natively. +// Let's throw a minimalistic implementation of absmouse driver. +// See: https://github.com/hathach/tinyusb/pull/1363 +// Also see: https://github.com/espressif/arduino-esp32/pull/6331 - extern "C" { +extern "C" { - // Absolute Mouse data struct is a copy of the relative mouse struct - // with int16_t instead of int8_t for X and Y coordinates. - typedef struct TU_ATTR_PACKED - { - uint8_t buttons = 0; - int16_t x = 0; - int16_t y = 0; - int8_t wheel = 0; - int8_t pan = 0; - } hid_abs_mouse_report_t; + // Absolute Mouse data struct is a copy of the relative mouse struct + // with int16_t instead of int8_t for X and Y coordinates. + typedef struct TU_ATTR_PACKED { + uint8_t buttons = 0; + int16_t x = 0; + int16_t y = 0; + int8_t wheel = 0; + int8_t pan = 0; + } hid_abs_mouse_report_t; - // Absolute Mouse Report Descriptor Template applies those datatype changes too - #define TUD_HID_REPORT_DESC_ABSMOUSE(...) \ - HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\ - HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ) ,\ - HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\ - /* Report ID if any */\ - __VA_ARGS__ \ - HID_USAGE ( HID_USAGE_DESKTOP_POINTER ) ,\ - HID_COLLECTION ( HID_COLLECTION_PHYSICAL ) ,\ - HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\ - HID_USAGE_MIN ( 1 ) ,\ - HID_USAGE_MAX ( 5 ) ,\ - HID_LOGICAL_MIN ( 0 ) ,\ - HID_LOGICAL_MAX ( 1 ) ,\ - /* Left, Right, Middle, Backward, Forward buttons */ \ - HID_REPORT_COUNT( 5 ) ,\ - HID_REPORT_SIZE ( 1 ) ,\ - HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\ - /* 3 bit padding */ \ - HID_REPORT_COUNT( 1 ) ,\ - HID_REPORT_SIZE ( 3 ) ,\ - HID_INPUT ( HID_CONSTANT ) ,\ - HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\ - /* X, Y absolute position [0, 32767] */ \ - HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\ - HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\ - HID_LOGICAL_MIN ( 0x00 ) ,\ - HID_LOGICAL_MAX_N( 0x7FFF, 2 ) ,\ - HID_REPORT_SIZE ( 16 ) ,\ - HID_REPORT_COUNT ( 2 ) ,\ - HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\ - /* Vertical wheel scroll [-127, 127] */ \ - HID_USAGE ( HID_USAGE_DESKTOP_WHEEL ) ,\ - HID_LOGICAL_MIN ( 0x81 ) ,\ - HID_LOGICAL_MAX ( 0x7f ) ,\ - HID_REPORT_COUNT( 1 ) ,\ - HID_REPORT_SIZE ( 8 ) ,\ - HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\ - HID_USAGE_PAGE ( HID_USAGE_PAGE_CONSUMER ), \ - /* Horizontal wheel scroll [-127, 127] */ \ - HID_USAGE_N ( HID_USAGE_CONSUMER_AC_PAN, 2 ), \ - HID_LOGICAL_MIN ( 0x81 ), \ - HID_LOGICAL_MAX ( 0x7f ), \ - HID_REPORT_COUNT( 1 ), \ - HID_REPORT_SIZE ( 8 ), \ - HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ), \ - HID_COLLECTION_END , \ - HID_COLLECTION_END \ +// Absolute Mouse Report Descriptor Template applies those datatype changes too +#define TUD_HID_REPORT_DESC_ABSMOUSE(...) \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), \ + HID_USAGE(HID_USAGE_DESKTOP_MOUSE), \ + HID_COLLECTION(HID_COLLECTION_APPLICATION), /* Report ID if any */ \ + __VA_ARGS__ \ + HID_USAGE(HID_USAGE_DESKTOP_POINTER), \ + HID_COLLECTION(HID_COLLECTION_PHYSICAL), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_BUTTON), \ + HID_USAGE_MIN(1), \ + HID_USAGE_MAX(5), \ + HID_LOGICAL_MIN(0), \ + HID_LOGICAL_MAX(1), /* Left, Right, Middle, Backward, Forward buttons */ \ + HID_REPORT_COUNT(5), \ + HID_REPORT_SIZE(1), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), /* 3 bit padding */ \ + HID_REPORT_COUNT(1), \ + HID_REPORT_SIZE(3), \ + HID_INPUT(HID_CONSTANT), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), /* X, Y absolute position [0, 32767] */ \ + HID_USAGE(HID_USAGE_DESKTOP_X), \ + HID_USAGE(HID_USAGE_DESKTOP_Y), \ + HID_LOGICAL_MIN(0x00), \ + HID_LOGICAL_MAX_N(0x7FFF, 2), \ + HID_REPORT_SIZE(16), \ + HID_REPORT_COUNT(2), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), /* Vertical wheel scroll [-127, 127] */ \ + HID_USAGE(HID_USAGE_DESKTOP_WHEEL), \ + HID_LOGICAL_MIN(0x81), \ + HID_LOGICAL_MAX(0x7f), \ + HID_REPORT_COUNT(1), \ + HID_REPORT_SIZE(8), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_RELATIVE), \ + HID_USAGE_PAGE(HID_USAGE_PAGE_CONSUMER), /* Horizontal wheel scroll [-127, 127] */ \ + HID_USAGE_N(HID_USAGE_CONSUMER_AC_PAN, 2), \ + HID_LOGICAL_MIN(0x81), \ + HID_LOGICAL_MAX(0x7f), \ + HID_REPORT_COUNT(1), \ + HID_REPORT_SIZE(8), \ + HID_INPUT(HID_DATA | HID_VARIABLE | HID_RELATIVE), \ + HID_COLLECTION_END, \ + HID_COLLECTION_END - static inline bool tud_hid_n_abs_mouse_report(uint8_t instance, uint8_t report_id, uint8_t buttons, int16_t x, int16_t y, int8_t vertical, int8_t horizontal) - { - hid_abs_mouse_report_t report = - { - .buttons = buttons, - .x = x, - .y = y, - .wheel = vertical, - .pan = horizontal - }; - return tud_hid_n_report(instance, report_id, &report, sizeof(report)); - } + static inline bool tud_hid_n_abs_mouse_report(uint8_t instance, uint8_t report_id, uint8_t buttons, int16_t x, int16_t y, int8_t vertical, int8_t horizontal) { + hid_abs_mouse_report_t report = { + .buttons = buttons, + .x = x, + .y = y, + .wheel = vertical, + .pan = horizontal + }; + return tud_hid_n_report(instance, report_id, &report, sizeof(report)); + } - static inline bool tud_hid_abs_mouse_report(uint8_t report_id, uint8_t buttons, int16_t x, int16_t y, int8_t vertical, int8_t horizontal) - { - return tud_hid_n_abs_mouse_report(0, report_id, buttons, x, y, vertical, horizontal); - } + static inline bool tud_hid_abs_mouse_report(uint8_t report_id, uint8_t buttons, int16_t x, int16_t y, int8_t vertical, int8_t horizontal) { + return tud_hid_n_abs_mouse_report(0, report_id, buttons, x, y, vertical, horizontal); + } - } // end extern "C" +} // end extern "C" #else - #pragma message "This file is now safe to delete along with its include from USBHIDMouse.h" +#pragma message "This file is now safe to delete along with its include from USBHIDMouse.h" #endif - diff --git a/libraries/Update/examples/AWS_S3_OTA_Update/AWS_S3_OTA_Update.ino b/libraries/Update/examples/AWS_S3_OTA_Update/AWS_S3_OTA_Update.ino index 9f5d3d15168..9e65aa27915 100644 --- a/libraries/Update/examples/AWS_S3_OTA_Update/AWS_S3_OTA_Update.ino +++ b/libraries/Update/examples/AWS_S3_OTA_Update/AWS_S3_OTA_Update.ino @@ -35,29 +35,26 @@ const char* SSID = "YOUR-SSID"; const char* PSWD = "YOUR-SSID-PSWD"; // S3 Bucket Config -String host = "bucket-name.s3.ap-south-1.amazonaws.com"; // Host => bucket-name.s3.region.amazonaws.com -int port = 80; // Non https. For HTTPS 443. As of today, HTTPS doesn't work. -String bin = "/sketch-name.ino.bin"; // bin file name with a slash in front. +String host = "bucket-name.s3.ap-south-1.amazonaws.com"; // Host => bucket-name.s3.region.amazonaws.com +int port = 80; // Non https. For HTTPS 443. As of today, HTTPS doesn't work. +String bin = "/sketch-name.ino.bin"; // bin file name with a slash in front. // Utility to extract header value from headers String getHeaderValue(String header, String headerName) { return header.substring(strlen(headerName.c_str())); } -// OTA Logic +// OTA Logic void execOTA() { Serial.println("Connecting to: " + String(host)); // Connect to S3 if (client.connect(host.c_str(), port)) { // Connection Succeed. - // Fecthing the bin + // Fetching the bin Serial.println("Fetching Bin: " + String(bin)); // Get the contents of the bin file - client.print(String("GET ") + bin + " HTTP/1.1\r\n" + - "Host: " + host + "\r\n" + - "Cache-Control: no-cache\r\n" + - "Connection: close\r\n\r\n"); + client.print(String("GET ") + bin + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Cache-Control: no-cache\r\n" + "Connection: close\r\n\r\n"); // Check what is being sent // Serial.print(String("GET ") + bin + " HTTP/1.1\r\n" + @@ -88,7 +85,7 @@ void execOTA() { Content-Type: application/octet-stream Content-Length: 357280 Server: AmazonS3 - + {{BIN FILE CONTENTS}} */ @@ -105,7 +102,7 @@ void execOTA() { // Update.writeStream(); if (!line.length()) { //headers ended - break; // and get the OTA started + break; // and get the OTA started } // Check if the HTTP Response is 200 @@ -160,7 +157,7 @@ void execOTA() { if (written == contentLength) { Serial.println("Written : " + String(written) + " successfully"); } else { - Serial.println("Written only : " + String(written) + "/" + String(contentLength) + ". Retry?" ); + Serial.println("Written only : " + String(written) + "/" + String(contentLength) + ". Retry?"); // retry?? // execOTA(); } @@ -201,7 +198,7 @@ void setup() { // Wait for connection to establish while (WiFi.status() != WL_CONNECTED) { - Serial.print("."); // Keep the serial monitor lit! + Serial.print("."); // Keep the serial monitor lit! delay(500); } @@ -219,12 +216,12 @@ void loop() { /* * Serial Monitor log for this sketch - * + * * If the OTA succeeded, it would load the preference sketch, with a small modification. i.e. * Print `OTA Update succeeded!! This is an example sketch : Preferences > StartCounter` * And then keeps on restarting every 10 seconds, updating the preferences - * - * + * + * rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0x00 clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 @@ -247,7 +244,7 @@ void loop() { OTA done! Update successfully completed. Rebooting. ets Jun 8 2016 00:22:57 - + rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0x00 clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 @@ -257,13 +254,13 @@ void loop() { load:0x40078000,len:10632 load:0x40080000,len:252 entry 0x40080034 - + OTA Update succeeded!! This is an example sketch : Preferences > StartCounter Current counter value: 1 Restarting in 10 seconds... E (102534) wifi: esp_wifi_stop 802 wifi is not init ets Jun 8 2016 00:22:57 - + rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0x00 clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 @@ -273,11 +270,11 @@ void loop() { load:0x40078000,len:10632 load:0x40080000,len:252 entry 0x40080034 - + OTA Update succeeded!! This is an example sketch : Preferences > StartCounter Current counter value: 2 Restarting in 10 seconds... .... - * + * */ diff --git a/libraries/Update/examples/HTTPS_OTA_Update/HTTPS_OTA_Update.ino b/libraries/Update/examples/HTTPS_OTA_Update/HTTPS_OTA_Update.ino index dfc6266e2fa..5d73a8db0ea 100644 --- a/libraries/Update/examples/HTTPS_OTA_Update/HTTPS_OTA_Update.ino +++ b/libraries/Update/examples/HTTPS_OTA_Update/HTTPS_OTA_Update.ino @@ -4,98 +4,97 @@ // This sketch shows how to implement HTTPS firmware update Over The Air. // Please provide your WiFi credentials, https URL to the firmware image and the server certificate. -static const char *ssid = "your-ssid"; // your network SSID (name of wifi network) -static const char *password = "your-password"; // your network password +static const char *ssid = "your-ssid"; // your network SSID (name of wifi network) +static const char *password = "your-password"; // your network password -static const char *url = "https://example.com/firmware.bin"; //state url of your firmware image +static const char *url = "https://example.com/firmware.bin"; //state url of your firmware image -static const char *server_certificate = "-----BEGIN CERTIFICATE-----\n" \ - "MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/\n" \ - "MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" \ - "DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow\n" \ - "SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAh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n" \ - "AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo\n" \ - "uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/\n" \ - "wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu\n" \ - "X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG\n" \ - "PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n" \ - "KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n" \ - "-----END CERTIFICATE-----"; +static const char *server_certificate = "-----BEGIN CERTIFICATE-----\n" + "MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/\n" + "MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" + "DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow\n" + "SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT\n" + "GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC\n" + "AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF\n" + "q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8\n" + "SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0\n" + "Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA\n" +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ERTIFICATE-----"; static HttpsOTAStatus_t otastatus; -void HttpEvent(HttpEvent_t *event) -{ - switch(event->event_id) { - case HTTP_EVENT_ERROR: - Serial.println("Http Event Error"); - break; - case HTTP_EVENT_ON_CONNECTED: - Serial.println("Http Event On Connected"); - break; - case HTTP_EVENT_HEADER_SENT: - Serial.println("Http Event Header Sent"); - break; - case HTTP_EVENT_ON_HEADER: - Serial.printf("Http Event On Header, key=%s, value=%s\n", event->header_key, event->header_value); - break; - case HTTP_EVENT_ON_DATA: - break; - case HTTP_EVENT_ON_FINISH: - Serial.println("Http Event On Finish"); - break; - case HTTP_EVENT_DISCONNECTED: - Serial.println("Http Event Disconnected"); - break; - case HTTP_EVENT_REDIRECT: - Serial.println("Http Event Redirect"); - break; - } +void HttpEvent(HttpEvent_t *event) { + switch (event->event_id) { + case HTTP_EVENT_ERROR: + Serial.println("Http Event Error"); + break; + case HTTP_EVENT_ON_CONNECTED: + Serial.println("Http Event On Connected"); + break; + case HTTP_EVENT_HEADER_SENT: + Serial.println("Http Event Header Sent"); + break; + case HTTP_EVENT_ON_HEADER: + Serial.printf("Http Event On Header, key=%s, value=%s\n", event->header_key, event->header_value); + break; + case HTTP_EVENT_ON_DATA: + break; + case HTTP_EVENT_ON_FINISH: + Serial.println("Http Event On Finish"); + break; + case HTTP_EVENT_DISCONNECTED: + Serial.println("Http Event Disconnected"); + break; + case HTTP_EVENT_REDIRECT: + Serial.println("Http Event Redirect"); + break; + } } -void setup(){ +void setup() { - Serial.begin(115200); - Serial.print("Attempting to connect to SSID: "); - WiFi.begin(ssid, password); + Serial.begin(115200); + Serial.print("Attempting to connect to SSID: "); + WiFi.begin(ssid, password); - // attempt to connect to Wifi network: - while (WiFi.status() != WL_CONNECTED) { - Serial.print("."); - delay(1000); - } + // attempt to connect to Wifi network: + while (WiFi.status() != WL_CONNECTED) { + Serial.print("."); + delay(1000); + } + + Serial.print("Connected to "); + Serial.println(ssid); - Serial.print("Connected to "); - Serial.println(ssid); - - HttpsOTA.onHttpEvent(HttpEvent); - Serial.println("Starting OTA"); - HttpsOTA.begin(url, server_certificate); + HttpsOTA.onHttpEvent(HttpEvent); + Serial.println("Starting OTA"); + HttpsOTA.begin(url, server_certificate); - Serial.println("Please Wait it takes some time ..."); + Serial.println("Please Wait it takes some time ..."); } -void loop(){ - otastatus = HttpsOTA.status(); - if(otastatus == HTTPS_OTA_SUCCESS) { - Serial.println("Firmware written successfully. To reboot device, call API ESP.restart() or PUSH restart button on device"); - } else if(otastatus == HTTPS_OTA_FAIL) { - Serial.println("Firmware Upgrade Fail"); - } - delay(1000); +void loop() { + otastatus = HttpsOTA.status(); + if (otastatus == HTTPS_OTA_SUCCESS) { + Serial.println("Firmware written successfully. To reboot device, call API ESP.restart() or PUSH restart button on device"); + } else if (otastatus == HTTPS_OTA_FAIL) { + Serial.println("Firmware Upgrade Fail"); + } + delay(1000); } diff --git a/libraries/Update/examples/HTTPS_OTA_Update/Readme.md b/libraries/Update/examples/HTTPS_OTA_Update/Readme.md index 27fdb59612b..8a0a158a877 100644 --- a/libraries/Update/examples/HTTPS_OTA_Update/Readme.md +++ b/libraries/Update/examples/HTTPS_OTA_Update/Readme.md @@ -1,16 +1,16 @@ # OTA Firmware Upgrade for Arduino This sketch allows Arduino user to perform Over The Air (OTA) firmware upgrade. It uses HTTPS. - + # API introduced for OTA -## HttpsOTA.begin(const char * url, const char * server_certificate, bool skip_cert_common_name_check) +## HttpsOTA.begin(const char * url, const char * server_certificate, bool skip_cert_common_name_check) Main API which starts firmware upgrade ### Parameters * url : URL for the uploaded firmware image * server_certificate : Provide the ota server certificate for authentication via HTTPS -* skip_cert_common_name_check : Skip any validation of server certificate CN field +* skip_cert_common_name_check : Skip any validation of server certificate CN field The default value provided to skip_cert_common_name_check is true @@ -19,14 +19,14 @@ The default value provided to skip_cert_common_name_check is true This API exposes HTTP Events to the user ### Parameter -Function passed has following signature +Function passed has following signature void HttpEvent (HttpEvent_t * event); # HttpsOTA.otaStatus() It tracks the progress of OTA firmware upgrade. * HTTPS_OTA_IDLE : OTA upgrade have not started yet. -* HTTPS_OTA_UPDATNG : OTA upgarde is in progress. +* HTTPS_OTA_UPDATNG : OTA upgrade is in progress. * HTTPS_OTA_SUCCESS : OTA upgrade is successful. * HTTPS_OTA_FAIL : OTA upgrade failed. -* HTTPS_OTA_ERR : Error occured while creating xEventGroup(). +* HTTPS_OTA_ERR : Error occurred while creating xEventGroup(). diff --git a/libraries/Update/examples/HTTP_Client_AES_OTA_Update/HTTP_Client_AES_OTA_Update.ino b/libraries/Update/examples/HTTP_Client_AES_OTA_Update/HTTP_Client_AES_OTA_Update.ino index a07e78c11a2..57001b94e0f 100644 --- a/libraries/Update/examples/HTTP_Client_AES_OTA_Update/HTTP_Client_AES_OTA_Update.ino +++ b/libraries/Update/examples/HTTP_Client_AES_OTA_Update/HTTP_Client_AES_OTA_Update.ino @@ -1,333 +1,333 @@ -/* -An example of how to use HTTPClient to download an encrypted and plain image files OTA from a web server. -This example uses Wifi & HTTPClient to connect to webserver and two functions for obtaining firmware image from webserver. -One uses the example 'updater.php' code on server to check and/or send relavent download firmware image file, -the other directly downloads the firmware file from web server. - -To use:- -Make a folder/directory on your webserver where your firmware images will be uploaded to. ie. /firmware -The 'updater.php' file can also be uploaded to the same folder. Edit and change definitions in 'update.php' to suit your needs. -In sketch: - set HTTPUPDATE_HOST to domain name or IP address if on LAN of your web server - set HTTPUPDATE_UPDATER_URI to path and file to call 'updater.php' -or set HTTPUPDATE_DIRECT_URI to path and firmware file to download - edit other HTTPUPDATE_ as needed - -Encrypted image will help protect your app image file from being copied and used on blank devices, encrypt your image file by using espressif IDF. -First install an app on device that has Update setup with the OTA decrypt mode on, same key, address and flash_crypt_conf as used in IDF to encrypt image file or vice versa. - -For easier development use the default U_AES_DECRYPT_AUTO decrypt mode. This mode allows both plain and encrypted app images to be uploaded. - -Note:- App image can also encrypted on device, by using espressif IDF to configure & enabled FLASH encryption, suggest the use of a different 'OTA_KEY' key for update from the eFuses 'flash_encryption' key used by device. - - ie. "Update.setupCrypt(OTA_KEY, OTA_ADDRESS, OTA_CFG);" - -defaults:- {if not set ie. "Update.setupCrypt();" } - OTA_KEY = 0 ( 0 = no key, disables decryption ) - OTA_ADDRESS = 0 ( suggest dont set address to app0=0x10000 usually or app1=varies ) - OTA_CFG = 0xf - OTA_MODE = U_AES_DECRYPT_AUTO - -OTA_MODE options:- - U_AES_DECRYPT_NONE decryption disabled, loads OTA image files as sent(plain) - U_AES_DECRYPT_AUTO auto loads both plain & encrypted OTA FLASH image files, and plain OTA SPIFFS image files - U_AES_DECRYPT_ON decrypts OTA image files - -https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/ - -Example: - espsecure.py encrypt_flash_data -k ota_key.bin --flash_crypt_conf 0xf -a 0x4320 -o output_filename.bin source_filename.bin - -espsecure.py encrypt_flash_data = runs the idf encryption function to make a encrypted output file from a source file - -k text = path/filename to the AES 256bit(32byte) encryption key file - --flash_crypt_conf 0xn = 0x0 to 0xf, the more bits set the higher the security of encryption(address salting, 0x0 would use ota_key with no address salting) - -a 0xnnnnnn00 = 0x00 to 0x00fffff0 address offset(must be a multiple of 16, but better to use multiple of 32), used to offset the salting (has no effect when = --flash_crypt_conf 0x0) - -o text = path/filename to save encrypted output file to - text = path/filename to open source file from -*/ - -#include -#include -#include -#include -#include - -//========================================================================== -//========================================================================== -const char* WIFI_SSID = "wifi-ssid"; -const char* WIFI_PASSWORD = "wifi-password"; - -const uint8_t OTA_KEY[32] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ - 0x38, 0x39, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, \ - 0x61, 0x20, 0x73, 0x69, 0x6d, 0x70, 0x6c, 0x65, \ - 0x74, 0x65, 0x73, 0x74, 0x20, 0x6b, 0x65, 0x79 }; - -/* -const uint8_t OTA_KEY[32] = {'0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', ' ', 't', 'h', 'i', 's', ' ', - 'a', ' ', 's', 'i', 'm', 'p', 'l', 'e', - 't', 'e', 's', 't', ' ', 'k', 'e', 'y' }; -*/ - -//const uint8_t OTA_KEY[33] = "0123456789 this a simpletest key"; - -const uint32_t OTA_ADDRESS = 0x4320; -const uint32_t OTA_CFG = 0x0f; -const uint32_t OTA_MODE = U_AES_DECRYPT_AUTO; - -const char* HTTPUPDATE_USERAGRENT = "ESP32-Updater"; -//const char* HTTPUPDATE_HOST = "www.yourdomain.com"; -const char* HTTPUPDATE_HOST = "192.168.1.2"; -const uint16_t HTTPUPDATE_PORT = 80; -const char* HTTPUPDATE_UPDATER_URI = "/firmware/updater.php"; //uri to 'updater.php' -const char* HTTPUPDATE_DIRECT_URI = "/firmware/HTTP_Client_AES_OTA_Update-v1.1.xbin"; //uri to image file - -const char* HTTPUPDATE_USER = NULL; //use NULL if no authentication needed -//const char* HTTPUPDATE_USER = "user"; -const char* HTTPUPDATE_PASSWORD = "password"; - -const char* HTTPUPDATE_BRAND = "21"; /* Brand ID */ -const char* HTTPUPDATE_MODEL = "HTTP_Client_AES_OTA_Update"; /* Project name */ -const char* HTTPUPDATE_FIRMWARE = "0.9"; /* Firmware version */ - -//========================================================================== -//========================================================================== -String urlEncode(const String& url, const char* safeChars="-_.~") { - String encoded = ""; - char temp[4]; - - for (int i = 0; i < url.length(); i++){ - temp[0] = url.charAt(i); - if(temp[0] == 32){//space - encoded.concat('+'); - }else if( (temp[0] >= 48 && temp[0] <= 57) /*0-9*/ - || (temp[0] >= 65 && temp[0] <= 90) /*A-Z*/ - || (temp[0] >= 97 && temp[0] <= 122) /*a-z*/ - || (strchr(safeChars, temp[0]) != NULL) /* "=&-_.~" */ - ){ - encoded.concat(temp[0]); - }else{ //character needs encoding - snprintf(temp, 4, "%%%02X", temp[0]); - encoded.concat(temp); - } - } - return encoded; -} - -//========================================================================== -bool addQuery(String* query, const String name, const String value) { - if( name.length() && value.length() ){ - if( query->length() < 3 ){ - *query = "?"; - }else{ - query->concat('&'); - } - query->concat( urlEncode(name) ); - query->concat('='); - query->concat( urlEncode(value) ); - return true; - } - return false; -} - -//========================================================================== -//========================================================================== -void printProgress(size_t progress, const size_t& size) { - static int last_progress=-1; - if(size>0){ - progress = (progress*100)/size; - progress = (progress>100 ? 100 : progress); //0-100 - if( progress != last_progress ){ - Serial.printf("Progress: %d%%\n", progress); - last_progress = progress; - } - } -} - -//========================================================================== -bool http_downloadUpdate(HTTPClient& http, uint32_t size=0) { - size = (size == 0 ? http.getSize() : size); - if(size == 0){ - return false; - } - NetworkClient *client = http.getStreamPtr(); - - if( !Update.begin(size, U_FLASH) ) { - Serial.printf("Update.begin failed! (%s)\n", Update.errorString() ); - return false; - } - - if( !Update.setupCrypt(OTA_KEY, OTA_ADDRESS, OTA_CFG, OTA_MODE)){ - Serial.println("Update.setupCrypt failed!"); - } - - if( Update.writeStream(*client) != size ) { - Serial.printf("Update.writeStream failed! (%s)\n", Update.errorString() ); - return false; - } - - if( !Update.end() ) { - Serial.printf("Update.end failed! (%s)\n", Update.errorString() ); - return false; - } - return true; -} - -//========================================================================== -int http_sendRequest(HTTPClient& http) { - -//set request Headers to be sent to server - http.useHTTP10(true); // use HTTP/1.0 for update since the update handler not support any transfer Encoding - http.setTimeout(8000); - http.addHeader("Cache-Control", "no-cache"); - -//set own name for HTTPclient user-agent - http.setUserAgent(HTTPUPDATE_USERAGRENT); - - int code = http.GET(); //send the GET request to HTTP server - int len = http.getSize(); - - if(code == HTTP_CODE_OK){ - return (len>0 ? len : 0); //return 0 or length of image to download - }else if(code < 0){ - Serial.printf("Error: %s\n", http.errorToString(code).c_str()); - return code; //error code should be minus between -1 to -11 - }else{ - Serial.printf("Error: HTTP Server response code %i\n", code); - return -code; //return code should be minus between -100 to -511 - } -} - -//========================================================================== -/* http_updater sends a GET request to 'update.php' on web server */ -bool http_updater(const String& host, const uint16_t& port, String uri, const bool& download, const char* user=NULL, const char* password=NULL) { -//add GET query params to be sent to server (are used by server 'updater.php' code to determine what action to take) - String query = ""; - addQuery(&query, "cmd",(download ? "download" :"check") ); //action command - -//setup HTTPclient to be ready to connect & send a request to HTTP server - HTTPClient http; - NetworkClient client; - uri.concat(query); //GET query added to end of uri path - if( !http.begin(client, host, port, uri) ){ - return false; //httpclient setup error - } - Serial.printf( "Sending HTTP request 'http://%s:%i%s'\n", host.c_str(), port, uri.c_str() ); - -//set basic authorization, if needed for webpage access - if(user != NULL && password != NULL){ - http.setAuthorization(user, password); //set basic Authorization to server, if needed be gain access - } - -//add unique Headers to be sent to server used by server 'update.php' code to determine there a suitable firmware update image avaliable - http.addHeader("Brand-Code", HTTPUPDATE_BRAND); - http.addHeader("Model", HTTPUPDATE_MODEL); - http.addHeader("Firmware", HTTPUPDATE_FIRMWARE); - -//set headers to look for to get returned values in servers http response to our http request - const char * headerkeys[] = { "update", "version" }; //server returns update 0=no update found, 1=update found, version=version of update found - size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*); - http.collectHeaders(headerkeys, headerkeyssize); - -//connect & send HTTP request to server - int size = http_sendRequest(http); - -//is there an image to download - if( size > 0 || (!download && size == 0) ){ - if( !http.header("update") || http.header("update").toInt() == 0 ){ - Serial.println("No Firmware avaliable"); - }else if( !http.header("version") || http.header("version").toFloat() <= String(HTTPUPDATE_FIRMWARE).toFloat() ){ - Serial.println("Firmware is upto Date"); - }else{ -//image avaliabe to download & update - if(!download){ - Serial.printf( "Found V%s Firmware\n", http.header("version").c_str() ); - }else{ - Serial.printf( "Downloading & Installing V%s Firmware\n", http.header("version").c_str() ); - } - if( !download || http_downloadUpdate(http) ){ - http.end(); //end connection - return true; - } - } - } - - http.end(); //end connection - return false; -} - -//========================================================================== -/* this downloads Firmware image file directly from web server */ -bool http_direct(const String& host, const uint16_t& port, const String& uri, const char* user=NULL, const char* password=NULL) { -//setup HTTPclient to be ready to connect & send a request to HTTP server - HTTPClient http; - NetworkClient client; - if( !http.begin(client, host, port, uri) ){ - return false; //httpclient setup error - } - Serial.printf( "Sending HTTP request 'http://%s:%i%s'\n", host.c_str(), port, uri.c_str() ); - -//set basic authorization, if needed for webpage access - if(user != NULL && password != NULL){ - http.setAuthorization(user, password); //set basic Authorization to server, if needed be gain access - } - -//connect & send HTTP request to server - int size = http_sendRequest(http); - -//is there an image to download - if(size > 0){ - if( http_downloadUpdate(http) ){ - http.end(); - return true; //end connection - } - }else{ - Serial.println("Image File not found"); - } - - http.end(); //end connection - return false; -} - -//========================================================================== -//========================================================================== - -void setup() { - Serial.begin(115200); - Serial.println(); - Serial.printf("Booting %s V%s\n", HTTPUPDATE_MODEL, HTTPUPDATE_FIRMWARE); - - WiFi.mode(WIFI_AP_STA); - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); - if(WiFi.waitForConnectResult() != WL_CONNECTED){ - Serial.println("WiFi failed, retrying."); - } - int i = 0; - while (WiFi.waitForConnectResult() != WL_CONNECTED){ - Serial.print("."); - if( (++i % 100) == 0){ - Serial.println(); - } - delay(100); - } - Serial.printf( "Connected to Wifi\nLocal IP: %s\n", WiFi.localIP().toString().c_str() ); - - Update.onProgress(printProgress); - - Serial.println("Checking with Server, if New Firmware avaliable"); - if( http_updater(HTTPUPDATE_HOST, HTTPUPDATE_PORT, HTTPUPDATE_UPDATER_URI, 0, HTTPUPDATE_USER, HTTPUPDATE_PASSWORD) ){ //check for new firmware - if( http_updater(HTTPUPDATE_HOST, HTTPUPDATE_PORT, HTTPUPDATE_UPDATER_URI, 1, HTTPUPDATE_USER, HTTPUPDATE_PASSWORD) ){ //update to new firmware - Serial.println("Firmware Update Sucessfull, rebooting"); - ESP.restart(); - } - } - - Serial.println("Checking Server for Firmware Image File to Download & Install"); - if( http_direct(HTTPUPDATE_HOST, HTTPUPDATE_PORT, HTTPUPDATE_DIRECT_URI, HTTPUPDATE_USER, HTTPUPDATE_PASSWORD) ){ - Serial.println("Firmware Update Sucessfull, rebooting"); - ESP.restart(); - } -} - -void loop() { -} +/* +An example of how to use HTTPClient to download an encrypted and plain image files OTA from a web server. +This example uses Wifi & HTTPClient to connect to webserver and two functions for obtaining firmware image from webserver. +One uses the example 'updater.php' code on server to check and/or send relevant download firmware image file, +the other directly downloads the firmware file from web server. + +To use:- +Make a folder/directory on your webserver where your firmware images will be uploaded to. ie. /firmware +The 'updater.php' file can also be uploaded to the same folder. Edit and change definitions in 'update.php' to suit your needs. +In sketch: + set HTTPUPDATE_HOST to domain name or IP address if on LAN of your web server + set HTTPUPDATE_UPDATER_URI to path and file to call 'updater.php' +or set HTTPUPDATE_DIRECT_URI to path and firmware file to download + edit other HTTPUPDATE_ as needed + +Encrypted image will help protect your app image file from being copied and used on blank devices, encrypt your image file by using espressif IDF. +First install an app on device that has Update setup with the OTA decrypt mode on, same key, address and flash_crypt_conf as used in IDF to encrypt image file or vice versa. + +For easier development use the default U_AES_DECRYPT_AUTO decrypt mode. This mode allows both plain and encrypted app images to be uploaded. + +Note:- App image can also encrypted on device, by using espressif IDF to configure & enabled FLASH encryption, suggest the use of a different 'OTA_KEY' key for update from the eFuses 'flash_encryption' key used by device. + + ie. "Update.setupCrypt(OTA_KEY, OTA_ADDRESS, OTA_CFG);" + +defaults:- {if not set ie. "Update.setupCrypt();" } + OTA_KEY = 0 ( 0 = no key, disables decryption ) + OTA_ADDRESS = 0 ( suggest dont set address to app0=0x10000 usually or app1=varies ) + OTA_CFG = 0xf + OTA_MODE = U_AES_DECRYPT_AUTO + +OTA_MODE options:- + U_AES_DECRYPT_NONE decryption disabled, loads OTA image files as sent(plain) + U_AES_DECRYPT_AUTO auto loads both plain & encrypted OTA FLASH image files, and plain OTA SPIFFS image files + U_AES_DECRYPT_ON decrypts OTA image files + +https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/ + +Example: + espsecure.py encrypt_flash_data -k ota_key.bin --flash_crypt_conf 0xf -a 0x4320 -o output_filename.bin source_filename.bin + +espsecure.py encrypt_flash_data = runs the idf encryption function to make a encrypted output file from a source file + -k text = path/filename to the AES 256bit(32byte) encryption key file + --flash_crypt_conf 0xn = 0x0 to 0xf, the more bits set the higher the security of encryption(address salting, 0x0 would use ota_key with no address salting) + -a 0xnnnnnn00 = 0x00 to 0x00fffff0 address offset(must be a multiple of 16, but better to use multiple of 32), used to offset the salting (has no effect when = --flash_crypt_conf 0x0) + -o text = path/filename to save encrypted output file to + text = path/filename to open source file from +*/ + +#include +#include +#include +#include +#include + +//========================================================================== +//========================================================================== +const char* WIFI_SSID = "wifi-ssid"; +const char* WIFI_PASSWORD = "wifi-password"; + +const uint8_t OTA_KEY[32] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, + 0x61, 0x20, 0x73, 0x69, 0x6d, 0x70, 0x6c, 0x65, + 0x74, 0x65, 0x73, 0x74, 0x20, 0x6b, 0x65, 0x79 }; + +/* +const uint8_t OTA_KEY[32] = {'0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', ' ', 't', 'h', 'i', 's', ' ', + 'a', ' ', 's', 'i', 'm', 'p', 'l', 'e', + 't', 'e', 's', 't', ' ', 'k', 'e', 'y' }; +*/ + +//const uint8_t OTA_KEY[33] = "0123456789 this a simpletest key"; + +const uint32_t OTA_ADDRESS = 0x4320; +const uint32_t OTA_CFG = 0x0f; +const uint32_t OTA_MODE = U_AES_DECRYPT_AUTO; + +const char* HTTPUPDATE_USERAGRENT = "ESP32-Updater"; +//const char* HTTPUPDATE_HOST = "www.yourdomain.com"; +const char* HTTPUPDATE_HOST = "192.168.1.2"; +const uint16_t HTTPUPDATE_PORT = 80; +const char* HTTPUPDATE_UPDATER_URI = "/firmware/updater.php"; //uri to 'updater.php' +const char* HTTPUPDATE_DIRECT_URI = "/firmware/HTTP_Client_AES_OTA_Update-v1.1.xbin"; //uri to image file + +const char* HTTPUPDATE_USER = NULL; //use NULL if no authentication needed +//const char* HTTPUPDATE_USER = "user"; +const char* HTTPUPDATE_PASSWORD = "password"; + +const char* HTTPUPDATE_BRAND = "21"; /* Brand ID */ +const char* HTTPUPDATE_MODEL = "HTTP_Client_AES_OTA_Update"; /* Project name */ +const char* HTTPUPDATE_FIRMWARE = "0.9"; /* Firmware version */ + +//========================================================================== +//========================================================================== +String urlEncode(const String& url, const char* safeChars = "-_.~") { + String encoded = ""; + char temp[4]; + + for (int i = 0; i < url.length(); i++) { + temp[0] = url.charAt(i); + if (temp[0] == 32) { //space + encoded.concat('+'); + } else if ((temp[0] >= 48 && temp[0] <= 57) /*0-9*/ + || (temp[0] >= 65 && temp[0] <= 90) /*A-Z*/ + || (temp[0] >= 97 && temp[0] <= 122) /*a-z*/ + || (strchr(safeChars, temp[0]) != NULL) /* "=&-_.~" */ + ) { + encoded.concat(temp[0]); + } else { //character needs encoding + snprintf(temp, 4, "%%%02X", temp[0]); + encoded.concat(temp); + } + } + return encoded; +} + +//========================================================================== +bool addQuery(String* query, const String name, const String value) { + if (name.length() && value.length()) { + if (query->length() < 3) { + *query = "?"; + } else { + query->concat('&'); + } + query->concat(urlEncode(name)); + query->concat('='); + query->concat(urlEncode(value)); + return true; + } + return false; +} + +//========================================================================== +//========================================================================== +void printProgress(size_t progress, const size_t& size) { + static int last_progress = -1; + if (size > 0) { + progress = (progress * 100) / size; + progress = (progress > 100 ? 100 : progress); //0-100 + if (progress != last_progress) { + Serial.printf("Progress: %d%%\n", progress); + last_progress = progress; + } + } +} + +//========================================================================== +bool http_downloadUpdate(HTTPClient& http, uint32_t size = 0) { + size = (size == 0 ? http.getSize() : size); + if (size == 0) { + return false; + } + NetworkClient* client = http.getStreamPtr(); + + if (!Update.begin(size, U_FLASH)) { + Serial.printf("Update.begin failed! (%s)\n", Update.errorString()); + return false; + } + + if (!Update.setupCrypt(OTA_KEY, OTA_ADDRESS, OTA_CFG, OTA_MODE)) { + Serial.println("Update.setupCrypt failed!"); + } + + if (Update.writeStream(*client) != size) { + Serial.printf("Update.writeStream failed! (%s)\n", Update.errorString()); + return false; + } + + if (!Update.end()) { + Serial.printf("Update.end failed! (%s)\n", Update.errorString()); + return false; + } + return true; +} + +//========================================================================== +int http_sendRequest(HTTPClient& http) { + + //set request Headers to be sent to server + http.useHTTP10(true); // use HTTP/1.0 for update since the update handler not support any transfer Encoding + http.setTimeout(8000); + http.addHeader("Cache-Control", "no-cache"); + + //set own name for HTTPclient user-agent + http.setUserAgent(HTTPUPDATE_USERAGRENT); + + int code = http.GET(); //send the GET request to HTTP server + int len = http.getSize(); + + if (code == HTTP_CODE_OK) { + return (len > 0 ? len : 0); //return 0 or length of image to download + } else if (code < 0) { + Serial.printf("Error: %s\n", http.errorToString(code).c_str()); + return code; //error code should be minus between -1 to -11 + } else { + Serial.printf("Error: HTTP Server response code %i\n", code); + return -code; //return code should be minus between -100 to -511 + } +} + +//========================================================================== +/* http_updater sends a GET request to 'update.php' on web server */ +bool http_updater(const String& host, const uint16_t& port, String uri, const bool& download, const char* user = NULL, const char* password = NULL) { + //add GET query params to be sent to server (are used by server 'updater.php' code to determine what action to take) + String query = ""; + addQuery(&query, "cmd", (download ? "download" : "check")); //action command + + //setup HTTPclient to be ready to connect & send a request to HTTP server + HTTPClient http; + NetworkClient client; + uri.concat(query); //GET query added to end of uri path + if (!http.begin(client, host, port, uri)) { + return false; //httpclient setup error + } + Serial.printf("Sending HTTP request 'http://%s:%i%s'\n", host.c_str(), port, uri.c_str()); + + //set basic authorization, if needed for webpage access + if (user != NULL && password != NULL) { + http.setAuthorization(user, password); //set basic Authorization to server, if needed be gain access + } + + //add unique Headers to be sent to server used by server 'update.php' code to determine there a suitable firmware update image available + http.addHeader("Brand-Code", HTTPUPDATE_BRAND); + http.addHeader("Model", HTTPUPDATE_MODEL); + http.addHeader("Firmware", HTTPUPDATE_FIRMWARE); + + //set headers to look for to get returned values in servers http response to our http request + const char* headerkeys[] = { "update", "version" }; //server returns update 0=no update found, 1=update found, version=version of update found + size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*); + http.collectHeaders(headerkeys, headerkeyssize); + + //connect & send HTTP request to server + int size = http_sendRequest(http); + + //is there an image to download + if (size > 0 || (!download && size == 0)) { + if (!http.header("update") || http.header("update").toInt() == 0) { + Serial.println("No Firmware available"); + } else if (!http.header("version") || http.header("version").toFloat() <= String(HTTPUPDATE_FIRMWARE).toFloat()) { + Serial.println("Firmware is upto Date"); + } else { + //image avaliabe to download & update + if (!download) { + Serial.printf("Found V%s Firmware\n", http.header("version").c_str()); + } else { + Serial.printf("Downloading & Installing V%s Firmware\n", http.header("version").c_str()); + } + if (!download || http_downloadUpdate(http)) { + http.end(); //end connection + return true; + } + } + } + + http.end(); //end connection + return false; +} + +//========================================================================== +/* this downloads Firmware image file directly from web server */ +bool http_direct(const String& host, const uint16_t& port, const String& uri, const char* user = NULL, const char* password = NULL) { + //setup HTTPclient to be ready to connect & send a request to HTTP server + HTTPClient http; + NetworkClient client; + if (!http.begin(client, host, port, uri)) { + return false; //httpclient setup error + } + Serial.printf("Sending HTTP request 'http://%s:%i%s'\n", host.c_str(), port, uri.c_str()); + + //set basic authorization, if needed for webpage access + if (user != NULL && password != NULL) { + http.setAuthorization(user, password); //set basic Authorization to server, if needed be gain access + } + + //connect & send HTTP request to server + int size = http_sendRequest(http); + + //is there an image to download + if (size > 0) { + if (http_downloadUpdate(http)) { + http.end(); + return true; //end connection + } + } else { + Serial.println("Image File not found"); + } + + http.end(); //end connection + return false; +} + +//========================================================================== +//========================================================================== + +void setup() { + Serial.begin(115200); + Serial.println(); + Serial.printf("Booting %s V%s\n", HTTPUPDATE_MODEL, HTTPUPDATE_FIRMWARE); + + WiFi.mode(WIFI_AP_STA); + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); + if (WiFi.waitForConnectResult() != WL_CONNECTED) { + Serial.println("WiFi failed, retrying."); + } + int i = 0; + while (WiFi.waitForConnectResult() != WL_CONNECTED) { + Serial.print("."); + if ((++i % 100) == 0) { + Serial.println(); + } + delay(100); + } + Serial.printf("Connected to Wifi\nLocal IP: %s\n", WiFi.localIP().toString().c_str()); + + Update.onProgress(printProgress); + + Serial.println("Checking with Server, if New Firmware available"); + if (http_updater(HTTPUPDATE_HOST, HTTPUPDATE_PORT, HTTPUPDATE_UPDATER_URI, 0, HTTPUPDATE_USER, HTTPUPDATE_PASSWORD)) { //check for new firmware + if (http_updater(HTTPUPDATE_HOST, HTTPUPDATE_PORT, HTTPUPDATE_UPDATER_URI, 1, HTTPUPDATE_USER, HTTPUPDATE_PASSWORD)) { //update to new firmware + Serial.println("Firmware Update Successful, rebooting"); + ESP.restart(); + } + } + + Serial.println("Checking Server for Firmware Image File to Download & Install"); + if (http_direct(HTTPUPDATE_HOST, HTTPUPDATE_PORT, HTTPUPDATE_DIRECT_URI, HTTPUPDATE_USER, HTTPUPDATE_PASSWORD)) { + Serial.println("Firmware Update Successful, rebooting"); + ESP.restart(); + } +} + +void loop() { +} diff --git a/libraries/Update/examples/HTTP_Client_AES_OTA_Update/updater.php b/libraries/Update/examples/HTTP_Client_AES_OTA_Update/updater.php index 4edfb75a126..056a741baa4 100644 --- a/libraries/Update/examples/HTTP_Client_AES_OTA_Update/updater.php +++ b/libraries/Update/examples/HTTP_Client_AES_OTA_Update/updater.php @@ -42,10 +42,10 @@ function verify($valid){ /*********************************************************************************/ if( !$firmware['filename'] || !file_exists($firmware['filename']) ){ - header('update: 0' );//no update avaliable + header('update: 0' );//no update available exit; }else{ - header('update: 1' );//update avaliable + header('update: 1' );//update available header('version: ' . $firmware['version'] ); if($GetArgs['cmd'] == "download"){ //Get file type and set it as Content Type diff --git a/libraries/Update/examples/HTTP_Server_AES_OTA_Update/HTTP_Server_AES_OTA_Update.ino b/libraries/Update/examples/HTTP_Server_AES_OTA_Update/HTTP_Server_AES_OTA_Update.ino index 885115596c2..4d8abb71303 100644 --- a/libraries/Update/examples/HTTP_Server_AES_OTA_Update/HTTP_Server_AES_OTA_Update.ino +++ b/libraries/Update/examples/HTTP_Server_AES_OTA_Update/HTTP_Server_AES_OTA_Update.ino @@ -1,235 +1,237 @@ -/* -An example of how to use Update to upload encrypted and plain image files OTA. This example uses a simple webserver & Wifi connection via AP or STA with mDNS and DNS for simple host URI. - -Encrypted image will help protect your app image file from being copied and used on blank devices, encrypt your image file by using espressif IDF. -First install an app on device that has Update setup with the OTA decrypt mode on, same key, address and flash_crypt_conf as used in IDF to encrypt image file or vice versa. - -For easier development use the default U_AES_DECRYPT_AUTO decrypt mode. This mode allows both plain and encrypted app images to be uploaded. - -Note:- App image can also encrypted on device, by using espressif IDF to configure & enabled FLASH encryption, suggest the use of a different 'OTA_KEY' key for update from the eFuses 'flash_encryption' key used by device. - - ie. "Update.setupCrypt(OTA_KEY, OTA_ADDRESS, OTA_CFG);" - -defaults:- {if not set ie. "Update.setupCrypt();" } - OTA_KEY = 0 ( 0 = no key, disables decryption ) - OTA_ADDRESS = 0 ( suggest dont set address to app0=0x10000 usually or app1=varies ) - OTA_CFG = 0xf - OTA_MODE = U_AES_DECRYPT_AUTO - -OTA_MODE options:- - U_AES_DECRYPT_NONE decryption disabled, loads OTA image files as sent(plain) - U_AES_DECRYPT_AUTO auto loads both plain & encrypted OTA FLASH image files, and plain OTA SPIFFS image files - U_AES_DECRYPT_ON decrypts OTA image files - -https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/ - -Example: - espsecure.py encrypt_flash_data -k ota_key.bin --flash_crypt_conf 0xf -a 0x4320 -o output_filename.bin source_filename.bin - -espsecure.py encrypt_flash_data = runs the idf encryption function to make a encrypted output file from a source file - -k text = path/filename to the AES 256bit(32byte) encryption key file - --flash_crypt_conf 0xn = 0x0 to 0xf, the more bits set the higher the security of encryption(address salting, 0x0 would use ota_key with no address salting) - -a 0xnnnnnn00 = 0x00 to 0x00fffff0 address offset(must be a multiple of 16, but better to use multiple of 32), used to offset the salting (has no effect when = --flash_crypt_conf 0x0) - -o text = path/filename to save encrypted output file to - text = path/filename to open source file from -*/ - -#include -#include -#include -#include -#include -#include - -WebServer httpServer(80); - -//with WIFI_MODE_AP defined the ESP32 is a wifi AP, with it undefined ESP32 tries to connect to wifi STA -#define WIFI_MODE_AP - -#ifdef WIFI_MODE_AP - #include - DNSServer dnsServer; -#endif - -const char* host = "esp32-web"; -const char* ssid = "wifi-ssid"; -const char* password = "wifi-password"; - -const uint8_t OTA_KEY[32] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ - 0x38, 0x39, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, \ - 0x61, 0x20, 0x73, 0x69, 0x6d, 0x70, 0x6c, 0x65, \ - 0x74, 0x65, 0x73, 0x74, 0x20, 0x6b, 0x65, 0x79 }; - -/* -const uint8_t OTA_KEY[32] = {'0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', ' ', 't', 'h', 'i', 's', ' ', - 'a', ' ', 's', 'i', 'm', 'p', 'l', 'e', - 't', 'e', 's', 't', ' ', 'k', 'e', 'y' }; -*/ - -//const uint8_t OTA_KEY[33] = "0123456789 this a simpletest key"; - -const uint32_t OTA_ADDRESS = 0x4320; //OTA_ADDRESS value has no effect when OTA_CFG = 0x00 -const uint32_t OTA_CFG = 0x0f; -const uint32_t OTA_MODE = U_AES_DECRYPT_AUTO; - -/*=================================================================*/ -const char* update_path = "update"; - -static const char UpdatePage_HTML[] PROGMEM = -R"( - - - Image Upload - - - - -
- Firmware:

-

- -
-


-
- FileSystem:

-

- -
- - )"; - -/*=================================================================*/ - -void printProgress(size_t progress, size_t size) { - static int last_progress=-1; - if(size>0){ - progress = (progress*100)/size; - progress = (progress>100 ? 100 : progress); //0-100 - if( progress != last_progress ){ - Serial.printf("\nProgress: %d%%", progress); - last_progress = progress; - } - } -} - -void setupHttpUpdateServer() { - //redirecting not found web pages back to update page - httpServer.onNotFound( [&]() { //webpage not found - httpServer.sendHeader("Location", String("../")+String(update_path) ); - httpServer.send(302, F("text/html"), "" ); - }); - - // handler for the update web page - httpServer.on(String("/")+String(update_path), HTTP_GET, [&]() { - httpServer.send_P(200, PSTR("text/html"), UpdatePage_HTML); - }); - - // handler for the update page form POST - httpServer.on( String("/")+String(update_path), HTTP_POST, [&]() { - // handler when file upload finishes - if (Update.hasError()) { - httpServer.send(200, F("text/html"), String(F("Update error: ")) + String(Update.errorString()) ); - } else { - httpServer.client().setNoDelay(true); - httpServer.send(200, PSTR("text/html"), String(F("Update Success! Rebooting...")) ); - delay(100); - httpServer.client().stop(); - ESP.restart(); - } - }, [&]() { - // handler for the file upload, get's the sketch bytes, and writes - // them through the Update object - HTTPUpload& upload = httpServer.upload(); - if (upload.status == UPLOAD_FILE_START) { - Serial.printf("Update: %s\n", upload.filename.c_str()); - if (upload.name == "filesystem") { - if (!Update.begin(SPIFFS.totalBytes(), U_SPIFFS)) {//start with max available size - Update.printError(Serial); - } - } else { - uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; - if (!Update.begin(maxSketchSpace, U_FLASH)) {//start with max available size - Update.printError(Serial); - } - } - } else if ( upload.status == UPLOAD_FILE_ABORTED || Update.hasError() ) { - if(upload.status == UPLOAD_FILE_ABORTED){ - if(!Update.end(false)){ - Update.printError(Serial); - } - Serial.println("Update was aborted"); - } - } else if (upload.status == UPLOAD_FILE_WRITE) { - Serial.printf("."); - if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) { - Update.printError(Serial); - } - } else if (upload.status == UPLOAD_FILE_END) { - if (Update.end(true)) { //true to set the size to the current progress - Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize); - } else { - Update.printError(Serial); - } - } - delay(0); - }); - - Update.onProgress(printProgress); -} - -/*=================================================================*/ - -void setup(void) { - Serial.begin(115200); - Serial.println(); - Serial.println("Booting Sketch..."); - WiFi.mode(WIFI_AP_STA); -#ifdef WIFI_MODE_AP - WiFi.softAP(ssid, password); - dnsServer.setErrorReplyCode(DNSReplyCode::NoError); - dnsServer.start(53, "*", WiFi.softAPIP() ); //if DNS started with "*" for domain name, it will reply with provided IP to all DNS request - Serial.printf("Wifi AP started, IP address: %s\n", WiFi.softAPIP().toString().c_str() ); - Serial.printf("You can connect to ESP32 AP use:-\n ssid: %s\npassword: %s\n\n", ssid, password); -#else - WiFi.begin(ssid, password); - if(WiFi.waitForConnectResult() != WL_CONNECTED){ - Serial.println("WiFi failed, retrying."); - } - int i = 0; - while (WiFi.waitForConnectResult() != WL_CONNECTED){ - Serial.print("."); - if( (++i % 100) == 0){ - Serial.println(); - } - delay(100); - } - Serial.printf("Connected to Wifi\nLocal IP: %s\n", WiFi.localIP().toString().c_str()); -#endif - - if( MDNS.begin(host) ) { - Serial.println("mDNS responder started"); - } - - setupHttpUpdateServer(); - - if( Update.setupCrypt(OTA_KEY, OTA_ADDRESS, OTA_CFG, OTA_MODE)){ - Serial.println("Upload Decryption Ready"); - } - - httpServer.begin(); - - MDNS.addService("http", "tcp", 80); -#ifdef WIFI_MODE_AP - Serial.printf("HTTPUpdateServer ready with Captive DNS!\nOpen http://anyname.xyz/%s in your browser\n", update_path); -#else - Serial.printf("HTTPUpdateServer ready!\nOpen http://%s.local/%s in your browser\n", host, update_path); -#endif -} - -void loop(void) { - httpServer.handleClient(); -#ifdef WIFI_MODE_AP - dnsServer.processNextRequest(); //DNS captive portal for easy access to this device webserver -#endif -} +/* +An example of how to use Update to upload encrypted and plain image files OTA. This example uses a simple webserver & Wifi connection via AP or STA with mDNS and DNS for simple host URI. + +Encrypted image will help protect your app image file from being copied and used on blank devices, encrypt your image file by using espressif IDF. +First install an app on device that has Update setup with the OTA decrypt mode on, same key, address and flash_crypt_conf as used in IDF to encrypt image file or vice versa. + +For easier development use the default U_AES_DECRYPT_AUTO decrypt mode. This mode allows both plain and encrypted app images to be uploaded. + +Note:- App image can also encrypted on device, by using espressif IDF to configure & enabled FLASH encryption, suggest the use of a different 'OTA_KEY' key for update from the eFuses 'flash_encryption' key used by device. + + ie. "Update.setupCrypt(OTA_KEY, OTA_ADDRESS, OTA_CFG);" + +defaults:- {if not set ie. "Update.setupCrypt();" } + OTA_KEY = 0 ( 0 = no key, disables decryption ) + OTA_ADDRESS = 0 ( suggest dont set address to app0=0x10000 usually or app1=varies ) + OTA_CFG = 0xf + OTA_MODE = U_AES_DECRYPT_AUTO + +OTA_MODE options:- + U_AES_DECRYPT_NONE decryption disabled, loads OTA image files as sent(plain) + U_AES_DECRYPT_AUTO auto loads both plain & encrypted OTA FLASH image files, and plain OTA SPIFFS image files + U_AES_DECRYPT_ON decrypts OTA image files + +https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/ + +Example: + espsecure.py encrypt_flash_data -k ota_key.bin --flash_crypt_conf 0xf -a 0x4320 -o output_filename.bin source_filename.bin + +espsecure.py encrypt_flash_data = runs the idf encryption function to make a encrypted output file from a source file + -k text = path/filename to the AES 256bit(32byte) encryption key file + --flash_crypt_conf 0xn = 0x0 to 0xf, the more bits set the higher the security of encryption(address salting, 0x0 would use ota_key with no address salting) + -a 0xnnnnnn00 = 0x00 to 0x00fffff0 address offset(must be a multiple of 16, but better to use multiple of 32), used to offset the salting (has no effect when = --flash_crypt_conf 0x0) + -o text = path/filename to save encrypted output file to + text = path/filename to open source file from +*/ + +#include +#include +#include +#include +#include +#include + +WebServer httpServer(80); + +//with WIFI_MODE_AP defined the ESP32 is a wifi AP, with it undefined ESP32 tries to connect to wifi STA +#define WIFI_MODE_AP + +#ifdef WIFI_MODE_AP +#include +DNSServer dnsServer; +#endif + +const char* host = "esp32-web"; +const char* ssid = "wifi-ssid"; +const char* password = "wifi-password"; + +const uint8_t OTA_KEY[32] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, + 0x61, 0x20, 0x73, 0x69, 0x6d, 0x70, 0x6c, 0x65, + 0x74, 0x65, 0x73, 0x74, 0x20, 0x6b, 0x65, 0x79 }; + +/* +const uint8_t OTA_KEY[32] = {'0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', ' ', 't', 'h', 'i', 's', ' ', + 'a', ' ', 's', 'i', 'm', 'p', 'l', 'e', + 't', 'e', 's', 't', ' ', 'k', 'e', 'y' }; +*/ + +//const uint8_t OTA_KEY[33] = "0123456789 this a simpletest key"; + +const uint32_t OTA_ADDRESS = 0x4320; //OTA_ADDRESS value has no effect when OTA_CFG = 0x00 +const uint32_t OTA_CFG = 0x0f; +const uint32_t OTA_MODE = U_AES_DECRYPT_AUTO; + +/*=================================================================*/ +const char* update_path = "update"; + +static const char UpdatePage_HTML[] PROGMEM = + R"( + + + Image Upload + + + + +
+ Firmware:

+

+ +
+


+
+ FileSystem:

+

+ +
+ + )"; + +/*=================================================================*/ + +void printProgress(size_t progress, size_t size) { + static int last_progress = -1; + if (size > 0) { + progress = (progress * 100) / size; + progress = (progress > 100 ? 100 : progress); //0-100 + if (progress != last_progress) { + Serial.printf("\nProgress: %d%%", progress); + last_progress = progress; + } + } +} + +void setupHttpUpdateServer() { + //redirecting not found web pages back to update page + httpServer.onNotFound([&]() { //webpage not found + httpServer.sendHeader("Location", String("../") + String(update_path)); + httpServer.send(302, F("text/html"), ""); + }); + + // handler for the update web page + httpServer.on(String("/") + String(update_path), HTTP_GET, [&]() { + httpServer.send_P(200, PSTR("text/html"), UpdatePage_HTML); + }); + + // handler for the update page form POST + httpServer.on( + String("/") + String(update_path), HTTP_POST, [&]() { + // handler when file upload finishes + if (Update.hasError()) { + httpServer.send(200, F("text/html"), String(F("Update error: ")) + String(Update.errorString())); + } else { + httpServer.client().setNoDelay(true); + httpServer.send(200, PSTR("text/html"), String(F("Update Success! Rebooting..."))); + delay(100); + httpServer.client().stop(); + ESP.restart(); + } + }, + [&]() { + // handler for the file upload, gets the sketch bytes, and writes + // them through the Update object + HTTPUpload& upload = httpServer.upload(); + if (upload.status == UPLOAD_FILE_START) { + Serial.printf("Update: %s\n", upload.filename.c_str()); + if (upload.name == "filesystem") { + if (!Update.begin(SPIFFS.totalBytes(), U_SPIFFS)) { //start with max available size + Update.printError(Serial); + } + } else { + uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; + if (!Update.begin(maxSketchSpace, U_FLASH)) { //start with max available size + Update.printError(Serial); + } + } + } else if (upload.status == UPLOAD_FILE_ABORTED || Update.hasError()) { + if (upload.status == UPLOAD_FILE_ABORTED) { + if (!Update.end(false)) { + Update.printError(Serial); + } + Serial.println("Update was aborted"); + } + } else if (upload.status == UPLOAD_FILE_WRITE) { + Serial.printf("."); + if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) { + Update.printError(Serial); + } + } else if (upload.status == UPLOAD_FILE_END) { + if (Update.end(true)) { //true to set the size to the current progress + Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize); + } else { + Update.printError(Serial); + } + } + delay(0); + }); + + Update.onProgress(printProgress); +} + +/*=================================================================*/ + +void setup(void) { + Serial.begin(115200); + Serial.println(); + Serial.println("Booting Sketch..."); + WiFi.mode(WIFI_AP_STA); +#ifdef WIFI_MODE_AP + WiFi.softAP(ssid, password); + dnsServer.setErrorReplyCode(DNSReplyCode::NoError); + dnsServer.start(53, "*", WiFi.softAPIP()); //if DNS started with "*" for domain name, it will reply with provided IP to all DNS request + Serial.printf("Wifi AP started, IP address: %s\n", WiFi.softAPIP().toString().c_str()); + Serial.printf("You can connect to ESP32 AP use:-\n ssid: %s\npassword: %s\n\n", ssid, password); +#else + WiFi.begin(ssid, password); + if (WiFi.waitForConnectResult() != WL_CONNECTED) { + Serial.println("WiFi failed, retrying."); + } + int i = 0; + while (WiFi.waitForConnectResult() != WL_CONNECTED) { + Serial.print("."); + if ((++i % 100) == 0) { + Serial.println(); + } + delay(100); + } + Serial.printf("Connected to Wifi\nLocal IP: %s\n", WiFi.localIP().toString().c_str()); +#endif + + if (MDNS.begin(host)) { + Serial.println("mDNS responder started"); + } + + setupHttpUpdateServer(); + + if (Update.setupCrypt(OTA_KEY, OTA_ADDRESS, OTA_CFG, OTA_MODE)) { + Serial.println("Upload Decryption Ready"); + } + + httpServer.begin(); + + MDNS.addService("http", "tcp", 80); +#ifdef WIFI_MODE_AP + Serial.printf("HTTPUpdateServer ready with Captive DNS!\nOpen http://anyname.xyz/%s in your browser\n", update_path); +#else + Serial.printf("HTTPUpdateServer ready!\nOpen http://%s.local/%s in your browser\n", host, update_path); +#endif +} + +void loop(void) { + httpServer.handleClient(); +#ifdef WIFI_MODE_AP + dnsServer.processNextRequest(); //DNS captive portal for easy access to this device webserver +#endif +} diff --git a/libraries/Update/examples/OTAWebUpdater/OTAWebUpdater.ino b/libraries/Update/examples/OTAWebUpdater/OTAWebUpdater.ino index 27e4ac6d95f..0e0a5a3bd7b 100644 --- a/libraries/Update/examples/OTAWebUpdater/OTAWebUpdater.ino +++ b/libraries/Update/examples/OTAWebUpdater/OTAWebUpdater.ino @@ -5,7 +5,7 @@ #include #include "html.h" -#define SSID_FORMAT "ESP32-%06lX" // 12 chars total +#define SSID_FORMAT "ESP32-%06lX" // 12 chars total //#define PASSWORD "test123456" // generate if remarked WebServer server(80); @@ -15,23 +15,23 @@ uint8_t otaDone = 0; const char* alphanum = "0123456789!@#$%^&*abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; String generatePass(uint8_t str_len) { String buff; - for(int i = 0; i < str_len; i++) - buff += alphanum[random(strlen(alphanum)-1)]; + for (int i = 0; i < str_len; i++) + buff += alphanum[random(strlen(alphanum) - 1)]; return buff; } void apMode() { char ssid[13]; char passwd[11]; - long unsigned int espmac = ESP.getEfuseMac() >> 24; + long unsigned int espmac = ESP.getEfuseMac() >> 24; snprintf(ssid, 13, SSID_FORMAT, espmac); #ifdef PASSWORD snprintf(passwd, 11, PASSWORD); #else snprintf(passwd, 11, generatePass(10).c_str()); -#endif +#endif WiFi.mode(WIFI_AP); - WiFi.softAP(ssid, passwd); // Set up the SoftAP + WiFi.softAP(ssid, passwd); // Set up the SoftAP MDNS.begin("esp32"); Serial.printf("AP: %s, PASS: %s\n", ssid, passwd); } @@ -42,7 +42,7 @@ void handleUpdateEnd() { server.send(502, "text/plain", Update.errorString()); } else { server.sendHeader("Refresh", "10"); - server.sendHeader("Location","/"); + server.sendHeader("Location", "/"); server.send(307); ESP.restart(); } @@ -75,18 +75,26 @@ void handleUpdate() { } void webServerInit() { - server.on("/update", HTTP_POST, [](){handleUpdateEnd();}, [](){handleUpdate();}); - server.on("/favicon.ico", HTTP_GET, [](){ - server.sendHeader("Content-Encoding", "gzip"); - server.send_P(200, "image/x-icon", favicon_ico_gz, favicon_ico_gz_len); + server.on( + "/update", HTTP_POST, []() { + handleUpdateEnd(); + }, + []() { + handleUpdate(); + }); + server.on("/favicon.ico", HTTP_GET, []() { + server.sendHeader("Content-Encoding", "gzip"); + server.send_P(200, "image/x-icon", favicon_ico_gz, favicon_ico_gz_len); + }); + server.onNotFound([]() { + server.send(200, "text/html", indexHtml); }); - server.onNotFound([]() {server.send(200, "text/html", indexHtml);}); server.begin(); Serial.printf("Web Server ready at http://esp32.local or http://%s\n", WiFi.softAPIP().toString().c_str()); } void everySecond() { - if (otaDone > 1) Serial.printf("ota: %d%%\n", otaDone); + if (otaDone > 1) Serial.printf("ota: %d%%\n", otaDone); } void setup() { diff --git a/libraries/Update/examples/OTAWebUpdater/html.h b/libraries/Update/examples/OTAWebUpdater/html.h index 9a100e69357..eb63d229e1b 100644 --- a/libraries/Update/examples/OTAWebUpdater/html.h +++ b/libraries/Update/examples/OTAWebUpdater/html.h @@ -15,19 +15,19 @@ const char* indexHtml = R"literal( var prg = document.getElementById('prg'); var form = document.getElementById('upload-form'); form.addEventListener('submit', el=>{ - prg.style.backgroundColor = 'blue'; + prg.style.backgroundColor = 'blue'; el.preventDefault(); var data = new FormData(form); var req = new XMLHttpRequest(); var fsize = document.getElementById('file').files[0].size; - req.open('POST', '/update?size=' + fsize); + req.open('POST', '/update?size=' + fsize); req.upload.addEventListener('progress', p=>{ let w = Math.round(p.loaded/p.total*100) + '%'; if(p.lengthComputable){ prg.innerHTML = w; prg.style.width = w; } - if(w == '100%') prg.style.backgroundColor = 'black'; + if(w == '100%') prg.style.backgroundColor = 'black'; }); req.send(data); }); diff --git a/libraries/Update/examples/SD_Update/SD_Update.ino b/libraries/Update/examples/SD_Update/SD_Update.ino index 61966f98dd2..f0ed9e77233 100644 --- a/libraries/Update/examples/SD_Update/SD_Update.ino +++ b/libraries/Update/examples/SD_Update/SD_Update.ino @@ -1,4 +1,4 @@ -/* +/* Name: SD_Update.ino Created: 12.09.2017 15:07:17 Author: Frederik Merz @@ -9,9 +9,9 @@ 2. Copy update.bin to a SD-Card, you can basically compile this or any other example then copy and rename the app binary to the sd card root - 3. Connect SD-Card as shown in SD example, + 3. Connect SD-Card as shown in SD example, this can also be adapted for SPI - 3. After successfull update and reboot, ESP32 shall start the new app + 3. After successful update and reboot, ESP32 shall start the new app */ #include @@ -20,93 +20,85 @@ // perform the actual update from a given stream void performUpdate(Stream &updateSource, size_t updateSize) { - if (Update.begin(updateSize)) { - size_t written = Update.writeStream(updateSource); - if (written == updateSize) { - Serial.println("Written : " + String(written) + " successfully"); - } - else { - Serial.println("Written only : " + String(written) + "/" + String(updateSize) + ". Retry?"); - } - if (Update.end()) { - Serial.println("OTA done!"); - if (Update.isFinished()) { - Serial.println("Update successfully completed. Rebooting."); - } - else { - Serial.println("Update not finished? Something went wrong!"); - } - } - else { - Serial.println("Error Occurred. Error #: " + String(Update.getError())); + if (Update.begin(updateSize)) { + size_t written = Update.writeStream(updateSource); + if (written == updateSize) { + Serial.println("Written : " + String(written) + " successfully"); + } else { + Serial.println("Written only : " + String(written) + "/" + String(updateSize) + ". Retry?"); + } + if (Update.end()) { + Serial.println("OTA done!"); + if (Update.isFinished()) { + Serial.println("Update successfully completed. Rebooting."); + } else { + Serial.println("Update not finished? Something went wrong!"); } + } else { + Serial.println("Error Occurred. Error #: " + String(Update.getError())); + } - } - else - { - Serial.println("Not enough space to begin OTA"); - } + } else { + Serial.println("Not enough space to begin OTA"); + } } // check given FS for valid update.bin and perform update if available void updateFromFS(fs::FS &fs) { - File updateBin = fs.open("/update.bin"); - if (updateBin) { - if(updateBin.isDirectory()){ - Serial.println("Error, update.bin is not a file"); - updateBin.close(); - return; - } + File updateBin = fs.open("/update.bin"); + if (updateBin) { + if (updateBin.isDirectory()) { + Serial.println("Error, update.bin is not a file"); + updateBin.close(); + return; + } - size_t updateSize = updateBin.size(); + size_t updateSize = updateBin.size(); - if (updateSize > 0) { - Serial.println("Try to start update"); - performUpdate(updateBin, updateSize); - } - else { - Serial.println("Error, file is empty"); - } + if (updateSize > 0) { + Serial.println("Try to start update"); + performUpdate(updateBin, updateSize); + } else { + Serial.println("Error, file is empty"); + } - updateBin.close(); - - // whe finished remove the binary from sd card to indicate end of the process - fs.remove("/update.bin"); - } - else { - Serial.println("Could not load update.bin from sd root"); - } + updateBin.close(); + + // when finished remove the binary from sd card to indicate end of the process + fs.remove("/update.bin"); + } else { + Serial.println("Could not load update.bin from sd root"); + } } void setup() { - uint8_t cardType; - Serial.begin(115200); - Serial.println("Welcome to the SD-Update example!"); + uint8_t cardType; + Serial.begin(115200); + Serial.println("Welcome to the SD-Update example!"); - // You can uncomment this and build again - // Serial.println("Update successfull"); + // You can uncomment this and build again + // Serial.println("Update successful"); - //first init and check SD card - if (!SD.begin()) { - rebootEspWithReason("Card Mount Failed"); - } + //first init and check SD card + if (!SD.begin()) { + rebootEspWithReason("Card Mount Failed"); + } - cardType = SD.cardType(); + cardType = SD.cardType(); - if (cardType == CARD_NONE) { - rebootEspWithReason("No SD_MMC card attached"); - }else{ - updateFromFS(SD); + if (cardType == CARD_NONE) { + rebootEspWithReason("No SD_MMC card attached"); + } else { + updateFromFS(SD); } } -void rebootEspWithReason(String reason){ - Serial.println(reason); - delay(1000); - ESP.restart(); +void rebootEspWithReason(String reason) { + Serial.println(reason); + delay(1000); + ESP.restart(); } //will not be reached void loop() { - -} \ No newline at end of file +} diff --git a/libraries/Update/keywords.txt b/libraries/Update/keywords.txt index 95dd92591c8..53544dbaf6c 100644 --- a/libraries/Update/keywords.txt +++ b/libraries/Update/keywords.txt @@ -21,4 +21,3 @@ printError KEYWORD2 ####################################### # Constants (LITERAL1) ####################################### - diff --git a/libraries/Update/src/HttpsOTAUpdate.cpp b/libraries/Update/src/HttpsOTAUpdate.cpp index 07133fd403b..9cc700a8cc8 100644 --- a/libraries/Update/src/HttpsOTAUpdate.cpp +++ b/libraries/Update/src/HttpsOTAUpdate.cpp @@ -20,11 +20,11 @@ #include "HttpsOTAUpdate.h" #define OTA_TASK_STACK_SIZE 9216 -typedef void (*HttpEventCb)(HttpEvent_t*); +typedef void (*HttpEventCb)(HttpEvent_t *); -static esp_http_client_config_t config; +static esp_http_client_config_t config; static HttpEventCb cb; -static EventGroupHandle_t ota_status = NULL;//check for ota status +static EventGroupHandle_t ota_status = NULL; //check for ota status static EventBits_t set_bit; const int OTA_IDLE_BIT = BIT0; @@ -32,83 +32,78 @@ const int OTA_UPDATING_BIT = BIT1; const int OTA_SUCCESS_BIT = BIT2; const int OTA_FAIL_BIT = BIT3; -esp_err_t http_event_handler(esp_http_client_event_t *event) -{ - cb(event); - return ESP_OK; +esp_err_t http_event_handler(esp_http_client_event_t *event) { + cb(event); + return ESP_OK; } -void https_ota_task(void *param) -{ - if(ota_status) { - xEventGroupSetBits(ota_status, OTA_UPDATING_BIT); - xEventGroupClearBits(ota_status, OTA_IDLE_BIT); +void https_ota_task(void *param) { + if (ota_status) { + xEventGroupSetBits(ota_status, OTA_UPDATING_BIT); + xEventGroupClearBits(ota_status, OTA_IDLE_BIT); + } + esp_https_ota_config_t cfg; + cfg.http_config = (const esp_http_client_config_t *)param; + cfg.http_client_init_cb = NULL; + cfg.bulk_flash_erase = false; //Erase entire flash partition during initialization + cfg.partial_http_download = false; //Enable Firmware image to be downloaded over multiple HTTP requests + cfg.max_http_request_size = 0; //Maximum request size for partial HTTP download + + esp_err_t ret = esp_https_ota((const esp_https_ota_config_t *)&cfg); + if (ret == ESP_OK) { + if (ota_status) { + xEventGroupClearBits(ota_status, OTA_UPDATING_BIT); + xEventGroupSetBits(ota_status, OTA_SUCCESS_BIT); } - esp_https_ota_config_t cfg; - cfg.http_config = (const esp_http_client_config_t *)param; - cfg.http_client_init_cb = NULL; - cfg.bulk_flash_erase = false; //Erase entire flash partition during initialization - cfg.partial_http_download = false; //Enable Firmware image to be downloaded over multiple HTTP requests - cfg.max_http_request_size = 0; //Maximum request size for partial HTTP download - - esp_err_t ret = esp_https_ota((const esp_https_ota_config_t *)&cfg); - if(ret == ESP_OK) { - if(ota_status) { - xEventGroupClearBits(ota_status, OTA_UPDATING_BIT); - xEventGroupSetBits(ota_status, OTA_SUCCESS_BIT); - } - } else { - if(ota_status) { - xEventGroupClearBits(ota_status, OTA_UPDATING_BIT); - xEventGroupSetBits(ota_status, OTA_FAIL_BIT); - } + } else { + if (ota_status) { + xEventGroupClearBits(ota_status, OTA_UPDATING_BIT); + xEventGroupSetBits(ota_status, OTA_FAIL_BIT); } - vTaskDelete(NULL); + } + vTaskDelete(NULL); } -HttpsOTAStatus_t HttpsOTAUpdateClass::status() -{ - if(ota_status) { - set_bit = xEventGroupGetBits(ota_status); - if(set_bit == OTA_IDLE_BIT) { - return HTTPS_OTA_IDLE; - } - if(set_bit == OTA_UPDATING_BIT) { - return HTTPS_OTA_UPDATING; - } - if(set_bit == OTA_SUCCESS_BIT) { - return HTTPS_OTA_SUCCESS; - } - if(set_bit == OTA_FAIL_BIT) { - return HTTPS_OTA_FAIL; - } +HttpsOTAStatus_t HttpsOTAUpdateClass::status() { + if (ota_status) { + set_bit = xEventGroupGetBits(ota_status); + if (set_bit == OTA_IDLE_BIT) { + return HTTPS_OTA_IDLE; } - return HTTPS_OTA_ERR; + if (set_bit == OTA_UPDATING_BIT) { + return HTTPS_OTA_UPDATING; + } + if (set_bit == OTA_SUCCESS_BIT) { + return HTTPS_OTA_SUCCESS; + } + if (set_bit == OTA_FAIL_BIT) { + return HTTPS_OTA_FAIL; + } + } + return HTTPS_OTA_ERR; } -void HttpsOTAUpdateClass::onHttpEvent(HttpEventCb cbEvent) -{ - cb = cbEvent; +void HttpsOTAUpdateClass::onHttpEvent(HttpEventCb cbEvent) { + cb = cbEvent; } -void HttpsOTAUpdateClass::begin(const char *url, const char *cert_pem, bool skip_cert_common_name_check) -{ - config.url = url; - config.cert_pem = cert_pem; - config.skip_cert_common_name_check = skip_cert_common_name_check; - config.event_handler = http_event_handler; - - if(!ota_status) { - ota_status = xEventGroupCreate(); - if(!ota_status) { - log_e("OTA Event Group Create Failed"); - } - xEventGroupSetBits(ota_status, OTA_IDLE_BIT); - } - - if (xTaskCreate(&https_ota_task, "https_ota_task", OTA_TASK_STACK_SIZE, &config, 5, NULL) != pdPASS) { - log_e("Couldn't create ota task\n"); +void HttpsOTAUpdateClass::begin(const char *url, const char *cert_pem, bool skip_cert_common_name_check) { + config.url = url; + config.cert_pem = cert_pem; + config.skip_cert_common_name_check = skip_cert_common_name_check; + config.event_handler = http_event_handler; + + if (!ota_status) { + ota_status = xEventGroupCreate(); + if (!ota_status) { + log_e("OTA Event Group Create Failed"); } + xEventGroupSetBits(ota_status, OTA_IDLE_BIT); + } + + if (xTaskCreate(&https_ota_task, "https_ota_task", OTA_TASK_STACK_SIZE, &config, 5, NULL) != pdPASS) { + log_e("Couldn't create ota task\n"); + } } HttpsOTAUpdateClass HttpsOTA; diff --git a/libraries/Update/src/HttpsOTAUpdate.h b/libraries/Update/src/HttpsOTAUpdate.h index 74eb81a3fec..d470ad50722 100644 --- a/libraries/Update/src/HttpsOTAUpdate.h +++ b/libraries/Update/src/HttpsOTAUpdate.h @@ -11,21 +11,20 @@ #include "esp_http_client.h" #define HttpEvent_t esp_http_client_event_t -typedef enum -{ - HTTPS_OTA_IDLE, - HTTPS_OTA_UPDATING, - HTTPS_OTA_SUCCESS, - HTTPS_OTA_FAIL, - HTTPS_OTA_ERR -}HttpsOTAStatus_t; +typedef enum { + HTTPS_OTA_IDLE, + HTTPS_OTA_UPDATING, + HTTPS_OTA_SUCCESS, + HTTPS_OTA_FAIL, + HTTPS_OTA_ERR +} HttpsOTAStatus_t; class HttpsOTAUpdateClass { - public: - void begin(const char *url, const char *cert_pem, bool skip_cert_common_name_check = true); - void onHttpEvent(void (*http_event_cb_t)(HttpEvent_t *)); - HttpsOTAStatus_t status(); +public: + void begin(const char *url, const char *cert_pem, bool skip_cert_common_name_check = true); + void onHttpEvent(void (*http_event_cb_t)(HttpEvent_t *)); + HttpsOTAStatus_t status(); }; extern HttpsOTAUpdateClass HttpsOTA; diff --git a/libraries/Update/src/Update.h b/libraries/Update/src/Update.h index 339bea4a40e..97bd99148e9 100644 --- a/libraries/Update/src/Update.h +++ b/libraries/Update/src/Update.h @@ -12,82 +12,82 @@ #include #include "esp_partition.h" -#define UPDATE_ERROR_OK (0) -#define UPDATE_ERROR_WRITE (1) -#define UPDATE_ERROR_ERASE (2) -#define UPDATE_ERROR_READ (3) -#define UPDATE_ERROR_SPACE (4) -#define UPDATE_ERROR_SIZE (5) -#define UPDATE_ERROR_STREAM (6) -#define UPDATE_ERROR_MD5 (7) -#define UPDATE_ERROR_MAGIC_BYTE (8) -#define UPDATE_ERROR_ACTIVATE (9) -#define UPDATE_ERROR_NO_PARTITION (10) -#define UPDATE_ERROR_BAD_ARGUMENT (11) -#define UPDATE_ERROR_ABORT (12) -#define UPDATE_ERROR_DECRYPT (13) +#define UPDATE_ERROR_OK (0) +#define UPDATE_ERROR_WRITE (1) +#define UPDATE_ERROR_ERASE (2) +#define UPDATE_ERROR_READ (3) +#define UPDATE_ERROR_SPACE (4) +#define UPDATE_ERROR_SIZE (5) +#define UPDATE_ERROR_STREAM (6) +#define UPDATE_ERROR_MD5 (7) +#define UPDATE_ERROR_MAGIC_BYTE (8) +#define UPDATE_ERROR_ACTIVATE (9) +#define UPDATE_ERROR_NO_PARTITION (10) +#define UPDATE_ERROR_BAD_ARGUMENT (11) +#define UPDATE_ERROR_ABORT (12) +#define UPDATE_ERROR_DECRYPT (13) #define UPDATE_SIZE_UNKNOWN 0xFFFFFFFF -#define U_FLASH 0 -#define U_SPIFFS 100 -#define U_AUTH 200 +#define U_FLASH 0 +#define U_SPIFFS 100 +#define U_AUTH 200 -#define ENCRYPTED_BLOCK_SIZE 16 +#define ENCRYPTED_BLOCK_SIZE 16 #define ENCRYPTED_TWEAK_BLOCK_SIZE 32 -#define ENCRYPTED_KEY_SIZE 32 +#define ENCRYPTED_KEY_SIZE 32 -#define U_AES_DECRYPT_NONE 0 -#define U_AES_DECRYPT_AUTO 1 -#define U_AES_DECRYPT_ON 2 -#define U_AES_DECRYPT_MODE_MASK 3 +#define U_AES_DECRYPT_NONE 0 +#define U_AES_DECRYPT_AUTO 1 +#define U_AES_DECRYPT_ON 2 +#define U_AES_DECRYPT_MODE_MASK 3 #define U_AES_IMAGE_DECRYPTING_BIT 4 -#define SPI_SECTORS_PER_BLOCK 16 // usually large erase block is 32k/64k -#define SPI_FLASH_BLOCK_SIZE (SPI_SECTORS_PER_BLOCK*SPI_FLASH_SEC_SIZE) +#define SPI_SECTORS_PER_BLOCK 16 // usually large erase block is 32k/64k +#define SPI_FLASH_BLOCK_SIZE (SPI_SECTORS_PER_BLOCK * SPI_FLASH_SEC_SIZE) class UpdateClass { - public: - typedef std::function THandlerFunction_Progress; +public: + typedef std::function THandlerFunction_Progress; - UpdateClass(); + UpdateClass(); - /* + /* This callback will be called when Update is receiving data */ - UpdateClass& onProgress(THandlerFunction_Progress fn); + UpdateClass &onProgress(THandlerFunction_Progress fn); - /* + /* Call this to check the space needed for the update Will return false if there is not enough space */ - bool begin(size_t size=UPDATE_SIZE_UNKNOWN, int command = U_FLASH, int ledPin = -1, uint8_t ledOn = LOW, const char *label = NULL); + bool begin(size_t size = UPDATE_SIZE_UNKNOWN, int command = U_FLASH, int ledPin = -1, uint8_t ledOn = LOW, const char *label = NULL); - /* + /* Setup decryption configuration Crypt Key is 32bytes(256bits) block of data, use the same key as used to encrypt image file Crypt Address, use the same value as used to encrypt image file Crypt Config, use the same value as used to encrypt image file Crypt Mode, used to select if image files should be decrypted or not */ - bool setupCrypt(const uint8_t *cryptKey=0, size_t cryptAddress=0, uint8_t cryptConfig=0xf, int cryptMode=U_AES_DECRYPT_AUTO); + bool setupCrypt(const uint8_t *cryptKey = 0, size_t cryptAddress = 0, uint8_t cryptConfig = 0xf, int cryptMode = U_AES_DECRYPT_AUTO); - /* + /* Writes a buffer to the flash and increments the address Returns the amount written */ - size_t write(uint8_t *data, size_t len); + size_t write(uint8_t *data, size_t len); - /* + /* Writes the remaining bytes from the Stream to the flash Uses readBytes() and sets UPDATE_ERROR_STREAM on timeout Returns the bytes written Should be equal to the remaining bytes when called Usable for slow streams like Serial */ - size_t writeStream(Stream &data); + size_t writeStream(Stream &data); - /* + /* If all bytes are written this call will write the config to eboot and return true @@ -95,151 +95,175 @@ class UpdateClass { or there is an error this will clear everything and return false the last error is available through getError() - evenIfRemaining is helpfull when you update without knowing the final size first + evenIfRemaining is helpful when you update without knowing the final size first */ - bool end(bool evenIfRemaining = false); + bool end(bool evenIfRemaining = false); - /* + /* sets AES256 key(32 bytes) used for decrypting image file */ - bool setCryptKey(const uint8_t *cryptKey); + bool setCryptKey(const uint8_t *cryptKey); - /* + /* sets crypt mode used on image files */ - bool setCryptMode(const int cryptMode); + bool setCryptMode(const int cryptMode); - /* + /* sets address used for decrypting image file */ - void setCryptAddress(const size_t cryptAddress){ _cryptAddress = cryptAddress & 0x00fffff0; } + void setCryptAddress(const size_t cryptAddress) { + _cryptAddress = cryptAddress & 0x00fffff0; + } - /* + /* sets crypt config used for decrypting image file */ - void setCryptConfig(const uint8_t cryptConfig){ _cryptCfg = cryptConfig & 0x0f; } + void setCryptConfig(const uint8_t cryptConfig) { + _cryptCfg = cryptConfig & 0x0f; + } - /* + /* Aborts the running update */ - void abort(); + void abort(); - /* + /* Prints the last error to an output stream */ - void printError(Print &out); + void printError(Print &out); - const char * errorString(); + const char *errorString(); - /* + /* sets the expected MD5 for the firmware (hexString) */ - bool setMD5(const char * expected_md5); + bool setMD5(const char *expected_md5); - /* + /* returns the MD5 String of the successfully ended firmware */ - String md5String(void){ return _md5.toString(); } + String md5String(void) { + return _md5.toString(); + } - /* + /* populated the result with the md5 bytes of the successfully ended firmware */ - void md5(uint8_t * result){ return _md5.getBytes(result); } - - //Helpers - uint8_t getError(){ return _error; } - void clearError(){ _error = UPDATE_ERROR_OK; } - bool hasError(){ return _error != UPDATE_ERROR_OK; } - bool isRunning(){ return _size > 0; } - bool isFinished(){ return _progress == _size; } - size_t size(){ return _size; } - size_t progress(){ return _progress; } - size_t remaining(){ return _size - _progress; } - - /* + void md5(uint8_t *result) { + return _md5.getBytes(result); + } + + //Helpers + uint8_t getError() { + return _error; + } + void clearError() { + _error = UPDATE_ERROR_OK; + } + bool hasError() { + return _error != UPDATE_ERROR_OK; + } + bool isRunning() { + return _size > 0; + } + bool isFinished() { + return _progress == _size; + } + size_t size() { + return _size; + } + size_t progress() { + return _progress; + } + size_t remaining() { + return _size - _progress; + } + + /* Template to write from objects that expose available() and read(uint8_t*, size_t) methods faster than the writeStream method writes only what is available */ - template - size_t write(T &data){ - size_t written = 0; - if (hasError() || !isRunning()) - return 0; - - size_t available = data.available(); - while(available) { - if(_bufferLen + available > remaining()){ - available = remaining() - _bufferLen; - } - if(_bufferLen + available > 4096) { - size_t toBuff = 4096 - _bufferLen; - data.read(_buffer + _bufferLen, toBuff); - _bufferLen += toBuff; - if(!_writeBuffer()) + template + size_t write(T &data) { + size_t written = 0; + if (hasError() || !isRunning()) + return 0; + + size_t available = data.available(); + while (available) { + if (_bufferLen + available > remaining()) { + available = remaining() - _bufferLen; + } + if (_bufferLen + available > 4096) { + size_t toBuff = 4096 - _bufferLen; + data.read(_buffer + _bufferLen, toBuff); + _bufferLen += toBuff; + if (!_writeBuffer()) + return written; + written += toBuff; + } else { + data.read(_buffer + _bufferLen, available); + _bufferLen += available; + written += available; + if (_bufferLen == remaining()) { + if (!_writeBuffer()) { return written; - written += toBuff; - } else { - data.read(_buffer + _bufferLen, available); - _bufferLen += available; - written += available; - if(_bufferLen == remaining()) { - if(!_writeBuffer()) { - return written; - } } } - if(remaining() == 0) - return written; - available = data.available(); } - return written; + if (remaining() == 0) + return written; + available = data.available(); } + return written; + } - /* + /* check if there is a firmware on the other OTA partition that you can bootinto */ - bool canRollBack(); - /* + bool canRollBack(); + /* set the other OTA partition as bootable (reboot to enable) */ - bool rollBack(); - - private: - void _reset(); - void _abort(uint8_t err); - void _cryptKeyTweak(size_t cryptAddress, uint8_t *tweaked_key); - bool _decryptBuffer(); - bool _writeBuffer(); - bool _verifyHeader(uint8_t data); - bool _verifyEnd(); - bool _enablePartition(const esp_partition_t* partition); - bool _chkDataInBlock(const uint8_t *data, size_t len) const; // check if block contains any data or is empty - - - uint8_t _error; - uint8_t *_cryptKey; - uint8_t *_cryptBuffer; - uint8_t *_buffer; - uint8_t *_skipBuffer; - size_t _bufferLen; - size_t _size; - THandlerFunction_Progress _progress_callback; - uint32_t _progress; - uint32_t _paroffset; - uint32_t _command; - const esp_partition_t* _partition; - - String _target_md5; - MD5Builder _md5; - - int _ledPin; - uint8_t _ledOn; - - uint8_t _cryptMode; - size_t _cryptAddress; - uint8_t _cryptCfg; + bool rollBack(); + +private: + void _reset(); + void _abort(uint8_t err); + void _cryptKeyTweak(size_t cryptAddress, uint8_t *tweaked_key); + bool _decryptBuffer(); + bool _writeBuffer(); + bool _verifyHeader(uint8_t data); + bool _verifyEnd(); + bool _enablePartition(const esp_partition_t *partition); + bool _chkDataInBlock(const uint8_t *data, size_t len) const; // check if block contains any data or is empty + + + uint8_t _error; + uint8_t *_cryptKey; + uint8_t *_cryptBuffer; + uint8_t *_buffer; + uint8_t *_skipBuffer; + size_t _bufferLen; + size_t _size; + THandlerFunction_Progress _progress_callback; + uint32_t _progress; + uint32_t _paroffset; + uint32_t _command; + const esp_partition_t *_partition; + + String _target_md5; + MD5Builder _md5; + + int _ledPin; + uint8_t _ledOn; + + uint8_t _cryptMode; + size_t _cryptAddress; + uint8_t _cryptCfg; }; #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_UPDATE) diff --git a/libraries/Update/src/Updater.cpp b/libraries/Update/src/Updater.cpp index 8017d1d3c1b..3ca17942c35 100644 --- a/libraries/Update/src/Updater.cpp +++ b/libraries/Update/src/Updater.cpp @@ -11,598 +11,579 @@ #include "esp_image_format.h" #include "mbedtls/aes.h" -static const char * _err2str(uint8_t _error){ - if(_error == UPDATE_ERROR_OK){ - return ("No Error"); - } else if(_error == UPDATE_ERROR_WRITE){ - return ("Flash Write Failed"); - } else if(_error == UPDATE_ERROR_ERASE){ - return ("Flash Erase Failed"); - } else if(_error == UPDATE_ERROR_READ){ - return ("Flash Read Failed"); - } else if(_error == UPDATE_ERROR_SPACE){ - return ("Not Enough Space"); - } else if(_error == UPDATE_ERROR_SIZE){ - return ("Bad Size Given"); - } else if(_error == UPDATE_ERROR_STREAM){ - return ("Stream Read Timeout"); - } else if(_error == UPDATE_ERROR_MD5){ - return ("MD5 Check Failed"); - } else if(_error == UPDATE_ERROR_MAGIC_BYTE){ - return ("Wrong Magic Byte"); - } else if(_error == UPDATE_ERROR_ACTIVATE){ - return ("Could Not Activate The Firmware"); - } else if(_error == UPDATE_ERROR_NO_PARTITION){ - return ("Partition Could Not be Found"); - } else if(_error == UPDATE_ERROR_BAD_ARGUMENT){ - return ("Bad Argument"); - } else if(_error == UPDATE_ERROR_ABORT){ - return ("Aborted"); - } else if(_error == UPDATE_ERROR_DECRYPT){ - return ("Decryption error"); - } - return ("UNKNOWN"); +static const char *_err2str(uint8_t _error) { + if (_error == UPDATE_ERROR_OK) { + return ("No Error"); + } else if (_error == UPDATE_ERROR_WRITE) { + return ("Flash Write Failed"); + } else if (_error == UPDATE_ERROR_ERASE) { + return ("Flash Erase Failed"); + } else if (_error == UPDATE_ERROR_READ) { + return ("Flash Read Failed"); + } else if (_error == UPDATE_ERROR_SPACE) { + return ("Not Enough Space"); + } else if (_error == UPDATE_ERROR_SIZE) { + return ("Bad Size Given"); + } else if (_error == UPDATE_ERROR_STREAM) { + return ("Stream Read Timeout"); + } else if (_error == UPDATE_ERROR_MD5) { + return ("MD5 Check Failed"); + } else if (_error == UPDATE_ERROR_MAGIC_BYTE) { + return ("Wrong Magic Byte"); + } else if (_error == UPDATE_ERROR_ACTIVATE) { + return ("Could Not Activate The Firmware"); + } else if (_error == UPDATE_ERROR_NO_PARTITION) { + return ("Partition Could Not be Found"); + } else if (_error == UPDATE_ERROR_BAD_ARGUMENT) { + return ("Bad Argument"); + } else if (_error == UPDATE_ERROR_ABORT) { + return ("Aborted"); + } else if (_error == UPDATE_ERROR_DECRYPT) { + return ("Decryption error"); + } + return ("UNKNOWN"); } -static bool _partitionIsBootable(const esp_partition_t* partition){ - uint8_t buf[ENCRYPTED_BLOCK_SIZE]; - if(!partition){ - return false; - } - if(!ESP.partitionRead(partition, 0, (uint32_t*)buf, ENCRYPTED_BLOCK_SIZE)) { - return false; - } +static bool _partitionIsBootable(const esp_partition_t *partition) { + uint8_t buf[ENCRYPTED_BLOCK_SIZE]; + if (!partition) { + return false; + } + if (!ESP.partitionRead(partition, 0, (uint32_t *)buf, ENCRYPTED_BLOCK_SIZE)) { + return false; + } - if(buf[0] != ESP_IMAGE_HEADER_MAGIC) { - return false; - } - return true; + if (buf[0] != ESP_IMAGE_HEADER_MAGIC) { + return false; + } + return true; } -bool UpdateClass::_enablePartition(const esp_partition_t* partition){ - if(!partition){ - return false; - } - return ESP.partitionWrite(partition, 0, (uint32_t*) _skipBuffer, ENCRYPTED_BLOCK_SIZE); +bool UpdateClass::_enablePartition(const esp_partition_t *partition) { + if (!partition) { + return false; + } + return ESP.partitionWrite(partition, 0, (uint32_t *)_skipBuffer, ENCRYPTED_BLOCK_SIZE); } UpdateClass::UpdateClass() -: _error(0) -, _cryptKey(0) -, _cryptBuffer(0) -, _buffer(0) -, _skipBuffer(0) -, _bufferLen(0) -, _size(0) -, _progress_callback(NULL) -, _progress(0) -, _paroffset(0) -, _command(U_FLASH) -, _partition(NULL) -, _cryptMode(U_AES_DECRYPT_AUTO) -, _cryptAddress(0) -, _cryptCfg(0xf) -{ + : _error(0), _cryptKey(0), _cryptBuffer(0), _buffer(0), _skipBuffer(0), _bufferLen(0), _size(0), _progress_callback(NULL), _progress(0), _paroffset(0), _command(U_FLASH), _partition(NULL), _cryptMode(U_AES_DECRYPT_AUTO), _cryptAddress(0), _cryptCfg(0xf) { } -UpdateClass& UpdateClass::onProgress(THandlerFunction_Progress fn) { - _progress_callback = fn; - return *this; +UpdateClass &UpdateClass::onProgress(THandlerFunction_Progress fn) { + _progress_callback = fn; + return *this; } void UpdateClass::_reset() { - if (_buffer) { - delete[] _buffer; - } - if (_skipBuffer) { - delete[] _skipBuffer; - } - - _cryptBuffer = nullptr; - _buffer = nullptr; - _skipBuffer = nullptr; - _bufferLen = 0; - _progress = 0; - _size = 0; - _command = U_FLASH; - - if(_ledPin != -1) { - digitalWrite(_ledPin, !_ledOn); // off - } + if (_buffer) { + delete[] _buffer; + } + if (_skipBuffer) { + delete[] _skipBuffer; + } + + _cryptBuffer = nullptr; + _buffer = nullptr; + _skipBuffer = nullptr; + _bufferLen = 0; + _progress = 0; + _size = 0; + _command = U_FLASH; + + if (_ledPin != -1) { + digitalWrite(_ledPin, !_ledOn); // off + } } -bool UpdateClass::canRollBack(){ - if(_buffer){ //Update is running - return false; - } - const esp_partition_t* partition = esp_ota_get_next_update_partition(NULL); - return _partitionIsBootable(partition); +bool UpdateClass::canRollBack() { + if (_buffer) { //Update is running + return false; + } + const esp_partition_t *partition = esp_ota_get_next_update_partition(NULL); + return _partitionIsBootable(partition); } -bool UpdateClass::rollBack(){ - if(_buffer){ //Update is running - return false; - } - const esp_partition_t* partition = esp_ota_get_next_update_partition(NULL); - return _partitionIsBootable(partition) && !esp_ota_set_boot_partition(partition); +bool UpdateClass::rollBack() { + if (_buffer) { //Update is running + return false; + } + const esp_partition_t *partition = esp_ota_get_next_update_partition(NULL); + return _partitionIsBootable(partition) && !esp_ota_set_boot_partition(partition); } bool UpdateClass::begin(size_t size, int command, int ledPin, uint8_t ledOn, const char *label) { - if(_size > 0){ - log_w("already running"); - return false; - } + if (_size > 0) { + log_w("already running"); + return false; + } - _ledPin = ledPin; - _ledOn = !!ledOn; // 0(LOW) or 1(HIGH) + _ledPin = ledPin; + _ledOn = !!ledOn; // 0(LOW) or 1(HIGH) - _reset(); - _error = 0; - _target_md5 = emptyString; - _md5 = MD5Builder(); + _reset(); + _error = 0; + _target_md5 = emptyString; + _md5 = MD5Builder(); - if(size == 0) { - _error = UPDATE_ERROR_SIZE; - return false; - } + if (size == 0) { + _error = UPDATE_ERROR_SIZE; + return false; + } - if (command == U_FLASH) { - _partition = esp_ota_get_next_update_partition(NULL); - if(!_partition){ - _error = UPDATE_ERROR_NO_PARTITION; - return false; - } - log_d("OTA Partition: %s", _partition->label); - } - else if (command == U_SPIFFS) { - _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, label); - _paroffset = 0; - if(!_partition){ - _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL); - _paroffset = 0x1000; //Offset for ffat, assuming size is already corrected - if(!_partition){ - _error = UPDATE_ERROR_NO_PARTITION; - return false; - } - } + if (command == U_FLASH) { + _partition = esp_ota_get_next_update_partition(NULL); + if (!_partition) { + _error = UPDATE_ERROR_NO_PARTITION; + return false; } - else { - _error = UPDATE_ERROR_BAD_ARGUMENT; - log_e("bad command %u", command); + log_d("OTA Partition: %s", _partition->label); + } else if (command == U_SPIFFS) { + _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, label); + _paroffset = 0; + if (!_partition) { + _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL); + _paroffset = 0x1000; //Offset for ffat, assuming size is already corrected + if (!_partition) { + _error = UPDATE_ERROR_NO_PARTITION; return false; + } } + } else { + _error = UPDATE_ERROR_BAD_ARGUMENT; + log_e("bad command %u", command); + return false; + } - if(size == UPDATE_SIZE_UNKNOWN){ - size = _partition->size; - } else if(size > _partition->size){ - _error = UPDATE_ERROR_SIZE; - log_e("too large %u > %u", size, _partition->size); - return false; - } + if (size == UPDATE_SIZE_UNKNOWN) { + size = _partition->size; + } else if (size > _partition->size) { + _error = UPDATE_ERROR_SIZE; + log_e("too large %u > %u", size, _partition->size); + return false; + } - //initialize - _buffer = new (std::nothrow) uint8_t[SPI_FLASH_SEC_SIZE]; - if (!_buffer) { - log_e("_buffer allocation failed"); - return false; - } - _size = size; - _command = command; - _md5.begin(); - return true; + //initialize + _buffer = new (std::nothrow) uint8_t[SPI_FLASH_SEC_SIZE]; + if (!_buffer) { + log_e("_buffer allocation failed"); + return false; + } + _size = size; + _command = command; + _md5.begin(); + return true; } -bool UpdateClass::setupCrypt(const uint8_t *cryptKey, size_t cryptAddress, uint8_t cryptConfig, int cryptMode){ - if(setCryptKey(cryptKey)){ - if(setCryptMode(cryptMode)){ - setCryptAddress(cryptAddress); - setCryptConfig(cryptConfig); - return true; - } +bool UpdateClass::setupCrypt(const uint8_t *cryptKey, size_t cryptAddress, uint8_t cryptConfig, int cryptMode) { + if (setCryptKey(cryptKey)) { + if (setCryptMode(cryptMode)) { + setCryptAddress(cryptAddress); + setCryptConfig(cryptConfig); + return true; } - return false; + } + return false; } -bool UpdateClass::setCryptKey(const uint8_t *cryptKey){ - if(!cryptKey){ - if (_cryptKey){ - delete[] _cryptKey; - _cryptKey = 0; - log_d("AES key unset"); - } - return false; //key cleared, no key to decrypt with - } - //initialize - if(!_cryptKey){ - _cryptKey = new (std::nothrow) uint8_t[ENCRYPTED_KEY_SIZE]; - } - if(!_cryptKey){ - log_e("new failed"); - return false; - } - memcpy(_cryptKey, cryptKey, ENCRYPTED_KEY_SIZE); - return true; +bool UpdateClass::setCryptKey(const uint8_t *cryptKey) { + if (!cryptKey) { + if (_cryptKey) { + delete[] _cryptKey; + _cryptKey = 0; + log_d("AES key unset"); + } + return false; //key cleared, no key to decrypt with + } + //initialize + if (!_cryptKey) { + _cryptKey = new (std::nothrow) uint8_t[ENCRYPTED_KEY_SIZE]; + } + if (!_cryptKey) { + log_e("new failed"); + return false; + } + memcpy(_cryptKey, cryptKey, ENCRYPTED_KEY_SIZE); + return true; } -bool UpdateClass::setCryptMode(const int cryptMode){ - if(cryptMode >= U_AES_DECRYPT_NONE && cryptMode <= U_AES_DECRYPT_ON){ - _cryptMode = cryptMode; - }else{ - log_e("bad crypt mode argument %i", cryptMode); - return false; - } - return true; +bool UpdateClass::setCryptMode(const int cryptMode) { + if (cryptMode >= U_AES_DECRYPT_NONE && cryptMode <= U_AES_DECRYPT_ON) { + _cryptMode = cryptMode; + } else { + log_e("bad crypt mode argument %i", cryptMode); + return false; + } + return true; } -void UpdateClass::_abort(uint8_t err){ - _reset(); - _error = err; +void UpdateClass::_abort(uint8_t err) { + _reset(); + _error = err; } -void UpdateClass::abort(){ - _abort(UPDATE_ERROR_ABORT); +void UpdateClass::abort() { + _abort(UPDATE_ERROR_ABORT); } -void UpdateClass::_cryptKeyTweak(size_t cryptAddress, uint8_t *tweaked_key){ - memcpy(tweaked_key, _cryptKey, ENCRYPTED_KEY_SIZE ); - if(_cryptCfg == 0) return; //no tweaking needed, use crypt key as-is - - const uint8_t pattern[] = { 23, 23, 23, 14, 23, 23, 23, 12, 23, 23, 23, 10, 23, 23, 23, 8 }; - int pattern_idx = 0; - int key_idx = 0; - int bit_len = 0; - uint32_t tweak = 0; - cryptAddress &= 0x00ffffe0; //bit 23-5 - cryptAddress <<= 8; //bit23 shifted to bit31(MSB) - while(pattern_idx < sizeof(pattern)){ - tweak = cryptAddress<<(23 - pattern[pattern_idx]); //bit shift for small patterns - // alternative to: tweak = rotl32(tweak,8 - bit_len); - tweak = (tweak<<(8 - bit_len)) | (tweak>>(24 + bit_len)); //rotate to line up with end of previous tweak bits - bit_len += pattern[pattern_idx++] - 4; //add number of bits in next pattern(23-4 = 19bits = 23bit to 5bit) - while(bit_len > 7){ - tweaked_key[key_idx++] ^= tweak; //XOR byte - // alternative to: tweak = rotl32(tweak, 8); - tweak = (tweak<<8) | (tweak>>24); //compiler should optimize to use rotate(fast) - bit_len -=8; +void UpdateClass::_cryptKeyTweak(size_t cryptAddress, uint8_t *tweaked_key) { + memcpy(tweaked_key, _cryptKey, ENCRYPTED_KEY_SIZE); + if (_cryptCfg == 0) return; //no tweaking needed, use crypt key as-is + + const uint8_t pattern[] = { 23, 23, 23, 14, 23, 23, 23, 12, 23, 23, 23, 10, 23, 23, 23, 8 }; + int pattern_idx = 0; + int key_idx = 0; + int bit_len = 0; + uint32_t tweak = 0; + cryptAddress &= 0x00ffffe0; //bit 23-5 + cryptAddress <<= 8; //bit23 shifted to bit31(MSB) + while (pattern_idx < sizeof(pattern)) { + tweak = cryptAddress << (23 - pattern[pattern_idx]); //bit shift for small patterns + // alternative to: tweak = rotl32(tweak,8 - bit_len); + tweak = (tweak << (8 - bit_len)) | (tweak >> (24 + bit_len)); //rotate to line up with end of previous tweak bits + bit_len += pattern[pattern_idx++] - 4; //add number of bits in next pattern(23-4 = 19bits = 23bit to 5bit) + while (bit_len > 7) { + tweaked_key[key_idx++] ^= tweak; //XOR byte + // alternative to: tweak = rotl32(tweak, 8); + tweak = (tweak << 8) | (tweak >> 24); //compiler should optimize to use rotate(fast) + bit_len -= 8; + } + tweaked_key[key_idx] ^= tweak; //XOR remaining bits, will XOR zeros if no remaining bits + } + if (_cryptCfg == 0xf) return; //return with fully tweaked key + + //some of tweaked key bits need to be restore back to crypt key bits + const uint8_t cfg_bits[] = { 67, 65, 63, 61 }; + key_idx = 0; + pattern_idx = 0; + while (key_idx < ENCRYPTED_KEY_SIZE) { + bit_len += cfg_bits[pattern_idx]; + if ((_cryptCfg & (1 << pattern_idx)) == 0) { //restore crypt key bits + while (bit_len > 0) { + if (bit_len > 7 || ((_cryptCfg & (2 << pattern_idx)) == 0)) { //restore a crypt key byte + tweaked_key[key_idx] = _cryptKey[key_idx]; + } else { //MSBits restore crypt key bits, LSBits keep as tweaked bits + tweaked_key[key_idx] &= (0xff >> bit_len); + tweaked_key[key_idx] |= (_cryptKey[key_idx] & (~(0xff >> bit_len))); } - tweaked_key[key_idx] ^= tweak; //XOR remaining bits, will XOR zeros if no remaining bits - } - if(_cryptCfg == 0xf) return; //return with fully tweaked key - - //some of tweaked key bits need to be restore back to crypt key bits - const uint8_t cfg_bits[] = { 67, 65, 63, 61 }; - key_idx = 0; - pattern_idx = 0; - while(key_idx < ENCRYPTED_KEY_SIZE){ - bit_len += cfg_bits[pattern_idx]; - if( (_cryptCfg & (1< 0){ - if( bit_len > 7 || ((_cryptCfg & (2<>bit_len); - tweaked_key[key_idx] |= (_cryptKey[key_idx] & (~(0xff>>bit_len)) ); - } - key_idx++; - bit_len -= 8; - } - }else{ //keep tweaked key bits - while(bit_len > 0){ - if( bit_len <8 && ((_cryptCfg & (2<>bit_len)); - tweaked_key[key_idx] |= (_cryptKey[key_idx] & (0xff>>bit_len)); - } - key_idx++; - bit_len -= 8; - } + key_idx++; + bit_len -= 8; + } + } else { //keep tweaked key bits + while (bit_len > 0) { + if (bit_len < 8 && ((_cryptCfg & (2 << pattern_idx)) == 0)) { //MSBits keep as tweaked bits, LSBits restore crypt key bits + tweaked_key[key_idx] &= (~(0xff >> bit_len)); + tweaked_key[key_idx] |= (_cryptKey[key_idx] & (0xff >> bit_len)); } - pattern_idx++; + key_idx++; + bit_len -= 8; + } } + pattern_idx++; + } } -bool UpdateClass::_decryptBuffer(){ - if(!_cryptKey){ - log_w("AES key not set"); - return false; - } - if(_bufferLen%ENCRYPTED_BLOCK_SIZE !=0 ){ - log_e("buffer size error"); - return false; - } - if(!_cryptBuffer){ - _cryptBuffer = new (std::nothrow) uint8_t[ENCRYPTED_BLOCK_SIZE]; - } - if(!_cryptBuffer){ - log_e("new failed"); - return false; - } - uint8_t tweaked_key[ENCRYPTED_KEY_SIZE]; //tweaked crypt key - int done = 0; +bool UpdateClass::_decryptBuffer() { + if (!_cryptKey) { + log_w("AES key not set"); + return false; + } + if (_bufferLen % ENCRYPTED_BLOCK_SIZE != 0) { + log_e("buffer size error"); + return false; + } + if (!_cryptBuffer) { + _cryptBuffer = new (std::nothrow) uint8_t[ENCRYPTED_BLOCK_SIZE]; + } + if (!_cryptBuffer) { + log_e("new failed"); + return false; + } + uint8_t tweaked_key[ENCRYPTED_KEY_SIZE]; //tweaked crypt key + int done = 0; - /* + /* Mbedtls functions will be replaced with esp_aes functions when hardware acceleration is available To Do: Replace mbedtls for the cases where there's no hardware acceleration */ - mbedtls_aes_context ctx; //initialize AES - mbedtls_aes_init( &ctx ); - while((_bufferLen - done) >= ENCRYPTED_BLOCK_SIZE){ - for(int i=0; i < ENCRYPTED_BLOCK_SIZE; i++) _cryptBuffer[(ENCRYPTED_BLOCK_SIZE - 1) - i] = _buffer[i + done]; //reverse order 16 bytes to decrypt - if( ((_cryptAddress + _progress + done) % ENCRYPTED_TWEAK_BLOCK_SIZE) == 0 || done == 0 ){ - _cryptKeyTweak(_cryptAddress + _progress + done, tweaked_key); //update tweaked crypt key - if( mbedtls_aes_setkey_enc( &ctx, tweaked_key, 256 ) ){ - return false; - } - if( mbedtls_aes_setkey_dec( &ctx, tweaked_key, 256 ) ){ - return false; - } - } - if( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_ENCRYPT, _cryptBuffer, _cryptBuffer ) ){ //use MBEDTLS_AES_ENCRYPT to decrypt flash code - return false; - } - for(int i=0; i < ENCRYPTED_BLOCK_SIZE; i++) _buffer[i + done] = _cryptBuffer[(ENCRYPTED_BLOCK_SIZE - 1) - i]; //reverse order 16 bytes from decrypt - done += ENCRYPTED_BLOCK_SIZE; + mbedtls_aes_context ctx; //initialize AES + mbedtls_aes_init(&ctx); + while ((_bufferLen - done) >= ENCRYPTED_BLOCK_SIZE) { + for (int i = 0; i < ENCRYPTED_BLOCK_SIZE; i++) _cryptBuffer[(ENCRYPTED_BLOCK_SIZE - 1) - i] = _buffer[i + done]; //reverse order 16 bytes to decrypt + if (((_cryptAddress + _progress + done) % ENCRYPTED_TWEAK_BLOCK_SIZE) == 0 || done == 0) { + _cryptKeyTweak(_cryptAddress + _progress + done, tweaked_key); //update tweaked crypt key + if (mbedtls_aes_setkey_enc(&ctx, tweaked_key, 256)) { + return false; + } + if (mbedtls_aes_setkey_dec(&ctx, tweaked_key, 256)) { + return false; + } } - return true; + if (mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT, _cryptBuffer, _cryptBuffer)) { //use MBEDTLS_AES_ENCRYPT to decrypt flash code + return false; + } + for (int i = 0; i < ENCRYPTED_BLOCK_SIZE; i++) _buffer[i + done] = _cryptBuffer[(ENCRYPTED_BLOCK_SIZE - 1) - i]; //reverse order 16 bytes from decrypt + done += ENCRYPTED_BLOCK_SIZE; + } + return true; } -bool UpdateClass::_writeBuffer(){ - //first bytes of loading image, check to see if loading image needs decrypting - if(!_progress){ - _cryptMode &= U_AES_DECRYPT_MODE_MASK; - if( ( _cryptMode == U_AES_DECRYPT_ON ) - || ((_command == U_FLASH) && (_cryptMode & U_AES_DECRYPT_AUTO) && (_buffer[0] != ESP_IMAGE_HEADER_MAGIC)) - ){ - _cryptMode |= U_AES_IMAGE_DECRYPTING_BIT; //set to decrypt the loading image - log_d("Decrypting OTA Image"); - } +bool UpdateClass::_writeBuffer() { + //first bytes of loading image, check to see if loading image needs decrypting + if (!_progress) { + _cryptMode &= U_AES_DECRYPT_MODE_MASK; + if ((_cryptMode == U_AES_DECRYPT_ON) + || ((_command == U_FLASH) && (_cryptMode & U_AES_DECRYPT_AUTO) && (_buffer[0] != ESP_IMAGE_HEADER_MAGIC))) { + _cryptMode |= U_AES_IMAGE_DECRYPTING_BIT; //set to decrypt the loading image + log_d("Decrypting OTA Image"); + } + } + //check if data in buffer needs decrypting + if (_cryptMode & U_AES_IMAGE_DECRYPTING_BIT) { + if (!_decryptBuffer()) { + _abort(UPDATE_ERROR_DECRYPT); + return false; } - //check if data in buffer needs decrypting - if( _cryptMode & U_AES_IMAGE_DECRYPTING_BIT ){ - if( !_decryptBuffer() ){ - _abort(UPDATE_ERROR_DECRYPT); - return false; - } + } + //first bytes of new firmware + uint8_t skip = 0; + if (!_progress && _command == U_FLASH) { + //check magic + if (_buffer[0] != ESP_IMAGE_HEADER_MAGIC) { + _abort(UPDATE_ERROR_MAGIC_BYTE); + return false; } - //first bytes of new firmware - uint8_t skip = 0; - if(!_progress && _command == U_FLASH){ - //check magic - if(_buffer[0] != ESP_IMAGE_HEADER_MAGIC){ - _abort(UPDATE_ERROR_MAGIC_BYTE); - return false; - } - //Stash the first 16 bytes of data and set the offset so they are - //not written at this point so that partially written firmware - //will not be bootable - skip = ENCRYPTED_BLOCK_SIZE; - _skipBuffer = new (std::nothrow) uint8_t[skip]; - if (!_skipBuffer) { - log_e("_skipBuffer allocation failed"); - return false; - } - memcpy(_skipBuffer, _buffer, skip); - } - if (!_progress && _progress_callback) { - _progress_callback(0, _size); - } - size_t offset = _partition->address + _progress; - bool block_erase = (_size - _progress >= SPI_FLASH_BLOCK_SIZE) && (offset % SPI_FLASH_BLOCK_SIZE == 0); // if it's the block boundary, than erase the whole block from here - bool part_head_sectors = _partition->address % SPI_FLASH_BLOCK_SIZE && offset < (_partition->address / SPI_FLASH_BLOCK_SIZE + 1) * SPI_FLASH_BLOCK_SIZE; // sector belong to unaligned partition heading block - bool part_tail_sectors = offset >= (_partition->address + _size) / SPI_FLASH_BLOCK_SIZE * SPI_FLASH_BLOCK_SIZE; // sector belong to unaligned partition tailing block - if (block_erase || part_head_sectors || part_tail_sectors){ - if(!ESP.partitionEraseRange(_partition, _progress, block_erase ? SPI_FLASH_BLOCK_SIZE : SPI_FLASH_SEC_SIZE)){ - _abort(UPDATE_ERROR_ERASE); - return false; - } + //Stash the first 16 bytes of data and set the offset so they are + //not written at this point so that partially written firmware + //will not be bootable + skip = ENCRYPTED_BLOCK_SIZE; + _skipBuffer = new (std::nothrow) uint8_t[skip]; + if (!_skipBuffer) { + log_e("_skipBuffer allocation failed"); + return false; } - - // try to skip empty blocks on unecrypted partitions - if ((_partition->encrypted || _chkDataInBlock(_buffer + skip/sizeof(uint32_t), _bufferLen - skip)) && !ESP.partitionWrite(_partition, _progress + skip, (uint32_t*)_buffer + skip/sizeof(uint32_t), _bufferLen - skip)) { - _abort(UPDATE_ERROR_WRITE); - return false; + memcpy(_skipBuffer, _buffer, skip); + } + if (!_progress && _progress_callback) { + _progress_callback(0, _size); + } + size_t offset = _partition->address + _progress; + bool block_erase = (_size - _progress >= SPI_FLASH_BLOCK_SIZE) && (offset % SPI_FLASH_BLOCK_SIZE == 0); // if it's the block boundary, than erase the whole block from here + bool part_head_sectors = _partition->address % SPI_FLASH_BLOCK_SIZE && offset < (_partition->address / SPI_FLASH_BLOCK_SIZE + 1) * SPI_FLASH_BLOCK_SIZE; // sector belong to unaligned partition heading block + bool part_tail_sectors = offset >= (_partition->address + _size) / SPI_FLASH_BLOCK_SIZE * SPI_FLASH_BLOCK_SIZE; // sector belong to unaligned partition tailing block + if (block_erase || part_head_sectors || part_tail_sectors) { + if (!ESP.partitionEraseRange(_partition, _progress, block_erase ? SPI_FLASH_BLOCK_SIZE : SPI_FLASH_SEC_SIZE)) { + _abort(UPDATE_ERROR_ERASE); + return false; } + } - //restore magic or md5 will fail - if(!_progress && _command == U_FLASH){ - _buffer[0] = ESP_IMAGE_HEADER_MAGIC; - } - _md5.add(_buffer, _bufferLen); - _progress += _bufferLen; - _bufferLen = 0; - if (_progress_callback) { - _progress_callback(_progress, _size); - } - return true; + // try to skip empty blocks on unecrypted partitions + if ((_partition->encrypted || _chkDataInBlock(_buffer + skip / sizeof(uint32_t), _bufferLen - skip)) && !ESP.partitionWrite(_partition, _progress + skip, (uint32_t *)_buffer + skip / sizeof(uint32_t), _bufferLen - skip)) { + _abort(UPDATE_ERROR_WRITE); + return false; + } + + //restore magic or md5 will fail + if (!_progress && _command == U_FLASH) { + _buffer[0] = ESP_IMAGE_HEADER_MAGIC; + } + _md5.add(_buffer, _bufferLen); + _progress += _bufferLen; + _bufferLen = 0; + if (_progress_callback) { + _progress_callback(_progress, _size); + } + return true; } bool UpdateClass::_verifyHeader(uint8_t data) { - if(_command == U_FLASH) { - if(data != ESP_IMAGE_HEADER_MAGIC) { - _abort(UPDATE_ERROR_MAGIC_BYTE); - return false; - } - return true; - } else if(_command == U_SPIFFS) { - return true; + if (_command == U_FLASH) { + if (data != ESP_IMAGE_HEADER_MAGIC) { + _abort(UPDATE_ERROR_MAGIC_BYTE); + return false; } - return false; + return true; + } else if (_command == U_SPIFFS) { + return true; + } + return false; } bool UpdateClass::_verifyEnd() { - if(_command == U_FLASH) { - if(!_enablePartition(_partition) || !_partitionIsBootable(_partition)) { - _abort(UPDATE_ERROR_READ); - return false; - } - - if(esp_ota_set_boot_partition(_partition)){ - _abort(UPDATE_ERROR_ACTIVATE); - return false; - } - _reset(); - return true; - } else if(_command == U_SPIFFS) { - _reset(); - return true; + if (_command == U_FLASH) { + if (!_enablePartition(_partition) || !_partitionIsBootable(_partition)) { + _abort(UPDATE_ERROR_READ); + return false; } - return false; -} -bool UpdateClass::setMD5(const char * expected_md5){ - if(strlen(expected_md5) != 32) - { - return false; + if (esp_ota_set_boot_partition(_partition)) { + _abort(UPDATE_ERROR_ACTIVATE); + return false; } - _target_md5 = expected_md5; - _target_md5.toLowerCase(); + _reset(); + return true; + } else if (_command == U_SPIFFS) { + _reset(); return true; + } + return false; } -bool UpdateClass::end(bool evenIfRemaining){ - if(hasError() || _size == 0){ - return false; - } +bool UpdateClass::setMD5(const char *expected_md5) { + if (strlen(expected_md5) != 32) { + return false; + } + _target_md5 = expected_md5; + _target_md5.toLowerCase(); + return true; +} - if(!isFinished() && !evenIfRemaining){ - log_e("premature end: res:%u, pos:%u/%u\n", getError(), progress(), _size); - _abort(UPDATE_ERROR_ABORT); - return false; - } +bool UpdateClass::end(bool evenIfRemaining) { + if (hasError() || _size == 0) { + return false; + } - if(evenIfRemaining) { - if(_bufferLen > 0) { - _writeBuffer(); - } - _size = progress(); + if (!isFinished() && !evenIfRemaining) { + log_e("premature end: res:%u, pos:%u/%u\n", getError(), progress(), _size); + _abort(UPDATE_ERROR_ABORT); + return false; + } + + if (evenIfRemaining) { + if (_bufferLen > 0) { + _writeBuffer(); } + _size = progress(); + } - _md5.calculate(); - if(_target_md5.length()) { - if(_target_md5 != _md5.toString()){ - _abort(UPDATE_ERROR_MD5); - return false; - } + _md5.calculate(); + if (_target_md5.length()) { + if (_target_md5 != _md5.toString()) { + _abort(UPDATE_ERROR_MD5); + return false; } + } - return _verifyEnd(); + return _verifyEnd(); } size_t UpdateClass::write(uint8_t *data, size_t len) { - if(hasError() || !isRunning()){ - return 0; - } - - if(len > remaining()){ - _abort(UPDATE_ERROR_SPACE); - return 0; - } - - size_t left = len; - - while((_bufferLen + left) > SPI_FLASH_SEC_SIZE) { - size_t toBuff = SPI_FLASH_SEC_SIZE - _bufferLen; - memcpy(_buffer + _bufferLen, data + (len - left), toBuff); - _bufferLen += toBuff; - if(!_writeBuffer()){ - return len - left; - } - left -= toBuff; - } - memcpy(_buffer + _bufferLen, data + (len - left), left); - _bufferLen += left; - if(_bufferLen == remaining()){ - if(!_writeBuffer()){ - return len - left; - } - } - return len; + if (hasError() || !isRunning()) { + return 0; + } + + if (len > remaining()) { + _abort(UPDATE_ERROR_SPACE); + return 0; + } + + size_t left = len; + + while ((_bufferLen + left) > SPI_FLASH_SEC_SIZE) { + size_t toBuff = SPI_FLASH_SEC_SIZE - _bufferLen; + memcpy(_buffer + _bufferLen, data + (len - left), toBuff); + _bufferLen += toBuff; + if (!_writeBuffer()) { + return len - left; + } + left -= toBuff; + } + memcpy(_buffer + _bufferLen, data + (len - left), left); + _bufferLen += left; + if (_bufferLen == remaining()) { + if (!_writeBuffer()) { + return len - left; + } + } + return len; } size_t UpdateClass::writeStream(Stream &data) { - size_t written = 0; - size_t toRead = 0; - int timeout_failures = 0; + size_t written = 0; + size_t toRead = 0; + int timeout_failures = 0; - if(hasError() || !isRunning()) - return 0; + if (hasError() || !isRunning()) + return 0; - if(!_verifyHeader(data.peek())) { - _reset(); - return 0; - } + if (!_verifyHeader(data.peek())) { + _reset(); + return 0; + } - if(_ledPin != -1) { - pinMode(_ledPin, OUTPUT); - } + if (_ledPin != -1) { + pinMode(_ledPin, OUTPUT); + } - while(remaining()) { - if(_ledPin != -1) { - digitalWrite(_ledPin, _ledOn); // Switch LED on - } - size_t bytesToRead = SPI_FLASH_SEC_SIZE - _bufferLen; - if(bytesToRead > remaining()) { - bytesToRead = remaining(); - } + while (remaining()) { + if (_ledPin != -1) { + digitalWrite(_ledPin, _ledOn); // Switch LED on + } + size_t bytesToRead = SPI_FLASH_SEC_SIZE - _bufferLen; + if (bytesToRead > remaining()) { + bytesToRead = remaining(); + } - /* + /* Init read&timeout counters and try to read, if read failed, increase counter, wait 100ms and try to read again. If counter > 300 (30 sec), give up/abort */ - toRead = 0; - timeout_failures = 0; - while(!toRead) { - toRead = data.readBytes(_buffer + _bufferLen, bytesToRead); - if(toRead == 0) { - timeout_failures++; - if (timeout_failures >= 300) { - _abort(UPDATE_ERROR_STREAM); - return written; - } - delay(100); - } + toRead = 0; + timeout_failures = 0; + while (!toRead) { + toRead = data.readBytes(_buffer + _bufferLen, bytesToRead); + if (toRead == 0) { + timeout_failures++; + if (timeout_failures >= 300) { + _abort(UPDATE_ERROR_STREAM); + return written; } + delay(100); + } + } - if(_ledPin != -1) { - digitalWrite(_ledPin, !_ledOn); // Switch LED off - } - _bufferLen += toRead; - if((_bufferLen == remaining() || _bufferLen == SPI_FLASH_SEC_SIZE) && !_writeBuffer()) - return written; - written += toRead; - - #if CONFIG_FREERTOS_UNICORE - delay(1); // Fix solo WDT - #endif + if (_ledPin != -1) { + digitalWrite(_ledPin, !_ledOn); // Switch LED off } - return written; + _bufferLen += toRead; + if ((_bufferLen == remaining() || _bufferLen == SPI_FLASH_SEC_SIZE) && !_writeBuffer()) + return written; + written += toRead; + +#if CONFIG_FREERTOS_UNICORE + delay(1); // Fix solo WDT +#endif + } + return written; } -void UpdateClass::printError(Print &out){ - out.println(_err2str(_error)); +void UpdateClass::printError(Print &out) { + out.println(_err2str(_error)); } -const char * UpdateClass::errorString(){ - return _err2str(_error); +const char *UpdateClass::errorString() { + return _err2str(_error); } bool UpdateClass::_chkDataInBlock(const uint8_t *data, size_t len) const { - // check 32-bit aligned blocks only - if (!len || len % sizeof(uint32_t)) - return true; + // check 32-bit aligned blocks only + if (!len || len % sizeof(uint32_t)) + return true; - size_t dwl = len / sizeof(uint32_t); + size_t dwl = len / sizeof(uint32_t); - do { - if (*(uint32_t*)data ^ 0xffffffff) // for SPI NOR flash empty blocks are all one's, i.e. filled with 0xff byte - return true; + do { + if (*(uint32_t *)data ^ 0xffffffff) // for SPI NOR flash empty blocks are all one's, i.e. filled with 0xff byte + return true; - data += sizeof(uint32_t); - } while (--dwl); - return false; + data += sizeof(uint32_t); + } while (--dwl); + return false; } #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_UPDATE) diff --git a/libraries/WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino b/libraries/WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino index 0362a287a59..1eddb7e6635 100644 --- a/libraries/WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino +++ b/libraries/WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino @@ -65,8 +65,7 @@ void handleRoot() { \ ", - hr, min, sec - ); + hr, min, sec); server.send(200, "text/html", temp); digitalWrite(led, 0); } @@ -126,7 +125,7 @@ void setup(void) { void loop(void) { server.handleClient(); - delay(2);//allow the cpu to switch to other tasks + delay(2); //allow the cpu to switch to other tasks } void drawGraph() { diff --git a/libraries/WebServer/examples/FSBrowser/FSBrowser.ino b/libraries/WebServer/examples/FSBrowser/FSBrowser.ino index 93b448c3b89..32c16885bd1 100644 --- a/libraries/WebServer/examples/FSBrowser/FSBrowser.ino +++ b/libraries/WebServer/examples/FSBrowser/FSBrowser.ino @@ -90,10 +90,10 @@ String getContentType(String filename) { return "text/plain"; } -bool exists(String path){ +bool exists(String path) { bool yes = false; File file = FILESYSTEM.open(path, "r"); - if(!file.isDirectory()){ + if (!file.isDirectory()) { yes = true; } file.close(); @@ -129,7 +129,8 @@ void handleFileUpload() { if (!filename.startsWith("/")) { filename = "/" + filename; } - DBG_OUTPUT_PORT.print("handleFileUpload Name: "); DBG_OUTPUT_PORT.println(filename); + DBG_OUTPUT_PORT.print("handleFileUpload Name: "); + DBG_OUTPUT_PORT.println(filename); fsUploadFile = FILESYSTEM.open(filename, "w"); filename = String(); } else if (upload.status == UPLOAD_FILE_WRITE) { @@ -141,7 +142,8 @@ void handleFileUpload() { if (fsUploadFile) { fsUploadFile.close(); } - DBG_OUTPUT_PORT.print("handleFileUpload Size: "); DBG_OUTPUT_PORT.println(upload.totalSize); + DBG_OUTPUT_PORT.print("handleFileUpload Size: "); + DBG_OUTPUT_PORT.println(upload.totalSize); } } @@ -198,19 +200,19 @@ void handleFileList() { path = String(); String output = "["; - if(root.isDirectory()){ - File file = root.openNextFile(); - while(file){ - if (output != "[") { - output += ','; - } - output += "{\"type\":\""; - output += (file.isDirectory()) ? "dir" : "file"; - output += "\",\"name\":\""; - output += String(file.path()).substring(1); - output += "\"}"; - file = root.openNextFile(); + if (root.isDirectory()) { + File file = root.openNextFile(); + while (file) { + if (output != "[") { + output += ','; } + output += "{\"type\":\""; + output += (file.isDirectory()) ? "dir" : "file"; + output += "\",\"name\":\""; + output += String(file.path()).substring(1); + output += "\"}"; + file = root.openNextFile(); + } } output += "]"; server.send(200, "text/json", output); @@ -223,15 +225,15 @@ void setup(void) { if (FORMAT_FILESYSTEM) FILESYSTEM.format(); FILESYSTEM.begin(); { - File root = FILESYSTEM.open("/"); - File file = root.openNextFile(); - while(file){ - String fileName = file.name(); - size_t fileSize = file.size(); - DBG_OUTPUT_PORT.printf("FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str()); - file = root.openNextFile(); - } - DBG_OUTPUT_PORT.printf("\n"); + File root = FILESYSTEM.open("/"); + File file = root.openNextFile(); + while (file) { + String fileName = file.name(); + size_t fileSize = file.size(); + DBG_OUTPUT_PORT.printf("FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str()); + file = root.openNextFile(); + } + DBG_OUTPUT_PORT.printf("\n"); } @@ -271,9 +273,11 @@ void setup(void) { server.on("/edit", HTTP_DELETE, handleFileDelete); //first callback is called after the request has ended with all parsed arguments //second callback handles file uploads at that location - server.on("/edit", HTTP_POST, []() { - server.send(200, "text/plain", ""); - }, handleFileUpload); + server.on( + "/edit", HTTP_POST, []() { + server.send(200, "text/plain", ""); + }, + handleFileUpload); //called when the url is not defined here //use it to load content from FILESYSTEM @@ -295,10 +299,9 @@ void setup(void) { }); server.begin(); DBG_OUTPUT_PORT.println("HTTP server started"); - } void loop(void) { server.handleClient(); - delay(2);//allow the cpu to switch to other tasks + delay(2); //allow the cpu to switch to other tasks } diff --git a/libraries/WebServer/examples/FSBrowser/data/index.htm b/libraries/WebServer/examples/FSBrowser/data/index.htm index 9cb560cb0b0..36858db6043 100644 --- a/libraries/WebServer/examples/FSBrowser/data/index.htm +++ b/libraries/WebServer/examples/FSBrowser/data/index.htm @@ -1,8 +1,8 @@ - %d: [%d][%02X:%02X:%02X:%02X:%02X:%02X] %s (%d) (%c) (%s)", - i, - chan_scan, - BSSID_scan[0], BSSID_scan[1], BSSID_scan[2], BSSID_scan[3], BSSID_scan[4], BSSID_scan[5], - ssid_scan.c_str(), - rssi_scan, - (sec_scan == WIFI_AUTH_OPEN) ? ' ' : '*', - (hidden_scan) ? "hidden" : "visible"); - } else { - log_d(" %d: [%d][%02X:%02X:%02X:%02X:%02X:%02X] %s (%d) (%c) (%s)", - i, - chan_scan, - BSSID_scan[0], BSSID_scan[1], BSSID_scan[2], BSSID_scan[3], BSSID_scan[4], BSSID_scan[5], - ssid_scan.c_str(), - rssi_scan, - (sec_scan == WIFI_AUTH_OPEN) ? ' ' : '*', - (hidden_scan) ? "hidden" : "visible"); - } + if (ssid_scan == entry.ssid || hidden_scan) { // SSID match or hidden network found + if (!hidden_scan) { + log_v("known ssid: %s, has failed: %s", entry.ssid, entry.hasFailed ? "yes" : "no"); + foundCount++; } - log_v("foundCount = %d, failCount = %d", foundCount, failCount); - // if all the APs in the list have failed, reset the failure flags - if (foundCount == failCount) { - resetFails(); // keeps trying the APs in the list - } - } - // clean up ram - WiFi.scanDelete(); + if (!entry.hasFailed) { + if (hidden_scan) { + WiFi.begin(entry.ssid, entry.passphrase, chan_scan, BSSID_scan); - if(bestIndex >= 0) { - log_i("[WIFI] Connecting BSSID: %02X:%02X:%02X:%02X:%02X:%02X SSID: %s Channel: %d (%d)", bestBSSID[0], bestBSSID[1], bestBSSID[2], bestBSSID[3], bestBSSID[4], bestBSSID[5], bestNetwork.ssid, bestChannel, bestNetworkDb); + // If the ssid returned from the scan is empty, it is a hidden SSID + // it appears that the WiFi.begin() function is asynchronous and takes + // additional time to connect to a hidden SSID. Therefore a delay of 1000ms + // is added for hidden SSIDs before calling WiFi.status() + delay(1000); - if (ipv6_support == true) { - WiFi.enableIPv6(); - } - WiFi.disconnect(); - delay(10); - WiFi.begin(bestNetwork.ssid, (_bAllowOpenAP && bestNetworkSec == WIFI_AUTH_OPEN) ? NULL : bestNetwork.passphrase, bestChannel, bestBSSID); - status = WiFi.status(); - _bWFMInit = true; - - startTime = millis(); - // wait for connection, fail, or timeout - while(status != WL_CONNECTED && (millis() - startTime) <= connectTimeout) { // && status != WL_NO_SSID_AVAIL && status != WL_CONNECT_FAILED - delay(10); status = WiFi.status(); - } + startTime = millis(); + + while (status != WL_CONNECTED && (millis() - startTime) <= connectTimeout) { + delay(10); + status = WiFi.status(); + } + + WiFi.disconnect(); + delay(10); - switch(status) { - case WL_CONNECTED: - log_i("[WIFI] Connecting done."); - log_d("[WIFI] SSID: %s", WiFi.SSID().c_str()); - log_d("[WIFI] IP: %s", WiFi.localIP().toString().c_str()); - log_d("[WIFI] MAC: %s", WiFi.BSSIDstr().c_str()); - log_d("[WIFI] Channel: %d", WiFi.channel()); - - if (_connectionTestCBFunc != NULL) { - // We connected to an AP but if it's a captive portal we're not going anywhere. Test it. - if (_connectionTestCBFunc()) { - resetFails(); - } else { - markAsFailed(bestIndex); - WiFi.disconnect(); - delay(10); - status = WiFi.status(); - } + if (status == WL_CONNECTED) { + log_v("hidden ssid %s found", entry.ssid); + ssid_scan = entry.ssid; + foundCount++; } else { - resetFails(); + continue; } - break; - case WL_NO_SSID_AVAIL: - log_e("[WIFI] Connecting Failed AP not found."); - markAsFailed(bestIndex); - break; - case WL_CONNECT_FAILED: - log_e("[WIFI] Connecting Failed."); - markAsFailed(bestIndex); - break; - default: - log_e("[WIFI] Connecting Failed (%d).", status); - markAsFailed(bestIndex); - break; + } + known = true; + log_v("rssi_scan: %d, bestNetworkDb: %d", rssi_scan, bestNetworkDb); + if (rssi_scan > bestNetworkDb) { // best network + if (_bAllowOpenAP || (sec_scan == WIFI_AUTH_OPEN || entry.passphrase)) { // check for passphrase if not open wlan + log_v("best network is now: %s", ssid_scan); + bestIndex = x; + bestNetworkSec = sec_scan; + bestNetworkDb = rssi_scan; + bestChannel = chan_scan; + memcpy((void*)&bestNetwork, (void*)&entry, sizeof(bestNetwork)); + memcpy((void*)&bestBSSID, (void*)BSSID_scan, sizeof(bestBSSID)); + } + } + break; + } else { + failCount++; } + } + } + + if (known) { + log_d(" ---> %d: [%d][%02X:%02X:%02X:%02X:%02X:%02X] %s (%d) (%c) (%s)", + i, + chan_scan, + BSSID_scan[0], BSSID_scan[1], BSSID_scan[2], BSSID_scan[3], BSSID_scan[4], BSSID_scan[5], + ssid_scan.c_str(), + rssi_scan, + (sec_scan == WIFI_AUTH_OPEN) ? ' ' : '*', + (hidden_scan) ? "hidden" : "visible"); } else { - log_e("[WIFI] no matching wifi found!"); + log_d(" %d: [%d][%02X:%02X:%02X:%02X:%02X:%02X] %s (%d) (%c) (%s)", + i, + chan_scan, + BSSID_scan[0], BSSID_scan[1], BSSID_scan[2], BSSID_scan[3], BSSID_scan[4], BSSID_scan[5], + ssid_scan.c_str(), + rssi_scan, + (sec_scan == WIFI_AUTH_OPEN) ? ' ' : '*', + (hidden_scan) ? "hidden" : "visible"); } + } + log_v("foundCount = %d, failCount = %d", foundCount, failCount); + // if all the APs in the list have failed, reset the failure flags + if (foundCount == failCount) { + resetFails(); // keeps trying the APs in the list + } + } + // clean up ram + WiFi.scanDelete(); + + if (bestIndex >= 0) { + log_i("[WIFI] Connecting BSSID: %02X:%02X:%02X:%02X:%02X:%02X SSID: %s Channel: %d (%d)", bestBSSID[0], bestBSSID[1], bestBSSID[2], bestBSSID[3], bestBSSID[4], bestBSSID[5], bestNetwork.ssid, bestChannel, bestNetworkDb); + + if (ipv6_support == true) { + WiFi.enableIPv6(); + } + WiFi.disconnect(); + delay(10); + WiFi.begin(bestNetwork.ssid, (_bAllowOpenAP && bestNetworkSec == WIFI_AUTH_OPEN) ? NULL : bestNetwork.passphrase, bestChannel, bestBSSID); + status = WiFi.status(); + _bWFMInit = true; + + startTime = millis(); + // wait for connection, fail, or timeout + while (status != WL_CONNECTED && (millis() - startTime) <= connectTimeout) { // && status != WL_NO_SSID_AVAIL && status != WL_CONNECT_FAILED + delay(10); + status = WiFi.status(); + } + + switch (status) { + case WL_CONNECTED: + log_i("[WIFI] Connecting done."); + log_d("[WIFI] SSID: %s", WiFi.SSID().c_str()); + log_d("[WIFI] IP: %s", WiFi.localIP().toString().c_str()); + log_d("[WIFI] MAC: %s", WiFi.BSSIDstr().c_str()); + log_d("[WIFI] Channel: %d", WiFi.channel()); + + if (_connectionTestCBFunc != NULL) { + // We connected to an AP but if it's a captive portal we're not going anywhere. Test it. + if (_connectionTestCBFunc()) { + resetFails(); + } else { + markAsFailed(bestIndex); + WiFi.disconnect(); + delay(10); + status = WiFi.status(); + } + } else { + resetFails(); + } + break; + case WL_NO_SSID_AVAIL: + log_e("[WIFI] Connecting Failed AP not found."); + markAsFailed(bestIndex); + break; + case WL_CONNECT_FAILED: + log_e("[WIFI] Connecting Failed."); + markAsFailed(bestIndex); + break; + default: + log_e("[WIFI] Connecting Failed (%d).", status); + markAsFailed(bestIndex); + break; + } } else { - // start scan - log_d("[WIFI] delete old wifi config..."); - WiFi.disconnect(); - - log_d("[WIFI] start scan"); - // scan wifi async mode - WiFi.scanNetworks(true); + log_e("[WIFI] no matching wifi found!"); } + } else { + // start scan + log_d("[WIFI] delete old wifi config..."); + WiFi.disconnect(); + + log_d("[WIFI] start scan"); + // scan wifi async mode + WiFi.scanNetworks(true); + } - return status; + return status; } void WiFiMulti::enableIPv6(bool state) { - ipv6_support = state; + ipv6_support = state; } void WiFiMulti::markAsFailed(int32_t i) { - APlist[i].hasFailed = true; - log_d("[WIFI] Marked SSID %s as failed", APlist[i].ssid); + APlist[i].hasFailed = true; + log_d("[WIFI] Marked SSID %s as failed", APlist[i].ssid); } -void WiFiMulti::resetFails(){ - for(uint32_t i = 0; i < APlist.size(); i++) { - APlist[i].hasFailed = false; - } - log_d("[WIFI] Resetting failure flags"); +void WiFiMulti::resetFails() { + for (uint32_t i = 0; i < APlist.size(); i++) { + APlist[i].hasFailed = false; + } + log_d("[WIFI] Resetting failure flags"); } void WiFiMulti::setStrictMode(bool bStrict) { - _bStrict = bStrict; + _bStrict = bStrict; } void WiFiMulti::setAllowOpenAP(bool bAllowOpenAP) { - _bAllowOpenAP = bAllowOpenAP; + _bAllowOpenAP = bAllowOpenAP; } void WiFiMulti::setConnectionTestCallbackFunc(ConnectionTestCB_t cbFunc) { - _connectionTestCBFunc = cbFunc; + _connectionTestCBFunc = cbFunc; } #endif /* SOC_WIFI_SUPPORTED */ diff --git a/libraries/WiFi/src/WiFiMulti.h b/libraries/WiFi/src/WiFiMulti.h index c380c9ee18d..7605487a537 100644 --- a/libraries/WiFi/src/WiFiMulti.h +++ b/libraries/WiFi/src/WiFiMulti.h @@ -32,50 +32,49 @@ #include typedef struct { - char * ssid; - char * passphrase; - bool hasFailed; + char* ssid; + char* passphrase; + bool hasFailed; } WifiAPlist_t; typedef std::function ConnectionTestCB_t; -class WiFiMulti -{ +class WiFiMulti { public: - WiFiMulti(); - ~WiFiMulti(); + WiFiMulti(); + ~WiFiMulti(); - bool addAP(const char* ssid, const char *passphrase = NULL); - uint8_t run(uint32_t connectTimeout=5000, bool scanHidden=false); - void enableIPv6(bool state); + bool addAP(const char* ssid, const char* passphrase = NULL); + uint8_t run(uint32_t connectTimeout = 5000, bool scanHidden = false); + void enableIPv6(bool state); - // Force (default: true) to only keep connected or to connect to an AP from the provided WiFiMulti list. - // When bStrict is false, it will keep the last/current connected AP even if not in the WiFiMulti List. - void setStrictMode(bool bStrict = true); - - // allows (true) to connect to ANY open AP, even if not in the user list - // default false (do not connect to an open AP that has not been explicitaly added by the user to list) - void setAllowOpenAP(bool bAllowOpenAP = false); + // Force (default: true) to only keep connected or to connect to an AP from the provided WiFiMulti list. + // When bStrict is false, it will keep the last/current connected AP even if not in the WiFiMulti List. + void setStrictMode(bool bStrict = true); - // clears the current list of Multi APs and frees the memory - void APlistClean(void); + // allows (true) to connect to ANY open AP, even if not in the user list + // default false (do not connect to an open AP that has not been explicitaly added by the user to list) + void setAllowOpenAP(bool bAllowOpenAP = false); - // allow the user to define a callback function that will validate the connection to the Internet. - // if the callback returns true, the connection is considered valid and the AP will added to the validated AP list. - // set the callback to NULL to disable the feature and validate any SSID that is in the list. - void setConnectionTestCallbackFunc(ConnectionTestCB_t cbFunc); + // clears the current list of Multi APs and frees the memory + void APlistClean(void); + + // allow the user to define a callback function that will validate the connection to the Internet. + // if the callback returns true, the connection is considered valid and the AP will added to the validated AP list. + // set the callback to NULL to disable the feature and validate any SSID that is in the list. + void setConnectionTestCallbackFunc(ConnectionTestCB_t cbFunc); private: - std::vector APlist; - bool ipv6_support; + std::vector APlist; + bool ipv6_support; - bool _bStrict = true; - bool _bAllowOpenAP = false; - ConnectionTestCB_t _connectionTestCBFunc = NULL; - bool _bWFMInit = false; + bool _bStrict = true; + bool _bAllowOpenAP = false; + ConnectionTestCB_t _connectionTestCBFunc = NULL; + bool _bWFMInit = false; - void markAsFailed(int32_t i); - void resetFails(); + void markAsFailed(int32_t i); + void resetFails(); }; #endif /* SOC_WIFI_SUPPORTED */ diff --git a/libraries/WiFi/src/WiFiSTA.cpp b/libraries/WiFi/src/WiFiSTA.cpp index 1e7731bb930..5b2dbdac82d 100644 --- a/libraries/WiFi/src/WiFiSTA.cpp +++ b/libraries/WiFi/src/WiFiSTA.cpp @@ -44,7 +44,7 @@ #include #include "esp_mac.h" -#if __has_include ("esp_eap_client.h") +#if __has_include("esp_eap_client.h") #include "esp_eap_client.h" #else #include "esp_wpa2.h" @@ -59,57 +59,52 @@ * @return one of the value defined in wl_status_t * */ -wl_status_t WiFiSTAClass::status() -{ - return STA.status(); +wl_status_t WiFiSTAClass::status() { + return STA.status(); } -wl_status_t WiFiSTAClass::begin(const char* wpa2_ssid, wpa2_auth_method_t method, const char* wpa2_identity, const char* wpa2_username, const char *wpa2_password, const char* ca_pem, const char* client_crt, const char* client_key, int32_t channel, const uint8_t* bssid, bool connect) -{ - if(!STA.begin()) { - return WL_CONNECT_FAILED; - } +wl_status_t WiFiSTAClass::begin(const char* wpa2_ssid, wpa2_auth_method_t method, const char* wpa2_identity, const char* wpa2_username, const char* wpa2_password, const char* ca_pem, const char* client_crt, const char* client_key, int32_t channel, const uint8_t* bssid, bool connect) { + if (!STA.begin()) { + return WL_CONNECT_FAILED; + } - if(!STA.connect(wpa2_ssid, method, wpa2_identity, wpa2_username, wpa2_password, ca_pem, client_crt, client_key, channel, bssid, connect)){ - return WL_CONNECT_FAILED; - } + if (!STA.connect(wpa2_ssid, method, wpa2_identity, wpa2_username, wpa2_password, ca_pem, client_crt, client_key, channel, bssid, connect)) { + return WL_CONNECT_FAILED; + } - return STA.status(); + return STA.status(); } -wl_status_t WiFiSTAClass::begin(const char* ssid, const char *passphrase, int32_t channel, const uint8_t* bssid, bool connect) -{ - if(!STA.begin()) { - return WL_CONNECT_FAILED; - } +wl_status_t WiFiSTAClass::begin(const char* ssid, const char* passphrase, int32_t channel, const uint8_t* bssid, bool connect) { + if (!STA.begin()) { + return WL_CONNECT_FAILED; + } - if(!STA.connect(ssid, passphrase, channel, bssid, connect)){ - return WL_CONNECT_FAILED; - } + if (!STA.connect(ssid, passphrase, channel, bssid, connect)) { + return WL_CONNECT_FAILED; + } - return STA.status(); + return STA.status(); } /** * Use to connect to SDK config. * @return wl_status_t */ -wl_status_t WiFiSTAClass::begin() -{ - if(!STA.begin(true)) { - return WL_CONNECT_FAILED; - } +wl_status_t WiFiSTAClass::begin() { + if (!STA.begin(true)) { + return WL_CONNECT_FAILED; + } - return STA.status(); + return STA.status(); } /** * will force a disconnect and then start reconnecting to AP * @return true when successful */ -bool WiFiSTAClass::reconnect() -{ - return STA.reconnect(); +bool WiFiSTAClass::reconnect() { + return STA.reconnect(); } /** @@ -118,9 +113,8 @@ bool WiFiSTAClass::reconnect() * @param eraseap `true` to erase the AP configuration from the NVS memory. * @return `true` when successful. */ -bool WiFiSTAClass::disconnectAsync(bool wifioff, bool eraseap) -{ - return disconnect(wifioff, eraseap, 0); +bool WiFiSTAClass::disconnectAsync(bool wifioff, bool eraseap) { + return disconnect(wifioff, eraseap, 0); } /** @@ -130,15 +124,14 @@ bool WiFiSTAClass::disconnectAsync(bool wifioff, bool eraseap) * @param timeoutLength timeout to wait for status change * @return `true` when successful. */ -bool WiFiSTAClass::disconnect(bool wifioff, bool eraseap, unsigned long timeoutLength) -{ - if (!STA.disconnect(eraseap, timeoutLength)) { - return false; - } - if (wifioff) { - return STA.end(); - } - return true; +bool WiFiSTAClass::disconnect(bool wifioff, bool eraseap, unsigned long timeoutLength) { + if (!STA.disconnect(eraseap, timeoutLength)) { + return false; + } + if (wifioff) { + return STA.end(); + } + return true; } /** @@ -149,14 +142,14 @@ bool WiFiSTAClass::disconnect(bool wifioff, bool eraseap, unsigned long timeoutL * - esp_wifi_set_protocol, * - esp_wifi_set_config related * - esp_wifi_set_mode - * + * * @return true if erase succeeded * @note: Resets SSID, password, protocol, mode, etc. * These settings are maintained by WiFi driver in IDF. * WiFi driver must be initialized. */ bool WiFiSTAClass::eraseAP(void) { - return STA.erase(); + return STA.erase(); } /** @@ -167,35 +160,34 @@ bool WiFiSTAClass::eraseAP(void) { * @param dns1 Static DNS server 1 * @param dns2 Static DNS server 2 */ -bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2) -{ - // handle Arduino ordering of parameters: ip, dns, gw, subnet - if (local_ip.type() == IPv4 && local_ip != INADDR_NONE && subnet[0] != 255) { - IPAddress tmp = dns1; - dns1 = gateway; - gateway = subnet; - subnet = (tmp != INADDR_NONE) ? tmp : IPAddress(255, 255, 255, 0); - } +bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2) { + // handle Arduino ordering of parameters: ip, dns, gw, subnet + if (local_ip.type() == IPv4 && local_ip != INADDR_NONE && subnet[0] != 255) { + IPAddress tmp = dns1; + dns1 = gateway; + gateway = subnet; + subnet = (tmp != INADDR_NONE) ? tmp : IPAddress(255, 255, 255, 0); + } - return STA.begin() && STA.config(local_ip, gateway, subnet, dns1, dns2); + return STA.begin() && STA.config(local_ip, gateway, subnet, dns1, dns2); } bool WiFiSTAClass::config(IPAddress local_ip, IPAddress dns) { - if (local_ip == INADDR_NONE) { - return config(INADDR_NONE, INADDR_NONE, INADDR_NONE); - } + if (local_ip == INADDR_NONE) { + return config(INADDR_NONE, INADDR_NONE, INADDR_NONE); + } - if (local_ip.type() != IPv4) { - return false; - } + if (local_ip.type() != IPv4) { + return false; + } - IPAddress gw(local_ip); - gw[3] = 1; - if (dns == INADDR_NONE) { - dns = gw; - } - return config(local_ip, gw, IPAddress(255, 255, 255, 0), dns); + IPAddress gw(local_ip); + gw[3] = 1; + if (dns == INADDR_NONE) { + dns = gw; + } + return config(local_ip, gw, IPAddress(255, 255, 255, 0), dns); } /** @@ -203,9 +195,8 @@ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress dns) { * @param dns1 Static DNS server 1 * @param dns2 Static DNS server 2 (optional) */ -bool WiFiSTAClass::setDNS(IPAddress dns1, IPAddress dns2) -{ - return STA.begin() && STA.dnsIP(0, dns1) && STA.dnsIP(1, dns2); +bool WiFiSTAClass::setDNS(IPAddress dns1, IPAddress dns2) { + return STA.begin() && STA.dnsIP(0, dns1) && STA.dnsIP(1, dns2); } /** @@ -213,16 +204,15 @@ bool WiFiSTAClass::setDNS(IPAddress dns1, IPAddress dns2) * @param m wifi_bandwidth_t */ bool WiFiSTAClass::bandwidth(wifi_bandwidth_t bandwidth) { - return STA.bandwidth(bandwidth); + return STA.bandwidth(bandwidth); } /** * is STA interface connected? * @return true if STA is connected to an AP */ -bool WiFiSTAClass::isConnected() -{ - return STA.connected(); +bool WiFiSTAClass::isConnected() { + return STA.connected(); } /** @@ -230,49 +220,44 @@ bool WiFiSTAClass::isConnected() * Must be called before WiFi.begin(). * @param minSecurity wifi_auth_mode_t */ -void WiFiSTAClass::setMinSecurity(wifi_auth_mode_t minSecurity) -{ - return STA.setMinSecurity(minSecurity); +void WiFiSTAClass::setMinSecurity(wifi_auth_mode_t minSecurity) { + return STA.setMinSecurity(minSecurity); } /** - * Set the way that AP is chosen. + * Set the way that AP is chosen. * First SSID match[WIFI_FAST_SCAN] or Sorted[WIFI_ALL_CHANNEL_SCAN] (RSSI or Security) * Must be called before WiFi.begin() * @param scanMethod wifi_scan_method_t */ -void WiFiSTAClass::setScanMethod(wifi_scan_method_t scanMethod) -{ - return STA.setScanMethod(scanMethod); +void WiFiSTAClass::setScanMethod(wifi_scan_method_t scanMethod) { + return STA.setScanMethod(scanMethod); } /** - * Set the way that AP is sorted. (requires scanMethod WIFI_ALL_CHANNEL_SCAN) + * Set the way that AP is sorted. (requires scanMethod WIFI_ALL_CHANNEL_SCAN) * By SSID[WIFI_CONNECT_AP_BY_SIGNAL] or Security[WIFI_CONNECT_AP_BY_SECURITY] * Must be called before WiFi.begin() * @param sortMethod wifi_sort_method_t */ -void WiFiSTAClass::setSortMethod(wifi_sort_method_t sortMethod) -{ - return STA.setSortMethod(sortMethod); +void WiFiSTAClass::setSortMethod(wifi_sort_method_t sortMethod) { + return STA.setSortMethod(sortMethod); } /** - * Function used to set the automatic reconnection if the connection is lost. + * Function used to set the automatic reconnection if the connection is lost. * @param autoReconnect `true` to enable this option. - * @return true + * @return true */ -bool WiFiSTAClass::setAutoReconnect(bool autoReconnect) -{ - return STA.setAutoReconnect(autoReconnect); +bool WiFiSTAClass::setAutoReconnect(bool autoReconnect) { + return STA.setAutoReconnect(autoReconnect); } /** * Function used to get the automatic reconnection if the connection is lost. * @return The function will return `true` if this setting is enabled. */ -bool WiFiSTAClass::getAutoReconnect() -{ - return STA.getAutoReconnect(); +bool WiFiSTAClass::getAutoReconnect() { + return STA.getAutoReconnect(); } /** @@ -280,18 +265,16 @@ bool WiFiSTAClass::getAutoReconnect() * returns the status reached or disconnect if STA is off * @return wl_status_t */ -uint8_t WiFiSTAClass::waitForConnectResult(unsigned long timeoutLength) -{ - return STA.waitForConnectResult(timeoutLength); +uint8_t WiFiSTAClass::waitForConnectResult(unsigned long timeoutLength) { + return STA.waitForConnectResult(timeoutLength); } /** * Get the station interface IP address. * @return IPAddress station IP */ -IPAddress WiFiSTAClass::localIP() -{ - return STA.localIP(); +IPAddress WiFiSTAClass::localIP() { + return STA.localIP(); } @@ -300,36 +283,32 @@ IPAddress WiFiSTAClass::localIP() * @param mac pointer to uint8_t array with length WL_MAC_ADDR_LENGTH * @return pointer to uint8_t * */ -uint8_t* WiFiSTAClass::macAddress(uint8_t* mac) -{ - return STA.macAddress(mac); +uint8_t* WiFiSTAClass::macAddress(uint8_t* mac) { + return STA.macAddress(mac); } /** * Get the station interface MAC address. * @return String mac */ -String WiFiSTAClass::macAddress(void) -{ - return STA.macAddress(); +String WiFiSTAClass::macAddress(void) { + return STA.macAddress(); } /** * Get the interface subnet mask address. * @return IPAddress subnetMask */ -IPAddress WiFiSTAClass::subnetMask() -{ - return STA.subnetMask(); +IPAddress WiFiSTAClass::subnetMask() { + return STA.subnetMask(); } /** * Get the gateway ip address. * @return IPAddress gatewayIP */ -IPAddress WiFiSTAClass::gatewayIP() -{ - return STA.gatewayIP(); +IPAddress WiFiSTAClass::gatewayIP() { + return STA.gatewayIP(); } /** @@ -337,110 +316,98 @@ IPAddress WiFiSTAClass::gatewayIP() * @param dns_no * @return IPAddress DNS Server IP */ -IPAddress WiFiSTAClass::dnsIP(uint8_t dns_no) -{ - return STA.dnsIP(dns_no); +IPAddress WiFiSTAClass::dnsIP(uint8_t dns_no) { + return STA.dnsIP(dns_no); } /** * Get the broadcast ip address. * @return IPAddress broadcastIP */ -IPAddress WiFiSTAClass::broadcastIP() -{ - return STA.broadcastIP(); +IPAddress WiFiSTAClass::broadcastIP() { + return STA.broadcastIP(); } /** * Get the network id. * @return IPAddress networkID */ -IPAddress WiFiSTAClass::networkID() -{ - return STA.networkID(); +IPAddress WiFiSTAClass::networkID() { + return STA.networkID(); } /** * Get the subnet CIDR. * @return uint8_t subnetCIDR */ -uint8_t WiFiSTAClass::subnetCIDR() -{ - return STA.subnetCIDR(); +uint8_t WiFiSTAClass::subnetCIDR() { + return STA.subnetCIDR(); } /** * Return the current SSID associated with the network * @return SSID */ -String WiFiSTAClass::SSID() const -{ - return STA.SSID(); +String WiFiSTAClass::SSID() const { + return STA.SSID(); } /** * Return the current pre shared key associated with the network * @return psk string */ -String WiFiSTAClass::psk() const -{ - return STA.psk(); +String WiFiSTAClass::psk() const { + return STA.psk(); } /** * Return the current bssid / mac associated with the network if configured * @return bssid uint8_t * */ -uint8_t* WiFiSTAClass::BSSID(uint8_t* buff) -{ - return STA.BSSID(buff); +uint8_t* WiFiSTAClass::BSSID(uint8_t* buff) { + return STA.BSSID(buff); } /** * Return the current bssid / mac associated with the network if configured * @return String bssid mac */ -String WiFiSTAClass::BSSIDstr(void) -{ - return STA.BSSIDstr(); +String WiFiSTAClass::BSSIDstr(void) { + return STA.BSSIDstr(); } /** * Return the current network RSSI. * @return RSSI value */ -int8_t WiFiSTAClass::RSSI(void) -{ - return STA.RSSI(); +int8_t WiFiSTAClass::RSSI(void) { + return STA.RSSI(); } /** * Enable IPv6 on the station interface. * Should be called before WiFi.begin() - * + * * @return true on success */ -bool WiFiSTAClass::enableIPv6(bool en) -{ - return STA.enableIPv6(en); +bool WiFiSTAClass::enableIPv6(bool en) { + return STA.enableIPv6(en); } /** * Get the station interface link-local IPv6 address. * @return IPAddress */ -IPAddress WiFiSTAClass::linkLocalIPv6() -{ - return STA.linkLocalIPv6(); +IPAddress WiFiSTAClass::linkLocalIPv6() { + return STA.linkLocalIPv6(); } /** * Get the station interface global IPv6 address. * @return IPAddress */ -IPAddress WiFiSTAClass::globalIPv6() -{ - return STA.globalIPv6(); +IPAddress WiFiSTAClass::globalIPv6() { + return STA.globalIPv6(); } @@ -448,65 +415,65 @@ bool WiFiSTAClass::_smartConfigStarted = false; bool WiFiSTAClass::_smartConfigDone = false; /** - * @brief - * + * @brief + * * @param type Select type of SmartConfig. Default type is SC_TYPE_ESPTOUCH - * @param crypt_key When using type SC_TYPE_ESPTOUTCH_V2 crypt key needed, else ignored. Lenght should be 16 chars. + * @param crypt_key When using type SC_TYPE_ESPTOUTCH_V2 crypt key needed, else ignored. Length should be 16 chars. * @return true if configuration is successful. * @return false if configuration fails. */ bool WiFiSTAClass::beginSmartConfig(smartconfig_type_t type, char* crypt_key) { - esp_err_t err; - if (_smartConfigStarted) { - return false; - } - - if (!WiFi.mode(WIFI_STA)) { - return false; - } - esp_wifi_disconnect(); - - smartconfig_start_config_t conf = SMARTCONFIG_START_CONFIG_DEFAULT(); - - if (type == SC_TYPE_ESPTOUCH_V2){ - conf.esp_touch_v2_enable_crypt = true; - conf.esp_touch_v2_key = crypt_key; - } - - err = esp_smartconfig_set_type(type); - if (err != ESP_OK) { - log_e("SmartConfig Set Type Failed!"); - return false; - } - err = esp_smartconfig_start(&conf); - if (err != ESP_OK) { - log_e("SmartConfig Start Failed!"); - return false; - } - _smartConfigStarted = true; - _smartConfigDone = false; - return true; + esp_err_t err; + if (_smartConfigStarted) { + return false; + } + + if (!WiFi.mode(WIFI_STA)) { + return false; + } + esp_wifi_disconnect(); + + smartconfig_start_config_t conf = SMARTCONFIG_START_CONFIG_DEFAULT(); + + if (type == SC_TYPE_ESPTOUCH_V2) { + conf.esp_touch_v2_enable_crypt = true; + conf.esp_touch_v2_key = crypt_key; + } + + err = esp_smartconfig_set_type(type); + if (err != ESP_OK) { + log_e("SmartConfig Set Type Failed!"); + return false; + } + err = esp_smartconfig_start(&conf); + if (err != ESP_OK) { + log_e("SmartConfig Start Failed!"); + return false; + } + _smartConfigStarted = true; + _smartConfigDone = false; + return true; } bool WiFiSTAClass::stopSmartConfig() { - if (!_smartConfigStarted) { - return true; - } + if (!_smartConfigStarted) { + return true; + } - if (esp_smartconfig_stop() == ESP_OK) { - _smartConfigStarted = false; - return true; - } + if (esp_smartconfig_stop() == ESP_OK) { + _smartConfigStarted = false; + return true; + } - return false; + return false; } bool WiFiSTAClass::smartConfigDone() { - if (!_smartConfigStarted) { - return false; - } + if (!_smartConfigStarted) { + return false; + } - return _smartConfigDone; + return _smartConfigDone; } #endif /* SOC_WIFI_SUPPORTED */ diff --git a/libraries/WiFi/src/WiFiSTA.h b/libraries/WiFi/src/WiFiSTA.h index d04a16d13d8..81d2d3ce2c2 100644 --- a/libraries/WiFi/src/WiFiSTA.h +++ b/libraries/WiFi/src/WiFiSTA.h @@ -32,9 +32,9 @@ #endif typedef enum { - WPA2_AUTH_TLS = 0, - WPA2_AUTH_PEAP = 1, - WPA2_AUTH_TTLS = 2 + WPA2_AUTH_TLS = 0, + WPA2_AUTH_PEAP = 1, + WPA2_AUTH_TTLS = 2 } wpa2_auth_method_t; @@ -42,146 +42,144 @@ typedef enum { // ------------------------------------ NEW STA Implementation ---------------------------------- // ---------------------------------------------------------------------------------------------- -class STAClass: public NetworkInterface { - public: - STAClass(); - ~STAClass(); +class STAClass : public NetworkInterface { +public: + STAClass(); + ~STAClass(); - bool begin(bool tryConnect = false); - bool end(); + bool begin(bool tryConnect = false); + bool end(); - bool bandwidth(wifi_bandwidth_t bandwidth); + bool bandwidth(wifi_bandwidth_t bandwidth); - bool connect(); - bool connect(const char* ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true); - bool connect(const char* wpa2_ssid, wpa2_auth_method_t method, const char* wpa2_identity=NULL, const char* wpa2_username=NULL, const char *wpa2_password=NULL, const char* ca_pem=NULL, const char* client_crt=NULL, const char* client_key=NULL, int32_t channel=0, const uint8_t* bssid=0, bool connect=true); - bool disconnect(bool eraseap = false, unsigned long timeout = 0); - bool reconnect(); - bool erase(); + bool connect(); + bool connect(const char* ssid, const char* passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true); + bool connect(const char* wpa2_ssid, wpa2_auth_method_t method, const char* wpa2_identity = NULL, const char* wpa2_username = NULL, const char* wpa2_password = NULL, const char* ca_pem = NULL, const char* client_crt = NULL, const char* client_key = NULL, int32_t channel = 0, const uint8_t* bssid = 0, bool connect = true); + bool disconnect(bool eraseap = false, unsigned long timeout = 0); + bool reconnect(); + bool erase(); - uint8_t waitForConnectResult(unsigned long timeoutLength = 60000); + uint8_t waitForConnectResult(unsigned long timeoutLength = 60000); - bool setAutoReconnect(bool autoReconnect); - bool getAutoReconnect(); + bool setAutoReconnect(bool autoReconnect); + bool getAutoReconnect(); - // Next group functions must be called before WiFi.begin() - void setMinSecurity(wifi_auth_mode_t minSecurity);// Default is WIFI_AUTH_WPA2_PSK - void setScanMethod(wifi_scan_method_t scanMethod);// Default is WIFI_FAST_SCAN - void setSortMethod(wifi_sort_method_t sortMethod);// Default is WIFI_CONNECT_AP_BY_SIGNAL + // Next group functions must be called before WiFi.begin() + void setMinSecurity(wifi_auth_mode_t minSecurity); // Default is WIFI_AUTH_WPA2_PSK + void setScanMethod(wifi_scan_method_t scanMethod); // Default is WIFI_FAST_SCAN + void setSortMethod(wifi_sort_method_t sortMethod); // Default is WIFI_CONNECT_AP_BY_SIGNAL - wl_status_t status(); + wl_status_t status(); - String SSID() const; - String psk() const; - uint8_t * BSSID(uint8_t* bssid = NULL); - String BSSIDstr(); - int8_t RSSI(); + String SSID() const; + String psk() const; + uint8_t* BSSID(uint8_t* bssid = NULL); + String BSSIDstr(); + int8_t RSSI(); - const char * disconnectReasonName(wifi_err_reason_t reason); + const char* disconnectReasonName(wifi_err_reason_t reason); - // Private Use - void _setStatus(wl_status_t status); - void _onStaEvent(int32_t event_id, void* event_data); + // Private Use + void _setStatus(wl_status_t status); + void _onStaEvent(int32_t event_id, void* event_data); - protected: - wifi_auth_mode_t _minSecurity; - wifi_scan_method_t _scanMethod; - wifi_sort_method_t _sortMethod; - bool _autoReconnect; - wl_status_t _status; +protected: + wifi_auth_mode_t _minSecurity; + wifi_scan_method_t _scanMethod; + wifi_sort_method_t _sortMethod; + bool _autoReconnect; + wl_status_t _status; - size_t printDriverInfo(Print & out) const; + size_t printDriverInfo(Print& out) const; - friend class WiFiGenericClass; - bool onEnable(); - bool onDisable(); + friend class WiFiGenericClass; + bool onEnable(); + bool onDisable(); }; // ---------------------------------------------------------------------------------------------- // ------------------------------- OLD STA API (compatibility) ---------------------------------- // ---------------------------------------------------------------------------------------------- -class WiFiSTAClass -{ +class WiFiSTAClass { public: - STAClass STA; + STAClass STA; - wl_status_t begin(const char* wpa2_ssid, wpa2_auth_method_t method, const char* wpa2_identity=NULL, const char* wpa2_username=NULL, const char *wpa2_password=NULL, const char* ca_pem=NULL, const char* client_crt=NULL, const char* client_key=NULL, int32_t channel=0, const uint8_t* bssid=0, bool connect=true); - wl_status_t begin(const String& wpa2_ssid, wpa2_auth_method_t method, const String& wpa2_identity = (const char*)NULL, const String& wpa2_username = (const char*)NULL, const String& wpa2_password = (const char*)NULL, const String& ca_pem = (const char*)NULL, const String& client_crt = (const char*)NULL, const String& client_key = (const char*)NULL, int32_t channel=0, const uint8_t* bssid=0, bool connect=true) { - return begin(wpa2_ssid.c_str(), method, wpa2_identity.c_str(), wpa2_username.c_str(), wpa2_password.c_str(), ca_pem.c_str(), client_crt.c_str(), client_key.c_str(), channel, bssid, connect); - } - wl_status_t begin(const char* ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true); - wl_status_t begin(const String& ssid, const String& passphrase = (const char*)NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true) { - return begin(ssid.c_str(), passphrase.c_str(), channel, bssid, connect); - } - wl_status_t begin(); + wl_status_t begin(const char* wpa2_ssid, wpa2_auth_method_t method, const char* wpa2_identity = NULL, const char* wpa2_username = NULL, const char* wpa2_password = NULL, const char* ca_pem = NULL, const char* client_crt = NULL, const char* client_key = NULL, int32_t channel = 0, const uint8_t* bssid = 0, bool connect = true); + wl_status_t begin(const String& wpa2_ssid, wpa2_auth_method_t method, const String& wpa2_identity = (const char*)NULL, const String& wpa2_username = (const char*)NULL, const String& wpa2_password = (const char*)NULL, const String& ca_pem = (const char*)NULL, const String& client_crt = (const char*)NULL, const String& client_key = (const char*)NULL, int32_t channel = 0, const uint8_t* bssid = 0, bool connect = true) { + return begin(wpa2_ssid.c_str(), method, wpa2_identity.c_str(), wpa2_username.c_str(), wpa2_password.c_str(), ca_pem.c_str(), client_crt.c_str(), client_key.c_str(), channel, bssid, connect); + } + wl_status_t begin(const char* ssid, const char* passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true); + wl_status_t begin(const String& ssid, const String& passphrase = (const char*)NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true) { + return begin(ssid.c_str(), passphrase.c_str(), channel, bssid, connect); + } + wl_status_t begin(); - // also accepts Arduino ordering of parameters: ip, dns, gw, mask - bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000); + // also accepts Arduino ordering of parameters: ip, dns, gw, mask + bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000); - // two and one parameter version. 2nd parameter is DNS like in Arduino - bool config(IPAddress local_ip, IPAddress dns = (uint32_t)0x00000000); + // two and one parameter version. 2nd parameter is DNS like in Arduino + bool config(IPAddress local_ip, IPAddress dns = (uint32_t)0x00000000); - bool setDNS(IPAddress dns1, IPAddress dns2 = (uint32_t)0x00000000); // sets DNS IP for all network interfaces + bool setDNS(IPAddress dns1, IPAddress dns2 = (uint32_t)0x00000000); // sets DNS IP for all network interfaces - bool bandwidth(wifi_bandwidth_t bandwidth); + bool bandwidth(wifi_bandwidth_t bandwidth); - bool reconnect(); - bool disconnectAsync(bool wifioff = false, bool eraseap = false); - bool disconnect(bool wifioff = false, bool eraseap = false, unsigned long timeoutLength = 100); - bool eraseAP(void); + bool reconnect(); + bool disconnectAsync(bool wifioff = false, bool eraseap = false); + bool disconnect(bool wifioff = false, bool eraseap = false, unsigned long timeoutLength = 100); + bool eraseAP(void); - bool isConnected(); + bool isConnected(); - bool setAutoReconnect(bool autoReconnect); - bool getAutoReconnect(); + bool setAutoReconnect(bool autoReconnect); + bool getAutoReconnect(); - uint8_t waitForConnectResult(unsigned long timeoutLength = 60000); + uint8_t waitForConnectResult(unsigned long timeoutLength = 60000); - // Next group functions must be called before WiFi.begin() - void setMinSecurity(wifi_auth_mode_t minSecurity);// Default is WIFI_AUTH_WPA2_PSK - void setScanMethod(wifi_scan_method_t scanMethod);// Default is WIFI_FAST_SCAN - void setSortMethod(wifi_sort_method_t sortMethod);// Default is WIFI_CONNECT_AP_BY_SIGNAL + // Next group functions must be called before WiFi.begin() + void setMinSecurity(wifi_auth_mode_t minSecurity); // Default is WIFI_AUTH_WPA2_PSK + void setScanMethod(wifi_scan_method_t scanMethod); // Default is WIFI_FAST_SCAN + void setSortMethod(wifi_sort_method_t sortMethod); // Default is WIFI_CONNECT_AP_BY_SIGNAL - // STA WiFi info - wl_status_t status(); - String SSID() const; - String psk() const; + // STA WiFi info + wl_status_t status(); + String SSID() const; + String psk() const; - uint8_t * BSSID(uint8_t* bssid = NULL); - String BSSIDstr(); + uint8_t* BSSID(uint8_t* bssid = NULL); + String BSSIDstr(); - int8_t RSSI(); + int8_t RSSI(); - IPAddress localIP(); + IPAddress localIP(); - uint8_t * macAddress(uint8_t* mac); - String macAddress(); + uint8_t* macAddress(uint8_t* mac); + String macAddress(); - IPAddress subnetMask(); - IPAddress gatewayIP(); - IPAddress dnsIP(uint8_t dns_no = 0); + IPAddress subnetMask(); + IPAddress gatewayIP(); + IPAddress dnsIP(uint8_t dns_no = 0); - IPAddress broadcastIP(); - IPAddress networkID(); - uint8_t subnetCIDR(); - - bool enableIPv6(bool en=true); - IPAddress linkLocalIPv6(); - IPAddress globalIPv6(); + IPAddress broadcastIP(); + IPAddress networkID(); + uint8_t subnetCIDR(); - // ---------------------------------------------------------------------------------------------- - // ---------------------------------------- Smart Config ---------------------------------------- - // ---------------------------------------------------------------------------------------------- + bool enableIPv6(bool en = true); + IPAddress linkLocalIPv6(); + IPAddress globalIPv6(); + + // ---------------------------------------------------------------------------------------------- + // ---------------------------------------- Smart Config ---------------------------------------- + // ---------------------------------------------------------------------------------------------- protected: - static bool _smartConfigStarted; + static bool _smartConfigStarted; public: - bool beginSmartConfig(smartconfig_type_t type = SC_TYPE_ESPTOUCH, char* crypt_key = NULL); - bool stopSmartConfig(); - bool smartConfigDone(); - - static bool _smartConfigDone; + bool beginSmartConfig(smartconfig_type_t type = SC_TYPE_ESPTOUCH, char* crypt_key = NULL); + bool stopSmartConfig(); + bool smartConfigDone(); + static bool _smartConfigDone; }; diff --git a/libraries/WiFi/src/WiFiScan.cpp b/libraries/WiFi/src/WiFiScan.cpp index 4ec7e1471e5..a69856e941e 100644 --- a/libraries/WiFi/src/WiFiScan.cpp +++ b/libraries/WiFi/src/WiFiScan.cpp @@ -55,49 +55,48 @@ void* WiFiScanClass::_scanResult = 0; * @param show_hidden show hidden networks * @return Number of discovered networks */ -int16_t WiFiScanClass::scanNetworks(bool async, bool show_hidden, bool passive, uint32_t max_ms_per_chan, uint8_t channel, const char * ssid, const uint8_t * bssid) -{ - if(WiFiGenericClass::getStatusBits() & WIFI_SCANNING_BIT) { - return WIFI_SCAN_RUNNING; +int16_t WiFiScanClass::scanNetworks(bool async, bool show_hidden, bool passive, uint32_t max_ms_per_chan, uint8_t channel, const char* ssid, const uint8_t* bssid) { + if (WiFiGenericClass::getStatusBits() & WIFI_SCANNING_BIT) { + return WIFI_SCAN_RUNNING; + } + + WiFiScanClass::_scanTimeout = max_ms_per_chan * 20; + WiFiScanClass::_scanAsync = async; + + WiFi.enableSTA(true); + + scanDelete(); + + wifi_scan_config_t config; + config.ssid = (uint8_t*)ssid; + config.bssid = (uint8_t*)bssid; + config.channel = channel; + config.show_hidden = show_hidden; + if (passive) { + config.scan_type = WIFI_SCAN_TYPE_PASSIVE; + config.scan_time.passive = max_ms_per_chan; + } else { + config.scan_type = WIFI_SCAN_TYPE_ACTIVE; + config.scan_time.active.min = 100; + config.scan_time.active.max = max_ms_per_chan; + } + if (esp_wifi_scan_start(&config, false) == ESP_OK) { + _scanStarted = millis(); + if (!_scanStarted) { //Prevent 0 from millis overflow + ++_scanStarted; } - WiFiScanClass::_scanTimeout = max_ms_per_chan * 20; - WiFiScanClass::_scanAsync = async; - - WiFi.enableSTA(true); - - scanDelete(); + WiFiGenericClass::clearStatusBits(WIFI_SCAN_DONE_BIT); + WiFiGenericClass::setStatusBits(WIFI_SCANNING_BIT); - wifi_scan_config_t config; - config.ssid = (uint8_t*)ssid; - config.bssid = (uint8_t*)bssid; - config.channel = channel; - config.show_hidden = show_hidden; - if(passive){ - config.scan_type = WIFI_SCAN_TYPE_PASSIVE; - config.scan_time.passive = max_ms_per_chan; - } else { - config.scan_type = WIFI_SCAN_TYPE_ACTIVE; - config.scan_time.active.min = 100; - config.scan_time.active.max = max_ms_per_chan; + if (WiFiScanClass::_scanAsync) { + return WIFI_SCAN_RUNNING; } - if(esp_wifi_scan_start(&config, false) == ESP_OK) { - _scanStarted = millis(); - if (!_scanStarted) { //Prevent 0 from millis overflow - ++_scanStarted; - } - - WiFiGenericClass::clearStatusBits(WIFI_SCAN_DONE_BIT); - WiFiGenericClass::setStatusBits(WIFI_SCANNING_BIT); - - if(WiFiScanClass::_scanAsync) { - return WIFI_SCAN_RUNNING; - } - if(WiFiGenericClass::waitStatusBits(WIFI_SCAN_DONE_BIT, 10000)){ - return (int16_t) WiFiScanClass::_scanCount; - } + if (WiFiGenericClass::waitStatusBits(WIFI_SCAN_DONE_BIT, 10000)) { + return (int16_t)WiFiScanClass::_scanCount; } - return WIFI_SCAN_FAILED; + } + return WIFI_SCAN_FAILED; } @@ -107,18 +106,17 @@ int16_t WiFiScanClass::scanNetworks(bool async, bool show_hidden, bool passive, * @param result void *arg * @param status STATUS */ -void WiFiScanClass::_scanDone() -{ - esp_wifi_scan_get_ap_num(&(WiFiScanClass::_scanCount)); - if(WiFiScanClass::_scanCount) { - WiFiScanClass::_scanResult = new wifi_ap_record_t[WiFiScanClass::_scanCount]; - if(!WiFiScanClass::_scanResult || esp_wifi_scan_get_ap_records(&(WiFiScanClass::_scanCount), (wifi_ap_record_t*)_scanResult) != ESP_OK) { - WiFiScanClass::_scanCount = 0; - } +void WiFiScanClass::_scanDone() { + esp_wifi_scan_get_ap_num(&(WiFiScanClass::_scanCount)); + if (WiFiScanClass::_scanCount) { + WiFiScanClass::_scanResult = new wifi_ap_record_t[WiFiScanClass::_scanCount]; + if (!WiFiScanClass::_scanResult || esp_wifi_scan_get_ap_records(&(WiFiScanClass::_scanCount), (wifi_ap_record_t*)_scanResult) != ESP_OK) { + WiFiScanClass::_scanCount = 0; } - WiFiScanClass::_scanStarted=0; //Reset after a scan is completed for normal behavior - WiFiGenericClass::setStatusBits(WIFI_SCAN_DONE_BIT); - WiFiGenericClass::clearStatusBits(WIFI_SCANNING_BIT); + } + WiFiScanClass::_scanStarted = 0; //Reset after a scan is completed for normal behavior + WiFiGenericClass::setStatusBits(WIFI_SCAN_DONE_BIT); + WiFiGenericClass::clearStatusBits(WIFI_SCANNING_BIT); } /** @@ -126,12 +124,11 @@ void WiFiScanClass::_scanDone() * @param i specify from which network item want to get the information * @return bss_info * */ -void * WiFiScanClass::_getScanInfoByIndex(int i) -{ - if(!WiFiScanClass::_scanResult || (size_t) i >= WiFiScanClass::_scanCount) { - return 0; - } - return reinterpret_cast(WiFiScanClass::_scanResult) + i; +void* WiFiScanClass::_getScanInfoByIndex(int i) { + if (!WiFiScanClass::_scanResult || (size_t)i >= WiFiScanClass::_scanCount) { + return 0; + } + return reinterpret_cast(WiFiScanClass::_scanResult) + i; } /** @@ -140,35 +137,33 @@ void * WiFiScanClass::_getScanInfoByIndex(int i) * -1 if scan not fin * -2 if scan not triggered */ -int16_t WiFiScanClass::scanComplete() -{ - if(WiFiGenericClass::getStatusBits() & WIFI_SCAN_DONE_BIT) { - return WiFiScanClass::_scanCount; - } - - if(WiFiGenericClass::getStatusBits() & WIFI_SCANNING_BIT) { - return WIFI_SCAN_RUNNING; - } - // last one to avoid time affecting Async mode - if (WiFiScanClass::_scanStarted && (millis()-WiFiScanClass::_scanStarted) > WiFiScanClass::_scanTimeout) { //Check is scan was started and if the delay expired, return WIFI_SCAN_FAILED in this case - WiFiGenericClass::clearStatusBits(WIFI_SCANNING_BIT); - return WIFI_SCAN_FAILED; - } - +int16_t WiFiScanClass::scanComplete() { + if (WiFiGenericClass::getStatusBits() & WIFI_SCAN_DONE_BIT) { + return WiFiScanClass::_scanCount; + } + + if (WiFiGenericClass::getStatusBits() & WIFI_SCANNING_BIT) { + return WIFI_SCAN_RUNNING; + } + // last one to avoid time affecting Async mode + if (WiFiScanClass::_scanStarted && (millis() - WiFiScanClass::_scanStarted) > WiFiScanClass::_scanTimeout) { //Check is scan was started and if the delay expired, return WIFI_SCAN_FAILED in this case + WiFiGenericClass::clearStatusBits(WIFI_SCANNING_BIT); return WIFI_SCAN_FAILED; + } + + return WIFI_SCAN_FAILED; } /** * delete last scan result from RAM */ -void WiFiScanClass::scanDelete() -{ - WiFiGenericClass::clearStatusBits(WIFI_SCAN_DONE_BIT); - if(WiFiScanClass::_scanResult) { - delete[] reinterpret_cast(WiFiScanClass::_scanResult); - WiFiScanClass::_scanResult = 0; - WiFiScanClass::_scanCount = 0; - } +void WiFiScanClass::scanDelete() { + WiFiGenericClass::clearStatusBits(WIFI_SCAN_DONE_BIT); + if (WiFiScanClass::_scanResult) { + delete[] reinterpret_cast(WiFiScanClass::_scanResult); + WiFiScanClass::_scanResult = 0; + WiFiScanClass::_scanCount = 0; + } } @@ -182,18 +177,17 @@ void WiFiScanClass::scanDelete() * @param channel int32_t * * @return (true if ok) */ -bool WiFiScanClass::getNetworkInfo(uint8_t i, String &ssid, uint8_t &encType, int32_t &rssi, uint8_t* &bssid, int32_t &channel) -{ - wifi_ap_record_t* it = reinterpret_cast(_getScanInfoByIndex(i)); - if(!it) { - return false; - } - ssid = (const char*) it->ssid; - encType = it->authmode; - rssi = it->rssi; - bssid = it->bssid; - channel = it->primary; - return true; +bool WiFiScanClass::getNetworkInfo(uint8_t i, String& ssid, uint8_t& encType, int32_t& rssi, uint8_t*& bssid, int32_t& channel) { + wifi_ap_record_t* it = reinterpret_cast(_getScanInfoByIndex(i)); + if (!it) { + return false; + } + ssid = (const char*)it->ssid; + encType = it->authmode; + rssi = it->rssi; + bssid = it->bssid; + channel = it->primary; + return true; } @@ -202,13 +196,12 @@ bool WiFiScanClass::getNetworkInfo(uint8_t i, String &ssid, uint8_t &encType, in * @param i specify from which network item want to get the information * @return ssid string of the specified item on the networks scanned list */ -String WiFiScanClass::SSID(uint8_t i) -{ - wifi_ap_record_t* it = reinterpret_cast(_getScanInfoByIndex(i)); - if(!it) { - return String(); - } - return String(reinterpret_cast(it->ssid)); +String WiFiScanClass::SSID(uint8_t i) { + wifi_ap_record_t* it = reinterpret_cast(_getScanInfoByIndex(i)); + if (!it) { + return String(); + } + return String(reinterpret_cast(it->ssid)); } @@ -217,13 +210,12 @@ String WiFiScanClass::SSID(uint8_t i) * @param i specify from which network item want to get the information * @return encryption type (enum wl_enc_type) of the specified item on the networks scanned list */ -wifi_auth_mode_t WiFiScanClass::encryptionType(uint8_t i) -{ - wifi_ap_record_t* it = reinterpret_cast(_getScanInfoByIndex(i)); - if(!it) { - return WIFI_AUTH_OPEN; - } - return it->authmode; +wifi_auth_mode_t WiFiScanClass::encryptionType(uint8_t i) { + wifi_ap_record_t* it = reinterpret_cast(_getScanInfoByIndex(i)); + if (!it) { + return WIFI_AUTH_OPEN; + } + return it->authmode; } /** @@ -231,13 +223,12 @@ wifi_auth_mode_t WiFiScanClass::encryptionType(uint8_t i) * @param i specify from which network item want to get the information * @return signed value of RSSI of the specified item on the networks scanned list */ -int32_t WiFiScanClass::RSSI(uint8_t i) -{ - wifi_ap_record_t* it = reinterpret_cast(_getScanInfoByIndex(i)); - if(!it) { - return 0; - } - return it->rssi; +int32_t WiFiScanClass::RSSI(uint8_t i) { + wifi_ap_record_t* it = reinterpret_cast(_getScanInfoByIndex(i)); + if (!it) { + return 0; + } + return it->rssi; } @@ -247,21 +238,20 @@ int32_t WiFiScanClass::RSSI(uint8_t i) * @param buff optional buffer for the result uint8_t array with length 6 * @return uint8_t * MAC / BSSID of scanned wifi */ -uint8_t * WiFiScanClass::BSSID(uint8_t i, uint8_t* buff) -{ - wifi_ap_record_t* it = reinterpret_cast(_getScanInfoByIndex(i)); - if(buff != NULL) { - if(!it) { - memset(buff, 0, 6); - } else { - memcpy(buff, it->bssid, 6); - } - return buff; - } - if(!it) { - return 0; +uint8_t* WiFiScanClass::BSSID(uint8_t i, uint8_t* buff) { + wifi_ap_record_t* it = reinterpret_cast(_getScanInfoByIndex(i)); + if (buff != NULL) { + if (!it) { + memset(buff, 0, 6); + } else { + memcpy(buff, it->bssid, 6); } - return it->bssid; + return buff; + } + if (!it) { + return 0; + } + return it->bssid; } /** @@ -269,24 +259,22 @@ uint8_t * WiFiScanClass::BSSID(uint8_t i, uint8_t* buff) * @param i specify from which network item want to get the information * @return String MAC / BSSID of scanned wifi */ -String WiFiScanClass::BSSIDstr(uint8_t i) -{ - char mac[18] = { 0 }; - wifi_ap_record_t* it = reinterpret_cast(_getScanInfoByIndex(i)); - if(!it) { - return String(); - } - sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", it->bssid[0], it->bssid[1], it->bssid[2], it->bssid[3], it->bssid[4], it->bssid[5]); - return String(mac); +String WiFiScanClass::BSSIDstr(uint8_t i) { + char mac[18] = { 0 }; + wifi_ap_record_t* it = reinterpret_cast(_getScanInfoByIndex(i)); + if (!it) { + return String(); + } + sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", it->bssid[0], it->bssid[1], it->bssid[2], it->bssid[3], it->bssid[4], it->bssid[5]); + return String(mac); } -int32_t WiFiScanClass::channel(uint8_t i) -{ - wifi_ap_record_t* it = reinterpret_cast(_getScanInfoByIndex(i)); - if(!it) { - return 0; - } - return it->primary; +int32_t WiFiScanClass::channel(uint8_t i) { + wifi_ap_record_t* it = reinterpret_cast(_getScanInfoByIndex(i)); + if (!it) { + return 0; + } + return it->primary; } #endif /* SOC_WIFI_SUPPORTED */ diff --git a/libraries/WiFi/src/WiFiScan.h b/libraries/WiFi/src/WiFiScan.h index 31a06d310ec..5979f11174e 100644 --- a/libraries/WiFi/src/WiFiScan.h +++ b/libraries/WiFi/src/WiFiScan.h @@ -28,40 +28,40 @@ #include "WiFiType.h" #include "WiFiGeneric.h" -class WiFiScanClass -{ +class WiFiScanClass { public: - int16_t scanNetworks(bool async = false, bool show_hidden = false, bool passive = false, uint32_t max_ms_per_chan = 300, uint8_t channel = 0, const char * ssid=nullptr, const uint8_t * bssid=nullptr); + int16_t scanNetworks(bool async = false, bool show_hidden = false, bool passive = false, uint32_t max_ms_per_chan = 300, uint8_t channel = 0, const char *ssid = nullptr, const uint8_t *bssid = nullptr); - int16_t scanComplete(); - void scanDelete(); + int16_t scanComplete(); + void scanDelete(); - // scan result - bool getNetworkInfo(uint8_t networkItem, String &ssid, uint8_t &encryptionType, int32_t &RSSI, uint8_t* &BSSID, int32_t &channel); + // scan result + bool getNetworkInfo(uint8_t networkItem, String &ssid, uint8_t &encryptionType, int32_t &RSSI, uint8_t *&BSSID, int32_t &channel); - String SSID(uint8_t networkItem); - wifi_auth_mode_t encryptionType(uint8_t networkItem); - int32_t RSSI(uint8_t networkItem); - uint8_t * BSSID(uint8_t networkItem, uint8_t* bssid = NULL); - String BSSIDstr(uint8_t networkItem); - int32_t channel(uint8_t networkItem); - static void * getScanInfoByIndex(int i) { return _getScanInfoByIndex(i); }; + String SSID(uint8_t networkItem); + wifi_auth_mode_t encryptionType(uint8_t networkItem); + int32_t RSSI(uint8_t networkItem); + uint8_t *BSSID(uint8_t networkItem, uint8_t *bssid = NULL); + String BSSIDstr(uint8_t networkItem); + int32_t channel(uint8_t networkItem); + static void *getScanInfoByIndex(int i) { + return _getScanInfoByIndex(i); + }; - static void _scanDone(); + static void _scanDone(); protected: - static bool _scanAsync; - - static uint32_t _scanStarted; - static uint32_t _scanTimeout; - static uint16_t _scanCount; - - static void* _scanResult; + static bool _scanAsync; - static void * _getScanInfoByIndex(int i); + static uint32_t _scanStarted; + static uint32_t _scanTimeout; + static uint16_t _scanCount; + static void *_scanResult; + + static void *_getScanInfoByIndex(int i); }; diff --git a/libraries/WiFi/src/WiFiType.h b/libraries/WiFi/src/WiFiType.h index d85e457e1ec..fbc04b412e8 100644 --- a/libraries/WiFi/src/WiFiType.h +++ b/libraries/WiFi/src/WiFiType.h @@ -26,30 +26,30 @@ #include "esp_wifi_types.h" -#define WIFI_SCAN_RUNNING (-1) -#define WIFI_SCAN_FAILED (-2) +#define WIFI_SCAN_RUNNING (-1) +#define WIFI_SCAN_FAILED (-2) -#define WiFiMode_t wifi_mode_t -#define WIFI_OFF WIFI_MODE_NULL -#define WIFI_STA WIFI_MODE_STA -#define WIFI_AP WIFI_MODE_AP -#define WIFI_AP_STA WIFI_MODE_APSTA +#define WiFiMode_t wifi_mode_t +#define WIFI_OFF WIFI_MODE_NULL +#define WIFI_STA WIFI_MODE_STA +#define WIFI_AP WIFI_MODE_AP +#define WIFI_AP_STA WIFI_MODE_APSTA -#define WiFiEvent_t arduino_event_id_t +#define WiFiEvent_t arduino_event_id_t #define WiFiEventInfo_t arduino_event_info_t #define WiFiEventId_t wifi_event_id_t typedef enum { - WL_NO_SHIELD = 255, // for compatibility with WiFi Shield library - WL_STOPPED = 254, - WL_IDLE_STATUS = 0, - WL_NO_SSID_AVAIL = 1, - WL_SCAN_COMPLETED = 2, - WL_CONNECTED = 3, - WL_CONNECT_FAILED = 4, - WL_CONNECTION_LOST = 5, - WL_DISCONNECTED = 6 + WL_NO_SHIELD = 255, // for compatibility with WiFi Shield library + WL_STOPPED = 254, + WL_IDLE_STATUS = 0, + WL_NO_SSID_AVAIL = 1, + WL_SCAN_COMPLETED = 2, + WL_CONNECTED = 3, + WL_CONNECT_FAILED = 4, + WL_CONNECTION_LOST = 5, + WL_DISCONNECTED = 6 } wl_status_t; #endif /* SOC_WIFI_SUPPORTED */ diff --git a/libraries/WiFiProv/examples/WiFiProv/README.md b/libraries/WiFiProv/examples/WiFiProv/README.md index efee39fd7a5..b0eb9654a6e 100644 --- a/libraries/WiFiProv/examples/WiFiProv/README.md +++ b/libraries/WiFiProv/examples/WiFiProv/README.md @@ -118,4 +118,4 @@ Provisioning Ends [I][WiFiProv.cpp:150] beginProvision(): SSID: Wce***** [I][WiFiProv.cpp:152] beginProvision(): CONNECTING TO THE ACCESS POINT: Connected IP address: 192.168.43.120 -``` \ No newline at end of file +``` diff --git a/libraries/WiFiProv/examples/WiFiProv/WiFiProv.ino b/libraries/WiFiProv/examples/WiFiProv/WiFiProv.ino index 72c043cb74f..b8530910d7e 100644 --- a/libraries/WiFiProv/examples/WiFiProv/WiFiProv.ino +++ b/libraries/WiFiProv/examples/WiFiProv/WiFiProv.ino @@ -12,70 +12,71 @@ Note: This sketch takes up a lot of space for the app and may not be able to fla #include "WiFi.h" // #define USE_SOFT_AP // Uncomment if you want to enforce using the Soft AP method instead of BLE -const char * pop = "abcd1234"; // Proof of possession - otherwise called a PIN - string provided by the device, entered by the user in the phone app -const char * service_name = "PROV_123"; // Name of your device (the Espressif apps expects by default device name starting with "Prov_") -const char * service_key = NULL; // Password used for SofAP method (NULL = no password needed) -bool reset_provisioned = true; // When true the library will automatically delete previously provisioned data. +const char *pop = "abcd1234"; // Proof of possession - otherwise called a PIN - string provided by the device, entered by the user in the phone app +const char *service_name = "PROV_123"; // Name of your device (the Espressif apps expects by default device name starting with "Prov_") +const char *service_key = NULL; // Password used for SofAP method (NULL = no password needed) +bool reset_provisioned = true; // When true the library will automatically delete previously provisioned data. // WARNING: SysProvEvent is called from a separate FreeRTOS task (thread)! -void SysProvEvent(arduino_event_t *sys_event) -{ - switch (sys_event->event_id) { +void SysProvEvent(arduino_event_t *sys_event) { + switch (sys_event->event_id) { case ARDUINO_EVENT_WIFI_STA_GOT_IP: - Serial.print("\nConnected IP address : "); - Serial.println(IPAddress(sys_event->event_info.got_ip.ip_info.ip.addr)); - break; + Serial.print("\nConnected IP address : "); + Serial.println(IPAddress(sys_event->event_info.got_ip.ip_info.ip.addr)); + break; case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: - Serial.println("\nDisconnected. Connecting to the AP again... "); - break; + Serial.println("\nDisconnected. Connecting to the AP again... "); + break; case ARDUINO_EVENT_PROV_START: - Serial.println("\nProvisioning started\nGive Credentials of your access point using smartphone app"); - break; - case ARDUINO_EVENT_PROV_CRED_RECV: { + Serial.println("\nProvisioning started\nGive Credentials of your access point using smartphone app"); + break; + case ARDUINO_EVENT_PROV_CRED_RECV: + { Serial.println("\nReceived Wi-Fi credentials"); Serial.print("\tSSID : "); - Serial.println((const char *) sys_event->event_info.prov_cred_recv.ssid); + Serial.println((const char *)sys_event->event_info.prov_cred_recv.ssid); Serial.print("\tPassword : "); - Serial.println((char const *) sys_event->event_info.prov_cred_recv.password); + Serial.println((char const *)sys_event->event_info.prov_cred_recv.password); break; - } - case ARDUINO_EVENT_PROV_CRED_FAIL: { + } + case ARDUINO_EVENT_PROV_CRED_FAIL: + { Serial.println("\nProvisioning failed!\nPlease reset to factory and retry provisioning\n"); - if(sys_event->event_info.prov_fail_reason == WIFI_PROV_STA_AUTH_ERROR) - Serial.println("\nWi-Fi AP password incorrect"); + if (sys_event->event_info.prov_fail_reason == WIFI_PROV_STA_AUTH_ERROR) + Serial.println("\nWi-Fi AP password incorrect"); else - Serial.println("\nWi-Fi AP not found....Add API \" nvs_flash_erase() \" before beginProvision()"); + Serial.println("\nWi-Fi AP not found....Add API \" nvs_flash_erase() \" before beginProvision()"); break; - } + } case ARDUINO_EVENT_PROV_CRED_SUCCESS: - Serial.println("\nProvisioning Successful"); - break; + Serial.println("\nProvisioning Successful"); + break; case ARDUINO_EVENT_PROV_END: - Serial.println("\nProvisioning Ends"); - break; + Serial.println("\nProvisioning Ends"); + break; default: - break; - } + break; + } } void setup() { Serial.begin(115200); WiFi.onEvent(SysProvEvent); -// BLE Provisioning using the ESP SoftAP Prov works fine for any BLE SoC, incuding ESP32, ESP32S3 and ESP32C3. +// BLE Provisioning using the ESP SoftAP Prov works fine for any BLE SoC, including ESP32, ESP32S3 and ESP32C3. #if CONFIG_BLUEDROID_ENABLED && !defined(USE_SOFT_AP) - Serial.println("Begin Provisioning using BLE"); - // Sample uuid that user can pass during provisioning using BLE - uint8_t uuid[16] = {0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf, - 0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02 }; - WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name, service_key, uuid, reset_provisioned); - log_d("ble qr"); - WiFiProv.printQR(service_name, pop, "ble"); + Serial.println("Begin Provisioning using BLE"); + // Sample uuid that user can pass during provisioning using BLE + uint8_t uuid[16] = { 0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf, + 0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02 }; + WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name, service_key, uuid, reset_provisioned); + log_d("ble qr"); + WiFiProv.printQR(service_name, pop, "ble"); #else - Serial.println("Begin Provisioning using Soft AP"); - WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name, service_key); - log_d("wifi qr"); - WiFiProv.printQR(service_name, pop, "softap"); + Serial.println("Begin Provisioning using Soft AP"); + WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name, service_key); + log_d("wifi qr"); + WiFiProv.printQR(service_name, pop, "softap"); #endif } diff --git a/libraries/WiFiProv/src/WiFiProv.cpp b/libraries/WiFiProv/src/WiFiProv.cpp index 2b401b41f51..e94f87be660 100644 --- a/libraries/WiFiProv/src/WiFiProv.cpp +++ b/libraries/WiFiProv/src/WiFiProv.cpp @@ -1,21 +1,21 @@ /* WiFiProv.cpp - WiFiProv class for provisioning All rights reserved. - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - + */ #include "soc/soc_caps.h" #if SOC_WIFI_SUPPORTED @@ -29,7 +29,7 @@ #include #include #if __has_include("qrcode.h") - #include "qrcode.h" +#include "qrcode.h" #endif #include @@ -47,152 +47,165 @@ bool wifiLowLevelInit(bool persistent); #if CONFIG_BLUEDROID_ENABLED -static const uint8_t custom_service_uuid[16] = { 0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf, - 0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02, }; +static const uint8_t custom_service_uuid[16] = { + 0xb4, + 0xdf, + 0x5a, + 0x1c, + 0x3f, + 0x6b, + 0xf4, + 0xbf, + 0xea, + 0x4a, + 0x82, + 0x03, + 0x04, + 0x90, + 0x1a, + 0x02, +}; #endif #define SERV_NAME_PREFIX_PROV "PROV_" -static void get_device_service_name(prov_scheme_t prov_scheme, char *service_name, size_t max) -{ - uint8_t eth_mac[6] = {0,0,0,0,0,0}; - if(esp_wifi_get_mac((wifi_interface_t)WIFI_IF_STA, eth_mac) != ESP_OK){ - log_e("esp_wifi_get_mac failed!"); - return; - } +static void get_device_service_name(prov_scheme_t prov_scheme, char *service_name, size_t max) { + uint8_t eth_mac[6] = { 0, 0, 0, 0, 0, 0 }; + if (esp_wifi_get_mac((wifi_interface_t)WIFI_IF_STA, eth_mac) != ESP_OK) { + log_e("esp_wifi_get_mac failed!"); + return; + } #if CONFIG_IDF_TARGET_ESP32 && defined(CONFIG_BLUEDROID_ENABLED) - if(prov_scheme == WIFI_PROV_SCHEME_BLE) { - snprintf(service_name, max, "%s%02X%02X%02X",SERV_NAME_PREFIX_PROV, eth_mac[3], eth_mac[4], eth_mac[5]); - } else { + if (prov_scheme == WIFI_PROV_SCHEME_BLE) { + snprintf(service_name, max, "%s%02X%02X%02X", SERV_NAME_PREFIX_PROV, eth_mac[3], eth_mac[4], eth_mac[5]); + } else { #endif - snprintf(service_name, max, "%s%02X%02X%02X",SERV_NAME_PREFIX_PROV, eth_mac[3], eth_mac[4], eth_mac[5]); + snprintf(service_name, max, "%s%02X%02X%02X", SERV_NAME_PREFIX_PROV, eth_mac[3], eth_mac[4], eth_mac[5]); #if CONFIG_IDF_TARGET_ESP32 && defined(CONFIG_BLUEDROID_ENABLED) - } + } #endif } -void WiFiProvClass :: beginProvision(prov_scheme_t prov_scheme, scheme_handler_t scheme_handler, wifi_prov_security_t security, const char * pop, const char *service_name, const char *service_key, uint8_t * uuid, bool reset_provisioned) -{ - bool provisioned = false; - static char service_name_temp[32]; +void WiFiProvClass ::beginProvision(prov_scheme_t prov_scheme, scheme_handler_t scheme_handler, wifi_prov_security_t security, const char *pop, const char *service_name, const char *service_key, uint8_t *uuid, bool reset_provisioned) { + bool provisioned = false; + static char service_name_temp[32]; - wifi_prov_mgr_config_t config; + wifi_prov_mgr_config_t config; #if CONFIG_BLUEDROID_ENABLED - if(prov_scheme == WIFI_PROV_SCHEME_BLE) { - config.scheme = wifi_prov_scheme_ble; - } else { + if (prov_scheme == WIFI_PROV_SCHEME_BLE) { + config.scheme = wifi_prov_scheme_ble; + } else { #endif - config.scheme = wifi_prov_scheme_softap; + config.scheme = wifi_prov_scheme_softap; #if CONFIG_BLUEDROID_ENABLED - } + } - if(scheme_handler == WIFI_PROV_SCHEME_HANDLER_NONE){ + if (scheme_handler == WIFI_PROV_SCHEME_HANDLER_NONE) { #endif - wifi_prov_event_handler_t scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE; - memcpy(&config.scheme_event_handler, &scheme_event_handler, sizeof(wifi_prov_event_handler_t)); + wifi_prov_event_handler_t scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE; + memcpy(&config.scheme_event_handler, &scheme_event_handler, sizeof(wifi_prov_event_handler_t)); #if CONFIG_BLUEDROID_ENABLED - } else if(scheme_handler == WIFI_PROV_SCHEME_HANDLER_FREE_BTDM){ - wifi_prov_event_handler_t scheme_event_handler = WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM; - memcpy(&config.scheme_event_handler, &scheme_event_handler, sizeof(wifi_prov_event_handler_t)); - } else if(scheme_handler == WIFI_PROV_SCHEME_HANDLER_FREE_BT){ - wifi_prov_event_handler_t scheme_event_handler = WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BT; - memcpy(&config.scheme_event_handler, &scheme_event_handler, sizeof(wifi_prov_event_handler_t)); - } else if(scheme_handler == WIFI_PROV_SCHEME_HANDLER_FREE_BLE){ - wifi_prov_event_handler_t scheme_event_handler = WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BLE; - memcpy(&config.scheme_event_handler, &scheme_event_handler, sizeof(wifi_prov_event_handler_t)); - } else { - log_e("Unknown scheme handler!"); - return; - } + } else if (scheme_handler == WIFI_PROV_SCHEME_HANDLER_FREE_BTDM) { + wifi_prov_event_handler_t scheme_event_handler = WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM; + memcpy(&config.scheme_event_handler, &scheme_event_handler, sizeof(wifi_prov_event_handler_t)); + } else if (scheme_handler == WIFI_PROV_SCHEME_HANDLER_FREE_BT) { + wifi_prov_event_handler_t scheme_event_handler = WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BT; + memcpy(&config.scheme_event_handler, &scheme_event_handler, sizeof(wifi_prov_event_handler_t)); + } else if (scheme_handler == WIFI_PROV_SCHEME_HANDLER_FREE_BLE) { + wifi_prov_event_handler_t scheme_event_handler = WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BLE; + memcpy(&config.scheme_event_handler, &scheme_event_handler, sizeof(wifi_prov_event_handler_t)); + } else { + log_e("Unknown scheme handler!"); + return; + } #endif - config.app_event_handler.event_cb = NULL; - config.app_event_handler.user_data = NULL; - wifiLowLevelInit(true); - if(wifi_prov_mgr_init(config) != ESP_OK){ - log_e("wifi_prov_mgr_init failed!"); - return; - } - if(reset_provisioned){ - log_i("Resetting provisioned data."); - wifi_prov_mgr_reset_provisioning(); - }else if(wifi_prov_mgr_is_provisioned(&provisioned) != ESP_OK){ - log_e("wifi_prov_mgr_is_provisioned failed!"); - wifi_prov_mgr_deinit(); - return; - } - if(provisioned == false) { + config.app_event_handler.event_cb = NULL; + config.app_event_handler.user_data = NULL; + wifiLowLevelInit(true); + if (wifi_prov_mgr_init(config) != ESP_OK) { + log_e("wifi_prov_mgr_init failed!"); + return; + } + if (reset_provisioned) { + log_i("Resetting provisioned data."); + wifi_prov_mgr_reset_provisioning(); + } else if (wifi_prov_mgr_is_provisioned(&provisioned) != ESP_OK) { + log_e("wifi_prov_mgr_is_provisioned failed!"); + wifi_prov_mgr_deinit(); + return; + } + if (provisioned == false) { #if CONFIG_BLUEDROID_ENABLED - if(prov_scheme == WIFI_PROV_SCHEME_BLE) { - service_key = NULL; - if(uuid == NULL) { - uuid=(uint8_t *)custom_service_uuid; - } - wifi_prov_scheme_ble_set_service_uuid(uuid); - } + if (prov_scheme == WIFI_PROV_SCHEME_BLE) { + service_key = NULL; + if (uuid == NULL) { + uuid = (uint8_t *)custom_service_uuid; + } + wifi_prov_scheme_ble_set_service_uuid(uuid); + } #endif - if(service_name == NULL) { - get_device_service_name(prov_scheme, service_name_temp, 32); - service_name = (const char *)service_name_temp; - } + if (service_name == NULL) { + get_device_service_name(prov_scheme, service_name_temp, 32); + service_name = (const char *)service_name_temp; + } #if CONFIG_BLUEDROID_ENABLED - if(prov_scheme == WIFI_PROV_SCHEME_BLE) { - log_i("Starting AP using BLE. service_name : %s, pop : %s",service_name,pop); - } else { + if (prov_scheme == WIFI_PROV_SCHEME_BLE) { + log_i("Starting AP using BLE. service_name : %s, pop : %s", service_name, pop); + } else { #endif - if(service_key == NULL) { - log_i("Starting provisioning AP using SOFTAP. service_name : %s, pop : %s",service_name,pop); - } else { - log_i("Starting provisioning AP using SOFTAP. service_name : %s, password : %s, pop : %s",service_name,service_key,pop); - } + if (service_key == NULL) { + log_i("Starting provisioning AP using SOFTAP. service_name : %s, pop : %s", service_name, pop); + } else { + log_i("Starting provisioning AP using SOFTAP. service_name : %s, password : %s, pop : %s", service_name, service_key, pop); + } #if CONFIG_BLUEDROID_ENABLED - } + } #endif - if(wifi_prov_mgr_start_provisioning(security, pop, service_name, service_key) != ESP_OK){ - log_e("wifi_prov_mgr_start_provisioning failed!"); - return; - } - } else { - log_i("Already Provisioned"); + if (wifi_prov_mgr_start_provisioning(security, pop, service_name, service_key) != ESP_OK) { + log_e("wifi_prov_mgr_start_provisioning failed!"); + return; + } + } else { + log_i("Already Provisioned"); #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO - static wifi_config_t conf; - esp_wifi_get_config((wifi_interface_t)WIFI_IF_STA,&conf); - log_i("Attempting connect to AP: %s\n",conf.sta.ssid); + static wifi_config_t conf; + esp_wifi_get_config((wifi_interface_t)WIFI_IF_STA, &conf); + log_i("Attempting connect to AP: %s\n", conf.sta.ssid); #endif - esp_wifi_start(); - wifi_prov_mgr_deinit(); - WiFi.begin(); - } + esp_wifi_start(); + wifi_prov_mgr_deinit(); + WiFi.begin(); + } } // Copied from IDF example -void WiFiProvClass :: printQR(const char *name, const char *pop, const char *transport){ - if (!name || !transport) { - log_w("Cannot generate QR code payload. Data missing."); - return; - } - char payload[150] = {0}; - if (pop) { - snprintf(payload, sizeof(payload), "{\"ver\":\"%s\",\"name\":\"%s\"" \ - ",\"pop\":\"%s\",\"transport\":\"%s\"}", - "v1", name, pop, transport); - } else { - snprintf(payload, sizeof(payload), "{\"ver\":\"%s\",\"name\":\"%s\"" \ - ",\"transport\":\"%s\"}", - "v1", name, transport); - } +void WiFiProvClass ::printQR(const char *name, const char *pop, const char *transport) { + if (!name || !transport) { + log_w("Cannot generate QR code payload. Data missing."); + return; + } + char payload[150] = { 0 }; + if (pop) { + snprintf(payload, sizeof(payload), "{\"ver\":\"%s\",\"name\":\"%s\"" + ",\"pop\":\"%s\",\"transport\":\"%s\"}", + "v1", name, pop, transport); + } else { + snprintf(payload, sizeof(payload), "{\"ver\":\"%s\",\"name\":\"%s\"" + ",\"transport\":\"%s\"}", + "v1", name, transport); + } #if __has_include("qrcode.h") - log_i("Scan this QR code from the provisioning application for Provisioning."); - esp_qrcode_config_t cfg = ESP_QRCODE_CONFIG_DEFAULT(); - esp_qrcode_generate(&cfg, payload); + log_i("Scan this QR code from the provisioning application for Provisioning."); + esp_qrcode_config_t cfg = ESP_QRCODE_CONFIG_DEFAULT(); + esp_qrcode_generate(&cfg, payload); #else - log_i("If QR code is not visible, copy paste the below URL in a browser.\n%s?data=%s", "https://espressif.github.io/esp-jumpstart/qrcode.html", payload); - log_i("If you are using Arduino as IDF component, install ESP Rainmaker:\nhttps://github.com/espressif/esp-rainmaker"); + log_i("If QR code is not visible, copy paste the below URL in a browser.\n%s?data=%s", "https://espressif.github.io/esp-jumpstart/qrcode.html", payload); + log_i("If you are using Arduino as IDF component, install ESP Rainmaker:\nhttps://github.com/espressif/esp-rainmaker"); #endif } WiFiProvClass WiFiProv; #endif /* SOC_WIFI_SUPPORTED */ - diff --git a/libraries/WiFiProv/src/WiFiProv.h b/libraries/WiFiProv/src/WiFiProv.h index 014d636be9e..8b768a32c73 100644 --- a/libraries/WiFiProv/src/WiFiProv.h +++ b/libraries/WiFiProv/src/WiFiProv.h @@ -1,17 +1,17 @@ - /* +/* WiFiProv.h - Base class for provisioning support All right reserved. - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA @@ -26,32 +26,31 @@ #include "wifi_provisioning/manager.h" //Select the scheme using which you want to provision typedef enum { - WIFI_PROV_SCHEME_SOFTAP, + WIFI_PROV_SCHEME_SOFTAP, #if CONFIG_BLUEDROID_ENABLED - WIFI_PROV_SCHEME_BLE, + WIFI_PROV_SCHEME_BLE, #endif - WIFI_PROV_SCHEME_MAX + WIFI_PROV_SCHEME_MAX } prov_scheme_t; typedef enum { - WIFI_PROV_SCHEME_HANDLER_NONE, + WIFI_PROV_SCHEME_HANDLER_NONE, #if CONFIG_BLUEDROID_ENABLED - WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, - WIFI_PROV_SCHEME_HANDLER_FREE_BLE, - WIFI_PROV_SCHEME_HANDLER_FREE_BT, + WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, + WIFI_PROV_SCHEME_HANDLER_FREE_BLE, + WIFI_PROV_SCHEME_HANDLER_FREE_BT, #endif - WIFI_PROV_SCHEME_HANDLER_MAX + WIFI_PROV_SCHEME_HANDLER_MAX } scheme_handler_t; -//Provisioning class -class WiFiProvClass -{ - public: +//Provisioning class +class WiFiProvClass { +public: - void beginProvision(prov_scheme_t prov_scheme = WIFI_PROV_SCHEME_SOFTAP, scheme_handler_t scheme_handler = WIFI_PROV_SCHEME_HANDLER_NONE, - wifi_prov_security_t security = WIFI_PROV_SECURITY_1, const char * pop = "abcd1234", const char * service_name = NULL, - const char * service_key = NULL, uint8_t *uuid = NULL, bool reset_provisioned = false); - void printQR(const char *name, const char *pop, const char *transport); + void beginProvision(prov_scheme_t prov_scheme = WIFI_PROV_SCHEME_SOFTAP, scheme_handler_t scheme_handler = WIFI_PROV_SCHEME_HANDLER_NONE, + wifi_prov_security_t security = WIFI_PROV_SECURITY_1, const char *pop = "abcd1234", const char *service_name = NULL, + const char *service_key = NULL, uint8_t *uuid = NULL, bool reset_provisioned = false); + void printQR(const char *name, const char *pop, const char *transport); }; extern WiFiProvClass WiFiProv; diff --git a/libraries/Wire/examples/WireMaster/WireMaster.ino b/libraries/Wire/examples/WireMaster/WireMaster.ino index ba5bca5c168..ea603e3c649 100644 --- a/libraries/Wire/examples/WireMaster/WireMaster.ino +++ b/libraries/Wire/examples/WireMaster/WireMaster.ino @@ -18,11 +18,11 @@ void loop() { Wire.printf("Hello World! %lu", i++); uint8_t error = Wire.endTransmission(true); Serial.printf("endTransmission: %u\n", error); - + //Read 16 bytes from the slave uint8_t bytesReceived = Wire.requestFrom(I2C_DEV_ADDR, 16); Serial.printf("requestFrom: %u\n", bytesReceived); - if((bool)bytesReceived){ //If received more than zero bytes + if ((bool)bytesReceived) { //If received more than zero bytes uint8_t temp[bytesReceived]; Wire.readBytes(temp, bytesReceived); log_print_buf(temp, bytesReceived); diff --git a/libraries/Wire/examples/WireScan/WireScan.ino b/libraries/Wire/examples/WireScan/WireScan.ino index 4f2750b1db8..59f17af60fc 100644 --- a/libraries/Wire/examples/WireScan/WireScan.ino +++ b/libraries/Wire/examples/WireScan/WireScan.ino @@ -12,17 +12,17 @@ void loop() { delay(5000); Serial.println("Scanning for I2C devices ..."); - for(address = 0x01; address < 0x7f; address++){ + for (address = 0x01; address < 0x7f; address++) { Wire.beginTransmission(address); error = Wire.endTransmission(); - if (error == 0){ + if (error == 0) { Serial.printf("I2C device found at address 0x%02X\n", address); nDevices++; - } else if(error != 2){ + } else if (error != 2) { Serial.printf("Error %d at address 0x%02X\n", error, address); } } - if (nDevices == 0){ + if (nDevices == 0) { Serial.println("No I2C devices found"); } } diff --git a/libraries/Wire/examples/WireSlave/WireSlave.ino b/libraries/Wire/examples/WireSlave/WireSlave.ino index e689e189a7a..ff6bf39061c 100644 --- a/libraries/Wire/examples/WireSlave/WireSlave.ino +++ b/libraries/Wire/examples/WireSlave/WireSlave.ino @@ -4,15 +4,15 @@ uint32_t i = 0; -void onRequest(){ +void onRequest() { Wire.print(i++); Wire.print(" Packets."); Serial.println("onRequest"); } -void onReceive(int len){ +void onReceive(int len) { Serial.printf("onReceive[%d]: ", len); - while(Wire.available()){ + while (Wire.available()) { Serial.write(Wire.read()); } Serial.println(); @@ -33,5 +33,4 @@ void setup() { } void loop() { - } diff --git a/libraries/Wire/keywords.txt b/libraries/Wire/keywords.txt index a2fbf317e95..80d5f0d61a2 100644 --- a/libraries/Wire/keywords.txt +++ b/libraries/Wire/keywords.txt @@ -32,4 +32,3 @@ TwoWire KEYWORD2 ####################################### # Constants (LITERAL1) ####################################### - diff --git a/libraries/Wire/library.properties b/libraries/Wire/library.properties index f97fa0d0293..79fddb63065 100644 --- a/libraries/Wire/library.properties +++ b/libraries/Wire/library.properties @@ -2,7 +2,7 @@ name=Wire version=2.0.0 author=Hristo Gochkov maintainer=Hristo Gochkov -sentence=Allows the communication between devices or sensors connected via Two Wire Interface Bus. For esp8266 boards. +sentence=Allows the communication between devices or sensors connected via Two Wire Interface Bus. For esp8266 boards. paragraph= category=Signal Input/Output url=http://arduino.cc/en/Reference/Wire diff --git a/libraries/Wire/src/Wire.cpp b/libraries/Wire/src/Wire.cpp index ac8c353575f..b21dd54f890 100644 --- a/libraries/Wire/src/Wire.cpp +++ b/libraries/Wire/src/Wire.cpp @@ -39,414 +39,389 @@ extern "C" { #include "Arduino.h" TwoWire::TwoWire(uint8_t bus_num) - :num(bus_num & 1) - ,sda(-1) - ,scl(-1) - ,bufferSize(I2C_BUFFER_LENGTH) // default Wire Buffer Size - ,rxBuffer(NULL) - ,rxIndex(0) - ,rxLength(0) - ,txBuffer(NULL) - ,txLength(0) - ,txAddress(0) - ,_timeOutMillis(50) - ,nonStop(false) + : num(bus_num & 1), sda(-1), scl(-1), bufferSize(I2C_BUFFER_LENGTH) // default Wire Buffer Size + , + rxBuffer(NULL), rxIndex(0), rxLength(0), txBuffer(NULL), txLength(0), txAddress(0), _timeOutMillis(50), nonStop(false) #if !CONFIG_DISABLE_HAL_LOCKS - ,currentTaskHandle(NULL) - ,lock(NULL) + , + currentTaskHandle(NULL), lock(NULL) #endif #if SOC_I2C_SUPPORT_SLAVE - ,is_slave(false) - ,user_onRequest(NULL) - ,user_onReceive(NULL) + , + is_slave(false), user_onRequest(NULL), user_onReceive(NULL) #endif /* SOC_I2C_SUPPORT_SLAVE */ -{} - -TwoWire::~TwoWire() { - end(); +} + +TwoWire::~TwoWire() { + end(); #if !CONFIG_DISABLE_HAL_LOCKS - if(lock != NULL){ - vSemaphoreDelete(lock); - } + if (lock != NULL) { + vSemaphoreDelete(lock); + } #endif } -bool TwoWire::initPins(int sdaPin, int sclPin) -{ - if(sdaPin < 0) { // default param passed - if(num == 0) { - if(sda==-1) { - sdaPin = SDA; //use Default Pin - } else { - sdaPin = sda; // reuse prior pin - } - } else { - if(sda==-1) { +bool TwoWire::initPins(int sdaPin, int sclPin) { + if (sdaPin < 0) { // default param passed + if (num == 0) { + if (sda == -1) { + sdaPin = SDA; //use Default Pin + } else { + sdaPin = sda; // reuse prior pin + } + } else { + if (sda == -1) { #ifdef WIRE1_PIN_DEFINED - sdaPin = SDA1; + sdaPin = SDA1; #else - log_e("no Default SDA Pin for Second Peripheral"); - return false; //no Default pin for Second Peripheral + log_e("no Default SDA Pin for Second Peripheral"); + return false; //no Default pin for Second Peripheral #endif - } else { - sdaPin = sda; // reuse prior pin - } - } - } - - if(sclPin < 0) { // default param passed - if(num == 0) { - if(scl == -1) { - sclPin = SCL; // use Default pin - } else { - sclPin = scl; // reuse prior pin - } - } else { - if(scl == -1) { + } else { + sdaPin = sda; // reuse prior pin + } + } + } + + if (sclPin < 0) { // default param passed + if (num == 0) { + if (scl == -1) { + sclPin = SCL; // use Default pin + } else { + sclPin = scl; // reuse prior pin + } + } else { + if (scl == -1) { #ifdef WIRE1_PIN_DEFINED - sclPin = SCL1; + sclPin = SCL1; #else - log_e("no Default SCL Pin for Second Peripheral"); - return false; //no Default pin for Second Peripheral + log_e("no Default SCL Pin for Second Peripheral"); + return false; //no Default pin for Second Peripheral #endif - } else { - sclPin = scl; // reuse prior pin - } - } + } else { + sclPin = scl; // reuse prior pin + } } + } - sda = sdaPin; - scl = sclPin; - return true; + sda = sdaPin; + scl = sclPin; + return true; } -bool TwoWire::setPins(int sdaPin, int sclPin) -{ +bool TwoWire::setPins(int sdaPin, int sclPin) { #if !CONFIG_DISABLE_HAL_LOCKS - if(lock == NULL){ - lock = xSemaphoreCreateMutex(); - if(lock == NULL){ - log_e("xSemaphoreCreateMutex failed"); - return false; - } - } - //acquire lock - if(xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE){ - log_e("could not acquire lock"); - return false; - } + if (lock == NULL) { + lock = xSemaphoreCreateMutex(); + if (lock == NULL) { + log_e("xSemaphoreCreateMutex failed"); + return false; + } + } + //acquire lock + if (xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE) { + log_e("could not acquire lock"); + return false; + } #endif - if(!i2cIsInit(num)){ - initPins(sdaPin, sclPin); - } else { - log_e("bus already initialized. change pins only when not."); - } + if (!i2cIsInit(num)) { + initPins(sdaPin, sclPin); + } else { + log_e("bus already initialized. change pins only when not."); + } #if !CONFIG_DISABLE_HAL_LOCKS - //release lock - xSemaphoreGive(lock); + //release lock + xSemaphoreGive(lock); #endif - return !i2cIsInit(num); + return !i2cIsInit(num); } -bool TwoWire::allocateWireBuffer() -{ - // or both buffer can be allocated or none will be +bool TwoWire::allocateWireBuffer() { + // or both buffer can be allocated or none will be + if (rxBuffer == NULL) { + rxBuffer = (uint8_t *)malloc(bufferSize); if (rxBuffer == NULL) { - rxBuffer = (uint8_t *)malloc(bufferSize); - if (rxBuffer == NULL) { - log_e("Can't allocate memory for I2C_%d rxBuffer", num); - return false; - } + log_e("Can't allocate memory for I2C_%d rxBuffer", num); + return false; } + } + if (txBuffer == NULL) { + txBuffer = (uint8_t *)malloc(bufferSize); if (txBuffer == NULL) { - txBuffer = (uint8_t *)malloc(bufferSize); - if (txBuffer == NULL) { - log_e("Can't allocate memory for I2C_%d txBuffer", num); - freeWireBuffer(); // free rxBuffer for safety! - return false; - } + log_e("Can't allocate memory for I2C_%d txBuffer", num); + freeWireBuffer(); // free rxBuffer for safety! + return false; } - // in case both were allocated before, they must have the same size. All good. - return true; + } + // in case both were allocated before, they must have the same size. All good. + return true; } -void TwoWire::freeWireBuffer() -{ - if (rxBuffer != NULL) { - free(rxBuffer); - rxBuffer = NULL; - } - if (txBuffer != NULL) { - free(txBuffer); - txBuffer = NULL; - } +void TwoWire::freeWireBuffer() { + if (rxBuffer != NULL) { + free(rxBuffer); + rxBuffer = NULL; + } + if (txBuffer != NULL) { + free(txBuffer); + txBuffer = NULL; + } } -size_t TwoWire::setBufferSize(size_t bSize) -{ - // Maximum size .... HEAP limited ;-) - if (bSize < 32) { // 32 bytes is the I2C FIFO Len for ESP32/S2/S3/C3 - log_e("Minimum Wire Buffer size is 32 bytes"); - return 0; - } +size_t TwoWire::setBufferSize(size_t bSize) { + // Maximum size .... HEAP limited ;-) + if (bSize < 32) { // 32 bytes is the I2C FIFO Len for ESP32/S2/S3/C3 + log_e("Minimum Wire Buffer size is 32 bytes"); + return 0; + } #if !CONFIG_DISABLE_HAL_LOCKS - if(lock == NULL){ - lock = xSemaphoreCreateMutex(); - if(lock == NULL){ - log_e("xSemaphoreCreateMutex failed"); - return 0; - } - } - //acquire lock - if(xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE){ - log_e("could not acquire lock"); - return 0; - } + if (lock == NULL) { + lock = xSemaphoreCreateMutex(); + if (lock == NULL) { + log_e("xSemaphoreCreateMutex failed"); + return 0; + } + } + //acquire lock + if (xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE) { + log_e("could not acquire lock"); + return 0; + } #endif - // allocateWireBuffer allocates memory for both pointers or just free them - if (rxBuffer != NULL || txBuffer != NULL) { - // if begin() has been already executed, memory size changes... data may be lost. We don't care! :^) - if (bSize != bufferSize) { - // we want a new buffer size ... just reset buffer pointers and allocate new ones - freeWireBuffer(); - bufferSize = bSize; - if (!allocateWireBuffer()) { - // failed! Error message already issued - bSize = 0; // returns error - log_e("Buffer allocation failed"); - } - } // else nothing changes, all set! - } else { - // no memory allocated yet, just change the size value - allocation in begin() - bufferSize = bSize; - } + // allocateWireBuffer allocates memory for both pointers or just free them + if (rxBuffer != NULL || txBuffer != NULL) { + // if begin() has been already executed, memory size changes... data may be lost. We don't care! :^) + if (bSize != bufferSize) { + // we want a new buffer size ... just reset buffer pointers and allocate new ones + freeWireBuffer(); + bufferSize = bSize; + if (!allocateWireBuffer()) { + // failed! Error message already issued + bSize = 0; // returns error + log_e("Buffer allocation failed"); + } + } // else nothing changes, all set! + } else { + // no memory allocated yet, just change the size value - allocation in begin() + bufferSize = bSize; + } #if !CONFIG_DISABLE_HAL_LOCKS - //release lock - xSemaphoreGive(lock); - + //release lock + xSemaphoreGive(lock); + #endif - return bSize; + return bSize; } #if SOC_I2C_SUPPORT_SLAVE // Slave Begin -bool TwoWire::begin(uint8_t addr, int sdaPin, int sclPin, uint32_t frequency) -{ - bool started = false; +bool TwoWire::begin(uint8_t addr, int sdaPin, int sclPin, uint32_t frequency) { + bool started = false; #if !CONFIG_DISABLE_HAL_LOCKS - if(lock == NULL){ - lock = xSemaphoreCreateMutex(); - if(lock == NULL){ - log_e("xSemaphoreCreateMutex failed"); - return false; - } - } - //acquire lock - if(xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE){ - log_e("could not acquire lock"); - return false; - } + if (lock == NULL) { + lock = xSemaphoreCreateMutex(); + if (lock == NULL) { + log_e("xSemaphoreCreateMutex failed"); + return false; + } + } + //acquire lock + if (xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE) { + log_e("could not acquire lock"); + return false; + } #endif - if(is_slave){ - log_w("Bus already started in Slave Mode."); - started = true; - goto end; - } - if(i2cIsInit(num)){ - log_e("Bus already started in Master Mode."); - goto end; - } - if (!allocateWireBuffer()) { - // failed! Error Message already issued - goto end; - } - if(!initPins(sdaPin, sclPin)){ - goto end; - } - i2cSlaveAttachCallbacks(num, onRequestService, onReceiveService, this); - if(i2cSlaveInit(num, sda, scl, addr, frequency, bufferSize, bufferSize) != ESP_OK){ - log_e("Slave Init ERROR"); - goto end; - } - is_slave = true; + if (is_slave) { + log_w("Bus already started in Slave Mode."); started = true; + goto end; + } + if (i2cIsInit(num)) { + log_e("Bus already started in Master Mode."); + goto end; + } + if (!allocateWireBuffer()) { + // failed! Error Message already issued + goto end; + } + if (!initPins(sdaPin, sclPin)) { + goto end; + } + i2cSlaveAttachCallbacks(num, onRequestService, onReceiveService, this); + if (i2cSlaveInit(num, sda, scl, addr, frequency, bufferSize, bufferSize) != ESP_OK) { + log_e("Slave Init ERROR"); + goto end; + } + is_slave = true; + started = true; end: - if (!started) freeWireBuffer(); + if (!started) freeWireBuffer(); #if !CONFIG_DISABLE_HAL_LOCKS - //release lock - xSemaphoreGive(lock); + //release lock + xSemaphoreGive(lock); #endif - return started; + return started; } #endif /* SOC_I2C_SUPPORT_SLAVE */ // Master Begin -bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency) -{ - bool started = false; - esp_err_t err = ESP_OK; +bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency) { + bool started = false; + esp_err_t err = ESP_OK; #if !CONFIG_DISABLE_HAL_LOCKS - if(lock == NULL){ - lock = xSemaphoreCreateMutex(); - if(lock == NULL){ - log_e("xSemaphoreCreateMutex failed"); - return false; - } - } - //acquire lock - if(xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE){ - log_e("could not acquire lock"); - return false; - } + if (lock == NULL) { + lock = xSemaphoreCreateMutex(); + if (lock == NULL) { + log_e("xSemaphoreCreateMutex failed"); + return false; + } + } + //acquire lock + if (xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE) { + log_e("could not acquire lock"); + return false; + } #endif #if SOC_I2C_SUPPORT_SLAVE - if(is_slave){ - log_e("Bus already started in Slave Mode."); - goto end; - } + if (is_slave) { + log_e("Bus already started in Slave Mode."); + goto end; + } #endif /* SOC_I2C_SUPPORT_SLAVE */ - if(i2cIsInit(num)){ - log_w("Bus already started in Master Mode."); - started = true; - goto end; - } - if (!allocateWireBuffer()) { - // failed! Error Message already issued - goto end; - } - if(!initPins(sdaPin, sclPin)){ - goto end; - } - err = i2cInit(num, sda, scl, frequency); - started = (err == ESP_OK); + if (i2cIsInit(num)) { + log_w("Bus already started in Master Mode."); + started = true; + goto end; + } + if (!allocateWireBuffer()) { + // failed! Error Message already issued + goto end; + } + if (!initPins(sdaPin, sclPin)) { + goto end; + } + err = i2cInit(num, sda, scl, frequency); + started = (err == ESP_OK); end: - if (!started) freeWireBuffer(); + if (!started) freeWireBuffer(); #if !CONFIG_DISABLE_HAL_LOCKS - //release lock - xSemaphoreGive(lock); + //release lock + xSemaphoreGive(lock); #endif - return started; - + return started; } -bool TwoWire::end() -{ - esp_err_t err = ESP_OK; +bool TwoWire::end() { + esp_err_t err = ESP_OK; #if !CONFIG_DISABLE_HAL_LOCKS - if(lock != NULL){ - //acquire lock - if(xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE){ - log_e("could not acquire lock"); - return false; - } + if (lock != NULL) { + //acquire lock + if (xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE) { + log_e("could not acquire lock"); + return false; + } #endif #if SOC_I2C_SUPPORT_SLAVE - if(is_slave){ - err = i2cSlaveDeinit(num); - if(err == ESP_OK){ - is_slave = false; - } - } else + if (is_slave) { + err = i2cSlaveDeinit(num); + if (err == ESP_OK) { + is_slave = false; + } + } else #endif /* SOC_I2C_SUPPORT_SLAVE */ - if(i2cIsInit(num)){ - err = i2cDeinit(num); - } - freeWireBuffer(); + if (i2cIsInit(num)) { + err = i2cDeinit(num); + } + freeWireBuffer(); #if !CONFIG_DISABLE_HAL_LOCKS - //release lock - xSemaphoreGive(lock); - } + //release lock + xSemaphoreGive(lock); + } #endif - return (err == ESP_OK); + return (err == ESP_OK); } -uint32_t TwoWire::getClock() -{ - uint32_t frequency = 0; +uint32_t TwoWire::getClock() { + uint32_t frequency = 0; #if !CONFIG_DISABLE_HAL_LOCKS - //acquire lock - if(lock == NULL || xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE){ - log_e("could not acquire lock"); - } else { + //acquire lock + if (lock == NULL || xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE) { + log_e("could not acquire lock"); + } else { #endif #if SOC_I2C_SUPPORT_SLAVE - if(is_slave){ - log_e("Bus is in Slave Mode"); - } else + if (is_slave) { + log_e("Bus is in Slave Mode"); + } else #endif /* SOC_I2C_SUPPORT_SLAVE */ - { - i2cGetClock(num, &frequency); - } -#if !CONFIG_DISABLE_HAL_LOCKS - //release lock - xSemaphoreGive(lock); + { + i2cGetClock(num, &frequency); } +#if !CONFIG_DISABLE_HAL_LOCKS + //release lock + xSemaphoreGive(lock); + } #endif - return frequency; + return frequency; } -bool TwoWire::setClock(uint32_t frequency) -{ - esp_err_t err = ESP_OK; +bool TwoWire::setClock(uint32_t frequency) { + esp_err_t err = ESP_OK; #if !CONFIG_DISABLE_HAL_LOCKS - //acquire lock - if(lock == NULL || xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE){ - log_e("could not acquire lock"); - return false; - } + //acquire lock + if (lock == NULL || xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE) { + log_e("could not acquire lock"); + return false; + } #endif #if SOC_I2C_SUPPORT_SLAVE - if(is_slave){ - log_e("Bus is in Slave Mode"); - err = ESP_FAIL; - } else + if (is_slave) { + log_e("Bus is in Slave Mode"); + err = ESP_FAIL; + } else #endif /* SOC_I2C_SUPPORT_SLAVE */ - { - err = i2cSetClock(num, frequency); - } + { + err = i2cSetClock(num, frequency); + } #if !CONFIG_DISABLE_HAL_LOCKS - //release lock - xSemaphoreGive(lock); + //release lock + xSemaphoreGive(lock); #endif - return (err == ESP_OK); + return (err == ESP_OK); } -void TwoWire::setTimeOut(uint16_t timeOutMillis) -{ - _timeOutMillis = timeOutMillis; +void TwoWire::setTimeOut(uint16_t timeOutMillis) { + _timeOutMillis = timeOutMillis; } -uint16_t TwoWire::getTimeOut() -{ - return _timeOutMillis; +uint16_t TwoWire::getTimeOut() { + return _timeOutMillis; } -void TwoWire::beginTransmission(uint8_t address) -{ +void TwoWire::beginTransmission(uint8_t address) { #if SOC_I2C_SUPPORT_SLAVE - if(is_slave){ - log_e("Bus is in Slave Mode"); - return; - } + if (is_slave) { + log_e("Bus is in Slave Mode"); + return; + } #endif /* SOC_I2C_SUPPORT_SLAVE */ #if !CONFIG_DISABLE_HAL_LOCKS - TaskHandle_t task = xTaskGetCurrentTaskHandle(); - if (currentTaskHandle != task) - { - //acquire lock - if(lock == NULL || xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE){ - log_e("could not acquire lock"); - return; - } - currentTaskHandle = task; + TaskHandle_t task = xTaskGetCurrentTaskHandle(); + if (currentTaskHandle != task) { + //acquire lock + if (lock == NULL || xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE) { + log_e("could not acquire lock"); + return; } + currentTaskHandle = task; + } #endif - nonStop = false; - txAddress = address; - txLength = 0; + nonStop = false; + txAddress = address; + txLength = 0; } /* @@ -459,225 +434,209 @@ endTransmission() returns: 4: other error. 5: timeout */ -uint8_t TwoWire::endTransmission(bool sendStop) -{ +uint8_t TwoWire::endTransmission(bool sendStop) { #if SOC_I2C_SUPPORT_SLAVE - if(is_slave){ - log_e("Bus is in Slave Mode"); - return 4; - } + if (is_slave) { + log_e("Bus is in Slave Mode"); + return 4; + } #endif /* SOC_I2C_SUPPORT_SLAVE */ - if (txBuffer == NULL){ - log_e("NULL TX buffer pointer"); - return 4; - } - esp_err_t err = ESP_OK; - if(sendStop){ - err = i2cWrite(num, txAddress, txBuffer, txLength, _timeOutMillis); + if (txBuffer == NULL) { + log_e("NULL TX buffer pointer"); + return 4; + } + esp_err_t err = ESP_OK; + if (sendStop) { + err = i2cWrite(num, txAddress, txBuffer, txLength, _timeOutMillis); #if !CONFIG_DISABLE_HAL_LOCKS - currentTaskHandle = NULL; - //release lock - xSemaphoreGive(lock); + currentTaskHandle = NULL; + //release lock + xSemaphoreGive(lock); #endif - } else { - //mark as non-stop - nonStop = true; - } - switch(err){ - case ESP_OK: return 0; - case ESP_FAIL: return 2; - case ESP_ERR_TIMEOUT: return 5; - default: break; - } - return 4; + } else { + //mark as non-stop + nonStop = true; + } + switch (err) { + case ESP_OK: return 0; + case ESP_FAIL: return 2; + case ESP_ERR_TIMEOUT: return 5; + default: break; + } + return 4; } -uint8_t TwoWire::endTransmission() -{ - return endTransmission(true); +uint8_t TwoWire::endTransmission() { + return endTransmission(true); } -size_t TwoWire::requestFrom(uint8_t address, size_t size, bool sendStop) -{ +size_t TwoWire::requestFrom(uint8_t address, size_t size, bool sendStop) { #if SOC_I2C_SUPPORT_SLAVE - if(is_slave){ - log_e("Bus is in Slave Mode"); - return 0; - } + if (is_slave) { + log_e("Bus is in Slave Mode"); + return 0; + } #endif /* SOC_I2C_SUPPORT_SLAVE */ - if (rxBuffer == NULL || txBuffer == NULL){ - log_e("NULL buffer pointer"); - return 0; - } - esp_err_t err = ESP_OK; + if (rxBuffer == NULL || txBuffer == NULL) { + log_e("NULL buffer pointer"); + return 0; + } + esp_err_t err = ESP_OK; #if !CONFIG_DISABLE_HAL_LOCKS - TaskHandle_t task = xTaskGetCurrentTaskHandle(); - if (currentTaskHandle != task) - { - //acquire lock - if(lock == NULL || xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE){ - log_e("could not acquire lock"); - return 0; - } - currentTaskHandle = task; + TaskHandle_t task = xTaskGetCurrentTaskHandle(); + if (currentTaskHandle != task) { + //acquire lock + if (lock == NULL || xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE) { + log_e("could not acquire lock"); + return 0; } -#endif - if(nonStop){ - if(address != txAddress){ - log_e("Unfinished Repeated Start transaction! Expected address do not match! %u != %u", address, txAddress); + currentTaskHandle = task; + } +#endif + if (nonStop) { + if (address != txAddress) { + log_e("Unfinished Repeated Start transaction! Expected address do not match! %u != %u", address, txAddress); #if !CONFIG_DISABLE_HAL_LOCKS - currentTaskHandle = NULL; - //release lock - xSemaphoreGive(lock); + currentTaskHandle = NULL; + //release lock + xSemaphoreGive(lock); #endif - return 0; - } - nonStop = false; - rxIndex = 0; - rxLength = 0; - err = i2cWriteReadNonStop(num, address, txBuffer, txLength, rxBuffer, size, _timeOutMillis, &rxLength); - if(err){ - log_e("i2cWriteReadNonStop returned Error %d", err); - } - } else { - rxIndex = 0; - rxLength = 0; - err = i2cRead(num, address, rxBuffer, size, _timeOutMillis, &rxLength); - if(err){ - log_e("i2cRead returned Error %d", err); - } + return 0; } + nonStop = false; + rxIndex = 0; + rxLength = 0; + err = i2cWriteReadNonStop(num, address, txBuffer, txLength, rxBuffer, size, _timeOutMillis, &rxLength); + if (err) { + log_e("i2cWriteReadNonStop returned Error %d", err); + } + } else { + rxIndex = 0; + rxLength = 0; + err = i2cRead(num, address, rxBuffer, size, _timeOutMillis, &rxLength); + if (err) { + log_e("i2cRead returned Error %d", err); + } + } #if !CONFIG_DISABLE_HAL_LOCKS - currentTaskHandle = NULL; - //release lock - xSemaphoreGive(lock); + currentTaskHandle = NULL; + //release lock + xSemaphoreGive(lock); #endif - return rxLength; + return rxLength; } -size_t TwoWire::requestFrom(uint8_t address, size_t size){ - return requestFrom(address, size, true); +size_t TwoWire::requestFrom(uint8_t address, size_t size) { + return requestFrom(address, size, true); } -size_t TwoWire::write(uint8_t data) -{ - if (txBuffer == NULL){ - log_e("NULL TX buffer pointer"); - return 0; - } - if(txLength >= bufferSize) { - return 0; - } - txBuffer[txLength++] = data; - return 1; +size_t TwoWire::write(uint8_t data) { + if (txBuffer == NULL) { + log_e("NULL TX buffer pointer"); + return 0; + } + if (txLength >= bufferSize) { + return 0; + } + txBuffer[txLength++] = data; + return 1; } -size_t TwoWire::write(const uint8_t *data, size_t quantity) -{ - for(size_t i = 0; i < quantity; ++i) { - if(!write(data[i])) { - return i; - } +size_t TwoWire::write(const uint8_t *data, size_t quantity) { + for (size_t i = 0; i < quantity; ++i) { + if (!write(data[i])) { + return i; } - return quantity; - + } + return quantity; } -int TwoWire::available() -{ - int result = rxLength - rxIndex; - return result; +int TwoWire::available() { + int result = rxLength - rxIndex; + return result; } -int TwoWire::read() -{ - int value = -1; - if (rxBuffer == NULL){ - log_e("NULL RX buffer pointer"); - return value; - } - if(rxIndex < rxLength) { - value = rxBuffer[rxIndex++]; - } +int TwoWire::read() { + int value = -1; + if (rxBuffer == NULL) { + log_e("NULL RX buffer pointer"); return value; + } + if (rxIndex < rxLength) { + value = rxBuffer[rxIndex++]; + } + return value; } -int TwoWire::peek() -{ - int value = -1; - if (rxBuffer == NULL){ - log_e("NULL RX buffer pointer"); - return value; - } - if(rxIndex < rxLength) { - value = rxBuffer[rxIndex]; - } +int TwoWire::peek() { + int value = -1; + if (rxBuffer == NULL) { + log_e("NULL RX buffer pointer"); return value; + } + if (rxIndex < rxLength) { + value = rxBuffer[rxIndex]; + } + return value; } -void TwoWire::flush() -{ - rxIndex = 0; - rxLength = 0; - txLength = 0; - //i2cFlush(num); // cleanup +void TwoWire::flush() { + rxIndex = 0; + rxLength = 0; + txLength = 0; + //i2cFlush(num); // cleanup } -void TwoWire::onReceive( void (*function)(int) ) -{ +void TwoWire::onReceive(void (*function)(int)) { #if SOC_I2C_SUPPORT_SLAVE - user_onReceive = function; + user_onReceive = function; #endif } // sets function called on slave read -void TwoWire::onRequest( void (*function)(void) ) -{ +void TwoWire::onRequest(void (*function)(void)) { #if SOC_I2C_SUPPORT_SLAVE - user_onRequest = function; + user_onRequest = function; #endif } #if SOC_I2C_SUPPORT_SLAVE -size_t TwoWire::slaveWrite(const uint8_t * buffer, size_t len) -{ - return i2cSlaveWrite(num, buffer, len, _timeOutMillis); +size_t TwoWire::slaveWrite(const uint8_t *buffer, size_t len) { + return i2cSlaveWrite(num, buffer, len, _timeOutMillis); } -void TwoWire::onReceiveService(uint8_t num, uint8_t* inBytes, size_t numBytes, bool stop, void * arg) -{ - TwoWire * wire = (TwoWire*)arg; - if(!wire->user_onReceive){ - return; - } - if (wire->rxBuffer == NULL){ - log_e("NULL RX buffer pointer"); - return; - } - for(uint8_t i = 0; i < numBytes; ++i){ - wire->rxBuffer[i] = inBytes[i]; - } - wire->rxIndex = 0; - wire->rxLength = numBytes; - wire->user_onReceive(numBytes); +void TwoWire::onReceiveService(uint8_t num, uint8_t *inBytes, size_t numBytes, bool stop, void *arg) { + TwoWire *wire = (TwoWire *)arg; + if (!wire->user_onReceive) { + return; + } + if (wire->rxBuffer == NULL) { + log_e("NULL RX buffer pointer"); + return; + } + for (uint8_t i = 0; i < numBytes; ++i) { + wire->rxBuffer[i] = inBytes[i]; + } + wire->rxIndex = 0; + wire->rxLength = numBytes; + wire->user_onReceive(numBytes); } -void TwoWire::onRequestService(uint8_t num, void * arg) -{ - TwoWire * wire = (TwoWire*)arg; - if(!wire->user_onRequest){ - return; - } - if (wire->txBuffer == NULL){ - log_e("NULL TX buffer pointer"); - return; - } - wire->txLength = 0; - wire->user_onRequest(); - if(wire->txLength){ - wire->slaveWrite((uint8_t*)wire->txBuffer, wire->txLength); - } +void TwoWire::onRequestService(uint8_t num, void *arg) { + TwoWire *wire = (TwoWire *)arg; + if (!wire->user_onRequest) { + return; + } + if (wire->txBuffer == NULL) { + log_e("NULL TX buffer pointer"); + return; + } + wire->txLength = 0; + wire->user_onRequest(); + if (wire->txLength) { + wire->slaveWrite((uint8_t *)wire->txBuffer, wire->txLength); + } } #endif /* SOC_I2C_SUPPORT_SLAVE */ diff --git a/libraries/Wire/src/Wire.h b/libraries/Wire/src/Wire.h index 2a5e9b4215d..fcf94313d52 100644 --- a/libraries/Wire/src/Wire.h +++ b/libraries/Wire/src/Wire.h @@ -40,109 +40,106 @@ #include "Stream.h" // WIRE_HAS_BUFFER_SIZE means Wire has setBufferSize() -#define WIRE_HAS_BUFFER_SIZE 1 -// WIRE_HAS_END means Wire has end() +#define WIRE_HAS_BUFFER_SIZE 1 +// WIRE_HAS_END means Wire has end() #define WIRE_HAS_END 1 #ifndef I2C_BUFFER_LENGTH - #define I2C_BUFFER_LENGTH 128 // Default size, if none is set using Wire::setBuffersize(size_t) +#define I2C_BUFFER_LENGTH 128 // Default size, if none is set using Wire::setBuffersize(size_t) #endif #if SOC_I2C_SUPPORT_SLAVE -typedef void(*user_onRequest)(void); -typedef void(*user_onReceive)(uint8_t*, int); +typedef void (*user_onRequest)(void); +typedef void (*user_onReceive)(uint8_t *, int); #endif /* SOC_I2C_SUPPORT_SLAVE */ -class TwoWire: public HardwareI2C -{ +class TwoWire : public HardwareI2C { protected: - uint8_t num; - int8_t sda; - int8_t scl; + uint8_t num; + int8_t sda; + int8_t scl; - size_t bufferSize; - uint8_t *rxBuffer; - size_t rxIndex; - size_t rxLength; + size_t bufferSize; + uint8_t *rxBuffer; + size_t rxIndex; + size_t rxLength; - uint8_t *txBuffer; - size_t txLength; - uint16_t txAddress; + uint8_t *txBuffer; + size_t txLength; + uint16_t txAddress; - uint32_t _timeOutMillis; - bool nonStop; + uint32_t _timeOutMillis; + bool nonStop; #if !CONFIG_DISABLE_HAL_LOCKS - TaskHandle_t currentTaskHandle; - SemaphoreHandle_t lock; + TaskHandle_t currentTaskHandle; + SemaphoreHandle_t lock; #endif private: #if SOC_I2C_SUPPORT_SLAVE - bool is_slave; - void (*user_onRequest)(void); - void (*user_onReceive)(int); - static void onRequestService(uint8_t, void *); - static void onReceiveService(uint8_t, uint8_t*, size_t, bool, void *); + bool is_slave; + void (*user_onRequest)(void); + void (*user_onReceive)(int); + static void onRequestService(uint8_t, void *); + static void onReceiveService(uint8_t, uint8_t *, size_t, bool, void *); #endif /* SOC_I2C_SUPPORT_SLAVE */ - bool initPins(int sdaPin, int sclPin); - bool allocateWireBuffer(); - void freeWireBuffer(); + bool initPins(int sdaPin, int sclPin); + bool allocateWireBuffer(); + void freeWireBuffer(); public: - TwoWire(uint8_t bus_num); - ~TwoWire(); + TwoWire(uint8_t bus_num); + ~TwoWire(); - bool begin() override final - { - return begin(-1, -1); - } + bool begin() override final { + return begin(-1, -1); + } - bool begin(uint8_t address) override final - { + bool begin(uint8_t address) override final { #if SOC_I2C_SUPPORT_SLAVE - return begin(address, -1, -1, 0); + return begin(address, -1, -1, 0); #else - log_e("I2C slave is not supported on " CONFIG_IDF_TARGET); - return false; + log_e("I2C slave is not supported on " CONFIG_IDF_TARGET); + return false; #endif - } - - bool end() override; - - bool setClock(uint32_t freq) override; - - void beginTransmission(uint8_t address) override; - uint8_t endTransmission(bool stopBit) override; - uint8_t endTransmission() override; - - size_t requestFrom(uint8_t address, size_t len, bool stopBit) override; - size_t requestFrom(uint8_t address, size_t len) override; - - void onReceive(void(*)(int)) override; - void onRequest(void(*)(void)) override; - - //call setPins() first, so that begin() can be called without arguments from libraries - bool setPins(int sda, int scl); - - bool begin(int sda, int scl, uint32_t frequency=0); // returns true, if successful init of i2c bus + } + + bool end() override; + + bool setClock(uint32_t freq) override; + + void beginTransmission(uint8_t address) override; + uint8_t endTransmission(bool stopBit) override; + uint8_t endTransmission() override; + + size_t requestFrom(uint8_t address, size_t len, bool stopBit) override; + size_t requestFrom(uint8_t address, size_t len) override; + + void onReceive(void (*)(int)) override; + void onRequest(void (*)(void)) override; + + //call setPins() first, so that begin() can be called without arguments from libraries + bool setPins(int sda, int scl); + + bool begin(int sda, int scl, uint32_t frequency = 0); // returns true, if successful init of i2c bus #if SOC_I2C_SUPPORT_SLAVE - bool begin(uint8_t slaveAddr, int sda, int scl, uint32_t frequency); + bool begin(uint8_t slaveAddr, int sda, int scl, uint32_t frequency); #endif /* SOC_I2C_SUPPORT_SLAVE */ - size_t setBufferSize(size_t bSize); + size_t setBufferSize(size_t bSize); - void setTimeOut(uint16_t timeOutMillis); // default timeout of i2c transactions is 50ms - uint16_t getTimeOut(); + void setTimeOut(uint16_t timeOutMillis); // default timeout of i2c transactions is 50ms + uint16_t getTimeOut(); - uint32_t getClock(); + uint32_t getClock(); - size_t write(uint8_t) override; - size_t write(const uint8_t *, size_t) override; - int available() override; - int read() override; - int peek() override; - void flush() override; + size_t write(uint8_t) override; + size_t write(const uint8_t *, size_t) override; + int available() override; + int read() override; + int peek() override; + void flush() override; #if SOC_I2C_SUPPORT_SLAVE - size_t slaveWrite(const uint8_t *, size_t); + size_t slaveWrite(const uint8_t *, size_t); #endif /* SOC_I2C_SUPPORT_SLAVE */ }; diff --git a/tests/democfg/democfg.ino b/tests/democfg/democfg.ino index 835dc1b20b2..b86d28196e0 100644 --- a/tests/democfg/democfg.ino +++ b/tests/democfg/democfg.ino @@ -1,4 +1,4 @@ -void setup(){ +void setup() { Serial.begin(115200); while (!Serial) { ; @@ -7,5 +7,5 @@ void setup(){ Serial.println("Hello cfg!"); } -void loop(){ +void loop() { } diff --git a/tests/democfg/test_democfg.py b/tests/democfg/test_democfg.py index 0dcc877dc36..c34128d7e16 100644 --- a/tests/democfg/test_democfg.py +++ b/tests/democfg/test_democfg.py @@ -1,2 +1,2 @@ def test_cfg(dut): - dut.expect('Hello cfg!') + dut.expect("Hello cfg!") diff --git a/tests/hello_world/hello_world.ino b/tests/hello_world/hello_world.ino index 0cc110d42a5..668398a755a 100644 --- a/tests/hello_world/hello_world.ino +++ b/tests/hello_world/hello_world.ino @@ -1,4 +1,4 @@ -void setup(){ +void setup() { // Open serial communications and wait for port to open: Serial.begin(115200); while (!Serial) { @@ -8,5 +8,5 @@ void setup(){ Serial.println("Hello Arduino!"); } -void loop(){ +void loop() { } diff --git a/tests/hello_world/test_hello_world.py b/tests/hello_world/test_hello_world.py index f7ed50cde40..bec1a73fc37 100644 --- a/tests/hello_world/test_hello_world.py +++ b/tests/hello_world/test_hello_world.py @@ -1,2 +1,2 @@ def test_hello_world(dut): - dut.expect('Hello Arduino!') + dut.expect("Hello Arduino!") diff --git a/tests/nvs/nvs.ino b/tests/nvs/nvs.ino index 7bfe25ff00b..20b5b460098 100644 --- a/tests/nvs/nvs.ino +++ b/tests/nvs/nvs.ino @@ -4,7 +4,7 @@ Preferences preferences; void setup() { Serial.begin(115200); - + while (!Serial) { ; } @@ -25,7 +25,7 @@ void setup() { // Close the Preferences preferences.end(); - + // Wait 1 second delay(1000); diff --git a/tests/nvs/test_nvs.py b/tests/nvs/test_nvs.py index 656ab544ee2..d46db220434 100644 --- a/tests/nvs/test_nvs.py +++ b/tests/nvs/test_nvs.py @@ -1,7 +1,7 @@ def test_nvs(dut): - dut.expect('Current counter value: 0') - dut.expect('Current counter value: 1') - dut.expect('Current counter value: 2') - dut.expect('Current counter value: 3') - dut.expect('Current counter value: 4') - dut.expect('Current counter value: 5') \ No newline at end of file + dut.expect("Current counter value: 0") + dut.expect("Current counter value: 1") + dut.expect("Current counter value: 2") + dut.expect("Current counter value: 3") + dut.expect("Current counter value: 4") + dut.expect("Current counter value: 5") diff --git a/tests/periman/periman.ino b/tests/periman/periman.ino index dd9d61724a9..7b791971b27 100644 --- a/tests/periman/periman.ino +++ b/tests/periman/periman.ino @@ -30,17 +30,17 @@ #define ADC1_DEFAULT A4 #if CONFIG_IDF_TARGET_ESP32 -# define ADC2_DEFAULT A5 +#define ADC2_DEFAULT A5 #else -# define ADC2_DEFAULT A3 +#define ADC2_DEFAULT A3 #endif #if CONFIG_IDF_TARGET_ESP32 -# define TOUCH1_DEFAULT T0 -# define TOUCH2_DEFAULT T2 +#define TOUCH1_DEFAULT T0 +#define TOUCH2_DEFAULT T2 #else -# define TOUCH1_DEFAULT T4 -# define TOUCH2_DEFAULT T5 +#define TOUCH1_DEFAULT T4 +#define TOUCH2_DEFAULT T5 #endif /* Global variables */ @@ -55,7 +55,7 @@ int8_t uart1_tx_pin; void onReceive_cb(void) { // This is a callback function that will be activated on UART RX events size_t available = Serial1.available(); - while (available --) { + while (available--) { Serial.print((char)Serial1.read()); } } @@ -156,9 +156,9 @@ void adc_continuous_test(void) { #else setup_test("ADC_Continuous", ADC1_DEFAULT, ADC2_DEFAULT); test_executed = true; - uint8_t adc_pins[] = {ADC1_DEFAULT, ADC2_DEFAULT}; + uint8_t adc_pins[] = { ADC1_DEFAULT, ADC2_DEFAULT }; uint8_t adc_pins_count = 2; - adc_continuos_data_t * result = NULL; + adc_continuos_data_t* result = NULL; analogContinuousSetWidth(12); analogContinuousSetAtten(ADC_11db); @@ -270,11 +270,11 @@ void touch_test(void) { void setup() { Serial.begin(115200); - while(!Serial) { delay(10); } + while (!Serial) { delay(10); } Serial1.setPins(UART1_RX_DEFAULT, UART1_TX_DEFAULT); Serial1.begin(115200); - while(!Serial1) { delay(10); } + while (!Serial1) { delay(10); } Serial1.onReceive(onReceive_cb); uart_internal_loopback(1, uart1_rx_pin); diff --git a/tests/periman/test_periman.py b/tests/periman/test_periman.py index 4bce226bfad..d8dc4b8eeb5 100644 --- a/tests/periman/test_periman.py +++ b/tests/periman/test_periman.py @@ -1,14 +1,25 @@ def test_periman(dut): - peripherals = ["GPIO", "SigmaDelta", "LEDC", "RMT", "I2S", "I2C", "SPI", - "ADC_Oneshot", "ADC_Continuous", "DAC", "Touch"] + peripherals = [ + "GPIO", + "SigmaDelta", + "LEDC", + "RMT", + "I2S", + "I2C", + "SPI", + "ADC_Oneshot", + "ADC_Continuous", + "DAC", + "Touch", + ] pattern = rb"(?:\b\w+\b test: This should(?: not)? be printed|Peripheral Manager test done)" while True: try: res = dut.expect(pattern, timeout=10) - except: - assert False, f"Could not detect end of test" + except Exception as e: # noqa: F841 + assert False, "Could not detect end of test" console_output = res.group(0).decode("utf-8") peripheral = console_output.split()[0] diff --git a/tests/timer/timer.ino b/tests/timer/timer.ino index e641ada1702..012da4a89e3 100644 --- a/tests/timer/timer.ino +++ b/tests/timer/timer.ino @@ -1,8 +1,8 @@ /* HW Timer test */ #include -#define TIMER_FREQUENCY 4000000 -#define TIMER_FREQUENCY_XTAL_CLK 1000 +#define TIMER_FREQUENCY 4000000 +#define TIMER_FREQUENCY_XTAL_CLK 1000 /* * ESP32 - APB clk only (1kHz not possible) @@ -11,34 +11,34 @@ * S3 - APB + XTAL clk */ -static hw_timer_t * timer = NULL; +static hw_timer_t* timer = NULL; static volatile bool alarm_flag; /* setUp / tearDown functions are intended to be called before / after each test. */ void setUp(void) { timer = timerBegin(TIMER_FREQUENCY); - if(timer == NULL){ - TEST_FAIL_MESSAGE("Timer init failed in setUp()"); + if (timer == NULL) { + TEST_FAIL_MESSAGE("Timer init failed in setUp()"); } timerStop(timer); timerRestart(timer); } -void tearDown(void){ +void tearDown(void) { timerEnd(timer); } -void ARDUINO_ISR_ATTR onTimer(){ +void ARDUINO_ISR_ATTR onTimer() { alarm_flag = true; } -void timer_interrupt_test(void){ +void timer_interrupt_test(void) { alarm_flag = false; timerAttachInterrupt(timer, &onTimer); timerAlarm(timer, (1.2 * TIMER_FREQUENCY), true, 0); timerStart(timer); - + delay(2000); TEST_ASSERT_EQUAL(true, alarm_flag); @@ -53,7 +53,7 @@ void timer_interrupt_test(void){ TEST_ASSERT_EQUAL(false, alarm_flag); } -void timer_divider_test(void){ +void timer_divider_test(void) { uint64_t time_val; uint64_t comp_time_val; @@ -67,13 +67,13 @@ void timer_divider_test(void){ timerEnd(timer); timer = timerBegin(2 * TIMER_FREQUENCY); - if(timer == NULL){ - TEST_FAIL_MESSAGE("Timer init failed!"); + if (timer == NULL) { + TEST_FAIL_MESSAGE("Timer init failed!"); } timerRestart(timer); - delay(1000); + delay(1000); comp_time_val = timerRead(timer); - + TEST_ASSERT_INT_WITHIN(4000, 4000000, time_val); TEST_ASSERT_INT_WITHIN(8000, 8000000, comp_time_val); @@ -81,18 +81,18 @@ void timer_divider_test(void){ timerEnd(timer); timer = timerBegin(TIMER_FREQUENCY / 16); - if(timer == NULL){ - TEST_FAIL_MESSAGE("Timer init failed!"); + if (timer == NULL) { + TEST_FAIL_MESSAGE("Timer init failed!"); } timerRestart(timer); - delay(1000); + delay(1000); comp_time_val = timerRead(timer); TEST_ASSERT_INT_WITHIN(4000, 4000000, time_val); TEST_ASSERT_INT_WITHIN(2500, 250000, comp_time_val); } -void timer_read_test(void){ +void timer_read_test(void) { uint64_t set_timer_val = 0xFF; uint64_t get_timer_val = 0; @@ -103,16 +103,16 @@ void timer_read_test(void){ TEST_ASSERT_EQUAL(set_timer_val, get_timer_val); } -void timer_clock_select_test(void){ +void timer_clock_select_test(void) { // Set timer frequency that can be achieved using XTAL clock source (autoselected) timer = timerBegin(TIMER_FREQUENCY_XTAL_CLK); - + uint32_t resolution = timerGetFrequency(timer); - TEST_ASSERT_EQUAL(TIMER_FREQUENCY_XTAL_CLK,resolution); + TEST_ASSERT_EQUAL(TIMER_FREQUENCY_XTAL_CLK, resolution); } -void setup(){ - +void setup() { + // Open serial communications and wait for port to open: Serial.begin(115200); while (!Serial) { @@ -123,11 +123,11 @@ void setup(){ RUN_TEST(timer_read_test); RUN_TEST(timer_interrupt_test); RUN_TEST(timer_divider_test); - #if !CONFIG_IDF_TARGET_ESP32 +#if !CONFIG_IDF_TARGET_ESP32 RUN_TEST(timer_clock_select_test); - #endif +#endif UNITY_END(); } -void loop(){ +void loop() { } diff --git a/tests/touch/touch.ino b/tests/touch/touch.ino index 42c0cf393a5..0969dc8eee3 100644 --- a/tests/touch/touch.ino +++ b/tests/touch/touch.ino @@ -7,62 +7,62 @@ #if CONFIG_IDF_TARGET_ESP32 -#define TEST_TOUCH_CHANNEL (9) +#define TEST_TOUCH_CHANNEL (9) static touch_pad_t touch_list[TEST_TOUCH_CHANNEL] = { - TOUCH_PAD_NUM0, - //TOUCH_PAD_NUM1 is GPIO0, for download. - TOUCH_PAD_NUM2, - TOUCH_PAD_NUM3, - TOUCH_PAD_NUM4, - TOUCH_PAD_NUM5, - TOUCH_PAD_NUM6, - TOUCH_PAD_NUM7, - TOUCH_PAD_NUM8, - TOUCH_PAD_NUM9 + TOUCH_PAD_NUM0, + //TOUCH_PAD_NUM1 is GPIO0, for download. + TOUCH_PAD_NUM2, + TOUCH_PAD_NUM3, + TOUCH_PAD_NUM4, + TOUCH_PAD_NUM5, + TOUCH_PAD_NUM6, + TOUCH_PAD_NUM7, + TOUCH_PAD_NUM8, + TOUCH_PAD_NUM9 }; -uint8_t TOUCH_GPIOS[] = {4,2,15,13,12,14,27,33,32}; +uint8_t TOUCH_GPIOS[] = { 4, 2, 15, 13, 12, 14, 27, 33, 32 }; #define NO_TOUCH_GPIO 25 -#define RELEASED_VALUE 80 //80+ read value to pass test -#define PRESSED_VALUE 20 //20- read value to pass test -#define INTERRUPT_THRESHOLD 40 +#define RELEASED_VALUE 80 //80+ read value to pass test +#define PRESSED_VALUE 20 //20- read value to pass test +#define INTERRUPT_THRESHOLD 40 -#else //ESP32S2 and ESP32S3 +#else //ESP32S2 and ESP32S3 -#define TEST_TOUCH_CHANNEL (12) //14 +#define TEST_TOUCH_CHANNEL (12) //14 static touch_pad_t touch_list[TEST_TOUCH_CHANNEL] = { - TOUCH_PAD_NUM1, - TOUCH_PAD_NUM2, - TOUCH_PAD_NUM3, - TOUCH_PAD_NUM4, - TOUCH_PAD_NUM5, - TOUCH_PAD_NUM6, - TOUCH_PAD_NUM7, - TOUCH_PAD_NUM8, - TOUCH_PAD_NUM9, - TOUCH_PAD_NUM10, - TOUCH_PAD_NUM11, - TOUCH_PAD_NUM12 - //TOUCH_PAD_NUM13, //Wrong reading - //TOUCH_PAD_NUM14 + TOUCH_PAD_NUM1, + TOUCH_PAD_NUM2, + TOUCH_PAD_NUM3, + TOUCH_PAD_NUM4, + TOUCH_PAD_NUM5, + TOUCH_PAD_NUM6, + TOUCH_PAD_NUM7, + TOUCH_PAD_NUM8, + TOUCH_PAD_NUM9, + TOUCH_PAD_NUM10, + TOUCH_PAD_NUM11, + TOUCH_PAD_NUM12 + //TOUCH_PAD_NUM13, //Wrong reading + //TOUCH_PAD_NUM14 }; -uint8_t TOUCH_GPIOS[] = {1,2,3,4,5,6,7,8,9,10,11,12/*,13,14*/}; +uint8_t TOUCH_GPIOS[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 /*,13,14*/ }; #define NO_TOUCH_GPIO 17 #if CONFIG_IDF_TARGET_ESP32S2 - #define RELEASED_VALUE 10000 //10000- read value to pass test - #define PRESSED_VALUE 42000 //40000+ read value to pass test - #define INTERRUPT_THRESHOLD 30000 +#define RELEASED_VALUE 10000 //10000- read value to pass test +#define PRESSED_VALUE 42000 //40000+ read value to pass test +#define INTERRUPT_THRESHOLD 30000 #elif CONFIG_IDF_TARGET_ESP32S3 - #define RELEASED_VALUE 25000 //25000- read value to pass test - #define PRESSED_VALUE 90000 //90000+ read value to pass test - #define INTERRUPT_THRESHOLD 80000 +#define RELEASED_VALUE 25000 //25000- read value to pass test +#define PRESSED_VALUE 90000 //90000+ read value to pass test +#define INTERRUPT_THRESHOLD 80000 #else - #error Test not currently supported on this chip. Please adjust and try again! +#error Test not currently supported on this chip. Please adjust and try again! #endif #endif @@ -95,16 +95,15 @@ static void test_release_fake(touch_pad_t pad_num) { /* These functions are intended to be called before and after each test. */ void setUp(void) { - } void tearDown(void) { for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { - test_release_fake(touch_list[i]); + test_release_fake(touch_list[i]); } delay(100); } - + /* * Test Touch read on all available channels - compare values if reading is right */ @@ -112,30 +111,30 @@ void test_touch_read(void) { //TEST RELEASE STATE for (int i = 0; i < sizeof(TOUCH_GPIOS); i++) { - #ifdef CONFIG_IDF_TARGET_ESP32 - TEST_ASSERT_GREATER_THAN(RELEASED_VALUE, touchRead(TOUCH_GPIOS[i])); - #else - TEST_ASSERT_LESS_THAN(RELEASED_VALUE, touchRead(TOUCH_GPIOS[i])); - #endif +#ifdef CONFIG_IDF_TARGET_ESP32 + TEST_ASSERT_GREATER_THAN(RELEASED_VALUE, touchRead(TOUCH_GPIOS[i])); +#else + TEST_ASSERT_LESS_THAN(RELEASED_VALUE, touchRead(TOUCH_GPIOS[i])); +#endif } // TEST PRESS STATE for (int j = 0; j < TEST_TOUCH_CHANNEL; j++) { - test_press_fake(touch_list[j]); + test_press_fake(touch_list[j]); } delay(100); - + for (int k = 0; k < sizeof(TOUCH_GPIOS); k++) { - #ifdef CONFIG_IDF_TARGET_ESP32 - TEST_ASSERT_LESS_THAN(PRESSED_VALUE,touchRead(TOUCH_GPIOS[k])); - #else - TEST_ASSERT_GREATER_THAN(PRESSED_VALUE, touchRead(TOUCH_GPIOS[k])); - #endif +#ifdef CONFIG_IDF_TARGET_ESP32 + TEST_ASSERT_LESS_THAN(PRESSED_VALUE, touchRead(TOUCH_GPIOS[k])); +#else + TEST_ASSERT_GREATER_THAN(PRESSED_VALUE, touchRead(TOUCH_GPIOS[k])); +#endif } } void test_touch_interrtupt(void) { - + touchAttachInterrupt(TOUCH_GPIOS[0], gotTouch1, INTERRUPT_THRESHOLD); touchAttachInterrupt(TOUCH_GPIOS[1], gotTouch2, INTERRUPT_THRESHOLD); @@ -143,16 +142,16 @@ void test_touch_interrtupt(void) { test_press_fake(touch_list[1]); delay(300); - + touchDetachInterrupt(TOUCH_GPIOS[0]); touchDetachInterrupt(TOUCH_GPIOS[1]); - + TEST_ASSERT_TRUE(touch1detected); TEST_ASSERT_TRUE(touch2detected); } void test_touch_errors(void) { - + TEST_ASSERT_FALSE(touchRead(NO_TOUCH_GPIO)); } @@ -161,7 +160,7 @@ void setup() { while (!Serial) { ; } - + UNITY_BEGIN(); RUN_TEST(test_touch_read); RUN_TEST(test_touch_interrtupt); @@ -170,13 +169,12 @@ void setup() { } void loop() { - } #else //PASS TEST for UNSUPPORTED CHIPS -void test_pass(void){ +void test_pass(void) { TEST_ASSERT_EQUAL(1, 1); } @@ -185,14 +183,13 @@ void setup() { while (!Serial) { ; } - + UNITY_BEGIN(); RUN_TEST(test_pass); UNITY_END(); } void loop() { - } #endif diff --git a/tests/uart/uart.ino b/tests/uart/uart.ino index c10dfc58b24..d727907d577 100644 --- a/tests/uart/uart.ino +++ b/tests/uart/uart.ino @@ -47,9 +47,9 @@ */ #if SOC_UART_NUM == 2 - // Used for the pin swap test - #define NEW_RX1 6 - #define NEW_TX1 7 +// Used for the pin swap test +#define NEW_RX1 6 +#define NEW_TX1 7 #endif /* Utility global variables */ @@ -64,56 +64,56 @@ extern int8_t uart_get_TxPin(uint8_t uart_num); // This function starts all the available test UARTs void start_serial(unsigned long baudrate = 115200) { - #if SOC_UART_NUM >= 2 - Serial1.begin(baudrate); - while(!Serial1) { delay(10); } - #endif - - #if SOC_UART_NUM >= 3 - Serial2.begin(baudrate); - while(!Serial2) { delay(10); } - #endif +#if SOC_UART_NUM >= 2 + Serial1.begin(baudrate); + while (!Serial1) { delay(10); } +#endif + +#if SOC_UART_NUM >= 3 + Serial2.begin(baudrate); + while (!Serial2) { delay(10); } +#endif } // This function stops all the available test UARTs void stop_serial(bool hard_stop = false) { - #if SOC_UART_NUM >= 2 - Serial1.end(/*hard_stop*/); - #endif +#if SOC_UART_NUM >= 2 + Serial1.end(/*hard_stop*/); +#endif - #if SOC_UART_NUM >= 3 - Serial2.end(/*hard_stop*/); - #endif +#if SOC_UART_NUM >= 3 + Serial2.end(/*hard_stop*/); +#endif } // This function transmits a message and checks if it was received correctly void transmit_and_check_msg(const String msg_append, bool perform_assert = true) { - delay(100); // Wait for some settings changes to take effect - #if SOC_UART_NUM == 2 - Serial1.print("Hello from Serial1 (UART1) >>> via loopback >>> Serial1 (UART1) " + msg_append); - Serial1.flush(); - delay(100); - if (perform_assert) { - TEST_ASSERT_EQUAL_STRING(("Hello from Serial1 (UART1) >>> via loopback >>> Serial1 (UART1) " + msg_append).c_str(), recv_msg.c_str()); - } - #elif SOC_UART_NUM == 3 - Serial1.print("Hello from Serial1 (UART1) >>> to >>> Serial2 (UART2) " + msg_append); - Serial1.flush(); - delay(100); - if (perform_assert) { - TEST_ASSERT_EQUAL_STRING(("Hello from Serial1 (UART1) >>> to >>> Serial2 (UART2) " + msg_append).c_str(), recv_msg.c_str()); - } - - Serial2.print("Hello from Serial2 (UART2) >>> to >>> Serial1 (UART1) " + msg_append); - Serial2.flush(); - delay(100); - if (perform_assert) { - TEST_ASSERT_EQUAL_STRING(("Hello from Serial2 (UART2) >>> to >>> Serial1 (UART1) " + msg_append).c_str(), recv_msg.c_str()); - } - #else - log_d("No UARTs available for transmission"); - TEST_FAIL(); - #endif + delay(100); // Wait for some settings changes to take effect +#if SOC_UART_NUM == 2 + Serial1.print("Hello from Serial1 (UART1) >>> via loopback >>> Serial1 (UART1) " + msg_append); + Serial1.flush(); + delay(100); + if (perform_assert) { + TEST_ASSERT_EQUAL_STRING(("Hello from Serial1 (UART1) >>> via loopback >>> Serial1 (UART1) " + msg_append).c_str(), recv_msg.c_str()); + } +#elif SOC_UART_NUM == 3 + Serial1.print("Hello from Serial1 (UART1) >>> to >>> Serial2 (UART2) " + msg_append); + Serial1.flush(); + delay(100); + if (perform_assert) { + TEST_ASSERT_EQUAL_STRING(("Hello from Serial1 (UART1) >>> to >>> Serial2 (UART2) " + msg_append).c_str(), recv_msg.c_str()); + } + + Serial2.print("Hello from Serial2 (UART2) >>> to >>> Serial1 (UART1) " + msg_append); + Serial2.flush(); + delay(100); + if (perform_assert) { + TEST_ASSERT_EQUAL_STRING(("Hello from Serial2 (UART2) >>> to >>> Serial1 (UART1) " + msg_append).c_str(), recv_msg.c_str()); + } +#else + log_d("No UARTs available for transmission"); + TEST_FAIL(); +#endif } /* Tasks */ @@ -122,11 +122,11 @@ void transmit_and_check_msg(const String msg_append, bool perform_assert = true) void task_delayed_msg(void *pvParameters) { HardwareSerial *selected_serial; - #if SOC_UART_NUM == 2 - selected_serial = &Serial; - #elif SOC_UART_NUM == 3 - selected_serial = &Serial1; - #endif +#if SOC_UART_NUM == 2 + selected_serial = &Serial; +#elif SOC_UART_NUM == 3 + selected_serial = &Serial1; +#endif delay(2000); selected_serial->println("Hello from Serial1 to detect baudrate"); @@ -142,13 +142,19 @@ void setUp(void) { #if SOC_UART_NUM == 2 log_d("Setup internal loop-back from and back to Serial1 (UART1) TX >> Serial1 (UART1) RX"); - Serial1.onReceive([]() {onReceive_cb(Serial1);}); + Serial1.onReceive([]() { + onReceive_cb(Serial1); + }); uart_internal_loopback(1, RX1); #elif SOC_UART_NUM == 3 log_d("Setup internal loop-back between Serial1 (UART1) <<--->> Serial2 (UART2)"); - Serial1.onReceive([]() {onReceive_cb(Serial1);}); - Serial2.onReceive([]() {onReceive_cb(Serial2);}); + Serial1.onReceive([]() { + onReceive_cb(Serial1); + }); + Serial2.onReceive([]() { + onReceive_cb(Serial2); + }); uart_internal_loopback(1, RX2); uart_internal_loopback(2, RX1); #endif @@ -166,7 +172,7 @@ void onReceive_cb(HardwareSerial &selected_serial) { int uart_num = -1; char c; - (void)uart_num; // Avoid compiler warning when debug level is set to none + (void)uart_num; // Avoid compiler warning when debug level is set to none if (&selected_serial == &Serial) { uart_num = 0; @@ -187,7 +193,7 @@ void onReceive_cb(HardwareSerial &selected_serial) { peeked_char = selected_serial.peek(); } - while (available --) { + while (available--) { c = (char)selected_serial.read(); recv_msg += c; } @@ -215,10 +221,10 @@ void change_baudrate_test(void) { Serial1.updateBaudRate(9600); TEST_ASSERT_UINT_WITHIN(192, 9600, Serial1.baudRate()); - #if SOC_UART_NUM == 3 - Serial2.updateBaudRate(9600); - TEST_ASSERT_UINT_WITHIN(192, 9600, Serial2.baudRate()); - #endif +#if SOC_UART_NUM == 3 + Serial2.updateBaudRate(9600); + TEST_ASSERT_UINT_WITHIN(192, 9600, Serial2.baudRate()); +#endif log_d("Sending string using 9600 baudrate"); transmit_and_check_msg("using 9600 baudrate"); @@ -229,9 +235,9 @@ void change_baudrate_test(void) { //Baudrate error should be within 2% of the target baudrate TEST_ASSERT_UINT_WITHIN(2304, 115200, Serial1.baudRate()); - #if SOC_UART_NUM == 3 - TEST_ASSERT_UINT_WITHIN(2304, 115200, Serial2.baudRate()); - #endif +#if SOC_UART_NUM == 3 + TEST_ASSERT_UINT_WITHIN(2304, 115200, Serial2.baudRate()); +#endif log_d("Sending string using 115200 baudrate"); transmit_and_check_msg("using 115200 baudrate"); @@ -410,43 +416,42 @@ void change_pins_test(void) { log_d("Disabling UART loopback"); - #if SOC_UART_NUM == 2 - esp_rom_gpio_connect_out_signal(SOC_RX0, SIG_GPIO_OUT_IDX, false, false); - #elif SOC_UART_NUM == 3 - esp_rom_gpio_connect_out_signal(RX1, SIG_GPIO_OUT_IDX, false, false); - esp_rom_gpio_connect_out_signal(RX2, SIG_GPIO_OUT_IDX, false, false); - #endif +#if SOC_UART_NUM == 2 + esp_rom_gpio_connect_out_signal(SOC_RX0, SIG_GPIO_OUT_IDX, false, false); +#elif SOC_UART_NUM == 3 + esp_rom_gpio_connect_out_signal(RX1, SIG_GPIO_OUT_IDX, false, false); + esp_rom_gpio_connect_out_signal(RX2, SIG_GPIO_OUT_IDX, false, false); +#endif log_d("Swapping UART pins"); - #if SOC_UART_NUM == 2 - Serial1.setPins(NEW_RX1, NEW_TX1); - TEST_ASSERT_EQUAL(NEW_RX1, uart_get_RxPin(1)); - TEST_ASSERT_EQUAL(NEW_TX1, uart_get_TxPin(1)); - #elif SOC_UART_NUM == 3 - Serial1.setPins(RX2, TX2); - Serial2.setPins(RX1, TX1); - TEST_ASSERT_EQUAL(RX2, uart_get_RxPin(1)); - TEST_ASSERT_EQUAL(TX2, uart_get_TxPin(1)); - TEST_ASSERT_EQUAL(RX1, uart_get_RxPin(2)); - TEST_ASSERT_EQUAL(TX1, uart_get_TxPin(2)); - #endif +#if SOC_UART_NUM == 2 + Serial1.setPins(NEW_RX1, NEW_TX1); + TEST_ASSERT_EQUAL(NEW_RX1, uart_get_RxPin(1)); + TEST_ASSERT_EQUAL(NEW_TX1, uart_get_TxPin(1)); +#elif SOC_UART_NUM == 3 + Serial1.setPins(RX2, TX2); + Serial2.setPins(RX1, TX1); + TEST_ASSERT_EQUAL(RX2, uart_get_RxPin(1)); + TEST_ASSERT_EQUAL(TX2, uart_get_TxPin(1)); + TEST_ASSERT_EQUAL(RX1, uart_get_RxPin(2)); + TEST_ASSERT_EQUAL(TX1, uart_get_TxPin(2)); +#endif start_serial(115200); log_d("Re-enabling UART loopback"); - #if SOC_UART_NUM == 2 - uart_internal_loopback(1, NEW_RX1); - #elif SOC_UART_NUM == 3 - uart_internal_loopback(1, RX1); - uart_internal_loopback(2, RX2); - #endif +#if SOC_UART_NUM == 2 + uart_internal_loopback(1, NEW_RX1); +#elif SOC_UART_NUM == 3 + uart_internal_loopback(1, RX1); + uart_internal_loopback(2, RX2); +#endif transmit_and_check_msg("using new pins"); Serial.println("Change pins test successful"); - } // This test checks if the auto baudrate detection works on ESP32 and ESP32-S2 @@ -459,12 +464,12 @@ void auto_baudrate_test(void) { log_d("Stopping test serial. Using Serial2 for ESP32 and Serial1 for ESP32-S2."); - #if SOC_UART_NUM == 2 - selected_serial = &Serial1; - uart_internal_loopback(0, RX1); - #elif SOC_UART_NUM == 3 - selected_serial = &Serial2; - #endif +#if SOC_UART_NUM == 2 + selected_serial = &Serial1; + uart_internal_loopback(0, RX1); +#elif SOC_UART_NUM == 3 + selected_serial = &Serial2; +#endif //selected_serial->end(false); @@ -477,10 +482,10 @@ void auto_baudrate_test(void) { selected_serial->begin(0); baudrate = selected_serial->baudRate(); - #if SOC_UART_NUM == 2 - Serial.end(); - Serial.begin(115200); - #endif +#if SOC_UART_NUM == 2 + Serial.end(); + Serial.begin(115200); +#endif TEST_ASSERT_UINT_WITHIN(2304, 115200, baudrate); @@ -496,9 +501,9 @@ void periman_test(void) { Wire.begin(RX1, TX1); - #if SOC_UART_NUM == 3 - Wire1.begin(RX2, TX2); - #endif +#if SOC_UART_NUM == 3 + Wire1.begin(RX2, TX2); +#endif recv_msg = ""; @@ -510,13 +515,13 @@ void periman_test(void) { Serial1.setPins(RX1, TX1); - #if SOC_UART_NUM == 3 - Serial2.setPins(RX2, TX2); - uart_internal_loopback(1, RX2); - uart_internal_loopback(2, RX1); - #elif SOC_UART_NUM == 2 - uart_internal_loopback(1, RX1); - #endif +#if SOC_UART_NUM == 3 + Serial2.setPins(RX2, TX2); + uart_internal_loopback(1, RX2); + uart_internal_loopback(2, RX1); +#elif SOC_UART_NUM == 2 + uart_internal_loopback(1, RX1); +#endif log_d("Trying to send message using UART with I2C disabled"); transmit_and_check_msg("while I2C is disabled"); @@ -554,7 +559,7 @@ void change_cpu_frequency_test(void) { void setup() { Serial.begin(115200); - while(!Serial) { delay(10); } + while (!Serial) { delay(10); } log_d("SOC_UART_NUM = %d", SOC_UART_NUM); // Begin needs to be called before setting up the loopback because it creates the serial object @@ -563,13 +568,19 @@ void setup() { #if SOC_UART_NUM == 2 log_d("Setup internal loop-back from and back to Serial1 (UART1) TX >> Serial1 (UART1) RX"); - Serial1.onReceive([]() {onReceive_cb(Serial1);}); + Serial1.onReceive([]() { + onReceive_cb(Serial1); + }); uart_internal_loopback(1, RX1); #elif SOC_UART_NUM == 3 log_d("Setup internal loop-back between Serial1 (UART1) <<--->> Serial2 (UART2)"); - Serial1.onReceive([]() {onReceive_cb(Serial1);}); - Serial2.onReceive([]() {onReceive_cb(Serial2);}); + Serial1.onReceive([]() { + onReceive_cb(Serial1); + }); + Serial2.onReceive([]() { + onReceive_cb(Serial2); + }); uart_internal_loopback(1, RX2); uart_internal_loopback(2, RX1); #endif @@ -584,9 +595,9 @@ void setup() { RUN_TEST(change_cpu_frequency_test); RUN_TEST(disabled_uart_calls_test); RUN_TEST(enabled_uart_calls_test); - #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 - RUN_TEST(auto_baudrate_test); - #endif +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 + RUN_TEST(auto_baudrate_test); +#endif RUN_TEST(periman_test); RUN_TEST(change_pins_test); RUN_TEST(end_when_stopped_test); diff --git a/tests/unity/unity.ino b/tests/unity/unity.ino index 2a1c131ca74..2d0a09d0804 100644 --- a/tests/unity/unity.ino +++ b/tests/unity/unity.ino @@ -5,15 +5,15 @@ void setUp(void) { } -void tearDown(void){ +void tearDown(void) { } -void test_pass(void){ +void test_pass(void) { TEST_ASSERT_EQUAL(1, 1); } -void test_fail(void){ +void test_fail(void) { TEST_ASSERT_EQUAL(1, 1); } @@ -22,7 +22,7 @@ void setup() { while (!Serial) { ; } - + UNITY_BEGIN(); RUN_TEST(test_pass); RUN_TEST(test_fail); diff --git a/tools/espota.py b/tools/espota.py index f640a66792c..fd95955a2f3 100755 --- a/tools/espota.py +++ b/tools/espota.py @@ -8,9 +8,10 @@ # Modified since 2016-01-03 from Matthew O'Gorman (https://githumb.com/mogorman) # # This script will push an OTA update to the ESP -# use it like: python espota.py -i -I -p -P [-a password] -f +# use it like: +# python espota.py -i -I -p -P [-a password] -f # Or to upload SPIFFS image: -# python espota.py -i -I -p -P [-a password] -s -f +# python espota.py -i -I -p -P [-a password] -s -f # # Changes # 2015-09-18: @@ -53,6 +54,7 @@ # Constants PROGRESS_BAR_LENGTH = 60 + # update_progress(): Displays or updates a console progress bar def update_progress(progress): if PROGRESS: @@ -69,18 +71,21 @@ def update_progress(progress): progress = 1 status = "Done...\r\n" block = int(round(PROGRESS_BAR_LENGTH * progress)) - text = "\rUploading: [{0}] {1}% {2}".format("=" * block + " " * (PROGRESS_BAR_LENGTH - block), int(progress * 100), status) + text = "\rUploading: [{0}] {1}% {2}".format( + "=" * block + " " * (PROGRESS_BAR_LENGTH - block), int(progress * 100), status + ) sys.stderr.write(text) sys.stderr.flush() else: sys.stderr.write(".") sys.stderr.flush() -def serve(remote_addr, local_addr, remote_port, local_port, password, filename, command=FLASH): + +def serve(remote_addr, local_addr, remote_port, local_port, password, filename, command=FLASH): # noqa: C901 # Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_address = (local_addr, local_port) - logging.info('Starting on %s:%s', str(server_address[0]), str(server_address[1])) + logging.info("Starting on %s:%s", str(server_address[0]), str(server_address[1])) try: sock.bind(server_address) sock.listen(1) @@ -89,14 +94,14 @@ def serve(remote_addr, local_addr, remote_port, local_port, password, filename, return 1 content_size = os.path.getsize(filename) - file_md5 = hashlib.md5(open(filename, 'rb').read()).hexdigest() - logging.info('Upload size: %d', content_size) - message = '%d %d %d %s\n' % (command, local_port, content_size, file_md5) + file_md5 = hashlib.md5(open(filename, "rb").read()).hexdigest() + logging.info("Upload size: %d", content_size) + message = "%d %d %d %s\n" % (command, local_port, content_size, file_md5) # Wait for a connection inv_tries = 0 - data = '' - msg = 'Sending invitation to %s ' % remote_addr + data = "" + msg = "Sending invitation to %s " % remote_addr sys.stderr.write(msg) sys.stderr.flush() while inv_tries < 10: @@ -104,67 +109,67 @@ def serve(remote_addr, local_addr, remote_port, local_port, password, filename, sock2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) remote_address = (remote_addr, int(remote_port)) try: - sent = sock2.sendto(message.encode(), remote_address) - except: - sys.stderr.write('failed\n') + sent = sock2.sendto(message.encode(), remote_address) # noqa: F841 + except: # noqa: E722 + sys.stderr.write("failed\n") sys.stderr.flush() sock2.close() - logging.error('Host %s Not Found', remote_addr) + logging.error("Host %s Not Found", remote_addr) return 1 sock2.settimeout(TIMEOUT) try: data = sock2.recv(37).decode() break - except: - sys.stderr.write('.') + except: # noqa: E722 + sys.stderr.write(".") sys.stderr.flush() sock2.close() - sys.stderr.write('\n') + sys.stderr.write("\n") sys.stderr.flush() if inv_tries == 10: - logging.error('No response from the ESP') + logging.error("No response from the ESP") return 1 if data != "OK": - if data.startswith('AUTH'): + if data.startswith("AUTH"): nonce = data.split()[1] - cnonce_text = '%s%u%s%s' % (filename, content_size, file_md5, remote_addr) + cnonce_text = "%s%u%s%s" % (filename, content_size, file_md5, remote_addr) cnonce = hashlib.md5(cnonce_text.encode()).hexdigest() passmd5 = hashlib.md5(password.encode()).hexdigest() - result_text = '%s:%s:%s' % (passmd5, nonce, cnonce) + result_text = "%s:%s:%s" % (passmd5, nonce, cnonce) result = hashlib.md5(result_text.encode()).hexdigest() - sys.stderr.write('Authenticating...') + sys.stderr.write("Authenticating...") sys.stderr.flush() - message = '%d %s %s\n' % (AUTH, cnonce, result) + message = "%d %s %s\n" % (AUTH, cnonce, result) sock2.sendto(message.encode(), remote_address) sock2.settimeout(10) try: data = sock2.recv(32).decode() - except: - sys.stderr.write('FAIL\n') - logging.error('No Answer to our Authentication') + except: # noqa: E722 + sys.stderr.write("FAIL\n") + logging.error("No Answer to our Authentication") sock2.close() return 1 if data != "OK": - sys.stderr.write('FAIL\n') - logging.error('%s', data) + sys.stderr.write("FAIL\n") + logging.error("%s", data) sock2.close() sys.exit(1) return 1 - sys.stderr.write('OK\n') + sys.stderr.write("OK\n") else: - logging.error('Bad Answer: %s', data) + logging.error("Bad Answer: %s", data) sock2.close() return 1 sock2.close() - logging.info('Waiting for device...') + logging.info("Waiting for device...") try: sock.settimeout(10) connection, client_address = sock.accept() sock.settimeout(None) connection.settimeout(None) - except: - logging.error('No response from device') + except: # noqa: E722 + logging.error("No response from device") sock.close() return 1 try: @@ -172,7 +177,7 @@ def serve(remote_addr, local_addr, remote_port, local_port, password, filename, if PROGRESS: update_progress(0) else: - sys.stderr.write('Uploading') + sys.stderr.write("Uploading") sys.stderr.flush() offset = 0 while True: @@ -185,39 +190,39 @@ def serve(remote_addr, local_addr, remote_port, local_port, password, filename, try: connection.sendall(chunk) res = connection.recv(10) - last_response_contained_ok = 'OK' in res.decode() + last_response_contained_ok = "OK" in res.decode() except Exception as e: - sys.stderr.write('\n') - logging.error('Error Uploading: %s', str(e)) + sys.stderr.write("\n") + logging.error("Error Uploading: %s", str(e)) connection.close() return 1 if last_response_contained_ok: - logging.info('Success') + logging.info("Success") connection.close() return 0 - sys.stderr.write('\n') - logging.info('Waiting for result...') + sys.stderr.write("\n") + logging.info("Waiting for result...") count = 0 while count < 5: count += 1 connection.settimeout(60) try: data = connection.recv(32).decode() - logging.info('Result: %s', data) + logging.info("Result: %s", data) if "OK" in data: - logging.info('Success') + logging.info("Success") connection.close() return 0 except Exception as e: - logging.error('Error receiving result: %s', str(e)) + logging.error("Error receiving result: %s", str(e)) connection.close() return 1 - logging.error('Error response from device') + logging.error("Error response from device") connection.close() return 1 @@ -229,16 +234,19 @@ def serve(remote_addr, local_addr, remote_port, local_port, password, filename, def parse_args(unparsed_args): - parser = argparse.ArgumentParser( - description="Transmit image over the air to the ESP32 module with OTA support." - ) + parser = argparse.ArgumentParser(description="Transmit image over the air to the ESP32 module with OTA support.") # destination ip and port parser.add_argument("-i", "--ip", dest="esp_ip", action="store", help="ESP32 IP Address.", default=False) parser.add_argument("-I", "--host_ip", dest="host_ip", action="store", help="Host IP Address.", default="0.0.0.0") parser.add_argument("-p", "--port", dest="esp_port", type=int, help="ESP32 OTA Port. Default: 3232", default=3232) parser.add_argument( - "-P", "--host_port", dest="host_port", type=int, help="Host server OTA Port. Default: random 10000-60000", default=random.randint(10000, 60000) + "-P", + "--host_port", + dest="host_port", + type=int, + help="Host server OTA Port. Default: random 10000-60000", + default=random.randint(10000, 60000), ) # authentication @@ -246,12 +254,40 @@ def parse_args(unparsed_args): # image parser.add_argument("-f", "--file", dest="image", help="Image file.", metavar="FILE", default=None) - parser.add_argument("-s", "--spiffs", dest="spiffs", action="store_true", help="Transmit a SPIFFS image and do not flash the module.", default=False) + parser.add_argument( + "-s", + "--spiffs", + dest="spiffs", + action="store_true", + help="Transmit a SPIFFS image and do not flash the module.", + default=False, + ) # output - parser.add_argument("-d", "--debug", dest="debug", action="store_true", help="Show debug output. Overrides loglevel with debug.", default=False) - parser.add_argument("-r", "--progress", dest="progress", action="store_true", help="Show progress output. Does not work for Arduino IDE.", default=False) - parser.add_argument("-t", "--timeout", dest="timeout", type=int, help="Timeout to wait for the ESP32 to accept invitation.", default=10) + parser.add_argument( + "-d", + "--debug", + dest="debug", + action="store_true", + help="Show debug output. Overrides loglevel with debug.", + default=False, + ) + parser.add_argument( + "-r", + "--progress", + dest="progress", + action="store_true", + help="Show progress output. Does not work for Arduino IDE.", + default=False, + ) + parser.add_argument( + "-t", + "--timeout", + dest="timeout", + type=int, + help="Timeout to wait for the ESP32 to accept invitation.", + default=10, + ) return parser.parse_args(unparsed_args) diff --git a/tools/gen_crt_bundle.py b/tools/gen_crt_bundle.py index 87e29e61fa4..4f2c78c1df4 100644 --- a/tools/gen_crt_bundle.py +++ b/tools/gen_crt_bundle.py @@ -37,27 +37,29 @@ from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import serialization except ImportError: - print('The cryptography package is not installed.' - 'Please refer to the Get Started section of the ESP-IDF Programming Guide for ' - 'setting up the required packages.') + print( + "The cryptography package is not installed." + "Please refer to the Get Started section of the ESP-IDF Programming Guide for " + "setting up the required packages." + ) raise -ca_bundle_bin_file = 'x509_crt_bundle' +ca_bundle_bin_file = "x509_crt_bundle" quiet = False def status(msg): - """ Print status message to stderr """ + """Print status message to stderr""" if not quiet: critical(msg) def critical(msg): - """ Print critical message to stderr """ - sys.stderr.write('gen_crt_bundle.py: ') + """Print critical message to stderr""" + sys.stderr.write("gen_crt_bundle.py: ") sys.stderr.write(msg) - sys.stderr.write('\n') + sys.stderr.write("\n") class CertificateBundle: @@ -75,75 +77,77 @@ def add_from_path(self, crts_path): found |= self.add_from_file(os.path.join(crts_path, file_path)) if found is False: - raise InputError('No valid x509 certificates found in %s' % crts_path) + raise InputError("No valid x509 certificates found in %s" % crts_path) def add_from_file(self, file_path): try: - if file_path.endswith('.pem'): - status('Parsing certificates from %s' % file_path) - with open(file_path, 'r', encoding='utf-8') as f: + if file_path.endswith(".pem"): + status("Parsing certificates from %s" % file_path) + with open(file_path, "r", encoding="utf-8") as f: crt_str = f.read() self.add_from_pem(crt_str) return True - elif file_path.endswith('.der'): - status('Parsing certificates from %s' % file_path) - with open(file_path, 'rb') as f: + elif file_path.endswith(".der"): + status("Parsing certificates from %s" % file_path) + with open(file_path, "rb") as f: crt_str = f.read() self.add_from_der(crt_str) return True except ValueError: - critical('Invalid certificate in %s' % file_path) - raise InputError('Invalid certificate') + critical("Invalid certificate in %s" % file_path) + raise InputError("Invalid certificate") return False def add_from_pem(self, crt_str): - """ A single PEM file may have multiple certificates """ + """A single PEM file may have multiple certificates""" - crt = '' + crt = "" count = 0 start = False for strg in crt_str.splitlines(True): - if strg == '-----BEGIN CERTIFICATE-----\n' and start is False: - crt = '' + if strg == "-----BEGIN CERTIFICATE-----\n" and start is False: + crt = "" start = True - elif strg == '-----END CERTIFICATE-----\n' and start is True: - crt += strg + '\n' + elif strg == "-----END CERTIFICATE-----\n" and start is True: + crt += strg + "\n" start = False self.certificates.append(x509.load_pem_x509_certificate(crt.encode(), default_backend())) count += 1 if start is True: crt += strg - if(count == 0): - raise InputError('No certificate found') + if count == 0: + raise InputError("No certificate found") - status('Successfully added %d certificates' % count) + status("Successfully added %d certificates" % count) def add_from_der(self, crt_str): self.certificates.append(x509.load_der_x509_certificate(crt_str, default_backend())) - status('Successfully added 1 certificate') + status("Successfully added 1 certificate") def create_bundle(self): # Sort certificates in order to do binary search when looking up certificates self.certificates = sorted(self.certificates, key=lambda cert: cert.subject.public_bytes(default_backend())) - bundle = struct.pack('>H', len(self.certificates)) + bundle = struct.pack(">H", len(self.certificates)) for crt in self.certificates: - """ Read the public key as DER format """ + """Read the public key as DER format""" pub_key = crt.public_key() - pub_key_der = pub_key.public_bytes(serialization.Encoding.DER, serialization.PublicFormat.SubjectPublicKeyInfo) + pub_key_der = pub_key.public_bytes( + serialization.Encoding.DER, serialization.PublicFormat.SubjectPublicKeyInfo + ) """ Read the subject name as DER format """ sub_name_der = crt.subject.public_bytes(default_backend()) name_len = len(sub_name_der) key_len = len(pub_key_der) - len_data = struct.pack('>HH', name_len, key_len) + len_data = struct.pack(">HH", name_len, key_len) bundle += len_data bundle += sub_name_der @@ -154,23 +158,23 @@ def create_bundle(self): def add_with_filter(self, crts_path, filter_path): filter_set = set() - with open(filter_path, 'r', encoding='utf-8') as f: - csv_reader = csv.reader(f, delimiter=',') + with open(filter_path, "r", encoding="utf-8") as f: + csv_reader = csv.reader(f, delimiter=",") # Skip header next(csv_reader) for row in csv_reader: filter_set.add(row[1]) - status('Parsing certificates from %s' % crts_path) + status("Parsing certificates from %s" % crts_path) crt_str = [] - with open(crts_path, 'r', encoding='utf-8') as f: + with open(crts_path, "r", encoding="utf-8") as f: crt_str = f.read() # Split all certs into a list of (name, certificate string) tuples - pem_crts = re.findall(r'(^.+?)\n(=+\n[\s\S]+?END CERTIFICATE-----\n)', crt_str, re.MULTILINE) + pem_crts = re.findall(r"(^.+?)\n(=+\n[\s\S]+?END CERTIFICATE-----\n)", crt_str, re.MULTILINE) - filtered_crts = '' + filtered_crts = "" for name, crt in pem_crts: if name in filter_set: filtered_crts += crt @@ -186,13 +190,22 @@ def __init__(self, e): def main(): global quiet - parser = argparse.ArgumentParser(description='ESP-IDF x509 certificate bundle utility') - - parser.add_argument('--quiet', '-q', help="Don't print non-critical status messages to stderr", action='store_true') - parser.add_argument('--input', '-i', nargs='+', required=True, - help='Paths to the custom certificate folders or files to parse, parses all .pem or .der files') - parser.add_argument('--filter', '-f', help='Path to CSV-file where the second columns contains the name of the certificates \ - that should be included from cacrt_all.pem') + parser = argparse.ArgumentParser(description="ESP-IDF x509 certificate bundle utility") + + parser.add_argument("--quiet", "-q", help="Don't print non-critical status messages to stderr", action="store_true") + parser.add_argument( + "--input", + "-i", + nargs="+", + required=True, + help="Paths to the custom certificate folders or files to parse, parses all .pem or .der files", + ) + parser.add_argument( + "--filter", + "-f", + help="Path to CSV-file where the second columns contains the name of the certificates \ + that should be included from cacrt_all.pem", + ) args = parser.parse_args() @@ -202,24 +215,24 @@ def main(): for path in args.input: if os.path.isfile(path): - if os.path.basename(path) == 'cacrt_all.pem' and args.filter: + if os.path.basename(path) == "cacrt_all.pem" and args.filter: bundle.add_with_filter(path, args.filter) else: bundle.add_from_file(path) elif os.path.isdir(path): bundle.add_from_path(path) else: - raise InputError('Invalid --input=%s, is neither file nor folder' % args.input) + raise InputError("Invalid --input=%s, is neither file nor folder" % args.input) - status('Successfully added %d certificates in total' % len(bundle.certificates)) + status("Successfully added %d certificates in total" % len(bundle.certificates)) crt_bundle = bundle.create_bundle() - with open(ca_bundle_bin_file, 'wb') as f: + with open(ca_bundle_bin_file, "wb") as f: f.write(crt_bundle) -if __name__ == '__main__': +if __name__ == "__main__": try: main() except InputError as e: diff --git a/tools/gen_esp32part.py b/tools/gen_esp32part.py index 5eb8475539e..4ba0ee59517 100755 --- a/tools/gen_esp32part.py +++ b/tools/gen_esp32part.py @@ -21,30 +21,30 @@ import struct import sys -MAX_PARTITION_LENGTH = 0xC00 # 3K for partition data (96 entries) leaves 1K in a 4K sector for signature -MD5_PARTITION_BEGIN = b'\xEB\xEB' + b'\xFF' * 14 # The first 2 bytes are like magic numbers for MD5 sum -PARTITION_TABLE_SIZE = 0x1000 # Size of partition table +MAX_PARTITION_LENGTH = 0xC00 # 3K for partition data (96 entries) leaves 1K in a 4K sector for signature +MD5_PARTITION_BEGIN = b"\xEB\xEB" + b"\xFF" * 14 # The first 2 bytes are like magic numbers for MD5 sum +PARTITION_TABLE_SIZE = 0x1000 # Size of partition table MIN_PARTITION_SUBTYPE_APP_OTA = 0x10 NUM_PARTITION_SUBTYPE_APP_OTA = 16 SECURE_NONE = None -SECURE_V1 = 'v1' -SECURE_V2 = 'v2' +SECURE_V1 = "v1" +SECURE_V2 = "v2" -__version__ = '1.2' +__version__ = "1.2" APP_TYPE = 0x00 DATA_TYPE = 0x01 TYPES = { - 'app': APP_TYPE, - 'data': DATA_TYPE, + "app": APP_TYPE, + "data": DATA_TYPE, } def get_ptype_as_int(ptype): - """ Convert a string which might be numeric or the name of a partition type to an integer """ + """Convert a string which might be numeric or the name of a partition type to an integer""" try: return TYPES[ptype] except KeyError: @@ -57,27 +57,27 @@ def get_ptype_as_int(ptype): # Keep this map in sync with esp_partition_subtype_t enum in esp_partition.h SUBTYPES = { APP_TYPE: { - 'factory': 0x00, - 'test': 0x20, + "factory": 0x00, + "test": 0x20, }, DATA_TYPE: { - 'ota': 0x00, - 'phy': 0x01, - 'nvs': 0x02, - 'coredump': 0x03, - 'nvs_keys': 0x04, - 'efuse': 0x05, - 'undefined': 0x06, - 'esphttpd': 0x80, - 'fat': 0x81, - 'spiffs': 0x82, - 'littlefs': 0x83, + "ota": 0x00, + "phy": 0x01, + "nvs": 0x02, + "coredump": 0x03, + "nvs_keys": 0x04, + "efuse": 0x05, + "undefined": 0x06, + "esphttpd": 0x80, + "fat": 0x81, + "spiffs": 0x82, + "littlefs": 0x83, }, } def get_subtype_as_int(ptype, subtype): - """ Convert a string which might be numeric or the name of a partition subtype to an integer """ + """Convert a string which might be numeric or the name of a partition subtype to an integer""" try: return SUBTYPES[get_ptype_as_int(ptype)][subtype] except KeyError: @@ -106,28 +106,28 @@ def get_alignment_size_for_type(ptype): # For secure boot v2 case, app partition must be 4K aligned # signature block (4K) is kept after padding the unsigned image to 64K boundary return 0x1000 - # No specific size alignement requirement as such + # No specific size alignment requirement as such return 0x1 def get_partition_type(ptype): - if ptype == 'app': + if ptype == "app": return APP_TYPE - if ptype == 'data': + if ptype == "data": return DATA_TYPE - raise InputError('Invalid partition type') + raise InputError("Invalid partition type") def add_extra_subtypes(csv): for line_no in csv: try: - fields = [line.strip() for line in line_no.split(',')] + fields = [line.strip() for line in line_no.split(",")] for subtype, subtype_values in SUBTYPES.items(): - if (int(fields[2], 16) in subtype_values.values() and subtype == get_partition_type(fields[0])): - raise ValueError('Found duplicate value in partition subtype') + if int(fields[2], 16) in subtype_values.values() and subtype == get_partition_type(fields[0]): + raise ValueError("Found duplicate value in partition subtype") SUBTYPES[TYPES[fields[0]]][fields[1]] = int(fields[2], 16) except InputError as err: - raise InputError('Error parsing custom subtypes: %s' % err) + raise InputError("Error parsing custom subtypes: %s" % err) quiet = False @@ -137,15 +137,15 @@ def add_extra_subtypes(csv): def status(msg): - """ Print status message to stderr """ + """Print status message to stderr""" if not quiet: critical(msg) def critical(msg): - """ Print critical message to stderr """ + """Print critical message to stderr""" sys.stderr.write(msg) - sys.stderr.write('\n') + sys.stderr.write("\n") class PartitionTable(list): @@ -157,35 +157,38 @@ def from_file(cls, f): data = f.read() data_is_binary = data[0:2] == PartitionDefinition.MAGIC_BYTES if data_is_binary: - status('Parsing binary partition input...') + status("Parsing binary partition input...") return cls.from_binary(data), True data = data.decode() - status('Parsing CSV input...') + status("Parsing CSV input...") return cls.from_csv(data), False @classmethod - def from_csv(cls, csv_contents): + def from_csv(cls, csv_contents): # noqa: C901 res = PartitionTable() lines = csv_contents.splitlines() def expand_vars(f): f = os.path.expandvars(f) - m = re.match(r'(? 1) + duplicates = set(n for n in names if names.count(n) > 1) # noqa: C401 # print sorted duplicate partitions by name if len(duplicates) != 0: - critical('A list of partitions that have the same name:') - for p in sorted(self, key=lambda x:x.name): + critical("A list of partitions that have the same name:") + for p in sorted(self, key=lambda x: x.name): if len(duplicates.intersection([p.name])) != 0: - critical('%s' % (p.to_csv())) - raise InputError('Partition names must be unique') + critical("%s" % (p.to_csv())) + raise InputError("Partition names must be unique") # check for overlaps last = None - for p in sorted(self, key=lambda x:x.offset): + for p in sorted(self, key=lambda x: x.offset): if p.offset < offset_part_table + PARTITION_TABLE_SIZE: - raise InputError('Partition offset 0x%x is below 0x%x' % (p.offset, offset_part_table + PARTITION_TABLE_SIZE)) + raise InputError( + "Partition offset 0x%x is below 0x%x" % (p.offset, offset_part_table + PARTITION_TABLE_SIZE) + ) if last is not None and p.offset < last.offset + last.size: - raise InputError('Partition at 0x%x overlaps 0x%x-0x%x' % (p.offset, last.offset, last.offset + last.size - 1)) + raise InputError( + "Partition at 0x%x overlaps 0x%x-0x%x" % (p.offset, last.offset, last.offset + last.size - 1) + ) last = p # check that otadata should be unique - otadata_duplicates = [p for p in self if p.type == TYPES['data'] and p.subtype == SUBTYPES[DATA_TYPE]['ota']] + otadata_duplicates = [p for p in self if p.type == TYPES["data"] and p.subtype == SUBTYPES[DATA_TYPE]["ota"]] if len(otadata_duplicates) > 1: for p in otadata_duplicates: - critical('%s' % (p.to_csv())) - raise InputError('Found multiple otadata partitions. Only one partition can be defined with type="data"(1) and subtype="ota"(0).') + critical("%s" % (p.to_csv())) + raise InputError( + 'Found multiple otadata partitions. Only one partition can be defined with type="data"(1) and subtype="ota"(0).' # noqa: E501 + ) if len(otadata_duplicates) == 1 and otadata_duplicates[0].size != 0x2000: p = otadata_duplicates[0] - critical('%s' % (p.to_csv())) - raise InputError('otadata partition must have size = 0x2000') + critical("%s" % (p.to_csv())) + raise InputError("otadata partition must have size = 0x2000") def flash_size(self): - """ Return the size that partitions will occupy in flash - (ie the offset the last partition ends at) + """Return the size that partitions will occupy in flash + (ie the offset the last partition ends at) """ try: last = sorted(self, reverse=True)[0] @@ -289,67 +301,69 @@ def flash_size(self): return last.offset + last.size def verify_size_fits(self, flash_size_bytes: int) -> None: - """ Check that partition table fits into the given flash size. - Raises InputError otherwise. + """Check that partition table fits into the given flash size. + Raises InputError otherwise. """ table_size = self.flash_size() if flash_size_bytes < table_size: mb = 1024 * 1024 - raise InputError('Partitions tables occupies %.1fMB of flash (%d bytes) which does not fit in configured ' - "flash size %dMB. Change the flash size in menuconfig under the 'Serial Flasher Config' menu." % - (table_size / mb, table_size, flash_size_bytes / mb)) + raise InputError( + "Partitions tables occupies %.1fMB of flash (%d bytes) which does not fit in configured " + "flash size %dMB. Change the flash size in menuconfig under the 'Serial Flasher Config' menu." + % (table_size / mb, table_size, flash_size_bytes / mb) + ) @classmethod def from_binary(cls, b): md5 = hashlib.md5() result = cls() - for o in range(0,len(b),32): - data = b[o:o + 32] + for o in range(0, len(b), 32): + data = b[o : o + 32] if len(data) != 32: - raise InputError('Partition table length must be a multiple of 32 bytes') - if data == b'\xFF' * 32: + raise InputError("Partition table length must be a multiple of 32 bytes") + if data == b"\xFF" * 32: return result # got end marker if md5sum and data[:2] == MD5_PARTITION_BEGIN[:2]: # check only the magic number part if data[16:] == md5.digest(): continue # the next iteration will check for the end marker else: - raise InputError("MD5 checksums don't match! (computed: 0x%s, parsed: 0x%s)" % (md5.hexdigest(), binascii.hexlify(data[16:]))) + raise InputError( + "MD5 checksums don't match! (computed: 0x%s, parsed: 0x%s)" + % (md5.hexdigest(), binascii.hexlify(data[16:])) + ) else: md5.update(data) result.append(PartitionDefinition.from_binary(data)) - raise InputError('Partition table is missing an end-of-table marker') + raise InputError("Partition table is missing an end-of-table marker") def to_binary(self): - result = b''.join(e.to_binary() for e in self) + result = b"".join(e.to_binary() for e in self) if md5sum: result += MD5_PARTITION_BEGIN + hashlib.md5(result).digest() if len(result) >= MAX_PARTITION_LENGTH: - raise InputError('Binary partition table length (%d) longer than max' % len(result)) - result += b'\xFF' * (MAX_PARTITION_LENGTH - len(result)) # pad the sector, for signing + raise InputError("Binary partition table length (%d) longer than max" % len(result)) + result += b"\xFF" * (MAX_PARTITION_LENGTH - len(result)) # pad the sector, for signing return result def to_csv(self, simple_formatting=False): - rows = ['# ESP-IDF Partition Table', - '# Name, Type, SubType, Offset, Size, Flags'] + rows = ["# ESP-IDF Partition Table", "# Name, Type, SubType, Offset, Size, Flags"] rows += [x.to_csv(simple_formatting) for x in self] - return '\n'.join(rows) + '\n' + return "\n".join(rows) + "\n" class PartitionDefinition(object): - MAGIC_BYTES = b'\xAA\x50' + MAGIC_BYTES = b"\xAA\x50" # dictionary maps flag name (as used in CSV flags list, property name) # to bit set in flags words in binary format - FLAGS = { - 'encrypted': 0 - } + FLAGS = {"encrypted": 0} # add subtypes for the 16 OTA slot values ("ota_XX, etc.") for ota_slot in range(NUM_PARTITION_SUBTYPE_APP_OTA): - SUBTYPES[TYPES['app']]['ota_%d' % ota_slot] = MIN_PARTITION_SUBTYPE_APP_OTA + ota_slot + SUBTYPES[TYPES["app"]]["ota_%d" % ota_slot] = MIN_PARTITION_SUBTYPE_APP_OTA + ota_slot def __init__(self): - self.name = '' + self.name = "" self.type = None self.subtype = None self.offset = None @@ -358,9 +372,9 @@ def __init__(self): @classmethod def from_csv(cls, line, line_no): - """ Parse a line from the CSV """ - line_w_defaults = line + ',,,,' # lazy way to support default fields - fields = [f.strip() for f in line_w_defaults.split(',')] + """Parse a line from the CSV""" + line_w_defaults = line + ",,,," # lazy way to support default fields + fields = [f.strip() for f in line_w_defaults.split(",")] res = PartitionDefinition() res.line_no = line_no @@ -372,7 +386,7 @@ def from_csv(cls, line, line_no): if res.size is None: raise InputError("Size field can't be empty") - flags = fields[5].split(':') + flags = fields[5].split(":") for flag in flags: if flag in cls.FLAGS: setattr(res, flag, True) @@ -382,18 +396,34 @@ def from_csv(cls, line, line_no): return res def __eq__(self, other): - return self.name == other.name and self.type == other.type \ - and self.subtype == other.subtype and self.offset == other.offset \ + return ( + self.name == other.name + and self.type == other.type + and self.subtype == other.subtype + and self.offset == other.offset and self.size == other.size + ) def __repr__(self): def maybe_hex(x): - return '0x%x' % x if x is not None else 'None' - return "PartitionDefinition('%s', 0x%x, 0x%x, %s, %s)" % (self.name, self.type, self.subtype or 0, - maybe_hex(self.offset), maybe_hex(self.size)) + return "0x%x" % x if x is not None else "None" + + return "PartitionDefinition('%s', 0x%x, 0x%x, %s, %s)" % ( + self.name, + self.type, + self.subtype or 0, + maybe_hex(self.offset), + maybe_hex(self.size), + ) def __str__(self): - return "Part '%s' %d/%d @ 0x%x size 0x%x" % (self.name, self.type, self.subtype, self.offset or -1, self.size or -1) + return "Part '%s' %d/%d @ 0x%x size 0x%x" % ( + self.name, + self.type, + self.subtype, + self.offset or -1, + self.size or -1, + ) def __cmp__(self, other): return self.offset - other.offset @@ -411,69 +441,73 @@ def __ge__(self, other): return self.offset >= other.offset def parse_type(self, strval): - if strval == '': + if strval == "": raise InputError("Field 'type' can't be left empty.") return parse_int(strval, TYPES) def parse_subtype(self, strval): - if strval == '': - if self.type == TYPES['app']: - raise InputError('App partition cannot have an empty subtype') - return SUBTYPES[DATA_TYPE]['undefined'] + if strval == "": + if self.type == TYPES["app"]: + raise InputError("App partition cannot have an empty subtype") + return SUBTYPES[DATA_TYPE]["undefined"] return parse_int(strval, SUBTYPES.get(self.type, {})) def parse_address(self, strval): - if strval == '': + if strval == "": return None # PartitionTable will fill in default return parse_int(strval) - def verify(self): + def verify(self): # noqa: C901 if self.type is None: - raise ValidationError(self, 'Type field is not set') + raise ValidationError(self, "Type field is not set") if self.subtype is None: - raise ValidationError(self, 'Subtype field is not set') + raise ValidationError(self, "Subtype field is not set") if self.offset is None: - raise ValidationError(self, 'Offset field is not set') + raise ValidationError(self, "Offset field is not set") if self.size is None: - raise ValidationError(self, 'Size field is not set') + raise ValidationError(self, "Size field is not set") offset_align = get_alignment_offset_for_type(self.type) if self.offset % offset_align: - raise ValidationError(self, 'Offset 0x%x is not aligned to 0x%x' % (self.offset, offset_align)) + raise ValidationError(self, "Offset 0x%x is not aligned to 0x%x" % (self.offset, offset_align)) if self.type == APP_TYPE and secure is not SECURE_NONE: size_align = get_alignment_size_for_type(self.type) if self.size % size_align: - raise ValidationError(self, 'Size 0x%x is not aligned to 0x%x' % (self.size, size_align)) + raise ValidationError(self, "Size 0x%x is not aligned to 0x%x" % (self.size, size_align)) - if self.name in TYPES and TYPES.get(self.name, '') != self.type: - critical("WARNING: Partition has name '%s' which is a partition type, but does not match this partition's " - 'type (0x%x). Mistake in partition table?' % (self.name, self.type)) + if self.name in TYPES and TYPES.get(self.name, "") != self.type: + critical( + "WARNING: Partition has name '%s' which is a partition type, but does not match this partition's " + "type (0x%x). Mistake in partition table?" % (self.name, self.type) + ) all_subtype_names = [] for names in (t.keys() for t in SUBTYPES.values()): all_subtype_names += names - if self.name in all_subtype_names and SUBTYPES.get(self.type, {}).get(self.name, '') != self.subtype: - critical("WARNING: Partition has name '%s' which is a partition subtype, but this partition has " - 'non-matching type 0x%x and subtype 0x%x. Mistake in partition table?' % (self.name, self.type, self.subtype)) + if self.name in all_subtype_names and SUBTYPES.get(self.type, {}).get(self.name, "") != self.subtype: + critical( + "WARNING: Partition has name '%s' which is a partition subtype, but this partition has " + "non-matching type 0x%x and subtype 0x%x. Mistake in partition table?" + % (self.name, self.type, self.subtype) + ) - STRUCT_FORMAT = b'<2sBBLL16sL' + STRUCT_FORMAT = b"<2sBBLL16sL" @classmethod def from_binary(cls, b): if len(b) != 32: - raise InputError('Partition definition length must be exactly 32 bytes. Got %d bytes.' % len(b)) + raise InputError("Partition definition length must be exactly 32 bytes. Got %d bytes." % len(b)) res = cls() - (magic, res.type, res.subtype, res.offset, - res.size, res.name, flags) = struct.unpack(cls.STRUCT_FORMAT, b) - if b'\x00' in res.name: # strip null byte padding from name string - res.name = res.name[:res.name.index(b'\x00')] + (magic, res.type, res.subtype, res.offset, res.size, res.name, flags) = struct.unpack(cls.STRUCT_FORMAT, b) + if b"\x00" in res.name: # strip null byte padding from name string + res.name = res.name[: res.name.index(b"\x00")] res.name = res.name.decode() if magic != cls.MAGIC_BYTES: - raise InputError('Invalid magic bytes (%r) for partition definition' % magic) - for flag,bit in cls.FLAGS.items(): + raise InputError("Invalid magic bytes (%r) for partition definition" % magic) + for flag, bit in cls.FLAGS.items(): if flags & (1 << bit): setattr(res, flag, True) flags &= ~(1 << bit) if flags != 0: - critical('WARNING: Partition definition had unknown flag(s) 0x%08x. Newer binary format?' % flags) + critical("WARNING: Partition definition had unknown flag(s) 0x%08x. Newer binary format?" % flags) return res def get_flags_list(self): @@ -481,37 +515,45 @@ def get_flags_list(self): def to_binary(self): flags = sum((1 << self.FLAGS[flag]) for flag in self.get_flags_list()) - return struct.pack(self.STRUCT_FORMAT, - self.MAGIC_BYTES, - self.type, self.subtype, - self.offset, self.size, - self.name.encode(), - flags) + return struct.pack( + self.STRUCT_FORMAT, + self.MAGIC_BYTES, + self.type, + self.subtype, + self.offset, + self.size, + self.name.encode(), + flags, + ) def to_csv(self, simple_formatting=False): def addr_format(a, include_sizes): if not simple_formatting and include_sizes: - for (val, suffix) in [(0x100000, 'M'), (0x400, 'K')]: + for (val, suffix) in [(0x100000, "M"), (0x400, "K")]: if a % val == 0: - return '%d%s' % (a // val, suffix) - return '0x%x' % a + return "%d%s" % (a // val, suffix) + return "0x%x" % a def lookup_keyword(t, keywords): - for k,v in keywords.items(): + for k, v in keywords.items(): if simple_formatting is False and t == v: return k - return '%d' % t + return "%d" % t def generate_text_flags(): - """ colon-delimited list of flags """ - return ':'.join(self.get_flags_list()) + """colon-delimited list of flags""" + return ":".join(self.get_flags_list()) - return ','.join([self.name, - lookup_keyword(self.type, TYPES), - lookup_keyword(self.subtype, SUBTYPES.get(self.type, {})), - addr_format(self.offset, False), - addr_format(self.size, True), - generate_text_flags()]) + return ",".join( + [ + self.name, + lookup_keyword(self.type, TYPES), + lookup_keyword(self.subtype, SUBTYPES.get(self.type, {})), + addr_format(self.offset, False), + addr_format(self.size, True), + generate_text_flags(), + ] + ) def parse_int(v, keywords={}): @@ -519,39 +561,60 @@ def parse_int(v, keywords={}): k/m/K/M suffixes and 'keyword' value lookup. """ try: - for letter, multiplier in [('k', 1024), ('m', 1024 * 1024)]: + for letter, multiplier in [("k", 1024), ("m", 1024 * 1024)]: if v.lower().endswith(letter): return parse_int(v[:-1], keywords) * multiplier return int(v, 0) except ValueError: if len(keywords) == 0: - raise InputError('Invalid field value %s' % v) + raise InputError("Invalid field value %s" % v) try: return keywords[v.lower()] except KeyError: - raise InputError("Value '%s' is not valid. Known keywords: %s" % (v, ', '.join(keywords))) + raise InputError("Value '%s' is not valid. Known keywords: %s" % (v, ", ".join(keywords))) -def main(): +def main(): # noqa: C901 global quiet global md5sum global offset_part_table global secure - parser = argparse.ArgumentParser(description='ESP32 partition table utility') - - parser.add_argument('--flash-size', help='Optional flash size limit, checks partition table fits in flash', - nargs='?', choices=['1MB', '2MB', '4MB', '8MB', '16MB', '32MB', '64MB', '128MB']) - parser.add_argument('--disable-md5sum', help='Disable md5 checksum for the partition table', default=False, action='store_true') - parser.add_argument('--no-verify', help="Don't verify partition table fields", action='store_true') - parser.add_argument('--verify', '-v', help='Verify partition table fields (deprecated, this behaviour is ' - 'enabled by default and this flag does nothing.', action='store_true') - parser.add_argument('--quiet', '-q', help="Don't print non-critical status messages to stderr", action='store_true') - parser.add_argument('--offset', '-o', help='Set offset partition table', default='0x8000') - parser.add_argument('--secure', help='Require app partitions to be suitable for secure boot', nargs='?', const=SECURE_V1, choices=[SECURE_V1, SECURE_V2]) - parser.add_argument('--extra-partition-subtypes', help='Extra partition subtype entries', nargs='*') - parser.add_argument('input', help='Path to CSV or binary file to parse.', type=argparse.FileType('rb')) - parser.add_argument('output', help='Path to output converted binary or CSV file. Will use stdout if omitted.', - nargs='?', default='-') + parser = argparse.ArgumentParser(description="ESP32 partition table utility") + + parser.add_argument( + "--flash-size", + help="Optional flash size limit, checks partition table fits in flash", + nargs="?", + choices=["1MB", "2MB", "4MB", "8MB", "16MB", "32MB", "64MB", "128MB"], + ) + parser.add_argument( + "--disable-md5sum", help="Disable md5 checksum for the partition table", default=False, action="store_true" + ) + parser.add_argument("--no-verify", help="Don't verify partition table fields", action="store_true") + parser.add_argument( + "--verify", + "-v", + help="Verify partition table fields (deprecated, this behavior is " + "enabled by default and this flag does nothing.", + action="store_true", + ) + parser.add_argument("--quiet", "-q", help="Don't print non-critical status messages to stderr", action="store_true") + parser.add_argument("--offset", "-o", help="Set offset partition table", default="0x8000") + parser.add_argument( + "--secure", + help="Require app partitions to be suitable for secure boot", + nargs="?", + const=SECURE_V1, + choices=[SECURE_V1, SECURE_V2], + ) + parser.add_argument("--extra-partition-subtypes", help="Extra partition subtype entries", nargs="*") + parser.add_argument("input", help="Path to CSV or binary file to parse.", type=argparse.FileType("rb")) + parser.add_argument( + "output", + help="Path to output converted binary or CSV file. Will use stdout if omitted.", + nargs="?", + default="-", + ) args = parser.parse_args() @@ -565,11 +628,11 @@ def main(): table, input_is_binary = PartitionTable.from_file(args.input) if not args.no_verify: - status('Verifying table...') + status("Verifying table...") table.verify() if args.flash_size: - size_mb = int(args.flash_size.replace('MB', '')) + size_mb = int(args.flash_size.replace("MB", "")) table.verify_size_fits(size_mb * 1024 * 1024) # Make sure that the output directory is created @@ -584,7 +647,7 @@ def main(): if input_is_binary: output = table.to_csv() - with sys.stdout if args.output == '-' else open(args.output, 'w') as f: + with sys.stdout if args.output == "-" else open(args.output, "w") as f: f.write(output) else: output = table.to_binary() @@ -592,7 +655,7 @@ def main(): stdout_binary = sys.stdout.buffer # Python 3 except AttributeError: stdout_binary = sys.stdout - with stdout_binary if args.output == '-' else open(args.output, 'wb') as f: + with stdout_binary if args.output == "-" else open(args.output, "wb") as f: f.write(output) @@ -603,11 +666,10 @@ def __init__(self, e): class ValidationError(InputError): def __init__(self, partition, message): - super(ValidationError, self).__init__( - 'Partition %s invalid: %s' % (partition.name, message)) + super(ValidationError, self).__init__("Partition %s invalid: %s" % (partition.name, message)) -if __name__ == '__main__': +if __name__ == "__main__": try: main() except InputError as e: diff --git a/tools/gen_insights_package.py b/tools/gen_insights_package.py index c2b5047d5d6..c9e2765ce94 100644 --- a/tools/gen_insights_package.py +++ b/tools/gen_insights_package.py @@ -10,22 +10,23 @@ PROJECT_NAME_SIZE = 32 # Input path of temporary build directory created by Arduino -BUILD_DIR=sys.argv[1] +BUILD_DIR = sys.argv[1] # Input project name -PROJ_NAME=sys.argv[2] +PROJ_NAME = sys.argv[2] # Input path to create output package -TARGET_PATH=sys.argv[3] +TARGET_PATH = sys.argv[3] + def main(): print("Creating ESP Insights Firmware Package.") archive_path = os.path.join(BUILD_DIR, PROJ_NAME) out_path = os.path.join(TARGET_PATH, PROJ_NAME) - + # Create target archive directories - os.makedirs(archive_path, exist_ok = True) - os.makedirs(os.path.join(archive_path, "partition_table"), exist_ok = True) - os.makedirs(os.path.join(archive_path, "bootloader"), exist_ok = True) - + os.makedirs(archive_path, exist_ok=True) + os.makedirs(os.path.join(archive_path, "partition_table"), exist_ok=True) + os.makedirs(os.path.join(archive_path, "bootloader"), exist_ok=True) + # Copy files from build directory to archive directory shutil.copy2(os.path.join(BUILD_DIR, PROJ_NAME + ".bin"), archive_path) shutil.copy2(os.path.join(BUILD_DIR, PROJ_NAME + ".elf"), archive_path) @@ -33,24 +34,20 @@ def main(): shutil.copy2(os.path.join(BUILD_DIR, "partitions.csv"), archive_path) shutil.copy2(os.path.join(BUILD_DIR, PROJ_NAME + ".bootloader.bin"), os.path.join(archive_path, "bootloader")) shutil.copy2(os.path.join(BUILD_DIR, PROJ_NAME + ".partitions.bin"), os.path.join(archive_path, "partition_table")) - - with open(os.path.join(BUILD_DIR, PROJ_NAME + ".bin"), 'rb') as bin_file: + + with open(os.path.join(BUILD_DIR, PROJ_NAME + ".bin"), "rb") as bin_file: bin_file.seek(VERSION_NAME_OFFSET) - version_name = (bin_file.read(VERSION_NAME_SIZE).decode('utf-8')).split('\x00', 1)[0] + version_name = (bin_file.read(VERSION_NAME_SIZE).decode("utf-8")).split("\x00", 1)[0] bin_file.seek(PROJECT_NAME_OFFSET) - project_name = (bin_file.read(PROJECT_NAME_SIZE).decode('utf-8')).split('\x00', 1)[0] - project_build_config_obj = { - "project" : { - "name" : project_name, - "version": version_name - } - } + project_name = (bin_file.read(PROJECT_NAME_SIZE).decode("utf-8")).split("\x00", 1)[0] + project_build_config_obj = {"project": {"name": project_name, "version": version_name}} with open(os.path.join(archive_path, "project_build_config.json"), "w") as json_file: json_file.write(json.dumps(project_build_config_obj)) - + shutil.make_archive(out_path, "zip", BUILD_DIR, PROJ_NAME) print("Archive created at {}".format(out_path + ".zip")) return -if __name__ == '__main__': - main() \ No newline at end of file + +if __name__ == "__main__": + main() diff --git a/tools/get.py b/tools/get.py index 10af3d14a9d..ffa314ec625 100755 --- a/tools/get.py +++ b/tools/get.py @@ -26,23 +26,25 @@ if sys.version_info[0] == 3: from urllib.request import urlretrieve from urllib.request import urlopen - unicode = lambda s: str(s) + + unicode = lambda s: str(s) # noqa: E731 else: # Not Python 3 - today, it is most likely to be Python 2 from urllib import urlretrieve from urllib import urlopen -if 'Windows' in platform.system(): +if "Windows" in platform.system(): import requests # determine if application is a script file or frozen exe -if getattr(sys, 'frozen', False): +if getattr(sys, "frozen", False): current_dir = os.path.dirname(os.path.realpath(unicode(sys.executable))) elif __file__: current_dir = os.path.dirname(os.path.realpath(unicode(__file__))) -#current_dir = os.path.dirname(os.path.realpath(unicode(__file__))) -dist_dir = current_dir + '/dist/' +# current_dir = os.path.dirname(os.path.realpath(unicode(__file__))) +dist_dir = current_dir + "/dist/" + def sha256sum(filename, blocksize=65536): hash = hashlib.sha256() @@ -51,6 +53,7 @@ def sha256sum(filename, blocksize=65536): hash.update(block) return hash.hexdigest() + def mkdir_p(path): try: os.makedirs(path) @@ -58,14 +61,15 @@ def mkdir_p(path): if exc.errno != errno.EEXIST or not os.path.isdir(path): raise + def report_progress(count, blockSize, totalSize): if sys.stdout.isatty(): if totalSize > 0: - percent = int(count*blockSize*100/totalSize) + percent = int(count * blockSize * 100 / totalSize) percent = min(100, percent) sys.stdout.write("\r%d%%" % percent) else: - sofar = (count*blockSize) / 1024 + sofar = (count * blockSize) / 1024 if sofar >= 1000: sofar /= 1024 sys.stdout.write("\r%dMB " % (sofar)) @@ -73,48 +77,51 @@ def report_progress(count, blockSize, totalSize): sys.stdout.write("\r%dKB" % (sofar)) sys.stdout.flush() + def unpack(filename, destination): - dirname = '' - print('Extracting {0} ...'.format(os.path.basename(filename))) + dirname = "" + print("Extracting {0} ...".format(os.path.basename(filename))) sys.stdout.flush() - if filename.endswith('tar.gz'): - tfile = tarfile.open(filename, 'r:gz') + if filename.endswith("tar.gz"): + tfile = tarfile.open(filename, "r:gz") tfile.extractall(destination) dirname = tfile.getnames()[0] - elif filename.endswith('tar.xz'): - tfile = tarfile.open(filename, 'r:xz') + elif filename.endswith("tar.xz"): + tfile = tarfile.open(filename, "r:xz") tfile.extractall(destination) dirname = tfile.getnames()[0] - elif filename.endswith('zip'): + elif filename.endswith("zip"): zfile = zipfile.ZipFile(filename) zfile.extractall(destination) dirname = zfile.namelist()[0] else: - raise NotImplementedError('Unsupported archive type') + raise NotImplementedError("Unsupported archive type") # a little trick to rename tool directories so they don't contain version number - rename_to = re.match(r'^([a-z][^\-]*\-*)+', dirname).group(0).strip('-') - if rename_to == dirname and dirname.startswith('esp32-arduino-libs-'): - rename_to = 'esp32-arduino-libs' + rename_to = re.match(r"^([a-z][^\-]*\-*)+", dirname).group(0).strip("-") + if rename_to == dirname and dirname.startswith("esp32-arduino-libs-"): + rename_to = "esp32-arduino-libs" if rename_to != dirname: - print('Renaming {0} to {1} ...'.format(dirname, rename_to)) + print("Renaming {0} to {1} ...".format(dirname, rename_to)) if os.path.isdir(rename_to): shutil.rmtree(rename_to) shutil.move(dirname, rename_to) -def download_file_with_progress(url,filename): + +def download_file_with_progress(url, filename): import ssl import contextlib + ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE - with contextlib.closing(urlopen(url,context=ctx)) as fp: - total_size = int(fp.getheader("Content-Length",fp.getheader("Content-length","0"))) + with contextlib.closing(urlopen(url, context=ctx)) as fp: + total_size = int(fp.getheader("Content-Length", fp.getheader("Content-length", "0"))) block_count = 0 block_size = 1024 * 8 block = fp.read(block_size) if block: - with open(filename,'wb') as out_file: + with open(filename, "wb") as out_file: out_file.write(block) block_count += 1 report_progress(block_count, block_size, total_size) @@ -126,19 +133,21 @@ def download_file_with_progress(url,filename): block_count += 1 report_progress(block_count, block_size, total_size) else: - raise Exception ('nonexisting file or connection error') + raise Exception("nonexisting file or connection error") -def download_file(url,filename): + +def download_file(url, filename): import ssl import contextlib + ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE - with contextlib.closing(urlopen(url,context=ctx)) as fp: + with contextlib.closing(urlopen(url, context=ctx)) as fp: block_size = 1024 * 8 block = fp.read(block_size) if block: - with open(filename,'wb') as out_file: + with open(filename, "wb") as out_file: out_file.write(block) while True: block = fp.read(block_size) @@ -146,57 +155,60 @@ def download_file(url,filename): break out_file.write(block) else: - raise Exception ('nonexisting file or connection error') + raise Exception("nonexisting file or connection error") + def get_tool(tool): sys_name = platform.system() - archive_name = tool['archiveFileName'] + archive_name = tool["archiveFileName"] local_path = dist_dir + archive_name - url = tool['url'] + url = tool["url"] if not os.path.isfile(local_path): - print('Downloading ' + archive_name + ' ...') + print("Downloading " + archive_name + " ...") sys.stdout.flush() - if 'CYGWIN_NT' in sys_name: + if "CYGWIN_NT" in sys_name: import ssl + ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE urlretrieve(url, local_path, report_progress, context=ctx) - elif 'Windows' in sys_name: + elif "Windows" in sys_name: r = requests.get(url) - f = open(local_path, 'wb') + f = open(local_path, "wb") f.write(r.content) f.close() else: - is_ci = os.environ.get('GITHUB_WORKSPACE'); + is_ci = os.environ.get("GITHUB_WORKSPACE") if is_ci: download_file(url, local_path) else: try: urlretrieve(url, local_path, report_progress) - except: + except: # noqa: E722 download_file_with_progress(url, local_path) sys.stdout.write("\rDone \n") sys.stdout.flush() else: - print('Tool {0} already downloaded'.format(archive_name)) + print("Tool {0} already downloaded".format(archive_name)) sys.stdout.flush() - unpack(local_path, '.') + unpack(local_path, ".") + def load_tools_list(filename, platform): - tools_info = json.load(open(filename))['packages'][0]['tools'] + tools_info = json.load(open(filename))["packages"][0]["tools"] tools_to_download = [] for t in tools_info: - tool_platform = [p for p in t['systems'] if p['host'] == platform] + tool_platform = [p for p in t["systems"] if p["host"] == platform] if len(tool_platform) == 0: # Fallback to x86 on Apple ARM - if platform == 'arm64-apple-darwin': - tool_platform = [p for p in t['systems'] if p['host'] == 'x86_64-apple-darwin'] + if platform == "arm64-apple-darwin": + tool_platform = [p for p in t["systems"] if p["host"] == "x86_64-apple-darwin"] if len(tool_platform) == 0: continue # Fallback to 32bit on 64bit x86 Windows - elif platform == 'x86_64-mingw32': - tool_platform = [p for p in t['systems'] if p['host'] == 'i686-mingw32'] + elif platform == "x86_64-mingw32": + tool_platform = [p for p in t["systems"] if p["host"] == "i686-mingw32"] if len(tool_platform) == 0: continue else: @@ -204,37 +216,43 @@ def load_tools_list(filename, platform): tools_to_download.append(tool_platform[0]) return tools_to_download + def identify_platform(): - arduino_platform_names = {'Darwin' : {32 : 'i386-apple-darwin', 64 : 'x86_64-apple-darwin'}, - 'DarwinARM': {32 : 'arm64-apple-darwin', 64 : 'arm64-apple-darwin'}, - 'Linux' : {32 : 'i686-pc-linux-gnu', 64 : 'x86_64-pc-linux-gnu'}, - 'LinuxARM' : {32 : 'arm-linux-gnueabihf', 64 : 'aarch64-linux-gnu'}, - 'Windows' : {32 : 'i686-mingw32', 64 : 'x86_64-mingw32'}} + arduino_platform_names = { + "Darwin": {32: "i386-apple-darwin", 64: "x86_64-apple-darwin"}, + "DarwinARM": {32: "arm64-apple-darwin", 64: "arm64-apple-darwin"}, + "Linux": {32: "i686-pc-linux-gnu", 64: "x86_64-pc-linux-gnu"}, + "LinuxARM": {32: "arm-linux-gnueabihf", 64: "aarch64-linux-gnu"}, + "Windows": {32: "i686-mingw32", 64: "x86_64-mingw32"}, + } bits = 32 if sys.maxsize > 2**32: bits = 64 sys_name = platform.system() sys_platform = platform.platform() - if 'Darwin' in sys_name and (sys_platform.find('arm') > 0 or sys_platform.find('arm64') > 0): - sys_name = 'DarwinARM' - if 'Linux' in sys_name and (sys_platform.find('arm') > 0 or sys_platform.find('aarch64') > 0): - sys_name = 'LinuxARM' - if 'CYGWIN_NT' in sys_name: - sys_name = 'Windows' - print('System: %s, Bits: %d, Info: %s' % (sys_name, bits, sys_platform)) + if "Darwin" in sys_name and (sys_platform.find("arm") > 0 or sys_platform.find("arm64") > 0): + sys_name = "DarwinARM" + if "Linux" in sys_name and (sys_platform.find("arm") > 0 or sys_platform.find("aarch64") > 0): + sys_name = "LinuxARM" + if "CYGWIN_NT" in sys_name: + sys_name = "Windows" + print("System: %s, Bits: %d, Info: %s" % (sys_name, bits, sys_platform)) return arduino_platform_names[sys_name][bits] -if __name__ == '__main__': - is_test = (len(sys.argv) > 1 and sys.argv[1] == '-h') + +if __name__ == "__main__": + is_test = len(sys.argv) > 1 and sys.argv[1] == "-h" if is_test: - print('Test run!') + print("Test run!") identified_platform = identify_platform() - print('Platform: {0}'.format(identified_platform)) - tools_to_download = load_tools_list(current_dir + '/../package/package_esp32_index.template.json', identified_platform) + print("Platform: {0}".format(identified_platform)) + tools_to_download = load_tools_list( + current_dir + "/../package/package_esp32_index.template.json", identified_platform + ) mkdir_p(dist_dir) for tool in tools_to_download: if is_test: - print('Would install: {0}'.format(tool['archiveFileName'])) + print("Would install: {0}".format(tool["archiveFileName"])) else: get_tool(tool) - print('Platform Tools Installed') + print("Platform Tools Installed") diff --git a/tools/ide-debug/svd/esp32.svd b/tools/ide-debug/svd/esp32.svd index 783023f1aec..7e895e4e354 100644 --- a/tools/ide-debug/svd/esp32.svd +++ b/tools/ide-debug/svd/esp32.svd @@ -28961,7 +28961,7 @@ Note: FIFO pointers will be out of reset after 2 cycles of system clocks in addi SEND_CCSD - When set, SD/MMC sends CCSD to the CE-ATA device. Software sets this bit only if the current command is expecting CCS (that is, RW_BLK), and if interrupts are enabled for the CE-ATA device. Once the CCSD pattern is sent to the device, SD/MMC automatically clears the SDHOST_SEND_CCSD bit. It also sets the Command Done (CD) bit in the SDHOST_RINTSTS_REG register, and generates an interrupt for the host, in case the Command Done interrupt is not masked. + When set, SD/MMC sends CCSD to the CE-ATA device. Software sets this bit only if the current command is expecting CCS (that is, RW_BLK), and if interrupts are enabled for the CE-ATA device. Once the CCSD pattern is sent to the device, SD/MMC automatically clears the SDHOST_SEND_CCSD bit. It also sets the Command Done (CD) bit in the SDHOST_RINTSTS_REG register, and generates an interrupt for the host, in case the Command Done interrupt is not masked. NOTE: Once the SDHOST_SEND_CCSD bit is set, it takes two card clock cycles to drive the CCSD on the CMD line. Due to this, within the boundary conditions the CCSD may be sent to the CE-ATA device, even if the device has signalled CCS. 9 1 @@ -29164,13 +29164,13 @@ Bit 12 (HLE): Hardware locked write error; Bit 11 (FRUN): FIFO underrun/overrun error; Bit 10 (HTO): Data starvation-by-host timeout; Bit 9 (DRTO): Data read timeout; -Bit 8 (RTO): Response timeout; -Bit 7 (DCRC): Data CRC error; -Bit 6 (RCRC): Response CRC error; -Bit 5 (RXDR): Receive FIFO data request; -Bit 4 (TXDR): Transmit FIFO data request; -Bit 3 (DTO): Data transfer over; -Bit 2 (CD): Command done; +Bit 8 (RTO): Response timeout; +Bit 7 (DCRC): Data CRC error; +Bit 6 (RCRC): Response CRC error; +Bit 5 (RXDR): Receive FIFO data request; +Bit 4 (TXDR): Transmit FIFO data request; +Bit 3 (DTO): Data transfer over; +Bit 2 (CD): Command done; Bit 1 (RE): Response error; Bit 0 (CD): Card detect. 0 @@ -29321,7 +29321,7 @@ Software should set this bit to indicate that CE-ATA device is being accessed fo CCS_EXPECTED Expected Command Completion Signal (CCS) configuration. 0: Interrupts are not enabled in CE-ATA device (nIEN = 1 in ATA control register), or command does not expect CCS from device; -1: Interrupts are enabled in CE-ATA device (nIEN = 0), and RW_BLK command expects command completion signal from CE-ATA device. +1: Interrupts are enabled in CE-ATA device (nIEN = 0), and RW_BLK command expects command completion signal from CE-ATA device. If the command expects Command Completion Signal (CCS) from the CE-ATA device, the software should set this control bit. SD/MMC sets Data Transfer Over (DTO) bit in RINTSTS register and generates interrupt to host if Data Transfer Over interrupt is not masked. 23 1 @@ -29417,17 +29417,17 @@ If the command expects Command Completion Signal (CCS) from the CE-ATA device, t Bit 15 (EBE): End-bit error/no CRC error; Bit 14 (ACD): Auto command done; Bit 13 (SBE/BCI): RX Start Bit Error; -Bit 12 (HLE): Hardware locked write error; +Bit 12 (HLE): Hardware locked write error; Bit 11 (FRUN): FIFO underrun/overrun error; Bit 10 (HTO): Data starvation by host timeout (HTO); -Bit 9 (DTRO): Data read timeout; -Bit 8 (RTO): Response timeout; -Bit 7 (DCRC): Data CRC error; -Bit 6 (RCRC): Response CRC error; -Bit 5 (RXDR): Receive FIFO data request; +Bit 9 (DTRO): Data read timeout; +Bit 8 (RTO): Response timeout; +Bit 7 (DCRC): Data CRC error; +Bit 6 (RCRC): Response CRC error; +Bit 5 (RXDR): Receive FIFO data request; Bit 4 (TXDR): Transmit FIFO data request; -Bit 3 (DTO): Data transfer over; -Bit 2 (CD): Command done; +Bit 3 (DTO): Data transfer over; +Bit 2 (CD): Command done; Bit 1 (RE): Response error; Bit 0 (CD): Card detect. 0 @@ -29455,17 +29455,17 @@ Bit 0 (CD): Card detect. Bit 15 (EBE): End-bit error/no CRC error; Bit 14 (ACD): Auto command done; Bit 13 (SBE/BCI): RX Start Bit Error; -Bit 12 (HLE): Hardware locked write error; +Bit 12 (HLE): Hardware locked write error; Bit 11 (FRUN): FIFO underrun/overrun error; Bit 10 (HTO): Data starvation by host timeout (HTO); -Bit 9 (DTRO): Data read timeout; -Bit 8 (RTO): Response timeout; -Bit 7 (DCRC): Data CRC error; -Bit 6 (RCRC): Response CRC error; -Bit 5 (RXDR): Receive FIFO data request; +Bit 9 (DTRO): Data read timeout; +Bit 8 (RTO): Response timeout; +Bit 7 (DCRC): Data CRC error; +Bit 6 (RCRC): Response CRC error; +Bit 5 (RXDR): Receive FIFO data request; Bit 4 (TXDR): Transmit FIFO data request; -Bit 3 (DTO): Data transfer over; -Bit 2 (CD): Command done; +Bit 3 (DTO): Data transfer over; +Bit 2 (CD): Command done; Bit 1 (RE): Response error; Bit 0 (CD): Card detect. 0 @@ -29522,8 +29522,8 @@ Bit 0 (CD): Card detect. COMMAND_FSM_STATES Command FSM states. 0: Idle; -1: Send init sequence; -2: Send cmd start bit; +1: Send init sequence; +2: Send cmd start bit; 3: Send cmd tx bit; 4: Send cmd index + arg; 5: Send cmd crc7; @@ -29605,13 +29605,13 @@ Bit 0 (CD): Card detect. DMA_MULTIPLE_TRANSACTION_SIZE Burst size of multiple transaction, should be programmed same as DMA controller multiple-transaction-size SDHOST_SRC/DEST_MSIZE. -000: 1-byte transfer; -001: 4-byte transfer; -010: 8-byte transfer; -011: 16-byte transfer; -100: 32-byte transfer; -101: 64-byte transfer; -110: 128-byte transfer; +000: 1-byte transfer; +001: 4-byte transfer; +010: 8-byte transfer; +011: 16-byte transfer; +100: 32-byte transfer; +101: 64-byte transfer; +110: 128-byte transfer; 111: 256-byte transfer. 28 3 @@ -29824,8 +29824,8 @@ Bit 0 (CD): Card detect. CARD_RESET Hardware reset. -1: Active mode; -0: Reset. +1: Active mode; +0: Reset. These bits cause the cards to enter pre-idle state, which requires them to be re-initialized. SDHOST_RST_CARD_RESET[0] should be set to 1'b0 to reset card0, SDHOST_RST_CARD_RESET[1] should be set to 1'b0 to reset card1. 0 2 @@ -29863,13 +29863,13 @@ These bits cause the cards to enter pre-idle state, which requires them to be re PBL Programmable Burst Length. These bits indicate the maximum number of beats to be performed in one IDMAC???Internal DMA Control???transaction. The IDMAC will always attempt to burst as specified in PBL each time it starts a burst transfer on the host bus. The permissible values are 1, 4, 8, 16, 32, 64, 128 and 256. This value is the mirror of MSIZE of FIFOTH register. In order to change this value, write the required value to FIFOTH register. This is an encode value as follows: -000: 1-byte transfer; -001: 4-byte transfer; -010: 8-byte transfer; -011: 16-byte transfer; -100: 32-byte transfer; -101: 64-byte transfer; -110: 128-byte transfer; +000: 1-byte transfer; +001: 4-byte transfer; +010: 8-byte transfer; +011: 16-byte transfer; +100: 32-byte transfer; +101: 64-byte transfer; +110: 128-byte transfer; 111: 256-byte transfer. PBL is a read-only value and is applicable only for data access, it does not apply to descriptor access. 8 @@ -29945,12 +29945,12 @@ PBL is a read-only value and is applicable only for data access, it does not app CES Card Error Summary. Indicates the status of the transaction to/from the card, also present in RINTSTS. Indicates the logical OR of the following bits: -EBE : End Bit Error; -RTO : Response Timeout/Boot Ack Timeout; -RCRC : Response CRC; -SBE : Start Bit Error; -DRTO : Data Read Timeout/BDS timeout; -DCRC : Data CRC for Receive; +EBE : End Bit Error; +RTO : Response Timeout/Boot Ack Timeout; +RCRC : Response CRC; +SBE : Start Bit Error; +DRTO : Data Read Timeout/BDS timeout; +DCRC : Data CRC for Receive; RE : Response Error. Writing 1 clears this bit. The abort condition of the IDMAC depends on the setting of this CES bit. If the CES bit is enabled, then the IDMAC aborts on a response error. 5 @@ -29984,14 +29984,14 @@ Others: Reserved. FSM DMAC FSM present state. -0: DMA_IDLE (idle state); -1: DMA_SUSPEND (suspend state); -2: DESC_RD (descriptor reading state); -3: DESC_CHK (descriptor checking state); +0: DMA_IDLE (idle state); +1: DMA_SUSPEND (suspend state); +2: DESC_RD (descriptor reading state); +3: DESC_CHK (descriptor checking state); 4: DMA_RD_REQ_WAIT (read-data request waiting state); -5: DMA_WR_REQ_WAIT (write-data request waiting state); -6: DMA_RD (data-read state); -7: DMA_WR (data-write state); +5: DMA_WR_REQ_WAIT (write-data request waiting state); +6: DMA_RD (data-read state); +7: DMA_WR (data-write state); 8: DESC_CLOSE (descriptor close state). 13 4 @@ -46084,4 +46084,4 @@ IDINTEN[4]: DU Interrupt. - \ No newline at end of file + diff --git a/tools/ide-debug/svd/esp32c2.svd b/tools/ide-debug/svd/esp32c2.svd index 59e05295df9..84aa455b880 100644 --- a/tools/ide-debug/svd/esp32c2.svd +++ b/tools/ide-debug/svd/esp32c2.svd @@ -6079,7 +6079,7 @@ module as an I2C Slave. TX_LSB_FIRST - This bit is used to control the sending mode for data needing to be sent. + This bit is used to control the sending mode for data needing to be sent. 1: send data from the least significant bit, 0: send data from the most significant bit. 6 @@ -6175,7 +6175,7 @@ module as an I2C Slave. SCL_MAIN_STATE_LAST - This field indicates the states of the I2C module state machine. + This field indicates the states of the I2C module state machine. 0: Idle, 1: Address shift, 2: ACK address, 3: Rx data, 4: Tx data, 5: Send ACK, 6: Wait ACK 24 3 @@ -7016,7 +7016,7 @@ in I2C module clock cycles, the I2C controller will ignore that pulse. COMMAND - This is the content of command 0. It consists of three parts: + This is the content of command 0. It consists of three parts: op_code is the command, 0: RSTART, 1: WRITE, 2: READ, 3: STOP, 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -20746,4 +20746,4 @@ protection is enabled. - \ No newline at end of file + diff --git a/tools/ide-debug/svd/esp32c3.svd b/tools/ide-debug/svd/esp32c3.svd index 532b90bd669..aea2a98acdd 100644 --- a/tools/ide-debug/svd/esp32c3.svd +++ b/tools/ide-debug/svd/esp32c3.svd @@ -36095,4 +36095,4 @@ - \ No newline at end of file + diff --git a/tools/ide-debug/svd/esp32c6.svd b/tools/ide-debug/svd/esp32c6.svd index ae2dae46dbf..33d3464537a 100644 --- a/tools/ide-debug/svd/esp32c6.svd +++ b/tools/ide-debug/svd/esp32c6.svd @@ -17744,7 +17744,7 @@ SDIO20_CONF [29],sdio negedge sample enablel.[30],sdio posedge sample enable.[31],sdio cmd/dat in delayed cycles control,0:no delay, 1:delay 1 cycle. -[25]: sdio1.1 dat/cmd sending out edge control,1:negedge,0:posedge when highseed mode. +[25]: sdio1.1 dat/cmd sending out edge control,1:negedge,0:posedge when highseed mode. [26]: sdio2.0 dat/cmd sending out edge control,1:negedge when [12]=0,0:negedge when [12]=0,posedge when highspeed mode enable. [27]: sdio interrupt sending out delay control,1:delay one cycle, 0: no delay. [28]: sdio data pad pull up enable @@ -21230,7 +21230,7 @@ module as an I2C Slave. TX_LSB_FIRST - This bit is used to control the sending mode for data needing to be sent. + This bit is used to control the sending mode for data needing to be sent. 1: send data from the least significant bit, 0: send data from the most significant bit. 6 @@ -21363,7 +21363,7 @@ equal to the address of the slave, then this bit will be of high level. SCL_MAIN_STATE_LAST - This field indicates the states of the I2C module state machine. + This field indicates the states of the I2C module state machine. 0: Idle, 1: Address shift, 2: ACK address, 3: Rx data, 4: Tx data, 5: Send ACK, 6: Wait ACK 24 3 @@ -22321,7 +22321,7 @@ in I2C module clock cycles, the I2C controller will ignore that pulse. COMMAND0 - This is the content of command 0. It consists of three parts: + This is the content of command 0. It consists of three parts: op_code is the command, 0: RSTART, 1: WRITE, 2: READ, 3: STOP, 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -22348,7 +22348,7 @@ level. COMMAND1 - This is the content of command 1. It consists of three parts: + This is the content of command 1. It consists of three parts: op_code is the command, 0: RSTART, 1: WRITE, 2: READ, 3: STOP, 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -22375,7 +22375,7 @@ level. COMMAND2 - This is the content of command 2. It consists of three parts: + This is the content of command 2. It consists of three parts: op_code is the command, 0: RSTART, 1: WRITE, 2: READ, 3: STOP, 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -22402,7 +22402,7 @@ Level. COMMAND3 - This is the content of command 3. It consists of three parts: + This is the content of command 3. It consists of three parts: op_code is the command, 0: RSTART, 1: WRITE, 2: READ, 3: STOP, 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -22429,7 +22429,7 @@ level. COMMAND4 - This is the content of command 4. It consists of three parts: + This is the content of command 4. It consists of three parts: op_code is the command, 0: RSTART, 1: WRITE, 2: READ, 3: STOP, 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -22482,7 +22482,7 @@ Information. COMMAND6 - This is the content of command 6. It consists of three parts: + This is the content of command 6. It consists of three parts: op_code is the command, 0: RSTART, 1: WRITE, 2: READ, 3: STOP, 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -22508,7 +22508,7 @@ Information. COMMAND7 - This is the content of command 7. It consists of three parts: + This is the content of command 7. It consists of three parts: op_code is the command, 0: RSTART, 1: WRITE, 2: READ, 3: STOP, 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -26821,7 +26821,7 @@ The least significant eight bits represent the fractional part. CH_GAMMA_DUTY_INC - Ledc ch%s gamma duty inc of current ram write address.This register is used to increase or decrease the duty of output signal on channel %s. + Ledc ch%s gamma duty inc of current ram write address.This register is used to increase or decrease the duty of output signal on channel %s. 1: Increase 0: Decrease. 0 @@ -30399,7 +30399,7 @@ Clock I2C_TX_LSB_FIRST - This bit is used to control the sending mode for data needing to be sent. + This bit is used to control the sending mode for data needing to be sent. 1: send data from the least significant bit, 0: send data from the most significant bit. 6 @@ -30488,7 +30488,7 @@ Clock I2C_SCL_MAIN_STATE_LAST - This field indicates the states of the I2C module state machine. + This field indicates the states of the I2C module state machine. 0: Idle, 1: Address shift, 2: ACK address, 3: Rx data, 4: Tx data, 5: Send ACK, 6: Wait ACK 24 3 @@ -31326,7 +31326,7 @@ in I2C module clock cycles, the I2C controller will ignore that pulse. I2C_COMMAND0 - This is the content of command 0. It consists of three parts: + This is the content of command 0. It consists of three parts: op_code is the command, 0: RSTART, 1: WRITE, 2: READ, 3: STOP, 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -31353,7 +31353,7 @@ level. I2C_COMMAND1 - This is the content of command 1. It consists of three parts: + This is the content of command 1. It consists of three parts: op_code is the command, 0: RSTART, 1: WRITE, 2: READ, 3: STOP, 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -31380,7 +31380,7 @@ level. I2C_COMMAND2 - This is the content of command 2. It consists of three parts: + This is the content of command 2. It consists of three parts: op_code is the command, 0: RSTART, 1: WRITE, 2: READ, 3: STOP, 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -31407,7 +31407,7 @@ Level. I2C_COMMAND3 - This is the content of command 3. It consists of three parts: + This is the content of command 3. It consists of three parts: op_code is the command, 0: RSTART, 1: WRITE, 2: READ, 3: STOP, 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -31434,7 +31434,7 @@ level. I2C_COMMAND4 - This is the content of command 4. It consists of three parts: + This is the content of command 4. It consists of three parts: op_code is the command, 0: RSTART, 1: WRITE, 2: READ, 3: STOP, 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -31487,7 +31487,7 @@ Information. I2C_COMMAND6 - This is the content of command 6. It consists of three parts: + This is the content of command 6. It consists of three parts: op_code is the command, 0: RSTART, 1: WRITE, 2: READ, 3: STOP, 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -31513,7 +31513,7 @@ Information. I2C_COMMAND7 - This is the content of command 7. It consists of three parts: + This is the content of command 7. It consists of three parts: op_code is the command, 0: RSTART, 1: WRITE, 2: READ, 3: STOP, 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -41924,7 +41924,7 @@ Information. RX_PULSE_SUBMODE_SEL - Pulse submode selection. + Pulse submode selection. 0000: positive pulse start(data bit included) && positive pulse end(data bit included) 0001: positive pulse start(data bit included) && positive pulse end (data bit excluded) 0010: positive pulse start(data bit excluded) && positive pulse end (data bit included) @@ -41950,9 +41950,9 @@ Information. RX_SMP_MODE_SEL - Rx data sampling mode selection. + Rx data sampling mode selection. 000: external level enable mode -001: external pulse enable mode +001: external pulse enable mode 010: internal software enable mode 24 2 @@ -41974,9 +41974,9 @@ Information. RX_BUS_WID_SEL - Rx data bus width selection. -100: bus width is 1 bit -011: bus width is 2 bits + Rx data bus width selection. +100: bus width is 1 bit +011: bus width is 2 bits 010: bus width is 4 bits 001: bus width is 8 bits 000: bus width is 16 bits @@ -42080,7 +42080,7 @@ Information. TX_BUS_WID_SEL - Tx data bus width selection. + Tx data bus width selection. 100: bus width is 1 bit 011: bus width is 2 bits 010: bus width is 4 bits @@ -49494,7 +49494,7 @@ Any pulses with width less than this will be ignored when the filter is enabled. MEM_OWNER_CH2 This register marks the ownership of CHANNEL%s's ram block. -1'h1: Receiver is using the ram. +1'h1: Receiver is using the ram. 1'h0: APB bus is using the ram. 3 @@ -70849,4 +70849,4 @@ protection is enabled. - \ No newline at end of file + diff --git a/tools/ide-debug/svd/esp32h2.svd b/tools/ide-debug/svd/esp32h2.svd index 8a5d2938029..a19fad06bf0 100644 --- a/tools/ide-debug/svd/esp32h2.svd +++ b/tools/ide-debug/svd/esp32h2.svd @@ -10223,7 +10223,7 @@ module as an I2C Slave. TX_LSB_FIRST - This bit is used to control the sending mode for data needing to be sent. + This bit is used to control the sending mode for data needing to be sent. 1: send data from the least significant bit, 0: send data from the most significant bit. 6 @@ -10356,7 +10356,7 @@ equal to the address of the slave, then this bit will be of high level. SCL_MAIN_STATE_LAST - This field indicates the states of the I2C module state machine. + This field indicates the states of the I2C module state machine. 0: Idle, 1: Address shift, 2: ACK address, 3: Rx data, 4: Tx data, 5: Send ACK, 6: Wait ACK 24 3 @@ -11317,7 +11317,7 @@ in I2C module clock cycles, the I2C controller will ignore that pulse. COMMAND0 - This is the content of command 0. It consists of three parts: + This is the content of command 0. It consists of three parts: op_code is the command, 0: RSTART, 1: WRITE, 2: READ, 3: STOP, 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -13687,7 +13687,7 @@ The least significant eight bits represent the fractional part. CH_GAMMA_DUTY_INC - Ledc ch%s gamma duty inc of current ram write address.This register is used to increase or decrease the duty of output signal on channel %s. + Ledc ch%s gamma duty inc of current ram write address.This register is used to increase or decrease the duty of output signal on channel %s. 1: Increase 0: Decrease. 0 @@ -15191,7 +15191,7 @@ Any pulses with width less than this will be ignored when the filter is enabled. MEM_OWNER_CH2 This register marks the ownership of CHANNEL%s's ram block. -1'h1: Receiver is using the ram. +1'h1: Receiver is using the ram. 1'h0: APB bus is using the ram. 3 @@ -16270,7 +16270,7 @@ Any pulses with width less than this will be ignored when the filter is enabled. CONSTANT_TIME - Configures the constant_time option. + Configures the constant_time option. 0: Acceleration @@ -16291,7 +16291,7 @@ Any pulses with width less than this will be ignored when the filter is enabled. SEARCH_ENABLE - Configure the search option. + Configure the search option. 0: No acceleration (default) @@ -29568,4 +29568,4 @@ protection is enabled. - \ No newline at end of file + diff --git a/tools/ide-debug/svd/esp32s2.svd b/tools/ide-debug/svd/esp32s2.svd index 3154d5912f7..e3a9efba868 100644 --- a/tools/ide-debug/svd/esp32s2.svd +++ b/tools/ide-debug/svd/esp32s2.svd @@ -116,7 +116,7 @@ 0x2(AES_EN_256): AES-EN-256 # 0x4(AES_DE_128): AES-DE-128 # 0x5(AES_DE_192): AES-DE-192 # -0x6(AES_DE_256): AES-DE-256 +0x6(AES_DE_256): AES-DE-256 & 0 3 @@ -1572,12 +1572,12 @@ alternate-channel scan mode. INTR_MODE_CH0 - Configure channel 0 interrupt generate mode. -0/1: do not generate interrupt. + Configure channel 0 interrupt generate mode. +0/1: do not generate interrupt. 2: low level trigger. -3: high level trigger. -4: falling edge trigger. -5: raising edge trigger. +3: high level trigger. +4: falling edge trigger. +5: raising edge trigger. 6/7: falling and raising edge trigger. 0 3 @@ -1585,12 +1585,12 @@ alternate-channel scan mode. INTR_MODE_CH1 - Configure channel 1 interrupt generate mode. -0/1: do not generate interrupt. + Configure channel 1 interrupt generate mode. +0/1: do not generate interrupt. 2: low level trigger. -3: high level trigger. -4: falling edge trigger. -5: raising edge trigger. +3: high level trigger. +4: falling edge trigger. +5: raising edge trigger. 6/7: falling and raising edge trigger. 3 3 @@ -1598,12 +1598,12 @@ alternate-channel scan mode. INTR_MODE_CH2 - Configure channel 2 interrupt generate mode. -0/1: do not generate interrupt. + Configure channel 2 interrupt generate mode. +0/1: do not generate interrupt. 2: low level trigger. -3: high level trigger. -4: falling edge trigger. -5: raising edge trigger. +3: high level trigger. +4: falling edge trigger. +5: raising edge trigger. 6/7: falling and raising edge trigger. 6 3 @@ -1611,12 +1611,12 @@ alternate-channel scan mode. INTR_MODE_CH3 - Configure channel 3 interrupt generate mode. -0/1: do not generate interrupt. + Configure channel 3 interrupt generate mode. +0/1: do not generate interrupt. 2: low level trigger. -3: high level trigger. -4: falling edge trigger. -5: raising edge trigger. +3: high level trigger. +4: falling edge trigger. +5: raising edge trigger. 6/7: falling and raising edge trigger. 9 3 @@ -1624,12 +1624,12 @@ alternate-channel scan mode. INTR_MODE_CH4 - Configure channel 4 interrupt generate mode. -0/1: do not generate interrupt. + Configure channel 4 interrupt generate mode. +0/1: do not generate interrupt. 2: low level trigger. -3: high level trigger. -4: falling edge trigger. -5: raising edge trigger. +3: high level trigger. +4: falling edge trigger. +5: raising edge trigger. 6/7: falling and raising edge trigger. 12 3 @@ -1637,12 +1637,12 @@ alternate-channel scan mode. INTR_MODE_CH5 - Configure channel 5 interrupt generate mode. -0/1: do not generate interrupt. + Configure channel 5 interrupt generate mode. +0/1: do not generate interrupt. 2: low level trigger. -3: high level trigger. -4: falling edge trigger. -5: raising edge trigger. +3: high level trigger. +4: falling edge trigger. +5: raising edge trigger. 6/7: falling and raising edge trigger. 15 3 @@ -1650,12 +1650,12 @@ alternate-channel scan mode. INTR_MODE_CH6 - Configure channel 6 interrupt generate mode. -0/1: do not generate interrupt. + Configure channel 6 interrupt generate mode. +0/1: do not generate interrupt. 2: low level trigger. -3: high level trigger. -4: falling edge trigger. -5: raising edge trigger. +3: high level trigger. +4: falling edge trigger. +5: raising edge trigger. 6/7: falling and raising edge trigger. 18 3 @@ -1663,12 +1663,12 @@ alternate-channel scan mode. INTR_MODE_CH7 - Configure channel 7 interrupt generate mode. -0/1: do not generate interrupt. + Configure channel 7 interrupt generate mode. +0/1: do not generate interrupt. 2: low level trigger. -3: high level trigger. -4: falling edge trigger. -5: raising edge trigger. +3: high level trigger. +4: falling edge trigger. +5: raising edge trigger. 6/7: falling and raising edge trigger. 21 3 @@ -19132,7 +19132,7 @@ Any pulses with width less than this will be ignored when the filter is enabled. MEM_OWNER This register marks the ownership of CHANNEL%s's ram block. -1'h1: Receiver is using the ram. +1'h1: Receiver is using the ram. 1'h0: Transmitter is using the ram. 5 @@ -20883,7 +20883,7 @@ Any pulses with width less than this will be ignored when the filter is enabled. SEL - GPIO[0-17] can be used to wake up the chip when the chip is in the sleep mode. This register prompts the pad source to wake up the chip when the latter is indeep/light sleep mode. + GPIO[0-17] can be used to wake up the chip when the chip is in the sleep mode. This register prompts the pad source to wake up the chip when the latter is indeep/light sleep mode. 0: select GPIO0; 1: select GPIO2, etc 27 5 @@ -35290,8 +35290,8 @@ This register is used in autobaud detection. TICK_REF_ALWAYS_ON - This register is used to select the clock. -1: APB_CLK. + This register is used to select the clock. +1: APB_CLK. 0: REF_TICK. 27 1 @@ -35578,7 +35578,7 @@ This register is used in autobaud detection. RS485RXBY_TX_EN - 1: enable RS485 transmitter to send data when RS485 receiver line is busy. + 1: enable RS485 transmitter to send data when RS485 receiver line is busy. 0: RS485 transmitter should not send data when its receiver is busy. 4 1 @@ -35609,7 +35609,7 @@ This register is used in autobaud detection. PRE_IDLE_NUM - This register is used to configure the idle duration time before the first AT_CMD is received by the receiver. + This register is used to configure the idle duration time before the first AT_CMD is received by the receiver. It will not take the next data received as AT_CMD character when the duration is less than this register's value. 0 16 @@ -35947,7 +35947,7 @@ The UART_RXFIFO_TOUT_INT interrupt will be triggered when the receiver takes mor OUT_EOF_MODE - This register is used to specify the generation mode of UHCI_OUT_EOF_INT interrupt. + This register is used to specify the generation mode of UHCI_OUT_EOF_INT interrupt. 1: When DMA has popped all data from FIFO. 0: When AHB has pushed all data to FIFO. 8 @@ -36023,8 +36023,8 @@ The UART_RXFIFO_TOUT_INT interrupt will be triggered when the receiver takes mor LEN_EOF_EN - If this bit is set to 1, UHCI decoder stops receiving payload data when the number of received data bytes has reached the specified value. -The value is payload length indicated by UCHI packet header when UHCI_HEAD_EN is 1 or the value is a configuration value when UHCI_HEAD_EN is 0. + If this bit is set to 1, UHCI decoder stops receiving payload data when the number of received data bytes has reached the specified value. +The value is payload length indicated by UCHI packet header when UHCI_HEAD_EN is 1 or the value is a configuration value when UHCI_HEAD_EN is 0. If this bit is set to 0, UHCI decoder stops receiving payload data upon receiving 0xC0. 20 1 @@ -36630,7 +36630,7 @@ If this bit is set to 0, UHCI decoder stops receiving payload data upon receivi RX_ERR_CAUSE This register indicates the error type when DMA has received a packet with error. -3'b001: Checksum error in the HCI packet; +3'b001: Checksum error in the HCI packet; 3'b010: Sequence number error in the HCI packet; 3'b011: CRC bit error in the HCI packet; 3'b100: 0xC0 is found but the received HCI packet is not end; @@ -45740,4 +45740,4 @@ If this bit is set to 0, UHCI decoder stops receiving payload data upon receivi - \ No newline at end of file + diff --git a/tools/ide-debug/svd/esp32s3.svd b/tools/ide-debug/svd/esp32s3.svd index b1222ec89b6..a36e851ac7a 100644 --- a/tools/ide-debug/svd/esp32s3.svd +++ b/tools/ide-debug/svd/esp32s3.svd @@ -12626,7 +12626,7 @@ module as an I2C Slave. TX_LSB_FIRST - This bit is used to control the sending mode for data needing to be sent. + This bit is used to control the sending mode for data needing to be sent. 1: send data from the least significant bit; 0: send data from the most significant bit. 6 @@ -12759,7 +12759,7 @@ equal to the address of the slave, then this bit will be of high level. SCL_MAIN_STATE_LAST - This field indicates the states of the I2C module state machine. + This field indicates the states of the I2C module state machine. 0: Idle; 1: Address shift; 2: ACK address; 3: Rx data; 4: Tx data; 5: Send ACK; 6: Wait ACK 24 3 @@ -13692,7 +13692,7 @@ in I2C module clock cycles, the I2C controller will ignore that pulse. COMMAND - This is the content of command 0. It consists of three parts: + This is the content of command 0. It consists of three parts: op_code is the command, 0: RSTART; 1: WRITE; 2: READ; 3: STOP; 4: END. Byte_num represents the number of bytes that need to be sent or received. ack_check_en, ack_exp and ack are used to control the ACK bit. See I2C cmd structure for more @@ -26733,7 +26733,7 @@ Any pulses with width less than this will be ignored when the filter is enabled. MEM_OWNER This register marks the ownership of CHANNEL%s's ram block. -1'h1: Receiver is using the ram. +1'h1: Receiver is using the ram. 1'h0: APB bus is using the ram. 3 @@ -67568,4 +67568,4 @@ protection is enabled. - \ No newline at end of file + diff --git a/tools/partitions/app3M_fat9M_16MB.csv b/tools/partitions/app3M_fat9M_16MB.csv index 1f8f04531ed..b1dbf158601 100644 --- a/tools/partitions/app3M_fat9M_16MB.csv +++ b/tools/partitions/app3M_fat9M_16MB.csv @@ -5,4 +5,4 @@ app0, app, ota_0, 0x10000, 0x300000, app1, app, ota_1, 0x310000,0x300000, ffat, data, fat, 0x610000,0x9E0000, coredump, data, coredump,0xFF0000,0x10000, -# to create/use ffat, see https://github.com/marcmerlin/esp32_fatfsimage \ No newline at end of file +# to create/use ffat, see https://github.com/marcmerlin/esp32_fatfsimage diff --git a/tools/partitions/bare_minimum_2MB.csv b/tools/partitions/bare_minimum_2MB.csv index 290745e72e4..e688a47cfa2 100644 --- a/tools/partitions/bare_minimum_2MB.csv +++ b/tools/partitions/bare_minimum_2MB.csv @@ -1,3 +1,3 @@ # Name, Type, SubType, Offset, Size, Flags nvs, data, nvs, 36K, 20K, -factory, app, factory, 64K, 1900K, \ No newline at end of file +factory, app, factory, 64K, 1900K, diff --git a/tools/partitions/default.csv b/tools/partitions/default.csv index 6f68ce16fec..960469b8233 100644 --- a/tools/partitions/default.csv +++ b/tools/partitions/default.csv @@ -4,4 +4,4 @@ otadata, data, ota, 0xe000, 0x2000, app0, app, ota_0, 0x10000, 0x140000, app1, app, ota_1, 0x150000,0x140000, spiffs, data, spiffs, 0x290000,0x160000, -coredump, data, coredump,0x3F0000,0x10000, \ No newline at end of file +coredump, data, coredump,0x3F0000,0x10000, diff --git a/tools/partitions/default_16MB.csv b/tools/partitions/default_16MB.csv index 28511d0af9a..67d773728e9 100644 --- a/tools/partitions/default_16MB.csv +++ b/tools/partitions/default_16MB.csv @@ -4,4 +4,4 @@ otadata, data, ota, 0xe000, 0x2000, app0, app, ota_0, 0x10000, 0x640000, app1, app, ota_1, 0x650000,0x640000, spiffs, data, spiffs, 0xc90000,0x360000, -coredump, data, coredump,0xFF0000,0x10000, \ No newline at end of file +coredump, data, coredump,0xFF0000,0x10000, diff --git a/tools/partitions/default_8MB.csv b/tools/partitions/default_8MB.csv index 0310ac62977..4e92afa6936 100644 --- a/tools/partitions/default_8MB.csv +++ b/tools/partitions/default_8MB.csv @@ -4,4 +4,4 @@ otadata, data, ota, 0xe000, 0x2000, app0, app, ota_0, 0x10000, 0x330000, app1, app, ota_1, 0x340000,0x330000, spiffs, data, spiffs, 0x670000,0x180000, -coredump, data, coredump,0x7F0000,0x10000, \ No newline at end of file +coredump, data, coredump,0x7F0000,0x10000, diff --git a/tools/partitions/default_ffat.csv b/tools/partitions/default_ffat.csv index a7278a577ca..008bd390f70 100644 --- a/tools/partitions/default_ffat.csv +++ b/tools/partitions/default_ffat.csv @@ -4,4 +4,4 @@ otadata, data, ota, 0xe000, 0x2000, app0, app, ota_0, 0x10000, 0x140000, app1, app, ota_1, 0x150000,0x140000, ffat, data, fat, 0x290000,0x160000, -coredump, data, coredump,0x3F0000,0x10000, \ No newline at end of file +coredump, data, coredump,0x3F0000,0x10000, diff --git a/tools/partitions/huge_app.csv b/tools/partitions/huge_app.csv index 61254fcab25..1d00925f6e8 100644 --- a/tools/partitions/huge_app.csv +++ b/tools/partitions/huge_app.csv @@ -3,4 +3,4 @@ nvs, data, nvs, 0x9000, 0x5000, otadata, data, ota, 0xe000, 0x2000, app0, app, ota_0, 0x10000, 0x300000, spiffs, data, spiffs, 0x310000,0xE0000, -coredump, data, coredump,0x3F0000,0x10000, \ No newline at end of file +coredump, data, coredump,0x3F0000,0x10000, diff --git a/tools/partitions/large_spiffs_16MB.csv b/tools/partitions/large_spiffs_16MB.csv index 2fd720504d7..a0483430726 100644 --- a/tools/partitions/large_spiffs_16MB.csv +++ b/tools/partitions/large_spiffs_16MB.csv @@ -4,4 +4,4 @@ otadata, data, ota, 0xe000, 0x2000, app0, app, ota_0, 0x10000, 0x480000, app1, app, ota_1, 0x490000,0x480000, spiffs, data, spiffs, 0x910000,0x6E0000, -coredump, data, coredump,0xFF0000,0x10000, \ No newline at end of file +coredump, data, coredump,0xFF0000,0x10000, diff --git a/tools/partitions/m5stack_partitions_16MB_factory_6_apps.csv b/tools/partitions/m5stack_partitions_16MB_factory_6_apps.csv index 899eb862802..6840e864945 100644 --- a/tools/partitions/m5stack_partitions_16MB_factory_6_apps.csv +++ b/tools/partitions/m5stack_partitions_16MB_factory_6_apps.csv @@ -11,4 +11,3 @@ ota_5, 0, ota_5, 0xA10000, 0x200000 firmware, app, factory, 0xC10000, 0x0F0000 spiffs, data, spiffs, 0xD00000, 0x2F0000 coredump, data, coredump, 0xFF0000, 0x10000 - diff --git a/tools/partitions/max_app_8MB.csv b/tools/partitions/max_app_8MB.csv index 6aa8e8ec485..502d9fe9fa2 100644 --- a/tools/partitions/max_app_8MB.csv +++ b/tools/partitions/max_app_8MB.csv @@ -2,4 +2,4 @@ nvs, data, nvs, 0x9000, 0x5000, otadata, data, ota, 0xe000, 0x2000, app0, app, factory, 0x10000, 0x7E0000, -coredump, data, coredump,0x7F0000,0x10000, \ No newline at end of file +coredump, data, coredump,0x7F0000,0x10000, diff --git a/tools/partitions/min_spiffs.csv b/tools/partitions/min_spiffs.csv index 080f491d1dd..0990a3b469e 100644 --- a/tools/partitions/min_spiffs.csv +++ b/tools/partitions/min_spiffs.csv @@ -4,4 +4,4 @@ otadata, data, ota, 0xe000, 0x2000, app0, app, ota_0, 0x10000, 0x1E0000, app1, app, ota_1, 0x1F0000,0x1E0000, spiffs, data, spiffs, 0x3D0000,0x20000, -coredump, data, coredump,0x3F0000,0x10000, \ No newline at end of file +coredump, data, coredump,0x3F0000,0x10000, diff --git a/tools/partitions/minimal.csv b/tools/partitions/minimal.csv index 90280fbfaba..32c70abc1d7 100644 --- a/tools/partitions/minimal.csv +++ b/tools/partitions/minimal.csv @@ -3,4 +3,4 @@ nvs, data, nvs, 0x9000, 0x5000, otadata, data, ota, 0xe000, 0x2000, app0, app, ota_0, 0x10000, 0x140000, spiffs, data, spiffs, 0x150000, 0xA0000, -coredump, data, coredump,0x1F0000, 0x10000, \ No newline at end of file +coredump, data, coredump,0x1F0000, 0x10000, diff --git a/tools/partitions/no_ota.csv b/tools/partitions/no_ota.csv index 47ceb607797..173a4e1d7f7 100644 --- a/tools/partitions/no_ota.csv +++ b/tools/partitions/no_ota.csv @@ -3,4 +3,4 @@ nvs, data, nvs, 0x9000, 0x5000, otadata, data, ota, 0xe000, 0x2000, app0, app, ota_0, 0x10000, 0x200000, spiffs, data, spiffs, 0x210000,0x1E0000, -coredump, data, coredump,0x3F0000,0x10000, \ No newline at end of file +coredump, data, coredump,0x3F0000,0x10000, diff --git a/tools/partitions/noota_3g.csv b/tools/partitions/noota_3g.csv index 233cfb28258..71d9f5e7da4 100644 --- a/tools/partitions/noota_3g.csv +++ b/tools/partitions/noota_3g.csv @@ -3,4 +3,4 @@ nvs, data, nvs, 0x9000, 0x5000, otadata, data, ota, 0xe000, 0x2000, app0, app, ota_0, 0x10000, 0x100000, spiffs, data, spiffs, 0x110000,0x2E0000, -coredump, data, coredump,0x3F0000,0x10000, \ No newline at end of file +coredump, data, coredump,0x3F0000,0x10000, diff --git a/tools/partitions/rainmaker.csv b/tools/partitions/rainmaker.csv index 6038dafa1a0..7b05378ccf7 100644 --- a/tools/partitions/rainmaker.csv +++ b/tools/partitions/rainmaker.csv @@ -4,4 +4,4 @@ otadata, data, ota, 0xe000, 0x2000, ota_0, app, ota_0, 0x10000, 0x1E0000, ota_1, app, ota_1, 0x1F0000, 0x1E0000, fctry, data, nvs, 0x3D0000, 0x6000, -coredump, data, coredump, 0x3F0000, 0x10000, \ No newline at end of file +coredump, data, coredump, 0x3F0000, 0x10000, diff --git a/tools/partitions/zigbee.csv b/tools/partitions/zigbee.csv index 0c899f52ed2..938d59b01f3 100644 --- a/tools/partitions/zigbee.csv +++ b/tools/partitions/zigbee.csv @@ -6,4 +6,4 @@ app1, app, ota_1, 0x150000,0x140000, spiffs, data, spiffs, 0x290000,0x15B000, zb_storage, data, fat, 0x3EB000,0x4000, zb_fct, data, fat, 0x3EF000,0x1000, -coredump, data, coredump,0x3F0000,0x10000, \ No newline at end of file +coredump, data, coredump,0x3F0000,0x10000, diff --git a/tools/partitions/zigbee_zczr.csv b/tools/partitions/zigbee_zczr.csv index 5bceac4a5a6..e734e1d66c5 100644 --- a/tools/partitions/zigbee_zczr.csv +++ b/tools/partitions/zigbee_zczr.csv @@ -7,4 +7,4 @@ spiffs, data, spiffs, 0x290000,0x15A000, zb_storage, data, fat, 0x3EA000,0x4000, zb_fct, data, fat, 0x3EE000,0x1000, rcp_fw, data, spiffs, 0x3EF000,0x1000, -coredump, data, coredump,0x3F0000,0x10000, \ No newline at end of file +coredump, data, coredump,0x3F0000,0x10000, diff --git a/tools/platformio-build.py b/tools/platformio-build.py index 815f5ee3d22..06b5dac2e1b 100644 --- a/tools/platformio-build.py +++ b/tools/platformio-build.py @@ -32,9 +32,7 @@ platform = env.PioPlatform() board_config = env.BoardConfig() build_mcu = board_config.get("build.mcu", "").lower() -partitions_name = board_config.get( - "build.partitions", board_config.get("build.arduino.partitions", "") -) +partitions_name = board_config.get("build.partitions", board_config.get("build.arduino.partitions", "")) FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32") FRAMEWORK_LIBS_DIR = platform.get_package_dir("framework-arduinoespressif32-libs") @@ -62,11 +60,7 @@ def get_partition_table_csv(variants_dir): ) variant_partitions = join(variant_partitions_dir, "partitions.csv") - return ( - variant_partitions - if isfile(env.subst(variant_partitions)) - else join(fwpartitions_dir, "default.csv") - ) + return variant_partitions if isfile(env.subst(variant_partitions)) else join(fwpartitions_dir, "default.csv") def get_bootloader_image(variants_dir): @@ -98,14 +92,26 @@ def generate_bootloader_image(bootloader_elf): bootloader_cmd = env.Command( join("$BUILD_DIR", "bootloader.bin"), bootloader_elf, - env.VerboseAction(" ".join([ - '"$PYTHONEXE" "$OBJCOPY"', - "--chip", build_mcu, "elf2image", - "--flash_mode", "${__get_board_flash_mode(__env__)}", - "--flash_freq", "${__get_board_f_image(__env__)}", - "--flash_size", board_config.get("upload.flash_size", "4MB"), - "-o", "$TARGET", "$SOURCES" - ]), "Building $TARGET"), + env.VerboseAction( + " ".join( + [ + '"$PYTHONEXE" "$OBJCOPY"', + "--chip", + build_mcu, + "elf2image", + "--flash_mode", + "${__get_board_flash_mode(__env__)}", + "--flash_freq", + "${__get_board_f_image(__env__)}", + "--flash_size", + board_config.get("upload.flash_size", "4MB"), + "-o", + "$TARGET", + "$SOURCES", + ] + ), + "Building $TARGET", + ), ) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", bootloader_cmd) @@ -129,10 +135,7 @@ def add_tinyuf2_extra_image(): print("Warning! The `%s` UF2 bootloader image doesn't exist" % env.subst(tinuf2_image)) return - if any( - "tinyuf2.bin" == basename(extra_image[1]) - for extra_image in env.get("FLASH_EXTRA_IMAGES", []) - ): + if any("tinyuf2.bin" == basename(extra_image[1]) for extra_image in env.get("FLASH_EXTRA_IMAGES", [])): print("Warning! An extra UF2 bootloader image is already added!") return @@ -141,11 +144,7 @@ def add_tinyuf2_extra_image(): ( board_config.get( "upload.arduino.uf2_bootloader_offset", - ( - "0x2d0000" - if env.subst("$BOARD").startswith("adafruit") - else "0x410000" - ), + ("0x2d0000" if env.subst("$BOARD").startswith("adafruit") else "0x410000"), ), tinuf2_image, ), @@ -211,16 +210,11 @@ def add_tinyuf2_extra_image(): ("0x8000", join(env.subst("$BUILD_DIR"), "partitions.bin")), ("0xe000", join(FRAMEWORK_DIR, "tools", "partitions", "boot_app0.bin")), ] - + [ - (offset, join(FRAMEWORK_DIR, img)) - for offset, img in board_config.get("upload.arduino.flash_extra_images", []) - ], + + [(offset, join(FRAMEWORK_DIR, img)) for offset, img in board_config.get("upload.arduino.flash_extra_images", [])], ) # Add an extra UF2 image if the 'TinyUF2' partition is selected -if partitions_name.endswith("tinyuf2.csv") or board_config.get( - "upload.arduino.tinyuf2_image", "" -): +if partitions_name.endswith("tinyuf2.csv") or board_config.get("upload.arduino.tinyuf2_image", ""): add_tinyuf2_extra_image() # @@ -233,8 +227,7 @@ def add_tinyuf2_extra_image(): join("$BUILD_DIR", "partitions.bin"), "$PARTITIONS_TABLE_CSV", env.VerboseAction( - '"$PYTHONEXE" "%s" -q $SOURCE $TARGET' - % join(FRAMEWORK_DIR, "tools", "gen_esp32part.py"), + '"$PYTHONEXE" "%s" -q $SOURCE $TARGET' % join(FRAMEWORK_DIR, "tools", "gen_esp32part.py"), "Generating partitions $TARGET", ), ) @@ -245,7 +238,5 @@ def add_tinyuf2_extra_image(): # action = deepcopy(env["BUILDERS"]["ElfToBin"].action) -action.cmd_list = env["BUILDERS"]["ElfToBin"].action.cmd_list.replace( - "-o", "--elf-sha256-offset 0xb0 -o" -) +action.cmd_list = env["BUILDERS"]["ElfToBin"].action.cmd_list.replace("-o", "--elf-sha256-offset 0xb0 -o") env["BUILDERS"]["ElfToBin"].action = action diff --git a/variants/AirM2M_CORE_ESP32C3/pins_arduino.h b/variants/AirM2M_CORE_ESP32C3/pins_arduino.h index 48b128a25d0..ea40027c9e7 100644 --- a/variants/AirM2M_CORE_ESP32C3/pins_arduino.h +++ b/variants/AirM2M_CORE_ESP32C3/pins_arduino.h @@ -3,8 +3,8 @@ #include -static const uint8_t LED_BUILTIN = 12; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = 12; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t LED_BUILTIN_AUX = 13; @@ -15,10 +15,10 @@ static const uint8_t RX = 20; static const uint8_t SDA = 4; static const uint8_t SCL = 5; -static const uint8_t SS = 7; -static const uint8_t MOSI = 3; -static const uint8_t MISO = 10; -static const uint8_t SCK = 2; +static const uint8_t SS = 7; +static const uint8_t MOSI = 3; +static const uint8_t MISO = 10; +static const uint8_t SCK = 2; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/AirM2M_CORE_ESP32C3/variant.cpp b/variants/AirM2M_CORE_ESP32C3/variant.cpp index e7c8670a042..01bd641f5b9 100644 --- a/variants/AirM2M_CORE_ESP32C3/variant.cpp +++ b/variants/AirM2M_CORE_ESP32C3/variant.cpp @@ -1,7 +1,9 @@ #include "Arduino.h" -extern "C" void initVariant(void){ - // Stop LEDs floating - pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, LOW); - pinMode(LED_BUILTIN_AUX, OUTPUT); digitalWrite(LED_BUILTIN_AUX, LOW); -} \ No newline at end of file +extern "C" void initVariant(void) { + // Stop LEDs floating + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LOW); + pinMode(LED_BUILTIN_AUX, OUTPUT); + digitalWrite(LED_BUILTIN_AUX, LOW); +} diff --git a/variants/Aventen_S3_Sync/pins_arduino.h b/variants/Aventen_S3_Sync/pins_arduino.h index 3ced97de06d..3bf533da639 100644 --- a/variants/Aventen_S3_Sync/pins_arduino.h +++ b/variants/Aventen_S3_Sync/pins_arduino.h @@ -12,19 +12,19 @@ static const uint8_t TX = 43; static const uint8_t RX = 44; -static const uint8_t SDA = 2; -static const uint8_t SCL = 3; +static const uint8_t SDA = 2; +static const uint8_t SCL = 3; static const uint8_t SCL_1 = 21; static const uint8_t SDA_1 = 20; -static const uint8_t SS = 10; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 13; -static const uint8_t SCK = 12; +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; -static const uint8_t ALS = 17; +static const uint8_t ALS = 17; static const uint8_t RGB_DI = 38; -static const uint8_t RF_SW = 37; +static const uint8_t RF_SW = 37; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/Bee_Data_Logger/pins_arduino.h b/variants/Bee_Data_Logger/pins_arduino.h index d007ea18c6a..7cba79baf2e 100644 --- a/variants/Bee_Data_Logger/pins_arduino.h +++ b/variants/Bee_Data_Logger/pins_arduino.h @@ -16,12 +16,12 @@ static const uint8_t RX = 44; static const uint8_t SDA = 37; static const uint8_t SCL = 36; -static const uint8_t SS = 47; -static const uint8_t MOSI = 46; -static const uint8_t MISO = 45; -static const uint8_t SDO = 35; -static const uint8_t SDI = 37; -static const uint8_t SCK = 48; +static const uint8_t SS = 47; +static const uint8_t MOSI = 46; +static const uint8_t MISO = 45; +static const uint8_t SDO = 35; +static const uint8_t SDI = 37; +static const uint8_t SCK = 48; static const uint8_t A3 = 3; static const uint8_t A4 = 4; @@ -69,8 +69,8 @@ static const uint8_t RGB_PWR = 34; #define PIN_NEOPIXEL RGB_DATA // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN diff --git a/variants/Bee_Motion/pins_arduino.h b/variants/Bee_Motion/pins_arduino.h index d11f332cef9..8c06190e870 100644 --- a/variants/Bee_Motion/pins_arduino.h +++ b/variants/Bee_Motion/pins_arduino.h @@ -15,12 +15,12 @@ static const uint8_t RX = 44; static const uint8_t SDA = 36; static const uint8_t SCL = 37; -static const uint8_t SS = 5; -static const uint8_t MOSI = 16; -static const uint8_t MISO = 38; -static const uint8_t SDO = 35; -static const uint8_t SDI = 37; -static const uint8_t SCK = 15; +static const uint8_t SS = 5; +static const uint8_t MOSI = 16; +static const uint8_t MISO = 38; +static const uint8_t SDO = 35; +static const uint8_t SDI = 37; +static const uint8_t SCK = 15; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/Bee_Motion_Mini/pins_arduino.h b/variants/Bee_Motion_Mini/pins_arduino.h index 3e308be5de6..376125c2bf6 100644 --- a/variants/Bee_Motion_Mini/pins_arduino.h +++ b/variants/Bee_Motion_Mini/pins_arduino.h @@ -12,10 +12,10 @@ static const uint8_t PIR = 5; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 7; -static const uint8_t MOSI = 6; -static const uint8_t MISO = 5; -static const uint8_t SCK = 4; +static const uint8_t SS = 7; +static const uint8_t MOSI = 6; +static const uint8_t MISO = 5; +static const uint8_t SCK = 4; static const uint8_t A0 = 0; static const uint8_t A1 = 1; @@ -25,4 +25,3 @@ static const uint8_t A4 = 4; static const uint8_t A5 = 5; #endif /* Pins_Arduino_h */ - diff --git a/variants/Bee_Motion_S3/pins_arduino.h b/variants/Bee_Motion_S3/pins_arduino.h index 6eebf47d884..84d13be78e2 100644 --- a/variants/Bee_Motion_S3/pins_arduino.h +++ b/variants/Bee_Motion_S3/pins_arduino.h @@ -16,12 +16,12 @@ static const uint8_t RX = 44; static const uint8_t SDA = 37; static const uint8_t SCL = 36; -static const uint8_t SS = 5; -static const uint8_t MOSI = 15; -static const uint8_t MISO = 16; -static const uint8_t SDO = 35; -static const uint8_t SDI = 37; -static const uint8_t SCK = 17; +static const uint8_t SS = 5; +static const uint8_t MOSI = 15; +static const uint8_t MISO = 16; +static const uint8_t SDO = 35; +static const uint8_t SDI = 37; +static const uint8_t SCK = 17; static const uint8_t A5 = 5; static const uint8_t A6 = 6; @@ -76,8 +76,8 @@ static const uint8_t RGB_PWR = 34; #define PIN_NEOPIXEL RGB_DATA // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN diff --git a/variants/Bee_S3/pins_arduino.h b/variants/Bee_S3/pins_arduino.h index 2ea399fd532..740baf8fdd1 100644 --- a/variants/Bee_S3/pins_arduino.h +++ b/variants/Bee_S3/pins_arduino.h @@ -16,12 +16,12 @@ static const uint8_t RX = 44; static const uint8_t SDA = 37; static const uint8_t SCL = 36; -static const uint8_t SS = 5; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 38; -static const uint8_t SDO = 35; -static const uint8_t SDI = 38; -static const uint8_t SCK = 39; +static const uint8_t SS = 5; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 38; +static const uint8_t SDO = 35; +static const uint8_t SDI = 38; +static const uint8_t SCK = 39; static const uint8_t A3 = 3; @@ -68,8 +68,8 @@ static const uint8_t RGB_PWR = 34; #define PIN_NEOPIXEL RGB_DATA // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN diff --git a/variants/ET-Board/pins_arduino.h b/variants/ET-Board/pins_arduino.h index 7275f956f4f..b132299bd94 100644 --- a/variants/ET-Board/pins_arduino.h +++ b/variants/ET-Board/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 5; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 34; @@ -13,31 +13,31 @@ static const uint8_t RX = 35; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 29; -static const uint8_t MOSI = 37; -static const uint8_t MISO = 31; -static const uint8_t SCK = 30; - -static const uint8_t A0 = 36; // BUILTIN_Potentiometer -static const uint8_t A1 = 39; // BUILTIN_CDS -static const uint8_t A2 = 32; // BUILTIN_temperature -static const uint8_t A3 = 33; // Analog Input -static const uint8_t A4 = 34; // Analog Input -static const uint8_t A5 = 35; // Analog Input -static const uint8_t A6 = 25; // Analog Input -static const uint8_t A7 = 26; // Analog Input - - -static const uint8_t D2 = 27; // BUILTIN_LED_Red -static const uint8_t D3 = 14; // BUILTIN_LED_Blue -static const uint8_t D4 = 12; // BUILTIN_LED_Green -static const uint8_t D5 = 13; // BUILTIN_LED_Yellow -static const uint8_t D6 = 15; // BUILTIN_BUTTON_Red -static const uint8_t D7 = 16; // BUILTIN_BUTTON_Blue -static const uint8_t D8 = 17; // BUILTIN_BUTTON_Green -static const uint8_t D9 = 4; // BUILTIN_BUTTON_Yellow +static const uint8_t SS = 29; +static const uint8_t MOSI = 37; +static const uint8_t MISO = 31; +static const uint8_t SCK = 30; + +static const uint8_t A0 = 36; // BUILTIN_Potentiometer +static const uint8_t A1 = 39; // BUILTIN_CDS +static const uint8_t A2 = 32; // BUILTIN_temperature +static const uint8_t A3 = 33; // Analog Input +static const uint8_t A4 = 34; // Analog Input +static const uint8_t A5 = 35; // Analog Input +static const uint8_t A6 = 25; // Analog Input +static const uint8_t A7 = 26; // Analog Input + + +static const uint8_t D2 = 27; // BUILTIN_LED_Red +static const uint8_t D3 = 14; // BUILTIN_LED_Blue +static const uint8_t D4 = 12; // BUILTIN_LED_Green +static const uint8_t D5 = 13; // BUILTIN_LED_Yellow +static const uint8_t D6 = 15; // BUILTIN_BUTTON_Red +static const uint8_t D7 = 16; // BUILTIN_BUTTON_Blue +static const uint8_t D8 = 17; // BUILTIN_BUTTON_Green +static const uint8_t D9 = 4; // BUILTIN_BUTTON_Yellow static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; -#endif /* Pins_Arduino_h */ \ No newline at end of file +#endif /* Pins_Arduino_h */ diff --git a/variants/Edgebox-ESP-100/pins_arduino.h b/variants/Edgebox-ESP-100/pins_arduino.h index 0c14982ec9b..d2f54a89383 100644 --- a/variants/Edgebox-ESP-100/pins_arduino.h +++ b/variants/Edgebox-ESP-100/pins_arduino.h @@ -8,7 +8,7 @@ static const uint8_t TXD = 43; static const uint8_t RXD = 44; static const uint8_t RST = 0; -//I2C +//I2C static const uint8_t SDA = 20; static const uint8_t SCL = 19; @@ -56,4 +56,4 @@ static const uint8_t DI3 = 7; static const uint8_t AO0 = 42; static const uint8_t AO1 = 41; -#endif /* Pins_Arduino_h */ \ No newline at end of file +#endif /* Pins_Arduino_h */ diff --git a/variants/Geekble_ESP32C3/pins_arduino.h b/variants/Geekble_ESP32C3/pins_arduino.h index bd32db1e67c..0a7b6eb5646 100644 --- a/variants/Geekble_ESP32C3/pins_arduino.h +++ b/variants/Geekble_ESP32C3/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 10; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 21; @@ -13,10 +13,10 @@ static const uint8_t RX = 20; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 7; -static const uint8_t MOSI = 6; -static const uint8_t MISO = 5; -static const uint8_t SCK = 4; +static const uint8_t SS = 7; +static const uint8_t MOSI = 6; +static const uint8_t MISO = 5; +static const uint8_t SCK = 4; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/Microduino-esp32/pins_arduino.h b/variants/Microduino-esp32/pins_arduino.h index 7dc0d236de9..890ec66ac4e 100644 --- a/variants/Microduino-esp32/pins_arduino.h +++ b/variants/Microduino-esp32/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = -1; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define MTDO 15 @@ -15,17 +15,17 @@ static const uint8_t LED_BUILTIN = -1; static const uint8_t TX = 1; static const uint8_t RX = 3; -static const uint8_t SDA = 22;//23; -static const uint8_t SCL = 21;//19; +static const uint8_t SDA = 22; //23; +static const uint8_t SCL = 21; //19; -#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin) +#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin) static const uint8_t SDA1 = 12; static const uint8_t SCL1 = 13; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 12; static const uint8_t A1 = 13; @@ -45,12 +45,12 @@ static const uint8_t D0 = 3; static const uint8_t D1 = 1; static const uint8_t D2 = 16; static const uint8_t D3 = 17; -static const uint8_t D4 = 32;//ADC1_CH4 -static const uint8_t D5 = 33;//ADC1_CH5 -static const uint8_t D6 = 25;//ADC2_CH8 DAC_1 -static const uint8_t D7 = 26;//ADC2_CH9 DAC_2 -static const uint8_t D8 = 27;//ADC2_CH7 -static const uint8_t D9 = 14;//ADC2_CH6 +static const uint8_t D4 = 32; //ADC1_CH4 +static const uint8_t D5 = 33; //ADC1_CH5 +static const uint8_t D6 = 25; //ADC2_CH8 DAC_1 +static const uint8_t D7 = 26; //ADC2_CH9 DAC_2 +static const uint8_t D8 = 27; //ADC2_CH7 +static const uint8_t D9 = 14; //ADC2_CH6 static const uint8_t D10 = 5; static const uint8_t D11 = 23; static const uint8_t D12 = 19; diff --git a/variants/Nebula_S3/pins_arduino.h b/variants/Nebula_S3/pins_arduino.h index 39fbe5707d2..fb8965fc2d3 100644 --- a/variants/Nebula_S3/pins_arduino.h +++ b/variants/Nebula_S3/pins_arduino.h @@ -8,7 +8,7 @@ #define USB_PID 0x1001 static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 45; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 @@ -22,10 +22,10 @@ static const uint8_t SCL = 13; static const uint8_t SDA1 = 2; static const uint8_t SCL1 = 1; -static const uint8_t SS = 41; -static const uint8_t MOSI = 40; -static const uint8_t MISO = 39; -static const uint8_t SCK = 38; +static const uint8_t SS = 41; +static const uint8_t MOSI = 40; +static const uint8_t MISO = 39; +static const uint8_t SCK = 38; static const uint8_t D0 = 1; static const uint8_t D1 = 2; diff --git a/variants/S_ODI_Ultra_v1/pins_arduino.h b/variants/S_ODI_Ultra_v1/pins_arduino.h index 87a6d56e0b3..37bc36bf7f4 100644 --- a/variants/S_ODI_Ultra_v1/pins_arduino.h +++ b/variants/S_ODI_Ultra_v1/pins_arduino.h @@ -5,9 +5,9 @@ static const uint8_t LED_BUILTIN = 2; static const uint8_t LED_BUILTINB = 4; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -#define BUILTIN_LED2 LED_BUILTINB +#define BUILTIN_LED2 LED_BUILTINB static const uint8_t TX = 1; static const uint8_t RX = 3; @@ -15,10 +15,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; @@ -53,4 +53,4 @@ static const uint8_t DAC2 = 26; #endif /* Pins_Arduino_h */ -/* compitable with SPELEC S.ODI Ultra v1.0 (based on ESP32 Series)*/ +/* compatible with SPELEC S.ODI Ultra v1.0 (based on ESP32 Series)*/ diff --git a/variants/VALTRACK_V4_MFW_ESP32_C3/pins_arduino.h b/variants/VALTRACK_V4_MFW_ESP32_C3/pins_arduino.h index b473c8afff1..c2481b4f8df 100644 --- a/variants/VALTRACK_V4_MFW_ESP32_C3/pins_arduino.h +++ b/variants/VALTRACK_V4_MFW_ESP32_C3/pins_arduino.h @@ -12,10 +12,10 @@ static const uint8_t RX1 = 1; static const uint8_t SDA = 5; static const uint8_t SCL = 6; -static const uint8_t SS = 20; -static const uint8_t MOSI = 10; -static const uint8_t MISO = 9; -static const uint8_t SCK = 8; +static const uint8_t SS = 20; +static const uint8_t MOSI = 10; +static const uint8_t MISO = 9; +static const uint8_t SCK = 8; static const uint8_t A0 = 2; static const uint8_t A1 = 3; @@ -34,15 +34,15 @@ static const uint8_t D8 = 8; static const uint8_t D9 = 9; static const uint8_t D10 = 10; -static const uint8_t GPIO_IIC_DATA = 5; -static const uint8_t GPIO_IIC_CLOCK = 6; -static const uint8_t GPIO_PWRKEY = 7; +static const uint8_t GPIO_IIC_DATA = 5; +static const uint8_t GPIO_IIC_CLOCK = 6; +static const uint8_t GPIO_PWRKEY = 7; static const uint8_t GPIO_GSM_ENABLE = 10; static const uint8_t GPIO_TPS_ENABLE = 4; -static const uint8_t GPIO_INT1 = 3; -static const uint8_t GPIO_ANALOG_IN = 2; -static const uint8_t GPIO_SOS = 9; -static const uint8_t GPIO_CHG_IN = 4; +static const uint8_t GPIO_INT1 = 3; +static const uint8_t GPIO_ANALOG_IN = 2; +static const uint8_t GPIO_SOS = 9; +static const uint8_t GPIO_CHG_IN = 4; static const uint8_t GPIO_LED_SIGNAL = 8; diff --git a/variants/VALTRACK_V4_VTS_ESP32_C3/pins_arduino.h b/variants/VALTRACK_V4_VTS_ESP32_C3/pins_arduino.h index b473c8afff1..c2481b4f8df 100644 --- a/variants/VALTRACK_V4_VTS_ESP32_C3/pins_arduino.h +++ b/variants/VALTRACK_V4_VTS_ESP32_C3/pins_arduino.h @@ -12,10 +12,10 @@ static const uint8_t RX1 = 1; static const uint8_t SDA = 5; static const uint8_t SCL = 6; -static const uint8_t SS = 20; -static const uint8_t MOSI = 10; -static const uint8_t MISO = 9; -static const uint8_t SCK = 8; +static const uint8_t SS = 20; +static const uint8_t MOSI = 10; +static const uint8_t MISO = 9; +static const uint8_t SCK = 8; static const uint8_t A0 = 2; static const uint8_t A1 = 3; @@ -34,15 +34,15 @@ static const uint8_t D8 = 8; static const uint8_t D9 = 9; static const uint8_t D10 = 10; -static const uint8_t GPIO_IIC_DATA = 5; -static const uint8_t GPIO_IIC_CLOCK = 6; -static const uint8_t GPIO_PWRKEY = 7; +static const uint8_t GPIO_IIC_DATA = 5; +static const uint8_t GPIO_IIC_CLOCK = 6; +static const uint8_t GPIO_PWRKEY = 7; static const uint8_t GPIO_GSM_ENABLE = 10; static const uint8_t GPIO_TPS_ENABLE = 4; -static const uint8_t GPIO_INT1 = 3; -static const uint8_t GPIO_ANALOG_IN = 2; -static const uint8_t GPIO_SOS = 9; -static const uint8_t GPIO_CHG_IN = 4; +static const uint8_t GPIO_INT1 = 3; +static const uint8_t GPIO_ANALOG_IN = 2; +static const uint8_t GPIO_SOS = 9; +static const uint8_t GPIO_CHG_IN = 4; static const uint8_t GPIO_LED_SIGNAL = 8; diff --git a/variants/XIAO_ESP32C3/pins_arduino.h b/variants/XIAO_ESP32C3/pins_arduino.h index 8de70af9ea2..ca89c5f557e 100644 --- a/variants/XIAO_ESP32C3/pins_arduino.h +++ b/variants/XIAO_ESP32C3/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 20; static const uint8_t SDA = 6; static const uint8_t SCL = 7; -static const uint8_t SS = 20; -static const uint8_t MOSI = 10; -static const uint8_t MISO = 9; -static const uint8_t SCK = 8; +static const uint8_t SS = 20; +static const uint8_t MOSI = 10; +static const uint8_t MISO = 9; +static const uint8_t SCK = 8; static const uint8_t A0 = 2; static const uint8_t A1 = 3; diff --git a/variants/XIAO_ESP32C6/pins_arduino.h b/variants/XIAO_ESP32C6/pins_arduino.h index 43f319ba690..d93a85e3549 100644 --- a/variants/XIAO_ESP32C6/pins_arduino.h +++ b/variants/XIAO_ESP32C6/pins_arduino.h @@ -11,7 +11,7 @@ #define USB_SERIAL "" static const uint8_t LED_BUILTIN = 15; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 16; @@ -20,10 +20,10 @@ static const uint8_t RX = 17; static const uint8_t SDA = 22; static const uint8_t SCL = 23; -static const uint8_t SS = 21; +static const uint8_t SS = 21; static const uint8_t MOSI = 18; static const uint8_t MISO = 20; -static const uint8_t SCK = 19; +static const uint8_t SCK = 19; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/XIAO_ESP32S3/pins_arduino.h b/variants/XIAO_ESP32S3/pins_arduino.h index cb77ca81cb6..b019fd2d747 100644 --- a/variants/XIAO_ESP32S3/pins_arduino.h +++ b/variants/XIAO_ESP32S3/pins_arduino.h @@ -7,7 +7,7 @@ #define USB_PID 0x0056 static const uint8_t LED_BUILTIN = 21; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 43; @@ -16,10 +16,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 5; static const uint8_t SCL = 6; -static const uint8_t SS = 44; +static const uint8_t SS = 44; static const uint8_t MOSI = 9; static const uint8_t MISO = 8; -static const uint8_t SCK = 7; +static const uint8_t SCK = 7; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/adafruit_camera_esp32s3/pins_arduino.h b/variants/adafruit_camera_esp32s3/pins_arduino.h index 62132dcadc3..6107855e709 100644 --- a/variants/adafruit_camera_esp32s3/pins_arduino.h +++ b/variants/adafruit_camera_esp32s3/pins_arduino.h @@ -4,11 +4,11 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x239A -#define USB_PID 0x8117 -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "Camera ESP32-S3" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x239A +#define USB_PID 0x8117 +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "Camera ESP32-S3" +#define USB_SERIAL "" // Empty string for MAC address static const uint8_t PIN_NEOPIXEL = 1; @@ -16,31 +16,31 @@ static const uint8_t NEOPIXEL_PIN = 1; //By making LED_BUILTIN have the same value of RGB_BUILTIN //NeoPixel LED can also be used as LED_BUILTIN with digitalMode() + digitalWrite() -static const uint8_t LED_BUILTIN = PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() and digitalWrite() for blinking -#define RGB_BUILTIN (PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 static const uint8_t TFT_BACKLIGHT = 45; -static const uint8_t TFT_DC = 40; -static const uint8_t TFT_CS = 39; -static const uint8_t TFT_RESET = 38; -static const uint8_t TFT_RST = 38; +static const uint8_t TFT_DC = 40; +static const uint8_t TFT_CS = 39; +static const uint8_t TFT_RESET = 38; +static const uint8_t TFT_RST = 38; -static const uint8_t SD_CS = 48; +static const uint8_t SD_CS = 48; static const uint8_t SD_CHIP_SELECT = 48; -static const uint8_t SPEAKER = 46; +static const uint8_t SPEAKER = 46; static const uint8_t SCL = 33; static const uint8_t SDA = 34; -static const uint8_t SS = 48; -static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; -static const uint8_t MISO = 37; +static const uint8_t SS = 48; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; static const uint8_t A0 = 17; static const uint8_t A1 = 18; @@ -63,23 +63,23 @@ static const uint8_t DAC2 = 18; #define AWEXP_BUTTON_LEFT 14 #define AWEXP_BUTTON_DOWN 15 -#define RESET_GPIO_NUM 47 -#define PWDN_GPIO_NUM 21 -#define XCLK_GPIO_NUM 8 -#define SIOD_GPIO_NUM SDA -#define SIOC_GPIO_NUM SCL - -#define Y9_GPIO_NUM 7 -#define Y8_GPIO_NUM 9 -#define Y7_GPIO_NUM 10 -#define Y6_GPIO_NUM 12 -#define Y5_GPIO_NUM 14 -#define Y4_GPIO_NUM 16 -#define Y3_GPIO_NUM 15 -#define Y2_GPIO_NUM 13 -#define VSYNC_GPIO_NUM 5 -#define HREF_GPIO_NUM 6 -#define PCLK_GPIO_NUM 11 +#define RESET_GPIO_NUM 47 +#define PWDN_GPIO_NUM 21 +#define XCLK_GPIO_NUM 8 +#define SIOD_GPIO_NUM SDA +#define SIOC_GPIO_NUM SCL + +#define Y9_GPIO_NUM 7 +#define Y8_GPIO_NUM 9 +#define Y7_GPIO_NUM 10 +#define Y6_GPIO_NUM 12 +#define Y5_GPIO_NUM 14 +#define Y4_GPIO_NUM 16 +#define Y3_GPIO_NUM 15 +#define Y2_GPIO_NUM 13 +#define VSYNC_GPIO_NUM 5 +#define HREF_GPIO_NUM 6 +#define PCLK_GPIO_NUM 11 #endif /* Pins_Arduino_h */ diff --git a/variants/adafruit_camera_esp32s3/variant.cpp b/variants/adafruit_camera_esp32s3/variant.cpp index 06e5c24cb76..353818f19e8 100644 --- a/variants/adafruit_camera_esp32s3/variant.cpp +++ b/variants/adafruit_camera_esp32s3/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,18 +28,17 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - pinMode(TFT_BACKLIGHT, OUTPUT); - digitalWrite(TFT_BACKLIGHT, LOW); - pinMode(SD_CS, OUTPUT); - digitalWrite(SD_CS, HIGH); - pinMode(TFT_CS, OUTPUT); - digitalWrite(TFT_CS, HIGH); - pinMode(TFT_RESET, OUTPUT); - digitalWrite(TFT_RESET, LOW); - delay(1); - digitalWrite(TFT_RESET, HIGH); -} + // Initialize variant/board, called before setup() + void initVariant(void) { + pinMode(TFT_BACKLIGHT, OUTPUT); + digitalWrite(TFT_BACKLIGHT, LOW); + pinMode(SD_CS, OUTPUT); + digitalWrite(SD_CS, HIGH); + pinMode(TFT_CS, OUTPUT); + digitalWrite(TFT_CS, HIGH); + pinMode(TFT_RESET, OUTPUT); + digitalWrite(TFT_RESET, LOW); + delay(1); + digitalWrite(TFT_RESET, HIGH); + } } diff --git a/variants/adafruit_feather_esp32_v2/pins_arduino.h b/variants/adafruit_feather_esp32_v2/pins_arduino.h index 7aae51a2d16..ced795ca6fa 100644 --- a/variants/adafruit_feather_esp32_v2/pins_arduino.h +++ b/variants/adafruit_feather_esp32_v2/pins_arduino.h @@ -12,13 +12,13 @@ static const uint8_t RX = 7; static const uint8_t SDA = 22; static const uint8_t SCL = 20; -static const uint8_t SS = 33; -static const uint8_t MOSI = 19; -static const uint8_t MISO = 21; -static const uint8_t SCK = 5; +static const uint8_t SS = 33; +static const uint8_t MOSI = 19; +static const uint8_t MISO = 21; +static const uint8_t SCK = 5; // mapping to match other feathers and also in order -static const uint8_t A0 = 26; +static const uint8_t A0 = 26; static const uint8_t A1 = 25; static const uint8_t A2 = 34; static const uint8_t A3 = 39; @@ -39,15 +39,15 @@ static const uint8_t A13 = 35; // internal switch #define BUTTON 38 -// User LED +// User LED static const uint8_t LED_BUILTIN = 13; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // Neopixel #define PIN_NEOPIXEL 0 // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() and digitalWrite() for blinking -#define RGB_BUILTIN (PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 // Neopixel & I2C power diff --git a/variants/adafruit_feather_esp32_v2/variant.cpp b/variants/adafruit_feather_esp32_v2/variant.cpp index 9345f6058a6..92acd67a1e8 100644 --- a/variants/adafruit_feather_esp32_v2/variant.cpp +++ b/variants/adafruit_feather_esp32_v2/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,13 +28,11 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - // This board has a power control pin, and we must set it to output and high - // in order to enable the NeoPixels & I2C - pinMode(NEOPIXEL_I2C_POWER, OUTPUT); - digitalWrite(NEOPIXEL_I2C_POWER, HIGH); -} - + // Initialize variant/board, called before setup() + void initVariant(void) { + // This board has a power control pin, and we must set it to output and high + // in order to enable the NeoPixels & I2C + pinMode(NEOPIXEL_I2C_POWER, OUTPUT); + digitalWrite(NEOPIXEL_I2C_POWER, HIGH); + } } diff --git a/variants/adafruit_feather_esp32s2/pins_arduino.h b/variants/adafruit_feather_esp32s2/pins_arduino.h index 013ae6c6dea..a8851257cc6 100644 --- a/variants/adafruit_feather_esp32s2/pins_arduino.h +++ b/variants/adafruit_feather_esp32s2/pins_arduino.h @@ -4,35 +4,35 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x239A -#define USB_PID 0x80EB -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "Feather ESP32-S2" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x239A +#define USB_PID 0x80EB +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "Feather ESP32-S2" +#define USB_SERIAL "" // Empty string for MAC address -// User LED +// User LED #define LED_BUILTIN 13 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility // Neopixel #define PIN_NEOPIXEL 33 // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() and digitalWrite() for blinking -#define RGB_BUILTIN (PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 -#define NEOPIXEL_NUM 1 // number of neopixels -#define NEOPIXEL_POWER 21 // power pin -#define NEOPIXEL_POWER_ON HIGH // power pin state when on -#define I2C_POWER 7 // I2C power pin -#define PIN_I2C_POWER 7 // I2C power pin +#define NEOPIXEL_NUM 1 // number of neopixels +#define NEOPIXEL_POWER 21 // power pin +#define NEOPIXEL_POWER_ON HIGH // power pin state when on +#define I2C_POWER 7 // I2C power pin +#define PIN_I2C_POWER 7 // I2C power pin static const uint8_t SDA = 3; static const uint8_t SCL = 4; -static const uint8_t SS = 42; -static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; -static const uint8_t MISO = 37; +static const uint8_t SS = 42; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; static const uint8_t A0 = 18; static const uint8_t A1 = 17; diff --git a/variants/adafruit_feather_esp32s2/variant.cpp b/variants/adafruit_feather_esp32s2/variant.cpp index 069f735161d..f4ffd5b6303 100644 --- a/variants/adafruit_feather_esp32s2/variant.cpp +++ b/variants/adafruit_feather_esp32s2/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,19 +28,18 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - // This board has a power control pin, and we must set it to output and high - // in order to enable the NeoPixels. - pinMode(NEOPIXEL_POWER, OUTPUT); - digitalWrite(NEOPIXEL_POWER, HIGH); + // Initialize variant/board, called before setup() + void initVariant(void) { + // This board has a power control pin, and we must set it to output and high + // in order to enable the NeoPixels. + pinMode(NEOPIXEL_POWER, OUTPUT); + digitalWrite(NEOPIXEL_POWER, HIGH); - // turn on the I2C power by setting pin to opposite of 'rest state' - pinMode(PIN_I2C_POWER, INPUT); - delay(1); - bool polarity = digitalRead(PIN_I2C_POWER); - pinMode(PIN_I2C_POWER, OUTPUT); - digitalWrite(PIN_I2C_POWER, !polarity); -} + // turn on the I2C power by setting pin to opposite of 'rest state' + pinMode(PIN_I2C_POWER, INPUT); + delay(1); + bool polarity = digitalRead(PIN_I2C_POWER); + pinMode(PIN_I2C_POWER, OUTPUT); + digitalWrite(PIN_I2C_POWER, !polarity); + } } diff --git a/variants/adafruit_feather_esp32s2_reversetft/pins_arduino.h b/variants/adafruit_feather_esp32s2_reversetft/pins_arduino.h index d39b50628e2..7af92dc4dbc 100644 --- a/variants/adafruit_feather_esp32s2_reversetft/pins_arduino.h +++ b/variants/adafruit_feather_esp32s2_reversetft/pins_arduino.h @@ -4,39 +4,39 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x239A -#define USB_PID 0x80ED -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "Feather ESP32-S2 Reverse TFT" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x239A +#define USB_PID 0x80ED +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "Feather ESP32-S2 Reverse TFT" +#define USB_SERIAL "" // Empty string for MAC address -// User LED +// User LED #define LED_BUILTIN 13 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility // Neopixel #define PIN_NEOPIXEL 33 // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() and digitalWrite() for blinking -#define RGB_BUILTIN (PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 -#define NEOPIXEL_NUM 1 // number of neopixels -#define NEOPIXEL_POWER 21 // power pin -#define NEOPIXEL_POWER_ON HIGH // power pin state when on +#define NEOPIXEL_NUM 1 // number of neopixels +#define NEOPIXEL_POWER 21 // power pin +#define NEOPIXEL_POWER_ON HIGH // power pin state when on -#define TFT_I2C_POWER 7 -#define TFT_CS 42 -#define TFT_RST 41 -#define TFT_DC 40 -#define TFT_BACKLITE 45 +#define TFT_I2C_POWER 7 +#define TFT_CS 42 +#define TFT_RST 41 +#define TFT_DC 40 +#define TFT_BACKLITE 45 static const uint8_t SDA = 3; static const uint8_t SCL = 4; -static const uint8_t SS = 42; -static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; -static const uint8_t MISO = 37; +static const uint8_t SS = 42; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; static const uint8_t A0 = 18; static const uint8_t A1 = 17; diff --git a/variants/adafruit_feather_esp32s2_reversetft/variant.cpp b/variants/adafruit_feather_esp32s2_reversetft/variant.cpp index 548ce9ff4a1..62a99bd039a 100644 --- a/variants/adafruit_feather_esp32s2_reversetft/variant.cpp +++ b/variants/adafruit_feather_esp32s2_reversetft/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,15 +28,13 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - // This board has power control pins, and we must set them to output and high - // in order to enable the NeoPixels, TFT & I2C - pinMode(NEOPIXEL_POWER, OUTPUT); - digitalWrite(NEOPIXEL_POWER, HIGH); - pinMode(TFT_I2C_POWER, OUTPUT); - digitalWrite(TFT_I2C_POWER, HIGH); -} - + // Initialize variant/board, called before setup() + void initVariant(void) { + // This board has power control pins, and we must set them to output and high + // in order to enable the NeoPixels, TFT & I2C + pinMode(NEOPIXEL_POWER, OUTPUT); + digitalWrite(NEOPIXEL_POWER, HIGH); + pinMode(TFT_I2C_POWER, OUTPUT); + digitalWrite(TFT_I2C_POWER, HIGH); + } } diff --git a/variants/adafruit_feather_esp32s2_tft/pins_arduino.h b/variants/adafruit_feather_esp32s2_tft/pins_arduino.h index ca713ac315d..9d74dc3e737 100644 --- a/variants/adafruit_feather_esp32s2_tft/pins_arduino.h +++ b/variants/adafruit_feather_esp32s2_tft/pins_arduino.h @@ -4,39 +4,39 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x239A -#define USB_PID 0x810F -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "Feather ESP32-S2 TFT" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x239A +#define USB_PID 0x810F +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "Feather ESP32-S2 TFT" +#define USB_SERIAL "" // Empty string for MAC address -// User LED +// User LED #define LED_BUILTIN 13 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility // Neopixel #define PIN_NEOPIXEL 33 // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() and digitalWrite() for blinking -#define RGB_BUILTIN (PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 -#define NEOPIXEL_NUM 1 // number of neopixels -#define NEOPIXEL_POWER 34 // power pin -#define NEOPIXEL_POWER_ON HIGH // power pin state when on +#define NEOPIXEL_NUM 1 // number of neopixels +#define NEOPIXEL_POWER 34 // power pin +#define NEOPIXEL_POWER_ON HIGH // power pin state when on -#define TFT_I2C_POWER 21 -#define TFT_CS 7 -#define TFT_RST 40 -#define TFT_DC 39 -#define TFT_BACKLITE 45 +#define TFT_I2C_POWER 21 +#define TFT_CS 7 +#define TFT_RST 40 +#define TFT_DC 39 +#define TFT_BACKLITE 45 static const uint8_t SDA = 42; static const uint8_t SCL = 41; -static const uint8_t SS = 7; -static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; -static const uint8_t MISO = 37; +static const uint8_t SS = 7; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; static const uint8_t A0 = 18; static const uint8_t A1 = 17; diff --git a/variants/adafruit_feather_esp32s2_tft/variant.cpp b/variants/adafruit_feather_esp32s2_tft/variant.cpp index 548ce9ff4a1..62a99bd039a 100644 --- a/variants/adafruit_feather_esp32s2_tft/variant.cpp +++ b/variants/adafruit_feather_esp32s2_tft/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,15 +28,13 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - // This board has power control pins, and we must set them to output and high - // in order to enable the NeoPixels, TFT & I2C - pinMode(NEOPIXEL_POWER, OUTPUT); - digitalWrite(NEOPIXEL_POWER, HIGH); - pinMode(TFT_I2C_POWER, OUTPUT); - digitalWrite(TFT_I2C_POWER, HIGH); -} - + // Initialize variant/board, called before setup() + void initVariant(void) { + // This board has power control pins, and we must set them to output and high + // in order to enable the NeoPixels, TFT & I2C + pinMode(NEOPIXEL_POWER, OUTPUT); + digitalWrite(NEOPIXEL_POWER, HIGH); + pinMode(TFT_I2C_POWER, OUTPUT); + digitalWrite(TFT_I2C_POWER, HIGH); + } } diff --git a/variants/adafruit_feather_esp32s3/pins_arduino.h b/variants/adafruit_feather_esp32s3/pins_arduino.h index a8c491a64ad..1f3592d7be4 100644 --- a/variants/adafruit_feather_esp32s3/pins_arduino.h +++ b/variants/adafruit_feather_esp32s3/pins_arduino.h @@ -4,27 +4,27 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x239A -#define USB_PID 0x811B -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "Feather ESP32-S3" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x239A +#define USB_PID 0x811B +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "Feather ESP32-S3" +#define USB_SERIAL "" // Empty string for MAC address -// User LED +// User LED #define LED_BUILTIN 13 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility // Neopixel #define PIN_NEOPIXEL 33 // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() and digitalWrite() for blinking -#define RGB_BUILTIN (PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 -#define NEOPIXEL_NUM 1 // number of neopixels -#define NEOPIXEL_POWER 21 // power pin -#define NEOPIXEL_POWER_ON HIGH // power pin state when on -#define I2C_POWER 7 // I2C power pin -#define PIN_I2C_POWER 7 // I2C power pin +#define NEOPIXEL_NUM 1 // number of neopixels +#define NEOPIXEL_POWER 21 // power pin +#define NEOPIXEL_POWER_ON HIGH // power pin state when on +#define I2C_POWER 7 // I2C power pin +#define PIN_I2C_POWER 7 // I2C power pin static const uint8_t TX = 39; @@ -35,10 +35,10 @@ static const uint8_t RX = 38; static const uint8_t SDA = 3; static const uint8_t SCL = 4; -static const uint8_t SS = 42; -static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; -static const uint8_t MISO = 37; +static const uint8_t SS = 42; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; static const uint8_t A0 = 18; static const uint8_t A1 = 17; diff --git a/variants/adafruit_feather_esp32s3/variant.cpp b/variants/adafruit_feather_esp32s3/variant.cpp index 52acb84102e..50515582fa5 100644 --- a/variants/adafruit_feather_esp32s3/variant.cpp +++ b/variants/adafruit_feather_esp32s3/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,16 +28,15 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - // This board has a power control pin, and we must set it to output and high - // in order to enable the NeoPixels. - pinMode(NEOPIXEL_POWER, OUTPUT); - digitalWrite(NEOPIXEL_POWER, HIGH); + // Initialize variant/board, called before setup() + void initVariant(void) { + // This board has a power control pin, and we must set it to output and high + // in order to enable the NeoPixels. + pinMode(NEOPIXEL_POWER, OUTPUT); + digitalWrite(NEOPIXEL_POWER, HIGH); - // turn on the I2C power by setting LDO enable pin 'high' - pinMode(PIN_I2C_POWER, OUTPUT); - digitalWrite(PIN_I2C_POWER, HIGH); -} + // turn on the I2C power by setting LDO enable pin 'high' + pinMode(PIN_I2C_POWER, OUTPUT); + digitalWrite(PIN_I2C_POWER, HIGH); + } } diff --git a/variants/adafruit_feather_esp32s3_nopsram/pins_arduino.h b/variants/adafruit_feather_esp32s3_nopsram/pins_arduino.h index 65aec064fad..c0811c18cd3 100644 --- a/variants/adafruit_feather_esp32s3_nopsram/pins_arduino.h +++ b/variants/adafruit_feather_esp32s3_nopsram/pins_arduino.h @@ -4,27 +4,27 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x239A -#define USB_PID 0x8113 -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "Feather ESP32-S3 No PSRAM" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x239A +#define USB_PID 0x8113 +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "Feather ESP32-S3 No PSRAM" +#define USB_SERIAL "" // Empty string for MAC address -// User LED +// User LED #define LED_BUILTIN 13 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility // Neopixel #define PIN_NEOPIXEL 33 // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() and digitalWrite() for blinking -#define RGB_BUILTIN (PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 -#define NEOPIXEL_NUM 1 // number of neopixels -#define NEOPIXEL_POWER 21 // power pin -#define NEOPIXEL_POWER_ON HIGH // power pin state when on -#define I2C_POWER 7 // I2C power pin -#define PIN_I2C_POWER 7 // I2C power pin +#define NEOPIXEL_NUM 1 // number of neopixels +#define NEOPIXEL_POWER 21 // power pin +#define NEOPIXEL_POWER_ON HIGH // power pin state when on +#define I2C_POWER 7 // I2C power pin +#define PIN_I2C_POWER 7 // I2C power pin static const uint8_t TX = 39; @@ -35,10 +35,10 @@ static const uint8_t RX = 38; static const uint8_t SDA = 3; static const uint8_t SCL = 4; -static const uint8_t SS = 42; -static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; -static const uint8_t MISO = 37; +static const uint8_t SS = 42; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; static const uint8_t A0 = 18; static const uint8_t A1 = 17; diff --git a/variants/adafruit_feather_esp32s3_nopsram/variant.cpp b/variants/adafruit_feather_esp32s3_nopsram/variant.cpp index 52acb84102e..50515582fa5 100644 --- a/variants/adafruit_feather_esp32s3_nopsram/variant.cpp +++ b/variants/adafruit_feather_esp32s3_nopsram/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,16 +28,15 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - // This board has a power control pin, and we must set it to output and high - // in order to enable the NeoPixels. - pinMode(NEOPIXEL_POWER, OUTPUT); - digitalWrite(NEOPIXEL_POWER, HIGH); + // Initialize variant/board, called before setup() + void initVariant(void) { + // This board has a power control pin, and we must set it to output and high + // in order to enable the NeoPixels. + pinMode(NEOPIXEL_POWER, OUTPUT); + digitalWrite(NEOPIXEL_POWER, HIGH); - // turn on the I2C power by setting LDO enable pin 'high' - pinMode(PIN_I2C_POWER, OUTPUT); - digitalWrite(PIN_I2C_POWER, HIGH); -} + // turn on the I2C power by setting LDO enable pin 'high' + pinMode(PIN_I2C_POWER, OUTPUT); + digitalWrite(PIN_I2C_POWER, HIGH); + } } diff --git a/variants/adafruit_feather_esp32s3_reversetft/pins_arduino.h b/variants/adafruit_feather_esp32s3_reversetft/pins_arduino.h index 8fa045489fe..678bcf8b87a 100644 --- a/variants/adafruit_feather_esp32s3_reversetft/pins_arduino.h +++ b/variants/adafruit_feather_esp32s3_reversetft/pins_arduino.h @@ -4,39 +4,39 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x239A -#define USB_PID 0x8123 -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "Feather ESP32-S3 Reverse TFT" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x239A +#define USB_PID 0x8123 +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "Feather ESP32-S3 Reverse TFT" +#define USB_SERIAL "" // Empty string for MAC address -// User LED +// User LED #define LED_BUILTIN 13 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility // Neopixel #define PIN_NEOPIXEL 33 // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() and digitalWrite() for blinking -#define RGB_BUILTIN (PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 -#define NEOPIXEL_NUM 1 // number of neopixels -#define NEOPIXEL_POWER 21 // power pin -#define NEOPIXEL_POWER_ON HIGH // power pin state when on +#define NEOPIXEL_NUM 1 // number of neopixels +#define NEOPIXEL_POWER 21 // power pin +#define NEOPIXEL_POWER_ON HIGH // power pin state when on -#define TFT_I2C_POWER 7 -#define TFT_CS 42 -#define TFT_RST 41 -#define TFT_DC 40 -#define TFT_BACKLITE 45 +#define TFT_I2C_POWER 7 +#define TFT_CS 42 +#define TFT_RST 41 +#define TFT_DC 40 +#define TFT_BACKLITE 45 static const uint8_t SDA = 3; static const uint8_t SCL = 4; -static const uint8_t SS = 42; -static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; -static const uint8_t MISO = 37; +static const uint8_t SS = 42; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; static const uint8_t A0 = 18; static const uint8_t A1 = 17; diff --git a/variants/adafruit_feather_esp32s3_reversetft/variant.cpp b/variants/adafruit_feather_esp32s3_reversetft/variant.cpp index 548ce9ff4a1..62a99bd039a 100644 --- a/variants/adafruit_feather_esp32s3_reversetft/variant.cpp +++ b/variants/adafruit_feather_esp32s3_reversetft/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,15 +28,13 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - // This board has power control pins, and we must set them to output and high - // in order to enable the NeoPixels, TFT & I2C - pinMode(NEOPIXEL_POWER, OUTPUT); - digitalWrite(NEOPIXEL_POWER, HIGH); - pinMode(TFT_I2C_POWER, OUTPUT); - digitalWrite(TFT_I2C_POWER, HIGH); -} - + // Initialize variant/board, called before setup() + void initVariant(void) { + // This board has power control pins, and we must set them to output and high + // in order to enable the NeoPixels, TFT & I2C + pinMode(NEOPIXEL_POWER, OUTPUT); + digitalWrite(NEOPIXEL_POWER, HIGH); + pinMode(TFT_I2C_POWER, OUTPUT); + digitalWrite(TFT_I2C_POWER, HIGH); + } } diff --git a/variants/adafruit_feather_esp32s3_tft/pins_arduino.h b/variants/adafruit_feather_esp32s3_tft/pins_arduino.h index 56860f3c2d7..c31318af9f5 100644 --- a/variants/adafruit_feather_esp32s3_tft/pins_arduino.h +++ b/variants/adafruit_feather_esp32s3_tft/pins_arduino.h @@ -4,39 +4,39 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x239A -#define USB_PID 0x811D -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "Feather ESP32-S3 TFT" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x239A +#define USB_PID 0x811D +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "Feather ESP32-S3 TFT" +#define USB_SERIAL "" // Empty string for MAC address -// User LED +// User LED #define LED_BUILTIN 13 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility // Neopixel #define PIN_NEOPIXEL 33 // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() and digitalWrite() for blinking -#define RGB_BUILTIN (PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 -#define NEOPIXEL_NUM 1 // number of neopixels -#define NEOPIXEL_POWER 34 // power pin -#define NEOPIXEL_POWER_ON HIGH // power pin state when on +#define NEOPIXEL_NUM 1 // number of neopixels +#define NEOPIXEL_POWER 34 // power pin +#define NEOPIXEL_POWER_ON HIGH // power pin state when on -#define TFT_I2C_POWER 21 -#define TFT_CS 7 -#define TFT_RST 40 -#define TFT_DC 39 -#define TFT_BACKLITE 45 +#define TFT_I2C_POWER 21 +#define TFT_CS 7 +#define TFT_RST 40 +#define TFT_DC 39 +#define TFT_BACKLITE 45 static const uint8_t SDA = 42; static const uint8_t SCL = 41; -static const uint8_t SS = 7; -static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; -static const uint8_t MISO = 37; +static const uint8_t SS = 7; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; static const uint8_t A0 = 18; static const uint8_t A1 = 17; diff --git a/variants/adafruit_feather_esp32s3_tft/variant.cpp b/variants/adafruit_feather_esp32s3_tft/variant.cpp index 548ce9ff4a1..62a99bd039a 100644 --- a/variants/adafruit_feather_esp32s3_tft/variant.cpp +++ b/variants/adafruit_feather_esp32s3_tft/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,15 +28,13 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - // This board has power control pins, and we must set them to output and high - // in order to enable the NeoPixels, TFT & I2C - pinMode(NEOPIXEL_POWER, OUTPUT); - digitalWrite(NEOPIXEL_POWER, HIGH); - pinMode(TFT_I2C_POWER, OUTPUT); - digitalWrite(TFT_I2C_POWER, HIGH); -} - + // Initialize variant/board, called before setup() + void initVariant(void) { + // This board has power control pins, and we must set them to output and high + // in order to enable the NeoPixels, TFT & I2C + pinMode(NEOPIXEL_POWER, OUTPUT); + digitalWrite(NEOPIXEL_POWER, HIGH); + pinMode(TFT_I2C_POWER, OUTPUT); + digitalWrite(TFT_I2C_POWER, HIGH); + } } diff --git a/variants/adafruit_funhouse_esp32s2/pins_arduino.h b/variants/adafruit_funhouse_esp32s2/pins_arduino.h index 3594af16021..61d0d142e46 100644 --- a/variants/adafruit_funhouse_esp32s2/pins_arduino.h +++ b/variants/adafruit_funhouse_esp32s2/pins_arduino.h @@ -4,47 +4,47 @@ #include -#define USB_VID 0x239A -#define USB_PID 0x80F9 -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "Funhouse ESP32-S2" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x239A +#define USB_PID 0x80F9 +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "Funhouse ESP32-S2" +#define USB_SERIAL "" // Empty string for MAC address -#define LED_BUILTIN 37 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN 37 +#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define PIN_BUTTON1 3 -#define PIN_BUTTON2 4 -#define PIN_BUTTON3 5 -#define PIN_BUTTON4 0 // BOOT0 switch +#define PIN_BUTTON1 3 +#define PIN_BUTTON2 4 +#define PIN_BUTTON3 5 +#define PIN_BUTTON4 0 // BOOT0 switch static const uint8_t PIN_DOTSTAR_DATA = 14; static const uint8_t PIN_DOTSTAR_CLOCK = 15; static const uint8_t TFT_BACKLIGHT = 21; -static const uint8_t TFT_DC = 39; -static const uint8_t TFT_CS = 40; -static const uint8_t TFT_RESET = 41; +static const uint8_t TFT_DC = 39; +static const uint8_t TFT_CS = 40; +static const uint8_t TFT_RESET = 41; -static const uint8_t SPEAKER = 42; -static const uint8_t BUTTON_DOWN = PIN_BUTTON1; +static const uint8_t SPEAKER = 42; +static const uint8_t BUTTON_DOWN = PIN_BUTTON1; static const uint8_t BUTTON_SELECT = PIN_BUTTON2; -static const uint8_t BUTTON_UP = PIN_BUTTON3; -static const uint8_t SENSOR_PIR = 16; -static const uint8_t SENSOR_LIGHT = 18; +static const uint8_t BUTTON_UP = PIN_BUTTON3; +static const uint8_t SENSOR_PIR = 16; +static const uint8_t SENSOR_LIGHT = 18; static const uint8_t SDA = 34; static const uint8_t SCL = 33; -static const uint8_t SS = 40; -static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; -static const uint8_t MISO = 37; +static const uint8_t SS = 40; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; static const uint8_t A0 = 17; static const uint8_t A1 = 2; static const uint8_t A2 = 1; -static const uint8_t A3 = 18; // light sensor +static const uint8_t A3 = 18; // light sensor diff --git a/variants/adafruit_funhouse_esp32s2/variant.cpp b/variants/adafruit_funhouse_esp32s2/variant.cpp index 750f5f72b02..3a5934e96f6 100644 --- a/variants/adafruit_funhouse_esp32s2/variant.cpp +++ b/variants/adafruit_funhouse_esp32s2/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,10 +28,7 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - -} - + // Initialize variant/board, called before setup() + void initVariant(void) { + } } diff --git a/variants/adafruit_itsybitsy_esp32/pins_arduino.h b/variants/adafruit_itsybitsy_esp32/pins_arduino.h index c526628f7b1..081d4bdbc7d 100644 --- a/variants/adafruit_itsybitsy_esp32/pins_arduino.h +++ b/variants/adafruit_itsybitsy_esp32/pins_arduino.h @@ -4,15 +4,15 @@ #include #include "soc/soc_caps.h" -// User LED +// User LED static const uint8_t LED_BUILTIN = 13; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // Neopixel static const uint8_t PIN_NEOPIXEL = 0; // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() and digitalWrite() for blinking -#define RGB_BUILTIN (PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 static const uint8_t NEOPIXEL_POWER = 2; @@ -26,12 +26,12 @@ static const uint8_t RX = 8; static const uint8_t SDA = 15; static const uint8_t SCL = 27; -static const uint8_t SS = 32; -static const uint8_t MOSI = 21; -static const uint8_t MISO = 22; -static const uint8_t SCK = 19; +static const uint8_t SS = 32; +static const uint8_t MOSI = 21; +static const uint8_t MISO = 22; +static const uint8_t SCK = 19; -static const uint8_t A0 = 25; +static const uint8_t A0 = 25; static const uint8_t A1 = 26; static const uint8_t A2 = 4; static const uint8_t A3 = 38; diff --git a/variants/adafruit_itsybitsy_esp32/variant.cpp b/variants/adafruit_itsybitsy_esp32/variant.cpp index 726ec8fa483..ef1982107f4 100644 --- a/variants/adafruit_itsybitsy_esp32/variant.cpp +++ b/variants/adafruit_itsybitsy_esp32/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,13 +28,11 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - // This board has a power control pin, and we must set it to output and high - // in order to enable the NeoPixels. - pinMode(NEOPIXEL_POWER, OUTPUT); - digitalWrite(NEOPIXEL_POWER, HIGH); -} - + // Initialize variant/board, called before setup() + void initVariant(void) { + // This board has a power control pin, and we must set it to output and high + // in order to enable the NeoPixels. + pinMode(NEOPIXEL_POWER, OUTPUT); + digitalWrite(NEOPIXEL_POWER, HIGH); + } } diff --git a/variants/adafruit_magtag29_esp32s2/pins_arduino.h b/variants/adafruit_magtag29_esp32s2/pins_arduino.h index aaeb744ce0a..ef6b886ab30 100644 --- a/variants/adafruit_magtag29_esp32s2/pins_arduino.h +++ b/variants/adafruit_magtag29_esp32s2/pins_arduino.h @@ -4,37 +4,37 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x239A -#define USB_PID 0x80E5 -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "EPD MagTag 2.9\" ESP32-S2" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x239A +#define USB_PID 0x80E5 +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "EPD MagTag 2.9\" ESP32-S2" +#define USB_SERIAL "" // Empty string for MAC address -// User LED +// User LED #define LED_BUILTIN 13 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility // Neopixel -#define PIN_NEOPIXEL 1 // D1 +#define PIN_NEOPIXEL 1 // D1 // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() and digitalWrite() for blinking -#define RGB_BUILTIN (PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 -#define NEOPIXEL_NUM 4 // number of neopixels -#define NEOPIXEL_POWER 21 // power pin -#define NEOPIXEL_POWER_ON LOW // power pin state when on +#define NEOPIXEL_NUM 4 // number of neopixels +#define NEOPIXEL_POWER 21 // power pin +#define NEOPIXEL_POWER_ON LOW // power pin state when on -#define PIN_BUTTON1 15 -#define PIN_BUTTON2 14 -#define PIN_BUTTON3 12 -#define PIN_BUTTON4 11 -#define PIN_BUTTON5 0 // BOOT0 switch +#define PIN_BUTTON1 15 +#define PIN_BUTTON2 14 +#define PIN_BUTTON3 12 +#define PIN_BUTTON4 11 +#define PIN_BUTTON5 0 // BOOT0 switch -static const uint8_t EPD_BUSY = 5; +static const uint8_t EPD_BUSY = 5; static const uint8_t EPD_RESET = 6; -static const uint8_t EPD_DC = 7; -static const uint8_t EPD_CS = 8; +static const uint8_t EPD_DC = 7; +static const uint8_t EPD_CS = 8; static const uint8_t ACCEL_IRQ = 9; @@ -50,10 +50,10 @@ static const uint8_t SPEAKER_SHUTDOWN = 16; static const uint8_t SDA = 33; static const uint8_t SCL = 34; -static const uint8_t SS = 8; -static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; -static const uint8_t MISO = 37; +static const uint8_t SS = 8; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; diff --git a/variants/adafruit_magtag29_esp32s2/variant.cpp b/variants/adafruit_magtag29_esp32s2/variant.cpp index 750f5f72b02..3a5934e96f6 100644 --- a/variants/adafruit_magtag29_esp32s2/variant.cpp +++ b/variants/adafruit_magtag29_esp32s2/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,10 +28,7 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - -} - + // Initialize variant/board, called before setup() + void initVariant(void) { + } } diff --git a/variants/adafruit_matrixportal_esp32s3/pins_arduino.h b/variants/adafruit_matrixportal_esp32s3/pins_arduino.h index 99529c02510..aecdc7fd9db 100644 --- a/variants/adafruit_matrixportal_esp32s3/pins_arduino.h +++ b/variants/adafruit_matrixportal_esp32s3/pins_arduino.h @@ -4,27 +4,27 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x239A -#define USB_PID 0x8125 -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "MatrixPortal ESP32-S3" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x239A +#define USB_PID 0x8125 +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "MatrixPortal ESP32-S3" +#define USB_SERIAL "" // Empty string for MAC address -// User LED +// User LED #define LED_BUILTIN 13 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define PIN_NEOPIXEL 4 -#define NEOPIXEL_PIN 4 +#define PIN_NEOPIXEL 4 +#define NEOPIXEL_PIN 4 // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() and digitalWrite() for blinking -#define RGB_BUILTIN (PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 -#define NEOPIXEL_NUM 1 -#define PIN_LIGHTSENSOR A5 +#define NEOPIXEL_NUM 1 +#define PIN_LIGHTSENSOR A5 -#define PIN_BUTTON_UP 6 -#define PIN_BUTTON_DOWN 7 +#define PIN_BUTTON_UP 6 +#define PIN_BUTTON_DOWN 7 static const uint8_t TX = 18; static const uint8_t RX = 8; @@ -34,9 +34,9 @@ static const uint8_t RX = 8; static const uint8_t SDA = 16; static const uint8_t SCL = 17; -static const uint8_t SS = -1; +static const uint8_t SS = -1; static const uint8_t MOSI = -1; -static const uint8_t SCK = -1; +static const uint8_t SCK = -1; static const uint8_t MISO = -1; static const uint8_t A0 = 12; @@ -44,11 +44,11 @@ static const uint8_t A1 = 3; static const uint8_t A2 = 9; static const uint8_t A3 = 10; static const uint8_t A4 = 11; -static const uint8_t A5 = 5; // Light +static const uint8_t A5 = 5; // Light -static const uint8_t T3 = 3; // Touch pin IDs map directly -static const uint8_t T8 = 8; // to underlying GPIO numbers NOT -static const uint8_t T9 = 9; // the analog numbers on board silk +static const uint8_t T3 = 3; // Touch pin IDs map directly +static const uint8_t T8 = 8; // to underlying GPIO numbers NOT +static const uint8_t T9 = 9; // the analog numbers on board silk static const uint8_t T10 = 10; static const uint8_t T11 = 11; static const uint8_t T12 = 12; diff --git a/variants/adafruit_metro_esp32s2/pins_arduino.h b/variants/adafruit_metro_esp32s2/pins_arduino.h index 3b2e02b1dc1..44e8b7abceb 100644 --- a/variants/adafruit_metro_esp32s2/pins_arduino.h +++ b/variants/adafruit_metro_esp32s2/pins_arduino.h @@ -4,24 +4,24 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x239A -#define USB_PID 0x80DF -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "Metro ESP32-S2" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x239A +#define USB_PID 0x80DF +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "Metro ESP32-S2" +#define USB_SERIAL "" // Empty string for MAC address -#define LED_BUILTIN 42 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN 42 +#define BUILTIN_LED LED_BUILTIN // backward compatibility // Neopixel -#define PIN_NEOPIXEL 45 +#define PIN_NEOPIXEL 45 // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() and digitalWrite() for blinking -#define RGB_BUILTIN (PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 -#define NEOPIXEL_NUM 1 +#define NEOPIXEL_NUM 1 -#define PIN_BUTTON1 0 // BOOT0 switch +#define PIN_BUTTON1 0 // BOOT0 switch static const uint8_t TX = 5; static const uint8_t RX = 6; @@ -31,10 +31,10 @@ static const uint8_t RX = 6; static const uint8_t SDA = 33; static const uint8_t SCL = 34; -static const uint8_t SS = 42; -static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; -static const uint8_t MISO = 37; +static const uint8_t SS = 42; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; static const uint8_t A0 = 17; static const uint8_t A1 = 18; diff --git a/variants/adafruit_metro_esp32s2/variant.cpp b/variants/adafruit_metro_esp32s2/variant.cpp index 750f5f72b02..3a5934e96f6 100644 --- a/variants/adafruit_metro_esp32s2/variant.cpp +++ b/variants/adafruit_metro_esp32s2/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,10 +28,7 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - -} - + // Initialize variant/board, called before setup() + void initVariant(void) { + } } diff --git a/variants/adafruit_metro_esp32s3/pins_arduino.h b/variants/adafruit_metro_esp32s3/pins_arduino.h index e9769f113f6..0a8517faa6d 100644 --- a/variants/adafruit_metro_esp32s3/pins_arduino.h +++ b/variants/adafruit_metro_esp32s3/pins_arduino.h @@ -4,24 +4,24 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x239A -#define USB_PID 0x8145 -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "Metro ESP32-S3" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x239A +#define USB_PID 0x8145 +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "Metro ESP32-S3" +#define USB_SERIAL "" // Empty string for MAC address -#define LED_BUILTIN 13 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN 13 +#define BUILTIN_LED LED_BUILTIN // backward compatibility // Neopixel -#define PIN_NEOPIXEL 46 +#define PIN_NEOPIXEL 46 // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() and digitalWrite() for blinking -#define RGB_BUILTIN (PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 -#define NEOPIXEL_NUM 1 +#define NEOPIXEL_NUM 1 -#define PIN_BUTTON1 0 // BOOT0 switch +#define PIN_BUTTON1 0 // BOOT0 switch static const uint8_t TX = 40; static const uint8_t RX = 41; @@ -31,9 +31,9 @@ static const uint8_t RX = 41; static const uint8_t SDA = 47; static const uint8_t SCL = 48; -static const uint8_t SS = 45; +static const uint8_t SS = 45; static const uint8_t MOSI = 42; -static const uint8_t SCK = 39; +static const uint8_t SCK = 39; static const uint8_t MISO = 21; static const uint8_t A0 = 14; diff --git a/variants/adafruit_metro_esp32s3/variant.cpp b/variants/adafruit_metro_esp32s3/variant.cpp index 485f08b4aef..85b5870d2f1 100644 --- a/variants/adafruit_metro_esp32s3/variant.cpp +++ b/variants/adafruit_metro_esp32s3/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,11 +28,10 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) { - // default SD_CS to input pullup (we cannot have built in pullup since its - // a strapping pin!) - pinMode(SS, INPUT_PULLUP); -} - + // Initialize variant/board, called before setup() + void initVariant(void) { + // default SD_CS to input pullup (we cannot have built in pullup since its + // a strapping pin!) + pinMode(SS, INPUT_PULLUP); + } } diff --git a/variants/adafruit_qtpy_esp32/pins_arduino.h b/variants/adafruit_qtpy_esp32/pins_arduino.h index 40cad9f7005..49022a79a10 100644 --- a/variants/adafruit_qtpy_esp32/pins_arduino.h +++ b/variants/adafruit_qtpy_esp32/pins_arduino.h @@ -5,10 +5,10 @@ #include "soc/soc_caps.h" // Neopixel -#define PIN_NEOPIXEL 5 +#define PIN_NEOPIXEL 5 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() @@ -26,16 +26,16 @@ static const uint8_t RX = 7; static const uint8_t SDA = 4; static const uint8_t SCL = 33; -#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin) +#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin) static const uint8_t SDA1 = 22; static const uint8_t SCL1 = 19; -static const uint8_t SS = 27; -static const uint8_t MOSI = 13; -static const uint8_t MISO = 12; -static const uint8_t SCK = 14; +static const uint8_t SS = 27; +static const uint8_t MOSI = 13; +static const uint8_t MISO = 12; +static const uint8_t SCK = 14; -static const uint8_t A0 = 26; +static const uint8_t A0 = 26; static const uint8_t A1 = 25; static const uint8_t A2 = 27; static const uint8_t A3 = 15; diff --git a/variants/adafruit_qtpy_esp32/variant.cpp b/variants/adafruit_qtpy_esp32/variant.cpp index 726ec8fa483..ef1982107f4 100644 --- a/variants/adafruit_qtpy_esp32/variant.cpp +++ b/variants/adafruit_qtpy_esp32/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,13 +28,11 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - // This board has a power control pin, and we must set it to output and high - // in order to enable the NeoPixels. - pinMode(NEOPIXEL_POWER, OUTPUT); - digitalWrite(NEOPIXEL_POWER, HIGH); -} - + // Initialize variant/board, called before setup() + void initVariant(void) { + // This board has a power control pin, and we must set it to output and high + // in order to enable the NeoPixels. + pinMode(NEOPIXEL_POWER, OUTPUT); + digitalWrite(NEOPIXEL_POWER, HIGH); + } } diff --git a/variants/adafruit_qtpy_esp32c3/pins_arduino.h b/variants/adafruit_qtpy_esp32c3/pins_arduino.h index 6b50bbddbd0..c40e39e6c69 100644 --- a/variants/adafruit_qtpy_esp32c3/pins_arduino.h +++ b/variants/adafruit_qtpy_esp32c3/pins_arduino.h @@ -9,8 +9,8 @@ // Neopixel #define PIN_NEOPIXEL 2 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() @@ -23,10 +23,10 @@ static const uint8_t RX = 20; static const uint8_t SDA = 5; static const uint8_t SCL = 6; -static const uint8_t SS = 6; -static const uint8_t MOSI = 7; -static const uint8_t MISO = 8; -static const uint8_t SCK = 10; +static const uint8_t SS = 6; +static const uint8_t MOSI = 7; +static const uint8_t MISO = 8; +static const uint8_t SCK = 10; static const uint8_t A0 = 4; static const uint8_t A1 = 3; diff --git a/variants/adafruit_qtpy_esp32s2/pins_arduino.h b/variants/adafruit_qtpy_esp32s2/pins_arduino.h index aac8614875b..828e1d052d1 100644 --- a/variants/adafruit_qtpy_esp32s2/pins_arduino.h +++ b/variants/adafruit_qtpy_esp32s2/pins_arduino.h @@ -4,36 +4,36 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x239A -#define USB_PID 0x8111 -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "QT Py ESP32-S2" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x239A +#define USB_PID 0x8111 +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "QT Py ESP32-S2" +#define USB_SERIAL "" // Empty string for MAC address // Neopixel -#define PIN_NEOPIXEL 39 -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define PIN_NEOPIXEL 39 +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() -#define RGB_BUILTIN LED_BUILTIN +#define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 -#define NEOPIXEL_NUM 1 // number of neopixels -#define NEOPIXEL_POWER 38 // power pin -#define NEOPIXEL_POWER_ON HIGH // power pin state when on +#define NEOPIXEL_NUM 1 // number of neopixels +#define NEOPIXEL_POWER 38 // power pin +#define NEOPIXEL_POWER_ON HIGH // power pin state when on static const uint8_t SDA = 7; static const uint8_t SCL = 6; -#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin) +#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin) static const uint8_t SDA1 = 41; static const uint8_t SCL1 = 40; -static const uint8_t SS = 42; -static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; -static const uint8_t MISO = 37; +static const uint8_t SS = 42; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; static const uint8_t A0 = 18; static const uint8_t A1 = 17; diff --git a/variants/adafruit_qtpy_esp32s2/variant.cpp b/variants/adafruit_qtpy_esp32s2/variant.cpp index 726ec8fa483..ef1982107f4 100644 --- a/variants/adafruit_qtpy_esp32s2/variant.cpp +++ b/variants/adafruit_qtpy_esp32s2/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,13 +28,11 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - // This board has a power control pin, and we must set it to output and high - // in order to enable the NeoPixels. - pinMode(NEOPIXEL_POWER, OUTPUT); - digitalWrite(NEOPIXEL_POWER, HIGH); -} - + // Initialize variant/board, called before setup() + void initVariant(void) { + // This board has a power control pin, and we must set it to output and high + // in order to enable the NeoPixels. + pinMode(NEOPIXEL_POWER, OUTPUT); + digitalWrite(NEOPIXEL_POWER, HIGH); + } } diff --git a/variants/adafruit_qtpy_esp32s3_n4r2/pins_arduino.h b/variants/adafruit_qtpy_esp32s3_n4r2/pins_arduino.h index f4082c5cb2c..5328b1febd8 100644 --- a/variants/adafruit_qtpy_esp32s3_n4r2/pins_arduino.h +++ b/variants/adafruit_qtpy_esp32s3_n4r2/pins_arduino.h @@ -4,22 +4,22 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x239A -#define USB_PID 0x8143 -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "QT Py ESP32-S3 (4MB Flash 2MB PSRAM)" -#define USB_SERIAL "" // Empty string for MAC adddress - -#define PIN_NEOPIXEL 39 -#define NEOPIXEL_NUM 1 // number of neopixels -#define NEOPIXEL_POWER 38 // power pin -#define NEOPIXEL_POWER_ON HIGH // power pin state when on - -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define USB_VID 0x239A +#define USB_PID 0x8143 +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "QT Py ESP32-S3 (4MB Flash 2MB PSRAM)" +#define USB_SERIAL "" // Empty string for MAC address + +#define PIN_NEOPIXEL 39 +#define NEOPIXEL_NUM 1 // number of neopixels +#define NEOPIXEL_POWER 38 // power pin +#define NEOPIXEL_POWER_ON HIGH // power pin state when on + +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() -#define RGB_BUILTIN LED_BUILTIN +#define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 static const uint8_t TX = 5; @@ -30,14 +30,14 @@ static const uint8_t RX = 16; static const uint8_t SDA = 7; static const uint8_t SCL = 6; -#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin) +#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin) static const uint8_t SDA1 = 41; static const uint8_t SCL1 = 40; -static const uint8_t SS = 42; -static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; -static const uint8_t MISO = 37; +static const uint8_t SS = 42; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; static const uint8_t A0 = 18; static const uint8_t A1 = 17; diff --git a/variants/adafruit_qtpy_esp32s3_n4r2/variant.cpp b/variants/adafruit_qtpy_esp32s3_n4r2/variant.cpp index 5f7a3c0b55d..ef1982107f4 100644 --- a/variants/adafruit_qtpy_esp32s3_n4r2/variant.cpp +++ b/variants/adafruit_qtpy_esp32s3_n4r2/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,12 +28,11 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - // This board has a power control pin, and we must set it to output and high - // in order to enable the NeoPixels. - pinMode(NEOPIXEL_POWER, OUTPUT); - digitalWrite(NEOPIXEL_POWER, HIGH); -} + // Initialize variant/board, called before setup() + void initVariant(void) { + // This board has a power control pin, and we must set it to output and high + // in order to enable the NeoPixels. + pinMode(NEOPIXEL_POWER, OUTPUT); + digitalWrite(NEOPIXEL_POWER, HIGH); + } } diff --git a/variants/adafruit_qtpy_esp32s3_nopsram/pins_arduino.h b/variants/adafruit_qtpy_esp32s3_nopsram/pins_arduino.h index e8f4ab08130..d52dab6d8da 100644 --- a/variants/adafruit_qtpy_esp32s3_nopsram/pins_arduino.h +++ b/variants/adafruit_qtpy_esp32s3_nopsram/pins_arduino.h @@ -4,22 +4,22 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x239A -#define USB_PID 0x8119 -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "QT Py ESP32-S3 No PSRAM" -#define USB_SERIAL "" // Empty string for MAC adddress - -#define PIN_NEOPIXEL 39 -#define NEOPIXEL_NUM 1 // number of neopixels -#define NEOPIXEL_POWER 38 // power pin -#define NEOPIXEL_POWER_ON HIGH // power pin state when on - -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define USB_VID 0x239A +#define USB_PID 0x8119 +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "QT Py ESP32-S3 No PSRAM" +#define USB_SERIAL "" // Empty string for MAC address + +#define PIN_NEOPIXEL 39 +#define NEOPIXEL_NUM 1 // number of neopixels +#define NEOPIXEL_POWER 38 // power pin +#define NEOPIXEL_POWER_ON HIGH // power pin state when on + +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() -#define RGB_BUILTIN LED_BUILTIN +#define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 static const uint8_t TX = 5; @@ -30,14 +30,14 @@ static const uint8_t RX = 16; static const uint8_t SDA = 7; static const uint8_t SCL = 6; -#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin) +#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin) static const uint8_t SDA1 = 41; static const uint8_t SCL1 = 40; -static const uint8_t SS = 42; -static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; -static const uint8_t MISO = 37; +static const uint8_t SS = 42; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; static const uint8_t A0 = 18; static const uint8_t A1 = 17; diff --git a/variants/adafruit_qtpy_esp32s3_nopsram/variant.cpp b/variants/adafruit_qtpy_esp32s3_nopsram/variant.cpp index 5f7a3c0b55d..ef1982107f4 100644 --- a/variants/adafruit_qtpy_esp32s3_nopsram/variant.cpp +++ b/variants/adafruit_qtpy_esp32s3_nopsram/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,12 +28,11 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - // This board has a power control pin, and we must set it to output and high - // in order to enable the NeoPixels. - pinMode(NEOPIXEL_POWER, OUTPUT); - digitalWrite(NEOPIXEL_POWER, HIGH); -} + // Initialize variant/board, called before setup() + void initVariant(void) { + // This board has a power control pin, and we must set it to output and high + // in order to enable the NeoPixels. + pinMode(NEOPIXEL_POWER, OUTPUT); + digitalWrite(NEOPIXEL_POWER, HIGH); + } } diff --git a/variants/adafruit_qualia_s3_rgb666/pins_arduino.h b/variants/adafruit_qualia_s3_rgb666/pins_arduino.h index 62f04d1a620..f9158e17a47 100644 --- a/variants/adafruit_qualia_s3_rgb666/pins_arduino.h +++ b/variants/adafruit_qualia_s3_rgb666/pins_arduino.h @@ -3,12 +3,12 @@ #include -#define USB_VID 0x239A -#define USB_PID 0x8147 +#define USB_VID 0x239A +#define USB_PID 0x8147 -#define USB_MANUFACTURER "Adafruit" -#define USB_PRODUCT "Qualia ESP32-S3 RGB666" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_MANUFACTURER "Adafruit" +#define USB_PRODUCT "Qualia ESP32-S3 RGB666" +#define USB_SERIAL "" // Empty string for MAC address static const uint8_t PCA_TFT_SCK = 0; static const uint8_t PCA_TFT_CS = 1; @@ -27,41 +27,41 @@ static const uint8_t RX = 17; static const uint8_t SDA = 8; static const uint8_t SCL = 18; -static const uint8_t SS = 15; +static const uint8_t SS = 15; static const uint8_t MOSI = 7; static const uint8_t MISO = 6; -static const uint8_t SCK = 5; +static const uint8_t SCK = 5; static const uint8_t A0 = 17; static const uint8_t A1 = 16; -static const uint8_t T3 = 3; // Touch pin IDs map directly -static const uint8_t T8 = 8; // to underlying GPIO numbers NOT -static const uint8_t T9 = 9; // the analog numbers on board silk +static const uint8_t T3 = 3; // Touch pin IDs map directly +static const uint8_t T8 = 8; // to underlying GPIO numbers NOT +static const uint8_t T9 = 9; // the analog numbers on board silk static const uint8_t T10 = 10; static const uint8_t T11 = 11; static const uint8_t T12 = 12; - static const uint8_t TFT_R1 = 11; - static const uint8_t TFT_R2 = 10; - static const uint8_t TFT_R3 = 9; - static const uint8_t TFT_R4 = 46; - static const uint8_t TFT_R5 = 3; - static const uint8_t TFT_G0 = 48; - static const uint8_t TFT_G1 = 47; - static const uint8_t TFT_G2 = 21; - static const uint8_t TFT_G3 = 14; - static const uint8_t TFT_G4 = 13; - static const uint8_t TFT_G5 = 12; - static const uint8_t TFT_B1 = 40; - static const uint8_t TFT_B2 = 39; - static const uint8_t TFT_B3 = 38; - static const uint8_t TFT_B4 = 0; - static const uint8_t TFT_B5 = 45; - static const uint8_t TFT_PCLK = 1; - static const uint8_t TFT_DE = 2; - static const uint8_t TFT_HSYNC = 41; - static const uint8_t TFT_VSYNC = 42; +static const uint8_t TFT_R1 = 11; +static const uint8_t TFT_R2 = 10; +static const uint8_t TFT_R3 = 9; +static const uint8_t TFT_R4 = 46; +static const uint8_t TFT_R5 = 3; +static const uint8_t TFT_G0 = 48; +static const uint8_t TFT_G1 = 47; +static const uint8_t TFT_G2 = 21; +static const uint8_t TFT_G3 = 14; +static const uint8_t TFT_G4 = 13; +static const uint8_t TFT_G5 = 12; +static const uint8_t TFT_B1 = 40; +static const uint8_t TFT_B2 = 39; +static const uint8_t TFT_B3 = 38; +static const uint8_t TFT_B4 = 0; +static const uint8_t TFT_B5 = 45; +static const uint8_t TFT_PCLK = 1; +static const uint8_t TFT_DE = 2; +static const uint8_t TFT_HSYNC = 41; +static const uint8_t TFT_VSYNC = 42; #endif /* Pins_Arduino_h */ diff --git a/variants/adafruit_qualia_s3_rgb666/variant.cpp b/variants/adafruit_qualia_s3_rgb666/variant.cpp index 811a6d508c9..540b15fc96a 100644 --- a/variants/adafruit_qualia_s3_rgb666/variant.cpp +++ b/variants/adafruit_qualia_s3_rgb666/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,10 +28,9 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) { - // default SD_CS to input pullup - pinMode(SS, INPUT_PULLUP); -} - + // Initialize variant/board, called before setup() + void initVariant(void) { + // default SD_CS to input pullup + pinMode(SS, INPUT_PULLUP); + } } diff --git a/variants/alksesp32/pins_arduino.h b/variants/alksesp32/pins_arduino.h index 79e4b0791e4..95238aae6e4 100644 --- a/variants/alksesp32/pins_arduino.h +++ b/variants/alksesp32/pins_arduino.h @@ -3,10 +3,10 @@ #include -#define ALKSESP32 // tell library to not map pins again +#define ALKSESP32 // tell library to not map pins again static const uint8_t LED_BUILTIN = 23; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -67,10 +67,10 @@ static const uint8_t S5 = 21; static const uint8_t SDA = 27; static const uint8_t SCL = 14; -static const uint8_t SS = 19; -static const uint8_t MOSI = 21; -static const uint8_t MISO = 22; -static const uint8_t SCK = 23; +static const uint8_t SS = 19; +static const uint8_t MOSI = 21; +static const uint8_t MISO = 22; +static const uint8_t SCK = 23; static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; diff --git a/variants/arduino_nano_nora/dfu_callbacks.cpp b/variants/arduino_nano_nora/dfu_callbacks.cpp index 3695db80ba6..b825b92274a 100644 --- a/variants/arduino_nano_nora/dfu_callbacks.cpp +++ b/variants/arduino_nano_nora/dfu_callbacks.cpp @@ -14,103 +14,91 @@ namespace { #pragma GCC diagnostic pop } -#define ALT_COUNT 1 +#define ALT_COUNT 1 //--------------------------------------------------------------------+ // DFU callbacks // Note: alt is used as the partition number, in order to support multiple partitions like FLASH, EEPROM, etc. //--------------------------------------------------------------------+ -uint16_t load_dfu_ota_descriptor(uint8_t * dst, uint8_t * itf) -{ +uint16_t load_dfu_ota_descriptor(uint8_t* dst, uint8_t* itf) { #define DFU_ATTRS (DFU_ATTR_CAN_DOWNLOAD | DFU_ATTR_CAN_UPLOAD | DFU_ATTR_MANIFESTATION_TOLERANT) - uint8_t str_index = tinyusb_add_string_descriptor("Arduino DFU"); - uint8_t descriptor[TUD_DFU_DESC_LEN(ALT_COUNT)] = { - // Interface number, string index, attributes, detach timeout, transfer size */ - TUD_DFU_DESCRIPTOR(*itf, ALT_COUNT, str_index, DFU_ATTRS, 100, CFG_TUD_DFU_XFER_BUFSIZE), - }; - *itf+=1; - memcpy(dst, descriptor, TUD_DFU_DESC_LEN(ALT_COUNT)); - return TUD_DFU_DESC_LEN(ALT_COUNT); + uint8_t str_index = tinyusb_add_string_descriptor("Arduino DFU"); + uint8_t descriptor[TUD_DFU_DESC_LEN(ALT_COUNT)] = { + // Interface number, string index, attributes, detach timeout, transfer size */ + TUD_DFU_DESCRIPTOR(*itf, ALT_COUNT, str_index, DFU_ATTRS, 100, CFG_TUD_DFU_XFER_BUFSIZE), + }; + *itf += 1; + memcpy(dst, descriptor, TUD_DFU_DESC_LEN(ALT_COUNT)); + return TUD_DFU_DESC_LEN(ALT_COUNT); } // Invoked right before tud_dfu_download_cb() (state=DFU_DNBUSY) or tud_dfu_manifest_cb() (state=DFU_MANIFEST) // Application return timeout in milliseconds (bwPollTimeout) for the next download/manifest operation. // During this period, USB host won't try to communicate with us. -uint32_t tud_dfu_get_timeout_cb(uint8_t alt, uint8_t state) -{ - if ( state == DFU_DNBUSY ) - { - // longest delay for Flash writing - return 10; - } - else if (state == DFU_MANIFEST) - { - // time for esp32_ota_set_boot_partition to check final image - return 100; - } - - return 0; +uint32_t tud_dfu_get_timeout_cb(uint8_t alt, uint8_t state) { + if (state == DFU_DNBUSY) { + // longest delay for Flash writing + return 10; + } else if (state == DFU_MANIFEST) { + // time for esp32_ota_set_boot_partition to check final image + return 100; + } + + return 0; } // Invoked when received DFU_DNLOAD (wLength>0) following by DFU_GETSTATUS (state=DFU_DNBUSY) requests // This callback could be returned before flashing op is complete (async). // Once finished flashing, application must call tud_dfu_finish_flashing() -void tud_dfu_download_cb(uint8_t alt, uint16_t block_num, uint8_t const* data, uint16_t length) -{ - if (!Update.isRunning()) - { - // this is the first data block, start update if possible - if (!Update.begin()) - { - tud_dfu_finish_flashing(DFU_STATUS_ERR_TARGET); - return; - } +void tud_dfu_download_cb(uint8_t alt, uint16_t block_num, uint8_t const* data, uint16_t length) { + if (!Update.isRunning()) { + // this is the first data block, start update if possible + if (!Update.begin()) { + tud_dfu_finish_flashing(DFU_STATUS_ERR_TARGET); + return; } + } - // write a block of data to Flash - // XXX: Update API is needlessly non-const - size_t written = Update.write(const_cast(data), length); - tud_dfu_finish_flashing((written == length) ? DFU_STATUS_OK : DFU_STATUS_ERR_WRITE); + // write a block of data to Flash + // XXX: Update API is needlessly non-const + size_t written = Update.write(const_cast(data), length); + tud_dfu_finish_flashing((written == length) ? DFU_STATUS_OK : DFU_STATUS_ERR_WRITE); } // Invoked when download process is complete, received DFU_DNLOAD (wLength=0) following by DFU_GETSTATUS (state=Manifest) // Application can do checksum, or actual flashing if buffered entire image previously. // Once finished flashing, application must call tud_dfu_finish_flashing() -void tud_dfu_manifest_cb(uint8_t alt) -{ - (void) alt; - bool ok = Update.end(true); +void tud_dfu_manifest_cb(uint8_t alt) { + (void)alt; + bool ok = Update.end(true); - // flashing op for manifest is complete - tud_dfu_finish_flashing(ok? DFU_STATUS_OK : DFU_STATUS_ERR_VERIFY); + // flashing op for manifest is complete + tud_dfu_finish_flashing(ok ? DFU_STATUS_OK : DFU_STATUS_ERR_VERIFY); } // Invoked when received DFU_UPLOAD request // Application must populate data with up to length bytes and // Return the number of written bytes -uint16_t tud_dfu_upload_cb(uint8_t alt, uint16_t block_num, uint8_t* data, uint16_t length) -{ - (void) alt; - (void) block_num; - (void) data; - (void) length; - - // not implemented - return 0; +uint16_t tud_dfu_upload_cb(uint8_t alt, uint16_t block_num, uint8_t* data, uint16_t length) { + (void)alt; + (void)block_num; + (void)data; + (void)length; + + // not implemented + return 0; } // Invoked when the Host has terminated a download or upload transfer -void tud_dfu_abort_cb(uint8_t alt) -{ - (void) alt; - // ignore +void tud_dfu_abort_cb(uint8_t alt) { + (void)alt; + // ignore } // Invoked when a DFU_DETACH request is received -void tud_dfu_detach_cb(void) -{ - // done, reboot - esp_restart(); +void tud_dfu_detach_cb(void) { + // done, reboot + esp_restart(); } diff --git a/variants/arduino_nano_nora/double_tap.c b/variants/arduino_nano_nora/double_tap.c index b98d5dded64..a06ad220056 100644 --- a/variants/arduino_nano_nora/double_tap.c +++ b/variants/arduino_nano_nora/double_tap.c @@ -8,7 +8,9 @@ #define NUM_TOKENS 3 static const uint32_t MAGIC_TOKENS[NUM_TOKENS] = { - 0xf01681de, 0xbd729b29, 0xd359be7a, + 0xf01681de, + 0xbd729b29, + 0xd359be7a, }; static void *magic_area; @@ -21,48 +23,48 @@ static uint32_t backup_area[NUM_TOKENS]; #include #include static uintptr_t get_extram_data_high(void) { - // get a pointer into SRAM area (only the address is useful) - void *psram_ptr = heap_caps_malloc(16, MALLOC_CAP_SPIRAM); - heap_caps_free(psram_ptr); + // get a pointer into SRAM area (only the address is useful) + void *psram_ptr = heap_caps_malloc(16, MALLOC_CAP_SPIRAM); + heap_caps_free(psram_ptr); - // keep moving backwards until leaving PSRAM area - uintptr_t psram_base_addr = (uintptr_t) psram_ptr; - psram_base_addr &= ~(CONFIG_MMU_PAGE_SIZE - 1); // align to start of page - while (esp_psram_check_ptr_addr((void *) psram_base_addr)) { - psram_base_addr -= CONFIG_MMU_PAGE_SIZE; - } + // keep moving backwards until leaving PSRAM area + uintptr_t psram_base_addr = (uintptr_t)psram_ptr; + psram_base_addr &= ~(CONFIG_MMU_PAGE_SIZE - 1); // align to start of page + while (esp_psram_check_ptr_addr((void *)psram_base_addr)) { + psram_base_addr -= CONFIG_MMU_PAGE_SIZE; + } - // offset is one page from start of PSRAM - return psram_base_addr + CONFIG_MMU_PAGE_SIZE + esp_psram_get_size(); + // offset is one page from start of PSRAM + return psram_base_addr + CONFIG_MMU_PAGE_SIZE + esp_psram_get_size(); } #else #include -#define get_extram_data_high() ((uintptr_t) SOC_EXTRAM_DATA_HIGH) +#define get_extram_data_high() ((uintptr_t)SOC_EXTRAM_DATA_HIGH) #endif void double_tap_init(void) { - // magic location block ends 0x20 bytes from end of PSRAM - magic_area = (void *) (get_extram_data_high() - 0x20 - sizeof(MAGIC_TOKENS)); + // magic location block ends 0x20 bytes from end of PSRAM + magic_area = (void *)(get_extram_data_high() - 0x20 - sizeof(MAGIC_TOKENS)); } void double_tap_mark() { - memcpy(backup_area, magic_area, sizeof(MAGIC_TOKENS)); - memcpy(magic_area, MAGIC_TOKENS, sizeof(MAGIC_TOKENS)); - Cache_WriteBack_Addr((uintptr_t) magic_area, sizeof(MAGIC_TOKENS)); + memcpy(backup_area, magic_area, sizeof(MAGIC_TOKENS)); + memcpy(magic_area, MAGIC_TOKENS, sizeof(MAGIC_TOKENS)); + Cache_WriteBack_Addr((uintptr_t)magic_area, sizeof(MAGIC_TOKENS)); } void double_tap_invalidate() { - if (memcmp(backup_area, MAGIC_TOKENS, sizeof(MAGIC_TOKENS))) { - // different contents: restore backup - memcpy(magic_area, backup_area, sizeof(MAGIC_TOKENS)); - } else { - // clear memory - memset(magic_area, 0, sizeof(MAGIC_TOKENS)); - } - Cache_WriteBack_Addr((uintptr_t) magic_area, sizeof(MAGIC_TOKENS)); + if (memcmp(backup_area, MAGIC_TOKENS, sizeof(MAGIC_TOKENS))) { + // different contents: restore backup + memcpy(magic_area, backup_area, sizeof(MAGIC_TOKENS)); + } else { + // clear memory + memset(magic_area, 0, sizeof(MAGIC_TOKENS)); + } + Cache_WriteBack_Addr((uintptr_t)magic_area, sizeof(MAGIC_TOKENS)); } bool double_tap_check_match() { - return (memcmp(magic_area, MAGIC_TOKENS, sizeof(MAGIC_TOKENS)) == 0); + return (memcmp(magic_area, MAGIC_TOKENS, sizeof(MAGIC_TOKENS)) == 0); } diff --git a/variants/arduino_nano_nora/double_tap.h b/variants/arduino_nano_nora/double_tap.h index e797f4f64fd..29da301a5b9 100644 --- a/variants/arduino_nano_nora/double_tap.h +++ b/variants/arduino_nano_nora/double_tap.h @@ -8,10 +8,10 @@ extern "C" { #endif -void double_tap_init(void); -void double_tap_mark(void); -void double_tap_invalidate(void); -bool double_tap_check_match(void); + void double_tap_init(void); + void double_tap_mark(void); + void double_tap_invalidate(void); + bool double_tap_check_match(void); #ifdef __cplusplus } diff --git a/variants/arduino_nano_nora/extra/nora_recovery/nora_recovery.ino b/variants/arduino_nano_nora/extra/nora_recovery/nora_recovery.ino index e8ec998d9ab..d47501f9df5 100644 --- a/variants/arduino_nano_nora/extra/nora_recovery/nora_recovery.ino +++ b/variants/arduino_nano_nora/extra/nora_recovery/nora_recovery.ino @@ -5,24 +5,24 @@ #define FADESTEP 8 void pulse_led() { - static uint32_t pulse_width = 0; - static uint8_t dir = 0; + static uint32_t pulse_width = 0; + static uint8_t dir = 0; - if (dir) { - pulse_width -= FADESTEP; - if (pulse_width < FADESTEP) { - dir = 0U; - pulse_width = FADESTEP; - } - } else { - pulse_width += FADESTEP; - if (pulse_width > 255) { - dir = 1U; - pulse_width = 255; - } - } + if (dir) { + pulse_width -= FADESTEP; + if (pulse_width < FADESTEP) { + dir = 0U; + pulse_width = FADESTEP; + } + } else { + pulse_width += FADESTEP; + if (pulse_width > 255) { + dir = 1U; + pulse_width = 255; + } + } - analogWrite(LED_GREEN, pulse_width); + analogWrite(LED_GREEN, pulse_width); } #include @@ -30,70 +30,70 @@ void pulse_led() { #include #include const esp_partition_t *find_previous_firmware() { - extern bool _recovery_active; - if (!_recovery_active) { - // user flashed this recovery sketch to an OTA partition - // stay here and wait for a proper firmware - return NULL; - } + extern bool _recovery_active; + if (!_recovery_active) { + // user flashed this recovery sketch to an OTA partition + // stay here and wait for a proper firmware + return NULL; + } - // booting from factory partition, look for a valid OTA image - esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, NULL); - for (; it != NULL; it = esp_partition_next(it)) { - const esp_partition_t *part = esp_partition_get(it); - if (part->subtype != ESP_PARTITION_SUBTYPE_APP_FACTORY) { - esp_partition_pos_t candidate = { part->address, part->size }; - esp_image_metadata_t meta; - if (esp_image_verify(ESP_IMAGE_VERIFY_SILENT, &candidate, &meta) == ESP_OK) { - // found, use it - return part; - } - } - } + // booting from factory partition, look for a valid OTA image + esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, NULL); + for (; it != NULL; it = esp_partition_next(it)) { + const esp_partition_t *part = esp_partition_get(it); + if (part->subtype != ESP_PARTITION_SUBTYPE_APP_FACTORY) { + esp_partition_pos_t candidate = { part->address, part->size }; + esp_image_metadata_t meta; + if (esp_image_verify(ESP_IMAGE_VERIFY_SILENT, &candidate, &meta) == ESP_OK) { + // found, use it + return part; + } + } + } - return NULL; + return NULL; } const esp_partition_t *user_part = NULL; void setup() { - user_part = find_previous_firmware(); - if (user_part) - esp_ota_set_boot_partition(user_part); + user_part = find_previous_firmware(); + if (user_part) + esp_ota_set_boot_partition(user_part); - extern bool _recovery_marker_found; - if (!_recovery_marker_found && user_part) { - // recovery marker not found, probable cold start - // try starting previous firmware immediately - esp_restart(); - } + extern bool _recovery_marker_found; + if (!_recovery_marker_found && user_part) { + // recovery marker not found, probable cold start + // try starting previous firmware immediately + esp_restart(); + } - // recovery marker found, or nothing else to load - printf("Recovery firmware started, waiting for USB\r\n"); + // recovery marker found, or nothing else to load + printf("Recovery firmware started, waiting for USB\r\n"); } void loop() { - static int elapsed_ms = 0; + static int elapsed_ms = 0; - pulse_led(); - delay(POLL_DELAY_MS); - if (USB) { - // wait indefinitely for DFU to complete - elapsed_ms = 0; - } else { - // wait for USB connection - elapsed_ms += POLL_DELAY_MS; - } + pulse_led(); + delay(POLL_DELAY_MS); + if (USB) { + // wait indefinitely for DFU to complete + elapsed_ms = 0; + } else { + // wait for USB connection + elapsed_ms += POLL_DELAY_MS; + } - if (elapsed_ms > USB_TIMEOUT_MS) { - elapsed_ms = 0; - // timed out, try loading previous firmware - if (user_part) { - // there was a valid FW image, load it - analogWrite(LED_GREEN, 255); - printf("Leaving recovery firmware\r\n"); - delay(200); - esp_restart(); // does not return - } - } + if (elapsed_ms > USB_TIMEOUT_MS) { + elapsed_ms = 0; + // timed out, try loading previous firmware + if (user_part) { + // there was a valid FW image, load it + analogWrite(LED_GREEN, 255); + printf("Leaving recovery firmware\r\n"); + delay(200); + esp_restart(); // does not return + } + } } diff --git a/variants/arduino_nano_nora/io_pin_remap.cpp b/variants/arduino_nano_nora/io_pin_remap.cpp index 1ff3a7a45c4..7bbd2728128 100644 --- a/variants/arduino_nano_nora/io_pin_remap.cpp +++ b/variants/arduino_nano_nora/io_pin_remap.cpp @@ -18,55 +18,53 @@ // NOTE: This must match with the remapped pin sequence in pins_arduino.h static const int8_t TO_GPIO_NUMBER[] = { - 44, // [ 0] D0, RX - 43, // [ 1] D1, TX - 5, // [ 2] D2 - 6, // [ 3] D3, CTS - 7, // [ 4] D4, DSR - 8, // [ 5] D5 - 9, // [ 6] D6 - 10, // [ 7] D7 - 17, // [ 8] D8 - 18, // [ 9] D9 - 21, // [10] D10, SS - 38, // [11] D11, MOSI - 47, // [12] D12, MISO - 48, // [13] D13, SCK, LED_BUILTIN - 46, // [14] LED_RED - 0, // [15] LED_GREEN - 45, // [16] LED_BLUE, RTS - 1, // [17] A0, DTR - 2, // [18] A1 - 3, // [19] A2 - 4, // [20] A3 - 11, // [21] A4, SDA - 12, // [22] A5, SCL - 13, // [23] A6 - 14, // [24] A7 + 44, // [ 0] D0, RX + 43, // [ 1] D1, TX + 5, // [ 2] D2 + 6, // [ 3] D3, CTS + 7, // [ 4] D4, DSR + 8, // [ 5] D5 + 9, // [ 6] D6 + 10, // [ 7] D7 + 17, // [ 8] D8 + 18, // [ 9] D9 + 21, // [10] D10, SS + 38, // [11] D11, MOSI + 47, // [12] D12, MISO + 48, // [13] D13, SCK, LED_BUILTIN + 46, // [14] LED_RED + 0, // [15] LED_GREEN + 45, // [16] LED_BLUE, RTS + 1, // [17] A0, DTR + 2, // [18] A1 + 3, // [19] A2 + 4, // [20] A3 + 11, // [21] A4, SDA + 12, // [22] A5, SCL + 13, // [23] A6 + 14, // [24] A7 }; #if defined(BOARD_HAS_PIN_REMAP) && !defined(BOARD_USES_HW_GPIO_NUMBERS) -int8_t digitalPinToGPIONumber(int8_t digitalPin) -{ - if ((digitalPin < 0) || (digitalPin >= NUM_DIGITAL_PINS)) - return -1; - return TO_GPIO_NUMBER[digitalPin]; +int8_t digitalPinToGPIONumber(int8_t digitalPin) { + if ((digitalPin < 0) || (digitalPin >= NUM_DIGITAL_PINS)) + return -1; + return TO_GPIO_NUMBER[digitalPin]; } -int8_t gpioNumberToDigitalPin(int8_t gpioNumber) -{ - if (gpioNumber < 0) - return -1; +int8_t gpioNumberToDigitalPin(int8_t gpioNumber) { + if (gpioNumber < 0) + return -1; - // slow linear table lookup - for (int8_t digitalPin = 0; digitalPin < NUM_DIGITAL_PINS; ++digitalPin) { - if (TO_GPIO_NUMBER[digitalPin] == gpioNumber) - return digitalPin; - } + // slow linear table lookup + for (int8_t digitalPin = 0; digitalPin < NUM_DIGITAL_PINS; ++digitalPin) { + if (TO_GPIO_NUMBER[digitalPin] == gpioNumber) + return digitalPin; + } - // not found - return -1; + // not found + return -1; } #endif diff --git a/variants/arduino_nano_nora/pins_arduino.h b/variants/arduino_nano_nora/pins_arduino.h index e1d0f6aa9af..489f2baa84a 100644 --- a/variants/arduino_nano_nora/pins_arduino.h +++ b/variants/arduino_nano_nora/pins_arduino.h @@ -16,63 +16,63 @@ // Arduino style definitions (API uses Dx) -static constexpr uint8_t D0 = 0; // also RX -static constexpr uint8_t D1 = 1; // also TX -static constexpr uint8_t D2 = 2; -static constexpr uint8_t D3 = 3; // also CTS -static constexpr uint8_t D4 = 4; // also DSR -static constexpr uint8_t D5 = 5; -static constexpr uint8_t D6 = 6; -static constexpr uint8_t D7 = 7; -static constexpr uint8_t D8 = 8; -static constexpr uint8_t D9 = 9; -static constexpr uint8_t D10 = 10; // also SS -static constexpr uint8_t D11 = 11; // also MOSI -static constexpr uint8_t D12 = 12; // also MISO -static constexpr uint8_t D13 = 13; // also SCK, LED_BUILTIN -static constexpr uint8_t LED_RED = 14; -static constexpr uint8_t LED_GREEN = 15; -static constexpr uint8_t LED_BLUE = 16; // also RTS - -static constexpr uint8_t A0 = 17; // also DTR -static constexpr uint8_t A1 = 18; -static constexpr uint8_t A2 = 19; -static constexpr uint8_t A3 = 20; -static constexpr uint8_t A4 = 21; // also SDA -static constexpr uint8_t A5 = 22; // also SCL -static constexpr uint8_t A6 = 23; -static constexpr uint8_t A7 = 24; +static constexpr uint8_t D0 = 0; // also RX +static constexpr uint8_t D1 = 1; // also TX +static constexpr uint8_t D2 = 2; +static constexpr uint8_t D3 = 3; // also CTS +static constexpr uint8_t D4 = 4; // also DSR +static constexpr uint8_t D5 = 5; +static constexpr uint8_t D6 = 6; +static constexpr uint8_t D7 = 7; +static constexpr uint8_t D8 = 8; +static constexpr uint8_t D9 = 9; +static constexpr uint8_t D10 = 10; // also SS +static constexpr uint8_t D11 = 11; // also MOSI +static constexpr uint8_t D12 = 12; // also MISO +static constexpr uint8_t D13 = 13; // also SCK, LED_BUILTIN +static constexpr uint8_t LED_RED = 14; +static constexpr uint8_t LED_GREEN = 15; +static constexpr uint8_t LED_BLUE = 16; // also RTS + +static constexpr uint8_t A0 = 17; // also DTR +static constexpr uint8_t A1 = 18; +static constexpr uint8_t A2 = 19; +static constexpr uint8_t A3 = 20; +static constexpr uint8_t A4 = 21; // also SDA +static constexpr uint8_t A5 = 22; // also SCL +static constexpr uint8_t A6 = 23; +static constexpr uint8_t A7 = 24; #else // ESP32-style definitions (API uses GPIOx) -static constexpr uint8_t D0 = 44; // also RX -static constexpr uint8_t D1 = 43; // also TX -static constexpr uint8_t D2 = 5; -static constexpr uint8_t D3 = 6; // also CTS -static constexpr uint8_t D4 = 7; // also DSR -static constexpr uint8_t D5 = 8; -static constexpr uint8_t D6 = 9; -static constexpr uint8_t D7 = 10; -static constexpr uint8_t D8 = 17; -static constexpr uint8_t D9 = 18; -static constexpr uint8_t D10 = 21; // also SS -static constexpr uint8_t D11 = 38; // also MOSI -static constexpr uint8_t D12 = 47; // also MISO -static constexpr uint8_t D13 = 48; // also SCK, LED_BUILTIN -static constexpr uint8_t LED_RED = 46; -static constexpr uint8_t LED_GREEN = 0; -static constexpr uint8_t LED_BLUE = 45; // also RTS - -static constexpr uint8_t A0 = 1; // also DTR -static constexpr uint8_t A1 = 2; -static constexpr uint8_t A2 = 3; -static constexpr uint8_t A3 = 4; -static constexpr uint8_t A4 = 11; // also SDA -static constexpr uint8_t A5 = 12; // also SCL -static constexpr uint8_t A6 = 13; -static constexpr uint8_t A7 = 14; +static constexpr uint8_t D0 = 44; // also RX +static constexpr uint8_t D1 = 43; // also TX +static constexpr uint8_t D2 = 5; +static constexpr uint8_t D3 = 6; // also CTS +static constexpr uint8_t D4 = 7; // also DSR +static constexpr uint8_t D5 = 8; +static constexpr uint8_t D6 = 9; +static constexpr uint8_t D7 = 10; +static constexpr uint8_t D8 = 17; +static constexpr uint8_t D9 = 18; +static constexpr uint8_t D10 = 21; // also SS +static constexpr uint8_t D11 = 38; // also MOSI +static constexpr uint8_t D12 = 47; // also MISO +static constexpr uint8_t D13 = 48; // also SCK, LED_BUILTIN +static constexpr uint8_t LED_RED = 46; +static constexpr uint8_t LED_GREEN = 0; +static constexpr uint8_t LED_BLUE = 45; // also RTS + +static constexpr uint8_t A0 = 1; // also DTR +static constexpr uint8_t A1 = 2; +static constexpr uint8_t A2 = 3; +static constexpr uint8_t A3 = 4; +static constexpr uint8_t A4 = 11; // also SDA +static constexpr uint8_t A5 = 12; // also SCL +static constexpr uint8_t A6 = 13; +static constexpr uint8_t A7 = 14; #endif @@ -86,26 +86,26 @@ static constexpr uint8_t LEDB = LED_BLUE; static constexpr uint8_t LED_BUILTIN = D13; -static constexpr uint8_t TX = D1; -static constexpr uint8_t RX = D0; -static constexpr uint8_t RTS = LED_BLUE; -static constexpr uint8_t CTS = D3; -static constexpr uint8_t DTR = A0; -static constexpr uint8_t DSR = D4; +static constexpr uint8_t TX = D1; +static constexpr uint8_t RX = D0; +static constexpr uint8_t RTS = LED_BLUE; +static constexpr uint8_t CTS = D3; +static constexpr uint8_t DTR = A0; +static constexpr uint8_t DSR = D4; -static constexpr uint8_t SS = D10; +static constexpr uint8_t SS = D10; static constexpr uint8_t MOSI = D11; static constexpr uint8_t MISO = D12; -static constexpr uint8_t SCK = D13; +static constexpr uint8_t SCK = D13; -static constexpr uint8_t SDA = A4; -static constexpr uint8_t SCL = A5; +static constexpr uint8_t SDA = A4; +static constexpr uint8_t SCL = A5; -#define PIN_I2S_SCK D7 -#define PIN_I2S_FS D8 -#define PIN_I2S_SD D9 -#define PIN_I2S_SD_OUT D9 // same as bidir -#define PIN_I2S_SD_IN D10 +#define PIN_I2S_SCK D7 +#define PIN_I2S_FS D8 +#define PIN_I2S_SD D9 +#define PIN_I2S_SD_OUT D9 // same as bidir +#define PIN_I2S_SD_IN D10 #ifndef __cplusplus #undef constexpr diff --git a/variants/arduino_nano_nora/variant.cpp b/variants/arduino_nano_nora/variant.cpp index cfdd503d949..3f65982f23b 100644 --- a/variants/arduino_nano_nora/variant.cpp +++ b/variants/arduino_nano_nora/variant.cpp @@ -10,95 +10,92 @@ #include extern "C" { - void initVariant() { - // nothing to do - } + void initVariant() { + // nothing to do + } } // global, accessible from recovery sketch -bool _recovery_marker_found; // double tap detected -bool _recovery_active; // running from factory partition +bool _recovery_marker_found; // double tap detected +bool _recovery_active; // running from factory partition #define DELAY_US 10000 #define FADESTEP 8 -static void rgb_pulse_delay(void) -{ - // Bv R^ G x - int widths[4] = { 192, 64, 0, 0 }; - int dec_led = 0; - - // initialize RGB signals from weak pinstraps - pinMode(LED_RED, OUTPUT); - pinMode(LED_GREEN, OUTPUT); - pinMode(LED_BLUE, OUTPUT); - while (dec_led < 3) { - widths[dec_led] -= FADESTEP; - widths[dec_led+1] += FADESTEP; - if (widths[dec_led] <= 0) { - widths[dec_led] = 0; - dec_led = dec_led+1; - widths[dec_led] = 255; - } - - analogWrite(LED_RED, 255-widths[1]); - analogWrite(LED_GREEN, 255-widths[2]); - analogWrite(LED_BLUE, 255-widths[0]); - delayMicroseconds(DELAY_US); +static void rgb_pulse_delay(void) { + // Bv R^ G x + int widths[4] = { 192, 64, 0, 0 }; + int dec_led = 0; + + // initialize RGB signals from weak pinstraps + pinMode(LED_RED, OUTPUT); + pinMode(LED_GREEN, OUTPUT); + pinMode(LED_BLUE, OUTPUT); + while (dec_led < 3) { + widths[dec_led] -= FADESTEP; + widths[dec_led + 1] += FADESTEP; + if (widths[dec_led] <= 0) { + widths[dec_led] = 0; + dec_led = dec_led + 1; + widths[dec_led] = 255; } - // reset pins to digital HIGH before leaving - digitalWrite(LED_RED, HIGH); - digitalWrite(LED_GREEN, HIGH); - digitalWrite(LED_BLUE, HIGH); + analogWrite(LED_RED, 255 - widths[1]); + analogWrite(LED_GREEN, 255 - widths[2]); + analogWrite(LED_BLUE, 255 - widths[0]); + delayMicroseconds(DELAY_US); + } + + // reset pins to digital HIGH before leaving + digitalWrite(LED_RED, HIGH); + digitalWrite(LED_GREEN, HIGH); + digitalWrite(LED_BLUE, HIGH); } -static void NANO_ESP32_enter_bootloader(void) -{ - if (!_recovery_active) { - // check for valid partition scheme - const esp_partition_t *ota_part = esp_ota_get_next_update_partition(NULL); - const esp_partition_t *fact_part = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL); - if (ota_part && fact_part) { - // set tokens so the recovery FW will find them - double_tap_mark(); - // invalidate other OTA image - esp_partition_erase_range(ota_part, 0, 4096); - // activate factory partition - esp_ota_set_boot_partition(fact_part); - } +static void NANO_ESP32_enter_bootloader(void) { + if (!_recovery_active) { + // check for valid partition scheme + const esp_partition_t *ota_part = esp_ota_get_next_update_partition(NULL); + const esp_partition_t *fact_part = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL); + if (ota_part && fact_part) { + // set tokens so the recovery FW will find them + double_tap_mark(); + // invalidate other OTA image + esp_partition_erase_range(ota_part, 0, 4096); + // activate factory partition + esp_ota_set_boot_partition(fact_part); } + } - esp_restart(); + esp_restart(); } -static void boot_double_tap_logic() -{ - const esp_partition_t *part = esp_ota_get_running_partition(); - _recovery_active = (part->subtype == ESP_PARTITION_SUBTYPE_APP_FACTORY); +static void boot_double_tap_logic() { + const esp_partition_t *part = esp_ota_get_running_partition(); + _recovery_active = (part->subtype == ESP_PARTITION_SUBTYPE_APP_FACTORY); - double_tap_init(); + double_tap_init(); - _recovery_marker_found = double_tap_check_match(); - if (_recovery_marker_found && !_recovery_active) { - // double tap detected in user application, reboot to factory - NANO_ESP32_enter_bootloader(); - } + _recovery_marker_found = double_tap_check_match(); + if (_recovery_marker_found && !_recovery_active) { + // double tap detected in user application, reboot to factory + NANO_ESP32_enter_bootloader(); + } - // delay with mark set then proceed - // - for normal startup, to detect first double tap - // - in recovery mode, to ignore several short presses - double_tap_mark(); - rgb_pulse_delay(); - double_tap_invalidate(); + // delay with mark set then proceed + // - for normal startup, to detect first double tap + // - in recovery mode, to ignore several short presses + double_tap_mark(); + rgb_pulse_delay(); + double_tap_invalidate(); } namespace { - class DoubleTap { - public: - DoubleTap() { - boot_double_tap_logic(); - } - }; - - DoubleTap dt __attribute__ ((init_priority (101))); +class DoubleTap { +public: + DoubleTap() { + boot_double_tap_logic(); + } +}; + +DoubleTap dt __attribute__((init_priority(101))); } diff --git a/variants/atd147_s3/pins_arduino.h b/variants/atd147_s3/pins_arduino.h index 0726a1c4a1c..f712cdd8c50 100644 --- a/variants/atd147_s3/pins_arduino.h +++ b/variants/atd147_s3/pins_arduino.h @@ -12,10 +12,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 10; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 13; -static const uint8_t SCK = 12; +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; #define LCD_CS SS #define LCD_SCK SCK diff --git a/variants/atmegazero_esp32s2/pins_arduino.h b/variants/atmegazero_esp32s2/pins_arduino.h index 45fd447331d..85675e0b616 100644 --- a/variants/atmegazero_esp32s2/pins_arduino.h +++ b/variants/atmegazero_esp32s2/pins_arduino.h @@ -13,7 +13,7 @@ static const uint8_t NEOPIXEL = 40; // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino static const uint8_t LED_BUILTIN = (NEOPIXEL + SOC_GPIO_PIN_COUNT); -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN @@ -27,10 +27,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 38; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 38; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 17; static const uint8_t A1 = 18; diff --git a/variants/bpi-bit/pins_arduino.h b/variants/bpi-bit/pins_arduino.h index 80ff9c2746b..b008f9f3c1e 100644 --- a/variants/bpi-bit/pins_arduino.h +++ b/variants/bpi-bit/pins_arduino.h @@ -13,8 +13,8 @@ static const uint8_t BUTTON_B = 27; static const uint8_t RGB_LED = 4; // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino -#define LED_BUILTIN (RGB_LED + SOC_GPIO_PIN_COUNT) // Just a single LED in the Matrix -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN (RGB_LED + SOC_GPIO_PIN_COUNT) // Just a single LED in the Matrix +#define BUILTIN_LED LED_BUILTIN // backward compatibility // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 diff --git a/variants/bpi_leaf_s3/pins_arduino.h b/variants/bpi_leaf_s3/pins_arduino.h index 45117347e2d..b00349136c8 100644 --- a/variants/bpi_leaf_s3/pins_arduino.h +++ b/variants/bpi_leaf_s3/pins_arduino.h @@ -15,8 +15,8 @@ // and change this setup for the chosen pin (for example 38) #define PIN_NEOPIXEL 48 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN @@ -28,10 +28,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 15; static const uint8_t SCL = 16; -static const uint8_t SS = 10; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 13; -static const uint8_t SCK = 12; +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/ch_denky/pins_arduino.h b/variants/ch_denky/pins_arduino.h index ac202d527db..a47ea587af9 100644 --- a/variants/ch_denky/pins_arduino.h +++ b/variants/ch_denky/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; @@ -47,24 +47,24 @@ static const uint8_t DAC2 = 26; // Specific CH2i (Charles Hallard) Boards // 1st Revision Denky with ESP WROOM32 + LoRa RN2483 module -#if defined (ARDUINO_DENKY_WROOM32) -#define PUSH_BUTTON 0 -#define TIC_ENABLE_PIN 4 -#define TIC_RX_PIN 33 -#define LORA_TX_PIN 26 -#define LORA_RX_PIN 27 -#define LORA_RESET 14 -#define RGB_LED_PIN 25 +#if defined(ARDUINO_DENKY_WROOM32) +#define PUSH_BUTTON 0 +#define TIC_ENABLE_PIN 4 +#define TIC_RX_PIN 33 +#define LORA_TX_PIN 26 +#define LORA_RX_PIN 27 +#define LORA_RESET 14 +#define RGB_LED_PIN 25 // 2nd Utra Small version with ESP Pico-D4-V3-02 -#elif defined (ARDUINO_DENKY_PICOV3) +#elif defined(ARDUINO_DENKY_PICOV3) // RGB Led Pins #define LED_RED_PIN 27 #define LED_GRN_PIN 26 #define LED_BLU_PIN 25 // Teleinfo RXD pin is connected to ESP32-PICO-V3-02 GPIO8 -#define TIC_RX_PIN 8 +#define TIC_RX_PIN 8 #endif diff --git a/variants/cnrs_aw2eth/pins_arduino.h b/variants/cnrs_aw2eth/pins_arduino.h index b21c5889a38..11b4ba8e38a 100644 --- a/variants/cnrs_aw2eth/pins_arduino.h +++ b/variants/cnrs_aw2eth/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 9; static const uint8_t SCL = 10; -static const uint8_t SS = 5; -static const uint8_t MOSI = 14; -static const uint8_t MISO = 13; -static const uint8_t SCK = 4; +static const uint8_t SS = 5; +static const uint8_t MOSI = 14; +static const uint8_t MISO = 13; +static const uint8_t SCK = 4; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/connaxio_espoir/pins_arduino.h b/variants/connaxio_espoir/pins_arduino.h index 6e9a4fa3ceb..189d32d885d 100644 --- a/variants/connaxio_espoir/pins_arduino.h +++ b/variants/connaxio_espoir/pins_arduino.h @@ -21,10 +21,10 @@ static const uint8_t SDA = 23; static const uint8_t SCL = 18; /* mikroBUS SPI */ -static const uint8_t SS = 15; +static const uint8_t SS = 15; static const uint8_t MOSI = 13; static const uint8_t MISO = 12; -static const uint8_t SCK = 14; +static const uint8_t SCK = 14; /* Default analog pins */ static const uint8_t A0 = 36; @@ -50,28 +50,28 @@ static const uint8_t T5 = 12; static const uint8_t T6 = 14; /* Other pin names */ -static const uint8_t AN = 36; +static const uint8_t AN = 36; static const uint8_t RST = 5; static const uint8_t PWM = 2; static const uint8_t INT = 4; -static const uint8_t CS = 15; +static const uint8_t CS = 15; static const uint8_t SDO = 13; static const uint8_t SDI = 12; /* Ethernet interface */ static const uint8_t ETH_INT = 35; -#define ETH_PHY_ADDR 0 +#define ETH_PHY_ADDR 0 #define ETH_PHY_POWER -1 -#define ETH_PHY_MDC 32 -#define ETH_PHY_MDIO 33 -#define ETH_PHY_TYPE ETH_PHY_KSZ8081 -#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN +#define ETH_PHY_MDC 32 +#define ETH_PHY_MDIO 33 +#define ETH_PHY_TYPE ETH_PHY_KSZ8081 +#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN /* USB interface */ -#define USB_VID 0x10C4 // Silabs's VID -#define USB_PID 0x8D9A // Espoir's PID, requires Silab USB PHY +#define USB_VID 0x10C4 // Silabs's VID +#define USB_PID 0x8D9A // Espoir's PID, requires Silab USB PHY #define USB_MANUFACTURER "Connaxio" -#define USB_PRODUCT "Espoir" -#define USB_SERIAL "" +#define USB_PRODUCT "Espoir" +#define USB_SERIAL "" #endif /* Pins_Arduino_h */ diff --git a/variants/crabik_slot_esp32_s3/pins_arduino.h b/variants/crabik_slot_esp32_s3/pins_arduino.h index b5021d5cd03..45c3a233b11 100644 --- a/variants/crabik_slot_esp32_s3/pins_arduino.h +++ b/variants/crabik_slot_esp32_s3/pins_arduino.h @@ -4,24 +4,24 @@ #include #define USB_VID 0x303a -#define USB_PID 0x814D // for user apps (https://github.com/espressif/usb-pids/pull/77) +#define USB_PID 0x814D // for user apps (https://github.com/espressif/usb-pids/pull/77) #define USB_MANUFACTURER "Crabik" #define USB_PRODUCT "Slot ESP32-S3" #define USB_SERIAL "" static const uint8_t LED_BUILTIN = 21; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -static const uint8_t S1 = 1; -static const uint8_t S2 = 12; -static const uint8_t S3 = 2; -static const uint8_t S4 = 11; -static const uint8_t S5 = 17; -static const uint8_t S6 = 18; -static const uint8_t S7 = 3; -static const uint8_t S8 = 4; -static const uint8_t S9 = 5; +static const uint8_t S1 = 1; +static const uint8_t S2 = 12; +static const uint8_t S3 = 2; +static const uint8_t S4 = 11; +static const uint8_t S5 = 17; +static const uint8_t S6 = 18; +static const uint8_t S7 = 3; +static const uint8_t S8 = 4; +static const uint8_t S9 = 5; static const uint8_t S10 = 6; static const uint8_t S11 = 7; static const uint8_t S12 = 8; @@ -41,28 +41,28 @@ static const uint8_t RX = S11; static const uint8_t SDA = 13; static const uint8_t SCL = 14; -static const uint8_t D = SDA; -static const uint8_t C = SCL; +static const uint8_t D = SDA; +static const uint8_t C = SCL; static const uint8_t MOSI = 35; static const uint8_t MISO = 37; -static const uint8_t SCK = 36; -static const uint8_t DO = MOSI; -static const uint8_t DI = MISO; -static const uint8_t CLK = SCK; -static const uint8_t CS1 = S5; -static const uint8_t CS2 = S6; -static const uint8_t SS = CS1; +static const uint8_t SCK = 36; +static const uint8_t DO = MOSI; +static const uint8_t DI = MISO; +static const uint8_t CLK = SCK; +static const uint8_t CS1 = S5; +static const uint8_t CS2 = S6; +static const uint8_t SS = CS1; -static const uint8_t T1 = 1; -static const uint8_t T2 = 2; -static const uint8_t T3 = 3; -static const uint8_t T4 = 4; -static const uint8_t T5 = 5; -static const uint8_t T6 = 6; -static const uint8_t T7 = 7; -static const uint8_t T8 = 8; -static const uint8_t T9 = 9; +static const uint8_t T1 = 1; +static const uint8_t T2 = 2; +static const uint8_t T3 = 3; +static const uint8_t T4 = 4; +static const uint8_t T5 = 5; +static const uint8_t T6 = 6; +static const uint8_t T7 = 7; +static const uint8_t T8 = 8; +static const uint8_t T9 = 9; static const uint8_t T10 = 10; static const uint8_t T11 = 11; static const uint8_t T12 = 12; diff --git a/variants/cytron_maker_feather_aiot_s3/pins_arduino.h b/variants/cytron_maker_feather_aiot_s3/pins_arduino.h index cf75fa6b0ac..833ed77a03a 100644 --- a/variants/cytron_maker_feather_aiot_s3/pins_arduino.h +++ b/variants/cytron_maker_feather_aiot_s3/pins_arduino.h @@ -4,34 +4,34 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x303A -#define USB_PID 0x80F8 -#define USB_MANUFACTURER "Cytron" -#define USB_PRODUCT "Maker Feather AIoT S3" -#define USB_SERIAL "" - -static const uint8_t LED_BUILTIN = 2; // Status LED. -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -static const uint8_t RGB_BUILTIN = SOC_GPIO_PIN_COUNT + 46; // RGB LED. -#define RGB_BUILTIN RGB_BUILTIN // necessary to make digitalWrite/digitalMode find it +#define USB_VID 0x303A +#define USB_PID 0x80F8 +#define USB_MANUFACTURER "Cytron" +#define USB_PRODUCT "Maker Feather AIoT S3" +#define USB_SERIAL "" + +static const uint8_t LED_BUILTIN = 2; // Status LED. +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +static const uint8_t RGB_BUILTIN = SOC_GPIO_PIN_COUNT + 46; // RGB LED. +#define RGB_BUILTIN RGB_BUILTIN // necessary to make digitalWrite/digitalMode find it #define RGB_BRIGHTNESS 64 -#define LED LED_BUILTIN -#define RGB RGB_BUILTIN -#define NEOPIXEL RGB_BUILTIN -#define RGB_BRIGHTNESS 65 +#define LED LED_BUILTIN +#define RGB RGB_BUILTIN +#define NEOPIXEL RGB_BUILTIN +#define RGB_BRIGHTNESS 65 -#define VP_EN 11 // V Peripheral Enable. -#define BUZZER 12 // Piezo Buzzer. -#define BOOT 0 // Boot Button. -#define BUTTON 3 // User Button. +#define VP_EN 11 // V Peripheral Enable. +#define BUZZER 12 // Piezo Buzzer. +#define BOOT 0 // Boot Button. +#define BUTTON 3 // User Button. -#define VIN 13 // Vin Sense. -#define VBATT 13 -#define VOLTAGE_MONITOR 13 +#define VIN 13 // Vin Sense. +#define VBATT 13 +#define VOLTAGE_MONITOR 13 static const uint8_t TX = 15; @@ -40,10 +40,10 @@ static const uint8_t RX = 16; static const uint8_t SDA = 42; static const uint8_t SCL = 41; -static const uint8_t SS = 7; -static const uint8_t MOSI = 8; -static const uint8_t SCK = 17; -static const uint8_t MISO = 18; +static const uint8_t SS = 7; +static const uint8_t MOSI = 8; +static const uint8_t SCK = 17; +static const uint8_t MISO = 18; static const uint8_t A0 = 10; static const uint8_t A1 = 9; diff --git a/variants/cytron_maker_feather_aiot_s3/variant.cpp b/variants/cytron_maker_feather_aiot_s3/variant.cpp index d90883480b3..8e5c493996c 100644 --- a/variants/cytron_maker_feather_aiot_s3/variant.cpp +++ b/variants/cytron_maker_feather_aiot_s3/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2022 Wai Weng for Cytron Technologies @@ -28,11 +28,10 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - // Turn on VPeripheral by default. - pinMode(VP_EN, OUTPUT); - digitalWrite(VP_EN, HIGH); -} + // Initialize variant/board, called before setup() + void initVariant(void) { + // Turn on VPeripheral by default. + pinMode(VP_EN, OUTPUT); + digitalWrite(VP_EN, HIGH); + } } diff --git a/variants/d-duino-32/pins_arduino.h b/variants/d-duino-32/pins_arduino.h index 935261996b1..b14955417af 100644 --- a/variants/d-duino-32/pins_arduino.h +++ b/variants/d-duino-32/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 5; static const uint8_t SCL = 4; -static const uint8_t SS = 15; -static const uint8_t MOSI = 13; -static const uint8_t MISO = 12; -static const uint8_t SCK = 14; +static const uint8_t SS = 15; +static const uint8_t MOSI = 13; +static const uint8_t MISO = 12; +static const uint8_t SCK = 14; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/d1_mini32/pins_arduino.h b/variants/d1_mini32/pins_arduino.h index 1b507cde1fd..3ffe9e3fe83 100644 --- a/variants/d1_mini32/pins_arduino.h +++ b/variants/d1_mini32/pins_arduino.h @@ -5,30 +5,30 @@ #include <../d32/d32_core.h> static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -static const uint8_t _VBAT = 35; // battery voltage +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +static const uint8_t _VBAT = 35; // battery voltage -#define PIN_WIRE_SDA SDA // backward compatibility -#define PIN_WIRE_SCL SCL // backward compatibility +#define PIN_WIRE_SDA SDA // backward compatibility +#define PIN_WIRE_SCL SCL // backward compatibility -static const uint8_t D0 = 26; -static const uint8_t D1 = 22; -static const uint8_t D2 = 21; -static const uint8_t D3 = 17; -static const uint8_t D4 = 16; -static const uint8_t D5 = 18; -static const uint8_t D6 = 19; -static const uint8_t D7 = 23; -static const uint8_t D8 = 5; -static const uint8_t RXD = 3; -static const uint8_t TXD = 1; +static const uint8_t D0 = 26; +static const uint8_t D1 = 22; +static const uint8_t D2 = 21; +static const uint8_t D3 = 17; +static const uint8_t D4 = 16; +static const uint8_t D5 = 18; +static const uint8_t D6 = 19; +static const uint8_t D7 = 23; +static const uint8_t D8 = 5; +static const uint8_t RXD = 3; +static const uint8_t TXD = 1; -#define PIN_SPI_SS SS // backward compatibility -#define PIN_SPI_MOSI MOSI // backward compatibility -#define PIN_SPI_MISO MISO // backward compatibility -#define PIN_SPI_SCK SCK // backward compatibility +#define PIN_SPI_SS SS // backward compatibility +#define PIN_SPI_MOSI MOSI // backward compatibility +#define PIN_SPI_MISO MISO // backward compatibility +#define PIN_SPI_SCK SCK // backward compatibility -#define PIN_A0 A0 // backward compatibility +#define PIN_A0 A0 // backward compatibility #endif /* Pins_Arduino_h */ diff --git a/variants/d1_uno32/pins_arduino.h b/variants/d1_uno32/pins_arduino.h index 6f46d419c83..6b8a59afbbd 100644 --- a/variants/d1_uno32/pins_arduino.h +++ b/variants/d1_uno32/pins_arduino.h @@ -11,10 +11,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 2; static const uint8_t A1 = 4; @@ -24,32 +24,32 @@ static const uint8_t A4 = 36; static const uint8_t A5 = 39; static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -#define PIN_WIRE_SDA SDA // backward compatibility -#define PIN_WIRE_SCL SCL // backward compatibility - -static const uint8_t D0 = 3; -static const uint8_t D1 = 1; -static const uint8_t D2 = 26; -static const uint8_t D3 = 25; -static const uint8_t D4 = 17; -static const uint8_t D5 = 16; -static const uint8_t D6 = 27; -static const uint8_t D7 = 14; -static const uint8_t D8 = 12; -static const uint8_t D9 = 13; -static const uint8_t D10 = 5; -static const uint8_t D11 = 23; -static const uint8_t D12 = 19; -static const uint8_t D13 = 18; - -#define PIN_SPI_SS SS // backward compatibility -#define PIN_SPI_MOSI MOSI // backward compatibility -#define PIN_SPI_MISO MISO // backward compatibility -#define PIN_SPI_SCK SCK // backward compatibility - -#define PIN_A0 A0 // backward compatibility +#define PIN_WIRE_SDA SDA // backward compatibility +#define PIN_WIRE_SCL SCL // backward compatibility + +static const uint8_t D0 = 3; +static const uint8_t D1 = 1; +static const uint8_t D2 = 26; +static const uint8_t D3 = 25; +static const uint8_t D4 = 17; +static const uint8_t D5 = 16; +static const uint8_t D6 = 27; +static const uint8_t D7 = 14; +static const uint8_t D8 = 12; +static const uint8_t D9 = 13; +static const uint8_t D10 = 5; +static const uint8_t D11 = 23; +static const uint8_t D12 = 19; +static const uint8_t D13 = 18; + +#define PIN_SPI_SS SS // backward compatibility +#define PIN_SPI_MOSI MOSI // backward compatibility +#define PIN_SPI_MISO MISO // backward compatibility +#define PIN_SPI_SCK SCK // backward compatibility + +#define PIN_A0 A0 // backward compatibility #endif /* Pins_Arduino_h */ diff --git a/variants/d32/d32_core.h b/variants/d32/d32_core.h index e658c980896..3d637594602 100644 --- a/variants/d32/d32_core.h +++ b/variants/d32/d32_core.h @@ -7,10 +7,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; @@ -43,4 +43,4 @@ static const uint8_t T9 = 32; static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; -#endif \ No newline at end of file +#endif diff --git a/variants/d32/pins_arduino.h b/variants/d32/pins_arduino.h index e517def5e8f..d5346c38acc 100644 --- a/variants/d32/pins_arduino.h +++ b/variants/d32/pins_arduino.h @@ -5,8 +5,8 @@ #include static const uint8_t LED_BUILTIN = 5; -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -static const uint8_t _VBAT = 35; // battery voltage +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +static const uint8_t _VBAT = 35; // battery voltage #endif /* Pins_Arduino_h */ diff --git a/variants/d32_pro/pins_arduino.h b/variants/d32_pro/pins_arduino.h index da7c14bc389..76acc067818 100644 --- a/variants/d32_pro/pins_arduino.h +++ b/variants/d32_pro/pins_arduino.h @@ -5,18 +5,18 @@ #include <../d32/d32_core.h> static const uint8_t LED_BUILTIN = 5; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -static const uint8_t _VBAT = 35; // battery voltage +static const uint8_t _VBAT = 35; // battery voltage -#define TF_CS 4 // TF (Micro SD Card) CS pin -#define TS_CS 12 // Touch Screen CS pin -#define TFT_CS 14 // TFT CS pin -#define TFT_LED 32 // TFT backlight control pin -#define TFT_RST 33 // TFT reset pin -#define TFT_DC 27 // TFT DC pin +#define TF_CS 4 // TF (Micro SD Card) CS pin +#define TS_CS 12 // Touch Screen CS pin +#define TFT_CS 14 // TFT CS pin +#define TFT_LED 32 // TFT backlight control pin +#define TFT_RST 33 // TFT reset pin +#define TFT_DC 27 // TFT DC pin -#define SS TF_CS +#define SS TF_CS #endif /* Pins_Arduino_h */ diff --git a/variants/deneyapkart/pins_arduino.h b/variants/deneyapkart/pins_arduino.h index 587f92433fa..e6e117ad48b 100644 --- a/variants/deneyapkart/pins_arduino.h +++ b/variants/deneyapkart/pins_arduino.h @@ -4,9 +4,9 @@ #include static const uint8_t LED_BUILTIN = 4; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -#define LEDB LED_BUILTIN +#define LEDB LED_BUILTIN #define LEDR 3 #define LEDG 1 @@ -23,10 +23,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 4; static const uint8_t SCL = 15; -static const uint8_t SS = 21; +static const uint8_t SS = 21; static const uint8_t MOSI = 5; static const uint8_t MISO = 18; -static const uint8_t SCK = 19; +static const uint8_t SCK = 19; static const uint8_t A0 = 36; static const uint8_t A1 = 39; @@ -42,16 +42,16 @@ static const uint8_t T3 = 14; static const uint8_t T4 = 12; static const uint8_t T5 = 13; -static const uint8_t D0 = 23; -static const uint8_t D1 = 22; -static const uint8_t D2 = 1; -static const uint8_t D3 = 3; -static const uint8_t D4 = 21; -static const uint8_t D5 = 19; -static const uint8_t D6 = 18; -static const uint8_t D7 = 5; -static const uint8_t D8 = 0; -static const uint8_t D9 = 2; +static const uint8_t D0 = 23; +static const uint8_t D1 = 22; +static const uint8_t D2 = 1; +static const uint8_t D3 = 3; +static const uint8_t D4 = 21; +static const uint8_t D5 = 19; +static const uint8_t D6 = 18; +static const uint8_t D7 = 5; +static const uint8_t D8 = 0; +static const uint8_t D9 = 2; static const uint8_t D10 = 4; static const uint8_t D11 = 15; static const uint8_t D12 = 13; @@ -77,8 +77,8 @@ static const uint8_t CAMD8 = 35; static const uint8_t CAMD9 = 34; static const uint8_t CAMPC = 5; static const uint8_t CAMXC = 32; -static const uint8_t CAMH = 39; -static const uint8_t CAMV = 36; +static const uint8_t CAMH = 39; +static const uint8_t CAMV = 36; static const uint8_t MICD = 12; static const uint8_t MICC = 13; diff --git a/variants/deneyapkart1A/pins_arduino.h b/variants/deneyapkart1A/pins_arduino.h index edac64ac794..1bd41d0986f 100644 --- a/variants/deneyapkart1A/pins_arduino.h +++ b/variants/deneyapkart1A/pins_arduino.h @@ -4,11 +4,11 @@ #include #include "soc/soc_caps.h" -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+13; //D12 -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 13; //D12 +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN -#define RGBLED LED_BUILTIN +#define RGBLED LED_BUILTIN #define RGB_BRIGHTNESS 64 static const uint8_t GPKEY = 0; @@ -24,10 +24,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 4; static const uint8_t SCL = 15; -static const uint8_t SS = 21; +static const uint8_t SS = 21; static const uint8_t MOSI = 5; static const uint8_t MISO = 18; -static const uint8_t SCK = 19; +static const uint8_t SCK = 19; static const uint8_t A0 = 36; static const uint8_t A1 = 39; @@ -43,16 +43,16 @@ static const uint8_t T3 = 14; static const uint8_t T4 = 12; static const uint8_t T5 = 13; -static const uint8_t D0 = 23; -static const uint8_t D1 = 22; -static const uint8_t D2 = 1; -static const uint8_t D3 = 3; -static const uint8_t D4 = 21; -static const uint8_t D5 = 19; -static const uint8_t D6 = 18; -static const uint8_t D7 = 5; -static const uint8_t D8 = 0; -static const uint8_t D9 = 2; +static const uint8_t D0 = 23; +static const uint8_t D1 = 22; +static const uint8_t D2 = 1; +static const uint8_t D3 = 3; +static const uint8_t D4 = 21; +static const uint8_t D5 = 19; +static const uint8_t D6 = 18; +static const uint8_t D7 = 5; +static const uint8_t D8 = 0; +static const uint8_t D9 = 2; static const uint8_t D10 = 4; static const uint8_t D11 = 15; static const uint8_t D12 = 13; @@ -78,8 +78,8 @@ static const uint8_t CAMD8 = 35; static const uint8_t CAMD9 = 34; static const uint8_t CAMPC = 5; static const uint8_t CAMXC = 32; -static const uint8_t CAMH = 39; -static const uint8_t CAMV = 36; +static const uint8_t CAMH = 39; +static const uint8_t CAMV = 36; static const uint8_t SDMI = 2; static const uint8_t SDMO = 14; diff --git a/variants/deneyapkart1Av2/pins_arduino.h b/variants/deneyapkart1Av2/pins_arduino.h index 34d84b057cf..e9e132eba4c 100644 --- a/variants/deneyapkart1Av2/pins_arduino.h +++ b/variants/deneyapkart1Av2/pins_arduino.h @@ -4,17 +4,17 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x303A -#define USB_PID 0x8147 -#define USB_MANUFACTURER "Turkish Technnology Team Foundation (T3)" -#define USB_PRODUCT "DENEYAP KART 1A v2" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x303A +#define USB_PID 0x8147 +#define USB_MANUFACTURER "Turkish Technology Team Foundation (T3)" +#define USB_PRODUCT "DENEYAP KART 1A v2" +#define USB_SERIAL "" // Empty string for MAC address -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+48; //D9 -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 48; //D9 +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN -#define RGBLED LED_BUILTIN +#define RGBLED LED_BUILTIN #define RGB_BRIGHTNESS 64 static const uint8_t GPKEY = 0; @@ -29,10 +29,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 47; static const uint8_t SCL = 21; -static const uint8_t SS = 42; -static const uint8_t MOSI = 39; -static const uint8_t MISO = 40; -static const uint8_t SCK = 41; +static const uint8_t SS = 42; +static const uint8_t MOSI = 39; +static const uint8_t MISO = 40; +static const uint8_t SCK = 41; static const uint8_t A0 = 4; static const uint8_t A1 = 5; @@ -54,16 +54,16 @@ static const uint8_t T6 = 10; static const uint8_t T7 = 1; static const uint8_t T8 = 2; -static const uint8_t D0 = 1; -static const uint8_t D1 = 2; -static const uint8_t D2 = 43; -static const uint8_t D3 = 44; -static const uint8_t D4 = 42; -static const uint8_t D5 = 41; -static const uint8_t D6 = 40; -static const uint8_t D7 = 39; -static const uint8_t D8 = 38; -static const uint8_t D9 = 48; +static const uint8_t D0 = 1; +static const uint8_t D1 = 2; +static const uint8_t D2 = 43; +static const uint8_t D3 = 44; +static const uint8_t D4 = 42; +static const uint8_t D5 = 41; +static const uint8_t D6 = 40; +static const uint8_t D7 = 39; +static const uint8_t D8 = 38; +static const uint8_t D9 = 48; static const uint8_t D10 = 47; static const uint8_t D11 = 21; static const uint8_t D12 = 10; @@ -93,8 +93,8 @@ static const uint8_t CAMD8 = 17; static const uint8_t CAMD9 = 15; static const uint8_t CAMPC = 39; static const uint8_t CAMXC = 16; -static const uint8_t CAMH = 7; -static const uint8_t CAMV = 6; +static const uint8_t CAMH = 7; +static const uint8_t CAMV = 6; static const uint8_t SDMI = 14; static const uint8_t SDMO = 12; diff --git a/variants/deneyapkartg/pins_arduino.h b/variants/deneyapkartg/pins_arduino.h index 817f63affc1..824477f2226 100644 --- a/variants/deneyapkartg/pins_arduino.h +++ b/variants/deneyapkartg/pins_arduino.h @@ -4,17 +4,17 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x303A -#define USB_PID 0x814A -#define USB_MANUFACTURER "Turkish Technnology Team Foundation (T3)" -#define USB_PRODUCT "DENEYAP KART G" -#define USB_SERIAL "" // Empty string for MAC adddress - -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+10; //D3 -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +#define USB_VID 0x303A +#define USB_PID 0x814A +#define USB_MANUFACTURER "Turkish Technology Team Foundation (T3)" +#define USB_PRODUCT "DENEYAP KART G" +#define USB_SERIAL "" // Empty string for MAC address + +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 10; //D3 +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN -#define RGBLED LED_BUILTIN +#define RGBLED LED_BUILTIN #define RGB_BRIGHTNESS 64 static const uint8_t GPKEY = 9; @@ -30,10 +30,10 @@ static const uint8_t RX = 20; static const uint8_t SDA = 8; static const uint8_t SCL = 2; -static const uint8_t SS = 7; +static const uint8_t SS = 7; static const uint8_t MOSI = 6; static const uint8_t MISO = 5; -static const uint8_t SCK = 4; +static const uint8_t SCK = 4; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/deneyapmini/pins_arduino.h b/variants/deneyapmini/pins_arduino.h index b4f8b71e05f..205b342c6aa 100644 --- a/variants/deneyapmini/pins_arduino.h +++ b/variants/deneyapmini/pins_arduino.h @@ -3,16 +3,16 @@ #include -#define USB_VID 0x303A -#define USB_PID 0x8141 -#define USB_MANUFACTURER "Turkish Technnology Team Foundation (T3)" -#define USB_PRODUCT "DENEYAP MINI" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x303A +#define USB_PID 0x8141 +#define USB_MANUFACTURER "Turkish Technology Team Foundation (T3)" +#define USB_PRODUCT "DENEYAP MINI" +#define USB_SERIAL "" // Empty string for MAC address static const uint8_t LED_BUILTIN = 35; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -#define LEDB LED_BUILTIN +#define LEDB LED_BUILTIN #define LEDR 34 #define LEDG 33 @@ -29,10 +29,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 36; static const uint8_t SCL = 37; -static const uint8_t SS = 21; +static const uint8_t SS = 21; static const uint8_t MOSI = 40; static const uint8_t MISO = 39; -static const uint8_t SCK = 38; +static const uint8_t SCK = 38; static const uint8_t A0 = 8; static const uint8_t A1 = 9; @@ -49,16 +49,16 @@ static const uint8_t T3 = 11; static const uint8_t T4 = 12; static const uint8_t T5 = 13; -static const uint8_t D0 = 44; -static const uint8_t D1 = 43; -static const uint8_t D2 = 42; -static const uint8_t D3 = 41; -static const uint8_t D4 = 40; -static const uint8_t D5 = 39; -static const uint8_t D6 = 38; -static const uint8_t D7 = 37; -static const uint8_t D8 = 36; -static const uint8_t D9 = 26; +static const uint8_t D0 = 44; +static const uint8_t D1 = 43; +static const uint8_t D2 = 42; +static const uint8_t D3 = 41; +static const uint8_t D4 = 40; +static const uint8_t D5 = 39; +static const uint8_t D6 = 38; +static const uint8_t D7 = 37; +static const uint8_t D8 = 36; +static const uint8_t D9 = 26; static const uint8_t D10 = 21; static const uint8_t D11 = 18; static const uint8_t D12 = 17; diff --git a/variants/deneyapminiv2/pins_arduino.h b/variants/deneyapminiv2/pins_arduino.h index 98ef80732f8..91a2a43761b 100644 --- a/variants/deneyapminiv2/pins_arduino.h +++ b/variants/deneyapminiv2/pins_arduino.h @@ -4,17 +4,17 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x303A -#define USB_PID 0x8144 -#define USB_MANUFACTURER "Turkish Technnology Team Foundation (T3)" -#define USB_PRODUCT "DENEYAP MINI v2" -#define USB_SERIAL "" // Empty string for MAC adddress - -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+33; //D14 -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +#define USB_VID 0x303A +#define USB_PID 0x8144 +#define USB_MANUFACTURER "Turkish Technology Team Foundation (T3)" +#define USB_PRODUCT "DENEYAP MINI v2" +#define USB_SERIAL "" // Empty string for MAC address + +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 33; //D14 +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN -#define RGBLED LED_BUILTIN +#define RGBLED LED_BUILTIN #define RGB_BRIGHTNESS 64 static const uint8_t GPKEY = 0; @@ -29,10 +29,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 36; static const uint8_t SCL = 37; -static const uint8_t SS = 21; +static const uint8_t SS = 21; static const uint8_t MOSI = 40; static const uint8_t MISO = 39; -static const uint8_t SCK = 38; +static const uint8_t SCK = 38; static const uint8_t A0 = 7; static const uint8_t A1 = 8; @@ -51,16 +51,16 @@ static const uint8_t T4 = 11; static const uint8_t T5 = 12; static const uint8_t T6 = 13; -static const uint8_t D0 = 44; -static const uint8_t D1 = 43; -static const uint8_t D2 = 42; -static const uint8_t D3 = 41; -static const uint8_t D4 = 40; -static const uint8_t D5 = 39; -static const uint8_t D6 = 38; -static const uint8_t D7 = 37; -static const uint8_t D8 = 36; -static const uint8_t D9 = 26; +static const uint8_t D0 = 44; +static const uint8_t D1 = 43; +static const uint8_t D2 = 42; +static const uint8_t D3 = 41; +static const uint8_t D4 = 40; +static const uint8_t D5 = 39; +static const uint8_t D6 = 38; +static const uint8_t D7 = 37; +static const uint8_t D8 = 36; +static const uint8_t D9 = 26; static const uint8_t D10 = 21; static const uint8_t D11 = 18; static const uint8_t D12 = 17; diff --git a/variants/department_of_alchemy_minimain_esp32s2/pins_arduino.h b/variants/department_of_alchemy_minimain_esp32s2/pins_arduino.h index 67427d7e516..d11d34e7d49 100644 --- a/variants/department_of_alchemy_minimain_esp32s2/pins_arduino.h +++ b/variants/department_of_alchemy_minimain_esp32s2/pins_arduino.h @@ -4,35 +4,35 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x303a -#define USB_PID 0x80FF -#define USB_MANUFACTURER "Department of Alchemy" -#define USB_PRODUCT "MiniMain ESP32-S2" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x303a +#define USB_PID 0x80FF +#define USB_MANUFACTURER "Department of Alchemy" +#define USB_PRODUCT "MiniMain ESP32-S2" +#define USB_SERIAL "" // Empty string for MAC address -// User LED +// User LED #define LED_BUILTIN 13 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility // Neopixel -#define PIN_NEOPIXEL 33 +#define PIN_NEOPIXEL 33 // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() and digitalWrite() for blinking -#define RGB_BUILTIN (PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 -#define NEOPIXEL_NUM 1 // number of neopixels -#define NEOPIXEL_POWER 21 // power pin -#define NEOPIXEL_POWER_ON HIGH // power pin state when on -#define PIN_SERVO 2 // servo pin -#define PIN_ISOLATED_INPUT 40 // optocoupled input +#define NEOPIXEL_NUM 1 // number of neopixels +#define NEOPIXEL_POWER 21 // power pin +#define NEOPIXEL_POWER_ON HIGH // power pin state when on +#define PIN_SERVO 2 // servo pin +#define PIN_ISOLATED_INPUT 40 // optocoupled input static const uint8_t SDA = 3; static const uint8_t SCL = 4; -static const uint8_t SS = 42; -static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; -static const uint8_t MISO = 37; +static const uint8_t SS = 42; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; static const uint8_t A0 = 18; static const uint8_t A1 = 17; diff --git a/variants/department_of_alchemy_minimain_esp32s2/variant.cpp b/variants/department_of_alchemy_minimain_esp32s2/variant.cpp index 5f7a3c0b55d..ef1982107f4 100644 --- a/variants/department_of_alchemy_minimain_esp32s2/variant.cpp +++ b/variants/department_of_alchemy_minimain_esp32s2/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,12 +28,11 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ - // This board has a power control pin, and we must set it to output and high - // in order to enable the NeoPixels. - pinMode(NEOPIXEL_POWER, OUTPUT); - digitalWrite(NEOPIXEL_POWER, HIGH); -} + // Initialize variant/board, called before setup() + void initVariant(void) { + // This board has a power control pin, and we must set it to output and high + // in order to enable the NeoPixels. + pinMode(NEOPIXEL_POWER, OUTPUT); + digitalWrite(NEOPIXEL_POWER, HIGH); + } } diff --git a/variants/dfrobot_beetle_esp32c3/pins_arduino.h b/variants/dfrobot_beetle_esp32c3/pins_arduino.h index abf093cfccb..be9a6f7c59b 100644 --- a/variants/dfrobot_beetle_esp32c3/pins_arduino.h +++ b/variants/dfrobot_beetle_esp32c3/pins_arduino.h @@ -3,14 +3,14 @@ #include -#define USB_VID 0x3343 -#define USB_PID 0x8364 -#define USB_MANUFACTURER "DFRobot" -#define USB_PRODUCT "Beetle ESP32-C3" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x3343 +#define USB_PID 0x8364 +#define USB_MANUFACTURER "DFRobot" +#define USB_PRODUCT "Beetle ESP32-C3" +#define USB_SERIAL "" // Empty string for MAC address static const uint8_t LED_BUILTIN = 10; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 21; @@ -19,10 +19,10 @@ static const uint8_t RX = 20; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 7; -static const uint8_t MOSI = 6; -static const uint8_t MISO = 5; -static const uint8_t SCK = 4; +static const uint8_t SS = 7; +static const uint8_t MOSI = 6; +static const uint8_t MISO = 5; +static const uint8_t SCK = 4; static const uint8_t A0 = 0; static const uint8_t A1 = 1; @@ -32,19 +32,19 @@ static const uint8_t A4 = 4; static const uint8_t A5 = 5; #define GDI_DISPLAY_FPC_INTERFACE -#ifdef GDI_DISPLAY_FPC_INTERFACE - -#define GDI_BLK LED_BUILTIN -#define GDI_SPI_SCLK SCK -#define GDI_SPI_MOSI MOSI -#define GDI_SPI_MISO MISO -#define GDI_DC A1 -#define GDI_RES A2 -#define GDI_CS SS -#define GDI_SDCS A0 -#define GDI_TCS A3 -#define GDI_SCL SCL -#define GDI_SDA SDA +#ifdef GDI_DISPLAY_FPC_INTERFACE + +#define GDI_BLK LED_BUILTIN +#define GDI_SPI_SCLK SCK +#define GDI_SPI_MOSI MOSI +#define GDI_SPI_MISO MISO +#define GDI_DC A1 +#define GDI_RES A2 +#define GDI_CS SS +#define GDI_SDCS A0 +#define GDI_TCS A3 +#define GDI_SCL SCL +#define GDI_SDA SDA #endif diff --git a/variants/dfrobot_beetle_esp32c6/pins_arduino.h b/variants/dfrobot_beetle_esp32c6/pins_arduino.h index 147a19f7007..d1667075569 100644 --- a/variants/dfrobot_beetle_esp32c6/pins_arduino.h +++ b/variants/dfrobot_beetle_esp32c6/pins_arduino.h @@ -6,7 +6,7 @@ static const uint8_t LED_BUILTIN = 15; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 16; @@ -15,10 +15,10 @@ static const uint8_t RX = 17; static const uint8_t SDA = 19; static const uint8_t SCL = 20; -static const uint8_t SS = 4; +static const uint8_t SS = 4; static const uint8_t MOSI = 22; static const uint8_t MISO = 21; -static const uint8_t SCK = 23; +static const uint8_t SCK = 23; #endif /* Pins_Arduino_h */ diff --git a/variants/dfrobot_firebeetle2_esp32c6/pins_arduino.h b/variants/dfrobot_firebeetle2_esp32c6/pins_arduino.h index 0321b29e4d2..3ccc431f6e5 100644 --- a/variants/dfrobot_firebeetle2_esp32c6/pins_arduino.h +++ b/variants/dfrobot_firebeetle2_esp32c6/pins_arduino.h @@ -6,7 +6,7 @@ static const uint8_t LED_BUILTIN = 15; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 16; @@ -15,42 +15,42 @@ static const uint8_t RX = 17; static const uint8_t SDA = 19; static const uint8_t SCL = 20; -static const uint8_t SS = 5; +static const uint8_t SS = 5; static const uint8_t MOSI = 22; static const uint8_t MISO = 21; -static const uint8_t SCK = 23; +static const uint8_t SCK = 23; static const uint8_t A1 = 2; static const uint8_t A2 = 3; static const uint8_t A3 = 4; static const uint8_t A4 = 5; -static const uint8_t D2 = 8; -static const uint8_t D3 = 14; -static const uint8_t D6 = 1; -static const uint8_t D7 = 18; -static const uint8_t D9 = 9; +static const uint8_t D2 = 8; +static const uint8_t D3 = 14; +static const uint8_t D6 = 1; +static const uint8_t D7 = 18; +static const uint8_t D9 = 9; static const uint8_t D11 = 7; static const uint8_t D12 = 6; static const uint8_t D13 = 15; #define GDI_DISPLAY_FPC_INTERFACE -#ifdef GDI_DISPLAY_FPC_INTERFACE - -#define GDI_BLK D13 -#define GDI_SPI_SCLK SCK -#define GDI_SPI_MOSI MOSI -#define GDI_SPI_MISO MISO -#define GDI_DC D2 -#define GDI_RES D3 -#define GDI_CS D6 //LCD_CS -#define GDI_SDCS D7 -#define GDI_FCS -1 -#define GDI_TCS D12 -#define GDI_SCL SCL -#define GDI_SDA SDA -#define GDI_INT D11 -#define GDI_BUSY_TE -1 +#ifdef GDI_DISPLAY_FPC_INTERFACE + +#define GDI_BLK D13 +#define GDI_SPI_SCLK SCK +#define GDI_SPI_MOSI MOSI +#define GDI_SPI_MISO MISO +#define GDI_DC D2 +#define GDI_RES D3 +#define GDI_CS D6 //LCD_CS +#define GDI_SDCS D7 +#define GDI_FCS -1 +#define GDI_TCS D12 +#define GDI_SCL SCL +#define GDI_SDA SDA +#define GDI_INT D11 +#define GDI_BUSY_TE -1 #endif diff --git a/variants/dfrobot_firebeetle2_esp32e/pins_arduino.h b/variants/dfrobot_firebeetle2_esp32e/pins_arduino.h index 335beebf32b..3048c5f6a12 100644 --- a/variants/dfrobot_firebeetle2_esp32e/pins_arduino.h +++ b/variants/dfrobot_firebeetle2_esp32e/pins_arduino.h @@ -1,70 +1,70 @@ -#ifndef Pins_Arduino_h -#define Pins_Arduino_h - -#include - -typedef unsigned char uint8_t; - -static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN - -static const uint8_t TX = 1; -static const uint8_t RX = 3; -static const uint8_t TX2 = 17; -static const uint8_t RX2 = 16; - -static const uint8_t SDA = 21; -static const uint8_t SCL = 22; - -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; - -static const uint8_t D0 = 3; -static const uint8_t D1 = 1; -static const uint8_t D2 = 25; -static const uint8_t D3 = 26; -static const uint8_t D4 = 27; -static const uint8_t D5 = 0; -static const uint8_t D6 = 14; -static const uint8_t D7 = 13; -static const uint8_t D8 = 5; -static const uint8_t D9 = 2; -static const uint8_t D10 = 17; -static const uint8_t D11 = 16; -static const uint8_t D12 = 4; -static const uint8_t D13 = 12; - -static const uint8_t A0 = 36; -static const uint8_t A1 = 39; -static const uint8_t A2 = 34; -static const uint8_t A3 = 35; -static const uint8_t A4 = 15; -static const uint8_t A5 = 35; -static const uint8_t A6 = 4; -static const uint8_t A7 = 0; -static const uint8_t A8 = 2; -static const uint8_t A9 = 13; -static const uint8_t A10 = 12; -static const uint8_t A11 = 14; -static const uint8_t A12 = 27; -static const uint8_t A13 = 25; -static const uint8_t A14 = 26; - -static const uint8_t T0 = 4; -static const uint8_t T1 = 0; -static const uint8_t T2 = 2; -static const uint8_t T3 = 15; -static const uint8_t T4 = 13; -static const uint8_t T5 = 12; -static const uint8_t T6 = 14; -static const uint8_t T7 = 27; -static const uint8_t T8 = 33; -static const uint8_t T9 = 32; - -static const uint8_t DAC1 = 25; -static const uint8_t DAC2 = 26; - -#endif /* Pins_Arduino_h */ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +typedef unsigned char uint8_t; + +static const uint8_t LED_BUILTIN = 2; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN + +static const uint8_t TX = 1; +static const uint8_t RX = 3; +static const uint8_t TX2 = 17; +static const uint8_t RX2 = 16; + +static const uint8_t SDA = 21; +static const uint8_t SCL = 22; + +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; + +static const uint8_t D0 = 3; +static const uint8_t D1 = 1; +static const uint8_t D2 = 25; +static const uint8_t D3 = 26; +static const uint8_t D4 = 27; +static const uint8_t D5 = 0; +static const uint8_t D6 = 14; +static const uint8_t D7 = 13; +static const uint8_t D8 = 5; +static const uint8_t D9 = 2; +static const uint8_t D10 = 17; +static const uint8_t D11 = 16; +static const uint8_t D12 = 4; +static const uint8_t D13 = 12; + +static const uint8_t A0 = 36; +static const uint8_t A1 = 39; +static const uint8_t A2 = 34; +static const uint8_t A3 = 35; +static const uint8_t A4 = 15; +static const uint8_t A5 = 35; +static const uint8_t A6 = 4; +static const uint8_t A7 = 0; +static const uint8_t A8 = 2; +static const uint8_t A9 = 13; +static const uint8_t A10 = 12; +static const uint8_t A11 = 14; +static const uint8_t A12 = 27; +static const uint8_t A13 = 25; +static const uint8_t A14 = 26; + +static const uint8_t T0 = 4; +static const uint8_t T1 = 0; +static const uint8_t T2 = 2; +static const uint8_t T3 = 15; +static const uint8_t T4 = 13; +static const uint8_t T5 = 12; +static const uint8_t T6 = 14; +static const uint8_t T7 = 27; +static const uint8_t T8 = 33; +static const uint8_t T9 = 32; + +static const uint8_t DAC1 = 25; +static const uint8_t DAC2 = 26; + +#endif /* Pins_Arduino_h */ diff --git a/variants/dfrobot_firebeetle2_esp32s3/pins_arduino.h b/variants/dfrobot_firebeetle2_esp32s3/pins_arduino.h index 012596b01af..1786ea9beb1 100644 --- a/variants/dfrobot_firebeetle2_esp32s3/pins_arduino.h +++ b/variants/dfrobot_firebeetle2_esp32s3/pins_arduino.h @@ -5,9 +5,9 @@ #define USB_VID 0x3343 #define USB_PID 0x83CF -#define USB_MANUFACTURER "DFRobot" -#define USB_PRODUCT "FireBeetle 2 ESP32-S3" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_MANUFACTURER "DFRobot" +#define USB_PRODUCT "FireBeetle 2 ESP32-S3" +#define USB_SERIAL "" // Empty string for MAC address static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -15,10 +15,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 1; static const uint8_t SCL = 2; -static const uint8_t SS = 10; -static const uint8_t MOSI = 15; -static const uint8_t MISO = 16; -static const uint8_t SCK = 17; +static const uint8_t SS = 10; +static const uint8_t MOSI = 15; +static const uint8_t MISO = 16; +static const uint8_t SCK = 17; static const uint8_t A0 = 4; static const uint8_t A1 = 5; @@ -28,12 +28,12 @@ static const uint8_t A4 = 10; static const uint8_t A5 = 11; -static const uint8_t D2 = 3; -static const uint8_t D3 = 38; -static const uint8_t D5 = 7; -static const uint8_t D6 = 18; -static const uint8_t D7 = 9; -static const uint8_t D9 = 0; +static const uint8_t D2 = 3; +static const uint8_t D3 = 38; +static const uint8_t D5 = 7; +static const uint8_t D6 = 18; +static const uint8_t D7 = 9; +static const uint8_t D9 = 0; static const uint8_t D10 = 14; static const uint8_t D11 = 13; static const uint8_t D12 = 12; @@ -41,7 +41,7 @@ static const uint8_t D13 = 21; static const uint8_t D14 = 47; static const uint8_t LED_BUILTIN = D13; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN @@ -61,22 +61,22 @@ static const uint8_t T13 = 13; static const uint8_t T14 = 14; #define GDI_DISPLAY_FPC_INTERFACE -#ifdef GDI_DISPLAY_FPC_INTERFACE +#ifdef GDI_DISPLAY_FPC_INTERFACE -#define GDI_BLK 21 -#define GDI_SPI_SCLK SCK -#define GDI_SPI_MOSI MOSI -#define GDI_SPI_MISO MISO -#define GDI_DC 3 -#define GDI_RES 38 -#define GDI_CS 18 -#define GDI_SDCS 9 -#define GDI_FCS 7 -#define GDI_TCS 12 -#define GDI_SCL SCL -#define GDI_SDA SDA -#define GDI_INT 13 -#define GDI_BUSY_TE 14 +#define GDI_BLK 21 +#define GDI_SPI_SCLK SCK +#define GDI_SPI_MOSI MOSI +#define GDI_SPI_MISO MISO +#define GDI_DC 3 +#define GDI_RES 38 +#define GDI_CS 18 +#define GDI_SDCS 9 +#define GDI_FCS 7 +#define GDI_TCS 12 +#define GDI_SCL SCL +#define GDI_SDA SDA +#define GDI_INT 13 +#define GDI_BUSY_TE 14 #endif diff --git a/variants/dfrobot_romeo_esp32s3/pins_arduino.h b/variants/dfrobot_romeo_esp32s3/pins_arduino.h index 40774c71ddf..2266ecf10e3 100644 --- a/variants/dfrobot_romeo_esp32s3/pins_arduino.h +++ b/variants/dfrobot_romeo_esp32s3/pins_arduino.h @@ -10,64 +10,64 @@ static const uint8_t SDA = 1; static const uint8_t SCL = 2; -static const uint8_t MOSI = 15; -static const uint8_t MISO = 16; -static const uint8_t SCK = 17; -static const uint8_t SS = 18; +static const uint8_t MOSI = 15; +static const uint8_t MISO = 16; +static const uint8_t SCK = 17; +static const uint8_t SS = 18; #define GDI_DISPLAY_FPC_INTERFACE -#ifdef GDI_DISPLAY_FPC_INTERFACE +#ifdef GDI_DISPLAY_FPC_INTERFACE -#define GDI_BLK 21 -#define GDI_SPI_SCLK SCK -#define GDI_SPI_MOSI MOSI -#define GDI_SPI_MISO MISO -#define GDI_DC 3 -#define GDI_RES 38 -#define GDI_CS 18 -#define GDI_SDCS 0 -#define GDI_FCS 7 -#define GDI_TCS 12 -#define GDI_SCL SCL -#define GDI_SDA SDA -#define GDI_INT 13 -#define GDI_BUSY_TE 14 +#define GDI_BLK 21 +#define GDI_SPI_SCLK SCK +#define GDI_SPI_MOSI MOSI +#define GDI_SPI_MISO MISO +#define GDI_DC 3 +#define GDI_RES 38 +#define GDI_CS 18 +#define GDI_SDCS 0 +#define GDI_FCS 7 +#define GDI_TCS 12 +#define GDI_SCL SCL +#define GDI_SDA SDA +#define GDI_INT 13 +#define GDI_BUSY_TE 14 #endif /* GDI_DISPLAY_FPC_INTERFACE */ // CAM #define CAM_DVP_INTERFACE -#ifdef CAM_DVP_INTERFACE +#ifdef CAM_DVP_INTERFACE -#define CAM_D5 4 -#define CAM_PCLK 5 -#define CAM_VSYNC 6 -#define CAM_D6 7 -#define CAM_D7 8 -#define CAM_D8 46 -#define CAM_D9 48 -#define CAM_XMCLK 45 -#define CAM_D2 39 -#define CAM_D3 40 -#define CAM_D4 41 -#define CAM_HREF 42 -#define CAM_SCL SCL -#define CAM_SDA SDA +#define CAM_D5 4 +#define CAM_PCLK 5 +#define CAM_VSYNC 6 +#define CAM_D6 7 +#define CAM_D7 8 +#define CAM_D8 46 +#define CAM_D9 48 +#define CAM_XMCLK 45 +#define CAM_D2 39 +#define CAM_D3 40 +#define CAM_D4 41 +#define CAM_HREF 42 +#define CAM_SCL SCL +#define CAM_SDA SDA #endif /* CAM_DVP_INTERFACE */ // Motor #define MOTOR_INTERFACE -#ifdef MOTOR_INTERFACE +#ifdef MOTOR_INTERFACE -#define M1_EN 12 -#define M1_PH 13 -#define M2_EN 14 -#define M2_PH 21 -#define M3_EN 9 -#define M3_PH 10 -#define M4_EN 47 -#define M4_PH 11 +#define M1_EN 12 +#define M1_PH 13 +#define M2_EN 14 +#define M2_PH 21 +#define M3_EN 9 +#define M3_PH 10 +#define M4_EN 47 +#define M4_PH 11 #endif diff --git a/variants/doitESP32devkitV1/pins_arduino.h b/variants/doitESP32devkitV1/pins_arduino.h index 467c58c0034..8e1d00416d1 100644 --- a/variants/doitESP32devkitV1/pins_arduino.h +++ b/variants/doitESP32devkitV1/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -13,10 +13,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/doitESPduino32/pins_arduino.h b/variants/doitESPduino32/pins_arduino.h index f0b54aa45bd..e94979a574d 100644 --- a/variants/doitESPduino32/pins_arduino.h +++ b/variants/doitESPduino32/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN @@ -12,15 +12,15 @@ static const uint8_t SDA = 21; static const uint8_t SCL = 22; //SPI -static const uint8_t IO5 = 5; //SS -static const uint8_t IO23 = 23; //MOSI -static const uint8_t IO19 = 19; //MISO -static const uint8_t IO18 = 18; //SCK +static const uint8_t IO5 = 5; //SS +static const uint8_t IO23 = 23; //MOSI +static const uint8_t IO19 = 19; //MISO +static const uint8_t IO18 = 18; //SCK -static const uint8_t SS = IO5; +static const uint8_t SS = IO5; static const uint8_t MOSI = IO23; static const uint8_t MISO = IO19; -static const uint8_t SCK = IO18; +static const uint8_t SCK = IO18; //ANALOG static const uint8_t IO36 = 36; @@ -61,33 +61,33 @@ static const uint8_t A3 = 34; static const uint8_t A4 = 36; static const uint8_t A5 = 39; -static const uint8_t D0 = 3; -static const uint8_t D1 = 1; -static const uint8_t D2 = 26; -static const uint8_t D3 = 25; -static const uint8_t D4 = 17; -static const uint8_t D5 = 16; -static const uint8_t D6 = 27; -static const uint8_t D7 = 14; -static const uint8_t D8 = 12; -static const uint8_t D9 = 13; -static const uint8_t D10 = 5; -static const uint8_t D11 = 23; -static const uint8_t D12 = 19; -static const uint8_t D13 = 18; +static const uint8_t D0 = 3; +static const uint8_t D1 = 1; +static const uint8_t D2 = 26; +static const uint8_t D3 = 25; +static const uint8_t D4 = 17; +static const uint8_t D5 = 16; +static const uint8_t D6 = 27; +static const uint8_t D7 = 14; +static const uint8_t D8 = 12; +static const uint8_t D9 = 13; +static const uint8_t D10 = 5; +static const uint8_t D11 = 23; +static const uint8_t D12 = 19; +static const uint8_t D13 = 18; static const uint8_t TX = 1; static const uint8_t RX = 3; -#define PIN_WIRE_SDA SDA // backward compatibility -#define PIN_WIRE_SCL SCL // backward compatibility +#define PIN_WIRE_SDA SDA // backward compatibility +#define PIN_WIRE_SCL SCL // backward compatibility -#define PIN_SPI_SS SS // backward compatibility -#define PIN_SPI_MOSI MOSI // backward compatibility -#define PIN_SPI_MISO MISO // backward compatibility -#define PIN_SPI_SCK SCK // backward compatibility +#define PIN_SPI_SS SS // backward compatibility +#define PIN_SPI_MOSI MOSI // backward compatibility +#define PIN_SPI_MISO MISO // backward compatibility +#define PIN_SPI_SCK SCK // backward compatibility -#define PIN_A0 A0 // backward compatibility +#define PIN_A0 A0 // backward compatibility // ESP-WROOM-32 does not have GPIO 14, 20(NC), 24, 28, 29, 30, 31, 36, 37, 38, 40+ // All pins should be PWM capable. The board is a clone of WeMos D1 R32. diff --git a/variants/dpu_esp32/pins_arduino.h b/variants/dpu_esp32/pins_arduino.h index 1b2e1b6634f..adc8ebd8b43 100644 --- a/variants/dpu_esp32/pins_arduino.h +++ b/variants/dpu_esp32/pins_arduino.h @@ -40,17 +40,17 @@ static const uint8_t DAC2 = 26; static const uint8_t SDA = 4; static const uint8_t SCL = 5; -static const uint8_t MOSI = 13; -static const uint8_t MISO = 12; -static const uint8_t SCK = 14; -static const uint8_t SS = 15; - -static const uint8_t TP_RST = 21; -static const uint8_t TP_INT = 19; -static const uint8_t TFT_BL = 18; -static const uint8_t TFT_CS = 15; -static const uint8_t TFT_DC = 27; +static const uint8_t MOSI = 13; +static const uint8_t MISO = 12; +static const uint8_t SCK = 14; +static const uint8_t SS = 15; + +static const uint8_t TP_RST = 21; +static const uint8_t TP_INT = 19; +static const uint8_t TFT_BL = 18; +static const uint8_t TFT_CS = 15; +static const uint8_t TFT_DC = 27; static const uint8_t TFT_RST = 32; -static const uint8_t SD_CS = 23; -static const uint8_t SD_CD = 22; +static const uint8_t SD_CS = 23; +static const uint8_t SD_CD = 22; #endif /* Pins_Arduino_h */ diff --git a/variants/esp32-devkit-lipo/pins_arduino.h b/variants/esp32-devkit-lipo/pins_arduino.h index fb715c0e79e..44dfe7cec8d 100644 --- a/variants/esp32-devkit-lipo/pins_arduino.h +++ b/variants/esp32-devkit-lipo/pins_arduino.h @@ -6,19 +6,19 @@ static const uint8_t TX = 1; static const uint8_t RX = 3; -#define TX1 33 // Ext1 pin 8 -#define RX1 25 // Ext1 pin 9 +#define TX1 33 // Ext1 pin 8 +#define RX1 25 // Ext1 pin 9 -#define TX2 19 // Ext2 pin 8 -#define RX2 18 // Ext2 pin 9 +#define TX2 19 // Ext2 pin 8 +#define RX2 18 // Ext2 pin 9 static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/esp32-evb/pins_arduino.h b/variants/esp32-evb/pins_arduino.h index 43691f02c7b..7a980667535 100644 --- a/variants/esp32-evb/pins_arduino.h +++ b/variants/esp32-evb/pins_arduino.h @@ -14,10 +14,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 13; static const uint8_t SCL = 16; -static const uint8_t SS = 17; -static const uint8_t MOSI = 2; -static const uint8_t MISO = 15; -static const uint8_t SCK = 14; +static const uint8_t SS = 17; +static const uint8_t MOSI = 2; +static const uint8_t MISO = 15; +static const uint8_t SCK = 14; #define BOARD_HAS_1BIT_SDMMC #define BOARD_MAX_SDMMC_FREQ SDMMC_FREQ_DEFAULT diff --git a/variants/esp32-gateway/pins_arduino.h b/variants/esp32-gateway/pins_arduino.h index 033e660f37d..3d2e75b44b6 100644 --- a/variants/esp32-gateway/pins_arduino.h +++ b/variants/esp32-gateway/pins_arduino.h @@ -3,28 +3,28 @@ #include -#if defined (ARDUINO_ESP32_GATEWAY_E) || defined (ARDUINO_ESP32_GATEWAY_F) -#define ETH_PHY_TYPE ETH_PHY_LAN8720 -#define ETH_PHY_ADDR 0 -#define ETH_PHY_MDC 23 -#define ETH_PHY_MDIO 18 -#define ETH_PHY_POWER 5 -#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT +#if defined(ARDUINO_ESP32_GATEWAY_E) || defined(ARDUINO_ESP32_GATEWAY_F) +#define ETH_PHY_TYPE ETH_PHY_LAN8720 +#define ETH_PHY_ADDR 0 +#define ETH_PHY_MDC 23 +#define ETH_PHY_MDIO 18 +#define ETH_PHY_POWER 5 +#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT #endif static const uint8_t LED_BUILTIN = 33; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 34; -static const uint8_t SCL = 16; // This is extention pin 11 -static const uint8_t SDA = 32; // This is extention pin 13 +static const uint8_t SCL = 16; // This is extension pin 11 +static const uint8_t SDA = 32; // This is extension pin 13 -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t TX = 1; static const uint8_t RX = 3; @@ -36,7 +36,7 @@ static const uint8_t A7 = 35; static const uint8_t T9 = 32; -#if defined (ARDUINO_ESP32_GATEWAY_F) +#if defined(ARDUINO_ESP32_GATEWAY_F) #define BOARD_HAS_1BIT_SDMMC #endif diff --git a/variants/esp32-poe-iso/pins_arduino.h b/variants/esp32-poe-iso/pins_arduino.h index fd16ab1c1ec..7f65fbb4638 100644 --- a/variants/esp32-poe-iso/pins_arduino.h +++ b/variants/esp32-poe-iso/pins_arduino.h @@ -3,15 +3,15 @@ #include -#define ETH_PHY_TYPE ETH_PHY_LAN8720 -#define ETH_PHY_ADDR 0 -#define ETH_PHY_MDC 23 -#define ETH_PHY_MDIO 18 -#define ETH_PHY_POWER 12 -#if defined BOARD_HAS_PSRAM // when PSRAM is enabled pins 16 and 17 are used for the PSRAM and alternative pins are used for respectively I2C SCL and Ethernet Clock GPIO -#define ETH_CLK_MODE ETH_CLOCK_GPIO0_OUT +#define ETH_PHY_TYPE ETH_PHY_LAN8720 +#define ETH_PHY_ADDR 0 +#define ETH_PHY_MDC 23 +#define ETH_PHY_MDIO 18 +#define ETH_PHY_POWER 12 +#if defined BOARD_HAS_PSRAM // when PSRAM is enabled pins 16 and 17 are used for the PSRAM and alternative pins are used for respectively I2C SCL and Ethernet Clock GPIO +#define ETH_CLK_MODE ETH_CLOCK_GPIO0_OUT #else -#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT +#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT #endif @@ -23,20 +23,20 @@ static const uint8_t RX = 3; #define TX1 4 #define RX1 36 -#define TX2 33 // ext2 pin 5 -#define RX2 35 // ext2 pin 3 +#define TX2 33 // ext2 pin 5 +#define RX2 35 // ext2 pin 3 static const uint8_t SDA = 13; -#if defined BOARD_HAS_PSRAM // when PSRAM is enabled pins 16 and 17 are used for the PSRAM and alternative pins are used for respectively I2C SCL and Ethernet Clock GPIO +#if defined BOARD_HAS_PSRAM // when PSRAM is enabled pins 16 and 17 are used for the PSRAM and alternative pins are used for respectively I2C SCL and Ethernet Clock GPIO static const uint8_t SCL = 33; #else static const uint8_t SCL = 16; #endif -static const uint8_t SS = 5; -static const uint8_t MOSI = 2; -static const uint8_t MISO = 15; -static const uint8_t SCK = 14; +static const uint8_t SS = 5; +static const uint8_t MOSI = 2; +static const uint8_t MISO = 15; +static const uint8_t SCK = 14; #define BOARD_HAS_1BIT_SDMMC diff --git a/variants/esp32-poe/pins_arduino.h b/variants/esp32-poe/pins_arduino.h index fd16ab1c1ec..7f65fbb4638 100644 --- a/variants/esp32-poe/pins_arduino.h +++ b/variants/esp32-poe/pins_arduino.h @@ -3,15 +3,15 @@ #include -#define ETH_PHY_TYPE ETH_PHY_LAN8720 -#define ETH_PHY_ADDR 0 -#define ETH_PHY_MDC 23 -#define ETH_PHY_MDIO 18 -#define ETH_PHY_POWER 12 -#if defined BOARD_HAS_PSRAM // when PSRAM is enabled pins 16 and 17 are used for the PSRAM and alternative pins are used for respectively I2C SCL and Ethernet Clock GPIO -#define ETH_CLK_MODE ETH_CLOCK_GPIO0_OUT +#define ETH_PHY_TYPE ETH_PHY_LAN8720 +#define ETH_PHY_ADDR 0 +#define ETH_PHY_MDC 23 +#define ETH_PHY_MDIO 18 +#define ETH_PHY_POWER 12 +#if defined BOARD_HAS_PSRAM // when PSRAM is enabled pins 16 and 17 are used for the PSRAM and alternative pins are used for respectively I2C SCL and Ethernet Clock GPIO +#define ETH_CLK_MODE ETH_CLOCK_GPIO0_OUT #else -#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT +#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT #endif @@ -23,20 +23,20 @@ static const uint8_t RX = 3; #define TX1 4 #define RX1 36 -#define TX2 33 // ext2 pin 5 -#define RX2 35 // ext2 pin 3 +#define TX2 33 // ext2 pin 5 +#define RX2 35 // ext2 pin 3 static const uint8_t SDA = 13; -#if defined BOARD_HAS_PSRAM // when PSRAM is enabled pins 16 and 17 are used for the PSRAM and alternative pins are used for respectively I2C SCL and Ethernet Clock GPIO +#if defined BOARD_HAS_PSRAM // when PSRAM is enabled pins 16 and 17 are used for the PSRAM and alternative pins are used for respectively I2C SCL and Ethernet Clock GPIO static const uint8_t SCL = 33; #else static const uint8_t SCL = 16; #endif -static const uint8_t SS = 5; -static const uint8_t MOSI = 2; -static const uint8_t MISO = 15; -static const uint8_t SCK = 14; +static const uint8_t SS = 5; +static const uint8_t MOSI = 2; +static const uint8_t MISO = 15; +static const uint8_t SCK = 14; #define BOARD_HAS_1BIT_SDMMC diff --git a/variants/esp32-sbc-fabgl/pins_arduino.h b/variants/esp32-sbc-fabgl/pins_arduino.h index 27ecc063483..3663de76cd4 100644 --- a/variants/esp32-sbc-fabgl/pins_arduino.h +++ b/variants/esp32-sbc-fabgl/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/esp32-trueverit-iot-driver-mkii/pins_arduino.h b/variants/esp32-trueverit-iot-driver-mkii/pins_arduino.h index 222046998dc..a04e73f24e5 100644 --- a/variants/esp32-trueverit-iot-driver-mkii/pins_arduino.h +++ b/variants/esp32-trueverit-iot-driver-mkii/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 18; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define TX1 12 diff --git a/variants/esp32-trueverit-iot-driver-mkiii/pins_arduino.h b/variants/esp32-trueverit-iot-driver-mkiii/pins_arduino.h index 0a468d58856..f1f49c73eb4 100644 --- a/variants/esp32-trueverit-iot-driver-mkiii/pins_arduino.h +++ b/variants/esp32-trueverit-iot-driver-mkiii/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 18; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define TX1 12 diff --git a/variants/esp32-trueverit-iot-driver/pins_arduino.h b/variants/esp32-trueverit-iot-driver/pins_arduino.h index da4ef3ce633..32f57291bed 100644 --- a/variants/esp32-trueverit-iot-driver/pins_arduino.h +++ b/variants/esp32-trueverit-iot-driver/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 18; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define TX1 12 diff --git a/variants/esp32/pins_arduino.h b/variants/esp32/pins_arduino.h index 27ecc063483..3663de76cd4 100644 --- a/variants/esp32/pins_arduino.h +++ b/variants/esp32/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/esp320/pins_arduino.h b/variants/esp320/pins_arduino.h index a7091aa09b2..cb9152a7aa8 100644 --- a/variants/esp320/pins_arduino.h +++ b/variants/esp320/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 5; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -13,9 +13,9 @@ static const uint8_t RX = 3; static const uint8_t SDA = 2; static const uint8_t SCL = 14; -static const uint8_t SS = 15; -static const uint8_t MOSI = 13; -static const uint8_t MISO = 12; -static const uint8_t SCK = 14; +static const uint8_t SS = 15; +static const uint8_t MOSI = 13; +static const uint8_t MISO = 12; +static const uint8_t SCK = 14; #endif /* Pins_Arduino_h */ diff --git a/variants/esp32_s3r8n16/pins_arduino.h b/variants/esp32_s3r8n16/pins_arduino.h index ba3f1908875..363a7e01f0f 100644 --- a/variants/esp32_s3r8n16/pins_arduino.h +++ b/variants/esp32_s3r8n16/pins_arduino.h @@ -5,8 +5,8 @@ #define USB_VID 0x303a #define USB_PID 0x1001 -#define USB_MANUFACTURER "4D Systems Pty Ltd" -#define USB_PRODUCT "4D Systems gen4-ESP32 16MB Modules (ESP32-S3R8n16)" +#define USB_MANUFACTURER "4D Systems Pty Ltd" +#define USB_PRODUCT "4D Systems gen4-ESP32 16MB Modules (ESP32-S3R8n16)" //#define USB_CLASS 2 static const uint8_t TX = 43; @@ -15,9 +15,9 @@ static const uint8_t RX = 44; static const uint8_t SDA = 17; static const uint8_t SCL = 18; -static const uint8_t SS = -1; // Modified elsewhere -static const uint8_t MOSI = -1; // Modified elsewhere -static const uint8_t MISO = -1; // Modified elsewhere -static const uint8_t SCK = -1; // Modified elsewhere +static const uint8_t SS = -1; // Modified elsewhere +static const uint8_t MOSI = -1; // Modified elsewhere +static const uint8_t MISO = -1; // Modified elsewhere +static const uint8_t SCK = -1; // Modified elsewhere #endif /* Pins_Arduino_h */ diff --git a/variants/esp32c2/pins_arduino.h b/variants/esp32c2/pins_arduino.h index 65978984e92..c69de6b938f 100644 --- a/variants/esp32c2/pins_arduino.h +++ b/variants/esp32c2/pins_arduino.h @@ -5,8 +5,8 @@ #include "soc/soc_caps.h" -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+13; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 13; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 20; @@ -15,10 +15,10 @@ static const uint8_t RX = 19; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 7; -static const uint8_t MOSI = 6; -static const uint8_t MISO = 5; -static const uint8_t SCK = 4; +static const uint8_t SS = 7; +static const uint8_t MOSI = 6; +static const uint8_t MISO = 5; +static const uint8_t SCK = 4; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/esp32c3-devkit-lipo/pins_arduino.h b/variants/esp32c3-devkit-lipo/pins_arduino.h index 7bed6a1ca3a..5459b893f27 100644 --- a/variants/esp32c3-devkit-lipo/pins_arduino.h +++ b/variants/esp32c3-devkit-lipo/pins_arduino.h @@ -5,24 +5,24 @@ #include "soc/soc_caps.h" static const uint8_t LED_BUILTIN = 8; -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t BUT_BUILTIN = 9; -#define BUILTIN_BUT BUT_BUILTIN // backward compatibility -#define BUT_BUILTIN BUT_BUILTIN // allow testing #ifdef BUT_BUILTIN +#define BUILTIN_BUT BUT_BUILTIN // backward compatibility +#define BUT_BUILTIN BUT_BUILTIN // allow testing #ifdef BUT_BUILTIN static const uint8_t TX = 21; static const uint8_t RX = 20; -// define I2C pins +// define I2C pins static const uint8_t SDA = 8; static const uint8_t SCL = 9; // define SPI pins -static const uint8_t SS = 7; -static const uint8_t MOSI = 6; -static const uint8_t MISO = 5; -static const uint8_t SCK = 4; +static const uint8_t SS = 7; +static const uint8_t MOSI = 6; +static const uint8_t MISO = 5; +static const uint8_t SCK = 4; // external power sense - disabled by default - check the schematic //static const uint8_t PWR_SENSE = 4; diff --git a/variants/esp32c3/pins_arduino.h b/variants/esp32c3/pins_arduino.h index 71318e27cf9..21a65f81ffe 100644 --- a/variants/esp32c3/pins_arduino.h +++ b/variants/esp32c3/pins_arduino.h @@ -4,10 +4,10 @@ #include #include "soc/soc_caps.h" -#define PIN_NEOPIXEL 8 +#define PIN_NEOPIXEL 8 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN @@ -19,10 +19,10 @@ static const uint8_t RX = 20; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 7; -static const uint8_t MOSI = 6; -static const uint8_t MISO = 5; -static const uint8_t SCK = 4; +static const uint8_t SS = 7; +static const uint8_t MOSI = 6; +static const uint8_t MISO = 5; +static const uint8_t SCK = 4; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/esp32c6-evb/pins_arduino.h b/variants/esp32c6-evb/pins_arduino.h index 5c266d190fd..a0b0d805ae7 100644 --- a/variants/esp32c6-evb/pins_arduino.h +++ b/variants/esp32c6-evb/pins_arduino.h @@ -5,22 +5,22 @@ #include "soc/soc_caps.h" static const uint8_t LED_BUILTIN = 8; -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t BUT_BUILTIN = 9; -#define BUILTIN_BUT BUT_BUILTIN // backward compatibility -#define BUT_BUILTIN BUT_BUILTIN // allow testing #ifdef BUT_BUILTIN +#define BUILTIN_BUT BUT_BUILTIN // backward compatibility +#define BUT_BUILTIN BUT_BUILTIN // allow testing #ifdef BUT_BUILTIN -#define REL1 10 -#define REL2 11 -#define REL3 22 -#define REL4 23 +#define REL1 10 +#define REL2 11 +#define REL3 22 +#define REL4 23 -#define DIN1 1 -#define DIN2 2 -#define DIN3 3 -#define DIN4 15 +#define DIN1 1 +#define DIN2 2 +#define DIN3 3 +#define DIN4 15 // available at UEXT and pUEXT + static const uint8_t TX1 = 5; @@ -29,10 +29,10 @@ static const uint8_t RX1 = 4; static const uint8_t SDA = 6; static const uint8_t SCL = 7; -static const uint8_t SS = 21; -static const uint8_t MOSI = 18; -static const uint8_t MISO = 20; -static const uint8_t SCK = 19; +static const uint8_t SS = 21; +static const uint8_t MOSI = 18; +static const uint8_t MISO = 20; +static const uint8_t SCK = 19; // available at UEXT and pUEXT - static const uint8_t TX = 16; diff --git a/variants/esp32c6/pins_arduino.h b/variants/esp32c6/pins_arduino.h index b551983d7fe..fc861cb64e8 100644 --- a/variants/esp32c6/pins_arduino.h +++ b/variants/esp32c6/pins_arduino.h @@ -4,10 +4,10 @@ #include #include "soc/soc_caps.h" -#define PIN_NEOPIXEL 8 +#define PIN_NEOPIXEL 8 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN @@ -19,10 +19,10 @@ static const uint8_t RX = 17; static const uint8_t SDA = 23; static const uint8_t SCL = 22; -static const uint8_t SS = 18; -static const uint8_t MOSI = 19; -static const uint8_t MISO = 20; -static const uint8_t SCK = 21; +static const uint8_t SS = 18; +static const uint8_t MOSI = 19; +static const uint8_t MISO = 20; +static const uint8_t SCK = 21; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/esp32da/pins_arduino.h b/variants/esp32da/pins_arduino.h index 7e8a27cbf54..212cb93a7e9 100644 --- a/variants/esp32da/pins_arduino.h +++ b/variants/esp32da/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/esp32h2-devkit-lipo/pins_arduino.h b/variants/esp32h2-devkit-lipo/pins_arduino.h index 25e547df6ac..6a75cabe7b8 100644 --- a/variants/esp32h2-devkit-lipo/pins_arduino.h +++ b/variants/esp32h2-devkit-lipo/pins_arduino.h @@ -4,10 +4,10 @@ #include #include "soc/soc_caps.h" -#define PIN_NEOPIXEL 8 +#define PIN_NEOPIXEL 8 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN @@ -22,10 +22,10 @@ static const uint8_t RX = 23; static const uint8_t SDA = 12; static const uint8_t SCL = 22; -static const uint8_t SS = 0; -static const uint8_t MOSI = 25; -static const uint8_t MISO = 11; -static const uint8_t SCK = 10; +static const uint8_t SS = 0; +static const uint8_t MOSI = 25; +static const uint8_t MISO = 11; +static const uint8_t SCK = 10; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/esp32h2/pins_arduino.h b/variants/esp32h2/pins_arduino.h index 93a02871090..5fc1bc44570 100644 --- a/variants/esp32h2/pins_arduino.h +++ b/variants/esp32h2/pins_arduino.h @@ -4,10 +4,10 @@ #include #include "soc/soc_caps.h" -#define PIN_NEOPIXEL 8 +#define PIN_NEOPIXEL 8 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN @@ -19,10 +19,10 @@ static const uint8_t RX = 23; static const uint8_t SDA = 12; static const uint8_t SCL = 22; -static const uint8_t SS = 0; -static const uint8_t MOSI = 25; -static const uint8_t MISO = 11; -static const uint8_t SCK = 10; +static const uint8_t SS = 0; +static const uint8_t MOSI = 25; +static const uint8_t MISO = 11; +static const uint8_t SCK = 10; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/esp32micromod/pins_arduino.h b/variants/esp32micromod/pins_arduino.h old mode 100755 new mode 100644 index b31f20dbea5..d93afb0f6ff --- a/variants/esp32micromod/pins_arduino.h +++ b/variants/esp32micromod/pins_arduino.h @@ -6,21 +6,21 @@ static const uint8_t TX = 1; static const uint8_t RX = 3; -#define TX1 17 -#define RX1 16 +#define TX1 17 +#define RX1 16 static const uint8_t SDA = 21; static const uint8_t SCL = 22; static const uint8_t I2C_INT = 4; -#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin) +#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin) static const uint8_t SDA1 = 26; static const uint8_t SCL1 = 25; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 34; static const uint8_t A1 = 35; @@ -63,7 +63,7 @@ static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #endif /* Pins_Arduino_h */ diff --git a/variants/esp32s2-devkit-lipo-usb/pins_arduino.h b/variants/esp32s2-devkit-lipo-usb/pins_arduino.h index 8f1106a0c1d..c59a8060025 100644 --- a/variants/esp32s2-devkit-lipo-usb/pins_arduino.h +++ b/variants/esp32s2-devkit-lipo-usb/pins_arduino.h @@ -4,13 +4,13 @@ #include #include "soc/soc_caps.h" -#define PIN_NEOPIXEL 18 +#define PIN_NEOPIXEL 18 #define RGB_BUILTIN PIN_NEOPIXEL #define RGB_BRIGHTNESS 64 static const uint8_t BUT_BUILTIN = 0; -#define BUILTIN_BUT BUT_BUILTIN // backward compatibility -#define BUT_BUILTIN BUT_BUILTIN // allow testing #ifdef LED_BUILTIN +#define BUILTIN_BUT BUT_BUILTIN // backward compatibility +#define BUT_BUILTIN BUT_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -18,10 +18,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 34; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SCK = 36; // external power sense - disabled by default - check the schematic //static const uint8_t PWR_SENSE = 7; diff --git a/variants/esp32s2-devkit-lipo/pins_arduino.h b/variants/esp32s2-devkit-lipo/pins_arduino.h index b041e2b3a73..0b8659b4ae3 100644 --- a/variants/esp32s2-devkit-lipo/pins_arduino.h +++ b/variants/esp32s2-devkit-lipo/pins_arduino.h @@ -4,26 +4,26 @@ #include #include "soc/soc_caps.h" -#define PIN_NEOPIXEL 18 +#define PIN_NEOPIXEL 18 #define RGB_BUILTIN PIN_NEOPIXEL #define RGB_BRIGHTNESS 64 static const uint8_t BUT_BUILTIN = 0; -#define BUILTIN_BUT BUT_BUILTIN // backward compatibility -#define BUT_BUILTIN BUT_BUILTIN // allow testing #ifdef BUT_BUILTIN +#define BUILTIN_BUT BUT_BUILTIN // backward compatibility +#define BUT_BUILTIN BUT_BUILTIN // allow testing #ifdef BUT_BUILTIN static const uint8_t TX = 43; static const uint8_t RX = 44; -// define I2C pins +// define I2C pins static const uint8_t SDA = 8; static const uint8_t SCL = 9; // define SPI pins -static const uint8_t SS = 34; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SCK = 36; // external power sense - disabled by default - check the schematic //static const uint8_t PWR_SENSE = 7; diff --git a/variants/esp32s2/pins_arduino.h b/variants/esp32s2/pins_arduino.h index ea68934a69b..19af0cfb443 100644 --- a/variants/esp32s2/pins_arduino.h +++ b/variants/esp32s2/pins_arduino.h @@ -5,12 +5,12 @@ #include "soc/soc_caps.h" // GPIO pin for Saola-1 & DevKitM-1 = 18 -#define PIN_NEOPIXEL 18 +#define PIN_NEOPIXEL 18 // GPIO pin for Kaluga = 45 //#define PIN_NEOPIXEL 45 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN @@ -22,10 +22,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 34; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/esp32s2thing_plus/pins_arduino.h b/variants/esp32s2thing_plus/pins_arduino.h index d5c4510aa5d..e28446e0843 100644 --- a/variants/esp32s2thing_plus/pins_arduino.h +++ b/variants/esp32s2thing_plus/pins_arduino.h @@ -10,7 +10,7 @@ #define USB_SERIAL "" static const uint8_t LED_BUILTIN = 13; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 43; @@ -22,10 +22,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 1; static const uint8_t SCL = 2; -static const uint8_t SS = 42; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 42; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 17; static const uint8_t A1 = 18; diff --git a/variants/esp32s2usb/pins_arduino.h b/variants/esp32s2usb/pins_arduino.h index 222c1de75e2..30c1f86c97e 100644 --- a/variants/esp32s2usb/pins_arduino.h +++ b/variants/esp32s2usb/pins_arduino.h @@ -4,20 +4,20 @@ #include // Default USB Settings -#define USB_VID 0x303A -#define USB_PID 0x0003 -#define USB_MANUFACTURER "Espressif Systems" -#define USB_PRODUCT "ESP32-S2-USB" -#define USB_SERIAL "0" -#define USB_WEBUSB_ENABLED false -#define USB_WEBUSB_URL "https://docs.espressif.com/projects/arduino-esp32/en/latest/_static/webusb.html" +#define USB_VID 0x303A +#define USB_PID 0x0003 +#define USB_MANUFACTURER "Espressif Systems" +#define USB_PRODUCT "ESP32-S2-USB" +#define USB_SERIAL "0" +#define USB_WEBUSB_ENABLED false +#define USB_WEBUSB_URL "https://docs.espressif.com/projects/arduino-esp32/en/latest/_static/webusb.html" // Default USB FirmwareMSC Settings -#define USB_FW_MSC_VENDOR_ID "ESP32-S2" //max 8 chars -#define USB_FW_MSC_PRODUCT_ID "Firmware MSC" //max 16 chars -#define USB_FW_MSC_PRODUCT_REVISION "1.23" //max 4 chars -#define USB_FW_MSC_VOLUME_NAME "S2-Firmware" //max 11 chars -#define USB_FW_MSC_SERIAL_NUMBER 0x00000000 +#define USB_FW_MSC_VENDOR_ID "ESP32-S2" //max 8 chars +#define USB_FW_MSC_PRODUCT_ID "Firmware MSC" //max 16 chars +#define USB_FW_MSC_PRODUCT_REVISION "1.23" //max 4 chars +#define USB_FW_MSC_VOLUME_NAME "S2-Firmware" //max 11 chars +#define USB_FW_MSC_SERIAL_NUMBER 0x00000000 static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -25,10 +25,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 34; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/esp32s3-devkit-lipo/pins_arduino.h b/variants/esp32s3-devkit-lipo/pins_arduino.h index bbad39f745f..3e1ae6f2381 100644 --- a/variants/esp32s3-devkit-lipo/pins_arduino.h +++ b/variants/esp32s3-devkit-lipo/pins_arduino.h @@ -8,12 +8,12 @@ #define USB_PID 0x1001 static const uint8_t LED_BUILTIN = 38; -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t BUT_BUILTIN = 0; -#define BUILTIN_BUT BUT_BUILTIN // backward compatibility -#define BUT_BUILTIN BUT_BUILTIN // allow testing #ifdef BUT_BUILTIN +#define BUILTIN_BUT BUT_BUILTIN // backward compatibility +#define BUT_BUILTIN BUT_BUILTIN // allow testing #ifdef BUT_BUILTIN static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -25,10 +25,10 @@ static const uint8_t RX1 = 18; static const uint8_t SDA = 48; static const uint8_t SCL = 47; -static const uint8_t SS = 10; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 13; -static const uint8_t SCK = 12; +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; // available at pUEXT - // external power sense diff --git a/variants/esp32s3/pins_arduino.h b/variants/esp32s3/pins_arduino.h index 339b47df0b4..d81006d9da8 100644 --- a/variants/esp32s3/pins_arduino.h +++ b/variants/esp32s3/pins_arduino.h @@ -10,10 +10,10 @@ // Some boards have too low voltage on this pin (board design bug) // Use different pin with 3V and connect with 48 // and change this setup for the chosen pin (for example 38) -#define PIN_NEOPIXEL 48 +#define PIN_NEOPIXEL 48 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN @@ -26,10 +26,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 10; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 13; -static const uint8_t SCK = 12; +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/esp32s3_powerfeather/pins_arduino.h b/variants/esp32s3_powerfeather/pins_arduino.h index 8d1c3cbd06a..c766dd14d11 100644 --- a/variants/esp32s3_powerfeather/pins_arduino.h +++ b/variants/esp32s3_powerfeather/pins_arduino.h @@ -3,53 +3,53 @@ #include -#define USB_VID 0x303A -#define USB_PID 0x81BB -#define USB_MANUFACTURER "PowerFeather" -#define USB_PRODUCT "ESP32-S3 PowerFeather" -#define USB_SERIAL "" +#define USB_VID 0x303A +#define USB_PID 0x81BB +#define USB_MANUFACTURER "PowerFeather" +#define USB_PRODUCT "ESP32-S3 PowerFeather" +#define USB_SERIAL "" static const uint8_t ALARM = 21; -static const uint8_t INT = 5; +static const uint8_t INT = 5; -static const uint8_t LED = 46; -static const uint8_t BTN = 0; -static const uint8_t EN = 7; +static const uint8_t LED = 46; +static const uint8_t BTN = 0; +static const uint8_t EN = 7; -static const uint8_t TX = 44; -static const uint8_t RX = 42; -static const uint8_t TX0 = 43; +static const uint8_t TX = 44; +static const uint8_t RX = 42; +static const uint8_t TX0 = 43; -static const uint8_t SS = -1; -static const uint8_t MISO = 41; -static const uint8_t MOSI = 40; -static const uint8_t SCK = 39; +static const uint8_t SS = -1; +static const uint8_t MISO = 41; +static const uint8_t MOSI = 40; +static const uint8_t SCK = 39; -static const uint8_t SCL = 36; -static const uint8_t SDA = 35; +static const uint8_t SCL = 36; +static const uint8_t SDA = 35; #define WIRE1_PIN_DEFINED 1 -static const uint8_t SCL1 = 48; -static const uint8_t SDA1 = 47; - -static const uint8_t A0 = 10; -static const uint8_t A1 = 9; -static const uint8_t A2 = 8; -static const uint8_t A3 = 3; -static const uint8_t A4 = 2; -static const uint8_t A5 = 1; - -static const uint8_t D5 = 15; -static const uint8_t D6 = 16; -static const uint8_t D7 = 37; -static const uint8_t D8 = 6; -static const uint8_t D9 = 17; -static const uint8_t D10 = 18; -static const uint8_t D11 = 45; -static const uint8_t D12 = 12; -static const uint8_t D13 = 11; +static const uint8_t SCL1 = 48; +static const uint8_t SDA1 = 47; + +static const uint8_t A0 = 10; +static const uint8_t A1 = 9; +static const uint8_t A2 = 8; +static const uint8_t A3 = 3; +static const uint8_t A4 = 2; +static const uint8_t A5 = 1; + +static const uint8_t D5 = 15; +static const uint8_t D6 = 16; +static const uint8_t D7 = 37; +static const uint8_t D8 = 6; +static const uint8_t D9 = 17; +static const uint8_t D10 = 18; +static const uint8_t D11 = 45; +static const uint8_t D12 = 12; +static const uint8_t D13 = 11; #define LED_BUILTIN 46 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #endif /* Pins_Arduino_h */ diff --git a/variants/esp32s3box/pins_arduino.h b/variants/esp32s3box/pins_arduino.h index 115ded2a2ec..5e9261d3140 100644 --- a/variants/esp32s3box/pins_arduino.h +++ b/variants/esp32s3box/pins_arduino.h @@ -12,10 +12,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 41; static const uint8_t SCL = 40; -static const uint8_t SS = 10; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 13; -static const uint8_t SCK = 12; +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; static const uint8_t A8 = 9; static const uint8_t A9 = 10; @@ -32,30 +32,30 @@ static const uint8_t T13 = 13; static const uint8_t T14 = 14; // Wire1 for ES7210 MIC ADC, ES8311 I2S DAC, ICM-42607-P IMU and TT21100 Touch Panel -#define I2C_SDA 8 -#define I2C_SCL 18 - -#define ES7210_ADDR 0x40 //MIC ADC -#define ES8311_ADDR 0x18 //I2S DAC -#define ICM42607P_ADDR 0x68 //IMU -#define TT21100_ADDR 0x24 //Touch Panel - -#define TFT_DC 4 -#define TFT_CS 5 -#define TFT_MOSI 6 -#define TFT_CLK 7 -#define TFT_MISO 0 -#define TFT_BL 45 -#define TFT_RST 48 - -#define I2S_LRCK 47 -#define I2S_MCLK 2 -#define I2S_SCLK 17 -#define I2S_SDIN 16 -#define I2S_DOUT 15 - -#define PA_PIN 46 //Audio Amp Power -#define MUTE_PIN 1 //MUTE Button -#define TS_IRQ 3 //Touch Screen IRQ +#define I2C_SDA 8 +#define I2C_SCL 18 + +#define ES7210_ADDR 0x40 //MIC ADC +#define ES8311_ADDR 0x18 //I2S DAC +#define ICM42607P_ADDR 0x68 //IMU +#define TT21100_ADDR 0x24 //Touch Panel + +#define TFT_DC 4 +#define TFT_CS 5 +#define TFT_MOSI 6 +#define TFT_CLK 7 +#define TFT_MISO 0 +#define TFT_BL 45 +#define TFT_RST 48 + +#define I2S_LRCK 47 +#define I2S_MCLK 2 +#define I2S_SCLK 17 +#define I2S_SDIN 16 +#define I2S_DOUT 15 + +#define PA_PIN 46 //Audio Amp Power +#define MUTE_PIN 1 //MUTE Button +#define TS_IRQ 3 //Touch Screen IRQ #endif /* Pins_Arduino_h */ diff --git a/variants/esp32s3camlcd/pins_arduino.h b/variants/esp32s3camlcd/pins_arduino.h index 9580091dd3a..5ad903915ce 100644 --- a/variants/esp32s3camlcd/pins_arduino.h +++ b/variants/esp32s3camlcd/pins_arduino.h @@ -12,52 +12,52 @@ static const uint8_t RX = 44; static const uint8_t SDA = 17; static const uint8_t SCL = 18; -static const uint8_t SS = 10; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 13; -static const uint8_t SCK = 12; +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; // Wire1 for Cam and TS -#define I2C_SDA 17 -#define I2C_SCL 18 - -#define PWDN_GPIO_NUM -1 -#define RESET_GPIO_NUM -1 -#define XCLK_GPIO_NUM 40 -#define SIOD_GPIO_NUM 17 -#define SIOC_GPIO_NUM 18 -#define Y9_GPIO_NUM 39 -#define Y8_GPIO_NUM 41 -#define Y7_GPIO_NUM 42 -#define Y6_GPIO_NUM 12 -#define Y5_GPIO_NUM 3 -#define Y4_GPIO_NUM 14 -#define Y3_GPIO_NUM 47 -#define Y2_GPIO_NUM 13 -#define VSYNC_GPIO_NUM 21 -#define HREF_GPIO_NUM 38 -#define PCLK_GPIO_NUM 11 - -#define TFT_FREQ 40000000 -#define TFT_BITS 8 -#define TFT_WIDTH 480 -#define TFT_HEIGHT 320 -#define TFT_WR 4 -#define TFT_DC 2 -#define TFT_D0 45 -#define TFT_D1 16 -#define TFT_D2 15 -#define TFT_D3 10 -#define TFT_D4 8 -#define TFT_D5 7 -#define TFT_D6 6 -#define TFT_D7 5 - -#define SDMMC_CMD 20 -#define SDMMC_CLK 9 -#define SDMMC_DATA 19 - -#define MIC_CLK 0 -#define MIC_DATA 1 +#define I2C_SDA 17 +#define I2C_SCL 18 + +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 40 +#define SIOD_GPIO_NUM 17 +#define SIOC_GPIO_NUM 18 +#define Y9_GPIO_NUM 39 +#define Y8_GPIO_NUM 41 +#define Y7_GPIO_NUM 42 +#define Y6_GPIO_NUM 12 +#define Y5_GPIO_NUM 3 +#define Y4_GPIO_NUM 14 +#define Y3_GPIO_NUM 47 +#define Y2_GPIO_NUM 13 +#define VSYNC_GPIO_NUM 21 +#define HREF_GPIO_NUM 38 +#define PCLK_GPIO_NUM 11 + +#define TFT_FREQ 40000000 +#define TFT_BITS 8 +#define TFT_WIDTH 480 +#define TFT_HEIGHT 320 +#define TFT_WR 4 +#define TFT_DC 2 +#define TFT_D0 45 +#define TFT_D1 16 +#define TFT_D2 15 +#define TFT_D3 10 +#define TFT_D4 8 +#define TFT_D5 7 +#define TFT_D6 6 +#define TFT_D7 5 + +#define SDMMC_CMD 20 +#define SDMMC_CLK 9 +#define SDMMC_DATA 19 + +#define MIC_CLK 0 +#define MIC_DATA 1 #endif /* Pins_Arduino_h */ diff --git a/variants/esp32s3usbotg/pins_arduino.h b/variants/esp32s3usbotg/pins_arduino.h index 1983c45d1a4..0fcdbe13249 100644 --- a/variants/esp32s3usbotg/pins_arduino.h +++ b/variants/esp32s3usbotg/pins_arduino.h @@ -12,10 +12,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 45; static const uint8_t SCL = 46; -static const uint8_t SS = 34; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -25,57 +25,57 @@ static const uint8_t T3 = 3; // SDCARD Slot #define BOARD_HAS_SDMMC -#define SDMMC_D2 33 // SDMMC Data2 -#define SDMMC_D3 34 // SDMMC Data3 / SPI CS -#define SDMMC_CMD 35 // SDMMC CMD / SPI MOSI -#define SDMMC_CLK 36 // SDMMC CLK / SPI SCK -#define SDMMC_D0 37 // SDMMC Data0 / SPI MISO -#define SDMMC_D1 38 // SDMMC Data1 +#define SDMMC_D2 33 // SDMMC Data2 +#define SDMMC_D3 34 // SDMMC Data3 / SPI CS +#define SDMMC_CMD 35 // SDMMC CMD / SPI MOSI +#define SDMMC_CLK 36 // SDMMC CLK / SPI SCK +#define SDMMC_D0 37 // SDMMC Data0 / SPI MISO +#define SDMMC_D1 38 // SDMMC Data1 #define BOARD_MAX_SDMMC_FREQ SDMMC_FREQ_DEFAULT // 240x240 LCD #define BOARD_HAS_SPI_LCD -#define LCD_MODEL ST7789 -#define LCD_WIDTH 240 -#define LCD_HEIGHT 240 // *RAM height is actually 320! -#define LCD_MISO -1 // LCD Does not use MISO. -#define LCD_DC 4 // Used to switch data and command status. -#define LCD_CS 5 // used to enable LCD, low level to enable. -#define LCD_CLK 6 // LCD SPI Clock. -#define LCD_MOSI 7 // LCD SPI MOSI. -#define LCD_RST 8 // used to reset LCD, low level to reset. -#define LCD_BL 9 // LCD backlight control. +#define LCD_MODEL ST7789 +#define LCD_WIDTH 240 +#define LCD_HEIGHT 240 // *RAM height is actually 320! +#define LCD_MISO -1 // LCD Does not use MISO. +#define LCD_DC 4 // Used to switch data and command status. +#define LCD_CS 5 // used to enable LCD, low level to enable. +#define LCD_CLK 6 // LCD SPI Clock. +#define LCD_MOSI 7 // LCD SPI MOSI. +#define LCD_RST 8 // used to reset LCD, low level to reset. +#define LCD_BL 9 // LCD backlight control. // Buttons -#define BUTTON_OK 0 // OK button, low level when pressed. -#define BUTTON_UP 10 // UP button, low level when pressed. -#define BUTTON_DOWN 11 // Down button, low level when pressed. -#define BUTTON_MENU 14 // Menu button, low level when pressed. +#define BUTTON_OK 0 // OK button, low level when pressed. +#define BUTTON_UP 10 // UP button, low level when pressed. +#define BUTTON_DOWN 11 // Down button, low level when pressed. +#define BUTTON_MENU 14 // Menu button, low level when pressed. // LEDs -#define LED_GREEN 15 // the light is lit when set high level. -#define LED_YELLOW 16 // the light is lit when set high level. +#define LED_GREEN 15 // the light is lit when set high level. +#define LED_YELLOW 16 // the light is lit when set high level. // Board Controls -#define DEV_VBUS_EN 12 // High level to enable DEV_VBUS power supply. -#define BOOST_EN 13 // High level to enable Battery Boost circuit. -#define LIMIT_EN 17 // Enable USB_HOST current limiting IC, high level enable. -#define USB_HOST_EN 18 // Used to switch the USB interface. When high level, the USB_HOST interface is enabled. When low level, the USB_DEV interface is enabled. +#define DEV_VBUS_EN 12 // High level to enable DEV_VBUS power supply. +#define BOOST_EN 13 // High level to enable Battery Boost circuit. +#define LIMIT_EN 17 // Enable USB_HOST current limiting IC, high level enable. +#define USB_HOST_EN 18 // Used to switch the USB interface. When high level, the USB_HOST interface is enabled. When low level, the USB_DEV interface is enabled. // Board Sensors -#define OVER_CURRENT 21 // Current overrun signal, high level means overrun. -#define HOST_VOLTS 1 // USB_DEV voltage monitoring, ADC1 channel 0. actual_v = value_v * 3.7 -#define BAT_VOLTS 2 // Battery voltage monitoring, ADC1 channel 1. actual_v = value_v * 2 +#define OVER_CURRENT 21 // Current overrun signal, high level means overrun. +#define HOST_VOLTS 1 // USB_DEV voltage monitoring, ADC1 channel 0. actual_v = value_v * 3.7 +#define BAT_VOLTS 2 // Battery voltage monitoring, ADC1 channel 1. actual_v = value_v * 2 // USB Port -#define USB_DN 19 // USB D- -#define USB_DP 20 // USB D+ +#define USB_DN 19 // USB D- +#define USB_DP 20 // USB D+ // Bottom header -#define MTCK 39 -#define MTDO 40 -#define MTDI 41 -#define MTMS 42 +#define MTCK 39 +#define MTDO 40 +#define MTDI 41 +#define MTMS 42 // #define FREE_6 3 // Idle, can be customized. // #define FREE_4 26 // Idle, can be customized. // #define FREE_1 45 // Idle, can be customized. @@ -83,7 +83,9 @@ static const uint8_t T3 = 3; // #define FREE_5 47 // Idle, can be customized. // #define FREE_3 48 // Idle, can be customized. -typedef enum { USB_HOST_POWER_OFF, USB_HOST_POWER_VBUS, USB_HOST_POWER_BAT } UsbHostPower_t; +typedef enum { USB_HOST_POWER_OFF, + USB_HOST_POWER_VBUS, + USB_HOST_POWER_BAT } UsbHostPower_t; void usbHostPower(UsbHostPower_t mode); void usbHostEnable(bool enable); diff --git a/variants/esp32s3usbotg/variant.cpp b/variants/esp32s3usbotg/variant.cpp index f5f24fdac2a..a8de800f90a 100644 --- a/variants/esp32s3usbotg/variant.cpp +++ b/variants/esp32s3usbotg/variant.cpp @@ -1,46 +1,52 @@ #include "Arduino.h" -void usbHostPower(UsbHostPower_t mode){ - static UsbHostPower_t m = USB_HOST_POWER_OFF; - if(m == mode){ - return; - } - if(mode == USB_HOST_POWER_OFF){ - digitalWrite(LIMIT_EN, LOW); - if(m == USB_HOST_POWER_VBUS){ - digitalWrite(DEV_VBUS_EN, LOW); - } else if(m == USB_HOST_POWER_BAT){ - digitalWrite(BOOST_EN, LOW); - } - } else if(mode == USB_HOST_POWER_VBUS){ - if(m == USB_HOST_POWER_BAT){ - digitalWrite(BOOST_EN, LOW); - } - digitalWrite(DEV_VBUS_EN, HIGH); - } else if(mode == USB_HOST_POWER_BAT){ - if(m == USB_HOST_POWER_VBUS){ - digitalWrite(DEV_VBUS_EN, LOW); - } - digitalWrite(BOOST_EN, HIGH); - } - if(mode != USB_HOST_POWER_OFF){ - digitalWrite(LIMIT_EN, HIGH); - } - m = mode; +void usbHostPower(UsbHostPower_t mode) { + static UsbHostPower_t m = USB_HOST_POWER_OFF; + if (m == mode) { + return; + } + if (mode == USB_HOST_POWER_OFF) { + digitalWrite(LIMIT_EN, LOW); + if (m == USB_HOST_POWER_VBUS) { + digitalWrite(DEV_VBUS_EN, LOW); + } else if (m == USB_HOST_POWER_BAT) { + digitalWrite(BOOST_EN, LOW); + } + } else if (mode == USB_HOST_POWER_VBUS) { + if (m == USB_HOST_POWER_BAT) { + digitalWrite(BOOST_EN, LOW); + } + digitalWrite(DEV_VBUS_EN, HIGH); + } else if (mode == USB_HOST_POWER_BAT) { + if (m == USB_HOST_POWER_VBUS) { + digitalWrite(DEV_VBUS_EN, LOW); + } + digitalWrite(BOOST_EN, HIGH); + } + if (mode != USB_HOST_POWER_OFF) { + digitalWrite(LIMIT_EN, HIGH); + } + m = mode; } -void usbHostEnable(bool enable){ - digitalWrite(USB_HOST_EN, enable); +void usbHostEnable(bool enable) { + digitalWrite(USB_HOST_EN, enable); } -extern "C" void initVariant(void){ - // Route USB to Device Side - pinMode(BOOST_EN, OUTPUT); digitalWrite(BOOST_EN, LOW); - pinMode(LIMIT_EN, OUTPUT); digitalWrite(LIMIT_EN, LOW); - pinMode(DEV_VBUS_EN, OUTPUT); digitalWrite(DEV_VBUS_EN, LOW); - pinMode(USB_HOST_EN, OUTPUT); digitalWrite(USB_HOST_EN, LOW); +extern "C" void initVariant(void) { + // Route USB to Device Side + pinMode(BOOST_EN, OUTPUT); + digitalWrite(BOOST_EN, LOW); + pinMode(LIMIT_EN, OUTPUT); + digitalWrite(LIMIT_EN, LOW); + pinMode(DEV_VBUS_EN, OUTPUT); + digitalWrite(DEV_VBUS_EN, LOW); + pinMode(USB_HOST_EN, OUTPUT); + digitalWrite(USB_HOST_EN, LOW); - // Turn Off LCD - pinMode(LCD_RST, OUTPUT); digitalWrite(LCD_RST, LOW); - pinMode(LCD_BL, OUTPUT); digitalWrite(LCD_BL, LOW); + // Turn Off LCD + pinMode(LCD_RST, OUTPUT); + digitalWrite(LCD_RST, LOW); + pinMode(LCD_BL, OUTPUT); + digitalWrite(LCD_BL, LOW); } diff --git a/variants/esp32thing/pins_arduino.h b/variants/esp32thing/pins_arduino.h index 68178cc2296..66f81860f5a 100644 --- a/variants/esp32thing/pins_arduino.h +++ b/variants/esp32thing/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 5; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -15,10 +15,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 2; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 2; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/esp32thing_plus/pins_arduino.h b/variants/esp32thing_plus/pins_arduino.h index 9b4b1e25147..b32e554ec91 100644 --- a/variants/esp32thing_plus/pins_arduino.h +++ b/variants/esp32thing_plus/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 13; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 17; @@ -16,13 +16,13 @@ static const uint8_t RX = 16; static const uint8_t SDA = 23; static const uint8_t SCL = 22; -static const uint8_t SS = 33; -static const uint8_t MOSI = 18; -static const uint8_t MISO = 19; -static const uint8_t SCK = 5; +static const uint8_t SS = 33; +static const uint8_t MOSI = 18; +static const uint8_t MISO = 19; +static const uint8_t SCK = 5; // mapping to match other feathers and also in order -static const uint8_t A0 = 26; +static const uint8_t A0 = 26; static const uint8_t A1 = 25; static const uint8_t A2 = 34; static const uint8_t A3 = 39; diff --git a/variants/esp32thing_plus_c/pins_arduino.h b/variants/esp32thing_plus_c/pins_arduino.h index fbfe934a698..b86b12a8d1f 100644 --- a/variants/esp32thing_plus_c/pins_arduino.h +++ b/variants/esp32thing_plus_c/pins_arduino.h @@ -5,11 +5,11 @@ #include "soc/soc_caps.h" static const uint8_t LED_BUILTIN = 13; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() -static const uint8_t RGB_BUILTIN = SOC_GPIO_PIN_COUNT+2; +static const uint8_t RGB_BUILTIN = SOC_GPIO_PIN_COUNT + 2; #define RGB_BUILTIN RGB_BUILTIN // necessary to make digitalWrite/digitalMode find it #define RGB_BRIGHTNESS 64 @@ -22,12 +22,12 @@ static const uint8_t RX = 16; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 15; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 15; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; -static const uint8_t A0 = 26; +static const uint8_t A0 = 26; static const uint8_t A1 = 25; static const uint8_t A2 = 34; static const uint8_t A3 = 39; diff --git a/variants/esp32vn-iot-uno/pins_arduino.h b/variants/esp32vn-iot-uno/pins_arduino.h index fd196bdf34f..087c87a4c71 100644 --- a/variants/esp32vn-iot-uno/pins_arduino.h +++ b/variants/esp32vn-iot-uno/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/esp_c3_m1_i_kit/pins_arduino.h b/variants/esp_c3_m1_i_kit/pins_arduino.h index 8f5f433fea3..01ee56d4230 100644 --- a/variants/esp_c3_m1_i_kit/pins_arduino.h +++ b/variants/esp_c3_m1_i_kit/pins_arduino.h @@ -12,13 +12,13 @@ static const uint8_t LED_WARM = 18; static const uint8_t LED_COLD = 19; -// RGB LED +// RGB LED static const uint8_t LED_RED = 3; static const uint8_t LED_GREEN = 4; static const uint8_t LED_BLUE = 5; static const uint8_t LED_BUILTIN = LED_WARM; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // Standard ESP32-C3 GPIOs @@ -28,10 +28,10 @@ static const uint8_t RX = 20; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 7; -static const uint8_t MOSI = 6; -static const uint8_t MISO = 5; -static const uint8_t SCK = 4; +static const uint8_t SS = 7; +static const uint8_t MOSI = 6; +static const uint8_t MISO = 5; +static const uint8_t SCK = 4; static const uint8_t A0 = 0; static const uint8_t A1 = 1; @@ -40,4 +40,4 @@ static const uint8_t A3 = 3; static const uint8_t A4 = 4; static const uint8_t A5 = 5; -#endif /* Pins_Arduino_h */ +#endif /* Pins_Arduino_h */ diff --git a/variants/espea32/pins_arduino.h b/variants/espea32/pins_arduino.h index 2a27157366f..bc0d7a1f772 100644 --- a/variants/espea32/pins_arduino.h +++ b/variants/espea32/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 5; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -15,10 +15,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/espectro32/pins_arduino.h b/variants/espectro32/pins_arduino.h index 449b79247ac..7f6dbb18e32 100644 --- a/variants/espectro32/pins_arduino.h +++ b/variants/espectro32/pins_arduino.h @@ -5,10 +5,10 @@ #ifndef ESPECTRO32_VERSION #define ESPECTRO32_VERSION 1 -#endif +#endif static const uint8_t LED_BUILTIN = 15; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -18,10 +18,10 @@ static const uint8_t SDA = 21; static const uint8_t SCL = 22; static const uint8_t SD_SS = 33; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/espino32/pins_arduino.h b/variants/espino32/pins_arduino.h index 571912b7ee9..840fd863629 100644 --- a/variants/espino32/pins_arduino.h +++ b/variants/espino32/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 16; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t BUILTIN_KEY = 0; @@ -15,10 +15,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/feather_esp32/pins_arduino.h b/variants/feather_esp32/pins_arduino.h index bc7c2dc6656..bd85ed5e526 100644 --- a/variants/feather_esp32/pins_arduino.h +++ b/variants/feather_esp32/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 13; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 17; @@ -16,13 +16,13 @@ static const uint8_t RX = 16; static const uint8_t SDA = 23; static const uint8_t SCL = 22; -static const uint8_t SS = 33; -static const uint8_t MOSI = 18; -static const uint8_t MISO = 19; -static const uint8_t SCK = 5; +static const uint8_t SS = 33; +static const uint8_t MOSI = 18; +static const uint8_t MISO = 19; +static const uint8_t SCK = 5; // mapping to match other feathers and also in order -static const uint8_t A0 = 26; +static const uint8_t A0 = 26; static const uint8_t A1 = 25; static const uint8_t A2 = 34; static const uint8_t A3 = 39; diff --git a/variants/firebeetle32/pins_arduino.h b/variants/firebeetle32/pins_arduino.h index 7fd4a527975..60a35d603c1 100644 --- a/variants/firebeetle32/pins_arduino.h +++ b/variants/firebeetle32/pins_arduino.h @@ -6,7 +6,7 @@ typedef unsigned char uint8_t; static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -15,10 +15,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t D0 = 3; static const uint8_t D1 = 1; diff --git a/variants/fm-devkit/pins_arduino.h b/variants/fm-devkit/pins_arduino.h index b0cc94038f6..63a6d866390 100644 --- a/variants/fm-devkit/pins_arduino.h +++ b/variants/fm-devkit/pins_arduino.h @@ -1,47 +1,47 @@ -#ifndef Pins_Arduino_h -#define Pins_Arduino_h - -#include - -static const uint8_t TX = 1; -static const uint8_t RX = 3; - -// IO -static const uint8_t LED_BUILTIN = 5; -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -static const uint8_t SW1 = 4; -static const uint8_t SW2 = 18; -static const uint8_t SW3 = 19; -static const uint8_t SW4 = 21; - -//I2S DAC -static const uint8_t I2S_MCLK = 2; // CLOCK must be an integer multiplier of SCLK -static const uint8_t I2S_LRCLK = 25; // LRCLK -static const uint8_t I2S_SCLK = 26; // SCLK - Fs (44100 Hz) -static const uint8_t I2S_DOUT = 22; // DATA - -//GPIO -static const uint8_t D0 = 34; // GPI - Input Only -static const uint8_t D1 = 35; // GPI - Input Only -static const uint8_t D2 = 32; // GPO - Output Only -static const uint8_t D3 = 33; // GPO - Output Only -static const uint8_t D4 = 27; -static const uint8_t D5 = 14; -static const uint8_t D6 = 12; -static const uint8_t D7 = 13; -static const uint8_t D8 = 15; -static const uint8_t D9 = 23; -static const uint8_t D10 = 0; - -// I2C BUS, 2k2 hardware pull-ups -static const uint8_t SDA = 16; -static const uint8_t SCL = 17; - -// SPI - unused but you can create your own definition in your sketch -static const int8_t SCK = -1; -static const int8_t MISO = -1; -static const int8_t MOSI = -1; -static const int8_t SS = -1; - -#endif /* Pins_Arduino_h */ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +static const uint8_t TX = 1; +static const uint8_t RX = 3; + +// IO +static const uint8_t LED_BUILTIN = 5; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +static const uint8_t SW1 = 4; +static const uint8_t SW2 = 18; +static const uint8_t SW3 = 19; +static const uint8_t SW4 = 21; + +//I2S DAC +static const uint8_t I2S_MCLK = 2; // CLOCK must be an integer multiplier of SCLK +static const uint8_t I2S_LRCLK = 25; // LRCLK +static const uint8_t I2S_SCLK = 26; // SCLK - Fs (44100 Hz) +static const uint8_t I2S_DOUT = 22; // DATA + +//GPIO +static const uint8_t D0 = 34; // GPI - Input Only +static const uint8_t D1 = 35; // GPI - Input Only +static const uint8_t D2 = 32; // GPO - Output Only +static const uint8_t D3 = 33; // GPO - Output Only +static const uint8_t D4 = 27; +static const uint8_t D5 = 14; +static const uint8_t D6 = 12; +static const uint8_t D7 = 13; +static const uint8_t D8 = 15; +static const uint8_t D9 = 23; +static const uint8_t D10 = 0; + +// I2C BUS, 2k2 hardware pull-ups +static const uint8_t SDA = 16; +static const uint8_t SCL = 17; + +// SPI - unused but you can create your own definition in your sketch +static const int8_t SCK = -1; +static const int8_t MISO = -1; +static const int8_t MOSI = -1; +static const int8_t SS = -1; + +#endif /* Pins_Arduino_h */ diff --git a/variants/franzininho_wifi_esp32s2/pins_arduino.h b/variants/franzininho_wifi_esp32s2/pins_arduino.h index 4a07156d0c3..629597bcac1 100644 --- a/variants/franzininho_wifi_esp32s2/pins_arduino.h +++ b/variants/franzininho_wifi_esp32s2/pins_arduino.h @@ -4,17 +4,17 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x303A -#define USB_PID 0x80A9 -#define USB_MANUFACTURER "Franzininho" -#define USB_PRODUCT "Franzininho WIFI" -#define USB_SERIAL "0" -#define USB_WEBUSB_ENABLED false +#define USB_VID 0x303A +#define USB_PID 0x80A9 +#define USB_MANUFACTURER "Franzininho" +#define USB_PRODUCT "Franzininho WIFI" +#define USB_SERIAL "0" +#define USB_WEBUSB_ENABLED false static const uint8_t PIN_NEOPIXEL = 18; // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino static const uint8_t LED_BUILTIN = (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT); -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN @@ -26,10 +26,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 34; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/franzininho_wifi_msc_esp32s2/pins_arduino.h b/variants/franzininho_wifi_msc_esp32s2/pins_arduino.h index 0589ad421d2..7f62aec0f74 100644 --- a/variants/franzininho_wifi_msc_esp32s2/pins_arduino.h +++ b/variants/franzininho_wifi_msc_esp32s2/pins_arduino.h @@ -4,24 +4,24 @@ #include #include "soc/soc_caps.h" -#define USB_VID 0x303A -#define USB_PID 0x80A9 -#define USB_MANUFACTURER "Franzininho" -#define USB_PRODUCT "Franzininho WIFI MSC" -#define USB_SERIAL "0" -#define USB_WEBUSB_ENABLED false +#define USB_VID 0x303A +#define USB_PID 0x80A9 +#define USB_MANUFACTURER "Franzininho" +#define USB_PRODUCT "Franzininho WIFI MSC" +#define USB_SERIAL "0" +#define USB_WEBUSB_ENABLED false // Default USB FirmwareMSC Settings -#define USB_FW_MSC_VENDOR_ID "ESP32-S2" //max 8 chars -#define USB_FW_MSC_PRODUCT_ID "Firmware MSC" //max 16 chars -#define USB_FW_MSC_PRODUCT_REVISION "1.23" //max 4 chars -#define USB_FW_MSC_VOLUME_NAME "S2-Firmware" //max 11 chars -#define USB_FW_MSC_SERIAL_NUMBER 0x00000000 +#define USB_FW_MSC_VENDOR_ID "ESP32-S2" //max 8 chars +#define USB_FW_MSC_PRODUCT_ID "Firmware MSC" //max 16 chars +#define USB_FW_MSC_PRODUCT_REVISION "1.23" //max 4 chars +#define USB_FW_MSC_VOLUME_NAME "S2-Firmware" //max 11 chars +#define USB_FW_MSC_SERIAL_NUMBER 0x00000000 static const uint8_t PIN_NEOPIXEL = 18; // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino static const uint8_t LED_BUILTIN = (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT); -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN @@ -33,10 +33,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 34; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/frog32/pins_arduino.h b/variants/frog32/pins_arduino.h index 27ecc063483..3663de76cd4 100644 --- a/variants/frog32/pins_arduino.h +++ b/variants/frog32/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/gpy/pins_arduino.h b/variants/gpy/pins_arduino.h index 255363ce5c7..06c9fc234ee 100644 --- a/variants/gpy/pins_arduino.h +++ b/variants/gpy/pins_arduino.h @@ -8,34 +8,34 @@ // NOTE: The Pycom pinout as well as spec sheet block diagram / pin details // incorrectly list the LTE pins. The correct pins are defined in the source and CSV // at https://github.com/pycom/pycom-micropython-sigfox/tree/master/esp32/boards/GPY. -#define LTE_CTS 18 // GPIO18 - Sequans modem CTS -#define LTE_RTS 19 // GPIO19 - Sequans modem RTS (pull low to communicate) -#define LTE_RX 23 // GPIO23 - Sequans modem RX -#define LTE_TX 5 // GPIO5 - Sequans modem TX -#define LTE_WAKE 27 // GPIO27 - Sequans modem wake-up interrupt +#define LTE_CTS 18 // GPIO18 - Sequans modem CTS +#define LTE_RTS 19 // GPIO19 - Sequans modem RTS (pull low to communicate) +#define LTE_RX 23 // GPIO23 - Sequans modem RX +#define LTE_TX 5 // GPIO5 - Sequans modem TX +#define LTE_WAKE 27 // GPIO27 - Sequans modem wake-up interrupt #define LTE_BAUD 921600 // Neopixel -#define PIN_NEOPIXEL 0 // ->2812 RGB !!! -static const uint8_t LED_BUILTIN = PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define PIN_NEOPIXEL 0 // ->2812 RGB !!! +static const uint8_t LED_BUILTIN = PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 -#define ANT_SELECT 21 // GPIO21 - WiFi external / internal antenna switch +#define ANT_SELECT 21 // GPIO21 - WiFi external / internal antenna switch static const uint8_t TX = 1; static const uint8_t RX = 3; static const uint8_t SDA = 12; static const uint8_t SCL = 13; - -static const uint8_t SS = 17; -static const uint8_t MOSI = 22; -static const uint8_t MISO = 37; -static const uint8_t SCK = 13; + +static const uint8_t SS = 17; +static const uint8_t MOSI = 22; +static const uint8_t MISO = 37; +static const uint8_t SCK = 13; static const uint8_t A0 = 36; static const uint8_t A1 = 37; diff --git a/variants/healthypi4/pins_arduino.h b/variants/healthypi4/pins_arduino.h index 69471053402..2b8707fdaeb 100644 --- a/variants/healthypi4/pins_arduino.h +++ b/variants/healthypi4/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 15; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 17; @@ -15,10 +15,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 2; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 2; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; @@ -51,15 +51,15 @@ static const uint8_t T9 = 32; static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; -static const uint8_t ADS1292_DRDY_PIN = 26; -static const uint8_t ADS1292_CS_PIN = 13; -static const uint8_t ADS1292_START_PIN = 14; -static const uint8_t ADS1292_PWDN_PIN = 27; -static const uint8_t AFE4490_CS_PIN = 21; -static const uint8_t AFE4490_DRDY_PIN = 39; -static const uint8_t AFE4490_PWDN_PIN = 4; +static const uint8_t ADS1292_DRDY_PIN = 26; +static const uint8_t ADS1292_CS_PIN = 13; +static const uint8_t ADS1292_START_PIN = 14; +static const uint8_t ADS1292_PWDN_PIN = 27; +static const uint8_t AFE4490_CS_PIN = 21; +static const uint8_t AFE4490_DRDY_PIN = 39; +static const uint8_t AFE4490_PWDN_PIN = 4; -static const uint8_t PUSH_BUTTON = 17; -static const uint8_t SLIDE_SWITCH = 16; +static const uint8_t PUSH_BUTTON = 17; +static const uint8_t SLIDE_SWITCH = 16; #endif /* Pins_Arduino_h */ diff --git a/variants/heltec_capsule_sensor_v3/pins_arduino.h b/variants/heltec_capsule_sensor_v3/pins_arduino.h index 4bc1b03481b..02bade56d13 100644 --- a/variants/heltec_capsule_sensor_v3/pins_arduino.h +++ b/variants/heltec_capsule_sensor_v3/pins_arduino.h @@ -13,8 +13,8 @@ // Some boards have too low voltage on this pin (board design bug) // Use different pin with 3V and connect with 48 // and change this setup for the chosen pin (for example 38) -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+48; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 48; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 @@ -26,10 +26,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 41; static const uint8_t SCL = 42; -static const uint8_t SS = 8; -static const uint8_t MOSI = 10; -static const uint8_t MISO = 11; -static const uint8_t SCK = 9; +static const uint8_t SS = 8; +static const uint8_t MOSI = 10; +static const uint8_t MISO = 11; +static const uint8_t SCK = 9; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/heltec_ht_de01/pins_arduino.h b/variants/heltec_ht_de01/pins_arduino.h index 95d285ca6e9..0c479fd3ff4 100644 --- a/variants/heltec_ht_de01/pins_arduino.h +++ b/variants/heltec_ht_de01/pins_arduino.h @@ -3,11 +3,11 @@ #include -#define HT_DE01 true +#define HT_DE01 true static const uint8_t LED_BUILTIN = 35; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -60,7 +60,7 @@ static const uint8_t T13 = 13; static const uint8_t T14 = 14; static const uint8_t Vext = 45; -static const uint8_t LED = 18; +static const uint8_t LED = 18; static const uint8_t RST_EINK = 6; static const uint8_t BUSY_EINK = 7; static const uint8_t CLK_EINK = 3; diff --git a/variants/heltec_wifi_kit_32/pins_arduino.h b/variants/heltec_wifi_kit_32/pins_arduino.h index a164f9e153a..a4141700483 100644 --- a/variants/heltec_wifi_kit_32/pins_arduino.h +++ b/variants/heltec_wifi_kit_32/pins_arduino.h @@ -3,12 +3,12 @@ #include -#define WIFI_Kit_32 true +#define WIFI_Kit_32 true #define DISPLAY_HEIGHT 64 -#define DISPLAY_WIDTH 128 +#define DISPLAY_WIDTH 128 static const uint8_t LED_BUILTIN = 25; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -19,10 +19,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A1 = 37; @@ -59,7 +59,7 @@ static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; static const uint8_t Vext = 21; -static const uint8_t LED = 25; +static const uint8_t LED = 25; static const uint8_t RST_OLED = 16; static const uint8_t SCL_OLED = 15; static const uint8_t SDA_OLED = 4; diff --git a/variants/heltec_wifi_kit_32_V3/pins_arduino.h b/variants/heltec_wifi_kit_32_V3/pins_arduino.h index c64fe199860..4f1de6a80cf 100644 --- a/variants/heltec_wifi_kit_32_V3/pins_arduino.h +++ b/variants/heltec_wifi_kit_32_V3/pins_arduino.h @@ -3,12 +3,12 @@ #include -#define WIFI_Kit_32_V3 true +#define WIFI_Kit_32_V3 true #define DISPLAY_HEIGHT 64 -#define DISPLAY_WIDTH 128 +#define DISPLAY_WIDTH 128 static const uint8_t LED_BUILTIN = 35; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -61,7 +61,7 @@ static const uint8_t T13 = 13; static const uint8_t T14 = 14; static const uint8_t Vext = 36; -static const uint8_t LED = 35; +static const uint8_t LED = 35; static const uint8_t RST_OLED = 21; static const uint8_t SCL_OLED = 18; static const uint8_t SDA_OLED = 17; diff --git a/variants/heltec_wifi_lora_32/pins_arduino.h b/variants/heltec_wifi_lora_32/pins_arduino.h index b702b97f437..60369c255ef 100644 --- a/variants/heltec_wifi_lora_32/pins_arduino.h +++ b/variants/heltec_wifi_lora_32/pins_arduino.h @@ -5,10 +5,10 @@ #define WIFI_LoRa_32 true #define DISPLAY_HEIGHT 64 -#define DISPLAY_WIDTH 128 +#define DISPLAY_WIDTH 128 static const uint8_t LED_BUILTIN = 25; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -19,10 +19,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 18; -static const uint8_t MOSI = 27; -static const uint8_t MISO = 19; -static const uint8_t SCK = 5; +static const uint8_t SS = 18; +static const uint8_t MOSI = 27; +static const uint8_t MISO = 19; +static const uint8_t SCK = 5; static const uint8_t A0 = 36; static const uint8_t A3 = 39; @@ -55,8 +55,8 @@ static const uint8_t T9 = 32; static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; -static const uint8_t Vext = 21; -static const uint8_t LED = 25; +static const uint8_t Vext = 21; +static const uint8_t LED = 25; static const uint8_t RST_OLED = 16; static const uint8_t SCL_OLED = 15; static const uint8_t SDA_OLED = 4; diff --git a/variants/heltec_wifi_lora_32_V2/pins_arduino.h b/variants/heltec_wifi_lora_32_V2/pins_arduino.h index d316145b8c6..ebec62f9dd5 100644 --- a/variants/heltec_wifi_lora_32_V2/pins_arduino.h +++ b/variants/heltec_wifi_lora_32_V2/pins_arduino.h @@ -5,10 +5,10 @@ #define WIFI_LoRa_32_V2 true #define DISPLAY_HEIGHT 64 -#define DISPLAY_WIDTH 128 +#define DISPLAY_WIDTH 128 static const uint8_t LED_BUILTIN = 25; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -19,10 +19,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 18; -static const uint8_t MOSI = 27; -static const uint8_t MISO = 19; -static const uint8_t SCK = 5; +static const uint8_t SS = 18; +static const uint8_t MOSI = 27; +static const uint8_t MISO = 19; +static const uint8_t SCK = 5; static const uint8_t A0 = 36; static const uint8_t A3 = 39; @@ -56,7 +56,7 @@ static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; static const uint8_t Vext = 21; -static const uint8_t LED = 25; +static const uint8_t LED = 25; static const uint8_t RST_OLED = 16; static const uint8_t SCL_OLED = 15; static const uint8_t SDA_OLED = 4; diff --git a/variants/heltec_wifi_lora_32_V3/pins_arduino.h b/variants/heltec_wifi_lora_32_V3/pins_arduino.h index bd0d35a8912..c370cddedc4 100644 --- a/variants/heltec_wifi_lora_32_V3/pins_arduino.h +++ b/variants/heltec_wifi_lora_32_V3/pins_arduino.h @@ -5,13 +5,13 @@ #define WIFI_LoRa_32_V3 true #define DISPLAY_HEIGHT 64 -#define DISPLAY_WIDTH 128 +#define DISPLAY_WIDTH 128 #define USB_VID 0x303a #define USB_PID 0x1001 static const uint8_t LED_BUILTIN = 35; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 43; @@ -20,10 +20,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 41; static const uint8_t SCL = 42; -static const uint8_t SS = 8; -static const uint8_t MOSI = 10; -static const uint8_t MISO = 11; -static const uint8_t SCK = 9; +static const uint8_t SS = 8; +static const uint8_t MOSI = 10; +static const uint8_t MISO = 11; +static const uint8_t SCK = 9; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -62,7 +62,7 @@ static const uint8_t T13 = 13; static const uint8_t T14 = 14; static const uint8_t Vext = 36; -static const uint8_t LED = 35; +static const uint8_t LED = 35; static const uint8_t RST_OLED = 21; static const uint8_t SCL_OLED = 18; static const uint8_t SDA_OLED = 17; diff --git a/variants/heltec_wireless_bridge/pins_arduino.h b/variants/heltec_wireless_bridge/pins_arduino.h index 0c601b7bbe4..7d2b7c7575c 100644 --- a/variants/heltec_wireless_bridge/pins_arduino.h +++ b/variants/heltec_wireless_bridge/pins_arduino.h @@ -7,26 +7,26 @@ static const uint8_t LED_BUILTIN = 25; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility static const uint8_t KEY_BUILTIN = 0; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 18; -static const uint8_t MOSI = 27; -static const uint8_t MISO = 19; -static const uint8_t SCK = 5; +static const uint8_t SS = 18; +static const uint8_t MOSI = 27; +static const uint8_t MISO = 19; +static const uint8_t SCK = 5; static const uint8_t Vext = 21; -static const uint8_t LED = 25; -static const uint8_t BLE_LED = 25; -static const uint8_t WIFI_LED = 23; -static const uint8_t LoRa_LED = 22; +static const uint8_t LED = 25; +static const uint8_t BLE_LED = 25; +static const uint8_t WIFI_LED = 23; +static const uint8_t LoRa_LED = 22; static const uint8_t RST_LoRa = 14; static const uint8_t DIO0 = 26; static const uint8_t DIO1 = 35; static const uint8_t DIO2 = 34; -#endif /* Pins_Arduino_h */ \ No newline at end of file +#endif /* Pins_Arduino_h */ diff --git a/variants/heltec_wireless_mini_shell/pins_arduino.h b/variants/heltec_wireless_mini_shell/pins_arduino.h index 50727032030..f755464135c 100644 --- a/variants/heltec_wireless_mini_shell/pins_arduino.h +++ b/variants/heltec_wireless_mini_shell/pins_arduino.h @@ -6,8 +6,8 @@ #define WIRELESS_MINI_SHELL true -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+8; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 8; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 @@ -19,10 +19,10 @@ static const uint8_t RX = 20; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 7; -static const uint8_t MOSI = 6; -static const uint8_t MISO = 5; -static const uint8_t SCK = 4; +static const uint8_t SS = 7; +static const uint8_t MOSI = 6; +static const uint8_t MISO = 5; +static const uint8_t SCK = 4; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/heltec_wireless_paper/pins_arduino.h b/variants/heltec_wireless_paper/pins_arduino.h index 1d02c70125f..09614348266 100644 --- a/variants/heltec_wireless_paper/pins_arduino.h +++ b/variants/heltec_wireless_paper/pins_arduino.h @@ -3,13 +3,13 @@ #include -#define WIRELESS_PAPER true +#define WIRELESS_PAPER true #define DISPLAY_HEIGHT 64 -#define DISPLAY_WIDTH 128 +#define DISPLAY_WIDTH 128 static const uint8_t LED_BUILTIN = 35; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -62,7 +62,7 @@ static const uint8_t T13 = 13; static const uint8_t T14 = 14; static const uint8_t Vext = 45; -static const uint8_t LED = 18; +static const uint8_t LED = 18; static const uint8_t RST_OLED = 21; static const uint8_t SCL_OLED = 18; static const uint8_t SDA_OLED = 17; diff --git a/variants/heltec_wireless_shell_v3/pins_arduino.h b/variants/heltec_wireless_shell_v3/pins_arduino.h index 33d46123824..9f4697820fc 100644 --- a/variants/heltec_wireless_shell_v3/pins_arduino.h +++ b/variants/heltec_wireless_shell_v3/pins_arduino.h @@ -6,13 +6,13 @@ #define HELTEC_WIRELESS_SHELL_V3 true #define DISPLAY_HEIGHT 0 -#define DISPLAY_WIDTH 0 +#define DISPLAY_WIDTH 0 #define USB_VID 0x303a #define USB_PID 0x1001 static const uint8_t LED_BUILTIN = 35; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 43; @@ -23,10 +23,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 2; static const uint8_t SCL = 3; -static const uint8_t SS = 8; -static const uint8_t MOSI = 10; -static const uint8_t MISO = 11; -static const uint8_t SCK = 9; +static const uint8_t SS = 8; +static const uint8_t MOSI = 10; +static const uint8_t MISO = 11; +static const uint8_t SCK = 9; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -65,7 +65,7 @@ static const uint8_t T13 = 13; static const uint8_t T14 = 14; static const uint8_t Vext = 36; -static const uint8_t LED = 35; +static const uint8_t LED = 35; static const uint8_t RST_OLED = 21; static const uint8_t SCL_OLED = 18; static const uint8_t SDA_OLED = 17; diff --git a/variants/heltec_wireless_stick/pins_arduino.h b/variants/heltec_wireless_stick/pins_arduino.h index 0910fcc7672..751fcfc506a 100644 --- a/variants/heltec_wireless_stick/pins_arduino.h +++ b/variants/heltec_wireless_stick/pins_arduino.h @@ -5,10 +5,10 @@ #define Wireless_Stick true #define DISPLAY_HEIGHT 32 -#define DISPLAY_WIDTH 64 +#define DISPLAY_WIDTH 64 static const uint8_t LED_BUILTIN = 25; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -19,10 +19,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 18; -static const uint8_t MOSI = 27; -static const uint8_t MISO = 19; -static const uint8_t SCK = 5; +static const uint8_t SS = 18; +static const uint8_t MOSI = 27; +static const uint8_t MISO = 19; +static const uint8_t SCK = 5; static const uint8_t A0 = 36; static const uint8_t A3 = 39; @@ -56,7 +56,7 @@ static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; static const uint8_t Vext = 21; -static const uint8_t LED = 25; +static const uint8_t LED = 25; static const uint8_t RST_OLED = 16; static const uint8_t SCL_OLED = 15; static const uint8_t SDA_OLED = 4; diff --git a/variants/heltec_wireless_stick_V1/pins_arduino.h b/variants/heltec_wireless_stick_V1/pins_arduino.h index 1c1b2196da3..4dab1293012 100644 --- a/variants/heltec_wireless_stick_V1/pins_arduino.h +++ b/variants/heltec_wireless_stick_V1/pins_arduino.h @@ -5,10 +5,10 @@ #define Wireless_Stick true #define DISPLAY_HEIGHT 32 -#define DISPLAY_WIDTH 64 +#define DISPLAY_WIDTH 64 static const uint8_t LED_BUILTIN = 25; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -19,10 +19,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 18; -static const uint8_t MOSI = 27; -static const uint8_t MISO = 19; -static const uint8_t SCK = 5; +static const uint8_t SS = 18; +static const uint8_t MOSI = 27; +static const uint8_t MISO = 19; +static const uint8_t SCK = 5; static const uint8_t A0 = 36; static const uint8_t A3 = 39; @@ -56,7 +56,7 @@ static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; static const uint8_t Vext = 21; -static const uint8_t LED = 25; +static const uint8_t LED = 25; static const uint8_t RST_OLED = 16; static const uint8_t SCL_OLED = 15; static const uint8_t SDA_OLED = 4; diff --git a/variants/heltec_wireless_stick_lite/pins_arduino.h b/variants/heltec_wireless_stick_lite/pins_arduino.h index ec4bac483de..89bdf0592cb 100644 --- a/variants/heltec_wireless_stick_lite/pins_arduino.h +++ b/variants/heltec_wireless_stick_lite/pins_arduino.h @@ -5,10 +5,10 @@ #define Wireless_Stick_Lite true #define DISPLAY_HEIGHT 0 -#define DISPLAY_WIDTH 0 +#define DISPLAY_WIDTH 0 static const uint8_t LED_BUILTIN = 25; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -19,10 +19,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 18; -static const uint8_t MOSI = 27; -static const uint8_t MISO = 19; -static const uint8_t SCK = 5; +static const uint8_t SS = 18; +static const uint8_t MOSI = 27; +static const uint8_t MISO = 19; +static const uint8_t SCK = 5; static const uint8_t A0 = 36; static const uint8_t A3 = 39; @@ -56,7 +56,7 @@ static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; static const uint8_t Vext = 21; -static const uint8_t LED = 25; +static const uint8_t LED = 25; static const uint8_t RST_LoRa = 14; static const uint8_t DIO0 = 26; static const uint8_t DIO1 = 35; diff --git a/variants/heltec_wireless_stick_lite_v3/pins_arduino.h b/variants/heltec_wireless_stick_lite_v3/pins_arduino.h index 0a0a466302c..02622989fbb 100644 --- a/variants/heltec_wireless_stick_lite_v3/pins_arduino.h +++ b/variants/heltec_wireless_stick_lite_v3/pins_arduino.h @@ -5,10 +5,10 @@ #define Wireless_Stick_Lite_V3 true #define DISPLAY_HEIGHT 0 -#define DISPLAY_WIDTH 0 +#define DISPLAY_WIDTH 0 static const uint8_t LED_BUILTIN = 35; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 43; @@ -17,10 +17,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 2; static const uint8_t SCL = 3; -static const uint8_t SS = 34; -static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; -static const uint8_t MISO = 37; +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -47,7 +47,7 @@ static const uint8_t T5 = 6; static const uint8_t T6 = 7; static const uint8_t Vext = 36; -static const uint8_t LED = 35; +static const uint8_t LED = 35; static const uint8_t RST_OLED = 21; static const uint8_t SCL_OLED = 18; static const uint8_t SDA_OLED = 17; diff --git a/variants/heltec_wireless_stick_v3/pins_arduino.h b/variants/heltec_wireless_stick_v3/pins_arduino.h index 6a2b805c0c1..dceacf63ba4 100644 --- a/variants/heltec_wireless_stick_v3/pins_arduino.h +++ b/variants/heltec_wireless_stick_v3/pins_arduino.h @@ -7,7 +7,7 @@ #define WIRELESS_STICK_V3 true #define DISPLAY_HEIGHT 32 -#define DISPLAY_WIDTH 64 +#define DISPLAY_WIDTH 64 #define USB_VID 0x303a #define USB_PID 0x1001 @@ -15,8 +15,8 @@ // Some boards have too low voltage on this pin (board design bug) // Use different pin with 3V and connect with 48 // and change this setup for the chosen pin (for example 38) -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+48; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 48; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 @@ -28,10 +28,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 41; static const uint8_t SCL = 42; -static const uint8_t SS = 8; -static const uint8_t MOSI = 10; -static const uint8_t MISO = 11; -static const uint8_t SCK = 9; +static const uint8_t SS = 8; +static const uint8_t MOSI = 10; +static const uint8_t MISO = 11; +static const uint8_t SCK = 9; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -70,7 +70,7 @@ static const uint8_t T13 = 13; static const uint8_t T14 = 14; static const uint8_t Vext = 36; -static const uint8_t LED = 35; +static const uint8_t LED = 35; static const uint8_t RST_OLED = 21; static const uint8_t SCL_OLED = 18; static const uint8_t SDA_OLED = 17; diff --git a/variants/heltec_wireless_tracker/pins_arduino.h b/variants/heltec_wireless_tracker/pins_arduino.h index d8a759a094c..32f13c22d75 100644 --- a/variants/heltec_wireless_tracker/pins_arduino.h +++ b/variants/heltec_wireless_tracker/pins_arduino.h @@ -10,8 +10,8 @@ // Some boards have too low voltage on this pin (board design bug) // Use different pin with 3V and connect with 48 // and change this setup for the chosen pin (for example 38) -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+48; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 48; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 @@ -22,10 +22,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 41; static const uint8_t SCL = 42; -static const uint8_t SS = 8; -static const uint8_t MOSI = 10; -static const uint8_t MISO = 11; -static const uint8_t SCK = 9; +static const uint8_t SS = 8; +static const uint8_t MOSI = 10; +static const uint8_t MISO = 11; +static const uint8_t SCK = 9; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -64,7 +64,7 @@ static const uint8_t T13 = 13; static const uint8_t T14 = 14; static const uint8_t Vext = 3; -static const uint8_t LED = 18; +static const uint8_t LED = 18; static const uint8_t RST_OLED = 39; static const uint8_t SCL_OLED = 41; static const uint8_t SDA_OLED = 42; diff --git a/variants/honeylemon/pins_arduino.h b/variants/honeylemon/pins_arduino.h index 044dad7f269..567989a3c90 100644 --- a/variants/honeylemon/pins_arduino.h +++ b/variants/honeylemon/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t BUILTIN_KEY = 0; @@ -15,10 +15,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/hornbill32dev/pins_arduino.h b/variants/hornbill32dev/pins_arduino.h index a868a7edffa..0bd626ab7ef 100644 --- a/variants/hornbill32dev/pins_arduino.h +++ b/variants/hornbill32dev/pins_arduino.h @@ -4,31 +4,31 @@ #include static const uint8_t LED_BUILTIN = 13; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; static const uint8_t TX = 1; -static const uint8_t RX = 3; - -static const uint8_t SDA = 21; -static const uint8_t SCL = 22; - -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; - -static const uint8_t A0 = 36; -static const uint8_t A3 = 39; -static const uint8_t A4 = 32; -static const uint8_t A5 = 33; -static const uint8_t A6 = 34; -static const uint8_t A7 = 35; -static const uint8_t A10 = 4; -static const uint8_t A11 = 0; -static const uint8_t A12 = 2; +static const uint8_t RX = 3; + +static const uint8_t SDA = 21; +static const uint8_t SCL = 22; + +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; + +static const uint8_t A0 = 36; +static const uint8_t A3 = 39; +static const uint8_t A4 = 32; +static const uint8_t A5 = 33; +static const uint8_t A6 = 34; +static const uint8_t A7 = 35; +static const uint8_t A10 = 4; +static const uint8_t A11 = 0; +static const uint8_t A12 = 2; static const uint8_t A13 = 15; static const uint8_t A14 = 13; static const uint8_t A15 = 12; @@ -37,8 +37,8 @@ static const uint8_t A17 = 27; static const uint8_t A18 = 25; static const uint8_t A19 = 26; -static const uint8_t T0 = 4; -static const uint8_t T1 = 0; +static const uint8_t T0 = 4; +static const uint8_t T1 = 0; static const uint8_t T2 = 2; static const uint8_t T3 = 15; static const uint8_t T4 = 13; @@ -48,7 +48,7 @@ static const uint8_t T7 = 27; static const uint8_t T8 = 33; static const uint8_t T9 = 32; -static const uint8_t DAC1 = 25; -static const uint8_t DAC2 = 26; +static const uint8_t DAC1 = 25; +static const uint8_t DAC2 = 26; #endif /* Pins_Arduino_h */ diff --git a/variants/hornbill32minima/pins_arduino.h b/variants/hornbill32minima/pins_arduino.h index a8fb52c60f7..029de341716 100644 --- a/variants/hornbill32minima/pins_arduino.h +++ b/variants/hornbill32minima/pins_arduino.h @@ -9,20 +9,20 @@ static const uint8_t RX = 3; //taken out on pgm header static const uint8_t SDA = 21; //1 static const uint8_t SCL = 22; //2 -static const uint8_t SS = 2; //3 -static const uint8_t MOSI = 23; //4 -static const uint8_t MISO = 19; //5 -static const uint8_t SCK = 18; //6 +static const uint8_t SS = 2; //3 +static const uint8_t MOSI = 23; //4 +static const uint8_t MISO = 19; //5 +static const uint8_t SCK = 18; //6 -static const uint8_t A6 = 34; //7 -static const uint8_t A7 = 35; //8 -static const uint8_t A10 = 4; //9 -static const uint8_t A11 = 0; // taken out on pgm header -static const uint8_t A12 = 2; // with SPI SS -static const uint8_t A13 = 15; //10 -static const uint8_t A14 = 13; //11 +static const uint8_t A6 = 34; //7 +static const uint8_t A7 = 35; //8 +static const uint8_t A10 = 4; //9 +static const uint8_t A11 = 0; // taken out on pgm header +static const uint8_t A12 = 2; // with SPI SS +static const uint8_t A13 = 15; //10 +static const uint8_t A14 = 13; //11 @@ -30,10 +30,10 @@ static const uint8_t DAC1 = 25; //12 static const uint8_t DAC2 = 26; //13 -static const uint8_t T0 = 4; //used -static const uint8_t T1 = 0; // taken out on pgm header -static const uint8_t T2 = 2; //used -static const uint8_t T3 = 15; //used +static const uint8_t T0 = 4; //used +static const uint8_t T1 = 0; // taken out on pgm header +static const uint8_t T2 = 2; //used +static const uint8_t T3 = 15; //used diff --git a/variants/imbrios-logsens-v1p1/pins_arduino.h b/variants/imbrios-logsens-v1p1/pins_arduino.h index c35040857ca..ee36c62282b 100644 --- a/variants/imbrios-logsens-v1p1/pins_arduino.h +++ b/variants/imbrios-logsens-v1p1/pins_arduino.h @@ -4,17 +4,17 @@ #include // Renaming few signals -#define SPI_CLK SCK // IO14 -#define SPI_MISO MISO // IO12 -#define SPI_MOSI MOSI // IO13 -#define SPI_CS0 SS // IO15, Default SPI CS: Extension Header, Pin_3 -#define SD_SPI_CS1 SPI_CS1 // SPI Chip Select: MicroSD Card -#define LED_WIFI_LINK LED1_BUILDIN // LED6 on the LogSens V1.1 Board -#define LED_WIFI_ACT LED2_BUILDIN // LED7 on the LogSens V1.1 Board\ +#define SPI_CLK SCK // IO14 +#define SPI_MISO MISO // IO12 +#define SPI_MOSI MOSI // IO13 +#define SPI_CS0 SS // IO15, Default SPI CS: Extension Header, Pin_3 +#define SD_SPI_CS1 SPI_CS1 // SPI Chip Select: MicroSD Card +#define LED_WIFI_LINK LED1_BUILDIN // LED6 on the LogSens V1.1 Board +#define LED_WIFI_ACT LED2_BUILDIN // LED7 on the LogSens V1.1 Board\ /* LED_BUILTIN is kept for compatibility reason; mapped to LED2 on the LogSens V1.1 Board */ static const uint8_t LED_BUILTIN = 33; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN /* UART0: Serial Port for Programming and Debugging on the LogSens V1.1 Board */ @@ -22,14 +22,14 @@ static const uint8_t TX = 1; static const uint8_t RX = 3; #ifdef BOARD_VARIANT_RS485 -/* UART2: Serial Port conencted to RS485 transceiver on the LogSens V1.1 Board */ +/* UART2: Serial Port connected to RS485 transceiver on the LogSens V1.1 Board */ static const uint8_t UART2_TX = 17; static const uint8_t UART2_RX = 16; static const uint8_t UART2_RTS = 4; #endif /* BOARD_VARIANT_RS485 */ #ifdef BOARD_VARIANT_CAN -/* CAN Bus conencted to CAN transceiver on the LogSens V1.1 Board */ +/* CAN Bus connected to CAN transceiver on the LogSens V1.1 Board */ static const uint8_t CAN_TX = 17; static const uint8_t CAN_RX = 16; static const uint8_t CAN_TXDE = 4; @@ -40,23 +40,23 @@ static const uint8_t SDA = 21; static const uint8_t SCL = 22; /* SPI Bus: Shared between MicroSD Card (X6) and Expansion Header (X3) */ -static const uint8_t SS = 15; // SPI Chip Select - 0; Connected to Extension Header, Pin_3 on the LogSens V1.1 Board -static const uint8_t MOSI = 13; -static const uint8_t MISO = 12; -static const uint8_t SCK = 14; +static const uint8_t SS = 15; // SPI Chip Select - 0; Connected to Extension Header, Pin_3 on the LogSens V1.1 Board +static const uint8_t MOSI = 13; +static const uint8_t MISO = 12; +static const uint8_t SCK = 14; + +static const uint8_t SS1 = 23; // SPI Chip Select - 1; connected to MicroSD Card on the LogSens V1.1 Board -static const uint8_t SS1 = 23; // SPI Chip Select - 1; connected to MicroSD Card on the LogSens V1.1 Board - /* Software Controlled: IO, LEDs and Switches */ -static const uint8_t BUZZER_CTRL = 19; // Signal connected to MOSFET gate pin to control conenctor (X8) -static const uint8_t SD_CARD_DETECT = 35; // MicroSD Card (X6): Card Detect Signal +static const uint8_t BUZZER_CTRL = 19; // Signal connected to MOSFET gate pin to control connector (X8) +static const uint8_t SD_CARD_DETECT = 35; // MicroSD Card (X6): Card Detect Signal -static const uint8_t SW2_BUILDIN = 0; // Tactile Switch-2 (SW2); ESP32 BOOT0 pin, Use it with care !! -static const uint8_t SW3_BUILDIN = 36; // Tactile Switch-3 (SW3) -static const uint8_t SW4_BUILDIN = 34; // Tactile Switch-4 (SW4) +static const uint8_t SW2_BUILDIN = 0; // Tactile Switch-2 (SW2); ESP32 BOOT0 pin, Use it with care !! +static const uint8_t SW3_BUILDIN = 36; // Tactile Switch-3 (SW3) +static const uint8_t SW4_BUILDIN = 34; // Tactile Switch-4 (SW4) -static const uint8_t LED1_BUILDIN = 32; // Connected to LogSens V1.1: LED6 -static const uint8_t LED2_BUILDIN = 33; // Connected to LogSens V1.1: LED7 +static const uint8_t LED1_BUILDIN = 32; // Connected to LogSens V1.1: LED6 +static const uint8_t LED2_BUILDIN = 33; // Connected to LogSens V1.1: LED7 /* Analog Input Channels accessible on the LogSens V1.1 Board */ diff --git a/variants/intorobot-fig/pins_arduino.h b/variants/intorobot-fig/pins_arduino.h index a0e8db822e8..d6a13496a78 100644 --- a/variants/intorobot-fig/pins_arduino.h +++ b/variants/intorobot-fig/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 4; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t RGB_R_BUILTIN = 27; @@ -19,10 +19,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 23; static const uint8_t SCL = 19; -static const uint8_t SS = 5; -static const uint8_t MOSI = 16; -static const uint8_t MISO = 17; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 16; +static const uint8_t MISO = 17; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A1 = 39; diff --git a/variants/ioxesp32/pins_arduino.h b/variants/ioxesp32/pins_arduino.h index 2a27157366f..bc0d7a1f772 100644 --- a/variants/ioxesp32/pins_arduino.h +++ b/variants/ioxesp32/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 5; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -15,10 +15,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/lilygo_t_display/pins_arduino.h b/variants/lilygo_t_display/pins_arduino.h index beae4b311c6..bd51ab8cec9 100644 --- a/variants/lilygo_t_display/pins_arduino.h +++ b/variants/lilygo_t_display/pins_arduino.h @@ -15,10 +15,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; @@ -56,4 +56,4 @@ static const uint8_t VBAT = 34; static const uint8_t RIGHT_BUTTON = 35; static const uint8_t LEFT_BUTTON = 0; -#endif /* Pins_Arduino_h */ \ No newline at end of file +#endif /* Pins_Arduino_h */ diff --git a/variants/lilygo_t_display_s3/pins_arduino.h b/variants/lilygo_t_display_s3/pins_arduino.h index 42b01587c39..7fcf0c2accc 100644 --- a/variants/lilygo_t_display_s3/pins_arduino.h +++ b/variants/lilygo_t_display_s3/pins_arduino.h @@ -16,10 +16,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 18; static const uint8_t SCL = 17; -static const uint8_t SS = 10; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 13; -static const uint8_t SCK = 12; +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; static const uint8_t TP_RESET = 21; static const uint8_t TP_INIT = 16; @@ -50,19 +50,19 @@ static const uint8_t PIN_21 = 21; static const uint8_t PIN_16 = 16; // P2 -static const uint8_t PIN_1 = 1; -static const uint8_t PIN_2 = 2; -static const uint8_t PIN_3 = 3; +static const uint8_t PIN_1 = 1; +static const uint8_t PIN_2 = 2; +static const uint8_t PIN_3 = 3; static const uint8_t PIN_10 = 10; static const uint8_t PIN_11 = 11; static const uint8_t PIN_12 = 12; static const uint8_t PIN_13 = 13; // Analog -static const uint8_t A0 = 1; -static const uint8_t A1 = 2; -static const uint8_t A2 = 3; -static const uint8_t A9 = 10; +static const uint8_t A0 = 1; +static const uint8_t A1 = 2; +static const uint8_t A2 = 3; +static const uint8_t A9 = 10; static const uint8_t A10 = 11; static const uint8_t A11 = 12; static const uint8_t A12 = 13; @@ -72,9 +72,9 @@ static const uint8_t A17 = 18; // Touch -static const uint8_t T1 = 1; -static const uint8_t T2 = 2; -static const uint8_t T3 = 3; +static const uint8_t T1 = 1; +static const uint8_t T2 = 2; +static const uint8_t T3 = 3; static const uint8_t T10 = 10; static const uint8_t T11 = 11; static const uint8_t T12 = 12; diff --git a/variants/lionbit/pins_arduino.h b/variants/lionbit/pins_arduino.h index 25d7bc1765c..9ba474664f7 100644 --- a/variants/lionbit/pins_arduino.h +++ b/variants/lionbit/pins_arduino.h @@ -3,85 +3,85 @@ #include -static const uint8_t LED_BUILTIN = 0; // GPIO0, ADC2_CH1, TOUCH1, RTC_GPIO11, CLK_OUT1,EMAC_TX_CLK -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +static const uint8_t LED_BUILTIN = 0; // GPIO0, ADC2_CH1, TOUCH1, RTC_GPIO11, CLK_OUT1,EMAC_TX_CLK +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -static const uint8_t SWITCH_A = 2; // GPIO2, ADC2_CH2, TOUCH2, RTC_GPIO12, HSPIWP, HS2_DATA0,SD_DATA0 -static const uint8_t SWITCH_B = 4; // GPIO4, ADC2_CH0, TOUCH0, RTC_GPIO10, HSPIHD, HS2_DATA1,SD_DATA1, EMAC_TX_ER +static const uint8_t SWITCH_A = 2; // GPIO2, ADC2_CH2, TOUCH2, RTC_GPIO12, HSPIWP, HS2_DATA0,SD_DATA0 +static const uint8_t SWITCH_B = 4; // GPIO4, ADC2_CH0, TOUCH0, RTC_GPIO10, HSPIHD, HS2_DATA1,SD_DATA1, EMAC_TX_ER static const uint8_t TX = 1; static const uint8_t RX = 3; /* LionBit pin setup */ -static const uint8_t D0 = 3; //Rx GPIO3, U0RXD, CLK_OUT2 -static const uint8_t D1 = 1; //TX GPIO1, U0TXD, CLK_OUT3, EMAC_RXD2 +static const uint8_t D0 = 3; //Rx GPIO3, U0RXD, CLK_OUT2 +static const uint8_t D1 = 1; //TX GPIO1, U0TXD, CLK_OUT3, EMAC_RXD2 //------------------------------------------------------------------- //Please do not use while using QIO SPI mode ; Use only DIO flash mode -static const uint8_t D2 = 9; //I/O U1RX GPIO9, SD_DATA2, SPIHD, HS1_DATA2, U1RXD -static const uint8_t D3 = 10; //I/O U1TX GPIO10, SD_DATA3, SPIWP, HS1_DATA3, U1TXD +static const uint8_t D2 = 9; //I/O U1RX GPIO9, SD_DATA2, SPIHD, HS1_DATA2, U1RXD +static const uint8_t D3 = 10; //I/O U1TX GPIO10, SD_DATA3, SPIWP, HS1_DATA3, U1TXD //------------------------------------------------------------------- -static const uint8_t U1RX = 9; //I/O U1RX -static const uint8_t U1TX = 10; //I/O U1TX +static const uint8_t U1RX = 9; //I/O U1RX +static const uint8_t U1TX = 10; //I/O U1TX //Second Segment - Sector -01 (Voltage (*5v or 3.3V) can be selected by using D4-7 Jumper -static const uint8_t D4 = 16; //I/O U2RX GPIO16, HS1_DATA4, U2RXD, EMAC_CLK_OUT -static const uint8_t D5 = 17; //I/O U2TX GPIO17, HS1_DATA5, U2TXD, EMAC_CLK_OUT_180 -static const uint8_t D6 = 21; //I/O SDA GPIO21, VSPIHD, EMAC_TX_EN -static const uint8_t D7 = 22; //I/O SCl GPIO22, VSPIWP, U0RTS, EMAC_TXD1 +static const uint8_t D4 = 16; //I/O U2RX GPIO16, HS1_DATA4, U2RXD, EMAC_CLK_OUT +static const uint8_t D5 = 17; //I/O U2TX GPIO17, HS1_DATA5, U2TXD, EMAC_CLK_OUT_180 +static const uint8_t D6 = 21; //I/O SDA GPIO21, VSPIHD, EMAC_TX_EN +static const uint8_t D7 = 22; //I/O SCl GPIO22, VSPIWP, U0RTS, EMAC_TXD1 //Second Segment - Sector -02 (Voltage (*5v or 3.3V) can be selected by using D8-11 Jumper -static const uint8_t D8 = 5; //I/O GPIO5, VSPICS0, HS1_DATA6, EMAC_RX_CLK -static const uint8_t D9 = 23; //I/O GPIO23, VSPID, HS1_STROBE **********************************************Don not use when display "ON or USE"************************* -static const uint8_t D10 = 19; //I/O GPIO19, VSPIQ, U0CTS, EMAC_TXD0 -static const uint8_t D11 = 18; //I/O GPIO18, VSPICLK, HS1_DATA7 **********************************************Don not use when display "ON or USE"************************* +static const uint8_t D8 = 5; //I/O GPIO5, VSPICS0, HS1_DATA6, EMAC_RX_CLK +static const uint8_t D9 = 23; //I/O GPIO23, VSPID, HS1_STROBE **********************************************Don not use when display "ON or USE"************************* +static const uint8_t D10 = 19; //I/O GPIO19, VSPIQ, U0CTS, EMAC_TXD0 +static const uint8_t D11 = 18; //I/O GPIO18, VSPICLK, HS1_DATA7 **********************************************Don not use when display "ON or USE"************************* // Analog to Digital Converter (Support 5V) ADC2 pins not recommended while using Wifi -static const uint8_t A0 /*ADC2_CH3 */ = 12; //MAX 5V,I/O GPIO12, ADC2_CH5, TOUCH5, RTC_GPIO15, MTDI, HSPIQ, HS2_DATA2,SD_DATA2, EMAC_TXD3 -static const uint8_t A1 /*ADC1_CH0 */ = 14; //MAX 5V,I/O GPIO14, ADC2_CH6, TOUCH6, RTC_GPIO16, MTMS, HSPICLK, HS2_CLK,SD_CLK, EMAC_TXD2 -static const uint8_t A2 /*ADC2_CH6 */ = 34; //MAX 5V,GPIO34, ADC1_CH6, RTC_GPIO4 ***********************/////////////////////Connected LDR///////////////////////////// -static const uint8_t A3 /*ADC1_CH7 */ = 35; //MAX 5V,GPIO35, ADC1_CH7, RTC_GPIO5 -static const uint8_t A4 /*ADC2_CH5 */ = 15; //MAX 5V,GPIO15, ADC2_CH3, TOUCH3, MTDO, HSPICS0, RTC_GPIO13, HS2_CMD,SD_CMD, EMAC_RXD3 -static const uint8_t A5 /*ADC2_CH4 */ = 13; //MAX 5V,GPIO13, ADC2_CH4, TOUCH4, RTC_GPIO14, MTCK, HSPID, HS2_DATA3,SD_DATA3, EMAC_RX_ER - //------------------------------------------------------------------- +static const uint8_t A0 /*ADC2_CH3 */ = 12; //MAX 5V,I/O GPIO12, ADC2_CH5, TOUCH5, RTC_GPIO15, MTDI, HSPIQ, HS2_DATA2,SD_DATA2, EMAC_TXD3 +static const uint8_t A1 /*ADC1_CH0 */ = 14; //MAX 5V,I/O GPIO14, ADC2_CH6, TOUCH6, RTC_GPIO16, MTMS, HSPICLK, HS2_CLK,SD_CLK, EMAC_TXD2 +static const uint8_t A2 /*ADC2_CH6 */ = 34; //MAX 5V,GPIO34, ADC1_CH6, RTC_GPIO4 ***********************/////////////////////Connected LDR///////////////////////////// +static const uint8_t A3 /*ADC1_CH7 */ = 35; //MAX 5V,GPIO35, ADC1_CH7, RTC_GPIO5 +static const uint8_t A4 /*ADC2_CH5 */ = 15; //MAX 5V,GPIO15, ADC2_CH3, TOUCH3, MTDO, HSPICS0, RTC_GPIO13, HS2_CMD,SD_CMD, EMAC_RXD3 +static const uint8_t A5 /*ADC2_CH4 */ = 13; //MAX 5V,GPIO13, ADC2_CH4, TOUCH4, RTC_GPIO14, MTCK, HSPID, HS2_DATA3,SD_DATA3, EMAC_RX_ER + //------------------------------------------------------------------- //------------------Touch Sensors------------------------------------------------- -static const uint8_t VP = 36; // GPIO36, ADC1_CH0, RTC_GPIO0 -static const uint8_t VN = 39; // GPIO39, ADC1_CH3, RTC_GPIO3 +static const uint8_t VP = 36; // GPIO36, ADC1_CH0, RTC_GPIO0 +static const uint8_t VN = 39; // GPIO39, ADC1_CH3, RTC_GPIO3 static const uint8_t T0 = 36; static const uint8_t T1 = 39; -static const uint8_t DAC1 = 25; // I/O GPIO25, DAC_1, ADC2_CH8, RTC_GPIO6, EMAC_RXD0 -static const uint8_t DAC2 = 26; // I/O GPIO26, DAC_2, ADC2_CH9, RTC_GPIO7, EMAC_RXD1 +static const uint8_t DAC1 = 25; // I/O GPIO25, DAC_1, ADC2_CH8, RTC_GPIO6, EMAC_RXD0 +static const uint8_t DAC2 = 26; // I/O GPIO26, DAC_2, ADC2_CH9, RTC_GPIO7, EMAC_RXD1 static const uint8_t SDA = 21; static const uint8_t SCL = 22; /* Hardware HSPI */ -static const uint8_t MOSI = 13; // 13; -static const uint8_t MISO = 12; // 12; -static const uint8_t SCK = 14; // 14; -static const uint8_t SS = 15; // 15; +static const uint8_t MOSI = 13; // 13; +static const uint8_t MISO = 12; // 12; +static const uint8_t SCK = 14; // 14; +static const uint8_t SS = 15; // 15; /* Software VSPI [Note : D9 and D11 Do not use when display "ON or USE"]*/ static const uint8_t VMOSI = 23; //23 /*Do not use when display "ON or USE"*/ -static const uint8_t VMISO = 19; // 19 -static const uint8_t VSCK = 18; // 18 /*Do not use when display "ON or USE"*/ -static const uint8_t VSS = 5; // 5 +static const uint8_t VMISO = 19; // 19 +static const uint8_t VSCK = 18; // 18 /*Do not use when display "ON or USE"*/ +static const uint8_t VSS = 5; // 5 // Inbuilt Display Unit 128*128 ST7735 Driver -static const uint8_t RST = 33; // - RESET GPIO33, XTAL_32K_N (32.768 kHz crystal oscillator output),ADC1_CH5, TOUCH8, RTC_GPIO8 -static const uint8_t CLK = 18; // - (18) CLK (D11) and D9 pin will engaged when display "ON or USE" -static const uint8_t CS = 27; // - CS GPIO27, ADC2_CH7, TOUCH7, RTC_GPIO17, EMAC_RX_DV -static const uint8_t DC = 32; //- DC/A0 GPIO32, XTAL_32K_P (32.768 kHz crystal oscillator input), ADC1_CH4,TOUCH9, RTC_GPIO9 -static const uint8_t ST_MOSI = 23; // - MOSI (D9) This D9 pin will engaged when display "ON or USE" - -static const uint8_t MTDO = 15; // A4 JTAG SIGNAL -> TDO -static const uint8_t MTDI = 12; // A0 JTAG SIGNAL -> TDI -static const uint8_t MTCK = 13; // A5 JTAG SIGNAL -> TCK -static const uint8_t MTMS = 14; // A1 JTAG SIGNAL -> TMS +static const uint8_t RST = 33; // - RESET GPIO33, XTAL_32K_N (32.768 kHz crystal oscillator output),ADC1_CH5, TOUCH8, RTC_GPIO8 +static const uint8_t CLK = 18; // - (18) CLK (D11) and D9 pin will engaged when display "ON or USE" +static const uint8_t CS = 27; // - CS GPIO27, ADC2_CH7, TOUCH7, RTC_GPIO17, EMAC_RX_DV +static const uint8_t DC = 32; //- DC/A0 GPIO32, XTAL_32K_P (32.768 kHz crystal oscillator input), ADC1_CH4,TOUCH9, RTC_GPIO9 +static const uint8_t ST_MOSI = 23; // - MOSI (D9) This D9 pin will engaged when display "ON or USE" + +static const uint8_t MTDO = 15; // A4 JTAG SIGNAL -> TDO +static const uint8_t MTDI = 12; // A0 JTAG SIGNAL -> TDI +static const uint8_t MTCK = 13; // A5 JTAG SIGNAL -> TCK +static const uint8_t MTMS = 14; // A1 JTAG SIGNAL -> TMS #endif /* Pins_Arduino_h */ diff --git a/variants/lionbits3/pins_arduino.h b/variants/lionbits3/pins_arduino.h index f7817d8340d..7967a7513dd 100644 --- a/variants/lionbits3/pins_arduino.h +++ b/variants/lionbits3/pins_arduino.h @@ -3,12 +3,12 @@ #include -static const uint8_t LED_BUILTIN = 0; //GPIO0, -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +static const uint8_t LED_BUILTIN = 0; //GPIO0, +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -static const uint8_t SWITCH_A = 46; //GPIO46, -static const uint8_t SWITCH_B = 47; //GPIO47, +static const uint8_t SWITCH_A = 46; //GPIO46, +static const uint8_t SWITCH_B = 47; //GPIO47, //Wifi and Bluetooth LEDs static const uint8_t WIFI_LED = 38; static const uint8_t BT_LED = 37; @@ -17,78 +17,78 @@ static const uint8_t BT_LED = 37; static const uint8_t TX = 1; static const uint8_t RX = 3; //------------------------------------------------------------------- -static const uint8_t U1RX = 9; //IO,GPIO9 -static const uint8_t U1TX = 10;//IO,GPIO10 +static const uint8_t U1RX = 9; //IO,GPIO9 +static const uint8_t U1TX = 10; //IO,GPIO10 /* LionBits3 pin setup */ -static const uint8_t D0 = 3; //RX,GPIO3,MCPWM -static const uint8_t D1 = 1; //TX,GPIO1,ADC1_CH0,MCPWM -static const uint8_t D2 = 9; //IO,GPIO9,ADC1_CH8,TOUCH9,MCPWM -static const uint8_t D3 = 10; //IO,GPIO10,ADC1_CH9,TOUCH10,MCPWM -static const uint8_t D4 = 11; //IO,GPIO11,ADC2_CH0,TOUCH11,MCPWM -static const uint8_t D5 = 12; //IO,GPIO12,ADC2_CH1,TOUCH12,MCPWM -static const uint8_t D6 = 13; //IO,GPIO13,ADC2_CH2,TOUCH13,MCPWM -static const uint8_t D7 = 14; //IO,GPIO14,ADC2_CH3,TOUCH14,MCPWM -static const uint8_t D8 = 15; //IO,GPIO15,ADC2_CH4,MCPWM -static const uint8_t D9 = 16; //IO,GPIO16,ADC2_CH5,MCPWM -static const uint8_t D10 = 17; //IO,GPIO17,ADC2_CH6,MCPWM -static const uint8_t D11 = 18; //IO,GPIO18,ADC2_CH7,MCPWM -static const uint8_t D12 = 8; //IO,GPIO8,ADC1_CH7,MCPWM -static const uint8_t D13 = 39; //IO,GPIO39,MCPWM -static const uint8_t D14 = 40; //IO,GPIO40,MCPWM -static const uint8_t D15 = 41; //IO,GPIO41,MCPWM -static const uint8_t D16 = 48; //IO,GPIO48,MCPWM -static const uint8_t D17 = 21; //IO,GPIO21,MCPWM +static const uint8_t D0 = 3; //RX,GPIO3,MCPWM +static const uint8_t D1 = 1; //TX,GPIO1,ADC1_CH0,MCPWM +static const uint8_t D2 = 9; //IO,GPIO9,ADC1_CH8,TOUCH9,MCPWM +static const uint8_t D3 = 10; //IO,GPIO10,ADC1_CH9,TOUCH10,MCPWM +static const uint8_t D4 = 11; //IO,GPIO11,ADC2_CH0,TOUCH11,MCPWM +static const uint8_t D5 = 12; //IO,GPIO12,ADC2_CH1,TOUCH12,MCPWM +static const uint8_t D6 = 13; //IO,GPIO13,ADC2_CH2,TOUCH13,MCPWM +static const uint8_t D7 = 14; //IO,GPIO14,ADC2_CH3,TOUCH14,MCPWM +static const uint8_t D8 = 15; //IO,GPIO15,ADC2_CH4,MCPWM +static const uint8_t D9 = 16; //IO,GPIO16,ADC2_CH5,MCPWM +static const uint8_t D10 = 17; //IO,GPIO17,ADC2_CH6,MCPWM +static const uint8_t D11 = 18; //IO,GPIO18,ADC2_CH7,MCPWM +static const uint8_t D12 = 8; //IO,GPIO8,ADC1_CH7,MCPWM +static const uint8_t D13 = 39; //IO,GPIO39,MCPWM +static const uint8_t D14 = 40; //IO,GPIO40,MCPWM +static const uint8_t D15 = 41; //IO,GPIO41,MCPWM +static const uint8_t D16 = 48; //IO,GPIO48,MCPWM +static const uint8_t D17 = 21; //IO,GPIO21,MCPWM //Other pins. -static const uint8_t BUZZER = 21; -static const uint8_t LDR = 7; +static const uint8_t BUZZER = 21; +static const uint8_t LDR = 7; static const uint8_t RGBLED = 48; // Analog to Digital Converter (Support 5V) ADC2 pins not recommended while using Wifi -static const uint8_t A0 = 2; //IO,GPIO2,ADC1_CH1,TOUCH2,MCPWM -static const uint8_t A1 = 1; //IO,GPIO1,ADC1_CH0,TOUCH1,MCPWM -static const uint8_t A2 = 3; //IO,GPIO3,ADC1_CH2,TOUCH3,MCPWM -static const uint8_t A3 = 4; //IO,GPIO4,ADC1_CH3,TOUCH4,MCPWM -static const uint8_t A4 = 5; //IO,GPIO5,ADC1_CH4,TOUCH5,MCPWM -static const uint8_t A5 = 6; //IO,GPIO6,ADC1_CH5,TOUCH6,MCPWM -static const uint8_t A6 = 7; //IO,GPIO7,ADC1_CH6,TOUCH7,MCPWM -static const uint8_t AD1 = 7; //IO,GPIO7,ADC1_CH6,TOUCH7,MCPWM +static const uint8_t A0 = 2; //IO,GPIO2,ADC1_CH1,TOUCH2,MCPWM +static const uint8_t A1 = 1; //IO,GPIO1,ADC1_CH0,TOUCH1,MCPWM +static const uint8_t A2 = 3; //IO,GPIO3,ADC1_CH2,TOUCH3,MCPWM +static const uint8_t A3 = 4; //IO,GPIO4,ADC1_CH3,TOUCH4,MCPWM +static const uint8_t A4 = 5; //IO,GPIO5,ADC1_CH4,TOUCH5,MCPWM +static const uint8_t A5 = 6; //IO,GPIO6,ADC1_CH5,TOUCH6,MCPWM +static const uint8_t A6 = 7; //IO,GPIO7,ADC1_CH6,TOUCH7,MCPWM +static const uint8_t AD1 = 7; //IO,GPIO7,ADC1_CH6,TOUCH7,MCPWM // Inbuilt Display Unit 128*128 ST7735 Driver New -static const uint8_t SDA = 40; //GPIO40; -static const uint8_t SCL = 41; //GPIO41; +static const uint8_t SDA = 40; //GPIO40; +static const uint8_t SCL = 41; //GPIO41; /* Hardware HSPI */ -static const uint8_t MOSI = 35; //GPIO35; -static const uint8_t MISO = 37; //GPIO37; -static const uint8_t SCK = 36; //GPIO36; -static const uint8_t SS = 34; //GPIO34; -static const uint8_t SDO = 35; //GPIO35; -static const uint8_t SDI = 37; //GPIO37; -//---------------------------------- - -static const uint8_t TFT_RST = 38; //GPIO38; -static const uint8_t TFT_SCLK = 35; //GPIO35; -static const uint8_t TFT_CS = 42; //GPIO42; -static const uint8_t TFT_DC = 37; //GPIO37; -static const uint8_t TFT_MOSI = 36; //GPIO36; - -static const uint8_t LCD_A0 = 37; //GPIO37, -static const uint8_t LCD_BACK_LIGHT = 45; //GPIO45, -static const uint8_t DAC1 = 21; //GPIO21, -//LCD aditional pins +static const uint8_t MOSI = 35; //GPIO35; +static const uint8_t MISO = 37; //GPIO37; +static const uint8_t SCK = 36; //GPIO36; +static const uint8_t SS = 34; //GPIO34; +static const uint8_t SDO = 35; //GPIO35; +static const uint8_t SDI = 37; //GPIO37; +//---------------------------------- + +static const uint8_t TFT_RST = 38; //GPIO38; +static const uint8_t TFT_SCLK = 35; //GPIO35; +static const uint8_t TFT_CS = 42; //GPIO42; +static const uint8_t TFT_DC = 37; //GPIO37; +static const uint8_t TFT_MOSI = 36; //GPIO36; + +static const uint8_t LCD_A0 = 37; //GPIO37, +static const uint8_t LCD_BACK_LIGHT = 45; //GPIO45, +static const uint8_t DAC1 = 21; //GPIO21, +//LCD additional pins //Adafruit 128*128 ST7735 Driver New -static const uint8_t rst = 38; -static const uint8_t sclk = 35; -static const uint8_t cs = 42; -static const uint8_t dc = 37; -static const uint8_t mosi = 36; +static const uint8_t rst = 38; +static const uint8_t sclk = 35; +static const uint8_t cs = 42; +static const uint8_t dc = 37; +static const uint8_t mosi = 36; -#define VP 36 //GPIO36, -#define VN 39 //GPIO39, +#define VP 36 //GPIO36, +#define VN 39 //GPIO39, -#endif /* Pins_Arduino_h */ \ No newline at end of file +#endif /* Pins_Arduino_h */ diff --git a/variants/lolin32-lite/pins_arduino.h b/variants/lolin32-lite/pins_arduino.h old mode 100755 new mode 100644 index 6aa497a8575..140d06b8423 --- a/variants/lolin32-lite/pins_arduino.h +++ b/variants/lolin32-lite/pins_arduino.h @@ -7,16 +7,16 @@ static const uint8_t TX = 1; static const uint8_t RX = 3; static const uint8_t LED_BUILTIN = 22; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t SDA = 19; static const uint8_t SCL = 23; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/lolin32/pins_arduino.h b/variants/lolin32/pins_arduino.h index cba6162b645..12ca95c4cab 100644 --- a/variants/lolin32/pins_arduino.h +++ b/variants/lolin32/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 5; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -13,10 +13,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/lolin_c3_mini/pins_arduino.h b/variants/lolin_c3_mini/pins_arduino.h index 842683330cd..c7357975ac7 100644 --- a/variants/lolin_c3_mini/pins_arduino.h +++ b/variants/lolin_c3_mini/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 7; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 21; @@ -13,10 +13,10 @@ static const uint8_t RX = 20; static const uint8_t SDA = 8; static const uint8_t SCL = 10; -static const uint8_t SS = 5; -static const uint8_t MOSI = 4; -static const uint8_t MISO = 3; -static const uint8_t SCK = 2; +static const uint8_t SS = 5; +static const uint8_t MOSI = 4; +static const uint8_t MISO = 3; +static const uint8_t SCK = 2; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/lolin_c3_pico/pins_arduino.h b/variants/lolin_c3_pico/pins_arduino.h index e66e7bfd14b..8d4cfc5c4f0 100644 --- a/variants/lolin_c3_pico/pins_arduino.h +++ b/variants/lolin_c3_pico/pins_arduino.h @@ -6,7 +6,7 @@ #include static const uint8_t LED_BUILTIN = 7; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 21; @@ -15,12 +15,12 @@ static const uint8_t RX = 20; static const uint8_t SDA = 8; static const uint8_t SCL = 10; -static const uint8_t VBAT = 3; +static const uint8_t VBAT = 3; -static const uint8_t SCK = 2; -static const uint8_t MISO = 0; -static const uint8_t MOSI = 4; -static const uint8_t SS = 5; +static const uint8_t SCK = 2; +static const uint8_t MISO = 0; +static const uint8_t MOSI = 4; +static const uint8_t SS = 5; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/lolin_s2_mini/pins_arduino.h b/variants/lolin_s2_mini/pins_arduino.h index 558e2e02a23..342650d07e0 100644 --- a/variants/lolin_s2_mini/pins_arduino.h +++ b/variants/lolin_s2_mini/pins_arduino.h @@ -4,22 +4,22 @@ #include // Default USB Settings -#define USB_VID 0x303a -#define USB_PID 0x80C2 -#define USB_MANUFACTURER "WEMOS.CC" -#define USB_PRODUCT "LOLIN-S2-MINI" -#define USB_SERIAL "0" +#define USB_VID 0x303a +#define USB_PID 0x80C2 +#define USB_MANUFACTURER "WEMOS.CC" +#define USB_PRODUCT "LOLIN-S2-MINI" +#define USB_SERIAL "0" // Default USB FirmwareMSC Settings -#define USB_FW_MSC_VENDOR_ID "ESP32-S2" //max 8 chars -#define USB_FW_MSC_PRODUCT_ID "Firmware MSC" //max 16 chars -#define USB_FW_MSC_PRODUCT_REVISION "1.23" //max 4 chars -#define USB_FW_MSC_VOLUME_NAME "S2-Firmware" //max 11 chars -#define USB_FW_MSC_SERIAL_NUMBER 0x00000000 +#define USB_FW_MSC_VENDOR_ID "ESP32-S2" //max 8 chars +#define USB_FW_MSC_PRODUCT_ID "Firmware MSC" //max 16 chars +#define USB_FW_MSC_PRODUCT_REVISION "1.23" //max 4 chars +#define USB_FW_MSC_VOLUME_NAME "S2-Firmware" //max 11 chars +#define USB_FW_MSC_SERIAL_NUMBER 0x00000000 static const uint8_t LED_BUILTIN = 15; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 39; @@ -28,10 +28,10 @@ static const uint8_t RX = 37; static const uint8_t SDA = 33; static const uint8_t SCL = 35; -static const uint8_t SS = 12; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 9; -static const uint8_t SCK = 7; +static const uint8_t SS = 12; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 9; +static const uint8_t SCK = 7; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/lolin_s2_pico/pins_arduino.h b/variants/lolin_s2_pico/pins_arduino.h index 325e11ecff1..6ccd4c5764e 100644 --- a/variants/lolin_s2_pico/pins_arduino.h +++ b/variants/lolin_s2_pico/pins_arduino.h @@ -4,22 +4,22 @@ #include // Default USB Settings -#define USB_VID 0x303a -#define USB_PID 0x80C5 -#define USB_MANUFACTURER "WEMOS.CC" -#define USB_PRODUCT "LOLIN-S2-PICO" -#define USB_SERIAL "0" +#define USB_VID 0x303a +#define USB_PID 0x80C5 +#define USB_MANUFACTURER "WEMOS.CC" +#define USB_PRODUCT "LOLIN-S2-PICO" +#define USB_SERIAL "0" // Default USB FirmwareMSC Settings -#define USB_FW_MSC_VENDOR_ID "ESP32-S2" //max 8 chars -#define USB_FW_MSC_PRODUCT_ID "Firmware MSC" //max 16 chars -#define USB_FW_MSC_PRODUCT_REVISION "1.23" //max 4 chars -#define USB_FW_MSC_VOLUME_NAME "S2-Firmware" //max 11 chars -#define USB_FW_MSC_SERIAL_NUMBER 0x00000000 +#define USB_FW_MSC_VENDOR_ID "ESP32-S2" //max 8 chars +#define USB_FW_MSC_PRODUCT_ID "Firmware MSC" //max 16 chars +#define USB_FW_MSC_PRODUCT_REVISION "1.23" //max 4 chars +#define USB_FW_MSC_VOLUME_NAME "S2-Firmware" //max 11 chars +#define USB_FW_MSC_SERIAL_NUMBER 0x00000000 static const uint8_t LED_BUILTIN = 10; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 38; @@ -28,10 +28,10 @@ static const uint8_t RX = 33; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 34; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -72,6 +72,6 @@ static const uint8_t T14 = 14; static const uint8_t DAC1 = 17; static const uint8_t DAC2 = 18; -static const uint8_t S2_PICO_OLED_RESET = 18; +static const uint8_t S2_PICO_OLED_RESET = 18; #endif /* Pins_Arduino_h */ diff --git a/variants/lolin_s3/pins_arduino.h b/variants/lolin_s3/pins_arduino.h index d058630b69d..048123df30f 100644 --- a/variants/lolin_s3/pins_arduino.h +++ b/variants/lolin_s3/pins_arduino.h @@ -7,8 +7,8 @@ #define USB_VID 0x303a #define USB_PID 0x1001 -static const uint8_t LED_BUILTIN = 38+SOC_GPIO_PIN_COUNT; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = 38 + SOC_GPIO_PIN_COUNT; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 @@ -19,10 +19,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 42; static const uint8_t SCL = 41; -static const uint8_t SS = 10; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 13; -static const uint8_t SCK = 12; +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/lolin_s3_mini/pins_arduino.h b/variants/lolin_s3_mini/pins_arduino.h index 8c8b5c93854..8765ec558b7 100644 --- a/variants/lolin_s3_mini/pins_arduino.h +++ b/variants/lolin_s3_mini/pins_arduino.h @@ -7,8 +7,8 @@ #define USB_VID 0x303a #define USB_PID 0x8167 -static const uint8_t LED_BUILTIN = 47+SOC_GPIO_PIN_COUNT; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = 47 + SOC_GPIO_PIN_COUNT; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 @@ -19,10 +19,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 35; static const uint8_t SCL = 36; -static const uint8_t SS = 10; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 13; -static const uint8_t SCK = 12; +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/lolin_s3_pro/pins_arduino.h b/variants/lolin_s3_pro/pins_arduino.h index 6a3259ed6e8..c09f0987e61 100644 --- a/variants/lolin_s3_pro/pins_arduino.h +++ b/variants/lolin_s3_pro/pins_arduino.h @@ -7,8 +7,8 @@ #define USB_VID 0x303a #define USB_PID 0x8161 -static const uint8_t LED_BUILTIN = 38+SOC_GPIO_PIN_COUNT; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = 38 + SOC_GPIO_PIN_COUNT; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 @@ -19,16 +19,16 @@ static const uint8_t RX = 44; static const uint8_t SDA = 9; static const uint8_t SCL = 10; -static const uint8_t SS = 0; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 13; -static const uint8_t SCK = 12; +static const uint8_t SS = 0; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; -static const uint8_t TF_CS = 46; +static const uint8_t TF_CS = 46; -static const uint8_t TS_CS = 45; -static const uint8_t TFT_CS = 48; -static const uint8_t TFT_DC = 47; +static const uint8_t TS_CS = 45; +static const uint8_t TFT_CS = 48; +static const uint8_t TFT_DC = 47; static const uint8_t TFT_RST = 21; static const uint8_t TFT_LED = 14; diff --git a/variants/lopy/pins_arduino.h b/variants/lopy/pins_arduino.h index 2c44d12d06b..5f1756c4dd8 100644 --- a/variants/lopy/pins_arduino.h +++ b/variants/lopy/pins_arduino.h @@ -5,37 +5,37 @@ #include "soc/soc_caps.h" // SPI LoRa Radio -#define LORA_SCK 5 // GPIO5 - SX1276 SCK -#define LORA_MISO 19 // GPIO19 - SX1276 MISO -#define LORA_MOSI 27 // GPIO27 - SX1276 MOSI -#define LORA_CS 17 // GPIO17 - SX1276 CS -#define LORA_RST 18 // GPIO18 - SX1276 RST -#define LORA_IRQ 23 // GPIO23 - SX1276 IO0 +#define LORA_SCK 5 // GPIO5 - SX1276 SCK +#define LORA_MISO 19 // GPIO19 - SX1276 MISO +#define LORA_MOSI 27 // GPIO27 - SX1276 MOSI +#define LORA_CS 17 // GPIO17 - SX1276 CS +#define LORA_RST 18 // GPIO18 - SX1276 RST +#define LORA_IRQ 23 // GPIO23 - SX1276 IO0 #define LORA_IO0 LORA_IRQ // alias #define LORA_IO1 LORA_IRQ // tied by diode to IO0 #define LORA_IO2 LORA_IRQ // tied by diode to IO0 // Neopixel -#define PIN_NEOPIXEL 0 // ->2812 RGB !!! -static const uint8_t LED_BUILTIN = PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define PIN_NEOPIXEL 0 // ->2812 RGB !!! +static const uint8_t LED_BUILTIN = PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 -#define ANT_SELECT 16 // GPIO16 - External Antenna Switch +#define ANT_SELECT 16 // GPIO16 - External Antenna Switch static const uint8_t TX = 1; static const uint8_t RX = 3; static const uint8_t SDA = 12; static const uint8_t SCL = 13; - -static const uint8_t SS = 17; -static const uint8_t MOSI = 22; -static const uint8_t MISO = 37; -static const uint8_t SCK = 13; + +static const uint8_t SS = 17; +static const uint8_t MOSI = 22; +static const uint8_t MISO = 37; +static const uint8_t SCK = 13; static const uint8_t A0 = 36; static const uint8_t A1 = 37; diff --git a/variants/lopy4/pins_arduino.h b/variants/lopy4/pins_arduino.h index ba89a4b401f..10500ec7a9a 100644 --- a/variants/lopy4/pins_arduino.h +++ b/variants/lopy4/pins_arduino.h @@ -5,37 +5,37 @@ #include "soc/soc_caps.h" // SPI LoRa Radio -#define LORA_SCK 5 // GPIO5 - SX1276 SCK -#define LORA_MISO 19 // GPIO19 - SX1276 MISO -#define LORA_MOSI 27 // GPIO27 - SX1276 MOSI -#define LORA_CS 18 // GPIO18 - SX1276 CS -#define LORA_IRQ 23 // GPIO23 - SX1276 IO0 +#define LORA_SCK 5 // GPIO5 - SX1276 SCK +#define LORA_MISO 19 // GPIO19 - SX1276 MISO +#define LORA_MOSI 27 // GPIO27 - SX1276 MOSI +#define LORA_CS 18 // GPIO18 - SX1276 CS +#define LORA_IRQ 23 // GPIO23 - SX1276 IO0 #define LORA_IO0 LORA_IRQ // alias -#define LORA_IO1 LORA_IRQ // tied by diode to IO0 -#define LORA_IO2 LORA_IRQ // tied by diode to IO0 +#define LORA_IO1 LORA_IRQ // tied by diode to IO0 +#define LORA_IO2 LORA_IRQ // tied by diode to IO0 #define LORA_RST NOT_A_PIN // Neopixel -#define PIN_NEOPIXEL 0 // ->2812 RGB !!! -static const uint8_t LED_BUILTIN = PIN_NEOPIXEL+SOC_GPIO_PIN_COUNT; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define PIN_NEOPIXEL 0 // ->2812 RGB !!! +static const uint8_t LED_BUILTIN = PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 -#define ANT_SELECT 21 // GPIO21 - External Antenna Switch +#define ANT_SELECT 21 // GPIO21 - External Antenna Switch static const uint8_t TX = 1; static const uint8_t RX = 3; static const uint8_t SDA = 12; static const uint8_t SCL = 13; - -static const uint8_t SS = 18; -static const uint8_t MOSI = 22; -static const uint8_t MISO = 37; -static const uint8_t SCK = 13; + +static const uint8_t SS = 18; +static const uint8_t MOSI = 22; +static const uint8_t MISO = 37; +static const uint8_t SCK = 13; static const uint8_t A0 = 36; static const uint8_t A1 = 37; diff --git a/variants/m5stack_atom/pins_arduino.h b/variants/m5stack_atom/pins_arduino.h index 06a3ec76f64..59fa3341f12 100644 --- a/variants/m5stack_atom/pins_arduino.h +++ b/variants/m5stack_atom/pins_arduino.h @@ -34,9 +34,9 @@ static const uint8_t DAC2 = 26; static const uint8_t ADC1 = 35; static const uint8_t ADC2 = 36; -static const uint8_t SS = 19; -static const uint8_t MOSI = 33; -static const uint8_t MISO = 23; -static const uint8_t SCK = 22; +static const uint8_t SS = 19; +static const uint8_t MOSI = 33; +static const uint8_t MISO = 23; +static const uint8_t SCK = 22; #endif /* Pins_Arduino_h */ diff --git a/variants/m5stack_atoms3/pins_arduino.h b/variants/m5stack_atoms3/pins_arduino.h index 2fab4d136b1..0a5cf777017 100644 --- a/variants/m5stack_atoms3/pins_arduino.h +++ b/variants/m5stack_atoms3/pins_arduino.h @@ -11,9 +11,9 @@ // Use different pin with 3V and connect with 48 // and change this setup for the chosen pin (for example 38) static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 48; -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN -#define RGB_BUILTIN LED_BUILTIN +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN +#define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 static const uint8_t TX = 43; @@ -25,20 +25,20 @@ static const uint8_t RXD2 = 2; static const uint8_t SDA = 38; static const uint8_t SCL = 39; -static const uint8_t SS = 15; +static const uint8_t SS = 15; static const uint8_t MOSI = 21; static const uint8_t MISO = -1; -static const uint8_t SCK = 17; - -static const uint8_t G0 = 0; -static const uint8_t G1 = 1; -static const uint8_t G2 = 2; -static const uint8_t G3 = 3; -static const uint8_t G4 = 4; -static const uint8_t G5 = 5; -static const uint8_t G6 = 6; -static const uint8_t G7 = 7; -static const uint8_t G8 = 8; +static const uint8_t SCK = 17; + +static const uint8_t G0 = 0; +static const uint8_t G1 = 1; +static const uint8_t G2 = 2; +static const uint8_t G3 = 3; +static const uint8_t G4 = 4; +static const uint8_t G5 = 5; +static const uint8_t G6 = 6; +static const uint8_t G7 = 7; +static const uint8_t G8 = 8; static const uint8_t G36 = 36; static const uint8_t G37 = 37; static const uint8_t G38 = 38; diff --git a/variants/m5stack_capsule/pins_arduino.h b/variants/m5stack_capsule/pins_arduino.h index 2f3473bb368..0209d2162fe 100644 --- a/variants/m5stack_capsule/pins_arduino.h +++ b/variants/m5stack_capsule/pins_arduino.h @@ -16,21 +16,21 @@ static const uint8_t RXD2 = 2; static const uint8_t SDA = 13; static const uint8_t SCL = 15; -static const uint8_t SS = 11; -static const uint8_t MOSI = 12; -static const uint8_t MISO = 39; -static const uint8_t SCK = 14; - -static const uint8_t G0 = 0; -static const uint8_t G1 = 1; -static const uint8_t G2 = 2; -static const uint8_t G3 = 3; -static const uint8_t G4 = 4; -static const uint8_t G5 = 5; -static const uint8_t G6 = 6; -static const uint8_t G7 = 7; -static const uint8_t G8 = 8; -static const uint8_t G9 = 9; +static const uint8_t SS = 11; +static const uint8_t MOSI = 12; +static const uint8_t MISO = 39; +static const uint8_t SCK = 14; + +static const uint8_t G0 = 0; +static const uint8_t G1 = 1; +static const uint8_t G2 = 2; +static const uint8_t G3 = 3; +static const uint8_t G4 = 4; +static const uint8_t G5 = 5; +static const uint8_t G6 = 6; +static const uint8_t G7 = 7; +static const uint8_t G8 = 8; +static const uint8_t G9 = 9; static const uint8_t G10 = 10; static const uint8_t G11 = 11; static const uint8_t G12 = 12; diff --git a/variants/m5stack_cardputer/pins_arduino.h b/variants/m5stack_cardputer/pins_arduino.h index 14a7d56fa06..d0fd5c3467e 100644 --- a/variants/m5stack_cardputer/pins_arduino.h +++ b/variants/m5stack_cardputer/pins_arduino.h @@ -16,21 +16,21 @@ static const uint8_t RXD2 = 2; static const uint8_t SDA = 13; static const uint8_t SCL = 15; -static const uint8_t SS = 12; -static const uint8_t MOSI = 14; -static const uint8_t MISO = 39; -static const uint8_t SCK = 40; - -static const uint8_t G0 = 0; -static const uint8_t G1 = 1; -static const uint8_t G2 = 2; -static const uint8_t G3 = 3; -static const uint8_t G4 = 4; -static const uint8_t G5 = 5; -static const uint8_t G6 = 6; -static const uint8_t G7 = 7; -static const uint8_t G8 = 8; -static const uint8_t G9 = 9; +static const uint8_t SS = 12; +static const uint8_t MOSI = 14; +static const uint8_t MISO = 39; +static const uint8_t SCK = 40; + +static const uint8_t G0 = 0; +static const uint8_t G1 = 1; +static const uint8_t G2 = 2; +static const uint8_t G3 = 3; +static const uint8_t G4 = 4; +static const uint8_t G5 = 5; +static const uint8_t G6 = 6; +static const uint8_t G7 = 7; +static const uint8_t G8 = 8; +static const uint8_t G9 = 9; static const uint8_t G10 = 10; static const uint8_t G11 = 11; static const uint8_t G12 = 12; diff --git a/variants/m5stack_core/pins_arduino.h b/variants/m5stack_core/pins_arduino.h index 1984ab6bc6e..cf807aab447 100644 --- a/variants/m5stack_core/pins_arduino.h +++ b/variants/m5stack_core/pins_arduino.h @@ -12,10 +12,10 @@ static const uint8_t RXD2 = 16; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t G23 = 23; static const uint8_t G19 = 19; diff --git a/variants/m5stack_core2/pins_arduino.h b/variants/m5stack_core2/pins_arduino.h index c5ea5d78eee..a4bd6bb29a6 100644 --- a/variants/m5stack_core2/pins_arduino.h +++ b/variants/m5stack_core2/pins_arduino.h @@ -12,10 +12,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 32; static const uint8_t SCL = 33; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 38; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 38; +static const uint8_t SCK = 18; static const uint8_t G23 = 23; static const uint8_t G38 = 38; diff --git a/variants/m5stack_coreink/pins_arduino.h b/variants/m5stack_coreink/pins_arduino.h index 84c0903c166..5d6f3ea0b4a 100644 --- a/variants/m5stack_coreink/pins_arduino.h +++ b/variants/m5stack_coreink/pins_arduino.h @@ -12,10 +12,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 32; static const uint8_t SCL = 33; -static const uint8_t SS = 9; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 34; -static const uint8_t SCK = 18; +static const uint8_t SS = 9; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 34; +static const uint8_t SCK = 18; static const uint8_t G26 = 26; static const uint8_t G36 = 36; diff --git a/variants/m5stack_cores3/pins_arduino.h b/variants/m5stack_cores3/pins_arduino.h index c9bbb02c72f..33cdb761343 100644 --- a/variants/m5stack_cores3/pins_arduino.h +++ b/variants/m5stack_cores3/pins_arduino.h @@ -11,9 +11,9 @@ // Use different pin with 3V and connect with 48 // and change this setup for the chosen pin (for example 38) static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 48; -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN -#define RGB_BUILTIN LED_BUILTIN +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN +#define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 static const uint8_t TX = 43; @@ -25,21 +25,21 @@ static const uint8_t RXD2 = 18; static const uint8_t SDA = 12; static const uint8_t SCL = 11; -static const uint8_t SS = 15; +static const uint8_t SS = 15; static const uint8_t MOSI = 37; static const uint8_t MISO = 35; -static const uint8_t SCK = 36; - -static const uint8_t G0 = 0; -static const uint8_t G1 = 1; -static const uint8_t G2 = 2; -static const uint8_t G3 = 3; -static const uint8_t G4 = 4; -static const uint8_t G5 = 5; -static const uint8_t G6 = 6; -static const uint8_t G7 = 7; -static const uint8_t G8 = 8; -static const uint8_t G9 = 9; +static const uint8_t SCK = 36; + +static const uint8_t G0 = 0; +static const uint8_t G1 = 1; +static const uint8_t G2 = 2; +static const uint8_t G3 = 3; +static const uint8_t G4 = 4; +static const uint8_t G5 = 5; +static const uint8_t G6 = 6; +static const uint8_t G7 = 7; +static const uint8_t G8 = 8; +static const uint8_t G9 = 9; static const uint8_t G11 = 11; static const uint8_t G12 = 12; static const uint8_t G13 = 13; diff --git a/variants/m5stack_dial/pins_arduino.h b/variants/m5stack_dial/pins_arduino.h index 14a7d56fa06..d0fd5c3467e 100644 --- a/variants/m5stack_dial/pins_arduino.h +++ b/variants/m5stack_dial/pins_arduino.h @@ -16,21 +16,21 @@ static const uint8_t RXD2 = 2; static const uint8_t SDA = 13; static const uint8_t SCL = 15; -static const uint8_t SS = 12; -static const uint8_t MOSI = 14; -static const uint8_t MISO = 39; -static const uint8_t SCK = 40; - -static const uint8_t G0 = 0; -static const uint8_t G1 = 1; -static const uint8_t G2 = 2; -static const uint8_t G3 = 3; -static const uint8_t G4 = 4; -static const uint8_t G5 = 5; -static const uint8_t G6 = 6; -static const uint8_t G7 = 7; -static const uint8_t G8 = 8; -static const uint8_t G9 = 9; +static const uint8_t SS = 12; +static const uint8_t MOSI = 14; +static const uint8_t MISO = 39; +static const uint8_t SCK = 40; + +static const uint8_t G0 = 0; +static const uint8_t G1 = 1; +static const uint8_t G2 = 2; +static const uint8_t G3 = 3; +static const uint8_t G4 = 4; +static const uint8_t G5 = 5; +static const uint8_t G6 = 6; +static const uint8_t G7 = 7; +static const uint8_t G8 = 8; +static const uint8_t G9 = 9; static const uint8_t G10 = 10; static const uint8_t G11 = 11; static const uint8_t G12 = 12; diff --git a/variants/m5stack_fire/pins_arduino.h b/variants/m5stack_fire/pins_arduino.h index 0cb66c9eb50..3759219d1bf 100644 --- a/variants/m5stack_fire/pins_arduino.h +++ b/variants/m5stack_fire/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t G23 = 23; static const uint8_t G19 = 19; diff --git a/variants/m5stack_paper/pins_arduino.h b/variants/m5stack_paper/pins_arduino.h index 68b64386bef..02ccc73d933 100644 --- a/variants/m5stack_paper/pins_arduino.h +++ b/variants/m5stack_paper/pins_arduino.h @@ -12,10 +12,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 25; static const uint8_t SCL = 32; -static const uint8_t SS = 15; -static const uint8_t MOSI = 12; -static const uint8_t MISO = 13; -static const uint8_t SCK = 14; +static const uint8_t SS = 15; +static const uint8_t MOSI = 12; +static const uint8_t MISO = 13; +static const uint8_t SCK = 14; static const uint8_t G25 = 25; static const uint8_t G32 = 32; diff --git a/variants/m5stack_poe_cam/pins_arduino.h b/variants/m5stack_poe_cam/pins_arduino.h index 75c8831b923..9ae9b238731 100644 --- a/variants/m5stack_poe_cam/pins_arduino.h +++ b/variants/m5stack_poe_cam/pins_arduino.h @@ -10,10 +10,10 @@ static const uint8_t SDA = 25; static const uint8_t SCL = 33; // Modified elsewhere -static const uint8_t SS = -1; -static const uint8_t MOSI = -1; -static const uint8_t MISO = -1; -static const uint8_t SCK = -1; +static const uint8_t SS = -1; +static const uint8_t MOSI = -1; +static const uint8_t MISO = -1; +static const uint8_t SCK = -1; static const uint8_t G23 = 23; static const uint8_t G25 = 25; diff --git a/variants/m5stack_stamp_c3/pins_arduino.h b/variants/m5stack_stamp_c3/pins_arduino.h index 66399b0c04b..629fc1b41e6 100644 --- a/variants/m5stack_stamp_c3/pins_arduino.h +++ b/variants/m5stack_stamp_c3/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 20; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 7; -static const uint8_t MOSI = 6; -static const uint8_t MISO = 5; -static const uint8_t SCK = 4; +static const uint8_t SS = 7; +static const uint8_t MOSI = 6; +static const uint8_t MISO = 5; +static const uint8_t SCK = 4; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/m5stack_stamp_pico/pins_arduino.h b/variants/m5stack_stamp_pico/pins_arduino.h index d052243f92a..37a17ffec4d 100644 --- a/variants/m5stack_stamp_pico/pins_arduino.h +++ b/variants/m5stack_stamp_pico/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 19; -static const uint8_t MOSI = 26; -static const uint8_t MISO = 36; -static const uint8_t SCK = 18; +static const uint8_t SS = 19; +static const uint8_t MOSI = 26; +static const uint8_t MISO = 36; +static const uint8_t SCK = 18; static const uint8_t G26 = 26; static const uint8_t G36 = 36; diff --git a/variants/m5stack_stamp_s3/pins_arduino.h b/variants/m5stack_stamp_s3/pins_arduino.h index d2af16ecaf9..595da52bf29 100644 --- a/variants/m5stack_stamp_s3/pins_arduino.h +++ b/variants/m5stack_stamp_s3/pins_arduino.h @@ -17,21 +17,21 @@ static const uint8_t SDA = 13; static const uint8_t SCL = 15; // Modified elsewhere -static const uint8_t SS = -1; -static const uint8_t MOSI = -1; -static const uint8_t MISO = -1; -static const uint8_t SCK = -1; - -static const uint8_t G0 = 0; -static const uint8_t G1 = 1; -static const uint8_t G2 = 2; -static const uint8_t G3 = 3; -static const uint8_t G4 = 4; -static const uint8_t G5 = 5; -static const uint8_t G6 = 6; -static const uint8_t G7 = 7; -static const uint8_t G8 = 8; -static const uint8_t G9 = 9; +static const uint8_t SS = -1; +static const uint8_t MOSI = -1; +static const uint8_t MISO = -1; +static const uint8_t SCK = -1; + +static const uint8_t G0 = 0; +static const uint8_t G1 = 1; +static const uint8_t G2 = 2; +static const uint8_t G3 = 3; +static const uint8_t G4 = 4; +static const uint8_t G5 = 5; +static const uint8_t G6 = 6; +static const uint8_t G7 = 7; +static const uint8_t G8 = 8; +static const uint8_t G9 = 9; static const uint8_t G10 = 10; static const uint8_t G11 = 11; static const uint8_t G12 = 12; diff --git a/variants/m5stack_station/pins_arduino.h b/variants/m5stack_station/pins_arduino.h index 3a5812e3262..d8285fe88b6 100644 --- a/variants/m5stack_station/pins_arduino.h +++ b/variants/m5stack_station/pins_arduino.h @@ -15,15 +15,15 @@ static const uint8_t RXD2 = 16; static const uint8_t SDA = 32; static const uint8_t SCL = 33; -static const uint8_t SS = 5; +static const uint8_t SS = 5; static const uint8_t MOSI = 23; static const uint8_t MISO = -1; -static const uint8_t SCK = 18; +static const uint8_t SCK = 18; -static const uint8_t G1 = 1; -static const uint8_t G3 = 3; -static const uint8_t G4 = 4; -static const uint8_t G5 = 5; +static const uint8_t G1 = 1; +static const uint8_t G3 = 3; +static const uint8_t G4 = 4; +static const uint8_t G5 = 5; static const uint8_t G13 = 13; static const uint8_t G14 = 14; static const uint8_t G16 = 16; diff --git a/variants/m5stack_stickc/pins_arduino.h b/variants/m5stack_stickc/pins_arduino.h index 6a32c71f697..1948afc96d7 100644 --- a/variants/m5stack_stickc/pins_arduino.h +++ b/variants/m5stack_stickc/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 32; static const uint8_t SCL = 33; -static const uint8_t SS = 5; -static const uint8_t MOSI = 15; -static const uint8_t MISO = 36; -static const uint8_t SCK = 13; +static const uint8_t SS = 5; +static const uint8_t MOSI = 15; +static const uint8_t MISO = 36; +static const uint8_t SCK = 13; static const uint8_t G9 = 9; static const uint8_t G10 = 10; diff --git a/variants/m5stack_stickc_plus/pins_arduino.h b/variants/m5stack_stickc_plus/pins_arduino.h index 6a32c71f697..1948afc96d7 100644 --- a/variants/m5stack_stickc_plus/pins_arduino.h +++ b/variants/m5stack_stickc_plus/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 32; static const uint8_t SCL = 33; -static const uint8_t SS = 5; -static const uint8_t MOSI = 15; -static const uint8_t MISO = 36; -static const uint8_t SCK = 13; +static const uint8_t SS = 5; +static const uint8_t MOSI = 15; +static const uint8_t MISO = 36; +static const uint8_t SCK = 13; static const uint8_t G9 = 9; static const uint8_t G10 = 10; diff --git a/variants/m5stack_stickc_plus2/pins_arduino.h b/variants/m5stack_stickc_plus2/pins_arduino.h index 6a32c71f697..1948afc96d7 100644 --- a/variants/m5stack_stickc_plus2/pins_arduino.h +++ b/variants/m5stack_stickc_plus2/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 32; static const uint8_t SCL = 33; -static const uint8_t SS = 5; -static const uint8_t MOSI = 15; -static const uint8_t MISO = 36; -static const uint8_t SCK = 13; +static const uint8_t SS = 5; +static const uint8_t MOSI = 15; +static const uint8_t MISO = 36; +static const uint8_t SCK = 13; static const uint8_t G9 = 9; static const uint8_t G10 = 10; diff --git a/variants/m5stack_timer_cam/pins_arduino.h b/variants/m5stack_timer_cam/pins_arduino.h index 5a2cc5dcdb4..8c1196425b9 100644 --- a/variants/m5stack_timer_cam/pins_arduino.h +++ b/variants/m5stack_timer_cam/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility static const uint8_t TX = 1; static const uint8_t RX = 3; @@ -12,10 +12,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 4; static const uint8_t SCL = 13; -static const uint8_t SS = 5; +static const uint8_t SS = 5; static const uint8_t MOSI = 23; static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SCK = 18; static const uint8_t G23 = 23; static const uint8_t G25 = 25; diff --git a/variants/m5stack_tough/pins_arduino.h b/variants/m5stack_tough/pins_arduino.h index c5ea5d78eee..a4bd6bb29a6 100644 --- a/variants/m5stack_tough/pins_arduino.h +++ b/variants/m5stack_tough/pins_arduino.h @@ -12,10 +12,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 32; static const uint8_t SCL = 33; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 38; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 38; +static const uint8_t SCK = 18; static const uint8_t G23 = 23; static const uint8_t G38 = 38; diff --git a/variants/m5stack_unit_cam/pins_arduino.h b/variants/m5stack_unit_cam/pins_arduino.h index 5697b1303ba..453e1c41516 100644 --- a/variants/m5stack_unit_cam/pins_arduino.h +++ b/variants/m5stack_unit_cam/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 4; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility static const uint8_t TX = 1; static const uint8_t RX = 3; @@ -12,10 +12,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 17; static const uint8_t SCL = 16; -static const uint8_t SS = 5; +static const uint8_t SS = 5; static const uint8_t MOSI = 23; static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SCK = 18; static const uint8_t G23 = 23; static const uint8_t G25 = 25; diff --git a/variants/m5stack_unit_cams3/pins_arduino.h b/variants/m5stack_unit_cams3/pins_arduino.h index d2af16ecaf9..595da52bf29 100644 --- a/variants/m5stack_unit_cams3/pins_arduino.h +++ b/variants/m5stack_unit_cams3/pins_arduino.h @@ -17,21 +17,21 @@ static const uint8_t SDA = 13; static const uint8_t SCL = 15; // Modified elsewhere -static const uint8_t SS = -1; -static const uint8_t MOSI = -1; -static const uint8_t MISO = -1; -static const uint8_t SCK = -1; - -static const uint8_t G0 = 0; -static const uint8_t G1 = 1; -static const uint8_t G2 = 2; -static const uint8_t G3 = 3; -static const uint8_t G4 = 4; -static const uint8_t G5 = 5; -static const uint8_t G6 = 6; -static const uint8_t G7 = 7; -static const uint8_t G8 = 8; -static const uint8_t G9 = 9; +static const uint8_t SS = -1; +static const uint8_t MOSI = -1; +static const uint8_t MISO = -1; +static const uint8_t SCK = -1; + +static const uint8_t G0 = 0; +static const uint8_t G1 = 1; +static const uint8_t G2 = 2; +static const uint8_t G3 = 3; +static const uint8_t G4 = 4; +static const uint8_t G5 = 5; +static const uint8_t G6 = 6; +static const uint8_t G7 = 7; +static const uint8_t G8 = 8; +static const uint8_t G9 = 9; static const uint8_t G10 = 10; static const uint8_t G11 = 11; static const uint8_t G12 = 12; diff --git a/variants/magicbit/pins_arduino.h b/variants/magicbit/pins_arduino.h index 0e91fa211a0..093cfcc3da0 100644 --- a/variants/magicbit/pins_arduino.h +++ b/variants/magicbit/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; @@ -59,8 +59,8 @@ static const uint8_t MOTOR1B = 18; static const uint8_t MOTOR2A = 16; static const uint8_t MOTOR2B = 17; -static const uint8_t LED_BUILTIN=16; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = 16; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #endif /* Pins_Arduino_h */ diff --git a/variants/makergo_c3_supermini/pins_arduino.h b/variants/makergo_c3_supermini/pins_arduino.h index f62df83dbf5..349e2481d9a 100644 --- a/variants/makergo_c3_supermini/pins_arduino.h +++ b/variants/makergo_c3_supermini/pins_arduino.h @@ -7,10 +7,10 @@ #define RX1 1 static const uint8_t LED_BUILTIN = 8; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -static const uint8_t BOOT_BUILTIN = 9; // built-in boot button +static const uint8_t BOOT_BUILTIN = 9; // built-in boot button static const uint8_t TX = 21; static const uint8_t RX = 20; @@ -18,10 +18,10 @@ static const uint8_t RX = 20; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 7; -static const uint8_t MOSI = 6; -static const uint8_t MISO = 5; -static const uint8_t SCK = 4; +static const uint8_t SS = 7; +static const uint8_t MOSI = 6; +static const uint8_t MISO = 5; +static const uint8_t SCK = 4; static const uint8_t A0 = 0; static const uint8_t A1 = 1; @@ -31,4 +31,3 @@ static const uint8_t A4 = 4; static const uint8_t A5 = 5; #endif /* Pins_Arduino_h */ - diff --git a/variants/metro_esp-32/pins_arduino.h b/variants/metro_esp-32/pins_arduino.h index cc13c5f6ffc..675ea79bd6e 100644 --- a/variants/metro_esp-32/pins_arduino.h +++ b/variants/metro_esp-32/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -14,9 +14,9 @@ static const uint8_t SCL = 22; static const uint8_t ADR = 12; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; #endif /* Pins_Arduino_h */ diff --git a/variants/mgbot-iotik32a/pins_arduino.h b/variants/mgbot-iotik32a/pins_arduino.h index 84de808ee08..10d1033b196 100644 --- a/variants/mgbot-iotik32a/pins_arduino.h +++ b/variants/mgbot-iotik32a/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 4; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -20,10 +20,10 @@ static const uint8_t RX2 = 16; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/mgbot-iotik32b/pins_arduino.h b/variants/mgbot-iotik32b/pins_arduino.h index 81ee34f16e5..b85d91520ba 100644 --- a/variants/mgbot-iotik32b/pins_arduino.h +++ b/variants/mgbot-iotik32b/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 18; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // IR receiver @@ -25,10 +25,10 @@ static const uint8_t RX2 = 16; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/mhetesp32devkit/pins_arduino.h b/variants/mhetesp32devkit/pins_arduino.h index 467c58c0034..8e1d00416d1 100644 --- a/variants/mhetesp32devkit/pins_arduino.h +++ b/variants/mhetesp32devkit/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -13,10 +13,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/mhetesp32minikit/pins_arduino.h b/variants/mhetesp32minikit/pins_arduino.h index 467c58c0034..8e1d00416d1 100644 --- a/variants/mhetesp32minikit/pins_arduino.h +++ b/variants/mhetesp32minikit/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -13,10 +13,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/micro_s2/pins_arduino.h b/variants/micro_s2/pins_arduino.h index 18fd2685b80..eb743d4f11e 100644 --- a/variants/micro_s2/pins_arduino.h +++ b/variants/micro_s2/pins_arduino.h @@ -15,12 +15,12 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 34; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SDO = 35; -static const uint8_t SDI = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SDO = 35; +static const uint8_t SDI = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -61,13 +61,13 @@ static const uint8_t T14 = 14; static const uint8_t DAC1 = 17; static const uint8_t DAC2 = 18; -static const uint8_t LED_BUILTIN = 21; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = 21; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t PIXEL_BUILTIN = 33; // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() -#define RGB_BUILTIN (PIXEL_BUILTIN + SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (PIXEL_BUILTIN + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 static const uint8_t BUTTON_BUILTIN = 0; diff --git a/variants/mpython/pins_arduino.h b/variants/mpython/pins_arduino.h index 5f17b4ad1e3..c87fb822b77 100644 --- a/variants/mpython/pins_arduino.h +++ b/variants/mpython/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 23; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/namino_arancio/pins_arduino.h b/variants/namino_arancio/pins_arduino.h index 2236ca712a3..78000a477b0 100644 --- a/variants/namino_arancio/pins_arduino.h +++ b/variants/namino_arancio/pins_arduino.h @@ -13,185 +13,185 @@ #define NAMINO_ARANCIO_BOARD /* Begin Pins on ESP32-S3-WROOM-1U-N4R8 */ -static const uint8_t GPIO4 = 4; -static const uint8_t GPIO5 = 5; -static const uint8_t GPIO6 = 6; -static const uint8_t GPIO7 = 7; -static const uint8_t GPIO15 = 15; -static const uint8_t GPIO16 = 16; -static const uint8_t GPIO17 = 17; -static const uint8_t GPIO18 = 18; -static const uint8_t GPIO8 = 8; -static const uint8_t GPIO19 = 19; -static const uint8_t GPIO20 = 20; -static const uint8_t GPIO3 = 3; -static const uint8_t GPIO46 = 46; -static const uint8_t GPIO9 = 9; -static const uint8_t GPIO10 = 10; -static const uint8_t GPIO11 = 11; -static const uint8_t GPIO12 = 12; -static const uint8_t GPIO13 = 13; -static const uint8_t GPIO14 = 14; -static const uint8_t GPIO21 = 21; -static const uint8_t GPIO47 = 47; -static const uint8_t GPIO48 = 48; -static const uint8_t GPIO45 = 45; -static const uint8_t GPIO0 = 0; -static const uint8_t GPIO35 = 35; -static const uint8_t GPIO36 = 36; -static const uint8_t GPIO37 = 37; -static const uint8_t GPIO38 = 38; -static const uint8_t GPIO39 = 39; -static const uint8_t GPIO40 = 40; -static const uint8_t GPIO41 = 41; -static const uint8_t GPIO42 = 42; -static const uint8_t GPIO44 = 44; -static const uint8_t GPIO43 = 43; -static const uint8_t GPIO2 = 2; -static const uint8_t GPIO1 = 1; - -static const uint8_t RESET_ADD_ON = GPIO46; -static const uint8_t SS = GPIO10; -static const uint8_t MOSI = GPIO11; -static const uint8_t MISO = GPIO13; -static const uint8_t SCK = GPIO12; +static const uint8_t GPIO4 = 4; +static const uint8_t GPIO5 = 5; +static const uint8_t GPIO6 = 6; +static const uint8_t GPIO7 = 7; +static const uint8_t GPIO15 = 15; +static const uint8_t GPIO16 = 16; +static const uint8_t GPIO17 = 17; +static const uint8_t GPIO18 = 18; +static const uint8_t GPIO8 = 8; +static const uint8_t GPIO19 = 19; +static const uint8_t GPIO20 = 20; +static const uint8_t GPIO3 = 3; +static const uint8_t GPIO46 = 46; +static const uint8_t GPIO9 = 9; +static const uint8_t GPIO10 = 10; +static const uint8_t GPIO11 = 11; +static const uint8_t GPIO12 = 12; +static const uint8_t GPIO13 = 13; +static const uint8_t GPIO14 = 14; +static const uint8_t GPIO21 = 21; +static const uint8_t GPIO47 = 47; +static const uint8_t GPIO48 = 48; +static const uint8_t GPIO45 = 45; +static const uint8_t GPIO0 = 0; +static const uint8_t GPIO35 = 35; +static const uint8_t GPIO36 = 36; +static const uint8_t GPIO37 = 37; +static const uint8_t GPIO38 = 38; +static const uint8_t GPIO39 = 39; +static const uint8_t GPIO40 = 40; +static const uint8_t GPIO41 = 41; +static const uint8_t GPIO42 = 42; +static const uint8_t GPIO44 = 44; +static const uint8_t GPIO43 = 43; +static const uint8_t GPIO2 = 2; +static const uint8_t GPIO1 = 1; + +static const uint8_t RESET_ADD_ON = GPIO46; +static const uint8_t SS = GPIO10; +static const uint8_t MOSI = GPIO11; +static const uint8_t MISO = GPIO13; +static const uint8_t SCK = GPIO12; // SPI SD CARD -static const uint8_t CS_SDCARD = GPIO2; +static const uint8_t CS_SDCARD = GPIO2; // prog pins -static const uint8_t BOOT_MODE = GPIO47; -static const uint8_t ISP_TX = GPIO17; -static const uint8_t ISP_RX = GPIO18; -static const uint8_t NM_RESET = GPIO48; +static const uint8_t BOOT_MODE = GPIO47; +static const uint8_t ISP_TX = GPIO17; +static const uint8_t ISP_RX = GPIO18; +static const uint8_t NM_RESET = GPIO48; /* End Pins on ESP32-S3-WROOM-1U-N4R8 */ /* Begin Analog Pins on ESP32-S3-WROOM-1U-N4R8 */ -static const uint8_t ADC1_CH3 = GPIO4; -static const uint8_t ADC1_CH4 = GPIO5; -static const uint8_t ADC1_CH5 = GPIO6; -static const uint8_t ADC1_CH6 = GPIO7; -static const uint8_t ADC2_CH4 = GPIO15; -static const uint8_t ADC2_CH5 = GPIO16; -static const uint8_t ADC2_CH6 = GPIO17; -static const uint8_t ADC2_CH7 = GPIO18; -static const uint8_t ADC1_CH7 = GPIO8; -static const uint8_t ADC2_CH8 = GPIO19; -static const uint8_t ADC2_CH9 = GPIO20; -static const uint8_t ADC1_CH2 = GPIO3; -static const uint8_t ADC1_CH8 = GPIO9; -static const uint8_t ADC1_CH9 = GPIO10; -static const uint8_t ADC2_CH0 = GPIO11; -static const uint8_t ADC2_CH1 = GPIO12; -static const uint8_t ADC2_CH2 = GPIO13; -static const uint8_t ADC2_CH3 = GPIO14; -static const uint8_t ADC1_CH1 = GPIO2; -static const uint8_t ADC1_CH0 = GPIO1; +static const uint8_t ADC1_CH3 = GPIO4; +static const uint8_t ADC1_CH4 = GPIO5; +static const uint8_t ADC1_CH5 = GPIO6; +static const uint8_t ADC1_CH6 = GPIO7; +static const uint8_t ADC2_CH4 = GPIO15; +static const uint8_t ADC2_CH5 = GPIO16; +static const uint8_t ADC2_CH6 = GPIO17; +static const uint8_t ADC2_CH7 = GPIO18; +static const uint8_t ADC1_CH7 = GPIO8; +static const uint8_t ADC2_CH8 = GPIO19; +static const uint8_t ADC2_CH9 = GPIO20; +static const uint8_t ADC1_CH2 = GPIO3; +static const uint8_t ADC1_CH8 = GPIO9; +static const uint8_t ADC1_CH9 = GPIO10; +static const uint8_t ADC2_CH0 = GPIO11; +static const uint8_t ADC2_CH1 = GPIO12; +static const uint8_t ADC2_CH2 = GPIO13; +static const uint8_t ADC2_CH3 = GPIO14; +static const uint8_t ADC1_CH1 = GPIO2; +static const uint8_t ADC1_CH0 = GPIO1; /* End Analog Pins on ESP32-S3-WROOM-1U-N4R8 */ /* Begin Touch Pins on ESP32-S3-WROOM-1U-N4R8 */ -static const uint8_t TOUCH4 = GPIO4; -static const uint8_t TOUCH5 = GPIO5; -static const uint8_t TOUCH6 = GPIO6; -static const uint8_t TOUCH7 = GPIO7; -static const uint8_t TOUCH8 = GPIO8; -static const uint8_t TOUCH3 = GPIO3; -static const uint8_t TOUCH9 = GPIO9; -static const uint8_t TOUCH10 = GPIO10; -static const uint8_t TOUCH11 = GPIO11; -static const uint8_t TOUCH12 = GPIO12; -static const uint8_t TOUCH13 = GPIO13; -static const uint8_t TOUCH14 = GPIO14; -static const uint8_t TOUCH2 = GPIO2; -static const uint8_t TOUCH1 = GPIO1; +static const uint8_t TOUCH4 = GPIO4; +static const uint8_t TOUCH5 = GPIO5; +static const uint8_t TOUCH6 = GPIO6; +static const uint8_t TOUCH7 = GPIO7; +static const uint8_t TOUCH8 = GPIO8; +static const uint8_t TOUCH3 = GPIO3; +static const uint8_t TOUCH9 = GPIO9; +static const uint8_t TOUCH10 = GPIO10; +static const uint8_t TOUCH11 = GPIO11; +static const uint8_t TOUCH12 = GPIO12; +static const uint8_t TOUCH13 = GPIO13; +static const uint8_t TOUCH14 = GPIO14; +static const uint8_t TOUCH2 = GPIO2; +static const uint8_t TOUCH1 = GPIO1; /* End Touch Pins on ESP32-S3-WROOM-1U-N4R8 */ -static const uint8_t TX = GPIO17; -static const uint8_t RX = GPIO18; - -static const uint8_t SDA = GPIO1; -static const uint8_t SCL = GPIO0; -static const uint8_t NAMINO_ARANCIO_I2C_SDA = SDA; -static const uint8_t NAMINO_ARANCIO_I2C_SCL = SCL; -static const uint8_t NM_I2C_SDA = SDA; -static const uint8_t NM_I2C_SCL = SCL; - -static const uint8_t A0 = ADC1_CH0; -static const uint8_t A1 = ADC1_CH1; -static const uint8_t A2 = ADC1_CH2; -static const uint8_t A3 = ADC1_CH3; -static const uint8_t A4 = ADC1_CH4; -static const uint8_t A5 = ADC1_CH5; -static const uint8_t A6 = ADC1_CH6; -static const uint8_t A7 = ADC1_CH7; -static const uint8_t A8 = ADC2_CH0; -static const uint8_t A9 = ADC2_CH1; -static const uint8_t A10 = ADC2_CH2; -static const uint8_t A11 = ADC2_CH3; -static const uint8_t A12 = ADC2_CH4; -static const uint8_t A13 = ADC2_CH5; -static const uint8_t A14 = ADC2_CH6; -static const uint8_t A15 = ADC2_CH7; - -static const uint8_t DAC1 = 0; -static const uint8_t DAC2 = 0; +static const uint8_t TX = GPIO17; +static const uint8_t RX = GPIO18; + +static const uint8_t SDA = GPIO1; +static const uint8_t SCL = GPIO0; +static const uint8_t NAMINO_ARANCIO_I2C_SDA = SDA; +static const uint8_t NAMINO_ARANCIO_I2C_SCL = SCL; +static const uint8_t NM_I2C_SDA = SDA; +static const uint8_t NM_I2C_SCL = SCL; + +static const uint8_t A0 = ADC1_CH0; +static const uint8_t A1 = ADC1_CH1; +static const uint8_t A2 = ADC1_CH2; +static const uint8_t A3 = ADC1_CH3; +static const uint8_t A4 = ADC1_CH4; +static const uint8_t A5 = ADC1_CH5; +static const uint8_t A6 = ADC1_CH6; +static const uint8_t A7 = ADC1_CH7; +static const uint8_t A8 = ADC2_CH0; +static const uint8_t A9 = ADC2_CH1; +static const uint8_t A10 = ADC2_CH2; +static const uint8_t A11 = ADC2_CH3; +static const uint8_t A12 = ADC2_CH4; +static const uint8_t A13 = ADC2_CH5; +static const uint8_t A14 = ADC2_CH6; +static const uint8_t A15 = ADC2_CH7; + +static const uint8_t DAC1 = 0; +static const uint8_t DAC2 = 0; /* Begin Arduino naming */ -static const uint8_t RESET_ARDUINO = GPIO46; -static const uint8_t PC0 = GPIO3; -static const uint8_t PC1 = GPIO4; -static const uint8_t PC2 = GPIO5; -static const uint8_t PC3 = GPIO6; -static const uint8_t PC4 = GPIO7; -static const uint8_t PC5 = GPIO8; -static const uint8_t PB5 = GPIO35; -static const uint8_t PB4 = GPIO36; -static const uint8_t PB3 = GPIO37; -static const uint8_t PB2 = GPIO38; -static const uint8_t PB1 = GPIO39; -static const uint8_t PB0 = GPIO40; -static const uint8_t PD7 = GPIO41; -static const uint8_t PD6 = GPIO42; -static const uint8_t PD5 = GPIO21; -static const uint8_t PD4 = GPIO16; -static const uint8_t PD3 = GPIO14; -static const uint8_t PD2 = GPIO9; -static const uint8_t PD1 = GPIO17; -static const uint8_t PD0 = GPIO18; +static const uint8_t RESET_ARDUINO = GPIO46; +static const uint8_t PC0 = GPIO3; +static const uint8_t PC1 = GPIO4; +static const uint8_t PC2 = GPIO5; +static const uint8_t PC3 = GPIO6; +static const uint8_t PC4 = GPIO7; +static const uint8_t PC5 = GPIO8; +static const uint8_t PB5 = GPIO35; +static const uint8_t PB4 = GPIO36; +static const uint8_t PB3 = GPIO37; +static const uint8_t PB2 = GPIO38; +static const uint8_t PB1 = GPIO39; +static const uint8_t PB0 = GPIO40; +static const uint8_t PD7 = GPIO41; +static const uint8_t PD6 = GPIO42; +static const uint8_t PD5 = GPIO21; +static const uint8_t PD4 = GPIO16; +static const uint8_t PD3 = GPIO14; +static const uint8_t PD2 = GPIO9; +static const uint8_t PD1 = GPIO17; +static const uint8_t PD0 = GPIO18; /* End Arduino naming */ /* Begin alternate naming */ -static const uint8_t J1_io0 = SCL; - -static const uint8_t J2_35 = PB5; -static const uint8_t J2_36 = PB4; -static const uint8_t J2_37 = PB3; -static const uint8_t J2_38 = PB2; -static const uint8_t J2_39 = PB1; -static const uint8_t J2_40 = PB0; - -static const uint8_t J3_io8 = PD7; -static const uint8_t J3_7 = PD6; -static const uint8_t J3_21 = PD5; -static const uint8_t J3_16 = PD4; -static const uint8_t J3_14 = PD3; -static const uint8_t J3_9 = PD2; -static const uint8_t J3_17 = TX; -static const uint8_t J3_18 = RX; - -static const uint8_t J4_cs_io2 = CS_SDCARD; -static const uint8_t J4_sclk = SCK; -static const uint8_t J4_mosi = MOSI; -static const uint8_t J4_miso = MISO; - -static const uint8_t J9_io3 = PC0; -static const uint8_t J9_4 = PC1; -static const uint8_t J9_5 = PC2; -static const uint8_t J9_6 = PC3; -static const uint8_t J9_7 = PC4; -static const uint8_t J9_8 = PC5; - -static const uint8_t J10_enc_A = 0; -static const uint8_t J10_enc_B = 0; -static const uint8_t J10_sw = 0; +static const uint8_t J1_io0 = SCL; + +static const uint8_t J2_35 = PB5; +static const uint8_t J2_36 = PB4; +static const uint8_t J2_37 = PB3; +static const uint8_t J2_38 = PB2; +static const uint8_t J2_39 = PB1; +static const uint8_t J2_40 = PB0; + +static const uint8_t J3_io8 = PD7; +static const uint8_t J3_7 = PD6; +static const uint8_t J3_21 = PD5; +static const uint8_t J3_16 = PD4; +static const uint8_t J3_14 = PD3; +static const uint8_t J3_9 = PD2; +static const uint8_t J3_17 = TX; +static const uint8_t J3_18 = RX; + +static const uint8_t J4_cs_io2 = CS_SDCARD; +static const uint8_t J4_sclk = SCK; +static const uint8_t J4_mosi = MOSI; +static const uint8_t J4_miso = MISO; + +static const uint8_t J9_io3 = PC0; +static const uint8_t J9_4 = PC1; +static const uint8_t J9_5 = PC2; +static const uint8_t J9_6 = PC3; +static const uint8_t J9_7 = PC4; +static const uint8_t J9_8 = PC5; + +static const uint8_t J10_enc_A = 0; +static const uint8_t J10_enc_B = 0; +static const uint8_t J10_sw = 0; /* End alternate naming */ #endif /* Pins_Arduino_h */ diff --git a/variants/namino_bianco/pins_arduino.h b/variants/namino_bianco/pins_arduino.h index 48fbf6da301..2b1840b4eef 100644 --- a/variants/namino_bianco/pins_arduino.h +++ b/variants/namino_bianco/pins_arduino.h @@ -14,184 +14,184 @@ #define NAMINO_BIANCO_BOARD /* Begin Pins on ESP32-S3-WROOM-1U-N4R8 */ -static const uint8_t GPIO4 = 4; -static const uint8_t GPIO5 = 5; -static const uint8_t GPIO6 = 6; -static const uint8_t GPIO7 = 7; -static const uint8_t GPIO15 = 15; -static const uint8_t GPIO16 = 16; -static const uint8_t GPIO17 = 17; -static const uint8_t GPIO18 = 18; -static const uint8_t GPIO8 = 8; -static const uint8_t GPIO19 = 19; -static const uint8_t GPIO20 = 20; -static const uint8_t GPIO3 = 3; -static const uint8_t GPIO46 = 46; -static const uint8_t GPIO9 = 9; -static const uint8_t GPIO10 = 10; -static const uint8_t GPIO11 = 11; -static const uint8_t GPIO12 = 12; -static const uint8_t GPIO13 = 13; -static const uint8_t GPIO14 = 14; -static const uint8_t GPIO21 = 21; -static const uint8_t GPIO47 = 47; -static const uint8_t GPIO48 = 48; -static const uint8_t GPIO45 = 45; -static const uint8_t GPIO0 = 0; -static const uint8_t GPIO35 = 35; -static const uint8_t GPIO36 = 36; -static const uint8_t GPIO37 = 37; -static const uint8_t GPIO38 = 38; -static const uint8_t GPIO39 = 39; -static const uint8_t GPIO40 = 40; -static const uint8_t GPIO41 = 41; -static const uint8_t GPIO42 = 42; -static const uint8_t GPIO44 = 44; -static const uint8_t GPIO43 = 43; -static const uint8_t GPIO2 = 2; -static const uint8_t GPIO1 = 1; - -static const uint8_t SS = GPIO48; -static const uint8_t MOSI = GPIO11; -static const uint8_t MISO = GPIO13; -static const uint8_t SCK = GPIO12; +static const uint8_t GPIO4 = 4; +static const uint8_t GPIO5 = 5; +static const uint8_t GPIO6 = 6; +static const uint8_t GPIO7 = 7; +static const uint8_t GPIO15 = 15; +static const uint8_t GPIO16 = 16; +static const uint8_t GPIO17 = 17; +static const uint8_t GPIO18 = 18; +static const uint8_t GPIO8 = 8; +static const uint8_t GPIO19 = 19; +static const uint8_t GPIO20 = 20; +static const uint8_t GPIO3 = 3; +static const uint8_t GPIO46 = 46; +static const uint8_t GPIO9 = 9; +static const uint8_t GPIO10 = 10; +static const uint8_t GPIO11 = 11; +static const uint8_t GPIO12 = 12; +static const uint8_t GPIO13 = 13; +static const uint8_t GPIO14 = 14; +static const uint8_t GPIO21 = 21; +static const uint8_t GPIO47 = 47; +static const uint8_t GPIO48 = 48; +static const uint8_t GPIO45 = 45; +static const uint8_t GPIO0 = 0; +static const uint8_t GPIO35 = 35; +static const uint8_t GPIO36 = 36; +static const uint8_t GPIO37 = 37; +static const uint8_t GPIO38 = 38; +static const uint8_t GPIO39 = 39; +static const uint8_t GPIO40 = 40; +static const uint8_t GPIO41 = 41; +static const uint8_t GPIO42 = 42; +static const uint8_t GPIO44 = 44; +static const uint8_t GPIO43 = 43; +static const uint8_t GPIO2 = 2; +static const uint8_t GPIO1 = 1; + +static const uint8_t SS = GPIO48; +static const uint8_t MOSI = GPIO11; +static const uint8_t MISO = GPIO13; +static const uint8_t SCK = GPIO12; /* End Pins on ESP32-S3-WROOM-1U-N4R8 */ /* Begin Analog Pins on ESP32-S3-WROOM-1U-N4R8 */ -static const uint8_t ADC1_CH3 = GPIO4; -static const uint8_t ADC1_CH4 = GPIO5; -static const uint8_t ADC1_CH5 = GPIO6; -static const uint8_t ADC1_CH6 = GPIO7; -static const uint8_t ADC2_CH4 = GPIO15; -static const uint8_t ADC2_CH5 = GPIO16; -static const uint8_t ADC2_CH6 = GPIO17; -static const uint8_t ADC2_CH7 = GPIO18; -static const uint8_t ADC1_CH7 = GPIO8; -static const uint8_t ADC2_CH8 = GPIO19; -static const uint8_t ADC2_CH9 = GPIO20; -static const uint8_t ADC1_CH2 = GPIO3; -static const uint8_t ADC1_CH8 = GPIO9; -static const uint8_t ADC1_CH9 = GPIO10; -static const uint8_t ADC2_CH0 = GPIO11; -static const uint8_t ADC2_CH1 = GPIO12; -static const uint8_t ADC2_CH2 = GPIO13; -static const uint8_t ADC2_CH3 = GPIO14; -static const uint8_t ADC1_CH1 = GPIO2; -static const uint8_t ADC1_CH0 = GPIO1; +static const uint8_t ADC1_CH3 = GPIO4; +static const uint8_t ADC1_CH4 = GPIO5; +static const uint8_t ADC1_CH5 = GPIO6; +static const uint8_t ADC1_CH6 = GPIO7; +static const uint8_t ADC2_CH4 = GPIO15; +static const uint8_t ADC2_CH5 = GPIO16; +static const uint8_t ADC2_CH6 = GPIO17; +static const uint8_t ADC2_CH7 = GPIO18; +static const uint8_t ADC1_CH7 = GPIO8; +static const uint8_t ADC2_CH8 = GPIO19; +static const uint8_t ADC2_CH9 = GPIO20; +static const uint8_t ADC1_CH2 = GPIO3; +static const uint8_t ADC1_CH8 = GPIO9; +static const uint8_t ADC1_CH9 = GPIO10; +static const uint8_t ADC2_CH0 = GPIO11; +static const uint8_t ADC2_CH1 = GPIO12; +static const uint8_t ADC2_CH2 = GPIO13; +static const uint8_t ADC2_CH3 = GPIO14; +static const uint8_t ADC1_CH1 = GPIO2; +static const uint8_t ADC1_CH0 = GPIO1; /* End Analog Pins on ESP32-S3-WROOM-1U-N4R8 */ /* Begin Touch Pins on ESP32-S3-WROOM-1U-N4R8 */ -static const uint8_t TOUCH4 = GPIO4; -static const uint8_t TOUCH5 = GPIO5; -static const uint8_t TOUCH6 = GPIO6; -static const uint8_t TOUCH7 = GPIO7; -static const uint8_t TOUCH8 = GPIO8; -static const uint8_t TOUCH3 = GPIO3; -static const uint8_t TOUCH9 = GPIO9; -static const uint8_t TOUCH10 = GPIO10; -static const uint8_t TOUCH11 = GPIO11; -static const uint8_t TOUCH12 = GPIO12; -static const uint8_t TOUCH13 = GPIO13; -static const uint8_t TOUCH14 = GPIO14; -static const uint8_t TOUCH2 = GPIO2; -static const uint8_t TOUCH1 = GPIO1; +static const uint8_t TOUCH4 = GPIO4; +static const uint8_t TOUCH5 = GPIO5; +static const uint8_t TOUCH6 = GPIO6; +static const uint8_t TOUCH7 = GPIO7; +static const uint8_t TOUCH8 = GPIO8; +static const uint8_t TOUCH3 = GPIO3; +static const uint8_t TOUCH9 = GPIO9; +static const uint8_t TOUCH10 = GPIO10; +static const uint8_t TOUCH11 = GPIO11; +static const uint8_t TOUCH12 = GPIO12; +static const uint8_t TOUCH13 = GPIO13; +static const uint8_t TOUCH14 = GPIO14; +static const uint8_t TOUCH2 = GPIO2; +static const uint8_t TOUCH1 = GPIO1; /* End Touch Pins on ESP32-S3-WROOM-1U-N4R8 */ -static const uint8_t TX = GPIO17; -static const uint8_t RX = GPIO18; - -static const uint8_t SDA = GPIO1; -static const uint8_t SCL = GPIO2; -static const uint8_t NM_I2C_SDA = SDA; -static const uint8_t NM_I2C_SCL = SCL; - -static const uint8_t A0 = ADC1_CH2; -static const uint8_t A1 = ADC1_CH3; -static const uint8_t A2 = ADC1_CH4; -static const uint8_t A3 = ADC1_CH5; -static const uint8_t A4 = ADC1_CH6; -static const uint8_t A5 = ADC2_CH4; -static const uint8_t A6 = 0; -static const uint8_t A7 = 0; -static const uint8_t A8 = 0; -static const uint8_t A9 = 0; -static const uint8_t A10 = 0; -static const uint8_t A11 = 0; -static const uint8_t A12 = 0; -static const uint8_t A13 = 0; -static const uint8_t A14 = 0; -static const uint8_t A15 = 0; - -static const uint8_t DAC1 = 0; -static const uint8_t DAC2 = 0; +static const uint8_t TX = GPIO17; +static const uint8_t RX = GPIO18; + +static const uint8_t SDA = GPIO1; +static const uint8_t SCL = GPIO2; +static const uint8_t NM_I2C_SDA = SDA; +static const uint8_t NM_I2C_SCL = SCL; + +static const uint8_t A0 = ADC1_CH2; +static const uint8_t A1 = ADC1_CH3; +static const uint8_t A2 = ADC1_CH4; +static const uint8_t A3 = ADC1_CH5; +static const uint8_t A4 = ADC1_CH6; +static const uint8_t A5 = ADC2_CH4; +static const uint8_t A6 = 0; +static const uint8_t A7 = 0; +static const uint8_t A8 = 0; +static const uint8_t A9 = 0; +static const uint8_t A10 = 0; +static const uint8_t A11 = 0; +static const uint8_t A12 = 0; +static const uint8_t A13 = 0; +static const uint8_t A14 = 0; +static const uint8_t A15 = 0; + +static const uint8_t DAC1 = 0; +static const uint8_t DAC2 = 0; /* Begin Arduino naming */ -static const uint8_t RESET_ARDUINO = 0; -static const uint8_t PC0 = GPIO3; -static const uint8_t PC1 = GPIO4; -static const uint8_t PC2 = GPIO5; -static const uint8_t PC3 = GPIO6; -static const uint8_t PC4 = GPIO7; -static const uint8_t PC5 = GPIO15; -static const uint8_t PB5 = GPIO35; -static const uint8_t PB4 = GPIO36; -static const uint8_t PB3 = GPIO37; -static const uint8_t PB2 = GPIO38; -static const uint8_t PB1 = GPIO39; -static const uint8_t PB0 = GPIO40; -static const uint8_t PD7 = GPIO41; -static const uint8_t PD6 = GPIO42; -static const uint8_t PD5 = GPIO21; -static const uint8_t PD4 = GPIO16; -static const uint8_t PD3 = GPIO14; -static const uint8_t PD2 = GPIO47; -static const uint8_t PD1 = GPIO17; -static const uint8_t PD0 = GPIO18; +static const uint8_t RESET_ARDUINO = 0; +static const uint8_t PC0 = GPIO3; +static const uint8_t PC1 = GPIO4; +static const uint8_t PC2 = GPIO5; +static const uint8_t PC3 = GPIO6; +static const uint8_t PC4 = GPIO7; +static const uint8_t PC5 = GPIO15; +static const uint8_t PB5 = GPIO35; +static const uint8_t PB4 = GPIO36; +static const uint8_t PB3 = GPIO37; +static const uint8_t PB2 = GPIO38; +static const uint8_t PB1 = GPIO39; +static const uint8_t PB0 = GPIO40; +static const uint8_t PD7 = GPIO41; +static const uint8_t PD6 = GPIO42; +static const uint8_t PD5 = GPIO21; +static const uint8_t PD4 = GPIO16; +static const uint8_t PD3 = GPIO14; +static const uint8_t PD2 = GPIO47; +static const uint8_t PD1 = GPIO17; +static const uint8_t PD0 = GPIO18; /* End Arduino naming */ /* Begin alternate naming */ -static const uint8_t PB_SCL = SCL; -static const uint8_t PB_SDA = SDA; -static const uint8_t PB_35 = PB5; -static const uint8_t PB_36 = PB4; -static const uint8_t PB_37 = PB3; -static const uint8_t PB_38 = PB2; -static const uint8_t PB_39 = PB1; -static const uint8_t PB_40 = PB0; - -static const uint8_t PD_io41 = PD7; -static const uint8_t PD_42 = PD6; -static const uint8_t PD_21 = PD5; -static const uint8_t PD_16 = PD4; -static const uint8_t PD_14 = PD3; -static const uint8_t PD_47 = PD2; -static const uint8_t PD_17 = TX; -static const uint8_t PD_18 = RX; - - -static const uint8_t PC_io3 = PC0; -static const uint8_t PC_4 = PC1; -static const uint8_t PC_5 = PC2; -static const uint8_t PC_6 = PC3; -static const uint8_t PC_7 = PC4; -static const uint8_t PC_15 = PC5; - -static const uint8_t M1_3_AN = GPIO3; -static const uint8_t M1_RST = 0; -static const uint8_t M1_48_CS = SS; -static const uint8_t M1_12_SCK = SCK; -static const uint8_t M1_13_MISO = MISO; -static const uint8_t M1_11_MOSI = MOSI; -static const uint8_t M2_47_PWM = GPIO47; -static const uint8_t M2_14_INT = GPIO14; -static const uint8_t M2_18_RX = GPIO18; -static const uint8_t M2_17_TX = GPIO17; -static const uint8_t M2_2_SCL = SCL; -static const uint8_t M2_1_SDA = SDA; - -static const uint8_t J3_SCL = SCL; -static const uint8_t J3_SDA = SDA; +static const uint8_t PB_SCL = SCL; +static const uint8_t PB_SDA = SDA; +static const uint8_t PB_35 = PB5; +static const uint8_t PB_36 = PB4; +static const uint8_t PB_37 = PB3; +static const uint8_t PB_38 = PB2; +static const uint8_t PB_39 = PB1; +static const uint8_t PB_40 = PB0; + +static const uint8_t PD_io41 = PD7; +static const uint8_t PD_42 = PD6; +static const uint8_t PD_21 = PD5; +static const uint8_t PD_16 = PD4; +static const uint8_t PD_14 = PD3; +static const uint8_t PD_47 = PD2; +static const uint8_t PD_17 = TX; +static const uint8_t PD_18 = RX; + + +static const uint8_t PC_io3 = PC0; +static const uint8_t PC_4 = PC1; +static const uint8_t PC_5 = PC2; +static const uint8_t PC_6 = PC3; +static const uint8_t PC_7 = PC4; +static const uint8_t PC_15 = PC5; + +static const uint8_t M1_3_AN = GPIO3; +static const uint8_t M1_RST = 0; +static const uint8_t M1_48_CS = SS; +static const uint8_t M1_12_SCK = SCK; +static const uint8_t M1_13_MISO = MISO; +static const uint8_t M1_11_MOSI = MOSI; +static const uint8_t M2_47_PWM = GPIO47; +static const uint8_t M2_14_INT = GPIO14; +static const uint8_t M2_18_RX = GPIO18; +static const uint8_t M2_17_TX = GPIO17; +static const uint8_t M2_2_SCL = SCL; +static const uint8_t M2_1_SDA = SDA; + +static const uint8_t J3_SCL = SCL; +static const uint8_t J3_SDA = SDA; /* End alternate naming */ diff --git a/variants/namino_rosso/pins_arduino.h b/variants/namino_rosso/pins_arduino.h index aa5075a4bee..90508e90257 100644 --- a/variants/namino_rosso/pins_arduino.h +++ b/variants/namino_rosso/pins_arduino.h @@ -13,185 +13,185 @@ #define NAMINO_ROSSO_BOARD /* Begin Pins on ESP32-S3-WROOM-1U-N4R8 */ -static const uint8_t GPIO4 = 4; -static const uint8_t GPIO5 = 5; -static const uint8_t GPIO6 = 6; -static const uint8_t GPIO7 = 7; -static const uint8_t GPIO15 = 15; -static const uint8_t GPIO16 = 16; -static const uint8_t GPIO17 = 17; -static const uint8_t GPIO18 = 18; -static const uint8_t GPIO8 = 8; -static const uint8_t GPIO19 = 19; -static const uint8_t GPIO20 = 20; -static const uint8_t GPIO3 = 3; -static const uint8_t GPIO46 = 46; -static const uint8_t GPIO9 = 9; -static const uint8_t GPIO10 = 10; -static const uint8_t GPIO11 = 11; -static const uint8_t GPIO12 = 12; -static const uint8_t GPIO13 = 13; -static const uint8_t GPIO14 = 14; -static const uint8_t GPIO21 = 21; -static const uint8_t GPIO47 = 47; -static const uint8_t GPIO48 = 48; -static const uint8_t GPIO45 = 45; -static const uint8_t GPIO0 = 0; -static const uint8_t GPIO35 = 35; -static const uint8_t GPIO36 = 36; -static const uint8_t GPIO37 = 37; -static const uint8_t GPIO38 = 38; -static const uint8_t GPIO39 = 39; -static const uint8_t GPIO40 = 40; -static const uint8_t GPIO41 = 41; -static const uint8_t GPIO42 = 42; -static const uint8_t GPIO44 = 44; -static const uint8_t GPIO43 = 43; -static const uint8_t GPIO2 = 2; -static const uint8_t GPIO1 = 1; - -static const uint8_t RESET_ADD_ON = GPIO46; -static const uint8_t SS = GPIO10; -static const uint8_t MOSI = GPIO11; -static const uint8_t MISO = GPIO13; -static const uint8_t SCK = GPIO12; +static const uint8_t GPIO4 = 4; +static const uint8_t GPIO5 = 5; +static const uint8_t GPIO6 = 6; +static const uint8_t GPIO7 = 7; +static const uint8_t GPIO15 = 15; +static const uint8_t GPIO16 = 16; +static const uint8_t GPIO17 = 17; +static const uint8_t GPIO18 = 18; +static const uint8_t GPIO8 = 8; +static const uint8_t GPIO19 = 19; +static const uint8_t GPIO20 = 20; +static const uint8_t GPIO3 = 3; +static const uint8_t GPIO46 = 46; +static const uint8_t GPIO9 = 9; +static const uint8_t GPIO10 = 10; +static const uint8_t GPIO11 = 11; +static const uint8_t GPIO12 = 12; +static const uint8_t GPIO13 = 13; +static const uint8_t GPIO14 = 14; +static const uint8_t GPIO21 = 21; +static const uint8_t GPIO47 = 47; +static const uint8_t GPIO48 = 48; +static const uint8_t GPIO45 = 45; +static const uint8_t GPIO0 = 0; +static const uint8_t GPIO35 = 35; +static const uint8_t GPIO36 = 36; +static const uint8_t GPIO37 = 37; +static const uint8_t GPIO38 = 38; +static const uint8_t GPIO39 = 39; +static const uint8_t GPIO40 = 40; +static const uint8_t GPIO41 = 41; +static const uint8_t GPIO42 = 42; +static const uint8_t GPIO44 = 44; +static const uint8_t GPIO43 = 43; +static const uint8_t GPIO2 = 2; +static const uint8_t GPIO1 = 1; + +static const uint8_t RESET_ADD_ON = GPIO46; +static const uint8_t SS = GPIO10; +static const uint8_t MOSI = GPIO11; +static const uint8_t MISO = GPIO13; +static const uint8_t SCK = GPIO12; // SPI SD CARD -static const uint8_t CS_SDCARD = GPIO2; +static const uint8_t CS_SDCARD = GPIO2; // prog pins -static const uint8_t BOOT_MODE = GPIO47; -static const uint8_t ISP_TX = GPIO17; -static const uint8_t ISP_RX = GPIO18; -static const uint8_t NM_RESET = GPIO48; +static const uint8_t BOOT_MODE = GPIO47; +static const uint8_t ISP_TX = GPIO17; +static const uint8_t ISP_RX = GPIO18; +static const uint8_t NM_RESET = GPIO48; /* End Pins on ESP32-S3-WROOM-1U-N4R8 */ /* Begin Analog Pins on ESP32-S3-WROOM-1U-N4R8 */ -static const uint8_t ADC1_CH3 = GPIO4; -static const uint8_t ADC1_CH4 = GPIO5; -static const uint8_t ADC1_CH5 = GPIO6; -static const uint8_t ADC1_CH6 = GPIO7; -static const uint8_t ADC2_CH4 = GPIO15; -static const uint8_t ADC2_CH5 = GPIO16; -static const uint8_t ADC2_CH6 = GPIO17; -static const uint8_t ADC2_CH7 = GPIO18; -static const uint8_t ADC1_CH7 = GPIO8; -static const uint8_t ADC2_CH8 = GPIO19; -static const uint8_t ADC2_CH9 = GPIO20; -static const uint8_t ADC1_CH2 = GPIO3; -static const uint8_t ADC1_CH8 = GPIO9; -static const uint8_t ADC1_CH9 = GPIO10; -static const uint8_t ADC2_CH0 = GPIO11; -static const uint8_t ADC2_CH1 = GPIO12; -static const uint8_t ADC2_CH2 = GPIO13; -static const uint8_t ADC2_CH3 = GPIO14; -static const uint8_t ADC1_CH1 = GPIO2; -static const uint8_t ADC1_CH0 = GPIO1; +static const uint8_t ADC1_CH3 = GPIO4; +static const uint8_t ADC1_CH4 = GPIO5; +static const uint8_t ADC1_CH5 = GPIO6; +static const uint8_t ADC1_CH6 = GPIO7; +static const uint8_t ADC2_CH4 = GPIO15; +static const uint8_t ADC2_CH5 = GPIO16; +static const uint8_t ADC2_CH6 = GPIO17; +static const uint8_t ADC2_CH7 = GPIO18; +static const uint8_t ADC1_CH7 = GPIO8; +static const uint8_t ADC2_CH8 = GPIO19; +static const uint8_t ADC2_CH9 = GPIO20; +static const uint8_t ADC1_CH2 = GPIO3; +static const uint8_t ADC1_CH8 = GPIO9; +static const uint8_t ADC1_CH9 = GPIO10; +static const uint8_t ADC2_CH0 = GPIO11; +static const uint8_t ADC2_CH1 = GPIO12; +static const uint8_t ADC2_CH2 = GPIO13; +static const uint8_t ADC2_CH3 = GPIO14; +static const uint8_t ADC1_CH1 = GPIO2; +static const uint8_t ADC1_CH0 = GPIO1; /* End Analog Pins on ESP32-S3-WROOM-1U-N4R8 */ /* Begin Touch Pins on ESP32-S3-WROOM-1U-N4R8 */ -static const uint8_t TOUCH4 = GPIO4; -static const uint8_t TOUCH5 = GPIO5; -static const uint8_t TOUCH6 = GPIO6; -static const uint8_t TOUCH7 = GPIO7; -static const uint8_t TOUCH8 = GPIO8; -static const uint8_t TOUCH3 = GPIO3; -static const uint8_t TOUCH9 = GPIO9; -static const uint8_t TOUCH10 = GPIO10; -static const uint8_t TOUCH11 = GPIO11; -static const uint8_t TOUCH12 = GPIO12; -static const uint8_t TOUCH13 = GPIO13; -static const uint8_t TOUCH14 = GPIO14; -static const uint8_t TOUCH2 = GPIO2; -static const uint8_t TOUCH1 = GPIO1; +static const uint8_t TOUCH4 = GPIO4; +static const uint8_t TOUCH5 = GPIO5; +static const uint8_t TOUCH6 = GPIO6; +static const uint8_t TOUCH7 = GPIO7; +static const uint8_t TOUCH8 = GPIO8; +static const uint8_t TOUCH3 = GPIO3; +static const uint8_t TOUCH9 = GPIO9; +static const uint8_t TOUCH10 = GPIO10; +static const uint8_t TOUCH11 = GPIO11; +static const uint8_t TOUCH12 = GPIO12; +static const uint8_t TOUCH13 = GPIO13; +static const uint8_t TOUCH14 = GPIO14; +static const uint8_t TOUCH2 = GPIO2; +static const uint8_t TOUCH1 = GPIO1; /* End Touch Pins on ESP32-S3-WROOM-1U-N4R8 */ -static const uint8_t TX = GPIO17; -static const uint8_t RX = GPIO18; - -static const uint8_t SDA = GPIO1; -static const uint8_t SCL = GPIO0; -static const uint8_t NAMINO_ARANCIO_I2C_SDA = SDA; -static const uint8_t NAMINO_ARANCIO_I2C_SCL = SCL; -static const uint8_t NM_I2C_SDA = SDA; -static const uint8_t NM_I2C_SCL = SCL; - -static const uint8_t A0 = ADC1_CH0; -static const uint8_t A1 = ADC1_CH1; -static const uint8_t A2 = ADC1_CH2; -static const uint8_t A3 = ADC1_CH3; -static const uint8_t A4 = ADC1_CH4; -static const uint8_t A5 = ADC1_CH5; -static const uint8_t A6 = ADC1_CH6; -static const uint8_t A7 = ADC1_CH7; -static const uint8_t A8 = ADC2_CH0; -static const uint8_t A9 = ADC2_CH1; -static const uint8_t A10 = ADC2_CH2; -static const uint8_t A11 = ADC2_CH3; -static const uint8_t A12 = ADC2_CH4; -static const uint8_t A13 = ADC2_CH5; -static const uint8_t A14 = ADC2_CH6; -static const uint8_t A15 = ADC2_CH7; - -static const uint8_t DAC1 = 0; -static const uint8_t DAC2 = 0; +static const uint8_t TX = GPIO17; +static const uint8_t RX = GPIO18; + +static const uint8_t SDA = GPIO1; +static const uint8_t SCL = GPIO0; +static const uint8_t NAMINO_ARANCIO_I2C_SDA = SDA; +static const uint8_t NAMINO_ARANCIO_I2C_SCL = SCL; +static const uint8_t NM_I2C_SDA = SDA; +static const uint8_t NM_I2C_SCL = SCL; + +static const uint8_t A0 = ADC1_CH0; +static const uint8_t A1 = ADC1_CH1; +static const uint8_t A2 = ADC1_CH2; +static const uint8_t A3 = ADC1_CH3; +static const uint8_t A4 = ADC1_CH4; +static const uint8_t A5 = ADC1_CH5; +static const uint8_t A6 = ADC1_CH6; +static const uint8_t A7 = ADC1_CH7; +static const uint8_t A8 = ADC2_CH0; +static const uint8_t A9 = ADC2_CH1; +static const uint8_t A10 = ADC2_CH2; +static const uint8_t A11 = ADC2_CH3; +static const uint8_t A12 = ADC2_CH4; +static const uint8_t A13 = ADC2_CH5; +static const uint8_t A14 = ADC2_CH6; +static const uint8_t A15 = ADC2_CH7; + +static const uint8_t DAC1 = 0; +static const uint8_t DAC2 = 0; /* Begin Arduino naming */ -static const uint8_t RESET_ARDUINO = GPIO46; -static const uint8_t PC0 = GPIO3; -static const uint8_t PC1 = GPIO4; -static const uint8_t PC2 = GPIO5; -static const uint8_t PC3 = GPIO6; -static const uint8_t PC4 = GPIO7; -static const uint8_t PC5 = GPIO8; -static const uint8_t PB5 = GPIO35; -static const uint8_t PB4 = GPIO36; -static const uint8_t PB3 = GPIO37; -static const uint8_t PB2 = GPIO38; -static const uint8_t PB1 = GPIO39; -static const uint8_t PB0 = GPIO40; -static const uint8_t PD7 = GPIO41; -static const uint8_t PD6 = GPIO42; -static const uint8_t PD5 = GPIO21; -static const uint8_t PD4 = GPIO16; -static const uint8_t PD3 = GPIO14; -static const uint8_t PD2 = GPIO9; -static const uint8_t PD1 = GPIO17; -static const uint8_t PD0 = GPIO18; +static const uint8_t RESET_ARDUINO = GPIO46; +static const uint8_t PC0 = GPIO3; +static const uint8_t PC1 = GPIO4; +static const uint8_t PC2 = GPIO5; +static const uint8_t PC3 = GPIO6; +static const uint8_t PC4 = GPIO7; +static const uint8_t PC5 = GPIO8; +static const uint8_t PB5 = GPIO35; +static const uint8_t PB4 = GPIO36; +static const uint8_t PB3 = GPIO37; +static const uint8_t PB2 = GPIO38; +static const uint8_t PB1 = GPIO39; +static const uint8_t PB0 = GPIO40; +static const uint8_t PD7 = GPIO41; +static const uint8_t PD6 = GPIO42; +static const uint8_t PD5 = GPIO21; +static const uint8_t PD4 = GPIO16; +static const uint8_t PD3 = GPIO14; +static const uint8_t PD2 = GPIO9; +static const uint8_t PD1 = GPIO17; +static const uint8_t PD0 = GPIO18; /* End Arduino naming */ /* Begin alternate naming */ -static const uint8_t J1_io0 = SCL; - -static const uint8_t J2_35 = PB5; -static const uint8_t J2_36 = PB4; -static const uint8_t J2_37 = PB3; -static const uint8_t J2_38 = PB2; -static const uint8_t J2_39 = PB1; -static const uint8_t J2_40 = PB0; - -static const uint8_t J3_io8 = PD7; -static const uint8_t J3_7 = PD6; -static const uint8_t J3_21 = PD5; -static const uint8_t J3_16 = PD4; -static const uint8_t J3_14 = PD3; -static const uint8_t J3_9 = PD2; -static const uint8_t J3_17 = TX; -static const uint8_t J3_18 = RX; - -static const uint8_t J4_cs_io2 = CS_SDCARD; -static const uint8_t J4_sclk = SCK; -static const uint8_t J4_mosi = MOSI; -static const uint8_t J4_miso = MISO; - -static const uint8_t J9_io3 = PC0; -static const uint8_t J9_4 = PC1; -static const uint8_t J9_5 = PC2; -static const uint8_t J9_6 = PC3; -static const uint8_t J9_7 = PC4; -static const uint8_t J9_8 = PC5; - -static const uint8_t J10_enc_A = 0; -static const uint8_t J10_enc_B = 0; -static const uint8_t J10_sw = 0; +static const uint8_t J1_io0 = SCL; + +static const uint8_t J2_35 = PB5; +static const uint8_t J2_36 = PB4; +static const uint8_t J2_37 = PB3; +static const uint8_t J2_38 = PB2; +static const uint8_t J2_39 = PB1; +static const uint8_t J2_40 = PB0; + +static const uint8_t J3_io8 = PD7; +static const uint8_t J3_7 = PD6; +static const uint8_t J3_21 = PD5; +static const uint8_t J3_16 = PD4; +static const uint8_t J3_14 = PD3; +static const uint8_t J3_9 = PD2; +static const uint8_t J3_17 = TX; +static const uint8_t J3_18 = RX; + +static const uint8_t J4_cs_io2 = CS_SDCARD; +static const uint8_t J4_sclk = SCK; +static const uint8_t J4_mosi = MOSI; +static const uint8_t J4_miso = MISO; + +static const uint8_t J9_io3 = PC0; +static const uint8_t J9_4 = PC1; +static const uint8_t J9_5 = PC2; +static const uint8_t J9_6 = PC3; +static const uint8_t J9_7 = PC4; +static const uint8_t J9_8 = PC5; + +static const uint8_t J10_enc_A = 0; +static const uint8_t J10_enc_B = 0; +static const uint8_t J10_sw = 0; /* End alternate naming */ #endif /* Pins_Arduino_h */ diff --git a/variants/nano32/pins_arduino.h b/variants/nano32/pins_arduino.h index 571912b7ee9..840fd863629 100644 --- a/variants/nano32/pins_arduino.h +++ b/variants/nano32/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 16; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t BUILTIN_KEY = 0; @@ -15,10 +15,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/nina_w10/pins_arduino.h b/variants/nina_w10/pins_arduino.h index 660424de2b6..ea1c5ab681d 100644 --- a/variants/nina_w10/pins_arduino.h +++ b/variants/nina_w10/pins_arduino.h @@ -15,10 +15,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 12; static const uint8_t SCL = 13; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/node32s/pins_arduino.h b/variants/node32s/pins_arduino.h index f4d30d32c09..e7c7a87e2c6 100644 --- a/variants/node32s/pins_arduino.h +++ b/variants/node32s/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -15,10 +15,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/nodemcu-32s/pins_arduino.h b/variants/nodemcu-32s/pins_arduino.h index f4d30d32c09..e7c7a87e2c6 100644 --- a/variants/nodemcu-32s/pins_arduino.h +++ b/variants/nodemcu-32s/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -15,10 +15,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/nologo_esp32c3_super_mini/pins_arduino.h b/variants/nologo_esp32c3_super_mini/pins_arduino.h index 3b4c144cca6..fdcc730c1a0 100644 --- a/variants/nologo_esp32c3_super_mini/pins_arduino.h +++ b/variants/nologo_esp32c3_super_mini/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 8; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 21; @@ -13,10 +13,10 @@ static const uint8_t RX = 20; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 7; -static const uint8_t MOSI = 6; -static const uint8_t MISO = 5; -static const uint8_t SCK = 4; +static const uint8_t SS = 7; +static const uint8_t MOSI = 6; +static const uint8_t MISO = 5; +static const uint8_t SCK = 4; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/nologo_esp32s3_pico/pins_arduino.h b/variants/nologo_esp32s3_pico/pins_arduino.h index 42109e0c12b..6a9000eb1a1 100644 --- a/variants/nologo_esp32s3_pico/pins_arduino.h +++ b/variants/nologo_esp32s3_pico/pins_arduino.h @@ -8,7 +8,7 @@ #define USB_PID 0x1001 static const uint8_t LED_BUILTIN = 21; -#define BUILTIN_LED LED_BUILTIN +#define BUILTIN_LED LED_BUILTIN #define LED_BUILTIN LED_BUILTIN #define RGB_BUILTIN SOC_GPIO_PIN_COUNT + LED_BUILTIN #define RGB_BRIGHTNESS 64 diff --git a/variants/nora_w10/pins_arduino.h b/variants/nora_w10/pins_arduino.h index ee473f5856f..a833fbb2440 100644 --- a/variants/nora_w10/pins_arduino.h +++ b/variants/nora_w10/pins_arduino.h @@ -9,76 +9,76 @@ // The pin assignments in this file are based on u-blox EVK-NORA-W1, a Arduino compatible board. // For your own module design you can freely chose the pins available on the module module pins -static const uint8_t TX = 43; -static const uint8_t RX = 44; -static const uint8_t RTS = 45; -static const uint8_t CTS = 6; -static const uint8_t DTR = 1; -static const uint8_t DSR = 7; +static const uint8_t TX = 43; +static const uint8_t RX = 44; +static const uint8_t RTS = 45; +static const uint8_t CTS = 6; +static const uint8_t DTR = 1; +static const uint8_t DSR = 7; -static const uint8_t SW1 = 46; -static const uint8_t SW2 = 0; // BOOT -static const uint8_t SW3 = 47; -static const uint8_t SW4 = 48; +static const uint8_t SW1 = 46; +static const uint8_t SW2 = 0; // BOOT +static const uint8_t SW3 = 47; +static const uint8_t SW4 = 48; -static const uint8_t LED_RED = 5; -static const uint8_t LED_GREEN = 2; -static const uint8_t LED_BLUE = 8; -#define BUILTIN_LED LED_BLUE // backward compatibility -#define LED_BUILTIN LED_BLUE +static const uint8_t LED_RED = 5; +static const uint8_t LED_GREEN = 2; +static const uint8_t LED_BLUE = 8; +#define BUILTIN_LED LED_BLUE // backward compatibility +#define LED_BUILTIN LED_BLUE -static const uint8_t SS = 34; +static const uint8_t SS = 34; static const uint8_t MOSI = 35; static const uint8_t MISO = 37; -static const uint8_t SCK = 36; +static const uint8_t SCK = 36; -static const uint8_t A0 = 11; -static const uint8_t A1 = 12; -static const uint8_t A2 = 13; -static const uint8_t A3 = 5; -static const uint8_t A4 = 15; -static const uint8_t A5 = 16; +static const uint8_t A0 = 11; +static const uint8_t A1 = 12; +static const uint8_t A2 = 13; +static const uint8_t A3 = 5; +static const uint8_t A4 = 15; +static const uint8_t A5 = 16; -static const uint8_t D0 = 44; // RX0 -static const uint8_t D1 = 43; // TX0 -static const uint8_t D2 = 46; -static const uint8_t D3 = 4; -static const uint8_t D4 = 3; -static const uint8_t D5 = 2; -static const uint8_t D6 = 14; -static const uint8_t D7 = 10; +static const uint8_t D0 = 44; // RX0 +static const uint8_t D1 = 43; // TX0 +static const uint8_t D2 = 46; +static const uint8_t D3 = 4; +static const uint8_t D4 = 3; +static const uint8_t D5 = 2; +static const uint8_t D6 = 14; +static const uint8_t D7 = 10; -static const uint8_t D8 = 33; -static const uint8_t D9 = 38; -static const uint8_t D10 = 34; // SS -static const uint8_t D11 = 35; // MOSI -static const uint8_t D12 = 37; // MISO -static const uint8_t D13 = 36; // SCK -static const uint8_t SDA1 = 21; -static const uint8_t SCL1 = 0; +static const uint8_t D8 = 33; +static const uint8_t D9 = 38; +static const uint8_t D10 = 34; // SS +static const uint8_t D11 = 35; // MOSI +static const uint8_t D12 = 37; // MISO +static const uint8_t D13 = 36; // SCK +static const uint8_t SDA1 = 21; +static const uint8_t SCL1 = 0; -static const uint8_t D14 = 45; // RTS -static const uint8_t D15 = 6; // CTS -static const uint8_t D16 = 1; // DTR -static const uint8_t D17 = 7; // DSR -static const uint8_t D18 = 47; -static const uint8_t D19 = 48; -static const uint8_t SDA = 18; -static const uint8_t SCL = 17; +static const uint8_t D14 = 45; // RTS +static const uint8_t D15 = 6; // CTS +static const uint8_t D16 = 1; // DTR +static const uint8_t D17 = 7; // DSR +static const uint8_t D18 = 47; +static const uint8_t D19 = 48; +static const uint8_t SDA = 18; +static const uint8_t SCL = 17; -static const uint8_t T1 = 1; -static const uint8_t T2 = 2; -static const uint8_t T3 = 3; -static const uint8_t T4 = 4; -static const uint8_t T5 = 5; -static const uint8_t T6 = 6; -static const uint8_t T7 = 7; -static const uint8_t T8 = 8; -static const uint8_t T9 = 9; -static const uint8_t T10 = 10; -static const uint8_t T11 = 11; -static const uint8_t T12 = 12; -static const uint8_t T13 = 13; -static const uint8_t T14 = 14; +static const uint8_t T1 = 1; +static const uint8_t T2 = 2; +static const uint8_t T3 = 3; +static const uint8_t T4 = 4; +static const uint8_t T5 = 5; +static const uint8_t T6 = 6; +static const uint8_t T7 = 7; +static const uint8_t T8 = 8; +static const uint8_t T9 = 9; +static const uint8_t T10 = 10; +static const uint8_t T11 = 11; +static const uint8_t T12 = 12; +static const uint8_t T13 = 13; +static const uint8_t T14 = 14; #endif /* Pins_Arduino_h */ diff --git a/variants/odroid_esp32/pins_arduino.h b/variants/odroid_esp32/pins_arduino.h index dc10a37cd8a..f89dfff1bdd 100644 --- a/variants/odroid_esp32/pins_arduino.h +++ b/variants/odroid_esp32/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -13,10 +13,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 15; static const uint8_t SCL = 4; -static const uint8_t SS = 22; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 22; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; diff --git a/variants/onehorse32dev/pins_arduino.h b/variants/onehorse32dev/pins_arduino.h index 03cbbc1676c..06364e54f8b 100644 --- a/variants/onehorse32dev/pins_arduino.h +++ b/variants/onehorse32dev/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 5; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -15,10 +15,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A1 = 37; diff --git a/variants/openkb/pins_arduino.h b/variants/openkb/pins_arduino.h index c429cc3f32a..e17d7ae5a31 100644 --- a/variants/openkb/pins_arduino.h +++ b/variants/openkb/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 16; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -13,10 +13,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; @@ -73,12 +73,12 @@ static const uint8_t OUTPUT2 = 27; static const uint8_t SDA0 = 21; static const uint8_t SCL0 = 22; -#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin) +#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin) static const uint8_t SDA1 = 4; static const uint8_t SCL1 = 5; static const uint8_t KB_GPIO18 = 18; static const uint8_t KB_GPIO19 = 19; -static const uint8_t KB_GPIO23= 23; +static const uint8_t KB_GPIO23 = 23; #endif /* Pins_Arduino_h */ diff --git a/variants/oroca_edubot/pins_arduino.h b/variants/oroca_edubot/pins_arduino.h index e9322abb9c9..b73dc4dd000 100644 --- a/variants/oroca_edubot/pins_arduino.h +++ b/variants/oroca_edubot/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 13; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 17; @@ -13,18 +13,18 @@ static const uint8_t RX = 16; static const uint8_t SDA = 23; static const uint8_t SCL = 22; -static const uint8_t SS = 2; -static const uint8_t MOSI = 18; -static const uint8_t MISO = 19; -static const uint8_t SCK = 5; +static const uint8_t SS = 2; +static const uint8_t MOSI = 18; +static const uint8_t MISO = 19; +static const uint8_t SCK = 5; -static const uint8_t A0 = 34; +static const uint8_t A0 = 34; static const uint8_t A1 = 39; static const uint8_t A2 = 36; static const uint8_t A3 = 33; -static const uint8_t D0 = 4; +static const uint8_t D0 = 4; static const uint8_t D1 = 16; static const uint8_t D2 = 17; static const uint8_t D3 = 22; diff --git a/variants/pico32/pins_arduino.h b/variants/pico32/pins_arduino.h index 27ecc063483..3663de76cd4 100644 --- a/variants/pico32/pins_arduino.h +++ b/variants/pico32/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/piranha_esp-32/pins_arduino.h b/variants/piranha_esp-32/pins_arduino.h index aa170ca1605..57616dac637 100644 --- a/variants/piranha_esp-32/pins_arduino.h +++ b/variants/piranha_esp-32/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -15,10 +15,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A11 = 0; static const uint8_t A13 = 15; diff --git a/variants/pocket_32/pins_arduino.h b/variants/pocket_32/pins_arduino.h index 325331dbb26..9c904d04226 100644 --- a/variants/pocket_32/pins_arduino.h +++ b/variants/pocket_32/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 16; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -13,10 +13,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/quantum/pins_arduino.h b/variants/quantum/pins_arduino.h index 27ecc063483..3663de76cd4 100644 --- a/variants/quantum/pins_arduino.h +++ b/variants/quantum/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/redpill_esp32s3/pins_arduino.h b/variants/redpill_esp32s3/pins_arduino.h index 4c3672d263f..60f7dfd35f9 100644 --- a/variants/redpill_esp32s3/pins_arduino.h +++ b/variants/redpill_esp32s3/pins_arduino.h @@ -8,7 +8,7 @@ #define USB_PID 0x1001 static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 3; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 @@ -19,10 +19,10 @@ static const uint8_t RX = 44; 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 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; diff --git a/variants/roboheart_hercules/pins_arduino.h b/variants/roboheart_hercules/pins_arduino.h index 198967d8839..cd7f093dc9d 100644 --- a/variants/roboheart_hercules/pins_arduino.h +++ b/variants/roboheart_hercules/pins_arduino.h @@ -3,7 +3,7 @@ #include -// Motor driver pins +// Motor driver pins #define MOTOR_A_IN1 25 // PHASE/IN1 #define MOTOR_A_IN2 26 // ENABLE/IN2 @@ -13,13 +13,13 @@ #define MOTOR_C_IN1 33 // PHASE/IN1 #define MOTOR_C_IN2 4 // ENABLE/IN2 -#define SLEEP_MOTOR_ABC 2 // nSLEEP +#define SLEEP_MOTOR_ABC 2 // nSLEEP -#define LED_ROBOHEART 13 // Built in LED -#define BUILTIN_LED LED_ROBOHEART // backward compatibility +#define LED_ROBOHEART 13 // Built in LED +#define BUILTIN_LED LED_ROBOHEART // backward compatibility #define LED_BUILTIN LED_ROBOHEART -#define BUTTON_ROBOHEART 0 // Button +#define BUTTON_ROBOHEART 0 // Button // I2C IMU sensor #define IMU_SDA 21 @@ -35,7 +35,7 @@ #define GSM_RTS 14 #define GSM_TX TXD1 #define GSM_RX RXD1 -#define BATTERY_PIN 36 // Battery ADC pin +#define BATTERY_PIN 36 // Battery ADC pin static const uint8_t TX = 35; static const uint8_t RX = 34; @@ -46,10 +46,10 @@ static const uint8_t RXD2 = 16; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t G23 = 23; static const uint8_t G19 = 19; diff --git a/variants/sensebox_mcu_esp32s2/partitions-4MB-tinyuf2.csv b/variants/sensebox_mcu_esp32s2/partitions-4MB-tinyuf2.csv index 461a8dfea6a..164ba0d5965 100644 --- a/variants/sensebox_mcu_esp32s2/partitions-4MB-tinyuf2.csv +++ b/variants/sensebox_mcu_esp32s2/partitions-4MB-tinyuf2.csv @@ -9,4 +9,3 @@ ota_0, 0, ota_0, 0x10000, 1408K, ota_1, 0, ota_1, 0x170000, 1408K, uf2, app, factory,0x2d0000, 256K, ffat, data, fat, 0x310000, 960K, - diff --git a/variants/sensebox_mcu_esp32s2/pins_arduino.h b/variants/sensebox_mcu_esp32s2/pins_arduino.h index 9a6e4eb4a47..b10e5495ffb 100644 --- a/variants/sensebox_mcu_esp32s2/pins_arduino.h +++ b/variants/sensebox_mcu_esp32s2/pins_arduino.h @@ -7,70 +7,70 @@ #define USB_PID 0x81B8 #define USB_MANUFACTURER "senseBox" #define USB_PRODUCT "MCU-S2 ESP32S2" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_SERIAL "" // Empty string for MAC address // Default USB FirmwareMSC Settings -#define USB_FW_MSC_VENDOR_ID "senseBox" // max 8 chars -#define USB_FW_MSC_PRODUCT_ID "MCU-S2 ESP32S2" // max 16 chars -#define USB_FW_MSC_PRODUCT_REVISION "1.00" // max 4 chars -#define USB_FW_MSC_VOLUME_NAME "senseBox" // max 11 chars +#define USB_FW_MSC_VENDOR_ID "senseBox" // max 8 chars +#define USB_FW_MSC_PRODUCT_ID "MCU-S2 ESP32S2" // max 16 chars +#define USB_FW_MSC_PRODUCT_REVISION "1.00" // max 4 chars +#define USB_FW_MSC_VOLUME_NAME "senseBox" // max 11 chars #define USB_FW_MSC_SERIAL_NUMBER 0x00000000 -#define PIN_NEOPIXEL 1 // NeoPixel LED -#define NEOPIXEL_PIN 1 // NeoPixel LED -#define NEOPIXEL_NUM 1 // number of neopixels +#define PIN_NEOPIXEL 1 // NeoPixel LED +#define NEOPIXEL_PIN 1 // NeoPixel LED +#define NEOPIXEL_NUM 1 // number of neopixels // Default I2C QWIIC-Ports static const uint8_t SDA = 39; static const uint8_t SCL = 40; -#define PIN_QWIIC_SDA 39 -#define PIN_QWIIC_SCL 40 +#define PIN_QWIIC_SDA 39 +#define PIN_QWIIC_SCL 40 // Secondary I2C MPU6050 -#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin) +#define WIRE1_PIN_DEFINED 1 // See Wire.cpp at bool TwoWire::initPins(int sdaPin, int sclPin) static const uint8_t SCL1 = 42; static const uint8_t SDA1 = 45; -#define PIN_I2C_SCL 42 -#define PIN_I2C_SDA 45 -#define PIN_I2C_INT 46 +#define PIN_I2C_SCL 42 +#define PIN_I2C_SDA 45 +#define PIN_I2C_INT 46 // SPI -static const uint8_t SS = 42; +static const uint8_t SS = 42; static const uint8_t MOSI = 35; -static const uint8_t SCK = 36; +static const uint8_t SCK = 36; static const uint8_t MISO = 37; -// XBEE Pins -#define PIN_XBEE_ENABLE 41 -#define PIN_XBEE_INT 33 -#define PIN_XBEE_CS 34 -#define PIN_XBEE_MOSI 35 -#define PIN_XBEE_SCLK 36 -#define PIN_XBEE_MISO 37 -#define PIN_XBEE_RESET 38 -#define PIN_XBEE_TXD 17 -#define PIN_XBEE_RXD 18 +// XBEE Pins +#define PIN_XBEE_ENABLE 41 +#define PIN_XBEE_INT 33 +#define PIN_XBEE_CS 34 +#define PIN_XBEE_MOSI 35 +#define PIN_XBEE_SCLK 36 +#define PIN_XBEE_MISO 37 +#define PIN_XBEE_RESET 38 +#define PIN_XBEE_TXD 17 +#define PIN_XBEE_RXD 18 // Alias XB1 -#define PIN_XB1_ENABLE 41 -#define PIN_XB1_INT 33 -#define PIN_XB1_CS 34 -#define PIN_XB1_MOSI 35 -#define PIN_XB1_SCLK 36 -#define PIN_XB1_MISO 37 -#define PIN_XB1_RESET 38 -#define PIN_XB1_TXD 17 -#define PIN_XB1_RXD 18 +#define PIN_XB1_ENABLE 41 +#define PIN_XB1_INT 33 +#define PIN_XB1_CS 34 +#define PIN_XB1_MOSI 35 +#define PIN_XB1_SCLK 36 +#define PIN_XB1_MISO 37 +#define PIN_XB1_RESET 38 +#define PIN_XB1_TXD 17 +#define PIN_XB1_RXD 18 // IO Pins -#define PIN_LED 1 -#define PIN_IO2 2 -#define PIN_IO3 3 -#define PIN_IO4 4 -#define PIN_IO5 5 -#define PIN_IO6 6 -#define PIN_IO7 7 -#define IO_ENABLE 8 +#define PIN_LED 1 +#define PIN_IO2 2 +#define PIN_IO3 3 +#define PIN_IO4 4 +#define PIN_IO5 5 +#define PIN_IO6 6 +#define PIN_IO7 7 +#define IO_ENABLE 8 static const uint8_t A2 = PIN_IO2; static const uint8_t A3 = PIN_IO3; @@ -89,35 +89,35 @@ static const uint8_t D7 = PIN_IO7; // UART Port static const uint8_t TX = 43; static const uint8_t RX = 44; -#define PIN_UART_TXD 43 -#define PIN_UART_RXD 44 -#define PIN_UART_ENABLE 26 +#define PIN_UART_TXD 43 +#define PIN_UART_RXD 44 +#define PIN_UART_ENABLE 26 // UART XBee static const uint8_t TX1 = 17; static const uint8_t RX1 = 18; // PD-Sensor -#define PD_SENSE 14 -#define PD_ENABLE 21 -#define PIN_PD_ENABLE 21 +#define PD_SENSE 14 +#define PD_ENABLE 21 +#define PIN_PD_ENABLE 21 // SD-Card -#define VSPI_MISO 13 -#define VSPI_MOSI 11 -#define VSPI_SCLK 12 -#define VSPI_SS 10 -#define SD_ENABLE 9 - -#define PIN_SD_ENABLE 9 -#define PIN_SD_CS 10 -#define PIN_SD_MOSI 11 -#define PIN_SD_SCLK 12 -#define PIN_SD_MISO 13 +#define VSPI_MISO 13 +#define VSPI_MOSI 11 +#define VSPI_SCLK 12 +#define VSPI_SS 10 +#define SD_ENABLE 9 + +#define PIN_SD_ENABLE 9 +#define PIN_SD_CS 10 +#define PIN_SD_MOSI 11 +#define PIN_SD_SCLK 12 +#define PIN_SD_MISO 13 // USB -#define PIN_USB_DM 19 -#define PIN_USB_DP 20 +#define PIN_USB_DM 19 +#define PIN_USB_DP 20 // Touch Pins static const uint8_t T2 = PIN_IO2; diff --git a/variants/sensebox_mcu_esp32s2/variant.cpp b/variants/sensebox_mcu_esp32s2/variant.cpp index 311f69b8d35..948988d84d6 100644 --- a/variants/sensebox_mcu_esp32s2/variant.cpp +++ b/variants/sensebox_mcu_esp32s2/variant.cpp @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries @@ -28,21 +28,20 @@ extern "C" { -// Initialize variant/board, called before setup() -void initVariant(void) -{ + // Initialize variant/board, called before setup() + void initVariant(void) { //enable IO Pins by default pinMode(IO_ENABLE, OUTPUT); - digitalWrite(IO_ENABLE,LOW); + digitalWrite(IO_ENABLE, LOW); //reset RGB pinMode(PIN_NEOPIXEL, OUTPUT); digitalWrite(PIN_NEOPIXEL, LOW); - + //enable XBEE by default pinMode(PIN_XB1_ENABLE, OUTPUT); digitalWrite(PIN_XB1_ENABLE, LOW); - + //enable UART by default pinMode(PIN_UART_ENABLE, OUTPUT); digitalWrite(PIN_UART_ENABLE, LOW); @@ -50,6 +49,5 @@ void initVariant(void) //enable PD-Sensor by default pinMode(PD_ENABLE, OUTPUT); digitalWrite(PD_ENABLE, HIGH); - -} + } } diff --git a/variants/sparkfun_esp32_iot_redboard/pins_arduino.h b/variants/sparkfun_esp32_iot_redboard/pins_arduino.h index abef21cdbbd..ba163f43536 100644 --- a/variants/sparkfun_esp32_iot_redboard/pins_arduino.h +++ b/variants/sparkfun_esp32_iot_redboard/pins_arduino.h @@ -5,11 +5,11 @@ #include "soc/soc_caps.h" static const uint8_t LED_BUILTIN = 18; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -#define NEO_PIXEL 2 //WS2812 LED -static const uint8_t RGB_BUILTIN = (SOC_GPIO_PIN_COUNT+NEO_PIXEL); +#define NEO_PIXEL 2 //WS2812 LED +static const uint8_t RGB_BUILTIN = (SOC_GPIO_PIN_COUNT + NEO_PIXEL); #define RGB_BUILTIN RGB_BUILTIN // necessary to make digitalWrite/digitalMode find it #define RGB_BRIGHTNESS 64 @@ -19,10 +19,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/sparkfun_esp32c6_qwiic_pocket/pins_arduino.h b/variants/sparkfun_esp32c6_qwiic_pocket/pins_arduino.h index 06bfee15b29..ca021a1426e 100644 --- a/variants/sparkfun_esp32c6_qwiic_pocket/pins_arduino.h +++ b/variants/sparkfun_esp32c6_qwiic_pocket/pins_arduino.h @@ -6,7 +6,7 @@ // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino static const uint8_t LED_BUILTIN = 23; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 16; @@ -15,10 +15,10 @@ static const uint8_t RX = 17; static const uint8_t SDA = 6; static const uint8_t SCL = 7; -static const uint8_t SS = 2; +static const uint8_t SS = 2; static const uint8_t MOSI = 3; static const uint8_t MISO = 4; -static const uint8_t SCK = 5; +static const uint8_t SCK = 5; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/sparkfun_esp32c6_thing_plus/pins_arduino.h b/variants/sparkfun_esp32c6_thing_plus/pins_arduino.h index 60bd42884d1..3bf6496d8ce 100644 --- a/variants/sparkfun_esp32c6_thing_plus/pins_arduino.h +++ b/variants/sparkfun_esp32c6_thing_plus/pins_arduino.h @@ -4,10 +4,10 @@ #include #include "soc/soc_caps.h" -#define PIN_NEOPIXEL 23 +#define PIN_NEOPIXEL 23 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN @@ -19,10 +19,10 @@ static const uint8_t RX = 17; static const uint8_t SDA = 6; static const uint8_t SCL = 7; -static const uint8_t SS = 5; +static const uint8_t SS = 5; static const uint8_t MOSI = 20; static const uint8_t MISO = 21; -static const uint8_t SCK = 19; +static const uint8_t SCK = 19; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/sparkfun_lora_gateway_1-channel/pins_arduino.h b/variants/sparkfun_lora_gateway_1-channel/pins_arduino.h old mode 100755 new mode 100644 index 529ee3d003c..589b72e5baa --- a/variants/sparkfun_lora_gateway_1-channel/pins_arduino.h +++ b/variants/sparkfun_lora_gateway_1-channel/pins_arduino.h @@ -1,52 +1,52 @@ -#ifndef Pins_Arduino_h -#define Pins_Arduino_h - -#include - -static const int LED_BUILTIN = 17; -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN - -static const uint8_t TX = 1; -static const uint8_t RX = 3; - -static const uint8_t SDA = 21; -static const uint8_t SCL = 22; - -static const uint8_t SS = 16; -static const uint8_t MOSI = 13; -static const uint8_t MISO = 12; -static const uint8_t SCK = 14; - -static const uint8_t A0 = 36; -static const uint8_t A3 = 39; -static const uint8_t A4 = 32; -static const uint8_t A5 = 33; -static const uint8_t A6 = 34; -static const uint8_t A7 = 35; -static const uint8_t A10 = 4; -static const uint8_t A11 = 0; -static const uint8_t A12 = 2; -static const uint8_t A13 = 15; -static const uint8_t A14 = 13; -static const uint8_t A15 = 12; -static const uint8_t A16 = 14; -static const uint8_t A17 = 27; -static const uint8_t A18 = 25; -static const uint8_t A19 = 26; - -static const uint8_t T0 = 4; -static const uint8_t T1 = 0; -static const uint8_t T2 = 2; -static const uint8_t T3 = 15; -static const uint8_t T4 = 13; -static const uint8_t T5 = 12; -static const uint8_t T6 = 14; -static const uint8_t T7 = 27; -static const uint8_t T8 = 33; -static const uint8_t T9 = 32; - -static const uint8_t DAC1 = 25; -static const uint8_t DAC2 = 26; - -#endif /* Pins_Arduino_h */ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +static const int LED_BUILTIN = 17; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN + +static const uint8_t TX = 1; +static const uint8_t RX = 3; + +static const uint8_t SDA = 21; +static const uint8_t SCL = 22; + +static const uint8_t SS = 16; +static const uint8_t MOSI = 13; +static const uint8_t MISO = 12; +static const uint8_t SCK = 14; + +static const uint8_t A0 = 36; +static const uint8_t A3 = 39; +static const uint8_t A4 = 32; +static const uint8_t A5 = 33; +static const uint8_t A6 = 34; +static const uint8_t A7 = 35; +static const uint8_t A10 = 4; +static const uint8_t A11 = 0; +static const uint8_t A12 = 2; +static const uint8_t A13 = 15; +static const uint8_t A14 = 13; +static const uint8_t A15 = 12; +static const uint8_t A16 = 14; +static const uint8_t A17 = 27; +static const uint8_t A18 = 25; +static const uint8_t A19 = 26; + +static const uint8_t T0 = 4; +static const uint8_t T1 = 0; +static const uint8_t T2 = 2; +static const uint8_t T3 = 15; +static const uint8_t T4 = 13; +static const uint8_t T5 = 12; +static const uint8_t T6 = 14; +static const uint8_t T7 = 27; +static const uint8_t T8 = 33; +static const uint8_t T9 = 32; + +static const uint8_t DAC1 = 25; +static const uint8_t DAC2 = 26; + +#endif /* Pins_Arduino_h */ diff --git a/variants/sparkfun_pro_micro_esp32c3/pins_arduino.h b/variants/sparkfun_pro_micro_esp32c3/pins_arduino.h index 8c29399fc63..bb268ca8fa0 100644 --- a/variants/sparkfun_pro_micro_esp32c3/pins_arduino.h +++ b/variants/sparkfun_pro_micro_esp32c3/pins_arduino.h @@ -3,11 +3,11 @@ #include -#define USB_VID 0x1B4F -#define USB_PID 0x0035 -#define USB_MANUFACTURER "SparkFun" -#define USB_PRODUCT "SparkFun_Pro_Micro-ESP32C3" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x1B4F +#define USB_PID 0x0035 +#define USB_MANUFACTURER "SparkFun" +#define USB_PRODUCT "SparkFun_Pro_Micro-ESP32C3" +#define USB_SERIAL "" // Empty string for MAC address static const uint8_t LED_BUILTIN = 10; @@ -20,10 +20,10 @@ static const uint8_t A2 = 2; static const uint8_t A3 = 3; static const uint8_t A4 = 4; -static const uint8_t D0 = 0; -static const uint8_t D1 = 1; -static const uint8_t D2 = 2; -static const uint8_t D3 = 3; +static const uint8_t D0 = 0; +static const uint8_t D1 = 1; +static const uint8_t D2 = 2; +static const uint8_t D3 = 3; static const uint8_t D4 = 4; static const uint8_t D5 = 5; static const uint8_t D6 = 6; @@ -35,14 +35,14 @@ static const uint8_t D10 = 10; static const uint8_t SDA = 5; static const uint8_t SCL = 6; -static const uint8_t SS = 10; -static const uint8_t MOSI = 3; -static const uint8_t MISO = 1; -static const uint8_t SCK = 0; +static const uint8_t SS = 10; +static const uint8_t MOSI = 3; +static const uint8_t MISO = 1; +static const uint8_t SCK = 0; -static const uint8_t PIN_I2S_SCK = 6; // Frame clock, no bit clock -static const uint8_t PIN_I2S_SD_DOUT = 7; // data out -static const uint8_t PIN_I2S_SD_IN = 5; // data in -static const uint8_t PIN_I2S_FS = 10; // frame select +static const uint8_t PIN_I2S_SCK = 6; // Frame clock, no bit clock +static const uint8_t PIN_I2S_SD_DOUT = 7; // data out +static const uint8_t PIN_I2S_SD_IN = 5; // data in +static const uint8_t PIN_I2S_FS = 10; // frame select #endif /* Pins_Arduino_h */ diff --git a/variants/tamc_termod_s3/pins_arduino.h b/variants/tamc_termod_s3/pins_arduino.h index 637da583243..1e25e7ee7cb 100644 --- a/variants/tamc_termod_s3/pins_arduino.h +++ b/variants/tamc_termod_s3/pins_arduino.h @@ -6,7 +6,7 @@ #define USB_VID 0x303a #define USB_PID 0x1001 -// This board has no NeoLED or any User LED +// This board has no NeoLED or any User LED static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -14,10 +14,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 10; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 13; -static const uint8_t SCK = 12; +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -55,21 +55,21 @@ static const uint8_t T12 = 12; static const uint8_t T13 = 13; static const uint8_t T14 = 14; -static const uint8_t BAT_LV = 1; -static const uint8_t CHG = 2; -static const uint8_t TFT_CS = 10; -static const uint8_t TFT_DC = 18; -static const uint8_t TFT_RST = 14; -static const uint8_t TFT_BCKL = 48; // TFT Backlight is enabled by soldering JP2 together -static const uint8_t SD_CS = 21; -static const uint8_t SD_CD = 47; // uSD Card Detect is enabled by soldering JP1 together. +static const uint8_t BAT_LV = 1; +static const uint8_t CHG = 2; +static const uint8_t TFT_CS = 10; +static const uint8_t TFT_DC = 18; +static const uint8_t TFT_RST = 14; +static const uint8_t TFT_BCKL = 48; // TFT Backlight is enabled by soldering JP2 together +static const uint8_t SD_CS = 21; +static const uint8_t SD_CD = 47; // uSD Card Detect is enabled by soldering JP1 together. #define DISPLAY_PORTRAIT 2 #define DISPLAY_LANDSCAPE 3 #define DISPLAY_PORTRAIT_FLIP 0 #define DISPLAY_LANDSCAPE_FLIP 1 -#define DISPLAY_WIDTH 240 +#define DISPLAY_WIDTH 240 #define DISPLAY_HEIGHT 320 /** diff --git a/variants/tamc_termod_s3/variant.cpp b/variants/tamc_termod_s3/variant.cpp index 72bbf62614d..8079bdbba8d 100644 --- a/variants/tamc_termod_s3/variant.cpp +++ b/variants/tamc_termod_s3/variant.cpp @@ -1,9 +1,9 @@ #include "Arduino.h" float getBatteryVoltage() { - int analogVolt = analogReadMilliVolts(1); + int analogVolt = analogReadMilliVolts(1); float voltage = analogVolt / 1000.0; - voltage = voltage * (100.0+200.0) / 200.0; + voltage = voltage * (100.0 + 200.0) / 200.0; return voltage; } @@ -20,8 +20,12 @@ bool getChargingState() { void (*__onChargeStart__)(); void (*__onChargeEnd__)(); -void setOnChargeStart(void (*func)()) { __onChargeStart__ = func; } -void setOnChargeEnd(void (*func)()) { __onChargeEnd__ = func; } +void setOnChargeStart(void (*func)()) { + __onChargeStart__ = func; +} +void setOnChargeEnd(void (*func)()) { + __onChargeEnd__ = func; +} void ARDUINO_ISR_ATTR chargeIsr() { if (getChargingState()) { @@ -31,7 +35,7 @@ void ARDUINO_ISR_ATTR chargeIsr() { } } -extern "C" void initVariant(void){ +extern "C" void initVariant(void) { pinMode(CHG, INPUT_PULLUP); attachInterrupt(CHG, chargeIsr, CHANGE); analogReadResolution(12); diff --git a/variants/tbeam/pins_arduino.h b/variants/tbeam/pins_arduino.h index b27a913e1ff..27453f7a76f 100644 --- a/variants/tbeam/pins_arduino.h +++ b/variants/tbeam/pins_arduino.h @@ -4,20 +4,20 @@ #include // SPI LoRa Radio -#define LORA_SCK 5 // GPIO5 - SX1276 SCK -#define LORA_MISO 19 // GPIO19 - SX1276 MISO -#define LORA_MOSI 27 // GPIO27 - SX1276 MOSI -#define LORA_CS 18 // GPIO18 - SX1276 CS -#define LORA_RST 23 // GPIO23 - SX1276 RST -#define LORA_IRQ 26 // GPIO26 - SX1276 IO0 +#define LORA_SCK 5 // GPIO5 - SX1276 SCK +#define LORA_MISO 19 // GPIO19 - SX1276 MISO +#define LORA_MOSI 27 // GPIO27 - SX1276 MOSI +#define LORA_CS 18 // GPIO18 - SX1276 CS +#define LORA_RST 23 // GPIO23 - SX1276 RST +#define LORA_IRQ 26 // GPIO26 - SX1276 IO0 #define LORA_IO0 LORA_IRQ // alias -#define LORA_IO1 33 // GPIO33 - SX1276 IO1 -> wired on pcb AND connected to header pin LORA1 -#define LORA_IO2 32 // GPIO32 - SX1276 IO2 -> wired on pcb AND connected to header pin LORA2 +#define LORA_IO1 33 // GPIO33 - SX1276 IO1 -> wired on pcb AND connected to header pin LORA1 +#define LORA_IO2 32 // GPIO32 - SX1276 IO2 -> wired on pcb AND connected to header pin LORA2 static const uint8_t KEY_BUILTIN = 39; static const uint8_t LED_BUILTIN = 14; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -25,11 +25,11 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; - -static const uint8_t SS = 18; -static const uint8_t MOSI = 27; -static const uint8_t MISO = 19; -static const uint8_t SCK = 5; + +static const uint8_t SS = 18; +static const uint8_t MOSI = 27; +static const uint8_t MISO = 19; +static const uint8_t SCK = 5; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/thingpulse_epulse_feather/pins_arduino.h b/variants/thingpulse_epulse_feather/pins_arduino.h index 3538c84128a..62855db018f 100644 --- a/variants/thingpulse_epulse_feather/pins_arduino.h +++ b/variants/thingpulse_epulse_feather/pins_arduino.h @@ -4,19 +4,19 @@ #include static const uint8_t LED_BUILTIN = -1; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t SDA = 23; static const uint8_t SCL = 22; -static const uint8_t MOSI = 18; -static const uint8_t MISO = 19; -static const uint8_t SCK = 5; -static const uint8_t SS = -1; +static const uint8_t MOSI = 18; +static const uint8_t MISO = 19; +static const uint8_t SCK = 5; +static const uint8_t SS = -1; // mapping to match other feathers and also in order -static const uint8_t A0 = 26; +static const uint8_t A0 = 26; static const uint8_t A1 = 25; static const uint8_t A2 = 34; static const uint8_t A3 = 39; @@ -31,14 +31,14 @@ static const uint8_t A11 = 12; static const uint8_t A12 = 13; // vbat measure -static const uint8_t BATT_MONITOR = 35; // Note: voltage divider 2.2M/4.7M +static const uint8_t BATT_MONITOR = 35; // Note: voltage divider 2.2M/4.7M static const uint8_t A13 = 35; //static const uint8_t Ax = 0; // not used/available //static const uint8_t Ax = 2; // not used/available? GPIO02 is available! // touch inputs static const uint8_t T0 = 4; -static const uint8_t T2 = 2; +static const uint8_t T2 = 2; static const uint8_t T3 = 15; static const uint8_t T4 = 13; static const uint8_t T5 = 12; @@ -50,4 +50,4 @@ static const uint8_t T9 = 32; static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; -#endif /* Pins_Arduino_h */ \ No newline at end of file +#endif /* Pins_Arduino_h */ diff --git a/variants/thingpulse_epulse_feather_c6/pins_arduino.h b/variants/thingpulse_epulse_feather_c6/pins_arduino.h index b551983d7fe..fc861cb64e8 100644 --- a/variants/thingpulse_epulse_feather_c6/pins_arduino.h +++ b/variants/thingpulse_epulse_feather_c6/pins_arduino.h @@ -4,10 +4,10 @@ #include #include "soc/soc_caps.h" -#define PIN_NEOPIXEL 8 +#define PIN_NEOPIXEL 8 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN @@ -19,10 +19,10 @@ static const uint8_t RX = 17; static const uint8_t SDA = 23; static const uint8_t SCL = 22; -static const uint8_t SS = 18; -static const uint8_t MOSI = 19; -static const uint8_t MISO = 20; -static const uint8_t SCK = 21; +static const uint8_t SS = 18; +static const uint8_t MOSI = 19; +static const uint8_t MISO = 20; +static const uint8_t SCK = 21; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/ttgo-lora32-v1/pins_arduino.h b/variants/ttgo-lora32-v1/pins_arduino.h index b637cc51799..594eada3c51 100644 --- a/variants/ttgo-lora32-v1/pins_arduino.h +++ b/variants/ttgo-lora32-v1/pins_arduino.h @@ -1,70 +1,70 @@ -#ifndef Pins_Arduino_h -#define Pins_Arduino_h - -#include - -// I2C OLED Display works with SSD1306 driver -#define OLED_SDA 4 -#define OLED_SCL 15 -#define OLED_RST 16 - -// SPI LoRa Radio -#define LORA_SCK 5 // GPIO5 - SX1276 SCK -#define LORA_MISO 19 // GPIO19 - SX1276 MISO -#define LORA_MOSI 27 // GPIO27 - SX1276 MOSI -#define LORA_CS 18 // GPIO18 - SX1276 CS -#define LORA_RST 14 // GPIO14 - SX1276 RST -#define LORA_IRQ 26 // GPIO26 - SX1276 IRQ (interrupt request) - -static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN - -static const uint8_t KEY_BUILTIN = 0; - -static const uint8_t TX = 1; -static const uint8_t RX = 3; - -static const uint8_t SDA = 21; -static const uint8_t SCL = 22; - -static const uint8_t SS = 18; -static const uint8_t MOSI = 27; -static const uint8_t MISO = 19; -static const uint8_t SCK = 5; - -static const uint8_t A0 = 36; -static const uint8_t A1 = 37; -static const uint8_t A2 = 38; -static const uint8_t A3 = 39; -static const uint8_t A4 = 32; -static const uint8_t A5 = 33; -static const uint8_t A6 = 34; -static const uint8_t A7 = 35; - -static const uint8_t A10 = 4; -static const uint8_t A11 = 0; -static const uint8_t A12 = 2; -static const uint8_t A13 = 15; -static const uint8_t A14 = 13; -static const uint8_t A15 = 12; -static const uint8_t A16 = 14; -static const uint8_t A17 = 27; -static const uint8_t A18 = 25; -static const uint8_t A19 = 26; - -static const uint8_t T0 = 4; -static const uint8_t T1 = 0; -static const uint8_t T2 = 2; -static const uint8_t T3 = 15; -static const uint8_t T4 = 13; -static const uint8_t T5 = 12; -static const uint8_t T6 = 14; -static const uint8_t T7 = 27; -static const uint8_t T8 = 33; -static const uint8_t T9 = 32; - -static const uint8_t DAC1 = 25; -static const uint8_t DAC2 = 26; - -#endif /* Pins_Arduino_h */ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +// I2C OLED Display works with SSD1306 driver +#define OLED_SDA 4 +#define OLED_SCL 15 +#define OLED_RST 16 + +// SPI LoRa Radio +#define LORA_SCK 5 // GPIO5 - SX1276 SCK +#define LORA_MISO 19 // GPIO19 - SX1276 MISO +#define LORA_MOSI 27 // GPIO27 - SX1276 MOSI +#define LORA_CS 18 // GPIO18 - SX1276 CS +#define LORA_RST 14 // GPIO14 - SX1276 RST +#define LORA_IRQ 26 // GPIO26 - SX1276 IRQ (interrupt request) + +static const uint8_t LED_BUILTIN = 2; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN + +static const uint8_t KEY_BUILTIN = 0; + +static const uint8_t TX = 1; +static const uint8_t RX = 3; + +static const uint8_t SDA = 21; +static const uint8_t SCL = 22; + +static const uint8_t SS = 18; +static const uint8_t MOSI = 27; +static const uint8_t MISO = 19; +static const uint8_t SCK = 5; + +static const uint8_t A0 = 36; +static const uint8_t A1 = 37; +static const uint8_t A2 = 38; +static const uint8_t A3 = 39; +static const uint8_t A4 = 32; +static const uint8_t A5 = 33; +static const uint8_t A6 = 34; +static const uint8_t A7 = 35; + +static const uint8_t A10 = 4; +static const uint8_t A11 = 0; +static const uint8_t A12 = 2; +static const uint8_t A13 = 15; +static const uint8_t A14 = 13; +static const uint8_t A15 = 12; +static const uint8_t A16 = 14; +static const uint8_t A17 = 27; +static const uint8_t A18 = 25; +static const uint8_t A19 = 26; + +static const uint8_t T0 = 4; +static const uint8_t T1 = 0; +static const uint8_t T2 = 2; +static const uint8_t T3 = 15; +static const uint8_t T4 = 13; +static const uint8_t T5 = 12; +static const uint8_t T6 = 14; +static const uint8_t T7 = 27; +static const uint8_t T8 = 33; +static const uint8_t T9 = 32; + +static const uint8_t DAC1 = 25; +static const uint8_t DAC2 = 26; + +#endif /* Pins_Arduino_h */ diff --git a/variants/ttgo-lora32-v2/pins_arduino.h b/variants/ttgo-lora32-v2/pins_arduino.h index 3d5a0b36f3c..2c4ac6fd995 100644 --- a/variants/ttgo-lora32-v2/pins_arduino.h +++ b/variants/ttgo-lora32-v2/pins_arduino.h @@ -4,70 +4,70 @@ #include // I2C OLED Display works with SSD1306 driver -#define OLED_SDA 21 -#define OLED_SCL 22 -#define OLED_RST 16 +#define OLED_SDA 21 +#define OLED_SCL 22 +#define OLED_RST 16 // SPI LoRa Radio -#define LORA_SCK 5 // GPIO5 - SX1276 SCK -#define LORA_MISO 19 // GPIO19 - SX1276 MISO -#define LORA_MOSI 27 // GPIO27 - SX1276 MOSI -#define LORA_CS 18 // GPIO18 - SX1276 CS -#define LORA_RST 12 // GPIO14 - SX1276 RST -#define LORA_IRQ 26 // GPIO26 - SX1276 IRQ (interrupt request) +#define LORA_SCK 5 // GPIO5 - SX1276 SCK +#define LORA_MISO 19 // GPIO19 - SX1276 MISO +#define LORA_MOSI 27 // GPIO27 - SX1276 MOSI +#define LORA_CS 18 // GPIO18 - SX1276 CS +#define LORA_RST 12 // GPIO14 - SX1276 RST +#define LORA_IRQ 26 // GPIO26 - SX1276 IRQ (interrupt request) // SD card -#define SD_SCK 14 +#define SD_SCK 14 #define SD_MISO 2 #define SD_MOSI 15 -#define SD_CS 13 +#define SD_CS 13 -static const uint8_t LED_BUILTIN = 22; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +static const uint8_t LED_BUILTIN = 22; +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -static const uint8_t KEY_BUILTIN = 0; +static const uint8_t KEY_BUILTIN = 0; -static const uint8_t TX = 1; -static const uint8_t RX = 3; +static const uint8_t TX = 1; +static const uint8_t RX = 3; -static const uint8_t SDA = 21; -static const uint8_t SCL = 22; +static const uint8_t SDA = 21; +static const uint8_t SCL = 22; -static const uint8_t SS = 18; +static const uint8_t SS = 18; static const uint8_t MOSI = 27; static const uint8_t MISO = 19; -static const uint8_t SCK = 5; +static const uint8_t SCK = 5; -static const uint8_t A0 = 36; -static const uint8_t A1 = 37; -static const uint8_t A2 = 38; -static const uint8_t A3 = 39; -static const uint8_t A4 = 32; -static const uint8_t A5 = 33; -static const uint8_t A6 = 34; -static const uint8_t A7 = 35; -static const uint8_t A10 = 4; -static const uint8_t A11 = 0; -static const uint8_t A12 = 2; -static const uint8_t A13 = 15; -static const uint8_t A14 = 13; -static const uint8_t A15 = 12; -static const uint8_t A16 = 14; -static const uint8_t A17 = 27; -static const uint8_t A18 = 25; -static const uint8_t A19 = 26; +static const uint8_t A0 = 36; +static const uint8_t A1 = 37; +static const uint8_t A2 = 38; +static const uint8_t A3 = 39; +static const uint8_t A4 = 32; +static const uint8_t A5 = 33; +static const uint8_t A6 = 34; +static const uint8_t A7 = 35; +static const uint8_t A10 = 4; +static const uint8_t A11 = 0; +static const uint8_t A12 = 2; +static const uint8_t A13 = 15; +static const uint8_t A14 = 13; +static const uint8_t A15 = 12; +static const uint8_t A16 = 14; +static const uint8_t A17 = 27; +static const uint8_t A18 = 25; +static const uint8_t A19 = 26; -static const uint8_t T0 = 4; -static const uint8_t T1 = 0; -static const uint8_t T2 = 2; -static const uint8_t T3 = 15; -static const uint8_t T4 = 13; -static const uint8_t T5 = 12; -static const uint8_t T6 = 14; -static const uint8_t T7 = 27; -static const uint8_t T8 = 33; -static const uint8_t T9 = 32; +static const uint8_t T0 = 4; +static const uint8_t T1 = 0; +static const uint8_t T2 = 2; +static const uint8_t T3 = 15; +static const uint8_t T4 = 13; +static const uint8_t T5 = 12; +static const uint8_t T6 = 14; +static const uint8_t T7 = 27; +static const uint8_t T8 = 33; +static const uint8_t T9 = 32; static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; diff --git a/variants/ttgo-lora32-v21new/pins_arduino.h b/variants/ttgo-lora32-v21new/pins_arduino.h index a333d80917d..52dbd002cb7 100644 --- a/variants/ttgo-lora32-v21new/pins_arduino.h +++ b/variants/ttgo-lora32-v21new/pins_arduino.h @@ -10,72 +10,72 @@ #include // I2C OLED Display works with SSD1306 driver -#define OLED_SDA 21 -#define OLED_SCL 22 -#define OLED_RST 16 +#define OLED_SDA 21 +#define OLED_SCL 22 +#define OLED_RST 16 // SPI LoRa Radio -#define LORA_SCK 5 // GPIO5 - SX1276 SCK -#define LORA_MISO 19 // GPIO19 - SX1276 MISO -#define LORA_MOSI 27 // GPIO27 - SX1276 MOSI -#define LORA_CS 18 // GPIO18 - SX1276 CS -#define LORA_RST 23 // GPIO23 - SX1276 RST -#define LORA_IRQ 26 // GPIO26 - SX1276 IRQ (interrupt request) -#define LORA_D1 33 // GPIO33 - SX1276 IO1 (for LMIC Arduino library) -#define LORA_D2 32 // GPIO32 - SX1276 IO2 +#define LORA_SCK 5 // GPIO5 - SX1276 SCK +#define LORA_MISO 19 // GPIO19 - SX1276 MISO +#define LORA_MOSI 27 // GPIO27 - SX1276 MOSI +#define LORA_CS 18 // GPIO18 - SX1276 CS +#define LORA_RST 23 // GPIO23 - SX1276 RST +#define LORA_IRQ 26 // GPIO26 - SX1276 IRQ (interrupt request) +#define LORA_D1 33 // GPIO33 - SX1276 IO1 (for LMIC Arduino library) +#define LORA_D2 32 // GPIO32 - SX1276 IO2 // SD card -#define SD_SCK 14 +#define SD_SCK 14 #define SD_MISO 2 #define SD_MOSI 15 -#define SD_CS 13 +#define SD_CS 13 static const uint8_t LED_BUILTIN = 25; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -static const uint8_t KEY_BUILTIN = 0; +static const uint8_t KEY_BUILTIN = 0; -static const uint8_t TX = 1; -static const uint8_t RX = 3; +static const uint8_t TX = 1; +static const uint8_t RX = 3; -static const uint8_t SDA = 21; -static const uint8_t SCL = 22; +static const uint8_t SDA = 21; +static const uint8_t SCL = 22; -static const uint8_t SS = 18; +static const uint8_t SS = 18; static const uint8_t MOSI = 27; static const uint8_t MISO = 19; -static const uint8_t SCK = 5; +static const uint8_t SCK = 5; -static const uint8_t A0 = 36; -static const uint8_t A1 = 37; -static const uint8_t A2 = 38; -static const uint8_t A3 = 39; -static const uint8_t A4 = 32; -static const uint8_t A5 = 33; -static const uint8_t A6 = 34; -static const uint8_t A7 = 35; -static const uint8_t A10 = 4; -static const uint8_t A11 = 0; -static const uint8_t A12 = 2; -static const uint8_t A13 = 15; -static const uint8_t A14 = 13; -static const uint8_t A15 = 12; -static const uint8_t A16 = 14; -static const uint8_t A17 = 27; -static const uint8_t A18 = 25; -static const uint8_t A19 = 26; +static const uint8_t A0 = 36; +static const uint8_t A1 = 37; +static const uint8_t A2 = 38; +static const uint8_t A3 = 39; +static const uint8_t A4 = 32; +static const uint8_t A5 = 33; +static const uint8_t A6 = 34; +static const uint8_t A7 = 35; +static const uint8_t A10 = 4; +static const uint8_t A11 = 0; +static const uint8_t A12 = 2; +static const uint8_t A13 = 15; +static const uint8_t A14 = 13; +static const uint8_t A15 = 12; +static const uint8_t A16 = 14; +static const uint8_t A17 = 27; +static const uint8_t A18 = 25; +static const uint8_t A19 = 26; -static const uint8_t T0 = 4; -static const uint8_t T1 = 0; -static const uint8_t T2 = 2; -static const uint8_t T3 = 15; -static const uint8_t T4 = 13; -static const uint8_t T5 = 12; -static const uint8_t T6 = 14; -static const uint8_t T7 = 27; -static const uint8_t T8 = 33; -static const uint8_t T9 = 32; +static const uint8_t T0 = 4; +static const uint8_t T1 = 0; +static const uint8_t T2 = 2; +static const uint8_t T3 = 15; +static const uint8_t T4 = 13; +static const uint8_t T5 = 12; +static const uint8_t T6 = 14; +static const uint8_t T7 = 27; +static const uint8_t T8 = 33; +static const uint8_t T9 = 32; static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; diff --git a/variants/ttgo-t-oi-plus/pins_arduino.h b/variants/ttgo-t-oi-plus/pins_arduino.h index 782b5fb4342..5738ce0277d 100644 --- a/variants/ttgo-t-oi-plus/pins_arduino.h +++ b/variants/ttgo-t-oi-plus/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 3; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 21; diff --git a/variants/ttgo-t1/pins_arduino.h b/variants/ttgo-t1/pins_arduino.h index e6024f0ac5b..b8da3464e81 100644 --- a/variants/ttgo-t1/pins_arduino.h +++ b/variants/ttgo-t1/pins_arduino.h @@ -7,7 +7,7 @@ static const uint8_t TX = 1; static const uint8_t RX = 3; static const uint8_t LED_BUILTIN = 22; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t SDA = 21; @@ -16,10 +16,10 @@ static const uint8_t SDA = 21; static const uint8_t SCL = 23; // These are the settings used for the on-board SD card slot -static const uint8_t SS = 13; -static const uint8_t MOSI = 15; -static const uint8_t MISO = 2; -static const uint8_t SCK = 14; +static const uint8_t SS = 13; +static const uint8_t MOSI = 15; +static const uint8_t MISO = 2; +static const uint8_t SCK = 14; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/ttgo-t7-v13-mini32/pins_arduino.h b/variants/ttgo-t7-v13-mini32/pins_arduino.h old mode 100755 new mode 100644 index eecb5dc5817..23a98d70d5e --- a/variants/ttgo-t7-v13-mini32/pins_arduino.h +++ b/variants/ttgo-t7-v13-mini32/pins_arduino.h @@ -7,16 +7,16 @@ static const uint8_t TX = 1; static const uint8_t RX = 3; static const uint8_t LED_BUILTIN = 22; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/ttgo-t7-v14-mini32/pins_arduino.h b/variants/ttgo-t7-v14-mini32/pins_arduino.h old mode 100755 new mode 100644 index 496141a7364..f3ebba9f354 --- a/variants/ttgo-t7-v14-mini32/pins_arduino.h +++ b/variants/ttgo-t7-v14-mini32/pins_arduino.h @@ -7,16 +7,16 @@ static const uint8_t TX = 1; static const uint8_t RX = 3; static const uint8_t LED_BUILTIN = 19; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/turta_iot_node/pins_arduino.h b/variants/turta_iot_node/pins_arduino.h index 64ebeb17172..e5fbc40b04c 100644 --- a/variants/turta_iot_node/pins_arduino.h +++ b/variants/turta_iot_node/pins_arduino.h @@ -5,7 +5,7 @@ // LED static const uint8_t LED_BUILTIN = 13; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // UART @@ -17,13 +17,13 @@ static const uint8_t SDA = 23; static const uint8_t SCL = 22; // SPI -static const uint8_t SS = 21; -static const uint8_t MOSI = 18; -static const uint8_t MISO = 19; -static const uint8_t SCK = 5; +static const uint8_t SS = 21; +static const uint8_t MOSI = 18; +static const uint8_t MISO = 19; +static const uint8_t SCK = 5; // Analog Inputs -static const uint8_t A0 = 4; +static const uint8_t A0 = 4; static const uint8_t A1 = 25; static const uint8_t A2 = 26; static const uint8_t A3 = 27; diff --git a/variants/twatch/pins_arduino.h b/variants/twatch/pins_arduino.h index e10a0d6a8e1..9455ec6996e 100644 --- a/variants/twatch/pins_arduino.h +++ b/variants/twatch/pins_arduino.h @@ -4,30 +4,30 @@ #include // touch screen -#define TP_SDA 23 -#define TP_SCL 32 -#define TP_INT 38 +#define TP_SDA 23 +#define TP_SCL 32 +#define TP_INT 38 // Interrupt IO port -#define RTC_INT 37 -#define APX20X_INT 35 -#define BMA42X_INT1 39 +#define RTC_INT 37 +#define APX20X_INT 35 +#define BMA42X_INT1 39 static const uint8_t TX = 1; static const uint8_t RX = 3; //Serial1 Already assigned to GPS LORA -#define TX1 33 -#define RX1 34 +#define TX1 33 +#define RX1 34 // Already assigned to BMA423 PCF8563 and external extensions static const uint8_t SDA = 21; static const uint8_t SCL = 22; // SPI has been configured as an SD card slot and must be removed when downloading -static const uint8_t SS = 13; -static const uint8_t MOSI = 15; -static const uint8_t MISO = 2; -static const uint8_t SCK = 14; +static const uint8_t SS = 13; +static const uint8_t MOSI = 15; +static const uint8_t MISO = 2; +static const uint8_t SCK = 14; // Externally programmable IO static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; diff --git a/variants/uPesy_edu_esp32/pins_arduino.h b/variants/uPesy_edu_esp32/pins_arduino.h index 64fea337a89..80e481c1891 100644 --- a/variants/uPesy_edu_esp32/pins_arduino.h +++ b/variants/uPesy_edu_esp32/pins_arduino.h @@ -10,10 +10,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 33; static const uint8_t A1 = 32; @@ -23,32 +23,32 @@ static const uint8_t A4 = 36; static const uint8_t A5 = 39; static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN -#define PIN_WIRE_SDA SDA // backward compatibility -#define PIN_WIRE_SCL SCL // backward compatibility - -static const uint8_t D0 = 3; -static const uint8_t D1 = 1; -static const uint8_t D2 = 26; -static const uint8_t D3 = 25; -static const uint8_t D4 = 17; -static const uint8_t D5 = 16; -static const uint8_t D6 = 27; -static const uint8_t D7 = 14; -static const uint8_t D8 = 12; -static const uint8_t D9 = 13; -static const uint8_t D10 = 5; -static const uint8_t D11 = 23; -static const uint8_t D12 = 19; -static const uint8_t D13 = 18; - -#define PIN_SPI_SS SS // backward compatibility -#define PIN_SPI_MOSI MOSI // backward compatibility -#define PIN_SPI_MISO MISO // backward compatibility -#define PIN_SPI_SCK SCK // backward compatibility - -#define PIN_A0 A0 // backward compatibility +#define PIN_WIRE_SDA SDA // backward compatibility +#define PIN_WIRE_SCL SCL // backward compatibility + +static const uint8_t D0 = 3; +static const uint8_t D1 = 1; +static const uint8_t D2 = 26; +static const uint8_t D3 = 25; +static const uint8_t D4 = 17; +static const uint8_t D5 = 16; +static const uint8_t D6 = 27; +static const uint8_t D7 = 14; +static const uint8_t D8 = 12; +static const uint8_t D9 = 13; +static const uint8_t D10 = 5; +static const uint8_t D11 = 23; +static const uint8_t D12 = 19; +static const uint8_t D13 = 18; + +#define PIN_SPI_SS SS // backward compatibility +#define PIN_SPI_MOSI MOSI // backward compatibility +#define PIN_SPI_MISO MISO // backward compatibility +#define PIN_SPI_SCK SCK // backward compatibility + +#define PIN_A0 A0 // backward compatibility #endif /* Pins_Arduino_h */ diff --git a/variants/uPesy_esp32_wroom_devkit/pins_arduino.h b/variants/uPesy_esp32_wroom_devkit/pins_arduino.h index 467c58c0034..8e1d00416d1 100644 --- a/variants/uPesy_esp32_wroom_devkit/pins_arduino.h +++ b/variants/uPesy_esp32_wroom_devkit/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -13,10 +13,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/uPesy_esp32_wrover_devkit/pins_arduino.h b/variants/uPesy_esp32_wrover_devkit/pins_arduino.h index 467c58c0034..8e1d00416d1 100644 --- a/variants/uPesy_esp32_wrover_devkit/pins_arduino.h +++ b/variants/uPesy_esp32_wrover_devkit/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -13,10 +13,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/uPesy_esp32c3_basic/pins_arduino.h b/variants/uPesy_esp32c3_basic/pins_arduino.h index 62c27c4c051..10900d99f65 100644 --- a/variants/uPesy_esp32c3_basic/pins_arduino.h +++ b/variants/uPesy_esp32c3_basic/pins_arduino.h @@ -15,10 +15,10 @@ static const uint8_t RX = 20; static const uint8_t SDA = 3; static const uint8_t SCL = 10; -static const uint8_t SS = 7; -static const uint8_t MOSI = 6; -static const uint8_t MISO = 5; -static const uint8_t SCK = 4; +static const uint8_t SS = 7; +static const uint8_t MOSI = 6; +static const uint8_t MISO = 5; +static const uint8_t SCK = 4; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/uPesy_esp32c3_mini/pins_arduino.h b/variants/uPesy_esp32c3_mini/pins_arduino.h index 041078e74af..772291206ee 100644 --- a/variants/uPesy_esp32c3_mini/pins_arduino.h +++ b/variants/uPesy_esp32c3_mini/pins_arduino.h @@ -15,10 +15,10 @@ static const uint8_t RX = 20; static const uint8_t SDA = 3; static const uint8_t SCL = 10; -static const uint8_t SS = 7; -static const uint8_t MOSI = 6; -static const uint8_t MISO = 5; -static const uint8_t SCK = 4; +static const uint8_t SS = 7; +static const uint8_t MOSI = 6; +static const uint8_t MISO = 5; +static const uint8_t SCK = 4; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/uPesy_esp32s3_basic/pins_arduino.h b/variants/uPesy_esp32s3_basic/pins_arduino.h index 76eded265bd..2e08b3f3be1 100644 --- a/variants/uPesy_esp32s3_basic/pins_arduino.h +++ b/variants/uPesy_esp32s3_basic/pins_arduino.h @@ -13,11 +13,11 @@ static const uint8_t RGB_DATA = 38; // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() -#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 43; @@ -31,10 +31,10 @@ static const uint8_t RX1 = 18; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 10; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 13; -static const uint8_t SCK = 12; +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -72,10 +72,10 @@ static const uint8_t T12 = 12; static const uint8_t T13 = 13; static const uint8_t T14 = 14; -static const uint8_t MTMS = 42; -static const uint8_t MTDI = 41; -static const uint8_t MTDO = 40; -static const uint8_t MTCK = 39; +static const uint8_t MTMS = 42; +static const uint8_t MTDI = 41; +static const uint8_t MTDO = 40; +static const uint8_t MTCK = 39; diff --git a/variants/um_bling/pins_arduino.h b/variants/um_bling/pins_arduino.h index 81c5294a71f..b8819c56fcd 100644 --- a/variants/um_bling/pins_arduino.h +++ b/variants/um_bling/pins_arduino.h @@ -23,7 +23,7 @@ static const uint8_t SDO = 35; static const uint8_t SDI = 37; static const uint8_t SCK = 36; -static const uint8_t SD_CS= 21; +static const uint8_t SD_CS = 21; static const uint8_t SD_DETECT = 38; static const uint8_t A0 = 1; @@ -68,11 +68,11 @@ static const uint8_t RTC_INT = 7; static const uint8_t RGB_DATA = 18; // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() -#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino static const uint8_t LED_BUILTIN = RGB_BUILTIN; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t RGB_PWR = 6; diff --git a/variants/um_feathers2/pins_arduino.h b/variants/um_feathers2/pins_arduino.h index edcde26ac71..1c513431d07 100644 --- a/variants/um_feathers2/pins_arduino.h +++ b/variants/um_feathers2/pins_arduino.h @@ -15,12 +15,12 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 34; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SDO = 35; -static const uint8_t SDI = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SDO = 35; +static const uint8_t SDI = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/um_feathers2neo/pins_arduino.h b/variants/um_feathers2neo/pins_arduino.h index d66d565d280..3329056b294 100644 --- a/variants/um_feathers2neo/pins_arduino.h +++ b/variants/um_feathers2neo/pins_arduino.h @@ -16,12 +16,12 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 34; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SDO = 35; -static const uint8_t SDI = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SDO = 35; +static const uint8_t SDI = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 17; static const uint8_t A1 = 18; @@ -56,11 +56,11 @@ static const uint8_t NEOPIXEL_MATRIX_PWR = 4; static const uint8_t NEOPIXEL_DATA = 40; // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() -#define RGB_BUILTIN (NEOPIXEL_DATA + SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (NEOPIXEL_DATA + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino static const uint8_t LED_BUILTIN = RGB_BUILTIN; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t NEOPIXEL_PWR = 39; diff --git a/variants/um_feathers3/pins_arduino.h b/variants/um_feathers3/pins_arduino.h index 804a60d28e4..5d2c5128899 100644 --- a/variants/um_feathers3/pins_arduino.h +++ b/variants/um_feathers3/pins_arduino.h @@ -16,12 +16,12 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 5; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SDO = 35; -static const uint8_t SDI = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 5; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SDO = 35; +static const uint8_t SDI = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -52,13 +52,13 @@ static const uint8_t T14 = 14; static const uint8_t VBAT_SENSE = 2; static const uint8_t VBUS_SENSE = 34; -// User LED +// User LED #define LED_BUILTIN 13 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility static const uint8_t RGB_DATA = 40; // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() -#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 static const uint8_t RGB_PWR = 39; diff --git a/variants/um_nanos3/pins_arduino.h b/variants/um_nanos3/pins_arduino.h index 84d5b5a6219..15e5dfb0146 100644 --- a/variants/um_nanos3/pins_arduino.h +++ b/variants/um_nanos3/pins_arduino.h @@ -16,12 +16,12 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 34; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SDO = 35; -static const uint8_t SDI = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SDO = 35; +static const uint8_t SDI = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -45,11 +45,11 @@ static const uint8_t T9 = 9; static const uint8_t RGB_DATA = 41; // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() -#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino static const uint8_t LED_BUILTIN = RGB_BUILTIN; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t RGB_PWR = 42; diff --git a/variants/um_pros3/pins_arduino.h b/variants/um_pros3/pins_arduino.h index 9a8e8120151..deb96727fbd 100644 --- a/variants/um_pros3/pins_arduino.h +++ b/variants/um_pros3/pins_arduino.h @@ -16,12 +16,12 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 34; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SDO = 35; -static const uint8_t SDI = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SDO = 35; +static const uint8_t SDI = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -56,11 +56,11 @@ static const uint8_t VBUS_SENSE = 33; static const uint8_t RGB_DATA = 18; // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() -#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino static const uint8_t LED_BUILTIN = RGB_BUILTIN; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t RGB_PWR = 17; diff --git a/variants/um_rmp/pins_arduino.h b/variants/um_rmp/pins_arduino.h index 5d3b7acc283..c0ac4540053 100644 --- a/variants/um_rmp/pins_arduino.h +++ b/variants/um_rmp/pins_arduino.h @@ -16,12 +16,12 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 14; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SDO = 35; -static const uint8_t SDI = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 14; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SDO = 35; +static const uint8_t SDI = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -67,11 +67,11 @@ static const uint8_t VBUS_SENSE = 21; static const uint8_t RGB_DATA = 1; // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() -#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino static const uint8_t LED_BUILTIN = RGB_BUILTIN; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t RGB_PWR = 2; diff --git a/variants/um_tinyc6/pins_arduino.h b/variants/um_tinyc6/pins_arduino.h index 54fb497cd46..9571a93869e 100644 --- a/variants/um_tinyc6/pins_arduino.h +++ b/variants/um_tinyc6/pins_arduino.h @@ -16,12 +16,12 @@ static const uint8_t RX = 17; static const uint8_t SDA = 6; static const uint8_t SCL = 7; -static const uint8_t SS = 18; -static const uint8_t MOSI = 21; -static const uint8_t MISO = 20; -static const uint8_t SDO = 21; -static const uint8_t SDI = 20; -static const uint8_t SCK = 19; +static const uint8_t SS = 18; +static const uint8_t MOSI = 21; +static const uint8_t MISO = 20; +static const uint8_t SDO = 21; +static const uint8_t SDI = 20; +static const uint8_t SCK = 19; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -48,11 +48,11 @@ static const uint8_t VBUS_SENSE = 10; static const uint8_t RGB_DATA = 23; // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() -#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino static const uint8_t LED_BUILTIN = RGB_BUILTIN; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t RGB_PWR = 22; diff --git a/variants/um_tinypico/pins_arduino.h b/variants/um_tinypico/pins_arduino.h index b10b9274178..ce7f6dd2767 100644 --- a/variants/um_tinypico/pins_arduino.h +++ b/variants/um_tinypico/pins_arduino.h @@ -9,12 +9,12 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SDO = 23; -static const uint8_t SDI = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SDO = 23; +static const uint8_t SDI = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; diff --git a/variants/um_tinys2/pins_arduino.h b/variants/um_tinys2/pins_arduino.h index b3431781d99..a52a376bf1c 100644 --- a/variants/um_tinys2/pins_arduino.h +++ b/variants/um_tinys2/pins_arduino.h @@ -16,12 +16,12 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 14; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SDO = 35; -static const uint8_t SDI = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 14; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SDO = 35; +static const uint8_t SDI = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -67,11 +67,11 @@ static const uint8_t VBUS_SENSE = 21; static const uint8_t RGB_DATA = 1; // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() -#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino static const uint8_t LED_BUILTIN = RGB_BUILTIN; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t RGB_PWR = 2; diff --git a/variants/um_tinys3/pins_arduino.h b/variants/um_tinys3/pins_arduino.h index 251b1f8dd7d..5246c2ed173 100644 --- a/variants/um_tinys3/pins_arduino.h +++ b/variants/um_tinys3/pins_arduino.h @@ -16,12 +16,12 @@ static const uint8_t RX = 44; static const uint8_t SDA = 8; static const uint8_t SCL = 9; -static const uint8_t SS = 34; -static const uint8_t MOSI = 35; -static const uint8_t MISO = 37; -static const uint8_t SDO = 35; -static const uint8_t SDI = 37; -static const uint8_t SCK = 36; +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SDO = 35; +static const uint8_t SDI = 37; +static const uint8_t SCK = 36; static const uint8_t A0 = 1; static const uint8_t A1 = 2; @@ -48,11 +48,11 @@ static const uint8_t VBUS_SENSE = 33; static const uint8_t RGB_DATA = 18; // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() -#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) +#define RGB_BUILTIN (RGB_DATA + SOC_GPIO_PIN_COUNT) #define RGB_BRIGHTNESS 64 // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino static const uint8_t LED_BUILTIN = RGB_BUILTIN; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t RGB_PWR = 17; diff --git a/variants/unphone8/pins_arduino.h b/variants/unphone8/pins_arduino.h index 66e30bdd564..0fcd7d1e5a7 100644 --- a/variants/unphone8/pins_arduino.h +++ b/variants/unphone8/pins_arduino.h @@ -3,11 +3,11 @@ #include -#define USB_VID 0x16D0 -#define USB_PID 0x1178 +#define USB_VID 0x16D0 +#define USB_PID 0x1178 -#define LED_BUILTIN 13 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN 13 +#define BUILTIN_LED LED_BUILTIN // backward compatibility static const uint8_t TX = 37; static const uint8_t RX = 36; @@ -15,10 +15,10 @@ static const uint8_t RX = 36; static const uint8_t SDA = 1; static const uint8_t SCL = 2; -static const uint8_t SS = 3; -static const uint8_t MOSI = 39; -static const uint8_t MISO = 40; -static const uint8_t SCK = 38; +static const uint8_t SS = 3; +static const uint8_t MOSI = 39; +static const uint8_t MISO = 40; +static const uint8_t SCK = 38; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/unphone9/pins_arduino.h b/variants/unphone9/pins_arduino.h index e20cd337b7f..1edec9650e2 100644 --- a/variants/unphone9/pins_arduino.h +++ b/variants/unphone9/pins_arduino.h @@ -3,11 +3,11 @@ #include -#define USB_VID 0x16D0 -#define USB_PID 0x1178 +#define USB_VID 0x16D0 +#define USB_PID 0x1178 -#define LED_BUILTIN 13 -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN 13 +#define BUILTIN_LED LED_BUILTIN // backward compatibility static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -15,10 +15,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 3; static const uint8_t SCL = 4; -static const uint8_t SS = 13; -static const uint8_t MOSI = 40; -static const uint8_t MISO = 41; -static const uint8_t SCK = 39; +static const uint8_t SS = 13; +static const uint8_t MOSI = 40; +static const uint8_t MISO = 41; +static const uint8_t SCK = 39; static const uint8_t A0 = 1; static const uint8_t A1 = 2; diff --git a/variants/vintlabsdevkitv1/pins_arduino.h b/variants/vintlabsdevkitv1/pins_arduino.h index d0559b9f01b..ddffe2d072e 100644 --- a/variants/vintlabsdevkitv1/pins_arduino.h +++ b/variants/vintlabsdevkitv1/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -13,10 +13,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; @@ -49,7 +49,7 @@ static const uint8_t T9 = 32; static const uint8_t DAC1 = 25; static const uint8_t DAC2 = 26; -// PWM Driver pins for PWM Driver board +// PWM Driver pins for PWM Driver board static const uint8_t PWM0 = 12; static const uint8_t PWM1 = 13; static const uint8_t PWM2 = 14; diff --git a/variants/watchy/pins_arduino.h b/variants/watchy/pins_arduino.h index b5bc02f374c..326a0bc7e52 100644 --- a/variants/watchy/pins_arduino.h +++ b/variants/watchy/pins_arduino.h @@ -9,44 +9,44 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; - -static const uint8_t MENU_BTN_PIN = 26; -static const uint8_t BACK_BTN_PIN = 25; -static const uint8_t DOWN_BTN_PIN = 4; -static const uint8_t DISPLAY_CS = 5; -static const uint8_t DISPLAY_RES = 9; -static const uint8_t DISPLAY_DC = 10; -static const uint8_t DISPLAY_BUSY = 19; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; + +static const uint8_t MENU_BTN_PIN = 26; +static const uint8_t BACK_BTN_PIN = 25; +static const uint8_t DOWN_BTN_PIN = 4; +static const uint8_t DISPLAY_CS = 5; +static const uint8_t DISPLAY_RES = 9; +static const uint8_t DISPLAY_DC = 10; +static const uint8_t DISPLAY_BUSY = 19; static const uint8_t ACC_INT_1_PIN = 14; static const uint8_t ACC_INT_2_PIN = 12; static const uint8_t VIB_MOTOR_PIN = 13; -static const uint8_t RTC_INT_PIN = 27; - -#if defined (ARDUINO_WATCHY_V10) - static const uint8_t UP_BTN_PIN = 32; - static const uint8_t BATT_ADC_PIN = 33; - #define UP_BTN_MASK GPIO_SEL_32 - #define RTC_TYPE 1 //DS3231 -#elif defined (ARDUINO_WATCHY_V15) - static const uint8_t UP_BTN_PIN = 32; - static const uint8_t BATT_ADC_PIN = 35; - #define UP_BTN_MASK GPIO_SEL_32 - #define RTC_TYPE 2 //PCF8563 -#elif defined (ARDUINO_WATCHY_V20) - static const uint8_t UP_BTN_PIN = 35; - static const uint8_t BATT_ADC_PIN = 34; - #define UP_BTN_MASK GPIO_SEL_35 - #define RTC_TYPE 2 //PCF8563 +static const uint8_t RTC_INT_PIN = 27; + +#if defined(ARDUINO_WATCHY_V10) +static const uint8_t UP_BTN_PIN = 32; +static const uint8_t BATT_ADC_PIN = 33; +#define UP_BTN_MASK GPIO_SEL_32 +#define RTC_TYPE 1 //DS3231 +#elif defined(ARDUINO_WATCHY_V15) +static const uint8_t UP_BTN_PIN = 32; +static const uint8_t BATT_ADC_PIN = 35; +#define UP_BTN_MASK GPIO_SEL_32 +#define RTC_TYPE 2 //PCF8563 +#elif defined(ARDUINO_WATCHY_V20) +static const uint8_t UP_BTN_PIN = 35; +static const uint8_t BATT_ADC_PIN = 34; +#define UP_BTN_MASK GPIO_SEL_35 +#define RTC_TYPE 2 //PCF8563 #endif #define MENU_BTN_MASK GPIO_SEL_26 #define BACK_BTN_MASK GPIO_SEL_25 #define DOWN_BTN_MASK GPIO_SEL_4 -#define ACC_INT_MASK GPIO_SEL_14 -#define BTN_PIN_MASK MENU_BTN_MASK|BACK_BTN_MASK|UP_BTN_MASK|DOWN_BTN_MASK +#define ACC_INT_MASK GPIO_SEL_14 +#define BTN_PIN_MASK MENU_BTN_MASK | BACK_BTN_MASK | UP_BTN_MASK | DOWN_BTN_MASK #endif /* Pins_Arduino_h */ diff --git a/variants/waveshare_esp32s3_touch_lcd_128/pins_arduino.h b/variants/waveshare_esp32s3_touch_lcd_128/pins_arduino.h index c60d3f244b3..404a8c2e83c 100644 --- a/variants/waveshare_esp32s3_touch_lcd_128/pins_arduino.h +++ b/variants/waveshare_esp32s3_touch_lcd_128/pins_arduino.h @@ -3,15 +3,15 @@ #include -#define USB_VID 0x1A86 -#define USB_PID 0x55D3 -#define USB_MANUFACTURER "Waveshare" -#define USB_PRODUCT "ESP32-S3 Touch LCD 1.28" -#define USB_SERIAL "" // Empty string for MAC adddress +#define USB_VID 0x1A86 +#define USB_PID 0x55D3 +#define USB_MANUFACTURER "Waveshare" +#define USB_PRODUCT "ESP32-S3 Touch LCD 1.28" +#define USB_SERIAL "" // Empty string for MAC address -#define LCD_BACKLIGHT 2 -#define LCD_DC 8 -#define LCD_RST 14 +#define LCD_BACKLIGHT 2 +#define LCD_DC 8 +#define LCD_RST 14 #define TP_INT 5 #define TP_RST 13 @@ -27,11 +27,11 @@ static const uint8_t RX = 44; static const uint8_t SCL = 7; static const uint8_t SDA = 6; -static const uint8_t SS = 9; -static const uint8_t MOSI = 11; -static const uint8_t MISO = 12; -static const uint8_t SCK = 10; +static const uint8_t SS = 9; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 12; +static const uint8_t SCK = 10; -static const uint8_t A0 = 1; // Connected through voltage divider to battery pin +static const uint8_t A0 = 1; // Connected through voltage divider to battery pin #endif /* Pins_Arduino_h */ diff --git a/variants/wesp32/pins_arduino.h b/variants/wesp32/pins_arduino.h index 670c75fff93..8d7875b7688 100644 --- a/variants/wesp32/pins_arduino.h +++ b/variants/wesp32/pins_arduino.h @@ -3,10 +3,10 @@ #include -#define TX1 12 -#define RX1 13 -#define TX2 33 -#define RX2 39 +#define TX1 12 +#define RX1 13 +#define TX2 33 +#define RX2 39 static const uint8_t TX = 1; static const uint8_t RX = 3; @@ -14,10 +14,10 @@ static const uint8_t RX = 3; static const uint8_t SCL = 4; static const uint8_t SDA = 15; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 32; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 32; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39; @@ -31,11 +31,11 @@ static const uint8_t T2 = 2; static const uint8_t T8 = 33; static const uint8_t T9 = 32; -#define ETH_PHY_ADDR 0 +#define ETH_PHY_ADDR 0 #define ETH_PHY_POWER -1 -#define ETH_PHY_MDC 16 -#define ETH_PHY_MDIO 17 -#define ETH_PHY_TYPE ETH_PHY_LAN8720 -#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN +#define ETH_PHY_MDC 16 +#define ETH_PHY_MDIO 17 +#define ETH_PHY_TYPE ETH_PHY_LAN8720 +#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN #endif /* Pins_Arduino_h */ diff --git a/variants/widora-air/pins_arduino.h b/variants/widora-air/pins_arduino.h index 0c0472b3ac8..2240bbeeae2 100644 --- a/variants/widora-air/pins_arduino.h +++ b/variants/widora-air/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 25; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; @@ -15,10 +15,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 23; static const uint8_t SCL = 19; -static const uint8_t SS = 5; -static const uint8_t MOSI = 16; -static const uint8_t MISO = 17; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 16; +static const uint8_t MISO = 17; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A1 = 39; diff --git a/variants/wifiduino32/pins_arduino.h b/variants/wifiduino32/pins_arduino.h index cc3841aba73..669641652b4 100644 --- a/variants/wifiduino32/pins_arduino.h +++ b/variants/wifiduino32/pins_arduino.h @@ -1,60 +1,60 @@ -#ifndef Pins_Arduino_h -#define Pins_Arduino_h - -#include - -static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN - -static const uint8_t KEY_BUILTIN = 0; - -static const uint8_t TX = 1; -static const uint8_t RX = 3; - -static const uint8_t SDA = 5; -static const uint8_t SCL = 16; - -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; - -static const uint8_t A0 = 27; -static const uint8_t A1 = 14; -static const uint8_t A2 = 12; -static const uint8_t A3 = 35; -static const uint8_t A4 = 13; -static const uint8_t A5 = 4; - - -static const uint8_t D0 = 3; -static const uint8_t D1 = 1; -static const uint8_t D2 = 17; -static const uint8_t D3 = 15; -static const uint8_t D4 = 32; -static const uint8_t D5 = 33; -static const uint8_t D6 = 25; -static const uint8_t D7 = 26; -static const uint8_t D8 = 23; -static const uint8_t D9 = 22; -static const uint8_t D10 = 21; -static const uint8_t D11 = 19; -static const uint8_t D12 = 18; -static const uint8_t D13 = 2; - -static const uint8_t T0 = 4; -static const uint8_t T1 = 0; -static const uint8_t T2 = 2; -static const uint8_t T3 = 15; -static const uint8_t T4 = 13; -static const uint8_t T5 = 12; -static const uint8_t T6 = 14; -static const uint8_t T7 = 27; -static const uint8_t T8 = 33; -static const uint8_t T9 = 32; - -static const uint8_t DAC1 = 25; -static const uint8_t DAC2 = 26; - -#endif /* Pins_Arduino_h */ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +static const uint8_t LED_BUILTIN = 2; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN + +static const uint8_t KEY_BUILTIN = 0; + +static const uint8_t TX = 1; +static const uint8_t RX = 3; + +static const uint8_t SDA = 5; +static const uint8_t SCL = 16; + +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; + +static const uint8_t A0 = 27; +static const uint8_t A1 = 14; +static const uint8_t A2 = 12; +static const uint8_t A3 = 35; +static const uint8_t A4 = 13; +static const uint8_t A5 = 4; + + +static const uint8_t D0 = 3; +static const uint8_t D1 = 1; +static const uint8_t D2 = 17; +static const uint8_t D3 = 15; +static const uint8_t D4 = 32; +static const uint8_t D5 = 33; +static const uint8_t D6 = 25; +static const uint8_t D7 = 26; +static const uint8_t D8 = 23; +static const uint8_t D9 = 22; +static const uint8_t D10 = 21; +static const uint8_t D11 = 19; +static const uint8_t D12 = 18; +static const uint8_t D13 = 2; + +static const uint8_t T0 = 4; +static const uint8_t T1 = 0; +static const uint8_t T2 = 2; +static const uint8_t T3 = 15; +static const uint8_t T4 = 13; +static const uint8_t T5 = 12; +static const uint8_t T6 = 14; +static const uint8_t T7 = 27; +static const uint8_t T8 = 33; +static const uint8_t T9 = 32; + +static const uint8_t DAC1 = 25; +static const uint8_t DAC2 = 26; + +#endif /* Pins_Arduino_h */ diff --git a/variants/wifiduino32s3/pins_arduino.h b/variants/wifiduino32s3/pins_arduino.h index db372a34358..d26e415910e 100644 --- a/variants/wifiduino32s3/pins_arduino.h +++ b/variants/wifiduino32s3/pins_arduino.h @@ -14,10 +14,10 @@ static const uint8_t RX = 44; static const uint8_t SDA = 4; static const uint8_t SCL = 5; -static const uint8_t SS = 46; -static const uint8_t MOSI = 3; -static const uint8_t MISO = 20; -static const uint8_t SCK = 19; +static const uint8_t SS = 46; +static const uint8_t MOSI = 3; +static const uint8_t MISO = 20; +static const uint8_t SCK = 19; static const uint8_t A0 = 7; static const uint8_t A1 = 6; diff --git a/variants/wifiduinov2/pins_arduino.h b/variants/wifiduinov2/pins_arduino.h index f80247e24b9..916de50e642 100644 --- a/variants/wifiduinov2/pins_arduino.h +++ b/variants/wifiduinov2/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 13; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 21; @@ -13,10 +13,10 @@ static const uint8_t RX = 20; static const uint8_t SDA = 4; static const uint8_t SCL = 5; -static const uint8_t SS = 7; -static const uint8_t MOSI = 3; -static const uint8_t MISO = 10; -static const uint8_t SCK = 2; +static const uint8_t SS = 7; +static const uint8_t MOSI = 3; +static const uint8_t MISO = 10; +static const uint8_t SCK = 2; static const uint8_t A0 = 0; static const uint8_t A1 = 1; diff --git a/variants/wipy3/pins_arduino.h b/variants/wipy3/pins_arduino.h index 1cff6173ea1..355c61580dc 100644 --- a/variants/wipy3/pins_arduino.h +++ b/variants/wipy3/pins_arduino.h @@ -5,16 +5,16 @@ #include "soc/soc_caps.h" // Neopixel -#define PIN_NEOPIXEL 0 // ->2812 RGB !!! +#define PIN_NEOPIXEL 0 // ->2812 RGB !!! // BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino static const uint8_t LED_BUILTIN = (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT); -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 -#define ANT_SELECT 21 // GPIO21 - External Antenna Switch +#define ANT_SELECT 21 // GPIO21 - External Antenna Switch static const uint8_t TX = 1; static const uint8_t RX = 3; @@ -22,10 +22,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 12; static const uint8_t SCL = 13; -static const uint8_t SS = 2; -static const uint8_t MOSI = 22; -static const uint8_t MISO = 37; -static const uint8_t SCK = 13; +static const uint8_t SS = 2; +static const uint8_t MOSI = 22; +static const uint8_t MISO = 37; +static const uint8_t SCK = 13; static const uint8_t A0 = 36; static const uint8_t A1 = 37; diff --git a/variants/wt32-eth01/pins_arduino.h b/variants/wt32-eth01/pins_arduino.h index 49cc740efb3..ac4cc1b056b 100644 --- a/variants/wt32-eth01/pins_arduino.h +++ b/variants/wt32-eth01/pins_arduino.h @@ -19,17 +19,17 @@ // general purpose IO pins static const uint8_t IO0 = 0; -static const uint8_t IO1 = 1; // TXD0 / TX0 pin +static const uint8_t IO1 = 1; // TXD0 / TX0 pin static const uint8_t IO2 = 2; -static const uint8_t IO3 = 3; // RXD0 / RX0 pin +static const uint8_t IO3 = 3; // RXD0 / RX0 pin static const uint8_t IO4 = 4; -static const uint8_t IO5 = 5; // RXD2 / RXD pin +static const uint8_t IO5 = 5; // RXD2 / RXD pin static const uint8_t IO12 = 12; static const uint8_t IO14 = 14; static const uint8_t IO15 = 15; -static const uint8_t IO17 = 17; // TXD2 / TXD pin -static const uint8_t IO32 = 32; // CFG pin -static const uint8_t IO33 = 33; // 485_EN pin +static const uint8_t IO17 = 17; // TXD2 / TXD pin +static const uint8_t IO32 = 32; // CFG pin +static const uint8_t IO33 = 33; // 485_EN pin // input-only pins static const uint8_t IO35 = 35; @@ -45,10 +45,10 @@ static const uint8_t TX = 1; static const uint8_t RX = 3; //SPI VSPI default pins -static const uint8_t SS = -1; -static const uint8_t MOSI = 14; -static const uint8_t MISO = 15; -static const uint8_t SCK = 12; +static const uint8_t SS = -1; +static const uint8_t MOSI = 14; +static const uint8_t MISO = 15; +static const uint8_t SCK = 12; //I2C default pins static const uint8_t SDA = 33; diff --git a/variants/wt32-sc01-plus/pins_arduino.h b/variants/wt32-sc01-plus/pins_arduino.h index ae341c67832..b92b9a6c134 100644 --- a/variants/wt32-sc01-plus/pins_arduino.h +++ b/variants/wt32-sc01-plus/pins_arduino.h @@ -6,7 +6,7 @@ * Vendor: Wireless-Tag * Url: http://www.wireless-tag.com/portfolio/wt32-eth01/ */ - + #include #define USB_VID 0x303A @@ -27,11 +27,11 @@ static const uint8_t TX = 42; static const uint8_t RX = 1; static const uint8_t RTS = 2; //TOUCHSCREEN -static const uint8_t BL_PWM = 45; //BACKLIGHT PWM -static const uint8_t LCD_RESET = 4; //LCD RESET, MULTIPLEXED WITH TOUCH RESET -static const uint8_t LCD_RS = 0; //COMMAND/DATA -static const uint8_t LCD_WR = 47; //WRITE CLOCK -static const uint8_t LCD_TE = 48; //FRAME SYNC +static const uint8_t BL_PWM = 45; //BACKLIGHT PWM +static const uint8_t LCD_RESET = 4; //LCD RESET, MULTIPLEXED WITH TOUCH RESET +static const uint8_t LCD_RS = 0; //COMMAND/DATA +static const uint8_t LCD_WR = 47; //WRITE CLOCK +static const uint8_t LCD_TE = 48; //FRAME SYNC static const uint8_t LCD_DB0 = 9; static const uint8_t LCD_DB1 = 46; static const uint8_t LCD_DB2 = 3; @@ -54,12 +54,12 @@ static const uint8_t SCL = 5; static const uint8_t RST = 4; //MICRO SD CARD static const uint8_t SD_CS = 41; -static const uint8_t SD_DI = 40; //MOSI -static const uint8_t SD_DO = 38; //MISO +static const uint8_t SD_DI = 40; //MOSI +static const uint8_t SD_DO = 38; //MISO static const uint8_t SD_CLK = 39; -static const uint8_t SS = 41; -static const uint8_t MOSI = 40; -static const uint8_t MISO = 38; -static const uint8_t SCK = 39; +static const uint8_t SS = 41; +static const uint8_t MOSI = 40; +static const uint8_t MISO = 38; +static const uint8_t SCK = 39; #endif /* Pins_Arduino_h */ diff --git a/variants/xinabox/pins_arduino.h b/variants/xinabox/pins_arduino.h index b5978d1ea94..eeabcd7858a 100644 --- a/variants/xinabox/pins_arduino.h +++ b/variants/xinabox/pins_arduino.h @@ -4,7 +4,7 @@ #include static const uint8_t LED_BUILTIN = 27; -#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; @@ -13,9 +13,9 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; #endif /* Pins_Arduino_h */