Skip to content

Removes a few Warnings and fixes Math rand() to work like Arduino mainstream #7613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cores/esp32/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 10 additions & 18 deletions cores/esp32/WMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions cores/esp32/esp32-hal-rmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions cores/esp32/esp32-hal-spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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; i<c_longs; i++) {
for (size_t i=0; i<c_longs; i++) {
spi->dev->data_buf[i] = data[i];
}
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
Expand Down Expand Up @@ -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; i<c_longs; i++) {
for (size_t i=0; i<c_longs; i++) {
spi->dev->data_buf[i] = data[i];
}
} else {
for (int i=0; i<c_longs; i++) {
for (size_t i=0; i<c_longs; i++) {
spi->dev->data_buf[i] = 0xFFFFFFFF;
}
}
Expand All @@ -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; i<c_longs; i++) {
for (size_t i=0; i<c_longs; i++) {
result[i] = spi->dev->data_buf[i];
}
}
Expand Down Expand Up @@ -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; i<c_longs; i++) {
for (size_t i=0; i<c_longs; i++) {
if(msb){
if(l_bytes && i == (c_longs - 1)){
if(l_bytes == 2){
Expand Down
2 changes: 1 addition & 1 deletion cores/esp32/esp32-hal-timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static hw_timer_t timer_dev[4] = {
// timer_init() will list thru all timers and return free timer handle)


uint64_t inline timerRead(hw_timer_t *timer){
inline uint64_t timerRead(hw_timer_t *timer){

uint64_t value;
timer_get_counter_value(timer->group, timer->num,&value);
Expand Down
2 changes: 1 addition & 1 deletion cores/esp32/esp32-hal-uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions cores/esp32/stdlib_noniso.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ 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;

number += rounding;

// 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++;
Expand Down