diff --git a/.gitignore b/.gitignore index a686ac78564..92b4ae921e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ - tools/xtensa-esp32-elf tools/dist tools/esptool tools/esptool.exe +tools/mkspiffs/mkspiffs +tools/mkspiffs/mkspiffs.exe diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000000..1ca8b1312f5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libraries/BLE"] + path = libraries/BLE + url = https://github.com/nkolban/ESP32_BLE_Arduino.git diff --git a/.travis.yml b/.travis.yml index 344b7ecd659..f1c777e81c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,9 @@ script: - mkdir espressif - cd espressif - ln -s $TRAVIS_BUILD_DIR esp32 - - cd esp32/tools + - cd esp32 + - git submodule update --init --recursive + - cd tools - python get.py - export PATH="$HOME/arduino_ide:$TRAVIS_BUILD_DIR/tools/xtensa-esp32-elf/bin:$PATH" - which arduino diff --git a/Kconfig b/Kconfig index f0077d4050b..67f31c68aa7 100644 --- a/Kconfig +++ b/Kconfig @@ -66,6 +66,16 @@ config ARDUHAL_LOG_COLORS Enable ANSI terminal color codes in bootloader output. In order to view these, your terminal program must support ANSI color codes. +config ARDUHAL_ESP_LOG + bool "Forward ESP_LOGx to Arduino log output" + default "n" + help + This option will redefine the ESP_LOGx macros to Arduino's log_x macros. + To enable for your application, add the follwing after your includes: + #ifdef ARDUINO_ARCH_ESP32 + #include "esp32-hal-log.h" + #endif + endmenu config AUTOCONNECT_WIFI diff --git a/Makefile.projbuild b/Makefile.projbuild index 91f8fef86be..7aa9b39b4f4 100644 --- a/Makefile.projbuild +++ b/Makefile.projbuild @@ -9,7 +9,7 @@ endif BOOT_APP_BIN_FLASH_CMD = $(ESPTOOLPY_SERIAL) write_flash $(BOOT_APP_BIN_OFFSET) $(BOOT_APP_BIN_PATH) ESPTOOL_ALL_FLASH_ARGS += $(BOOT_APP_BIN_OFFSET) $(BOOT_APP_BIN_PATH) -CPPFLAGS += -DARDUINO=180 -DESP32=1 -DARDUINO_ARCH_ESP32=1 +CPPFLAGS += -DARDUINO=10800 -DESP32=1 -DARDUINO_ARCH_ESP32=1 boot-app0: @echo "Rebooting to APP0" diff --git a/README.md b/README.md index 2ed2e00e805..4c0c046e5a8 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Most of the framework is implemented. Most noticable is the missing analogWrite. + [Instructions for Mac](docs/arduino-ide/mac.md) + [Instructions for Debian/Ubuntu Linux](docs/arduino-ide/debian_ubuntu.md) + [Instructions for Fedora](docs/arduino-ide/fedora.md) + + [Instructions for openSUSE](docs/arduino-ide/opensuse.md) - [Using PlatformIO](docs/platformio.md) - [Building with make](docs/make.md) - [Using as ESP-IDF component](docs/esp-idf_component.md) diff --git a/cores/esp32/Esp.cpp b/cores/esp32/Esp.cpp index b11c7f53c31..c60abfbbfe9 100644 --- a/cores/esp32/Esp.cpp +++ b/cores/esp32/Esp.cpp @@ -119,7 +119,9 @@ uint32_t EspClass::getFreeHeap(void) uint8_t EspClass::getChipRevision(void) { - return (REG_READ(EFUSE_BLK0_RDATA3_REG) >> EFUSE_RD_CHIP_VER_RESERVE_S) && EFUSE_RD_CHIP_VER_RESERVE_V; + esp_chip_info_t chip_info; + esp_chip_info(&chip_info); + return chip_info.revision; } const char * EspClass::getSdkVersion(void) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 18d44a29a0b..b1245cb672c 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -9,8 +9,12 @@ HardwareSerial Serial(0); HardwareSerial::HardwareSerial(int uart_nr) : _uart_nr(uart_nr), _uart(NULL) {} -void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin) +void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert) { + if(0 > _uart_nr || _uart_nr > 2) { + log_e("Serial number is invalid, please use 0, 1 or 2"); + return; + } if(_uart) { end(); } @@ -26,7 +30,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in rxPin = 16; txPin = 17; } - _uart = uartBegin(_uart_nr, baud, config, rxPin, txPin, 256, false); + _uart = uartBegin(_uart_nr, baud, config, rxPin, txPin, 256, invert); } void HardwareSerial::end() @@ -89,7 +93,11 @@ size_t HardwareSerial::write(const uint8_t *buffer, size_t size) uartWriteBuf(_uart, buffer, size); return size; } +uint32_t HardwareSerial::baudRate() +{ + return uartGetBaudRate(_uart); +} HardwareSerial::operator bool() const { return true; diff --git a/cores/esp32/HardwareSerial.h b/cores/esp32/HardwareSerial.h index 64a4d484f09..1338f1c31ed 100644 --- a/cores/esp32/HardwareSerial.h +++ b/cores/esp32/HardwareSerial.h @@ -37,7 +37,7 @@ class HardwareSerial: public Stream public: HardwareSerial(int uart_nr); - void begin(unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1); + void begin(unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1, bool invert=false); void end(); int available(void); int peek(void); @@ -66,6 +66,7 @@ class HardwareSerial: public Stream { return write((uint8_t) n); } + uint32_t baudRate(); operator bool() const; void setDebugOutput(bool); diff --git a/cores/esp32/WString.cpp b/cores/esp32/WString.cpp index 3ca49822a3f..124b9753d53 100644 --- a/cores/esp32/WString.cpp +++ b/cores/esp32/WString.cpp @@ -23,6 +23,7 @@ #include "WString.h" #include "stdlib_noniso.h" +#include "esp32-hal-log.h" //extern "C" { //#include "esp_common.h" //} @@ -165,19 +166,23 @@ unsigned char String::reserve(unsigned int size) unsigned char String::changeBuffer(unsigned int maxStrLen) { - size_t newSize = (maxStrLen + 16) & (~0xf); - char *newbuffer = (char *) malloc(newSize); + size_t newSize = ((maxStrLen + 16) & (~0xf)) - 1; + char *newbuffer = (char *) realloc(buffer, newSize+1); if(newbuffer) { - memset(newbuffer, 0, newSize); - memcpy(newbuffer, buffer, len); - if (buffer) { - free(buffer); + if(newSize > len){ + if(newSize > capacity){ + memset(newbuffer+capacity, 0, newSize-capacity); + } + } else { + //new buffer can not fit the old len + newbuffer[newSize] = 0; + len = newSize; } - capacity = newSize - 1; + capacity = newSize; buffer = newbuffer; return 1; } - buffer = newbuffer; + log_e("realloc failed! Buffer unchanged"); return 0; } diff --git a/cores/esp32/esp32-hal-bt.c b/cores/esp32/esp32-hal-bt.c index 0d19e5d5b9f..d701bbbfdb6 100644 --- a/cores/esp32/esp32-hal-bt.c +++ b/cores/esp32/esp32-hal-bt.c @@ -14,7 +14,8 @@ #include "esp32-hal-bt.h" -#if CONFIG_BT_ENABLED +#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BLUEDROID_ENABLED) + #include "bt.h" #include "esp_bt_defs.h" @@ -51,7 +52,7 @@ bool btStop(){ return true; } if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED){ - if (esp_bt_controller_disable(ESP_BT_MODE_BTDM)) { + if (esp_bt_controller_disable()) { log_e("BT Disable failed"); return false; } diff --git a/cores/esp32/esp32-hal-gpio.c b/cores/esp32/esp32-hal-gpio.c index 6b2f9cc8a27..0db7b43c015 100644 --- a/cores/esp32/esp32-hal-gpio.c +++ b/cores/esp32/esp32-hal-gpio.c @@ -24,8 +24,6 @@ #include "soc/gpio_struct.h" #include "soc/rtc_io_reg.h" -#define ETS_GPIO_INUM 12 - const int8_t esp32_adc2gpio[20] = {36, -1, -1, 39, 32, 33, 34, 35, -1, -1, 4, 0, 2, 15, 13, 12, 14, 27, 25, 26}; const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[GPIO_PIN_COUNT]={ @@ -193,6 +191,7 @@ extern int IRAM_ATTR __digitalRead(uint8_t pin) return 0; } +static intr_handle_t gpio_intr_handle = NULL; static void IRAM_ATTR __onPinInterrupt(void *arg) { @@ -229,38 +228,29 @@ static void IRAM_ATTR __onPinInterrupt(void *arg) extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int intr_type) { static bool interrupt_initialized = false; - static int core_id = 0; if(!interrupt_initialized) { interrupt_initialized = true; - core_id = xPortGetCoreID(); - ESP_INTR_DISABLE(ETS_GPIO_INUM); - intr_matrix_set(core_id, ETS_GPIO_INTR_SOURCE, ETS_GPIO_INUM); - xt_set_interrupt_handler(ETS_GPIO_INUM, &__onPinInterrupt, NULL); - ESP_INTR_ENABLE(ETS_GPIO_INUM); + esp_intr_alloc(ETS_GPIO_INTR_SOURCE, (int)ESP_INTR_FLAG_IRAM, __onPinInterrupt, NULL, &gpio_intr_handle); } __pinInterruptHandlers[pin] = userFunc; - //lock gpio - ESP_INTR_DISABLE(ETS_GPIO_INUM); - if(core_id) { //APP_CPU + esp_intr_disable(gpio_intr_handle); + if(esp_intr_get_cpu(gpio_intr_handle)) { //APP_CPU GPIO.pin[pin].int_ena = 1; } else { //PRO_CPU GPIO.pin[pin].int_ena = 4; } GPIO.pin[pin].int_type = intr_type; - ESP_INTR_ENABLE(ETS_GPIO_INUM); - //unlock gpio + esp_intr_enable(gpio_intr_handle); } extern void __detachInterrupt(uint8_t pin) { - //lock gpio - ESP_INTR_DISABLE(ETS_GPIO_INUM); + esp_intr_disable(gpio_intr_handle); __pinInterruptHandlers[pin] = NULL; GPIO.pin[pin].int_ena = 0; GPIO.pin[pin].int_type = 0; - ESP_INTR_ENABLE(ETS_GPIO_INUM); - //unlock gpio + esp_intr_enable(gpio_intr_handle); } diff --git a/cores/esp32/esp32-hal-i2c.c b/cores/esp32/esp32-hal-i2c.c index e5354b91faa..dd3d35baafb 100644 --- a/cores/esp32/esp32-hal-i2c.c +++ b/cores/esp32/esp32-hal-i2c.c @@ -18,6 +18,7 @@ #include "freertos/task.h" #include "freertos/semphr.h" #include "rom/ets_sys.h" +#include "driver/periph_ctrl.h" #include "soc/i2c_reg.h" #include "soc/i2c_struct.h" #include "soc/dport_reg.h" @@ -30,6 +31,8 @@ #define DR_REG_I2C_EXT_BASE_FIXED 0x60013000 #define DR_REG_I2C1_EXT_BASE_FIXED 0x60027000 +#define COMMAND_BUFFER_LENGTH 16 + struct i2c_struct_t { i2c_dev_t * dev; #if !CONFIG_DISABLE_HAL_LOCKS @@ -126,26 +129,25 @@ void i2cSetCmd(i2c_t * i2c, uint8_t index, uint8_t op_code, uint8_t byte_num, bo i2c->dev->command[index].op_code = op_code; } -void i2cResetCmd(i2c_t * i2c){ - int i; +void i2cResetCmd(i2c_t * i2c) { + uint8_t i; for(i=0;i<16;i++){ i2c->dev->command[i].val = 0; } } -void i2cResetFiFo(i2c_t * i2c) -{ +void i2cResetFiFo(i2c_t * i2c) { i2c->dev->fifo_conf.tx_fifo_rst = 1; i2c->dev->fifo_conf.tx_fifo_rst = 0; i2c->dev->fifo_conf.rx_fifo_rst = 1; i2c->dev->fifo_conf.rx_fifo_rst = 0; } -i2c_err_t i2cWrite(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * data, uint8_t len, bool sendStop) +i2c_err_t i2cWrite(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * data, uint16_t len, bool sendStop) { int i; - uint8_t index = 0; - uint8_t dataLen = len + (addr_10bit?2:1); + uint16_t index = 0; + uint16_t dataLen = len + (addr_10bit?2:1); address = (address << 1); if(i2c == NULL){ @@ -154,6 +156,13 @@ i2c_err_t i2cWrite(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * dat I2C_MUTEX_LOCK(); + if (i2c->dev->status_reg.bus_busy == 1) + { + log_e( "Busy Timeout! Addr: %x", address >> 1 ); + I2C_MUTEX_UNLOCK(); + return I2C_ERROR_BUSY; + } + while(dataLen) { uint8_t willSend = (dataLen > 32)?32:dataLen; uint8_t dataSend = willSend; @@ -168,10 +177,13 @@ i2c_err_t i2cWrite(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * dat //CMD WRITE(ADDRESS + DATA) if(!index) { - i2c->dev->fifo_data.data = address & 0xFF; - dataSend--; - if(addr_10bit) { - i2c->dev->fifo_data.data = (address >> 8) & 0xFF; + if(addr_10bit){// address is leftshifted with Read/Write bit set + i2c->dev->fifo_data.data = (((address >> 8) & 0x6) | 0xF0); // send a9:a8 plus 1111 0xxW mask + i2c->dev->fifo_data.data = ((address >> 1) & 0xFF); // send a7:a0, remove W bit (7bit address style) + dataSend -= 2; + } + else { // 7bit address + i2c->dev->fifo_data.data = address & 0xFF; dataSend--; } } @@ -199,29 +211,29 @@ i2c_err_t i2cWrite(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * dat while(1) { //have been looping for too long if((millis() - startAt)>50){ - //log_e("Timeout! Addr: %x", address >> 1); + log_e("Timeout! Addr: %x", address >> 1); I2C_MUTEX_UNLOCK(); return I2C_ERROR_BUS; } //Bus failed (maybe check for this while waiting? if(i2c->dev->int_raw.arbitration_lost) { - //log_e("Bus Fail! Addr: %x", address >> 1); + log_e("Bus Fail! Addr: %x", address >> 1); I2C_MUTEX_UNLOCK(); return I2C_ERROR_BUS; } //Bus timeout if(i2c->dev->int_raw.time_out) { - //log_e("Bus Timeout! Addr: %x", address >> 1); + log_e("Bus Timeout! Addr: %x", address >> 1); I2C_MUTEX_UNLOCK(); return I2C_ERROR_TIMEOUT; } //Transmission did not finish and ACK_ERR is set if(i2c->dev->int_raw.ack_err) { - //log_w("Ack Error! Addr: %x", address >> 1); - while(i2c->dev->status_reg.bus_busy); + log_w("Ack Error! Addr: %x", address >> 1); + while((i2c->dev->status_reg.bus_busy) && ((millis() - startAt)<50)); I2C_MUTEX_UNLOCK(); return I2C_ERROR_ACK; } @@ -236,12 +248,25 @@ i2c_err_t i2cWrite(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * dat return I2C_ERROR_OK; } -i2c_err_t i2cRead(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * data, uint8_t len, bool sendStop) +uint8_t inc( uint8_t* index ) +{ + uint8_t i = index[ 0 ]; + if (++index[ 0 ] == COMMAND_BUFFER_LENGTH) + { + index[ 0 ] = 0; + } + + return i; +} + +i2c_err_t i2cRead(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * data, uint16_t len, bool sendStop) { address = (address << 1) | 1; uint8_t addrLen = (addr_10bit?2:1); - uint8_t index = 0; - uint8_t cmdIdx; + uint8_t amountRead[16]; + uint16_t index = 0; + uint8_t cmdIdx = 0, currentCmdIdx = 0, nextCmdCount; + bool stopped = false, isEndNear = false; uint8_t willRead; if(i2c == NULL){ @@ -250,90 +275,105 @@ i2c_err_t i2cRead(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * data I2C_MUTEX_LOCK(); + if (i2c->dev->status_reg.bus_busy == 1) + { + log_w( "Busy Timeout! Addr: %x", address >> 1 ); + I2C_MUTEX_UNLOCK(); + return I2C_ERROR_BUSY; + } + i2cResetFiFo(i2c); i2cResetCmd(i2c); //CMD START - i2cSetCmd(i2c, 0, I2C_CMD_RSTART, 0, false, false, false); + i2cSetCmd(i2c, cmdIdx++, I2C_CMD_RSTART, 0, false, false, false); //CMD WRITE ADDRESS - i2c->dev->fifo_data.val = address & 0xFF; - if(addr_10bit) { - i2c->dev->fifo_data.val = (address >> 8) & 0xFF; + if (addr_10bit) { // address is left-shifted with Read/Write bit set + i2c->dev->fifo_data.data = (((address >> 8) & 0x6) | 0xF1); // send a9:a8 plus 1111 0xxR mask + i2c->dev->fifo_data.data = ((address >> 1) & 0xFF); // send a7:a0, remove R bit (7bit address style) } - i2cSetCmd(i2c, 1, I2C_CMD_WRITE, addrLen, false, false, true); - - while(len) { - cmdIdx = (index)?0:2; - willRead = (len > 32)?32:(len-1); - if(cmdIdx){ - i2cResetFiFo(i2c); - } - - if(willRead){ - i2cSetCmd(i2c, cmdIdx++, I2C_CMD_READ, willRead, false, false, false); - } - - if((len - willRead) > 1) { - i2cSetCmd(i2c, cmdIdx++, I2C_CMD_END, 0, false, false, false); - } else { - willRead++; - i2cSetCmd(i2c, cmdIdx++, I2C_CMD_READ, 1, true, false, false); - if(sendStop) { - i2cSetCmd(i2c, cmdIdx++, I2C_CMD_STOP, 0, false, false, false); - } - } - - //Clear Interrupts - i2c->dev->int_clr.val = 0xFFFFFFFF; + else { // 7bit address + i2c->dev->fifo_data.data = address & 0xFF; + } + i2cSetCmd(i2c, cmdIdx++, I2C_CMD_WRITE, addrLen, false, false, true); + nextCmdCount = cmdIdx; - //START Transmission - i2c->dev->ctr.trans_start = 1; + //Clear Interrupts + i2c->dev->int_clr.val = 0x00001FFF; + //START Transmission + i2c->dev->ctr.trans_start = 1; + while (!stopped) { //WAIT Transmission uint32_t startAt = millis(); while(1) { //have been looping for too long - if((millis() - startAt)>50){ - //log_e("Timeout! Addr: %x", address >> 1); + if((millis() - startAt)>50) { + log_e("Timeout! Addr: %x, index %d", (address >> 1), index); I2C_MUTEX_UNLOCK(); return I2C_ERROR_BUS; } //Bus failed (maybe check for this while waiting? if(i2c->dev->int_raw.arbitration_lost) { - //log_e("Bus Fail! Addr: %x", address >> 1); + log_e("Bus Fail! Addr: %x", (address >> 1)); I2C_MUTEX_UNLOCK(); return I2C_ERROR_BUS; } //Bus timeout if(i2c->dev->int_raw.time_out) { - //log_e("Bus Timeout! Addr: %x", address >> 1); + log_e("Bus Timeout! Addr: %x, index %d", (address >> 1), index ); I2C_MUTEX_UNLOCK(); return I2C_ERROR_TIMEOUT; } //Transmission did not finish and ACK_ERR is set if(i2c->dev->int_raw.ack_err) { - //log_w("Ack Error! Addr: %x", address >> 1); + log_w("Ack Error! Addr: %x", address >> 1); + while((i2c->dev->status_reg.bus_busy) && ((millis() - startAt)<50)); I2C_MUTEX_UNLOCK(); return I2C_ERROR_ACK; } - if(i2c->dev->command[cmdIdx-1].done) { - break; + // Save bytes from the buffer as they arrive instead of doing them at the end of the loop since there is no + // pause from an END operation in this approach. + if((!isEndNear) && (nextCmdCount < 2)) { + willRead = ((len>32)?32:len); + if (willRead > 0) { + if (willRead > 1) { + i2cSetCmd(i2c, cmdIdx, I2C_CMD_READ, (amountRead[ inc( &cmdIdx ) ] = willRead -1), false, false, false); + nextCmdCount++; + } + i2cSetCmd(i2c, cmdIdx, I2C_CMD_READ, (amountRead[ inc( &cmdIdx ) ] = 1), (len<=32), false, false); + nextCmdCount++; + len -= willRead; + } else { + i2cSetCmd(i2c, inc( &cmdIdx ), I2C_CMD_STOP, 0, false, false, false); + isEndNear = true; + nextCmdCount++; + } } - } - int i = 0; - while(idev->fifo_data.val & 0xFF; + if(i2c->dev->command[currentCmdIdx].done) { + nextCmdCount--; + if (i2c->dev->command[currentCmdIdx].op_code == I2C_CMD_READ) { + while(amountRead[currentCmdIdx]>0) { + data[index++] = i2c->dev->fifo_data.val & 0xFF; + amountRead[currentCmdIdx]--; + } + i2cResetFiFo(i2c); + } else if (i2c->dev->command[currentCmdIdx].op_code == I2C_CMD_STOP) { + stopped = true; + } + inc( ¤tCmdIdx ); + break; + } } - len -= willRead; } I2C_MUTEX_UNLOCK(); + return I2C_ERROR_OK; } @@ -410,7 +450,7 @@ i2c_t * i2cInit(uint8_t i2c_num, uint16_t slave_addr, bool addr_10bit_en) DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG,DPORT_I2C_EXT1_CLK_EN); DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG,DPORT_I2C_EXT1_RST); } - + I2C_MUTEX_LOCK(); i2c->dev->ctr.val = 0; i2c->dev->ctr.ms_mode = (slave_addr == 0); @@ -419,7 +459,7 @@ i2c_t * i2cInit(uint8_t i2c_num, uint16_t slave_addr, bool addr_10bit_en) i2c->dev->ctr.clk_en = 1; //the max clock number of receiving a data - i2c->dev->timeout.tout = 400000;//clocks max=1048575 + i2c->dev->timeout.tout = 1048575;//clocks max=1048575 //disable apb nonfifo access i2c->dev->fifo_conf.nonfifo_en = 0; @@ -445,7 +485,25 @@ void i2cInitFix(i2c_t * i2c){ i2c->dev->fifo_data.data = 0; i2cSetCmd(i2c, 1, I2C_CMD_WRITE, 1, false, false, false); i2cSetCmd(i2c, 2, I2C_CMD_STOP, 0, false, false, false); + if (i2c->dev->status_reg.bus_busy) // If this condition is true, the while loop will timeout as done will not be set + { + log_e("Busy at initialization!"); + } i2c->dev->ctr.trans_start = 1; - while(!i2c->dev->command[2].done); + uint16_t count = 50000; + while ((!i2c->dev->command[2].done) && (--count > 0)); I2C_MUTEX_UNLOCK(); } + +void i2cReset(i2c_t* i2c){ + if(i2c == NULL){ + return; + } + I2C_MUTEX_LOCK(); + periph_module_t moduleId = (i2c == &_i2c_bus_array[0])?PERIPH_I2C0_MODULE:PERIPH_I2C1_MODULE; + periph_module_disable( moduleId ); + delay( 20 ); // Seems long but delay was chosen to ensure system teardown and setup without core generation + periph_module_enable( moduleId ); + I2C_MUTEX_UNLOCK(); +} + diff --git a/cores/esp32/esp32-hal-i2c.h b/cores/esp32/esp32-hal-i2c.h index 22486d76c68..f26c7ab2a60 100644 --- a/cores/esp32/esp32-hal-i2c.h +++ b/cores/esp32/esp32-hal-i2c.h @@ -27,7 +27,8 @@ typedef enum { I2C_ERROR_DEV, I2C_ERROR_ACK, I2C_ERROR_TIMEOUT, - I2C_ERROR_BUS + I2C_ERROR_BUS, + I2C_ERROR_BUSY } i2c_err_t; struct i2c_struct_t; @@ -47,9 +48,10 @@ i2c_err_t i2cDetachSCL(i2c_t * i2c, int8_t scl); i2c_err_t i2cAttachSDA(i2c_t * i2c, int8_t sda); i2c_err_t i2cDetachSDA(i2c_t * i2c, int8_t sda); -i2c_err_t i2cWrite(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * data, uint8_t len, bool sendStop); -i2c_err_t i2cRead(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * data, uint8_t len, bool sendStop); +i2c_err_t i2cWrite(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * data, uint16_t len, bool sendStop); +i2c_err_t i2cRead(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * data, uint16_t len, bool sendStop); +void i2cReset(i2c_t* i2c); #ifdef __cplusplus } diff --git a/cores/esp32/esp32-hal-log.h b/cores/esp32/esp32-hal-log.h index 0456fc0f019..015cd67aa21 100644 --- a/cores/esp32/esp32-hal-log.h +++ b/cores/esp32/esp32-hal-log.h @@ -107,6 +107,22 @@ int log_printf(const char *fmt, ...); #define log_e(format, ...) #endif +#ifdef CONFIG_ARDUHAL_ESP_LOG +#include "esp_log.h" + +#undef ESP_LOGE +#undef ESP_LOGW +#undef ESP_LOGI +#undef ESP_LOGD +#undef ESP_LOGV + +#define ESP_LOGE(tag, ...) log_e(__VA_ARGS__) +#define ESP_LOGW(tag, ...) log_w(__VA_ARGS__) +#define ESP_LOGI(tag, ...) log_i(__VA_ARGS__) +#define ESP_LOGD(tag, ...) log_d(__VA_ARGS__) +#define ESP_LOGV(tag, ...) log_v(__VA_ARGS__) +#endif + #ifdef __cplusplus } #endif diff --git a/cores/esp32/esp32-hal-misc.c b/cores/esp32/esp32-hal-misc.c index ea943b370c6..bf4ee06ebea 100644 --- a/cores/esp32/esp32-hal-misc.c +++ b/cores/esp32/esp32-hal-misc.c @@ -23,6 +23,15 @@ #include "esp_log.h" #include +//Undocumented!!! Get chip temperature in Farenheit +//Source: https://github.com/pcbreflux/espressif/blob/master/esp32/arduino/sketchbook/ESP32_int_temp_sensor/ESP32_int_temp_sensor.ino +uint8_t temprature_sens_read(); + +float temperatureRead() +{ + return (temprature_sens_read() - 32) / 1.8; +} + void yield() { vPortYield(); diff --git a/cores/esp32/esp32-hal-spi.c b/cores/esp32/esp32-hal-spi.c index 878d4731f31..c017f6a4832 100644 --- a/cores/esp32/esp32-hal-spi.c +++ b/cores/esp32/esp32-hal-spi.c @@ -407,14 +407,14 @@ spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_ #endif if(spi_num == HSPI) { - DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI_CLK_EN_1); - DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI_RST_1); + DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI_CLK_EN); + DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI_RST); } else if(spi_num == VSPI) { DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI_CLK_EN_2); DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI_RST_2); } else { - DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI_CLK_EN); - DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI_RST); + DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI_CLK_EN_1); + DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI_RST_1); } spiStopBus(spi); @@ -680,6 +680,16 @@ void spiTransferBytes(spi_t * spi, uint8_t * data, uint8_t * out, uint32_t size) SPI_MUTEX_UNLOCK(); } +void spiTransferBits(spi_t * spi, uint32_t data, uint32_t * out, uint8_t bits) +{ + if(!spi) { + return; + } + SPI_MUTEX_LOCK(); + spiTransferBitsNL(spi, data, out, bits); + SPI_MUTEX_UNLOCK(); +} + /* * Manual Lock Management * */ diff --git a/cores/esp32/esp32-hal-time.c b/cores/esp32/esp32-hal-time.c index 83f102177cd..176ac65cc2f 100644 --- a/cores/esp32/esp32-hal-time.c +++ b/cores/esp32/esp32-hal-time.c @@ -18,20 +18,20 @@ static void setTimeZone(long offset, int daylight) { char cst[16] = {0}; - char cdt[16] = "CDT"; + char cdt[16] = "DST"; char tz[32] = {0}; if(offset % 3600){ - sprintf(cst, "CST%ld:%02u:%02u", offset / 3600, abs((offset % 3600) / 60), abs(offset % 60)); + sprintf(cst, "UTC%ld:%02u:%02u", offset / 3600, abs((offset % 3600) / 60), abs(offset % 60)); } else { - sprintf(cst, "CST%ld", offset / 3600); + sprintf(cst, "UTC%ld", offset / 3600); } if(daylight != 3600){ long tz_dst = offset - daylight; if(tz_dst % 3600){ - sprintf(cdt, "CDT%ld:%02u:%02u", tz_dst / 3600, abs((tz_dst % 3600) / 60), abs(tz_dst % 60)); + sprintf(cdt, "DST%ld:%02u:%02u", tz_dst / 3600, abs((tz_dst % 3600) / 60), abs(tz_dst % 60)); } else { - sprintf(cdt, "CDT%ld", tz_dst / 3600); + sprintf(cdt, "DST%ld", tz_dst / 3600); } } sprintf(tz, "%s%s", cst, cdt); @@ -53,7 +53,7 @@ void configTime(long gmtOffset_sec, int daylightOffset_sec, const char* server1, sntp_setservername(1, (char*)server2); sntp_setservername(2, (char*)server3); sntp_init(); - setTimeZone(gmtOffset_sec, daylightOffset_sec); + setTimeZone(-gmtOffset_sec, daylightOffset_sec); } /* diff --git a/cores/esp32/esp32-hal-timer.c b/cores/esp32/esp32-hal-timer.c index 12ca21c5794..17743a4f6d8 100644 --- a/cores/esp32/esp32-hal-timer.c +++ b/cores/esp32/esp32-hal-timer.c @@ -22,7 +22,6 @@ #include "esp_attr.h" #include "esp_intr.h" -#define HWTIMER_INUM 10 #define HWTIMER_LOCK() portENTER_CRITICAL(timer->lock) #define HWTIMER_UNLOCK() portEXIT_CRITICAL(timer->lock) @@ -66,7 +65,7 @@ static hw_timer_t hw_timer[4] = { }; typedef void (*voidFuncPtr)(void); -static voidFuncPtr __timerInterruptHandlers[4] = {0,}; +static voidFuncPtr __timerInterruptHandlers[4] = {0,0,0,0}; void IRAM_ATTR __timerISR(void * arg){ uint32_t s0 = TIMERG0.int_st_timers.val; @@ -85,10 +84,8 @@ void IRAM_ATTR __timerISR(void * arg){ i = 4; //call callbacks while(i--){ - if(status & (1 << i)){ - if(__timerInterruptHandlers[i]){ - __timerInterruptHandlers[i](); - } + if(__timerInterruptHandlers[i] && status & (1 << i)){ + __timerInterruptHandlers[i](); } } } @@ -187,8 +184,6 @@ bool timerAlarmEnabled(hw_timer_t *timer){ return timer->dev->config.alarm_en; } - - hw_timer_t * timerBegin(uint8_t num, uint16_t divider, bool countUp){ if(num > 3){ return NULL; @@ -220,7 +215,10 @@ void timerEnd(hw_timer_t *timer){ void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){ static bool initialized = false; - ESP_INTR_DISABLE(HWTIMER_INUM); + static intr_handle_t intr_handle = NULL; + if(intr_handle){ + esp_intr_disable(intr_handle); + } if(fn == NULL){ timer->dev->config.level_int_en = 0; timer->dev->config.edge_int_en = 0; @@ -232,10 +230,6 @@ void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){ } __timerInterruptHandlers[timer->num] = NULL; } else { - if(!initialized){ - xt_set_interrupt_handler(HWTIMER_INUM, &__timerISR, NULL); - initialized = true; - } __timerInterruptHandlers[timer->num] = fn; timer->dev->config.level_int_en = edge?0:1;//When set, an alarm will generate a level type interrupt. timer->dev->config.edge_int_en = edge?1:0;//When set, an alarm will generate an edge type interrupt. @@ -253,14 +247,21 @@ void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){ intr_source = ETS_TG0_T0_EDGE_INTR_SOURCE + timer->timer; } } - intr_matrix_set(xPortGetCoreID(), intr_source, HWTIMER_INUM); + if(!initialized){ + initialized = true; + esp_intr_alloc(intr_source, (int)(ESP_INTR_FLAG_IRAM|ESP_INTR_FLAG_LOWMED|ESP_INTR_FLAG_EDGE), __timerISR, NULL, &intr_handle); + } else { + intr_matrix_set(esp_intr_get_cpu(intr_handle), intr_source, esp_intr_get_intno(intr_handle)); + } if(timer->group){ TIMERG1.int_ena.val |= BIT(timer->timer); } else { TIMERG0.int_ena.val |= BIT(timer->timer); } } - ESP_INTR_ENABLE(HWTIMER_INUM); + if(intr_handle){ + esp_intr_enable(intr_handle); + } } void timerDetachInterrupt(hw_timer_t *timer){ diff --git a/cores/esp32/esp32-hal-touch.c b/cores/esp32/esp32-hal-touch.c index 8f530150d55..94e8a8b8ac3 100644 --- a/cores/esp32/esp32-hal-touch.c +++ b/cores/esp32/esp32-hal-touch.c @@ -22,13 +22,12 @@ #include "soc/rtc_cntl_reg.h" #include "soc/sens_reg.h" -#define RTC_TOUCH_INUM 13 - static uint16_t __touchSleepCycles = 0x1000; static uint16_t __touchMeasureCycles = 0x1000; typedef void (*voidFuncPtr)(void); static voidFuncPtr __touchInterruptHandlers[10] = {0,}; +static intr_handle_t touch_intr_handle = NULL; void IRAM_ATTR __touchISR(void * arg) { @@ -66,6 +65,7 @@ void __touchInit() if(initialized){ return; } + initialized = true; SET_PERI_REG_BITS(RTC_IO_TOUCH_CFG_REG, RTC_IO_TOUCH_XPD_BIAS, 1, RTC_IO_TOUCH_XPD_BIAS_S); SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_MEAS_EN_CLR); //clear touch enable @@ -74,11 +74,7 @@ void __touchInit() __touchSetCycles(__touchMeasureCycles, __touchSleepCycles); - ESP_INTR_DISABLE(RTC_TOUCH_INUM); - intr_matrix_set(xPortGetCoreID(), ETS_RTC_CORE_INTR_SOURCE, RTC_TOUCH_INUM); - xt_set_interrupt_handler(RTC_TOUCH_INUM, &__touchISR, NULL); - ESP_INTR_ENABLE(RTC_TOUCH_INUM); - initialized = true; + esp_intr_alloc(ETS_RTC_CORE_INTR_SOURCE, (int)ESP_INTR_FLAG_IRAM, __touchISR, NULL, &touch_intr_handle); } uint16_t __touchRead(uint8_t pin) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 222bbcb27da..6612668901b 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -27,9 +27,7 @@ #include "soc/io_mux_reg.h" #include "soc/gpio_sig_map.h" #include "soc/dport_reg.h" - -#define ETS_UART_INUM 5 -#define ETS_UART2_INUM ETS_UART_INUM +#include "esp_intr_alloc.h" #define UART_REG_BASE(u) ((u==0)?DR_REG_UART_BASE:( (u==1)?DR_REG_UART1_BASE:( (u==2)?DR_REG_UART2_BASE:0))) #define UART_RXD_IDX(u) ((u==0)?U0RXD_IN_IDX:( (u==1)?U1RXD_IN_IDX:( (u==2)?U2RXD_IN_IDX:0))) @@ -45,6 +43,7 @@ struct uart_struct_t { #endif uint8_t num; xQueueHandle queue; + intr_handle_t intr_handle; }; #if CONFIG_DISABLE_HAL_LOCKS @@ -52,18 +51,18 @@ struct uart_struct_t { #define UART_MUTEX_UNLOCK() static uart_t _uart_bus_array[3] = { - {(volatile uart_dev_t *)(DR_REG_UART_BASE), 0, NULL}, - {(volatile uart_dev_t *)(DR_REG_UART1_BASE), 1, NULL}, - {(volatile uart_dev_t *)(DR_REG_UART2_BASE), 2, NULL} + {(volatile uart_dev_t *)(DR_REG_UART_BASE), 0, NULL, NULL}, + {(volatile uart_dev_t *)(DR_REG_UART1_BASE), 1, NULL, NULL}, + {(volatile uart_dev_t *)(DR_REG_UART2_BASE), 2, NULL, NULL} }; #else #define UART_MUTEX_LOCK() do {} while (xSemaphoreTake(uart->lock, portMAX_DELAY) != pdPASS) #define UART_MUTEX_UNLOCK() xSemaphoreGive(uart->lock) static uart_t _uart_bus_array[3] = { - {(volatile uart_dev_t *)(DR_REG_UART_BASE), NULL, 0, NULL}, - {(volatile uart_dev_t *)(DR_REG_UART1_BASE), NULL, 1, NULL}, - {(volatile uart_dev_t *)(DR_REG_UART2_BASE), NULL, 2, NULL} + {(volatile uart_dev_t *)(DR_REG_UART_BASE), NULL, 0, NULL, NULL}, + {(volatile uart_dev_t *)(DR_REG_UART1_BASE), NULL, 1, NULL, NULL}, + {(volatile uart_dev_t *)(DR_REG_UART2_BASE), NULL, 2, NULL, NULL} }; #endif @@ -75,6 +74,9 @@ static void IRAM_ATTR _uart_isr(void *arg) for(i=0;i<3;i++){ uart = &_uart_bus_array[i]; + if(uart->intr_handle == NULL){ + continue; + } uart->dev->int_clr.rxfifo_full = 1; uart->dev->int_clr.frm_err = 1; uart->dev->int_clr.rxfifo_tout = 1; @@ -91,18 +93,6 @@ static void IRAM_ATTR _uart_isr(void *arg) } } -void uartEnableGlobalInterrupt() -{ - xt_set_interrupt_handler(ETS_UART_INUM, _uart_isr, NULL); - ESP_INTR_ENABLE(ETS_UART_INUM); -} - -void uartDisableGlobalInterrupt() -{ - ESP_INTR_DISABLE(ETS_UART_INUM); - xt_set_interrupt_handler(ETS_UART_INUM, NULL, NULL); -} - void uartEnableInterrupt(uart_t* uart) { UART_MUTEX_LOCK(); @@ -114,7 +104,7 @@ void uartEnableInterrupt(uart_t* uart) uart->dev->int_ena.rxfifo_tout = 1; uart->dev->int_clr.val = 0xffffffff; - intr_matrix_set(xPortGetCoreID(), UART_INTR_SOURCE(uart->num), ETS_UART_INUM); + esp_intr_alloc(UART_INTR_SOURCE(uart->num), (int)ESP_INTR_FLAG_IRAM, _uart_isr, NULL, &uart->intr_handle); UART_MUTEX_UNLOCK(); } @@ -124,6 +114,10 @@ void uartDisableInterrupt(uart_t* uart) uart->dev->conf1.val = 0; uart->dev->int_ena.val = 0; uart->dev->int_clr.val = 0xffffffff; + + esp_intr_free(uart->intr_handle); + uart->intr_handle = NULL; + UART_MUTEX_UNLOCK(); } @@ -152,7 +146,6 @@ void uartAttachRx(uart_t* uart, uint8_t rxPin, bool inverted) pinMode(rxPin, INPUT); pinMatrixInAttach(rxPin, UART_RXD_IDX(uart->num), inverted); uartEnableInterrupt(uart); - uartEnableGlobalInterrupt(); } void uartAttachTx(uart_t* uart, uint8_t txPin, bool inverted) @@ -197,6 +190,9 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx } else if(uart_nr == 2){ DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_UART2_CLK_EN); DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_UART2_RST); + } else { + DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_UART_CLK_EN); + DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_UART_RST); } uartFlush(uart); uartSetBaudRate(uart, baudrate); diff --git a/cores/esp32/esp32-hal.h b/cores/esp32/esp32-hal.h index f6a51427662..d6e5ca8ca65 100644 --- a/cores/esp32/esp32-hal.h +++ b/cores/esp32/esp32-hal.h @@ -61,6 +61,9 @@ void yield(void); #include "esp32-hal-bt.h" #include "esp_system.h" +//returns chip temperature in Celsius +float temperatureRead(); + unsigned long micros(); unsigned long millis(); void delay(uint32_t); diff --git a/cores/esp32/pgmspace.h b/cores/esp32/pgmspace.h index 51faac162a0..e97e2fce634 100644 --- a/cores/esp32/pgmspace.h +++ b/cores/esp32/pgmspace.h @@ -29,8 +29,6 @@ typedef unsigned short prog_uint16_t; typedef long prog_int32_t; typedef unsigned long prog_uint32_t; -#define SIZE_IRRELEVANT 0x7fffffff - #define PROGMEM #define PGM_P const char * #define PGM_VOID_P const void * @@ -56,10 +54,15 @@ typedef unsigned long prog_uint32_t; #define memccpy_P memccpy #define memmem_P memmem #define memcpy_P memcpy +#define strcpy_P strcpy #define strncpy_P strncpy +#define strcat_p strcat #define strncat_P strncat +#define strcmp_P strcmp #define strncmp_P strncmp +#define strcasecmp_P strcasecmp #define strncasecmp_P strncasecmp +#define strlen_P strlen #define strnlen_P strnlen #define strstr_P strstr #define printf_P printf @@ -67,10 +70,4 @@ typedef unsigned long prog_uint32_t; #define snprintf_P snprintf #define vsnprintf_P vsnprintf -#define strlen_P(strP) strnlen_P((strP), SIZE_IRRELEVANT) -#define strcasecmp_P(str1, str2P) strncasecmp_P((str1), (str2P), SIZE_IRRELEVANT) -#define strcmp_P(str1, str2P) strncmp_P((str1), (str2P), SIZE_IRRELEVANT) -#define strcat_P(dest, src) strncat_P((dest), (src), SIZE_IRRELEVANT) -#define strcpy_P(dest, src) strncpy_P((dest), (src), SIZE_IRRELEVANT) - #endif diff --git a/docs/arduino-ide/debian_ubuntu.md b/docs/arduino-ide/debian_ubuntu.md index 0f95cf2ac31..1c28fcf8a72 100644 --- a/docs/arduino-ide/debian_ubuntu.md +++ b/docs/arduino-ide/debian_ubuntu.md @@ -13,7 +13,23 @@ Installation instructions for Debian / Ubuntu OS mkdir -p ~/Arduino/hardware/espressif && \ cd ~/Arduino/hardware/espressif && \ git clone https://github.com/espressif/arduino-esp32.git esp32 && \ - cd esp32/tools/ && \ + cd esp32 && \ + git submodule update --init --recursive && \ + cd tools && \ python get.py ``` - Restart Arduino IDE + + + +- If you have Arduino.app installed to /Applications/, modify the installation as follows, beginning at `mkdir -p ~/Arduino...`: + +```bash + cd /Applications/Arduino_*/Contents/java/hardware/ + mkdir -p espressif && \ + cd espressif && \ + git clone https://github.com/espressif/arduino-esp32.git esp32 && \ + cd esp32 && \ + git submodule update --init --recursive && \ + cd tools && \ + python get.py``` diff --git a/docs/arduino-ide/fedora.md b/docs/arduino-ide/fedora.md index 6672183989f..c28a2cace5b 100644 --- a/docs/arduino-ide/fedora.md +++ b/docs/arduino-ide/fedora.md @@ -10,7 +10,9 @@ Installation instructions for Fedora mkdir -p ~/Arduino/hardware/espressif && \ cd ~/Arduino/hardware/espressif && \ git clone https://github.com/espressif/arduino-esp32.git esp32 && \ - cd esp32/tools/ && \ + cd esp32 && \ + git submodule update --init --recursive && \ + cd tools && \ python get.py ``` - Restart Arduino IDE diff --git a/docs/arduino-ide/mac.md b/docs/arduino-ide/mac.md index 717d5ef3935..d3d022bdec4 100644 --- a/docs/arduino-ide/mac.md +++ b/docs/arduino-ide/mac.md @@ -8,7 +8,9 @@ Installation instructions for Mac OS mkdir -p ~/Documents/Arduino/hardware/espressif && \ cd ~/Documents/Arduino/hardware/espressif && \ git clone https://github.com/espressif/arduino-esp32.git esp32 && \ - cd esp32/tools/ && \ + cd esp32 && \ + git submodule update --init --recursive && \ + cd tools && \ python get.py ``` - If you get the error below. Install the command line dev tools with xcode-select --install and try the command above again: diff --git a/docs/arduino-ide/opensuse.md b/docs/arduino-ide/opensuse.md new file mode 100644 index 00000000000..4f28b9dd346 --- /dev/null +++ b/docs/arduino-ide/opensuse.md @@ -0,0 +1,22 @@ +Installation instructions for openSUSE +====================================== + +- Install the latest Arduino IDE from [arduino.cc](https://www.arduino.cc/en/Main/Software). +- Open Terminal and execute the following command (copy->paste and hit enter): + + ```bash + sudo usermod -a -G dialout $USER && \ + if [ `python --version 2>&1 | grep '2.7' | wc -l` = "1" ]; then \ + sudo zypper install git python-pip python-pyserial; \ + else \ + sudo zypper install git python3-pip python3-pyserial; \ + fi && \ + mkdir -p ~/Arduino/hardware/espressif && \ + cd ~/Arduino/hardware/espressif && \ + git clone https://github.com/espressif/arduino-esp32.git esp32 && \ + cd esp32 && \ + git submodule update --init --recursive && \ + cd tools && \ + python get.py + ``` +- Restart Arduino IDE diff --git a/docs/esp-idf_component.md b/docs/esp-idf_component.md index abf6f0c4ea0..be685125707 100644 --- a/docs/esp-idf_component.md +++ b/docs/esp-idf_component.md @@ -1,6 +1,8 @@ To use as a component of ESP-IDF ================================================= +## Installation + - Download and install [esp-idf](https://github.com/espressif/esp-idf) - Create blank idf project (from one of the examples) - in the project folder, create a folder called components and clone this repository inside @@ -9,7 +11,9 @@ To use as a component of ESP-IDF mkdir -p components && \ cd components && \ git clone https://github.com/espressif/arduino-esp32.git arduino && \ - cd .. && \ + cd arduino && \ + git submodule update --init --recursive && \ + cd ../.. && \ make menuconfig ``` - ```make menuconfig``` has some Arduino options @@ -53,3 +57,14 @@ To use as a component of ESP-IDF - If enabled, WiFi will start with the last known configuration - Else it will wait for WiFi.begin - ```make flash monitor``` will build, upload and open serial monitor to your board + +## Logging To Serial + +If you are writing code that does not require Arduino to compile and you want your `ESP_LOGx` macros to work in Arduino IDE, you can enable the compatibility by adding the following lines after your includes: + +```cpp +#ifdef ARDUINO_ARCH_ESP32 +#include "esp32-hal-log.h" +#endif +``` + diff --git a/libraries/ArduinoOTA/src/ArduinoOTA.h b/libraries/ArduinoOTA/src/ArduinoOTA.h index db477237914..16560ee611a 100644 --- a/libraries/ArduinoOTA/src/ArduinoOTA.h +++ b/libraries/ArduinoOTA/src/ArduinoOTA.h @@ -29,10 +29,10 @@ class ArduinoOTAClass ArduinoOTAClass(); ~ArduinoOTAClass(); - //Sets the service port. Default 8266 + //Sets the service port. Default 3232 void setPort(uint16_t port); - //Sets the device hostname. Default esp8266-xxxxxx + //Sets the device hostname. Default esp32-xxxxxx void setHostname(const char *hostname); String getHostname(); diff --git a/libraries/BLE b/libraries/BLE new file mode 160000 index 00000000000..cb1ab4ea76a --- /dev/null +++ b/libraries/BLE @@ -0,0 +1 @@ +Subproject commit cb1ab4ea76af17d347cdadcc003d1fe53af12aa7 diff --git a/libraries/ESP32/examples/AnalogOut/ledcWrite_RGB/ledcWrite_RGB.ino b/libraries/ESP32/examples/AnalogOut/ledcWrite_RGB/ledcWrite_RGB.ino new file mode 100644 index 00000000000..633d1c0896d --- /dev/null +++ b/libraries/ESP32/examples/AnalogOut/ledcWrite_RGB/ledcWrite_RGB.ino @@ -0,0 +1,130 @@ +/* + ledcWrite_RGB.ino + Runs through the full 255 color spectrum for an rgb led + Demonstrate ledcWrite functionality for driving leds with PWM on ESP32 + + This example code is in the public domain. + + Some basic modifications were made by vseven, mostly commenting. + */ + +// Set up the rgb led names +uint8_t ledR = A4; +uint8_t ledG = A5; +uint8_t ledB = A18; + +uint8_t ledArray[3] = {1, 2, 3}; // three led channels + +const boolean invert = true; // set true if common anode, false if common cathode + +uint8_t color = 0; // a value from 0 to 255 representing the hue +uint32_t R, G, B; // the Red Green and Blue color components +uint8_t brightness = 255; // 255 is maximum brightness, but can be changed. Might need 256 for common anode to fully turn off. + +// the setup routine runs once when you press reset: +void setup() +{ + Serial.begin(115200); + delay(10); + + ledcAttachPin(ledR, 1); // assign RGB led pins to channels + ledcAttachPin(ledG, 2); + ledcAttachPin(ledB, 3); + + // Initialize channels + // channels 0-15, resolution 1-16 bits, freq limits depend on resolution + // ledcSetup(uint8_t channel, uint32_t freq, uint8_t resolution_bits); + ledcSetup(1, 12000, 8); // 12 kHz PWM, 8-bit resolution + ledcSetup(2, 12000, 8); + ledcSetup(3, 12000, 8); +} + +// void loop runs over and over again +void loop() +{ + Serial.println("Send all LEDs a 255 and wait 2 seconds."); + // If your RGB LED turns off instead of on here you should check if the LED is common anode or cathode. + // If it doesn't fully turn off and is common anode try using 256. + ledcWrite(1, 255); + ledcWrite(2, 255); + ledcWrite(3, 255); + delay(2000); + Serial.println("Send all LEDs a 0 and wait 2 seconds."); + ledcWrite(1, 0); + ledcWrite(2, 0); + ledcWrite(3, 0); + delay(2000); + + Serial.println("Starting color fade loop."); + + for (color = 0; color < 255; color++) { // Slew through the color spectrum + + hueToRGB(color, brightness); // call function to convert hue to RGB + + // write the RGB values to the pins + ledcWrite(1, R); // write red component to channel 1, etc. + ledcWrite(2, G); + ledcWrite(3, B); + + delay(100); // full cycle of rgb over 256 colors takes 26 seconds + } + +} + +// Courtesy http://www.instructables.com/id/How-to-Use-an-RGB-LED/?ALLSTEPS +// function to convert a color to its Red, Green, and Blue components. + +void hueToRGB(uint8_t hue, uint8_t brightness) +{ + uint16_t scaledHue = (hue * 6); + uint8_t segment = scaledHue / 256; // segment 0 to 5 around the + // color wheel + uint16_t segmentOffset = + scaledHue - (segment * 256); // position within the segment + + uint8_t complement = 0; + uint16_t prev = (brightness * ( 255 - segmentOffset)) / 256; + uint16_t next = (brightness * segmentOffset) / 256; + + if(invert) + { + brightness = 255 - brightness; + complement = 255; + prev = 255 - prev; + next = 255 - next; + } + + switch(segment ) { + case 0: // red + R = brightness; + G = next; + B = complement; + break; + case 1: // yellow + R = prev; + G = brightness; + B = complement; + break; + case 2: // green + R = complement; + G = brightness; + B = next; + break; + case 3: // cyan + R = complement; + G = prev; + B = brightness; + break; + case 4: // blue + R = next; + G = complement; + B = brightness; + break; + case 5: // magenta + default: + R = brightness; + G = complement; + B = prev; + break; + } +} diff --git a/libraries/ESP32/examples/ESPNow/Basic/Master/Master.ino b/libraries/ESP32/examples/ESPNow/Basic/Master/Master.ino new file mode 100644 index 00000000000..26e020f68f0 --- /dev/null +++ b/libraries/ESP32/examples/ESPNow/Basic/Master/Master.ino @@ -0,0 +1,262 @@ +/** + ESPNOW - Basic communication - Master + Date: 26th September 2017 + Author: Arvind Ravulavaru + Purpose: ESPNow Communication between a Master ESP32 and a Slave ESP32 + Description: This sketch consists of the code for the Master module. + Resources: (A bit outdated) + a. https://espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf + b. http://www.esploradores.com/practica-6-conexion-esp-now/ + + << This Device Master >> + + Flow: Master + Step 1 : ESPNow Init on Master and set it in STA mode + Step 2 : Start scanning for Slave ESP32 (we have added a prefix of `slave` to the SSID of slave for an easy setup) + Step 3 : Once found, add Slave as peer + Step 4 : Register for send callback + Step 5 : Start Transmitting data from Master to Slave + + Flow: Slave + Step 1 : ESPNow Init on Slave + Step 2 : Update the SSID of Slave with a prefix of `slave` + Step 3 : Set Slave in AP mode + Step 4 : Register for receive callback and wait for data + Step 5 : Once data arrives, print it in the serial monitor + + Note: Master and Slave have been defined to easily understand the setup. + Based on the ESPNOW API, there is no concept of Master and Slave. + Any devices can act as master or salve. +*/ + +#include +#include + +// Global copy of slave +esp_now_peer_info_t slave; +#define CHANNEL 3 +#define PRINTSCANRESULTS 0 +#define DELETEBEFOREPAIR 0 + +// Init ESP Now with fallback +void InitESPNow() { + if (esp_now_init() == ESP_OK) { + Serial.println("ESPNow Init Success"); + } + else { + Serial.println("ESPNow Init Failed"); + // Retry InitESPNow, add a counte and then restart? + // InitESPNow(); + // or Simply Restart + ESP.restart(); + } +} + +// Scan for slaves in AP mode +void ScanForSlave() { + int8_t scanResults = WiFi.scanNetworks(); + // reset on each scan + bool slaveFound = 0; + memset(&slave, 0, sizeof(slave)); + + Serial.println(""); + if (scanResults == 0) { + Serial.println("No WiFi devices in AP Mode found"); + } else { + Serial.print("Found "); Serial.print(scanResults); Serial.println(" devices "); + for (int i = 0; i < scanResults; ++i) { + // Print SSID and RSSI for each device found + String SSID = WiFi.SSID(i); + int32_t RSSI = WiFi.RSSI(i); + String BSSIDstr = WiFi.BSSIDstr(i); + + if (PRINTSCANRESULTS) { + Serial.print(i + 1); + Serial.print(": "); + Serial.print(SSID); + Serial.print(" ("); + Serial.print(RSSI); + Serial.print(")"); + Serial.println(""); + } + delay(10); + // Check if the current device starts with `Slave` + if (SSID.indexOf("Slave") == 0) { + // SSID of interest + Serial.println("Found a Slave."); + Serial.print(i + 1); Serial.print(": "); Serial.print(SSID); Serial.print(" ["); Serial.print(BSSIDstr); Serial.print("]"); Serial.print(" ("); Serial.print(RSSI); Serial.print(")"); Serial.println(""); + // Get BSSID => Mac Address of the Slave + int mac[6]; + if ( 6 == sscanf(BSSIDstr.c_str(), "%x:%x:%x:%x:%x:%x%c", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5] ) ) { + for (int ii = 0; ii < 6; ++ii ) { + slave.peer_addr[ii] = (uint8_t) mac[ii]; + } + } + + slave.channel = CHANNEL; // pick a channel + slave.encrypt = 0; // no encryption + + slaveFound = 1; + // we are planning to have only one slave in this example; + // Hence, break after we find one, to be a bit efficient + break; + } + } + } + + if (slaveFound) { + Serial.println("Slave Found, processing.."); + } else { + Serial.println("Slave Not Found, trying again."); + } + + // clean up ram + WiFi.scanDelete(); +} + +// Check if the slave is already paired with the master. +// If not, pair the slave with master +bool manageSlave() { + if (slave.channel == CHANNEL) { + if (DELETEBEFOREPAIR) { + deletePeer(); + } + + Serial.print("Slave Status: "); + const esp_now_peer_info_t *peer = &slave; + const uint8_t *peer_addr = slave.peer_addr; + // check if the peer exists + bool exists = esp_now_is_peer_exist(peer_addr); + if ( exists) { + // Slave already paired. + Serial.println("Already Paired"); + return true; + } else { + // Slave not paired, attempt pair + esp_err_t addStatus = esp_now_add_peer(peer); + if (addStatus == ESP_OK) { + // Pair success + Serial.println("Pair success"); + return true; + } else if (addStatus == ESP_ERR_ESPNOW_NOT_INIT) { + // How did we get so far!! + Serial.println("ESPNOW Not Init"); + return false; + } else if (addStatus == ESP_ERR_ESPNOW_ARG) { + Serial.println("Invalid Argument"); + return false; + } else if (addStatus == ESP_ERR_ESPNOW_FULL) { + Serial.println("Peer list full"); + return false; + } else if (addStatus == ESP_ERR_ESPNOW_NO_MEM) { + Serial.println("Out of memory"); + return false; + } else if (addStatus == ESP_ERR_ESPNOW_EXIST) { + Serial.println("Peer Exists"); + return true; + } else { + Serial.println("Not sure what happened"); + return false; + } + } + } else { + // No slave found to process + Serial.println("No Slave found to process"); + return false; + } +} + +void deletePeer() { + const esp_now_peer_info_t *peer = &slave; + const uint8_t *peer_addr = slave.peer_addr; + esp_err_t delStatus = esp_now_del_peer(peer_addr); + Serial.print("Slave Delete Status: "); + if (delStatus == ESP_OK) { + // Delete success + Serial.println("Success"); + } else if (delStatus == ESP_ERR_ESPNOW_NOT_INIT) { + // How did we get so far!! + Serial.println("ESPNOW Not Init"); + } else if (delStatus == ESP_ERR_ESPNOW_ARG) { + Serial.println("Invalid Argument"); + } else if (delStatus == ESP_ERR_ESPNOW_NOT_FOUND) { + Serial.println("Peer not found."); + } else { + Serial.println("Not sure what happened"); + } +} + +uint8_t data = 0; +// send data +void sendData() { + data++; + const uint8_t *peer_addr = slave.peer_addr; + Serial.print("Sending: "); Serial.println(data); + esp_err_t result = esp_now_send(peer_addr, &data, sizeof(data)); + Serial.print("Send Status: "); + if (result == ESP_OK) { + Serial.println("Success"); + } else if (result == ESP_ERR_ESPNOW_NOT_INIT) { + // How did we get so far!! + Serial.println("ESPNOW not Init."); + } else if (result == ESP_ERR_ESPNOW_ARG) { + Serial.println("Invalid Argument"); + } else if (result == ESP_ERR_ESPNOW_INTERNAL) { + Serial.println("Internal Error"); + } else if (result == ESP_ERR_ESPNOW_NO_MEM) { + Serial.println("ESP_ERR_ESPNOW_NO_MEM"); + } else if (result == ESP_ERR_ESPNOW_NOT_FOUND) { + Serial.println("Peer not found."); + } else { + Serial.println("Not sure what happened"); + } +} + +// callback when data is sent from Master to Slave +void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { + char macStr[18]; + snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", + mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); + Serial.print("Last Packet Sent to: "); Serial.println(macStr); + Serial.print("Last Packet Send Status: "); Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail"); +} + +void setup() { + Serial.begin(115200); + //Set device in STA mode to begin with + WiFi.mode(WIFI_STA); + Serial.println("ESPNow/Basic/Master Example"); + // This is the mac address of the Master in Station Mode + Serial.print("STA MAC: "); Serial.println(WiFi.macAddress()); + // Init ESPNow with a fallback logic + InitESPNow(); + // Once ESPNow is successfully Init, we will register for Send CB to + // get the status of Trasnmitted packet + esp_now_register_send_cb(OnDataSent); +} + +void loop() { + // In the loop we scan for slave + ScanForSlave(); + // If Slave is found, it would be populate in `slave` variable + // We will check if `slave` is defined and then we proceed further + if (slave.channel == CHANNEL) { // check if slave channel is defined + // `slave` is defined + // Add slave as peer if it has not been added already + bool isPaired = manageSlave(); + if (isPaired) { + // pair success or already paired + // Send data to device + sendData(); + } else { + // slave pair failed + Serial.println("Slave pair failed!"); + } + } + else { + // No slave found to process + } + + // wait for 3seconds to run the logic again + delay(3000); +} \ No newline at end of file diff --git a/libraries/ESP32/examples/ESPNow/Basic/Slave/Slave.ino b/libraries/ESP32/examples/ESPNow/Basic/Slave/Slave.ino new file mode 100644 index 00000000000..21e963b8b19 --- /dev/null +++ b/libraries/ESP32/examples/ESPNow/Basic/Slave/Slave.ino @@ -0,0 +1,90 @@ +/** + ESPNOW - Basic communication - Slave + Date: 26th September 2017 + Author: Arvind Ravulavaru + Purpose: ESPNow Communication between a Master ESP32 and a Slave ESP32 + Description: This sketch consists of the code for the Slave module. + Resources: (A bit outdated) + a. https://espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf + b. http://www.esploradores.com/practica-6-conexion-esp-now/ + + << This Device Slave >> + + Flow: Master + Step 1 : ESPNow Init on Master and set it in STA mode + Step 2 : Start scanning for Slave ESP32 (we have added a prefix of `slave` to the SSID of slave for an easy setup) + Step 3 : Once found, add Slave as peer + Step 4 : Register for send callback + Step 5 : Start Transmitting data from Master to Slave + + Flow: Slave + Step 1 : ESPNow Init on Slave + Step 2 : Update the SSID of Slave with a prefix of `slave` + Step 3 : Set Slave in AP mode + Step 4 : Register for receive callback and wait for data + Step 5 : Once data arrives, print it in the serial monitor + + Note: Master and Slave have been defined to easily understand the setup. + Based on the ESPNOW API, there is no concept of Master and Slave. + Any devices can act as master or salve. +*/ + +#include +#include + +#define CHANNEL 1 + +// Init ESP Now with fallback +void InitESPNow() { + if (esp_now_init() == ESP_OK) { + Serial.println("ESPNow Init Success"); + } + else { + Serial.println("ESPNow Init Failed"); + // Retry InitESPNow, add a counte and then restart? + // InitESPNow(); + // or Simply Restart + ESP.restart(); + } +} + +// config AP SSID +void configDeviceAP() { + char* SSID = "Slave_1"; + bool result = WiFi.softAP(SSID, "Slave_1_Password", CHANNEL, 0); + if (!result) { + Serial.println("AP Config failed."); + } else { + Serial.println("AP Config Success. Broadcasting with AP: " + String(SSID)); + } +} + +void setup() { + Serial.begin(115200); + Serial.println("ESPNow/Basic/Slave Example"); + //Set device in AP mode to begin with + WiFi.mode(WIFI_AP); + // configure device AP mode + configDeviceAP(); + // This is the mac address of the Slave in AP Mode + Serial.print("AP MAC: "); Serial.println(WiFi.softAPmacAddress()); + // Init ESPNow with a fallback logic + InitESPNow(); + // Once ESPNow is successfully Init, we will register for recv CB to + // get recv packer info. + esp_now_register_recv_cb(OnDataRecv); +} + +// callback when data is recv from Master +void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) { + char macStr[18]; + snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", + mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); + Serial.print("Last Packet Recv from: "); Serial.println(macStr); + Serial.print("Last Packet Recv Data: "); Serial.println(*data); + Serial.println(""); +} + +void loop() { + // Chill +} \ No newline at end of file diff --git a/libraries/ESP32/examples/ESPNow/Multi-Slave/Master/Master.ino b/libraries/ESP32/examples/ESPNow/Multi-Slave/Master/Master.ino new file mode 100644 index 00000000000..87b8c331a1d --- /dev/null +++ b/libraries/ESP32/examples/ESPNow/Multi-Slave/Master/Master.ino @@ -0,0 +1,245 @@ +/** + ESPNOW - Basic communication - Master + Date: 26th September 2017 + Author: Arvind Ravulavaru + Purpose: ESPNow Communication between a Master ESP32 and multiple ESP32 Slaves + Description: This sketch consists of the code for the Master module. + Resources: (A bit outdated) + a. https://espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf + b. http://www.esploradores.com/practica-6-conexion-esp-now/ + + << This Device Master >> + + Flow: Master + Step 1 : ESPNow Init on Master and set it in STA mode + Step 2 : Start scanning for Slave ESP32 (we have added a prefix of `slave` to the SSID of slave for an easy setup) + Step 3 : Once found, add Slave as peer + Step 4 : Register for send callback + Step 5 : Start Transmitting data from Master to Slave(s) + + Flow: Slave + Step 1 : ESPNow Init on Slave + Step 2 : Update the SSID of Slave with a prefix of `slave` + Step 3 : Set Slave in AP mode + Step 4 : Register for receive callback and wait for data + Step 5 : Once data arrives, print it in the serial monitor + + Note: Master and Slave have been defined to easily understand the setup. + Based on the ESPNOW API, there is no concept of Master and Slave. + Any devices can act as master or salve. + + + // Sample Serial log with 1 master & 2 slaves + Found 12 devices + 1: Slave:24:0A:C4:81:CF:A4 [24:0A:C4:81:CF:A5] (-44) + 3: Slave:30:AE:A4:02:6D:CC [30:AE:A4:02:6D:CD] (-55) + 2 Slave(s) found, processing.. + Processing: 24:A:C4:81:CF:A5 Status: Already Paired + Processing: 30:AE:A4:2:6D:CD Status: Already Paired + Sending: 9 + Send Status: Success + Last Packet Sent to: 24:0a:c4:81:cf:a5 + Last Packet Send Status: Delivery Success + Send Status: Success + Last Packet Sent to: 30:ae:a4:02:6d:cd + Last Packet Send Status: Delivery Success + +*/ + +#include +#include + +// Global copy of slave +#define NUMSLAVES 20 +esp_now_peer_info_t slaves[NUMSLAVES] = {}; +int SlaveCnt = 0; + +#define CHANNEL 3 +#define PRINTSCANRESULTS 0 + +// Init ESP Now with fallback +void InitESPNow() { + if (esp_now_init() == ESP_OK) { + Serial.println("ESPNow Init Success"); + } + else { + Serial.println("ESPNow Init Failed"); + // Retry InitESPNow, add a counte and then restart? + // InitESPNow(); + // or Simply Restart + ESP.restart(); + } +} + +// Scan for slaves in AP mode +void ScanForSlave() { + int8_t scanResults = WiFi.scanNetworks(); + //reset slaves + memset(slaves, 0, sizeof(slaves)); + SlaveCnt = 0; + Serial.println(""); + if (scanResults == 0) { + Serial.println("No WiFi devices in AP Mode found"); + } else { + Serial.print("Found "); Serial.print(scanResults); Serial.println(" devices "); + for (int i = 0; i < scanResults; ++i) { + // Print SSID and RSSI for each device found + String SSID = WiFi.SSID(i); + int32_t RSSI = WiFi.RSSI(i); + String BSSIDstr = WiFi.BSSIDstr(i); + + if (PRINTSCANRESULTS) { + Serial.print(i + 1); Serial.print(": "); Serial.print(SSID); Serial.print(" ["); Serial.print(BSSIDstr); Serial.print("]"); Serial.print(" ("); Serial.print(RSSI); Serial.print(")"); Serial.println(""); + } + delay(10); + // Check if the current device starts with `Slave` + if (SSID.indexOf("Slave") == 0) { + // SSID of interest + Serial.print(i + 1); Serial.print(": "); Serial.print(SSID); Serial.print(" ["); Serial.print(BSSIDstr); Serial.print("]"); Serial.print(" ("); Serial.print(RSSI); Serial.print(")"); Serial.println(""); + // Get BSSID => Mac Address of the Slave + int mac[6]; + + if ( 6 == sscanf(BSSIDstr.c_str(), "%x:%x:%x:%x:%x:%x%c", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5] ) ) { + for (int ii = 0; ii < 6; ++ii ) { + slaves[SlaveCnt].peer_addr[ii] = (uint8_t) mac[ii]; + } + } + slaves[SlaveCnt].channel = CHANNEL; // pick a channel + slaves[SlaveCnt].encrypt = 0; // no encryption + SlaveCnt++; + } + } + } + + if (SlaveCnt > 0) { + Serial.print(SlaveCnt); Serial.println(" Slave(s) found, processing.."); + } else { + Serial.println("No Slave Found, trying again."); + } + + // clean up ram + WiFi.scanDelete(); +} + +// Check if the slave is already paired with the master. +// If not, pair the slave with master +void manageSlave() { + if (SlaveCnt > 0) { + for (int i = 0; i < SlaveCnt; i++) { + const esp_now_peer_info_t *peer = &slaves[i]; + const uint8_t *peer_addr = slaves[i].peer_addr; + Serial.print("Processing: "); + for (int ii = 0; ii < 6; ++ii ) { + Serial.print((uint8_t) slaves[i].peer_addr[ii], HEX); + if (ii != 5) Serial.print(":"); + } + Serial.print(" Status: "); + // check if the peer exists + bool exists = esp_now_is_peer_exist(peer_addr); + if (exists) { + // Slave already paired. + Serial.println("Already Paired"); + } else { + // Slave not paired, attempt pair + esp_err_t addStatus = esp_now_add_peer(peer); + if (addStatus == ESP_OK) { + // Pair success + Serial.println("Pair success"); + } else if (addStatus == ESP_ERR_ESPNOW_NOT_INIT) { + // How did we get so far!! + Serial.println("ESPNOW Not Init"); + } else if (addStatus == ESP_ERR_ESPNOW_ARG) { + Serial.println("Add Peer - Invalid Argument"); + } else if (addStatus == ESP_ERR_ESPNOW_FULL) { + Serial.println("Peer list full"); + } else if (addStatus == ESP_ERR_ESPNOW_NO_MEM) { + Serial.println("Out of memory"); + } else if (addStatus == ESP_ERR_ESPNOW_EXIST) { + Serial.println("Peer Exists"); + } else { + Serial.println("Not sure what happened"); + } + delay(100); + } + } + } else { + // No slave found to process + Serial.println("No Slave found to process"); + } +} + + +uint8_t data = 0; +// send data +void sendData() { + data++; + for (int i = 0; i < SlaveCnt; i++) { + const uint8_t *peer_addr = slaves[i].peer_addr; + if (i == 0) { // print only for first slave + Serial.print("Sending: "); + Serial.println(data); + } + esp_err_t result = esp_now_send(peer_addr, &data, sizeof(data)); + Serial.print("Send Status: "); + if (result == ESP_OK) { + Serial.println("Success"); + } else if (result == ESP_ERR_ESPNOW_NOT_INIT) { + // How did we get so far!! + Serial.println("ESPNOW not Init."); + } else if (result == ESP_ERR_ESPNOW_ARG) { + Serial.println("Invalid Argument"); + } else if (result == ESP_ERR_ESPNOW_INTERNAL) { + Serial.println("Internal Error"); + } else if (result == ESP_ERR_ESPNOW_NO_MEM) { + Serial.println("ESP_ERR_ESPNOW_NO_MEM"); + } else if (result == ESP_ERR_ESPNOW_NOT_FOUND) { + Serial.println("Peer not found."); + } else { + Serial.println("Not sure what happened"); + } + delay(100); + } +} + +// callback when data is sent from Master to Slave +void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { + char macStr[18]; + snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", + mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); + Serial.print("Last Packet Sent to: "); Serial.println(macStr); + Serial.print("Last Packet Send Status: "); Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail"); +} + +void setup() { + Serial.begin(115200); + //Set device in STA mode to begin with + WiFi.mode(WIFI_STA); + Serial.println("ESPNow/Multi-Slave/Master Example"); + // This is the mac address of the Master in Station Mode + Serial.print("STA MAC: "); Serial.println(WiFi.macAddress()); + // Init ESPNow with a fallback logic + InitESPNow(); + // Once ESPNow is successfully Init, we will register for Send CB to + // get the status of Trasnmitted packet + esp_now_register_send_cb(OnDataSent); +} + +void loop() { + // In the loop we scan for slave + ScanForSlave(); + // If Slave is found, it would be populate in `slave` variable + // We will check if `slave` is defined and then we proceed further + if (SlaveCnt > 0) { // check if slave channel is defined + // `slave` is defined + // Add slave as peer if it has not been added already + manageSlave(); + // pair success or already paired + // Send data to device + sendData(); + } else { + // No slave found to process + } + + // wait for 3seconds to run the logic again + delay(1000); +} \ No newline at end of file diff --git a/libraries/ESP32/examples/ESPNow/Multi-Slave/Slave/Slave.ino b/libraries/ESP32/examples/ESPNow/Multi-Slave/Slave/Slave.ino new file mode 100644 index 00000000000..8837d9c1b8d --- /dev/null +++ b/libraries/ESP32/examples/ESPNow/Multi-Slave/Slave/Slave.ino @@ -0,0 +1,93 @@ +/** + ESPNOW - Basic communication - Slave + Date: 26th September 2017 + Author: Arvind Ravulavaru + Purpose: ESPNow Communication between a Master ESP32 and multiple ESP32 Slaves + Description: This sketch consists of the code for the Slave module. + Resources: (A bit outdated) + a. https://espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf + b. http://www.esploradores.com/practica-6-conexion-esp-now/ + + << This Device Slave >> + + Flow: Master + Step 1 : ESPNow Init on Master and set it in STA mode + Step 2 : Start scanning for Slave ESP32 (we have added a prefix of `slave` to the SSID of slave for an easy setup) + Step 3 : Once found, add Slave as peer + Step 4 : Register for send callback + Step 5 : Start Transmitting data from Master to Slave(s) + + Flow: Slave + Step 1 : ESPNow Init on Slave + Step 2 : Update the SSID of Slave with a prefix of `slave` + Step 3 : Set Slave in AP mode + Step 4 : Register for receive callback and wait for data + Step 5 : Once data arrives, print it in the serial monitor + + Note: Master and Slave have been defined to easily understand the setup. + Based on the ESPNOW API, there is no concept of Master and Slave. + Any devices can act as master or salve. +*/ + +#include +#include + +#define CHANNEL 1 + +// Init ESP Now with fallback +void InitESPNow() { + if (esp_now_init() == ESP_OK) { + Serial.println("ESPNow Init Success"); + } + else { + Serial.println("ESPNow Init Failed"); + // Retry InitESPNow, add a counte and then restart? + // InitESPNow(); + // or Simply Restart + ESP.restart(); + } +} + +// config AP SSID +void configDeviceAP() { + String Prefix = "Slave:"; + String Mac = WiFi.macAddress(); + String SSID = Prefix + Mac; + String Password = "123456789"; + bool result = WiFi.softAP(SSID.c_str(), Password.c_str(), CHANNEL, 0); + if (!result) { + Serial.println("AP Config failed."); + } else { + Serial.println("AP Config Success. Broadcasting with AP: " + String(SSID)); + } +} + +void setup() { + Serial.begin(115200); + Serial.println("ESPNow/Basic/Slave Example"); + //Set device in AP mode to begin with + WiFi.mode(WIFI_AP); + // configure device AP mode + configDeviceAP(); + // This is the mac address of the Slave in AP Mode + Serial.print("AP MAC: "); Serial.println(WiFi.softAPmacAddress()); + // Init ESPNow with a fallback logic + InitESPNow(); + // Once ESPNow is successfully Init, we will register for recv CB to + // get recv packer info. + esp_now_register_recv_cb(OnDataRecv); +} + +// callback when data is recv from Master +void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) { + char macStr[18]; + snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", + mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); + Serial.print("Last Packet Recv from: "); Serial.println(macStr); + Serial.print("Last Packet Recv Data: "); Serial.println(*data); + Serial.println(""); +} + +void loop() { + // Chill +} \ No newline at end of file diff --git a/libraries/HTTPClient/src/HTTPClient.cpp b/libraries/HTTPClient/src/HTTPClient.cpp index f469a0934da..8b82bbe08e3 100644 --- a/libraries/HTTPClient/src/HTTPClient.cpp +++ b/libraries/HTTPClient/src/HTTPClient.cpp @@ -107,14 +107,11 @@ bool HTTPClient::begin(String url, const char* CAcert) { _transportTraits.reset(nullptr); _port = 443; - if (strlen(CAcert) == 0) { - return false; - } if (!beginInternal(url, "https")) { return false; } + _secure = true; _transportTraits = TransportTraitsPtr(new TLSTraits(CAcert)); - //log_d("[HTTP-Client][begin] CAcert: %s", CAcert.c_str()); return true; } @@ -124,10 +121,11 @@ bool HTTPClient::begin(String url, const char* CAcert) */ bool HTTPClient::begin(String url) { + _transportTraits.reset(nullptr); _port = 80; if (!beginInternal(url, "http")) { - return false; + return begin(url, (const char*)NULL); } _transportTraits = TransportTraitsPtr(new TransportTraits()); return true; @@ -135,18 +133,22 @@ bool HTTPClient::begin(String url) bool HTTPClient::beginInternal(String url, const char* expectedProtocol) { - log_d("[HTTP-Client][begin] url: %s", url.c_str()); - bool hasPort = false; + log_v("url: %s", url.c_str()); clear(); // check for : (http: or https: int index = url.indexOf(':'); if(index < 0) { - log_d("[HTTP-Client][begin] failed to parse protocol"); + log_e("failed to parse protocol"); return false; } _protocol = url.substring(0, index); + if (_protocol != expectedProtocol) { + log_w("unexpected protocol: %s, expected %s", _protocol.c_str(), expectedProtocol); + return false; + } + url.remove(0, (index + 3)); // remove http:// or https:// index = url.indexOf('/'); @@ -172,11 +174,7 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol) _host = host; } _uri = url; - if (_protocol != expectedProtocol) { - log_d("[HTTP-Client][begin] unexpected protocol: %s, expected %s", _protocol.c_str(), expectedProtocol); - return false; - } - log_d("[HTTP-Client][begin] host: %s port: %d url: %s", _host.c_str(), _port, _uri.c_str()); + log_d("host: %s port: %d url: %s", _host.c_str(), _port, _uri.c_str()); return true; } @@ -187,7 +185,7 @@ bool HTTPClient::begin(String host, uint16_t port, String uri) _port = port; _uri = uri; _transportTraits = TransportTraitsPtr(new TransportTraits()); - log_d("[HTTP-Client][begin] host: %s port: %d uri: %s", host.c_str(), port, uri.c_str()); + log_d("host: %s port: %d uri: %s", host.c_str(), port, uri.c_str()); return true; } @@ -202,7 +200,6 @@ bool HTTPClient::begin(String host, uint16_t port, String uri, const char* CAcer return false; } _transportTraits = TransportTraitsPtr(new TLSTraits(CAcert)); - //log_d("[HTTP-Client][begin] host: %s port: %d url: %s httpsFingerprint: %s", host.c_str(), port, uri.c_str(), httpsFingerprint.c_str()); return true; } @@ -214,19 +211,19 @@ void HTTPClient::end(void) { if(connected()) { if(_tcp->available() > 0) { - log_d("[HTTP-Client][end] still data in buffer (%d), clean up.", _tcp->available()); + log_d("still data in buffer (%d), clean up.", _tcp->available()); while(_tcp->available() > 0) { _tcp->read(); } } if(_reuse && _canReuse) { - log_d("[HTTP-Client][end] tcp keep open for reuse"); + log_d("tcp keep open for reuse"); } else { - log_d("[HTTP-Client][end] tcp stop"); + log_d("tcp stop"); _tcp->stop(); } } else { - log_d("[HTTP-Client][end] tcp is closed"); + log_v("tcp is closed"); } } @@ -294,7 +291,7 @@ void HTTPClient::setAuthorization(const char * auth) void HTTPClient::setTimeout(uint16_t timeout) { _tcpTimeout = timeout; - if(connected()) { + if(connected() && !_secure) { _tcp->setTimeout(timeout); } } @@ -467,11 +464,11 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) // are all Bytes a writen to stream ? if(bytesWrite != bytesRead) { - log_d("[HTTP-Client][sendRequest] short write, asked for %d but got %d retry...", bytesRead, bytesWrite); + log_d("short write, asked for %d but got %d retry...", bytesRead, bytesWrite); // check for write error if(_tcp->getWriteError()) { - log_d("[HTTP-Client][sendRequest] stream write error %d", _tcp->getWriteError()); + log_d("stream write error %d", _tcp->getWriteError()); //reset write error for retry _tcp->clearWriteError(); @@ -488,7 +485,7 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) if(bytesWrite != leftBytes) { // failed again - log_d("[HTTP-Client][sendRequest] short write, asked for %d but got %d failed.", leftBytes, bytesWrite); + log_d("short write, asked for %d but got %d failed.", leftBytes, bytesWrite); free(buff); return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); } @@ -496,7 +493,7 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) // check for write error if(_tcp->getWriteError()) { - log_d("[HTTP-Client][sendRequest] stream write error %d", _tcp->getWriteError()); + log_d("stream write error %d", _tcp->getWriteError()); free(buff); return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); } @@ -515,15 +512,15 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) free(buff); if(size && (int) size != bytesWritten) { - log_d("[HTTP-Client][sendRequest] Stream payload bytesWritten %d and size %d mismatch!.", bytesWritten, size); - log_d("[HTTP-Client][sendRequest] ERROR SEND PAYLOAD FAILED!"); + log_d("Stream payload bytesWritten %d and size %d mismatch!.", bytesWritten, size); + log_d("ERROR SEND PAYLOAD FAILED!"); return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); } else { - log_d("[HTTP-Client][sendRequest] Stream payload written: %d", bytesWritten); + log_d("Stream payload written: %d", bytesWritten); } } else { - log_d("[HTTP-Client][sendRequest] too less ram! need %d", HTTP_TCP_BUFFER_SIZE); + log_d("too less ram! need %d", HTTP_TCP_BUFFER_SIZE); return returnError(HTTPC_ERROR_TOO_LESS_RAM); } @@ -550,7 +547,7 @@ WiFiClient& HTTPClient::getStream(void) return *_tcp; } - log_d("[HTTP-Client] getStream: not connected"); + log_d("getStream: not connected"); static WiFiClient empty; return empty; } @@ -565,7 +562,7 @@ WiFiClient* HTTPClient::getStreamPtr(void) return _tcp.get(); } - log_d("[HTTP-Client] getStreamPtr: not connected"); + log_d("getStreamPtr: not connected"); return nullptr; } @@ -613,7 +610,7 @@ int HTTPClient::writeToStream(Stream * stream) // read size of chunk len = (uint32_t) strtol((const char *) chunkHeader.c_str(), NULL, 16); size += len; - log_d("[HTTP-Client] read chunk len: %d", len); + log_d(" read chunk len: %d", len); // data left? if(len > 0) { @@ -665,7 +662,7 @@ String HTTPClient::getString(void) if(_size) { // try to reserve needed memmory if(!sstring.reserve((_size + 1))) { - log_d("[HTTP-Client][getString] not enough memory to reserve a string! need: %d", (_size + 1)); + log_d("not enough memory to reserve a string! need: %d", (_size + 1)); return ""; } } @@ -806,7 +803,7 @@ bool HTTPClient::connect(void) { if(connected()) { - log_d("[HTTP-Client] connect. already connected, try reuse!"); + log_d("already connected, try reuse!"); while(_tcp->available() > 0) { _tcp->read(); } @@ -814,7 +811,7 @@ bool HTTPClient::connect(void) } if (!_transportTraits) { - log_d("[HTTP-Client] connect: HTTPClient::begin was not called or returned error"); + log_d("HTTPClient::begin was not called or returned error"); return false; } @@ -822,20 +819,20 @@ bool HTTPClient::connect(void) if (!_transportTraits->verify(*_tcp, _host.c_str())) { - log_d("[HTTP-Client] transport level verify failed"); + log_d("transport level verify failed"); _tcp->stop(); return false; } if(!_tcp->connect(_host.c_str(), _port)) { - log_d("[HTTP-Client] failed connect to %s:%u", _host.c_str(), _port); + log_d("failed connect to %s:%u", _host.c_str(), _port); return false; } - log_d("[HTTP-Client] connected to %s:%u", _host.c_str(), _port); + log_d(" connected to %s:%u", _host.c_str(), _port); // set Timeout for readBytesUntil and readStringUntil - _tcp->setTimeout(_tcpTimeout); + setTimeout(_tcpTimeout); /* #ifdef ESP8266 _tcp->setNoDelay(true); @@ -920,7 +917,7 @@ int HTTPClient::handleHeaderResponse() lastDataTime = millis(); - log_d("[HTTP-Client][handleHeaderResponse] RX: '%s'", headerLine.c_str()); + log_v("RX: '%s'", headerLine.c_str()); if(headerLine.startsWith("HTTP/1.")) { _returnCode = headerLine.substring(9, headerLine.indexOf(' ', 9)).toInt(); @@ -950,14 +947,14 @@ int HTTPClient::handleHeaderResponse() } if(headerLine == "") { - log_d("[HTTP-Client][handleHeaderResponse] code: %d", _returnCode); + log_d("code: %d", _returnCode); if(_size > 0) { - log_d("[HTTP-Client][handleHeaderResponse] size: %d", _size); + log_d("size: %d", _size); } if(transferEncoding.length() > 0) { - log_d("[HTTP-Client][handleHeaderResponse] Transfer-Encoding: %s", transferEncoding.c_str()); + log_d("Transfer-Encoding: %s", transferEncoding.c_str()); if(transferEncoding.equalsIgnoreCase("chunked")) { _transferEncoding = HTTPC_TE_CHUNKED; } else { @@ -970,7 +967,7 @@ int HTTPClient::handleHeaderResponse() if(_returnCode) { return _returnCode; } else { - log_d("[HTTP-Client][handleHeaderResponse] Remote host is not an HTTP Server!"); + log_d("Remote host is not an HTTP Server!"); return HTTPC_ERROR_NO_HTTP_SERVER; } } @@ -1036,11 +1033,11 @@ int HTTPClient::writeToStreamDataBlock(Stream * stream, int size) // are all Bytes a writen to stream ? if(bytesWrite != bytesRead) { - log_d("[HTTP-Client][writeToStream] short write asked for %d but got %d retry...", bytesRead, bytesWrite); + log_d("short write asked for %d but got %d retry...", bytesRead, bytesWrite); // check for write error if(stream->getWriteError()) { - log_d("[HTTP-Client][writeToStreamDataBlock] stream write error %d", stream->getWriteError()); + log_d("stream write error %d", stream->getWriteError()); //reset write error for retry stream->clearWriteError(); @@ -1057,7 +1054,7 @@ int HTTPClient::writeToStreamDataBlock(Stream * stream, int size) if(bytesWrite != leftBytes) { // failed again - log_d("[HTTP-Client][writeToStream] short write asked for %d but got %d failed.", leftBytes, bytesWrite); + log_w("short write asked for %d but got %d failed.", leftBytes, bytesWrite); free(buff); return HTTPC_ERROR_STREAM_WRITE; } @@ -1065,7 +1062,7 @@ int HTTPClient::writeToStreamDataBlock(Stream * stream, int size) // check for write error if(stream->getWriteError()) { - log_d("[HTTP-Client][writeToStreamDataBlock] stream write error %d", stream->getWriteError()); + log_w("stream write error %d", stream->getWriteError()); free(buff); return HTTPC_ERROR_STREAM_WRITE; } @@ -1083,15 +1080,15 @@ int HTTPClient::writeToStreamDataBlock(Stream * stream, int size) free(buff); - log_d("[HTTP-Client][writeToStreamDataBlock] connection closed or file end (written: %d).", bytesWritten); + log_d("connection closed or file end (written: %d).", bytesWritten); if((size > 0) && (size != bytesWritten)) { - log_d("[HTTP-Client][writeToStreamDataBlock] bytesWritten %d and size %d mismatch!.", bytesWritten, size); + log_d("bytesWritten %d and size %d mismatch!.", bytesWritten, size); return HTTPC_ERROR_STREAM_WRITE; } } else { - log_d("[HTTP-Client][writeToStreamDataBlock] too less ram! need %d", HTTP_TCP_BUFFER_SIZE); + log_w("too less ram! need %d", HTTP_TCP_BUFFER_SIZE); return HTTPC_ERROR_TOO_LESS_RAM; } @@ -1106,9 +1103,9 @@ int HTTPClient::writeToStreamDataBlock(Stream * stream, int size) int HTTPClient::returnError(int error) { if(error < 0) { - log_d("[HTTP-Client][returnError] error(%d): %s", error, errorToString(error).c_str()); + log_w("error(%d): %s", error, errorToString(error).c_str()); if(connected()) { - log_d("[HTTP-Client][returnError] tcp stop"); + log_d("tcp stop"); _tcp->stop(); } } diff --git a/libraries/HTTPClient/src/HTTPClient.h b/libraries/HTTPClient/src/HTTPClient.h index 6f27b0f5553..2104fb0c3e4 100644 --- a/libraries/HTTPClient/src/HTTPClient.h +++ b/libraries/HTTPClient/src/HTTPClient.h @@ -196,6 +196,7 @@ class HTTPClient bool _reuse = false; uint16_t _tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT; bool _useHTTP10 = false; + bool _secure = false; String _uri; String _protocol; diff --git a/libraries/Preferences/keywords.txt b/libraries/Preferences/keywords.txt index d621b5b239d..fe2d4333e6e 100644 --- a/libraries/Preferences/keywords.txt +++ b/libraries/Preferences/keywords.txt @@ -15,7 +15,7 @@ begin KEYWORD2 end KEYWORD2 clear KEYWORD2 -delete KEYWORD2 +remove KEYWORD2 putChar KEYWORD2 putUChar KEYWORD2 diff --git a/libraries/SD/examples/SD_Test/SD_Test.ino b/libraries/SD/examples/SD_Test/SD_Test.ino index 69c59766acc..6059446e600 100644 --- a/libraries/SD/examples/SD_Test/SD_Test.ino +++ b/libraries/SD/examples/SD_Test/SD_Test.ino @@ -212,6 +212,8 @@ void setup(){ renameFile(SD, "/hello.txt", "/foo.txt"); readFile(SD, "/foo.txt"); testFileIO(SD, "/test.txt"); + Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024)); + Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024)); } void loop(){ diff --git a/libraries/SD/src/SD.cpp b/libraries/SD/src/SD.cpp index 65e68c0f093..be307f39a6f 100644 --- a/libraries/SD/src/SD.cpp +++ b/libraries/SD/src/SD.cpp @@ -14,6 +14,7 @@ #include "vfs_api.h" #include "sd_diskio.h" +#include "ff.h" #include "FS.h" #include "SD.h" @@ -73,4 +74,32 @@ uint64_t SDFS::cardSize() return (uint64_t)sectors * sectorSize; } +uint64_t SDFS::totalBytes() +{ + FATFS* fsinfo; + DWORD fre_clust; + if(f_getfree("0:",&fre_clust,&fsinfo)!= 0) return 0; + uint64_t size = (fsinfo->csize)*(fsinfo->n_fatent - 2) +#if _MAX_SS != 512 + *(fsinfo->ssize); +#else + *512; +#endif + return size; +} + +uint64_t SDFS::usedBytes() +{ + FATFS* fsinfo; + DWORD fre_clust; + if(f_getfree("0:",&fre_clust,&fsinfo)!= 0) return 0; + uint64_t size = (fsinfo->csize)*((fsinfo->n_fatent - 2) - (fsinfo->free_clst)) +#if _MAX_SS != 512 + *(fsinfo->ssize); +#else + *512; +#endif + return size; +} + SDFS SD = SDFS(FSImplPtr(new VFSImpl())); diff --git a/libraries/SD/src/SD.h b/libraries/SD/src/SD.h index cf49bb8f55a..54e41ce38ab 100644 --- a/libraries/SD/src/SD.h +++ b/libraries/SD/src/SD.h @@ -32,6 +32,8 @@ class SDFS : public FS void end(); sdcard_type_t cardType(); uint64_t cardSize(); + uint64_t totalBytes(); + uint64_t usedBytes(); }; } diff --git a/libraries/SD/src/sd_diskio.cpp b/libraries/SD/src/sd_diskio.cpp index e82cdc61ef6..dbfadfeeb41 100644 --- a/libraries/SD/src/sd_diskio.cpp +++ b/libraries/SD/src/sd_diskio.cpp @@ -628,10 +628,10 @@ DRESULT ff_sd_ioctl(uint8_t pdrv, uint8_t cmd, void* buff) *((unsigned long*) buff) = s_cards[pdrv]->sectors; return RES_OK; case GET_SECTOR_SIZE: - *((unsigned long*) buff) = 512; + *((WORD*) buff) = 512; return RES_OK; case GET_BLOCK_SIZE: - *((unsigned long*)buff) = 1; + *((uint32_t*)buff) = 1; return RES_OK; } return RES_PARERR; diff --git a/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino b/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino index bfd986810c1..b9e872850a0 100644 --- a/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino +++ b/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino @@ -209,6 +209,8 @@ void setup(){ renameFile(SD_MMC, "/hello.txt", "/foo.txt"); readFile(SD_MMC, "/foo.txt"); testFileIO(SD_MMC, "/test.txt"); + Serial.printf("Total space: %lluMB\n", SD_MMC.totalBytes() / (1024 * 1024)); + Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024)); } void loop(){ diff --git a/libraries/SD_MMC/src/SD_MMC.cpp b/libraries/SD_MMC/src/SD_MMC.cpp index 54b97c1e5f3..d554413bab8 100644 --- a/libraries/SD_MMC/src/SD_MMC.cpp +++ b/libraries/SD_MMC/src/SD_MMC.cpp @@ -23,6 +23,7 @@ extern "C" { #include "driver/sdmmc_defs.h" #include "sdmmc_cmd.h" } +#include "ff.h" #include "SD_MMC.h" using namespace fs; @@ -98,5 +99,32 @@ uint64_t SDMMCFS::cardSize() return (uint64_t)_card->csd.capacity * _card->csd.sector_size; } +uint64_t SDMMCFS::totalBytes() +{ + FATFS* fsinfo; + DWORD fre_clust; + if(f_getfree("0:",&fre_clust,&fsinfo)!= 0) return 0; + uint64_t size = (fsinfo->csize)*(fsinfo->n_fatent - 2) +#if _MAX_SS != 512 + *(fsinfo->ssize); +#else + *512; +#endif + return size; +} + +uint64_t SDMMCFS::usedBytes() +{ + FATFS* fsinfo; + DWORD fre_clust; + if(f_getfree("0:",&fre_clust,&fsinfo)!= 0) return 0; + uint64_t size = (fsinfo->csize)*((fsinfo->n_fatent - 2) - (fsinfo->free_clst)) +#if _MAX_SS != 512 + *(fsinfo->ssize); +#else + *512; +#endif + return size; +} SDMMCFS SD_MMC = SDMMCFS(FSImplPtr(new VFSImpl())); diff --git a/libraries/SD_MMC/src/SD_MMC.h b/libraries/SD_MMC/src/SD_MMC.h index fad774cbe30..e3dc15432a5 100644 --- a/libraries/SD_MMC/src/SD_MMC.h +++ b/libraries/SD_MMC/src/SD_MMC.h @@ -32,6 +32,8 @@ class SDMMCFS : public FS void end(); sdcard_type_t cardType(); uint64_t cardSize(); + uint64_t totalBytes(); + uint64_t usedBytes(); }; } diff --git a/libraries/SPI/src/SPI.cpp b/libraries/SPI/src/SPI.cpp index e1e7a15c54f..629b50bce1b 100644 --- a/libraries/SPI/src/SPI.cpp +++ b/libraries/SPI/src/SPI.cpp @@ -127,8 +127,8 @@ void SPIClass::beginTransaction(SPISettings settings) void SPIClass::endTransaction() { if(_inTransaction){ - spiEndTransaction(_spi); _inTransaction = false; + spiEndTransaction(_spi); } } diff --git a/libraries/SPIFFS/examples/SPIFFS_Test/SPIFFS_Test.ino b/libraries/SPIFFS/examples/SPIFFS_Test/SPIFFS_Test.ino index 8a7ca7c2acd..f77f28e738f 100644 --- a/libraries/SPIFFS/examples/SPIFFS_Test/SPIFFS_Test.ino +++ b/libraries/SPIFFS/examples/SPIFFS_Test/SPIFFS_Test.ino @@ -36,7 +36,7 @@ void readFile(fs::FS &fs, const char * path){ Serial.printf("Reading file: %s\n", path); File file = fs.open(path); - if(!file){ + if(!file || file.isDirectory()){ Serial.println("Failed to open file for reading"); return; } @@ -101,7 +101,7 @@ void testFileIO(fs::FS &fs, const char * path){ size_t len = 0; uint32_t start = millis(); uint32_t end = start; - if(file){ + if(file && !file.isDirectory()){ len = file.size(); size_t flen = len; start = millis(); diff --git a/libraries/SimpleBLE/examples/SimpleBleDevice/SimpleBleDevice.ino b/libraries/SimpleBLE/examples/SimpleBleDevice/SimpleBleDevice.ino index 249363d4893..3a9825a6b84 100644 --- a/libraries/SimpleBLE/examples/SimpleBleDevice/SimpleBleDevice.ino +++ b/libraries/SimpleBLE/examples/SimpleBleDevice/SimpleBleDevice.ino @@ -17,6 +17,11 @@ // Button is attached between GPIO 0 and GND, and the device name changes each time the button is pressed #include "SimpleBLE.h" + +#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) +#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it +#endif + SimpleBLE ble; void onButton(){ diff --git a/libraries/SimpleBLE/src/SimpleBLE.cpp b/libraries/SimpleBLE/src/SimpleBLE.cpp index 01753052fa6..68064723c24 100644 --- a/libraries/SimpleBLE/src/SimpleBLE.cpp +++ b/libraries/SimpleBLE/src/SimpleBLE.cpp @@ -12,6 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "sdkconfig.h" + +#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BLUEDROID_ENABLED) + #include "SimpleBLE.h" #include "esp32-hal-log.h" @@ -125,3 +129,5 @@ void SimpleBLE::end() { _stop_gap(); } + +#endif diff --git a/libraries/SimpleBLE/src/SimpleBLE.h b/libraries/SimpleBLE/src/SimpleBLE.h index 23ba2e7b620..e43d90379a7 100644 --- a/libraries/SimpleBLE/src/SimpleBLE.h +++ b/libraries/SimpleBLE/src/SimpleBLE.h @@ -15,6 +15,9 @@ #ifndef _SIMPLE_BLE_H_ #define _SIMPLE_BLE_H_ +#include "sdkconfig.h" + +#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BLUEDROID_ENABLED) #include #include @@ -58,3 +61,5 @@ class SimpleBLE { }; #endif + +#endif diff --git a/libraries/Update/examples/SD_Update/SD_Update.ino b/libraries/Update/examples/SD_Update/SD_Update.ino new file mode 100644 index 00000000000..9f3f494aba8 --- /dev/null +++ b/libraries/Update/examples/SD_Update/SD_Update.ino @@ -0,0 +1,112 @@ +/* + Name: SD_Update.ino + Created: 12.09.2017 15:07:17 + Author: Frederik Merz + Purpose: Update firmware from SD card + + Steps: + 1. Flash this image to the ESP32 an run it + 2. Copy update.bin to a SD-Card, you can basically + compile this or any other example + then copy and rename the app binary to the sd card root + 3. Connect SD-Card as shown in SD_MMC example, + this can also be adapted for SPI + 3. After successfull update and reboot, ESP32 shall start the new app +*/ + +#include +#include +#include + +// perform the actual update from a given stream +void performUpdate(Stream &updateSource, size_t updateSize) { + if (Update.begin(updateSize)) { + size_t written = Update.writeStream(updateSource); + if (written == updateSize) { + Serial.println("Written : " + String(written) + " successfully"); + } + else { + Serial.println("Written only : " + String(written) + "/" + String(updateSize) + ". Retry?"); + } + if (Update.end()) { + Serial.println("OTA done!"); + if (Update.isFinished()) { + Serial.println("Update successfully completed. Rebooting."); + } + else { + Serial.println("Update not finished? Something went wrong!"); + } + } + else { + Serial.println("Error Occurred. Error #: " + String(Update.getError())); + } + + } + else + { + Serial.println("Not enough space to begin OTA"); + } +} + +// check given FS for valid update.bin and perform update if available +void updateFromFS(fs::FS &fs) { + File updateBin = fs.open("/update.bin"); + if (updateBin) { + if(updateBin.isDirectory()){ + Serial.println("Error, update.bin is not a file"); + updateBin.close(); + return; + } + + size_t updateSize = updateBin.size(); + + if (updateSize > 0) { + Serial.println("Try to start update"); + performUpdate(updateBin, updateSize); + } + else { + Serial.println("Error, file is empty"); + } + + updateBin.close(); + + // whe finished remove the binary from sd card to indicate end of the process + fs.remove("/update.bin"); + } + else { + Serial.println("Could not load update.bin from sd root"); + } +} + +void setup() { + uint8_t cardType; + Serial.begin(115200); + Serial.println("Welcome to the SD-Update example!"); + + // You can uncomment this and build again + // Serial.println("Update successfull"); + + //first init and check SD card + if (!SD_MMC.begin()) { + rebootEspWithReason("Card Mount Failed"); + } + + cardType = SD_MMC.cardType(); + + if (cardType == CARD_NONE) { + rebootEspWithReason("No SD_MMC card attached"); + }else{ + updateFromFS(SD_MMC); + } +} + +void rebootEspWithReason(String reason){ + Serial.println(reason); + delay(1000); + ESP.restart(); +} + +//will not be reached +void loop() { + +} \ No newline at end of file diff --git a/libraries/WiFi/examples/WPS/README.md b/libraries/WiFi/examples/WPS/README.md new file mode 100644 index 00000000000..69431423d5a --- /dev/null +++ b/libraries/WiFi/examples/WPS/README.md @@ -0,0 +1,104 @@ +Example Serial Logs For Various Cases +====================================== + +For WPS Push Button method,after the ESP32 boots up and prints that WPS has started, press the button that looks something like [this](https://www.verizon.com/supportresources/images/fqgrouter-frontview-wps-button.png) on your router. In case you dont find anything similar, check your router specs if it does really support WPS Push functionality. + +As for WPS Pin Mode, it will output a 8 digit Pin on the Serial Monitor that will change every 2 minutes if it hasn't connected. You need to log in to your router (generally reaching 192.168.0.1) and enter the pin shown in Serial Monitor in the WPS Settings of your router. + +#### WPS Push Button Failure + +``` +ets Jun 8 2016 00:22:57 + +rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) +configsip: 0, SPIWP:0xee +clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 +mode:DIO, clock div:1 +load:0x3fff0010,len:4 +load:0x3fff0014,len:732 +load:0x40078000,len:0 +load:0x40078000,len:11572 +entry 0x40078a14 + +Starting WPS +Station Mode Started +WPS Timedout, retrying +WPS Timedout, retrying +``` + +#### WPS Push Button Successfull + +``` +ets Jun 8 2016 00:22:57 + +rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) +ets Jun 8 2016 00:22:57 + +rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) +configsip: 0, SPIWP:0xee +clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 +mode:DIO, clock div:1 +load:0x3fff0010,len:4 +load:0x3fff0014,len:732 +load:0x40078000,len:0 +load:0x40078000,len:11572 +entry 0x40078a14 + +Starting WPS +Station Mode Started +WPS Successfull, stopping WPS and connecting to: < Your Router SSID > +Disconnected from station, attempting reconnection +Connected to : < Your Router SSID > +Got IP: 192.168.1.100 +``` + +#### WPS PIN Failure + +``` +ets Jun 8 2016 00:22:57 + +rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) +ets Jun 8 2016 00:22:57 + +rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) +configsip: 0, SPIWP:0xee +clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 +mode:DIO, clock div:1 +load:0x3fff0010,len:4 +load:0x3fff0014,len:732 +load:0x40078000,len:0 +load:0x40078000,len:11572 +entry 0x40078a14 + +Starting WPS +Station Mode Started +WPS_PIN = 94842104 +WPS Timedout, retrying +WPS_PIN = 55814171 +WPS Timedout, retrying +WPS_PIN = 71321622 +``` + +#### WPS PIN Successfull + +``` +ets Jun 8 2016 00:22:57 + +rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) +configsip: 0, SPIWP:0xee +clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 +mode:DIO, clock div:1 +load:0x3fff0010,len:4 +load:0x3fff0014,len:732 +load:0x40078000,len:0 +load:0x40078000,len:11572 +entry 0x40078a14 + +Starting WPS +Station Mode Started +WPS_PIN = 36807581 +WPS Successfull, stopping WPS and connecting to: +Disconnected from station, attempting reconnection +Connected to : +Got IP: 192.168.1.100 +``` diff --git a/libraries/WiFi/examples/WPS/WPS.ino b/libraries/WiFi/examples/WPS/WPS.ino new file mode 100644 index 00000000000..79e11e8a611 --- /dev/null +++ b/libraries/WiFi/examples/WPS/WPS.ino @@ -0,0 +1,96 @@ +/* +Example Code To Get ESP32 To Connect To A Router Using WPS +=========================================================== +This example code provides both Push Button method and Pin +based WPS entry to get your ESP connected to your WiFi router. + +Hardware Requirements +======================== +ESP32 and a Router having atleast one WPS functionality + +This code is under Public Domain License. + +Author: +Pranav Cherukupalli +*/ + +#include "WiFi.h" +#include "esp_wps.h" + +/* +Change the definition of the WPS mode +from WPS_TYPE_PBC to WPS_TYPE_PIN in +the case that you are using pin type +WPS +*/ +#define ESP_WPS_MODE WPS_TYPE_PBC + +esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(ESP_WPS_MODE); + +String wpspin2string(uint8_t a[]){ + char wps_pin[9]; + for(int i=0;i<8;i++){ + wps_pin[i] = a[i]; + } + wps_pin[8] = '\0'; + return (String)wps_pin; +} + +void WiFiEvent(WiFiEvent_t event, system_event_info_t info){ + switch(event){ + case SYSTEM_EVENT_STA_START: + Serial.println("Station Mode Started"); + break; + case SYSTEM_EVENT_STA_GOT_IP: + Serial.println("Connected to :" + String(WiFi.SSID())); + Serial.print("Got IP: "); + Serial.println(WiFi.localIP()); + break; + case SYSTEM_EVENT_STA_DISCONNECTED: + Serial.println("Disconnected from station, attempting reconnection"); + WiFi.reconnect(); + break; + case SYSTEM_EVENT_STA_WPS_ER_SUCCESS: + Serial.println("WPS Successfull, stopping WPS and connecting to: " + String(WiFi.SSID())); + esp_wifi_wps_disable(); + delay(10); + WiFi.begin(); + break; + case SYSTEM_EVENT_STA_WPS_ER_FAILED: + Serial.println("WPS Failed, retrying"); + esp_wifi_wps_disable(); + esp_wifi_wps_enable(&config); + esp_wifi_wps_start(0); + break; + case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT: + Serial.println("WPS Timedout, retrying"); + esp_wifi_wps_disable(); + esp_wifi_wps_enable(&config); + esp_wifi_wps_start(0); + break; + case SYSTEM_EVENT_STA_WPS_ER_PIN: + Serial.println("WPS_PIN = " + wpspin2string(info.sta_er_pin.pin_code)); + break; + default: + break; + } +} + +void setup(){ + Serial.begin(115200); + delay(10); + + Serial.println(); + + WiFi.onEvent(WiFiEvent); + WiFi.mode(WIFI_MODE_STA); + + Serial.println("Starting WPS"); + + esp_wifi_wps_enable(&config); + esp_wifi_wps_start(0); +} + +void loop(){ + //nothing to do here +} diff --git a/libraries/WiFi/src/WiFiAP.cpp b/libraries/WiFi/src/WiFiAP.cpp index ec5f647624e..19cb5fe5b58 100644 --- a/libraries/WiFi/src/WiFiAP.cpp +++ b/libraries/WiFi/src/WiFiAP.cpp @@ -37,6 +37,7 @@ extern "C" { #include #include #include +#include "apps/dhcpserver_options.h" } diff --git a/libraries/WiFi/src/WiFiClient.cpp b/libraries/WiFi/src/WiFiClient.cpp index 336f12b0a79..5b8c0fb65a3 100644 --- a/libraries/WiFi/src/WiFiClient.cpp +++ b/libraries/WiFi/src/WiFiClient.cpp @@ -118,7 +118,7 @@ int WiFiClient::setSocketOption(int option, char* value, size_t len) { int res = setsockopt(fd(), SOL_SOCKET, option, value, len); if(res < 0) { - log_e("%d", errno); + log_e("%X : %d", option, errno); } return res; } @@ -274,7 +274,7 @@ int WiFiClient::available() return 0; } int count; - int res = ioctl(fd(), FIONREAD, &count); + int res = lwip_ioctl_r(fd(), FIONREAD, &count); if(res < 0) { log_e("%d", errno); stop(); diff --git a/libraries/WiFi/src/WiFiGeneric.cpp b/libraries/WiFi/src/WiFiGeneric.cpp index ee16506356d..13ffc6ed824 100644 --- a/libraries/WiFi/src/WiFiGeneric.cpp +++ b/libraries/WiFi/src/WiFiGeneric.cpp @@ -51,12 +51,62 @@ extern "C" { #undef max #include +#include "sdkconfig.h" + +#if CONFIG_FREERTOS_UNICORE +#define ARDUINO_RUNNING_CORE 0 +#else +#define ARDUINO_RUNNING_CORE 1 +#endif + +static xQueueHandle _network_event_queue; +static TaskHandle_t _network_event_task_handle = NULL; + +static void _network_event_task(void * arg){ + system_event_t *event = NULL; + for (;;) { + if(xQueueReceive(_network_event_queue, &event, 0) == pdTRUE){ + WiFiGenericClass::_eventCallback(NULL, event); + } else { + vTaskDelay(1); + } + } + vTaskDelete(NULL); + _network_event_task_handle = NULL; +} + +static esp_err_t _network_event_cb(void *arg, system_event_t *event){ + if (xQueueSend(_network_event_queue, &event, portMAX_DELAY) != pdPASS) { + log_w("Network Event Queue Send Failed!"); + return ESP_FAIL; + } + return ESP_OK; +} + +static void _start_network_event_task(){ + if(!_network_event_queue){ + _network_event_queue = xQueueCreate(32, sizeof(system_event_t *)); + if(!_network_event_queue){ + log_e("Network Event Queue Create Failed!"); + return; + } + } + if(!_network_event_task_handle){ + xTaskCreatePinnedToCore(_network_event_task, "network_event", 4096, NULL, 2, &_network_event_task_handle, ARDUINO_RUNNING_CORE); + if(!_network_event_task_handle){ + log_e("Network Event Task Start Failed!"); + return; + } + } + esp_event_loop_init(&_network_event_cb, NULL); +} + void tcpipInit(){ static bool initialized = false; if(!initialized){ initialized = true; + _start_network_event_task(); tcpip_adapter_init(); - esp_event_loop_init(&WiFiGenericClass::_eventCallback, NULL); } } @@ -120,6 +170,12 @@ static bool espWiFiStop(){ // ------------------------------------------------- Generic WiFi function ----------------------------------------------- // ----------------------------------------------------------------------------------------------------------------------- +typedef struct { + WiFiEventCb cb; + WiFiEventFullCb fcb; + system_event_id_t event; +} WiFiEventCbList_t; + // arduino dont like std::vectors move static here static std::vector cbEventList; @@ -143,6 +199,19 @@ void WiFiGenericClass::onEvent(WiFiEventCb cbEvent, system_event_id_t event) } WiFiEventCbList_t newEventHandler; newEventHandler.cb = cbEvent; + newEventHandler.fcb = NULL; + newEventHandler.event = event; + cbEventList.push_back(newEventHandler); +} + +void WiFiGenericClass::onEvent(WiFiEventFullCb cbEvent, system_event_id_t event) +{ + if(!cbEvent) { + return; + } + WiFiEventCbList_t newEventHandler; + newEventHandler.cb = NULL; + newEventHandler.fcb = cbEvent; newEventHandler.event = event; cbEventList.push_back(newEventHandler); } @@ -166,6 +235,20 @@ void WiFiGenericClass::removeEvent(WiFiEventCb cbEvent, system_event_id_t event) } } +void WiFiGenericClass::removeEvent(WiFiEventFullCb cbEvent, system_event_id_t event) +{ + if(!cbEvent) { + return; + } + + for(uint32_t i = 0; i < cbEventList.size(); i++) { + WiFiEventCbList_t entry = cbEventList[i]; + if(entry.fcb == cbEvent && entry.event == event) { + cbEventList.erase(cbEventList.begin() + i); + } + } +} + /** * callback for WiFi events * @param arg @@ -208,9 +291,13 @@ esp_err_t WiFiGenericClass::_eventCallback(void *arg, system_event_t *event) for(uint32_t i = 0; i < cbEventList.size(); i++) { WiFiEventCbList_t entry = cbEventList[i]; - if(entry.cb) { + if(entry.cb || entry.fcb) { if(entry.event == (system_event_id_t) event->event_id || entry.event == SYSTEM_EVENT_MAX) { - entry.cb((system_event_id_t) event->event_id); + if(entry.cb){ + entry.cb((system_event_id_t) event->event_id); + } else { + entry.fcb((system_event_id_t) event->event_id, (system_event_info_t) event->event_info); + } } } } diff --git a/libraries/WiFi/src/WiFiGeneric.h b/libraries/WiFi/src/WiFiGeneric.h index 95b85b1693d..356f44e7289 100644 --- a/libraries/WiFi/src/WiFiGeneric.h +++ b/libraries/WiFi/src/WiFiGeneric.h @@ -28,11 +28,7 @@ #include typedef void (*WiFiEventCb)(system_event_id_t event); - -typedef struct { - WiFiEventCb cb; - system_event_id_t event; -} WiFiEventCbList_t; +typedef void (*WiFiEventFullCb)(system_event_id_t event, system_event_info_t info); class WiFiGenericClass { @@ -41,7 +37,9 @@ class WiFiGenericClass WiFiGenericClass(); void onEvent(WiFiEventCb cbEvent, system_event_id_t event = SYSTEM_EVENT_MAX); + void onEvent(WiFiEventFullCb cbEvent, system_event_id_t event = SYSTEM_EVENT_MAX); void removeEvent(WiFiEventCb cbEvent, system_event_id_t event = SYSTEM_EVENT_MAX); + void removeEvent(WiFiEventFullCb cbEvent, system_event_id_t event = SYSTEM_EVENT_MAX); int32_t channel(void); diff --git a/libraries/WiFi/src/WiFiSTA.cpp b/libraries/WiFi/src/WiFiSTA.cpp index 91e627433de..8178c834ea5 100644 --- a/libraries/WiFi/src/WiFiSTA.cpp +++ b/libraries/WiFi/src/WiFiSTA.cpp @@ -199,6 +199,7 @@ void WiFiSTAClass::_setStatus(wl_status_t status) */ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2) { + esp_err_t err = ESP_OK; if(!WiFi.enableSTA(true)) { return false; @@ -206,16 +207,40 @@ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subne esp_wifi_start(); tcpip_adapter_ip_info_t info; - info.ip.addr = static_cast(local_ip); - info.gw.addr = static_cast(gateway); - info.netmask.addr = static_cast(subnet); - tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA); - if(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &info) == ESP_OK) { - _useStaticIp = true; + if(local_ip != (uint32_t)0x00000000){ + info.ip.addr = static_cast(local_ip); + info.gw.addr = static_cast(gateway); + info.netmask.addr = static_cast(subnet); } else { + info.ip.addr = 0; + info.gw.addr = 0; + info.netmask.addr = 0; + } + + err = tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA); + if(err != ESP_OK && err != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED){ + log_e("DHCP could not be stopped! Error: %d", err); return false; } + + err = tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &info); + if(err != ERR_OK){ + log_e("STA IP could not be configured! Error: %d", err); + return false; + } + + if(info.ip.addr){ + _useStaticIp = true; + } else { + err = tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA); + if(err != ESP_OK && err != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED){ + log_w("DHCP could not be started! Error: %d", err); + return false; + } + _useStaticIp = false; + } + ip_addr_t d; d.type = IPADDR_TYPE_V4; diff --git a/libraries/WiFiClientSecure/src/ssl_client.cpp b/libraries/WiFiClientSecure/src/ssl_client.cpp index 124daaa2160..7e183f19b37 100644 --- a/libraries/WiFiClientSecure/src/ssl_client.cpp +++ b/libraries/WiFiClientSecure/src/ssl_client.cpp @@ -19,6 +19,9 @@ const char *pers = "esp32-tls"; static int handle_error(int err) { + if(err == -30848){ + return err; + } #ifdef MBEDTLS_ERROR_C char error_buf[100]; mbedtls_strerror(err, error_buf, 100); @@ -40,11 +43,11 @@ void ssl_init(sslclient_context *ssl_client) int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key) { char buf[512]; - int ret, flags, len, timeout; + int ret, flags, timeout; int enable = 1; - log_i("Free heap before TLS %u", xPortGetFreeHeapSize()); + log_v("Free heap before TLS %u", xPortGetFreeHeapSize()); - log_i("Starting socket"); + log_v("Starting socket"); ssl_client->socket = -1; ssl_client->socket = lwip_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); @@ -56,7 +59,8 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p struct hostent *server; server = gethostbyname(host); if (server == NULL) { - return 0; + log_e("gethostbyname failed"); + return -1; } IPAddress srv((const uint8_t *)(server->h_addr)); @@ -79,7 +83,7 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p fcntl( ssl_client->socket, F_SETFL, fcntl( ssl_client->socket, F_GETFL, 0 ) | O_NONBLOCK ); - log_i("Seeding the random number generator"); + log_v("Seeding the random number generator"); mbedtls_entropy_init(&ssl_client->entropy_ctx); ret = mbedtls_ctr_drbg_seed(&ssl_client->drbg_ctx, mbedtls_entropy_func, @@ -88,7 +92,7 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p return handle_error(ret); } - log_i("Setting up the SSL/TLS structure..."); + log_v("Setting up the SSL/TLS structure..."); if ((ret = mbedtls_ssl_config_defaults(&ssl_client->ssl_conf, MBEDTLS_SSL_IS_CLIENT, @@ -101,7 +105,7 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p // MBEDTLS_SSL_VERIFY_NONE if not. if (rootCABuff != NULL) { - log_i("Loading CA cert"); + log_v("Loading CA cert"); mbedtls_x509_crt_init(&ssl_client->ca_cert); mbedtls_ssl_conf_authmode(&ssl_client->ssl_conf, MBEDTLS_SSL_VERIFY_REQUIRED); ret = mbedtls_x509_crt_parse(&ssl_client->ca_cert, (const unsigned char *)rootCABuff, strlen(rootCABuff) + 1); @@ -119,14 +123,14 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p mbedtls_x509_crt_init(&ssl_client->client_cert); mbedtls_pk_init(&ssl_client->client_key); - log_i("Loading CRT cert"); + log_v("Loading CRT cert"); ret = mbedtls_x509_crt_parse(&ssl_client->client_cert, (const unsigned char *)cli_cert, strlen(cli_cert) + 1); if (ret < 0) { return handle_error(ret); } - log_i("Loading private key"); + log_v("Loading private key"); ret = mbedtls_pk_parse_key(&ssl_client->client_key, (const unsigned char *)cli_key, strlen(cli_key) + 1, NULL, 0); if (ret != 0) { @@ -136,7 +140,7 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p mbedtls_ssl_conf_own_cert(&ssl_client->ssl_conf, &ssl_client->client_cert, &ssl_client->client_key); } - log_i("Setting hostname for TLS session..."); + log_v("Setting hostname for TLS session..."); // Hostname set here should match CN in server certificate if((ret = mbedtls_ssl_set_hostname(&ssl_client->ssl_ctx, host)) != 0){ @@ -151,7 +155,7 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p mbedtls_ssl_set_bio(&ssl_client->ssl_ctx, &ssl_client->socket, mbedtls_net_send, mbedtls_net_recv, NULL ); - log_i("Performing the SSL/TLS handshake..."); + log_v("Performing the SSL/TLS handshake..."); while ((ret = mbedtls_ssl_handshake(&ssl_client->ssl_ctx)) != 0) { if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) { @@ -161,25 +165,24 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p if (cli_cert != NULL && cli_key != NULL) { - log_i("Protocol is %s Ciphersuite is %s", mbedtls_ssl_get_version(&ssl_client->ssl_ctx), mbedtls_ssl_get_ciphersuite(&ssl_client->ssl_ctx)); + log_d("Protocol is %s Ciphersuite is %s", mbedtls_ssl_get_version(&ssl_client->ssl_ctx), mbedtls_ssl_get_ciphersuite(&ssl_client->ssl_ctx)); if ((ret = mbedtls_ssl_get_record_expansion(&ssl_client->ssl_ctx)) >= 0) { - log_i("Record expansion is %d", ret); + log_d("Record expansion is %d", ret); } else { - log_i("Record expansion is unknown (compression)"); + log_w("Record expansion is unknown (compression)"); } } - log_i("Verifying peer X.509 certificate..."); + log_v("Verifying peer X.509 certificate..."); if ((flags = mbedtls_ssl_get_verify_result(&ssl_client->ssl_ctx)) != 0) { - log_e("Failed to verify peer certificate!"); bzero(buf, sizeof(buf)); mbedtls_x509_crt_verify_info(buf, sizeof(buf), " ! ", flags); - log_e("verification info: %s", buf); + log_e("Failed to verify peer certificate! verification info: %s", buf); stop_ssl_socket(ssl_client, rootCABuff, cli_cert, cli_key); //It's not safe continue. return handle_error(ret); } else { - log_i("Certificate verified."); + log_v("Certificate verified."); } if (rootCABuff != NULL) { @@ -194,7 +197,7 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p mbedtls_pk_free(&ssl_client->client_key); } - log_i("Free heap after TLS %u", xPortGetFreeHeapSize()); + log_v("Free heap after TLS %u", xPortGetFreeHeapSize()); return ssl_client->socket; } @@ -202,7 +205,7 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p void stop_ssl_socket(sslclient_context *ssl_client, const char *rootCABuff, const char *cli_cert, const char *cli_key) { - log_i("Cleaning SSL connection."); + log_v("Cleaning SSL connection."); if (ssl_client->socket >= 0) { close(ssl_client->socket); @@ -233,7 +236,7 @@ int data_to_read(sslclient_context *ssl_client) int send_ssl_data(sslclient_context *ssl_client, const uint8_t *data, uint16_t len) { - //log_i("Writing HTTP request..."); //for low level debug + log_v("Writing HTTP request..."); //for low level debug int ret = -1; while ((ret = mbedtls_ssl_write(&ssl_client->ssl_ctx, data, len)) <= 0) { @@ -243,18 +246,18 @@ int send_ssl_data(sslclient_context *ssl_client, const uint8_t *data, uint16_t l } len = ret; - //log_i("%d bytes written", len); //for low level debug + //log_v("%d bytes written", len); //for low level debug return ret; } int get_ssl_receive(sslclient_context *ssl_client, uint8_t *data, int length) { - //log_i( "Reading HTTP response..."); //for low level debug + //log_d( "Reading HTTP response..."); //for low level debug int ret = -1; ret = mbedtls_ssl_read(&ssl_client->ssl_ctx, data, length); - //log_i( "%d bytes readed", ret); //for low level debug + //log_v( "%d bytes read", ret); //for low level debug return ret; } diff --git a/libraries/Wire/src/Wire.cpp b/libraries/Wire/src/Wire.cpp index a3585284426..ba670eaf63a 100644 --- a/libraries/Wire/src/Wire.cpp +++ b/libraries/Wire/src/Wire.cpp @@ -211,4 +211,11 @@ void TwoWire::flush(void) txLength = 0; } +void TwoWire::reset(void) +{ + i2cReset( i2c ); + i2c = NULL; + begin( sda, scl ); +} + TwoWire Wire = TwoWire(0); diff --git a/libraries/Wire/src/Wire.h b/libraries/Wire/src/Wire.h index 39d0ff72759..d9a7a752088 100644 --- a/libraries/Wire/src/Wire.h +++ b/libraries/Wire/src/Wire.h @@ -72,6 +72,8 @@ class TwoWire: public Stream int peek(void); void flush(void); + void reset(void); + inline size_t write(const char * s) { return write((uint8_t*) s, strlen(s)); diff --git a/package/package_esp32_index.template.json b/package/package_esp32_index.template.json index 62cb662b62d..fb1a1f0329e 100644 --- a/package/package_esp32_index.template.json +++ b/package/package_esp32_index.template.json @@ -33,12 +33,17 @@ { "packager": "esp32", "name": "xtensa-esp32-elf-gcc", - "version": "1.22.0-61-gab8375a-5.2.0" + "version": "1.22.0-73-ge28a011-5.2.0" }, { "packager": "esp32", "name": "esptool", - "version": "a420774" + "version": "4dab24e" + }, + { + "packager": "esp32", + "name": "mkspiffs", + "version": "0.2.1" } ] } @@ -46,55 +51,103 @@ "tools": [ { "name": "xtensa-esp32-elf-gcc", - "version": "1.22.0-61-gab8375a-5.2.0", + "version": "1.22.0-73-ge28a011-5.2.0", "systems": [ { "host": "i686-mingw32", - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-win32-1.22.0-61-gab8375a-5.2.0-2.zip", - "archiveFileName": "xtensa-esp32-elf-win32-1.22.0-61-gab8375a-5.2.0-2.zip", - "checksum": "SHA-256:c00dbdab8e8acc273d4aa319a74f7bb1d9496c843159823201d685359174168f", - "size": "76346909" + "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-win32-1.22.0-73-ge28a011-5.2.0.zip", + "archiveFileName": "xtensa-esp32-elf-win32-1.22.0-73-ge28a011-5.2.0.zip", + "checksum": "SHA-256:97566173909b20567b99ec1b0f5746e341d65961f82fdb760a00937193d03d29", + "size": "78710389" }, { "host": "x86_64-apple-darwin", - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-osx-1.22.0-61-gab8375a-5.2.0.tar.gz", - "archiveFileName": "xtensa-esp32-elf-osx-1.22.0-61-gab8375a-5.2.0.tar.gz", - "checksum": "SHA-256:89a9a6084ec032ddcd4bdae37b428e533ed5fd0c0ab6b66ddf703e4b3f83d6e4", - "size": "40481812" + "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-osx-1.22.0-73-ge28a011-5.2.0.tar.gz", + "archiveFileName": "xtensa-esp32-elf-osx-1.22.0-73-ge28a011-5.2.0.tar.gz", + "checksum": "SHA-256:5eb503462eb7f6a41c0d6c0538b512ab35a0f76ce96514a4e7a6074f6b3ad0d0", + "size": "39903635" }, { "host": "x86_64-pc-linux-gnu", - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz", - "archiveFileName": "xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz", - "checksum": "SHA-256:b74333fd7f622f035fee7c4e0ca57c3e2ccb2515de5d901f33e87e79cdf0d4f9", - "size": "37674568" + "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-73-ge28a011-5.2.0.tar.gz", + "archiveFileName": "xtensa-esp32-elf-linux64-1.22.0-73-ge28a011-5.2.0.tar.gz", + "checksum": "SHA-256:3763dbed9fd43901c07757622e9c46d29e89eda812b83627df5cb9d019cae0e5", + "size": "37656793" }, { "host": "i686-pc-linux-gnu", - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-linux32-1.22.0-61-gab8375a-5.2.0.tar.gz", - "archiveFileName": "xtensa-esp32-elf-linux32-1.22.0-61-gab8375a-5.2.0.tar.gz", - "checksum": "SHA-256:dbb342b7c377a7c3a1fcccc60fa1193332d0c37e6a90c5075d3471c13c9e94ad", - "size": "41032647" + "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-linux32-1.22.0-73-ge28a011-5.2.0.tar.gz", + "archiveFileName": "xtensa-esp32-elf-linux32-1.22.0-73-ge28a011-5.2.0.tar.gz", + "checksum": "SHA-256:1d8b1dd16223dcb5181af7d713582cf7f22db36c0865d9fcff7b51cfac460641", + "size": "38991614" } ] }, { "name": "esptool", - "version": "a420774", + "version": "4dab24e", "systems": [ { "host": "i686-mingw32", - "url": "https://dl.espressif.com/dl/esptool-a420774-windows.zip", - "archiveFileName": "esptool-a420774-windows.zip", - "checksum": "SHA-256:7778545baa30a85a37a956e47e42a236fa67227f21b160b2164ef83a5e20a41f", - "size": "3394137" + "url": "https://dl.espressif.com/dl/esptool-4dab24e-windows.zip", + "archiveFileName": "esptool-4dab24e-windows.zip", + "checksum": "SHA-256:604014edbd79616470ecda20d623bac3a8d916b1147d37f7a66a83959eff066c", + "size": "3462819" }, { "host": "x86_64-apple-darwin", - "url": "https://dl.espressif.com/dl/esptool-a420774-macos.tar.gz", - "archiveFileName": "esptool-a420774-macos.tar.gz", - "checksum": "SHA-256:1a6237b695fe299357bfd78a9727564464a00e020bc7c7a4cf6fad02250eb2a2", - "size": "3808980" + "url": "https://dl.espressif.com/dl/esptool-4dab24e-macos.tar.gz", + "archiveFileName": "esptool-4dab24e-macos.tar.gz", + "checksum": "SHA-256:92fe2f0505ed93051681bd4d5d766664eacfa32745976dda695c728b529dcc8f", + "size": "3869525" + } + ] + }, + { + "name": "mkspiffs", + "version": "0.2.1", + "systems": [ + { + "host": "i686-mingw32", + "url": "https://github.com/igrr/mkspiffs/releases/download/0.2.1/mkspiffs-0.2.1-windows.zip", + "archiveFileName": "mkspiffs-0.2.1-windows.zip", + "checksum": "SHA-256:baf7b661f8f6128300a33ca20a2158fd9d0bcdad389c4424f913fe3ad08d2dd5", + "size": "347207" + }, + { + "host": "x86_64-apple-darwin", + "url": "https://github.com/igrr/mkspiffs/releases/download/0.2.1/mkspiffs-0.2.1-osx.tar.gz", + "archiveFileName": "mkspiffs-0.2.1-osx.tar.gz", + "checksum": "SHA-256:66e71f20d72fd7c5a75e016b5d88d51793558e68b0e069142dbe8ac1de30a431", + "size": "122716" + }, + { + "host": "i386-apple-darwin", + "url": "https://github.com/igrr/mkspiffs/releases/download/0.2.1/mkspiffs-0.2.1-osx.tar.gz", + "archiveFileName": "mkspiffs-0.2.1-osx.tar.gz", + "checksum": "SHA-256:66e71f20d72fd7c5a75e016b5d88d51793558e68b0e069142dbe8ac1de30a431", + "size": "122716" + }, + { + "host": "x86_64-pc-linux-gnu", + "url": "https://github.com/igrr/mkspiffs/releases/download/0.2.1/mkspiffs-0.2.1-linux64.tar.gz", + "archiveFileName": "mkspiffs-0.2.1-linux64.tar.gz", + "checksum": "SHA-256:cca5e947b4c953d4a2b15bae2cd69e052e20c6ac1975ec5d887596a37a24b41a", + "size": "49281" + }, + { + "host": "i686-pc-linux-gnu", + "url": "https://github.com/igrr/mkspiffs/releases/download/0.2.1/mkspiffs-0.2.1-linux32.tar.gz", + "archiveFileName": "mkspiffs-0.2.1-linux32.tar.gz", + "checksum": "SHA-256:7ac82238f703ec97e2a1c2be65665cff055ad91fccf976ff34a95f63bb80a20a", + "size": "47944" + }, + { + "host": "arm-linux-gnueabihf", + "url": "https://github.com/igrr/mkspiffs/releases/download/0.2.1/mkspiffs-0.2.1-linux-armhf.tar.gz", + "archiveFileName": "mkspiffs-0.2.1-linux-armhf.tar.gz", + "checksum": "SHA-256:2c2ae495502c054919ee03c9222eaf15fbdd3b45410129b5d978eb49845389c0", + "size": "43965" } ] } diff --git a/platform.txt b/platform.txt index 5fdc6e2bf20..201970c4b97 100644 --- a/platform.txt +++ b/platform.txt @@ -3,9 +3,10 @@ version=0.0.1 runtime.tools.xtensa-esp32-elf-gcc.path={runtime.platform.path}/tools/xtensa-esp32-elf -tools.esptool.cmd="{runtime.platform.path}/tools/esptool" -tools.esptool.cmd.linux=python "{runtime.platform.path}/tools/esptool.py" -tools.esptool.cmd.windows="{runtime.platform.path}/tools/esptool.exe" +tools.esptool.path={runtime.platform.path}/tools/esptool +tools.esptool.cmd="{tools.esptool.path}" +tools.esptool.cmd.linux=python "{tools.esptool.path}.py" +tools.esptool.cmd.windows="{tools.esptool.path}.exe" tools.esptool.network_cmd=python "{runtime.platform.path}/tools/espota.py" tools.esptool.network_cmd.windows="{runtime.platform.path}/tools/espota.exe" @@ -27,14 +28,14 @@ compiler.c.cmd=xtensa-esp32-elf-gcc compiler.c.flags=-std=gnu99 -Os -g3 -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -Wpointer-arith {compiler.warning_flags} -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -Wno-old-style-declaration -MMD -c compiler.cpp.cmd=xtensa-esp32-elf-g++ -compiler.cpp.flags=-std=gnu++11 -fno-exceptions -fno-rtti -Os -g3 -Wpointer-arith -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib {compiler.warning_flags} -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -fno-rtti -MMD -c +compiler.cpp.flags=-std=gnu++11 -fno-exceptions -Os -g3 -Wpointer-arith -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib {compiler.warning_flags} -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -fno-rtti -MMD -c compiler.S.cmd=xtensa-esp32-elf-gcc compiler.S.flags=-c -g3 -x assembler-with-cpp -MMD -mlongcalls compiler.c.elf.cmd=xtensa-esp32-elf-gcc -compiler.c.elf.flags=-nostdlib "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" -T esp32_out.ld -T esp32.common.ld -T esp32.rom.ld -T esp32.peripherals.ld -T esp32.rom.spiram_incompatible_fns.ld -u ld_include_panic_highint_hdl -u call_user_start_cpu0 -Wl,--gc-sections -Wl,-static -Wl,--undefined=uxTopUsedPriority -compiler.c.elf.libs=-lgcc -lstdc++ -lapp_trace -lapp_update -lbootloader_support -lbt -lbtdm_app -lc -lc_nano -lcoap -lcoexist -lconsole -lcore -lcxx -ldriver -lesp32 -lesp_adc_cal -lethernet -lexpat -lfatfs -lfreertos -lhal -lheap -ljsmn -ljson -llog -llwip -lm -lmbedtls -lmdns -lmicro-ecc -lnet80211 -lnewlib -lnghttp -lnvs_flash -lopenssl -lphy -lpp -lpthread -lrtc -lsdmmc -lsmartconfig -lsoc -lspi_flash -lspiffs -ltcpip_adapter -lulp -lvfs -lwear_levelling -lwpa -lwpa2 -lwpa_supplicant -lwps -lxtensa-debug-module +compiler.c.elf.flags=-nostdlib "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" -T esp32_out.ld -T esp32.common.ld -T esp32.rom.ld -T esp32.peripherals.ld -T esp32.rom.spiram_incompatible_fns.ld -u ld_include_panic_highint_hdl -u call_user_start_cpu0 -Wl,--gc-sections -Wl,-static -Wl,--undefined=uxTopUsedPriority -u __cxa_guard_dummy +compiler.c.elf.libs=-lgcc -lcxx -lstdc++ -lapp_trace -lapp_update -lbootloader_support -lbt -lbtdm_app -lc -lc_nano -lcoap -lcoexist -lconsole -lcore -ldriver -lesp32 -lesp_adc_cal -lespnow -lethernet -lexpat -lfatfs -lfreertos -lhal -lheap -ljsmn -ljson -llog -llwip -lm -lmbedtls -lmdns -lmicro-ecc -lnet80211 -lnewlib -lnghttp -lnvs_flash -lopenssl -lphy -lpp -lpthread -lrtc -lsdmmc -lsmartconfig -lsoc -lspi_flash -lspiffs -ltcpip_adapter -lulp -lvfs -lwear_levelling -lwpa -lwpa2 -lwpa_supplicant -lwps -lxtensa-debug-module compiler.as.cmd=xtensa-esp32-elf-as diff --git a/tools/gen_esp32part.exe b/tools/gen_esp32part.exe index 6379500de05..c4db89310bc 100644 Binary files a/tools/gen_esp32part.exe and b/tools/gen_esp32part.exe differ diff --git a/tools/gen_esp32part.py b/tools/gen_esp32part.py index 2600ac214db..897e637d079 100755 --- a/tools/gen_esp32part.py +++ b/tools/gen_esp32part.py @@ -51,9 +51,17 @@ def __init__(self): @classmethod def from_csv(cls, csv_contents): res = PartitionTable() - lines = csv_contents.split("\n") + lines = csv_contents.splitlines() + + def expand_vars(f): + f = os.path.expandvars(f) + m = re.match(r'(? 3) + #define BTA_GATTC_CL_MAX GATT_MAX_PHY_CHANNEL +#else + #define BTA_GATTC_CL_MAX 3 // The origin value is 10 +#endif #endif /* max known devices GATTC can support */ @@ -95,7 +95,7 @@ typedef UINT16 tBTA_GATTC_INT_EVT; #endif #define BTA_GATTC_WRITE_PREPARE GATT_WRITE_PREPARE - +#define BTA_GATTC_INVALID_HANDLE 0 /* internal strucutre for GATTC register API */ typedef struct { @@ -125,17 +125,15 @@ typedef tBTA_GATTC_API_OPEN tBTA_GATTC_API_CANCEL_OPEN; typedef struct { BT_HDR hdr; tBTA_GATT_AUTH_REQ auth_req; - tBTA_GATT_SRVC_ID srvc_id; - tBTA_GATT_ID char_id; - tBTA_GATT_ID *p_descr_type; + UINT16 handle; + tBTA_GATTC_EVT cmpl_evt; } tBTA_GATTC_API_READ; typedef struct { BT_HDR hdr; tBTA_GATT_AUTH_REQ auth_req; - tBTA_GATT_SRVC_ID srvc_id; - tBTA_GATT_ID char_id; - tBTA_GATT_ID *p_descr_type; + UINT16 handle; + tBTA_GATTC_EVT cmpl_evt; tBTA_GATTC_WRITE_TYPE write_type; UINT16 offset; UINT16 len; @@ -149,8 +147,7 @@ typedef struct { typedef struct { BT_HDR hdr; - tBTA_GATT_SRVC_ID srvc_id; - tBTA_GATT_ID char_id; + UINT16 handle; } tBTA_GATTC_API_CONFIRM; typedef tGATT_CL_COMPLETE tBTA_GATTC_CMPL; @@ -171,8 +168,9 @@ typedef struct { BT_HDR hdr; tBTA_GATT_AUTH_REQ auth_req; UINT8 num_attr; - tBTA_GATTC_ATTR_ID *p_id_list; -} tBTA_GATTC_API_READ_MULTI; + UINT16 handles[GATT_MAX_READ_MULTI_HANDLES]; + tBTA_GATTC_EVT cmpl_evt; +}tBTA_GATTC_API_READ_MULTI; typedef struct { BT_HDR hdr; @@ -215,9 +213,6 @@ typedef union { tBTA_GATTC_API_READ_MULTI api_read_multi; tBTA_GATTC_API_CFG_MTU api_mtu; tBTA_GATTC_OP_CMPL op_cmpl; - tBTA_GATTC_CI_EVT ci_open; - tBTA_GATTC_CI_EVT ci_save; - tBTA_GATTC_CI_LOAD ci_load; tBTA_GATTC_INT_CONN int_conn; tBTA_GATTC_ENC_CMPL enc_cmpl; @@ -230,43 +225,13 @@ typedef union { /* GATT server cache on the client */ -typedef union { - UINT8 uuid128[LEN_UUID_128]; - UINT16 uuid16; -} tBTA_GATTC_UUID; - -typedef struct gattc_attr_cache { - tBTA_GATTC_UUID *p_uuid; - struct gattc_attr_cache *p_next; - UINT16 uuid_len; - UINT16 attr_handle; - UINT8 inst_id; - tBTA_GATT_CHAR_PROP property; /* if characteristic, it is char property; - if included service, flag primary, - if descriptor, not used */ - tBTA_GATTC_ATTR_TYPE attr_type; -// btla-specific ++ -} __attribute__((packed)) tBTA_GATTC_CACHE_ATTR; -// btla-specific -- - -typedef struct gattc_svc_cache { - tBTA_GATT_SRVC_ID service_uuid; - tBTA_GATTC_CACHE_ATTR *p_attr; - tBTA_GATTC_CACHE_ATTR *p_last_attr; - UINT16 s_handle; - UINT16 e_handle; - struct gattc_svc_cache *p_next; - tBTA_GATTC_CACHE_ATTR *p_cur_char; -// btla-specific ++ -} __attribute__((packed)) tBTA_GATTC_CACHE; -// btla-specific -- - typedef struct { tBT_UUID uuid; UINT16 s_handle; UINT16 e_handle; + // this field is set only for characteristic + UINT16 char_decl_handle; BOOLEAN is_primary; - UINT8 srvc_inst_id; tBTA_GATT_CHAR_PROP property; } tBTA_GATTC_ATTR_REC; @@ -299,11 +264,7 @@ typedef struct { UINT8 state; - tBTA_GATTC_CACHE *p_srvc_cache; - tBTA_GATTC_CACHE *p_cur_srvc; - fixed_queue_t *cache_buffer; /* buffer queue used for storing the cache data */ - UINT8 *p_free; /* starting point to next available byte */ - UINT16 free_byte; /* number of available bytes in server cache buffer */ + list_t *p_srvc_cache; /* list of tBTA_GATTC_SERVICE */ UINT8 update_count; /* indication received */ UINT8 num_clcb; /* number of associated CLCB */ @@ -314,7 +275,7 @@ typedef struct { UINT8 next_avail_idx; UINT8 total_srvc; UINT8 total_char; - + UINT16 total_attr; UINT8 srvc_hdl_chg; /* service handle change indication pending */ UINT16 attr_index; /* cahce NV saving/loading attribute index */ @@ -328,8 +289,8 @@ typedef struct { typedef struct { BOOLEAN in_use; BD_ADDR remote_bda; - tBTA_GATTC_CHAR_ID char_id; -} tBTA_GATTC_NOTIF_REG; + UINT16 handle; +}tBTA_GATTC_NOTIF_REG; typedef struct { tBTA_GATTC_CBACK *p_cback; @@ -403,11 +364,7 @@ typedef struct { tBTA_GATTC_CLCB clcb[BTA_GATTC_CLCB_MAX]; tBTA_GATTC_SERV known_server[BTA_GATTC_KNOWN_SR_MAX]; -#if (SDP_INCLUDED == TRUE) - tSDP_DISCOVERY_DB *p_sdp_db; -#endif ///SDP_INCLUDED == TRUE - UINT16 sdp_conn_id; -} tBTA_GATTC_CB; +}tBTA_GATTC_CB; typedef enum { SERVICE_CHANGE_CCC_WRITTEN_SUCCESS = 0, @@ -474,10 +431,7 @@ extern void bta_gattc_confirm(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); extern void bta_gattc_execute(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); extern void bta_gattc_read_multi(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); extern void bta_gattc_ci_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); -extern void bta_gattc_ci_load(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); extern void bta_gattc_ci_close(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); -extern void bta_gattc_ci_save(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); -extern void bta_gattc_cache_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); extern void bta_gattc_ignore_op_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); extern void bta_gattc_restart_discover(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_msg); extern void bta_gattc_init_bk_conn(tBTA_GATTC_API_OPEN *p_data, tBTA_GATTC_RCB *p_clreg); @@ -509,20 +463,13 @@ extern tBTA_GATTC_CLCB *bta_gattc_find_int_disconn_clcb(tBTA_GATTC_DATA *p_msg); extern BOOLEAN bta_gattc_enqueue(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); -extern UINT16 bta_gattc_id2handle(tBTA_GATTC_SERV *p_srcb, tBTA_GATT_SRVC_ID *p_service_id, tBTA_GATT_ID *p_char_id, tBTA_GATT_ID *p_descr_uuid); -extern BOOLEAN bta_gattc_handle2id(tBTA_GATTC_SERV *p_srcb, UINT16 handle, tBTA_GATT_SRVC_ID *service_id, tBTA_GATT_ID *char_id, tBTA_GATT_ID *p_type); -extern BOOLEAN bta_gattc_uuid_compare (tBT_UUID *p_src, tBT_UUID *p_tar, BOOLEAN is_precise); -extern void bta_gattc_pack_attr_uuid(tBTA_GATTC_CACHE_ATTR *p_attr, tBT_UUID *p_uuid); +extern BOOLEAN bta_gattc_uuid_compare (const tBT_UUID *p_src, const tBT_UUID *p_tar, BOOLEAN is_precise); extern BOOLEAN bta_gattc_check_notif_registry(tBTA_GATTC_RCB *p_clreg, tBTA_GATTC_SERV *p_srcb, tBTA_GATTC_NOTIFY *p_notify); -extern tBTA_GATT_STATUS bta_gattc_pack_read_cb_data(tBTA_GATTC_SERV *p_srcb, tBT_UUID *p_descr_uuid, tGATT_VALUE *p_attr, tBTA_GATT_READ_VAL *p_value); extern BOOLEAN bta_gattc_mark_bg_conn (tBTA_GATTC_IF client_if, BD_ADDR_PTR remote_bda, BOOLEAN add, BOOLEAN is_listen); extern BOOLEAN bta_gattc_check_bg_conn (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, UINT8 role); extern UINT8 bta_gattc_num_reg_app(void); -extern void bta_gattc_clear_notif_registration(UINT16 conn_id); -extern tBTA_GATTC_SERV *bta_gattc_find_srvr_cache(BD_ADDR bda); -extern BOOLEAN bta_gattc_charid_compare(tBTA_GATTC_CHAR_ID *p_src, tBTA_GATTC_CHAR_ID *p_tar); -extern BOOLEAN bta_gattc_srvcid_compare(tBTA_GATT_SRVC_ID *p_src, tBTA_GATT_SRVC_ID *p_tar); -extern void bta_gattc_cpygattid(tBTA_GATT_ID *p_des, tBTA_GATT_ID *p_src); +extern void bta_gattc_clear_notif_registration(tBTA_GATTC_SERV *p_srcb, UINT16 conn_id, UINT16 start_handle, UINT16 end_handle); +extern tBTA_GATTC_SERV * bta_gattc_find_srvr_cache(BD_ADDR bda); /* discovery functions */ extern void bta_gattc_disc_res_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES *p_data); @@ -530,17 +477,41 @@ extern void bta_gattc_disc_cmpl_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type extern tBTA_GATT_STATUS bta_gattc_discover_procedure(UINT16 conn_id, tBTA_GATTC_SERV *p_server_cb, UINT8 disc_type); extern tBTA_GATT_STATUS bta_gattc_discover_pri_service(UINT16 conn_id, tBTA_GATTC_SERV *p_server_cb, UINT8 disc_type); extern void bta_gattc_search_service(tBTA_GATTC_CLCB *p_clcb, tBT_UUID *p_uuid); -extern tBTA_GATT_STATUS bta_gattc_query_cache(UINT16 conn_id, UINT8 query_type, tBTA_GATT_SRVC_ID *p_srvc_id, - tBTA_GATT_ID *p_start_rec, tBT_UUID *p_uuid_cond, - tBTA_GATT_ID *p_output, void *p_param); -extern tBTA_GATT_STATUS bta_gattc_init_cache(tBTA_GATTC_SERV *p_srvc_cb); -extern void bta_gattc_rebuild_cache(tBTA_GATTC_SERV *p_srcv, UINT16 num_attr, tBTA_GATTC_NV_ATTR *p_attr, UINT16 attr_index); -extern BOOLEAN bta_gattc_cache_save(tBTA_GATTC_SERV *p_srvc_cb, UINT16 conn_id); +extern const list_t* bta_gattc_get_services(UINT16 conn_id); +extern const tBTA_GATTC_SERVICE* bta_gattc_get_service_for_handle(UINT16 conn_id, UINT16 handle); +tBTA_GATTC_CHARACTERISTIC* bta_gattc_get_characteristic_srcb(tBTA_GATTC_SERV *p_srcb, UINT16 handle); +extern tBTA_GATTC_CHARACTERISTIC* bta_gattc_get_characteristic(UINT16 conn_id, UINT16 handle); +extern tBTA_GATTC_DESCRIPTOR* bta_gattc_get_descriptor(UINT16 conn_id, UINT16 handle); +extern void bta_gattc_get_db_size_handle(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, int *count); +extern void bta_gattc_get_db_size_with_type_handle(UINT16 conn_id, bt_gatt_db_attribute_type_t type, + UINT16 start_handle, UINT16 end_handle, UINT16 char_handle, int *count); +extern void bta_gattc_get_service_with_uuid(UINT16 conn_id, tBT_UUID *svc_uuid, + btgatt_db_element_t **svc_db, + int *count); + +extern void bta_gattc_get_db_with_opration(UINT16 conn_id, + bt_gatt_get_db_op_t op, + UINT16 char_handle, + tBT_UUID *incl_uuid, + tBT_UUID *char_uuid, + tBT_UUID *descr_uuid, + UINT16 start_handle, UINT16 end_handle, + btgatt_db_element_t **char_db, + int *count); + +extern void bta_gattc_get_gatt_db(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, btgatt_db_element_t **db, int *count); +extern tBTA_GATT_STATUS bta_gattc_init_cache(tBTA_GATTC_SERV *p_srvc_cb); +extern void bta_gattc_rebuild_cache(tBTA_GATTC_SERV *p_srcv, UINT16 num_attr, tBTA_GATTC_NV_ATTR *attr); +extern void bta_gattc_cache_save(tBTA_GATTC_SERV *p_srvc_cb, UINT16 conn_id); +extern void bta_gattc_reset_discover_st(tBTA_GATTC_SERV *p_srcb, tBTA_GATT_STATUS status); extern tBTA_GATTC_CONN *bta_gattc_conn_alloc(BD_ADDR remote_bda); extern tBTA_GATTC_CONN *bta_gattc_conn_find(BD_ADDR remote_bda); extern tBTA_GATTC_CONN *bta_gattc_conn_find_alloc(BD_ADDR remote_bda); extern BOOLEAN bta_gattc_conn_dealloc(BD_ADDR remote_bda); +extern bool bta_gattc_cache_load(tBTA_GATTC_CLCB *p_clcb); +extern void bta_gattc_cache_reset(BD_ADDR server_bda); + #endif /* BTA_GATTC_INT_H */ diff --git a/tools/sdk/include/bluedroid/btc_ble_storage.h b/tools/sdk/include/bluedroid/btc_ble_storage.h index 111f1f0a2b3..0d4d43e7c74 100644 --- a/tools/sdk/include/bluedroid/btc_ble_storage.h +++ b/tools/sdk/include/bluedroid/btc_ble_storage.h @@ -23,52 +23,25 @@ #define BTC_LE_LOCAL_KEY_DHK (1<<2) #define BTC_LE_LOCAL_KEY_ER (1<<3) +#define BTC_BLE_STORAGE_DEV_TYPE_STR "DevType" +#define BTC_BLE_STORAGE_ADDR_TYPE_STR "AddrType" +#define BTC_BLE_STORAGE_LINK_KEY_STR "LinkKey" +#define BTC_BLE_STORAGE_LE_KEY_PENC_STR "LE_KEY_PENC" +#define BTC_BLE_STORAGE_LE_KEY_PID_STR "LE_KEY_PID" +#define BTC_BLE_STORAGE_LE_KEY_PCSRK_STR "LE_KEY_PCSRK" +#define BTC_BLE_STORAGE_LE_KEY_LENC_STR "LE_KEY_LENC" +#define BTC_BLE_STORAGE_LE_KEY_LID_STR "LE_KEY_LID" +#define BTC_BLE_STORAGE_LE_KEY_LCSRK_STR "LE_KEY_LCSRK" + +#define BTC_BLE_STORAGE_LOCAL_ADAPTER_STR "Adapter" +#define BTC_BLE_STORAGE_LE_LOCAL_KEY_IR_STR "LE_LOCAL_KEY_IR" +#define BTC_BLE_STORAGE_LE_LOCAL_KEY_IRK_STR "LE_LOCAL_KEY_IRK" +#define BTC_BLE_STORAGE_LE_LOCAL_KEY_DHK_STR "LE_LOCAL_KEY_DHK" +#define BTC_BLE_STORAGE_LE_LOCAL_KEY_ER_STR "LE_LOCAL_KEY_ER" + /************************************************************************************ ** Local type definitions ************************************************************************************/ -typedef struct -{ - uint32_t num_devices; - bt_bdaddr_t devices[BTM_SEC_MAX_DEVICE_RECORDS]; -} btc_bonded_devices_t; - -typedef struct -{ - bool is_penc_key_rcvd; - tBTM_LE_PENC_KEYS penc_key; /* received peer encryption key */ - bool is_pcsrk_key_rcvd; - tBTM_LE_PCSRK_KEYS pcsrk_key; /* received peer device SRK */ - bool is_pid_key_rcvd; - tBTM_LE_PID_KEYS pid_key; /* peer device ID key */ - bool is_lenc_key_rcvd; - tBTM_LE_LENC_KEYS lenc_key; /* local encryption reproduction keys LTK = = d1(ER,DIV,0)*/ - bool is_lcsrk_key_rcvd; - tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/ - bool is_lidk_key_rcvd; /* local identity key received */ -} btc_dm_ble_cb_t; - -typedef struct -{ - bt_bdaddr_t static_bdaddr; - BD_ADDR bd_addr; - btc_dm_ble_cb_t ble; -} btc_dm_pairing_cb_t; - -typedef struct -{ - uint8_t ir[BT_OCTET16_LEN]; - uint8_t irk[BT_OCTET16_LEN]; - uint8_t dhk[BT_OCTET16_LEN]; -}btc_dm_local_key_id_t; - -typedef struct -{ - bool is_er_rcvd; - uint8_t er[BT_OCTET16_LEN]; - bool is_id_keys_rcvd; - btc_dm_local_key_id_t id_keys; /* ID kyes */ -}btc_dm_local_key_cb_t; - typedef struct { BT_OCTET16 sp_c; @@ -77,63 +50,37 @@ typedef struct } btc_dm_oob_cb_t; -extern btc_dm_pairing_cb_t pairing_cb; -extern btc_dm_local_key_cb_t ble_local_key_cb; -extern btc_bonded_devices_t bonded_devices; +void btc_storage_save(void); -bt_status_t btc_storage_load_bonded_ble_devices(void); - -bt_status_t btc_get_bonded_ble_devices_list(esp_ble_bond_dev_t *bond_dev); +bt_status_t btc_storage_add_ble_bonding_key( bt_bdaddr_t *remote_bd_addr, char *key, uint8_t key_type, uint8_t key_length); -bt_status_t btc_in_fetch_bonded_ble_devices(int add); +bt_status_t btc_storage_get_ble_bonding_key(bt_bdaddr_t *remote_bd_addr, uint8_t key_type, char *key_value, int key_length); -void btc_dm_remove_ble_bonding_keys(void); +bt_status_t btc_storage_remove_ble_bonding_keys(bt_bdaddr_t *remote_bd_addr); -bt_status_t btc_storage_add_ble_bonding_key( bt_bdaddr_t *remote_bd_addr, - char *key, - uint8_t key_type, - uint8_t key_length); +bool btc_storage_compare_address_key_value(bt_bdaddr_t *remote_bd_addr, uint8_t key_type, void *key_value, int key_length); -bool btc_compare_le_key_value(const uint8_t key_type, const size_t key_len, const tBTA_LE_KEY_VALUE *key_vaule, - bt_bdaddr_t bd_addr); +bt_status_t btc_storage_add_ble_local_key(char *key, uint8_t key_type, uint8_t key_length); -void btc_save_ble_bonding_keys(void); +bt_status_t btc_storage_remove_ble_local_keys(void); -bt_status_t btc_in_fetch_bonded_ble_device(const char *remote_bd_addr, int add, - btc_bonded_devices_t *p_bonded_devices); +bt_status_t btc_storage_get_ble_local_key(uint8_t key_type, char *key_value, int key_len); -bt_status_t btc_storage_get_ble_bonding_key(bt_bdaddr_t *remote_bd_addr, - uint8_t key_type, - char *key_value, - int key_length); +bt_status_t btc_storage_get_remote_addr_type(bt_bdaddr_t *remote_bd_addr, int *addr_type); -bool btc_storage_compare_address_key_value(bt_bdaddr_t *remote_bd_addr, - uint8_t key_type, void *key_value, int key_length); -bt_status_t btc_storage_add_ble_local_key(char *key, - uint8_t key_type, - uint8_t key_length); +bt_status_t btc_storage_set_remote_addr_type(bt_bdaddr_t *remote_bd_addr, uint8_t addr_type, bool flush); -bt_status_t btc_storage_remove_ble_bonding_keys(bt_bdaddr_t *remote_bd_addr); +bt_status_t btc_storage_remove_remote_addr_type(bt_bdaddr_t *remote_bd_addr, bool flush); -bt_status_t btc_storage_clear_bond_devices(void); +bt_status_t btc_storage_set_ble_dev_type(bt_bdaddr_t *bd_addr, bool flush); -bt_status_t btc_storage_remove_ble_local_keys(void); +bt_status_t btc_storage_remove_ble_dev_type(bt_bdaddr_t *remote_bd_addr, bool flush); -bt_status_t btc_storage_get_ble_local_key(uint8_t key_type, - char *key_value, - int key_len); +bt_status_t btc_storage_load_bonded_ble_devices(void); -bt_status_t btc_storage_get_remote_addr_type(bt_bdaddr_t *remote_bd_addr, - int *addr_type); +bt_status_t btc_storage_get_bonded_ble_devices_list(esp_ble_bond_dev_t *bond_dev, int dev_num); int btc_storage_get_num_ble_bond_devices(void); -bt_status_t btc_storage_set_remote_addr_type(bt_bdaddr_t *remote_bd_addr, - uint8_t addr_type); - -void btc_dm_load_ble_local_keys(void); - -void btc_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er, - tBTA_BLE_LOCAL_ID_KEYS *p_id_keys); #endif ///SMP_INCLUDED == TRUE -#endif ///__BTC_BLE_STORAGE_H__ \ No newline at end of file +#endif ///__BTC_BLE_STORAGE_H__ diff --git a/tools/sdk/include/bluedroid/btc_config.h b/tools/sdk/include/bluedroid/btc_config.h index 2367c53b40d..79f6137e851 100644 --- a/tools/sdk/include/bluedroid/btc_config.h +++ b/tools/sdk/include/bluedroid/btc_config.h @@ -20,8 +20,6 @@ #include "bt_types.h" -#define BTC_LE_DEV_TYPE "DevType" - typedef struct btc_config_section_iter_t btc_config_section_iter_t; bool btc_config_init(void); @@ -46,7 +44,6 @@ const btc_config_section_iter_t *btc_config_section_end(void); const btc_config_section_iter_t *btc_config_section_next(const btc_config_section_iter_t *section); const char *btc_config_section_name(const btc_config_section_iter_t *section); -void btc_config_save(void); void btc_config_flush(void); int btc_config_clear(void); @@ -55,4 +52,7 @@ bool btc_get_address_type(const BD_ADDR bd_addr, int *p_addr_type); bool btc_compare_address_key_value(const char *section, char *key_type, void *key_value, int key_length); bool btc_get_device_type(const BD_ADDR bd_addr, int *p_device_type); +void btc_config_lock(void); +void btc_config_unlock(void); + #endif diff --git a/tools/sdk/include/bluedroid/btc_dm.h b/tools/sdk/include/bluedroid/btc_dm.h index e397d82b4f7..44f4d84c199 100644 --- a/tools/sdk/include/bluedroid/btc_dm.h +++ b/tools/sdk/include/bluedroid/btc_dm.h @@ -29,6 +29,45 @@ typedef union { tBTA_DM_SEC sec; } btc_dm_sec_args_t; +typedef struct +{ + bool is_penc_key_rcvd; + tBTM_LE_PENC_KEYS penc_key; /* received peer encryption key */ + bool is_pcsrk_key_rcvd; + tBTM_LE_PCSRK_KEYS pcsrk_key; /* received peer device SRK */ + bool is_pid_key_rcvd; + tBTM_LE_PID_KEYS pid_key; /* peer device ID key */ + bool is_lenc_key_rcvd; + tBTM_LE_LENC_KEYS lenc_key; /* local encryption reproduction keys LTK = = d1(ER,DIV,0)*/ + bool is_lcsrk_key_rcvd; + tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/ + bool is_lidk_key_rcvd; /* local identity key received */ +} btc_dm_ble_cb_t; + +typedef struct +{ + bt_bdaddr_t static_bdaddr; + BD_ADDR bd_addr; + btc_dm_ble_cb_t ble; +} btc_dm_pairing_cb_t; + +typedef struct +{ + uint8_t ir[BT_OCTET16_LEN]; + uint8_t irk[BT_OCTET16_LEN]; + uint8_t dhk[BT_OCTET16_LEN]; +} btc_dm_local_key_id_t; + +typedef struct +{ + bool is_er_rcvd; + uint8_t er[BT_OCTET16_LEN]; + bool is_id_keys_rcvd; + btc_dm_local_key_id_t id_keys; /* ID kyes */ +} btc_dm_local_key_cb_t; + + + // void btc_dm_call_handler(btc_msg_t *msg); void btc_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *data); void btc_dm_sec_cb_handler(btc_msg_t *msg); @@ -37,4 +76,11 @@ void btc_dm_sec_arg_deep_copy(btc_msg_t *msg, void *dst, void *src); bt_status_t btc_dm_enable_service(tBTA_SERVICE_ID service_id); bt_status_t btc_dm_disable_service(tBTA_SERVICE_ID service_id); +#if (SMP_INCLUDED == TRUE) +void btc_dm_load_ble_local_keys(void); + +void btc_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er, + tBTA_BLE_LOCAL_ID_KEYS *p_id_keys); +#endif + #endif /* __BTC_DM_H__ */ diff --git a/tools/sdk/include/bluedroid/btc_gap_ble.h b/tools/sdk/include/bluedroid/btc_gap_ble.h index b6da5360650..8074c1b9b42 100644 --- a/tools/sdk/include/bluedroid/btc_gap_ble.h +++ b/tools/sdk/include/bluedroid/btc_gap_ble.h @@ -31,9 +31,12 @@ typedef enum { BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN, BTC_GAP_BLE_ACT_SET_RAND_ADDRESS, BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY, + BTC_GAP_BLE_ACT_UPDATE_WHITE_LIST, + BTC_GAP_BLE_ACT_SET_CONN_PARAMS, BTC_GAP_BLE_ACT_SET_DEV_NAME, BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW, BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW, + BTC_GAP_BLE_ACT_READ_RSSI, BTC_GAP_BLE_SET_ENCRYPTION_EVT, BTC_GAP_BLE_SET_SECURITY_PARAM_EVT, BTC_GAP_BLE_SECURITY_RSP_EVT, @@ -41,8 +44,6 @@ typedef enum { BTC_GAP_BLE_CONFIRM_REPLY_EVT, BTC_GAP_BLE_DISCONNECT_EVT, BTC_GAP_BLE_REMOVE_BOND_DEV_EVT, - BTC_GAP_BLE_CLEAR_BOND_DEV_EVT, - BTC_GAP_BLE_GET_BOND_DEV_EVT, } btc_gap_ble_act_t; /* btc_ble_gap_args_t */ @@ -81,7 +82,25 @@ typedef union { //BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY, struct cfg_local_privacy_args { bool privacy_enable; - } cfg_local_privacy; + } cfg_local_privacy; + //BTC_GAP_BLE_ACT_UPDATE_WHITE_LIST + struct update_white_list_args { + bool add_remove; + esp_bd_addr_t remote_bda; + }update_white_list; + //BTC_GAP_BLE_ACT_SET_CONN_PARAMS + struct set_conn_params_args { + esp_bd_addr_t bd_addr; + uint16_t min_conn_int; + uint16_t max_conn_int; + uint16_t slave_latency; + uint16_t supervision_tout; + }set_conn_params; + //BTC_GAP_BLE_ACT_SET_DEV_NAME, + struct set_dev_name_args { +#define ESP_GAP_DEVICE_NAME_MAX (32) + char device_name[ESP_GAP_DEVICE_NAME_MAX + 1]; + } set_dev_name; //BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW, struct config_adv_data_raw_args { uint8_t *raw_adv; @@ -127,11 +146,15 @@ typedef union { struct remove_bond_device_args { esp_bd_addr_t bd_addr; } remove_bond_device; + //BTC_GAP_BLE_ACT_READ_RSSI + struct read_rssi_args { + esp_bd_addr_t remote_addr; + } read_rssi; } btc_ble_gap_args_t; void btc_gap_ble_call_handler(btc_msg_t *msg); void btc_gap_ble_cb_handler(btc_msg_t *msg); - +void btc_get_whitelist_size(uint16_t *length); void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src); void btc_gap_ble_arg_deep_free(btc_msg_t *msg); void btc_gap_ble_cb_deep_free(btc_msg_t *msg); diff --git a/tools/sdk/include/bluedroid/btc_gattc.h b/tools/sdk/include/bluedroid/btc_gattc.h index d1e0e9680d7..5087e5d2333 100644 --- a/tools/sdk/include/bluedroid/btc_gattc.h +++ b/tools/sdk/include/bluedroid/btc_gattc.h @@ -27,13 +27,8 @@ typedef enum { BTC_GATTC_ACT_CLOSE, BTC_GATTC_ACT_CFG_MTU, BTC_GATTC_ACT_SEARCH_SERVICE, - BTC_GATTC_ACT_GET_FIRST_CHAR, - BTC_GATTC_ACT_GET_NEXT_CHAR, - BTC_GATTC_ACT_GET_FIRST_DESCR, - BTC_GATTC_ACT_GET_NEXT_DESCR, - BTC_GATTC_ACT_GET_FIRST_INCL_SERVICE, - BTC_GATTC_ACT_GET_NEXT_INCL_SERVICE, BTC_GATTC_ACT_READ_CHAR, + BTC_GATTC_ACT_READ_MULTIPLE_CHAR, BTC_GATTC_ACT_READ_CHAR_DESCR, BTC_GATTC_ACT_WRITE_CHAR, BTC_GATTC_ACT_WRITE_CHAR_DESCR, @@ -75,82 +70,67 @@ typedef union { bool filter_uuid_enable; esp_bt_uuid_t filter_uuid; } search_srvc; - //BTC_GATTC_ACT_GET_FIRST_CHAR, - struct get_first_char_arg { + //BTC_GATTC_ACT_GET_CHAR, + struct get_char_arg { uint16_t conn_id; - esp_gatt_srvc_id_t service_id; - } get_first_char; - //BTC_GATTC_ACT_GET_NEXT_CHAR, - struct get_next_char_arg { + uint16_t handle; + } get_char; + //BTC_GATTC_ACT_GET_DESCR, + struct get_descr_arg { uint16_t conn_id; - esp_gatt_srvc_id_t service_id; - esp_gatt_id_t char_id; - } get_next_char; - //BTC_GATTC_ACT_GET_FIRST_DESCR, - struct get_first_descr_arg { - uint16_t conn_id; - esp_gatt_srvc_id_t service_id; - esp_gatt_id_t char_id; - } get_first_descr; - //BTC_GATTC_ACT_GET_NEXT_DESCR, - struct get_next_descr_arg { - uint16_t conn_id; - esp_gatt_srvc_id_t service_id; - esp_gatt_id_t char_id; - esp_gatt_id_t descr_id; - } get_next_descr; + uint16_t handle; + } get_descr; //BTC_GATTC_ACT_GET_FIRST_INCL_SERVICE, struct get_first_incl_srvc_arg { uint16_t conn_id; - esp_gatt_srvc_id_t service_id; + uint16_t handle; } get_first_incl_srvc; //BTC_GATTC_ACT_GET_NEXT_INCL_SERVICE, struct get_next_incl_srvc_arg { uint16_t conn_id; - esp_gatt_srvc_id_t service_id; - esp_gatt_srvc_id_t start_service_id; + uint16_t handle; } get_next_incl_srvc; //BTC_GATTC_ACT_READ_CHAR, struct read_char_arg { uint16_t conn_id; - esp_gatt_srvc_id_t service_id; - esp_gatt_id_t char_id; + uint16_t handle; esp_gatt_auth_req_t auth_req; } read_char; + //BTC_GATTC_ACT_READ_MULTIPLE_CHAR + struct read_multiple_arg { + uint16_t conn_id; + uint8_t num_attr; + uint16_t handles[ESP_GATT_MAX_READ_MULTI_HANDLES]; + esp_gatt_auth_req_t auth_req; + } read_multiple; //BTC_GATTC_ACT_READ_CHAR_DESCR, struct read_descr_arg { uint16_t conn_id; - esp_gatt_srvc_id_t service_id; - esp_gatt_id_t char_id; - esp_gatt_id_t descr_id; + uint16_t handle; esp_gatt_auth_req_t auth_req; } read_descr; //BTC_GATTC_ACT_WRITE_CHAR, struct write_char_arg { uint16_t conn_id; uint16_t value_len; - esp_gatt_srvc_id_t service_id; - esp_gatt_id_t char_id; + uint16_t handle; uint8_t *value; - esp_gatt_write_type_t write_type; + esp_gatt_write_type_t write_type; esp_gatt_auth_req_t auth_req; } write_char; //BTC_GATTC_ACT_WRITE_CHAR_DESCR, struct write_descr_arg { uint16_t conn_id; uint16_t value_len; - esp_gatt_srvc_id_t service_id; - esp_gatt_id_t char_id; - esp_gatt_id_t descr_id; + uint16_t handle; uint8_t *value; - esp_gatt_write_type_t write_type; + esp_gatt_write_type_t write_type; esp_gatt_auth_req_t auth_req; } write_descr; //BTC_GATTC_ACT_PREPARE_WRITE, struct prep_write_arg { uint16_t conn_id; - esp_gatt_srvc_id_t service_id; - esp_gatt_id_t char_id; + uint16_t handle; uint16_t offset; uint16_t value_len; uint8_t *value; @@ -159,9 +139,7 @@ typedef union { //BTC_GATTC_ACT_PREPARE_WRITE_CHAR_DESCR, struct prep_write_descr_arg { uint16_t conn_id; - esp_gatt_srvc_id_t service_id; - esp_gatt_id_t char_id; - esp_gatt_id_t descr_id; + uint16_t handle; uint16_t offset; uint16_t value_len; uint8_t *value; @@ -176,15 +154,13 @@ typedef union { struct reg_for_notify_arg { esp_gatt_if_t gattc_if; esp_bd_addr_t remote_bda; - esp_gatt_srvc_id_t service_id; - esp_gatt_id_t char_id; + uint16_t handle; } reg_for_notify; //BTC_GATTC_ACT_UNREG_FOR_NOTIFY struct unreg_for_notify_arg { esp_gatt_if_t gattc_if; esp_bd_addr_t remote_bda; - esp_gatt_srvc_id_t service_id; - esp_gatt_id_t char_id; + uint16_t handle; } unreg_for_notify; //BTC_GATTC_ACT_CACHE_REFRESH, struct cache_refresh_arg { @@ -195,5 +171,56 @@ typedef union { void btc_gattc_call_handler(btc_msg_t *msg); void btc_gattc_cb_handler(btc_msg_t *msg); void btc_gattc_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src); +esp_gatt_status_t btc_ble_gattc_get_service(uint16_t conn_id, esp_bt_uuid_t *svc_uuid, + esp_gattc_service_elem_t *result, + uint16_t *count, uint16_t offset); +esp_gatt_status_t btc_ble_gattc_get_all_char(uint16_t conn_id, + uint16_t start_handle, + uint16_t end_handle, + esp_gattc_char_elem_t *result, + uint16_t *count, uint16_t offset); +esp_gatt_status_t btc_ble_gattc_get_all_descr(uint16_t conn_id, + uint16_t char_handle, + esp_gattc_descr_elem_t *result, + uint16_t *count, uint16_t offset); +esp_gatt_status_t btc_ble_gattc_get_char_by_uuid(uint16_t conn_id, + uint16_t start_handle, + uint16_t end_handle, + esp_bt_uuid_t char_uuid, + esp_gattc_char_elem_t *result, + uint16_t *count); +esp_gatt_status_t btc_ble_gattc_get_descr_by_uuid(uint16_t conn_id, + uint16_t start_handle, + uint16_t end_handle, + esp_bt_uuid_t char_uuid, + esp_bt_uuid_t descr_uuid, + esp_gattc_descr_elem_t *result, + uint16_t *count); + +esp_gatt_status_t btc_ble_gattc_get_descr_by_char_handle(uint16_t conn_id, + uint16_t char_handle, + esp_bt_uuid_t descr_uuid, + esp_gattc_descr_elem_t *result, + uint16_t *count); + +esp_gatt_status_t btc_ble_gattc_get_include_service(uint16_t conn_id, + uint16_t start_handle, + uint16_t end_handle, + esp_bt_uuid_t *incl_uuid, + esp_gattc_incl_svc_elem_t *result, + uint16_t *count); + +esp_gatt_status_t btc_ble_gattc_get_attr_count(uint16_t conn_id, + esp_gatt_db_attr_type_t type, + uint16_t start_handle, + uint16_t end_handle, + uint16_t char_handle, + uint16_t *count); + +esp_gatt_status_t btc_ble_gattc_get_db(uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, + esp_gattc_db_elem_t *db, uint16_t *count); + + + #endif /* __BTC_GATTC_H__ */ diff --git a/tools/sdk/include/bluedroid/btc_storage.h b/tools/sdk/include/bluedroid/btc_storage.h index c2fb6ccbba5..9e69b4139e8 100644 --- a/tools/sdk/include/bluedroid/btc_storage.h +++ b/tools/sdk/include/bluedroid/btc_storage.h @@ -19,6 +19,12 @@ #include "bt_defs.h" #include "bt_types.h" + +#define BTC_STORAGE_DEV_CLASS_STR "DevClass" +#define BTC_STORAGE_LINK_KEY_STR "LinkKey" /* same as the ble */ +#define BTC_STORAGE_LINK_KEY_TYPE_STR "LinkKeyType" +#define BTC_STORAGE_PIN_LENGTH_STR "PinLength" + /******************************************************************************* ** ** Function btc_storage_add_bonded_device diff --git a/tools/sdk/include/bluedroid/btm_api.h b/tools/sdk/include/bluedroid/btm_api.h index d4ee7b47341..ec27a59638e 100644 --- a/tools/sdk/include/bluedroid/btm_api.h +++ b/tools/sdk/include/bluedroid/btm_api.h @@ -146,6 +146,11 @@ typedef struct { UINT16 supervision_tout; }tBTM_LE_UPDATE_CONN_PRAMS; +typedef enum{ + BTM_WHITELIST_REMOVE = 0X00, + BTM_WHITELIST_ADD = 0X01, +}tBTM_WL_OPERATION; + typedef void (tBTM_DEV_STATUS_CB) (tBTM_DEV_STATUS status); @@ -177,6 +182,8 @@ typedef void (tBTM_UPDATE_CONN_PARAM_CBACK) (UINT8 status, BD_ADDR bd_addr, tBTM typedef void (tBTM_SET_PKT_DATA_LENGTH_CBACK) (UINT8 status, tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS *data_length_params); +typedef void (tBTM_ADD_WHITELIST_CBACK) (UINT8 status, tBTM_WL_OPERATION wl_opration); + typedef void (tBTM_SET_LOCAL_PRIVACY_CBACK) (UINT8 status); @@ -234,7 +241,7 @@ typedef void (tBTM_SET_LOCAL_PRIVACY_CBACK) (UINT8 status); /* inquiry activity mask */ #define BTM_BR_INQ_ACTIVE_MASK (BTM_GENERAL_INQUIRY_ACTIVE|BTM_LIMITED_INQUIRY_ACTIVE|BTM_PERIODIC_INQUIRY_ACTIVE) /* BR/EDR inquiry activity mask */ -#define BTM_BLE_SCAN_ACTIVE_MASK 0xF0 /* LE scan activity mask */ +#define BTM_BLE_SCAN_ACTIVE_MASK 0x01F0 /* LE scan activity mask */ #define BTM_BLE_INQ_ACTIVE_MASK (BTM_LE_GENERAL_INQUIRY_ACTIVE|BTM_LE_LIMITED_INQUIRY_ACTIVE) /* LE inquiry activity mask*/ #define BTM_INQUIRY_ACTIVE_MASK (BTM_BR_INQ_ACTIVE_MASK | BTM_BLE_INQ_ACTIVE_MASK) /* inquiry activity mask */ @@ -2833,6 +2840,11 @@ tBTM_STATUS BTM_ReadRSSI (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb); tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_CMPL_CB *p_cb); +tBTM_STATUS BTM_BleReadAdvTxPower(tBTM_CMPL_CB *p_cb); + +void BTM_BleGetWhiteListSize(uint16_t *length); + + /******************************************************************************* ** ** Function BTM_ReadLinkQuality diff --git a/tools/sdk/include/bluedroid/btm_ble_api.h b/tools/sdk/include/bluedroid/btm_ble_api.h index d23313cb812..fa6c575eac5 100644 --- a/tools/sdk/include/bluedroid/btm_ble_api.h +++ b/tools/sdk/include/bluedroid/btm_ble_api.h @@ -1207,6 +1207,22 @@ tBTM_STATUS BTM_BleWriteScanRspRaw(UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_le tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT32 duration, tBTM_INQ_RESULTS_CB *p_results_cb, tBTM_CMPL_CB *p_cmpl_cb); +/******************************************************************************* +** +** Function BTM_BleScan +** +** Description This procedure keep the device listening for advertising +** events from a broadcast device. +** +** Parameters start: start or stop scan. +** +** Returns void +** +*******************************************************************************/ +//extern +tBTM_STATUS BTM_BleScan(BOOLEAN start, UINT32 duration, + tBTM_INQ_RESULTS_CB *p_results_cb, tBTM_CMPL_CB *p_cmpl_cb); + /******************************************************************************* ** @@ -1695,7 +1711,7 @@ void BTM_BleTurnOnPrivacyOnRemote(BD_ADDR bd_addr, ** *******************************************************************************/ //extern -BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR emote_bda); +BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR emote_bda, tBTM_ADD_WHITELIST_CBACK *add_wl_cb); /******************************************************************************* ** diff --git a/tools/sdk/include/bluedroid/btm_ble_int.h b/tools/sdk/include/bluedroid/btm_ble_int.h index a73a42e76d7..b690db1bb17 100644 --- a/tools/sdk/include/bluedroid/btm_ble_int.h +++ b/tools/sdk/include/bluedroid/btm_ble_int.h @@ -86,13 +86,15 @@ typedef UINT8 tBTM_BLE_SEC_REQ_ACT; #define BTM_BLE_IS_RESOLVE_BDA(x) ((x[0] & BLE_RESOLVE_ADDR_MASK) == BLE_RESOLVE_ADDR_MSB) /* LE scan activity bit mask, continue with LE inquiry bits */ -#define BTM_LE_SELECT_CONN_ACTIVE 0x40 /* selection connection is in progress */ -#define BTM_LE_OBSERVE_ACTIVE 0x80 /* observe is in progress */ +#define BTM_LE_SELECT_CONN_ACTIVE 0x0040 /* selection connection is in progress */ +#define BTM_LE_OBSERVE_ACTIVE 0x0080 /* observe is in progress */ +#define BTM_LE_DISCOVER_ACTIVE 0x0100 /* scan is in progress */ /* BLE scan activity mask checking */ #define BTM_BLE_IS_SCAN_ACTIVE(x) ((x) & BTM_BLE_SCAN_ACTIVE_MASK) #define BTM_BLE_IS_INQ_ACTIVE(x) ((x) & BTM_BLE_INQUIRY_MASK) #define BTM_BLE_IS_OBS_ACTIVE(x) ((x) & BTM_LE_OBSERVE_ACTIVE) +#define BTM_BLE_IS_DISCO_ACTIVE(x) ((x) & BTM_LE_DISCOVER_ACTIVE) #define BTM_BLE_IS_SEL_CONN_ACTIVE(x) ((x) & BTM_LE_SELECT_CONN_ACTIVE) /* BLE ADDR type ID bit */ @@ -136,6 +138,7 @@ typedef struct { typedef struct { UINT16 discoverable_mode; UINT16 connectable_mode; + BOOLEAN scan_params_set; UINT32 scan_window; UINT32 scan_interval; UINT8 scan_type; /* current scan type: active or passive */ @@ -294,7 +297,7 @@ typedef void (tBTM_DATA_LENGTH_CHANGE_CBACK) (UINT16 max_tx_length, UINT16 max_r /* Define BLE Device Management control structure */ typedef struct { - UINT8 scan_activity; /* LE scan activity mask */ + UINT16 scan_activity; /* LE scan activity mask */ /***************************************************** ** BLE Inquiry @@ -306,6 +309,11 @@ typedef struct { tBTM_CMPL_CB *p_obs_cmpl_cb; TIMER_LIST_ENT obs_timer_ent; + /* scan callback and timer */ + tBTM_INQ_RESULTS_CB *p_scan_results_cb; + tBTM_CMPL_CB *p_scan_cmpl_cb; + TIMER_LIST_ENT scan_timer_ent; + /* background connection procedure cb value */ tBTM_BLE_CONN_TYPE bg_conn_type; UINT32 scan_int; @@ -314,6 +322,7 @@ typedef struct { /* white list information */ UINT8 white_list_avail_size; + tBTM_ADD_WHITELIST_CBACK *add_wl_cb; tBTM_BLE_WL_STATE wl_state; fixed_queue_t *conn_pending_q; @@ -357,7 +366,6 @@ tBTM_STATUS btm_ble_start_inquiry (UINT8 mode, UINT8 duration); void btm_ble_stop_scan(void); void btm_clear_all_pending_le_entry(void); -void btm_ble_stop_scan(); BOOLEAN btm_ble_send_extended_scan_params(UINT8 scan_type, UINT32 scan_int, UINT32 scan_win, UINT8 addr_type_own, UINT8 scan_filter_policy); @@ -405,7 +413,7 @@ void btm_ble_update_sec_key_size(BD_ADDR bd_addr, UINT8 enc_key_size); UINT8 btm_ble_read_sec_key_size(BD_ADDR bd_addr); /* white list function */ -BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr); +BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBTM_ADD_WHITELIST_CBACK *add_wl_cb); void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy); void btm_update_adv_filter_policy(tBTM_BLE_AFP adv_policy); void btm_ble_clear_white_list (void); diff --git a/tools/sdk/include/bluedroid/btm_int.h b/tools/sdk/include/bluedroid/btm_int.h index 42468d9586a..1b4cd7259df 100644 --- a/tools/sdk/include/bluedroid/btm_int.h +++ b/tools/sdk/include/bluedroid/btm_int.h @@ -416,6 +416,15 @@ void btm_sco_chk_pend_rolechange (UINT16 hci_handle); ** Define structure for Security Service Record. ** A record exists for each service registered with the Security Manager */ +#define BTM_SEC_OUT_FLAGS (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT | BTM_SEC_OUT_AUTHORIZE) +#define BTM_SEC_IN_FLAGS (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT | BTM_SEC_IN_AUTHORIZE) + +#define BTM_SEC_OUT_LEVEL4_FLAGS (BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_OUT_ENCRYPT | \ + BTM_SEC_OUT_MITM | BTM_SEC_MODE4_LEVEL4) + +#define BTM_SEC_IN_LEVEL4_FLAGS (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT | \ + BTM_SEC_IN_MITM | BTM_SEC_MODE4_LEVEL4) + typedef struct { UINT32 mx_proto_id; /* Service runs over this multiplexer protocol */ UINT32 orig_mx_chan_id; /* Channel on the multiplexer protocol */ @@ -878,6 +887,15 @@ typedef struct{ }tBTM_CallbackFunc; extern tBTM_CallbackFunc conn_param_update_cb; +/* security action for L2CAP COC channels */ +#define BTM_SEC_OK 1 +#define BTM_SEC_ENCRYPT 2 /* encrypt the link with current key */ +#define BTM_SEC_ENCRYPT_NO_MITM 3 /* unauthenticated encryption or better */ +#define BTM_SEC_ENCRYPT_MITM 4 /* authenticated encryption */ +#define BTM_SEC_ENC_PENDING 5 /* wait for link encryption pending */ + +typedef UINT8 tBTM_SEC_ACTION; + /* #ifdef __cplusplus extern "C" @@ -1082,6 +1100,10 @@ BOOLEAN btm_sec_is_a_bonded_dev (BD_ADDR bda); void btm_consolidate_dev(tBTM_SEC_DEV_REC *p_target_rec); BOOLEAN btm_sec_is_le_capable_dev (BD_ADDR bda); BOOLEAN btm_ble_init_pseudo_addr (tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR new_pseudo_addr); +extern BOOLEAN btm_ble_start_sec_check(BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_originator, + tBTM_SEC_CALLBACK *p_callback, void *p_ref_data); +extern tBTM_SEC_SERV_REC *btm_sec_find_first_serv (CONNECTION_TYPE conn_type, UINT16 psm); + #endif /* BLE_INCLUDED */ tINQ_DB_ENT *btm_inq_db_new (BD_ADDR p_bda); diff --git a/tools/sdk/include/bluedroid/btu.h b/tools/sdk/include/bluedroid/btu.h index cc960c59165..862ccec135b 100644 --- a/tools/sdk/include/bluedroid/btu.h +++ b/tools/sdk/include/bluedroid/btu.h @@ -160,9 +160,8 @@ typedef void (*tBTU_EVENT_CALLBACK)(BT_HDR *p_hdr); #define BTU_TTYPE_BLE_GAP_FAST_ADV 106 #define BTU_TTYPE_BLE_OBSERVE 107 - #define BTU_TTYPE_UCD_TO 108 - +#define BTU_TTYPE_BLE_SCAN 109 /* This is the inquiry response information held by BTU, and available diff --git a/tools/sdk/include/bluedroid/esp_bt_defs.h b/tools/sdk/include/bluedroid/esp_bt_defs.h index 513d37ec428..25a2e217b4f 100644 --- a/tools/sdk/include/bluedroid/esp_bt_defs.h +++ b/tools/sdk/include/bluedroid/esp_bt_defs.h @@ -66,8 +66,13 @@ typedef uint8_t esp_link_key[ESP_BT_OCTET16_LEN]; /* Link Key */ /// Default GATT interface id #define ESP_DEFAULT_GATT_IF 0xff -/// Default BLE connection param, if the value doesn't be overwritten -#define ESP_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */ +#define ESP_BLE_CONN_INT_MIN 0x0006 /*!< relate to BTM_BLE_CONN_INT_MIN in btm_ble_api.h */ +#define ESP_BLE_CONN_INT_MAX 0x0C80 /*!< relate to BTM_BLE_CONN_INT_MAX in btm_ble_api.h */ +#define ESP_BLE_CONN_LATENCY_MAX 500 /*!< relate to ESP_BLE_CONN_LATENCY_MAX in btm_ble_api.h */ +#define ESP_BLE_CONN_SUP_TOUT_MIN 0x000A /*!< relate to BTM_BLE_CONN_SUP_TOUT_MIN in btm_ble_api.h */ +#define ESP_BLE_CONN_SUP_TOUT_MAX 0x0C80 /*!< relate to ESP_BLE_CONN_SUP_TOUT_MAX in btm_ble_api.h */ +#define ESP_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */ /* relate to ESP_BLE_CONN_PARAM_UNDEF in btm_ble_api.h */ +#define ESP_BLE_SCAN_PARAM_UNDEF 0xffffffff /* relate to ESP_BLE_SCAN_PARAM_UNDEF in btm_ble_api.h */ /// Check the param is valid or not #define ESP_BLE_IS_VALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF)) diff --git a/tools/sdk/include/bluedroid/esp_gap_ble_api.h b/tools/sdk/include/bluedroid/esp_gap_ble_api.h index a7cafcd35ee..146bb9ec55e 100644 --- a/tools/sdk/include/bluedroid/esp_gap_ble_api.h +++ b/tools/sdk/include/bluedroid/esp_gap_ble_api.h @@ -68,7 +68,6 @@ typedef uint8_t esp_ble_auth_req_t; /*!< combination of the above bit #define ESP_IO_CAP_KBDISP 4 /*!< Keyboard display */ /* relate to BTM_IO_CAP_KBDISP in btm_api.h */ typedef uint8_t esp_ble_io_cap_t; /*!< combination of the io capability */ - /// GAP BLE callback event type typedef enum { ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT = 0, /*!< When advertising data set complete, the event comes */ @@ -97,6 +96,8 @@ typedef enum { ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT, /*!< When remove the bond device complete, the event comes */ ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT, /*!< When clear the bond device clear complete, the event comes */ ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT, /*!< When get the bond device list complete, the event comes */ + ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT, /*!< When read the rssi complete, the event comes */ + ESP_GAP_BLE_ADD_WHITELIST_COMPLETE_EVT, /*!< When add or remove whitelist complete, the event comes */ ESP_GAP_BLE_EVT_MAX, } esp_gap_ble_cb_event_t; @@ -462,6 +463,10 @@ typedef enum { ESP_BLE_EVT_SCAN_RSP = 0x04, /*!< Scan Response (SCAN_RSP) */ } esp_ble_evt_type_t; +typedef enum{ + ESP_BLE_WHITELIST_REMOVE = 0X00, /*!< remove mac from whitelist */ + ESP_BLE_WHITELIST_ADD = 0X01, /*!< add address to whitelist */ +}esp_ble_wl_opration; /** * @brief Gap callback parameters union */ @@ -569,7 +574,7 @@ typedef union { */ struct ble_local_privacy_cmpl_evt_param { esp_bt_status_t status; /*!< Indicate the set local privacy operation success status */ - } local_privacy_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT */ + } local_privacy_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT */ /** * @brief ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT */ @@ -591,6 +596,22 @@ typedef union { uint8_t dev_num; /*!< Indicate the get number device in the bond list */ esp_ble_bond_dev_t *bond_dev; /*!< the pointer to the bond device Structure */ }get_bond_dev_cmpl; /*!< Event parameter of ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT */ + /** + * @brief ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT + */ + struct ble_read_rssi_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicate the read adv tx power operation success status */ + int8_t rssi; /*!< The ble remote device rssi value, the range is from -127 to 20, the unit is dbm, + if the RSSI cannot be read, the RSSI metric shall be set to 127. */ + esp_bd_addr_t remote_addr; /*!< The remote device address */ + } read_rssi_cmpl; /*!< Event parameter of ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT */ + /** + * @brief ESP_GAP_BLE_ADD_WHITELIST_COMPLETE_EVT + */ + struct ble_add_whitelist_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicate the add or remove whitelist operation success status */ + esp_ble_wl_opration wl_opration; /*!< The value is ESP_BLE_WHITELIST_ADD if add address to whitelist operation success, ESP_BLE_WHITELIST_REMOVE if remove address from the whitelist operation success */ + } add_whitelist_cmpl; /*!< Event parameter of ESP_GAP_BLE_ADD_WHITELIST_COMPLETE_EVT */ } esp_ble_gap_cb_param_t; /** @@ -742,6 +763,48 @@ esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr); */ esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable); +/** +* @brief Add or remove device from white list +* +* @param[in] add_remove: the value is true if added the ble device to the white list, and false remove to the white list. +* @param[in] remote_bda: the remote device address add/remove from the white list. +* @return +* - ESP_OK : success +* - other : failed +* +*/ +esp_err_t esp_ble_gap_update_whitelist(bool add_remove, esp_bd_addr_t remote_bda); + +/** +* @brief Get the whitelist size in the controller +* +* @param[out] length: the white list length. +* @return +* - ESP_OK : success +* - other : failed +* +*/ +esp_err_t esp_ble_gap_get_whitelist_size(uint16_t *length); + +/** +* @brief This function is called to set the preferred connection +* parameters when default connection parameter is not desired before connecting. +* This API can only be used in the master role. +* +* @param[in] bd_addr: BD address of the peripheral +* @param[in] min_conn_int: minimum preferred connection interval +* @param[in] max_conn_int: maximum preferred connection interval +* @param[in] slave_latency: preferred slave latency +* @param[in] supervision_tout: preferred supervision timeout +* +* @return +* - ESP_OK : success +* - other : failed +* +*/ +esp_err_t esp_ble_gap_set_prefer_conn_params(esp_bd_addr_t bd_addr, + uint16_t min_conn_int, uint16_t max_conn_int, + uint16_t slave_latency, uint16_t supervision_tout); /** * @brief Set device name to the local device @@ -796,13 +859,26 @@ esp_err_t esp_ble_gap_config_adv_data_raw(uint8_t *raw_data, uint32_t raw_data_l */ esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_data_len); +/** + * @brief This function is called to read the RSSI of remote device. + * The address of link policy results are returned in the gap callback function with + * ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT event. + * + * @param[in] remote_addr : The remote connection device address. + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_gap_read_rssi(esp_bd_addr_t remote_addr); +#if (SMP_INCLUDED == TRUE) /** * @brief Set a GAP security parameter value. Overrides the default value. * -* @param[in] param_type :L the type of the param which to be set +* @param[in] param_type : the type of the param which to be set * @param[in] value : the param value -* @param[out] len : the length of the param value +* @param[in] len : the length of the param value * * @return - ESP_OK : success * - other : failed @@ -879,27 +955,41 @@ esp_err_t esp_ble_confirm_reply(esp_bd_addr_t bd_addr, bool accept); esp_err_t esp_ble_remove_bond_device(esp_bd_addr_t bd_addr); /** -* @brief Removes all of the device from the security database list of -* peer device. It manages unpairing event while connected. +* @brief Get the device number from the security database list of peer device. +* It will return the device bonded number immediately. * -* @return - ESP_OK : success -* - other : failed +* @return - >= 0 : bonded devices number. +* - < 0 : failed * */ -esp_err_t esp_ble_clear_bond_device_list(void); +int esp_ble_get_bond_device_num(void); + /** * @brief Get the device from the security database list of peer device. -* It will return the device bonded information from the ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT event. +* It will return the device bonded information immediately. +* @param[inout] dev_num: Indicate the dev_list array(buffer) size as input. +* If dev_num is large enough, it means the actual number as output. +* Suggest that dev_num value equal to esp_ble_get_bond_device_num(). * -* @return - ESP_OK : success -* - other : failed +* @param[out] dev_list: an array(buffer) of `esp_ble_bond_dev_t` type. Use for storing the bonded devices address. +* The dev_list should be allocated by who call this API. +* @return - ESP_OK : success +* - other : failed * */ -esp_err_t esp_ble_get_bond_device_list(void); +esp_err_t esp_ble_get_bond_device_list(int *dev_num, esp_ble_bond_dev_t *dev_list); + +#endif /* #if (SMP_INCLUDED == TRUE) */ /** * @brief This function is to disconnect the physical connection of the peer device +* gattc maybe have multiple virtual GATT server connections when multiple app_id registed. +* esp_ble_gattc_close (esp_gatt_if_t gattc_if, uint16_t conn_id) only close one virtual GATT server connection. +* if there exist other virtual GATT server connections, it does not disconnect the physical connection. +* esp_ble_gap_disconnect(esp_bd_addr_t remote_device) disconnect the physical connection directly. +* +* * * @param[in] remote_device : BD address of the peer device * diff --git a/tools/sdk/include/bluedroid/esp_gatt_defs.h b/tools/sdk/include/bluedroid/esp_gatt_defs.h index d0f73dd32cd..a98069eadb5 100644 --- a/tools/sdk/include/bluedroid/esp_gatt_defs.h +++ b/tools/sdk/include/bluedroid/esp_gatt_defs.h @@ -27,6 +27,7 @@ extern "C" { #define ESP_GATT_ILLEGAL_HANDLE 0 /// GATT attribute max handle #define ESP_GATT_ATTR_HANDLE_MAX 100 +#define ESP_GATT_MAX_READ_MULTI_HANDLES 10 /* Max attributes to read in one request */ /**@{ @@ -294,12 +295,12 @@ typedef uint8_t esp_gatt_char_prop_t; */ typedef struct { - uint16_t uuid_length; /*!< UUID length */ - uint8_t *uuid_p; /*!< UUID value */ - uint16_t perm; /*!< Attribute permission */ - uint16_t max_length; /*!< Maximum length of the element*/ - uint16_t length; /*!< Current length of the element*/ - uint8_t *value; /*!< Element value array*/ + uint16_t uuid_length; /*!< UUID length */ + uint8_t *uuid_p; /*!< UUID value */ + uint16_t perm; /*!< Attribute permission */ + uint16_t max_length; /*!< Maximum length of the element*/ + uint16_t length; /*!< Current length of the element*/ + uint8_t *value; /*!< Element value array*/ } esp_attr_desc_t; @@ -313,8 +314,8 @@ typedef struct /** * @brief if auto_rsp set to ESP_GATT_RSP_BY_APP, means the response of Write/Read operation will by replied by application. if auto_rsp set to ESP_GATT_AUTO_RSP, means the response of Write/Read operation will be replied by GATT stack automatically. - */ - uint8_t auto_rsp; + */ + uint8_t auto_rsp; } esp_attr_control_t; @@ -323,8 +324,8 @@ typedef struct */ typedef struct { - esp_attr_control_t attr_control; /*!< The attribute control type*/ - esp_attr_desc_t att_desc; /*!< The attribute type*/ + esp_attr_control_t attr_control; /*!< The attribute control type */ + esp_attr_desc_t att_desc; /*!< The attribute type */ } esp_gatts_attr_db_t; @@ -333,9 +334,9 @@ typedef struct */ typedef struct { - uint16_t attr_max_len; /*!< attribute max value length */ - uint16_t attr_len; /*!< attribute current value length */ - uint8_t *attr_value; /*!< the pointer to attribute value */ + uint16_t attr_max_len; /*!< attribute max value length */ + uint16_t attr_len; /*!< attribute current value length */ + uint8_t *attr_value; /*!< the pointer to attribute value */ } esp_attr_value_t; @@ -344,22 +345,19 @@ typedef struct */ typedef struct { - uint16_t start_hdl; /*!< Gatt start handle value of included service */ - uint16_t end_hdl; /*!< Gatt end handle value of included service */ - uint16_t uuid; /*!< Gatt attribute value UUID of included service */ -} esp_gatts_incl_svc_desc_t; /*!< Gatt include service entry element */ + uint16_t start_hdl; /*!< Gatt start handle value of included service */ + uint16_t end_hdl; /*!< Gatt end handle value of included service */ + uint16_t uuid; /*!< Gatt attribute value UUID of included service */ +} esp_gatts_incl_svc_desc_t; /*!< Gatt include service entry element */ /** * @brief Gatt include 128 bit service entry element */ typedef struct { - uint16_t start_hdl; /*!< Gatt start handle value of included 128 bit service */ - uint16_t end_hdl; /*!< Gatt end handle value of included 128 bit service */ -} esp_gatts_incl128_svc_desc_t; /*!< Gatt include 128 bit service entry element */ - - - + uint16_t start_hdl; /*!< Gatt start handle value of included 128 bit service */ + uint16_t end_hdl; /*!< Gatt end handle value of included 128 bit service */ +} esp_gatts_incl128_svc_desc_t; /*!< Gatt include 128 bit service entry element */ /// Gatt attribute value typedef struct { @@ -388,6 +386,75 @@ typedef enum { typedef uint8_t esp_gatt_if_t; /*!< Gatt interface type, different application on GATT client use different gatt_if */ +/** + * @brief the type of attribute element + */ +typedef enum { + ESP_GATT_DB_PRIMARY_SERVICE, /*!< Gattc primary service attribute type in the cache */ + ESP_GATT_DB_SECONDARY_SERVICE, /*!< Gattc secondary service attribute type in the cache */ + ESP_GATT_DB_CHARACTERISTIC, /*!< Gattc characteristic attribute type in the cache */ + ESP_GATT_DB_DESCRIPTOR, /*!< Gattc characteristic descriptor attribute type in the cache */ + ESP_GATT_DB_INCLUDED_SERVICE, /*!< Gattc include service attribute type in the cache */ + ESP_GATT_DB_ALL, /*!< Gattc all the attribute (primary service & secondary service & include service & char & descriptor) type in the cache */ +} esp_gatt_db_attr_type_t; /*!< Gattc attribute type element */ + +/** + * @brief read multiple attribute + */ +typedef struct { + uint8_t num_attr; /*!< The number of the attribute */ + uint16_t handles[ESP_GATT_MAX_READ_MULTI_HANDLES]; /*!< The handles list */ +} esp_gattc_multi_t; /*!< The gattc multiple read element */ + +/** + * @brief data base attribute element + */ +typedef struct { + esp_gatt_db_attr_type_t type; /*!< The attribute type */ + uint16_t attribute_handle; /*!< The attribute handle, it's valid for all of the type */ + uint16_t start_handle; /*!< The service start handle, it's valid only when the type = ESP_GATT_DB_PRIMARY_SERVICE or ESP_GATT_DB_SECONDARY_SERVICE */ + uint16_t end_handle; /*!< The service end handle, it's valid only when the type = ESP_GATT_DB_PRIMARY_SERVICE or ESP_GATT_DB_SECONDARY_SERVICE */ + esp_gatt_char_prop_t properties; /*!< The characteristic properties, it's valid only when the type = ESP_GATT_DB_CHARACTERISTIC */ + esp_bt_uuid_t uuid; /*!< The attribute uuid, it's valid for all of the type */ +} esp_gattc_db_elem_t; /*!< The gattc service data base element in the cache */ + +/** + * @brief service element + */ +typedef struct { + bool is_primary; /*!< The service flag, ture if the service is primary service, else is secondly service */ + uint16_t start_handle; /*!< The start handle of the service */ + uint16_t end_handle; /*!< The end handle of the service */ + esp_bt_uuid_t uuid; /*!< The uuid of the service */ +} esp_gattc_service_elem_t; /*!< The gattc service element */ + +/** + * @brief characteristic element + */ +typedef struct { + uint16_t char_handle; /*!< The characteristic handle */ + esp_gatt_char_prop_t properties; /*!< The characteristic properties */ + esp_bt_uuid_t uuid; /*!< The characteristic uuid */ +} esp_gattc_char_elem_t; /*!< The gattc characteristic element */ + +/** + * @brief descriptor element + */ +typedef struct { + uint16_t handle; /*!< The characteristic descriptor handle */ + esp_bt_uuid_t uuid; /*!< The characteristic descriptor uuid */ +} esp_gattc_descr_elem_t; /*!< The gattc descriptor type element */ + +/** + * @brief include service element + */ +typedef struct { + uint16_t handle; /*!< The include service current attribute handle */ + uint16_t incl_srvc_s_handle; /*!< The start hanlde of the service which has been included */ + esp_bt_uuid_t uuid; /*!< The include service uuid */ +} esp_gattc_incl_svc_elem_t; /*!< The gattc inclue service element */ + + #ifdef __cplusplus } #endif diff --git a/tools/sdk/include/bluedroid/esp_gattc_api.h b/tools/sdk/include/bluedroid/esp_gattc_api.h index b950d438f08..b72466b82c1 100644 --- a/tools/sdk/include/bluedroid/esp_gattc_api.h +++ b/tools/sdk/include/bluedroid/esp_gattc_api.h @@ -59,13 +59,11 @@ typedef enum { ESP_GATTC_SCAN_FLT_PARAM_EVT = 32, /*!< When Scan filter parameters are set, the event comes */ ESP_GATTC_SCAN_FLT_STATUS_EVT = 33, /*!< When Scan filter status is reported, the event comes */ ESP_GATTC_ADV_VSC_EVT = 34, /*!< When advertising vendor spec content event is reported, the event comes */ - ESP_GATTC_GET_CHAR_EVT = 35, /*!< When characteristic is got from GATT server, the event comes */ - ESP_GATTC_GET_DESCR_EVT = 36, /*!< When characteristic descriptor is got from GATT server, the event comes */ - ESP_GATTC_GET_INCL_SRVC_EVT = 37, /*!< When included service is got from GATT server, the event comes */ ESP_GATTC_REG_FOR_NOTIFY_EVT = 38, /*!< When register for notification of a service completes, the event comes */ ESP_GATTC_UNREG_FOR_NOTIFY_EVT = 39, /*!< When unregister for notification of a service completes, the event comes */ ESP_GATTC_CONNECT_EVT = 40, /*!< When the ble physical connection is set up, the event comes */ ESP_GATTC_DISCONNECT_EVT = 41, /*!< When the ble physical connection disconnected, the event comes */ + ESP_GATTC_READ_MUTIPLE_EVT = 42, /*!< When the ble characteristic or descriptor mutiple complete, the event comes */ } esp_gattc_cb_event_t; @@ -74,57 +72,59 @@ typedef enum { */ typedef union { /** - * @brief ESP_GATTC_REG_EVT - */ - struct gattc_reg_evt_param { - esp_gatt_status_t status; /*!< Operation status */ - uint16_t app_id; /*!< Application id which input in register API */ - } reg; /*!< Gatt client callback param of ESP_GATTC_REG_EVT */ + * @brief ESP_GATTC_REG_EVT + */ + struct gattc_reg_evt_param { + esp_gatt_status_t status; /*!< Operation status */ + uint16_t app_id; /*!< Application id which input in register API */ + } reg; /*!< Gatt client callback param of ESP_GATTC_REG_EVT */ /** * @brief ESP_GATTC_OPEN_EVT */ struct gattc_open_evt_param { - esp_gatt_status_t status; /*!< Operation status */ - uint16_t conn_id; /*!< Connection id */ - esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ - uint16_t mtu; /*!< MTU size */ - } open; /*!< Gatt client callback param of ESP_GATTC_OPEN_EVT */ + esp_gatt_status_t status; /*!< Operation status */ + uint16_t conn_id; /*!< Connection id */ + esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ + uint16_t mtu; /*!< MTU size */ + } open; /*!< Gatt client callback param of ESP_GATTC_OPEN_EVT */ /** * @brief ESP_GATTC_CLOSE_EVT */ struct gattc_close_evt_param { - esp_gatt_status_t status; /*!< Operation status */ - uint16_t conn_id; /*!< Connection id */ - esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ - esp_gatt_conn_reason_t reason; /*!< The reason of gatt connection close */ - } close; /*!< Gatt client callback param of ESP_GATTC_CLOSE_EVT */ + esp_gatt_status_t status; /*!< Operation status */ + uint16_t conn_id; /*!< Connection id */ + esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ + esp_gatt_conn_reason_t reason; /*!< The reason of gatt connection close */ + } close; /*!< Gatt client callback param of ESP_GATTC_CLOSE_EVT */ /** * @brief ESP_GATTC_CFG_MTU_EVT */ struct gattc_cfg_mtu_evt_param { - esp_gatt_status_t status; /*!< Operation status */ - uint16_t conn_id; /*!< Connection id */ - uint16_t mtu; /*!< MTU size */ - } cfg_mtu; /*!< Gatt client callback param of ESP_GATTC_CFG_MTU_EVT */ + esp_gatt_status_t status; /*!< Operation status */ + uint16_t conn_id; /*!< Connection id */ + uint16_t mtu; /*!< MTU size */ + } cfg_mtu; /*!< Gatt client callback param of ESP_GATTC_CFG_MTU_EVT */ /** * @brief ESP_GATTC_SEARCH_CMPL_EVT */ struct gattc_search_cmpl_evt_param { - esp_gatt_status_t status; /*!< Operation status */ - uint16_t conn_id; /*!< Connection id */ - } search_cmpl; /*!< Gatt client callback param of ESP_GATTC_SEARCH_CMPL_EVT */ + esp_gatt_status_t status; /*!< Operation status */ + uint16_t conn_id; /*!< Connection id */ + } search_cmpl; /*!< Gatt client callback param of ESP_GATTC_SEARCH_CMPL_EVT */ /** * @brief ESP_GATTC_SEARCH_RES_EVT */ struct gattc_search_res_evt_param { - uint16_t conn_id; /*!< Connection id */ - esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */ - } search_res; /*!< Gatt client callback param of ESP_GATTC_SEARCH_RES_EVT */ + uint16_t conn_id; /*!< Connection id */ + uint16_t start_handle; /*!< Service start handle */ + uint16_t end_handle; /*!< Service end handle */ + esp_gatt_id_t srvc_id; /*!< Service id, include service uuid and other information */ + } search_res; /*!< Gatt client callback param of ESP_GATTC_SEARCH_RES_EVT */ /** * @brief ESP_GATTC_READ_CHAR_EVT, ESP_GATTC_READ_DESCR_EVT @@ -133,17 +133,8 @@ typedef union { esp_gatt_status_t status; /*!< Operation status */ uint16_t conn_id; /*!< Connection id */ - esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */ - esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */ - esp_gatt_id_t descr_id; /*!< Descriptor id, include descriptor uuid and other information */ + uint16_t handle; /*!< Characteristic handle */ uint8_t *value; /*!< Characteristic value */ - uint16_t value_type; /*!< Characteristic value type, there is two value for this type: - ESP_GATTC_READ_VALUE_TYPE_VALUE(0x0000) and - ESP_GATTC_READ_VALUE_TYPE_AGG_FORMAT(0x2905). - If the value is ESP_GATTC_READ_VALUE_TYPE_VALUE means it is a generally - value type, and if is the type of ESP_GATTC_READ_VALUE_TYPE_AGG_FORMAT, - the unit of the value will indicate in the Characteristic - aggregate format descriptor */ uint16_t value_len; /*!< Characteristic value length */ } read; /*!< Gatt client callback param of ESP_GATTC_READ_CHAR_EVT */ @@ -151,99 +142,60 @@ typedef union { * @brief ESP_GATTC_WRITE_CHAR_EVT, ESP_GATTC_PREP_WRITE_EVT, ESP_GATTC_WRITE_DESCR_EVT */ struct gattc_write_evt_param { - esp_gatt_status_t status; /*!< Operation status */ - uint16_t conn_id; /*!< Connection id */ - esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */ - esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */ - esp_gatt_id_t descr_id; /*!< Descriptor id, include descriptor uuid and other information */ - } write; /*!< Gatt client callback param of ESP_GATTC_WRITE_DESCR_EVT */ + esp_gatt_status_t status; /*!< Operation status */ + uint16_t conn_id; /*!< Connection id */ + uint16_t handle; /*!< The Characteristic or descriptor handle */ + } write; /*!< Gatt client callback param of ESP_GATTC_WRITE_DESCR_EVT */ /** * @brief ESP_GATTC_EXEC_EVT */ struct gattc_exec_cmpl_evt_param { - esp_gatt_status_t status; /*!< Operation status */ - uint16_t conn_id; /*!< Connection id */ - } exec_cmpl; /*!< Gatt client callback param of ESP_GATTC_EXEC_EVT */ + esp_gatt_status_t status; /*!< Operation status */ + uint16_t conn_id; /*!< Connection id */ + } exec_cmpl; /*!< Gatt client callback param of ESP_GATTC_EXEC_EVT */ /** * @brief ESP_GATTC_NOTIFY_EVT */ struct gattc_notify_evt_param { - uint16_t conn_id; /*!< Connection id */ - esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ - esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */ - esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */ - esp_gatt_id_t descr_id; /*!< Descriptor id, include descriptor uuid and other information */ - uint16_t value_len; /*!< Notify attribute value */ - uint8_t *value; /*!< Notify attribute value */ - bool is_notify; /*!< True means notify, false means indicate */ - } notify; /*!< Gatt client callback param of ESP_GATTC_NOTIFY_EVT */ + uint16_t conn_id; /*!< Connection id */ + esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ + uint16_t handle; /*!< The Characteristic or descriptor handle */ + uint16_t value_len; /*!< Notify attribute value */ + uint8_t *value; /*!< Notify attribute value */ + bool is_notify; /*!< True means notify, false means indicate */ + } notify; /*!< Gatt client callback param of ESP_GATTC_NOTIFY_EVT */ /** * @brief ESP_GATTC_SRVC_CHG_EVT */ struct gattc_srvc_chg_evt_param { - esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ - } srvc_chg; /*!< Gatt client callback param of ESP_GATTC_SRVC_CHG_EVT */ + esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ + } srvc_chg; /*!< Gatt client callback param of ESP_GATTC_SRVC_CHG_EVT */ /** * @brief ESP_GATTC_CONGEST_EVT */ struct gattc_congest_evt_param { - uint16_t conn_id; /*!< Connection id */ - bool congested; /*!< Congested or not */ - } congest; /*!< Gatt client callback param of ESP_GATTC_CONGEST_EVT */ - - /** - * @brief ESP_GATTC_GET_CHAR_EVT - */ - struct gattc_get_char_evt_param { - esp_gatt_status_t status; /*!< Operation status */ - uint16_t conn_id; /*!< Connection id */ - esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */ - esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */ - esp_gatt_char_prop_t char_prop; /*!< Characteristic property */ - } get_char; /*!< Gatt client callback param of ESP_GATTC_GET_CHAR_EVT */ - - /** - * @brief ESP_GATTC_GET_DESCR_EVT - */ - struct gattc_get_descr_evt_param { - esp_gatt_status_t status; /*!< Operation status */ - uint16_t conn_id; /*!< Connection id */ - esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */ - esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */ - esp_gatt_id_t descr_id; /*!< Descriptor id, include descriptor uuid and other information */ - } get_descr; /*!< Gatt client callback param of ESP_GATTC_GET_DESCR_EVT */ - - /** - * @brief ESP_GATTC_GET_INCL_SRVC_EVT - */ - struct gattc_get_incl_srvc_evt_param { - esp_gatt_status_t status; /*!< Operation status */ - uint16_t conn_id; /*!< Connection id */ - esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */ - esp_gatt_srvc_id_t incl_srvc_id;/*!< Included service id, include service uuid and other information */ - } get_incl_srvc; /*!< Gatt client callback param of ESP_GATTC_GET_INCL_SRVC_EVT */ - + uint16_t conn_id; /*!< Connection id */ + bool congested; /*!< Congested or not */ + } congest; /*!< Gatt client callback param of ESP_GATTC_CONGEST_EVT */ /** * @brief ESP_GATTC_REG_FOR_NOTIFY_EVT */ struct gattc_reg_for_notify_evt_param { - esp_gatt_status_t status; /*!< Operation status */ - esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */ - esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */ - } reg_for_notify; /*!< Gatt client callback param of ESP_GATTC_REG_FOR_NOTIFY_EVT */ + esp_gatt_status_t status; /*!< Operation status */ + uint16_t handle; /*!< The characteristic or descriptor handle */ + } reg_for_notify; /*!< Gatt client callback param of ESP_GATTC_REG_FOR_NOTIFY_EVT */ - /** + /** * @brief ESP_GATTC_UNREG_FOR_NOTIFY_EVT */ struct gattc_unreg_for_notify_evt_param { - esp_gatt_status_t status; /*!< Operation status */ - esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */ - esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */ - } unreg_for_notify; /*!< Gatt client callback param of ESP_GATTC_UNREG_FOR_NOTIFY_EVT */ + esp_gatt_status_t status; /*!< Operation status */ + uint16_t handle; /*!< The characteristic or descriptor handle */ + } unreg_for_notify; /*!< Gatt client callback param of ESP_GATTC_UNREG_FOR_NOTIFY_EVT */ /** * @brief ESP_GATTC_CONNECT_EVT @@ -263,7 +215,7 @@ typedef union { esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ } disconnect; /*!< Gatt client callback param of ESP_GATTC_DISCONNECT_EVT */ -} esp_ble_gattc_cb_param_t; /*!< GATT client callback parameter union type */ +} esp_ble_gattc_cb_param_t; /*!< GATT client callback parameter union type */ /** * @brief GATT Client callback function type @@ -383,76 +335,233 @@ esp_err_t esp_ble_gattc_send_mtu_req (esp_gatt_if_t gattc_if, uint16_t conn_id); */ esp_err_t esp_ble_gattc_search_service(esp_gatt_if_t gattc_if, uint16_t conn_id, esp_bt_uuid_t *filter_uuid); +/** + * @brief Find all the service with the given service uuid in the gattc cache, if the svc_uuid is NULL, find all the service. + * Note: It just get service from local cache, won't get from remote devices. If want to get it from remote device, need + * to used the esp_ble_gattc_search_service. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id: connection ID which identify the server. + * @param[in] svc_uuid: the pointer to the service uuid. + * @param[out] result: The pointer to the service whith has been found in the gattc cache. + * @param[inout] count: input the number of service want to find, + * it will output the number of service has been found in the gattc cache with the given service uuid. + * @param[in] offset: Offset of the service position to get. + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_gatt_status_t esp_ble_gattc_get_service(esp_gatt_if_t gattc_if, uint16_t conn_id, esp_bt_uuid_t *svc_uuid, + esp_gattc_service_elem_t *result, uint16_t *count, uint16_t offset); /** - * @brief This function is called to find the first characteristic of the - * service on the given server. + * @brief Find all the characteristic with the given service in the gattc cache + * Note: It just get characteristic from local cache, won't get from remote devices. * * @param[in] gattc_if: Gatt client access interface. * @param[in] conn_id: connection ID which identify the server. - * @param[in] srvc_id: service ID - * @param[in] start_char_id: the start characteristic ID + * @param[in] start_handle: the attribute start handle. + * @param[in] end_handle: the attribute end handle + * @param[out] result: The pointer to the charateristic in the service. + * @param[inout] count: input the number of characteristic want to find, + * it will output the number of characteristic has been found in the gattc cache with the given service. + * @param[in] offset: Offset of the characteristic position to get. + * * @return * - ESP_OK: success * - other: failed * */ -esp_err_t esp_ble_gattc_get_characteristic(esp_gatt_if_t gattc_if, - uint16_t conn_id, - esp_gatt_srvc_id_t *srvc_id, - esp_gatt_id_t *start_char_id); +esp_gatt_status_t esp_ble_gattc_get_all_char(esp_gatt_if_t gattc_if, + uint16_t conn_id, + uint16_t start_handle, + uint16_t end_handle, + esp_gattc_char_elem_t *result, + uint16_t *count, uint16_t offset); /** - * @brief This function is called to find the descriptor of the - * service on the given server. + * @brief Find all the descriptor with the given characteristic in the gattc cache + * Note: It just get descriptor from local cache, won't get from remote devices. * * @param[in] gattc_if: Gatt client access interface. * @param[in] conn_id: connection ID which identify the server. - * @param[in] srvc_id: the service ID of which the characteristic is belonged to. - * @param[in] char_id: Characteristic ID, if NULL find the first available - * characteristic. - * @param[in] start_descr_id: the start descriptor id + * @param[in] char_handle: the given characteristic handle + * @param[out] result: The pointer to the descriptor in the characteristic. + * @param[inout] count: input the number of descriptor want to find, + * it will output the number of descriptor has been found in the gattc cache with the given characteristic. + * @param[in] offset: Offset of the descriptor position to get. * * @return * - ESP_OK: success * - other: failed * */ -esp_err_t esp_ble_gattc_get_descriptor(esp_gatt_if_t gattc_if, - uint16_t conn_id, - esp_gatt_srvc_id_t *srvc_id, - esp_gatt_id_t *char_id, - esp_gatt_id_t *start_descr_id); +esp_gatt_status_t esp_ble_gattc_get_all_descr(esp_gatt_if_t gattc_if, + uint16_t conn_id, + uint16_t char_handle, + esp_gattc_descr_elem_t *result, + uint16_t *count, uint16_t offset); /** - * @brief This function is called to find the first characteristic of the - * service on the given server. + * @brief Find the characteristic with the given characteristic uuid in the gattc cache + * Note: It just get characteristic from local cache, won't get from remote devices. * * @param[in] gattc_if: Gatt client access interface. * @param[in] conn_id: connection ID which identify the server. - * @param[in] srvc_id: the service ID of which the characteristic is belonged to. - * @param[in] start_incl_srvc_id: the start include service id + * @param[in] start_handle: the attribute start handle + * @param[in] end_handle: the attribute end handle + * @param[in] char_uuid: the characteristic uuid + * @param[out] result: The pointer to the characteristic in the service. + * @param[inout] count: input the number of characteristic want to find, + * it will output the number of characteristic has been found in the gattc cache with the given service. * * @return * - ESP_OK: success * - other: failed * */ -esp_err_t esp_ble_gattc_get_included_service(esp_gatt_if_t gattc_if, - uint16_t conn_id, - esp_gatt_srvc_id_t *srvc_id, - esp_gatt_srvc_id_t *start_incl_srvc_id); +esp_gatt_status_t esp_ble_gattc_get_char_by_uuid(esp_gatt_if_t gattc_if, + uint16_t conn_id, + uint16_t start_handle, + uint16_t end_handle, + esp_bt_uuid_t char_uuid, + esp_gattc_char_elem_t *result, + uint16_t *count); +/** + * @brief Find the descriptor with the given characteristic uuid in the gattc cache + * Note: It just get descriptor from local cache, won't get from remote devices. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id: connection ID which identify the server. + * @param[in] start_handle: the attribute start handle + * @param[in] end_handle: the attribute end handle + * @param[in] char_uuid: the characteristic uuid. + * @param[in] descr_uuid: the descriptor uuid. + * @param[out] result: The pointer to the descriptor in the given characteristic. + * @param[inout] count: input the number of descriptor want to find, + * it will output the number of descriptor has been found in the gattc cache with the given characteristic. + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_gatt_status_t esp_ble_gattc_get_descr_by_uuid(esp_gatt_if_t gattc_if, + uint16_t conn_id, + uint16_t start_handle, + uint16_t end_handle, + esp_bt_uuid_t char_uuid, + esp_bt_uuid_t descr_uuid, + esp_gattc_descr_elem_t *result, + uint16_t *count); + +/** + * @brief Find the descriptor with the given characteristic handle in the gattc cache + * Note: It just get descriptor from local cache, won't get from remote devices. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id: connection ID which identify the server. + * @param[in] char_handle: the characteristic handle. + * @param[in] descr_uuid: the descriptor uuid. + * @param[out] result: The pointer to the descriptor in the given characteristic. + * @param[inout] count: input the number of descriptor want to find, + * it will output the number of descriptor has been found in the gattc cache with the given characteristic. + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_gatt_status_t esp_ble_gattc_get_descr_by_char_handle(esp_gatt_if_t gattc_if, + uint16_t conn_id, + uint16_t char_handle, + esp_bt_uuid_t descr_uuid, + esp_gattc_descr_elem_t *result, + uint16_t *count); + +/** + * @brief Find the include service with the given service handle in the gattc cache + * Note: It just get include service from local cache, won't get from remote devices. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id: connection ID which identify the server. + * @param[in] start_handle: the attribute start handle + * @param[in] end_handle: the attribute end handle + * @param[in] incl_uuid: the include service uuid + * @param[out] result: The pointer to the include service in the given service. + * @param[inout] count: input the number of include service want to find, + * it will output the number of include service has been found in the gattc cache with the given service. + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_gatt_status_t esp_ble_gattc_get_include_service(esp_gatt_if_t gattc_if, + uint16_t conn_id, + uint16_t start_handle, + uint16_t end_handle, + esp_bt_uuid_t *incl_uuid, + esp_gattc_incl_svc_elem_t *result, + uint16_t *count); + + +/** + * @brief Find the attribute count with the given service or characteristic in the gattc cache + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id: connection ID which identify the server. + * @param[in] type: the attribute type. + * @param[in] start_handle: the attribute start handle, if the type is ESP_GATT_DB_DESCRIPTOR, this parameter should be ignore + * @param[in] end_handle: the attribute end handle, if the type is ESP_GATT_DB_DESCRIPTOR, this parameter should be ignore + * @param[in] char_handle: the characteristic handle, this parameter valid when the type is ESP_GATT_DB_DESCRIPTOR. If the type + * isn't ESP_GATT_DB_DESCRIPTOR, this parameter should be ignore. + * @param[out] count: output the number of attribute has been found in the gattc cache with the given attribute type. + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_gatt_status_t esp_ble_gattc_get_attr_count(esp_gatt_if_t gattc_if, + uint16_t conn_id, + esp_gatt_db_attr_type_t type, + uint16_t start_handle, + uint16_t end_handle, + uint16_t char_handle, + uint16_t *count); + +/** + * @brief This function is called to get the GATT database. + * Note: It just get attribute data base from local cache, won't get from remote devices. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] start_handle: the attribute start handle + * @param[in] end_handle: the attribute end handle + * @param[in] conn_id: connection ID which identify the server. + * @param[in] db: output parameter which will contain the GATT database copy. + * Caller is responsible for freeing it. + * @param[in] count: number of elements in database. + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_gatt_status_t esp_ble_gattc_get_db(esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, + esp_gattc_db_elem_t *db, uint16_t *count); /** * @brief This function is called to read a service's characteristics of - * the given characteristic ID + * the given characteristic handle * * @param[in] gattc_if: Gatt client access interface. * @param[in] conn_id : connection ID. - * @param[in] srvc_id : service ID. - * @param[in] char_id : characteristic ID to read. + * @param[in] handle : characteritic handle to read. * @param[in] auth_req : authenticate request type * * @return @@ -460,11 +569,28 @@ esp_err_t esp_ble_gattc_get_included_service(esp_gatt_if_t gattc_if, * - other: failed * */ -esp_err_t esp_ble_gattc_read_char (esp_gatt_if_t gattc_if, - uint16_t conn_id, - esp_gatt_srvc_id_t *srvc_id, - esp_gatt_id_t *char_id, - esp_gatt_auth_req_t auth_req); +esp_err_t esp_ble_gattc_read_char (esp_gatt_if_t gattc_if, + uint16_t conn_id, + uint16_t handle, + esp_gatt_auth_req_t auth_req); + +/** + * @brief This function is called to read multiple characteristic or + * characteristic descriptors. + * + * @param[in] gattc_if: Gatt client access interface. + * @param[in] conn_id : connection ID. + * @param[in] read_multi : pointer to the read multiple parameter. + * @param[in] auth_req : authenticate request type + * + * @return + * - ESP_OK: success + * - other: failed + * + */ +esp_err_t esp_ble_gattc_read_multiple(esp_gatt_if_t gattc_if, + uint16_t conn_id, esp_gattc_multi_t *read_multi, + esp_gatt_auth_req_t auth_req); /** @@ -472,9 +598,7 @@ esp_err_t esp_ble_gattc_read_char (esp_gatt_if_t gattc_if, * * @param[in] gattc_if: Gatt client access interface. * @param[in] conn_id : connection ID. - * @param[in] srvc_id : service ID. - * @param[in] char_id : characteristic ID to read. - * @param[in] descr_id : characteristic descriptor ID to read. + * @param[in] handle : descriptor handle to read. * @param[in] auth_req : authenticate request type * * @return @@ -483,11 +607,9 @@ esp_err_t esp_ble_gattc_read_char (esp_gatt_if_t gattc_if, * */ esp_err_t esp_ble_gattc_read_char_descr (esp_gatt_if_t gattc_if, - uint16_t conn_id, - esp_gatt_srvc_id_t *srvc_id, - esp_gatt_id_t *char_id, - esp_gatt_id_t *descr_id, - esp_gatt_auth_req_t auth_req); + uint16_t conn_id, + uint16_t handle, + esp_gatt_auth_req_t auth_req); /** @@ -495,8 +617,7 @@ esp_err_t esp_ble_gattc_read_char_descr (esp_gatt_if_t gattc_if, * * @param[in] gattc_if: Gatt client access interface. * @param[in] conn_id : connection ID. - * @param[in] srvc_id : service ID. - * @param[in] char_id : characteristic ID to write. + * @param[in] handle : characteristic handle to write. * @param[in] value_len: length of the value to be written. * @param[in] value : the value to be written. * @param[in] write_type : the type of attribute write operation. @@ -509,11 +630,10 @@ esp_err_t esp_ble_gattc_read_char_descr (esp_gatt_if_t gattc_if, */ esp_err_t esp_ble_gattc_write_char( esp_gatt_if_t gattc_if, uint16_t conn_id, - esp_gatt_srvc_id_t *srvc_id, - esp_gatt_id_t *char_id, + uint16_t handle, uint16_t value_len, uint8_t *value, - esp_gatt_write_type_t write_type, + esp_gatt_write_type_t write_type, esp_gatt_auth_req_t auth_req); @@ -522,9 +642,7 @@ esp_err_t esp_ble_gattc_write_char( esp_gatt_if_t gattc_if, * * @param[in] gattc_if: Gatt client access interface. * @param[in] conn_id : connection ID - * @param[in] srvc_id : service ID. - * @param[in] char_id : characteristic ID. - * @param[in] descr_id : characteristic descriptor ID to write. + * @param[in] handle : descriptor hadle to write. * @param[in] value_len: length of the value to be written. * @param[in] value : the value to be written. * @param[in] write_type : the type of attribute write operation. @@ -537,9 +655,7 @@ esp_err_t esp_ble_gattc_write_char( esp_gatt_if_t gattc_if, */ esp_err_t esp_ble_gattc_write_char_descr (esp_gatt_if_t gattc_if, uint16_t conn_id, - esp_gatt_srvc_id_t *srvc_id, - esp_gatt_id_t *char_id, - esp_gatt_id_t *descr_id, + uint16_t handle, uint16_t value_len, uint8_t *value, esp_gatt_write_type_t write_type, @@ -551,8 +667,7 @@ esp_err_t esp_ble_gattc_write_char_descr (esp_gatt_if_t gattc_if, * * @param[in] gattc_if: Gatt client access interface. * @param[in] conn_id : connection ID. - * @param[in] srvc_id : service ID. - * @param[in] char_id : GATT characteristic ID of the service. + * @param[in] handle : charateristic handle to prepare write. * @param[in] offset : offset of the write value. * @param[in] value_len: length of the value to be written. * @param[in] value : the value to be written. @@ -563,10 +678,9 @@ esp_err_t esp_ble_gattc_write_char_descr (esp_gatt_if_t gattc_if, * - other: failed * */ -esp_err_t esp_ble_gattc_prepare_write(esp_gatt_if_t gattc_if, +esp_err_t esp_ble_gattc_prepare_write(esp_gatt_if_t gattc_if, uint16_t conn_id, - esp_gatt_srvc_id_t *srvc_id, - esp_gatt_id_t *char_id, + uint16_t handle, uint16_t offset, uint16_t value_len, uint8_t *value, @@ -578,9 +692,7 @@ esp_err_t esp_ble_gattc_prepare_write(esp_gatt_if_t gattc_if, * * @param[in] gattc_if: Gatt client access interface. * @param[in] conn_id : connection ID. - * @param[in] srvc_id : service ID. - * @param[in] char_id : GATT characteristic ID of the service. - * @param[in] descr_id : characteristic descriptor ID to write. + * @param[in] handle : characteristic descriptor hanlde to prepare write. * @param[in] offset : offset of the write value. * @param[in] value_len: length of the value to be written. * @param[in] value : the value to be written. @@ -593,9 +705,7 @@ esp_err_t esp_ble_gattc_prepare_write(esp_gatt_if_t gattc_if, */ esp_err_t esp_ble_gattc_prepare_write_char_descr(esp_gatt_if_t gattc_if, uint16_t conn_id, - esp_gatt_srvc_id_t *srvc_id, - esp_gatt_id_t *char_id, - esp_gatt_id_t *descr_id, + uint16_t handle, uint16_t offset, uint16_t value_len, uint8_t *value, @@ -622,8 +732,7 @@ esp_err_t esp_ble_gattc_execute_write (esp_gatt_if_t gattc_if, uint16_t conn_id, * * @param[in] gattc_if: Gatt client access interface. * @param[in] server_bda : target GATT server. - * @param[in] srvc_id : pointer to GATT service ID. - * @param[in] char_id : pointer to GATT characteristic ID. + * @param[in] handle : GATT characteristic handle. * * @return * - ESP_OK: registration succeeds @@ -631,9 +740,8 @@ esp_err_t esp_ble_gattc_execute_write (esp_gatt_if_t gattc_if, uint16_t conn_id, * */ esp_err_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if, - esp_bd_addr_t server_bda, - esp_gatt_srvc_id_t *srvc_id, - esp_gatt_id_t *char_id); + esp_bd_addr_t server_bda, + uint16_t handle); /** @@ -641,8 +749,7 @@ esp_err_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if, * * @param[in] gattc_if: Gatt client access interface. * @param[in] server_bda : target GATT server. - * @param[in] srvc_id : pointer to GATT service ID. - * @param[in] char_id : pointer to GATT characteristic ID. + * @param[in] handle : GATT characteristic handle. * * @return * - ESP_OK: unregister succeeds @@ -650,9 +757,8 @@ esp_err_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if, * */ esp_err_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if, - esp_bd_addr_t server_bda, - esp_gatt_srvc_id_t *srvc_id, - esp_gatt_id_t *char_id); + esp_bd_addr_t server_bda, + uint16_t handle); /** diff --git a/tools/sdk/include/bluedroid/hci_layer.h b/tools/sdk/include/bluedroid/hci_layer.h index 76f93638ad3..5e9b8c695b5 100644 --- a/tools/sdk/include/bluedroid/hci_layer.h +++ b/tools/sdk/include/bluedroid/hci_layer.h @@ -21,7 +21,6 @@ #include "bt_types.h" #include "allocator.h" -#include "fixed_queue.h" #include "osi.h" #include "future.h" ///// LEGACY DEFINITIONS ///// diff --git a/tools/sdk/include/bluedroid/l2c_api.h b/tools/sdk/include/bluedroid/l2c_api.h index e6e7e44f0e4..e2faae41758 100644 --- a/tools/sdk/include/bluedroid/l2c_api.h +++ b/tools/sdk/include/bluedroid/l2c_api.h @@ -124,6 +124,8 @@ typedef UINT8 tL2CAP_CHNL_DATA_RATE; */ #define L2C_INVALID_PSM(psm) (((psm) & 0x0101) != 0x0001) #define L2C_IS_VALID_PSM(psm) (((psm) & 0x0101) == 0x0001) +#define L2C_IS_VALID_LE_PSM(psm) (((psm) > 0x0000) && ((psm) < 0x0100)) + /***************************************************************************** ** Type Definitions @@ -164,6 +166,17 @@ typedef struct { UINT16 flags; /* bit 0: 0-no continuation, 1-continuation */ } tL2CAP_CFG_INFO; +/* Define a structure to hold the configuration parameter for LE L2CAP connection +** oriented channels. +*/ +typedef struct +{ + UINT16 mtu; + UINT16 mps; + UINT16 credits; +} tL2CAP_LE_CFG_INFO; + + /* L2CAP channel configured field bitmap */ #define L2CAP_CH_CFG_MASK_MTU 0x0001 #define L2CAP_CH_CFG_MASK_QOS 0x0002 @@ -486,6 +499,72 @@ extern BOOLEAN L2CA_DisconnectReq (UINT16 cid); extern BOOLEAN L2CA_DisconnectRsp (UINT16 cid); #endif ///CLASSIC_BT_INCLUDED == TRUE +/******************************************************************************* +** +** Function L2CA_RegisterLECoc +** +** Description Other layers call this function to register for L2CAP +** Connection Oriented Channel. +** +** Returns PSM to use or zero if error. Typically, the PSM returned +** is the same as was passed in, but for an outgoing-only +** connection to a dynamic PSM, a "virtual" PSM is returned +** and should be used in the calls to L2CA_ConnectLECocReq() +** and BTM_SetSecurityLevel(). +** +*******************************************************************************/ +extern UINT16 L2CA_RegisterLECoc (UINT16 psm, tL2CAP_APPL_INFO *p_cb_info); + +/******************************************************************************* +** +** Function L2CA_DeregisterLECoc +** +** Description Other layers call this function to deregister for L2CAP +** Connection Oriented Channel. +** +** Returns void +** +*******************************************************************************/ +extern void L2CA_DeregisterLECoc (UINT16 psm); + +/******************************************************************************* +** +** Function L2CA_ConnectLECocReq +** +** Description Higher layers call this function to create an L2CAP LE COC. +** Note that the connection is not established at this time, but +** connection establishment gets started. The callback function +** will be invoked when connection establishes or fails. +** +** Returns the CID of the connection, or 0 if it failed to start +** +*******************************************************************************/ +extern UINT16 L2CA_ConnectLECocReq (UINT16 psm, BD_ADDR p_bd_addr, tL2CAP_LE_CFG_INFO *p_cfg); + +/******************************************************************************* +** +** Function L2CA_ConnectLECocRsp +** +** Description Higher layers call this function to accept an incoming +** L2CAP LE COC connection, for which they had gotten an connect +** indication callback. +** +** Returns TRUE for success, FALSE for failure +** +*******************************************************************************/ +extern BOOLEAN L2CA_ConnectLECocRsp (BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid, UINT16 result, + UINT16 status, tL2CAP_LE_CFG_INFO *p_cfg); + +/******************************************************************************* +** +** Function L2CA_GetPeerLECocConfig +** +** Description Get peers configuration for LE Connection Oriented Channel. +** +** Return value: TRUE if peer is connected +** +*******************************************************************************/ +extern BOOLEAN L2CA_GetPeerLECocConfig (UINT16 lcid, tL2CAP_LE_CFG_INFO* peer_cfg); /******************************************************************************* ** diff --git a/tools/sdk/include/bluedroid/l2c_int.h b/tools/sdk/include/bluedroid/l2c_int.h index ef31d1095ee..44ef74b2848 100644 --- a/tools/sdk/include/bluedroid/l2c_int.h +++ b/tools/sdk/include/bluedroid/l2c_int.h @@ -34,6 +34,17 @@ #define L2CAP_MIN_MTU 48 /* Minimum acceptable MTU is 48 bytes */ +/* LE credit based L2CAP connection parameters */ +#define L2CAP_LE_MIN_MTU 23 +#define L2CAP_LE_MIN_MPS 23 +#define L2CAP_LE_MAX_MPS 65533 +#define L2CAP_LE_MIN_CREDIT 0 +#define L2CAP_LE_MAX_CREDIT 65535 +#define L2CAP_LE_DEFAULT_MTU 512 +#define L2CAP_LE_DEFAULT_MPS 23 +#define L2CAP_LE_DEFAULT_CREDIT 1 + + /* Timeouts. Since L2CAP works off a 1-second list, all are in seconds. */ #define L2CAP_LINK_ROLE_SWITCH_TOUT 10 /* 10 seconds */ @@ -240,6 +251,17 @@ typedef struct { tL2CAP_APPL_INFO api; } tL2C_RCB; +typedef void (tL2CAP_SEC_CBACK) (BD_ADDR bd_addr, tBT_TRANSPORT trasnport, + void *p_ref_data, tBTM_STATUS result); + +typedef struct +{ + UINT16 psm; + tBT_TRANSPORT transport; + BOOLEAN is_originator; + tL2CAP_SEC_CBACK *p_callback; + void *p_ref_data; +}tL2CAP_SEC_DATA; #ifndef L2CAP_CBB_DEFAULT_DATA_RATE_BUFF_QUOTA #define L2CAP_CBB_DEFAULT_DATA_RATE_BUFF_QUOTA 100 @@ -252,6 +274,8 @@ typedef struct { typedef struct t_l2c_ccb { BOOLEAN in_use; /* TRUE when in use, FALSE when not */ tL2C_CHNL_STATE chnl_state; /* Channel state */ + tL2CAP_LE_CFG_INFO local_conn_cfg; /* Our config for ble conn oriented channel */ + tL2CAP_LE_CFG_INFO peer_conn_cfg; /* Peer device config ble conn oriented channel */ struct t_l2c_ccb *p_next_ccb; /* Next CCB in the chain */ struct t_l2c_ccb *p_prev_ccb; /* Previous CCB in the chain */ @@ -400,7 +424,8 @@ typedef struct t_l2c_linkcb { #if (BLE_INCLUDED == TRUE) tBLE_ADDR_TYPE ble_addr_type; UINT16 tx_data_len; /* tx data length used in data length extension */ - + fixed_queue_t *le_sec_pending_q; /* LE coc channels waiting for security check completion */ + UINT8 sec_act; #define L2C_BLE_CONN_UPDATE_DISABLE 0x1 /* disable update connection parameters */ #define L2C_BLE_NEW_CONN_PARAM 0x2 /* new connection parameter to be set */ #define L2C_BLE_UPDATE_PENDING 0x4 /* waiting for connection update finished */ @@ -488,6 +513,7 @@ typedef struct { UINT16 ble_round_robin_quota; /* Round-robin link quota */ UINT16 ble_round_robin_unacked; /* Round-robin unacked */ BOOLEAN ble_check_round_robin; /* Do a round robin check */ + tL2C_RCB ble_rcb_pool[BLE_MAX_L2CAP_CLIENTS]; /* Registration info pool */ #endif tL2CA_ECHO_DATA_CB *p_echo_data_cb; /* Echo data callback */ @@ -632,6 +658,12 @@ BOOLEAN l2c_ucd_process_event(tL2C_CCB *p_ccb, UINT16 event, void *p_data); #if (BLE_INCLUDED == TRUE) extern void l2cu_send_peer_ble_par_req (tL2C_LCB *p_lcb, UINT16 min_int, UINT16 max_int, UINT16 latency, UINT16 timeout); extern void l2cu_send_peer_ble_par_rsp (tL2C_LCB *p_lcb, UINT16 reason, UINT8 rem_id); +extern void l2cu_reject_ble_connection (tL2C_LCB *p_lcb, UINT8 rem_id, UINT16 result); +extern void l2cu_send_peer_ble_credit_based_conn_res (tL2C_CCB *p_ccb, UINT16 result); +extern void l2cu_send_peer_ble_credit_based_conn_req (tL2C_CCB *p_ccb); +extern void l2cu_send_peer_ble_flow_control_credit(tL2C_CCB *p_ccb, UINT16 credit_value); +extern void l2cu_send_peer_ble_credit_based_disconn_req(tL2C_CCB *p_ccb); + #endif extern BOOLEAN l2cu_initialize_fixed_ccb (tL2C_LCB *p_lcb, UINT16 fixed_cid, tL2CAP_FCR_OPTS *p_fcr); @@ -649,6 +681,9 @@ extern void l2cu_send_feature_req (tL2C_CCB *p_ccb); extern tL2C_RCB *l2cu_allocate_rcb (UINT16 psm); extern tL2C_RCB *l2cu_find_rcb_by_psm (UINT16 psm); extern void l2cu_release_rcb (tL2C_RCB *p_rcb); +extern tL2C_RCB *l2cu_allocate_ble_rcb (UINT16 psm); +extern tL2C_RCB *l2cu_find_ble_rcb_by_psm (UINT16 psm); + extern UINT8 l2cu_process_peer_cfg_req (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); extern void l2cu_process_peer_cfg_rsp (tL2C_CCB *p_ccb, tL2CAP_CFG_INFO *p_cfg); @@ -748,6 +783,13 @@ extern void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status, UINT16 UINT16 conn_latency, UINT16 conn_timeout); extern void l2cble_get_conn_param_format_err_from_contoller(UINT8 status, UINT16 handle); +extern void l2cble_credit_based_conn_req (tL2C_CCB *p_ccb); +extern void l2cble_credit_based_conn_res (tL2C_CCB *p_ccb, UINT16 result); +extern void l2cble_send_peer_disc_req(tL2C_CCB *p_ccb); +extern void l2cble_send_flow_control_credit(tL2C_CCB *p_ccb, UINT16 credit_value); +extern BOOLEAN l2ble_sec_access_req(BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_originator, tL2CAP_SEC_CBACK *p_callback, void *p_ref_data); + + #if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE) extern void l2cble_process_rc_param_request_evt(UINT16 handle, UINT16 int_min, UINT16 int_max, UINT16 latency, UINT16 timeout); diff --git a/tools/sdk/include/bluedroid/l2cdefs.h b/tools/sdk/include/bluedroid/l2cdefs.h index db5013a135c..56ddfb0df1c 100644 --- a/tools/sdk/include/bluedroid/l2cdefs.h +++ b/tools/sdk/include/bluedroid/l2cdefs.h @@ -41,6 +41,10 @@ #define L2CAP_CMD_BLE_UPDATE_REQ 0x12 #define L2CAP_CMD_BLE_UPDATE_RSP 0x13 +#define L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ 0x14 +#define L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES 0x15 +#define L2CAP_CMD_BLE_FLOW_CTRL_CREDIT 0x16 + /* Define some packet and header lengths @@ -70,6 +74,11 @@ #define L2CAP_CMD_BLE_UPD_REQ_LEN 8 /* Min and max interval, latency, tout */ #define L2CAP_CMD_BLE_UPD_RSP_LEN 2 /* Result */ +#define L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ_LEN 10 /* LE_PSM, SCID, MTU, MPS, Init Credit */ +#define L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES_LEN 10 /* DCID, MTU, MPS, Init credit, Result */ +#define L2CAP_CMD_BLE_FLOW_CTRL_CREDIT_LEN 4 /* CID, Credit */ + + /* Define the packet boundary flags */ diff --git a/tools/sdk/include/bt/bt.h b/tools/sdk/include/bt/bt.h index e2d7d842ef3..717218bd48f 100644 --- a/tools/sdk/include/bt/bt.h +++ b/tools/sdk/include/bt/bt.h @@ -102,11 +102,10 @@ typedef enum { ESP_BLE_PWR_TYPE_CONN_HDL6 = 6, /*!< For connection handle 6 */ ESP_BLE_PWR_TYPE_CONN_HDL7 = 7, /*!< For connection handle 7 */ ESP_BLE_PWR_TYPE_CONN_HDL8 = 8, /*!< For connection handle 8 */ - ESP_BLE_PWR_TYPE_CONN_HDL9 = 9, /*!< For connection handle 9 */ - ESP_BLE_PWR_TYPE_ADV = 10, /*!< For advertising */ - ESP_BLE_PWR_TYPE_SCAN = 11, /*!< For scan */ - ESP_BLE_PWR_TYPE_DEFAULT = 12, /*!< For default, if not set other, it will use default value */ - ESP_BLE_PWR_TYPE_NUM = 13, /*!< TYPE numbers */ + ESP_BLE_PWR_TYPE_ADV = 9, /*!< For advertising */ + ESP_BLE_PWR_TYPE_SCAN = 10, /*!< For scan */ + ESP_BLE_PWR_TYPE_DEFAULT = 11, /*!< For default, if not set other, it will use default value */ + ESP_BLE_PWR_TYPE_NUM = 12, /*!< TYPE numbers */ } esp_ble_power_type_t; /** @@ -159,20 +158,20 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg); esp_err_t esp_bt_controller_deinit(void); /** - * @brief Enable BT controller + * @brief Enable BT controller. + * Due to a known issue, you cannot call esp_bt_controller_enable() a second time + * to change the controller mode dynamically. To change controller mode, call + * esp_bt_controller_disable() and then call esp_bt_controller_enable() with the new mode. * @param mode : the mode(BLE/BT/BTDM) to enable. - * Now only support BTDM. * @return ESP_OK - success, other - failed */ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode); /** * @brief Disable BT controller - * @param mode : the mode(BLE/BT/BTDM) to disable. - * Now only support BTDM. * @return ESP_OK - success, other - failed */ -esp_err_t esp_bt_controller_disable(esp_bt_mode_t mode); +esp_err_t esp_bt_controller_disable(void); /** * @brief Get BT controller is initialised/de-initialised/enabled/disabled @@ -208,6 +207,36 @@ void esp_vhci_host_send_packet(uint8_t *data, uint16_t len); */ void esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback); +/** @brief esp_bt_controller_mem_release + * release the memory by mode, if never use the bluetooth mode + * it can release the .bbs, .data and other section to heap. + * The total size is about 70k bytes. + * + * If esp_bt_controller_enable(mode) has already been called, calling + * esp_bt_controller_mem_release(ESP_BT_MODE_BTDM) will automatically + * release all memory which is not needed for the currently enabled + * Bluetooth controller mode. + * + * For example, calling esp_bt_controller_enable(ESP_BT_MODE_BLE) then + * esp_bt_controller_mem_release(ESP_BT_MODE_BTDM) will enable BLE modes + * and release memory only used by BT Classic. Also, call esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT) + * is the same. + * + * Note that once BT controller memory is released, the process cannot be reversed. + * If your firmware will later upgrade the Bluetooth controller mode (BLE -> BT Classic or disabled -> enabled) + * then do not call this function. + * + * If user never use bluetooth controller, could call esp_bt_controller_mem_release(ESP_BT_MODE_BTDM) + * before esp_bt_controller_init or after esp_bt_controller_deinit. + * + * For example, user only use bluetooth to config SSID and PASSWORD of WIFI, after config, will never use bluetooth. + * Then, could call esp_bt_controller_mem_release(ESP_BT_MODE_BTDM) after esp_bt_controller_deinit. + * + * @param mode : the mode want to release memory + * @return ESP_OK - success, other - failed + */ +esp_err_t esp_bt_controller_mem_release(esp_bt_mode_t mode); + #ifdef __cplusplus } #endif diff --git a/tools/sdk/include/config/sdkconfig.h b/tools/sdk/include/config/sdkconfig.h index e3d97fab49e..4522d22d205 100644 --- a/tools/sdk/include/config/sdkconfig.h +++ b/tools/sdk/include/config/sdkconfig.h @@ -10,6 +10,7 @@ #define CONFIG_FREERTOS_MAX_TASK_NAME_LEN 16 #define CONFIG_BLE_SMP_ENABLE 1 #define CONFIG_TCP_RECVMBOX_SIZE 6 +#define CONFIG_LWIP_ETHARP_TRUST_IP_MAC 1 #define CONFIG_TCP_WND_DEFAULT 5744 #define CONFIG_SW_COEXIST_ENABLE 1 #define CONFIG_SPIFFS_USE_MAGIC_LENGTH 1 @@ -46,6 +47,7 @@ #define CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED 1 #define CONFIG_CONSOLE_UART_BAUDRATE 115200 #define CONFIG_LWIP_MAX_SOCKETS 10 +#define CONFIG_LWIP_NETIF_LOOPBACK 1 #define CONFIG_EMAC_TASK_PRIORITY 20 #define CONFIG_TIMER_TASK_STACK_DEPTH 2048 #define CONFIG_TCP_MSS 1436 @@ -54,6 +56,7 @@ #define CONFIG_ULP_COPROC_RESERVE_MEM 512 #define CONFIG_ESPTOOLPY_BAUD 921600 #define CONFIG_INT_WDT_CHECK_CPU1 1 +#define CONFIG_FLASHMODE_DIO 1 #define CONFIG_ESPTOOLPY_AFTER_RESET 1 #define CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED 1 #define CONFIG_TOOLPREFIX "xtensa-esp32-elf-" @@ -65,7 +68,6 @@ #define CONFIG_CONSOLE_UART_NUM 0 #define CONFIG_ESP32_APPTRACE_LOCK_ENABLE 1 #define CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC 1 -#define CONFIG_LWIP_THREAD_LOCAL_STORAGE_INDEX 0 #define CONFIG_TCP_OVERSIZE_MSS 1 #define CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS 1 #define CONFIG_CONSOLE_UART_DEFAULT 1 @@ -95,7 +97,6 @@ #define CONFIG_LOG_DEFAULT_LEVEL 1 #define CONFIG_TIMER_QUEUE_LENGTH 10 #define CONFIG_MAKE_WARN_UNDEFINED_VARIABLES 1 -#define CONFIG_BOOTLOADER_SPI_WP_PIN 7 #define CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM 0 #define CONFIG_MBEDTLS_CCM_C 1 #define CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER 20 @@ -104,6 +105,7 @@ #define CONFIG_ESP32_WIFI_NVS_ENABLED 1 #define CONFIG_ULP_COPROC_ENABLED 1 #define CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED 1 +#define CONFIG_LIBSODIUM_USE_MBEDTLS_SHA 1 #define CONFIG_DMA_RX_BUF_NUM 10 #define CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED 1 #define CONFIG_TCP_SYNMAXRTX 6 @@ -118,10 +120,10 @@ #define CONFIG_LWIP_DHCP_MAX_NTP_SERVERS 1 #define CONFIG_TCP_MSL 60000 #define CONFIG_MBEDTLS_SSL_PROTO_TLS1_1 1 +#define CONFIG_LWIP_SO_REUSE_RXTOALL 1 #define CONFIG_PARTITION_TABLE_SINGLE_APP 1 #define CONFIG_ESP32_WIFI_RX_BA_WIN 6 #define CONFIG_MBEDTLS_X509_CSR_PARSE_C 1 -#define CONFIG_FLASHMODE_QIO 1 #define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA 1 #define CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE 2048 #define CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY 2000 @@ -134,6 +136,7 @@ #define CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA 1 #define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM 32 #define CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED 1 +#define CONFIG_ARDUHAL_ESP_LOG 1 #define CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED 1 #define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 240 #define CONFIG_MBEDTLS_HARDWARE_AES 1 @@ -155,6 +158,7 @@ #define CONFIG_SPIFFS_OBJ_NAME_LEN 32 #define CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT 5 #define CONFIG_LOG_BOOTLOADER_LEVEL_NONE 1 +#define CONFIG_TCPIP_RECVMBOX_SIZE 32 #define CONFIG_ESP32_DEFAULT_CPU_FREQ_240 1 #define CONFIG_ESP32_XTAL_FREQ_AUTO 1 #define CONFIG_TCP_MAXRTX 12 @@ -177,7 +181,6 @@ #define CONFIG_MBEDTLS_TLS_SERVER 1 #define CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT 1 #define CONFIG_FREERTOS_ISR_STACKSIZE 1536 -#define CONFIG_CLASSIC_BT_ENABLED 1 #define CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK 1 #define CONFIG_OPENSSL_ASSERT_DO_NOTHING 1 #define CONFIG_WL_SECTOR_SIZE_4096 1 @@ -190,6 +193,7 @@ #define CONFIG_FATFS_MAX_LFN 255 #define CONFIG_ESP32_WIFI_TX_BUFFER_TYPE 1 #define CONFIG_ESPTOOLPY_BAUD_921600B 1 +#define CONFIG_LWIP_LOOPBACK_MAX_PBUFS 8 #define CONFIG_APP_OFFSET 0x10000 #define CONFIG_MEMMAP_SMP 1 #define CONFIG_SPI_FLASH_ROM_DRIVER_PATCH 1 diff --git a/tools/sdk/include/console/esp_console.h b/tools/sdk/include/console/esp_console.h index 17cf5fe7964..bea7eee7281 100644 --- a/tools/sdk/include/console/esp_console.h +++ b/tools/sdk/include/console/esp_console.h @@ -107,6 +107,8 @@ esp_err_t esp_console_cmd_register(const esp_console_cmd_t *cmd); * @param[out] cmd_ret return code from the command (set if command was run) * @return * - ESP_OK, if command was run + * - ESP_ERR_INVALID_ARG, if the command line is empty, or only contained + * whitespace * - ESP_ERR_NOT_FOUND, if command with given name wasn't registered * - ESP_ERR_INVALID_STATE, if esp_console_init wasn't called */ diff --git a/tools/sdk/include/driver/driver/adc.h b/tools/sdk/include/driver/driver/adc.h index 08d32288211..799001ddbbc 100644 --- a/tools/sdk/include/driver/driver/adc.h +++ b/tools/sdk/include/driver/driver/adc.h @@ -20,24 +20,38 @@ extern "C" { #endif #include +#include #include "esp_err.h" #include "driver/gpio.h" #include "soc/adc_channel.h" typedef enum { - ADC_ATTEN_0db = 0, /*!=0) The number of data bytes that pushed to the I2C slave buffer. */ -int i2c_slave_write_buffer(i2c_port_t i2c_num, uint8_t* data, int size, portBASE_TYPE ticks_to_wait); +int i2c_slave_write_buffer(i2c_port_t i2c_num, uint8_t* data, int size, TickType_t ticks_to_wait); /** * @brief I2C slave read data from internal buffer. When I2C slave receive data, isr will copy received data @@ -375,7 +375,7 @@ int i2c_slave_write_buffer(i2c_port_t i2c_num, uint8_t* data, int size, portBASE * - ESP_FAIL(-1) Parameter error * - Others(>=0) The number of data bytes that read from I2C slave buffer. */ -int i2c_slave_read_buffer(i2c_port_t i2c_num, uint8_t* data, size_t max_size, portBASE_TYPE ticks_to_wait); +int i2c_slave_read_buffer(i2c_port_t i2c_num, uint8_t* data, size_t max_size, TickType_t ticks_to_wait); /** * @brief set I2C master clock period @@ -481,6 +481,25 @@ esp_err_t i2c_set_data_timing(i2c_port_t i2c_num, int sample_time, int hold_time */ esp_err_t i2c_get_data_timing(i2c_port_t i2c_num, int* sample_time, int* hold_time); +/** + * @brief set I2C timeout value + * @param i2c_num I2C port number + * @param timeout timeout value for I2C bus (unit: APB 80Mhz clock cycle) + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG Parameter error + */ +esp_err_t i2c_set_timeout(i2c_port_t i2c_num, int timeout); + +/** + * @brief get I2C timeout value + * @param i2c_num I2C port number + * @param timeout pointer to get timeout value + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG Parameter error + */ +esp_err_t i2c_get_timeout(i2c_port_t i2c_num, int* timeout); /** * @brief set I2C data transfer mode * diff --git a/tools/sdk/include/driver/driver/i2s.h b/tools/sdk/include/driver/driver/i2s.h index 5777e34baa3..3644a831f99 100644 --- a/tools/sdk/include/driver/driver/i2s.h +++ b/tools/sdk/include/driver/driver/i2s.h @@ -26,6 +26,7 @@ #include "esp_attr.h" #include "esp_intr_alloc.h" #include "driver/periph_ctrl.h" +#include "driver/adc.h" #include "freertos/semphr.h" #ifdef __cplusplus @@ -118,10 +119,12 @@ typedef enum { I2S_MODE_TX = 4, I2S_MODE_RX = 8, I2S_MODE_DAC_BUILT_IN = 16, /*!< Output I2S data to built-in DAC, no matter the data format is 16bit or 32 bit, the DAC module will only take the 8bits from MSB*/ - //I2S_MODE_ADC_BUILT_IN = 32, /*!< Currently not supported yet, will be added for the next version*/ + I2S_MODE_ADC_BUILT_IN = 32, /*!< Input I2S data from built-in ADC, each data can be 12-bit width at most*/ I2S_MODE_PDM = 64, } i2s_mode_t; + + /** * @brief I2S configuration parameters for i2s_param_config function * @@ -135,6 +138,7 @@ typedef struct { int intr_alloc_flags; /*!< Flags used to allocate the interrupt. One or multiple (ORred) ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info */ int dma_buf_count; /*!< I2S DMA Buffer Count */ int dma_buf_len; /*!< I2S DMA Buffer Length */ + int use_apll; /*!< I2S using APLL as main I2S clock, enable it to get accurate clock */ } i2s_config_t; /** @@ -402,6 +406,17 @@ esp_err_t i2s_zero_dma_buffer(i2s_port_t i2s_num); */ esp_err_t i2s_set_clk(i2s_port_t i2s_num, uint32_t rate, i2s_bits_per_sample_t bits, i2s_channel_t ch); +/** + * @brief Set built-in ADC mode for I2S DMA, this function will initialize ADC pad, + * and set ADC parameters. + * @param adc_unit SAR ADC unit index + * @param adc_channel ADC channel index + * @return + * - ESP_OK Success + * - ESP_FAIL Parameter error + */ +esp_err_t i2s_set_adc_mode(adc_unit_t adc_unit, adc1_channel_t adc_channel); + #ifdef __cplusplus } #endif diff --git a/tools/sdk/include/driver/driver/ledc.h b/tools/sdk/include/driver/driver/ledc.h index 841b1c8d7ad..55c0c8d2ac3 100644 --- a/tools/sdk/include/driver/driver/ledc.h +++ b/tools/sdk/include/driver/driver/ledc.h @@ -26,6 +26,7 @@ extern "C" { #define LEDC_APB_CLK_HZ (APB_CLK_FREQ) #define LEDC_REF_CLK_HZ (1*1000000) +#define LEDC_ERR_DUTY (0xFFFFFFFF) typedef enum { LEDC_HIGH_SPEED_MODE = 0, /*!< LEDC high speed speed_mode */ @@ -206,10 +207,10 @@ esp_err_t ledc_set_duty(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t * @param channel LEDC channel(0-7), select from ledc_channel_t * * @return - * - (-1) parameter error + * - LEDC_ERR_DUTY if parameter error * - Others Current LEDC duty */ -int ledc_get_duty(ledc_mode_t speed_mode, ledc_channel_t channel); +uint32_t ledc_get_duty(ledc_mode_t speed_mode, ledc_channel_t channel); /** * @brief LEDC set gradient @@ -329,7 +330,7 @@ esp_err_t ledc_bind_channel_timer(ledc_mode_t speed_mode, uint32_t channel, uint * - ESP_ERR_INVALID_STATE Fade function not installed. * - ESP_FAIL Fade function init error */ -esp_err_t ledc_set_fade_with_step(ledc_mode_t speed_mode, ledc_channel_t channel, int target_duty, int scale, int cycle_num); +esp_err_t ledc_set_fade_with_step(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t target_duty, int scale, int cycle_num); /** * @brief Set LEDC fade function, with a limited time. Should call ledc_fade_func_install() before calling this function. @@ -346,7 +347,7 @@ esp_err_t ledc_set_fade_with_step(ledc_mode_t speed_mode, ledc_channel_t channel * - ESP_ERR_INVALID_STATE Fade function not installed. * - ESP_FAIL Fade function init error */ -esp_err_t ledc_set_fade_with_time(ledc_mode_t speed_mode, ledc_channel_t channel, int target_duty, int max_fade_time_ms); +esp_err_t ledc_set_fade_with_time(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t target_duty, int max_fade_time_ms); /** * @brief Install ledc fade function. This function will occupy interrupt of LEDC module. diff --git a/tools/sdk/include/driver/driver/pcnt.h b/tools/sdk/include/driver/driver/pcnt.h index 38a7e41d78c..ad47e51ec3d 100644 --- a/tools/sdk/include/driver/driver/pcnt.h +++ b/tools/sdk/include/driver/driver/pcnt.h @@ -18,59 +18,76 @@ extern "C" { #endif -#define PCNT_PIN_NOT_USED (-1) /*!< Pin are not used */ +#define PCNT_PIN_NOT_USED (-1) /*!< When selected for a pin, this pin will not be used */ +/** + * @brief Selection of available modes that determine the counter's action depending on the state of the control signal's input GPIO + * @note Configuration covers two actions, one for high, and one for low level on the control input + */ typedef enum { PCNT_MODE_KEEP = 0, /*!< Control mode: won't change counter mode*/ - PCNT_MODE_REVERSE = 1, /*!< Control mode: invert counter mode(increase -> decrease, decrease -> increase);*/ - PCNT_MODE_DISABLE = 2, /*!< Control mode: Inhibit counter(counter value will not change in this condition)*/ + PCNT_MODE_REVERSE = 1, /*!< Control mode: invert counter mode(increase -> decrease, decrease -> increase) */ + PCNT_MODE_DISABLE = 2, /*!< Control mode: Inhibit counter(counter value will not change in this condition) */ PCNT_MODE_MAX } pcnt_ctrl_mode_t; +/** + * @brief Selection of available modes that determine the counter's action on the edge of the pulse signal's input GPIO + * @note Configuration covers two actions, one for positive, and one for negative edge on the pulse input + */ typedef enum { - PCNT_COUNT_DIS = 0, /*!< Counter mode: Inhibit counter(counter value will not change in this condition)*/ - PCNT_COUNT_INC = 1, /*!< Counter mode: Increase counter value*/ - PCNT_COUNT_DEC = 2, /*!< Counter mode: Decrease counter value*/ + PCNT_COUNT_DIS = 0, /*!< Counter mode: Inhibit counter(counter value will not change in this condition) */ + PCNT_COUNT_INC = 1, /*!< Counter mode: Increase counter value */ + PCNT_COUNT_DEC = 2, /*!< Counter mode: Decrease counter value */ PCNT_COUNT_MAX } pcnt_count_mode_t; +/** + * @brief Selection of all available PCNT units + */ typedef enum { - PCNT_UNIT_0 = 0, /*!< PCNT unit0 */ - PCNT_UNIT_1 = 1, /*!< PCNT unit1 */ - PCNT_UNIT_2 = 2, /*!< PCNT unit2 */ - PCNT_UNIT_3 = 3, /*!< PCNT unit3 */ - PCNT_UNIT_4 = 4, /*!< PCNT unit4 */ - PCNT_UNIT_5 = 5, /*!< PCNT unit5 */ - PCNT_UNIT_6 = 6, /*!< PCNT unit6 */ - PCNT_UNIT_7 = 7, /*!< PCNT unit7 */ + PCNT_UNIT_0 = 0, /*!< PCNT unit 0 */ + PCNT_UNIT_1 = 1, /*!< PCNT unit 1 */ + PCNT_UNIT_2 = 2, /*!< PCNT unit 2 */ + PCNT_UNIT_3 = 3, /*!< PCNT unit 3 */ + PCNT_UNIT_4 = 4, /*!< PCNT unit 4 */ + PCNT_UNIT_5 = 5, /*!< PCNT unit 5 */ + PCNT_UNIT_6 = 6, /*!< PCNT unit 6 */ + PCNT_UNIT_7 = 7, /*!< PCNT unit 7 */ PCNT_UNIT_MAX, } pcnt_unit_t; +/** + * @brief Selection of channels available for a single PCNT unit + */ typedef enum { - PCNT_CHANNEL_0 = 0x00, /*!< PCNT channel0 */ - PCNT_CHANNEL_1 = 0x01, /*!< PCNT channel1 */ + PCNT_CHANNEL_0 = 0x00, /*!< PCNT channel 0 */ + PCNT_CHANNEL_1 = 0x01, /*!< PCNT channel 1 */ PCNT_CHANNEL_MAX, } pcnt_channel_t; +/** + * @brief Selection of counter's events the may trigger an interrupt + */ typedef enum { PCNT_EVT_L_LIM = 0, /*!< PCNT watch point event: Minimum counter value */ - PCNT_EVT_H_LIM = 1, /*!< PCNT watch point event: Maximum counter value*/ - PCNT_EVT_THRES_0 = 2, /*!< PCNT watch point event: threshold0 value event*/ - PCNT_EVT_THRES_1 = 3, /*!< PCNT watch point event: threshold1 value event*/ - PCNT_EVT_ZERO = 4, /*!< PCNT watch point event: counter value zero event*/ + PCNT_EVT_H_LIM = 1, /*!< PCNT watch point event: Maximum counter value */ + PCNT_EVT_THRES_0 = 2, /*!< PCNT watch point event: threshold0 value event */ + PCNT_EVT_THRES_1 = 3, /*!< PCNT watch point event: threshold1 value event */ + PCNT_EVT_ZERO = 4, /*!< PCNT watch point event: counter value zero event */ PCNT_EVT_MAX } pcnt_evt_type_t; /** - * @brief Pulse Counter configure struct + * @brief Pulse Counter configuration for a single channel */ typedef struct { - int pulse_gpio_num; /*!< Pulse input gpio_num, if you want to use gpio16, pulse_gpio_num = 16, a negative value will be ignored */ - int ctrl_gpio_num; /*!< Contol signal input gpio_num, a negative value will be ignored*/ - pcnt_ctrl_mode_t lctrl_mode; /*!< PCNT low control mode*/ - pcnt_ctrl_mode_t hctrl_mode; /*!< PCNT high control mode*/ - pcnt_count_mode_t pos_mode; /*!< PCNT positive edge count mode*/ - pcnt_count_mode_t neg_mode; /*!< PCNT negative edge count mode*/ + int pulse_gpio_num; /*!< Pulse input GPIO number, if you want to use GPIO16, enter pulse_gpio_num = 16, a negative value will be ignored */ + int ctrl_gpio_num; /*!< Control signal input GPIO number, a negative value will be ignored */ + pcnt_ctrl_mode_t lctrl_mode; /*!< PCNT low control mode */ + pcnt_ctrl_mode_t hctrl_mode; /*!< PCNT high control mode */ + pcnt_count_mode_t pos_mode; /*!< PCNT positive edge count mode */ + pcnt_count_mode_t neg_mode; /*!< PCNT negative edge count mode */ int16_t counter_h_lim; /*!< Maximum counter value */ int16_t counter_l_lim; /*!< Minimum counter value */ pcnt_unit_t unit; /*!< PCNT unit number */ @@ -150,7 +167,7 @@ esp_err_t pcnt_counter_clear(pcnt_unit_t pcnt_unit); esp_err_t pcnt_intr_enable(pcnt_unit_t pcnt_unit); /** - * @brief Disable PCNT interrupt for PCNT uint + * @brief Disable PCNT interrupt for PCNT unit * * @param pcnt_unit PCNT unit number * @@ -219,10 +236,10 @@ esp_err_t pcnt_get_event_value(pcnt_unit_t unit, pcnt_evt_type_t evt_type, int16 * * @param fn Interrupt handler function. * @param arg Parameter for handler function - * @param intr_alloc_flags Flags used to allocate the interrupt. One or multiple (ORred) - * ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info. - * @param handle Pointer to return handle. If non-NULL, a handle for the interrupt will - * be returned here. + * @param intr_alloc_flags Flags used to allocate the interrupt. One or multiple (ORred) + * ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info. + * @param handle Pointer to return handle. If non-NULL, a handle for the interrupt will + * be returned here. * * @return * - ESP_OK Success @@ -236,11 +253,9 @@ esp_err_t pcnt_isr_register(void (*fn)(void*), void * arg, int intr_alloc_flags, * @param unit PCNT unit number * @param channel PCNT channel number * @param pulse_io Pulse signal input GPIO - * @note - * Set to PCNT_PIN_NOT_USED if unused. * @param ctrl_io Control signal input GPIO - * @note - * Set to PCNT_PIN_NOT_USED if unused. + * + * @note Set the signal input to PCNT_PIN_NOT_USED if unused. * * @return * - ESP_OK Success @@ -329,8 +344,8 @@ esp_err_t pcnt_set_mode(pcnt_unit_t unit, pcnt_channel_t channel, * .pulse_gpio_num = 4, //set gpio4 as pulse input gpio * .ctrl_gpio_num = 5, //set gpio5 as control gpio * .channel = PCNT_CHANNEL_0, //use unit 0 channel 0 - * .lctrl_mode = PCNT_MODE_REVERSE, //when control signal is low ,reverse the primary counter mode(inc->dec/dec->inc) - * .hctrl_mode = PCNT_MODE_KEEP, //when control signal is high,keep the primary counter mode + * .lctrl_mode = PCNT_MODE_REVERSE, //when control signal is low, reverse the primary counter mode(inc->dec/dec->inc) + * .hctrl_mode = PCNT_MODE_KEEP, //when control signal is high, keep the primary counter mode * .pos_mode = PCNT_COUNT_INC, //increment the counter * .neg_mode = PCNT_COUNT_DIS, //keep the counter value * .counter_h_lim = 10, diff --git a/tools/sdk/include/driver/driver/periph_ctrl.h b/tools/sdk/include/driver/driver/periph_ctrl.h index cd09a78f533..e523598fa00 100644 --- a/tools/sdk/include/driver/driver/periph_ctrl.h +++ b/tools/sdk/include/driver/driver/periph_ctrl.h @@ -56,6 +56,7 @@ typedef enum { * * @param[in] periph : Peripheral module name * + * Clock for the module will be ungated, and reset de-asserted. * * @return NULL * @@ -67,12 +68,28 @@ void periph_module_enable(periph_module_t periph); * * @param[in] periph : Peripheral module name * + * Clock for the module will be gated, reset asserted. * * @return NULL * */ void periph_module_disable(periph_module_t periph); +/** + * @brief reset peripheral module + * + * @param[in] periph : Peripheral module name + * + * Reset will asserted then de-assrted for the peripheral. + * + * Calling this function does not enable or disable the clock for the module. + * + * @return NULL + * + */ +void periph_module_reset(periph_module_t periph); + + #ifdef __cplusplus } #endif diff --git a/tools/sdk/include/driver/driver/sdmmc_types.h b/tools/sdk/include/driver/driver/sdmmc_types.h index 4bc1e05e510..835eaa3fb71 100644 --- a/tools/sdk/include/driver/driver/sdmmc_types.h +++ b/tools/sdk/include/driver/driver/sdmmc_types.h @@ -102,6 +102,7 @@ typedef struct { #define SCF_RSP_R6 (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_IDX) #define SCF_RSP_R7 (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_IDX) esp_err_t error; /*!< error returned from transfer */ + int timeout_ms; /*!< response timeout, in milliseconds */ } sdmmc_command_t; /** @@ -127,6 +128,7 @@ typedef struct { esp_err_t (*set_card_clk)(int slot, uint32_t freq_khz); /*!< host function to set card clock frequency */ esp_err_t (*do_transaction)(int slot, sdmmc_command_t* cmdinfo); /*!< host function to do a transaction */ esp_err_t (*deinit)(void); /*!< host function to deinitialize the driver */ + int command_timeout_ms; /*!< timeout, in milliseconds, of a single command. Set to 0 to use the default value. */ } sdmmc_host_t; /** diff --git a/tools/sdk/include/driver/driver/sigmadelta.h b/tools/sdk/include/driver/driver/sigmadelta.h index 61a35c21f91..76237c193d3 100644 --- a/tools/sdk/include/driver/driver/sigmadelta.h +++ b/tools/sdk/include/driver/driver/sigmadelta.h @@ -27,14 +27,14 @@ extern "C" { * @brief Sigma-delta channel list */ typedef enum{ - SIGMADELTA_CHANNEL_0 = 0, /*!< Sigma-delta channel0 */ - SIGMADELTA_CHANNEL_1 = 1, /*!< Sigma-delta channel1 */ - SIGMADELTA_CHANNEL_2 = 2, /*!< Sigma-delta channel2 */ - SIGMADELTA_CHANNEL_3 = 3, /*!< Sigma-delta channel3 */ - SIGMADELTA_CHANNEL_4 = 4, /*!< Sigma-delta channel4 */ - SIGMADELTA_CHANNEL_5 = 5, /*!< Sigma-delta channel5 */ - SIGMADELTA_CHANNEL_6 = 6, /*!< Sigma-delta channel6 */ - SIGMADELTA_CHANNEL_7 = 7, /*!< Sigma-delta channel7 */ + SIGMADELTA_CHANNEL_0 = 0, /*!< Sigma-delta channel 0 */ + SIGMADELTA_CHANNEL_1 = 1, /*!< Sigma-delta channel 1 */ + SIGMADELTA_CHANNEL_2 = 2, /*!< Sigma-delta channel 2 */ + SIGMADELTA_CHANNEL_3 = 3, /*!< Sigma-delta channel 3 */ + SIGMADELTA_CHANNEL_4 = 4, /*!< Sigma-delta channel 4 */ + SIGMADELTA_CHANNEL_5 = 5, /*!< Sigma-delta channel 5 */ + SIGMADELTA_CHANNEL_6 = 6, /*!< Sigma-delta channel 6 */ + SIGMADELTA_CHANNEL_7 = 7, /*!< Sigma-delta channel 7 */ SIGMADELTA_CHANNEL_MAX, } sigmadelta_channel_t; @@ -64,7 +64,8 @@ esp_err_t sigmadelta_config(const sigmadelta_config_t *config); * * This function is used to set Sigma-delta channel duty, * If you add a capacitor between the output pin and ground, - * the average output voltage Vdc = VDDIO / 256 * duty + VDDIO/2, VDDIO is power supply voltage. + * the average output voltage will be Vdc = VDDIO / 256 * duty + VDDIO/2, + * where VDDIO is the power supply voltage. * * @param channel Sigma-delta channel number * @param duty Sigma-delta duty of one channel, the value ranges from -128 to 127, recommended range is -90 ~ 90. diff --git a/tools/sdk/include/driver/driver/spi_slave.h b/tools/sdk/include/driver/driver/spi_slave.h index 047ab41392b..ed12cb62df7 100644 --- a/tools/sdk/include/driver/driver/spi_slave.h +++ b/tools/sdk/include/driver/driver/spi_slave.h @@ -53,6 +53,7 @@ typedef struct { */ struct spi_slave_transaction_t { size_t length; ///< Total data length, in bits + size_t trans_len; ///< Transaction data length, in bits const void *tx_buffer; ///< Pointer to transmit buffer, or NULL for no MOSI phase void *rx_buffer; ///< Pointer to receive buffer, or NULL for no MISO phase void *user; ///< User-defined variable. Can be used to store eg transaction ID. diff --git a/tools/sdk/include/driver/driver/touch_pad.h b/tools/sdk/include/driver/driver/touch_pad.h index ce67a7dc72f..9d14fe4e712 100644 --- a/tools/sdk/include/driver/driver/touch_pad.h +++ b/tools/sdk/include/driver/driver/touch_pad.h @@ -31,8 +31,8 @@ typedef enum { TOUCH_PAD_NUM5, /*!< Touch pad channel 5 is GPIO12*/ TOUCH_PAD_NUM6, /*!< Touch pad channel 6 is GPIO14*/ TOUCH_PAD_NUM7, /*!< Touch pad channel 7 is GPIO27*/ - TOUCH_PAD_NUM8, /*!< Touch pad channel 8 is GPIO32*/ - TOUCH_PAD_NUM9, /*!< Touch pad channel 9 is GPIO33*/ + TOUCH_PAD_NUM8, /*!< Touch pad channel 8 is GPIO33*/ + TOUCH_PAD_NUM9, /*!< Touch pad channel 9 is GPIO32*/ TOUCH_PAD_MAX, } touch_pad_t; diff --git a/tools/sdk/include/driver/driver/uart.h b/tools/sdk/include/driver/driver/uart.h index 229685b7c3c..a4227b34817 100644 --- a/tools/sdk/include/driver/driver/uart.h +++ b/tools/sdk/include/driver/driver/uart.h @@ -35,7 +35,7 @@ extern "C" { #include "soc/uart_channel.h" #define UART_FIFO_LEN (128) /*!< Length of the hardware FIFO buffers */ -#define UART_INTR_MASK 0x1ff /*!< mask of all UART interrupts */ +#define UART_INTR_MASK 0x1ff /*!< Mask of all UART interrupts */ #define UART_LINE_INV_MASK (0x3f << 19) /*!< TBD */ #define UART_BITRATE_MAX 5000000 /*!< Max bit rate supported by UART */ #define UART_PIN_NO_CHANGE (-1) /*!< Constant for uart_set_pin function which indicates that UART pin should not be changed */ @@ -73,7 +73,7 @@ typedef enum { typedef enum { UART_NUM_0 = 0x0, /*!< UART base address 0x3ff40000*/ UART_NUM_1 = 0x1, /*!< UART base address 0x3ff50000*/ - UART_NUM_2 = 0x2, /*!< UART base address 0x3ff6E000*/ + UART_NUM_2 = 0x2, /*!< UART base address 0x3ff6e000*/ UART_NUM_MAX, } uart_port_t; @@ -81,7 +81,7 @@ typedef enum { * @brief UART parity constants */ typedef enum { - UART_PARITY_DISABLE = 0x0, /*!< Disable UART parity*/ + UART_PARITY_DISABLE = 0x0, /*!< Disable UART parity*/ UART_PARITY_EVEN = 0x2, /*!< Enable UART even parity*/ UART_PARITY_ODD = 0x3 /*!< Enable UART odd parity*/ } uart_parity_t; @@ -101,12 +101,13 @@ typedef enum { * @brief UART configuration parameters for uart_param_config function */ typedef struct { - int baud_rate; /*!< UART baudrate*/ + int baud_rate; /*!< UART baud rate*/ uart_word_length_t data_bits; /*!< UART byte size*/ uart_parity_t parity; /*!< UART parity mode*/ uart_stop_bits_t stop_bits; /*!< UART stop bits*/ - uart_hw_flowcontrol_t flow_ctrl; /*!< UART HW flow control mode(cts/rts)*/ - uint8_t rx_flow_ctrl_thresh ; /*!< UART HW RTS threshold*/ + uart_hw_flowcontrol_t flow_ctrl; /*!< UART HW flow control mode (cts/rts)*/ + uint8_t rx_flow_ctrl_thresh; /*!< UART HW RTS threshold*/ + bool use_ref_tick; /*!< Set to true if UART should be clocked from REF_TICK */ } uart_config_t; /** @@ -114,13 +115,13 @@ typedef struct { */ typedef struct { uint32_t intr_enable_mask; /*!< UART interrupt enable mask, choose from UART_XXXX_INT_ENA_M under UART_INT_ENA_REG(i), connect with bit-or operator*/ - uint8_t rx_timeout_thresh; /*!< UART timeout interrupt threshold(unit: time of sending one byte)*/ + uint8_t rx_timeout_thresh; /*!< UART timeout interrupt threshold (unit: time of sending one byte)*/ uint8_t txfifo_empty_intr_thresh; /*!< UART TX empty interrupt threshold.*/ uint8_t rxfifo_full_thresh; /*!< UART RX full interrupt threshold.*/ } uart_intr_config_t; /** - * @brief UART event types used in the ringbuffer + * @brief UART event types used in the ring buffer */ typedef enum { UART_DATA, /*!< UART data event*/ @@ -181,7 +182,7 @@ esp_err_t uart_get_word_length(uart_port_t uart_num, uart_word_length_t* data_bi esp_err_t uart_set_stop_bits(uart_port_t uart_num, uart_stop_bits_t stop_bits); /** - * @brief Set UART stop bits. + * @brief Get UART stop bits. * * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @param stop_bits Pointer to accept value of UART stop bits. @@ -193,7 +194,7 @@ esp_err_t uart_set_stop_bits(uart_port_t uart_num, uart_stop_bits_t stop_bits); esp_err_t uart_get_stop_bits(uart_port_t uart_num, uart_stop_bits_t* stop_bits); /** - * @brief Set UART parity. + * @brief Set UART parity mode. * * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @param parity_mode the enum of uart parity configuration @@ -230,7 +231,7 @@ esp_err_t uart_get_parity(uart_port_t uart_num, uart_parity_t* parity_mode); esp_err_t uart_set_baudrate(uart_port_t uart_num, uint32_t baudrate); /** - * @brief Get UART bit-rate. + * @brief Get UART baud rate. * * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @param baudrate Pointer to accept value of UART baud rate @@ -247,7 +248,9 @@ esp_err_t uart_get_baudrate(uart_port_t uart_num, uint32_t* baudrate); * * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @param inverse_mask Choose the wires that need to be inverted. - * Inverse_mask should be chosen from UART_INVERSE_RXD/UART_INVERSE_TXD/UART_INVERSE_RTS/UART_INVERSE_CTS, combine with OR operation. + * Inverse_mask should be chosen from + UART_INVERSE_RXD / UART_INVERSE_TXD / UART_INVERSE_RTS / UART_INVERSE_CTS, + combined with OR operation. * * @return * - ESP_OK Success @@ -260,8 +263,8 @@ esp_err_t uart_set_line_inverse(uart_port_t uart_num, uint32_t inverse_mask); * * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @param flow_ctrl Hardware flow control mode - * @param rx_thresh Threshold of Hardware RX flow control(0 ~ UART_FIFO_LEN). - * Only when UART_HW_FLOWCTRL_RTS is set, will the rx_thresh value be set. + * @param rx_thresh Threshold of Hardware RX flow control (0 ~ UART_FIFO_LEN). + * Only when UART_HW_FLOWCTRL_RTS is set, will the rx_thresh value be set. * * @return * - ESP_OK Success @@ -269,6 +272,20 @@ esp_err_t uart_set_line_inverse(uart_port_t uart_num, uint32_t inverse_mask); */ esp_err_t uart_set_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t flow_ctrl, uint8_t rx_thresh); +/** + * @brief Set software flow control. + * + * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 + * @param enable switch on or off + * @param rx_thresh_xon low water mark + * @param rx_thresh_xoff high water mark + * + * @return + * - ESP_OK Success + * - ESP_FAIL Parameter error + */ + esp_err_t uart_set_sw_flow_ctrl(uart_port_t uart_num, bool enable, uint8_t rx_thresh_xon, uint8_t rx_thresh_xoff); + /** * @brief Get hardware flow control mode * @@ -284,9 +301,9 @@ esp_err_t uart_get_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t* flo /** * @brief Clear UART interrupt status * - * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 - * @param clr_mask Bit mask of the status that to be cleared. - * enable_mask should be chosen from the fields of register UART_INT_CLR_REG. + * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 + * @param clr_mask Bit mask of the interrupt status to be cleared. + * The bit mask should be composed from the fields of register UART_INT_CLR_REG. * * @return * - ESP_OK Success @@ -297,9 +314,9 @@ esp_err_t uart_clear_intr_status(uart_port_t uart_num, uint32_t clr_mask); /** * @brief Set UART interrupt enable * - * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 + * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @param enable_mask Bit mask of the enable bits. - * enable_mask should be chosen from the fields of register UART_INT_ENA_REG. + * The bit mask should be composed from the fields of register UART_INT_ENA_REG. * * @return * - ESP_OK Success @@ -310,9 +327,9 @@ esp_err_t uart_enable_intr_mask(uart_port_t uart_num, uint32_t enable_mask); /** * @brief Clear UART interrupt enable bits * - * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 + * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @param disable_mask Bit mask of the disable bits. - * disable_mask should be chosen from the fields of register UART_INT_ENA_REG. + * The bit mask should be composed from the fields of register UART_INT_ENA_REG. * * @return * - ESP_OK Success @@ -320,9 +337,8 @@ esp_err_t uart_enable_intr_mask(uart_port_t uart_num, uint32_t enable_mask); */ esp_err_t uart_disable_intr_mask(uart_port_t uart_num, uint32_t disable_mask); - /** - * @brief Enable UART RX interrupt(RX_FULL & RX_TIMEOUT INTERRUPT) + * @brief Enable UART RX interrupt (RX_FULL & RX_TIMEOUT INTERRUPT) * * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @@ -333,7 +349,7 @@ esp_err_t uart_disable_intr_mask(uart_port_t uart_num, uint32_t disable_mask); esp_err_t uart_enable_rx_intr(uart_port_t uart_num); /** - * @brief Disable UART RX interrupt(RX_FULL & RX_TIMEOUT INTERRUPT) + * @brief Disable UART RX interrupt (RX_FULL & RX_TIMEOUT INTERRUPT) * * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @@ -344,7 +360,7 @@ esp_err_t uart_enable_rx_intr(uart_port_t uart_num); esp_err_t uart_disable_rx_intr(uart_port_t uart_num); /** - * @brief Disable UART TX interrupt(RX_FULL & RX_TIMEOUT INTERRUPT) + * @brief Disable UART TX interrupt (TX_FULL & TX_TIMEOUT INTERRUPT) * * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @@ -355,7 +371,7 @@ esp_err_t uart_disable_rx_intr(uart_port_t uart_num); esp_err_t uart_disable_tx_intr(uart_port_t uart_num); /** - * @brief Enable UART TX interrupt(RX_FULL & RX_TIMEOUT INTERRUPT) + * @brief Enable UART TX interrupt (TX_FULL & TX_TIMEOUT INTERRUPT) * * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @param enable 1: enable; 0: disable @@ -368,15 +384,15 @@ esp_err_t uart_disable_tx_intr(uart_port_t uart_num); esp_err_t uart_enable_tx_intr(uart_port_t uart_num, int enable, int thresh); /** - * @brief register UART interrupt handler(ISR). + * @brief Register UART interrupt handler (ISR). * * @note UART ISR handler will be attached to the same CPU core that this function is running on. * * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @param fn Interrupt handler function. * @param arg parameter for handler function - * @param intr_alloc_flags Flags used to allocate the interrupt. One or multiple (ORred) - * ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info. + * @param intr_alloc_flags Flags used to allocate the interrupt. One or multiple (ORred) + * ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info. * @param handle Pointer to return handle. If non-NULL, a handle for the interrupt will * be returned here. * @@ -386,7 +402,6 @@ esp_err_t uart_enable_tx_intr(uart_port_t uart_num, int enable, int thresh); */ esp_err_t uart_isr_register(uart_port_t uart_num, void (*fn)(void*), void * arg, int intr_alloc_flags, uart_isr_handle_t *handle); - /** * @brief Free UART interrupt handler registered by uart_isr_register. Must be called on the same core as * uart_isr_register was called. @@ -403,13 +418,16 @@ esp_err_t uart_isr_free(uart_port_t uart_num); * @brief Set UART pin number * * @note Internal signal can be output to multiple GPIO pads. - * Only one GPIO pad can connect with input signal. + * Only one GPIO pad can connect with input signal. * - * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 - * @param tx_io_num UART TX pin GPIO number, if set to UART_PIN_NO_CHANGE, use the current pin. - * @param rx_io_num UART RX pin GPIO number, if set to UART_PIN_NO_CHANGE, use the current pin. - * @param rts_io_num UART RTS pin GPIO number, if set to UART_PIN_NO_CHANGE, use the current pin. - * @param cts_io_num UART CTS pin GPIO number, if set to UART_PIN_NO_CHANGE, use the current pin. + * @note Instead of GPIO number a macro 'UART_PIN_NO_CHANGE' may be provided + to keep the currently allocated pin. + * + * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 + * @param tx_io_num UART TX pin GPIO number. + * @param rx_io_num UART RX pin GPIO number. + * @param rts_io_num UART RTS pin GPIO number. + * @param cts_io_num UART CTS pin GPIO number. * * @return * - ESP_OK Success @@ -418,11 +436,11 @@ esp_err_t uart_isr_free(uart_port_t uart_num); esp_err_t uart_set_pin(uart_port_t uart_num, int tx_io_num, int rx_io_num, int rts_io_num, int cts_io_num); /** - * @brief UART set RTS level (before inverse) - * UART rx hardware flow control should not be set. + * @brief Manually set the UART RTS pin level. + * @note UART must be configured with hardware flow control disabled. * * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 - * @param level 1: RTS output low(active); 0: RTS output high(block) + * @param level 1: RTS output low (active); 0: RTS output high (block) * * @return * - ESP_OK Success @@ -431,9 +449,9 @@ esp_err_t uart_set_pin(uart_port_t uart_num, int tx_io_num, int rx_io_num, int r esp_err_t uart_set_rts(uart_port_t uart_num, int level); /** - * @brief UART set DTR level (before inverse) + * @brief Manually set the UART DTR pin level. * - * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 + * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @param level 1: DTR output low; 0: DTR output high * * @return @@ -443,9 +461,9 @@ esp_err_t uart_set_rts(uart_port_t uart_num, int level); esp_err_t uart_set_dtr(uart_port_t uart_num, int level); /** -* @brief UART parameter configure +* @brief Set UART configuration parameters. * - * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 + * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @param uart_config UART parameter settings * * @return @@ -455,9 +473,9 @@ esp_err_t uart_set_dtr(uart_port_t uart_num, int level); esp_err_t uart_param_config(uart_port_t uart_num, const uart_config_t *uart_config); /** -* @brief UART interrupt configure +* @brief Configure UART interrupts. * - * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 + * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @param intr_conf UART interrupt settings * * @return @@ -471,18 +489,18 @@ esp_err_t uart_intr_config(uart_port_t uart_num, const uart_intr_config_t *intr_ * * UART ISR handler will be attached to the same CPU core that this function is running on. * + * @note Rx_buffer_size should be greater than UART_FIFO_LEN. Tx_buffer_size should be either zero or greater than UART_FIFO_LEN. + * * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 - * @param rx_buffer_size UART RX ring buffer size, rx_buffer_size should be greater than UART_FIFO_LEN. + * @param rx_buffer_size UART RX ring buffer size. * @param tx_buffer_size UART TX ring buffer size. - * If set to zero, driver will not use TX buffer, TX function will block task until all data have been sent out.. - * @note tx_buffer_size should be greater than UART_FIFO_LEN. - * + * If set to zero, driver will not use TX buffer, TX function will block task until all data have been sent out. * @param queue_size UART event queue size/depth. * @param uart_queue UART event queue handle (out param). On success, a new queue handle is written here to provide * access to UART events. If set to NULL, driver will not use an event queue. - * @param intr_alloc_flags Flags used to allocate the interrupt. One or multiple (ORred) - * ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info. Do not set ESP_INTR_FLAG_IRAM here - * (the driver's ISR handler is not located in IRAM) + * @param intr_alloc_flags Flags used to allocate the interrupt. One or multiple (ORred) + * ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info. Do not set ESP_INTR_FLAG_IRAM here + * (the driver's ISR handler is not located in IRAM) * * @return * - ESP_OK Success @@ -493,7 +511,7 @@ esp_err_t uart_driver_install(uart_port_t uart_num, int rx_buffer_size, int tx_b /** * @brief Uninstall UART driver. * - * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 + * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * * @return * - ESP_OK Success @@ -502,9 +520,9 @@ esp_err_t uart_driver_install(uart_port_t uart_num, int rx_buffer_size, int tx_b esp_err_t uart_driver_delete(uart_port_t uart_num); /** - * @brief Wait UART TX FIFO empty + * @brief Wait until UART TX FIFO is empty. * - * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 + * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @param ticks_to_wait Timeout, count in RTOS ticks * * @return @@ -517,59 +535,59 @@ esp_err_t uart_wait_tx_done(uart_port_t uart_num, TickType_t ticks_to_wait); /** * @brief Send data to the UART port from a given buffer and length. * - * This function will not wait for the space in TX FIFO, just fill the TX FIFO and return when the FIFO is full. + * This function will not wait for enough space in TX FIFO. It will just fill the available TX FIFO and return when the FIFO is full. * @note This function should only be used when UART TX buffer is not enabled. * * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 - * @param buffer data buffer address - * @param len data length to send + * @param buffer data buffer address + * @param len data length to send * * @return * - (-1) Parameter error - * - OTHERS(>=0) The number of data that pushed to the TX FIFO + * - OTHERS (>=0) The number of bytes pushed to the TX FIFO */ int uart_tx_chars(uart_port_t uart_num, const char* buffer, uint32_t len); /** * @brief Send data to the UART port from a given buffer and length, * - * If parameter tx_buffer_size is set to zero: + * If the UART driver's parameter 'tx_buffer_size' is set to zero: * This function will not return until all the data have been sent out, or at least pushed into TX FIFO. * - * Otherwise, if tx_buffer_size > 0, this function will return after copying all the data to tx ringbuffer, - * then, UART ISR will move data from ring buffer to TX FIFO gradually. + * Otherwise, if the 'tx_buffer_size' > 0, this function will return after copying all the data to tx ring buffer, + * UART ISR will then move data from the ring buffer to TX FIFO gradually. * * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 - * @param src data buffer address - * @param size data length to send + * @param src data buffer address + * @param size data length to send * * @return * - (-1) Parameter error - * - OTHERS(>=0) The number of data that pushed to the TX FIFO + * - OTHERS (>=0) The number of bytes pushed to the TX FIFO */ int uart_write_bytes(uart_port_t uart_num, const char* src, size_t size); /** - * @brief Send data to the UART port from a given buffer and length, + * @brief Send data to the UART port from a given buffer and length. * - * If parameter tx_buffer_size is set to zero: + * If the UART driver's parameter 'tx_buffer_size' is set to zero: * This function will not return until all the data and the break signal have been sent out. - * After all data send out, send a break signal. + * After all data is sent out, send a break signal. * - * Otherwise, if tx_buffer_size > 0, this function will return after copying all the data to tx ringbuffer, - * then, UART ISR will move data from ring buffer to TX FIFO gradually. - * After all data send out, send a break signal. + * Otherwise, if the 'tx_buffer_size' > 0, this function will return after copying all the data to tx ring buffer, + * UART ISR will then move data from the ring buffer to TX FIFO gradually. + * After all data sent out, send a break signal. * * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @param src data buffer address * @param size data length to send - * @param brk_len break signal length (unit: time of one data bit at current_baudrate) + * @param brk_len break signal length (unit: the time it takes to send a complete byte + including start, stop and parity bits at current_baudrate) * * @return * - (-1) Parameter error - * - OTHERS(>=0) The number of data that pushed to the TX FIFO + * - OTHERS (>=0) The number of bytes pushed to the TX FIFO */ - int uart_write_bytes_with_break(uart_port_t uart_num, const char* src, size_t size, int brk_len); /** @@ -582,12 +600,12 @@ int uart_write_bytes_with_break(uart_port_t uart_num, const char* src, size_t si * * @return * - (-1) Error - * - Others return a char data from uart fifo. + * - OTHERS (>=0) The number of bytes read from UART FIFO */ int uart_read_bytes(uart_port_t uart_num, uint8_t* buf, uint32_t length, TickType_t ticks_to_wait); /** - * @brief UART ring buffer flush + * @brief UART ring buffer flush. This will discard all data in the UART RX buffer. * * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2 * @@ -598,10 +616,10 @@ int uart_read_bytes(uart_port_t uart_num, uint8_t* buf, uint32_t length, TickTyp esp_err_t uart_flush(uart_port_t uart_num); /** - * @brief UART get RX ring buffer cached data length + * @brief UART get RX ring buffer cached data length * - * @param uart_num UART port number. - * @param size Pointer of size_t to accept cached data length + * @param uart_num UART port number. + * @param size Pointer of size_t to accept cached data length * * @return * - ESP_OK Success @@ -610,11 +628,11 @@ esp_err_t uart_flush(uart_port_t uart_num); esp_err_t uart_get_buffered_data_len(uart_port_t uart_num, size_t* size); /** - * @brief UART disable pattern detect function. - * Designed for applications like 'AT commands'. - * When the hardware detect a series of one same character, the interrupt will be triggered. + * @brief UART disable pattern detect function. + * Designed for applications like 'AT commands'. + * When the hardware detects a series of one same character, the interrupt will be triggered. * - * @param uart_num UART port number. + * @param uart_num UART port number. * * @return * - ESP_OK Success @@ -623,183 +641,22 @@ esp_err_t uart_get_buffered_data_len(uart_port_t uart_num, size_t* size); esp_err_t uart_disable_pattern_det_intr(uart_port_t uart_num); /** - * @brief UART enable pattern detect function. - * Designed for applications like 'AT commands'. - * When the hardware detect a series of one same character, the interrupt will be triggered. + * @brief UART enable pattern detect function. + * Designed for applications like 'AT commands'. + * When the hardware detect a series of one same character, the interrupt will be triggered. * * @param uart_num UART port number. * @param pattern_chr character of the pattern * @param chr_num number of the character, 8bit value. - * @param chr_tout timeout of the interval between each pattern characters, 24bit value, unit is APB(80Mhz) clock cycle. - * @param post_idle idle time after the last pattern character, 24bit value, unit is APB(80Mhz) clock cycle. - * @param pre_idle idle time before the first pattern character, 24bit value, unit is APB(80Mhz) clock cycle. + * @param chr_tout timeout of the interval between each pattern characters, 24bit value, unit is APB (80Mhz) clock cycle. + * @param post_idle idle time after the last pattern character, 24bit value, unit is APB (80Mhz) clock cycle. + * @param pre_idle idle time before the first pattern character, 24bit value, unit is APB (80Mhz) clock cycle. * * @return * - ESP_OK Success * - ESP_FAIL Parameter error */ esp_err_t uart_enable_pattern_det_intr(uart_port_t uart_num, char pattern_chr, uint8_t chr_num, int chr_tout, int post_idle, int pre_idle); -/***************************EXAMPLE********************************** - * - * - * ----------------EXAMPLE OF UART SETTING --------------------- - * @code{c} - * //1. Setup UART - * #include "freertos/queue.h" - * //a. Set UART parameter - * int uart_num = 0; //uart port number - * uart_config_t uart_config = { - * .baud_rate = 115200, //baudrate - * .data_bits = UART_DATA_8_BITS, //data bit mode - * .parity = UART_PARITY_DISABLE, //parity mode - * .stop_bits = UART_STOP_BITS_1, //stop bit mode - * .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, //hardware flow control(cts/rts) - * .rx_flow_ctrl_thresh = 120, //flow control threshold - * }; - * uart_param_config(uart_num, &uart_config); - * //b1. Setup UART driver(with UART queue) - * QueueHandle_t uart_queue; - * //parameters here are just an example, tx buffer size is 2048 - * uart_driver_install(uart_num, 1024 * 2, 1024 * 2, 10, &uart_queue, 0); - * //b2. Setup UART driver(without UART queue) - * //parameters here are just an example, tx buffer size is 0 - * uart_driver_install(uart_num, 1024 * 2, 0, 10, NULL, 0); - *@endcode - *-----------------------------------------------------------------------------* - * @code{c} - * //2. Set UART pin - * //set UART pin, not needed if use default pins. - * uart_set_pin(uart_num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, 15, 13); - * @endcode - *-----------------------------------------------------------------------------* - * @code{c} - * //3. Read data from UART. - * uint8_t data[128]; - * int length = 0; - * length = uart_read_bytes(uart_num, data, sizeof(data), 100); - * @endcode - *-----------------------------------------------------------------------------* - * @code{c} - * //4. Write data to UART. - * char* test_str = "This is a test string.\n" - * uart_write_bytes(uart_num, (const char*)test_str, strlen(test_str)); - * @endcode - *-----------------------------------------------------------------------------* - * @code{c} - * //5. Write data to UART, end with a break signal. - * uart_write_bytes_with_break(0, "test break\n",strlen("test break\n"), 100); - * @endcode - *-----------------------------------------------------------------------------* - * @code{c} - * //6. an example of echo test with hardware flow control on UART1 - * void uart_loop_back_test() - * { - * int uart_num = 1; - * uart_config_t uart_config = { - * .baud_rate = 115200, - * .data_bits = UART_DATA_8_BITS, - * .parity = UART_PARITY_DISABLE, - * .stop_bits = UART_STOP_BITS_1, - * .flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS, - * .rx_flow_ctrl_thresh = 122, - * }; - * //Configure UART1 parameters - * uart_param_config(uart_num, &uart_config); - * //Set UART1 pins(TX: IO16, RX: IO17, RTS: IO18, CTS: IO19) - * uart_set_pin(uart_num, 16, 17, 18, 19); - * //Install UART driver( We don't need an event queue here) - * uart_driver_install(uart_num, 1024 * 2, 1024*4, 0, NULL, 0); - * uint8_t data[1000]; - * while(1) { - * //Read data from UART - * int len = uart_read_bytes(uart_num, data, sizeof(data), 10); - * //Write data back to UART - * uart_write_bytes(uart_num, (const char*)data, len); - * } - * } - * @endcode - *-----------------------------------------------------------------------------* - * @code{c} - * //7. An example of using UART event queue on UART0. - * #include "freertos/queue.h" - * //A queue to handle UART event. - * QueueHandle_t uart0_queue; - * static const char *TAG = "uart_example"; - * void uart_task(void *pvParameters) - * { - * int uart_num = (int)pvParameters; - * uart_event_t event; - * size_t size = 1024; - * uint8_t* dtmp = (uint8_t*)malloc(size); - * for(;;) { - * //Waiting for UART event. - * if(xQueueReceive(uart0_queue, (void * )&event, (portTickType)portMAX_DELAY)) { - * ESP_LOGI(TAG, "uart[%d] event:", uart_num); - * switch(event.type) { - * memset(dtmp, 0, size); - * //Event of UART receving data - * case UART_DATA: - * ESP_LOGI(TAG,"data, len: %d", event.size); - * int len = uart_read_bytes(uart_num, dtmp, event.size, 10); - * ESP_LOGI(TAG, "uart read: %d", len); - * break; - * //Event of HW FIFO overflow detected - * case UART_FIFO_OVF: - * ESP_LOGI(TAG, "hw fifo overflow\n"); - * break; - * //Event of UART ring buffer full - * case UART_BUFFER_FULL: - * ESP_LOGI(TAG, "ring buffer full\n"); - * break; - * //Event of UART RX break detected - * case UART_BREAK: - * ESP_LOGI(TAG, "uart rx break\n"); - * break; - * //Event of UART parity check error - * case UART_PARITY_ERR: - * ESP_LOGI(TAG, "uart parity error\n"); - * break; - * //Event of UART frame error - * case UART_FRAME_ERR: - * ESP_LOGI(TAG, "uart frame error\n"); - * break; - * //Others - * default: - * ESP_LOGI(TAG, "uart event type: %d\n", event.type); - * break; - * } - * } - * } - * free(dtmp); - * dtmp = NULL; - * vTaskDelete(NULL); - * } - * - * void uart_queue_test() - * { - * int uart_num = 0; - * uart_config_t uart_config = { - * .baud_rate = 115200, - * .data_bits = UART_DATA_8_BITS, - * .parity = UART_PARITY_DISABLE, - * .stop_bits = UART_STOP_BITS_1, - * .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - * .rx_flow_ctrl_thresh = 122, - * }; - * //Set UART parameters - * uart_param_config(uart_num, &uart_config); - * //Set UART pins,(-1: default pin, no change.) - * uart_set_pin(uart_num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - * //Set UART log level - * esp_log_level_set(TAG, ESP_LOG_INFO); - * //Install UART driver, and get the queue. - * uart_driver_install(uart_num, 1024 * 2, 1024*4, 10, &uart0_queue, 0); - * //Create a task to handler UART event from ISR - * xTaskCreate(uart_task, "uTask", 1024, (void*)uart_num, 10, NULL); - * } - * @endcode - * - ***************************END OF EXAMPLE**********************************/ #ifdef __cplusplus } diff --git a/tools/sdk/include/esp32/esp32/pm.h b/tools/sdk/include/esp32/esp32/pm.h new file mode 100644 index 00000000000..a7cbf0eac71 --- /dev/null +++ b/tools/sdk/include/esp32/esp32/pm.h @@ -0,0 +1,42 @@ +// Copyright 2016-2017 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. +// 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. + + +#pragma once +#include +#include +#include "esp_err.h" + +#include "soc/rtc.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @brief Power management config for ESP32 + * + * Pass a pointer to this structure as an argument to esp_pm_configure function. + */ +typedef struct { + rtc_cpu_freq_t max_cpu_freq; /*!< Maximum CPU frequency to use */ + rtc_cpu_freq_t min_cpu_freq; /*!< Minimum CPU frequency to use when no frequency locks are taken */ + bool light_sleep_enable; /*!< Enter light sleep when no locks are taken */ +} esp_pm_config_esp32_t; + + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/include/esp32/esp_clk.h b/tools/sdk/include/esp32/esp_clk.h index 5c6f5cb8710..6526aa92724 100644 --- a/tools/sdk/include/esp32/esp_clk.h +++ b/tools/sdk/include/esp32/esp_clk.h @@ -18,20 +18,8 @@ * @file esp_clk.h * * This file contains declarations of clock related functions. - * These functions are used in ESP-IDF components, but should not be considered - * to be part of public API. */ -/** - * @brief Initialize clock-related settings - * - * Called from cpu_start.c, not intended to be called from other places. - * This function configures the CPU clock, RTC slow and fast clocks, and - * performs RTC slow clock calibration. - */ -void esp_clk_init(void); - - /** * @brief Get the calibration value of RTC slow clock * @@ -42,7 +30,6 @@ void esp_clk_init(void); */ uint32_t esp_clk_slowclk_cal_get(); - /** * @brief Update the calibration value of RTC slow clock * @@ -55,10 +42,34 @@ uint32_t esp_clk_slowclk_cal_get(); void esp_clk_slowclk_cal_set(uint32_t value); /** - * @brief Disables clock of some peripherals + * @brief Return current CPU clock frequency + * When frequency switching is performed, this frequency may change. + * However it is guaranteed that the frequency never changes with a critical + * section. * - * Called from cpu_start.c, not intended to be called from other places. - * This function disables clock of useless peripherals when cpu starts. + * @return CPU clock frequency, in Hz */ -void esp_perip_clk_init(void); +int esp_clk_cpu_freq(void); +/** + * @brief Return current APB clock frequency + * + * When frequency switching is performed, this frequency may change. + * However it is guaranteed that the frequency never changes with a critical + * section. + * + * @return APB clock frequency, in Hz + */ +int esp_clk_apb_freq(void); + + +/** + * @brief Read value of RTC counter, converting it to microseconds + * @attention The value returned by this function may change abruptly when + * calibration value of RTC counter is updated via esp_clk_slowclk_cal_set + * function. This should not happen unless application calls esp_clk_slowclk_cal_set. + * In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code. + * + * @return Value or RTC counter, expressed in microseconds + */ +uint64_t esp_clk_rtc_time(); diff --git a/tools/sdk/include/esp32/esp_crosscore_int.h b/tools/sdk/include/esp32/esp_crosscore_int.h index 0e4b2b83853..2f1c5b3becf 100644 --- a/tools/sdk/include/esp32/esp_crosscore_int.h +++ b/tools/sdk/include/esp32/esp_crosscore_int.h @@ -35,8 +35,20 @@ void esp_crosscore_int_init(); * This is used internally by FreeRTOS in multicore mode * and should not be called by the user. * - * @param coreID Core that should do the yielding + * @param core_id Core that should do the yielding */ -void esp_crosscore_int_send_yield(int coreId); +void esp_crosscore_int_send_yield(int core_id); -#endif \ No newline at end of file + +/** + * Send an interrupt to a CPU indicating it should update its + * CCOMPARE1 value due to a frequency switch. + * + * This is used internally when dynamic frequency switching is + * enabled, and should not be called from application code. + * + * @param core_id Core that should update its CCOMPARE1 value + */ +void esp_crosscore_int_send_freq_switch(int core_id); + +#endif diff --git a/tools/sdk/include/esp32/esp_dport_access.h b/tools/sdk/include/esp32/esp_dport_access.h index 49e15f69721..3acf806888b 100644 --- a/tools/sdk/include/esp32/esp_dport_access.h +++ b/tools/sdk/include/esp32/esp_dport_access.h @@ -27,6 +27,10 @@ void esp_dport_access_int_init(void); void esp_dport_access_int_pause(void); void esp_dport_access_int_resume(void); +//This routine does not stop the dport routines in any way that is recoverable. Please +//only call in case of panic(). +void esp_dport_access_int_abort(void); + #if defined(BOOTLOADER_BUILD) || defined(CONFIG_FREERTOS_UNICORE) || !defined(ESP_PLATFORM) #define DPORT_STALL_OTHER_CPU_START() #define DPORT_STALL_OTHER_CPU_END() diff --git a/tools/sdk/include/esp32/esp_freertos_hooks.h b/tools/sdk/include/esp32/esp_freertos_hooks.h index 45a1649723b..3d211192626 100644 --- a/tools/sdk/include/esp32/esp_freertos_hooks.h +++ b/tools/sdk/include/esp32/esp_freertos_hooks.h @@ -30,48 +30,82 @@ typedef bool (*esp_freertos_idle_cb_t)(); typedef void (*esp_freertos_tick_cb_t)(); /** - * @brief Register a callback to be called on the freertos idle hook - * The callback should return true if it's okay for the core to - * sleep until an interrupt (or FreeRTOS tick) happens and false - * if it should be called again as fast as possible. + * @brief Register a callback to be called from the specified core's idle hook. + * The callback should return true if it should be called by the idle hook + * once per interrupt (or FreeRTOS tick), and return false if it should + * be called repeatedly as fast as possible by the idle hook. * - * @warning Idle callbacks MUST NOT, UNDER ANY CIRCUMSTANCES, CALL + * @warning Idle callbacks MUST NOT, UNDER ANY CIRCUMSTANCES, CALL * A FUNCTION THAT MIGHT BLOCK. * - * @param esp_freertos_idle_cb_t new_idle_cb : Callback to be called + * @param[in] new_idle_cb Callback to be called + * @param[in] cpuid id of the core * - * @return ESP_OK : Callback registered - * @return ESP_ERR_NO_MEM : No more space to register hook + * @return + * - ESP_OK: Callback registered to the specified core's idle hook + * - ESP_ERR_NO_MEM: No more space on the specified core's idle hook to register callback + * - ESP_ERR_INVALID_ARG: cpuid is invalid */ -esp_err_t esp_register_freertos_idle_hook(esp_freertos_idle_cb_t new_idle_cb); +esp_err_t esp_register_freertos_idle_hook_for_cpu(esp_freertos_idle_cb_t new_idle_cb, UBaseType_t cpuid); /** - * @brief Register a callback to be called on the freertos tick hook + * @brief Register a callback to the idle hook of the core that calls this function. + * The callback should return true if it should be called by the idle hook + * once per interrupt (or FreeRTOS tick), and return false if it should + * be called repeatedly as fast as possible by the idle hook. + * + * @warning Idle callbacks MUST NOT, UNDER ANY CIRCUMSTANCES, CALL + * A FUNCTION THAT MIGHT BLOCK. * - * @param esp_freertos_tick_cb_t new_tick_cb : Callback to be called + * @param[in] new_idle_cb Callback to be called * - * @return ESP_OK : Callback registered - * @return ESP_ERR_NO_MEM : No more space to register hook + * @return + * - ESP_OK: Callback registered to the calling core's idle hook + * - ESP_ERR_NO_MEM: No more space on the calling core's idle hook to register callback */ -esp_err_t esp_register_freertos_tick_hook(esp_freertos_tick_cb_t tick_cb); +esp_err_t esp_register_freertos_idle_hook(esp_freertos_idle_cb_t new_idle_cb); +/** + * @brief Register a callback to be called from the specified core's tick hook. + * + * @param[in] new_tick_cb Callback to be called + * @param[in] cpuid id of the core + * + * @return + * - ESP_OK: Callback registered to specified core's tick hook + * - ESP_ERR_NO_MEM: No more space on the specified core's tick hook to register the callback + * - ESP_ERR_INVALID_ARG: cpuid is invalid + */ +esp_err_t esp_register_freertos_tick_hook_for_cpu(esp_freertos_tick_cb_t new_tick_cb, UBaseType_t cpuid); /** - * @brief Unregister an idle callback registered earlier + * @brief Register a callback to be called from the calling core's tick hook. * - * @param esp_freertos_idle_cb_t new_idle_cb : Callback to be unregistered + * @param[in] new_tick_cb Callback to be called * - * @return void + * @return + * - ESP_OK: Callback registered to the calling core's tick hook + * - ESP_ERR_NO_MEM: No more space on the calling core's tick hook to register the callback */ -void esp_deregister_freertos_idle_hook(esp_freertos_idle_cb_t old_idle_cb); +esp_err_t esp_register_freertos_tick_hook(esp_freertos_tick_cb_t new_tick_cb); /** - * @brief Unregister a tick callback registered earlier + * @brief Unregister an idle callback. If the idle callback is registered to + * the idle hooks of both cores, the idle hook will be unregistered from + * both cores * - * @param esp_freertos_idle_cb_t new_idle_cb : Callback to be unregistered + * @param[in] old_idle_cb Callback to be unregistered + */ +void esp_deregister_freertos_idle_hook(esp_freertos_idle_cb_t old_idle_cb); + + +/** + * @brief Unregister a tick callback. If the tick callback is registered to the + * tick hooks of both cores, the tick hook will be unregistered from + * both cores * - * @return void + * @param[in] old_tick_cb Callback to be unregistered */ void esp_deregister_freertos_tick_hook(esp_freertos_tick_cb_t old_tick_cb); @@ -80,4 +114,4 @@ void esp_deregister_freertos_tick_hook(esp_freertos_tick_cb_t old_tick_cb); #endif -#endif \ No newline at end of file +#endif diff --git a/tools/sdk/include/esp32/esp_now.h b/tools/sdk/include/esp32/esp_now.h new file mode 100644 index 00000000000..497d7377621 --- /dev/null +++ b/tools/sdk/include/esp32/esp_now.h @@ -0,0 +1,315 @@ +// Copyright 2015-2016 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. +// 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 __ESP_NOW_H__ +#define __ESP_NOW_H__ + +#include +#include "esp_err.h" +#include "esp_wifi_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** \defgroup WiFi_APIs WiFi Related APIs + * @brief WiFi APIs + */ + +/** @addtogroup WiFi_APIs + * @{ + */ + +/** \defgroup ESPNOW_APIs ESPNOW APIs + * @brief ESP32 ESPNOW APIs + * + */ + +/** @addtogroup ESPNOW_APIs + * @{ + */ + +#define ESP_ERR_ESPNOW_BASE (ESP_ERR_WIFI_BASE + 101) /*!< ESPNOW error number base. */ +#define ESP_ERR_ESPNOW_NOT_INIT (ESP_ERR_ESPNOW_BASE) /*!< ESPNOW is not initialized. */ +#define ESP_ERR_ESPNOW_ARG (ESP_ERR_ESPNOW_BASE + 1) /*!< Invalid argument */ +#define ESP_ERR_ESPNOW_NO_MEM (ESP_ERR_ESPNOW_BASE + 2) /*!< Out of memory */ +#define ESP_ERR_ESPNOW_FULL (ESP_ERR_ESPNOW_BASE + 3) /*!< ESPNOW peer list is full */ +#define ESP_ERR_ESPNOW_NOT_FOUND (ESP_ERR_ESPNOW_BASE + 4) /*!< ESPNOW peer is not found */ +#define ESP_ERR_ESPNOW_INTERNAL (ESP_ERR_ESPNOW_BASE + 5) /*!< Internal error */ +#define ESP_ERR_ESPNOW_EXIST (ESP_ERR_ESPNOW_BASE + 6) /*!< ESPNOW peer has existed */ + +#define ESP_NOW_ETH_ALEN 6 /*!< Length of ESPNOW peer MAC address */ +#define ESP_NOW_KEY_LEN 16 /*!< Length of ESPNOW peer local master key */ + +#define ESP_NOW_MAX_TOTAL_PEER_NUM 20 /*!< Maximum number of ESPNOW total peers */ +#define ESP_NOW_MAX_ENCRYPT_PEER_NUM 6 /*!< Maximum number of ESPNOW encrypted peers */ + +#define ESP_NOW_MAX_DATA_LEN 250 /*!< Maximum length of ESPNOW data which is sent very time */ + +/** + * @brief Status of sending ESPNOW data . + */ +typedef enum { + ESP_NOW_SEND_SUCCESS = 0, /**< Send ESPNOW data successfully */ + ESP_NOW_SEND_FAIL, /**< Send ESPNOW data fail */ +} esp_now_send_status_t; + +/** + * @brief ESPNOW peer information parameters. + */ +typedef struct esp_now_peer_info { + uint8_t peer_addr[ESP_NOW_ETH_ALEN]; /**< ESPNOW peer MAC address that is also the MAC address of station or softap */ + uint8_t lmk[ESP_NOW_KEY_LEN]; /**< ESPNOW peer local master key that is used to encrypt data */ + uint8_t channel; /**< Wi-Fi channel that peer uses to send/receive ESPNOW data. If the value is 0, + use the current channel which station or softap is on. Otherwise, it must be + set as the channel that station or softap is on. */ + wifi_interface_t ifidx; /**< Wi-Fi interface that peer uses to send/receive ESPNOW data */ + bool encrypt; /**< ESPNOW data that this peer sends/receives is encrypted or not */ + void *priv; /**< ESPNOW peer private data */ +} esp_now_peer_info_t; + +/** + * @brief Number of ESPNOW peers which exist currently. + */ +typedef struct esp_now_peer_num { + int total_num; /**< Total number of ESPNOW peers, maximum value is ESP_NOW_MAX_TOTAL_PEER_NUM */ + int encrypt_num; /**< Number of encrypted ESPNOW peers, maximum value is ESP_NOW_MAX_ENCRYPT_PEER_NUM */ +} esp_now_peer_num_t; + +/** + * @brief Callback function of receiving ESPNOW data + * @param mac_addr peer MAC address + * @param data received data + * @param data_len length of received data + */ +typedef void (*esp_now_recv_cb_t)(const uint8_t *mac_addr, const uint8_t *data, int data_len); + +/** + * @brief Callback function of sending ESPNOW data + * @param mac_addr peer MAC address + * @param status status of sending ESPNOW data (succeed or fail) + */ +typedef void (*esp_now_send_cb_t)(const uint8_t *mac_addr, esp_now_send_status_t status); + +/** + * @brief Initialize ESPNOW function + * + * @return + * - ESP_OK : succeed + * - ESP_ERR_ESPNOW_INTERNAL : Internal error + */ +esp_err_t esp_now_init(void); + +/** + * @brief De-initialize ESPNOW function + * + * @return + * - ESP_OK : succeed + */ +esp_err_t esp_now_deinit(void); + +/** + * @brief Get the version of ESPNOW + * + * @param version ESPNOW version + * + * @return + * - ESP_OK : succeed + * - ESP_ERR_ESPNOW_ARG : invalid argument + */ +esp_err_t esp_now_get_version(uint32_t *version); + +/** + * @brief Register callback function of receiving ESPNOW data + * + * @param cb callback function of receiving ESPNOW data + * + * @return + * - ESP_OK : succeed + * - ESP_ERR_ESPNOW_NOT_INIT : ESPNOW is not initialized + * - ESP_ERR_ESPNOW_INTERNAL : internal error + */ +esp_err_t esp_now_register_recv_cb(esp_now_recv_cb_t cb); + +/** + * @brief Unregister callback function of receiving ESPNOW data + * + * @return + * - ESP_OK : succeed + * - ESP_ERR_ESPNOW_NOT_INIT : ESPNOW is not initialized + */ +esp_err_t esp_now_unregister_recv_cb(void); + +/** + * @brief Register callback function of sending ESPNOW data + * + * @param cb callback function of sending ESPNOW data + * + * @return + * - ESP_OK : succeed + * - ESP_ERR_ESPNOW_NOT_INIT : ESPNOW is not initialized + * - ESP_ERR_ESPNOW_INTERNAL : internal error + */ +esp_err_t esp_now_register_send_cb(esp_now_send_cb_t cb); + +/** + * @brief Unregister callback function of sending ESPNOW data + * + * @return + * - ESP_OK : succeed + * - ESP_ERR_ESPNOW_NOT_INIT : ESPNOW is not initialized + */ +esp_err_t esp_now_unregister_send_cb(void); + +/** + * @brief Send ESPNOW data + * + * @attention 1. If peer_addr is not NULL, send data to the peer whose MAC address matches peer_addr + * @attention 2. If peer_addr is NULL, send data to all of the peers that are added to the peer list + * @attention 3. The maximum length of data must be less than ESP_NOW_MAX_DATA_LEN + * @attention 4. The buffer pointed to by data argument does not need to be valid after esp_now_send returns + * + * @param peer_addr peer MAC address + * @param data data to send + * @param len length of data + * + * @return + * - ESP_OK : succeed + * - ESP_ERR_ESPNOW_NOT_INIT : ESPNOW is not initialized + * - ESP_ERR_ESPNOW_ARG : invalid argument + * - ESP_ERR_ESPNOW_INTERNAL : internal error + * - ESP_ERR_ESPNOW_NO_MEM : out of memory + * - ESP_ERR_ESPNOW_NOT_FOUND : peer is not found + */ +esp_err_t esp_now_send(const uint8_t *peer_addr, const uint8_t *data, size_t len); + +/** + * @brief Add a peer to peer list + * + * @param peer peer information + * + * @return + * - ESP_OK : succeed + * - ESP_ERR_ESPNOW_NOT_INIT : ESPNOW is not initialized + * - ESP_ERR_ESPNOW_ARG : invalid argument + * - ESP_ERR_ESPNOW_FULL : peer list is full + * - ESP_ERR_ESPNOW_NO_MEM : out of memory + * - ESP_ERR_ESPNOW_EXIST : peer has existed + */ +esp_err_t esp_now_add_peer(const esp_now_peer_info_t *peer); + +/** + * @brief Delete a peer from peer list + * + * @param peer_addr peer MAC address + * + * @return + * - ESP_OK : succeed + * - ESP_ERR_ESPNOW_NOT_INIT : ESPNOW is not initialized + * - ESP_ERR_ESPNOW_ARG : invalid argument + * - ESP_ERR_ESPNOW_NOT_FOUND : peer is not found + */ +esp_err_t esp_now_del_peer(const uint8_t *peer_addr); + +/** + * @brief Modify a peer + * + * @param peer peer information + * + * @return + * - ESP_OK : succeed + * - ESP_ERR_ESPNOW_NOT_INIT : ESPNOW is not initialized + * - ESP_ERR_ESPNOW_ARG : invalid argument + * - ESP_ERR_ESPNOW_FULL : peer list is full + */ +esp_err_t esp_now_mod_peer(const esp_now_peer_info_t *peer); + +/** + * @brief Get a peer whose MAC address matches peer_addr from peer list + * + * @param peer_addr peer MAC address + * @param peer peer information + * + * @return + * - ESP_OK : succeed + * - ESP_ERR_ESPNOW_NOT_INIT : ESPNOW is not initialized + * - ESP_ERR_ESPNOW_ARG : invalid argument + * - ESP_ERR_ESPNOW_NOT_FOUND : peer is not found + */ +esp_err_t esp_now_get_peer(const uint8_t *peer_addr, esp_now_peer_info_t *peer); + +/** + * @brief Fetch a peer from peer list + * + * @param from_head fetch from head of list or not + * @param peer peer information + * + * @return + * - ESP_OK : succeed + * - ESP_ERR_ESPNOW_NOT_INIT : ESPNOW is not initialized + * - ESP_ERR_ESPNOW_ARG : invalid argument + * - ESP_ERR_ESPNOW_NOT_FOUND : peer is not found + */ +esp_err_t esp_now_fetch_peer(bool from_head, esp_now_peer_info_t *peer); + +/** + * @brief Peer exists or not + * + * @param peer_addr peer MAC address + * + * @return + * - true : peer exists + * - false : peer not exists + */ +bool esp_now_is_peer_exist(const uint8_t *peer_addr); + +/** + * @brief Get the number of peers + * + * @param num number of peers + * + * @return + * - ESP_OK : succeed + * - ESP_ERR_ESPNOW_NOT_INIT : ESPNOW is not initialized + * - ESP_ERR_ESPNOW_ARG : invalid argument + */ +esp_err_t esp_now_get_peer_num(esp_now_peer_num_t *num); + +/** + * @brief Set the primary master key + * + * @param pmk primary master key + * + * @attention 1. primary master key is used to encrypt local master key + * + * @return + * - ESP_OK : succeed + * - ESP_ERR_ESPNOW_NOT_INIT : ESPNOW is not initialized + * - ESP_ERR_ESPNOW_ARG : invalid argument + */ +esp_err_t esp_now_set_pmk(const uint8_t *pmk); + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __ESP_NOW_H__ */ diff --git a/tools/sdk/include/esp32/esp_phy_init.h b/tools/sdk/include/esp32/esp_phy_init.h index 347d8acaca9..1184c4e8dcc 100644 --- a/tools/sdk/include/esp32/esp_phy_init.h +++ b/tools/sdk/include/esp32/esp_phy_init.h @@ -30,112 +30,7 @@ extern "C" { * @brief Structure holding PHY init parameters */ typedef struct { - uint8_t param_ver_id; /*!< init_data structure version */ - uint8_t crystal_select; /*!< 0: 40MHz, 1: 26 MHz, 2: 24 MHz, 3: auto */ - uint8_t wifi_rx_gain_swp_step_1; /*!< do not change */ - uint8_t wifi_rx_gain_swp_step_2; /*!< do not change */ - uint8_t wifi_rx_gain_swp_step_3; /*!< do not change */ - uint8_t wifi_rx_gain_swp_step_4; /*!< do not change */ - uint8_t wifi_rx_gain_swp_step_5; /*!< do not change */ - uint8_t wifi_rx_gain_swp_step_6; /*!< do not change */ - uint8_t wifi_rx_gain_swp_step_7; /*!< do not change */ - uint8_t wifi_rx_gain_swp_step_8; /*!< do not change */ - uint8_t wifi_rx_gain_swp_step_9; /*!< do not change */ - uint8_t wifi_rx_gain_swp_step_10; /*!< do not change */ - uint8_t wifi_rx_gain_swp_step_11; /*!< do not change */ - uint8_t wifi_rx_gain_swp_step_12; /*!< do not change */ - uint8_t wifi_rx_gain_swp_step_13; /*!< do not change */ - uint8_t wifi_rx_gain_swp_step_14; /*!< do not change */ - uint8_t wifi_rx_gain_swp_step_15; /*!< do not change */ - uint8_t bt_rx_gain_swp_step_1; /*!< do not change */ - uint8_t bt_rx_gain_swp_step_2; /*!< do not change */ - uint8_t bt_rx_gain_swp_step_3; /*!< do not change */ - uint8_t bt_rx_gain_swp_step_4; /*!< do not change */ - uint8_t bt_rx_gain_swp_step_5; /*!< do not change */ - uint8_t bt_rx_gain_swp_step_6; /*!< do not change */ - uint8_t bt_rx_gain_swp_step_7; /*!< do not change */ - uint8_t bt_rx_gain_swp_step_8; /*!< do not change */ - uint8_t bt_rx_gain_swp_step_9; /*!< do not change */ - uint8_t bt_rx_gain_swp_step_10; /*!< do not change */ - uint8_t bt_rx_gain_swp_step_11; /*!< do not change */ - uint8_t bt_rx_gain_swp_step_12; /*!< do not change */ - uint8_t bt_rx_gain_swp_step_13; /*!< do not change */ - uint8_t bt_rx_gain_swp_step_14; /*!< do not change */ - uint8_t bt_rx_gain_swp_step_15; /*!< do not change */ - uint8_t gain_cmp_1; /*!< do not change */ - uint8_t gain_cmp_6; /*!< do not change */ - uint8_t gain_cmp_11; /*!< do not change */ - uint8_t gain_cmp_ext2_1; /*!< do not change */ - uint8_t gain_cmp_ext2_6; /*!< do not change */ - uint8_t gain_cmp_ext2_11; /*!< do not change */ - uint8_t gain_cmp_ext3_1; /*!< do not change */ - uint8_t gain_cmp_ext3_6; /*!< do not change */ - uint8_t gain_cmp_ext3_11; /*!< do not change */ - uint8_t gain_cmp_bt_ofs_1; /*!< do not change */ - uint8_t gain_cmp_bt_ofs_6; /*!< do not change */ - uint8_t gain_cmp_bt_ofs_11; /*!< do not change */ - uint8_t target_power_qdb_0; /*!< 78 means target power is 78/4=19.5dbm */ - uint8_t target_power_qdb_1; /*!< 76 means target power is 76/4=19dbm */ - uint8_t target_power_qdb_2; /*!< 74 means target power is 74/4=18.5dbm */ - uint8_t target_power_qdb_3; /*!< 68 means target power is 68/4=17dbm */ - uint8_t target_power_qdb_4; /*!< 64 means target power is 64/4=16dbm */ - uint8_t target_power_qdb_5; /*!< 52 means target power is 52/4=13dbm */ - uint8_t target_power_index_mcs0; /*!< target power index is 0, means target power is target_power_qdb_0 19.5dbm; (1m,2m,5.5m,11m,6m,9m) */ - uint8_t target_power_index_mcs1; /*!< target power index is 0, means target power is target_power_qdb_0 19.5dbm; (12m) */ - uint8_t target_power_index_mcs2; /*!< target power index is 1, means target power is target_power_qdb_1 19dbm; (18m) */ - uint8_t target_power_index_mcs3; /*!< target power index is 1, means target power is target_power_qdb_1 19dbm; (24m) */ - uint8_t target_power_index_mcs4; /*!< target power index is 2, means target power is target_power_qdb_2 18.5dbm; (36m) */ - uint8_t target_power_index_mcs5; /*!< target power index is 3, means target power is target_power_qdb_3 17dbm; (48m) */ - uint8_t target_power_index_mcs6; /*!< target power index is 4, means target power is target_power_qdb_4 16dbm; (54m) */ - uint8_t target_power_index_mcs7; /*!< target power index is 5, means target power is target_power_qdb_5 13dbm */ - uint8_t pwr_ind_11b_en; /*!< 0: 11b power is same as mcs0 and 6m, 1: 11b power different with OFDM */ - uint8_t pwr_ind_11b_0; /*!< 1m, 2m power index [0~5] */ - uint8_t pwr_ind_11b_1; /*!< 5.5m, 11m power index [0~5] */ - uint8_t chan_backoff_en; /*!< 0: channel backoff disable, 1:channel backoff enable */ - uint8_t chan1_power_backoff_qdb; /*!< 4 means backoff is 1db */ - uint8_t chan2_power_backoff_qdb; /*!< see chan1_power_backoff_qdb */ - uint8_t chan3_power_backoff_qdb; /*!< chan1_power_backoff_qdb */ - uint8_t chan4_power_backoff_qdb; /*!< chan1_power_backoff_qdb */ - uint8_t chan5_power_backoff_qdb; /*!< chan1_power_backoff_qdb */ - uint8_t chan6_power_backoff_qdb; /*!< chan1_power_backoff_qdb */ - uint8_t chan7_power_backoff_qdb; /*!< chan1_power_backoff_qdb */ - uint8_t chan8_power_backoff_qdb; /*!< chan1_power_backoff_qdb */ - uint8_t chan9_power_backoff_qdb; /*!< chan1_power_backoff_qdb */ - uint8_t chan10_power_backoff_qdb; /*!< chan1_power_backoff_qdb */ - uint8_t chan11_power_backoff_qdb; /*!< chan1_power_backoff_qdb */ - uint8_t chan12_power_backoff_qdb; /*!< chan1_power_backoff_qdb */ - uint8_t chan13_power_backoff_qdb; /*!< chan1_power_backoff_qdb */ - uint8_t chan14_power_backoff_qdb; /*!< chan1_power_backoff_qdb */ - uint8_t chan1_rate_backoff_index; /*!< if bit i is set, backoff data rate is target_power_qdb_i */ - uint8_t chan2_rate_backoff_index; /*!< see chan1_rate_backoff_index */ - uint8_t chan3_rate_backoff_index; /*!< see chan1_rate_backoff_index */ - uint8_t chan4_rate_backoff_index; /*!< see chan1_rate_backoff_index */ - uint8_t chan5_rate_backoff_index; /*!< see chan1_rate_backoff_index */ - uint8_t chan6_rate_backoff_index; /*!< see chan1_rate_backoff_index */ - uint8_t chan7_rate_backoff_index; /*!< see chan1_rate_backoff_index */ - uint8_t chan8_rate_backoff_index; /*!< see chan1_rate_backoff_index */ - uint8_t chan9_rate_backoff_index; /*!< see chan1_rate_backoff_index */ - uint8_t chan10_rate_backoff_index; /*!< see chan1_rate_backoff_index */ - uint8_t chan11_rate_backoff_index; /*!< see chan1_rate_backoff_index */ - uint8_t chan12_rate_backoff_index; /*!< see chan1_rate_backoff_index */ - uint8_t chan13_rate_backoff_index; /*!< see chan1_rate_backoff_index */ - uint8_t chan14_rate_backoff_index; /*!< see chan1_rate_backoff_index */ - uint8_t spur_freq_cfg_msb_1; /*!< first spur: */ - uint8_t spur_freq_cfg_1; /*!< spur_freq_cfg = (spur_freq_cfg_msb_1 <<8) | spur_freq_cfg_1 */ - uint8_t spur_freq_cfg_div_1; /*!< spur_freq=spur_freq_cfg/spur_freq_cfg_div_1 */ - uint8_t spur_freq_en_h_1; /*!< the seventh bit for total enable */ - uint8_t spur_freq_en_l_1; /*!< each bit for 1 channel, and use [spur_freq_en_h, spur_freq_en_l] to select the spur's channel priority */ - uint8_t spur_freq_cfg_msb_2; /*!< second spur: */ - uint8_t spur_freq_cfg_2; /*!< spur_freq_cfg = (spur_freq_cfg_msb_2 <<8) | spur_freq_cfg_2 */ - uint8_t spur_freq_cfg_div_2; /*!< spur_freq=spur_freq_cfg/spur_freq_cfg_div_2 */ - uint8_t spur_freq_en_h_2; /*!< the seventh bit for total enable */ - uint8_t spur_freq_en_l_2; /*!< each bit for 1 channel, and use [spur_freq_en_h, spur_freq_en_l] to select the spur's channel priority */ - uint8_t spur_freq_cfg_msb_3; /*!< third spur: */ - uint8_t spur_freq_cfg_3; /*!< spur_freq_cfg = (spur_freq_cfg_msb_3 <<8) | spur_freq_cfg_3 */ - uint8_t spur_freq_cfg_div_3; /*!< spur_freq=spur_freq_cfg/spur_freq_cfg_div_3 */ - uint8_t spur_freq_en_h_3; /*!< the seventh bit for total enable */ - uint8_t spur_freq_en_l_3; /*!< each bit for 1 channel, and use [spur_freq_en_h, spur_freq_en_l] to select the spur's channel priority, */ - uint8_t reserved[23]; /*!< reserved for future expansion */ + uint8_t params[128]; /*!< opaque PHY initialization parameters */ } esp_phy_init_data_t; /** diff --git a/tools/sdk/include/esp32/esp_pm.h b/tools/sdk/include/esp32/esp_pm.h new file mode 100644 index 00000000000..3887e77a921 --- /dev/null +++ b/tools/sdk/include/esp32/esp_pm.h @@ -0,0 +1,179 @@ +// Copyright 2016-2017 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. +// 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. + +#pragma once +#include +#include +#include "esp_err.h" + +// Include SoC-specific definitions. Only ESP32 supported for now. +#include "esp32/pm.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Power management constraints + */ +typedef enum { + /** + * Require CPU frequency to be at the maximum value set via esp_pm_configure. + * Argument is unused and should be set to 0. + */ + ESP_PM_CPU_FREQ_MAX, + /** + * Require APB frequency to be at the maximum value supported by the chip. + * Argument is unused and should be set to 0. + */ + ESP_PM_APB_FREQ_MAX, + /** + * Prevent the system from going into light sleep. + * Argument is unused and should be set to 0. + */ + ESP_PM_NO_LIGHT_SLEEP, +} esp_pm_lock_type_t; + +/** + * @brief Set implementation-specific power management configuration + * @param config pointer to implementation-specific configuration structure (e.g. esp_pm_config_esp32) + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG if the configuration values are not correct + * - ESP_ERR_NOT_SUPPORTED if certain combination of values is not supported, + * or if CONFIG_PM_ENABLE is not enabled in sdkconfig + */ +esp_err_t esp_pm_configure(const void* config); + + +/** + * @brief Opaque handle to the power management lock + */ +typedef struct esp_pm_lock* esp_pm_lock_handle_t; + + +/** + * @brief Initialize a lock handle for certain power management parameter + * + * When lock is created, initially it is not taken. + * Call esp_pm_lock_acquire to take the lock. + * + * This function must not be called from an ISR. + * + * @param lock_type Power management constraint which the lock should control + * @param arg argument, value depends on lock_type, see esp_pm_lock_type_t + * @param name arbitrary string identifying the lock (e.g. "wifi" or "spi"). + * Used by the esp_pm_dump_locks function to list existing locks. + * May be set to NULL. If not set to NULL, must point to a string which is valid + * for the lifetime of the lock. + * @param[out] out_handle handle returned from this function. Use this handle when calling + * esp_pm_lock_delete, esp_pm_lock_acquire, esp_pm_lock_release. + * Must not be NULL. + * @return + * - ESP_OK on success + * - ESP_ERR_NO_MEM if the lock structure can not be allocated + * - ESP_ERR_INVALID_ARG if out_handle is NULL or type argument is not valid + * - ESP_ERR_NOT_SUPPORTED if CONFIG_PM_ENABLE is not enabled in sdkconfig + */ +esp_err_t esp_pm_lock_create(esp_pm_lock_type_t lock_type, int arg, + const char* name, esp_pm_lock_handle_t* out_handle); + +/** + * @brief Take a power management lock + * + * Once the lock is taken, power management algorithm will not switch to the + * mode specified in a call to esp_pm_lock_create, or any of the lower power + * modes (higher numeric values of 'mode'). + * + * The lock is recursive, in the sense that if esp_pm_lock_acquire is called + * a number of times, esp_pm_lock_release has to be called the same number of + * times in order to release the lock. + * + * This function may be called from an ISR. + * + * This function is not thread-safe w.r.t. calls to other esp_pm_lock_* + * functions for the same handle. + * + * @param handle handle obtained from esp_pm_lock_create function + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG if the handle is invalid + * - ESP_ERR_NOT_SUPPORTED if CONFIG_PM_ENABLE is not enabled in sdkconfig + */ +esp_err_t esp_pm_lock_acquire(esp_pm_lock_handle_t handle); + +/** + * @brief Release the lock taken using esp_pm_lock_acquire. + * + * Call to this functions removes power management restrictions placed when + * taking the lock. + * + * Locks are recursive, so if esp_pm_lock_acquire is called a number of times, + * esp_pm_lock_release has to be called the same number of times in order to + * actually release the lock. + * + * This function may be called from an ISR. + * + * This function is not thread-safe w.r.t. calls to other esp_pm_lock_* + * functions for the same handle. + * + * @param handle handle obtained from esp_pm_lock_create function + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG if the handle is invalid + * - ESP_ERR_INVALID_STATE if lock is not acquired + * - ESP_ERR_NOT_SUPPORTED if CONFIG_PM_ENABLE is not enabled in sdkconfig + */ +esp_err_t esp_pm_lock_release(esp_pm_lock_handle_t handle); + +/** + * @brief Delete a lock created using esp_pm_lock + * + * The lock must be released before calling this function. + * + * This function must not be called from an ISR. + * + * @param handle handle obtained from esp_pm_lock_create function + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG if the handle argument is NULL + * - ESP_ERR_INVALID_STATE if the lock is still acquired + * - ESP_ERR_NOT_SUPPORTED if CONFIG_PM_ENABLE is not enabled in sdkconfig + */ +esp_err_t esp_pm_lock_delete(esp_pm_lock_handle_t handle); + +/** + * Dump the list of all locks to stderr + * + * This function dumps debugging information about locks created using + * esp_pm_lock_create to an output stream. + * + * This function must not be called from an ISR. If esp_pm_lock_acquire/release + * are called while this function is running, inconsistent results may be + * reported. + * + * @param stream stream to print information to; use stdout or stderr to print + * to the console; use fmemopen/open_memstream to print to a + * string buffer. + * @return + * - ESP_OK on success + * - ESP_ERR_NOT_SUPPORTED if CONFIG_PM_ENABLE is not enabled in sdkconfig + */ +esp_err_t esp_pm_dump_locks(FILE* stream); + + + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/include/esp32/esp_spiram.h b/tools/sdk/include/esp32/esp_spiram.h index 2eb9c08e5f3..9663dcddcbd 100644 --- a/tools/sdk/include/esp32/esp_spiram.h +++ b/tools/sdk/include/esp32/esp_spiram.h @@ -27,6 +27,17 @@ */ esp_err_t esp_spiram_init(); +/** + * @brief Configure Cache/MMU for access to external SPI RAM. + * + * Normally this function is called from cpu_start, if CONFIG_SPIRAM_BOOT_INIT + * option is enabled. Applications which need to enable SPI RAM at run time + * can disable CONFIG_SPIRAM_BOOT_INIT, and call this function later. + * + * @attention this function must be called with flash cache disabled. + */ +void esp_spiram_init_cache(); + /** * @brief Memory test for SPI RAM. Should be called after SPI RAM is initialized and @@ -39,6 +50,12 @@ esp_err_t esp_spiram_init(); bool esp_spiram_test(); +/** + * @brief Add the initialized SPI RAM to the heap allocator. + */ +esp_err_t esp_spiram_add_to_heapalloc(); + + /** * @brief Get the size of the attached SPI RAM chip selected in menuconfig * @@ -58,4 +75,16 @@ void esp_spiram_writeback_cache(); -#endif \ No newline at end of file +/** + * @brief Reserve a pool of internal memory for specific DMA/internal allocations + * + * @param size Size of reserved pool in bytes + * + * @return + * - ESP_OK on success + * - ESP_ERR_NO_MEM when no memory available for pool + */ +esp_err_t esp_spiram_reserve_dma_pool(size_t size); + + +#endif diff --git a/tools/sdk/include/esp32/esp_timer.h b/tools/sdk/include/esp32/esp_timer.h new file mode 100644 index 00000000000..e3e8b481286 --- /dev/null +++ b/tools/sdk/include/esp32/esp_timer.h @@ -0,0 +1,226 @@ +// Copyright 2017 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. +// 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. + +#pragma once + +/** + * @file esp_timer.h + * @brief microsecond-precision 64-bit timer API, replacement for ets_timer + * + * esp_timer APIs allow components to receive callbacks when a hardware timer + * reaches certain value. The timer provides microsecond accuracy and + * up to 64 bit range. Note that while the timer itself provides microsecond + * accuracy, callbacks are dispatched from an auxiliary task. Some time is + * needed to notify this task from timer ISR, and then to invoke the callback. + * If more than one callback needs to be dispatched at any particular time, + * each subsequent callback will be dispatched only when the previous callback + * returns. Therefore, callbacks should not do much work; instead, they should + * use RTOS notification mechanisms (queues, semaphores, event groups, etc.) to + * pass information to other tasks. + * + * It should be possible to request the callback to be called + * directly from the ISR. This reduces the latency, but has potential impact on + * all other callbacks which need to be dispatched. This option should only be + * used for simple callback functions, which do not take longer than a few + * microseconds to run. + * + * Implementation note: on the ESP32, esp_timer APIs use the "legacy" FRC2 + * timer. Timer callbacks are called from a task running on the PRO CPU. + */ + +#include +#include +#include "esp_err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Opaque type representing a single esp_timer + */ +typedef struct esp_timer* esp_timer_handle_t; + +/** + * @brief Timer callback function type + * @param arg pointer to opaque user-specific data + */ +typedef void (*esp_timer_cb_t)(void* arg); + + +/** + * @brief Method for dispatching timer callback + */ +typedef enum { + ESP_TIMER_TASK, //!< Callback is called from timer task + + /* Not supported for now, provision to allow callbacks to run directly + * from an ISR: + + ESP_TIMER_ISR, //!< Callback is called from timer ISR + + */ +} esp_timer_dispatch_t; + +/** + * @brief Timer configuration passed to esp_timer_create + */ +typedef struct { + esp_timer_cb_t callback; //!< Function to call when timer expires + void* arg; //!< Argument to pass to the callback + esp_timer_dispatch_t dispatch_method; //!< Call the callback from task or from ISR + const char* name; //!< Timer name, used in esp_timer_dump function +} esp_timer_create_args_t; + +/** + * @brief Initialize esp_timer library + * + * @note This function is called from startup code. Applications do not need + * to call this function before using other esp_timer APIs. + * + * @return + * - ESP_OK on success + * - ESP_ERR_NO_MEM if allocation has failed + * - ESP_ERR_INVALID_STATE if already initialized + * - other errors from interrupt allocator + */ +esp_err_t esp_timer_init(); + +/** + * @brief De-initialize esp_timer library + * + * @note Normally this function should not be called from applications + * + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_STATE if not yet initialized + */ +esp_err_t esp_timer_deinit(); + +/** + * @brief Create an esp_timer instance + * + * @note When done using the timer, delete it with esp_timer_delete function. + * + * @param create_args Pointer to a structure with timer creation arguments. + * Not saved by the library, can be allocated on the stack. + * @param[out] out_handle Output, pointer to esp_timer_handle_t variable which + * will hold the created timer handle. + * + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG if some of the create_args are not valid + * - ESP_ERR_INVALID_STATE if esp_timer library is not initialized yet + * - ESP_ERR_NO_MEM if memory allocation fails + */ +esp_err_t esp_timer_create(const esp_timer_create_args_t* create_args, + esp_timer_handle_t* out_handle); + +/** + * @brief Start one-shot timer + * + * Timer should not be running when this function is called. + * + * @param timer timer handle created using esp_timer_create + * @param timeout_us timer timeout, in microseconds relative to the current moment + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG if the handle is invalid + * - ESP_ERR_INVALID_STATE if the timer is already running + */ +esp_err_t esp_timer_start_once(esp_timer_handle_t timer, uint64_t timeout_us); + +/** + * @brief Start a periodic timer + * + * Timer should not be running when this function is called. This function will + * start the timer which will trigger every 'period' microseconds. + * + * @param timer timer handle created using esp_timer_create + * @param period timer period, in microseconds + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG if the handle is invalid + * - ESP_ERR_INVALID_STATE if the timer is already running + */ +esp_err_t esp_timer_start_periodic(esp_timer_handle_t timer, uint64_t period); + +/** + * @brief Stop the timer + * + * This function stops the timer previously started using esp_timer_start_once + * or esp_timer_start_periodic. + * + * @param timer timer handle created using esp_timer_create + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_STATE if the timer is not running + */ +esp_err_t esp_timer_stop(esp_timer_handle_t timer); + +/** + * @brief Delete an esp_timer instance + * + * The timer must be stopped before deleting. A one-shot timer which has expired + * does not need to be stopped. + * + * @param timer timer handle allocated using esp_timer_create + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_STATE if the timer is not running + */ +esp_err_t esp_timer_delete(esp_timer_handle_t timer); + +/** + * @brief Get time in microseconds since boot + * @return number of microseconds since esp_timer_init was called (this normally + * happens early during application startup). + */ +int64_t esp_timer_get_time(); + +/** + * @brief Dump the list of timers to a stream + * + * If CONFIG_ESP_TIMER_PROFILING option is enabled, this prints the list of all + * the existing timers. Otherwise, only the list active timers is printed. + * + * The format is: + * + * name period alarm times_armed times_triggered total_callback_run_time + * + * where: + * + * name — timer name (if CONFIG_ESP_TIMER_PROFILING is defined), or timer pointer + * period — period of timer, in microseconds, or 0 for one-shot timer + * alarm - time of the next alarm, in microseconds since boot, or 0 if the timer + * is not started + * + * The following fields are printed if CONFIG_ESP_TIMER_PROFILING is defined: + * + * times_armed — number of times the timer was armed via esp_timer_start_X + * times_triggered - number of times the callback was called + * total_callback_run_time - total time taken by callback to execute, across all calls + * + * @param stream stream (such as stdout) to dump the information to + * @return + * - ESP_OK on success + * - ESP_ERR_NO_MEM if can not allocate temporary buffer for the output + */ +esp_err_t esp_timer_dump(FILE* stream); + + +#ifdef __cplusplus +} +#endif + diff --git a/tools/sdk/include/esp32/esp_wifi.h b/tools/sdk/include/esp32/esp_wifi.h index 7bfa96379ee..0ae0644eaf5 100755 --- a/tools/sdk/include/esp32/esp_wifi.h +++ b/tools/sdk/include/esp32/esp_wifi.h @@ -181,14 +181,14 @@ extern const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs; * which are set by WIFI_INIT_CONFIG_DEFAULT, please be notified that the field 'magic' of * wifi_init_config_t should always be WIFI_INIT_CONFIG_MAGIC! * - * @param config provide WiFi init configuration + * @param config pointer to WiFi init configuration structure; can point to a temporary variable. * * @return * - ESP_OK: succeed * - ESP_ERR_WIFI_NO_MEM: out of memory * - others: refer to error code esp_err.h */ -esp_err_t esp_wifi_init(wifi_init_config_t *config); +esp_err_t esp_wifi_init(const wifi_init_config_t *config); /** * @brief Deinit WiFi @@ -341,7 +341,7 @@ esp_err_t esp_wifi_deauth_sta(uint16_t aid); * - ESP_ERR_WIFI_TIMEOUT: blocking scan is timeout * - others: refer to error code in esp_err.h */ -esp_err_t esp_wifi_scan_start(wifi_scan_config_t *config, bool block); +esp_err_t esp_wifi_scan_start(const wifi_scan_config_t *config, bool block); /** * @brief Stop the scan in process @@ -517,23 +517,34 @@ esp_err_t esp_wifi_set_channel(uint8_t primary, wifi_second_chan_t second); esp_err_t esp_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second); /** - * @brief Set country code - * The default value is WIFI_COUNTRY_CN + * @brief configure country info * - * @param country country type + * @attention 1. The default country is {.cc="CN", .schan=1, .nchan=13, policy=WIFI_COUNTRY_POLICY_AUTO} + * @attention 2. When the country policy is WIFI_COUNTRY_POLICY_AUTO, use the country info of AP to which + * the station is connected. E.g. if the configured country info is {.cc="USA", .schan=1, .nchan=11}, + * the country info of the AP to which the station is connected is {.cc="JP", .schan=1, .nchan=14}, + * then our country info is {.cc="JP", .schan=1, .nchan=14}. If the station disconnected + * from the AP, the country info back to {.cc="USA", .schan=1, .nchan=11} again. + * @attention 3. When the country policy is WIFI_COUNTRY_POLICY_MANUAL, always use the configured country info. + * @attention 4. When the country info is changed because of configuration or because the station connects to a different + * external AP, the country IE in probe response/beacon of the soft-AP is changed also. + * @attention 5. The country configuration is not stored into flash + * @attention 6. This API doesn't validate the per-country rules, it's up to the user to fill in all fields according to + * local regulations. + * + * @param country the configured country info * * @return * - ESP_OK: succeed * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init * - ESP_ERR_WIFI_ARG: invalid argument - * - others: refer to error code in esp_err.h */ -esp_err_t esp_wifi_set_country(wifi_country_t country); +esp_err_t esp_wifi_set_country(const wifi_country_t *country); /** - * @brief Get country code + * @brief get the current country info * - * @param country store current country + * @param country country info * * @return * - ESP_OK: succeed @@ -542,6 +553,7 @@ esp_err_t esp_wifi_set_country(wifi_country_t country); */ esp_err_t esp_wifi_get_country(wifi_country_t *country); + /** * @brief Set MAC address of the ESP32 WiFi station or the soft-AP interface. * @@ -562,7 +574,7 @@ esp_err_t esp_wifi_get_country(wifi_country_t *country); * - ESP_ERR_WIFI_MODE: WiFi mode is wrong * - others: refer to error codes in esp_err.h */ -esp_err_t esp_wifi_set_mac(wifi_interface_t ifx, uint8_t mac[6]); +esp_err_t esp_wifi_set_mac(wifi_interface_t ifx, const uint8_t mac[6]); /** * @brief Get mac of specified interface @@ -670,7 +682,7 @@ esp_err_t esp_wifi_get_promiscuous_filter(wifi_promiscuous_filter_t *filter); * - ESP_ERR_WIFI_NVS: WiFi internal NVS error * - others: refer to the erro code in esp_err.h */ -esp_err_t esp_wifi_set_config(wifi_interface_t ifx, wifi_config_t *conf); +esp_err_t esp_wifi_set_config(wifi_interface_t ifx, const wifi_config_t *conf); /** * @brief Get configuration of specified interface diff --git a/tools/sdk/include/esp32/esp_wifi_internal.h b/tools/sdk/include/esp32/esp_wifi_internal.h index 6627636df04..ed636ba67be 100644 --- a/tools/sdk/include/esp32/esp_wifi_internal.h +++ b/tools/sdk/include/esp32/esp_wifi_internal.h @@ -58,7 +58,7 @@ extern "C" { * - ESP_ERR_WIFI_NO_MEM: out of memory * - others: refer to error code esp_err.h */ -esp_err_t esp_wifi_init_internal(wifi_init_config_t *config); +esp_err_t esp_wifi_init_internal(const wifi_init_config_t *config); /** * @brief get whether the wifi driver is allowed to transmit data or not @@ -121,6 +121,41 @@ esp_err_t esp_wifi_internal_reg_rxcb(wifi_interface_t ifx, wifi_rxcb_t fn); */ esp_err_t esp_wifi_internal_set_sta_ip(void); +/** + * @brief Allocate a chunk of memory for WiFi driver + * + * @attention This API is not used for DMA memory allocation. + * + * @param size_t size : Size, in bytes, of the amount of memory to allocate + * + * @return A pointer to the memory allocated on success, NULL on failure + */ +void *wifi_malloc( size_t size ); + +/** + * @brief Reallocate a chunk of memory for WiFi driver + * + * @attention This API is not used for DMA memory allocation. + * + * @param void * ptr : Pointer to previously allocated memory, or NULL for a new allocation. + * @param size_t size : Size, in bytes, of the amount of memory to allocate + * + * @return A pointer to the memory allocated on success, NULL on failure + */ +void *wifi_realloc( void *ptr, size_t size ); + +/** + * @brief Callocate memory for WiFi driver + * + * @attention This API is not used for DMA memory allocation. + * + * @param size_t n : Number of continuing chunks of memory to allocate + * @param size_t size : Size, in bytes, of the amount of memory to allocate + * + * @return A pointer to the memory allocated on success, NULL on failure + */ +void *wifi_calloc( size_t n, size_t size ); + #ifdef __cplusplus } #endif diff --git a/tools/sdk/include/esp32/esp_wifi_types.h b/tools/sdk/include/esp32/esp_wifi_types.h index 2410b73ce1c..61161037ceb 100755 --- a/tools/sdk/include/esp32/esp_wifi_types.h +++ b/tools/sdk/include/esp32/esp_wifi_types.h @@ -40,11 +40,15 @@ typedef esp_interface_t wifi_interface_t; #define WIFI_IF_AP ESP_IF_WIFI_AP typedef enum { - WIFI_COUNTRY_CN = 0, /**< country China, channel range [1, 14] */ - WIFI_COUNTRY_JP, /**< country Japan, channel range [1, 14] */ - WIFI_COUNTRY_US, /**< country USA, channel range [1, 11] */ - WIFI_COUNTRY_EU, /**< country Europe, channel range [1, 13] */ - WIFI_COUNTRY_MAX + WIFI_COUNTRY_POLICY_AUTO, /**< Country policy is auto, use the country info of AP to which the station is connected */ + WIFI_COUNTRY_POLICY_MANUAL, /**< Country policy is manual, always use the configured country info */ +} wifi_country_policy_t; + +typedef struct { + char cc[3]; /**< country code string */ + uint8_t schan; /**< start channel */ + uint8_t nchan; /**< total channel number */ + wifi_country_policy_t policy; /**< country policy */ } wifi_country_t; typedef enum { @@ -121,6 +125,16 @@ typedef struct { wifi_scan_time_t scan_time; /**< scan time per channel */ } wifi_scan_config_t; +typedef enum { + WIFI_CIPHER_TYPE_NONE = 0, /**< the cipher type is none */ + WIFI_CIPHER_TYPE_WEP40, /**< the cipher type is WEP40 */ + WIFI_CIPHER_TYPE_WEP104, /**< the cipher type is WEP104 */ + WIFI_CIPHER_TYPE_TKIP, /**< the cipher type is TKIP */ + WIFI_CIPHER_TYPE_CCMP, /**< the cipher type is CCMP */ + WIFI_CIPHER_TYPE_TKIP_CCMP, /**< the cipher type is TKIP and CCMP */ + WIFI_CIPHER_TYPE_UNKNOWN, /**< the cipher type is unknown */ +} wifi_cipher_type_t; + typedef struct { uint8_t bssid[6]; /**< MAC address of AP */ uint8_t ssid[33]; /**< SSID of AP */ @@ -128,10 +142,31 @@ typedef struct { wifi_second_chan_t second; /**< second channel of AP */ int8_t rssi; /**< signal strength of AP */ wifi_auth_mode_t authmode; /**< authmode of AP */ - uint32_t low_rate_enable:1; /**< bit: 0 flag to identify if low rate is enabled or not */ - uint32_t reserved:31; /**< bit: 1..31 reserved */ + wifi_cipher_type_t pairwise_cipher; /**< pairwise cipher of AP */ + wifi_cipher_type_t group_cipher; /**< group cipher of AP */ + uint32_t phy_11b:1; /**< bit: 0 flag to identify if 11b mode is enabled or not */ + uint32_t phy_11g:1; /**< bit: 1 flag to identify if 11g mode is enabled or not */ + uint32_t phy_11n:1; /**< bit: 2 flag to identify if 11n mode is enabled or not */ + uint32_t phy_lr:1; /**< bit: 3 flag to identify if low rate is enabled or not */ + uint32_t wps:1; /**< bit: 4 flag to identify if WPS is supported or not */ + uint32_t reserved:27; /**< bit: 5..31 reserved */ } wifi_ap_record_t; +typedef enum { + WIFI_FAST_SCAN = 0, /**< Do fast scan, scan will end after find SSID match AP */ + WIFI_ALL_CHANNEL_SCAN, /**< All channel scan, scan will end after scan all the channel */ +}wifi_scan_method_t; + +typedef enum { + WIFI_CONNECT_AP_BY_SIGNAL = 0, /**< Sort match AP in scan list by RSSI */ + WIFI_CONNECT_AP_BY_SECURITY, /**< Sort match AP in scan list by security mode */ +}wifi_sort_method_t; + +typedef struct { + int8_t rssi; /**< The minimum rssi to accept in the fast scan mode */ + wifi_auth_mode_t authmode; /**< The weakest authmode to accept in the fast scan mode */ +}wifi_fast_scan_threshold_t; + typedef enum { WIFI_PS_NONE, /**< No power save */ WIFI_PS_MODEM, /**< Modem power save */ @@ -161,9 +196,12 @@ typedef struct { typedef struct { uint8_t ssid[32]; /**< SSID of target AP*/ uint8_t password[64]; /**< password of target AP*/ + wifi_scan_method_t scan_method; /**< do all channel scan or fast scan */ bool bssid_set; /**< whether set MAC address of target AP or not. Generally, station_config.bssid_set needs to be 0; and it needs to be 1 only when users need to check the MAC address of the AP.*/ uint8_t bssid[6]; /**< MAC address of target AP*/ uint8_t channel; /**< channel of target AP. Set to 1~13 to scan starting from the specified channel before connecting to AP. If the channel of AP is unknown, set it to 0.*/ + wifi_sort_method_t sort_method; /**< sort the connect AP in the list by rssi or security mode */ + wifi_fast_scan_threshold_t threshold; /**< When scan_method is set to WIFI_FAST_SCAN, only APs which have an auth mode that is more secure than the selected auth mode and a signal stronger than the minimum RSSI will be used. */ } wifi_sta_config_t; typedef union { diff --git a/tools/sdk/include/esp32/esp_wpa2.h b/tools/sdk/include/esp32/esp_wpa2.h index 6628bd1c906..c704e81c786 100644 --- a/tools/sdk/include/esp32/esp_wpa2.h +++ b/tools/sdk/include/esp32/esp_wpa2.h @@ -68,7 +68,7 @@ esp_err_t esp_wifi_sta_wpa2_ent_disable(void); * - ESP_ERR_WIFI_ARG: fail(len <= 0 or len >= 128) * - ESP_ERR_WIFI_NO_MEM: fail(internal memory malloc fail) */ -esp_err_t esp_wifi_sta_wpa2_ent_set_identity(unsigned char *identity, int len); +esp_err_t esp_wifi_sta_wpa2_ent_set_identity(const unsigned char *identity, int len); /** * @brief Clear identity for PEAP/TTLS method. @@ -88,7 +88,7 @@ void esp_wifi_sta_wpa2_ent_clear_identity(void); * - ESP_ERR_WIFI_ARG: fail(len <= 0 or len >= 128) * - ESP_ERR_WIFI_NO_MEM: fail(internal memory malloc fail) */ -esp_err_t esp_wifi_sta_wpa2_ent_set_username(unsigned char *username, int len); +esp_err_t esp_wifi_sta_wpa2_ent_set_username(const unsigned char *username, int len); /** * @brief Clear username for PEAP/TTLS method. @@ -108,7 +108,7 @@ void esp_wifi_sta_wpa2_ent_clear_username(void); * - ESP_ERR_WIFI_ARG: fail(len <= 0) * - ESP_ERR_WIFI_NO_MEM: fail(internal memory malloc fail) */ -esp_err_t esp_wifi_sta_wpa2_ent_set_password(unsigned char *password, int len); +esp_err_t esp_wifi_sta_wpa2_ent_set_password(const unsigned char *password, int len); /** * @brief Clear password for PEAP/TTLS method.. @@ -130,7 +130,7 @@ void esp_wifi_sta_wpa2_ent_clear_password(void); * - ESP_ERR_WIFI_NO_MEM: fail(internal memory malloc fail) */ -esp_err_t esp_wifi_sta_wpa2_ent_set_new_password(unsigned char *password, int len); +esp_err_t esp_wifi_sta_wpa2_ent_set_new_password(const unsigned char *password, int len); /** * @brief Clear new password for MSCHAPv2 method.. @@ -149,7 +149,7 @@ void esp_wifi_sta_wpa2_ent_clear_new_password(void); * @return * - ESP_ERR_WIFI_OK: succeed */ -esp_err_t esp_wifi_sta_wpa2_ent_set_ca_cert(unsigned char *ca_cert, int len); +esp_err_t esp_wifi_sta_wpa2_ent_set_ca_cert(const unsigned char *ca_cert, int len); /** * @brief Clear CA certificate for PEAP/TTLS method. @@ -172,7 +172,7 @@ void esp_wifi_sta_wpa2_ent_clear_ca_cert(void); * @return * - ESP_ERR_WIFI_OK: succeed */ -esp_err_t esp_wifi_sta_wpa2_ent_set_cert_key(unsigned char *client_cert, int client_cert_len, unsigned char *private_key, int private_key_len, unsigned char *private_key_passwd, int private_key_passwd_len); +esp_err_t esp_wifi_sta_wpa2_ent_set_cert_key(const unsigned char *client_cert, int client_cert_len, const unsigned char *private_key, int private_key_len, const unsigned char *private_key_passwd, int private_key_passwd_len); /** * @brief Clear client certificate and key. diff --git a/tools/sdk/include/esp_adc_cal/esp_adc_cal.h b/tools/sdk/include/esp_adc_cal/esp_adc_cal.h index 4a2d06a9535..adb6598496c 100644 --- a/tools/sdk/include/esp_adc_cal/esp_adc_cal.h +++ b/tools/sdk/include/esp_adc_cal/esp_adc_cal.h @@ -71,7 +71,7 @@ typedef struct { for uint32 arithmetic */ uint32_t offset; /** +#include "soc/soc_memory_layout.h" + //#include "xtensa_context.h" /*----------------------------------------------------------- @@ -123,9 +126,6 @@ typedef unsigned portBASE_TYPE UBaseType_t; #include "sdkconfig.h" #include "esp_attr.h" -#define portFIRST_TASK_HOOK CONFIG_FREERTOS_BREAK_ON_SCHEDULER_START_JTAG - - typedef struct { uint32_t owner; uint32_t count; @@ -203,7 +203,7 @@ void vPortCPUInitializeMutex(portMUX_TYPE *mux); #ifdef CONFIG_FREERTOS_PORTMUX_DEBUG void vPortCPUAcquireMutex(portMUX_TYPE *mux, const char *function, int line); bool vPortCPUAcquireMutexTimeout(portMUX_TYPE *mux, int timeout_cycles, const char *function, int line); -portBASE_TYPE vPortCPUReleaseMutex(portMUX_TYPE *mux, const char *function, int line); +void vPortCPUReleaseMutex(portMUX_TYPE *mux, const char *function, int line); void vTaskEnterCritical( portMUX_TYPE *mux, const char *function, int line ); @@ -245,6 +245,18 @@ static inline unsigned portENTER_CRITICAL_NESTED() { unsigned state = XTOS_SET_I #define portSET_INTERRUPT_MASK_FROM_ISR() portENTER_CRITICAL_NESTED() #define portCLEAR_INTERRUPT_MASK_FROM_ISR(state) portEXIT_CRITICAL_NESTED(state) +//Because the ROM routines don't necessarily handle a stack in external RAM correctly, we force +//the stack memory to always be internal. +#define pvPortMallocTcbMem(size) heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT) +#define pvPortMallocStackMem(size) heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT) + +//xTaskCreateStatic uses these functions to check incoming memory. +#define portVALID_TCB_MEM(ptr) (esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr)) +#ifndef CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY +#define portVALID_STACK_MEM(ptr) esp_ptr_byte_accessible(ptr) +#else +#define portVALID_STACK_MEM(ptr) (esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr)) +#endif /* * Wrapper for the Xtensa compare-and-set instruction. This subroutine will atomically compare diff --git a/tools/sdk/include/freertos/freertos/xtensa_rtos.h b/tools/sdk/include/freertos/freertos/xtensa_rtos.h index 980cc92e0d9..e5982b83a54 100644 --- a/tools/sdk/include/freertos/freertos/xtensa_rtos.h +++ b/tools/sdk/include/freertos/freertos/xtensa_rtos.h @@ -55,7 +55,7 @@ Should be included by all Xtensa generic and RTOS port-specific sources. /* Include any RTOS specific definitions that are needed by this header. */ -#include +#include "FreeRTOSConfig.h" /* Convert FreeRTOSConfig definitions to XTENSA definitions. diff --git a/tools/sdk/include/freertos/freertos/xtensa_timer.h b/tools/sdk/include/freertos/freertos/xtensa_timer.h index 9bb8648f692..fa4f96098c0 100644 --- a/tools/sdk/include/freertos/freertos/xtensa_timer.h +++ b/tools/sdk/include/freertos/freertos/xtensa_timer.h @@ -49,7 +49,7 @@ and the Xtensa core configuration need not have a timer. #include "xtensa_rtos.h" /* in case this wasn't included directly */ -#include +#include "FreeRTOSConfig.h" /* Select timer to use for periodic tick, and determine its interrupt number diff --git a/tools/sdk/include/heap/esp_heap_alloc_caps.h b/tools/sdk/include/heap/esp_heap_alloc_caps.h new file mode 100644 index 00000000000..f92e92e352a --- /dev/null +++ b/tools/sdk/include/heap/esp_heap_alloc_caps.h @@ -0,0 +1,35 @@ +// Copyright 2015-2016 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. +// 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. +#pragma once +#warning "This header is deprecated, please use functions defined in esp_heap_caps.h instead." +#include "esp_heap_caps.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Deprecated FreeRTOS-style esp_heap_alloc_caps.h functions follow */ + +/* Please use heap_caps_malloc() instead of this function */ +void *pvPortMallocCaps(size_t xWantedSize, uint32_t caps) asm("heap_caps_malloc") __attribute__((deprecated)); + +/* Please use heap_caps_get_minimum_free_heap_size() instead of this function */ +size_t xPortGetMinimumEverFreeHeapSizeCaps( uint32_t caps ) asm("heap_caps_get_minimum_free_heap_size") __attribute__((deprecated)); + +/* Please use heap_caps_get_free_size() instead of this function */ +size_t xPortGetFreeHeapSizeCaps( uint32_t caps ) asm("heap_caps_get_free_heap_size") __attribute__((deprecated)); + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/include/heap/esp_heap_caps.h b/tools/sdk/include/heap/esp_heap_caps.h new file mode 100644 index 00000000000..44822935286 --- /dev/null +++ b/tools/sdk/include/heap/esp_heap_caps.h @@ -0,0 +1,308 @@ +// Copyright 2015-2016 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. +// 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. +#pragma once + +#include +#include +#include "multi_heap.h" + +/** + * @brief Flags to indicate the capabilities of the various memory systems + */ +#define MALLOC_CAP_EXEC (1<<0) ///< Memory must be able to run executable code +#define MALLOC_CAP_32BIT (1<<1) ///< Memory must allow for aligned 32-bit data accesses +#define MALLOC_CAP_8BIT (1<<2) ///< Memory must allow for 8/16/...-bit data accesses +#define MALLOC_CAP_DMA (1<<3) ///< Memory must be able to accessed by DMA +#define MALLOC_CAP_PID2 (1<<4) ///< Memory must be mapped to PID2 memory space (PIDs are not currently used) +#define MALLOC_CAP_PID3 (1<<5) ///< Memory must be mapped to PID3 memory space (PIDs are not currently used) +#define MALLOC_CAP_PID4 (1<<6) ///< Memory must be mapped to PID4 memory space (PIDs are not currently used) +#define MALLOC_CAP_PID5 (1<<7) ///< Memory must be mapped to PID5 memory space (PIDs are not currently used) +#define MALLOC_CAP_PID6 (1<<8) ///< Memory must be mapped to PID6 memory space (PIDs are not currently used) +#define MALLOC_CAP_PID7 (1<<9) ///< Memory must be mapped to PID7 memory space (PIDs are not currently used) +#define MALLOC_CAP_SPIRAM (1<<10) ///< Memory must be in SPI RAM +#define MALLOC_CAP_INTERNAL (1<<11) ///< Memory must be internal; specifically it should not disappear when flash/spiram cache is switched off +#define MALLOC_CAP_DEFAULT (1<<12) ///< Memory can be returned in a non-capability-specific memory allocation (e.g. malloc(), calloc()) call +#define MALLOC_CAP_INVALID (1<<31) ///< Memory can't be used / list end marker + +/** + * @brief Allocate a chunk of memory which has the given capabilities + * + * Equivalent semantics to libc malloc(), for capability-aware memory. + * + * In IDF, ``malloc(p)`` is equivalent to ``heaps_caps_malloc(p, MALLOC_CAP_8BIT)``. + * + * @param size Size, in bytes, of the amount of memory to allocate + * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type + * of memory to be returned + * + * @return A pointer to the memory allocated on success, NULL on failure + */ +void *heap_caps_malloc(size_t size, uint32_t caps); + + +/** + * @brief Free memory previously allocated via heap_caps_malloc() or heap_caps_realloc(). + * + * Equivalent semantics to libc free(), for capability-aware memory. + * + * In IDF, ``free(p)`` is equivalent to ``heap_caps_free(p)``. + * + * @param ptr Pointer to memory previously returned from heap_caps_malloc() or heap_caps_realloc(). Can be NULL. + */ +void heap_caps_free( void *ptr); + +/** + * @brief Reallocate memory previously allocated via heaps_caps_malloc() or heaps_caps_realloc(). + * + * Equivalent semantics to libc realloc(), for capability-aware memory. + * + * In IDF, ``realloc(p, s)`` is equivalent to ``heap_caps_realloc(p, s, MALLOC_CAP_8BIT)``. + * + * 'caps' parameter can be different to the capabilities that any original 'ptr' was allocated with. In this way, + * realloc can be used to "move" a buffer if necessary to ensure it meets a new set of capabilities. + * + * @param ptr Pointer to previously allocated memory, or NULL for a new allocation. + * @param size Size of the new buffer requested, or 0 to free the buffer. + * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type + * of memory desired for the new allocation. + * + * @return Pointer to a new buffer of size 'size' with capabilities 'caps', or NULL if allocation failed. + */ +void *heap_caps_realloc( void *ptr, size_t size, int caps); + +/** + * @brief Allocate a chunk of memory which has the given capabilities. The initialized value in the memory is set to zero. + * + * Equivalent semantics to libc calloc(), for capability-aware memory. + * + * In IDF, ``calloc(p)`` is equivalent to ``heaps_caps_calloc(p, MALLOC_CAP_8BIT)``. + * + * @param n Number of continuing chunks of memory to allocate + * @param size Size, in bytes, of a chunk of memory to allocate + * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type + * of memory to be returned + * + * @return A pointer to the memory allocated on success, NULL on failure + */ +void *heap_caps_calloc(size_t n, size_t size, uint32_t caps); + +/** + * @brief Get the total free size of all the regions that have the given capabilities + * + * This function takes all regions capable of having the given capabilities allocated in them + * and adds up the free space they have. + * + * Note that because of heap fragmentation it is probably not possible to allocate a single block of memory + * of this size. Use heap_caps_get_largest_free_block() for this purpose. + + * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type + * of memory + * + * @return Amount of free bytes in the regions + */ +size_t heap_caps_get_free_size( uint32_t caps ); + + +/** + * @brief Get the total minimum free memory of all regions with the given capabilities + * + * This adds all the low water marks of the regions capable of delivering the memory + * with the given capabilities. + * + * Note the result may be less than the global all-time minimum available heap of this kind, as "low water marks" are + * tracked per-region. Individual regions' heaps may have reached their "low water marks" at different points in time. However + * this result still gives a "worst case" indication for all-time minimum free heap. + * + * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type + * of memory + * + * @return Amount of free bytes in the regions + */ +size_t heap_caps_get_minimum_free_size( uint32_t caps ); + +/** + * @brief Get the largest free block of memory able to be allocated with the given capabilities. + * + * Returns the largest value of ``s`` for which ``heap_caps_malloc(s, caps)`` will succeed. + * + * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type + * of memory + * + * @return Size of largest free block in bytes. + */ +size_t heap_caps_get_largest_free_block( uint32_t caps ); + + +/** + * @brief Get heap info for all regions with the given capabilities. + * + * Calls multi_heap_info() on all heaps which share the given capabilities. The information returned is an aggregate + * across all matching heaps. The meanings of fields are the same as defined for multi_heap_info_t, except that + * ``minimum_free_bytes`` has the same caveats described in heap_caps_get_minimum_free_size(). + * + * @param info Pointer to a structure which will be filled with relevant + * heap metadata. + * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type + * of memory + * + */ +void heap_caps_get_info( multi_heap_info_t *info, uint32_t caps ); + + +/** + * @brief Print a summary of all memory with the given capabilities. + * + * Calls multi_heap_info on all heaps which share the given capabilities, and + * prints a two-line summary for each, then a total summary. + * + * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type + * of memory + * + */ +void heap_caps_print_heap_info( uint32_t caps ); + +/** + * @brief Check integrity of all heap memory in the system. + * + * Calls multi_heap_check on all heaps. Optionally print errors if heaps are corrupt. + * + * Calling this function is equivalent to calling heap_caps_check_integrity + * with the caps argument set to MALLOC_CAP_INVALID. + * + * @param print_errors Print specific errors if heap corruption is found. + * + * @return True if all heaps are valid, False if at least one heap is corrupt. + */ +bool heap_caps_check_integrity_all(bool print_errors); + +/** + * @brief Check integrity of all heaps with the given capabilities. + * + * Calls multi_heap_check on all heaps which share the given capabilities. Optionally + * print errors if the heaps are corrupt. + * + * See also heap_caps_check_integrity_all to check all heap memory + * in the system and heap_caps_check_integrity_addr to check memory + * around a single address. + * + * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type + * of memory + * @param print_errors Print specific errors if heap corruption is found. + * + * @return True if all heaps are valid, False if at least one heap is corrupt. + */ +bool heap_caps_check_integrity(uint32_t caps, bool print_errors); + +/** + * @brief Check integrity of heap memory around a given address. + * + * This function can be used to check the integrity of a single region of heap memory, + * which contains the given address. + * + * This can be useful if debugging heap integrity for corruption at a known address, + * as it has a lower overhead than checking all heap regions. Note that if the corrupt + * address moves around between runs (due to timing or other factors) then this approach + * won't work and you should call heap_caps_check_integrity or + * heap_caps_check_integrity_all instead. + * + * @note The entire heap region around the address is checked, not only the adjacent + * heap blocks. + * + * @param addr Address in memory. Check for corruption in region containing this address. + * @param print_errors Print specific errors if heap corruption is found. + * + * @return True if the heap containing the specified address is valid, + * False if at least one heap is corrupt or the address doesn't belong to a heap region. + */ +bool heap_caps_check_integrity_addr(intptr_t addr, bool print_errors); + +/** + * @brief Enable malloc() in external memory and set limit below which + * malloc() attempts are placed in internal memory. + * + * When external memory is in use, the allocation strategy is to initially try to + * satisfy smaller allocation requests with internal memory and larger requests + * with external memory. This sets the limit between the two, as well as generally + * enabling allocation in external memory. + * + * @param limit Limit, in bytes. + */ +void heap_caps_malloc_extmem_enable(size_t limit); + +/** + * @brief Allocate a chunk of memory as preference in decreasing order. + * + * @attention The variable parameters are bitwise OR of MALLOC_CAP_* flags indicating the type of memory. + * This API prefers to allocate memory with the first parameter. If failed, allocate memory with + * the next parameter. It will try in this order until allocating a chunk of memory successfully + * or fail to allocate memories with any of the parameters. + * + * @param size Size, in bytes, of the amount of memory to allocate + * @param num Number of variable paramters + * + * @return A pointer to the memory allocated on success, NULL on failure + */ +void *heap_caps_malloc_prefer( size_t size, size_t num, ... ); + +/** + * @brief Allocate a chunk of memory as preference in decreasing order. + * + * @param ptr Pointer to previously allocated memory, or NULL for a new allocation. + * @param size Size of the new buffer requested, or 0 to free the buffer. + * @param num Number of variable paramters + * + * @return Pointer to a new buffer of size 'size', or NULL if allocation failed. + */ +void *heap_caps_realloc_prefer( void *ptr, size_t size, size_t num, ... ); + +/** + * @brief Allocate a chunk of memory as preference in decreasing order. + * + * @param n Number of continuing chunks of memory to allocate + * @param size Size, in bytes, of a chunk of memory to allocate + * @param num Number of variable paramters + * + * @return A pointer to the memory allocated on success, NULL on failure + */ +void *heap_caps_calloc_prefer( size_t n, size_t size, size_t num, ... ); + +/** + * @brief Dump the full structure of all heaps with matching capabilities. + * + * Prints a large amount of output to serial (because of locking limitations, + * the output bypasses stdout/stderr). For each (variable sized) block + * in each matching heap, the following output is printed on a single line: + * + * - Block address (the data buffer returned by malloc is 4 bytes after this + * if heap debugging is set to Basic, or 8 bytes otherwise). + * - Data size (the data size may be larger than the size requested by malloc, + * either due to heap fragmentation or because of heap debugging level). + * - Address of next block in the heap. + * - If the block is free, the address of the next free block is also printed. + * + * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type + * of memory + */ +void heap_caps_dump(uint32_t caps); + +/** + * @brief Dump the full structure of all heaps. + * + * Covers all registered heaps. Prints a large amount of output to serial. + * + * Output is the same as for heap_caps_dump. + * + */ +void heap_caps_dump_all(); + diff --git a/tools/sdk/include/heap/esp_heap_caps_init.h b/tools/sdk/include/heap/esp_heap_caps_init.h new file mode 100644 index 00000000000..5cfb8d82b51 --- /dev/null +++ b/tools/sdk/include/heap/esp_heap_caps_init.h @@ -0,0 +1,86 @@ +// Copyright 2017 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. +// 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. +#pragma once + +#include "esp_err.h" +#include "esp_heap_caps.h" +#include "soc/soc_memory_layout.h" + +/** + * @brief Initialize the capability-aware heap allocator. + * + * This is called once in the IDF startup code. Do not call it + * at other times. + */ +void heap_caps_init(); + +/** + * @brief Enable heap(s) in memory regions where the startup stacks are located. + * + * On startup, the pro/app CPUs have a certain memory region they use as stack, so we + * cannot do allocations in the regions these stack frames are. When FreeRTOS is + * completely started, they do not use that memory anymore and heap(s) there can + * be enabled. + */ +void heap_caps_enable_nonos_stack_heaps(); + +/** + * @brief Add a region of memory to the collection of heaps at runtime. + * + * Most memory regions are defined in soc_memory_layout.c for the SoC, + * and are registered via heap_caps_init(). Some regions can't be used + * immediately and are later enabled via heap_caps_enable_nonos_stack_heaps(). + * + * Call this function to add a region of memory to the heap at some later time. + * + * This function does not consider any of the "reserved" regions or other data in soc_memory_layout, caller needs to + * consider this themselves. + * + * All memory within the region specified by start & end parameters must be otherwise unused. + * + * The capabilities of the newly registered memory will be determined by the start address, as looked up in the regions + * specified in soc_memory_layout.c. + * + * Use heap_caps_add_region_with_caps() to register a region with custom capabilities. + * + * @param start Start address of new region. + * @param end End address of new region. + * + * @return ESP_OK on success, ESP_ERR_INVALID_ARG if a parameter is invalid, ESP_ERR_NOT_FOUND if the + * specified start address doesn't reside in a known region, or any error returned by heap_caps_add_region_with_caps(). + */ +esp_err_t heap_caps_add_region(intptr_t start, intptr_t end); + + +/** + * @brief Add a region of memory to the collection of heaps at runtime, with custom capabilities. + * + * Similar to heap_caps_add_region(), only custom memory capabilities are specified by the caller. + * + * @param caps Ordered array of capability masks for the new region, in order of priority. Must have length + * SOC_MEMORY_TYPE_NO_PRIOS. Does not need to remain valid after the call returns. + * @param start Start address of new region. + * @param end End address of new region. + * + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG if a parameter is invalid + * - ESP_ERR_NO_MEM if no memory to register new heap. + * - ESP_FAIL if region overlaps the start and/or end of an existing region + */ +esp_err_t heap_caps_add_region_with_caps(const uint32_t caps[], intptr_t start, intptr_t end); + + + + diff --git a/tools/sdk/include/heap/esp_heap_trace.h b/tools/sdk/include/heap/esp_heap_trace.h new file mode 100644 index 00000000000..24b5c60f55c --- /dev/null +++ b/tools/sdk/include/heap/esp_heap_trace.h @@ -0,0 +1,136 @@ +// Copyright 2015-2016 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. +// 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. +#pragma once + +#include "sdkconfig.h" +#include +#include + +#if !defined(CONFIG_HEAP_TRACING) && !defined(HEAP_TRACE_SRCFILE) +#warning "esp_heap_trace.h is included but heap tracing is disabled in menuconfig, functions are no-ops" +#endif + +#ifndef CONFIG_HEAP_TRACING_STACK_DEPTH +#define CONFIG_HEAP_TRACING_STACK_DEPTH 0 +#endif + +typedef enum { + HEAP_TRACE_ALL, + HEAP_TRACE_LEAKS, +} heap_trace_mode_t; + +/** + * @brief Trace record data type. Stores information about an allocated region of memory. + */ +typedef struct { + uint32_t ccount; ///< CCOUNT of the CPU when the allocation was made. LSB (bit value 1) is the CPU number (0 or 1). */ + void *address; ///< Address which was allocated + size_t size; ///< Size of the allocation + void *alloced_by[CONFIG_HEAP_TRACING_STACK_DEPTH]; ///< Call stack of the caller which allocated the memory. + void *freed_by[CONFIG_HEAP_TRACING_STACK_DEPTH]; ///< Call stack of the caller which freed the memory (all zero if not freed.) +} heap_trace_record_t; + +/** + * @brief Initialise heap tracing in standalone mode. + * @note Standalone mode is the only mode currently supported. + * + * This function must be called before any other heap tracing functions. + * + * To disable heap tracing and allow the buffer to be freed, stop tracing and then call heap_trace_init_standalone(NULL, 0); + * + * @param record_buffer Provide a buffer to use for heap trace data. Must remain valid any time heap tracing is enabled, meaning + * it must be allocated from internal memory not in PSRAM. + * @param num_records Size of the heap trace buffer, as number of record structures. + * @return + * - ESP_ERR_NOT_SUPPORTED Project was compiled without heap tracing enabled in menuconfig. + * - ESP_ERR_INVALID_STATE Heap tracing is currently in progress. + * - ESP_OK Heap tracing initialised successfully. + */ +esp_err_t heap_trace_init_standalone(heap_trace_record_t *record_buffer, size_t num_records); + +/** + * @brief Start heap tracing. All heap allocations & frees will be traced, until heap_trace_stop() is called. + * + * @note heap_trace_init_standalone() must be called to provide a valid buffer, before this function is called. + * + * @note Calling this function while heap tracing is running will reset the heap trace state and continue tracing. + * + * @param mode Mode for tracing. + * - HEAP_TRACE_ALL means all heap allocations and frees are traced. + * - HEAP_TRACE_LEAKS means only suspected memory leaks are traced. (When memory is freed, the record is removed from the trace buffer.) + * @return + * - ESP_ERR_NOT_SUPPORTED Project was compiled without heap tracing enabled in menuconfig. + * - ESP_ERR_INVALID_STATE A non-zero-length buffer has not been set via heap_trace_init_standalone(). + * - ESP_OK Tracing is started. + */ +esp_err_t heap_trace_start(heap_trace_mode_t mode); + +/** + * @brief Stop heap tracing. + * + * @return + * - ESP_ERR_NOT_SUPPORTED Project was compiled without heap tracing enabled in menuconfig. + * - ESP_ERR_INVALID_STATE Heap tracing was not in progress. + * - ESP_OK Heap tracing stopped.. + */ +esp_err_t heap_trace_stop(void); + +/** + * @brief Resume heap tracing which was previously stopped. + * + * Unlike heap_trace_start(), this function does not clear the + * buffer of any pre-existing trace records. + * + * The heap trace mode is the same as when heap_trace_start() was + * last called (or HEAP_TRACE_ALL if heap_trace_start() was never called). + * + * @return + * - ESP_ERR_NOT_SUPPORTED Project was compiled without heap tracing enabled in menuconfig. + * - ESP_ERR_INVALID_STATE Heap tracing was already started. + * - ESP_OK Heap tracing resumed. + */ +esp_err_t heap_trace_resume(void); + +/** + * @brief Return number of records in the heap trace buffer + * + * It is safe to call this function while heap tracing is running. + */ +size_t heap_trace_get_count(void); + +/** + * @brief Return a raw record from the heap trace buffer + * + * @note It is safe to call this function while heap tracing is running, however in HEAP_TRACE_LEAK mode record indexing may + * skip entries unless heap tracing is stopped first. + * + * @param index Index (zero-based) of the record to return. + * @param[out] record Record where the heap trace record will be copied. + * @return + * - ESP_ERR_NOT_SUPPORTED Project was compiled without heap tracing enabled in menuconfig. + * - ESP_ERR_INVALID_STATE Heap tracing was not initialised. + * - ESP_ERR_INVALID_ARG Index is out of bounds for current heap trace record count. + * - ESP_OK Record returned successfully. + */ +esp_err_t heap_trace_get(size_t index, heap_trace_record_t *record); + +/** + * @brief Dump heap trace record data to stdout + * + * @note It is safe to call this function while heap tracing is running, however in HEAP_TRACE_LEAK mode the dump may skip + * entries unless heap tracing is stopped first. + * + * + */ +void heap_trace_dump(void); diff --git a/tools/sdk/include/heap/esp_ota_ops.h b/tools/sdk/include/heap/esp_ota_ops.h deleted file mode 100755 index a089a92be05..00000000000 --- a/tools/sdk/include/heap/esp_ota_ops.h +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright 2015-2016 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. -// 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 _OTA_OPS_H -#define _OTA_OPS_H - -#include -#include -#include -#include "esp_err.h" -#include "esp_partition.h" -#include "esp_spi_flash.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -#define OTA_SIZE_UNKNOWN 0xffffffff /*!< Used for esp_ota_begin() if new image size is unknown */ - -#define ESP_ERR_OTA_BASE 0x1500 /*!< Base error code for ota_ops api */ -#define ESP_ERR_OTA_PARTITION_CONFLICT (ESP_ERR_OTA_BASE + 0x01) /*!< Error if request was to write or erase the current running partition */ -#define ESP_ERR_OTA_SELECT_INFO_INVALID (ESP_ERR_OTA_BASE + 0x02) /*!< Error if OTA data partition contains invalid content */ -#define ESP_ERR_OTA_VALIDATE_FAILED (ESP_ERR_OTA_BASE + 0x03) /*!< Error if OTA app image is invalid */ - -/** - * @brief Opaque handle for an application OTA update - * - * esp_ota_begin() returns a handle which is then used for subsequent - * calls to esp_ota_write() and esp_ota_end(). - */ -typedef uint32_t esp_ota_handle_t; - -/** - * @brief Commence an OTA update writing to the specified partition. - - * The specified partition is erased to the specified image size. - * - * If image size is not yet known, pass OTA_SIZE_UNKNOWN which will - * cause the entire partition to be erased. - * - * On success, this function allocates memory that remains in use - * until esp_ota_end() is called with the returned handle. - * - * @param partition Pointer to info for partition which will receive the OTA update. Required. - * @param image_size Size of new OTA app image. Partition will be erased in order to receive this size of image. If 0 or OTA_SIZE_UNKNOWN, the entire partition is erased. - * @param out_handle On success, returns a handle which should be used for subsequent esp_ota_write() and esp_ota_end() calls. - - * @return - * - ESP_OK: OTA operation commenced successfully. - * - ESP_ERR_INVALID_ARG: partition or out_handle arguments were NULL, or partition doesn't point to an OTA app partition. - * - ESP_ERR_NO_MEM: Cannot allocate memory for OTA operation. - * - ESP_ERR_OTA_PARTITION_CONFLICT: Partition holds the currently running firmware, cannot update in place. - * - ESP_ERR_NOT_FOUND: Partition argument not found in partition table. - * - ESP_ERR_OTA_SELECT_INFO_INVALID: The OTA data partition contains invalid data. - * - ESP_ERR_INVALID_SIZE: Partition doesn't fit in configured flash size. - * - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed. - */ -esp_err_t esp_ota_begin(const esp_partition_t* partition, size_t image_size, esp_ota_handle_t* out_handle); - -/** - * @brief Write OTA update data to partition - * - * This function can be called multiple times as - * data is received during the OTA operation. Data is written - * sequentially to the partition. - * - * @param handle Handle obtained from esp_ota_begin - * @param data Data buffer to write - * @param size Size of data buffer in bytes. - * - * @return - * - ESP_OK: Data was written to flash successfully. - * - ESP_ERR_INVALID_ARG: handle is invalid. - * - ESP_ERR_OTA_VALIDATE_FAILED: First byte of image contains invalid app image magic byte. - * - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed. - * - ESP_ERR_OTA_SELECT_INFO_INVALID: OTA data partition has invalid contents - */ -esp_err_t esp_ota_write(esp_ota_handle_t handle, const void* data, size_t size); - -/** - * @brief Finish OTA update and validate newly written app image. - * - * @param handle Handle obtained from esp_ota_begin(). - * - * @note After calling esp_ota_end(), the handle is no longer valid and any memory associated with it is freed (regardless of result). - * - * @return - * - ESP_OK: Newly written OTA app image is valid. - * - ESP_ERR_NOT_FOUND: OTA handle was not found. - * - ESP_ERR_INVALID_ARG: Handle was never written to. - * - ESP_ERR_OTA_VALIDATE_FAILED: OTA image is invalid (either not a valid app image, or - if secure boot is enabled - signature failed to verify.) - * - ESP_ERR_INVALID_STATE: If flash encryption is enabled, this result indicates an internal error writing the final encrypted bytes to flash. - */ -esp_err_t esp_ota_end(esp_ota_handle_t handle); - -/** - * @brief Configure OTA data for a new boot partition - * - * @note If this function returns ESP_OK, calling esp_restart() will boot the newly configured app partition. - * - * @param partition Pointer to info for partition containing app image to boot. - * - * @return - * - ESP_OK: OTA data updated, next reboot will use specified partition. - * - ESP_ERR_INVALID_ARG: partition argument was NULL or didn't point to a valid OTA partition of type "app". - * - ESP_ERR_OTA_VALIDATE_FAILED: Partition contained invalid app image. Also returned if secure boot is enabled and signature validation failed. - * - ESP_ERR_NOT_FOUND: OTA data partition not found. - * - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash erase or write failed. - */ -esp_err_t esp_ota_set_boot_partition(const esp_partition_t* partition); - -/** - * @brief Get partition info of currently configured boot app - * - * If esp_ota_set_boot_partition() has been called, the partition which was set by that function will be returned. - * - * If esp_ota_set_boot_partition() has not been called, the result is usually the same as esp_ota_get_running_partition(). - * The two results are not equal if the configured boot partition does not contain a valid app (meaning that the running partition - * will be an app that the bootloader chose via fallback). - * - * If the OTA data partition is not present or not valid then the result is the first app partition found in the - * partition table. In priority order, this means: the factory app, the first OTA app slot, or the test app partition. - * - * Note that there is no guarantee the returned partition is a valid app. Use esp_image_load(ESP_IMAGE_VERIFY, ...) to verify if the - * returned partition contains a bootable image. - * - * @return Pointer to info for partition structure, or NULL if partition table is invalid or a flash read operation failed. Any returned pointer is valid for the lifetime of the application. - */ -const esp_partition_t* esp_ota_get_boot_partition(void); - - -/** - * @brief Get partition info of currently running app - * - * This function is different to esp_ota_get_boot_partition() in that - * it ignores any change of selected boot partition caused by - * esp_ota_set_boot_partition(). Only the app whose code is currently - * running will have its partition information returned. - * - * The partition returned by this function may also differ from esp_ota_get_boot_partition() if the configured boot - * partition is somehow invalid, and the bootloader fell back to a different app partition at boot. - * - * @return Pointer to info for partition structure, or NULL if no partition is found or flash read operation failed. Returned pointer is valid for the lifetime of the application. - */ -const esp_partition_t* esp_ota_get_running_partition(void); - - -/** - * @brief Return the next OTA app partition which should be written with a new firmware. - * - * Call this function to find an OTA app partition which can be passed to esp_ota_begin(). - * - * Finds next partition round-robin, starting from the current running partition. - * - * @param start_from If set, treat this partition info as describing the current running partition. Can be NULL, in which case esp_ota_get_running_partition() is used to find the currently running partition. The result of this function is never the same as this argument. - * - * @return Pointer to info for partition which should be updated next. NULL result indicates invalid OTA data partition, or that no eligible OTA app slot partition was found. - * - */ -const esp_partition_t* esp_ota_get_next_update_partition(const esp_partition_t *start_from); - -#ifdef __cplusplus -} -#endif - -#endif /* OTA_OPS_H */ diff --git a/tools/sdk/include/heap/multi_heap.h b/tools/sdk/include/heap/multi_heap.h new file mode 100644 index 00000000000..dbd0cae8649 --- /dev/null +++ b/tools/sdk/include/heap/multi_heap.h @@ -0,0 +1,171 @@ +// Copyright 2015-2016 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. +// 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. +#pragma once +#include +#include +#include + +/* multi_heap is a heap implementation for handling multiple + heterogenous heaps in a single program. + + Any contiguous block of memory can be registered as a heap. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/** @brief Opaque handle to a registered heap */ +typedef struct multi_heap_info *multi_heap_handle_t; + +/** @brief malloc() a buffer in a given heap + * + * Semantics are the same as standard malloc(), only the returned buffer will be allocated in the specified heap. + * + * @param heap Handle to a registered heap. + * @param size Size of desired buffer. + * + * @return Pointer to new memory, or NULL if allocation fails. + */ +void *multi_heap_malloc(multi_heap_handle_t heap, size_t size); + +/** @brief free() a buffer in a given heap. + * + * Semantics are the same as standard free(), only the argument 'p' must be NULL or have been allocated in the specified heap. + * + * @param heap Handle to a registered heap. + * @param p NULL, or a pointer previously returned from multi_heap_malloc() or multi_heap_realloc() for the same heap. + */ +void multi_heap_free(multi_heap_handle_t heap, void *p); + +/** @brief realloc() a buffer in a given heap. + * + * Semantics are the same as standard realloc(), only the argument 'p' must be NULL or have been allocated in the specified heap. + * + * @param heap Handle to a registered heap. + * @param p NULL, or a pointer previously returned from multi_heap_malloc() or multi_heap_realloc() for the same heap. + * @param size Desired new size for buffer. + * + * @return New buffer of 'size' containing contents of 'p', or NULL if reallocation failed. + */ +void *multi_heap_realloc(multi_heap_handle_t heap, void *p, size_t size); + + +/** @brief Return the size that a particular pointer was allocated with. + * + * @param heap Handle to a registered heap. + * @param p Pointer, must have been previously returned from multi_heap_malloc() or multi_heap_realloc() for the same heap. + * + * @return Size of the memory allocated at this block. May be more than the original size argument, due + * to padding and minimum block sizes. + */ +size_t multi_heap_get_allocated_size(multi_heap_handle_t heap, void *p); + + +/** @brief Register a new heap for use + * + * This function initialises a heap at the specified address, and returns a handle for future heap operations. + * + * There is no equivalent function for deregistering a heap - if all blocks in the heap are free, you can immediately start using the memory for other purposes. + * + * @param start Start address of the memory to use for a new heap. + * @param size Size (in bytes) of the new heap. + * + * @return Handle of a new heap ready for use, or NULL if the heap region was too small to be initialised. + */ +multi_heap_handle_t multi_heap_register(void *start, size_t size); + + +/** @brief Associate a private lock pointer with a heap + * + * The lock argument is supplied to the MULTI_HEAP_LOCK() and MULTI_HEAP_UNLOCK() macros, defined in multi_heap_platform.h. + * + * The lock in question must be recursive. + * + * When the heap is first registered, the associated lock is NULL. + * + * @param heap Handle to a registered heap. + * @param lock Optional pointer to a locking structure to associate with this heap. + */ +void multi_heap_set_lock(multi_heap_handle_t heap, void* lock); + +/** @brief Dump heap information to stdout + * + * For debugging purposes, this function dumps information about every block in the heap to stdout. + * + * @param heap Handle to a registered heap. + */ +void multi_heap_dump(multi_heap_handle_t heap); + +/** @brief Check heap integrity + * + * Walks the heap and checks all heap data structures are valid. If any errors are detected, an error-specific message + * can be optionally printed to stderr. Print behaviour can be overriden at compile time by defining + * MULTI_CHECK_FAIL_PRINTF in multi_heap_platform.h. + * + * @param heap Handle to a registered heap. + * @param print_errors If true, errors will be printed to stderr. + * @return true if heap is valid, false otherwise. + */ +bool multi_heap_check(multi_heap_handle_t heap, bool print_errors); + +/** @brief Return free heap size + * + * Returns the number of bytes available in the heap. + * + * Equivalent to the total_free_bytes member returned by multi_heap_get_heap_info(). + * + * Note that the heap may be fragmented, so the actual maximum size for a single malloc() may be lower. To know this + * size, see the largest_free_block member returned by multi_heap_get_heap_info(). + * + * @param heap Handle to a registered heap. + * @return Number of free bytes. + */ +size_t multi_heap_free_size(multi_heap_handle_t heap); + +/** @brief Return the lifetime minimum free heap size + * + * Equivalent to the minimum_free_bytes member returned by multi_heap_get_info(). + * + * Returns the lifetime "low water mark" of possible values returned from multi_free_heap_size(), for the specified + * heap. + * + * @param heap Handle to a registered heap. + * @return Number of free bytes. + */ +size_t multi_heap_minimum_free_size(multi_heap_handle_t heap); + +/** @brief Structure to access heap metadata via multi_heap_get_info */ +typedef struct { + size_t total_free_bytes; ///< Total free bytes in the heap. Equivalent to multi_free_heap_size(). + size_t total_allocated_bytes; ///< Total bytes allocated to data in the heap. + size_t largest_free_block; ///< Size of largest free block in the heap. This is the largest malloc-able size. + size_t minimum_free_bytes; ///< Lifetime minimum free heap size. Equivalent to multi_minimum_free_heap_size(). + size_t allocated_blocks; ///< Number of (variable size) blocks allocated in the heap. + size_t free_blocks; ///< Number of (variable size) free blocks in the heap. + size_t total_blocks; ///< Total number of (variable size) blocks in the heap. +} multi_heap_info_t; + +/** @brief Return metadata about a given heap + * + * Fills a multi_heap_info_t structure with information about the specified heap. + * + * @param heap Handle to a registered heap. + * @param info Pointer to a structure to fill with heap metadata. + */ +void multi_heap_get_info(multi_heap_handle_t heap, multi_heap_info_t *info); + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/include/log/esp_log.h b/tools/sdk/include/log/esp_log.h index 734c80fe78a..085970c51eb 100644 --- a/tools/sdk/include/log/esp_log.h +++ b/tools/sdk/include/log/esp_log.h @@ -95,6 +95,62 @@ uint32_t esp_log_early_timestamp(void); */ void esp_log_write(esp_log_level_t level, const char* tag, const char* format, ...) __attribute__ ((format (printf, 3, 4))); +#include "esp_log_internal.h" + +/** + * @brief Log a buffer of hex bytes at specified level, seprated into 16 bytes each line. + * + * @param tag description tag + * + * @param buffer Pointer to the buffer array + * + * @param buff_len length of buffer in bytes + * + * @param level level of the log + * + */ +#define ESP_LOG_BUFFER_HEX_LEVEL( tag, buffer, buff_len, level ) do {\ + if ( LOG_LOCAL_LEVEL >= level ) esp_log_buffer_hex_internal( tag, buffer, buff_len, level ); } while(0) + +/** + * @brief Log a buffer of characters at specified level, seprated into 16 bytes each line. Buffer should contain only printable characters. + * + * @param tag description tag + * + * @param buffer Pointer to the buffer array + * + * @param buff_len length of buffer in bytes + * + * @param level level of the log + * + */ +#define ESP_LOG_BUFFER_CHAR_LEVEL( tag, buffer, buff_len, level ) do {\ + if ( LOG_LOCAL_LEVEL >= level ) esp_log_buffer_char_internal( tag, buffer, buff_len, level ); } while(0) + +/** + * @brief Dump a buffer to the log at specified level. + * + * The dump log shows just like the one below: + * + * W (195) log_example: 0x3ffb4280 45 53 50 33 32 20 69 73 20 67 72 65 61 74 2c 20 |ESP32 is great, | + * W (195) log_example: 0x3ffb4290 77 6f 72 6b 69 6e 67 20 61 6c 6f 6e 67 20 77 69 |working along wi| + * W (205) log_example: 0x3ffb42a0 74 68 20 74 68 65 20 49 44 46 2e 00 |th the IDF..| + * + * It is highly recommend to use terminals with over 102 text width. + * + * @param tag description tag + * + * @param buffer Pointer to the buffer array + * + * @param buff_len length of buffer in bytes + * + * @param level level of the log + */ +#define ESP_LOG_BUFFER_HEXDUMP( tag, buffer, buff_len, level ) do {\ + if ( LOG_LOCAL_LEVEL >= level ) esp_log_buffer_hexdump_internal( tag, buffer, buff_len, level); } while(0) + + +#if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) /** * @brief Log a buffer of hex bytes at Info level * @@ -104,8 +160,10 @@ void esp_log_write(esp_log_level_t level, const char* tag, const char* format, . * * @param buff_len length of buffer in bytes * + * @see ``esp_log_buffer_hex_level`` + * */ -void esp_log_buffer_hex(const char *tag, const void *buffer, uint16_t buff_len); +#define ESP_LOG_BUFFER_HEX(tag, buffer, buff_len) ESP_LOG_BUFFER_HEX_LEVEL( tag, buffer, buff_len, ESP_LOG_INFO ) /** * @brief Log a buffer of characters at Info level. Buffer should contain only printable characters. @@ -116,8 +174,20 @@ void esp_log_buffer_hex(const char *tag, const void *buffer, uint16_t buff_len); * * @param buff_len length of buffer in bytes * + * @see ``esp_log_buffer_char_level`` + * */ -void esp_log_buffer_char(const char *tag, const void *buffer, uint16_t buff_len); +#define ESP_LOG_BUFFER_CHAR(tag, buffer, buff_len) ESP_LOG_BUFFER_CHAR_LEVEL( tag, buffer, buff_len, ESP_LOG_INFO ) + +#else +#define ESP_LOG_BUFFER_HEX(tag, buffer, buff_len) {} +#define ESP_LOG_BUFFER_CHAR(tag, buffer, buff_len) {} +#endif + +//to be back compatible +#define esp_log_buffer_hex ESP_LOG_BUFFER_HEX +#define esp_log_buffer_char ESP_LOG_BUFFER_CHAR + #if CONFIG_LOG_COLORS #define LOG_COLOR_BLACK "30" @@ -190,6 +260,32 @@ void esp_log_buffer_char(const char *tag, const void *buffer, uint16_t buff_len) #define ESP_LOGV( tag, format, ... ) ESP_EARLY_LOGV(tag, format, ##__VA_ARGS__) #endif // BOOTLOADER_BUILD +/** runtime macro to output logs at a speicfied level. + * + * @param tag tag of the log, which can be used to change the log level by ``esp_log_level_set`` at runtime. + * + * @param level level of the output log. + * + * @param format format of the output log. see ``printf`` + * + * @param ... variables to be replaced into the log. see ``printf`` + * + * @see ``printf`` + */ +#define ESP_LOG_LEVEL(level, tag, format, ...) do {\ + if (level==ESP_LOG_ERROR ) { esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }\ + else if (level==ESP_LOG_WARN ) { esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }\ + else if (level==ESP_LOG_DEBUG ) { esp_log_write(ESP_LOG_DEBUG, tag, LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }\ + else if (level==ESP_LOG_VERBOSE ) { esp_log_write(ESP_LOG_VERBOSE, tag, LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }\ + else { esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }}while(0) + +/** runtime macro to output logs at a speicfied level. Also check the level with ``LOG_LOCAL_LEVEL``. + * + * @see ``printf``, ``ESP_LOG_LEVEL`` + */ +#define ESP_LOG_LEVEL_LOCAL(level, tag, format, ...) do {\ + if ( LOG_LOCAL_LEVEL >= level ) ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); } while(0); + #ifdef __cplusplus } #endif diff --git a/tools/sdk/include/lwip/port/netif/wlanif.h b/tools/sdk/include/log/esp_log_internal.h old mode 100755 new mode 100644 similarity index 55% rename from tools/sdk/include/lwip/port/netif/wlanif.h rename to tools/sdk/include/log/esp_log_internal.h index 9c79f5b0aff..a41243881e8 --- a/tools/sdk/include/lwip/port/netif/wlanif.h +++ b/tools/sdk/include/log/esp_log_internal.h @@ -12,31 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +#ifndef __ESP_LOG_INTERNAL_H__ +#define __ESP_LOG_INTERNAL_H__ -#ifndef _WLAN_LWIP_IF_H_ -#define _WLAN_LWIP_IF_H_ +//these two functions do not check level versus ESP_LOCAL_LEVEL, this should be done in esp_log.h +void esp_log_buffer_hex_internal(const char *tag, const void *buffer, uint16_t buff_len, esp_log_level_t level); +void esp_log_buffer_char_internal(const char *tag, const void *buffer, uint16_t buff_len, esp_log_level_t level); +void esp_log_buffer_hexdump_internal( const char *tag, const void *buffer, uint16_t buff_len, esp_log_level_t log_level); -#include "esp_wifi.h" - -#include "esp_wifi_internal.h" - -#include "lwip/err.h" - -#ifdef __cplusplus -extern "C" { -#endif - -err_t wlanif_init_ap(struct netif *netif); -err_t wlanif_init_sta(struct netif *netif); - -void wlanif_input(struct netif *netif, void *buffer, u16_t len, void* eb); - -wifi_interface_t wifi_get_interface(void *dev); - -void netif_reg_addr_change_cb(void* cb); - -#ifdef __cplusplus -} #endif -#endif /* _WLAN_LWIP_IF_H_ */ diff --git a/tools/sdk/include/lwip/apps/dhcpserver.h b/tools/sdk/include/lwip/apps/dhcpserver.h index 9e361833d3d..943f02a9171 100644 --- a/tools/sdk/include/lwip/apps/dhcpserver.h +++ b/tools/sdk/include/lwip/apps/dhcpserver.h @@ -15,8 +15,6 @@ #define __DHCPS_H__ #include "lwip/ip_addr.h" -//#include "esp_common.h" -#define USE_DNS typedef struct dhcps_state{ s16_t state; @@ -36,123 +34,6 @@ typedef struct dhcps_msg { u8_t options[312]; }dhcps_msg; -/** DHCP OPTIONS CODE **/ -typedef enum -{ - /* RFC 1497 Vendor Extensions */ - - PAD = 0, - END = 255, - - SUBNET_MASK = 1, - TIME_OFFSET = 2, - ROUTER = 3, - TIME_SERVER = 4, - NAME_SERVER = 5, - DOMAIN_NAME_SERVER = 6, - LOG_SERVER = 7, - COOKIE_SERVER = 8, - LPR_SERVER = 9, - IMPRESS_SERVER = 10, - RESOURCE_LOCATION_SERVER = 11, - HOST_NAME = 12, - BOOT_FILE_SIZE = 13, - MERIT_DUMP_FILE = 14, - DOMAIN_NAME = 15, - SWAP_SERVER = 16, - ROOT_PATH = 17, - EXTENSIONS_PATH = 18, - - /* IP Layer Parameters per Host */ - - IP_FORWARDING = 19, - NON_LOCAL_SOURCE_ROUTING = 20, - POLICY_FILTER = 21, - MAXIMUM_DATAGRAM_REASSEMBLY_SIZE = 22, - DEFAULT_IP_TIME_TO_LIVE = 23, - PATH_MTU_AGING_TIMEOUT = 24, - PATH_MTU_PLATEAU_TABLE = 25, - - /* IP Layer Parameters per Interface */ - - INTERFACE_MTU = 26, - ALL_SUBNETS_ARE_LOCAL = 27, - BROADCAST_ADDRESS = 28, - PERFORM_MASK_DISCOVERY = 29, - MASK_SUPPLIER = 30, - PERFORM_ROUTER_DISCOVERY = 31, - ROUTER_SOLICITATION_ADDRESS = 32, - STATIC_ROUTE = 33, - - /* Link Layer Parameters per Interface */ - - TRAILER_ENCAPSULATION = 34, - ARP_CACHE_TIMEOUT = 35, - ETHERNET_ENCAPSULATION = 36, - - /* TCP Parameters */ - - TCP_DEFAULT_TTL = 37, - TCP_KEEPALIVE_INTERVAL = 38, - TCP_KEEPALIVE_GARBAGE = 39, - - /* Application and Service Parameters */ - - NETWORK_INFORMATION_SERVICE_DOMAIN = 40, - NETWORK_INFORMATION_SERVERS = 41, - NETWORK_TIME_PROTOCOL_SERVERS = 42, - VENDOR_SPECIFIC_INFORMATION = 43, - NETBIOS_OVER_TCP_IP_NAME_SERVER = 44, - NETBIOS_OVER_TCP_IP_DATAGRAM_DISTRIBUTION_SERVER = 45, - NETBIOS_OVER_TCP_IP_NODE_TYPE = 46, - NETBIOS_OVER_TCP_IP_SCOPE = 47, - X_WINDOW_SYSTEM_FONT_SERVER = 48, - X_WINDOW_SYSTEM_DISPLAY_MANAGER = 49, - NETWORK_INFORMATION_SERVICE_PLUS_DOMAIN = 64, - NETWORK_INFORMATION_SERVICE_PLUS_SERVERS = 65, - MOBILE_IP_HOME_AGENT = 68, - SMTP_SERVER = 69, - POP3_SERVER = 70, - NNTP_SERVER = 71, - DEFAULT_WWW_SERVER = 72, - DEFAULT_FINGER_SERVER = 73, - DEFAULT_IRC_SERVER = 74, - STREETTALK_SERVER = 75, - STREETTALK_DIRECTORY_ASSISTANCE_SERVER = 76, - - /* DHCP Extensions */ - - REQUESTED_IP_ADDRESS = 50, - IP_ADDRESS_LEASE_TIME = 51, - OPTION_OVERLOAD = 52, - TFTP_SERVER_NAME = 66, - BOOTFILE_NAME = 67, - DHCP_MESSAGE_TYPE = 53, - SERVER_IDENTIFIER = 54, - PARAMETER_REQUEST_LIST = 55, - MESSAGE = 56, - MAXIMUM_DHCP_MESSAGE_SIZE = 57, - RENEWAL_T1_TIME_VALUE = 58, - REBINDING_T2_TIME_VALUE = 59, - VENDOR_CLASS_IDENTIFIER = 60, - CLIENT_IDENTIFIER = 61, - - USER_CLASS = 77, - FQDN = 81, - DHCP_AGENT_OPTIONS = 82, - NDS_SERVERS = 85, - NDS_TREE_NAME = 86, - NDS_CONTEXT = 87, - CLIENT_LAST_TRANSACTION_TIME = 91, - ASSOCIATED_IP = 92, - USER_AUTHENTICATION_PROTOCOL = 98, - AUTO_CONFIGURE = 116, - NAME_SERVICE_SEARCH = 117, - SUBNET_SELECTION = 118, - DOMAIN_SEARCH = 119, - CLASSLESS_ROUTE = 121, -} dhcp_msg_option; - /* Defined in esp_misc.h */ typedef struct { bool enable; @@ -163,6 +44,7 @@ typedef struct { enum dhcps_offer_option{ OFFER_START = 0x00, OFFER_ROUTER = 0x01, + OFFER_DNS = 0x02, OFFER_END }; @@ -176,26 +58,33 @@ struct dhcps_pool{ u32_t lease_timer; }; -typedef struct _list_node{ - void *pnode; - struct _list_node *pnext; -}list_node; - typedef u32_t dhcps_time_t; typedef u8_t dhcps_offer_t; typedef struct { - dhcps_offer_t dhcps_offer; - dhcps_time_t dhcps_time; - dhcps_lease_t dhcps_poll; + dhcps_offer_t dhcps_offer; + dhcps_offer_t dhcps_dns; + dhcps_time_t dhcps_time; + dhcps_lease_t dhcps_poll; } dhcps_options_t; -#define dhcps_router_enabled(offer) ((offer & OFFER_ROUTER) != 0) +static inline bool dhcps_router_enabled (dhcps_offer_t offer) +{ + return (offer & OFFER_ROUTER) != 0; +} + +static inline bool dhcps_dns_enabled (dhcps_offer_t offer) +{ + return (offer & OFFER_DNS) != 0; +} void dhcps_start(struct netif *netif, ip4_addr_t ip); void dhcps_stop(struct netif *netif); void *dhcps_option_info(u8_t op_id, u32_t opt_len); +void dhcps_set_option_info(u8_t op_id, void *opt_info, u32_t opt_len); bool dhcp_search_ip_on_mac(u8_t *mac, ip4_addr_t *ip); +void dhcps_dns_setserver(const ip_addr_t *dnsserver); +ip4_addr_t dhcps_dns_getserver(); #endif diff --git a/tools/sdk/include/lwip/apps/dhcpserver_options.h b/tools/sdk/include/lwip/apps/dhcpserver_options.h new file mode 100644 index 00000000000..38d46f6bff2 --- /dev/null +++ b/tools/sdk/include/lwip/apps/dhcpserver_options.h @@ -0,0 +1,134 @@ +// Copyright 2017 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. +// 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. +#pragma once + +/** DHCP Options + + This macros are not part of the public dhcpserver.h interface. + **/ +typedef enum +{ + /* RFC 1497 Vendor Extensions */ + + PAD = 0, + END = 255, + + SUBNET_MASK = 1, + TIME_OFFSET = 2, + ROUTER = 3, + TIME_SERVER = 4, + NAME_SERVER = 5, + DOMAIN_NAME_SERVER = 6, + LOG_SERVER = 7, + COOKIE_SERVER = 8, + LPR_SERVER = 9, + IMPRESS_SERVER = 10, + RESOURCE_LOCATION_SERVER = 11, + HOST_NAME = 12, + BOOT_FILE_SIZE = 13, + MERIT_DUMP_FILE = 14, + DOMAIN_NAME = 15, + SWAP_SERVER = 16, + ROOT_PATH = 17, + EXTENSIONS_PATH = 18, + + /* IP Layer Parameters per Host */ + + IP_FORWARDING = 19, + NON_LOCAL_SOURCE_ROUTING = 20, + POLICY_FILTER = 21, + MAXIMUM_DATAGRAM_REASSEMBLY_SIZE = 22, + DEFAULT_IP_TIME_TO_LIVE = 23, + PATH_MTU_AGING_TIMEOUT = 24, + PATH_MTU_PLATEAU_TABLE = 25, + + /* IP Layer Parameters per Interface */ + + INTERFACE_MTU = 26, + ALL_SUBNETS_ARE_LOCAL = 27, + BROADCAST_ADDRESS = 28, + PERFORM_MASK_DISCOVERY = 29, + MASK_SUPPLIER = 30, + PERFORM_ROUTER_DISCOVERY = 31, + ROUTER_SOLICITATION_ADDRESS = 32, + STATIC_ROUTE = 33, + + /* Link Layer Parameters per Interface */ + + TRAILER_ENCAPSULATION = 34, + ARP_CACHE_TIMEOUT = 35, + ETHERNET_ENCAPSULATION = 36, + + /* TCP Parameters */ + + TCP_DEFAULT_TTL = 37, + TCP_KEEPALIVE_INTERVAL = 38, + TCP_KEEPALIVE_GARBAGE = 39, + + /* Application and Service Parameters */ + + NETWORK_INFORMATION_SERVICE_DOMAIN = 40, + NETWORK_INFORMATION_SERVERS = 41, + NETWORK_TIME_PROTOCOL_SERVERS = 42, + VENDOR_SPECIFIC_INFORMATION = 43, + NETBIOS_OVER_TCP_IP_NAME_SERVER = 44, + NETBIOS_OVER_TCP_IP_DATAGRAM_DISTRIBUTION_SERVER = 45, + NETBIOS_OVER_TCP_IP_NODE_TYPE = 46, + NETBIOS_OVER_TCP_IP_SCOPE = 47, + X_WINDOW_SYSTEM_FONT_SERVER = 48, + X_WINDOW_SYSTEM_DISPLAY_MANAGER = 49, + NETWORK_INFORMATION_SERVICE_PLUS_DOMAIN = 64, + NETWORK_INFORMATION_SERVICE_PLUS_SERVERS = 65, + MOBILE_IP_HOME_AGENT = 68, + SMTP_SERVER = 69, + POP3_SERVER = 70, + NNTP_SERVER = 71, + DEFAULT_WWW_SERVER = 72, + DEFAULT_FINGER_SERVER = 73, + DEFAULT_IRC_SERVER = 74, + STREETTALK_SERVER = 75, + STREETTALK_DIRECTORY_ASSISTANCE_SERVER = 76, + + /* DHCP Extensions */ + + REQUESTED_IP_ADDRESS = 50, + IP_ADDRESS_LEASE_TIME = 51, + OPTION_OVERLOAD = 52, + TFTP_SERVER_NAME = 66, + BOOTFILE_NAME = 67, + DHCP_MESSAGE_TYPE = 53, + SERVER_IDENTIFIER = 54, + PARAMETER_REQUEST_LIST = 55, + MESSAGE = 56, + MAXIMUM_DHCP_MESSAGE_SIZE = 57, + RENEWAL_T1_TIME_VALUE = 58, + REBINDING_T2_TIME_VALUE = 59, + VENDOR_CLASS_IDENTIFIER = 60, + CLIENT_IDENTIFIER = 61, + + USER_CLASS = 77, + FQDN = 81, + DHCP_AGENT_OPTIONS = 82, + NDS_SERVERS = 85, + NDS_TREE_NAME = 86, + NDS_CONTEXT = 87, + CLIENT_LAST_TRANSACTION_TIME = 91, + ASSOCIATED_IP = 92, + USER_AUTHENTICATION_PROTOCOL = 98, + AUTO_CONFIGURE = 116, + NAME_SERVICE_SEARCH = 117, + SUBNET_SELECTION = 118, + DOMAIN_SEARCH = 119, + CLASSLESS_ROUTE = 121, +} dhcp_msg_option; diff --git a/tools/sdk/include/lwip/arch/sys_arch.h b/tools/sdk/include/lwip/arch/sys_arch.h index 716fd9fa53e..bb7ea18af73 100644 --- a/tools/sdk/include/lwip/arch/sys_arch.h +++ b/tools/sdk/include/lwip/arch/sys_arch.h @@ -37,6 +37,7 @@ #include "freertos/task.h" #include "freertos/queue.h" #include "freertos/semphr.h" +#include "arch/vfs_lwip.h" #ifdef __cplusplus extern "C" { diff --git a/tools/sdk/include/lwip/port/netif/ethernetif.h b/tools/sdk/include/lwip/arch/vfs_lwip.h old mode 100755 new mode 100644 similarity index 66% rename from tools/sdk/include/lwip/port/netif/ethernetif.h rename to tools/sdk/include/lwip/arch/vfs_lwip.h index 134e8eb5fe1..88714b03b9f --- a/tools/sdk/include/lwip/port/netif/ethernetif.h +++ b/tools/sdk/include/lwip/arch/vfs_lwip.h @@ -1,9 +1,9 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// Copyright 2017 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. // 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 @@ -12,24 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. - -#ifndef _ETH_LWIP_IF_H_ -#define _ETH_LWIP_IF_H_ - -#include "lwip/err.h" - #ifdef __cplusplus extern "C" { #endif -err_t ethernetif_init(struct netif *netif); - -void ethernetif_input(struct netif *netif, void *buffer, u16_t len); +/* Internal declarations used to ingreate LWIP port layer + to ESP-IDF VFS for POSIX I/O. +*/ +extern int lwip_socket_offset; -void netif_reg_addr_change_cb(void* cb); +void esp_vfs_lwip_sockets_register(); #ifdef __cplusplus } #endif - -#endif /* _ETH_LWIP_IF_H_ */ diff --git a/tools/sdk/include/lwip/lwip/autoip.h b/tools/sdk/include/lwip/lwip/autoip.h index 3bb413f493d..16eac510e9a 100755 --- a/tools/sdk/include/lwip/lwip/autoip.h +++ b/tools/sdk/include/lwip/lwip/autoip.h @@ -68,13 +68,8 @@ extern "C" { #define ANNOUNCE_NUM 2 /* (number of announcement packets) */ #define ANNOUNCE_INTERVAL 2 /* seconds (time between announcement packets) */ #define ANNOUNCE_WAIT 2 /* seconds (delay before announcing) */ -#if CONFIG_MDNS -#define MAX_CONFLICTS 9 /* (max conflicts before rate limiting) */ -#define RATE_LIMIT_INTERVAL 20 /* seconds (delay between successive attempts) */ -#else -#define MAX_CONFLICTS 10 /* (max conflicts before rate limiting) */ -#define RATE_LIMIT_INTERVAL 60 /* seconds (delay between successive attempts) */ -#endif +#define MAX_CONFLICTS LWIP_AUTOIP_MAX_CONFLICTS /* (max conflicts before rate limiting) */ +#define RATE_LIMIT_INTERVAL LWIP_AUTOIP_RATE_LIMIT_INTERVAL /* seconds (delay between successive attempts) */ #define DEFEND_INTERVAL 10 /* seconds (min. wait between defensive ARPs) */ /* AutoIP client states */ diff --git a/tools/sdk/include/lwip/lwip/dns.h b/tools/sdk/include/lwip/lwip/dns.h index 5ef12e56c2c..e080280391d 100755 --- a/tools/sdk/include/lwip/lwip/dns.h +++ b/tools/sdk/include/lwip/lwip/dns.h @@ -96,6 +96,7 @@ typedef void (*dns_found_callback)(const char *name, const ip_addr_t *ipaddr, vo void dns_init(void); void dns_tmr(void); void dns_setserver(u8_t numdns, const ip_addr_t *dnsserver); +void dns_clear_servers(bool keep_fallback); ip_addr_t dns_getserver(u8_t numdns); err_t dns_gethostbyname(const char *hostname, ip_addr_t *addr, dns_found_callback found, void *callback_arg); diff --git a/tools/sdk/include/lwip/lwip/ip_addr.h b/tools/sdk/include/lwip/lwip/ip_addr.h index 1e1ffb3f1eb..74897a9ee92 100755 --- a/tools/sdk/include/lwip/lwip/ip_addr.h +++ b/tools/sdk/include/lwip/lwip/ip_addr.h @@ -69,6 +69,10 @@ extern const ip_addr_t ip_addr_any_type; #define IP_IS_V6_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V6) #define IP_IS_V6(ipaddr) (((ipaddr) != NULL) && IP_IS_V6_VAL(*(ipaddr))) + +#define IP_V6_EQ_PART(ipaddr, WORD, VAL) (ip_2_ip6(ipaddr)->addr[WORD] == htonl(VAL)) +#define IP_IS_V4MAPPEDV6(ipaddr) (IP_IS_V6(ipaddr) && IP_V6_EQ_PART(ipaddr, 0, 0) && IP_V6_EQ_PART(ipaddr, 1, 0) && IP_V6_EQ_PART(ipaddr, 2, 0x0000FFFF)) + #define IP_SET_TYPE_VAL(ipaddr, iptype) do { (ipaddr).type = (iptype); }while(0) #define IP_SET_TYPE(ipaddr, iptype) do { if((ipaddr) != NULL) { IP_SET_TYPE_VAL(*(ipaddr), iptype); }}while(0) #define IP_GET_TYPE(ipaddr) ((ipaddr)->type) @@ -156,6 +160,27 @@ extern const ip_addr_t ip_addr_any_type; ((IP_IS_V6(addr)) ? ip6addr_ntoa_r(ip_2_ip6(addr), buf, buflen) : ip4addr_ntoa_r(ip_2_ip4(addr), buf, buflen))) int ipaddr_aton(const char *cp, ip_addr_t *addr); +/* Map an IPv4 ip_addr into an IPV6 ip_addr, using format + defined in RFC4291 2.5.5.2. + + Safe to call when dest==src. +*/ +#define ip_addr_make_ip4_mapped_ip6(dest, src) do { \ + u32_t tmp = ip_2_ip4(src)->addr; \ + IP_ADDR6((dest), 0x0, 0x0, htonl(0x0000FFFF), tmp); \ + } while(0) + +/* Convert an IPv4 mapped V6 address to an IPV4 address. + + Check IP_IS_V4MAPPEDV6(src) before using this. + + Safe to call when dest == src. +*/ +#define ip_addr_ip4_from_mapped_ip6(dest, src) do { \ + ip_2_ip4(dest)->addr = ip_2_ip6(src)->addr[3]; \ + IP_SET_TYPE(dest, IPADDR_TYPE_V4); \ + } while(0) + #else /* LWIP_IPV4 && LWIP_IPV6 */ #define IP_ADDR_PCB_VERSION_MATCH(addr, pcb) 1 diff --git a/tools/sdk/include/lwip/lwip/mem.h b/tools/sdk/include/lwip/lwip/mem.h index a90d07256ba..966d6bbb0c1 100755 --- a/tools/sdk/include/lwip/lwip/mem.h +++ b/tools/sdk/include/lwip/lwip/mem.h @@ -54,12 +54,26 @@ typedef size_t mem_size_t; #ifndef mem_free #define mem_free free #endif +/** + * lwip_malloc: if CONFIG_ALLOC_MEMORY_IN_SPIRAM_FIRST is enabled, Try to + * allocate memory for lwip in SPIRAM firstly. If failed, try to allocate + * internal memory then. + */ +#if CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST +#ifndef mem_malloc +#define mem_malloc(size) heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL) +#endif +#ifndef mem_calloc +#define mem_calloc(n, size) heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL) +#endif +#else #ifndef mem_malloc #define mem_malloc malloc #endif #ifndef mem_calloc #define mem_calloc calloc #endif +#endif /* Since there is no C library allocation function to shrink memory without moving it, define this to nothing. */ diff --git a/tools/sdk/include/lwip/lwip/opt.h b/tools/sdk/include/lwip/lwip/opt.h index 4d8d6bf70c1..6ea556ac11d 100755 --- a/tools/sdk/include/lwip/lwip/opt.h +++ b/tools/sdk/include/lwip/lwip/opt.h @@ -823,6 +823,22 @@ #define LWIP_DHCP_AUTOIP_COOP_TRIES 9 #endif +/** + * LWIP_AUTOIP_MAX_CONFLICTS: + * Maximum number of AutoIP IP conflicts before rate limiting is enabled. + */ +#ifndef LWIP_AUTOIP_MAX_CONFLICTS +#define LWIP_AUTOIP_MAX_CONFLICTS 10 +#endif + +/** + * LWIP_AUTOIP_RATE_LIMIT_INTERVAL: + * Rate limited request interval, in seconds. + */ +#ifndef LWIP_AUTOIP_RATE_LIMIT_INTERVAL +#define LWIP_AUTOIP_RATE_LIMIT_INTERVAL 60 +#endif + /* ---------------------------------- ----- SNMP MIB2 support ----- diff --git a/tools/sdk/include/lwip/lwip/sockets.h b/tools/sdk/include/lwip/lwip/sockets.h index d9622ea03d7..cb458988a6e 100755 --- a/tools/sdk/include/lwip/lwip/sockets.h +++ b/tools/sdk/include/lwip/lwip/sockets.h @@ -262,6 +262,27 @@ struct linger { */ #define IPV6_CHECKSUM 7 /* RFC3542: calculate and insert the ICMPv6 checksum for raw sockets. */ #define IPV6_V6ONLY 27 /* RFC3493: boolean control to restrict AF_INET6 sockets to IPv6 communications only. */ + +#if LWIP_IPV6_MLD +/* Socket options for IPV6 multicast, uses the MLD interface to manage group memberships. RFC2133. */ +#define IPV6_MULTICAST_IF 0x300 +#define IPV6_MULTICAST_HOPS 0x301 +#define IPV6_MULTICAST_LOOP 0x302 +#define IPV6_ADD_MEMBERSHIP 0x303 +#define IPV6_DROP_MEMBERSHIP 0x304 + +/* Structure used for IPV6_ADD/DROP_MEMBERSHIP */ +typedef struct ip6_mreq { + struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast addr */ + struct in6_addr ipv6mr_interface; /* local IP address of interface */ +} ip6_mreq; + +/* Commonly used synonyms for these options */ +#define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP +#define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP + +#endif /* LWIP_IPV6_MLD */ + #endif /* LWIP_IPV6 */ #if LWIP_UDP && LWIP_UDPLITE diff --git a/tools/sdk/include/lwip/lwip/udp.h b/tools/sdk/include/lwip/lwip/udp.h index a370d3f9b91..c2f6ed9df7f 100755 --- a/tools/sdk/include/lwip/lwip/udp.h +++ b/tools/sdk/include/lwip/lwip/udp.h @@ -173,6 +173,12 @@ void udp_init (void); #define udp_get_multicast_netif_addr(pcb) ip_2_ip4(&(pcb)->multicast_ip) #define udp_set_multicast_ttl(pcb, value) do { (pcb)->mcast_ttl = value; } while(0) #define udp_get_multicast_ttl(pcb) ((pcb)->mcast_ttl) + +#if LWIP_IPV6_MLD +#define udp_set_multicast_netif_ip6addr(pcb, ip6addr) ip_addr_copy_from_ip6((pcb)->multicast_ip, *(ip6addr)) +#define udp_get_multicast_netif_ip6addr(pcb) ip_2_ip6(&(pcb)->multicast_ip) +#endif + #endif /* LWIP_MULTICAST_TX_OPTIONS */ #if UDP_DEBUG diff --git a/tools/sdk/include/lwip/lwipopts.h b/tools/sdk/include/lwip/lwipopts.h index 7bc4021e5a9..88f4b1184d8 100644 --- a/tools/sdk/include/lwip/lwipopts.h +++ b/tools/sdk/include/lwip/lwipopts.h @@ -34,6 +34,7 @@ #include #include +#include #include #include #include "esp_task.h" @@ -221,10 +222,7 @@ ---------- AUTOIP options ---------- ------------------------------------ */ -#if CONFIG_MDNS - /** - * LWIP_AUTOIP==1: Enable AUTOIP module. - */ +#ifdef CONFIG_LWIP_AUTOIP #define LWIP_AUTOIP 1 /** @@ -240,8 +238,13 @@ * be prepared to handle a changing IP address when DHCP overrides * AutoIP. */ -#define LWIP_DHCP_AUTOIP_COOP_TRIES 2 -#endif +#define LWIP_DHCP_AUTOIP_COOP_TRIES CONFIG_LWIP_AUTOIP_TRIES + +#define LWIP_AUTOIP_MAX_CONFLICTS CONFIG_LWIP_AUTOIP_MAX_CONFLICTS + +#define LWIP_AUTOIP_RATE_LIMIT_INTERVAL CONFIG_LWIP_AUTOIP_RATE_LIMIT_INTERVAL + +#endif /* CONFIG_LWIP_AUTOIP */ /* ---------------------------------- @@ -269,6 +272,9 @@ */ #define LWIP_DNS 1 +#define DNS_MAX_SERVERS 3 +#define DNS_FALLBACK_SERVER_INDEX (DNS_MAX_SERVERS - 1) + /* --------------------------------- ---------- UDP options ---------- @@ -367,7 +373,7 @@ ---------- LOOPIF options ---------- ------------------------------------ */ -#if CONFIG_MDNS +#ifdef CONFIG_LWIP_NETIF_LOOPBACK /** * LWIP_NETIF_LOOPBACK==1: Support sending packets with a destination IP * address equal to the netif IP address, looping them back up the stack. @@ -378,7 +384,7 @@ * LWIP_LOOPBACK_MAX_PBUFS: Maximum number of pbufs on queue for loopback * sending for each netif (0 = disabled) */ -#define LWIP_LOOPBACK_MAX_PBUFS 8 +#define LWIP_LOOPBACK_MAX_PBUFS CONFIG_LWIP_LOOPBACK_MAX_PBUFS #endif /* @@ -416,7 +422,7 @@ * The queue size value itself is platform-dependent, but is passed to * sys_mbox_new() when tcpip_init is called. */ -#define TCPIP_MBOX_SIZE 32 +#define TCPIP_MBOX_SIZE CONFIG_TCPIP_RECVMBOX_SIZE /** * DEFAULT_UDP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a @@ -506,24 +512,32 @@ */ #define SO_REUSE CONFIG_LWIP_SO_REUSE -#if CONFIG_MDNS /** * SO_REUSE_RXTOALL==1: Pass a copy of incoming broadcast/multicast packets * to all local matches if SO_REUSEADDR is turned on. * WARNING: Adds a memcpy for every packet if passing to more than one pcb! */ -#define SO_REUSE_RXTOALL 1 -#endif +#define SO_REUSE_RXTOALL CONFIG_LWIP_SO_REUSE_RXTOALL /* ---------------------------------------- ---------- Statistics options ---------- ---------------------------------------- */ + /** * LWIP_STATS==1: Enable statistics collection in lwip_stats. */ -#define LWIP_STATS 0 +#define LWIP_STATS CONFIG_LWIP_STATS + +#if LWIP_STATS + +/** + * LWIP_STATS_DISPLAY==1: Compile in the statistics output functions. + */ +#define LWIP_STATS_DISPLAY CONFIG_LWIP_STATS +#endif + /* --------------------------------- @@ -674,8 +688,21 @@ * The peer *is* in the ARP table if it requested our address before. * Also notice that this slows down input processing of every IP packet! */ -#define ETHARP_TRUST_IP_MAC 1 +#define ETHARP_TRUST_IP_MAC CONFIG_LWIP_ETHARP_TRUST_IP_MAC + + +/** + * POSIX I/O functions are mapped to LWIP via the VFS layer + * (see port/vfs_lwip.c) + */ +#define LWIP_POSIX_SOCKETS_IO_NAMES 0 + +/** + * Socket offset is also determined via the VFS layer at + * filesystem registration time (see port/vfs_lwip.c) + */ +#define LWIP_SOCKET_OFFSET lwip_socket_offset /* Enable all Espressif-only options */ @@ -692,11 +719,12 @@ #define ESP_IP4_ATON 1 #define ESP_LIGHT_SLEEP 1 #define ESP_L2_TO_L3_COPY CONFIG_L2_TO_L3_COPY -#define ESP_STATS_MEM 0 -#define ESP_STATS_DROP 0 +#define ESP_STATS_MEM CONFIG_LWIP_STATS +#define ESP_STATS_DROP CONFIG_LWIP_STATS #define ESP_STATS_TCP 0 #define ESP_DHCP_TIMER 1 #define ESP_LWIP_LOGI(...) ESP_LOGI("lwip", __VA_ARGS__) +#define ESP_PING 1 #define TCP_WND_DEFAULT CONFIG_TCP_WND_DEFAULT #define TCP_SND_BUF_DEFAULT CONFIG_TCP_SND_BUF_DEFAULT diff --git a/tools/sdk/include/lwip/port/arch/cc.h b/tools/sdk/include/lwip/port/arch/cc.h deleted file mode 100644 index cba0b365ea2..00000000000 --- a/tools/sdk/include/lwip/port/arch/cc.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2001, Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef __ARCH_CC_H__ -#define __ARCH_CC_H__ - -#include -#include -#include -#include - -#include "arch/sys_arch.h" - -#define BYTE_ORDER LITTLE_ENDIAN - -typedef uint8_t u8_t; -typedef int8_t s8_t; -typedef uint16_t u16_t; -typedef int16_t s16_t; -typedef uint32_t u32_t; -typedef int32_t s32_t; - -typedef unsigned long mem_ptr_t; -typedef int sys_prot_t; - -#define S16_F "d" -#define U16_F "d" -#define X16_F "x" - -#define S32_F "d" -#define U32_F "d" -#define X32_F "x" - -#define PACK_STRUCT_FIELD(x) x -#define PACK_STRUCT_STRUCT __attribute__((packed)) -#define PACK_STRUCT_BEGIN -#define PACK_STRUCT_END - -#include - -#define LWIP_PLATFORM_DIAG(x) do {printf x;} while(0) -// __assert_func is the assertion failure handler from newlib, defined in assert.h -#define LWIP_PLATFORM_ASSERT(message) __assert_func(__FILE__, __LINE__, __ASSERT_FUNC, message) - -#ifdef NDEBUG -#define LWIP_NOASSERT -#else // Assertions enabled - -// If assertions are on, the default LWIP_ERROR handler behaviour is to -// abort w/ an assertion failure. Don't do this, instead just print the error (if LWIP_DEBUG is set) -// and run the handler (same as the LWIP_ERROR behaviour if LWIP_NOASSERT is set). -#ifdef LWIP_DEBUG -#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \ - puts(message); handler;}} while(0) -#else -// If LWIP_DEBUG is not set, return the error silently (default LWIP behaviour, also.) -#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \ - handler;}} while(0) -#endif // LWIP_DEBUG - -#endif /* NDEBUG */ - - -#endif /* __ARCH_CC_H__ */ diff --git a/tools/sdk/include/lwip/port/arch/perf.h b/tools/sdk/include/lwip/port/arch/perf.h deleted file mode 100644 index 089facac1df..00000000000 --- a/tools/sdk/include/lwip/port/arch/perf.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2001, Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef __PERF_H__ -#define __PERF_H__ - -#define PERF_START /* null definition */ -#define PERF_STOP(x) /* null definition */ - -#endif /* __PERF_H__ */ diff --git a/tools/sdk/include/lwip/port/arch/sys_arch.h b/tools/sdk/include/lwip/port/arch/sys_arch.h deleted file mode 100644 index 716fd9fa53e..00000000000 --- a/tools/sdk/include/lwip/port/arch/sys_arch.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ - -#ifndef __SYS_ARCH_H__ -#define __SYS_ARCH_H__ - -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/queue.h" -#include "freertos/semphr.h" - -#ifdef __cplusplus -extern "C" { -#endif - - -typedef xSemaphoreHandle sys_sem_t; -typedef xSemaphoreHandle sys_mutex_t; -typedef xTaskHandle sys_thread_t; - -typedef struct sys_mbox_s { - xQueueHandle os_mbox; - sys_mutex_t lock; - uint8_t alive; -}* sys_mbox_t; - - -#define LWIP_COMPAT_MUTEX 0 - -#if !LWIP_COMPAT_MUTEX -#define sys_mutex_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE ) -#define sys_mutex_set_invalid( x ) ( ( *x ) = NULL ) -#endif - -#define sys_mbox_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE ) -#define sys_mbox_set_invalid( x ) ( ( *x ) = NULL ) - -#define sys_sem_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE ) -#define sys_sem_set_invalid( x ) ( ( *x ) = NULL ) - -void sys_delay_ms(uint32_t ms); -sys_sem_t* sys_thread_sem_init(void); -void sys_thread_sem_deinit(void); -sys_sem_t* sys_thread_sem_get(void); - -#ifdef __cplusplus -} -#endif - -#endif /* __SYS_ARCH_H__ */ - diff --git a/tools/sdk/include/lwip/port/arpa/inet.h b/tools/sdk/include/lwip/port/arpa/inet.h deleted file mode 100644 index 94c6c17ed5a..00000000000 --- a/tools/sdk/include/lwip/port/arpa/inet.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2015-2016 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. -// 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 INET_H_ -#define INET_H_ - -#include "lwip/inet.h" - -#endif /* INET_H_ */ diff --git a/tools/sdk/include/lwip/port/lwipopts.h b/tools/sdk/include/lwip/port/lwipopts.h deleted file mode 100644 index 7bc4021e5a9..00000000000 --- a/tools/sdk/include/lwip/port/lwipopts.h +++ /dev/null @@ -1,765 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Simon Goldschmidt - * - */ -#ifndef __LWIPOPTS_H__ -#define __LWIPOPTS_H__ - -#include -#include -#include -#include -#include "esp_task.h" -#include "esp_system.h" -#include "sdkconfig.h" - -/* Enable all Espressif-only options */ - -/* - ----------------------------------------------- - ---------- Platform specific locking ---------- - ----------------------------------------------- -*/ -/** - * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain - * critical regions during buffer allocation, deallocation and memory - * allocation and deallocation. - */ -#define SYS_LIGHTWEIGHT_PROT 1 - -/** - * MEMCPY: override this if you have a faster implementation at hand than the - * one included in your C library - */ -#define MEMCPY(dst,src,len) memcpy(dst,src,len) - -/** - * SMEMCPY: override this with care! Some compilers (e.g. gcc) can inline a - * call to memcpy() if the length is known at compile time and is small. - */ -#define SMEMCPY(dst,src,len) memcpy(dst,src,len) - -#define LWIP_RAND esp_random - -/* - ------------------------------------ - ---------- Memory options ---------- - ------------------------------------ -*/ -/** - * MEM_LIBC_MALLOC==1: Use malloc/free/realloc provided by your C-library - * instead of the lwip internal allocator. Can save code size if you - * already use it. - */ -#define MEM_LIBC_MALLOC 1 - -/** -* MEMP_MEM_MALLOC==1: Use mem_malloc/mem_free instead of the lwip pool allocator. -* Especially useful with MEM_LIBC_MALLOC but handle with care regarding execution -* speed and usage from interrupts! -*/ -#define MEMP_MEM_MALLOC 1 - -/** - * MEM_ALIGNMENT: should be set to the alignment of the CPU - * 4 byte alignment -> #define MEM_ALIGNMENT 4 - * 2 byte alignment -> #define MEM_ALIGNMENT 2 - */ -#define MEM_ALIGNMENT 4 - -/* - ------------------------------------------------ - ---------- Internal Memory Pool Sizes ---------- - ------------------------------------------------ -*/ - -/** - * MEMP_NUM_NETCONN: the number of struct netconns. - * (only needed if you use the sequential API, like api_lib.c) - */ -#define MEMP_NUM_NETCONN CONFIG_LWIP_MAX_SOCKETS - -/** - * MEMP_NUM_RAW_PCB: Number of raw connection PCBs - * (requires the LWIP_RAW option) - */ -#define MEMP_NUM_RAW_PCB 16 - -/** - * MEMP_NUM_TCP_PCB: the number of simulatenously active TCP connections. - * (requires the LWIP_TCP option) - */ -#define MEMP_NUM_TCP_PCB 16 - -/** - * MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP connections. - * (requires the LWIP_TCP option) - */ -#define MEMP_NUM_TCP_PCB_LISTEN 16 - -/** - * MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One - * per active UDP "connection". - * (requires the LWIP_UDP option) - */ -#define MEMP_NUM_UDP_PCB 16 - -/* - -------------------------------- - ---------- ARP options ------- - -------------------------------- -*/ -/** - * ARP_QUEUEING==1: Multiple outgoing packets are queued during hardware address - * resolution. By default, only the most recent packet is queued per IP address. - * This is sufficient for most protocols and mainly reduces TCP connection - * startup time. Set this to 1 if you know your application sends more than one - * packet in a row to an IP address that is not in the ARP cache. - */ -#define ARP_QUEUEING 1 - -/* - -------------------------------- - ---------- IP options ---------- - -------------------------------- -*/ -/** - * IP_REASSEMBLY==1: Reassemble incoming fragmented IP packets. Note that - * this option does not affect outgoing packet sizes, which can be controlled - * via IP_FRAG. - */ -#define IP_REASSEMBLY CONFIG_LWIP_IP_REASSEMBLY - -/** - * IP_FRAG==1: Fragment outgoing IP packets if their size exceeds MTU. Note - * that this option does not affect incoming packet sizes, which can be - * controlled via IP_REASSEMBLY. - */ -#define IP_FRAG CONFIG_LWIP_IP_FRAG - -/** - * IP_REASS_MAXAGE: Maximum time (in multiples of IP_TMR_INTERVAL - so seconds, normally) - * a fragmented IP packet waits for all fragments to arrive. If not all fragments arrived - * in this time, the whole packet is discarded. - */ -#define IP_REASS_MAXAGE 3 - -/** - * IP_REASS_MAX_PBUFS: Total maximum amount of pbufs waiting to be reassembled. - * Since the received pbufs are enqueued, be sure to configure - * PBUF_POOL_SIZE > IP_REASS_MAX_PBUFS so that the stack is still able to receive - * packets even if the maximum amount of fragments is enqueued for reassembly! - */ -#define IP_REASS_MAX_PBUFS 10 - -/* - ---------------------------------- - ---------- ICMP options ---------- - ---------------------------------- -*/ - -#define LWIP_BROADCAST_PING CONFIG_LWIP_BROADCAST_PING - -#define LWIP_MULTICAST_PING CONFIG_LWIP_MULTICAST_PING - -/* - --------------------------------- - ---------- RAW options ---------- - --------------------------------- -*/ -/** - * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. - */ -#define LWIP_RAW 1 - -/* - ---------------------------------- - ---------- DHCP options ---------- - ---------------------------------- -*/ -/** - * LWIP_DHCP==1: Enable DHCP module. - */ -#define LWIP_DHCP 1 - -#define DHCP_MAXRTX 0 - -/** - * DHCP_DOES_ARP_CHECK==1: Do an ARP check on the offered address. - */ -#define DHCP_DOES_ARP_CHECK CONFIG_LWIP_DHCP_DOES_ARP_CHECK - -/* - ------------------------------------ - ---------- AUTOIP options ---------- - ------------------------------------ -*/ -#if CONFIG_MDNS - /** - * LWIP_AUTOIP==1: Enable AUTOIP module. - */ -#define LWIP_AUTOIP 1 - -/** -* LWIP_DHCP_AUTOIP_COOP==1: Allow DHCP and AUTOIP to be both enabled on -* the same interface at the same time. -*/ -#define LWIP_DHCP_AUTOIP_COOP 1 - -/** -* LWIP_DHCP_AUTOIP_COOP_TRIES: Set to the number of DHCP DISCOVER probes -* that should be sent before falling back on AUTOIP. This can be set -* as low as 1 to get an AutoIP address very quickly, but you should -* be prepared to handle a changing IP address when DHCP overrides -* AutoIP. -*/ -#define LWIP_DHCP_AUTOIP_COOP_TRIES 2 -#endif - -/* - ---------------------------------- - ---------- SNMP options ---------- - ---------------------------------- -*/ -/* - ---------------------------------- - ---------- IGMP options ---------- - ---------------------------------- -*/ -/** - * LWIP_IGMP==1: Turn on IGMP module. - */ -#define LWIP_IGMP 1 - -/* - ---------------------------------- - ---------- DNS options ----------- - ---------------------------------- -*/ -/** - * LWIP_DNS==1: Turn on DNS module. UDP must be available for DNS - * transport. - */ -#define LWIP_DNS 1 - -/* - --------------------------------- - ---------- UDP options ---------- - --------------------------------- -*/ -/* - --------------------------------- - ---------- TCP options ---------- - --------------------------------- -*/ - - -/** - * TCP_QUEUE_OOSEQ==1: TCP will queue segments that arrive out of order. - * Define to 0 if your device is low on memory. - */ -#define TCP_QUEUE_OOSEQ CONFIG_TCP_QUEUE_OOSEQ - -/* - * LWIP_EVENT_API==1: The user defines lwip_tcp_event() to receive all - * events (accept, sent, etc) that happen in the system. - * LWIP_CALLBACK_API==1: The PCB callback function is called directly - * for the event. This is the default. -*/ -#define TCP_MSS CONFIG_TCP_MSS - -/** - * TCP_MSL: The maximum segment lifetime in milliseconds - */ -#define TCP_MSL CONFIG_TCP_MSL - -/** - * TCP_MAXRTX: Maximum number of retransmissions of data segments. - */ -#define TCP_MAXRTX CONFIG_TCP_MAXRTX - -/** - * TCP_SYNMAXRTX: Maximum number of retransmissions of SYN segments. - */ -#define TCP_SYNMAXRTX CONFIG_TCP_SYNMAXRTX - -/** - * TCP_LISTEN_BACKLOG: Enable the backlog option for tcp listen pcb. - */ -#define TCP_LISTEN_BACKLOG 1 - - -/** - * TCP_OVERSIZE: The maximum number of bytes that tcp_write may - * allocate ahead of time - */ -#ifdef CONFIG_TCP_OVERSIZE_MSS -#define TCP_OVERSIZE TCP_MSS -#endif -#ifdef CONFIG_TCP_OVERSIZE_QUARTER_MSS -#define TCP_OVERSIZE (TCP_MSS/4) -#endif -#ifdef CONFIG_TCP_OVERSIZE_DISABLE -#define TCP_OVERSIZE 0 -#endif -#ifndef TCP_OVERSIZE -#error "One of CONFIG_TCP_OVERSIZE_xxx options should be set by sdkconfig" -#endif - -/* - ---------------------------------- - ---------- Pbuf options ---------- - ---------------------------------- -*/ - -/* - ------------------------------------------------ - ---------- Network Interfaces options ---------- - ------------------------------------------------ -*/ - -/** - * LWIP_NETIF_HOSTNAME==1: use DHCP_OPTION_HOSTNAME with netif's hostname - * field. - */ -#define LWIP_NETIF_HOSTNAME 1 - -/** - * LWIP_NETIF_TX_SINGLE_PBUF: if this is set to 1, lwIP tries to put all data - * to be sent into one single pbuf. This is for compatibility with DMA-enabled - * MACs that do not support scatter-gather. - * Beware that this might involve CPU-memcpy before transmitting that would not - * be needed without this flag! Use this only if you need to! - * - * @todo: TCP and IP-frag do not work with this, yet: - */ -#define LWIP_NETIF_TX_SINGLE_PBUF 1 - -/* - ------------------------------------ - ---------- LOOPIF options ---------- - ------------------------------------ -*/ -#if CONFIG_MDNS -/** - * LWIP_NETIF_LOOPBACK==1: Support sending packets with a destination IP - * address equal to the netif IP address, looping them back up the stack. - */ -#define LWIP_NETIF_LOOPBACK 1 - -/** - * LWIP_LOOPBACK_MAX_PBUFS: Maximum number of pbufs on queue for loopback - * sending for each netif (0 = disabled) - */ -#define LWIP_LOOPBACK_MAX_PBUFS 8 -#endif - -/* - ------------------------------------ - ---------- SLIPIF options ---------- - ------------------------------------ -*/ - -/* - ------------------------------------ - ---------- Thread options ---------- - ------------------------------------ -*/ -/** - * TCPIP_THREAD_NAME: The name assigned to the main tcpip thread. - */ -#define TCPIP_THREAD_NAME "tiT" - -/** - * TCPIP_THREAD_STACKSIZE: The stack size used by the main tcpip thread. - * The stack size value itself is platform-dependent, but is passed to - * sys_thread_new() when the thread is created. - */ -#define TCPIP_THREAD_STACKSIZE ESP_TASK_TCPIP_STACK - -/** - * TCPIP_THREAD_PRIO: The priority assigned to the main tcpip thread. - * The priority value itself is platform-dependent, but is passed to - * sys_thread_new() when the thread is created. - */ -#define TCPIP_THREAD_PRIO ESP_TASK_TCPIP_PRIO - -/** - * TCPIP_MBOX_SIZE: The mailbox size for the tcpip thread messages - * The queue size value itself is platform-dependent, but is passed to - * sys_mbox_new() when tcpip_init is called. - */ -#define TCPIP_MBOX_SIZE 32 - -/** - * DEFAULT_UDP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a - * NETCONN_UDP. The queue size value itself is platform-dependent, but is passed - * to sys_mbox_new() when the recvmbox is created. - */ -#define DEFAULT_UDP_RECVMBOX_SIZE CONFIG_UDP_RECVMBOX_SIZE - -/** - * DEFAULT_TCP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a - * NETCONN_TCP. The queue size value itself is platform-dependent, but is passed - * to sys_mbox_new() when the recvmbox is created. - */ -#define DEFAULT_TCP_RECVMBOX_SIZE CONFIG_TCP_RECVMBOX_SIZE - -/** - * DEFAULT_ACCEPTMBOX_SIZE: The mailbox size for the incoming connections. - * The queue size value itself is platform-dependent, but is passed to - * sys_mbox_new() when the acceptmbox is created. - */ -#define DEFAULT_ACCEPTMBOX_SIZE 6 - -/** - * DEFAULT_THREAD_STACKSIZE: The stack size used by any other lwIP thread. - * The stack size value itself is platform-dependent, but is passed to - * sys_thread_new() when the thread is created. - */ -#define DEFAULT_THREAD_STACKSIZE TCPIP_THREAD_STACKSIZE - -/** - * DEFAULT_THREAD_PRIO: The priority assigned to any other lwIP thread. - * The priority value itself is platform-dependent, but is passed to - * sys_thread_new() when the thread is created. - */ -#define DEFAULT_THREAD_PRIO TCPIP_THREAD_PRIO - -/** - * DEFAULT_RAW_RECVMBOX_SIZE: The mailbox size for the incoming packets on a - * NETCONN_RAW. The queue size value itself is platform-dependent, but is passed - * to sys_mbox_new() when the recvmbox is created. - */ -#define DEFAULT_RAW_RECVMBOX_SIZE 6 - -/* - ---------------------------------------------- - ---------- Sequential layer options ---------- - ---------------------------------------------- -*/ -/** - * LWIP_TCPIP_CORE_LOCKING: (EXPERIMENTAL!) - * Don't use it if you're not an active lwIP project member - */ -#define LWIP_TCPIP_CORE_LOCKING 0 - -/* - ------------------------------------ - ---------- Socket options ---------- - ------------------------------------ -*/ -/** - * LWIP_SO_SNDTIMEO==1: Enable send timeout for sockets/netconns and - * SO_SNDTIMEO processing. - */ -#define LWIP_SO_SNDTIMEO 1 - -/** - * LWIP_SO_RCVTIMEO==1: Enable receive timeout for sockets/netconns and - * SO_RCVTIMEO processing. - */ -#define LWIP_SO_RCVTIMEO 1 - -/** - * LWIP_TCP_KEEPALIVE==1: Enable TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT - * options processing. Note that TCP_KEEPIDLE and TCP_KEEPINTVL have to be set - * in seconds. (does not require sockets.c, and will affect tcp.c) - */ -#define LWIP_TCP_KEEPALIVE 1 - -/** - * LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing. - */ -#define LWIP_SO_RCVBUF CONFIG_LWIP_SO_RCVBUF - -/** - * SO_REUSE==1: Enable SO_REUSEADDR option. - * This option is set via menuconfig. - */ -#define SO_REUSE CONFIG_LWIP_SO_REUSE - -#if CONFIG_MDNS -/** - * SO_REUSE_RXTOALL==1: Pass a copy of incoming broadcast/multicast packets - * to all local matches if SO_REUSEADDR is turned on. - * WARNING: Adds a memcpy for every packet if passing to more than one pcb! - */ -#define SO_REUSE_RXTOALL 1 -#endif - -/* - ---------------------------------------- - ---------- Statistics options ---------- - ---------------------------------------- -*/ -/** - * LWIP_STATS==1: Enable statistics collection in lwip_stats. - */ -#define LWIP_STATS 0 - -/* - --------------------------------- - ---------- PPP options ---------- - --------------------------------- -*/ - -/** - * PPP_SUPPORT==1: Enable PPP. - */ -#define PPP_SUPPORT CONFIG_PPP_SUPPORT - -#if PPP_SUPPORT - -/** - * PAP_SUPPORT==1: Support PAP. - */ -#define PAP_SUPPORT CONFIG_PPP_PAP_SUPPORT - -/** - * CHAP_SUPPORT==1: Support CHAP. - */ -#define CHAP_SUPPORT CONFIG_PPP_CHAP_SUPPORT - -/** - * MSCHAP_SUPPORT==1: Support MSCHAP. - */ -#define MSCHAP_SUPPORT CONFIG_PPP_MSCHAP_SUPPORT - -/** - * CCP_SUPPORT==1: Support CCP. - */ -#define MPPE_SUPPORT CONFIG_PPP_MPPE_SUPPORT - -/** - * PPP_MAXIDLEFLAG: Max Xmit idle time (in ms) before resend flag char. - * TODO: If PPP_MAXIDLEFLAG > 0 and next package is send during PPP_MAXIDLEFLAG time, - * then 0x7E is not added at the begining of PPP package but 0x7E termination - * is always at the end. This behaviour brokes PPP dial with GSM (PPPoS). - * The PPP package should always start and end with 0x7E. - */ - -#define PPP_MAXIDLEFLAG 0 - -/** - * PPP_DEBUG: Enable debugging for PPP. - */ -#define PPP_DEBUG_ON CONFIG_PPP_DEBUG_ON - -#if PPP_DEBUG_ON -#define PPP_DEBUG LWIP_DBG_ON -#else -#define PPP_DEBUG LWIP_DBG_OFF -#endif - -#endif - -/* - -------------------------------------- - ---------- Checksum options ---------- - -------------------------------------- -*/ - -/* - --------------------------------------- - ---------- IPv6 options --------------- - --------------------------------------- -*/ -/** - * LWIP_IPV6==1: Enable IPv6 - */ -#define LWIP_IPV6 1 - -/* - --------------------------------------- - ---------- Hook options --------------- - --------------------------------------- -*/ -#define LWIP_HOOK_IP4_ROUTE_SRC ip4_route_src_hook - -/* - --------------------------------------- - ---------- Debugging options ---------- - --------------------------------------- -*/ -/** - * ETHARP_DEBUG: Enable debugging in etharp.c. - */ -#define ETHARP_DEBUG LWIP_DBG_OFF - -/** - * NETIF_DEBUG: Enable debugging in netif.c. - */ -#define NETIF_DEBUG LWIP_DBG_OFF - -/** - * PBUF_DEBUG: Enable debugging in pbuf.c. - */ -#define PBUF_DEBUG LWIP_DBG_OFF - -/** - * API_LIB_DEBUG: Enable debugging in api_lib.c. - */ -#define API_LIB_DEBUG LWIP_DBG_OFF - -/** - * SOCKETS_DEBUG: Enable debugging in sockets.c. - */ -#define SOCKETS_DEBUG LWIP_DBG_OFF - -/** - * ICMP_DEBUG: Enable debugging in icmp.c. - */ -#define ICMP_DEBUG LWIP_DBG_OFF - -/** - * IP_DEBUG: Enable debugging for IP. - */ -#define IP_DEBUG LWIP_DBG_OFF - -/** - * MEMP_DEBUG: Enable debugging in memp.c. - */ -#define MEMP_DEBUG LWIP_DBG_OFF - -/** - * TCP_INPUT_DEBUG: Enable debugging in tcp_in.c for incoming debug. - */ -#define TCP_INPUT_DEBUG LWIP_DBG_OFF - -/** - * TCP_OUTPUT_DEBUG: Enable debugging in tcp_out.c output functions. - */ -#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF - -/** - * TCPIP_DEBUG: Enable debugging in tcpip.c. - */ -#define TCPIP_DEBUG LWIP_DBG_OFF - -/** - * ETHARP_TRUST_IP_MAC==1: Incoming IP packets cause the ARP table to be - * updated with the source MAC and IP addresses supplied in the packet. - * You may want to disable this if you do not trust LAN peers to have the - * correct addresses, or as a limited approach to attempt to handle - * spoofing. If disabled, lwIP will need to make a new ARP request if - * the peer is not already in the ARP table, adding a little latency. - * The peer *is* in the ARP table if it requested our address before. - * Also notice that this slows down input processing of every IP packet! - */ -#define ETHARP_TRUST_IP_MAC 1 - - -/* Enable all Espressif-only options */ - -#define ESP_LWIP 1 -#define ESP_LWIP_ARP 1 -#define ESP_PER_SOC_TCP_WND 1 -#define ESP_THREAD_SAFE 1 -#define ESP_THREAD_SAFE_DEBUG LWIP_DBG_OFF -#define ESP_DHCP 1 -#define ESP_DNS 1 -#define ESP_IPV6_AUTOCONFIG 1 -#define ESP_PERF 0 -#define ESP_RANDOM_TCP_PORT 1 -#define ESP_IP4_ATON 1 -#define ESP_LIGHT_SLEEP 1 -#define ESP_L2_TO_L3_COPY CONFIG_L2_TO_L3_COPY -#define ESP_STATS_MEM 0 -#define ESP_STATS_DROP 0 -#define ESP_STATS_TCP 0 -#define ESP_DHCP_TIMER 1 -#define ESP_LWIP_LOGI(...) ESP_LOGI("lwip", __VA_ARGS__) - -#define TCP_WND_DEFAULT CONFIG_TCP_WND_DEFAULT -#define TCP_SND_BUF_DEFAULT CONFIG_TCP_SND_BUF_DEFAULT - -#if ESP_PERF -#define DBG_PERF_PATH_SET(dir, point) -#define DBG_PERF_FILTER_LEN 1000 - -enum { - DBG_PERF_DIR_RX = 0, - DBG_PERF_DIR_TX, -}; - -enum { - DBG_PERF_POINT_INT = 0, - DBG_PERF_POINT_WIFI_IN = 1, - DBG_PERF_POINT_WIFI_OUT = 2, - DBG_PERF_POINT_LWIP_IN = 3, - DBG_PERF_POINT_LWIP_OUT = 4, - DBG_PERF_POINT_SOC_IN = 5, - DBG_PERF_POINT_SOC_OUT = 6, -}; - -#else -#define DBG_PERF_PATH_SET(dir, point) -#define DBG_PERF_FILTER_LEN 1000 -#endif - -#if ESP_PER_SOC_TCP_WND -#define TCP_WND(pcb) (pcb->per_soc_tcp_wnd) -#define TCP_SND_BUF(pcb) (pcb->per_soc_tcp_snd_buf) -#endif - -/** - * DHCP_DEBUG: Enable debugging in dhcp.c. - */ -#define DHCP_DEBUG LWIP_DBG_OFF -#define LWIP_DEBUG LWIP_DBG_OFF -#define TCP_DEBUG LWIP_DBG_OFF - -#define CHECKSUM_CHECK_UDP 0 -#define CHECKSUM_CHECK_IP 0 - -#define LWIP_NETCONN_FULLDUPLEX 1 -#define LWIP_NETCONN_SEM_PER_THREAD 1 - -#define LWIP_DHCP_MAX_NTP_SERVERS CONFIG_LWIP_DHCP_MAX_NTP_SERVERS -#define LWIP_TIMEVAL_PRIVATE 0 - -#define SNTP_SET_SYSTEM_TIME_US(sec, us) \ - do { \ - struct timeval tv = { .tv_sec = sec, .tv_usec = us }; \ - settimeofday(&tv, NULL); \ - } while (0); - -#define SNTP_GET_SYSTEM_TIME(sec, us) \ - do { \ - struct timeval tv = { .tv_sec = 0, .tv_usec = 0 }; \ - gettimeofday(&tv, NULL); \ - (sec) = tv.tv_sec; \ - (us) = tv.tv_usec; \ - } while (0); - -#define SOC_SEND_LOG //printf - -#endif /* __LWIPOPTS_H__ */ diff --git a/tools/sdk/include/lwip/port/netinet/in.h b/tools/sdk/include/lwip/port/netinet/in.h deleted file mode 100644 index 7eaec63342f..00000000000 --- a/tools/sdk/include/lwip/port/netinet/in.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2015-2016 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. -// 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 IN_H_ -#define IN_H_ - -#include "lwip/inet.h" - -#define IN6_IS_ADDR_MULTICAST(a) IN_MULTICAST(a) - -#endif /* IN_H_ */ diff --git a/tools/sdk/include/lwip/posix/netdb.h b/tools/sdk/include/lwip/posix/netdb.h deleted file mode 100755 index 12d4c7f566c..00000000000 --- a/tools/sdk/include/lwip/posix/netdb.h +++ /dev/null @@ -1,33 +0,0 @@ -/** - * @file - * This file is a posix wrapper for lwip/netdb.h. - */ - -/* - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - */ - -#include "lwip/netdb.h" diff --git a/tools/sdk/include/lwip/posix/sys/socket.h b/tools/sdk/include/lwip/posix/sys/socket.h deleted file mode 100755 index 0ed9baf3d9f..00000000000 --- a/tools/sdk/include/lwip/posix/sys/socket.h +++ /dev/null @@ -1,33 +0,0 @@ -/** - * @file - * This file is a posix wrapper for lwip/sockets.h. - */ - -/* - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - */ - -#include "lwip/sockets.h" diff --git a/tools/sdk/include/newlib/sys/types.h b/tools/sdk/include/newlib/sys/types.h index ed33e0a617e..446946a36be 100644 --- a/tools/sdk/include/newlib/sys/types.h +++ b/tools/sdk/include/newlib/sys/types.h @@ -221,6 +221,9 @@ typedef unsigned int mode_t _ST_INT32; typedef unsigned short nlink_t; +/* FD_SET and friends are still LWIP only */ +# if !defined(ESP_PLATFORM) + /* We don't define fd_set and friends if we are compiling POSIX source, or if we have included (or may include as indicated by __USE_W32_SOCKETS) the W32api winsock[2].h header which @@ -266,6 +269,7 @@ typedef struct _types_fd_set { })) # endif /* !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (_WINSOCKAPI_) || defined (__USE_W32_SOCKETS)) */ +#endif /* !defined(ESP_PLATFORM) */ #undef __MS_types__ #undef _ST_INT32 diff --git a/tools/sdk/include/nvs_flash/nvs_flash.h b/tools/sdk/include/nvs_flash/nvs_flash.h index c9e4a72d742..a7ef7f4511e 100644 --- a/tools/sdk/include/nvs_flash/nvs_flash.h +++ b/tools/sdk/include/nvs_flash/nvs_flash.h @@ -24,7 +24,7 @@ extern "C" { * @brief Initialize the default NVS partition. * * This API initialises the default NVS partition. The default NVS partition - * is the one that is labelled "nvs" in the partition table. + * is the one that is labeled "nvs" in the partition table. * * @return * - ESP_OK if storage was successfully initialized. @@ -38,7 +38,7 @@ esp_err_t nvs_flash_init(void); /** * @brief Initialize NVS flash storage for the specified partition. * - * @param[in] partition_name Name (label) of the partition. Note that internally a reference to + * @param[in] partition_label Label of the partition. Note that internally a reference to * passed value is kept and it should be accessible for future operations * * @return @@ -48,7 +48,30 @@ esp_err_t nvs_flash_init(void); * - ESP_ERR_NOT_FOUND if specified partition is not found in the partition table * - one of the error codes from the underlying flash storage driver */ -esp_err_t nvs_flash_init_partition(const char *partition_name); +esp_err_t nvs_flash_init_partition(const char *partition_label); + +/** + * @brief Deinitialize NVS storage for the default NVS partition + * + * Default NVS partition is the partition with "nvs" label in the partition table. + * + * @return + * - ESP_OK on success (storage was deinitialized) + * - ESP_ERR_NVS_NOT_INITIALIZED if the storage was not initialized prior to this call + */ +esp_err_t nvs_flash_deinit(void); + +/** + * @brief Deinitialize NVS storage for the given NVS partition + * + * @param[in] partition_label Label of the partition + * + * @return + * - ESP_OK on success + * - ESP_ERR_NVS_NOT_INITIALIZED if the storage for given partition was not + * initialized prior to this call + */ +esp_err_t nvs_flash_deinit_partition(const char* partition_label); /** * @brief Erase the default NVS partition diff --git a/tools/sdk/include/soc/soc/rtc.h b/tools/sdk/include/soc/soc/rtc.h index b47e39e1e7b..f13c113b4e4 100644 --- a/tools/sdk/include/soc/soc/rtc.h +++ b/tools/sdk/include/soc/soc/rtc.h @@ -276,6 +276,25 @@ rtc_fast_freq_t rtc_clk_fast_freq_get(); */ void rtc_clk_cpu_freq_set(rtc_cpu_freq_t cpu_freq); +/** + * @brief Switch CPU frequency + * + * This is a faster version of rtc_clk_cpu_freq_set, which can handle some of + * the frequency switch paths (XTAL -> PLL, PLL -> XTAL). + * When switching from PLL to XTAL, PLL is not disabled (unlike rtc_clk_cpu_freq_set). + * When switching back from XTAL to PLL, only the same PLL can be used. + * Therefore it is not possible to switch 240 -> XTAL -> (80 or 160) using this + * function. + * + * For unsupported cases, this function falls back to rtc_clk_cpu_freq_set. + * + * Unlike rtc_clk_cpu_freq_set, this function relies on static data, so it is + * less safe to use it e.g. from a panic handler (when memory might be corrupted). + * + * @param cpu_freq new CPU frequency + */ +void rtc_clk_cpu_freq_set_fast(rtc_cpu_freq_t cpu_freq); + /** * @brief Get the currently selected CPU frequency * @@ -296,6 +315,14 @@ rtc_cpu_freq_t rtc_clk_cpu_freq_get(); */ uint32_t rtc_clk_cpu_freq_value(rtc_cpu_freq_t cpu_freq); +/** + * @brief Get rtc_cpu_freq_t enum value for given CPU frequency + * @param cpu_freq_mhz CPU frequency, one of 80, 160, 240, 2, and XTAL frequency + * @param[out] out_val output, rtc_cpu_freq_t value corresponding to the frequency + * @return true if the given frequency value matches one of enum values + */ + bool rtc_clk_cpu_freq_from_mhz(int cpu_freq_mhz, rtc_cpu_freq_t* out_val); + /** * @brief Store new APB frequency value into RTC_APB_FREQ_REG * diff --git a/tools/sdk/include/soc/soc/sens_reg.h b/tools/sdk/include/soc/soc/sens_reg.h index 0a032d218ec..6383ff62cdc 100644 --- a/tools/sdk/include/soc/soc/sens_reg.h +++ b/tools/sdk/include/soc/soc/sens_reg.h @@ -297,6 +297,8 @@ #define SENS_SAR1_ATTEN_M ((SENS_SAR1_ATTEN_V)<<(SENS_SAR1_ATTEN_S)) #define SENS_SAR1_ATTEN_V 0xFFFFFFFF #define SENS_SAR1_ATTEN_S 0 +#define SENS_SAR1_ATTEN_VAL_MASK 0x3 +#define SENS_SAR2_ATTEN_VAL_MASK 0x3 #define SENS_SAR_ATTEN2_REG (DR_REG_SENS_BASE + 0x0038) /* SENS_SAR2_ATTEN : R/W ;bitpos:[31:0] ;default: 32'hffffffff ; */ diff --git a/tools/sdk/include/soc/soc/soc.h b/tools/sdk/include/soc/soc/soc.h index 5d5cf3b7db4..8121e33b062 100644 --- a/tools/sdk/include/soc/soc/soc.h +++ b/tools/sdk/include/soc/soc/soc.h @@ -266,6 +266,7 @@ #define CPU_CLK_FREQ_ROM APB_CLK_FREQ_ROM #define CPU_CLK_FREQ APB_CLK_FREQ #define APB_CLK_FREQ ( 80*1000000 ) //unit: Hz +#define REF_CLK_FREQ ( 1000000 ) #define UART_CLK_FREQ APB_CLK_FREQ #define WDT_CLK_FREQ APB_CLK_FREQ #define TIMER_CLK_FREQ (80000000>>4) //80MHz divided by 16 @@ -274,12 +275,12 @@ //}} /* Overall memory map */ +#define SOC_DROM_LOW 0x3F400000 +#define SOC_DROM_HIGH 0x3F800000 #define SOC_IROM_LOW 0x400D0000 #define SOC_IROM_HIGH 0x40400000 #define SOC_IRAM_LOW 0x40080000 #define SOC_IRAM_HIGH 0x400A0000 -#define SOC_DROM_LOW 0x3F400000 -#define SOC_DROM_HIGH 0x3F800000 #define SOC_RTC_IRAM_LOW 0x400C0000 #define SOC_RTC_IRAM_HIGH 0x400C2000 #define SOC_RTC_DATA_LOW 0x50000000 @@ -295,6 +296,16 @@ #define SOC_DMA_LOW 0x3FFAE000 #define SOC_DMA_HIGH 0x40000000 +// Region of memory that is byte-accessible. See esp_ptr_byte_accessible(). +#define SOC_BYTE_ACCESSIBLE_LOW 0x3FF90000 +#define SOC_BYTE_ACCESSIBLE_HIGH 0x40000000 + +//Region of memory that is internal, as in on the same silicon die as the ESP32 CPUs +//(excluding RTC data region, that's checked separately.) See esp_ptr_internal(). +#define SOC_MEM_INTERNAL_LOW 0x3FF90000 +#define SOC_MEM_INTERNAL_HIGH 0x400C2000 + + //Interrupt hardware source table //This table is decided by hardware, don't touch this. #define ETS_WIFI_MAC_INTR_SOURCE 0/**< interrupt of WiFi MAC, level*/ diff --git a/tools/sdk/include/soc/soc/soc_memory_layout.h b/tools/sdk/include/soc/soc/soc_memory_layout.h new file mode 100644 index 00000000000..1c1415e3dc3 --- /dev/null +++ b/tools/sdk/include/soc/soc/soc_memory_layout.h @@ -0,0 +1,91 @@ +// Copyright 2010-2016 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. +// 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. +#pragma once +#include +#include +#include + +#include "soc/soc.h" +#include "sdkconfig.h" +#include "esp_attr.h" + +#define SOC_MEMORY_TYPE_NO_PRIOS 3 + +/* Type descriptor holds a description for a particular type of memory on a particular SoC. + */ +typedef struct { + const char *name; ///< Name of this memory type + uint32_t caps[SOC_MEMORY_TYPE_NO_PRIOS]; ///< Capabilities for this memory type (as a prioritised set) + bool aliased_iram; ///< If true, this is data memory that is is also mapped in IRAM + bool startup_stack; ///< If true, memory of this type is used for ROM stack during startup +} soc_memory_type_desc_t; + +/* Constant table of tag descriptors for all this SoC's tags */ +extern const soc_memory_type_desc_t soc_memory_types[]; +extern const size_t soc_memory_type_count; + +/* Region descriptor holds a description for a particular region of memory on a particular SoC. + */ +typedef struct +{ + intptr_t start; ///< Start address of the region + size_t size; ///< Size of the region in bytes + size_t type; ///< Type of the region (index into soc_memory_types array) + intptr_t iram_address; ///< If non-zero, is equivalent address in IRAM +} soc_memory_region_t; + +extern const soc_memory_region_t soc_memory_regions[]; +extern const size_t soc_memory_region_count; + +/* Region descriptor holds a description for a particular region of + memory reserved on this SoC for a particular use (ie not available + for stack/heap usage.) */ +typedef struct +{ + intptr_t start; + intptr_t end; +} soc_reserved_region_t; + +extern const soc_reserved_region_t soc_reserved_regions[]; +extern const size_t soc_reserved_region_count; + +inline static bool IRAM_ATTR esp_ptr_dma_capable(const void *p) +{ + return (intptr_t)p >= SOC_DMA_LOW && (intptr_t)p < SOC_DMA_HIGH; +} + +inline static bool IRAM_ATTR esp_ptr_executable(const void *p) +{ + intptr_t ip = (intptr_t) p; + return (ip >= SOC_IROM_LOW && ip < SOC_IROM_HIGH) + || (ip >= SOC_IRAM_LOW && ip < SOC_IRAM_HIGH) + || (ip >= SOC_RTC_IRAM_LOW && ip < SOC_RTC_IRAM_HIGH); +} + +inline static bool IRAM_ATTR esp_ptr_byte_accessible(const void *p) +{ + bool r; + r = ((intptr_t)p >= SOC_BYTE_ACCESSIBLE_LOW && (intptr_t)p < SOC_BYTE_ACCESSIBLE_HIGH); +#if CONFIG_SPIRAM_SUPPORT + r |= ((intptr_t)p >= SOC_EXTRAM_DATA_LOW && (intptr_t)p < SOC_EXTRAM_DATA_HIGH); +#endif + return r; +} + +inline static bool IRAM_ATTR esp_ptr_internal(const void *p) { + bool r; + r = ((intptr_t)p >= SOC_MEM_INTERNAL_LOW && (intptr_t)p < SOC_MEM_INTERNAL_HIGH); + r |= ((intptr_t)p >= SOC_RTC_DATA_LOW && (intptr_t)p < SOC_RTC_DATA_HIGH); + return r; +} diff --git a/tools/sdk/include/soc/soc/syscon_struct.h b/tools/sdk/include/soc/soc/syscon_struct.h index 60d8ed0ab5e..42bd643d169 100644 --- a/tools/sdk/include/soc/soc/syscon_struct.h +++ b/tools/sdk/include/soc/soc/syscon_struct.h @@ -18,112 +18,106 @@ extern "C" { #endif -typedef struct { +typedef volatile struct { union { struct { - volatile uint32_t pre_div: 10; - volatile uint32_t clk_320m_en: 1; - volatile uint32_t clk_en: 1; - volatile uint32_t rst_tick: 1; - volatile uint32_t quick_clk_chng: 1; - volatile uint32_t reserved14: 18; + uint32_t pre_div: 10; + uint32_t clk_320m_en: 1; + uint32_t clk_en: 1; + uint32_t rst_tick: 1; + uint32_t quick_clk_chng: 1; + uint32_t reserved14: 18; }; - volatile uint32_t val; + uint32_t val; }clk_conf; union { struct { - volatile uint32_t xtal_tick: 8; - volatile uint32_t reserved8: 24; + uint32_t xtal_tick: 8; + uint32_t reserved8: 24; }; - volatile uint32_t val; + uint32_t val; }xtal_tick_conf; union { struct { - volatile uint32_t pll_tick: 8; - volatile uint32_t reserved8: 24; + uint32_t pll_tick: 8; + uint32_t reserved8: 24; }; - volatile uint32_t val; + uint32_t val; }pll_tick_conf; union { struct { - volatile uint32_t ck8m_tick: 8; - volatile uint32_t reserved8: 24; + uint32_t ck8m_tick: 8; + uint32_t reserved8: 24; }; - volatile uint32_t val; + uint32_t val; }ck8m_tick_conf; union { struct { - volatile uint32_t start_force: 1; - volatile uint32_t start: 1; - volatile uint32_t sar2_mux: 1; /*1: SAR ADC2 is controlled by DIG ADC2 CTRL 0: SAR ADC2 is controlled by PWDET CTRL*/ - volatile uint32_t work_mode: 2; /*0: single mode 1: double mode 2: alternate mode*/ - volatile uint32_t sar_sel: 1; /*0: SAR1 1: SAR2 only work for single SAR mode*/ - volatile uint32_t sar_clk_gated: 1; - volatile uint32_t sar_clk_div: 8; /*SAR clock divider*/ - volatile uint32_t sar1_patt_len: 4; /*0 ~ 15 means length 1 ~ 16*/ - volatile uint32_t sar2_patt_len: 4; /*0 ~ 15 means length 1 ~ 16*/ - volatile uint32_t sar1_patt_p_clear: 1; /*clear the pointer of pattern table for DIG ADC1 CTRL*/ - volatile uint32_t sar2_patt_p_clear: 1; /*clear the pointer of pattern table for DIG ADC2 CTRL*/ - volatile uint32_t data_sar_sel: 1; /*1: sar_sel will be coded by the MSB of the 16-bit output data in this case the resolution should not be larger than 11 bits.*/ - volatile uint32_t data_to_i2s: 1; /*1: I2S input data is from SAR ADC (for DMA) 0: I2S input data is from GPIO matrix*/ - volatile uint32_t reserved27: 5; + uint32_t start_force: 1; + uint32_t start: 1; + uint32_t sar2_mux: 1; /*1: SAR ADC2 is controlled by DIG ADC2 CTRL 0: SAR ADC2 is controlled by PWDET CTRL*/ + uint32_t work_mode: 2; /*0: single mode 1: double mode 2: alternate mode*/ + uint32_t sar_sel: 1; /*0: SAR1 1: SAR2 only work for single SAR mode*/ + uint32_t sar_clk_gated: 1; + uint32_t sar_clk_div: 8; /*SAR clock divider*/ + uint32_t sar1_patt_len: 4; /*0 ~ 15 means length 1 ~ 16*/ + uint32_t sar2_patt_len: 4; /*0 ~ 15 means length 1 ~ 16*/ + uint32_t sar1_patt_p_clear: 1; /*clear the pointer of pattern table for DIG ADC1 CTRL*/ + uint32_t sar2_patt_p_clear: 1; /*clear the pointer of pattern table for DIG ADC2 CTRL*/ + uint32_t data_sar_sel: 1; /*1: sar_sel will be coded by the MSB of the 16-bit output data in this case the resolution should not be larger than 11 bits.*/ + uint32_t data_to_i2s: 1; /*1: I2S input data is from SAR ADC (for DMA) 0: I2S input data is from GPIO matrix*/ + uint32_t reserved27: 5; }; - volatile uint32_t val; + uint32_t val; }saradc_ctrl; union { struct { - volatile uint32_t meas_num_limit: 1; - volatile uint32_t max_meas_num: 8; /*max conversion number*/ - volatile uint32_t sar1_inv: 1; /*1: data to DIG ADC1 CTRL is inverted otherwise not*/ - volatile uint32_t sar2_inv: 1; /*1: data to DIG ADC2 CTRL is inverted otherwise not*/ - volatile uint32_t reserved11: 21; + uint32_t meas_num_limit: 1; + uint32_t max_meas_num: 8; /*max conversion number*/ + uint32_t sar1_inv: 1; /*1: data to DIG ADC1 CTRL is inverted otherwise not*/ + uint32_t sar2_inv: 1; /*1: data to DIG ADC2 CTRL is inverted otherwise not*/ + uint32_t reserved11: 21; }; - volatile uint32_t val; + uint32_t val; }saradc_ctrl2; union { struct { - volatile uint32_t rstb_wait: 8; - volatile uint32_t standby_wait: 8; - volatile uint32_t start_wait: 8; - volatile uint32_t sample_cycle: 8; /*sample cycles*/ + uint32_t rstb_wait: 8; + uint32_t standby_wait: 8; + uint32_t start_wait: 8; + uint32_t sample_cycle: 8; /*sample cycles*/ }; - volatile uint32_t val; + uint32_t val; }saradc_fsm; - volatile uint32_t saradc_sar1_patt_tab1; /*item 0 ~ 3 for pattern table 1 (each item one byte)*/ - volatile uint32_t saradc_sar1_patt_tab2; /*Item 4 ~ 7 for pattern table 1 (each item one byte)*/ - volatile uint32_t saradc_sar1_patt_tab3; /*Item 8 ~ 11 for pattern table 1 (each item one byte)*/ - volatile uint32_t saradc_sar1_patt_tab4; /*Item 12 ~ 15 for pattern table 1 (each item one byte)*/ - volatile uint32_t saradc_sar2_patt_tab1; /*item 0 ~ 3 for pattern table 2 (each item one byte)*/ - volatile uint32_t saradc_sar2_patt_tab2; /*Item 4 ~ 7 for pattern table 2 (each item one byte)*/ - volatile uint32_t saradc_sar2_patt_tab3; /*Item 8 ~ 11 for pattern table 2 (each item one byte)*/ - volatile uint32_t saradc_sar2_patt_tab4; /*Item 12 ~ 15 for pattern table 2 (each item one byte)*/ + uint32_t saradc_sar1_patt_tab[4]; /*item 0 ~ 3 for ADC1 pattern table*/ + uint32_t saradc_sar2_patt_tab[4]; /*item 0 ~ 3 for ADC2 pattern table*/ union { struct { - volatile uint32_t apll_tick: 8; - volatile uint32_t reserved8: 24; + uint32_t apll_tick: 8; + uint32_t reserved8: 24; }; - volatile uint32_t val; + uint32_t val; }apll_tick_conf; - volatile uint32_t reserved_40; - volatile uint32_t reserved_44; - volatile uint32_t reserved_48; - volatile uint32_t reserved_4c; - volatile uint32_t reserved_50; - volatile uint32_t reserved_54; - volatile uint32_t reserved_58; - volatile uint32_t reserved_5c; - volatile uint32_t reserved_60; - volatile uint32_t reserved_64; - volatile uint32_t reserved_68; - volatile uint32_t reserved_6c; - volatile uint32_t reserved_70; - volatile uint32_t reserved_74; - volatile uint32_t reserved_78; - volatile uint32_t date; /**/ + uint32_t reserved_40; + uint32_t reserved_44; + uint32_t reserved_48; + uint32_t reserved_4c; + uint32_t reserved_50; + uint32_t reserved_54; + uint32_t reserved_58; + uint32_t reserved_5c; + uint32_t reserved_60; + uint32_t reserved_64; + uint32_t reserved_68; + uint32_t reserved_6c; + uint32_t reserved_70; + uint32_t reserved_74; + uint32_t reserved_78; + uint32_t date; /**/ } syscon_dev_t; #ifdef __cplusplus } #endif - +extern syscon_dev_t SYSCON; #endif /* _SOC_SYSCON_STRUCT_H_ */ diff --git a/tools/sdk/include/spiffs/esp_spiffs.h b/tools/sdk/include/spiffs/esp_spiffs.h index 9a1f12c437e..ae1b9ad4306 100644 --- a/tools/sdk/include/spiffs/esp_spiffs.h +++ b/tools/sdk/include/spiffs/esp_spiffs.h @@ -18,6 +18,10 @@ #include #include "esp_err.h" +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Configuration structure for esp_vfs_spiffs_register */ @@ -91,4 +95,8 @@ esp_err_t esp_spiffs_format(const char* partition_label); */ esp_err_t esp_spiffs_info(const char* partition_label, size_t *total_bytes, size_t *used_bytes); +#ifdef __cplusplus +} +#endif + #endif /* _ESP_SPIFFS_H_ */ diff --git a/tools/sdk/include/spiffs/spiffs_config.h b/tools/sdk/include/spiffs/spiffs_config.h index e0c9d7f9d2f..e412bfd0cfa 100755 --- a/tools/sdk/include/spiffs/spiffs_config.h +++ b/tools/sdk/include/spiffs/spiffs_config.h @@ -24,27 +24,27 @@ #define SPIFFS_TAG "SPIFFS" // Set generic spiffs debug output call. -#if CONGIG_SPIFFS_DBG +#if CONFIG_SPIFFS_DBG #define SPIFFS_DBG(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) #else #define SPIFFS_DBG(...) #endif -#if CONGIG_SPIFFS_API_DBG +#if CONFIG_SPIFFS_API_DBG #define SPIFFS_API_DBG(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) #else #define SPIFFS_API_DBG(...) #endif -#if CONGIG_SPIFFS_DBG +#if CONFIG_SPIFFS_DBG #define SPIFFS_GC_DBG(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) #else #define SPIFFS_GC_DBG(...) #endif -#if CONGIG_SPIFFS_CACHE_DBG +#if CONFIG_SPIFFS_CACHE_DBG #define SPIFFS_CACHE_DBG(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) #else #define SPIFFS_CACHE_DBG(...) #endif -#if CONGIG_SPIFFS_CHECK_DBG +#if CONFIG_SPIFFS_CHECK_DBG #define SPIFFS_CHECK_DBG(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) #else #define SPIFFS_CHECK_DBG(...) diff --git a/tools/sdk/include/tcpip_adapter/tcpip_adapter.h b/tools/sdk/include/tcpip_adapter/tcpip_adapter.h index 2e6db6b5a71..d7ee00ea099 100644 --- a/tools/sdk/include/tcpip_adapter/tcpip_adapter.h +++ b/tools/sdk/include/tcpip_adapter/tcpip_adapter.h @@ -113,6 +113,19 @@ typedef enum { TCPIP_ADAPTER_IF_MAX } tcpip_adapter_if_t; +/*type of DNS server*/ +typedef enum { + TCPIP_ADAPTER_DNS_MAIN= 0, /**DNS main server address*/ + TCPIP_ADAPTER_DNS_BACKUP, /**DNS backup server address,for STA only,support soft-AP in future*/ + TCPIP_ADAPTER_DNS_FALLBACK, /**DNS fallback server address,for STA only*/ + TCPIP_ADAPTER_DNS_MAX /**Max DNS */ +} tcpip_adapter_dns_type_t; + +/*info of DNS server*/ +typedef struct { + ip_addr_t ip; +} tcpip_adapter_dns_info_t; + /* status of DHCP client or DHCP server */ typedef enum { TCPIP_ADAPTER_DHCP_INIT = 0, /**< DHCP client/server in initial state */ @@ -130,6 +143,7 @@ typedef enum{ } tcpip_adapter_option_mode_t; typedef enum{ + TCPIP_ADAPTER_DOMAIN_NAME_SERVER = 6, /**< domain name server */ TCPIP_ADAPTER_ROUTER_SOLICITATION_ADDRESS = 32, /**< solicitation router address */ TCPIP_ADAPTER_REQUESTED_IP_ADDRESS = 50, /**< request IP address pool */ TCPIP_ADAPTER_IP_ADDRESS_LEASE_TIME = 51, /**< request IP address lease time */ @@ -145,14 +159,19 @@ typedef struct tcpip_adapter_api_msg_s { tcpip_adapter_if_t tcpip_if; tcpip_adapter_ip_info_t *ip_info; uint8_t *mac; - const char *hostname; + void *data; } tcpip_adapter_api_msg_t; +typedef struct tcpip_adapter_dns_param_s { + tcpip_adapter_dns_type_t dns_type; + tcpip_adapter_dns_info_t *dns_info; +} tcpip_adapter_dns_param_t; + #define TCPIP_ADAPTER_TRHEAD_SAFE 1 #define TCPIP_ADAPTER_IPC_LOCAL 0 #define TCPIP_ADAPTER_IPC_REMOTE 1 -#define TCPIP_ADAPTER_IPC_CALL(_if, _mac, _ip, _hostname, _fn) do {\ +#define TCPIP_ADAPTER_IPC_CALL(_if, _mac, _ip, _data, _fn) do {\ tcpip_adapter_api_msg_t msg;\ if (tcpip_inited == false) {\ ESP_LOGE(TAG, "tcpip_adapter is not initialized!");\ @@ -160,9 +179,9 @@ typedef struct tcpip_adapter_api_msg_s { }\ memset(&msg, 0, sizeof(msg));\ msg.tcpip_if = (_if);\ - msg.mac = (_mac);\ - msg.ip_info = (_ip);\ - msg.hostname = (_hostname);\ + msg.mac = (uint8_t*)(_mac);\ + msg.ip_info = (tcpip_adapter_ip_info_t*)(_ip);\ + msg.data = (void*)(_data);\ msg.api_fn = (_fn);\ if (TCPIP_ADAPTER_IPC_REMOTE == tcpip_adapter_ipc_check(&msg)) {\ ESP_LOGD(TAG, "check: remote, if=%d fn=%p\n", (_if), (_fn));\ @@ -292,6 +311,47 @@ esp_err_t tcpip_adapter_get_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_i */ esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_ip_info_t *ip_info); +/** + * @brief Set DNS Server's information + * + * There has an DNS Server information copy in adapter library, set DNS Server for appointed interface and type. + * + * 1.In station mode, if dhcp client is enabled, then only the fallback DNS server can be set(TCPIP_ADAPTER_DNS_FALLBACK). + * Fallback DNS server is only used if no DNS servers are set via DHCP. + * If dhcp client is disabled, then need to set main/backup dns server(TCPIP_ADAPTER_DNS_MAIN, TCPIP_ADAPTER_DNS_BACKUP). + * + * 2.In soft-AP mode, the DNS Server's main dns server offered to the station is the IP address of soft-AP, + * if the application don't want to use the IP address of soft-AP, they can set the main dns server. + * + * This function is mainly used for setting static or Fallback DNS Server. + * + * @param[in] tcpip_if: the interface which we want to set DNS Server information + * @param[in] type: the type of DNS Server,including TCPIP_ADAPTER_DNS_MAIN, TCPIP_ADAPTER_DNS_BACKUP, TCPIP_ADAPTER_DNS_FALLBACK + * @param[in] dns: the DNS Server address to be set + * + * @return + * - ESP_OK on success + * - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS invalid params + */ +esp_err_t tcpip_adapter_set_dns_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dns_type_t type, tcpip_adapter_dns_info_t *dns); + +/** + * @brief Get DNS Server's information + * + * When set the DNS Server information successfully, can get the DNS Server's information via the appointed tcpip_if and type + * + * This function is mainly used for getting DNS Server information. + * + * @param[in] tcpip_if: the interface which we want to get DNS Server information + * @param[in] type: the type of DNS Server,including TCPIP_ADAPTER_DNS_MAIN, TCPIP_ADAPTER_DNS_BACKUP, TCPIP_ADAPTER_DNS_FALLBACK + * @param[in] dns: the DNS Server address to be get + * + * @return + * - ESP_OK on success + * - ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS invalid params + */ +esp_err_t tcpip_adapter_get_dns_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dns_type_t type, tcpip_adapter_dns_info_t *dns); + /** * @brief Get interface's old IP information * diff --git a/tools/sdk/include/vfs/esp_vfs.h b/tools/sdk/include/vfs/esp_vfs.h index 6ced2ce2b84..ab645fccf68 100644 --- a/tools/sdk/include/vfs/esp_vfs.h +++ b/tools/sdk/include/vfs/esp_vfs.h @@ -43,16 +43,30 @@ extern "C" { */ #define ESP_VFS_FLAG_CONTEXT_PTR 1 +/** + * Flag which indicates that the FD space of the VFS implementation should be made + * the same as the FD space in newlib. This means that the normal masking off + * of VFS-independent fd bits is ignored and the full user-facing fd is passed to + * the VFS implementation. + * + * Set the p_minimum_fd & p_maximum_fd pointers when registering the socket in + * order to know what range of FDs can be used with the registered VFS. + * + * This is mostly useful for LWIP which shares the socket FD space with + * socket-specific functions. + * + */ +#define ESP_VFS_FLAG_SHARED_FD_SPACE 2 + /** * @brief VFS definition structure * * This structure should be filled with pointers to corresponding * FS driver functions. * - * If the FS implementation has an option to use certain offset for - * all file descriptors, this value should be passed into fd_offset - * field. Otherwise VFS component will translate all FDs to start - * at zero offset. + * VFS component will translate all FDs so that the filesystem implementation + * sees them starting at zero. The caller sees a global FD which is prefixed + * with an pre-filesystem-implementation. * * Some FS implementations expect some state (e.g. pointer to some structure) * to be passed in as a first argument. For these implementations, @@ -67,8 +81,7 @@ extern "C" { */ typedef struct { - int fd_offset; /*!< file descriptor offset, determined by the FS driver */ - int flags; /*!< ESP_VFS_FLAG_CONTEXT_PTR or ESP_VFS_FLAG_DEFAULT */ + int flags; /*!< ESP_VFS_FLAG_CONTEXT_PTR or ESP_VFS_FLAG_DEFAULT, plus optionally ESP_VFS_FLAG_SHARED_FD_SPACE */ union { ssize_t (*write_p)(void* p, int fd, const void * data, size_t size); ssize_t (*write)(int fd, const void * data, size_t size); @@ -145,6 +158,14 @@ typedef struct int (*fcntl_p)(void* ctx, int fd, int cmd, va_list args); int (*fcntl)(int fd, int cmd, va_list args); }; + union { + int (*ioctl_p)(void* ctx, int fd, int cmd, va_list args); + int (*ioctl)(int fd, int cmd, va_list args); + }; + union { + int (*fsync_p)(void* ctx, int fd); + int (*fsync)(int fd); + }; } esp_vfs_t; @@ -170,6 +191,22 @@ typedef struct esp_err_t esp_vfs_register(const char* base_path, const esp_vfs_t* vfs, void* ctx); +/** + * Special case function for registering a VFS that uses a method other than + * open() to open new file descriptors. + * + * This is a special-purpose function intended for registering LWIP sockets to VFS. + * + * @param vfs Pointer to esp_vfs_t. Meaning is the same as for esp_vfs_register(). + * @param ctx Pointer to context structure. Meaning is the same as for esp_vfs_register(). + * @param p_min_fd If non-NULL, on success this variable is written with the minimum (global/user-facing) FD that this VFS will use. This is useful when ESP_VFS_FLAG_SHARED_FD_SPACE is set in vfs->flags. + * @param p_max_fd If non-NULL, on success this variable is written with one higher than the maximum (global/user-facing) FD that this VFS will use. This is useful when ESP_VFS_FLAG_SHARED_FD_SPACE is set in vfs->flags. + * + * @return ESP_OK if successful, ESP_ERR_NO_MEM if too many VFSes are + * registered. + */ +esp_err_t esp_vfs_register_socket_space(const esp_vfs_t *vfs, void *ctx, int *p_min_fd, int *p_max_fd); + /** * Unregister a virtual filesystem for given path prefix * diff --git a/tools/sdk/include/vfs/esp_vfs_dev.h b/tools/sdk/include/vfs/esp_vfs_dev.h index b51527fcfc6..b330b4c5654 100644 --- a/tools/sdk/include/vfs/esp_vfs_dev.h +++ b/tools/sdk/include/vfs/esp_vfs_dev.h @@ -12,11 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef __ESP_VFS_DEV_H__ -#define __ESP_VFS_DEV_H__ +#pragma once #include "esp_vfs.h" +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Line ending settings */ @@ -81,4 +84,6 @@ void esp_vfs_dev_uart_use_nonblocking(int uart_num); */ void esp_vfs_dev_uart_use_driver(int uart_num); -#endif //__ESP_VFS_DEV_H__ +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/ld/esp32.common.ld b/tools/sdk/ld/esp32.common.ld index 99f9dd54345..32fc089d31d 100644 --- a/tools/sdk/ld/esp32.common.ld +++ b/tools/sdk/ld/esp32.common.ld @@ -89,13 +89,14 @@ SECTIONS *libesp32.a:core_dump.o(.literal .text .literal.* .text.*) *libapp_trace.a:(.literal .text .literal.* .text.*) *libxtensa-debug-module.a:eri.o(.literal .text .literal.* .text.*) - *libesp32.a:app_trace.o(.literal .text .literal.* .text.*) *libphy.a:(.literal .text .literal.* .text.*) *librtc.a:(.literal .text .literal.* .text.*) *libsoc.a:(.literal .text .literal.* .text.*) *libhal.a:(.literal .text .literal.* .text.*) *libgcc.a:lib2funcs.o(.literal .text .literal.* .text.*) *libspi_flash.a:spi_flash_rom_patch.o(.literal .text .literal.* .text.*) + *libgcov.a:(.literal .text .literal.* .text.*) + INCLUDE esp32.spiram.rom-functions-iram.ld _iram_text_end = ABSOLUTE(.); } > iram0_0_seg @@ -116,9 +117,12 @@ SECTIONS *(.dram1 .dram1.*) *libesp32.a:panic.o(.rodata .rodata.*) *libphy.a:(.rodata .rodata.*) + *libsoc.a:rtc_clk.o(.rodata .rodata.*) *libapp_trace.a:(.rodata .rodata.*) + *libgcov.a:(.rodata .rodata.*) *libheap.a:multi_heap.o(.rodata .rodata.*) *libheap.a:multi_heap_poisoning.o(.rodata .rodata.*) + INCLUDE esp32.spiram.rom-functions-dram.ld _data_end = ABSOLUTE(.); . = ALIGN(4); } >dram0_0_seg diff --git a/tools/sdk/ld/esp32.peripherals.ld b/tools/sdk/ld/esp32.peripherals.ld index 2ff635f20fb..621fedea13d 100644 --- a/tools/sdk/ld/esp32.peripherals.ld +++ b/tools/sdk/ld/esp32.peripherals.ld @@ -20,8 +20,9 @@ PROVIDE ( TIMERG0 = 0x3ff5F000 ); PROVIDE ( TIMERG1 = 0x3ff60000 ); PROVIDE ( SPI2 = 0x3ff64000 ); PROVIDE ( SPI3 = 0x3ff65000 ); +PROVIDE ( SYSCON = 0x3ff66000 ); PROVIDE ( I2C1 = 0x3ff67000 ); +PROVIDE ( SDMMC = 0x3ff68000 ); PROVIDE ( MCPWM1 = 0x3ff6C000 ); PROVIDE ( I2S1 = 0x3ff6D000 ); PROVIDE ( UART2 = 0x3ff6E000 ); -PROVIDE ( SDMMC = 0x3ff68000 ); diff --git a/tools/sdk/ld/esp32.rom.ld b/tools/sdk/ld/esp32.rom.ld index d60eeb90c3a..c1c1df0884e 100644 --- a/tools/sdk/ld/esp32.rom.ld +++ b/tools/sdk/ld/esp32.rom.ld @@ -215,9 +215,17 @@ PROVIDE ( llc_state = 0x3ffb96f8 ); PROVIDE ( lldesc_build_chain = 0x4000a850 ); PROVIDE ( lldesc_num2link = 0x4000a948 ); PROVIDE ( lldesc_set_owner = 0x4000a974 ); +PROVIDE ( lld_evt_deferred_elt_push = 0x400466b4 ); +PROVIDE ( lld_evt_deferred_elt_pop = 0x400466dc ); +PROVIDE ( lld_evt_winsize_change = 0x40046730 ); +PROVIDE ( lld_evt_rxwin_compute = 0x400467c8 ); +PROVIDE ( lld_evt_slave_time_compute = 0x40046818 ); PROVIDE ( lld_evt_env = 0x3ffb9704 ); +PROVIDE ( lld_evt_elt_wait_get = 0x400468e4 ); +PROVIDE ( lld_evt_get_next_free_slot = 0x4004692c ); PROVIDE ( lld_pdu_adv_pk_desc_tab = 0x3ff98c70 ); PROVIDE ( lld_pdu_llcp_pk_desc_tab = 0x3ff98b68 ); +PROVIDE ( lld_pdu_pack = 0x4004ab14 ); PROVIDE ( LLM_AA_CT1 = 0x3ff98d8a ); PROVIDE ( LLM_AA_CT2 = 0x3ff98d88 ); PROVIDE ( llm_default_handler = 0x3ff98d80 ); @@ -353,6 +361,8 @@ PROVIDE ( r_ea_interval_delete = 0x400155a8 ); PROVIDE ( r_ea_interval_duration_req = 0x4001597c ); PROVIDE ( r_ea_interval_insert = 0x4001557c ); PROVIDE ( r_ea_interval_remove = 0x40015590 ); +PROVIDE ( ea_conflict_check = 0x40014e9c ); +PROVIDE ( ea_prog_timer = 0x40014f88 ); PROVIDE ( realloc = 0x4000becc ); PROVIDE ( _realloc_r = 0x4000bbe0 ); PROVIDE ( r_ea_offset_req = 0x40015748 ); @@ -1692,6 +1702,7 @@ PROVIDE ( ets_update_cpu_frequency_rom = 0x40008550 ); /* Updates g_ticks_per_u /* Following are static data, but can be used, not generated by script <<<<< btdm data */ PROVIDE ( hci_tl_env = 0x3ffb8154 ); PROVIDE ( ld_acl_env = 0x3ffb8258 ); +PROVIDE ( ea_env = 0x3ffb80ec ); PROVIDE ( ld_active_ch_map = 0x3ffb8334 ); PROVIDE ( ld_bcst_acl_env = 0x3ffb8274 ); PROVIDE ( ld_csb_rx_env = 0x3ffb8278 ); @@ -1713,5 +1724,6 @@ PROVIDE ( LM_SniffSubRate = 0x3ffb8214 ); PROVIDE ( prbs_64bytes = 0x3ff98992 ); PROVIDE ( nvds_env = 0x3ffb8364 ); PROVIDE ( nvds_magic_number = 0x3ff9912a ); +PROVIDE ( TASK_DESC_LLD = 0x3ff98b58 ); /* Above are static data, but can be used, not generated by script >>>>> btdm data */ diff --git a/tools/sdk/ld/esp32.spiram.rom-functions-dram.ld b/tools/sdk/ld/esp32.spiram.rom-functions-dram.ld new file mode 100644 index 00000000000..da59bc09c4e --- /dev/null +++ b/tools/sdk/ld/esp32.spiram.rom-functions-dram.ld @@ -0,0 +1,143 @@ +/* + If the Newlib functions in ROM aren't used (eg because the external SPI RAM workaround is active), these functions will + be linked into the application directly instead. Normally, they would end up in flash, which is undesirable because esp-idf + and/or applications may assume that because these functions normally are in ROM, they are accessible even when flash is + inaccessible. To work around this, this ld fragment places these functions in RAM instead. If the ROM functions are used, + these defines do nothing, so they can still be included in that situation. + + This file is responsible for placing the rodata segment in DRAM. +*/ + + *lib_a-utoa.o(.rodata .rodata.*) + *lib_a-longjmp.o(.rodata .rodata.*) + *lib_a-setjmp.o(.rodata .rodata.*) + *lib_a-abs.o(.rodata .rodata.*) + *lib_a-div.o(.rodata .rodata.*) + *lib_a-labs.o(.rodata .rodata.*) + *lib_a-ldiv.o(.rodata .rodata.*) + *lib_a-quorem.o(.rodata .rodata.*) + *lib_a-qsort.o(.rodata .rodata.*) + *lib_a-utoa.o(.rodata .rodata.*) + *lib_a-itoa.o(.rodata .rodata.*) + *lib_a-atoi.o(.rodata .rodata.*) + *lib_a-atol.o(.rodata .rodata.*) + *lib_a-strtol.o(.rodata .rodata.*) + *lib_a-strtoul.o(.rodata .rodata.*) + *lib_a-wcrtomb.o(.rodata .rodata.*) + *lib_a-fvwrite.o(.rodata .rodata.*) + *lib_a-wbuf.o(.rodata .rodata.*) + *lib_a-wsetup.o(.rodata .rodata.*) + *lib_a-fputwc.o(.rodata .rodata.*) + *lib_a-wctomb_r.o(.rodata .rodata.*) + *lib_a-ungetc.o(.rodata .rodata.*) + *lib_a-makebuf.o(.rodata .rodata.*) + *lib_a-fflush.o(.rodata .rodata.*) + *lib_a-refill.o(.rodata .rodata.*) + *lib_a-s_fpclassify.o(.rodata .rodata.*) + *lib_a-locale.o(.rodata .rodata.*) + *lib_a-asctime.o(.rodata .rodata.*) + *lib_a-ctime.o(.rodata .rodata.*) + *lib_a-ctime_r.o(.rodata .rodata.*) + *lib_a-lcltime.o(.rodata .rodata.*) + *lib_a-lcltime_r.o(.rodata .rodata.*) + *lib_a-gmtime.o(.rodata .rodata.*) + *lib_a-gmtime_r.o(.rodata .rodata.*) + *lib_a-strftime.o(.rodata .rodata.*) + *lib_a-mktime.o(.rodata .rodata.*) + *lib_a-syswrite.o(.rodata .rodata.*) + *lib_a-tzset_r.o(.rodata .rodata.*) + *lib_a-tzset.o(.rodata .rodata.*) + *lib_a-toupper.o(.rodata .rodata.*) + *lib_a-tolower.o(.rodata .rodata.*) + *lib_a-toascii.o(.rodata .rodata.*) + *lib_a-systimes.o(.rodata .rodata.*) + *lib_a-time.o(.rodata .rodata.*) + *lib_a-bsd_qsort_r.o(.rodata .rodata.*) + *lib_a-qsort_r.o(.rodata .rodata.*) + *lib_a-gettzinfo.o(.rodata .rodata.*) + *lib_a-strupr.o(.rodata .rodata.*) + *lib_a-asctime_r.o(.rodata .rodata.*) + *lib_a-bzero.o(.rodata .rodata.*) + *lib_a-close.o(.rodata .rodata.*) + *lib_a-creat.o(.rodata .rodata.*) + *lib_a-environ.o(.rodata .rodata.*) + *lib_a-fclose.o(.rodata .rodata.*) + *lib_a-isalnum.o(.rodata .rodata.*) + *lib_a-isalpha.o(.rodata .rodata.*) + *lib_a-isascii.o(.rodata .rodata.*) + *lib_a-isblank.o(.rodata .rodata.*) + *lib_a-iscntrl.o(.rodata .rodata.*) + *lib_a-isdigit.o(.rodata .rodata.*) + *lib_a-isgraph.o(.rodata .rodata.*) + *lib_a-islower.o(.rodata .rodata.*) + *lib_a-isprint.o(.rodata .rodata.*) + *lib_a-ispunct.o(.rodata .rodata.*) + *lib_a-isspace.o(.rodata .rodata.*) + *lib_a-isupper.o(.rodata .rodata.*) + *lib_a-memccpy.o(.rodata .rodata.*) + *lib_a-memchr.o(.rodata .rodata.*) + *lib_a-memcmp.o(.rodata .rodata.*) + *lib_a-memcpy.o(.rodata .rodata.*) + *lib_a-memmove.o(.rodata .rodata.*) + *lib_a-memrchr.o(.rodata .rodata.*) + *lib_a-memset.o(.rodata .rodata.*) + *lib_a-open.o(.rodata .rodata.*) + *lib_a-rand.o(.rodata .rodata.*) + *lib_a-rand_r.o(.rodata .rodata.*) + *lib_a-read.o(.rodata .rodata.*) + *lib_a-rshift.o(.rodata .rodata.*) + *lib_a-sbrk.o(.rodata .rodata.*) + *lib_a-srand.o(.rodata .rodata.*) + *lib_a-strcasecmp.o(.rodata .rodata.*) + *lib_a-strcasestr.o(.rodata .rodata.*) + *lib_a-strcat.o(.rodata .rodata.*) + *lib_a-strchr.o(.rodata .rodata.*) + *lib_a-strcmp.o(.rodata .rodata.*) + *lib_a-strcoll.o(.rodata .rodata.*) + *lib_a-strcpy.o(.rodata .rodata.*) + *lib_a-strcspn.o(.rodata .rodata.*) + *lib_a-strdup.o(.rodata .rodata.*) + *lib_a-strlcat.o(.rodata .rodata.*) + *lib_a-strlcpy.o(.rodata .rodata.*) + *lib_a-strlen.o(.rodata .rodata.*) + *lib_a-strlwr.o(.rodata .rodata.*) + *lib_a-strncasecmp.o(.rodata .rodata.*) + *lib_a-strncat.o(.rodata .rodata.*) + *lib_a-strncmp.o(.rodata .rodata.*) + *lib_a-strncpy.o(.rodata .rodata.*) + *lib_a-strndup.o(.rodata .rodata.*) + *lib_a-strnlen.o(.rodata .rodata.*) + *lib_a-strrchr.o(.rodata .rodata.*) + *lib_a-strsep.o(.rodata .rodata.*) + *lib_a-strspn.o(.rodata .rodata.*) + *lib_a-strstr.o(.rodata .rodata.*) + *lib_a-strtok_r.o(.rodata .rodata.*) + *lib_a-strupr.o(.rodata .rodata.*) + *lib_a-stdio.o(.rodata .rodata.*) + *lib_a-syssbrk.o(.rodata .rodata.*) + *lib_a-sysclose.o(.rodata .rodata.*) + *lib_a-sysopen.o(.rodata .rodata.*) + *creat.o(.rodata .rodata.*) + *lib_a-sysread.o(.rodata .rodata.*) + *lib_a-syswrite.o(.rodata .rodata.*) + *lib_a-impure.o(.rodata .rodata.*) + *lib_a-tzvars.o(.rodata .rodata.*) + *lib_a-sf_nan.o(.rodata .rodata.*) + *lib_a-tzcalc_limits.o(.rodata .rodata.*) + *lib_a-month_lengths.o(.rodata .rodata.*) + *lib_a-timelocal.o(.rodata .rodata.*) + *lib_a-findfp.o(.rodata .rodata.*) + *lock.o(.rodata .rodata.*) + *lib_a-getenv_r.o(.rodata .rodata.*) + *isatty.o(.rodata .rodata.*) + *lib_a-fwalk.o(.rodata .rodata.*) + *lib_a-getenv_r.o(.rodata .rodata.*) + *lib_a-tzlock.o(.rodata .rodata.*) + *lib_a-ctype_.o(.rodata .rodata.*) + *lib_a-sccl.o(.rodata .rodata.*) + *lib_a-strptime.o(.rodata .rodata.*) + *lib_a-envlock.o(.rodata .rodata.*) + *lib_a-raise.o(.rodata .rodata.*) + *lib_a-strdup_r.o(.rodata .rodata.*) + *lib_a-system.o(.rodata .rodata.*) + *lib_a-strndup_r.o(.rodata .rodata.*) diff --git a/tools/sdk/ld/esp32.spiram.rom-functions-iram.ld b/tools/sdk/ld/esp32.spiram.rom-functions-iram.ld new file mode 100644 index 00000000000..6f97fb6b15e --- /dev/null +++ b/tools/sdk/ld/esp32.spiram.rom-functions-iram.ld @@ -0,0 +1,144 @@ +/* + If the Newlib functions in ROM aren't used (eg because the external SPI RAM workaround is active), these functions will + be linked into the application directly instead. Normally, they would end up in flash, which is undesirable because esp-idf + and/or applications may assume that because these functions normally are in ROM, they are accessible even when flash is + inaccessible. To work around this, this ld fragment places these functions in RAM instead. If the ROM functions are used, + these defines do nothing, so they can still be included in that situation. + + This file is responsible for placing the literal and text segments in IRAM. +*/ + + + *lib_a-utoa.o(.literal .text .literal.* .text.*) + *lib_a-longjmp.o(.literal .text .literal.* .text.*) + *lib_a-setjmp.o(.literal .text .literal.* .text.*) + *lib_a-abs.o(.literal .text .literal.* .text.*) + *lib_a-div.o(.literal .text .literal.* .text.*) + *lib_a-labs.o(.literal .text .literal.* .text.*) + *lib_a-ldiv.o(.literal .text .literal.* .text.*) + *lib_a-quorem.o(.literal .text .literal.* .text.*) + *lib_a-qsort.o(.literal .text .literal.* .text.*) + *lib_a-utoa.o(.literal .text .literal.* .text.*) + *lib_a-itoa.o(.literal .text .literal.* .text.*) + *lib_a-atoi.o(.literal .text .literal.* .text.*) + *lib_a-atol.o(.literal .text .literal.* .text.*) + *lib_a-strtol.o(.literal .text .literal.* .text.*) + *lib_a-strtoul.o(.literal .text .literal.* .text.*) + *lib_a-wcrtomb.o(.literal .text .literal.* .text.*) + *lib_a-fvwrite.o(.literal .text .literal.* .text.*) + *lib_a-wbuf.o(.literal .text .literal.* .text.*) + *lib_a-wsetup.o(.literal .text .literal.* .text.*) + *lib_a-fputwc.o(.literal .text .literal.* .text.*) + *lib_a-wctomb_r.o(.literal .text .literal.* .text.*) + *lib_a-ungetc.o(.literal .text .literal.* .text.*) + *lib_a-makebuf.o(.literal .text .literal.* .text.*) + *lib_a-fflush.o(.literal .text .literal.* .text.*) + *lib_a-refill.o(.literal .text .literal.* .text.*) + *lib_a-s_fpclassify.o(.literal .text .literal.* .text.*) + *lib_a-locale.o(.literal .text .literal.* .text.*) + *lib_a-asctime.o(.literal .text .literal.* .text.*) + *lib_a-ctime.o(.literal .text .literal.* .text.*) + *lib_a-ctime_r.o(.literal .text .literal.* .text.*) + *lib_a-lcltime.o(.literal .text .literal.* .text.*) + *lib_a-lcltime_r.o(.literal .text .literal.* .text.*) + *lib_a-gmtime.o(.literal .text .literal.* .text.*) + *lib_a-gmtime_r.o(.literal .text .literal.* .text.*) + *lib_a-strftime.o(.literal .text .literal.* .text.*) + *lib_a-mktime.o(.literal .text .literal.* .text.*) + *lib_a-syswrite.o(.literal .text .literal.* .text.*) + *lib_a-tzset_r.o(.literal .text .literal.* .text.*) + *lib_a-tzset.o(.literal .text .literal.* .text.*) + *lib_a-toupper.o(.literal .text .literal.* .text.*) + *lib_a-tolower.o(.literal .text .literal.* .text.*) + *lib_a-toascii.o(.literal .text .literal.* .text.*) + *lib_a-systimes.o(.literal .text .literal.* .text.*) + *lib_a-time.o(.literal .text .literal.* .text.*) + *lib_a-bsd_qsort_r.o(.literal .text .literal.* .text.*) + *lib_a-qsort_r.o(.literal .text .literal.* .text.*) + *lib_a-gettzinfo.o(.literal .text .literal.* .text.*) + *lib_a-strupr.o(.literal .text .literal.* .text.*) + *lib_a-asctime_r.o(.literal .text .literal.* .text.*) + *lib_a-bzero.o(.literal .text .literal.* .text.*) + *lib_a-close.o(.literal .text .literal.* .text.*) + *lib_a-creat.o(.literal .text .literal.* .text.*) + *lib_a-environ.o(.literal .text .literal.* .text.*) + *lib_a-fclose.o(.literal .text .literal.* .text.*) + *lib_a-isalnum.o(.literal .text .literal.* .text.*) + *lib_a-isalpha.o(.literal .text .literal.* .text.*) + *lib_a-isascii.o(.literal .text .literal.* .text.*) + *lib_a-isblank.o(.literal .text .literal.* .text.*) + *lib_a-iscntrl.o(.literal .text .literal.* .text.*) + *lib_a-isdigit.o(.literal .text .literal.* .text.*) + *lib_a-isgraph.o(.literal .text .literal.* .text.*) + *lib_a-islower.o(.literal .text .literal.* .text.*) + *lib_a-isprint.o(.literal .text .literal.* .text.*) + *lib_a-ispunct.o(.literal .text .literal.* .text.*) + *lib_a-isspace.o(.literal .text .literal.* .text.*) + *lib_a-isupper.o(.literal .text .literal.* .text.*) + *lib_a-memccpy.o(.literal .text .literal.* .text.*) + *lib_a-memchr.o(.literal .text .literal.* .text.*) + *lib_a-memcmp.o(.literal .text .literal.* .text.*) + *lib_a-memcpy.o(.literal .text .literal.* .text.*) + *lib_a-memmove.o(.literal .text .literal.* .text.*) + *lib_a-memrchr.o(.literal .text .literal.* .text.*) + *lib_a-memset.o(.literal .text .literal.* .text.*) + *lib_a-open.o(.literal .text .literal.* .text.*) + *lib_a-rand.o(.literal .text .literal.* .text.*) + *lib_a-rand_r.o(.literal .text .literal.* .text.*) + *lib_a-read.o(.literal .text .literal.* .text.*) + *lib_a-rshift.o(.literal .text .literal.* .text.*) + *lib_a-sbrk.o(.literal .text .literal.* .text.*) + *lib_a-srand.o(.literal .text .literal.* .text.*) + *lib_a-strcasecmp.o(.literal .text .literal.* .text.*) + *lib_a-strcasestr.o(.literal .text .literal.* .text.*) + *lib_a-strcat.o(.literal .text .literal.* .text.*) + *lib_a-strchr.o(.literal .text .literal.* .text.*) + *lib_a-strcmp.o(.literal .text .literal.* .text.*) + *lib_a-strcoll.o(.literal .text .literal.* .text.*) + *lib_a-strcpy.o(.literal .text .literal.* .text.*) + *lib_a-strcspn.o(.literal .text .literal.* .text.*) + *lib_a-strdup.o(.literal .text .literal.* .text.*) + *lib_a-strlcat.o(.literal .text .literal.* .text.*) + *lib_a-strlcpy.o(.literal .text .literal.* .text.*) + *lib_a-strlen.o(.literal .text .literal.* .text.*) + *lib_a-strlwr.o(.literal .text .literal.* .text.*) + *lib_a-strncasecmp.o(.literal .text .literal.* .text.*) + *lib_a-strncat.o(.literal .text .literal.* .text.*) + *lib_a-strncmp.o(.literal .text .literal.* .text.*) + *lib_a-strncpy.o(.literal .text .literal.* .text.*) + *lib_a-strndup.o(.literal .text .literal.* .text.*) + *lib_a-strnlen.o(.literal .text .literal.* .text.*) + *lib_a-strrchr.o(.literal .text .literal.* .text.*) + *lib_a-strsep.o(.literal .text .literal.* .text.*) + *lib_a-strspn.o(.literal .text .literal.* .text.*) + *lib_a-strstr.o(.literal .text .literal.* .text.*) + *lib_a-strtok_r.o(.literal .text .literal.* .text.*) + *lib_a-strupr.o(.literal .text .literal.* .text.*) + *lib_a-stdio.o(.literal .text .literal.* .text.*) + *lib_a-syssbrk.o(.literal .text .literal.* .text.*) + *lib_a-sysclose.o(.literal .text .literal.* .text.*) + *lib_a-sysopen.o(.literal .text .literal.* .text.*) + *creat.o(.literal .text .literal.* .text.*) + *lib_a-sysread.o(.literal .text .literal.* .text.*) + *lib_a-syswrite.o(.literal .text .literal.* .text.*) + *lib_a-impure.o(.literal .text .literal.* .text.*) + *lib_a-tzvars.o(.literal .text .literal.* .text.*) + *lib_a-sf_nan.o(.literal .text .literal.* .text.*) + *lib_a-tzcalc_limits.o(.literal .text .literal.* .text.*) + *lib_a-month_lengths.o(.literal .text .literal.* .text.*) + *lib_a-timelocal.o(.literal .text .literal.* .text.*) + *lib_a-findfp.o(.literal .text .literal.* .text.*) + *lock.o(.literal .text .literal.* .text.*) + *lib_a-getenv_r.o(.literal .text .literal.* .text.*) + *isatty.o(.literal .text .literal.* .text.*) + *lib_a-fwalk.o(.literal .text .literal.* .text.*) + *lib_a-getenv_r.o(.literal .text .literal.* .text.*) + *lib_a-tzlock.o(.literal .text .literal.* .text.*) + *lib_a-ctype_.o(.literal .text .literal.* .text.*) + *lib_a-sccl.o(.literal .text .literal.* .text.*) + *lib_a-strptime.o(.literal .text .literal.* .text.*) + *lib_a-envlock.o(.literal .text .literal.* .text.*) + *lib_a-raise.o(.literal .text .literal.* .text.*) + *lib_a-strdup_r.o(.literal .text .literal.* .text.*) + *lib_a-system.o(.literal .text .literal.* .text.*) + *lib_a-strndup_r.o(.literal .text .literal.* .text.*) diff --git a/tools/sdk/lib/libapp_trace.a b/tools/sdk/lib/libapp_trace.a index eded79e4be3..741ba707ed5 100644 Binary files a/tools/sdk/lib/libapp_trace.a and b/tools/sdk/lib/libapp_trace.a differ diff --git a/tools/sdk/lib/libapp_update.a b/tools/sdk/lib/libapp_update.a index 80ad0cda077..0e955f0c8a5 100644 Binary files a/tools/sdk/lib/libapp_update.a and b/tools/sdk/lib/libapp_update.a differ diff --git a/tools/sdk/lib/libbootloader_support.a b/tools/sdk/lib/libbootloader_support.a index 2e802de6485..20d0a90b706 100644 Binary files a/tools/sdk/lib/libbootloader_support.a and b/tools/sdk/lib/libbootloader_support.a differ diff --git a/tools/sdk/lib/libbt.a b/tools/sdk/lib/libbt.a index 9c60935f8c3..ae7e13ec6f2 100644 Binary files a/tools/sdk/lib/libbt.a and b/tools/sdk/lib/libbt.a differ diff --git a/tools/sdk/lib/libbtdm_app.a b/tools/sdk/lib/libbtdm_app.a index 116119ce561..c5be6a90384 100644 Binary files a/tools/sdk/lib/libbtdm_app.a and b/tools/sdk/lib/libbtdm_app.a differ diff --git a/tools/sdk/lib/libc.a b/tools/sdk/lib/libc.a index 36a1cc60784..56f7e985644 100644 Binary files a/tools/sdk/lib/libc.a and b/tools/sdk/lib/libc.a differ diff --git a/tools/sdk/lib/libc_nano.a b/tools/sdk/lib/libc_nano.a index 9afd3798782..09029a21c12 100644 Binary files a/tools/sdk/lib/libc_nano.a and b/tools/sdk/lib/libc_nano.a differ diff --git a/tools/sdk/lib/libcoap.a b/tools/sdk/lib/libcoap.a index 8700a585bbf..a3fa3744c0a 100644 Binary files a/tools/sdk/lib/libcoap.a and b/tools/sdk/lib/libcoap.a differ diff --git a/tools/sdk/lib/libcoexist.a b/tools/sdk/lib/libcoexist.a index e4c9ea72068..3bbf3f9494a 100644 Binary files a/tools/sdk/lib/libcoexist.a and b/tools/sdk/lib/libcoexist.a differ diff --git a/tools/sdk/lib/libconsole.a b/tools/sdk/lib/libconsole.a index 43c9e6aaf9c..d9424e8a68d 100644 Binary files a/tools/sdk/lib/libconsole.a and b/tools/sdk/lib/libconsole.a differ diff --git a/tools/sdk/lib/libcore.a b/tools/sdk/lib/libcore.a index 1435083dbc7..d88f71758d9 100644 Binary files a/tools/sdk/lib/libcore.a and b/tools/sdk/lib/libcore.a differ diff --git a/tools/sdk/lib/libcxx.a b/tools/sdk/lib/libcxx.a index 401ecc095d0..3907b7b2388 100644 Binary files a/tools/sdk/lib/libcxx.a and b/tools/sdk/lib/libcxx.a differ diff --git a/tools/sdk/lib/libdriver.a b/tools/sdk/lib/libdriver.a index 06dccf8b0dd..f099703851a 100644 Binary files a/tools/sdk/lib/libdriver.a and b/tools/sdk/lib/libdriver.a differ diff --git a/tools/sdk/lib/libesp32.a b/tools/sdk/lib/libesp32.a index 7d68815b2f2..0d94d812b88 100644 Binary files a/tools/sdk/lib/libesp32.a and b/tools/sdk/lib/libesp32.a differ diff --git a/tools/sdk/lib/libesp_adc_cal.a b/tools/sdk/lib/libesp_adc_cal.a index 962aad2c1a9..32a3ea0ca4e 100644 Binary files a/tools/sdk/lib/libesp_adc_cal.a and b/tools/sdk/lib/libesp_adc_cal.a differ diff --git a/tools/sdk/lib/libespnow.a b/tools/sdk/lib/libespnow.a new file mode 100644 index 00000000000..9f34fe3dfbc Binary files /dev/null and b/tools/sdk/lib/libespnow.a differ diff --git a/tools/sdk/lib/libethernet.a b/tools/sdk/lib/libethernet.a index 9ced0ef7e40..af0a47e17ec 100644 Binary files a/tools/sdk/lib/libethernet.a and b/tools/sdk/lib/libethernet.a differ diff --git a/tools/sdk/lib/libexpat.a b/tools/sdk/lib/libexpat.a index 2ae482e4038..6110487084c 100644 Binary files a/tools/sdk/lib/libexpat.a and b/tools/sdk/lib/libexpat.a differ diff --git a/tools/sdk/lib/libfatfs.a b/tools/sdk/lib/libfatfs.a index 2011dd2bf3a..bcccfba8573 100644 Binary files a/tools/sdk/lib/libfatfs.a and b/tools/sdk/lib/libfatfs.a differ diff --git a/tools/sdk/lib/libfreertos.a b/tools/sdk/lib/libfreertos.a index 761dde3fdab..5f4cc1e0bcd 100644 Binary files a/tools/sdk/lib/libfreertos.a and b/tools/sdk/lib/libfreertos.a differ diff --git a/tools/sdk/lib/libheap.a b/tools/sdk/lib/libheap.a index bb091941426..0efa897b121 100644 Binary files a/tools/sdk/lib/libheap.a and b/tools/sdk/lib/libheap.a differ diff --git a/tools/sdk/lib/libjsmn.a b/tools/sdk/lib/libjsmn.a index 7c7d1bca1f8..274afea637e 100644 Binary files a/tools/sdk/lib/libjsmn.a and b/tools/sdk/lib/libjsmn.a differ diff --git a/tools/sdk/lib/libjson.a b/tools/sdk/lib/libjson.a index 6e7e9994ba7..913c98190e0 100644 Binary files a/tools/sdk/lib/libjson.a and b/tools/sdk/lib/libjson.a differ diff --git a/tools/sdk/lib/liblog.a b/tools/sdk/lib/liblog.a index 9a4deeb82c1..36a23608456 100644 Binary files a/tools/sdk/lib/liblog.a and b/tools/sdk/lib/liblog.a differ diff --git a/tools/sdk/lib/liblwip.a b/tools/sdk/lib/liblwip.a index 91a6512bade..62c0517a5ef 100644 Binary files a/tools/sdk/lib/liblwip.a and b/tools/sdk/lib/liblwip.a differ diff --git a/tools/sdk/lib/libmbedtls.a b/tools/sdk/lib/libmbedtls.a index 9908a606b40..28bf8f9535c 100644 Binary files a/tools/sdk/lib/libmbedtls.a and b/tools/sdk/lib/libmbedtls.a differ diff --git a/tools/sdk/lib/libmdns.a b/tools/sdk/lib/libmdns.a index 09aa46b4afd..b3dc5505a9f 100644 Binary files a/tools/sdk/lib/libmdns.a and b/tools/sdk/lib/libmdns.a differ diff --git a/tools/sdk/lib/libmicro-ecc.a b/tools/sdk/lib/libmicro-ecc.a index 2f0924e8fa9..55810bf19ff 100644 Binary files a/tools/sdk/lib/libmicro-ecc.a and b/tools/sdk/lib/libmicro-ecc.a differ diff --git a/tools/sdk/lib/libnet80211.a b/tools/sdk/lib/libnet80211.a index 22451429901..36722353bc7 100644 Binary files a/tools/sdk/lib/libnet80211.a and b/tools/sdk/lib/libnet80211.a differ diff --git a/tools/sdk/lib/libnewlib.a b/tools/sdk/lib/libnewlib.a index 2e0cad7fbc8..33ba81cf646 100644 Binary files a/tools/sdk/lib/libnewlib.a and b/tools/sdk/lib/libnewlib.a differ diff --git a/tools/sdk/lib/libnghttp.a b/tools/sdk/lib/libnghttp.a index 83d630ff78a..c182d1b45d4 100644 Binary files a/tools/sdk/lib/libnghttp.a and b/tools/sdk/lib/libnghttp.a differ diff --git a/tools/sdk/lib/libnvs_flash.a b/tools/sdk/lib/libnvs_flash.a index 8b26ebf2116..c800dcb7ad1 100644 Binary files a/tools/sdk/lib/libnvs_flash.a and b/tools/sdk/lib/libnvs_flash.a differ diff --git a/tools/sdk/lib/libopenssl.a b/tools/sdk/lib/libopenssl.a index f7917173645..8045e885404 100644 Binary files a/tools/sdk/lib/libopenssl.a and b/tools/sdk/lib/libopenssl.a differ diff --git a/tools/sdk/lib/libphy.a b/tools/sdk/lib/libphy.a index fbc06687068..045a7149782 100755 Binary files a/tools/sdk/lib/libphy.a and b/tools/sdk/lib/libphy.a differ diff --git a/tools/sdk/lib/libpp.a b/tools/sdk/lib/libpp.a index c03937e4cca..3a3db261aa7 100644 Binary files a/tools/sdk/lib/libpp.a and b/tools/sdk/lib/libpp.a differ diff --git a/tools/sdk/lib/libpthread.a b/tools/sdk/lib/libpthread.a index 711aae108ca..1feeaae2a52 100644 Binary files a/tools/sdk/lib/libpthread.a and b/tools/sdk/lib/libpthread.a differ diff --git a/tools/sdk/lib/librtc.a b/tools/sdk/lib/librtc.a index 79f1f99d863..7998bdca3b8 100755 Binary files a/tools/sdk/lib/librtc.a and b/tools/sdk/lib/librtc.a differ diff --git a/tools/sdk/lib/libsdmmc.a b/tools/sdk/lib/libsdmmc.a index dfb4874ee80..d08cc06414c 100644 Binary files a/tools/sdk/lib/libsdmmc.a and b/tools/sdk/lib/libsdmmc.a differ diff --git a/tools/sdk/lib/libsmartconfig.a b/tools/sdk/lib/libsmartconfig.a index bf674e3e275..4f021751479 100644 Binary files a/tools/sdk/lib/libsmartconfig.a and b/tools/sdk/lib/libsmartconfig.a differ diff --git a/tools/sdk/lib/libsoc.a b/tools/sdk/lib/libsoc.a index 0eae0785bac..601cffd770b 100644 Binary files a/tools/sdk/lib/libsoc.a and b/tools/sdk/lib/libsoc.a differ diff --git a/tools/sdk/lib/libspi_flash.a b/tools/sdk/lib/libspi_flash.a index a855393d320..b95f85d6a52 100644 Binary files a/tools/sdk/lib/libspi_flash.a and b/tools/sdk/lib/libspi_flash.a differ diff --git a/tools/sdk/lib/libspiffs.a b/tools/sdk/lib/libspiffs.a index c818e6493fd..71f3a77f3c2 100644 Binary files a/tools/sdk/lib/libspiffs.a and b/tools/sdk/lib/libspiffs.a differ diff --git a/tools/sdk/lib/libtcpip_adapter.a b/tools/sdk/lib/libtcpip_adapter.a index 8c6ceeefc95..f53692e7dfc 100644 Binary files a/tools/sdk/lib/libtcpip_adapter.a and b/tools/sdk/lib/libtcpip_adapter.a differ diff --git a/tools/sdk/lib/libulp.a b/tools/sdk/lib/libulp.a index 88336583005..13fa2636ce3 100644 Binary files a/tools/sdk/lib/libulp.a and b/tools/sdk/lib/libulp.a differ diff --git a/tools/sdk/lib/libvfs.a b/tools/sdk/lib/libvfs.a index 48795a2f737..5250330f75f 100644 Binary files a/tools/sdk/lib/libvfs.a and b/tools/sdk/lib/libvfs.a differ diff --git a/tools/sdk/lib/libwear_levelling.a b/tools/sdk/lib/libwear_levelling.a index 25caf566a1b..4bb29c832a7 100644 Binary files a/tools/sdk/lib/libwear_levelling.a and b/tools/sdk/lib/libwear_levelling.a differ diff --git a/tools/sdk/lib/libwpa.a b/tools/sdk/lib/libwpa.a index 34572eec4e9..15787279fd0 100644 Binary files a/tools/sdk/lib/libwpa.a and b/tools/sdk/lib/libwpa.a differ diff --git a/tools/sdk/lib/libwpa2.a b/tools/sdk/lib/libwpa2.a index 75d10620da5..63842c26588 100644 Binary files a/tools/sdk/lib/libwpa2.a and b/tools/sdk/lib/libwpa2.a differ diff --git a/tools/sdk/lib/libwpa_supplicant.a b/tools/sdk/lib/libwpa_supplicant.a index 2e81515a20b..5ca06e10d3f 100644 Binary files a/tools/sdk/lib/libwpa_supplicant.a and b/tools/sdk/lib/libwpa_supplicant.a differ diff --git a/tools/sdk/lib/libwps.a b/tools/sdk/lib/libwps.a index a8325838e23..56a88fbfc50 100644 Binary files a/tools/sdk/lib/libwps.a and b/tools/sdk/lib/libwps.a differ diff --git a/tools/sdk/lib/libxtensa-debug-module.a b/tools/sdk/lib/libxtensa-debug-module.a index e61a5ebdd5d..520e489139f 100644 Binary files a/tools/sdk/lib/libxtensa-debug-module.a and b/tools/sdk/lib/libxtensa-debug-module.a differ diff --git a/tools/sdk/sdkconfig b/tools/sdk/sdkconfig index 6f4b111a924..7d4a3feb03d 100644 --- a/tools/sdk/sdkconfig +++ b/tools/sdk/sdkconfig @@ -14,62 +14,61 @@ CONFIG_MAKE_WARN_UNDEFINED_VARIABLES=y # Bootloader config # CONFIG_LOG_BOOTLOADER_LEVEL_NONE=y -# CONFIG_LOG_BOOTLOADER_LEVEL_ERROR is not set -# CONFIG_LOG_BOOTLOADER_LEVEL_WARN is not set -# CONFIG_LOG_BOOTLOADER_LEVEL_INFO is not set -# CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG is not set -# CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE is not set +CONFIG_LOG_BOOTLOADER_LEVEL_ERROR= +CONFIG_LOG_BOOTLOADER_LEVEL_WARN= +CONFIG_LOG_BOOTLOADER_LEVEL_INFO= +CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG= +CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE= CONFIG_LOG_BOOTLOADER_LEVEL=0 -CONFIG_BOOTLOADER_SPI_WP_PIN=7 # # Security features # -# CONFIG_SECURE_BOOT_ENABLED is not set -# CONFIG_FLASH_ENCRYPTION_ENABLED is not set +CONFIG_SECURE_BOOT_ENABLED= +CONFIG_FLASH_ENCRYPTION_ENABLED= # # Serial flasher config # CONFIG_ESPTOOLPY_PORT="/dev/cu.usbserial-DO00EAB0" -# CONFIG_ESPTOOLPY_BAUD_115200B is not set -# CONFIG_ESPTOOLPY_BAUD_230400B is not set +CONFIG_ESPTOOLPY_BAUD_115200B= +CONFIG_ESPTOOLPY_BAUD_230400B= CONFIG_ESPTOOLPY_BAUD_921600B=y -# CONFIG_ESPTOOLPY_BAUD_2MB is not set -# CONFIG_ESPTOOLPY_BAUD_OTHER is not set +CONFIG_ESPTOOLPY_BAUD_2MB= +CONFIG_ESPTOOLPY_BAUD_OTHER= CONFIG_ESPTOOLPY_BAUD_OTHER_VAL=115200 CONFIG_ESPTOOLPY_BAUD=921600 CONFIG_ESPTOOLPY_COMPRESSED=y -CONFIG_FLASHMODE_QIO=y -# CONFIG_FLASHMODE_QOUT is not set -# CONFIG_FLASHMODE_DIO is not set -# CONFIG_FLASHMODE_DOUT is not set +CONFIG_FLASHMODE_QIO= +CONFIG_FLASHMODE_QOUT= +CONFIG_FLASHMODE_DIO=y +CONFIG_FLASHMODE_DOUT= CONFIG_ESPTOOLPY_FLASHMODE="dio" -# CONFIG_ESPTOOLPY_FLASHFREQ_80M is not set +CONFIG_ESPTOOLPY_FLASHFREQ_80M= CONFIG_ESPTOOLPY_FLASHFREQ_40M=y -# CONFIG_ESPTOOLPY_FLASHFREQ_26M is not set -# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set +CONFIG_ESPTOOLPY_FLASHFREQ_26M= +CONFIG_ESPTOOLPY_FLASHFREQ_20M= CONFIG_ESPTOOLPY_FLASHFREQ="40m" -# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set -# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set +CONFIG_ESPTOOLPY_FLASHSIZE_1MB= +CONFIG_ESPTOOLPY_FLASHSIZE_2MB= CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y -# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set -# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set +CONFIG_ESPTOOLPY_FLASHSIZE_8MB= +CONFIG_ESPTOOLPY_FLASHSIZE_16MB= CONFIG_ESPTOOLPY_FLASHSIZE="4MB" CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y CONFIG_ESPTOOLPY_BEFORE_RESET=y -# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set +CONFIG_ESPTOOLPY_BEFORE_NORESET= CONFIG_ESPTOOLPY_BEFORE="default_reset" CONFIG_ESPTOOLPY_AFTER_RESET=y -# CONFIG_ESPTOOLPY_AFTER_NORESET is not set +CONFIG_ESPTOOLPY_AFTER_NORESET= CONFIG_ESPTOOLPY_AFTER="hard_reset" -# CONFIG_MONITOR_BAUD_9600B is not set -# CONFIG_MONITOR_BAUD_57600B is not set +CONFIG_MONITOR_BAUD_9600B= +CONFIG_MONITOR_BAUD_57600B= CONFIG_MONITOR_BAUD_115200B=y -# CONFIG_MONITOR_BAUD_230400B is not set -# CONFIG_MONITOR_BAUD_921600B is not set -# CONFIG_MONITOR_BAUD_2MB is not set -# CONFIG_MONITOR_BAUD_OTHER is not set +CONFIG_MONITOR_BAUD_230400B= +CONFIG_MONITOR_BAUD_921600B= +CONFIG_MONITOR_BAUD_2MB= +CONFIG_MONITOR_BAUD_OTHER= CONFIG_MONITOR_BAUD_OTHER_VAL=115200 CONFIG_MONITOR_BAUD=115200 @@ -77,8 +76,8 @@ CONFIG_MONITOR_BAUD=115200 # Partition Table # CONFIG_PARTITION_TABLE_SINGLE_APP=y -# CONFIG_PARTITION_TABLE_TWO_OTA is not set -# CONFIG_PARTITION_TABLE_CUSTOM is not set +CONFIG_PARTITION_TABLE_TWO_OTA= +CONFIG_PARTITION_TABLE_CUSTOM= CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000 CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp.csv" @@ -88,10 +87,11 @@ CONFIG_APP_OFFSET=0x10000 # Compiler options # CONFIG_OPTIMIZATION_LEVEL_DEBUG=y -# CONFIG_OPTIMIZATION_LEVEL_RELEASE is not set +CONFIG_OPTIMIZATION_LEVEL_RELEASE= CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED=y -# CONFIG_OPTIMIZATION_ASSERTIONS_SILENT is not set -# CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED is not set +CONFIG_OPTIMIZATION_ASSERTIONS_SILENT= +CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED= +CONFIG_CXX_EXCEPTIONS= # # Component config @@ -100,9 +100,9 @@ CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED=y # # Application Level Tracing # -# CONFIG_ESP32_APPTRACE_DEST_TRAX is not set +CONFIG_ESP32_APPTRACE_DEST_TRAX= CONFIG_ESP32_APPTRACE_DEST_NONE=y -# CONFIG_ESP32_APPTRACE_ENABLE is not set +CONFIG_ESP32_APPTRACE_ENABLE= CONFIG_ESP32_APPTRACE_LOCK_ENABLE=y # @@ -114,30 +114,31 @@ CONFIG_ESP32_APPTRACE_LOCK_ENABLE=y # CONFIG_ENABLE_ARDUINO_DEPENDS=y CONFIG_AUTOSTART_ARDUINO=y -# CONFIG_DISABLE_HAL_LOCKS is not set +CONFIG_DISABLE_HAL_LOCKS= # # Debug Log Configuration # -# CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_NONE is not set +CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_NONE= CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_ERROR=y -# CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_WARN is not set -# CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_INFO is not set -# CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_DEBUG is not set -# CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_VERBOSE is not set +CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_WARN= +CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_INFO= +CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_DEBUG= +CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_VERBOSE= CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL=1 -# CONFIG_ARDUHAL_LOG_COLORS is not set -# CONFIG_AUTOCONNECT_WIFI is not set -# CONFIG_AWS_IOT_SDK is not set +CONFIG_ARDUHAL_LOG_COLORS= +CONFIG_ARDUHAL_ESP_LOG=y +CONFIG_AUTOCONNECT_WIFI= +CONFIG_AWS_IOT_SDK= CONFIG_BT_ENABLED=y CONFIG_BLUEDROID_ENABLED=y CONFIG_BTC_TASK_STACK_SIZE=8192 -# CONFIG_BLUEDROID_MEM_DEBUG is not set -CONFIG_CLASSIC_BT_ENABLED=y +CONFIG_BLUEDROID_MEM_DEBUG= +CONFIG_CLASSIC_BT_ENABLED= CONFIG_GATTS_ENABLE=y CONFIG_GATTC_ENABLE=y CONFIG_BLE_SMP_ENABLE=y -# CONFIG_BT_STACK_NO_LOG is not set +CONFIG_BT_STACK_NO_LOG= CONFIG_BT_ACL_CONNECTIONS=4 CONFIG_BTDM_CONTROLLER_RUN_CPU=0 CONFIG_SMP_ENABLE=y @@ -146,21 +147,21 @@ CONFIG_BT_RESERVE_DRAM=0x10000 # # ESP32-specific # -# CONFIG_ESP32_DEFAULT_CPU_FREQ_80 is not set -# CONFIG_ESP32_DEFAULT_CPU_FREQ_160 is not set +CONFIG_ESP32_DEFAULT_CPU_FREQ_80= +CONFIG_ESP32_DEFAULT_CPU_FREQ_160= CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240 CONFIG_MEMMAP_SMP=y -# CONFIG_SPIRAM_SUPPORT is not set -# CONFIG_MEMMAP_TRACEMEM is not set -# CONFIG_MEMMAP_TRACEMEM_TWOBANKS is not set -# CONFIG_ESP32_TRAX is not set +CONFIG_SPIRAM_SUPPORT= +CONFIG_MEMMAP_TRACEMEM= +CONFIG_MEMMAP_TRACEMEM_TWOBANKS= +CONFIG_ESP32_TRAX= CONFIG_TRACEMEM_RESERVE_DRAM=0x0 -# CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH is not set -# CONFIG_ESP32_ENABLE_COREDUMP_TO_UART is not set +CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH= +CONFIG_ESP32_ENABLE_COREDUMP_TO_UART= CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y -# CONFIG_ESP32_ENABLE_COREDUMP is not set -# CONFIG_TWO_UNIVERSAL_MAC_ADDRESS is not set +CONFIG_ESP32_ENABLE_COREDUMP= +CONFIG_TWO_UNIVERSAL_MAC_ADDRESS= CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS=y CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=4 CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32 @@ -169,55 +170,55 @@ CONFIG_MAIN_TASK_STACK_SIZE=4096 CONFIG_IPC_TASK_STACK_SIZE=1024 CONFIG_TIMER_TASK_STACK_SIZE=4096 CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF=y -# CONFIG_NEWLIB_STDOUT_LINE_ENDING_LF is not set -# CONFIG_NEWLIB_STDOUT_LINE_ENDING_CR is not set -# CONFIG_NEWLIB_STDIN_LINE_ENDING_CRLF is not set -# CONFIG_NEWLIB_STDIN_LINE_ENDING_LF is not set +CONFIG_NEWLIB_STDOUT_LINE_ENDING_LF= +CONFIG_NEWLIB_STDOUT_LINE_ENDING_CR= +CONFIG_NEWLIB_STDIN_LINE_ENDING_CRLF= +CONFIG_NEWLIB_STDIN_LINE_ENDING_LF= CONFIG_NEWLIB_STDIN_LINE_ENDING_CR=y -# CONFIG_NEWLIB_NANO_FORMAT is not set +CONFIG_NEWLIB_NANO_FORMAT= CONFIG_CONSOLE_UART_DEFAULT=y -# CONFIG_CONSOLE_UART_CUSTOM is not set -# CONFIG_CONSOLE_UART_NONE is not set +CONFIG_CONSOLE_UART_CUSTOM= +CONFIG_CONSOLE_UART_NONE= CONFIG_CONSOLE_UART_NUM=0 CONFIG_CONSOLE_UART_BAUDRATE=115200 CONFIG_ULP_COPROC_ENABLED=y CONFIG_ULP_COPROC_RESERVE_MEM=512 -# CONFIG_ESP32_PANIC_PRINT_HALT is not set +CONFIG_ESP32_PANIC_PRINT_HALT= CONFIG_ESP32_PANIC_PRINT_REBOOT=y -# CONFIG_ESP32_PANIC_SILENT_REBOOT is not set -# CONFIG_ESP32_PANIC_GDBSTUB is not set -# CONFIG_ESP32_DEBUG_OCDAWARE is not set +CONFIG_ESP32_PANIC_SILENT_REBOOT= +CONFIG_ESP32_PANIC_GDBSTUB= +CONFIG_ESP32_DEBUG_OCDAWARE= CONFIG_INT_WDT=y CONFIG_INT_WDT_TIMEOUT_MS=300 CONFIG_INT_WDT_CHECK_CPU1=y CONFIG_TASK_WDT=y -# CONFIG_TASK_WDT_PANIC is not set +CONFIG_TASK_WDT_PANIC= CONFIG_TASK_WDT_TIMEOUT_S=5 CONFIG_TASK_WDT_CHECK_IDLE_TASK=y -# CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set +CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1= CONFIG_BROWNOUT_DET=y CONFIG_BROWNOUT_DET_LVL_SEL_0=y -# CONFIG_BROWNOUT_DET_LVL_SEL_1 is not set -# CONFIG_BROWNOUT_DET_LVL_SEL_2 is not set -# CONFIG_BROWNOUT_DET_LVL_SEL_3 is not set -# CONFIG_BROWNOUT_DET_LVL_SEL_4 is not set -# CONFIG_BROWNOUT_DET_LVL_SEL_5 is not set -# CONFIG_BROWNOUT_DET_LVL_SEL_6 is not set -# CONFIG_BROWNOUT_DET_LVL_SEL_7 is not set +CONFIG_BROWNOUT_DET_LVL_SEL_1= +CONFIG_BROWNOUT_DET_LVL_SEL_2= +CONFIG_BROWNOUT_DET_LVL_SEL_3= +CONFIG_BROWNOUT_DET_LVL_SEL_4= +CONFIG_BROWNOUT_DET_LVL_SEL_5= +CONFIG_BROWNOUT_DET_LVL_SEL_6= +CONFIG_BROWNOUT_DET_LVL_SEL_7= CONFIG_BROWNOUT_DET_LVL=0 -# CONFIG_ESP32_TIME_SYSCALL_USE_RTC is not set +CONFIG_ESP32_TIME_SYSCALL_USE_RTC= CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1=y -# CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 is not set -# CONFIG_ESP32_TIME_SYSCALL_USE_NONE is not set +CONFIG_ESP32_TIME_SYSCALL_USE_FRC1= +CONFIG_ESP32_TIME_SYSCALL_USE_NONE= CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y -# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL is not set +CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL= CONFIG_ESP32_RTC_CLK_CAL_CYCLES=1024 CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=2000 -# CONFIG_ESP32_XTAL_FREQ_40 is not set -# CONFIG_ESP32_XTAL_FREQ_26 is not set +CONFIG_ESP32_XTAL_FREQ_40= +CONFIG_ESP32_XTAL_FREQ_26= CONFIG_ESP32_XTAL_FREQ_AUTO=y CONFIG_ESP32_XTAL_FREQ=0 -# CONFIG_DISABLE_BASIC_ROM_CONSOLE is not set +CONFIG_DISABLE_BASIC_ROM_CONSOLE= # # Wi-Fi @@ -225,7 +226,7 @@ CONFIG_ESP32_XTAL_FREQ=0 CONFIG_SW_COEXIST_ENABLE=y CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=10 CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=0 -# CONFIG_ESP32_WIFI_STATIC_TX_BUFFER is not set +CONFIG_ESP32_WIFI_STATIC_TX_BUFFER= CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER=y CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1 CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=32 @@ -238,10 +239,15 @@ CONFIG_ESP32_WIFI_NVS_ENABLED=y # PHY # CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE=y -# CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION is not set +CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION= CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER=20 CONFIG_ESP32_PHY_MAX_TX_POWER=20 +# +# Power Management +# +CONFIG_PM_ENABLE= + # # Ethernet # @@ -253,93 +259,105 @@ CONFIG_EMAC_TASK_PRIORITY=20 # # FAT Filesystem support # -# CONFIG_FATFS_CODEPAGE_ASCII is not set -# CONFIG_FATFS_CODEPAGE_437 is not set -# CONFIG_FATFS_CODEPAGE_720 is not set -# CONFIG_FATFS_CODEPAGE_737 is not set -# CONFIG_FATFS_CODEPAGE_771 is not set -# CONFIG_FATFS_CODEPAGE_775 is not set +CONFIG_FATFS_CODEPAGE_ASCII= +CONFIG_FATFS_CODEPAGE_437= +CONFIG_FATFS_CODEPAGE_720= +CONFIG_FATFS_CODEPAGE_737= +CONFIG_FATFS_CODEPAGE_771= +CONFIG_FATFS_CODEPAGE_775= CONFIG_FATFS_CODEPAGE_850=y -# CONFIG_FATFS_CODEPAGE_852 is not set -# CONFIG_FATFS_CODEPAGE_855 is not set -# CONFIG_FATFS_CODEPAGE_857 is not set -# CONFIG_FATFS_CODEPAGE_860 is not set -# CONFIG_FATFS_CODEPAGE_861 is not set -# CONFIG_FATFS_CODEPAGE_862 is not set -# CONFIG_FATFS_CODEPAGE_863 is not set -# CONFIG_FATFS_CODEPAGE_864 is not set -# CONFIG_FATFS_CODEPAGE_865 is not set -# CONFIG_FATFS_CODEPAGE_866 is not set -# CONFIG_FATFS_CODEPAGE_869 is not set -# CONFIG_FATFS_CODEPAGE_932 is not set -# CONFIG_FATFS_CODEPAGE_936 is not set -# CONFIG_FATFS_CODEPAGE_949 is not set -# CONFIG_FATFS_CODEPAGE_950 is not set +CONFIG_FATFS_CODEPAGE_852= +CONFIG_FATFS_CODEPAGE_855= +CONFIG_FATFS_CODEPAGE_857= +CONFIG_FATFS_CODEPAGE_860= +CONFIG_FATFS_CODEPAGE_861= +CONFIG_FATFS_CODEPAGE_862= +CONFIG_FATFS_CODEPAGE_863= +CONFIG_FATFS_CODEPAGE_864= +CONFIG_FATFS_CODEPAGE_865= +CONFIG_FATFS_CODEPAGE_866= +CONFIG_FATFS_CODEPAGE_869= +CONFIG_FATFS_CODEPAGE_932= +CONFIG_FATFS_CODEPAGE_936= +CONFIG_FATFS_CODEPAGE_949= +CONFIG_FATFS_CODEPAGE_950= CONFIG_FATFS_CODEPAGE=850 -# CONFIG_FATFS_LFN_NONE is not set -# CONFIG_FATFS_LFN_HEAP is not set +CONFIG_FATFS_LFN_NONE= +CONFIG_FATFS_LFN_HEAP= CONFIG_FATFS_LFN_STACK=y CONFIG_FATFS_MAX_LFN=255 # # FreeRTOS # -# CONFIG_FREERTOS_UNICORE is not set +CONFIG_FREERTOS_UNICORE= CONFIG_FREERTOS_CORETIMER_0=y -# CONFIG_FREERTOS_CORETIMER_1 is not set +CONFIG_FREERTOS_CORETIMER_1= CONFIG_FREERTOS_HZ=1000 -# CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION is not set -# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE is not set -# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL is not set +CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION= +CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE= +CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL= CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=y CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y CONFIG_FREERTOS_INTERRUPT_BACKTRACE=y CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 CONFIG_FREERTOS_ASSERT_FAIL_ABORT=y -# CONFIG_FREERTOS_ASSERT_FAIL_PRINT_CONTINUE is not set -# CONFIG_FREERTOS_ASSERT_DISABLE is not set -# CONFIG_ENABLE_MEMORY_DEBUG is not set +CONFIG_FREERTOS_ASSERT_FAIL_PRINT_CONTINUE= +CONFIG_FREERTOS_ASSERT_DISABLE= CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1024 CONFIG_FREERTOS_ISR_STACKSIZE=1536 -# CONFIG_FREERTOS_LEGACY_HOOKS is not set +CONFIG_FREERTOS_LEGACY_HOOKS= CONFIG_FREERTOS_MAX_TASK_NAME_LEN=16 -# CONFIG_SUPPORT_STATIC_ALLOCATION is not set +CONFIG_SUPPORT_STATIC_ALLOCATION= CONFIG_TIMER_TASK_PRIORITY=1 CONFIG_TIMER_TASK_STACK_DEPTH=2048 CONFIG_TIMER_QUEUE_LENGTH=10 -# CONFIG_FREERTOS_DEBUG_INTERNALS is not set +CONFIG_FREERTOS_USE_TRACE_FACILITY= +CONFIG_FREERTOS_DEBUG_INTERNALS= # # Heap memory debugging # -# CONFIG_HEAP_POISONING_DISABLED is not set +CONFIG_HEAP_POISONING_DISABLED= CONFIG_HEAP_POISONING_LIGHT=y -# CONFIG_HEAP_POISONING_COMPREHENSIVE is not set -# CONFIG_HEAP_TRACING is not set +CONFIG_HEAP_POISONING_COMPREHENSIVE= +CONFIG_HEAP_TRACING= + +# +# libsodium +# +CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y # # Log output # -# CONFIG_LOG_DEFAULT_LEVEL_NONE is not set +CONFIG_LOG_DEFAULT_LEVEL_NONE= CONFIG_LOG_DEFAULT_LEVEL_ERROR=y -# CONFIG_LOG_DEFAULT_LEVEL_WARN is not set -# CONFIG_LOG_DEFAULT_LEVEL_INFO is not set -# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set -# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set +CONFIG_LOG_DEFAULT_LEVEL_WARN= +CONFIG_LOG_DEFAULT_LEVEL_INFO= +CONFIG_LOG_DEFAULT_LEVEL_DEBUG= +CONFIG_LOG_DEFAULT_LEVEL_VERBOSE= CONFIG_LOG_DEFAULT_LEVEL=1 -# CONFIG_LOG_COLORS is not set +CONFIG_LOG_COLORS= # # LWIP # -# CONFIG_L2_TO_L3_COPY is not set +CONFIG_L2_TO_L3_COPY= CONFIG_LWIP_MAX_SOCKETS=10 -CONFIG_LWIP_THREAD_LOCAL_STORAGE_INDEX=0 CONFIG_LWIP_SO_REUSE=y +CONFIG_LWIP_SO_REUSE_RXTOALL=y CONFIG_LWIP_SO_RCVBUF=y CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1 -# CONFIG_LWIP_IP_FRAG is not set -# CONFIG_LWIP_IP_REASSEMBLY is not set +CONFIG_LWIP_IP_FRAG= +CONFIG_LWIP_IP_REASSEMBLY= +CONFIG_LWIP_STATS= +CONFIG_LWIP_ETHARP_TRUST_IP_MAC=y +CONFIG_TCPIP_RECVMBOX_SIZE=32 +CONFIG_LWIP_DHCP_DOES_ARP_CHECK= +CONFIG_LWIP_AUTOIP= +CONFIG_LWIP_NETIF_LOOPBACK=y +CONFIG_LWIP_LOOPBACK_MAX_PBUFS=8 # # TCP @@ -353,37 +371,36 @@ CONFIG_TCP_WND_DEFAULT=5744 CONFIG_TCP_RECVMBOX_SIZE=6 CONFIG_TCP_QUEUE_OOSEQ=y CONFIG_TCP_OVERSIZE_MSS=y -# CONFIG_TCP_OVERSIZE_QUARTER_MSS is not set -# CONFIG_TCP_OVERSIZE_DISABLE is not set +CONFIG_TCP_OVERSIZE_QUARTER_MSS= +CONFIG_TCP_OVERSIZE_DISABLE= # # UDP # CONFIG_UDP_RECVMBOX_SIZE=6 -# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set CONFIG_TCPIP_TASK_STACK_SIZE=2560 -# CONFIG_PPP_SUPPORT is not set +CONFIG_PPP_SUPPORT= # # ICMP # -# CONFIG_LWIP_MULTICAST_PING is not set -# CONFIG_LWIP_BROADCAST_PING is not set +CONFIG_LWIP_MULTICAST_PING= +CONFIG_LWIP_BROADCAST_PING= # # mbedTLS # CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=16384 -# CONFIG_MBEDTLS_DEBUG is not set +CONFIG_MBEDTLS_DEBUG= CONFIG_MBEDTLS_HARDWARE_AES=y -# CONFIG_MBEDTLS_HARDWARE_MPI is not set -# CONFIG_MBEDTLS_HARDWARE_SHA is not set +CONFIG_MBEDTLS_HARDWARE_MPI= +CONFIG_MBEDTLS_HARDWARE_SHA= CONFIG_MBEDTLS_HAVE_TIME=y -# CONFIG_MBEDTLS_HAVE_TIME_DATE is not set +CONFIG_MBEDTLS_HAVE_TIME_DATE= CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT=y -# CONFIG_MBEDTLS_TLS_SERVER_ONLY is not set -# CONFIG_MBEDTLS_TLS_CLIENT_ONLY is not set -# CONFIG_MBEDTLS_TLS_DISABLED is not set +CONFIG_MBEDTLS_TLS_SERVER_ONLY= +CONFIG_MBEDTLS_TLS_CLIENT_ONLY= +CONFIG_MBEDTLS_TLS_DISABLED= CONFIG_MBEDTLS_TLS_SERVER=y CONFIG_MBEDTLS_TLS_CLIENT=y CONFIG_MBEDTLS_TLS_ENABLED=y @@ -391,7 +408,7 @@ CONFIG_MBEDTLS_TLS_ENABLED=y # # TLS Key Exchange Methods # -# CONFIG_MBEDTLS_PSK_MODES is not set +CONFIG_MBEDTLS_PSK_MODES= CONFIG_MBEDTLS_KEY_EXCHANGE_RSA=y CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA=y CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE=y @@ -400,11 +417,11 @@ CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA=y CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA=y CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA=y CONFIG_MBEDTLS_SSL_RENEGOTIATION=y -# CONFIG_MBEDTLS_SSL_PROTO_SSL3 is not set +CONFIG_MBEDTLS_SSL_PROTO_SSL3= CONFIG_MBEDTLS_SSL_PROTO_TLS1=y CONFIG_MBEDTLS_SSL_PROTO_TLS1_1=y CONFIG_MBEDTLS_SSL_PROTO_TLS1_2=y -# CONFIG_MBEDTLS_SSL_PROTO_DTLS is not set +CONFIG_MBEDTLS_SSL_PROTO_DTLS= CONFIG_MBEDTLS_SSL_ALPN=y CONFIG_MBEDTLS_SSL_SESSION_TICKETS=y @@ -412,16 +429,16 @@ CONFIG_MBEDTLS_SSL_SESSION_TICKETS=y # Symmetric Ciphers # CONFIG_MBEDTLS_AES_C=y -# CONFIG_MBEDTLS_CAMELLIA_C is not set -# CONFIG_MBEDTLS_DES_C is not set +CONFIG_MBEDTLS_CAMELLIA_C= +CONFIG_MBEDTLS_DES_C= CONFIG_MBEDTLS_RC4_DISABLED=y -# CONFIG_MBEDTLS_RC4_ENABLED_NO_DEFAULT is not set -# CONFIG_MBEDTLS_RC4_ENABLED is not set -# CONFIG_MBEDTLS_BLOWFISH_C is not set -# CONFIG_MBEDTLS_XTEA_C is not set +CONFIG_MBEDTLS_RC4_ENABLED_NO_DEFAULT= +CONFIG_MBEDTLS_RC4_ENABLED= +CONFIG_MBEDTLS_BLOWFISH_C= +CONFIG_MBEDTLS_XTEA_C= CONFIG_MBEDTLS_CCM_C=y CONFIG_MBEDTLS_GCM_C=y -# CONFIG_MBEDTLS_RIPEMD160_C is not set +CONFIG_MBEDTLS_RIPEMD160_C= # # Certificates @@ -450,9 +467,9 @@ CONFIG_MBEDTLS_ECP_NIST_OPTIM=y # # OpenSSL # -# CONFIG_OPENSSL_DEBUG is not set +CONFIG_OPENSSL_DEBUG= CONFIG_OPENSSL_ASSERT_DO_NOTHING=y -# CONFIG_OPENSSL_ASSERT_EXIT is not set +CONFIG_OPENSSL_ASSERT_EXIT= # # PThreads @@ -463,7 +480,7 @@ CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT=2048 # # SPI Flash driver # -# CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set +CONFIG_SPI_FLASH_ENABLE_COUNTERS= CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y # @@ -476,10 +493,10 @@ CONFIG_SPIFFS_MAX_PARTITIONS=3 # CONFIG_SPIFFS_CACHE=y CONFIG_SPIFFS_CACHE_WR=y -# CONFIG_SPIFFS_CACHE_STATS is not set +CONFIG_SPIFFS_CACHE_STATS= CONFIG_SPIFFS_PAGE_CHECK=y CONFIG_SPIFFS_GC_MAX_RUNS=10 -# CONFIG_SPIFFS_GC_STATS is not set +CONFIG_SPIFFS_GC_STATS= CONFIG_SPIFFS_OBJ_NAME_LEN=32 CONFIG_SPIFFS_USE_MAGIC=y CONFIG_SPIFFS_USE_MAGIC_LENGTH=y @@ -487,12 +504,12 @@ CONFIG_SPIFFS_USE_MAGIC_LENGTH=y # # Debug Configuration # -# CONFIG_SPIFFS_DBG is not set -# CONFIG_SPIFFS_API_DBG is not set -# CONFIG_SPIFFS_GC_DBG is not set -# CONFIG_SPIFFS_CACHE_DBG is not set -# CONFIG_SPIFFS_CHECK_DBG is not set -# CONFIG_SPIFFS_TEST_VISUALISATION is not set +CONFIG_SPIFFS_DBG= +CONFIG_SPIFFS_API_DBG= +CONFIG_SPIFFS_GC_DBG= +CONFIG_SPIFFS_CACHE_DBG= +CONFIG_SPIFFS_CHECK_DBG= +CONFIG_SPIFFS_TEST_VISUALISATION= # # tcpip adapter @@ -502,6 +519,6 @@ CONFIG_IP_LOST_TIMER_INTERVAL=120 # # Wear Levelling # -# CONFIG_WL_SECTOR_SIZE_512 is not set +CONFIG_WL_SECTOR_SIZE_512= CONFIG_WL_SECTOR_SIZE_4096=y CONFIG_WL_SECTOR_SIZE=4096 diff --git a/variants/heltec_wifi_kit_32/pins_arduino.h b/variants/heltec_wifi_kit_32/pins_arduino.h index 39a059eb027..e22d01e8905 100644 --- a/variants/heltec_wifi_kit_32/pins_arduino.h +++ b/variants/heltec_wifi_kit_32/pins_arduino.h @@ -11,7 +11,7 @@ #define digitalPinToInterrupt(p) (((p)<40)?(p):-1) #define digitalPinHasPWM(p) (p < 34) -static const uint8_t LED_BUILTIN = 2; +static const uint8_t LED_BUILTIN = 25; #define BUILTIN_LED LED_BUILTIN // backward compatibility static const uint8_t KEY_BUILTIN = 0; @@ -22,17 +22,20 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 18; -static const uint8_t MOSI = 27; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; static const uint8_t MISO = 19; -static const uint8_t SCK = 5; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; +static const uint8_t A1 = 37; +static const uint8_t A2 = 38; static const uint8_t A3 = 39; static const uint8_t A4 = 32; static const uint8_t A5 = 33; static const uint8_t A6 = 34; static const uint8_t A7 = 35; + static const uint8_t A10 = 4; static const uint8_t A11 = 0; static const uint8_t A12 = 2;