I am using PlatdormIO with VScode.
The workspace include several ESP32 projects which communicate with each other.
Since these projects have several several classes in common, I created an .h file at the root of the workspace and tried to include it like regular lib, or with include <…/xx.h>, which failed compilation.
I also tried to reference the class directly without the #include - failed again.
How can I create a class that will be used by several projects within same workspace/
Yes, if you want to do it the proper way as PlatformIO intents it. Shared code (whether it be only a header file or with accompanying code or not) can be put in a library that the projects refer to in their platformio.ini by declaring it as a lib_extra_dirs.
If you don’t care about that, you can hack it in using build_flags in each project’s platformio.ini:
-I<path to folder where your .h file is>
PlatformIO doesn’t know about “multi workspaces”, that’s a VSCode concept. PlatformIO projects are standalone from each other – unless you edit their configuration to refer to a common libary folder, for example.