Friday, August 12, 2022

Use of Macros

I am listing some unique macros:

1. Following macros used for incrementing/decrementing any numer(integer preferred) x. This usually can be used when you are having Menu layout using pushbuttons. For each pushbutton, menu index value x can be increased/decreased by any value inc/dec and can be set to a limit max/min

#define INC(x,max,inc) x = (x<=(max - inc))?(x+inc):max
#define DEC(x,min,dec) x = (x>=(min + dec))?(x-dec):min


2. When using RTOS you have periodic tasks that may loop in every 10ms or 50ms etc. Usually while development, we want to constantly change this loop time and test functions out. But while changing this many variables that are dependent on the task time need to be varied. Following macros can be used appropriately adjust the values depending on task time.

#define TASK2_REPEAT_MS        20
#define COUNT_1SEC_TASK2    (1000/TASK2_REPEAT_MS)


example usage

Lets say you have task that repeats every 20ms. and there is a variable that checks for 1sec loop.

 

your caode can be written using above macros:

task2(){

 uint8_t var_u81secCounter;

 var_u81secCounter++;

if(var_u81secCounter > COUNT_1SEC_TASK2    ) {

/* do things whatever you want to do every 1second

}



THis way if you change task periodicity to 50ms, all you need to update is macro TASK2_REPEAT_MS       50. Nothing else






Thursday, August 4, 2022

ESP32 Development

1. In the field of IoT ESP32 is major player. There are many Arduino versions are available, however they are only limited to small projects and hobby projects. If you want to develop a professional application, then you need to learn about ESP-IDF. This is the framework specially developed for ESP32 using which we can quickly drive various peripherals.

2. In addition ESP Also provides eclipse based IDE to make things even easier for developers:

3. Find the ESP-IDE here : https://dl.espressif.com/dl/esp-idf/


 

4. Select 2nd option as offline installer gives you reference that you have v2.5.0 version of IDE & ESP-IDF Version v4.4.

 5.  Git link - https://github.com/espressif/idf-installer

6