How to #define processor specific code segment? (eg: ATMEGA, ATTINY, ESP8266, RP2040, etc.)

I'm currently writing a grand library to easily reuse my code. I'm using several different boards and chips in my circuits. (I design my own PCBs, so not always using something off the shelf, and when I do I usually use something minimal eg: pro-mini, ESP12F module, or Pico) I know the definition should be something like #ifdef SOMETHING //code here #endif I would be interested in a list of keywords to check for the following: - ATMEGAs (I've used ATMEGA238P, and ATMEGA32U4 in my designs) - ATTINYs (Used a variety of ATTINY 44/84 and 25/45/85) - ESP8266 (Used 12E/F module specifically) - ESP32 (I have not yet tested, but would like to in the future) - RP2040 (Pico specifically.) - STM32 (I have some STM32L010C6, and STM32L011F4P6 low power custom circuits) But I bet having a list of keywords to check for a bunch of processors you can just loop up on discord would be beneficial to everyone writing a library, so feel free to add anything you have worked with.
6 Replies
RPBCACUEAIIBH
RPBCACUEAIIBHOP•3y ago
For ESP12E/F modules it's "ESP8266" (I found it as I have used it before in one of my sketches.) It's "AVR" for both ATMEGAs, and ATTINYs (I think...) For the pico it's "PICO_RP2040" that probably pico only, not all RP2040...
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
RPBCACUEAIIBH
RPBCACUEAIIBHOP•3y ago
@3l G1zzm0 For the time being not much... I just created a LibLab sketch with different setup() and loop() for different microcontrollers that already compiles for AVR, ESP8266 and Pico, for testing stuff on all 3 by just having them all plugged in, selecting one, then hitting upload for the same sketch. But for example I already have a class written that handles EEPROM/Flash for AVR and ESP8266 differently, and there will be some wi-fi stuff and multiprocessing stuff that will only work on ESP8266, or Pico, but when I includ the collective library header to a new sketch, it should compile, whatever MCU I use. For a complete picture I also plan to make it with non-microcontroller stuff so I can use the same 1 library header, and some of the same code for writing PC software for my MCU projects. Not sure how doable it is, I just had an idea to unify everything and trying to make it happen. 🙂
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
RPBCACUEAIIBH
RPBCACUEAIIBHOP•3y ago
Exactly! 😄 @Oops.se Yes that is pretty much how my sketch works right now. 🙂 except it will check for "PCSoftware" too and when I'm writing simple CPP code for PC, I just do something like this: #define PCSoftware #include "MainHeader.h" and the main header contains all the branching to different architecture.
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?