I'm developing a project where I use ESP32 as the main processor and have ATMEGA MCUS such as 32u4 and 328p do peripherals. In developing the code, there are three firmware, one on each processor. It's a lot of work to keep them separate so I decide to share some classes among the three projects. I'm using Arduino IDE for the ATMEGA MCUs and ESP-IDF release 3.3 for ESP32. In Arduino IDE, it #define ARDUINO as an IDE version number so you can do conditional compilation depending on version. In order to share class code, things like heap_caps_malloc() needs to be changed into malloc() so I am using:
Code: Select all
#ifdef ARDUINO
uint8_t *ddata=(uint8_t*)malloc(USB_DESCRIPTOR_MAX_LEN*4); // Allocate 1024 bytes of memory. Longest one is Honeywell 7580g 646 bytes
#else
uint8_t *ddata=(uint8_t*)heap_caps_malloc(USB_DESCRIPTOR_MAX_LEN*4,MALLOC_CAP_SPIRAM); // Allocate 1024 bytes of memory. Longest one is Honeywell 7580g 646 bytes
#endif
Code: Select all
#if defined(ARDUINO)
uint8_t *ddata=(uint8_t*)malloc(1024);
#elif defined(ESP32)
uint8_t *ddata=(uint8_t*)heap_caps_malloc(1024,MALLOC_CAP_SPIRAM);
#else
//blah maybe using online compilers to test functionality
#endif