Files
ESP32-S3-LCD-1.3/.docs/CORRECT_FILE_LOCATIONS.md
T
2026-09-21 10:28:35 +02:00

5.1 KiB

Correct File Locations - Quick Reference

✅ Correct Structure

Implementation Files (.cpp) → src/

src/
├── main.cpp                    ✅ Main application
├── display_init.cpp            ✅ Display hardware driver
├── uart_receiver.cpp           (future - Phase 2)
└── data_validator.cpp          (future - Phase 4)

Rule: ALL .cpp implementation files go in src/


Header Files (.h) → include/modules/

include/modules/
├── display_init.h              ✅ Display module interface
├── uart_receiver.h             (future - Phase 2)
└── data_validator.h            (future - Phase 4)

Rule: Module header files go in include/modules/


Why This Structure?

.cpp files in src/

  • ✅ PlatformIO automatically compiles all .cpp in src/
  • ✅ Implementation details are separated from interfaces
  • ✅ Standard C++ project structure

.h files in include/

  • ✅ Headers are on the include path
  • ✅ Can be included with #include "modules/display_init.h"
  • ✅ Public interfaces are visible to all modules

❌ Common Mistakes

❌ WRONG: .cpp in include/

include/modules/
└── display_init.cpp     ❌ WRONG! Move to src/

Problem: Include directories are for headers, not implementations

Fix:

mv include/modules/display_init.cpp src/

❌ WRONG: .h in src/

src/
└── display_init.h       ❌ WRONG! Move to include/modules/

Problem: Headers in src/ are not on the include path

Fix:

mv src/display_init.h include/modules/

Include Path Examples

From src/main.cpp:

#include "modules/display_init.h"  ✅ Correct

From src/display_init.cpp:

#include "modules/display_init.h"  ✅ Correct

From any module:

#include "modules/display_init.h"  ✅ Always use this format

Special Cases

SquareLine Studio UI Files

include/ui/
├── ui.h                 ✅ Header in include/
├── ui.c                 ✅ Implementation also in include/ (special case)
└── screens/
    ├── ui_Home_Screen.h ✅
    └── ui_Home_Screen.c ✅

Why this is different:

  • SquareLine Studio exports both .h and .c to the same folder
  • build_src_filter in platformio.ini includes +<../include/ui/*>
  • This tells PlatformIO to compile .c files from include/ui/

This is the ONLY exception - don't do this for your own modules!


Creating a New Module

Example: Adding settings_manager module

  1. Create header in include/modules/:
# Create the header
cat > include/modules/settings_manager.h << 'EOF'
#ifndef SETTINGS_MANAGER_H
#define SETTINGS_MANAGER_H

namespace SettingsManager {
    void init();
    void save();
    int getBrightnessSetting();
}

#endif
EOF
  1. Create implementation in src/:
# Create the implementation
cat > src/settings_manager.cpp << 'EOF'
#include "modules/settings_manager.h"
#include <Preferences.h>

namespace SettingsManager {
    void init() {
        // Implementation
    }

    void save() {
        // Implementation
    }

    int getBrightnessSetting() {
        // Implementation
        return 128;
    }
}
EOF
  1. Use in main.cpp:
#include "modules/settings_manager.h"

void setup() {
    SettingsManager::init();
    int brightness = SettingsManager::getBrightnessSetting();
}

Quick Checklist

When creating a new module:

  • Header file (.h) in include/modules/
  • Implementation file (.cpp) in src/
  • Include guard in header (#ifndef, #define, #endif)
  • Include statement: #include "modules/module_name.h"
  • Namespace to avoid naming conflicts
  • Build test: pio run

Current Project Structure

ESP32-S3-LCD-1.3/
├── src/                           ← Implementation files (.cpp)
│   ├── main.cpp
│   ├── display_init.cpp           ✅ CORRECT LOCATION
│   └── main_minimal.cpp.bak
│
├── include/
│   ├── modules/                   ← Module headers (.h)
│   │   └── display_init.h         ✅ CORRECT LOCATION
│   ├── config/
│   │   └── lv_conf.h
│   ├── protocol/
│   │   └── automotive_data.h
│   └── ui/                        ← SquareLine UI (special case)
│       ├── ui.h
│       ├── ui.c                   ← Exception: .c in include/
│       └── screens/
│
└── platformio.ini

Summary

File Type Location Include As
.cpp (implementation) src/ N/A (compiled by PlatformIO)
.h (header) include/modules/ #include "modules/name.h"
SquareLine .c include/ui/ Auto-included
SquareLine .h include/ui/ #include "ui/ui.h"

Remember:

  • ✅ Headers in include/
  • ✅ Implementations in src/
  • ❌ Never mix them up!

Last Updated: 2025-11-08 Status: ✅ Correct structure verified, builds successfully