diff --git a/cores/esp32/Print.cpp b/cores/esp32/Print.cpp index 3636d99e658..e5d388ec588 100644 --- a/cores/esp32/Print.cpp +++ b/cores/esp32/Print.cpp @@ -58,7 +58,7 @@ size_t Print::printf(const char *format, ...) va_end(arg); return 0; }; - if(len >= sizeof(loc_buf)){ + if(len >= (int)sizeof(loc_buf)){ // comparation of same sign type for the compiler temp = (char*) malloc(len+1); if(temp == NULL) { va_end(arg); diff --git a/cores/esp32/WMath.cpp b/cores/esp32/WMath.cpp index 931ac96637b..078e18a8767 100644 --- a/cores/esp32/WMath.cpp +++ b/cores/esp32/WMath.cpp @@ -36,25 +36,17 @@ void randomSeed(unsigned long seed) } } -long random(long howbig) +long random( long howsmall, long howbig ); +long random( long howbig ) { - uint32_t x = esp_random(); - uint64_t m = uint64_t(x) * uint64_t(howbig); - uint32_t l = uint32_t(m); - if (l < howbig) { - uint32_t t = -howbig; - if (t >= howbig) { - t -= howbig; - if (t >= howbig) - t %= howbig; - } - while (l < t) { - x = esp_random(); - m = uint64_t(x) * uint64_t(howbig); - l = uint32_t(m); - } - } - return m >> 32; + if ( howbig == 0 ) + { + return 0 ; + } + if (howbig < 0) { + return (random(0, -howbig)); + } + return esp_random() % howbig; } long random(long howsmall, long howbig) diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index a220119d316..309cd13b327 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -88,9 +88,9 @@ struct rmt_obj_s { bool allocated; EventGroupHandle_t events; - int channel; - int buffers; - int data_size; + uint32_t channel; + uint32_t buffers; + uint32_t data_size; uint32_t* data_ptr; rmt_rx_data_cb_t cb; void * arg; @@ -133,7 +133,7 @@ static xSemaphoreHandle g_rmt_block_lock = NULL; static rmt_obj_t* _rmtAllocate(int pin, int from, int size) { - size_t i; + int i; // setup how many buffers shall we use g_rmt_objects[from].buffers = size; @@ -539,10 +539,10 @@ float rmtSetTick(rmt_obj_t* rmt, float tick) rmt_obj_t* rmtInit(int pin, bool tx_not_rx, rmt_reserve_memsize_t memsize) { - int buffers = memsize; + uint32_t buffers = memsize; rmt_obj_t* rmt = NULL; - size_t i = 0; - size_t j = 0; + uint32_t i = 0; + uint32_t j = 0; // create common block mutex for protecting allocs from multiple threads if (!g_rmt_block_lock) { diff --git a/cores/esp32/esp32-hal-spi.c b/cores/esp32/esp32-hal-spi.c index 39ad027be55..16ff3b65d10 100644 --- a/cores/esp32/esp32-hal-spi.c +++ b/cores/esp32/esp32-hal-spi.c @@ -1003,7 +1003,7 @@ static void __spiTransferBytes(spi_t * spi, const uint8_t * data, uint8_t * out, if(!spi) { return; } - int i; + uint32_t i; if(bytes > 64) { bytes = 64; @@ -1298,7 +1298,7 @@ void spiWriteNL(spi_t * spi, const void * data_in, uint32_t len){ #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif - for (int i=0; idev->data_buf[i] = data[i]; } #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 @@ -1333,11 +1333,11 @@ void spiTransferBytesNL(spi_t * spi, const void * data_in, uint8_t * data_out, u spi->dev->mosi_dlen.usr_mosi_dbitlen = (c_len*8)-1; spi->dev->miso_dlen.usr_miso_dbitlen = (c_len*8)-1; if(data){ - for (int i=0; idev->data_buf[i] = data[i]; } } else { - for (int i=0; idev->data_buf[i] = 0xFFFFFFFF; } } @@ -1349,17 +1349,17 @@ void spiTransferBytesNL(spi_t * spi, const void * data_in, uint8_t * data_out, u while(spi->dev->cmd.usr); if(result){ if(c_len & 3){ - for (int i=0; i<(c_longs-1); i++) { + for (size_t i=0; i<(c_longs-1); i++) { result[i] = spi->dev->data_buf[i]; } uint32_t last_data = spi->dev->data_buf[c_longs-1]; uint8_t * last_out8 = (uint8_t *)&result[c_longs-1]; uint8_t * last_data8 = (uint8_t *)&last_data; - for (int i=0; i<(c_len & 3); i++) { + for (size_t i=0; i<(c_len & 3); i++) { last_out8[i] = last_data8[i]; } } else { - for (int i=0; idev->data_buf[i]; } } @@ -1439,7 +1439,7 @@ void ARDUINO_ISR_ATTR spiWritePixelsNL(spi_t * spi, const void * data_in, uint32 #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif - for (int i=0; igroup, timer->num,&value); diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 0dbe9e52d76..785b2bdbd6e 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -535,7 +535,7 @@ int log_printfv(const char *format, va_list arg) { static char loc_buf[64]; char * temp = loc_buf; - int len; + uint32_t len; va_list copy; va_copy(copy, arg); len = vsnprintf(NULL, 0, format, copy); diff --git a/cores/esp32/stdlib_noniso.c b/cores/esp32/stdlib_noniso.c index d30febd97f8..e1e9eed6d41 100644 --- a/cores/esp32/stdlib_noniso.c +++ b/cores/esp32/stdlib_noniso.c @@ -163,7 +163,7 @@ char * dtostrf(double number, signed int width, unsigned int prec, char *s) { // Round correctly so that print(1.999, 2) prints as "2.00" // I optimized out most of the divisions double rounding = 2.0; - for (uint32_t i = 0; i < prec; ++i) + for (unsigned int i = 0; i < prec; ++i) rounding *= 10.0; rounding = 1.0 / rounding; @@ -171,7 +171,7 @@ char * dtostrf(double number, signed int width, unsigned int prec, char *s) { // Figure out how big our number really is double tenpow = 1.0; - int digitcount = 1; + unsigned int digitcount = 1; while (number >= 10.0 * tenpow) { tenpow *= 10.0; digitcount++;