So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By column
#84867 Hello,

I was playing with ESP8266 with Arduino IDE. From this experience I have learned that all projects should contain two main functions - void setup() and void loop().

Later I moved to Visual Studio Code with Platformio and first sample with name Blink I choose has experience different structure :
Code: Select alluser_rf_cal_sector_set(void)

{

enum flash_size_map size_map = system_get_flash_size_map();

uint32 rf_cal_sec = 0;

switch (size_map) {

case FLASH_SIZE_4M_MAP_256_256:

rf_cal_sec = 128 - 5;

break;

case FLASH_SIZE_8M_MAP_512_512:

rf_cal_sec = 256 - 5;

break;

case FLASH_SIZE_16M_MAP_512_512:

case FLASH_SIZE_16M_MAP_1024_1024:

rf_cal_sec = 512 - 5;

break;

case FLASH_SIZE_32M_MAP_512_512:

case FLASH_SIZE_32M_MAP_1024_1024:

rf_cal_sec = 1024 - 5;

break;

case FLASH_SIZE_64M_MAP_1024_1024:

rf_cal_sec = 2048 - 5;

break;

case FLASH_SIZE_128M_MAP_1024_1024:

rf_cal_sec = 4096 - 5;

break;

default:

rf_cal_sec = 0;

break;

}

return rf_cal_sec;

}

void blinky(void *arg)

{

static uint8_t state = 0;

if (state) {

GPIO_OUTPUT_SET(2, 1);

} else {

GPIO_OUTPUT_SET(2, 0);

}

state ^= 1;

}

void ICACHE_FLASH_ATTR user_init(void)

{

gpio_init();

uart_init(115200, 115200);

os_printf("SDK version:%s\n", system_get_sdk_version());

// Disable WiFi

wifi_set_opmode(NULL_MODE);

PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);

os_timer_disarm(&ptimer);

os_timer_setfn(&ptimer, (os_timer_func_t *)blinky, NULL);

os_timer_arm(&ptimer, 2000, 1);

}


Code contains 3 functions, but none of them are setup or loop. What basic principals of creating program for ESP8266? Which function is entry point? What function should persist in program?