From cc4efb2cef72bb1ce1037fb152d7bc38029e8a64 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Fri, 6 Oct 2023 07:43:59 -0300 Subject: [PATCH 01/18] Update README.md (#8727) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 97318c3e120..723cc0f0014 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Arduino core for the ESP32, ESP32-S2, ESP32-S3 and ESP32-C3 +# Arduino core for the ESP32, ESP32-S2, ESP32-S3, ESP32-C3, ESP32-C6 and ESP32-H2 ![Build Status](https://github.com/espressif/arduino-esp32/workflows/ESP32%20Arduino%20CI/badge.svg) [![Documentation Status](https://readthedocs.com/projects/espressif-arduino-esp32/badge/?version=latest)](https://docs.espressif.com/projects/arduino-esp32/en/latest/?badge=latest) [![External Libraries Test](https://github.com/espressif/arduino-esp32/actions/workflows/lib.yml/badge.svg?branch=master&event=schedule)](https://github.com/espressif/arduino-esp32/actions/workflows/lib.yml?link=http://https://github.com/espressif/arduino-esp32/blob/master/LIBRARIES_TEST.md) From 9e5264770972e99e0c9663e15bb4783379a8b601 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri, 6 Oct 2023 12:45:06 +0200 Subject: [PATCH 02/18] include ctime needed for newest GCC (#8722) --- cores/esp32/HardwareSerial.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 33014f13a66..c5c24ab5a34 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "pins_arduino.h" #include "HardwareSerial.h" From 6b1933b3f29e9db14cc70bfb3bdbf52e855b4914 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Fri, 6 Oct 2023 07:45:56 -0300 Subject: [PATCH 03/18] 3.0.0 - UART Peripheral Manager + Detach UART pins on begin()/setPins() (#8719) * detach UART pins * fixes uartEnd() call --- cores/esp32/HardwareSerial.cpp | 51 ++--- cores/esp32/HardwareSerial.h | 12 +- cores/esp32/chip-debug-report.cpp | 5 +- cores/esp32/esp32-hal-periman.h | 5 +- cores/esp32/esp32-hal-uart.c | 320 ++++++++++++++++++++---------- cores/esp32/esp32-hal-uart.h | 14 +- 6 files changed, 269 insertions(+), 138 deletions(-) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index c5c24ab5a34..c165195b0ff 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -149,7 +149,7 @@ void serialEventRun(void) #define HSERIAL_MUTEX_UNLOCK() #endif -HardwareSerial::HardwareSerial(int uart_nr) : +HardwareSerial::HardwareSerial(uint8_t uart_nr) : _uart_nr(uart_nr), _uart(NULL), _rxBufferSize(256), @@ -173,6 +173,12 @@ _eventTask(NULL) } } #endif + // sets UART0 (default console) RX/TX pins as already configured in boot + if (uart_nr == 0) { + setPins(SOC_RX0, SOC_TX0); + } + // set deinit function in the Peripheral Manager + uart_init_PeriMan(); } HardwareSerial::~HardwareSerial() @@ -342,8 +348,8 @@ void HardwareSerial::_uartEventTask(void *args) 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(0 > _uart_nr || _uart_nr >= SOC_UART_NUM) { - log_e("Serial number is invalid, please use numers from 0 to %u", SOC_UART_NUM - 1); + 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; } @@ -357,26 +363,32 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in 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) { - rxPin = SOC_RX0; - txPin = SOC_TX0; + // do not change RX0/TX0 if it has already been set before + rxPin = _rxPin < 0 ? SOC_RX0 : _rxPin; + txPin = _txPin < 0 ? SOC_TX0 : _txPin; } break; #if SOC_UART_NUM > 1 // may save some flash bytes... case UART_NUM_1: if (rxPin < 0 && txPin < 0) { - rxPin = RX1; - txPin = TX1; + // do not change RX1/TX1 if it has already been set before + rxPin = _rxPin < 0 ? RX1 : _rxPin; + txPin = _txPin < 0 ? TX1 : _txPin; } break; #endif #if SOC_UART_NUM > 2 // may save some flash bytes... case UART_NUM_2: if (rxPin < 0 && txPin < 0) { - rxPin = RX2; - txPin = TX2; + // do not change RX2/TX2 if it has already been set before + rxPin = _rxPin < 0 ? RX2 : _rxPin; + txPin = _txPin < 0 ? TX2 : _txPin; } break; #endif @@ -390,6 +402,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in } // 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 (!baud) { // using baud rate as zero, forces it to try to detect the current baud rate in place @@ -452,13 +465,13 @@ void HardwareSerial::end(bool fullyTerminate) uartSetDebug(0); } _rxFIFOFull = 0; - uartEnd(_uart); // fully detach all pins and delete the UART driver + uartEnd(_uart_nr); // fully detach all pins and delete the UART driver } else { // do not invalidate callbacks, detach pins, invalidate DBG output uart_driver_delete(_uart_nr); } - uartEnd(_uart); + uartEnd(_uart_nr); _uart = 0; _destroyEventTask(); } @@ -540,8 +553,8 @@ 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); } @@ -556,19 +569,11 @@ void HardwareSerial::setRxInvert(bool 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) { - if(_uart == NULL) { - log_e("setPins() shall be called after begin() - nothing done\n"); - return false; - } - - // uartSetPins() checks if pins are valid for each function and for the SoC - if (uartSetPins(_uart, rxPin, txPin, ctsPin, rtsPin)) { - return true; - } else { - return false; - } + // 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 (must use setAllPins() before) diff --git a/cores/esp32/HardwareSerial.h b/cores/esp32/HardwareSerial.h index 358264375e6..3e8261d370d 100644 --- a/cores/esp32/HardwareSerial.h +++ b/cores/esp32/HardwareSerial.h @@ -71,7 +71,7 @@ typedef std::function OnReceiveErrorCb; class HardwareSerial: public Stream { public: - HardwareSerial(int uart_nr); + 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) @@ -106,6 +106,11 @@ class HardwareSerial: public Stream // 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(bool fullyTerminate = true); void updateBaudRate(unsigned long baud); @@ -160,7 +165,8 @@ class HardwareSerial: public Stream void setRxInvert(bool); // Negative Pin Number will keep it unmodified, thus this function can set individual pins - // SetPins shall be called after Serial begin() + // 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) bool setHwFlowCtrlMode(uint8_t mode = HW_FLOWCTRL_CTS_RTS, uint8_t threshold = 64); // 64 is half FIFO Length @@ -170,7 +176,7 @@ class HardwareSerial: public Stream size_t setTxBufferSize(size_t new_size); protected: - int _uart_nr; + uint8_t _uart_nr; uart_t* _uart; size_t _rxBufferSize; size_t _txBufferSize; diff --git a/cores/esp32/chip-debug-report.cpp b/cores/esp32/chip-debug-report.cpp index fa9b9564b78..a8821b9695c 100644 --- a/cores/esp32/chip-debug-report.cpp +++ b/cores/esp32/chip-debug-report.cpp @@ -253,7 +253,10 @@ static void printPerimanInfo(void){ chip_report_printf(" %17u : ", i); switch(type){ case ESP32_BUS_TYPE_GPIO: chip_report_printf("GPIO\n"); break; - case ESP32_BUS_TYPE_UART: chip_report_printf("UART\n"); break; + case ESP32_BUS_TYPE_UART_RX: chip_report_printf("UART_RX\n"); break; + case ESP32_BUS_TYPE_UART_TX: chip_report_printf("UART_TX\n"); break; + case ESP32_BUS_TYPE_UART_CTS: chip_report_printf("UART_CTS\n"); break; + case ESP32_BUS_TYPE_UART_RTS: chip_report_printf("UART_RTS\n"); break; #if SOC_SDM_SUPPORTED case ESP32_BUS_TYPE_SIGMADELTA: chip_report_printf("SIGMADELTA\n"); break; #endif diff --git a/cores/esp32/esp32-hal-periman.h b/cores/esp32/esp32-hal-periman.h index 72827eeff93..94e80986698 100644 --- a/cores/esp32/esp32-hal-periman.h +++ b/cores/esp32/esp32-hal-periman.h @@ -17,7 +17,10 @@ extern "C" 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, // IO is used as UART pin + 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 #endif diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 149c8c40dcd..7817d7463b0 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -65,8 +65,8 @@ static uart_t _uart_bus_array[] = { #else -#define UART_MUTEX_LOCK() do {} while (xSemaphoreTake(uart->lock, portMAX_DELAY) != pdPASS) -#define UART_MUTEX_UNLOCK() 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}, @@ -80,35 +80,178 @@ static uart_t _uart_bus_array[] = { #endif -// IDF UART has no detach function. As consequence, after ending a UART, the previous pins continue -// to work as RX/TX. It can be verified by changing the UART pins and writing to the UART. Output can -// be seen in the previous pins and new pins as well. -// Valid pin UART_PIN_NO_CHANGE is defined to (-1) // Negative Pin Number will keep it unmodified, thus this function can detach individual pins -static void _uartDetachPins(uart_t* uart, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) +// 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 == NULL) { - return; + 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; } - if (txPin >= 0) { + // 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); + esp_rom_gpio_connect_in_signal(GPIO_FUNC_IN_LOW, UART_PERIPH_SIGNAL(uart_num, SOC_UART_RX_PIN_IDX), false); + uart->_rxPin = -1; // -1 means unassigned/detached + if (!perimanSetPinBus(rxPin, ESP32_BUS_TYPE_INIT, NULL)) { + 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 (!perimanSetPinBus(txPin, ESP32_BUS_TYPE_INIT, NULL)) { + retCode = false; + log_e("UART%d failed to detach TX pin %d", uart_num, txPin); + } } - - if (rxPin >= 0) { - gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[rxPin], PIN_FUNC_GPIO); - esp_rom_gpio_connect_in_signal(GPIO_FUNC_IN_LOW, UART_PERIPH_SIGNAL(uart->num, SOC_UART_RX_PIN_IDX), false); + 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 (!perimanSetPinBus(ctsPin, ESP32_BUS_TYPE_INIT, NULL)) { + retCode = false; + log_e("UART%d failed to detach CTS pin %d", uart_num, ctsPin); + } } - - if (rtsPin >= 0) { + 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 (!perimanSetPinBus(rtsPin, ESP32_BUS_TYPE_INIT, NULL)) { + 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) +{ + // sanity check - it should never happen + assert(busptr && "_uartDetachBus_RX bus NULL pointer."); + 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) +{ + // sanity check - it should never happen + assert(busptr && "_uartDetachBus_TX bus NULL pointer."); + 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) +{ + // sanity check - it should never happen + assert(busptr && "_uartDetachBus_CTS bus NULL pointer."); + 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) +{ + // sanity check - it should never happen + assert(busptr && "_uartDetachBus_RTS bus NULL pointer."); + 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 +// 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) { + // 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); + 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) { + // 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); + 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) { - 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); + // 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); + 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) { + // 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); + 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_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); } // Routines that take care of UART events will be in the HardwareSerial Class code @@ -135,99 +278,59 @@ bool uartIsDriverInstalled(uart_t* uart) return false; } -// Peripheral Manager detach callback -static bool _uartDetachBus(void *busptr) -{ - // sanity check - it should never happen - assert(busptr && "_uartDetachBus bus NULL pointer."); - - bool retCode = true; - uart_t* bus = (uart_t*) busptr; - - if (bus->_rxPin > 0 && perimanGetPinBusType(bus->_rxPin) == ESP32_BUS_TYPE_UART) { - int8_t oldPinNum = bus->_rxPin; - _uartDetachPins(bus, bus->_rxPin, -1, -1, -1); - bus->_rxPin = -1; - retCode &= perimanSetPinBus(oldPinNum, ESP32_BUS_TYPE_INIT, NULL); - } - if (retCode && bus->_txPin > 0 && perimanGetPinBusType(bus->_txPin) == ESP32_BUS_TYPE_UART) { - int8_t oldPinNum = bus->_txPin; - _uartDetachPins(bus, -1, bus->_txPin, -1, -1); - bus->_txPin = -1; - retCode &= perimanSetPinBus(oldPinNum, ESP32_BUS_TYPE_INIT, NULL); - } - if (retCode && bus->_ctsPin > 0 && perimanGetPinBusType(bus->_ctsPin) == ESP32_BUS_TYPE_UART) { - int8_t oldPinNum = bus->_ctsPin; - _uartDetachPins(bus, -1, -1, bus->_ctsPin, -1); - bus->_ctsPin = -1; - retCode &= perimanSetPinBus(oldPinNum, ESP32_BUS_TYPE_INIT, NULL); - } - if (retCode && bus->_rtsPin > 0 && perimanGetPinBusType(bus->_rtsPin) == ESP32_BUS_TYPE_UART) { - int8_t oldPinNum = bus->_rtsPin; - _uartDetachPins(bus, -1, -1, -1, bus->_rtsPin); - bus->_rtsPin = -1; - retCode &= perimanSetPinBus(oldPinNum, ESP32_BUS_TYPE_INIT, NULL); - } - if(retCode && uart_is_driver_installed(bus->num)) { - retCode &= ESP_OK == uart_driver_delete(bus->num); - } - - return retCode; -} - -// Valid pin UART_PIN_NO_CHANGE is defined to (-1) // Negative Pin Number will keep it unmodified, thus this function can set individual pins -bool uartSetPins(uart_t* uart, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) +// 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 == NULL) { + 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(); - if (rxPin > 0) { - // detachs previous UART pin - if (uart->_rxPin > 0 && rxPin != uart->_rxPin) _uartDetachPins(uart, uart->_rxPin, -1, -1, -1); - //assign the new one - retCode &= perimanSetPinBus(rxPin, ESP32_BUS_TYPE_UART, (void *)uart); - if (retCode) { - uart->_rxPin = rxPin; - } + + //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); } - if (retCode && txPin > 0) { - // detachs previous UART pin - if (uart->_txPin > 0 && txPin != uart->_txPin) _uartDetachPins(uart, -1, uart->_txPin, -1, -1); - //assign the new one - retCode &= perimanSetPinBus(txPin, ESP32_BUS_TYPE_UART, (void *)uart); - if (retCode) { - uart->_txPin = txPin; - } + 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); } - if (retCode && ctsPin > 0) { - // detachs previous UART pin - if (uart->_ctsPin > 0 && ctsPin != uart->_ctsPin) _uartDetachPins(uart, -1, -1, uart->_ctsPin, -1); - //assign the new one - retCode &= perimanSetPinBus(ctsPin, ESP32_BUS_TYPE_UART, (void *)uart); - if (retCode) { - uart->_ctsPin = ctsPin; - } + 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); } - if (retCode && rtsPin > 0) { - // detachs previous UART pin - if (uart->_rtsPin > 0 && rtsPin != uart->_rtsPin) _uartDetachPins(uart, -1, -1, -1, uart->_rtsPin); - //assign the new one - retCode &= perimanSetPinBus(rtsPin, ESP32_BUS_TYPE_UART, (void *)uart); - if (retCode) { - uart->_rtsPin = rtsPin; - } + 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); } - // IDF uart_set_pin() will issue necessary Error Message and take care of all GPIO Number validation. - if (retCode) retCode &= ESP_OK == uart_set_pin(uart->num, txPin, rxPin, rtsPin, ctsPin); + // 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 it fails at any point ... detachs UART - if (!retCode) _uartDetachBus((void *) uart); + if (!retCode) { + log_e("UART%d set pins failed."); + } return retCode; } @@ -251,11 +354,8 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx } uart_t* uart = &_uart_bus_array[uart_nr]; - // set Peripheral Manager deInit Callback - perimanSetBusDeinit(ESP32_BUS_TYPE_UART, _uartDetachBus); - if (uart_is_driver_installed(uart_nr)) { - _uartDetachBus((void *) uart); + uartEnd(uart_nr); } #if !CONFIG_DISABLE_HAL_LOCKS @@ -288,12 +388,12 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx } UART_MUTEX_UNLOCK(); - - if (retCode) retCode &= uartSetPins(uart, rxPin, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + // 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) uartFlush(uart); else { - _uartDetachBus((void *) uart); + uartEnd(uart_nr); uart = NULL; log_e("UART%d initialization error.", uart->num); } @@ -348,14 +448,20 @@ bool uartSetRxFIFOFull(uart_t* uart, uint8_t numBytesFIFOFull) } -void uartEnd(uart_t* uart) +void uartEnd(uint8_t uart_num) { - if(uart == NULL) { + 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(); - _uartDetachBus((void *) uart); + _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(); } diff --git a/cores/esp32/esp32-hal-uart.h b/cores/esp32/esp32-hal-uart.h index a1531d6042d..c904a248f4c 100644 --- a/cores/esp32/esp32-hal-uart.h +++ b/cores/esp32/esp32-hal-uart.h @@ -103,7 +103,7 @@ struct uart_struct_t; typedef struct uart_struct_t uart_t; 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(uart_t* uart); +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); @@ -133,8 +133,16 @@ int uartGetDebug(); bool uartIsDriverInstalled(uart_t* uart); -// Negative Pin Number will keep it unmodified, thus this function can set/reset individual pins -bool uartSetPins(uart_t* uart, 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); + // Enables or disables HW Flow Control function -- needs also to set CTS and/or RTS pins bool uartSetHwFlowCtrlMode(uart_t *uart, uint8_t mode, uint8_t threshold); From b98b52a1a8a7fe32dd4b2e176cfe77212e74e153 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Fri, 6 Oct 2023 07:46:40 -0300 Subject: [PATCH 04/18] Reorganize RS485 Mode - FlowCtrl (#8718) --- cores/esp32/HardwareSerial.cpp | 14 ++++-- cores/esp32/HardwareSerial.h | 43 ++++++++++++++++- cores/esp32/esp32-hal-uart.c | 6 +-- cores/esp32/esp32-hal-uart.h | 85 +++++----------------------------- 4 files changed, 66 insertions(+), 82 deletions(-) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index c165195b0ff..1780da41213 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -576,14 +576,20 @@ bool HardwareSerial::setPins(int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t r return uartSetPins(_uart_nr, rxPin, txPin, ctsPin, rtsPin); } -// Enables or disables Hardware Flow Control using RTS and/or CTS pins (must use setAllPins() before) -bool HardwareSerial::setHwFlowCtrlMode(uint8_t mode, uint8_t threshold) +// 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, +// UART_HW_FLOWCTRL_CTS, UART_HW_FLOWCTRL_CTS_RTS +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 (HwFlowCtrl must be disabled and RTS pin set) -bool HardwareSerial::setMode(uint8_t mode) +// 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); } diff --git a/cores/esp32/HardwareSerial.h b/cores/esp32/HardwareSerial.h index 3e8261d370d..459d5f385b6 100644 --- a/cores/esp32/HardwareSerial.h +++ b/cores/esp32/HardwareSerial.h @@ -56,6 +56,36 @@ #include "freertos/task.h" #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 +}; + +typedef uart_mode_t SerialMode; +typedef uart_hw_flowcontrol_t SerialHwFlowCtrl; + typedef enum { UART_NO_ERROR, UART_BREAK_ERROR, @@ -169,9 +199,18 @@ class HardwareSerial: public Stream // 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) - bool setHwFlowCtrlMode(uint8_t mode = HW_FLOWCTRL_CTS_RTS, uint8_t threshold = 64); // 64 is half FIFO Length + // 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 - bool setMode(uint8_t mode); + // 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); diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 7817d7463b0..243eb16a454 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -335,14 +335,14 @@ bool uartSetPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, in } // -bool uartSetHwFlowCtrlMode(uart_t *uart, uint8_t mode, uint8_t threshold) { +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, (uart_hw_flowcontrol_t) mode, threshold)); + bool retCode = (ESP_OK == uart_set_hw_flow_ctrl(uart->num, mode, threshold)); UART_MUTEX_UNLOCK(); return retCode; } @@ -716,7 +716,7 @@ void uart_install_putc() // 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, uint8_t mode) +bool uartSetMode(uart_t *uart, uart_mode_t mode) { if (uart == NULL || uart->num >= SOC_UART_NUM) { diff --git a/cores/esp32/esp32-hal-uart.h b/cores/esp32/esp32-hal-uart.h index c904a248f4c..fbb9694c58a 100644 --- a/cores/esp32/esp32-hal-uart.h +++ b/cores/esp32/esp32-hal-uart.h @@ -27,77 +27,7 @@ extern "C" { #include #include "freertos/FreeRTOS.h" #include "freertos/queue.h" - -#ifdef __cplusplus -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 -}; -#else -#define SERIAL_5N1 0x8000010 -#define SERIAL_6N1 0x8000014 -#define SERIAL_7N1 0x8000018 -#define SERIAL_8N1 0x800001c -#define SERIAL_5N2 0x8000030 -#define SERIAL_6N2 0x8000034 -#define SERIAL_7N2 0x8000038 -#define SERIAL_8N2 0x800003c -#define SERIAL_5E1 0x8000012 -#define SERIAL_6E1 0x8000016 -#define SERIAL_7E1 0x800001a -#define SERIAL_8E1 0x800001e -#define SERIAL_5E2 0x8000032 -#define SERIAL_6E2 0x8000036 -#define SERIAL_7E2 0x800003a -#define SERIAL_8E2 0x800003e -#define SERIAL_5O1 0x8000013 -#define SERIAL_6O1 0x8000017 -#define SERIAL_7O1 0x800001b -#define SERIAL_8O1 0x800001f -#define SERIAL_5O2 0x8000033 -#define SERIAL_6O2 0x8000037 -#define SERIAL_7O2 0x800003b -#define SERIAL_8O2 0x800003f -#endif // __cplusplus - -// These are Hardware Flow Contol possible usage -// equivalent to UDF enum uart_hw_flowcontrol_t from -// https://github.com/espressif/esp-idf/blob/master/components/hal/include/hal/uart_types.h#L75-L81 -#define HW_FLOWCTRL_DISABLE 0x0 // disable HW Flow Control -#define HW_FLOWCTRL_RTS 0x1 // use only RTS PIN for HW Flow Control -#define HW_FLOWCTRL_CTS 0x2 // use only CTS PIN for HW Flow Control -#define HW_FLOWCTRL_CTS_RTS 0x3 // use both CTS and RTS PIN for HW Flow Control - -// These are Hardware Uart Modes possible usage -// equivalent to UDF enum uart_mode_t from -// https://github.com/espressif/esp-idf/blob/master/components/hal/include/hal/uart_types.h#L34-L40 -#define MODE_UART 0x00 // mode: regular UART mode -#define MODE_RS485_HALF_DUPLEX 0x01 // mode: half duplex RS485 UART mode control by RTS pin -#define MODE_IRDA 0x02 // mode: IRDA UART mode -#define MODE_RS485_COLLISION_DETECT 0x03 // mode: RS485 collision detection UART mode (used for test purposes) -#define MODE_RS485_APP_CTRL 0x04 +#include "hal/uart_types.h" struct uart_struct_t; typedef struct uart_struct_t uart_t; @@ -145,11 +75,20 @@ void uart_init_PeriMan(void); // Enables or disables HW Flow Control function -- needs also to set CTS and/or RTS pins -bool uartSetHwFlowCtrlMode(uart_t *uart, uint8_t mode, uint8_t threshold); +// 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 -bool uartSetMode(uart_t *uart, uint8_t mode); +// 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); From 352af86478717dafd9522d081c1f318e9217ac9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Fri, 6 Oct 2023 12:47:08 +0200 Subject: [PATCH 05/18] Analog Continuous mode API (#8715) * Adds Analog Continuous mode API * fix when stopping/starting ADC data are not complete * Added example * fix size check * update frequency in example * set buffer to NULL if error occurs * add docs * set buffer to null on error * fix example * update docs * fix example * change return value to bool type * updated adc modes description in docs * Add empty line at the end of sketch --- cores/esp32/esp32-hal-adc.c | 425 +++++++++++++++++- cores/esp32/esp32-hal-adc.h | 50 +++ docs/source/api/adc.rst | 138 +++++- .../AnalogReadContinuous.ino | 71 +++ 4 files changed, 652 insertions(+), 32 deletions(-) create mode 100644 libraries/ESP32/examples/AnalogReadContinuous/AnalogReadContinuous.ino diff --git a/cores/esp32/esp32-hal-adc.c b/cores/esp32/esp32-hal-adc.c index b53eb868d3d..4278b2d1a78 100644 --- a/cores/esp32/esp32-hal-adc.c +++ b/cores/esp32/esp32-hal-adc.c @@ -1,4 +1,4 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// Copyright 2015-2023 Espressif Systems (Shanghai) PTE LTD // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,14 +18,28 @@ #include "esp32-hal.h" #include "esp32-hal-periman.h" #include "esp_adc/adc_oneshot.h" +#include "esp_adc/adc_continuous.h" #include "esp_adc/adc_cali_scheme.h" static uint8_t __analogAttenuation = ADC_11db; static uint8_t __analogWidth = SOC_ADC_RTC_MAX_BITWIDTH; static uint8_t __analogReturnedWidth = SOC_ADC_RTC_MAX_BITWIDTH; -adc_oneshot_unit_handle_t adc_handle[SOC_ADC_PERIPH_NUM]; -adc_cali_handle_t adc_cali_handle[SOC_ADC_PERIPH_NUM]; +typedef struct { + 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_handle_t; + +adc_handle_t adc_handle[SOC_ADC_PERIPH_NUM]; static bool adcDetachBus(void * pin){ adc_channel_t adc_channel; @@ -42,11 +56,23 @@ static bool adcDetachBus(void * pin){ } if(used_channels == 1){ //only 1 channel is used - esp_err_t err = adc_oneshot_del_unit(adc_handle[adc_unit]); + 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_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; } - adc_handle[adc_unit] = NULL; + #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; } return true; } @@ -59,12 +85,12 @@ esp_err_t __analogChannelConfig(adc_bitwidth_t width, adc_attenuation_t atten, i }; 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] != NULL){ + 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], channel, &config); + 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; @@ -72,10 +98,10 @@ esp_err_t __analogChannelConfig(adc_bitwidth_t width, adc_attenuation_t atten, i } } //ADC calibration reconfig only if all channels are updated - if(adc_cali_handle[adc_unit] != NULL){ + 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_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; @@ -86,14 +112,14 @@ esp_err_t __analogChannelConfig(adc_bitwidth_t width, adc_attenuation_t atten, i .bitwidth = width, }; log_d("Creating ADC_UNIT_%d curve cali handle",adc_unit); - err = adc_cali_create_scheme_curve_fitting(&cali_config, &adc_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_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32H2) //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED + #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_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; @@ -104,7 +130,7 @@ esp_err_t __analogChannelConfig(adc_bitwidth_t width, adc_attenuation_t atten, i .bitwidth = width, }; log_d("Creating ADC_UNIT_%d line cali handle",adc_unit); - err = adc_cali_create_scheme_line_fitting(&cali_config, &adc_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; @@ -128,7 +154,7 @@ esp_err_t __analogChannelConfig(adc_bitwidth_t width, adc_attenuation_t atten, i log_e("Pin %u is not ADC pin!", pin); return err; } - err = adc_oneshot_config_channel(adc_handle[adc_unit], channel, &config); + 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; @@ -174,12 +200,12 @@ void __analogSetWidth(uint8_t bits){ 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] == NULL) { + 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]); + 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); @@ -197,7 +223,7 @@ esp_err_t __analogInit(uint8_t pin, adc_channel_t channel, adc_unit_t adc_unit){ .atten = __analogAttenuation, }; - err = adc_oneshot_config_channel(adc_handle[adc_unit], channel, &config); + 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; @@ -245,7 +271,7 @@ uint16_t __analogRead(uint8_t pin){ } } - adc_oneshot_read(adc_handle[adc_unit], channel, &value); + adc_oneshot_read(adc_handle[adc_unit].adc_oneshot_handle, channel, &value); return mapResolution(value); } @@ -269,7 +295,7 @@ uint32_t __analogReadMilliVolts(uint8_t pin){ } } - if(adc_cali_handle[adc_unit] == NULL){ + 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 = { @@ -277,14 +303,14 @@ uint32_t __analogReadMilliVolts(uint8_t pin){ .atten = __analogAttenuation, .bitwidth = __analogWidth, }; - err = adc_cali_create_scheme_curve_fitting(&cali_config, &adc_cali_handle[adc_unit]); - #elif !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32H2) //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED + 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_cali_handle[adc_unit]); + 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!"); @@ -292,7 +318,7 @@ uint32_t __analogReadMilliVolts(uint8_t pin){ } } - err = adc_oneshot_get_calibrated_result(adc_handle[adc_unit], adc_cali_handle[adc_unit], channel, &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; @@ -310,4 +336,357 @@ extern void analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation) extern void analogSetWidth(uint8_t bits) __attribute__ ((weak, alias("__analogSetWidth"))); #endif +/* + * ADC Continuous mode + */ + +#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) +#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) +#endif + +static uint8_t __adcContinuousAtten = ADC_11db; +static uint8_t __adcContinuousWidth = SOC_ADC_DIGI_MAX_BITWIDTH; + +static uint8_t used_adc_channels = 0; +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; + + 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_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(!perimanSetPinBus(io_pin, ESP32_BUS_TYPE_INIT, NULL)){ + return false; + } + } + } + } + return true; +} + +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; +} + +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; + + //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; + } + } + + //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; + } + + //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(!perimanSetPinBus(pins[j], ESP32_BUS_TYPE_INIT, NULL)){ + 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; + +#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); + } +#endif + + 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; + } + + //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, + }; + 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; + } + } + + for(int k = 0; k < pins_count; k++){ + if(!perimanSetPinBus(pins[k], ESP32_BUS_TYPE_ADC_CONT, (void *)(adc_unit+1))){ + log_e("perimanSetPinBus to ADC Continuous failed!"); + adcContinuousDetachBus((void *)(adc_unit+1)); + return false; + } + } + + 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; + } +} + +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!"); + } + 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!"); + } + 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; +} + +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; +} + #endif diff --git a/cores/esp32/esp32-hal-adc.h b/cores/esp32/esp32-hal-adc.h index f25e1abce41..41122b2d4bb 100644 --- a/cores/esp32/esp32-hal-adc.h +++ b/cores/esp32/esp32-hal-adc.h @@ -77,6 +77,56 @@ void analogSetWidth(uint8_t bits); #endif +/* + * Analog Continuous mode + * */ + +typedef struct { + uint8_t pin; /*! AnalogReadSerial. .. literalinclude:: ../../../libraries/ESP32/examples/AnalogRead/AnalogRead.ino :language: arduino -Or you can run Arduino example 01.Basics -> AnalogReadSerial. +Here is an example of how to use the ADC in Continuous mode. + +.. literalinclude:: ../../../libraries/ESP32/examples/AnalogReadContinuous/AnalogReadContinuous.ino + :language: arduino diff --git a/libraries/ESP32/examples/AnalogReadContinuous/AnalogReadContinuous.ino b/libraries/ESP32/examples/AnalogReadContinuous/AnalogReadContinuous.ino new file mode 100644 index 00000000000..c0928318fb6 --- /dev/null +++ b/libraries/ESP32/examples/AnalogReadContinuous/AnalogReadContinuous.ino @@ -0,0 +1,71 @@ +// Define how many conversion per pin will happen and reading the data will be and average of all conversions +#define CONVERSIONS_PER_PIN 5 + +// 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 +#else +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 +uint8_t adc_pins_count = sizeof(adc_pins) / sizeof(uint8_t); + +// Flag which will be set in ISR when conversion is done +volatile bool adc_coversion_done = false; + +// Result structure for ADC Continuous reading +adc_continuos_data_t * result = NULL; + +// ISR Function that will be triggered when ADC conversion is done +void ARDUINO_ISR_ATTR adcComplete() { + adc_coversion_done = true; +} + +void setup() { + // 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: 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); + + // 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)) { + + // 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); + } + + // 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."); + } + } +} From 93a45019a8fb6e673104ee0866eded359c6adeeb Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Fri, 6 Oct 2023 13:47:35 +0300 Subject: [PATCH 06/18] HTTPClient - Fix case sensitiveness for header keys (#8713) --- libraries/HTTPClient/src/HTTPClient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/HTTPClient/src/HTTPClient.cpp b/libraries/HTTPClient/src/HTTPClient.cpp index f13e7a2e306..62a9c44901b 100644 --- a/libraries/HTTPClient/src/HTTPClient.cpp +++ b/libraries/HTTPClient/src/HTTPClient.cpp @@ -1081,7 +1081,7 @@ void HTTPClient::collectHeaders(const char* headerKeys[], const size_t headerKey String HTTPClient::header(const char* name) { for(size_t i = 0; i < _headerKeysCount; ++i) { - if(_currentHeaders[i].key == name) { + if(_currentHeaders[i].key.equalsIgnoreCase(name)) { return _currentHeaders[i].value; } } @@ -1112,7 +1112,7 @@ int HTTPClient::headers() bool HTTPClient::hasHeader(const char* name) { for(size_t i = 0; i < _headerKeysCount; ++i) { - if((_currentHeaders[i].key == name) && (_currentHeaders[i].value.length() > 0)) { + if((_currentHeaders[i].key.equalsIgnoreCase(name)) && (_currentHeaders[i].value.length() > 0)) { return true; } } From e2487b128d59a717ecada6cb36566addc3ddc769 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Fri, 6 Oct 2023 13:47:54 +0300 Subject: [PATCH 07/18] [ETH] Implement SPI support, multiple interfaces and more (#8712) --- .../examples/ETH_LAN8720/ETH_LAN8720.ino | 29 +- .../examples/ETH_TLK110/ETH_TLK110.ino | 27 +- .../ETH_W5500_Arduino_SPI/.skip.esp32h2 | 0 .../ETH_W5500_Arduino_SPI.ino | 110 ++ .../examples/ETH_W5500_IDF_SPI/.skip.esp32h2 | 0 .../ETH_W5500_IDF_SPI/ETH_W5500_IDF_SPI.ino | 107 ++ libraries/Ethernet/src/ETH.cpp | 1174 +++++++++++------ libraries/Ethernet/src/ETH.h | 209 ++- libraries/WiFi/src/WiFiGeneric.cpp | 8 +- libraries/WiFi/src/WiFiGeneric.h | 1 + 10 files changed, 1154 insertions(+), 511 deletions(-) create mode 100644 libraries/Ethernet/examples/ETH_W5500_Arduino_SPI/.skip.esp32h2 create mode 100644 libraries/Ethernet/examples/ETH_W5500_Arduino_SPI/ETH_W5500_Arduino_SPI.ino create mode 100644 libraries/Ethernet/examples/ETH_W5500_IDF_SPI/.skip.esp32h2 create mode 100644 libraries/Ethernet/examples/ETH_W5500_IDF_SPI/ETH_W5500_IDF_SPI.ino diff --git a/libraries/Ethernet/examples/ETH_LAN8720/ETH_LAN8720.ino b/libraries/Ethernet/examples/ETH_LAN8720/ETH_LAN8720.ino index a3651d9ef98..862263973ee 100644 --- a/libraries/Ethernet/examples/ETH_LAN8720/ETH_LAN8720.ino +++ b/libraries/Ethernet/examples/ETH_LAN8720/ETH_LAN8720.ino @@ -3,11 +3,20 @@ */ +// Important to be defined BEFORE including ETH.h for ETH.begin() to work. +// Example RMII LAN8720 (Olimex, etc.) +#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 + #include static bool eth_connected = false; -void WiFiEvent(WiFiEvent_t event) +void onEvent(arduino_event_id_t event, arduino_event_info_t info) { switch (event) { case ARDUINO_EVENT_ETH_START: @@ -19,18 +28,14 @@ void WiFiEvent(WiFiEvent_t event) Serial.println("ETH Connected"); break; case ARDUINO_EVENT_ETH_GOT_IP: - Serial.print("ETH MAC: "); - Serial.print(ETH.macAddress()); - Serial.print(", IPv4: "); - Serial.print(ETH.localIP()); - if (ETH.fullDuplex()) { - Serial.print(", FULL_DUPLEX"); - } - Serial.print(", "); - Serial.print(ETH.linkSpeed()); - Serial.println("Mbps"); + Serial.println("ETH Got IP"); + ETH.printInfo(Serial); eth_connected = true; break; + case ARDUINO_EVENT_ETH_LOST_IP: + Serial.println("ETH Lost IP"); + eth_connected = false; + break; case ARDUINO_EVENT_ETH_DISCONNECTED: Serial.println("ETH Disconnected"); eth_connected = false; @@ -67,7 +72,7 @@ void testClient(const char * host, uint16_t port) void setup() { Serial.begin(115200); - WiFi.onEvent(WiFiEvent); + WiFi.onEvent(onEvent); ETH.begin(); } diff --git a/libraries/Ethernet/examples/ETH_TLK110/ETH_TLK110.ino b/libraries/Ethernet/examples/ETH_TLK110/ETH_TLK110.ino index c144b6eeb00..9558889fbd2 100644 --- a/libraries/Ethernet/examples/ETH_TLK110/ETH_TLK110.ino +++ b/libraries/Ethernet/examples/ETH_TLK110/ETH_TLK110.ino @@ -5,15 +5,16 @@ #include +#define ETH_TYPE ETH_PHY_TLK110 #define ETH_ADDR 31 -#define ETH_POWER_PIN 17 #define ETH_MDC_PIN 23 #define ETH_MDIO_PIN 18 -#define ETH_TYPE ETH_PHY_TLK110 +#define ETH_POWER_PIN 17 +#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN static bool eth_connected = false; -void WiFiEvent(WiFiEvent_t event) +void onEvent(arduino_event_id_t event, arduino_event_info_t info) { switch (event) { case ARDUINO_EVENT_ETH_START: @@ -25,18 +26,14 @@ void WiFiEvent(WiFiEvent_t event) Serial.println("ETH Connected"); break; case ARDUINO_EVENT_ETH_GOT_IP: - Serial.print("ETH MAC: "); - Serial.print(ETH.macAddress()); - Serial.print(", IPv4: "); - Serial.print(ETH.localIP()); - if (ETH.fullDuplex()) { - Serial.print(", FULL_DUPLEX"); - } - Serial.print(", "); - Serial.print(ETH.linkSpeed()); - Serial.println("Mbps"); + Serial.println("ETH Got IP"); + ETH.printInfo(Serial); eth_connected = true; break; + case ARDUINO_EVENT_ETH_LOST_IP: + Serial.println("ETH Lost IP"); + eth_connected = false; + break; case ARDUINO_EVENT_ETH_DISCONNECTED: Serial.println("ETH Disconnected"); eth_connected = false; @@ -73,8 +70,8 @@ void testClient(const char * host, uint16_t port) void setup() { Serial.begin(115200); - WiFi.onEvent(WiFiEvent); - ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE); + WiFi.onEvent(onEvent); + ETH.begin(ETH_TYPE, ETH_ADDR, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_POWER_PIN, ETH_CLK_MODE); } diff --git a/libraries/Ethernet/examples/ETH_W5500_Arduino_SPI/.skip.esp32h2 b/libraries/Ethernet/examples/ETH_W5500_Arduino_SPI/.skip.esp32h2 new file mode 100644 index 00000000000..e69de29bb2d 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 new file mode 100644 index 00000000000..0b7e3cf1342 --- /dev/null +++ b/libraries/Ethernet/examples/ETH_W5500_Arduino_SPI/ETH_W5500_Arduino_SPI.ino @@ -0,0 +1,110 @@ +/* + This sketch shows the Ethernet event usage + +*/ + +#include +#include + +// Set this to 1 to enable dual Ethernet support +#define USE_TWO_ETH_PORTS 0 + +#define ETH_TYPE ETH_PHY_W5500 +#define ETH_ADDR 1 +#define ETH_CS 15 +#define ETH_IRQ 4 +#define ETH_RST 5 + +// SPI pins +#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 +#define ETH1_TYPE ETH_PHY_W5500 +#define ETH1_ADDR 1 +#define ETH1_CS 32 +#define ETH1_IRQ 33 +#define ETH1_RST 18 +ETHClass ETH1(1); +#endif + +static bool eth_connected = false; + +void onEvent(arduino_event_id_t event, arduino_event_info_t info) +{ + switch (event) { + case ARDUINO_EVENT_ETH_START: + Serial.println("ETH Started"); + //set eth hostname here + ETH.setHostname("esp32-eth0"); + break; + case ARDUINO_EVENT_ETH_CONNECTED: + Serial.println("ETH Connected"); + break; + case ARDUINO_EVENT_ETH_GOT_IP: + Serial.printf("ETH Got IP: '%s'\n", esp_netif_get_desc(info.got_ip.esp_netif)); + ETH.printInfo(Serial); +#if USE_TWO_ETH_PORTS + ETH1.printInfo(Serial); +#endif + eth_connected = true; + break; + case ARDUINO_EVENT_ETH_LOST_IP: + Serial.println("ETH Lost IP"); + eth_connected = false; + break; + case ARDUINO_EVENT_ETH_DISCONNECTED: + Serial.println("ETH Disconnected"); + eth_connected = false; + break; + case ARDUINO_EVENT_ETH_STOP: + Serial.println("ETH Stopped"); + eth_connected = false; + break; + default: + break; + } +} + +void testClient(const char * host, uint16_t port) +{ + Serial.print("\nconnecting to "); + Serial.println(host); + + WiFiClient client; + if (!client.connect(host, port)) { + Serial.println("connection failed"); + return; + } + client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host); + while (client.connected() && !client.available()); + while (client.available()) { + Serial.write(client.read()); + } + + Serial.println("closing connection\n"); + client.stop(); +} + +void setup() +{ + Serial.begin(115200); + WiFi.onEvent(onEvent); + + SPI.begin(ETH_SPI_SCK, ETH_SPI_MISO, ETH_SPI_MOSI); + ETH.begin(ETH_TYPE, ETH_ADDR, ETH_CS, ETH_IRQ, ETH_RST, SPI); +#if USE_TWO_ETH_PORTS + ETH1.begin(ETH1_TYPE, ETH1_ADDR, ETH1_CS, ETH1_IRQ, ETH1_RST, SPI); +#endif +} + + +void loop() +{ + if (eth_connected) { + testClient("google.com", 80); + } + delay(10000); +} diff --git a/libraries/Ethernet/examples/ETH_W5500_IDF_SPI/.skip.esp32h2 b/libraries/Ethernet/examples/ETH_W5500_IDF_SPI/.skip.esp32h2 new file mode 100644 index 00000000000..e69de29bb2d 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 new file mode 100644 index 00000000000..d68b3e1d162 --- /dev/null +++ b/libraries/Ethernet/examples/ETH_W5500_IDF_SPI/ETH_W5500_IDF_SPI.ino @@ -0,0 +1,107 @@ +/* + This sketch shows the Ethernet event usage + +*/ + +#include + +// Set this to 1 to enable dual Ethernet support +#define USE_TWO_ETH_PORTS 0 + +#define ETH_TYPE ETH_PHY_W5500 +#define ETH_ADDR 1 +#define ETH_CS 15 +#define ETH_IRQ 4 +#define ETH_RST 5 +#define ETH_SPI_HOST SPI2_HOST +#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 +#define ETH1_TYPE ETH_PHY_W5500 +#define ETH1_ADDR 1 +#define ETH1_CS 32 +#define ETH1_IRQ 33 +#define ETH1_RST 18 +ETHClass ETH1(1); +#endif + +static bool eth_connected = false; + +void onEvent(arduino_event_id_t event, arduino_event_info_t info) +{ + switch (event) { + case ARDUINO_EVENT_ETH_START: + Serial.println("ETH Started"); + //set eth hostname here + ETH.setHostname("esp32-eth0"); + break; + case ARDUINO_EVENT_ETH_CONNECTED: + Serial.println("ETH Connected"); + break; + case ARDUINO_EVENT_ETH_GOT_IP: + Serial.printf("ETH Got IP: '%s'\n", esp_netif_get_desc(info.got_ip.esp_netif)); + ETH.printInfo(Serial); +#if USE_TWO_ETH_PORTS + ETH1.printInfo(Serial); +#endif + eth_connected = true; + break; + case ARDUINO_EVENT_ETH_LOST_IP: + Serial.println("ETH Lost IP"); + eth_connected = false; + break; + case ARDUINO_EVENT_ETH_DISCONNECTED: + Serial.println("ETH Disconnected"); + eth_connected = false; + break; + case ARDUINO_EVENT_ETH_STOP: + Serial.println("ETH Stopped"); + eth_connected = false; + break; + default: + break; + } +} + +void testClient(const char * host, uint16_t port) +{ + Serial.print("\nconnecting to "); + Serial.println(host); + + WiFiClient client; + if (!client.connect(host, port)) { + Serial.println("connection failed"); + return; + } + client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host); + while (client.connected() && !client.available()); + while (client.available()) { + Serial.write(client.read()); + } + + Serial.println("closing connection\n"); + client.stop(); +} + +void setup() +{ + Serial.begin(115200); + WiFi.onEvent(onEvent); + ETH.begin(ETH_TYPE, ETH_ADDR, ETH_CS, ETH_IRQ, ETH_RST, ETH_SPI_HOST, ETH_SPI_SCK, ETH_SPI_MISO, ETH_SPI_MOSI); +#if USE_TWO_ETH_PORTS + // Since SPI bus is shared, we should skip the SPI pins when calling ETH1.begin() + ETH1.begin(ETH1_TYPE, ETH1_ADDR, ETH1_CS, ETH1_IRQ, ETH1_RST, ETH_SPI_HOST); +#endif +} + + +void loop() +{ + if (eth_connected) { + testClient("google.com", 80); + } + delay(10000); +} diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index c50b3f3721e..ca439bee5ec 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -20,23 +20,17 @@ #include "ETH.h" #include "esp_system.h" -#if ESP_IDF_VERSION_MAJOR > 3 - #include "esp_event.h" - #include "esp_eth.h" - #include "esp_eth_mac.h" - #include "esp_eth_com.h" -#if CONFIG_IDF_TARGET_ESP32 - #include "soc/emac_ext_struct.h" - #include "soc/rtc.h" - //#include "soc/io_mux_reg.h" - //#include "hal/gpio_hal.h" -#endif - #include "esp32-hal-periman.h" -#else - #include "eth_phy/phy.h" - #include "eth_phy/phy_tlk110.h" - #include "eth_phy/phy_lan8720.h" -#endif +#include "esp_event.h" +#include "esp_eth.h" +#include "esp_eth_mac.h" +#include "esp_eth_com.h" +#include "driver/gpio.h" +#include "driver/spi_master.h" +#if CONFIG_ETH_USE_ESP32_EMAC +#include "soc/emac_ext_struct.h" +#include "soc/rtc.h" +#endif /* CONFIG_ETH_USE_ESP32_EMAC */ +#include "esp32-hal-periman.h" #include "lwip/err.h" #include "lwip/dns.h" #include "esp_mac.h" @@ -48,336 +42,167 @@ extern void tcpipInit(); extern void add_esp_interface_netif(esp_interface_t interface, esp_netif_t* esp_netif); /* from WiFiGeneric */ -#if ESP_IDF_VERSION_MAJOR > 3 - -/** -* @brief Callback function invoked when lowlevel initialization is finished -* -* @param[in] eth_handle: handle of Ethernet driver -* -* @return -* - ESP_OK: process extra lowlevel initialization successfully -* - ESP_FAIL: error occurred when processing extra lowlevel initialization -*/ - -static eth_clock_mode_t eth_clock_mode = ETH_CLK_MODE; - -#if CONFIG_ETH_RMII_CLK_INPUT -/* -static void emac_config_apll_clock(void) -{ - // apll_freq = xtal_freq * (4 + sdm2 + sdm1/256 + sdm0/65536)/((o_div + 2) * 2) - rtc_xtal_freq_t rtc_xtal_freq = rtc_clk_xtal_freq_get(); - switch (rtc_xtal_freq) { - case RTC_XTAL_FREQ_40M: // Recommended - // 50 MHz = 40MHz * (4 + 6) / (2 * (2 + 2) = 50.000 - // sdm0 = 0, sdm1 = 0, sdm2 = 6, o_div = 2 - rtc_clk_apll_enable(true, 0, 0, 6, 2); - break; - case RTC_XTAL_FREQ_26M: - // 50 MHz = 26MHz * (4 + 15 + 118 / 256 + 39/65536) / ((3 + 2) * 2) = 49.999992 - // sdm0 = 39, sdm1 = 118, sdm2 = 15, o_div = 3 - rtc_clk_apll_enable(true, 39, 118, 15, 3); - break; - case RTC_XTAL_FREQ_24M: - // 50 MHz = 24MHz * (4 + 12 + 255 / 256 + 255/65536) / ((2 + 2) * 2) = 49.499977 - // sdm0 = 255, sdm1 = 255, sdm2 = 12, o_div = 2 - rtc_clk_apll_enable(true, 255, 255, 12, 2); - break; - default: // Assume we have a 40M xtal - rtc_clk_apll_enable(true, 0, 0, 6, 2); - break; - } -} -*/ -#endif - -/* -static esp_err_t on_lowlevel_init_done(esp_eth_handle_t eth_handle){ -#if CONFIG_IDF_TARGET_ESP32 - if(eth_clock_mode > ETH_CLOCK_GPIO17_OUT){ - return ESP_FAIL; - } - // First deinit current config if different -#if CONFIG_ETH_RMII_CLK_INPUT - if(eth_clock_mode != ETH_CLOCK_GPIO0_IN && eth_clock_mode != ETH_CLOCK_GPIO0_OUT){ - pinMode(0, INPUT); - } -#endif - -#if CONFIG_ETH_RMII_CLK_OUTPUT -#if CONFIG_ETH_RMII_CLK_OUTPUT_GPIO0 - if(eth_clock_mode > ETH_CLOCK_GPIO0_OUT){ - pinMode(0, INPUT); - } -#elif CONFIG_ETH_RMII_CLK_OUT_GPIO == 16 - if(eth_clock_mode != ETH_CLOCK_GPIO16_OUT){ - pinMode(16, INPUT); - } -#elif CONFIG_ETH_RMII_CLK_OUT_GPIO == 17 - if(eth_clock_mode != ETH_CLOCK_GPIO17_OUT){ - pinMode(17, INPUT); - } -#endif -#endif - - // Setup interface for the correct pin -#if CONFIG_ETH_PHY_INTERFACE_MII - EMAC_EXT.ex_phyinf_conf.phy_intf_sel = 4; -#endif - if(eth_clock_mode == ETH_CLOCK_GPIO0_IN){ -#ifndef CONFIG_ETH_RMII_CLK_INPUT - // RMII clock (50MHz) input to GPIO0 - //gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_EMAC_TX_CLK); - //PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[0]); - pinMode(0, INPUT); - PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[0], 5); - EMAC_EXT.ex_clk_ctrl.ext_en = 1; - EMAC_EXT.ex_clk_ctrl.int_en = 0; - EMAC_EXT.ex_oscclk_conf.clk_sel = 1; +ETHClass::ETHClass(uint8_t eth_index) + :_eth_started(false) + ,_eth_handle(NULL) + ,_esp_netif(NULL) + ,_eth_index(eth_index) + ,_phy_type(ETH_PHY_MAX) +#if ETH_SPI_SUPPORTS_CUSTOM + ,_spi(NULL) #endif - } else { - if(eth_clock_mode == ETH_CLOCK_GPIO0_OUT){ -#ifndef CONFIG_ETH_RMII_CLK_OUTPUT_GPIO0 - // APLL clock output to GPIO0 (must be configured to 50MHz!) - //gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1); - //PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[0]); - pinMode(0, OUTPUT); - PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[0], 1); - // Choose the APLL clock to output on GPIO - REG_WRITE(PIN_CTRL, 6); -#endif - } else if(eth_clock_mode == ETH_CLOCK_GPIO16_OUT){ -#if CONFIG_ETH_RMII_CLK_OUT_GPIO != 16 - // RMII CLK (50MHz) output to GPIO16 - //gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO16_U, FUNC_GPIO16_EMAC_CLK_OUT); - //PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[16]); - pinMode(16, OUTPUT); - PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[16], 5); -#endif - } else if(eth_clock_mode == ETH_CLOCK_GPIO17_OUT){ -#if CONFIG_ETH_RMII_CLK_OUT_GPIO != 17 - // RMII CLK (50MHz) output to GPIO17 - //gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO17_U, FUNC_GPIO17_EMAC_CLK_OUT_180); - //PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[17]); - pinMode(17, OUTPUT); - PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[17], 5); -#endif - } -#if CONFIG_ETH_RMII_CLK_INPUT - EMAC_EXT.ex_clk_ctrl.ext_en = 0; - EMAC_EXT.ex_clk_ctrl.int_en = 1; - EMAC_EXT.ex_oscclk_conf.clk_sel = 0; - emac_config_apll_clock(); - EMAC_EXT.ex_clkout_conf.div_num = 0; - EMAC_EXT.ex_clkout_conf.h_div_num = 0; -#endif - } -#endif - return ESP_OK; -} -*/ - - -/** -* @brief Callback function invoked when lowlevel deinitialization is finished -* -* @param[in] eth_handle: handle of Ethernet driver -* -* @return -* - ESP_OK: process extra lowlevel deinitialization successfully -* - ESP_FAIL: error occurred when processing extra lowlevel deinitialization -*/ -//static esp_err_t on_lowlevel_deinit_done(esp_eth_handle_t eth_handle){ -// return ESP_OK; -//} - - - -#else -static int _eth_phy_mdc_pin = -1; -static int _eth_phy_mdio_pin = -1; -static int _eth_phy_power_pin = -1; -static eth_phy_power_enable_func _eth_phy_power_enable_orig = NULL; - -static void _eth_phy_config_gpio(void) -{ - if(_eth_phy_mdc_pin < 0 || _eth_phy_mdio_pin < 0){ - log_e("MDC and MDIO pins are not configured!"); - return; - } - phy_rmii_configure_data_interface_pins(); - phy_rmii_smi_configure_pins(_eth_phy_mdc_pin, _eth_phy_mdio_pin); -} - -static void _eth_phy_power_enable(bool enable) -{ - pinMode(_eth_phy_power_pin, OUTPUT); - digitalWrite(_eth_phy_power_pin, enable); - delay(1); -} -#endif - -ETHClass::ETHClass() - :initialized(false) - ,staticIP(false) -#if ESP_IDF_VERSION_MAJOR > 3 - ,eth_handle(NULL) -#endif - ,_started(false) -{ -} + ,_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) +#endif /* CONFIG_ETH_USE_ESP32_EMAC */ +{} ETHClass::~ETHClass() {} bool ETHClass::ethDetachBus(void * bus_pointer){ ETHClass *bus = (ETHClass *) bus_pointer; - if(bus->_started) { + if(bus->_eth_started){ bus->end(); } return true; } -bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t type, eth_clock_mode_t clock_mode, bool use_mac_from_efuse) +#if CONFIG_ETH_USE_ESP32_EMAC +bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, int power, eth_clock_mode_t clock_mode) { -#if ESP_IDF_VERSION_MAJOR > 3 - if(esp_netif != NULL){ + esp_err_t ret = ESP_OK; + if(_esp_netif != NULL){ return true; } perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET, ETHClass::ethDetachBus); - eth_clock_mode = clock_mode; tcpipInit(); - if (use_mac_from_efuse) - { - uint8_t p[6] = { 0x00,0x00,0x00,0x00,0x00,0x00 }; - esp_efuse_mac_get_custom(p); - esp_base_mac_addr_set(p); - } + 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 = mdc; + mac_config.smi_mdio_gpio_num = mdio; - //tcpip_adapter_set_default_eth_handlers(); - - esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH(); - esp_netif = esp_netif_new(&cfg); + _pin_mcd = mdc; + _pin_mdio = mdio; + _pin_rmii_clock = mac_config.clock_config.rmii.clock_gpio; + _pin_power = power; - esp_eth_mac_t *eth_mac = NULL; -#if CONFIG_ETH_SPI_ETHERNET_DM9051 - if(type == ETH_PHY_DM9051){ - return false;//todo - } else { -#endif -#if CONFIG_ETH_USE_ESP32_EMAC - eth_esp32_emac_config_t mac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); - mac_config.clock_config.rmii.clock_mode = (eth_clock_mode) ? EMAC_CLK_OUT : EMAC_CLK_EXT_IN; - mac_config.clock_config.rmii.clock_gpio = (1 == eth_clock_mode) ? EMAC_APPL_CLK_OUT_GPIO : (2 == eth_clock_mode) ? EMAC_CLK_OUT_GPIO : (3 == eth_clock_mode) ? EMAC_CLK_OUT_180_GPIO : EMAC_CLK_IN_GPIO; - mac_config.smi_mdc_gpio_num = mdc; - mac_config.smi_mdio_gpio_num = mdio; - - _pin_mcd = mdc; - _pin_mdio = mdio; - _pin_rmii_clock = mac_config.clock_config.rmii.clock_gpio; - - if(!perimanSetPinBus(_pin_rmii_clock, ESP32_BUS_TYPE_INIT, NULL)){ return false; } - if(!perimanSetPinBus(_pin_mcd, ESP32_BUS_TYPE_INIT, NULL)){ return false; } - if(!perimanSetPinBus(_pin_mdio, ESP32_BUS_TYPE_INIT, NULL)){ return false; } - - eth_mac_config_t eth_mac_config = ETH_MAC_DEFAULT_CONFIG(); - eth_mac_config.sw_reset_timeout_ms = 1000; - - eth_mac = esp_eth_mac_new_esp32(&mac_config, ð_mac_config); - - if(!perimanSetPinBus(ETH_RMII_TX_EN, ESP32_BUS_TYPE_INIT, NULL)){ return false; } - if(!perimanSetPinBus(ETH_RMII_TX0, ESP32_BUS_TYPE_INIT, NULL)){ return false; } - if(!perimanSetPinBus(ETH_RMII_TX1, ESP32_BUS_TYPE_INIT, NULL)){ return false; } - if(!perimanSetPinBus(ETH_RMII_RX0, ESP32_BUS_TYPE_INIT, NULL)){ return false; } - if(!perimanSetPinBus(ETH_RMII_RX1_EN, ESP32_BUS_TYPE_INIT, NULL)){ return false; } - if(!perimanSetPinBus(ETH_RMII_CRS_DV, ESP32_BUS_TYPE_INIT, NULL)){ return false; } -#endif -#if CONFIG_ETH_SPI_ETHERNET_DM9051 + if(!perimanSetPinBus(_pin_rmii_clock, ESP32_BUS_TYPE_INIT, NULL)){ return false; } + if(!perimanSetPinBus(_pin_mcd, ESP32_BUS_TYPE_INIT, NULL)){ return false; } + if(!perimanSetPinBus(_pin_mdio, ESP32_BUS_TYPE_INIT, NULL)){ return false; } + if(!perimanSetPinBus(ETH_RMII_TX_EN, ESP32_BUS_TYPE_INIT, NULL)){ return false; } + if(!perimanSetPinBus(ETH_RMII_TX0, ESP32_BUS_TYPE_INIT, NULL)){ return false; } + if(!perimanSetPinBus(ETH_RMII_TX1, ESP32_BUS_TYPE_INIT, NULL)){ return false; } + if(!perimanSetPinBus(ETH_RMII_RX0, ESP32_BUS_TYPE_INIT, NULL)){ return false; } + if(!perimanSetPinBus(ETH_RMII_RX1_EN, ESP32_BUS_TYPE_INIT, NULL)){ return false; } + if(!perimanSetPinBus(ETH_RMII_CRS_DV, ESP32_BUS_TYPE_INIT, NULL)){ return false; } + if(_pin_power != -1){ + if(!perimanSetPinBus(_pin_power, ESP32_BUS_TYPE_INIT, NULL)){ return false; } } -#endif - if(eth_mac == NULL){ + 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; } - _pin_power = power; - if(_pin_power != -1){ - if(!perimanSetPinBus(_pin_power, ESP32_BUS_TYPE_INIT, NULL)){ return false; } - } - eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); phy_config.phy_addr = phy_addr; phy_config.reset_gpio_num = power; - esp_eth_phy_t *eth_phy = NULL; + esp_eth_phy_t *phy = NULL; switch(type){ case ETH_PHY_LAN8720: - eth_phy = esp_eth_phy_new_lan87xx(&phy_config); + phy = esp_eth_phy_new_lan87xx(&phy_config); break; case ETH_PHY_TLK110: - eth_phy = esp_eth_phy_new_ip101(&phy_config); + phy = esp_eth_phy_new_ip101(&phy_config); break; case ETH_PHY_RTL8201: - eth_phy = esp_eth_phy_new_rtl8201(&phy_config); + phy = esp_eth_phy_new_rtl8201(&phy_config); break; case ETH_PHY_DP83848: - eth_phy = esp_eth_phy_new_dp83848(&phy_config); - break; -#if CONFIG_ETH_SPI_ETHERNET_DM9051 - case ETH_PHY_DM9051: - eth_phy = esp_eth_phy_new_dm9051(&phy_config); + phy = esp_eth_phy_new_dp83848(&phy_config); break; -#endif case ETH_PHY_KSZ8041: -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4,4,0) - eth_phy = esp_eth_phy_new_ksz80xx(&phy_config); -#else - log_e("unsupported ethernet type 'ETH_PHY_KSZ8041'"); -#endif + phy = esp_eth_phy_new_ksz80xx(&phy_config); break; case ETH_PHY_KSZ8081: -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4,4,0) - eth_phy = esp_eth_phy_new_ksz80xx(&phy_config); -#else - log_e("unsupported ethernet type 'ETH_PHY_KSZ8081'"); -#endif + phy = esp_eth_phy_new_ksz80xx(&phy_config); break; default: + log_e("Unsupported PHY %d", type); break; } - if(eth_phy == NULL){ + if(phy == NULL){ log_e("esp_eth_phy_new failed"); return false; } - eth_handle = NULL; - esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(eth_mac, eth_phy); - //eth_config.on_lowlevel_init_done = on_lowlevel_init_done; - //eth_config.on_lowlevel_deinit_done = on_lowlevel_deinit_done; - if(esp_eth_driver_install(ð_config, ð_handle) != ESP_OK || eth_handle == NULL){ - log_e("esp_eth_driver_install failed"); + _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("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_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); + 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 */ - if(esp_netif_attach(esp_netif, esp_eth_new_netif_glue(eth_handle)) != ESP_OK){ - log_e("esp_netif_attach failed"); + 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 WiFiGeneric to receive events */ - add_esp_interface_netif(ESP_IF_ETH, esp_netif); + add_esp_interface_netif(ESP_IF_ETH, _esp_netif); - if(esp_eth_start(eth_handle) != ESP_OK){ - log_e("esp_eth_start failed"); + ret = esp_eth_start(_eth_handle); + if(ret != ESP_OK){ + log_e("esp_eth_start failed: %d", ret); return false; } - _started = true; + _eth_started = true; if(!perimanSetPinBus(_pin_rmii_clock, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; } if(!perimanSetPinBus(_pin_mcd, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; } @@ -393,70 +218,378 @@ bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_typ if(_pin_power != -1){ if(!perimanSetPinBus(_pin_power, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; } } -#else - esp_err_t err; - if(initialized){ - err = esp_eth_enable(); - if(err){ - log_e("esp_eth_enable error: %d", err); - return false; + // 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); + + return true; + +err: + 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 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_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); + +#if CONFIG_ETH_SPI_ETHERNET_DM9051 + 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 +#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; + } + _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); + +#if CONFIG_ETH_SPI_ETHERNET_DM9051 + 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 +#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); } - _started = true; + } else +#endif + { + log_e("Unsupported PHY module: %d", _phy_type); + digitalWrite(_pin_cs, HIGH); + _spi->endTransaction(); + 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, uint8_t phy_addr, int cs, int irq, int rst, +#if ETH_SPI_SUPPORTS_CUSTOM + 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; + + if(_eth_started || _esp_netif != NULL || _eth_handle != NULL){ + log_w("ETH Already Started"); return true; } - _eth_phy_mdc_pin = mdc; - _eth_phy_mdio_pin = mdio; - _eth_phy_power_pin = power; - - if(type == ETH_PHY_LAN8720){ - eth_config_t config = phy_lan8720_default_ethernet_config; - memcpy(ð_config, &config, sizeof(eth_config_t)); - } else if(type == ETH_PHY_TLK110){ - eth_config_t config = phy_tlk110_default_ethernet_config; - memcpy(ð_config, &config, sizeof(eth_config_t)); - } else if(type == ETH_PHY_IP101) { - eth_config_t config = phy_ip101_default_ethernet_config; - memcpy(ð_config, &config, sizeof(eth_config_t)); - } else { - log_e("Bad ETH_PHY type: %u", (uint8_t)type); + if(cs < 0 || irq < 0){ + log_e("CS and IRQ pins must be defined!"); return false; } - eth_config.phy_addr = (eth_phy_base_t)phy_addr; - eth_config.clock_mode = clock_mode; - eth_config.gpio_config = _eth_phy_config_gpio; - eth_config.tcpip_input = tcpip_adapter_eth_input; - if(_eth_phy_power_pin >= 0){ - _eth_phy_power_enable_orig = eth_config.phy_power_enable; - eth_config.phy_power_enable = _eth_phy_power_enable; + perimanSetBusDeinit(ESP32_BUS_TYPE_ETHERNET, ETHClass::ethDetachBus); + + if(_pin_cs != -1){ + if(!perimanSetPinBus(_pin_cs, ESP32_BUS_TYPE_INIT, NULL)){ return false; } + } + if(_pin_rst != -1){ + if(!perimanSetPinBus(_pin_rst, ESP32_BUS_TYPE_INIT, NULL)){ return false; } + } + if(_pin_irq != -1){ + if(!perimanSetPinBus(_pin_irq, ESP32_BUS_TYPE_INIT, NULL)){ return false; } + } + if(_pin_sck != -1){ + if(!perimanSetPinBus(_pin_sck, ESP32_BUS_TYPE_INIT, NULL)){ return false; } + } + if(_pin_miso != -1){ + if(!perimanSetPinBus(_pin_miso, ESP32_BUS_TYPE_INIT, NULL)){ return false; } + } + if(_pin_mosi != -1){ + if(!perimanSetPinBus(_pin_mosi, ESP32_BUS_TYPE_INIT, NULL)){ return false; } + } + +#if ETH_SPI_SUPPORTS_CUSTOM + _spi = spi; +#endif + if(spi_freq_mhz){ + _spi_freq_mhz = spi_freq_mhz; + } + _phy_type = type; + _pin_cs = cs; + _pin_irq = irq; + _pin_rst = rst; + _pin_sck = sck; + _pin_miso = miso; + _pin_mosi = mosi; + +#if ETH_SPI_SUPPORTS_CUSTOM + if(_spi != NULL){ + pinMode(_pin_cs, OUTPUT); + digitalWrite(_pin_cs, HIGH); + } +#endif + + // Init SPI bus + if(_pin_sck >= 0 && _pin_miso >= 0 && _pin_mosi >= 0){ + spi_bus_config_t buscfg = { + .mosi_io_num = _pin_mosi, + .miso_io_num = _pin_miso, + .sclk_io_num = _pin_sck, + .quadwp_io_num = -1, + .quadhd_io_num = -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; + } } tcpipInit(); - if (use_mac_from_efuse) - { - uint8_t p[6] = { 0x00,0x00,0x00,0x00,0x00,0x00 }; - esp_efuse_mac_get_custom(p); - esp_base_mac_addr_set(p); + // 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; } - err = esp_eth_init(ð_config); - if(!err){ - initialized = true; - err = esp_eth_enable(); - if(err){ - log_e("esp_eth_enable error: %d", err); - } else { - _started = true; - return true; + // 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 = { + .mode = 0, + .clock_speed_hz = _spi_freq_mhz * 1000 * 1000, + .input_delay_ns = 20, + .spics_io_num = _pin_cs, + .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 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; } - } else { - log_e("esp_eth_init error: %d", err); +#endif + 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 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; + } +#endif + 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 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; + } +#endif + 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); + 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; + } + + // attach to WiFiGeneric to receive events + add_esp_interface_netif(ESP_IF_ETH, _esp_netif); + + // 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; + } + + _eth_started = true; + + // If Arduino's SPI is used, cs pin is in GPIO mode +#if ETH_SPI_SUPPORTS_CUSTOM + if(_spi == NULL){ #endif - // 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); + if(!perimanSetPinBus(_pin_cs, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; } +#if ETH_SPI_SUPPORTS_CUSTOM + } +#endif + if(!perimanSetPinBus(_pin_irq, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; } + + if(_pin_sck != -1){ + if(!perimanSetPinBus(_pin_sck, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; } + } + if(_pin_miso != -1){ + if(!perimanSetPinBus(_pin_miso, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; } + } + if(_pin_mosi != -1){ + if(!perimanSetPinBus(_pin_mosi, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; } + } + if(_pin_rst != -1){ + if(!perimanSetPinBus(_pin_rst, ESP32_BUS_TYPE_ETHERNET, (void *)(this))){ goto err; } + } return true; @@ -466,57 +599,149 @@ bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_typ return false; } +#if ETH_SPI_SUPPORTS_CUSTOM +bool ETHClass::begin(eth_phy_type_t type, uint8_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); +} +#endif + +bool ETHClass::begin(eth_phy_type_t type, uint8_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, +#endif + sck, miso, mosi, spi_host, spi_freq_mhz); +} + +void ETHClass::end(void) +{ + _eth_started = false; + + if(_esp_netif != NULL){ + esp_netif_destroy(_esp_netif); + _esp_netif = NULL; + } + + 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; +#endif + +#if CONFIG_ETH_USE_ESP32_EMAC + if(_pin_rmii_clock != -1 && _pin_mcd != -1 && _pin_mdio != -1){ + perimanSetPinBus(_pin_rmii_clock, ESP32_BUS_TYPE_INIT, NULL); + perimanSetPinBus(_pin_mcd, ESP32_BUS_TYPE_INIT, NULL); + perimanSetPinBus(_pin_mdio, ESP32_BUS_TYPE_INIT, NULL); + + perimanSetPinBus(ETH_RMII_TX_EN, ESP32_BUS_TYPE_INIT, NULL); + perimanSetPinBus(ETH_RMII_TX0, ESP32_BUS_TYPE_INIT, NULL); + perimanSetPinBus(ETH_RMII_TX1, ESP32_BUS_TYPE_INIT, NULL); + perimanSetPinBus(ETH_RMII_RX0, ESP32_BUS_TYPE_INIT, NULL); + perimanSetPinBus(ETH_RMII_RX1_EN, ESP32_BUS_TYPE_INIT, NULL); + perimanSetPinBus(ETH_RMII_CRS_DV, ESP32_BUS_TYPE_INIT, NULL); + + _pin_rmii_clock = -1; + _pin_mcd = -1; + _pin_mdio = -1; + } + + if(_pin_power != -1){ + perimanSetPinBus(_pin_power, ESP32_BUS_TYPE_INIT, NULL); + _pin_power = -1; + } +#endif /* CONFIG_ETH_USE_ESP32_EMAC */ + if(_pin_cs != -1){ + perimanSetPinBus(_pin_cs, ESP32_BUS_TYPE_INIT, NULL); + _pin_cs = -1; + } + if(_pin_irq != -1){ + perimanSetPinBus(_pin_irq, ESP32_BUS_TYPE_INIT, NULL); + _pin_irq = -1; + } + if(_pin_sck != -1){ + perimanSetPinBus(_pin_sck, ESP32_BUS_TYPE_INIT, NULL); + _pin_sck = -1; + } + if(_pin_miso != -1){ + perimanSetPinBus(_pin_miso, ESP32_BUS_TYPE_INIT, NULL); + _pin_miso = -1; + } + if(_pin_mosi != -1){ + perimanSetPinBus(_pin_mosi, ESP32_BUS_TYPE_INIT, NULL); + _pin_mosi = -1; + } + if(_pin_rst != -1){ + perimanSetPinBus(_pin_rst, ESP32_BUS_TYPE_INIT, NULL); + _pin_rst = -1; + } +} + bool ETHClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2) { + 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; + d1.ip.type = IPADDR_TYPE_V4; + d2.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); } 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; } - err = esp_netif_dhcpc_stop(esp_netif); + // 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: %d", err); return false; } - err = esp_netif_set_ip_info(esp_netif, &info); + // 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: %d", err); return false; } - if(info.ip.addr){ - staticIP = true; - } else { - err = esp_netif_dhcpc_start(esp_netif); + // Set DNS1-Server + esp_netif_set_dns_info(_esp_netif, ESP_NETIF_DNS_MAIN, &d1); + + // Set DNS2-Server + esp_netif_set_dns_info(_esp_netif, ESP_NETIF_DNS_BACKUP, &d2); + + // 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: %d", err); return false; } - staticIP = false; - } - - esp_netif_dns_info_t d; - d.ip.type = IPADDR_TYPE_V4; - - if(static_cast(dns1) != 0) { - // Set DNS1-Server - d.ip.u_addr.ip4.addr = static_cast(dns1); - esp_netif_set_dns_info(esp_netif, ESP_NETIF_DNS_MAIN, &d); - } - - if(static_cast(dns2) != 0) { - // Set DNS2-Server - d.ip.u_addr.ip4.addr = static_cast(dns2); - esp_netif_set_dns_info(esp_netif, ESP_NETIF_DNS_BACKUP, &d); } return true; @@ -524,8 +749,11 @@ bool ETHClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, I IPAddress ETHClass::localIP() { + if(_esp_netif == NULL){ + return IPAddress(); + } esp_netif_ip_info_t ip; - if(esp_netif_get_ip_info(esp_netif, &ip)){ + if(esp_netif_get_ip_info(_esp_netif, &ip)){ return IPAddress(); } return IPAddress(ip.ip.addr); @@ -533,8 +761,11 @@ IPAddress ETHClass::localIP() IPAddress ETHClass::subnetMask() { + if(_esp_netif == NULL){ + return IPAddress(); + } esp_netif_ip_info_t ip; - if(esp_netif_get_ip_info(esp_netif, &ip)){ + if(esp_netif_get_ip_info(_esp_netif, &ip)){ return IPAddress(); } return IPAddress(ip.netmask.addr); @@ -542,8 +773,11 @@ IPAddress ETHClass::subnetMask() IPAddress ETHClass::gatewayIP() { + if(_esp_netif == NULL){ + return IPAddress(); + } esp_netif_ip_info_t ip; - if(esp_netif_get_ip_info(esp_netif, &ip)){ + if(esp_netif_get_ip_info(_esp_netif, &ip)){ return IPAddress(); } return IPAddress(ip.gw.addr); @@ -551,8 +785,11 @@ IPAddress ETHClass::gatewayIP() IPAddress ETHClass::dnsIP(uint8_t dns_no) { + 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){ + if(esp_netif_get_dns_info(_esp_netif, dns_no?ESP_NETIF_DNS_BACKUP:ESP_NETIF_DNS_MAIN, &d) != ESP_OK){ return IPAddress(); } return IPAddress(d.ip.u_addr.ip4.addr); @@ -560,8 +797,11 @@ IPAddress ETHClass::dnsIP(uint8_t dns_no) IPAddress ETHClass::broadcastIP() { + if(_esp_netif == NULL){ + return IPAddress(); + } esp_netif_ip_info_t ip; - if(esp_netif_get_ip_info(esp_netif, &ip)){ + if(esp_netif_get_ip_info(_esp_netif, &ip)){ return IPAddress(); } return WiFiGenericClass::calculateBroadcast(IPAddress(ip.gw.addr), IPAddress(ip.netmask.addr)); @@ -569,8 +809,11 @@ IPAddress ETHClass::broadcastIP() IPAddress ETHClass::networkID() { + if(_esp_netif == NULL){ + return IPAddress(); + } esp_netif_ip_info_t ip; - if(esp_netif_get_ip_info(esp_netif, &ip)){ + if(esp_netif_get_ip_info(_esp_netif, &ip)){ return IPAddress(); } return WiFiGenericClass::calculateNetworkID(IPAddress(ip.gw.addr), IPAddress(ip.netmask.addr)); @@ -578,8 +821,11 @@ IPAddress ETHClass::networkID() uint8_t ETHClass::subnetCIDR() { + if(_esp_netif == NULL){ + return (uint8_t)0; + } esp_netif_ip_info_t ip; - if(esp_netif_get_ip_info(esp_netif, &ip)){ + if(esp_netif_get_ip_info(_esp_netif, &ip)){ return (uint8_t)0; } return WiFiGenericClass::calculateSubnetCIDR(IPAddress(ip.netmask.addr)); @@ -587,8 +833,11 @@ uint8_t ETHClass::subnetCIDR() const char * ETHClass::getHostname() { + if(_esp_netif == NULL){ + return ""; + } const char * hostname; - if(esp_netif_get_hostname(esp_netif, &hostname)){ + if(esp_netif_get_hostname(_esp_netif, &hostname)){ return NULL; } return hostname; @@ -596,64 +845,129 @@ const char * ETHClass::getHostname() bool ETHClass::setHostname(const char * hostname) { - return esp_netif_set_hostname(esp_netif, hostname) == 0; + if(_esp_netif == NULL){ + return false; + } + return esp_netif_set_hostname(_esp_netif, hostname) == 0; } -bool ETHClass::fullDuplex() +bool ETHClass::enableIpV6() { -#if ESP_IDF_VERSION_MAJOR > 3 - eth_duplex_t link_duplex; - esp_eth_ioctl(eth_handle, ETH_CMD_G_DUPLEX_MODE, &link_duplex); - return (link_duplex == ETH_DUPLEX_FULL); -#else - return eth_config.phy_get_duplex_mode(); -#endif + if(_esp_netif == NULL){ + return false; + } + return esp_netif_create_ip6_linklocal(_esp_netif) == 0; } -bool ETHClass::linkUp() +IPv6Address ETHClass::localIPv6() +{ + if(_esp_netif == NULL){ + return IPv6Address(); + } + static esp_ip6_addr_t addr; + if(esp_netif_get_ip6_linklocal(_esp_netif, &addr)){ + return IPv6Address(); + } + return IPv6Address(addr.addr); +} + +const char * ETHClass::ifkey(void) +{ + if(_esp_netif == NULL){ + return ""; + } + return esp_netif_get_ifkey(_esp_netif); +} + +const char * ETHClass::desc(void) +{ + if(_esp_netif == NULL){ + return ""; + } + return esp_netif_get_desc(_esp_netif); +} + +String ETHClass::impl_name(void) +{ + 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); +} + +bool ETHClass::connected() { -#if ESP_IDF_VERSION_MAJOR > 3 return WiFiGenericClass::getStatusBits() & ETH_CONNECTED_BIT; -#else - return eth_config.phy_check_link(); -#endif } -uint8_t ETHClass::linkSpeed() +bool ETHClass::hasIP() { -#if ESP_IDF_VERSION_MAJOR > 3 - eth_speed_t link_speed; - esp_eth_ioctl(eth_handle, ETH_CMD_G_SPEED, &link_speed); - return (link_speed == ETH_SPEED_10M)?10:100; -#else - return eth_config.phy_get_speed_mode()?100:10; -#endif + return WiFiGenericClass::getStatusBits() & ETH_HAS_IP_BIT; } -bool ETHClass::enableIpV6() +bool ETHClass::linkUp() { - return esp_netif_create_ip6_linklocal(esp_netif) == 0; + if(_esp_netif == NULL){ + return false; + } + return esp_netif_is_netif_up(_esp_netif); } -IPv6Address ETHClass::localIPv6() +bool ETHClass::fullDuplex() { - static esp_ip6_addr_t addr; - if(esp_netif_get_ip6_linklocal(esp_netif, &addr)){ - return IPv6Address(); + if(_eth_handle == NULL){ + return false; } - return IPv6Address(addr.addr); + 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() +{ + 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() +{ + 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() +{ + 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::macAddress(uint8_t* mac) { + if(_eth_handle == NULL){ + return NULL; + } if(!mac){ return NULL; } -#ifdef ESP_IDF_VERSION_MAJOR - esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac); -#else - esp_eth_get_mac(mac); -#endif + esp_eth_ioctl(_eth_handle, ETH_CMD_G_MAC_ADDR, mac); return mac; } @@ -666,36 +980,48 @@ String ETHClass::macAddress(void) return String(macStr); } -#if ESP_IDF_VERSION_MAJOR > 3 - -void ETHClass::end(void) -{ - if(esp_eth_stop(eth_handle) != ESP_OK) { - log_e("Failed to stop Ehternet"); - return; +void ETHClass::printInfo(Print & out){ + out.print(desc()); + out.print(":"); + if(linkUp()){ + out.print(" "); + + out.print(" "); + out.print("ether "); + out.print(macAddress()); + out.printf(" phy 0x%lX", phyAddr()); + out.println(); + + out.print(" "); + out.print("inet "); + out.print(localIP()); + out.print(" netmask "); + out.print(subnetMask()); + out.print(" broadcast "); + out.print(broadcastIP()); + out.println(); + + out.print(" "); + out.print("gateway "); + out.print(gatewayIP()); + out.print(" dns "); + out.print(dnsIP()); + out.println(); + + out.println(); } -#endif - ETHClass ETH; diff --git a/libraries/Ethernet/src/ETH.h b/libraries/Ethernet/src/ETH.h index 31981ec2198..7ef39ef561f 100644 --- a/libraries/Ethernet/src/ETH.h +++ b/libraries/Ethernet/src/ETH.h @@ -21,11 +21,59 @@ #ifndef _ETH_H_ #define _ETH_H_ +// +// Example configurations for pins_arduino.h to allow starting with ETH.begin(); +// + +// // Example RMII LAN8720 (Olimex, etc.) +// #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 + +// // Example RMII ESP32_Ethernet_V4 +// #define ETH_PHY_TYPE ETH_PHY_TLK110 +// #define ETH_PHY_ADDR 1 +// #define ETH_PHY_MDC 23 +// #define ETH_PHY_MDIO 18 +// #define ETH_PHY_POWER -1 +// #define ETH_CLK_MODE ETH_CLOCK_GPIO0_OUT + +// // Example SPI using ESP-IDF's driver +// #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 + +// // Example SPI using Arduino's driver +// #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 SPI + +// This will be uncommented once custom SPI support is available in ESP-IDF +#define ETH_SPI_SUPPORTS_CUSTOM 1 + #include "WiFi.h" +#if ETH_SPI_SUPPORTS_CUSTOM +#include "SPI.h" +#endif #include "esp_system.h" #include "esp_eth.h" #include "esp_netif.h" +#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; //Dedicated GPIOs for RMII #define ETH_RMII_TX_EN 21 #define ETH_RMII_TX0 19 @@ -33,94 +81,137 @@ #define ETH_RMII_RX0 25 #define ETH_RMII_RX1_EN 26 #define ETH_RMII_CRS_DV 27 - -#ifndef ETH_PHY_ADDR -#define ETH_PHY_ADDR 0 -#endif - -#ifndef ETH_PHY_TYPE -#define ETH_PHY_TYPE ETH_PHY_LAN8720 -#endif - -#ifndef ETH_PHY_POWER -#define ETH_PHY_POWER -1 -#endif - -#ifndef ETH_PHY_MDC -#define ETH_PHY_MDC 23 -#endif - -#ifndef ETH_PHY_MDIO -#define ETH_PHY_MDIO 18 +#endif /* CONFIG_ETH_USE_ESP32_EMAC */ + +#ifndef ETH_PHY_SPI_FREQ_MHZ +#define ETH_PHY_SPI_FREQ_MHZ 20 +#endif /* ETH_PHY_SPI_FREQ_MHZ */ + +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, +#endif /* CONFIG_ETH_USE_ESP32_EMAC */ +#if CONFIG_ETH_SPI_ETHERNET_DM9051 + ETH_PHY_DM9051, #endif - -#ifndef ETH_CLK_MODE -#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN +#if CONFIG_ETH_SPI_ETHERNET_W5500 + ETH_PHY_W5500, #endif - -#if ESP_IDF_VERSION_MAJOR > 3 -typedef enum { ETH_CLOCK_GPIO0_IN, ETH_CLOCK_GPIO0_OUT, ETH_CLOCK_GPIO16_OUT, ETH_CLOCK_GPIO17_OUT } eth_clock_mode_t; +#if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL + ETH_PHY_KSZ8851, #endif - -typedef enum { ETH_PHY_LAN8720, ETH_PHY_TLK110, ETH_PHY_RTL8201, ETH_PHY_DP83848, ETH_PHY_DM9051, ETH_PHY_KSZ8041, ETH_PHY_KSZ8081, ETH_PHY_MAX } eth_phy_type_t; -#define ETH_PHY_IP101 ETH_PHY_TLK110 + ETH_PHY_MAX +} eth_phy_type_t; class ETHClass { - private: - bool initialized; - bool staticIP; -#if ESP_IDF_VERSION_MAJOR > 3 - esp_eth_handle_t eth_handle; - esp_netif_t *esp_netif; - - protected: - bool _started; - int8_t _pin_mcd = -1; - int8_t _pin_mdio = -1; - int8_t _pin_power = -1; - int8_t _pin_rmii_clock = -1; - static void eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data); -#else - bool _started; - eth_config_t eth_config; -#endif public: - ETHClass(); + ETHClass(uint8_t eth_index=0); ~ETHClass(); - bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE, bool use_mac_from_efuse=false); +#if CONFIG_ETH_USE_ESP32_EMAC + bool begin(eth_phy_type_t type, uint8_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, uint8_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, uint8_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(){ +#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 +#endif + return false; + } - bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000); + void end(); + // Netif APIs + esp_netif_t * netif(void){ return _esp_netif; } + 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); const char * getHostname(); bool setHostname(const char * hostname); - - bool fullDuplex(); - bool linkUp(); - uint8_t linkSpeed(); - - bool enableIpV6(); - IPv6Address localIPv6(); - IPAddress localIP(); IPAddress subnetMask(); IPAddress gatewayIP(); IPAddress dnsIP(uint8_t dns_no = 0); - IPAddress broadcastIP(); IPAddress networkID(); uint8_t subnetCIDR(); + bool enableIpV6(); + IPv6Address localIPv6(); + const char * ifkey(void); + const char * desc(void); + String impl_name(void); + + // Event based getters + bool connected(); + bool hasIP(); + // ETH Handle APIs uint8_t * macAddress(uint8_t* mac); String macAddress(); + bool fullDuplex(); + bool linkUp(); + uint8_t linkSpeed(); + bool autoNegotiation(); + uint32_t phyAddr(); - void end(); + // Info APIs + void printInfo(Print & out); friend class WiFiClient; friend class WiFiServer; +#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); +#endif + + 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); +#endif + + static void eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data); + private: + bool _eth_started; + esp_eth_handle_t _eth_handle; + esp_netif_t *_esp_netif; + uint8_t _eth_index; + eth_phy_type_t _phy_type; +#if ETH_SPI_SUPPORTS_CUSTOM + 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; +#if CONFIG_ETH_USE_ESP32_EMAC + 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, uint8_t phy_addr, int cs, int irq, int rst, +#if ETH_SPI_SUPPORTS_CUSTOM + SPIClass * spi, +#endif + int sck, int miso, int mosi, spi_host_device_t spi_host, uint8_t spi_freq_mhz); }; extern ETHClass ETH; diff --git a/libraries/WiFi/src/WiFiGeneric.cpp b/libraries/WiFi/src/WiFiGeneric.cpp index 7c8629b3c45..733b90ad525 100644 --- a/libraries/WiFi/src/WiFiGeneric.cpp +++ b/libraries/WiFi/src/WiFiGeneric.cpp @@ -444,10 +444,13 @@ static void _arduino_event_cb(void* arg, esp_event_base_t event_base, int32_t ev } else if (event_base == IP_EVENT && event_id == IP_EVENT_ETH_GOT_IP) { #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; - log_v("Ethernet got %sip:" IPSTR, event->ip_changed?"new":"", IP2STR(&event->ip_info.ip)); + log_v("Ethernet got %sip:" IPSTR, event->ip_changed?"new ":"", IP2STR(&event->ip_info.ip)); #endif arduino_event.event_id = ARDUINO_EVENT_ETH_GOT_IP; memcpy(&arduino_event.event_info.got_ip, event_data, sizeof(ip_event_got_ip_t)); + } else if (event_base == ETH_EVENT && event_id == IP_EVENT_ETH_LOST_IP) { + log_v("Ethernet Lost IP"); + arduino_event.event_id = ARDUINO_EVENT_ETH_LOST_IP; /* * IPv6 @@ -870,6 +873,7 @@ const char * WiFiGenericClass::eventName(arduino_event_id_t id) { 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_WPS_ER_SUCCESS: return "WPS_ER_SUCCESS"; case ARDUINO_EVENT_WPS_ER_FAILED: return "WPS_ER_FAILED"; @@ -1137,6 +1141,8 @@ esp_err_t WiFiGenericClass::_eventCallback(arduino_event_t *event) gw[0], gw[1], gw[2], gw[3]); #endif setStatusBits(ETH_CONNECTED_BIT | ETH_HAS_IP_BIT); + } else if(event->event_id == ARDUINO_EVENT_ETH_LOST_IP) { + clearStatusBits(ETH_HAS_IP_BIT); } else if(event->event_id == ARDUINO_EVENT_WIFI_STA_GOT_IP6) { setStatusBits(STA_CONNECTED_BIT | STA_HAS_IP6_BIT); diff --git a/libraries/WiFi/src/WiFiGeneric.h b/libraries/WiFi/src/WiFiGeneric.h index 25fa1b2937e..38396f5a72e 100644 --- a/libraries/WiFi/src/WiFiGeneric.h +++ b/libraries/WiFi/src/WiFiGeneric.h @@ -59,6 +59,7 @@ typedef enum { 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_WPS_ER_SUCCESS, ARDUINO_EVENT_WPS_ER_FAILED, From 9a28c93bcac00ed4dd7d9692507c0db0e3055e49 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Fri, 6 Oct 2023 13:48:17 +0300 Subject: [PATCH 08/18] Add support for custom panic handler (#8711) * Add support for custom panic handler * Resolve comments --- cores/esp32/esp32-hal-misc.c | 90 ++++++++++++++++++++++++++++++++++++ cores/esp32/esp32-hal.h | 16 +++++++ platform.txt | 2 +- 3 files changed, 107 insertions(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-misc.c b/cores/esp32/esp32-hal-misc.c index 6a7931117ad..ae1083c9a7a 100644 --- a/cores/esp32/esp32-hal-misc.c +++ b/cores/esp32/esp32-hal-misc.c @@ -322,3 +322,93 @@ const char * ARDUINO_ISR_ATTR pathToFileName(const char * path) return path+pos; } +#include "esp_rom_sys.h" +#include "esp_debug_helpers.h" +#if CONFIG_IDF_TARGET_ARCH_XTENSA +#include "esp_cpu_utils.h" +#else +#include "riscv/rvruntime-frames.h" +#endif +#include "esp_memory_utils.h" +#include "esp_private/panic_internal.h" + +static arduino_panic_handler_t _panic_handler = 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; +} + +arduino_panic_handler_t get_arduino_panic_handler(void){ + return _panic_handler; +} + +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; + +#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; + } + } + } + + 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; + } + } + } +#endif + _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); +} diff --git a/cores/esp32/esp32-hal.h b/cores/esp32/esp32-hal.h index f71788e9399..2f53bb2ff66 100644 --- a/cores/esp32/esp32-hal.h +++ b/cores/esp32/esp32-hal.h @@ -137,6 +137,22 @@ void arduino_phy_init(); 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); + #ifdef __cplusplus } #endif diff --git a/platform.txt b/platform.txt index c345b941017..cf87e2ea7b2 100644 --- a/platform.txt +++ b/platform.txt @@ -70,7 +70,7 @@ compiler.size.cmd={compiler.prefix}size compiler.c.extra_flags=-MMD -c compiler.cpp.extra_flags=-MMD -c compiler.S.extra_flags=-MMD -c -x assembler-with-cpp -compiler.c.elf.extra_flags="-Wl,--Map={build.path}/{build.project_name}.map" "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-L{compiler.sdk.path}/{build.memory_type}" +compiler.c.elf.extra_flags="-Wl,--Map={build.path}/{build.project_name}.map" "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-L{compiler.sdk.path}/{build.memory_type}" "-Wl,--wrap=esp_panic_handler" compiler.ar.extra_flags= compiler.objcopy.eep.extra_flags= compiler.elf2hex.extra_flags= From 709c9350642f3358af929e7906abd32afb4c4b34 Mon Sep 17 00:00:00 2001 From: MathewHDYT <48954742+MathewHDYT@users.noreply.github.com> Date: Fri, 6 Oct 2023 12:48:59 +0200 Subject: [PATCH 09/18] Fix memory leak and undefined behavour in Updater.cpp (UpdaterClass) (#8671) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix memory leak and undefined behavour in Updater #7984 * Update error message Co-authored-by: Jan Procházka <90197375+P-R-O-C-H-Y@users.noreply.github.com> * Update error message Co-authored-by: Jan Procházka <90197375+P-R-O-C-H-Y@users.noreply.github.com> --------- Co-authored-by: Jan Procházka <90197375+P-R-O-C-H-Y@users.noreply.github.com> Co-authored-by: Me No Dev --- libraries/Update/src/Updater.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/libraries/Update/src/Updater.cpp b/libraries/Update/src/Updater.cpp index 0bbff0bb63b..80538a5eae2 100644 --- a/libraries/Update/src/Updater.cpp +++ b/libraries/Update/src/Updater.cpp @@ -76,9 +76,15 @@ UpdateClass& UpdateClass::onProgress(THandlerFunction_Progress fn) { } void UpdateClass::_reset() { - if (_buffer) + if (_buffer) { delete[] _buffer; - _buffer = 0; + } + if (_skipBuffer) { + delete[] _skipBuffer; + } + + _buffer = nullptr; + _skipBuffer = nullptr; _bufferLen = 0; _progress = 0; _size = 0; @@ -159,9 +165,9 @@ bool UpdateClass::begin(size_t size, int command, int ledPin, uint8_t ledOn, con } //initialize - _buffer = (uint8_t*)malloc(SPI_FLASH_SEC_SIZE); - if(!_buffer){ - log_e("malloc failed"); + _buffer = new (std::nothrow) uint8_t[SPI_FLASH_SEC_SIZE]; + if (!_buffer) { + log_e("_buffer allocation failed"); return false; } _size = size; @@ -193,10 +199,10 @@ bool UpdateClass::_writeBuffer(){ //not written at this point so that partially written firmware //will not be bootable skip = ENCRYPTED_BLOCK_SIZE; - _skipBuffer = (uint8_t*)malloc(skip); - if(!_skipBuffer){ - log_e("malloc failed"); - return false; + _skipBuffer = new (std::nothrow) uint8_t[skip]; + if (!_skipBuffer) { + log_e("_skipBuffer allocation failed"); + return false; } memcpy(_skipBuffer, _buffer, skip); } From ab6a25ed8db8431f6d0464b560445ed9e0e62be6 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Fri, 6 Oct 2023 07:50:15 -0300 Subject: [PATCH 10/18] Master5.1 s3 gpio48 and platform txt review (#8726) * variants + S3 GPIO48 * fixes unphone8.build.flash_type * fixes unphone8.build.flash_type * heltec board name issue step 1 * heltec board name issue step 2 * fixes defines and new boards * final review --- boards.txt | 2 +- cores/esp32/Arduino.h | 12 ++++++++ cores/esp32/esp32-hal-gpio.c | 3 ++ variants/AirM2M_CORE_ESP32C3/pins_arduino.h | 12 ++------ variants/Aventen_S3_Sync/pins_arduino.h | 9 ------ variants/Bee_Data_Logger/pins_arduino.h | 17 ++++++------ variants/Bee_Motion/pins_arduino.h | 8 ------ variants/Bee_Motion_Mini/pins_arduino.h | 22 +++++++++------ variants/Bee_Motion_S3/pins_arduino.h | 17 ++++++------ variants/Bee_S3/pins_arduino.h | 18 ++++++------ variants/ET-Board/pins_arduino.h | 12 +------- variants/Edgebox-ESP-100/pins_arduino.h | 8 ------ variants/Microduino-esp32/pins_arduino.h | 10 +------ variants/Nebula_S3/pins_arduino.h | 14 ++-------- variants/S_ODI_Ultra_v1/pins_arduino.h | 10 +------ .../VALTRACK_V4_MFW_ESP32_C3/pins_arduino.h | 8 ------ .../VALTRACK_V4_VTS_ESP32_C3/pins_arduino.h | 8 ------ variants/XIAO_ESP32C3/pins_arduino.h | 8 ------ variants/XIAO_ESP32S3/pins_arduino.h | 11 +------- .../adafruit_camera_esp32s3/pins_arduino.h | 20 ++++++++------ .../adafruit_feather_esp32_v2/pins_arduino.h | 21 ++++++-------- .../adafruit_feather_esp32s2/pins_arduino.h | 20 ++++++-------- .../pins_arduino.h | 20 ++++++-------- .../pins_arduino.h | 20 ++++++-------- .../adafruit_feather_esp32s3/pins_arduino.h | 18 ++++++------ .../pins_arduino.h | 18 ++++++------ .../pins_arduino.h | 20 ++++++-------- .../pins_arduino.h | 20 ++++++-------- .../adafruit_funhouse_esp32s2/pins_arduino.h | 10 +------ .../adafruit_itsybitsy_esp32/pins_arduino.h | 16 +++++------ .../adafruit_magtag29_esp32s2/pins_arduino.h | 20 ++++++-------- .../pins_arduino.h | 17 ++++++------ .../adafruit_metro_esp32s2/pins_arduino.h | 16 +++++------ .../bootloader-tinyuf2.bin | Bin 22256 -> 22256 bytes .../adafruit_metro_esp32s3/pins_arduino.h | 26 ++++++++---------- variants/adafruit_metro_esp32s3/tinyuf2.bin | Bin 174736 -> 174736 bytes variants/adafruit_metro_esp32s3/variant.cpp | 3 +- variants/adafruit_qtpy_esp32/pins_arduino.h | 17 +++++++----- variants/adafruit_qtpy_esp32c3/pins_arduino.h | 19 +++++++------ variants/adafruit_qtpy_esp32s2/pins_arduino.h | 21 ++++++-------- .../adafruit_qtpy_esp32s3_n4r2/pins_arduino.h | 11 ++------ .../pins_arduino.h | 11 ++------ .../adafruit_qualia_s3_rgb666/pins_arduino.h | 8 ------ variants/alksesp32/pins_arduino.h | 10 +------ variants/atd147_s3/pins_arduino.h | 9 ------ variants/atmegazero_esp32s2/pins_arduino.h | 17 ++++++------ variants/bpi-bit/pins_arduino.h | 16 +++++------ variants/bpi_leaf_s3/pins_arduino.h | 15 ++++------ variants/ch_denky/pins_arduino.h | 8 ------ variants/cnrs_aw2eth/pins_arduino.h | 8 ------ variants/connaxio_espoir/pins_arduino.h | 8 ------ variants/crabik_slot_esp32_s3/pins_arduino.h | 10 +------ .../pins_arduino.h | 17 +++--------- variants/d-duino-32/pins_arduino.h | 8 ------ variants/d1_mini32/pins_arduino.h | 2 +- variants/d1_uno32/pins_arduino.h | 11 +------- variants/d32/d32_core.h | 8 ------ variants/d32/pins_arduino.h | 2 +- variants/d32_pro/pins_arduino.h | 3 +- variants/deneyapkart/pins_arduino.h | 12 ++------ variants/deneyapkart1A/pins_arduino.h | 14 ++-------- variants/deneyapkart1Av2/pins_arduino.h | 14 ++-------- variants/deneyapkartg/pins_arduino.h | 14 ++-------- variants/deneyapmini/pins_arduino.h | 12 ++------ variants/deneyapminiv2/pins_arduino.h | 14 ++-------- .../pins_arduino.h | 20 ++++++-------- .../dfrobot_beetle_esp32c3/pins_arduino.h | 11 ++------ .../dfrobot_firebeetle2_esp32e/pins_arduino.h | 12 +------- .../pins_arduino.h | 11 ++------ variants/dfrobot_romeo_esp32s3/pins_arduino.h | 11 -------- variants/doitESP32devkitV1/pins_arduino.h | 10 +------ variants/doitESPduino32/pins_arduino.h | 9 +----- variants/dpu_esp32/pins_arduino.h | 8 ------ variants/esp32-devkit-lipo/pins_arduino.h | 8 ------ variants/esp32-evb/pins_arduino.h | 9 ------ variants/esp32-gateway/pins_arduino.h | 10 +------ variants/esp32-poe-iso/pins_arduino.h | 8 ------ variants/esp32-poe/pins_arduino.h | 8 ------ .../pins_arduino.h | 11 ++------ .../pins_arduino.h | 11 ++------ .../esp32-trueverit-iot-driver/pins_arduino.h | 11 ++------ variants/esp32/pins_arduino.h | 8 ------ variants/esp320/pins_arduino.h | 10 +------ variants/esp32_s3r8n16/pins_arduino.h | 9 ------ variants/esp32c3/pins_arduino.h | 15 ++++------ variants/esp32c6/pins_arduino.h | 15 ++++------ variants/esp32da/pins_arduino.h | 8 ------ variants/esp32h2/pins_arduino.h | 15 ++++------ variants/esp32micromod/pins_arduino.h | 10 ++----- variants/esp32s2/pins_arduino.h | 19 ++++++------- variants/esp32s2thing_plus/pins_arduino.h | 9 +----- variants/esp32s2usb/pins_arduino.h | 9 ------ variants/esp32s3/pins_arduino.h | 14 ++++------ variants/esp32s3box/pins_arduino.h | 8 ------ variants/esp32s3camlcd/pins_arduino.h | 8 ------ variants/esp32s3usbotg/pins_arduino.h | 8 ------ variants/esp32thing/pins_arduino.h | 10 +------ variants/esp32thing_plus/pins_arduino.h | 10 +------ variants/esp32thing_plus_c/pins_arduino.h | 13 ++------- variants/esp32vn-iot-uno/pins_arduino.h | 8 ------ variants/esp_c3_m1_i_kit/pins_arduino.h | 9 +----- variants/espea32/pins_arduino.h | 10 +------ variants/espectro32/pins_arduino.h | 10 +------ variants/espino32/pins_arduino.h | 10 +------ variants/feather_esp32/pins_arduino.h | 10 +------ variants/firebeetle32/pins_arduino.h | 12 +------- variants/fm-devkit/pins_arduino.h | 10 ++----- .../franzininho_wifi_esp32s2/pins_arduino.h | 16 +++++------ .../pins_arduino.h | 16 +++++------ variants/frog32/pins_arduino.h | 8 ------ variants/gpy/pins_arduino.h | 18 ++++++------ variants/healthypi4/pins_arduino.h | 10 +------ variants/heltec_wifi_kit_32/pins_arduino.h | 10 +------ .../pins_arduino.h | 10 +------ variants/heltec_wifi_lora_32/pins_arduino.h | 10 +------ .../heltec_wifi_lora_32_V2/pins_arduino.h | 10 +------ .../heltec_wifi_lora_32_V3/pins_arduino.h | 18 ++---------- variants/heltec_wireless_stick/pins_arduino.h | 10 +------ .../heltec_wireless_stick_lite/pins_arduino.h | 10 +------ .../pins_arduino.h | 10 +------ variants/honeylemon/pins_arduino.h | 10 +------ variants/hornbill32dev/pins_arduino.h | 10 +------ variants/hornbill32minima/pins_arduino.h | 8 ------ variants/imbrios-logsens-v1p1/pins_arduino.h | 12 ++------ 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 | 9 ------ variants/lionbit/pins_arduino.h | 11 ++------ variants/lionbits3/pins_arduino.h | 11 ++------ variants/lolin32-lite/pins_arduino.h | 9 +----- variants/lolin32/pins_arduino.h | 12 +------- variants/lolin_c3_mini/pins_arduino.h | 9 +----- variants/lolin_s2_mini/pins_arduino.h | 9 +----- variants/lolin_s2_pico/pins_arduino.h | 9 +----- variants/lolin_s3/pins_arduino.h | 13 ++------- variants/lolin_s3_mini/pins_arduino.h | 14 ++-------- variants/lolin_s3_pro/pins_arduino.h | 14 ++-------- variants/lopy/pins_arduino.h | 18 ++++++------ variants/lopy4/pins_arduino.h | 18 ++++++------ variants/m5stack_atom/pins_arduino.h | 8 ------ variants/m5stack_atoms3/pins_arduino.h | 18 ++---------- variants/m5stack_core2/pins_arduino.h | 8 ------ variants/m5stack_core_esp32/pins_arduino.h | 8 ------ variants/m5stack_coreink/pins_arduino.h | 8 ------ variants/m5stack_cores3/pins_arduino.h | 19 +------------ variants/m5stack_fire/pins_arduino.h | 8 ------ variants/m5stack_stamp_pico/pins_arduino.h | 9 ------ variants/m5stack_stamp_s3/pins_arduino.h | 10 ------- variants/m5stack_station/pins_arduino.h | 8 ------ variants/m5stack_timer_cam/pins_arduino.h | 9 +----- variants/m5stick_c/pins_arduino.h | 8 ------ variants/magicbit/pins_arduino.h | 11 ++------ 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 | 12 ++------ variants/mhetesp32minikit/pins_arduino.h | 12 ++------ variants/micro_s2/pins_arduino.h | 16 +++++------ variants/mpython/pins_arduino.h | 8 ------ variants/namino_arancio/pins_arduino.h | 8 ------ variants/namino_rosso/pins_arduino.h | 8 ------ 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 +------ variants/nora_w10/pins_arduino.h | 9 ------ variants/odroid_esp32/pins_arduino.h | 10 +------ variants/onehorse32dev/pins_arduino.h | 10 +------ variants/openkb/pins_arduino.h | 10 +------ variants/oroca_edubot/pins_arduino.h | 10 +------ variants/pico32/pins_arduino.h | 8 ------ variants/piranha_esp-32/pins_arduino.h | 10 +------ variants/pocket_32/pins_arduino.h | 12 +------- variants/quantum/pins_arduino.h | 8 ------ variants/redpill_esp32s3/pins_arduino.h | 13 ++------- variants/roboheart_hercules/pins_arduino.h | 9 ------ variants/sonoff_dualr3/pins_arduino.h | 8 ------ .../pins_arduino.h | 15 +++------- .../pins_arduino.h | 10 ++----- variants/tamc_termod_s3/pins_arduino.h | 18 +----------- variants/tbeam/pins_arduino.h | 10 +------ variants/ttgo-lora32-v1/pins_arduino.h | 10 +------ variants/ttgo-lora32-v2/pins_arduino.h | 12 ++------ variants/ttgo-lora32-v21new/pins_arduino.h | 14 ++-------- variants/ttgo-t-oi-plus/pins_arduino.h | 10 ++----- variants/ttgo-t1/pins_arduino.h | 10 +------ variants/ttgo-t7-v13-mini32/pins_arduino.h | 9 +----- variants/ttgo-t7-v14-mini32/pins_arduino.h | 9 +----- variants/turta_iot_node/pins_arduino.h | 10 +------ variants/twatch/pins_arduino.h | 8 ------ .../uPesy_esp32_wroom_devkit/pins_arduino.h | 10 +------ .../uPesy_esp32_wrover_devkit/pins_arduino.h | 10 +------ variants/um_feathers2/pins_arduino.h | 8 ------ variants/um_feathers2neo/pins_arduino.h | 17 ++++++------ variants/um_feathers3/pins_arduino.h | 18 ++++++------ variants/um_nanos3/pins_arduino.h | 17 ++++++------ variants/um_pros3/pins_arduino.h | 17 ++++++------ variants/um_rmp/pins_arduino.h | 17 ++++++------ variants/um_tinypico/pins_arduino.h | 8 ------ variants/um_tinys2/pins_arduino.h | 17 ++++++------ variants/um_tinys3/pins_arduino.h | 17 ++++++------ variants/unphone8/pins_arduino.h | 8 ------ variants/unphone9/pins_arduino.h | 8 ------ variants/vintlabsdevkitv1/pins_arduino.h | 10 +------ variants/watchy/pins_arduino.h | 8 ------ variants/wesp32/pins_arduino.h | 8 ------ variants/widora-air/pins_arduino.h | 11 +------- variants/wifiduino32/pins_arduino.h | 10 +------ variants/wifiduino32s3/pins_arduino.h | 18 +----------- variants/wifiduinov2/pins_arduino.h | 15 ++-------- variants/wipy3/pins_arduino.h | 19 ++++++------- variants/wt32-eth01/pins_arduino.h | 8 ------ variants/xinabox/pins_arduino.h | 10 +------ 214 files changed, 557 insertions(+), 1898 deletions(-) rename variants/{heltec_wifi_kit_32_v3 => heltec_wifi_kit_32_V3}/pins_arduino.h (84%) diff --git a/boards.txt b/boards.txt index d1ef1989e7a..4b46104ea16 100644 --- a/boards.txt +++ b/boards.txt @@ -23802,7 +23802,7 @@ unphone8.build.partitions=default_8MB unphone8.build.defines=-DBOARD_HAS_PSRAM -DUNPHONE_SPIN=8 unphone8.build.loop_core=-DARDUINO_RUNNING_CORE=1 unphone8.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 -unphone8.build.flash_type=qspi +unphone8.build.flash_type=qio unphone8.build.psram_type=qspi unphone8.build.memory_type={build.flash_type}_{build.psram_type} diff --git a/cores/esp32/Arduino.h b/cores/esp32/Arduino.h index cd87a914517..2756f6f3cb4 100644 --- a/cores/esp32/Arduino.h +++ b/cores/esp32/Arduino.h @@ -129,6 +129,18 @@ #define NOT_AN_INTERRUPT -1 #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 +#if SOC_ADC_PERIPH_NUM == 1 +#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) +#endif +#define EXTERNAL_NUM_INTERRUPTS NUM_DIGITAL_PINS // All GPIOs +#define analogInputToDigitalPin(p) (((p)= 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); diff --git a/variants/AirM2M_CORE_ESP32C3/pins_arduino.h b/variants/AirM2M_CORE_ESP32C3/pins_arduino.h index 4af6c1d87cd..48b128a25d0 100644 --- a/variants/AirM2M_CORE_ESP32C3/pins_arduino.h +++ b/variants/AirM2M_CORE_ESP32C3/pins_arduino.h @@ -3,16 +3,10 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 22 -#define NUM_DIGITAL_PINS 22 -#define NUM_ANALOG_INPUTS 6 - -#define analogInputToDigitalPin(p) (((p) -#include "soc/soc_caps.h" #define USB_VID 0x303a #define USB_PID 0x1001 @@ -10,14 +9,6 @@ #define USB_PRODUCT "Aventen S3 Sync" #define USB_SERIAL "" -#define NUM_DIGITAL_PINS SOC_GPIO_PIN_COUNT // GPIO 0..48 -#define NUM_ANALOG_INPUTS 20 // GPIO 1..20 -#define EXTERNAL_NUM_INTERRUPTS NUM_DIGITAL_PINS // All GPIOs - -#define analogInputToDigitalPin(p) (((p) +#include "soc/soc_caps.h" #define USB_VID 0x303A #define USB_PID 0x815C @@ -9,14 +10,6 @@ #define USB_PRODUCT "Bee Data Logger" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 13 -#define NUM_ANALOG_INPUTS 7 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -74,5 +67,13 @@ static const uint8_t LDO2 = 34; static const uint8_t RGB_DATA = 40; 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 +#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 #endif /* Pins_Arduino_h */ diff --git a/variants/Bee_Motion/pins_arduino.h b/variants/Bee_Motion/pins_arduino.h index 18cc71f24f5..d11f332cef9 100644 --- a/variants/Bee_Motion/pins_arduino.h +++ b/variants/Bee_Motion/pins_arduino.h @@ -9,14 +9,6 @@ #define USB_PRODUCT "Bee Motion S3" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 21 -#define NUM_ANALOG_INPUTS 12 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/Bee_Motion_Mini/pins_arduino.h b/variants/Bee_Motion_Mini/pins_arduino.h index e3f43decb4a..3e308be5de6 100644 --- a/variants/Bee_Motion_Mini/pins_arduino.h +++ b/variants/Bee_Motion_Mini/pins_arduino.h @@ -3,22 +3,26 @@ #include - -#define EXTERNAL_NUM_INTERRUPTS 4 -#define NUM_DIGITAL_PINS 4 -#define NUM_ANALOG_INPUTS 2 - -#define analogInputToDigitalPin(p) (((p)<6)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<22)?(p):-1) -#define digitalPinHasPWM(p) (p < 22) - static const uint8_t TX = 21; static const uint8_t RX = 20; static const uint8_t BOOT_BTN = 9; 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 A0 = 0; +static const uint8_t A1 = 1; +static const uint8_t A2 = 2; +static const uint8_t A3 = 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 19025426c65..6eebf47d884 100644 --- a/variants/Bee_Motion_S3/pins_arduino.h +++ b/variants/Bee_Motion_S3/pins_arduino.h @@ -2,6 +2,7 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x303A #define USB_PID 0x8113 @@ -9,14 +10,6 @@ #define USB_PRODUCT "Bee Motion S3" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 27 -#define NUM_ANALOG_INPUTS 11 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -81,5 +74,13 @@ static const uint8_t LDO2 = 34; static const uint8_t RGB_DATA = 40; 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 +#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 #endif /* Pins_Arduino_h */ diff --git a/variants/Bee_S3/pins_arduino.h b/variants/Bee_S3/pins_arduino.h index b095fb8fd7f..2ea399fd532 100644 --- a/variants/Bee_S3/pins_arduino.h +++ b/variants/Bee_S3/pins_arduino.h @@ -2,6 +2,7 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x303A #define USB_PID 0x8110 @@ -9,14 +10,6 @@ #define USB_PRODUCT "BeeS3" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 45 -#define NUM_DIGITAL_PINS 15 -#define NUM_ANALOG_INPUTS 8 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -73,4 +66,13 @@ static const uint8_t VBAT_VOLTAGE = 1; static const uint8_t RGB_DATA = 48; 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 +#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 + #endif /* Pins_Arduino_h */ diff --git a/variants/ET-Board/pins_arduino.h b/variants/ET-Board/pins_arduino.h index 9dada4cb50d..7275f956f4f 100644 --- a/variants/ET-Board/pins_arduino.h +++ b/variants/ET-Board/pins_arduino.h @@ -3,19 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 7 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 5; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN - - +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 34; static const uint8_t RX = 35; diff --git a/variants/Edgebox-ESP-100/pins_arduino.h b/variants/Edgebox-ESP-100/pins_arduino.h index ae212f44dea..0c14982ec9b 100644 --- a/variants/Edgebox-ESP-100/pins_arduino.h +++ b/variants/Edgebox-ESP-100/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 34 -#define NUM_DIGITAL_PINS 34 -#define NUM_ANALOG_INPUTS 2 - -#define analogInputToDigitalPin(p) (((p)<2)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<34)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - //Programming and Debugging Port static const uint8_t TXD = 43; static const uint8_t RXD = 44; diff --git a/variants/Microduino-esp32/pins_arduino.h b/variants/Microduino-esp32/pins_arduino.h index 034bd6173b3..7dc0d236de9 100644 --- a/variants/Microduino-esp32/pins_arduino.h +++ b/variants/Microduino-esp32/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 22 -#define NUM_ANALOG_INPUTS 12 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = -1; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define MTDO 15 #define MTDI 12 diff --git a/variants/Nebula_S3/pins_arduino.h b/variants/Nebula_S3/pins_arduino.h index 513aef8409e..39fbe5707d2 100644 --- a/variants/Nebula_S3/pins_arduino.h +++ b/variants/Nebula_S3/pins_arduino.h @@ -2,22 +2,14 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x303a #define USB_PID 0x1001 -#define EXTERNAL_NUM_INTERRUPTS 20 -#define NUM_DIGITAL_PINS 20 -#define NUM_ANALOG_INPUTS 6 - -#define analogInputToDigitalPin(p) (((p)<6)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<20)?(p):-1) -#define digitalPinHasPWM(p) (p < 20) - - -static const uint8_t LED_BUILTIN = 45; +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 45; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 diff --git a/variants/S_ODI_Ultra_v1/pins_arduino.h b/variants/S_ODI_Ultra_v1/pins_arduino.h index 51278ce94be..87a6d56e0b3 100644 --- a/variants/S_ODI_Ultra_v1/pins_arduino.h +++ b/variants/S_ODI_Ultra_v1/pins_arduino.h @@ -3,18 +3,10 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 2; static const uint8_t LED_BUILTINB = 4; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define BUILTIN_LED2 LED_BUILTINB static const uint8_t TX = 1; diff --git a/variants/VALTRACK_V4_MFW_ESP32_C3/pins_arduino.h b/variants/VALTRACK_V4_MFW_ESP32_C3/pins_arduino.h index 4e3c771578b..b473c8afff1 100644 --- a/variants/VALTRACK_V4_MFW_ESP32_C3/pins_arduino.h +++ b/variants/VALTRACK_V4_MFW_ESP32_C3/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 22 -#define NUM_DIGITAL_PINS 22 -#define NUM_ANALOG_INPUTS 6 - -#define analogInputToDigitalPin(p) (((p) -#define EXTERNAL_NUM_INTERRUPTS 22 -#define NUM_DIGITAL_PINS 22 -#define NUM_ANALOG_INPUTS 6 - -#define analogInputToDigitalPin(p) (((p) -#define EXTERNAL_NUM_INTERRUPTS 22 -#define NUM_DIGITAL_PINS 22 -#define NUM_ANALOG_INPUTS 6 - -#define analogInputToDigitalPin(p) (((p) -#include "soc/soc_caps.h" #define USB_VID 0x2886 #define USB_PID 0x0056 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - static const uint8_t LED_BUILTIN = 21; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN - -#define analogInputToDigitalPin(p) (((p) - +#include "soc/soc_caps.h" #define USB_VID 0x239A #define USB_PID 0x8117 @@ -11,17 +11,19 @@ #define USB_SERIAL "" // Empty string for MAC adddress -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t PIN_NEOPIXEL = 1; 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 +#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_BRIGHTNESS 64 + + //static const uint8_t TFT_BACKLIGHT = 41; static const uint8_t TFT_DC = 40; static const uint8_t TFT_CS = 39; diff --git a/variants/adafruit_feather_esp32_v2/pins_arduino.h b/variants/adafruit_feather_esp32_v2/pins_arduino.h index 71e32cc60e1..7aae51a2d16 100644 --- a/variants/adafruit_feather_esp32_v2/pins_arduino.h +++ b/variants/adafruit_feather_esp32_v2/pins_arduino.h @@ -2,18 +2,7 @@ #define Pins_Arduino_h #include - -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - -static const uint8_t LED_BUILTIN = 13; -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#include "soc/soc_caps.h" static const uint8_t TX = 8; static const uint8_t RX = 7; @@ -50,8 +39,16 @@ static const uint8_t A13 = 35; // internal switch #define BUTTON 38 +// User LED +static const uint8_t LED_BUILTIN = 13; +#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_BRIGHTNESS 64 // Neopixel & I2C power #define NEOPIXEL_I2C_POWER 2 diff --git a/variants/adafruit_feather_esp32s2/pins_arduino.h b/variants/adafruit_feather_esp32s2/pins_arduino.h index 261377de89c..013ae6c6dea 100644 --- a/variants/adafruit_feather_esp32s2/pins_arduino.h +++ b/variants/adafruit_feather_esp32s2/pins_arduino.h @@ -2,7 +2,7 @@ #define Pins_Arduino_h #include - +#include "soc/soc_caps.h" #define USB_VID 0x239A #define USB_PID 0x80EB @@ -10,18 +10,16 @@ #define USB_PRODUCT "Feather ESP32-S2" #define USB_SERIAL "" // Empty string for MAC adddress +// User LED +#define LED_BUILTIN 13 +#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - -#define LED_BUILTIN 13 +// 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_BRIGHTNESS 64 -#define PIN_NEOPIXEL 33 #define NEOPIXEL_NUM 1 // number of neopixels #define NEOPIXEL_POWER 21 // power pin #define NEOPIXEL_POWER_ON HIGH // power pin state when on diff --git a/variants/adafruit_feather_esp32s2_reversetft/pins_arduino.h b/variants/adafruit_feather_esp32s2_reversetft/pins_arduino.h index 6758b16a898..d39b50628e2 100644 --- a/variants/adafruit_feather_esp32s2_reversetft/pins_arduino.h +++ b/variants/adafruit_feather_esp32s2_reversetft/pins_arduino.h @@ -2,7 +2,7 @@ #define Pins_Arduino_h #include - +#include "soc/soc_caps.h" #define USB_VID 0x239A #define USB_PID 0x80ED @@ -10,18 +10,16 @@ #define USB_PRODUCT "Feather ESP32-S2 Reverse TFT" #define USB_SERIAL "" // Empty string for MAC adddress +// User LED +#define LED_BUILTIN 13 +#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - -#define LED_BUILTIN 13 +// 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_BRIGHTNESS 64 -#define PIN_NEOPIXEL 33 #define NEOPIXEL_NUM 1 // number of neopixels #define NEOPIXEL_POWER 21 // power pin #define NEOPIXEL_POWER_ON HIGH // power pin state when on diff --git a/variants/adafruit_feather_esp32s2_tft/pins_arduino.h b/variants/adafruit_feather_esp32s2_tft/pins_arduino.h index 8eaef02334d..ca713ac315d 100644 --- a/variants/adafruit_feather_esp32s2_tft/pins_arduino.h +++ b/variants/adafruit_feather_esp32s2_tft/pins_arduino.h @@ -2,7 +2,7 @@ #define Pins_Arduino_h #include - +#include "soc/soc_caps.h" #define USB_VID 0x239A #define USB_PID 0x810F @@ -10,18 +10,16 @@ #define USB_PRODUCT "Feather ESP32-S2 TFT" #define USB_SERIAL "" // Empty string for MAC adddress +// User LED +#define LED_BUILTIN 13 +#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - -#define LED_BUILTIN 13 +// 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_BRIGHTNESS 64 -#define PIN_NEOPIXEL 33 #define NEOPIXEL_NUM 1 // number of neopixels #define NEOPIXEL_POWER 34 // power pin #define NEOPIXEL_POWER_ON HIGH // power pin state when on diff --git a/variants/adafruit_feather_esp32s3/pins_arduino.h b/variants/adafruit_feather_esp32s3/pins_arduino.h index 16ae97b640f..a8c491a64ad 100644 --- a/variants/adafruit_feather_esp32s3/pins_arduino.h +++ b/variants/adafruit_feather_esp32s3/pins_arduino.h @@ -2,6 +2,7 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x239A #define USB_PID 0x811B @@ -9,17 +10,16 @@ #define USB_PRODUCT "Feather ESP32-S3" #define USB_SERIAL "" // Empty string for MAC adddress -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 +// User LED +#define LED_BUILTIN 13 +#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) +// 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_BRIGHTNESS 64 -#define LED_BUILTIN 13 - -#define PIN_NEOPIXEL 33 #define NEOPIXEL_NUM 1 // number of neopixels #define NEOPIXEL_POWER 21 // power pin #define NEOPIXEL_POWER_ON HIGH // power pin state when on diff --git a/variants/adafruit_feather_esp32s3_nopsram/pins_arduino.h b/variants/adafruit_feather_esp32s3_nopsram/pins_arduino.h index 58a23a17f7c..65aec064fad 100644 --- a/variants/adafruit_feather_esp32s3_nopsram/pins_arduino.h +++ b/variants/adafruit_feather_esp32s3_nopsram/pins_arduino.h @@ -2,6 +2,7 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x239A #define USB_PID 0x8113 @@ -9,17 +10,16 @@ #define USB_PRODUCT "Feather ESP32-S3 No PSRAM" #define USB_SERIAL "" // Empty string for MAC adddress -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 +// User LED +#define LED_BUILTIN 13 +#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) +// 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_BRIGHTNESS 64 -#define LED_BUILTIN 13 - -#define PIN_NEOPIXEL 33 #define NEOPIXEL_NUM 1 // number of neopixels #define NEOPIXEL_POWER 21 // power pin #define NEOPIXEL_POWER_ON HIGH // power pin state when on diff --git a/variants/adafruit_feather_esp32s3_reversetft/pins_arduino.h b/variants/adafruit_feather_esp32s3_reversetft/pins_arduino.h index 594940f5710..8fa045489fe 100644 --- a/variants/adafruit_feather_esp32s3_reversetft/pins_arduino.h +++ b/variants/adafruit_feather_esp32s3_reversetft/pins_arduino.h @@ -2,7 +2,7 @@ #define Pins_Arduino_h #include - +#include "soc/soc_caps.h" #define USB_VID 0x239A #define USB_PID 0x8123 @@ -10,18 +10,16 @@ #define USB_PRODUCT "Feather ESP32-S3 Reverse TFT" #define USB_SERIAL "" // Empty string for MAC adddress +// User LED +#define LED_BUILTIN 13 +#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - -#define LED_BUILTIN 13 +// 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_BRIGHTNESS 64 -#define PIN_NEOPIXEL 33 #define NEOPIXEL_NUM 1 // number of neopixels #define NEOPIXEL_POWER 21 // power pin #define NEOPIXEL_POWER_ON HIGH // power pin state when on diff --git a/variants/adafruit_feather_esp32s3_tft/pins_arduino.h b/variants/adafruit_feather_esp32s3_tft/pins_arduino.h index d1a9dc5ff81..56860f3c2d7 100644 --- a/variants/adafruit_feather_esp32s3_tft/pins_arduino.h +++ b/variants/adafruit_feather_esp32s3_tft/pins_arduino.h @@ -2,7 +2,7 @@ #define Pins_Arduino_h #include - +#include "soc/soc_caps.h" #define USB_VID 0x239A #define USB_PID 0x811D @@ -10,18 +10,16 @@ #define USB_PRODUCT "Feather ESP32-S3 TFT" #define USB_SERIAL "" // Empty string for MAC adddress +// User LED +#define LED_BUILTIN 13 +#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - -#define LED_BUILTIN 13 +// 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_BRIGHTNESS 64 -#define PIN_NEOPIXEL 33 #define NEOPIXEL_NUM 1 // number of neopixels #define NEOPIXEL_POWER 34 // power pin #define NEOPIXEL_POWER_ON HIGH // power pin state when on diff --git a/variants/adafruit_funhouse_esp32s2/pins_arduino.h b/variants/adafruit_funhouse_esp32s2/pins_arduino.h index 6b4fa1ec5b3..3594af16021 100644 --- a/variants/adafruit_funhouse_esp32s2/pins_arduino.h +++ b/variants/adafruit_funhouse_esp32s2/pins_arduino.h @@ -10,16 +10,8 @@ #define USB_PRODUCT "Funhouse ESP32-S2" #define USB_SERIAL "" // Empty string for MAC adddress - -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - #define LED_BUILTIN 37 +#define BUILTIN_LED LED_BUILTIN // backward compatibility #define PIN_BUTTON1 3 #define PIN_BUTTON2 4 diff --git a/variants/adafruit_itsybitsy_esp32/pins_arduino.h b/variants/adafruit_itsybitsy_esp32/pins_arduino.h index d81c077c91d..c526628f7b1 100644 --- a/variants/adafruit_itsybitsy_esp32/pins_arduino.h +++ b/variants/adafruit_itsybitsy_esp32/pins_arduino.h @@ -2,21 +2,19 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - +// User LED static const uint8_t LED_BUILTIN = 13; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#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_BRIGHTNESS 64 + static const uint8_t NEOPIXEL_POWER = 2; static const uint8_t TX = 20; diff --git a/variants/adafruit_magtag29_esp32s2/pins_arduino.h b/variants/adafruit_magtag29_esp32s2/pins_arduino.h index 610312d05fd..aaeb744ce0a 100644 --- a/variants/adafruit_magtag29_esp32s2/pins_arduino.h +++ b/variants/adafruit_magtag29_esp32s2/pins_arduino.h @@ -2,7 +2,7 @@ #define Pins_Arduino_h #include - +#include "soc/soc_caps.h" #define USB_VID 0x239A #define USB_PID 0x80E5 @@ -10,18 +10,16 @@ #define USB_PRODUCT "EPD MagTag 2.9\" ESP32-S2" #define USB_SERIAL "" // Empty string for MAC adddress +// User LED +#define LED_BUILTIN 13 +#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - -#define LED_BUILTIN 13 - +// Neopixel #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_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 diff --git a/variants/adafruit_matrixportal_esp32s3/pins_arduino.h b/variants/adafruit_matrixportal_esp32s3/pins_arduino.h index fc7e69f5c1d..99529c02510 100644 --- a/variants/adafruit_matrixportal_esp32s3/pins_arduino.h +++ b/variants/adafruit_matrixportal_esp32s3/pins_arduino.h @@ -2,6 +2,7 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x239A #define USB_PID 0x8125 @@ -9,18 +10,16 @@ #define USB_PRODUCT "MatrixPortal ESP32-S3" #define USB_SERIAL "" // Empty string for MAC adddress -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 6 - -#define analogInputToDigitalPin(p) (((p) - +#include "soc/soc_caps.h" #define USB_VID 0x239A #define USB_PID 0x80DF @@ -10,17 +10,15 @@ #define USB_PRODUCT "Metro ESP32-S2" #define USB_SERIAL "" // Empty string for MAC adddress -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - #define LED_BUILTIN 42 +#define BUILTIN_LED LED_BUILTIN // backward compatibility +// Neopixel #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_BRIGHTNESS 64 + #define NEOPIXEL_NUM 1 #define PIN_BUTTON1 0 // BOOT0 switch diff --git a/variants/adafruit_metro_esp32s3/bootloader-tinyuf2.bin b/variants/adafruit_metro_esp32s3/bootloader-tinyuf2.bin index 2ed855b65a59f12e9c7a659ccbf24b4691f58426..73e8c06b33bd5ce0ffccfb8ffe6ba67e8171c717 100644 GIT binary patch delta 2633 zcmY*b4^R}>8Grllgk#Y|0pXCiceoyh8gK821%%;FBc(J>IE>VgGW?0>SR+kM)l53H z$3vrMVrC?3oj7BryN6eh^s30jG1i-MXo*sZO4^t@!7`3(E7}%^NMnb6+xPBFn(oa0 z-n-xTz2Eok_rAA#Q&DOvN^$oX`uW0sZgfF#`;S(8FXG#DICHe}ec%OGzhRDI=3kgG zj$!))e5b0IxdfWO#T>_su&~51z_!)iVtku^isu{2gJu8*4Is!r&MwNjMvYcF z=+Vjt>p=5%JbKd^kTTGpy@8^BCv!P(7rtRkq=1Qi{exi!~?6 zE&^gLXDdmNs|Y!yD5n)*Q3dEFKk+0`z-^&%s-!+RfhHbIou+miyV9PPw3K$fCyA^2Lh{!@i%{AJmVF8heF;OZ| z&0+hycD~;%ud`PEAhMZlGuNrp;%2tFZ?NY>dS3+*SYw~(^|JLlQKXes&I#jed$Kg#7*>Am z^G-6tB;&OY_PA%%anu?$BA*%jO?a31`fsA;+p7PZkZXP-XSR? zDmMGs2Z4g0?%{O0J04r-vAMCG8hV3f4|(aD9iI3Bt?;9 zz|5zQrpMBw>5;V@jwAIUhv&Z72;ike@=5%d%x%Zz6N{DywMDE_BpkB_D#->PLFy3% zcN2U5RAduQq`tw>8pwDPwREAVDd1+cWvm9+Ksj)m82@X?wgI?EfD<;XvVYHUyqK-{vRR} zN6xr^6I%Lm8s^Tt%=v54mY?1UNJMROGLs4-)@hPI&9|5DAoG?6^spXnHC?Yq@p{x~ z?llb#P`6b8w-alWgRhV=(8ls+=p@rdGjD|sS$b-r6e%RiRR}*}9x?IRbr+`F&+dPd z-uDb}UwAy@p{qO~d&VSHl1DFLY3(s8V+O9oig0&rF$2_4yE!a4MmGD!|(V>tf zfx-bwe9ELKnb+Q;y0TF(b*RtM(I=dsG&^S53Cw0-_H4%2e8dOfT*Rm11dgUa9<@JS zl9=XC;dnzN{Fc5W!!rhM)*%IqDJg^J1->C7|8?;~QM|^GKE_*-v=Y-h*!T&<^DE5! zJ2AezL6h@@yr6i6!G73lOu;fK!fB!0s*QY`vtW+5MlS!4BVAtJ7r4aO&g;E&vJ^ZY z<4FkdV}?&(VJ0qoO<))=N@^$9h<{+DlX@=$uao>^H2+*We~`Co7Z}W4Azbnd@imbl z5|30@>ehKKTmaxjVlQOW3;J1lz4_F&UHtY_r@q{MFnf?<2El^(kWAUuF4MkZ#%QXO z1|8!W9pgeLO~=e2lyNO2jL}RyqIZl_DnS9hAiru`Kld{_h5DKX)p=Ic`)3Y&YsF)NW>fl^a16bcV3QBkZgNm+VVmQLJp)I-Vd4%0P1 z$>8IUEe9AkCBXY6(I^vfo76N?wur|Rj$1^7v-Au2`{TCF5g&736a}?mQV~{HSsluW zr;W4ZABA92CK=^)SP6H!E(m;jQc#&(0I$w=xHAf2huz|`3(~)5;a9Ux=yF^3%ZX3e zhn(ZJdHr9`;?kV+@M*4ddm`t!UZ{jQ@d_Ecv+zbesbK!pfVN~(a*}=|*SR;Fc09QC h%WlxNFzsf0f8=Ke{vz((clqeu&>M}PZ=BZ_{V&L~96kU5 delta 2605 zcmY*b4R90372ea`30Xb|DHtQm7@vgCmK`uU8I1p^B`6TwP>>nZ;EWyHpwhT;N&_^V zsWb9A8DbKc!5o*li(J^U)u?{Cb3F;fA3hO zy|S|P;0^ek^hd|SX-$T!$p|({-#Ut>turS6X}et~@NSu7NT ztYV<8VO@)p;35K!$nu~JYzhzkWQrMKE_=OJ-NMAI@e)HRF<=!Dthj9e5T&$o*8T3A zORR;?_c*I2Y1w@Bh*g*}Tyu;;8OQ=zn@vpP{Kw=KE{tS@$ZphpcRXO(8@IT4<9=E zmlb7XL*|V`ir8~aqPnQD)Lqi@HNxvX%v!e%k3~%21`2*9U30o?uOp&&6Y>3Bt}B>E zzBP9O z&m%IaD5jyGu$)u-DJu>l*B}ZE5(7mvCLShu1g&)wZ$(TEXTqa_JhpCNiPNm=It>)xc+_gTF>z??SJCTS4Zdpmc7q4egS+ zJHcnr;!G2!Y6TPML@}$LBqqP5H9%U&gKeHB#D>P0WW%j9Gr4yZ7JDGT%`G^?%j{>L!|97RD`%0Db6EV z^NPcogP2SsCP#Jbb;TzJC~E;YoO}|5@RAui(V_Cj9w+Kfdn0?ly~ly}blZ}Y-$|*t zW?9a>_$t*i6ZKJh`fZ*4{M%H>jZtO{qc)7bZ-0QR0RS@)mxcq_Z-MEk<8FGA&7Hvh z;?jqC4ySO5CViV~I9rc^yRF2-@Yxd!zV z&1KAQv=SYzRy&DTrHrQ*sUOqgJ9-}tFOnk0Ok4)Hi*trf&=@*LpwtQCYK0NvkCa%9 z=o}lF3*ZSN_t46S^d&!wic5F-WmHI7;>yi9sCSN13ZXn)CvA4E4ogJ0-P%X{>v_17 zOvX&0o8mHo!w-I}_>b9Mw60HQkNlNCa*pTPLPu!-A%2VnIE)wXYae=9RBzGvSpH5| zI&}CLf$_ai!sJfm)JM)fs*MxjHeLCR4)cld)CGg|!*{wyuaJvRwCUoVc9(B>qMmw&+TW z4lP8lzm>vYca zno=Paxzyuq46|yS#pEPAYD$>MT!XCecXo+261RjtV3n16e5EcAMJ{35+XYvW01{Si zb<9K*dhuG}17aY~!WumsrQWcVJN8o*cI_w|rD7)SI3Bc**kn6|u8~X@=*nUpUL`?l zHMpv&YN%Iemq*8s)+JF_M4cbuVS=a#pW`)3NfJ0ifCp77*72RKo}qE+A0a`7mYCz= z0)3!B=d3E}v(7BlspOr5A>uX|F@58Y!=A^6k}hw*zv`zRiclSreq;4>>$ zQa7R09Esah#M%aU`~dk})70&2l{q#(4e&^p|k%r?&8zYtoUSsth5!H68`@}A(i zjFdfjdCQft_xf*UgJl_u#+o6+y4h_KHNFFd=l5Eqs3Zz@2+|a;%g~_a1vm zIL7utIl`*v$k;nmjSqd6|DEXiRdZ~XW%cO3#6+IUH||9 diff --git a/variants/adafruit_metro_esp32s3/pins_arduino.h b/variants/adafruit_metro_esp32s3/pins_arduino.h index 5b3f8c23606..dd77fa7a5ab 100644 --- a/variants/adafruit_metro_esp32s3/pins_arduino.h +++ b/variants/adafruit_metro_esp32s3/pins_arduino.h @@ -2,6 +2,7 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x239A #define USB_PID 0x8145 @@ -9,18 +10,15 @@ #define USB_PRODUCT "Metro ESP32-S3" #define USB_SERIAL "" // Empty string for MAC adddress -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - #define LED_BUILTIN 13 +#define BUILTIN_LED LED_BUILTIN // backward compatibility + +// Neopixel +#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_BRIGHTNESS 64 -#define PIN_NEOPIXEL 46 -#define NEOPIXEL_PIN 46 #define NEOPIXEL_NUM 1 #define PIN_BUTTON1 0 // BOOT0 switch @@ -33,10 +31,10 @@ 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 MOSI = 42; -static const uint8_t SCK = 39; -static const uint8_t MISO = 21; +static const uint8_t SS = 21; +static const uint8_t MOSI = 35; +static const uint8_t SCK = 36; +static const uint8_t MISO = 37; static const uint8_t A0 = 14; static const uint8_t A1 = 15; diff --git a/variants/adafruit_metro_esp32s3/tinyuf2.bin b/variants/adafruit_metro_esp32s3/tinyuf2.bin index 25a5ba66b1e8020665347240932ecc49070f6c42..d57e5b75b55353e5d6f200e26ed04c88b8b5d881 100644 GIT binary patch delta 1722 zcmXYx2~5*h9LL{#rSPY;AcL|ZC@o05H@W;HKJ1@bm4P~TpcRW2CldsX2lI-iibpgV zqfN*Do*716Ts+W}twaSColaxoIpY$|x~Kyuird&J=IvXx;gj$0c-Qaue-FcwNv%0E$Gc^O`Np0$jqCZD@>DkSV#5uo=lIB; ziQzptUAOx5yLJD?H2A!Z62F-a&-Rz*97^-|JLWU$^i|A$PF?=kvDdFEHE``pW(c!T<6fnRVej5>RYmWlqpPRTmpJ90K|jPVBg;L z@xI{l!?eoZP!|+p8=9lq!3oL>5M3iC8kuw-T*DRjGK|$39SdUU=rfbF?SvGANV7I_(O=Fpcg;_ zD9dG;d01PPs9RPC}~3I0KK9H{!!R-ph0M~mGKW?bEp-% z8nHF7zgB;Xq-nHAHR|Y4%PfWQw~#GDwh49;?5EILbYN@&N<*9mP!bN6~b{6*#wn0q?RveHcZH=?XPNPm>0DOBh%2g2SQx zBvH9{0dY)=cPBuoyIgD{8x*TDAQ!vsG%KakN%7 z8fZ$sV+P(CCOAQ&HbdGDU!M8$*yr>TAzNXuNAu7?(GL3#{wv%C5%^RC)ujenW4H@5 z2p)iL^^t)l;ksy}>B#(&*?4iY@UoCW``tf7=a=C=K=p`+dgUp{0RSP#`Uz=XONa-Q zXmZs>(e$JA3JlAxmX%f`Q7SOC8Y~2h!1p>72;HpyiQVWu)e=KfN>5?&-C!-avp`lT zQOx3RAr9NA?H)!y1)*8DoQ$_UmX%O!+-LW5@u6@($g?po4@1a)ZeO`6qor&5 U;;zh-`8NwSN&TmH(w0^K1GXjt`Tzg` delta 1753 zcmY+EYfw{16vuZr1VTtaglJGK32O0y3JTtU3%Nvm6;!N3K_Z|81+;B|An0g=s1!ed zFsXB~&=EzeGxaqMHrAFITdhj^a>P1xY9G@MGgNWJDy<{h+kezAy_4Vk&pCT`@7Z&A z)AED51;0od+d3&iGi&a=S({87ic9915?d{^$HmW2o|~8)mq1=VD~lZlLqcoA48z8N zz9)a(wEmdV7I3_D$bKikAT~VWo5o*n6}ZdC@4KOO?aIw^8|d@|jlJ@1TXnHxPGVwQ zoO@Z~N0Z%;bBh?Yx$^Qy{Y�H>+I*)@YaA>gTSrhU;jp>p(^6|4MN^t0)YyXw~WK z9VN+z7e%->SKjlJ@wn=$VyFA+^Ai~Nsp_R_pkqKd(1S=|aP?GOrFQpTM^GT$;cngO z^rM;X(0YYJ+mXU}C-8z1mvQfz)PpM-Z^~r6QQvF!LSwDe@(`M{g7N6(j1NE$LQg2D z<@#hI5(6RUbG_ys#DZ41gByaGGP98JOt-P|e$6>O{f#N7z>oAiV^pTk$6_U_q+PVs zb4*F2sIoho@uO0&KkYMqJfHE(M8>y)ORz6OZ$L+(^PyX%o&cJmoq}D>0Ht3Li(S&G zsNlQ?my`>lnu%MWGwF7yV71{+OmE?*5J5-%m)m;Ln64kRB291C*zO=xi+ z{LthV1+9{vsc4k54DKUPjbYVhLEH$HWv9FbN)|Al3aUVQo*>RaOwSqD`EpSHYS@vO zBf@Wj-GRK@zzaL8g%s)Q6h-oWSuV}S9(?N&M)n8PV&4j)O2wfe8mT>yMx<;(Li0i_ zfTWmIUjg^!8u%ArmqUl36U>Yk!d?o^fbK=C0rolRK_Hz>A4@tljWL#pj3;9>2cw5! z$H0C9-GUBS(ipFh)~V@4=QxDh;9da?_6T&Qh4BZ#2F_wvKSA4p0}ZTQ!}u?Y88_x4 zhWxLAG9A|lYz0@rD2QK#j@%`d&O5~NE%HAFCqXsh9Z(OneleTD37iE$J|xREK9xhz zmSLITL@RWJ+(&E_Op%O1G|ZW|gz;i<1hh4vix zw;(bDA+3nFgP%eCGSmugX|XK)i?II%c<<%-*H9Pu9t37Eo&??j&A^+%BzF*yy__Yg>O7B`;taQ z$a}Es&^$Cy?uFftKZDyK44>*%sX|LPYX@Ntfno4S`cq3M;CBYeeDp65i}@hK z&U?t%vKHq78jhH+S8eMUw*x}XJ|(1c2O%vWOCd^c2GioHWk^dX6U1&E5z8>O0#t%( za7~StLz|=#yp0Y>#t<5neGQAB0F9u3lOR$e8svXu`D8k^3?Tb&;G1>Z%J})ag6NAS zHUDA4hr;Qc z?=hUxmh595v5du}86VW;pXk4I<&byy=7#q(-*pta_MA3OA7pLH@ne^4%h>hSe +#include "soc/soc_caps.h" -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 +// Neopixel +#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 +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) +// RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() +#define RGB_BUILTIN LED_BUILTIN +#define RGB_BRIGHTNESS 64 -#define PIN_NEOPIXEL 5 #define NEOPIXEL_POWER 8 static const uint8_t TX = 32; diff --git a/variants/adafruit_qtpy_esp32c3/pins_arduino.h b/variants/adafruit_qtpy_esp32c3/pins_arduino.h index 6c93bfd5820..6b50bbddbd0 100644 --- a/variants/adafruit_qtpy_esp32c3/pins_arduino.h +++ b/variants/adafruit_qtpy_esp32c3/pins_arduino.h @@ -2,17 +2,20 @@ #define Pins_Arduino_h #include - -#define EXTERNAL_NUM_INTERRUPTS 22 -#define NUM_DIGITAL_PINS 22 -#define NUM_ANALOG_INPUTS 6 - -#define analogInputToDigitalPin(p) (((p) - +#include "soc/soc_caps.h" #define USB_VID 0x239A #define USB_PID 0x8111 @@ -10,18 +10,15 @@ #define USB_PRODUCT "QT Py ESP32-S2" #define USB_SERIAL "" // Empty string for MAC adddress - -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - -//#define LED_BUILTIN 13 - +// 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 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 NEOPIXEL_NUM 1 // number of neopixels #define NEOPIXEL_POWER 38 // power pin #define NEOPIXEL_POWER_ON HIGH // power pin state when on diff --git a/variants/adafruit_qtpy_esp32s3_n4r2/pins_arduino.h b/variants/adafruit_qtpy_esp32s3_n4r2/pins_arduino.h index 789161da4ad..f4082c5cb2c 100644 --- a/variants/adafruit_qtpy_esp32s3_n4r2/pins_arduino.h +++ b/variants/adafruit_qtpy_esp32s3_n4r2/pins_arduino.h @@ -10,14 +10,6 @@ #define USB_PRODUCT "QT Py ESP32-S3 (4MB Flash 2MB PSRAM)" #define USB_SERIAL "" // Empty string for MAC adddress -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - #define PIN_NEOPIXEL 39 #define NEOPIXEL_NUM 1 // number of neopixels #define NEOPIXEL_POWER 38 // power pin @@ -25,7 +17,8 @@ static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#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 diff --git a/variants/adafruit_qtpy_esp32s3_nopsram/pins_arduino.h b/variants/adafruit_qtpy_esp32s3_nopsram/pins_arduino.h index 38305f67e36..e8f4ab08130 100644 --- a/variants/adafruit_qtpy_esp32s3_nopsram/pins_arduino.h +++ b/variants/adafruit_qtpy_esp32s3_nopsram/pins_arduino.h @@ -10,14 +10,6 @@ #define USB_PRODUCT "QT Py ESP32-S3 No PSRAM" #define USB_SERIAL "" // Empty string for MAC adddress -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - #define PIN_NEOPIXEL 39 #define NEOPIXEL_NUM 1 // number of neopixels #define NEOPIXEL_POWER 38 // power pin @@ -25,7 +17,8 @@ static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#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 diff --git a/variants/adafruit_qualia_s3_rgb666/pins_arduino.h b/variants/adafruit_qualia_s3_rgb666/pins_arduino.h index 120a50b91a6..62f04d1a620 100644 --- a/variants/adafruit_qualia_s3_rgb666/pins_arduino.h +++ b/variants/adafruit_qualia_s3_rgb666/pins_arduino.h @@ -10,14 +10,6 @@ #define USB_PRODUCT "Qualia ESP32-S3 RGB666" #define USB_SERIAL "" // Empty string for MAC adddress -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 2 - -#define analogInputToDigitalPin(p) (((p) -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - #define ALKSESP32 // tell library to not map pins again static const uint8_t LED_BUILTIN = 23; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/atd147_s3/pins_arduino.h b/variants/atd147_s3/pins_arduino.h index 5cbb1ebe3b3..0726a1c4a1c 100644 --- a/variants/atd147_s3/pins_arduino.h +++ b/variants/atd147_s3/pins_arduino.h @@ -2,19 +2,10 @@ #define Pins_Arduino_h #include -#include "soc/soc_caps.h" #define USB_VID 0x303a #define USB_PID 0x1001 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/atmegazero_esp32s2/pins_arduino.h b/variants/atmegazero_esp32s2/pins_arduino.h index 44df45e0b18..45fd447331d 100644 --- a/variants/atmegazero_esp32s2/pins_arduino.h +++ b/variants/atmegazero_esp32s2/pins_arduino.h @@ -2,6 +2,7 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x239A #define USB_PID 0x800A @@ -9,15 +10,15 @@ #define USB_PRODUCT "ATMZ-ESP32S2" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - 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 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 + static const uint8_t PD5 = 0; static const uint8_t TX = 43; diff --git a/variants/bpi-bit/pins_arduino.h b/variants/bpi-bit/pins_arduino.h index f1ef3003662..80ff9c2746b 100644 --- a/variants/bpi-bit/pins_arduino.h +++ b/variants/bpi-bit/pins_arduino.h @@ -2,22 +2,22 @@ #define Pins_Arduino_h #include - -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p) < 20) ? (analogChannelToDigitalPin(p)) : -1) -#define digitalPinToInterrupt(p) (((p) < 40) ? (p) : -1) -#define digitalPinHasPWM(p) (p < 34) +#include "soc/soc_caps.h" static const uint8_t BUZZER = 25; static const uint8_t BUTTON_A = 35; static const uint8_t BUTTON_B = 27; +// NeoPixel Matrix 5 x 5 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 +// RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() +#define RGB_BUILTIN LED_BUILTIN +#define RGB_BRIGHTNESS 64 static const uint8_t LIGHT_SENSOR1 = 36; static const uint8_t LIGHT_SENSOR2 = 39; diff --git a/variants/bpi_leaf_s3/pins_arduino.h b/variants/bpi_leaf_s3/pins_arduino.h index 56876ce9c9d..45117347e2d 100644 --- a/variants/bpi_leaf_s3/pins_arduino.h +++ b/variants/bpi_leaf_s3/pins_arduino.h @@ -10,23 +10,18 @@ #define USB_PRODUCT "BPI-Leaf-S3" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - // 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 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 -#define LED_BUILTIN LED_BUILTIN +#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 25 -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/ch_denky/pins_arduino.h b/variants/ch_denky/pins_arduino.h index 23a786e0e53..ac202d527db 100644 --- a/variants/ch_denky/pins_arduino.h +++ b/variants/ch_denky/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/cnrs_aw2eth/pins_arduino.h b/variants/cnrs_aw2eth/pins_arduino.h index 56db3aebe58..b21c5889a38 100644 --- a/variants/cnrs_aw2eth/pins_arduino.h +++ b/variants/cnrs_aw2eth/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/connaxio_espoir/pins_arduino.h b/variants/connaxio_espoir/pins_arduino.h index ac5d025afd8..6e9a4fa3ceb 100644 --- a/variants/connaxio_espoir/pins_arduino.h +++ b/variants/connaxio_espoir/pins_arduino.h @@ -8,14 +8,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - /* USB UART */ static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/crabik_slot_esp32_s3/pins_arduino.h b/variants/crabik_slot_esp32_s3/pins_arduino.h index 31aa9ee79cb..b5021d5cd03 100644 --- a/variants/crabik_slot_esp32_s3/pins_arduino.h +++ b/variants/crabik_slot_esp32_s3/pins_arduino.h @@ -9,17 +9,9 @@ #define USB_PRODUCT "Slot ESP32-S3" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t LED_BUILTIN = 21; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t S1 = 1; static const uint8_t S2 = 12; diff --git a/variants/cytron_maker_feather_aiot_s3/pins_arduino.h b/variants/cytron_maker_feather_aiot_s3/pins_arduino.h index bd3e9c278c9..cf75fa6b0ac 100644 --- a/variants/cytron_maker_feather_aiot_s3/pins_arduino.h +++ b/variants/cytron_maker_feather_aiot_s3/pins_arduino.h @@ -10,23 +10,14 @@ #define USB_PRODUCT "Maker Feather AIoT S3" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 20 -#define NUM_ANALOG_INPUTS 12 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - - - 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 BUILTIN_LED LED_BUILTIN // Backward compatibility -#define LED_BUILTIN LED_BUILTIN #define LED LED_BUILTIN -#define RGB_BUILTIN RGB_BUILTIN #define RGB RGB_BUILTIN #define NEOPIXEL RGB_BUILTIN #define RGB_BRIGHTNESS 65 diff --git a/variants/d-duino-32/pins_arduino.h b/variants/d-duino-32/pins_arduino.h index 579cdfac77b..935261996b1 100644 --- a/variants/d-duino-32/pins_arduino.h +++ b/variants/d-duino-32/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/d1_mini32/pins_arduino.h b/variants/d1_mini32/pins_arduino.h index 69982798610..1b507cde1fd 100644 --- a/variants/d1_mini32/pins_arduino.h +++ b/variants/d1_mini32/pins_arduino.h @@ -6,7 +6,7 @@ static const uint8_t LED_BUILTIN = 2; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#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 diff --git a/variants/d1_uno32/pins_arduino.h b/variants/d1_uno32/pins_arduino.h index 8bf0a6d7fa3..6f46d419c83 100644 --- a/variants/d1_uno32/pins_arduino.h +++ b/variants/d1_uno32/pins_arduino.h @@ -5,15 +5,6 @@ #include - -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; @@ -34,7 +25,7 @@ static const uint8_t A5 = 39; static const uint8_t LED_BUILTIN = 2; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define PIN_WIRE_SDA SDA // backward compatibility #define PIN_WIRE_SCL SCL // backward compatibility diff --git a/variants/d32/d32_core.h b/variants/d32/d32_core.h index 0416719f2cb..e658c980896 100644 --- a/variants/d32/d32_core.h +++ b/variants/d32/d32_core.h @@ -1,14 +1,6 @@ #ifndef _D32_CORE_H_ #define _D32_CORE_H_ -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/d32/pins_arduino.h b/variants/d32/pins_arduino.h index 810eeae6de2..e517def5e8f 100644 --- a/variants/d32/pins_arduino.h +++ b/variants/d32/pins_arduino.h @@ -6,7 +6,7 @@ static const uint8_t LED_BUILTIN = 5; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#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 ce36f21bc08..da7c14bc389 100644 --- a/variants/d32_pro/pins_arduino.h +++ b/variants/d32_pro/pins_arduino.h @@ -6,7 +6,8 @@ static const uint8_t LED_BUILTIN = 5; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN + static const uint8_t _VBAT = 35; // battery voltage #define TF_CS 4 // TF (Micro SD Card) CS pin diff --git a/variants/deneyapkart/pins_arduino.h b/variants/deneyapkart/pins_arduino.h index 9b28273cc7d..587f92433fa 100644 --- a/variants/deneyapkart/pins_arduino.h +++ b/variants/deneyapkart/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 4; -#define BUILTIN_LED LED_BUILTIN -#define LED_BUILTIN LED_BUILTIN +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define LEDB LED_BUILTIN #define LEDR 3 #define LEDG 1 diff --git a/variants/deneyapkart1A/pins_arduino.h b/variants/deneyapkart1A/pins_arduino.h index a079608fe16..edac64ac794 100644 --- a/variants/deneyapkart1A/pins_arduino.h +++ b/variants/deneyapkart1A/pins_arduino.h @@ -4,17 +4,9 @@ #include #include "soc/soc_caps.h" -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+13; -#define BUILTIN_LED LED_BUILTIN -#define LED_BUILTIN 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 RGB_BRIGHTNESS 64 diff --git a/variants/deneyapkart1Av2/pins_arduino.h b/variants/deneyapkart1Av2/pins_arduino.h index 24928d48422..34d84b057cf 100644 --- a/variants/deneyapkart1Av2/pins_arduino.h +++ b/variants/deneyapkart1Av2/pins_arduino.h @@ -10,17 +10,9 @@ #define USB_PRODUCT "DENEYAP KART 1A v2" #define USB_SERIAL "" // Empty string for MAC adddress -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+48; -#define BUILTIN_LED LED_BUILTIN -#define LED_BUILTIN 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 RGB_BRIGHTNESS 64 diff --git a/variants/deneyapkartg/pins_arduino.h b/variants/deneyapkartg/pins_arduino.h index f73f172876d..817f63affc1 100644 --- a/variants/deneyapkartg/pins_arduino.h +++ b/variants/deneyapkartg/pins_arduino.h @@ -10,17 +10,9 @@ #define USB_PRODUCT "DENEYAP KART G" #define USB_SERIAL "" // Empty string for MAC adddress -#define EXTERNAL_NUM_INTERRUPTS 22 -#define NUM_DIGITAL_PINS 22 -#define NUM_ANALOG_INPUTS 6 - -#define analogInputToDigitalPin(p) (((p) - +#include "soc/soc_caps.h" #define USB_VID 0x303a #define USB_PID 0x80FF @@ -10,18 +10,16 @@ #define USB_PRODUCT "MiniMain ESP32-S2" #define USB_SERIAL "" // Empty string for MAC adddress +// User LED +#define LED_BUILTIN 13 +#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - -#define LED_BUILTIN 13 - +// 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_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 diff --git a/variants/dfrobot_beetle_esp32c3/pins_arduino.h b/variants/dfrobot_beetle_esp32c3/pins_arduino.h index 735f894281f..abf093cfccb 100644 --- a/variants/dfrobot_beetle_esp32c3/pins_arduino.h +++ b/variants/dfrobot_beetle_esp32c3/pins_arduino.h @@ -9,16 +9,9 @@ #define USB_PRODUCT "Beetle ESP32-C3" #define USB_SERIAL "" // Empty string for MAC adddress - -#define EXTERNAL_NUM_INTERRUPTS 22 -#define NUM_DIGITAL_PINS 22 -#define NUM_ANALOG_INPUTS 6 - -#define analogInputToDigitalPin(p) (((p) -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - typedef unsigned char uint8_t; static const uint8_t LED_BUILTIN = 2; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN - - +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/dfrobot_firebeetle2_esp32s3/pins_arduino.h b/variants/dfrobot_firebeetle2_esp32s3/pins_arduino.h index 91e164478b2..012596b01af 100644 --- a/variants/dfrobot_firebeetle2_esp32s3/pins_arduino.h +++ b/variants/dfrobot_firebeetle2_esp32s3/pins_arduino.h @@ -9,15 +9,6 @@ #define USB_PRODUCT "FireBeetle 2 ESP32-S3" #define USB_SERIAL "" // Empty string for MAC adddress -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - - static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -50,6 +41,8 @@ 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 LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t T1 = 1; diff --git a/variants/dfrobot_romeo_esp32s3/pins_arduino.h b/variants/dfrobot_romeo_esp32s3/pins_arduino.h index 1c16f6e9f65..40774c71ddf 100644 --- a/variants/dfrobot_romeo_esp32s3/pins_arduino.h +++ b/variants/dfrobot_romeo_esp32s3/pins_arduino.h @@ -3,17 +3,6 @@ #include - - -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - - static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/doitESP32devkitV1/pins_arduino.h b/variants/doitESP32devkitV1/pins_arduino.h index 69e4138428f..467c58c0034 100644 --- a/variants/doitESP32devkitV1/pins_arduino.h +++ b/variants/doitESP32devkitV1/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 2; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/doitESPduino32/pins_arduino.h b/variants/doitESPduino32/pins_arduino.h index 991090a5fac..afd5dbe6aab 100644 --- a/variants/doitESPduino32/pins_arduino.h +++ b/variants/doitESPduino32/pins_arduino.h @@ -3,16 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - 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 SDA = 21; diff --git a/variants/dpu_esp32/pins_arduino.h b/variants/dpu_esp32/pins_arduino.h index ff6cb1e9ba4..1b2e1b6634f 100644 --- a/variants/dpu_esp32/pins_arduino.h +++ b/variants/dpu_esp32/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/esp32-devkit-lipo/pins_arduino.h b/variants/esp32-devkit-lipo/pins_arduino.h index d784eb0297a..fb715c0e79e 100644 --- a/variants/esp32-devkit-lipo/pins_arduino.h +++ b/variants/esp32-devkit-lipo/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/esp32-evb/pins_arduino.h b/variants/esp32-evb/pins_arduino.h index 327a5ba92e4..43691f02c7b 100644 --- a/variants/esp32-evb/pins_arduino.h +++ b/variants/esp32-evb/pins_arduino.h @@ -3,15 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - - static const uint8_t KEY_BUILTIN = 34; static const uint8_t TX = 1; diff --git a/variants/esp32-gateway/pins_arduino.h b/variants/esp32-gateway/pins_arduino.h index 5dd5d7e0fd9..1ba5fd0bfe9 100644 --- a/variants/esp32-gateway/pins_arduino.h +++ b/variants/esp32-gateway/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - #if defined (ARDUINO_ESP32_GATEWAY_E) || defined (ARDUINO_ESP32_GATEWAY_F) #define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT #define ETH_PHY_POWER 5 @@ -18,7 +10,7 @@ static const uint8_t LED_BUILTIN = 33; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 34; diff --git a/variants/esp32-poe-iso/pins_arduino.h b/variants/esp32-poe-iso/pins_arduino.h index 06a0dc15afd..b9033d74cfe 100644 --- a/variants/esp32-poe-iso/pins_arduino.h +++ b/variants/esp32-poe-iso/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - #define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT #define ETH_PHY_POWER 12 diff --git a/variants/esp32-poe/pins_arduino.h b/variants/esp32-poe/pins_arduino.h index 06a0dc15afd..b9033d74cfe 100644 --- a/variants/esp32-poe/pins_arduino.h +++ b/variants/esp32-poe/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - #define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT #define ETH_PHY_POWER 12 diff --git a/variants/esp32-trueverit-iot-driver-mkii/pins_arduino.h b/variants/esp32-trueverit-iot-driver-mkii/pins_arduino.h index aea4585f266..222046998dc 100644 --- a/variants/esp32-trueverit-iot-driver-mkii/pins_arduino.h +++ b/variants/esp32-trueverit-iot-driver-mkii/pins_arduino.h @@ -4,15 +4,8 @@ #include static const uint8_t LED_BUILTIN = 18; -#define BUILTIN_LED LED_BUILTIN // backward compatibility - -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p) < 20) ? (analogChannelToDigitalPin(p)) : -1) -#define digitalPinToInterrupt(p) (((p) < 40) ? (p) : -1) -#define digitalPinHasPWM(p) (p < 34) +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define TX1 12 #define RX1 13 diff --git a/variants/esp32-trueverit-iot-driver-mkiii/pins_arduino.h b/variants/esp32-trueverit-iot-driver-mkiii/pins_arduino.h index b86654113b8..0a468d58856 100644 --- a/variants/esp32-trueverit-iot-driver-mkiii/pins_arduino.h +++ b/variants/esp32-trueverit-iot-driver-mkiii/pins_arduino.h @@ -4,15 +4,8 @@ #include static const uint8_t LED_BUILTIN = 18; -#define BUILTIN_LED LED_BUILTIN // backward compatibility - -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p) < 20) ? (analogChannelToDigitalPin(p)) : -1) -#define digitalPinToInterrupt(p) (((p) < 40) ? (p) : -1) -#define digitalPinHasPWM(p) (p < 34) +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define TX1 12 #define RX1 13 diff --git a/variants/esp32-trueverit-iot-driver/pins_arduino.h b/variants/esp32-trueverit-iot-driver/pins_arduino.h index f6fa15fc4f2..da4ef3ce633 100644 --- a/variants/esp32-trueverit-iot-driver/pins_arduino.h +++ b/variants/esp32-trueverit-iot-driver/pins_arduino.h @@ -4,15 +4,8 @@ #include static const uint8_t LED_BUILTIN = 18; -#define BUILTIN_LED LED_BUILTIN // backward compatibility - -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p) < 20) ? (analogChannelToDigitalPin(p)) : -1) -#define digitalPinToInterrupt(p) (((p) < 40) ? (p) : -1) -#define digitalPinHasPWM(p) (p < 34) +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define TX1 12 #define RX1 13 diff --git a/variants/esp32/pins_arduino.h b/variants/esp32/pins_arduino.h index 4ad96ccef51..27ecc063483 100644 --- a/variants/esp32/pins_arduino.h +++ b/variants/esp32/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/esp320/pins_arduino.h b/variants/esp320/pins_arduino.h index f62b6502c42..a7091aa09b2 100644 --- a/variants/esp320/pins_arduino.h +++ b/variants/esp320/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 11 -#define NUM_DIGITAL_PINS 12 -#define NUM_ANALOG_INPUTS 5 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 5; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/esp32_s3r8n16/pins_arduino.h b/variants/esp32_s3r8n16/pins_arduino.h index 919765a7583..ba3f1908875 100644 --- a/variants/esp32_s3r8n16/pins_arduino.h +++ b/variants/esp32_s3r8n16/pins_arduino.h @@ -2,7 +2,6 @@ #define Pins_Arduino_h #include -#include "soc/soc_caps.h" #define USB_VID 0x303a #define USB_PID 0x1001 @@ -10,14 +9,6 @@ #define USB_PRODUCT "4D Systems gen4-ESP32 16MB Modules (ESP32-S3R8n16)" //#define USB_CLASS 2 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/esp32c3/pins_arduino.h b/variants/esp32c3/pins_arduino.h index ab28240d4b4..71318e27cf9 100644 --- a/variants/esp32c3/pins_arduino.h +++ b/variants/esp32c3/pins_arduino.h @@ -4,20 +4,15 @@ #include #include "soc/soc_caps.h" -#define EXTERNAL_NUM_INTERRUPTS 22 -#define NUM_DIGITAL_PINS 22 -#define NUM_ANALOG_INPUTS 6 - -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+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 -#define LED_BUILTIN LED_BUILTIN +#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 analogInputToDigitalPin(p) (((p) #include "soc/soc_caps.h" -#define EXTERNAL_NUM_INTERRUPTS 24 -#define NUM_DIGITAL_PINS 24 -#define NUM_ANALOG_INPUTS 7 - -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+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 -#define LED_BUILTIN LED_BUILTIN +#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 analogInputToDigitalPin(p) (((p) -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/esp32h2/pins_arduino.h b/variants/esp32h2/pins_arduino.h index dda584ccb49..93a02871090 100644 --- a/variants/esp32h2/pins_arduino.h +++ b/variants/esp32h2/pins_arduino.h @@ -4,20 +4,15 @@ #include #include "soc/soc_caps.h" -#define EXTERNAL_NUM_INTERRUPTS 28 -#define NUM_DIGITAL_PINS 28 -#define NUM_ANALOG_INPUTS 5 - -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+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 -#define LED_BUILTIN LED_BUILTIN +#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 analogInputToDigitalPin(p) (((p) -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; @@ -71,5 +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 LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #endif /* Pins_Arduino_h */ diff --git a/variants/esp32s2/pins_arduino.h b/variants/esp32s2/pins_arduino.h index 4ab0f712042..ea68934a69b 100644 --- a/variants/esp32s2/pins_arduino.h +++ b/variants/esp32s2/pins_arduino.h @@ -4,21 +4,18 @@ #include #include "soc/soc_caps.h" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+18; // GPIO pin for Saola-1 & DevKitM-1 = 18 -//static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+45; // GPIO pin for Kaluga = 45 +// GPIO pin for Saola-1 & DevKitM-1 = 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 -#define LED_BUILTIN LED_BUILTIN +#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 analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/esp32s2thing_plus/pins_arduino.h b/variants/esp32s2thing_plus/pins_arduino.h index 219f357981e..d5c4510aa5d 100644 --- a/variants/esp32s2thing_plus/pins_arduino.h +++ b/variants/esp32s2thing_plus/pins_arduino.h @@ -9,16 +9,9 @@ #define USB_PRODUCT "ESP32-S2 Thing Plus" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t LED_BUILTIN = 13; #define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/esp32s2usb/pins_arduino.h b/variants/esp32s2usb/pins_arduino.h index c6d464b79b4..636c62482a0 100644 --- a/variants/esp32s2usb/pins_arduino.h +++ b/variants/esp32s2usb/pins_arduino.h @@ -19,15 +19,6 @@ #define USB_FW_MSC_VOLUME_NAME "S2-Firmware" //max 11 chars #define USB_FW_MSC_SERIAL_NUMBER 0x00000000 - -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/esp32s3/pins_arduino.h b/variants/esp32s3/pins_arduino.h index d746573aa94..339b47df0b4 100644 --- a/variants/esp32s3/pins_arduino.h +++ b/variants/esp32s3/pins_arduino.h @@ -7,22 +7,18 @@ #define USB_VID 0x303a #define USB_PID 0x1001 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - // 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 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 -#define LED_BUILTIN LED_BUILTIN +#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 analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/esp32s3box/pins_arduino.h b/variants/esp32s3box/pins_arduino.h index 3ed655d1d3f..115ded2a2ec 100644 --- a/variants/esp32s3box/pins_arduino.h +++ b/variants/esp32s3box/pins_arduino.h @@ -6,14 +6,6 @@ #define USB_VID 0x303a #define USB_PID 0x1001 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/esp32s3camlcd/pins_arduino.h b/variants/esp32s3camlcd/pins_arduino.h index 308644ff52e..9580091dd3a 100644 --- a/variants/esp32s3camlcd/pins_arduino.h +++ b/variants/esp32s3camlcd/pins_arduino.h @@ -6,14 +6,6 @@ #define USB_VID 0x303a #define USB_PID 0x1001 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/esp32s3usbotg/pins_arduino.h b/variants/esp32s3usbotg/pins_arduino.h index 94edeeca74c..1983c45d1a4 100644 --- a/variants/esp32s3usbotg/pins_arduino.h +++ b/variants/esp32s3usbotg/pins_arduino.h @@ -6,14 +6,6 @@ #define USB_VID 0x303a #define USB_PID 0x1001 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/esp32thing/pins_arduino.h b/variants/esp32thing/pins_arduino.h index 2ab5614033f..68178cc2296 100644 --- a/variants/esp32thing/pins_arduino.h +++ b/variants/esp32thing/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 5; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/esp32thing_plus/pins_arduino.h b/variants/esp32thing_plus/pins_arduino.h index f1342b2c3c0..9b4b1e25147 100644 --- a/variants/esp32thing_plus/pins_arduino.h +++ b/variants/esp32thing_plus/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 13; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 17; static const uint8_t RX = 16; diff --git a/variants/esp32thing_plus_c/pins_arduino.h b/variants/esp32thing_plus_c/pins_arduino.h index e91fb212a99..fbfe934a698 100644 --- a/variants/esp32thing_plus_c/pins_arduino.h +++ b/variants/esp32thing_plus_c/pins_arduino.h @@ -4,20 +4,13 @@ #include #include "soc/soc_caps.h" -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 13; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#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; -#define RGB_BUILTIN RGB_BUILTIN +#define RGB_BUILTIN RGB_BUILTIN // necessary to make digitalWrite/digitalMode find it #define RGB_BRIGHTNESS 64 static const uint8_t TX = 17; diff --git a/variants/esp32vn-iot-uno/pins_arduino.h b/variants/esp32vn-iot-uno/pins_arduino.h index c6e9127e254..fd196bdf34f 100644 --- a/variants/esp32vn-iot-uno/pins_arduino.h +++ b/variants/esp32vn-iot-uno/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/esp_c3_m1_i_kit/pins_arduino.h b/variants/esp_c3_m1_i_kit/pins_arduino.h index 0a1a0fe9fe8..8f5f433fea3 100644 --- a/variants/esp_c3_m1_i_kit/pins_arduino.h +++ b/variants/esp_c3_m1_i_kit/pins_arduino.h @@ -8,14 +8,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 22 -#define NUM_DIGITAL_PINS 22 -#define NUM_ANALOG_INPUTS 6 - -#define analogInputToDigitalPin(p) (((p) -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 5; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/espectro32/pins_arduino.h b/variants/espectro32/pins_arduino.h index 0be1919c1d6..449b79247ac 100644 --- a/variants/espectro32/pins_arduino.h +++ b/variants/espectro32/pins_arduino.h @@ -7,17 +7,9 @@ #define ESPECTRO32_VERSION 1 #endif -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 15; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/espino32/pins_arduino.h b/variants/espino32/pins_arduino.h index 586f9725dc4..571912b7ee9 100644 --- a/variants/espino32/pins_arduino.h +++ b/variants/espino32/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 38 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 16; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t BUILTIN_KEY = 0; diff --git a/variants/feather_esp32/pins_arduino.h b/variants/feather_esp32/pins_arduino.h index 8b2b200ddcb..bc7c2dc6656 100644 --- a/variants/feather_esp32/pins_arduino.h +++ b/variants/feather_esp32/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 13; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 17; static const uint8_t RX = 16; diff --git a/variants/firebeetle32/pins_arduino.h b/variants/firebeetle32/pins_arduino.h index 15d54fe9a37..7fd4a527975 100644 --- a/variants/firebeetle32/pins_arduino.h +++ b/variants/firebeetle32/pins_arduino.h @@ -3,21 +3,11 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - typedef unsigned char uint8_t; static const uint8_t LED_BUILTIN = 2; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN - - +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/fm-devkit/pins_arduino.h b/variants/fm-devkit/pins_arduino.h index 5c1054fafb5..b0cc94038f6 100644 --- a/variants/fm-devkit/pins_arduino.h +++ b/variants/fm-devkit/pins_arduino.h @@ -3,19 +3,13 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - 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; diff --git a/variants/franzininho_wifi_esp32s2/pins_arduino.h b/variants/franzininho_wifi_esp32s2/pins_arduino.h index dd287f417d0..4a07156d0c3 100644 --- a/variants/franzininho_wifi_esp32s2/pins_arduino.h +++ b/variants/franzininho_wifi_esp32s2/pins_arduino.h @@ -2,6 +2,7 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x303A #define USB_PID 0x80A9 @@ -10,15 +11,14 @@ #define USB_SERIAL "0" #define USB_WEBUSB_ENABLED false -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - 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 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 static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/franzininho_wifi_msc_esp32s2/pins_arduino.h b/variants/franzininho_wifi_msc_esp32s2/pins_arduino.h index 58db2039d26..0589ad421d2 100644 --- a/variants/franzininho_wifi_msc_esp32s2/pins_arduino.h +++ b/variants/franzininho_wifi_msc_esp32s2/pins_arduino.h @@ -2,6 +2,7 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x303A #define USB_PID 0x80A9 @@ -17,15 +18,14 @@ #define USB_FW_MSC_VOLUME_NAME "S2-Firmware" //max 11 chars #define USB_FW_MSC_SERIAL_NUMBER 0x00000000 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - 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 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 static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/frog32/pins_arduino.h b/variants/frog32/pins_arduino.h index 4ad96ccef51..27ecc063483 100644 --- a/variants/frog32/pins_arduino.h +++ b/variants/frog32/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/gpy/pins_arduino.h b/variants/gpy/pins_arduino.h index aa41db48bf1..255363ce5c7 100644 --- a/variants/gpy/pins_arduino.h +++ b/variants/gpy/pins_arduino.h @@ -2,14 +2,7 @@ #define Pins_Arduino_h #include - -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 18 - -#define analogInputToDigitalPin(p) (((p)<40)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) +#include "soc/soc_caps.h" // Sequans Monarch LTE Cat M1/NB1 modem // NOTE: The Pycom pinout as well as spec sheet block diagram / pin details @@ -22,9 +15,14 @@ #define LTE_WAKE 27 // GPIO27 - Sequans modem wake-up interrupt #define LTE_BAUD 921600 -static const uint8_t LED_BUILTIN = 0; // ->2812 RGB !!! +// 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 LED_BUILTIN LED_BUILTIN +#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 diff --git a/variants/healthypi4/pins_arduino.h b/variants/healthypi4/pins_arduino.h index b3eb897374a..69471053402 100644 --- a/variants/healthypi4/pins_arduino.h +++ b/variants/healthypi4/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 15; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 17; diff --git a/variants/heltec_wifi_kit_32/pins_arduino.h b/variants/heltec_wifi_kit_32/pins_arduino.h index 9efa252d564..a164f9e153a 100644 --- a/variants/heltec_wifi_kit_32/pins_arduino.h +++ b/variants/heltec_wifi_kit_32/pins_arduino.h @@ -7,17 +7,9 @@ #define DISPLAY_HEIGHT 64 #define DISPLAY_WIDTH 128 -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 25; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/heltec_wifi_kit_32_v3/pins_arduino.h b/variants/heltec_wifi_kit_32_V3/pins_arduino.h similarity index 84% rename from variants/heltec_wifi_kit_32_v3/pins_arduino.h rename to variants/heltec_wifi_kit_32_V3/pins_arduino.h index 6e889604dd8..c64fe199860 100644 --- a/variants/heltec_wifi_kit_32_v3/pins_arduino.h +++ b/variants/heltec_wifi_kit_32_V3/pins_arduino.h @@ -7,17 +7,9 @@ #define DISPLAY_HEIGHT 64 #define DISPLAY_WIDTH 128 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t LED_BUILTIN = 35; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/heltec_wifi_lora_32/pins_arduino.h b/variants/heltec_wifi_lora_32/pins_arduino.h index ee5a2affd46..b702b97f437 100644 --- a/variants/heltec_wifi_lora_32/pins_arduino.h +++ b/variants/heltec_wifi_lora_32/pins_arduino.h @@ -7,17 +7,9 @@ #define DISPLAY_HEIGHT 64 #define DISPLAY_WIDTH 128 -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 25; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/heltec_wifi_lora_32_V2/pins_arduino.h b/variants/heltec_wifi_lora_32_V2/pins_arduino.h index 420c23c3ffa..d316145b8c6 100644 --- a/variants/heltec_wifi_lora_32_V2/pins_arduino.h +++ b/variants/heltec_wifi_lora_32_V2/pins_arduino.h @@ -7,17 +7,9 @@ #define DISPLAY_HEIGHT 64 #define DISPLAY_WIDTH 128 -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 25; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/heltec_wifi_lora_32_V3/pins_arduino.h b/variants/heltec_wifi_lora_32_V3/pins_arduino.h index cbc50a0d117..bd0d35a8912 100644 --- a/variants/heltec_wifi_lora_32_V3/pins_arduino.h +++ b/variants/heltec_wifi_lora_32_V3/pins_arduino.h @@ -2,7 +2,6 @@ #define Pins_Arduino_h #include -#include "soc/soc_caps.h" #define WIFI_LoRa_32_V3 true #define DISPLAY_HEIGHT 64 @@ -11,22 +10,9 @@ #define USB_VID 0x303a #define USB_PID 0x1001 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -// 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; +static const uint8_t LED_BUILTIN = 35; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN -#define RGB_BUILTIN LED_BUILTIN -#define RGB_BRIGHTNESS 64 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/heltec_wireless_stick/pins_arduino.h b/variants/heltec_wireless_stick/pins_arduino.h index a1c4eec28c8..0910fcc7672 100644 --- a/variants/heltec_wireless_stick/pins_arduino.h +++ b/variants/heltec_wireless_stick/pins_arduino.h @@ -7,17 +7,9 @@ #define DISPLAY_HEIGHT 32 #define DISPLAY_WIDTH 64 -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 25; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/heltec_wireless_stick_lite/pins_arduino.h b/variants/heltec_wireless_stick_lite/pins_arduino.h index 981c66b2b74..ec4bac483de 100644 --- a/variants/heltec_wireless_stick_lite/pins_arduino.h +++ b/variants/heltec_wireless_stick_lite/pins_arduino.h @@ -7,17 +7,9 @@ #define DISPLAY_HEIGHT 0 #define DISPLAY_WIDTH 0 -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 25; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/heltec_wireless_stick_lite_v3/pins_arduino.h b/variants/heltec_wireless_stick_lite_v3/pins_arduino.h index 174b9e7f2d5..bf6cf207660 100644 --- a/variants/heltec_wireless_stick_lite_v3/pins_arduino.h +++ b/variants/heltec_wireless_stick_lite_v3/pins_arduino.h @@ -7,17 +7,9 @@ #define DISPLAY_HEIGHT 0 #define DISPLAY_WIDTH 0 -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 20 -#define NUM_ANALOG_INPUTS 15 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 35; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/honeylemon/pins_arduino.h b/variants/honeylemon/pins_arduino.h index 0156f5d3254..044dad7f269 100644 --- a/variants/honeylemon/pins_arduino.h +++ b/variants/honeylemon/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 38 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 2; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t BUILTIN_KEY = 0; diff --git a/variants/hornbill32dev/pins_arduino.h b/variants/hornbill32dev/pins_arduino.h index 48adf9d75a8..a868a7edffa 100644 --- a/variants/hornbill32dev/pins_arduino.h +++ b/variants/hornbill32dev/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 13; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/hornbill32minima/pins_arduino.h b/variants/hornbill32minima/pins_arduino.h index c8d65c77a01..a8fb52c60f7 100644 --- a/variants/hornbill32minima/pins_arduino.h +++ b/variants/hornbill32minima/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; //taken out on pgm header static const uint8_t RX = 3; //taken out on pgm header diff --git a/variants/imbrios-logsens-v1p1/pins_arduino.h b/variants/imbrios-logsens-v1p1/pins_arduino.h index 3c3f083e034..338b9151f7d 100644 --- a/variants/imbrios-logsens-v1p1/pins_arduino.h +++ b/variants/imbrios-logsens-v1p1/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 9 -#define NUM_ANALOG_INPUTS 7 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - // Renaming few signals #define SPI_CLK SCK // IO14 #define SPI_MISO MISO // IO12 @@ -22,8 +14,8 @@ /* 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 LED_BUILTIN LED_BUILTIN +#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 */ static const uint8_t TX = 1; diff --git a/variants/intorobot-fig/pins_arduino.h b/variants/intorobot-fig/pins_arduino.h index 50cb9c83ce4..a0e8db822e8 100644 --- a/variants/intorobot-fig/pins_arduino.h +++ b/variants/intorobot-fig/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 7 -#define NUM_ANALOG_INPUTS 10 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 4; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t RGB_R_BUILTIN = 27; static const uint8_t RGB_G_BUILTIN = 21; diff --git a/variants/ioxesp32/pins_arduino.h b/variants/ioxesp32/pins_arduino.h index 37985c2b476..2a27157366f 100644 --- a/variants/ioxesp32/pins_arduino.h +++ b/variants/ioxesp32/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 5; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/lilygo_t_display/pins_arduino.h b/variants/lilygo_t_display/pins_arduino.h index 87edf8ccd32..beae4b311c6 100644 --- a/variants/lilygo_t_display/pins_arduino.h +++ b/variants/lilygo_t_display/pins_arduino.h @@ -9,14 +9,6 @@ #define USB_PRODUCT "T-Display" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; @@ -64,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 */ +#endif /* Pins_Arduino_h */ \ No newline at end of file diff --git a/variants/lilygo_t_display_s3/pins_arduino.h b/variants/lilygo_t_display_s3/pins_arduino.h index 099bdad5876..42b01587c39 100644 --- a/variants/lilygo_t_display_s3/pins_arduino.h +++ b/variants/lilygo_t_display_s3/pins_arduino.h @@ -2,19 +2,10 @@ #define Pins_Arduino_h #include -#include "soc/soc_caps.h" #define USB_VID 0x303a #define USB_PID 0x1001 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t BUTTON_1 = 0; static const uint8_t BUTTON_2 = 14; static const uint8_t BAT_VOLT = 4; diff --git a/variants/lionbit/pins_arduino.h b/variants/lionbit/pins_arduino.h index b7f5825079a..25d7bc1765c 100644 --- a/variants/lionbit/pins_arduino.h +++ b/variants/lionbit/pins_arduino.h @@ -3,15 +3,10 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p) < 20) ? (analogChannelToDigitalPin(p)) : -1) -#define digitalPinToInterrupt(p) (((p) < 40) ? (p) : -1) -#define digitalPinHasPWM(p) (p < 34) - 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 diff --git a/variants/lionbits3/pins_arduino.h b/variants/lionbits3/pins_arduino.h index 1428b1507c5..f7817d8340d 100644 --- a/variants/lionbits3/pins_arduino.h +++ b/variants/lionbits3/pins_arduino.h @@ -3,15 +3,10 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p) < 20) ? (analogChannelToDigitalPin(p)) : -1) -#define digitalPinToInterrupt(p) (((p) < 40) ? (p) : -1) -#define digitalPinHasPWM(p) (p < 34) - 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, //Wifi and Bluetooth LEDs diff --git a/variants/lolin32-lite/pins_arduino.h b/variants/lolin32-lite/pins_arduino.h index 883695dfcf1..6aa497a8575 100755 --- a/variants/lolin32-lite/pins_arduino.h +++ b/variants/lolin32-lite/pins_arduino.h @@ -3,19 +3,12 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - 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 LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t SDA = 19; static const uint8_t SCL = 23; diff --git a/variants/lolin32/pins_arduino.h b/variants/lolin32/pins_arduino.h index f38be67cc58..cba6162b645 100644 --- a/variants/lolin32/pins_arduino.h +++ b/variants/lolin32/pins_arduino.h @@ -3,19 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 5; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN - - +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/lolin_c3_mini/pins_arduino.h b/variants/lolin_c3_mini/pins_arduino.h index 59889448572..842683330cd 100644 --- a/variants/lolin_c3_mini/pins_arduino.h +++ b/variants/lolin_c3_mini/pins_arduino.h @@ -3,16 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 22 -#define NUM_DIGITAL_PINS 22 -#define NUM_ANALOG_INPUTS 6 - -#define analogInputToDigitalPin(p) (((p) +#include "soc/soc_caps.h" #define USB_VID 0x303a #define USB_PID 0x8167 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 18 - - -static const uint8_t LED_BUILTIN = 47; +static const uint8_t LED_BUILTIN = 47+SOC_GPIO_PIN_COUNT; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/lolin_s3_pro/pins_arduino.h b/variants/lolin_s3_pro/pins_arduino.h index a70e31b74d8..6a3259ed6e8 100644 --- a/variants/lolin_s3_pro/pins_arduino.h +++ b/variants/lolin_s3_pro/pins_arduino.h @@ -2,25 +2,17 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x303a #define USB_PID 0x8161 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 18 - - -static const uint8_t LED_BUILTIN = 38; +static const uint8_t LED_BUILTIN = 38+SOC_GPIO_PIN_COUNT; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/lopy/pins_arduino.h b/variants/lopy/pins_arduino.h index 235f209825a..2c44d12d06b 100644 --- a/variants/lopy/pins_arduino.h +++ b/variants/lopy/pins_arduino.h @@ -2,14 +2,7 @@ #define Pins_Arduino_h #include - -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 18 - -#define analogInputToDigitalPin(p) (((p)<40)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) +#include "soc/soc_caps.h" // SPI LoRa Radio #define LORA_SCK 5 // GPIO5 - SX1276 SCK @@ -22,9 +15,14 @@ #define LORA_IO1 LORA_IRQ // tied by diode to IO0 #define LORA_IO2 LORA_IRQ // tied by diode to IO0 -static const uint8_t LED_BUILTIN = 0; // ->2812 RGB !!! +// 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 LED_BUILTIN LED_BUILTIN +#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 diff --git a/variants/lopy4/pins_arduino.h b/variants/lopy4/pins_arduino.h index 723d3fa8c3c..ba89a4b401f 100644 --- a/variants/lopy4/pins_arduino.h +++ b/variants/lopy4/pins_arduino.h @@ -2,14 +2,7 @@ #define Pins_Arduino_h #include - -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 18 - -#define analogInputToDigitalPin(p) (((p)<40)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) +#include "soc/soc_caps.h" // SPI LoRa Radio #define LORA_SCK 5 // GPIO5 - SX1276 SCK @@ -22,9 +15,14 @@ #define LORA_IO2 LORA_IRQ // tied by diode to IO0 #define LORA_RST NOT_A_PIN -static const uint8_t LED_BUILTIN = 0; // ->2812 RGB !!! +// 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 LED_BUILTIN LED_BUILTIN +#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 diff --git a/variants/m5stack_atom/pins_arduino.h b/variants/m5stack_atom/pins_arduino.h index 645436bd7da..00f3d130743 100644 --- a/variants/m5stack_atom/pins_arduino.h +++ b/variants/m5stack_atom/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/m5stack_atoms3/pins_arduino.h b/variants/m5stack_atoms3/pins_arduino.h index 8af4ef2e53d..4da5a93b978 100644 --- a/variants/m5stack_atoms3/pins_arduino.h +++ b/variants/m5stack_atoms3/pins_arduino.h @@ -7,24 +7,12 @@ #define USB_VID 0x303a #define USB_PID 0x1001 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -// 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 -#define LED_BUILTIN LED_BUILTIN +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 35; +#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 -#define analogInputToDigitalPin(p) \ - (((p) < 20) ? (analogChannelToDigitalPin(p)) : -1) -#define digitalPinToInterrupt(p) (((p) < 48) ? (p) : -1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/m5stack_core2/pins_arduino.h b/variants/m5stack_core2/pins_arduino.h index 895c7c0de2a..c5ea5d78eee 100644 --- a/variants/m5stack_core2/pins_arduino.h +++ b/variants/m5stack_core2/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - #define TX2 14 #define RX2 13 diff --git a/variants/m5stack_core_esp32/pins_arduino.h b/variants/m5stack_core_esp32/pins_arduino.h index 8b86a0d6fdc..1984ab6bc6e 100644 --- a/variants/m5stack_core_esp32/pins_arduino.h +++ b/variants/m5stack_core_esp32/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 20 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/m5stack_coreink/pins_arduino.h b/variants/m5stack_coreink/pins_arduino.h index 4ce9b122880..84c0903c166 100644 --- a/variants/m5stack_coreink/pins_arduino.h +++ b/variants/m5stack_coreink/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - #define TX2 14 #define RX2 13 diff --git a/variants/m5stack_cores3/pins_arduino.h b/variants/m5stack_cores3/pins_arduino.h index c8c979abe69..fd6e5b886d3 100644 --- a/variants/m5stack_cores3/pins_arduino.h +++ b/variants/m5stack_cores3/pins_arduino.h @@ -2,28 +2,11 @@ #define Pins_Arduino_h #include -#include "soc/soc_caps.h" #define USB_VID 0x303a #define USB_PID 0x1001 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -// 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 -#define LED_BUILTIN LED_BUILTIN -#define RGB_BUILTIN LED_BUILTIN -#define RGB_BRIGHTNESS 64 - -#define analogInputToDigitalPin(p) \ - (((p) < 20) ? (analogChannelToDigitalPin(p)) : -1) -#define digitalPinToInterrupt(p) (((p) < 48) ? (p) : -1) -#define digitalPinHasPWM(p) (p < 46) +// CoreS3 has no builtin LED / NeoLED static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/m5stack_fire/pins_arduino.h b/variants/m5stack_fire/pins_arduino.h index 8b86a0d6fdc..1984ab6bc6e 100644 --- a/variants/m5stack_fire/pins_arduino.h +++ b/variants/m5stack_fire/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 20 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/m5stack_stamp_pico/pins_arduino.h b/variants/m5stack_stamp_pico/pins_arduino.h index d784362da76..705890facea 100644 --- a/variants/m5stack_stamp_pico/pins_arduino.h +++ b/variants/m5stack_stamp_pico/pins_arduino.h @@ -3,15 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/m5stack_stamp_s3/pins_arduino.h b/variants/m5stack_stamp_s3/pins_arduino.h index 510a459b11d..999d8c753a5 100644 --- a/variants/m5stack_stamp_s3/pins_arduino.h +++ b/variants/m5stack_stamp_s3/pins_arduino.h @@ -2,20 +2,10 @@ #define Pins_Arduino_h #include -#include "soc/soc_caps.h" #define USB_VID 0x303a #define USB_PID 0x1001 -#define EXTERNAL_NUM_INTERRUPTS 23 -#define NUM_DIGITAL_PINS 46 -#define NUM_ANALOG_INPUTS 15 - -#define analogInputToDigitalPin(p) \ - (((p) < 20) ? (analogChannelToDigitalPin(p)) : -1) -#define digitalPinToInterrupt(p) (((p) < 48) ? (p) : -1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/m5stack_station/pins_arduino.h b/variants/m5stack_station/pins_arduino.h index 9ba182b90b5..3a5812e3262 100644 --- a/variants/m5stack_station/pins_arduino.h +++ b/variants/m5stack_station/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 20 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p<34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/m5stack_timer_cam/pins_arduino.h b/variants/m5stack_timer_cam/pins_arduino.h index 1f7f4b46aae..f26bac1482c 100644 --- a/variants/m5stack_timer_cam/pins_arduino.h +++ b/variants/m5stack_timer_cam/pins_arduino.h @@ -3,16 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - 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; diff --git a/variants/m5stick_c/pins_arduino.h b/variants/m5stick_c/pins_arduino.h index e4d73f6a2e3..35092416486 100644 --- a/variants/m5stick_c/pins_arduino.h +++ b/variants/m5stick_c/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/magicbit/pins_arduino.h b/variants/magicbit/pins_arduino.h index 6bf769942a7..0e91fa211a0 100644 --- a/variants/magicbit/pins_arduino.h +++ b/variants/magicbit/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; @@ -66,6 +58,9 @@ static const uint8_t MOTOR1A = 27; 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 +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #endif /* Pins_Arduino_h */ diff --git a/variants/metro_esp-32/pins_arduino.h b/variants/metro_esp-32/pins_arduino.h index 6675823c50e..cc13c5f6ffc 100644 --- a/variants/metro_esp-32/pins_arduino.h +++ b/variants/metro_esp-32/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 2; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/mgbot-iotik32a/pins_arduino.h b/variants/mgbot-iotik32a/pins_arduino.h index 283e01b2b9b..84de808ee08 100644 --- a/variants/mgbot-iotik32a/pins_arduino.h +++ b/variants/mgbot-iotik32a/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 4; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/mgbot-iotik32b/pins_arduino.h b/variants/mgbot-iotik32b/pins_arduino.h index 04dfe30c52f..81ee34f16e5 100644 --- a/variants/mgbot-iotik32b/pins_arduino.h +++ b/variants/mgbot-iotik32b/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 18; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // IR receiver static const uint8_t IR = 27; diff --git a/variants/mhetesp32devkit/pins_arduino.h b/variants/mhetesp32devkit/pins_arduino.h index badd89bf58c..467c58c0034 100644 --- a/variants/mhetesp32devkit/pins_arduino.h +++ b/variants/mhetesp32devkit/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN -#define LED_BUILTIN LED_BUILTIN +#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; diff --git a/variants/mhetesp32minikit/pins_arduino.h b/variants/mhetesp32minikit/pins_arduino.h index badd89bf58c..467c58c0034 100644 --- a/variants/mhetesp32minikit/pins_arduino.h +++ b/variants/mhetesp32minikit/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 2; -#define BUILTIN_LED LED_BUILTIN -#define LED_BUILTIN LED_BUILTIN +#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; diff --git a/variants/micro_s2/pins_arduino.h b/variants/micro_s2/pins_arduino.h index 389e51d9772..18fd2685b80 100644 --- a/variants/micro_s2/pins_arduino.h +++ b/variants/micro_s2/pins_arduino.h @@ -9,14 +9,6 @@ #define USB_PRODUCT "microS2" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -70,8 +62,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 +#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_BRIGHTNESS 64 + static const uint8_t BUTTON_BUILTIN = 0; #endif /* Pins_Arduino_h */ diff --git a/variants/mpython/pins_arduino.h b/variants/mpython/pins_arduino.h index 301700d6355..5f17b4ad1e3 100644 --- a/variants/mpython/pins_arduino.h +++ b/variants/mpython/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/namino_arancio/pins_arduino.h b/variants/namino_arancio/pins_arduino.h index 6f1972a4b5b..7cf807c014b 100644 --- a/variants/namino_arancio/pins_arduino.h +++ b/variants/namino_arancio/pins_arduino.h @@ -6,20 +6,12 @@ #define Pins_Arduino_h #include -#include "soc/soc_caps.h" #define USB_VID 0x303a #define USB_PID 0x1001 #define NAMINO_ARANCIO_BOARD -#define NUM_DIGITAL_PINS SOC_GPIO_PIN_COUNT // GPIO 0..48 -#define NUM_ANALOG_INPUTS 20 // GPIO 1..20 -#define EXTERNAL_NUM_INTERRUPTS NUM_DIGITAL_PINS // All GPIOs -#define analogInputToDigitalPin(p) (((p) -#include "soc/soc_caps.h" #define USB_VID 0x303a #define USB_PID 0x1001 #define NAMINO_ROSSO_BOARD -#define NUM_DIGITAL_PINS SOC_GPIO_PIN_COUNT // GPIO 0..48 -#define NUM_ANALOG_INPUTS 20 // GPIO 1..20 -#define EXTERNAL_NUM_INTERRUPTS NUM_DIGITAL_PINS // All GPIOs -#define analogInputToDigitalPin(p) (((p) -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 38 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 16; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t BUILTIN_KEY = 0; diff --git a/variants/nina_w10/pins_arduino.h b/variants/nina_w10/pins_arduino.h index 00bd44c05b9..660424de2b6 100644 --- a/variants/nina_w10/pins_arduino.h +++ b/variants/nina_w10/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_GREEN = 33; static const uint8_t LED_RED = 23; static const uint8_t LED_BLUE = 21; diff --git a/variants/node32s/pins_arduino.h b/variants/node32s/pins_arduino.h index b37eaed659c..f4d30d32c09 100644 --- a/variants/node32s/pins_arduino.h +++ b/variants/node32s/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 2; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/nodemcu-32s/pins_arduino.h b/variants/nodemcu-32s/pins_arduino.h index b37eaed659c..f4d30d32c09 100644 --- a/variants/nodemcu-32s/pins_arduino.h +++ b/variants/nodemcu-32s/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 2; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/nora_w10/pins_arduino.h b/variants/nora_w10/pins_arduino.h index ccf4556dcfc..ee473f5856f 100644 --- a/variants/nora_w10/pins_arduino.h +++ b/variants/nora_w10/pins_arduino.h @@ -2,19 +2,10 @@ #define Pins_Arduino_h #include -#include "soc/soc_caps.h" #define USB_VID 0x303a #define USB_PID 0x1001 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - // 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 diff --git a/variants/odroid_esp32/pins_arduino.h b/variants/odroid_esp32/pins_arduino.h index 01a863ab236..dc10a37cd8a 100644 --- a/variants/odroid_esp32/pins_arduino.h +++ b/variants/odroid_esp32/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 2; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/onehorse32dev/pins_arduino.h b/variants/onehorse32dev/pins_arduino.h index e57615e3272..03cbbc1676c 100644 --- a/variants/onehorse32dev/pins_arduino.h +++ b/variants/onehorse32dev/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 5; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/openkb/pins_arduino.h b/variants/openkb/pins_arduino.h index 4928bd49539..c429cc3f32a 100644 --- a/variants/openkb/pins_arduino.h +++ b/variants/openkb/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 38 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 16; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/oroca_edubot/pins_arduino.h b/variants/oroca_edubot/pins_arduino.h index 1cfa1fb86fb..e9322abb9c9 100644 --- a/variants/oroca_edubot/pins_arduino.h +++ b/variants/oroca_edubot/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 13; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 17; static const uint8_t RX = 16; diff --git a/variants/pico32/pins_arduino.h b/variants/pico32/pins_arduino.h index 4ad96ccef51..27ecc063483 100644 --- a/variants/pico32/pins_arduino.h +++ b/variants/pico32/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/piranha_esp-32/pins_arduino.h b/variants/piranha_esp-32/pins_arduino.h index 4de761d9aa5..aa170ca1605 100644 --- a/variants/piranha_esp-32/pins_arduino.h +++ b/variants/piranha_esp-32/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 2; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/pocket_32/pins_arduino.h b/variants/pocket_32/pins_arduino.h index af926f45982..325331dbb26 100644 --- a/variants/pocket_32/pins_arduino.h +++ b/variants/pocket_32/pins_arduino.h @@ -3,19 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 16; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN - - +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/quantum/pins_arduino.h b/variants/quantum/pins_arduino.h index 4ad96ccef51..27ecc063483 100644 --- a/variants/quantum/pins_arduino.h +++ b/variants/quantum/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/redpill_esp32s3/pins_arduino.h b/variants/redpill_esp32s3/pins_arduino.h index 0b58bd2415e..4c3672d263f 100644 --- a/variants/redpill_esp32s3/pins_arduino.h +++ b/variants/redpill_esp32s3/pins_arduino.h @@ -2,21 +2,14 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x303A #define USB_PID 0x1001 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - -static const uint8_t LED_BUILTIN = 3; +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 3; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 diff --git a/variants/roboheart_hercules/pins_arduino.h b/variants/roboheart_hercules/pins_arduino.h index 17a5951773e..fc98590040f 100644 --- a/variants/roboheart_hercules/pins_arduino.h +++ b/variants/roboheart_hercules/pins_arduino.h @@ -3,15 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 20 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - - // Motor driver pins #define MOTOR_A_IN1 25 // PHASE/IN1 #define MOTOR_A_IN2 26 // ENABLE/IN2 diff --git a/variants/sonoff_dualr3/pins_arduino.h b/variants/sonoff_dualr3/pins_arduino.h index 1b3fae2d8bb..e7d6c6c1555 100644 --- a/variants/sonoff_dualr3/pins_arduino.h +++ b/variants/sonoff_dualr3/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/sparkfun_esp32_iot_redboard/pins_arduino.h b/variants/sparkfun_esp32_iot_redboard/pins_arduino.h index b644d7baf95..abef21cdbbd 100644 --- a/variants/sparkfun_esp32_iot_redboard/pins_arduino.h +++ b/variants/sparkfun_esp32_iot_redboard/pins_arduino.h @@ -4,20 +4,13 @@ #include #include "soc/soc_caps.h" -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 18; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -static const uint8_t RGB_BUILTIN = SOC_GPIO_PIN_COUNT+2; -#define RGB_BUILTIN RGB_BUILTIN +#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 static const uint8_t TX = 1; diff --git a/variants/sparkfun_lora_gateway_1-channel/pins_arduino.h b/variants/sparkfun_lora_gateway_1-channel/pins_arduino.h index 5d0b845764d..529ee3d003c 100755 --- a/variants/sparkfun_lora_gateway_1-channel/pins_arduino.h +++ b/variants/sparkfun_lora_gateway_1-channel/pins_arduino.h @@ -3,15 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - 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; diff --git a/variants/tamc_termod_s3/pins_arduino.h b/variants/tamc_termod_s3/pins_arduino.h index ca86f85469f..637da583243 100644 --- a/variants/tamc_termod_s3/pins_arduino.h +++ b/variants/tamc_termod_s3/pins_arduino.h @@ -2,27 +2,11 @@ #define Pins_Arduino_h #include -#include "soc/soc_caps.h" #define USB_VID 0x303a #define USB_PID 0x1001 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -// 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 -#define LED_BUILTIN LED_BUILTIN -#define RGB_BUILTIN LED_BUILTIN -#define RGB_BRIGHTNESS 64 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) +// This board has no NeoLED or any User LED static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/tbeam/pins_arduino.h b/variants/tbeam/pins_arduino.h index fdec62d96d3..b27a913e1ff 100644 --- a/variants/tbeam/pins_arduino.h +++ b/variants/tbeam/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 20 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - // SPI LoRa Radio #define LORA_SCK 5 // GPIO5 - SX1276 SCK #define LORA_MISO 19 // GPIO19 - SX1276 MISO @@ -26,7 +18,7 @@ static const uint8_t KEY_BUILTIN = 39; static const uint8_t LED_BUILTIN = 14; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/ttgo-lora32-v1/pins_arduino.h b/variants/ttgo-lora32-v1/pins_arduino.h index 0faf524e233..b637cc51799 100644 --- a/variants/ttgo-lora32-v1/pins_arduino.h +++ b/variants/ttgo-lora32-v1/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - // I2C OLED Display works with SSD1306 driver #define OLED_SDA 4 #define OLED_SCL 15 @@ -26,7 +18,7 @@ static const uint8_t LED_BUILTIN = 2; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/ttgo-lora32-v2/pins_arduino.h b/variants/ttgo-lora32-v2/pins_arduino.h index 5cf49fdd4b7..3d5a0b36f3c 100644 --- a/variants/ttgo-lora32-v2/pins_arduino.h +++ b/variants/ttgo-lora32-v2/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - // I2C OLED Display works with SSD1306 driver #define OLED_SDA 21 #define OLED_SCL 22 @@ -31,8 +23,8 @@ #define SD_CS 13 static const uint8_t LED_BUILTIN = 22; -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/ttgo-lora32-v21new/pins_arduino.h b/variants/ttgo-lora32-v21new/pins_arduino.h index cb4f917b8fc..a333d80917d 100644 --- a/variants/ttgo-lora32-v21new/pins_arduino.h +++ b/variants/ttgo-lora32-v21new/pins_arduino.h @@ -9,14 +9,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - // I2C OLED Display works with SSD1306 driver #define OLED_SDA 21 #define OLED_SCL 22 @@ -38,9 +30,9 @@ #define SD_MOSI 15 #define SD_CS 13 -static const uint8_t LED_BUILTIN = 25 ; -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +static const uint8_t LED_BUILTIN = 25; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/ttgo-t-oi-plus/pins_arduino.h b/variants/ttgo-t-oi-plus/pins_arduino.h index 16cac90bdaf..782b5fb4342 100644 --- a/variants/ttgo-t-oi-plus/pins_arduino.h +++ b/variants/ttgo-t-oi-plus/pins_arduino.h @@ -3,15 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 12 -#define NUM_DIGITAL_PINS 12 -#define NUM_ANALOG_INPUTS 3 - -#define analogInputToDigitalPin(p) (((p) -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - 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 LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t SDA = 21; // Despite the many diagrams from TTGO showing SCL on pin 22, due to the on-board LED diff --git a/variants/ttgo-t7-v13-mini32/pins_arduino.h b/variants/ttgo-t7-v13-mini32/pins_arduino.h index 75057d726d5..eecb5dc5817 100755 --- a/variants/ttgo-t7-v13-mini32/pins_arduino.h +++ b/variants/ttgo-t7-v13-mini32/pins_arduino.h @@ -3,19 +3,12 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - 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 LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t SDA = 21; static const uint8_t SCL = 22; diff --git a/variants/ttgo-t7-v14-mini32/pins_arduino.h b/variants/ttgo-t7-v14-mini32/pins_arduino.h index b0ca79e64e4..496141a7364 100755 --- a/variants/ttgo-t7-v14-mini32/pins_arduino.h +++ b/variants/ttgo-t7-v14-mini32/pins_arduino.h @@ -3,19 +3,12 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - 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 LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t SDA = 21; static const uint8_t SCL = 22; diff --git a/variants/turta_iot_node/pins_arduino.h b/variants/turta_iot_node/pins_arduino.h index f156ee2fb70..64ebeb17172 100644 --- a/variants/turta_iot_node/pins_arduino.h +++ b/variants/turta_iot_node/pins_arduino.h @@ -3,18 +3,10 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 20 -#define NUM_DIGITAL_PINS 21 -#define NUM_ANALOG_INPUTS 9 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - // LED static const uint8_t LED_BUILTIN = 13; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN // UART static const uint8_t TX = 10; diff --git a/variants/twatch/pins_arduino.h b/variants/twatch/pins_arduino.h index b46288c7e76..e10a0d6a8e1 100644 --- a/variants/twatch/pins_arduino.h +++ b/variants/twatch/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 20 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - // touch screen #define TP_SDA 23 #define TP_SCL 32 diff --git a/variants/uPesy_esp32_wroom_devkit/pins_arduino.h b/variants/uPesy_esp32_wroom_devkit/pins_arduino.h index 69e4138428f..467c58c0034 100644 --- a/variants/uPesy_esp32_wroom_devkit/pins_arduino.h +++ b/variants/uPesy_esp32_wroom_devkit/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 2; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/uPesy_esp32_wrover_devkit/pins_arduino.h b/variants/uPesy_esp32_wrover_devkit/pins_arduino.h index 69e4138428f..467c58c0034 100644 --- a/variants/uPesy_esp32_wrover_devkit/pins_arduino.h +++ b/variants/uPesy_esp32_wrover_devkit/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 2; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/um_feathers2/pins_arduino.h b/variants/um_feathers2/pins_arduino.h index 26ff851d66f..edcde26ac71 100644 --- a/variants/um_feathers2/pins_arduino.h +++ b/variants/um_feathers2/pins_arduino.h @@ -9,14 +9,6 @@ #define USB_PRODUCT "FeatherS2" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; diff --git a/variants/um_feathers2neo/pins_arduino.h b/variants/um_feathers2neo/pins_arduino.h index 44609d463ab..d66d565d280 100644 --- a/variants/um_feathers2neo/pins_arduino.h +++ b/variants/um_feathers2neo/pins_arduino.h @@ -2,6 +2,7 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x239A #define USB_PID 0x80B4 @@ -9,14 +10,6 @@ #define USB_PRODUCT "FeatherS2 Neo" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 22 -#define NUM_ANALOG_INPUTS 11 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -62,6 +55,14 @@ static const uint8_t NEOPIXEL_MATRIX_DATA = 21; 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_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 LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN + static const uint8_t NEOPIXEL_PWR = 39; static const uint8_t VBAT_SENSE = 2; diff --git a/variants/um_feathers3/pins_arduino.h b/variants/um_feathers3/pins_arduino.h index 9b60548d08f..804a60d28e4 100644 --- a/variants/um_feathers3/pins_arduino.h +++ b/variants/um_feathers3/pins_arduino.h @@ -2,6 +2,7 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x303A #define USB_PID 0x80D6 @@ -9,14 +10,6 @@ #define USB_PRODUCT "FeatherS3" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 21 -#define NUM_ANALOG_INPUTS 13 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -59,10 +52,17 @@ static const uint8_t T14 = 14; static const uint8_t VBAT_SENSE = 2; static const uint8_t VBUS_SENSE = 34; +// User LED +#define LED_BUILTIN 13 +#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_BRIGHTNESS 64 + static const uint8_t RGB_PWR = 39; static const uint8_t LDO2 = 39; -static const uint8_t LED_BUILTIN = 13; static const uint8_t LED = 13; #endif /* Pins_Arduino_h */ diff --git a/variants/um_nanos3/pins_arduino.h b/variants/um_nanos3/pins_arduino.h index d80a40b8517..84d5b5a6219 100644 --- a/variants/um_nanos3/pins_arduino.h +++ b/variants/um_nanos3/pins_arduino.h @@ -2,6 +2,7 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x303A #define USB_PID 0x8179 @@ -9,14 +10,6 @@ #define USB_PRODUCT "Nanos3" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 17 -#define NUM_ANALOG_INPUTS 9 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -51,6 +44,14 @@ static const uint8_t T8 = 8; 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_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 LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN + static const uint8_t RGB_PWR = 42; #endif /* Pins_Arduino_h */ diff --git a/variants/um_pros3/pins_arduino.h b/variants/um_pros3/pins_arduino.h index d46a772d0cb..9a8e8120151 100644 --- a/variants/um_pros3/pins_arduino.h +++ b/variants/um_pros3/pins_arduino.h @@ -2,6 +2,7 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x303A #define USB_PID 0x80D3 @@ -9,14 +10,6 @@ #define USB_PRODUCT "ProS3" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 27 -#define NUM_ANALOG_INPUTS 14 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -62,6 +55,14 @@ static const uint8_t VBAT_SENSE = 10; 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_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 LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN + static const uint8_t RGB_PWR = 17; static const uint8_t LDO2 = 17; diff --git a/variants/um_rmp/pins_arduino.h b/variants/um_rmp/pins_arduino.h index bf79ad86176..5d3b7acc283 100644 --- a/variants/um_rmp/pins_arduino.h +++ b/variants/um_rmp/pins_arduino.h @@ -2,6 +2,7 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x303A #define USB_PID 0x8001 @@ -9,14 +10,6 @@ #define USB_PRODUCT "RM Pro" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -73,6 +66,14 @@ static const uint8_t VBAT_SENSE = 3; 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_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 LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN + static const uint8_t RGB_PWR = 2; #endif /* Pins_Arduino_h */ diff --git a/variants/um_tinypico/pins_arduino.h b/variants/um_tinypico/pins_arduino.h index 134a5ce88d4..b10b9274178 100644 --- a/variants/um_tinypico/pins_arduino.h +++ b/variants/um_tinypico/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/um_tinys2/pins_arduino.h b/variants/um_tinys2/pins_arduino.h index a493a3fd78b..b3431781d99 100644 --- a/variants/um_tinys2/pins_arduino.h +++ b/variants/um_tinys2/pins_arduino.h @@ -2,6 +2,7 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x303A #define USB_PID 0x8001 @@ -9,14 +10,6 @@ #define USB_PRODUCT "TinyS2" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -73,6 +66,14 @@ static const uint8_t VBAT_SENSE = 3; 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_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 LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN + static const uint8_t RGB_PWR = 2; #endif /* Pins_Arduino_h */ diff --git a/variants/um_tinys3/pins_arduino.h b/variants/um_tinys3/pins_arduino.h index ca2b4ba4873..251b1f8dd7d 100644 --- a/variants/um_tinys3/pins_arduino.h +++ b/variants/um_tinys3/pins_arduino.h @@ -2,6 +2,7 @@ #define Pins_Arduino_h #include +#include "soc/soc_caps.h" #define USB_VID 0x303A #define USB_PID 0x80D0 @@ -9,14 +10,6 @@ #define USB_PRODUCT "TinyS3" #define USB_SERIAL "" -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 17 -#define NUM_ANALOG_INPUTS 9 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - static const uint8_t TX = 43; static const uint8_t RX = 44; @@ -54,6 +47,14 @@ static const uint8_t VBAT_SENSE = 10; 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_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 LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN + static const uint8_t RGB_PWR = 17; #endif /* Pins_Arduino_h */ diff --git a/variants/unphone8/pins_arduino.h b/variants/unphone8/pins_arduino.h index f6270e7224b..66e30bdd564 100644 --- a/variants/unphone8/pins_arduino.h +++ b/variants/unphone8/pins_arduino.h @@ -6,14 +6,6 @@ #define USB_VID 0x16D0 #define USB_PID 0x1178 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - #define LED_BUILTIN 13 #define BUILTIN_LED LED_BUILTIN // backward compatibility diff --git a/variants/unphone9/pins_arduino.h b/variants/unphone9/pins_arduino.h index d16ec924358..e20cd337b7f 100644 --- a/variants/unphone9/pins_arduino.h +++ b/variants/unphone9/pins_arduino.h @@ -6,14 +6,6 @@ #define USB_VID 0x16D0 #define USB_PID 0x1178 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) - #define LED_BUILTIN 13 #define BUILTIN_LED LED_BUILTIN // backward compatibility diff --git a/variants/vintlabsdevkitv1/pins_arduino.h b/variants/vintlabsdevkitv1/pins_arduino.h index 6f0df757180..d0559b9f01b 100644 --- a/variants/vintlabsdevkitv1/pins_arduino.h +++ b/variants/vintlabsdevkitv1/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 2; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/watchy/pins_arduino.h b/variants/watchy/pins_arduino.h index 2c93c173429..b5bc02f374c 100644 --- a/variants/watchy/pins_arduino.h +++ b/variants/watchy/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/variants/wesp32/pins_arduino.h b/variants/wesp32/pins_arduino.h index 7dbfa439e06..670c75fff93 100644 --- a/variants/wesp32/pins_arduino.h +++ b/variants/wesp32/pins_arduino.h @@ -3,14 +3,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - #define TX1 12 #define RX1 13 #define TX2 33 diff --git a/variants/widora-air/pins_arduino.h b/variants/widora-air/pins_arduino.h index 4cb0fa4da0d..0c0472b3ac8 100644 --- a/variants/widora-air/pins_arduino.h +++ b/variants/widora-air/pins_arduino.h @@ -3,18 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 7 -#define NUM_ANALOG_INPUTS 10 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 25; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN - +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/wifiduino32/pins_arduino.h b/variants/wifiduino32/pins_arduino.h index 841721d6d8d..cc3841aba73 100644 --- a/variants/wifiduino32/pins_arduino.h +++ b/variants/wifiduino32/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 2; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t KEY_BUILTIN = 0; diff --git a/variants/wifiduino32s3/pins_arduino.h b/variants/wifiduino32s3/pins_arduino.h index 9115256472b..db372a34358 100644 --- a/variants/wifiduino32s3/pins_arduino.h +++ b/variants/wifiduino32s3/pins_arduino.h @@ -2,27 +2,11 @@ #define Pins_Arduino_h #include -#include "soc/soc_caps.h" #define USB_VID 0x303a #define USB_PID 0x1001 -#define EXTERNAL_NUM_INTERRUPTS 46 -#define NUM_DIGITAL_PINS 48 -#define NUM_ANALOG_INPUTS 20 - -// 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 -#define LED_BUILTIN LED_BUILTIN -#define BOARD_HAS_NEOPIXEL -#define LED_BRIGHTNESS 64 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) -#define digitalPinHasPWM(p) (p < 46) +// No USER LED or NeoLED static const uint8_t TX = 45; static const uint8_t RX = 44; diff --git a/variants/wifiduinov2/pins_arduino.h b/variants/wifiduinov2/pins_arduino.h index 4eb83a7c3ae..f80247e24b9 100644 --- a/variants/wifiduinov2/pins_arduino.h +++ b/variants/wifiduinov2/pins_arduino.h @@ -2,21 +2,10 @@ #define Pins_Arduino_h #include -#include "soc/soc_caps.h" -#define EXTERNAL_NUM_INTERRUPTS 22 -#define NUM_DIGITAL_PINS 22 -#define NUM_ANALOG_INPUTS 6 - -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+13; +static const uint8_t LED_BUILTIN = 13; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN -#define BOARD_HAS_NEOPIXEL -#define LED_BRIGHTNESS 64 - -#define analogInputToDigitalPin(p) (((p) +#include "soc/soc_caps.h" -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 18 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - -static const uint8_t LED_BUILTIN = 0; // ->2812 RGB !!! +// Neopixel +#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 LED_BUILTIN LED_BUILTIN +#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 diff --git a/variants/wt32-eth01/pins_arduino.h b/variants/wt32-eth01/pins_arduino.h index 6cb2a6a5d7a..49cc740efb3 100644 --- a/variants/wt32-eth01/pins_arduino.h +++ b/variants/wt32-eth01/pins_arduino.h @@ -9,14 +9,6 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p) < 20) ? (analogChannelToDigitalPin(p)) : -1) -#define digitalPinToInterrupt(p) (((p) < 40) ? (p) : -1) -#define digitalPinHasPWM(p) (p < 34) - // interface to Ethernet PHY (LAN8720A) #define ETH_PHY_ADDR 1 #define ETH_PHY_POWER 16 diff --git a/variants/xinabox/pins_arduino.h b/variants/xinabox/pins_arduino.h index 52b3e4f12d8..b5978d1ea94 100644 --- a/variants/xinabox/pins_arduino.h +++ b/variants/xinabox/pins_arduino.h @@ -3,17 +3,9 @@ #include -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - static const uint8_t LED_BUILTIN = 27; #define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN static const uint8_t TX = 1; static const uint8_t RX = 3; From 1da0ca88e85ee4b50d81b41f23f5d41ddec90f5a Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Fri, 6 Oct 2023 13:50:53 +0300 Subject: [PATCH 11/18] Add TFLite Micro examples (#8717) * create TFLite library * add TFLite hello_world example * add TFLite micro_speech example --------- Co-authored-by: Sanket Wadekar <67091512+sanketwadekar@users.noreply.github.com> --- .../examples/hello_world/README.md | 18 + .../examples/hello_world/constants.cpp | 19 + .../examples/hello_world/constants.h | 32 + .../examples/hello_world/hello_world.ino | 111 ++ .../examples/hello_world/model.cpp | 237 +++ .../TFLiteMicro/examples/hello_world/model.h | 31 + .../examples/hello_world/output_handler.cpp | 23 + .../examples/hello_world/output_handler.h | 24 + .../examples/micro_speech/README.md | 22 + .../examples/micro_speech/audio_provider.cpp | 198 ++ .../examples/micro_speech/audio_provider.h | 44 + .../micro_speech/command_responder.cpp | 27 + .../examples/micro_speech/command_responder.h | 30 + .../micro_speech/feature_provider.cpp | 118 ++ .../examples/micro_speech/feature_provider.h | 50 + .../micro_speech/micro_features_generator.cpp | 116 ++ .../micro_speech/micro_features_generator.h | 30 + .../micro_speech/micro_model_settings.cpp | 23 + .../micro_speech/micro_model_settings.h | 43 + .../examples/micro_speech/micro_speech.ino | 161 ++ .../examples/micro_speech/model.cpp | 1596 +++++++++++++++++ .../TFLiteMicro/examples/micro_speech/model.h | 27 + .../micro_speech/recognize_commands.cpp | 137 ++ .../micro_speech/recognize_commands.h | 151 ++ .../examples/micro_speech/ringbuf.c | 333 ++++ .../examples/micro_speech/ringbuf.h | 86 + libraries/TFLiteMicro/library.properties | 8 + libraries/TFLiteMicro/src/TFLIteMicro.h | 6 + libraries/TFLiteMicro/src/utility.h | 10 + 29 files changed, 3711 insertions(+) create mode 100644 libraries/TFLiteMicro/examples/hello_world/README.md create mode 100644 libraries/TFLiteMicro/examples/hello_world/constants.cpp create mode 100644 libraries/TFLiteMicro/examples/hello_world/constants.h create mode 100644 libraries/TFLiteMicro/examples/hello_world/hello_world.ino create mode 100644 libraries/TFLiteMicro/examples/hello_world/model.cpp create mode 100644 libraries/TFLiteMicro/examples/hello_world/model.h create mode 100644 libraries/TFLiteMicro/examples/hello_world/output_handler.cpp create mode 100644 libraries/TFLiteMicro/examples/hello_world/output_handler.h create mode 100644 libraries/TFLiteMicro/examples/micro_speech/README.md create mode 100644 libraries/TFLiteMicro/examples/micro_speech/audio_provider.cpp create mode 100644 libraries/TFLiteMicro/examples/micro_speech/audio_provider.h create mode 100644 libraries/TFLiteMicro/examples/micro_speech/command_responder.cpp create mode 100644 libraries/TFLiteMicro/examples/micro_speech/command_responder.h create mode 100644 libraries/TFLiteMicro/examples/micro_speech/feature_provider.cpp create mode 100644 libraries/TFLiteMicro/examples/micro_speech/feature_provider.h create mode 100644 libraries/TFLiteMicro/examples/micro_speech/micro_features_generator.cpp create mode 100644 libraries/TFLiteMicro/examples/micro_speech/micro_features_generator.h create mode 100644 libraries/TFLiteMicro/examples/micro_speech/micro_model_settings.cpp create mode 100644 libraries/TFLiteMicro/examples/micro_speech/micro_model_settings.h create mode 100644 libraries/TFLiteMicro/examples/micro_speech/micro_speech.ino create mode 100644 libraries/TFLiteMicro/examples/micro_speech/model.cpp create mode 100644 libraries/TFLiteMicro/examples/micro_speech/model.h create mode 100644 libraries/TFLiteMicro/examples/micro_speech/recognize_commands.cpp create mode 100644 libraries/TFLiteMicro/examples/micro_speech/recognize_commands.h create mode 100644 libraries/TFLiteMicro/examples/micro_speech/ringbuf.c create mode 100644 libraries/TFLiteMicro/examples/micro_speech/ringbuf.h create mode 100644 libraries/TFLiteMicro/library.properties create mode 100644 libraries/TFLiteMicro/src/TFLIteMicro.h create mode 100644 libraries/TFLiteMicro/src/utility.h diff --git a/libraries/TFLiteMicro/examples/hello_world/README.md b/libraries/TFLiteMicro/examples/hello_world/README.md new file mode 100644 index 00000000000..6fadc59a176 --- /dev/null +++ b/libraries/TFLiteMicro/examples/hello_world/README.md @@ -0,0 +1,18 @@ +# Hello World Example + +This example is designed to demonstrate the absolute basics of using [TensorFlow +Lite for Microcontrollers](https://www.tensorflow.org/lite/microcontrollers). +It includes the full end-to-end workflow of training a model, converting it for +use with TensorFlow Lite for Microcontrollers for running inference on a +microcontroller. + +The model is trained to replicate a `sine` function and generates a pattern of +data to either blink LEDs or control an animation, depending on the capabilities +of the device. + +## Deploy to ESP32 + +The sample has been tested on ESP-IDF version `release/v4.2` and `release/v4.4` with the following devices: +- [ESP32-DevKitC](http://esp-idf.readthedocs.io/en/latest/get-started/get-started-devkitc.html) +- [ESP32-S3-DevKitC](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html) +- [ESP-EYE](https://github.com/espressif/esp-who/blob/master/docs/en/get-started/ESP-EYE_Getting_Started_Guide.md) diff --git a/libraries/TFLiteMicro/examples/hello_world/constants.cpp b/libraries/TFLiteMicro/examples/hello_world/constants.cpp new file mode 100644 index 00000000000..bc32fc3f9c0 --- /dev/null +++ b/libraries/TFLiteMicro/examples/hello_world/constants.cpp @@ -0,0 +1,19 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +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. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "constants.h" + +// This is a small number so that it's easy to read the logs +const int kInferencesPerCycle = 20; diff --git a/libraries/TFLiteMicro/examples/hello_world/constants.h b/libraries/TFLiteMicro/examples/hello_world/constants.h new file mode 100644 index 00000000000..f452893209d --- /dev/null +++ b/libraries/TFLiteMicro/examples/hello_world/constants.h @@ -0,0 +1,32 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +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. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_CONSTANTS_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_CONSTANTS_H_ + +// This constant represents the range of x values our model was trained on, +// which is from 0 to (2 * Pi). We approximate Pi to avoid requiring additional +// libraries. +const float kXrange = 2.f * 3.14159265359f; + +// This constant determines the number of inferences to perform across the range +// of x values defined above. Since each inference takes time, the higher this +// number, the more time it will take to run through the entire range. The value +// of this constant can be tuned so that one full cycle takes a desired amount +// of time. Since different devices take different amounts of time to perform +// inference, this value should be defined per-device. +extern const int kInferencesPerCycle; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_CONSTANTS_H_ diff --git a/libraries/TFLiteMicro/examples/hello_world/hello_world.ino b/libraries/TFLiteMicro/examples/hello_world/hello_world.ino new file mode 100644 index 00000000000..04fdd064a48 --- /dev/null +++ b/libraries/TFLiteMicro/examples/hello_world/hello_world.ino @@ -0,0 +1,111 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +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. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + + +#include "tensorflow/lite/micro/micro_mutable_op_resolver.h" +#include "tensorflow/lite/micro/micro_interpreter.h" +#include "tensorflow/lite/micro/system_setup.h" +#include "tensorflow/lite/schema/schema_generated.h" + +#include "model.h" +#include "constants.h" +#include "output_handler.h" + +// Globals, used for compatibility with Arduino-style sketches. +namespace { +const tflite::Model* model = nullptr; +tflite::MicroInterpreter* interpreter = nullptr; +TfLiteTensor* input = nullptr; +TfLiteTensor* output = nullptr; +int inference_count = 0; + +constexpr int kTensorArenaSize = 2000; +uint8_t tensor_arena[kTensorArenaSize]; +} // namespace + +// The name of this function is important for Arduino compatibility. +void setup() { + // Map the model into a usable data structure. This doesn't involve any + // copying or parsing, it's a very lightweight operation. + 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); + return; + } + + // Pull in only the operation implementations we need. + static tflite::MicroMutableOpResolver<1> resolver; + if (resolver.AddFullyConnected() != kTfLiteOk) { + return; + } + + // Build an interpreter to run the model with. + static tflite::MicroInterpreter static_interpreter( + model, resolver, tensor_arena, kTensorArenaSize); + interpreter = &static_interpreter; + + // Allocate memory from the tensor_arena for the model's tensors. + TfLiteStatus allocate_status = interpreter->AllocateTensors(); + if (allocate_status != kTfLiteOk) { + MicroPrintf("AllocateTensors() failed"); + return; + } + + // Obtain pointers to the model's input and output tensors. + input = interpreter->input(0); + output = interpreter->output(0); + + // Keep track of how many inferences we have performed. + inference_count = 0; +} + +// The name of this function is important for Arduino compatibility. +void loop() { + // Calculate an x value to feed into the model. We compare the current + // 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 x = position * kXrange; + + // Quantize the input from floating-point to integer + int8_t x_quantized = x / input->params.scale + input->params.zero_point; + // Place the quantized input in the model's input tensor + input->data.int8[0] = x_quantized; + + // Run inference, and report any error + TfLiteStatus invoke_status = interpreter->Invoke(); + if (invoke_status != kTfLiteOk) { + MicroPrintf("Invoke failed on x: %f\n", + static_cast(x)); + return; + } + + // Obtain the quantized output from model's output tensor + int8_t y_quantized = output->data.int8[0]; + // Dequantize the output from integer to floating-point + float y = (y_quantized - output->params.zero_point) * output->params.scale; + + // Output the results. A custom HandleOutput function can be implemented + // for each supported hardware target. + HandleOutput(x, y); + + // Increment the inference_counter, and reset it if we have reached + // the total number per cycle + inference_count += 1; + if (inference_count >= kInferencesPerCycle) inference_count = 0; +} diff --git a/libraries/TFLiteMicro/examples/hello_world/model.cpp b/libraries/TFLiteMicro/examples/hello_world/model.cpp new file mode 100644 index 00000000000..f04a9f661c6 --- /dev/null +++ b/libraries/TFLiteMicro/examples/hello_world/model.cpp @@ -0,0 +1,237 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +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. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// Automatically created from a TensorFlow Lite flatbuffer using the command: +// xxd -i model.tflite > model.cc + +// This is a standard TensorFlow Lite model file that has been converted into a +// C data array, so it can be easily compiled into a binary for devices that +// don't have a file system. + +// See train/README.md for a full description of the creation process. + +#include "model.h" + +// 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, 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/hello_world/model.h b/libraries/TFLiteMicro/examples/hello_world/model.h new file mode 100644 index 00000000000..488f47b3afd --- /dev/null +++ b/libraries/TFLiteMicro/examples/hello_world/model.h @@ -0,0 +1,31 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +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. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// Automatically created from a TensorFlow Lite flatbuffer using the command: +// xxd -i model.tflite > model.cc + +// This is a standard TensorFlow Lite model file that has been converted into a +// C data array, so it can be easily compiled into a binary for devices that +// don't have a file system. + +// See train/README.md for a full description of the creation process. + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MODEL_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MODEL_H_ + +extern const unsigned char g_model[]; +extern const int g_model_len; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MODEL_H_ diff --git a/libraries/TFLiteMicro/examples/hello_world/output_handler.cpp b/libraries/TFLiteMicro/examples/hello_world/output_handler.cpp new file mode 100644 index 00000000000..0d5f80ee202 --- /dev/null +++ b/libraries/TFLiteMicro/examples/hello_world/output_handler.cpp @@ -0,0 +1,23 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +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. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "output_handler.h" +#include "tensorflow/lite/micro/micro_log.h" + +void HandleOutput(float x_value, float y_value) { + // Log the current X and Y values + MicroPrintf("x_value: %f, y_value: %f\n", static_cast(x_value), + static_cast(y_value)); +} diff --git a/libraries/TFLiteMicro/examples/hello_world/output_handler.h b/libraries/TFLiteMicro/examples/hello_world/output_handler.h new file mode 100644 index 00000000000..a16846043b3 --- /dev/null +++ b/libraries/TFLiteMicro/examples/hello_world/output_handler.h @@ -0,0 +1,24 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +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. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_OUTPUT_HANDLER_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_OUTPUT_HANDLER_H_ + +#include "tensorflow/lite/c/common.h" + +// Called by the main loop to produce some output based on the x and y values +void HandleOutput(float x_value, float y_value); + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_OUTPUT_HANDLER_H_ diff --git a/libraries/TFLiteMicro/examples/micro_speech/README.md b/libraries/TFLiteMicro/examples/micro_speech/README.md new file mode 100644 index 00000000000..ed293bf2e06 --- /dev/null +++ b/libraries/TFLiteMicro/examples/micro_speech/README.md @@ -0,0 +1,22 @@ +# Micro Speech Example + +This example shows how to run a 20 kB model that can recognize 2 keywords, +"yes" and "no", from speech data. + +The application listens to its surroundings with a microphone and indicates +when it has detected a word by displaying data on a screen. + +## Deploy to ESP32 + +The sample has been tested on ESP-IDF version `release/v4.2` and `release/v4.4` with the following devices: +- [ESP32-DevKitC](http://esp-idf.readthedocs.io/en/latest/get-started/get-started-devkitc.html) +- [ESP32-S3-DevKitC](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html) +- [ESP-EYE](https://github.com/espressif/esp-who/blob/master/docs/en/get-started/ESP-EYE_Getting_Started_Guide.md) + +### Sample output + + * When a keyword is detected you will see following output sample output on the log screen: + +``` +Heard yes () at