This may be making things more complex than they need to be but I am curious for learning purposes...
I am trying to brainstorm how I would go about making my own main() function for esp8266 related boards I am working with just to test out. I am aware for AVR based boards that the main() function being used that defines setup() and loop() is located here /arduino/hardware/arduino/avr/cores/arduino/main.cpp
and looks like:
int main(void)
{
init();
initVariant();
#if defined(USBCON)
USBDevice.attach();
#endif
setup();
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
return 0;
}
Seeing that every arduino program follows the same generic setup() and loop() I was intrigued when I saw how different it is when working with the ESP8266.
I was curious how I could edit the setup() and loop() for the ESP8266 main file I believe to be located in this file /.arduino15/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266/core_esp8266_main.cpp
and the portion of the code I interpreted as the "main" in this case was this:
Does anyone have any ideas on how I could potentially modify this or my existing code to allows for the use of main() and not be set to using setup() and loop()?
Looks like the first function in the ESP8266 core is "user_init()", also in core_esp8266_main.cpp. It is the function that sets up a 'task' that runs loop_wrapper():
extern "C" void user_init(void) {
struct rst_info *rtc_info_ptr = system_get_rst_info();
memcpy((void *) &resetInfo, (void *) rtc_info_ptr, sizeof(resetInfo));
uart_div_modify(0, UART_CLK_FREQ / (115200));
init(); // in core_esp8266_wiring.c, inits hw regs and sdk timer
initVariant();
experimental::initFlashQuirks(); // Chip specific flash init.
cont_init(g_pcont);
#if defined(DEBUG_ESP_HWDT) || defined(DEBUG_ESP_HWDT_NOEXTRA4K)
debug_hwdt_init();
#endif
#if defined(UMM_HEAP_EXTERNAL)
install_vm_exception_handler();
#endif
#if defined(NON32XFER_HANDLER) || defined(MMU_IRAM_HEAP)
install_non32xfer_exception_handler();
#endif
#if defined(MMU_IRAM_HEAP)
umm_init_iram();
#endif
preinit(); // Prior to C++ Dynamic Init (not related to above init() ). Meant to be user redefinable.
__disableWiFiAtBootTime(); // default weak function disables WiFi
ets_task(loop_task,
LOOP_TASK_PRIORITY, s_loop_queue,
LOOP_QUEUE_SIZE);
system_init_done_cb(&init_done);
}
It isn't called from anywhere in the Arduino core but is referenced in a bunch of pre-compiled libraries: