未验证 提交 2333df5a 编写于 作者: R Rodrigo Garcia 提交者: GitHub

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

* fixes warnings and rand function

* removes extra space - style
上级 5dff15ce
......@@ -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);
......
......@@ -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)
......
......@@ -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) {
......
......@@ -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; 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
......@@ -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;
}
}
......@@ -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];
}
}
......@@ -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){
......
......@@ -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);
......
......@@ -537,7 +537,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);
......
......@@ -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++;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册