lego-esp32s3-gameboy/fix_poti_manager_nfc_json.sh

156 lines
5.2 KiB
Bash
Executable File

#!/bin/bash
# Fix remaining compilation errors for gnuboy ESP32-S3
# Set your gnuboy project path here (adjust if needed!)
GNUBOY_DIR=~/Arduino/gameboy/gnuboy
echo "=== Fixing gnuboy compilation errors ==="
echo "Project directory: $GNUBOY_DIR"
if [ ! -d "$GNUBOY_DIR" ]; then
echo "ERROR: Project directory not found!"
echo "Please edit this script and set GNUBOY_DIR to your gnuboy path"
exit 1
fi
cd "$GNUBOY_DIR"
# ============================================
# 1. Copy hardware_config.h to main/include if comes from an old build, else error file not found. Zhis was okay in newer version. If you are on newer version comment it out to supress copy error
# ============================================
echo ""
echo "1. Installing hardware_config.h..."
mkdir -p main/include
cp main/hardware_config.h main/include/
echo " ✓ hardware_config.h installed"
# ============================================
# 2. Fix potentiometer_manager - ADC calibration
# ============================================
echo ""
echo "2. Fixing potentiometer_manager (esp_adc_cal.h issue)..."
# Check if component exists
if [ -f "components/potentiometer_manager/potentiometer_manager.c" ]; then
# Replace esp_adc_cal.h with esp_adc/adc_cali.h (ESP-IDF v4.4)
sed -i 's/#include "esp_adc_cal.h"/#include "driver\/adc.h"/g' \
components/potentiometer_manager/potentiometer_manager.c
# Also need to fix ADC calibration API calls if present
# In ESP-IDF v4.4, ADC calibration is optional/different
echo " ✓ potentiometer_manager patched"
else
echo " ⚠ potentiometer_manager not found, skipping"
fi
# ============================================
# 3. Add cJSON dependency to nfc_manager
# ============================================
echo ""
echo "3. Fixing nfc_manager (cJSON dependency)..."
if [ -f "components/nfc_manager/CMakeLists.txt" ]; then
# Check if cJSON is already in REQUIRES
if ! grep -q "json" components/nfc_manager/CMakeLists.txt; then
# Add json to REQUIRES (cJSON is part of ESP-IDF as 'json' component)
sed -i 's/REQUIRES \(.*\)/REQUIRES \1 json/g' components/nfc_manager/CMakeLists.txt
echo " ✓ cJSON dependency added"
else
echo " ✓ cJSON dependency already present"
fi
else
echo " ⚠ nfc_manager/CMakeLists.txt not found"
fi
# ============================================
# 4. Add hardware_config.h include path to components
# ============================================
echo ""
echo "4. Adding hardware_config.h include paths..."
# Components that need hardware_config.h
COMPONENTS="st7789 link_cable potentiometer_manager"
for comp in $COMPONENTS; do
if [ -f "components/$comp/CMakeLists.txt" ]; then
# Add main/include to include directories
if ! grep -q "\${CMAKE_SOURCE_DIR}/main/include" "components/$comp/CMakeLists.txt"; then
# Find PRIV_INCLUDE_DIRS or add after idf_component_register
if grep -q "PRIV_INCLUDE_DIRS" "components/$comp/CMakeLists.txt"; then
sed -i "s|PRIV_INCLUDE_DIRS|PRIV_INCLUDE_DIRS \"\${CMAKE_SOURCE_DIR}/main/include\"|g" \
"components/$comp/CMakeLists.txt"
elif grep -q "idf_component_register" "components/$comp/CMakeLists.txt"; then
# Add INCLUDE_DIRS line before closing parenthesis
sed -i '/idf_component_register(/a\ INCLUDE_DIRS "include" "${CMAKE_SOURCE_DIR}/main/include"' \
"components/$comp/CMakeLists.txt"
fi
echo "$comp: hardware_config.h path added"
fi
fi
done
# 2. st7789/CMakeLists.txt
cat > components/st7789/CMakeLists.txt << 'EOF'
idf_component_register(
SRCS "st7789.c"
INCLUDE_DIRS "include" "${CMAKE_SOURCE_DIR}/main/include"
PRIV_INCLUDE_DIRS "."
REQUIRES driver esp_timer spi_flash
)
EOF
# 3. link_cable/CMakeLists.txt
cat > components/link_cable/CMakeLists.txt << 'EOF'
idf_component_register(
SRCS "link_cable.c"
INCLUDE_DIRS "include" "${CMAKE_SOURCE_DIR}/main/include"
PRIV_INCLUDE_DIRS "."
REQUIRES driver freertos
)
EOF
# 4. nfc_manager/CMakeLists.txt (mit json für cJSON!)
cat > components/nfc_manager/CMakeLists.txt << 'EOF'
idf_component_register(
SRCS "nfc_manager.c"
INCLUDE_DIRS "include" "${CMAKE_SOURCE_DIR}/main/include"
PRIV_INCLUDE_DIRS "."
REQUIRES driver json freertos fatfs
)
EOF
# 5. potentiometer_manager/CMakeLists.txt
cat > components/potentiometer_manager/CMakeLists.txt << 'EOF'
idf_component_register(
SRCS "potentiometer_manager.c"
INCLUDE_DIRS "include" "${CMAKE_SOURCE_DIR}/main/include"
PRIV_INCLUDE_DIRS "."
REQUIRES driver esp_hw_support st7789
)
EOF
#6 sdconfig
echo "CONFIG_ESP32S3_SPIRAM_SUPPORT=y" >> sdkconfig
echo "CONFIG_SPIRAM=y" >> sdkconfig
echo "CONFIG_SPIRAM_MODE_QUAD=y" >> sdkconfig
echo "CONFIG_SPIRAM_TYPE_AUTO=y" >> sdkconfig
# ============================================
# 5. Clean build and rebuild
# ============================================
echo ""
echo "5. Cleaning build directory..."
rm -rf build sdkconfig sdkconfig.old
echo ""
echo "=== All fixes applied! ==="
echo ""
echo "Next steps:"
echo " cd $GNUBOY_DIR"
echo " source ~/esp-idf/export.sh"
echo " idf.py set-target esp32s3"
echo " idf.py build"
echo ""