/** * @file hardware_config.h * @brief Hardware pin configuration for Waveshare ESP32-S3-Touch-LCD-2 * * This file contains ALL pin definitions for the LEGO GameBoy project. * Centralized configuration - change pins here only! * * Hardware: Waveshare ESP32-S3-Touch-LCD-2 (2.0" ST7789 240x320) * - ESP32-S3-WROOM-1 module * - 16MB Flash, 8MB PSRAM * - 2.0" ST7789 TFT Display (240x320) * - Integrated touch controller */ #pragma once #ifdef __cplusplus extern "C" { #endif // ============================================ // DISPLAY PINS (ST7789 - 2.0" 240x320) // SPI Interface // ============================================ #define LCD_SPI_HOST SPI2_HOST #define LCD_PIXEL_CLOCK_HZ (40 * 1000 * 1000) // 40MHz #define LCD_PIN_MOSI 11 // SPI MOSI (DIN) #define LCD_PIN_MISO 13 // SPI MISO (nicht verwendet bei Display) #define LCD_PIN_SCLK 12 // SPI Clock #define LCD_PIN_CS 10 // Chip Select #define LCD_PIN_DC 8 // Data/Command #define LCD_PIN_RST 14 // Reset #define LCD_PIN_BCKL 9 // Backlight (PWM capable) // Display specs #define LCD_WIDTH 240 #define LCD_HEIGHT 320 #define LCD_ROTATION 0 // 0, 1, 2, or 3 (0 = Portrait) // Backlight PWM #define LCD_BCKL_DEFAULT 80 // 0-100% #define LCD_BCKL_MIN 10 #define LCD_BCKL_MAX 100 // ============================================ // TOUCH CONTROLLER PINS (CST816S) // I2C Interface // ============================================ #define TOUCH_I2C_NUM I2C_NUM_0 #define TOUCH_I2C_SCL 6 #define TOUCH_I2C_SDA 5 #define TOUCH_I2C_INT 7 // Touch interrupt (active low) #define TOUCH_I2C_RST -1 // Optional reset (not used) #define TOUCH_I2C_ADDR 0x15 // CST816S address #define TOUCH_I2C_FREQ_HZ 400000 // 400kHz // ============================================ // SD CARD PINS (SPI - shares with Display) // ============================================ #define SD_SPI_HOST LCD_SPI_HOST // Same SPI bus as display! #define SD_PIN_MOSI LCD_PIN_MOSI #define SD_PIN_MISO LCD_PIN_MISO #define SD_PIN_SCLK LCD_PIN_SCLK #define SD_PIN_CS 4 // Separate CS from display! // ============================================ // AUDIO PINS (I2S - MAX98357A) // ============================================ #define I2S_NUM I2S_NUM_0 #define I2S_SAMPLE_RATE 32000 // Hz (GameBoy: 32kHz) #define I2S_BITS_PER_SAMPLE 16 #define I2S_PIN_BCLK 35 // Bit Clock (moved from 41 - conflict fixed!) #define I2S_PIN_LRC 36 // Left/Right Clock (WS) (moved from 42 - conflict fixed!) #define I2S_PIN_DIN 37 // Data In (to MAX98357A) (moved from 40) // No MCLK needed for MAX98357A! #define I2S_DMA_BUF_COUNT 8 #define I2S_DMA_BUF_LEN 1024 // ============================================ // NFC READER PINS (PN532) // I2C Interface (separate bus from touch!) // ============================================ #define NFC_I2C_NUM I2C_NUM_1 #define NFC_I2C_SCL 16 // I2C Clock #define NFC_I2C_SDA 15 // I2C Data #define NFC_I2C_INT -1 // Optional interrupt #define NFC_I2C_RST -1 // Optional reset #define NFC_I2C_ADDR 0x24 // PN532 I2C address #define NFC_I2C_FREQ_HZ 100000 // 100kHz (PN532 spec) // ============================================ // GAMEBOY BUTTON PINS // All inputs with pull-up // ============================================ #define BTN_UP 1 #define BTN_DOWN 2 #define BTN_LEFT 42 #define BTN_RIGHT 41 #define BTN_A 21 #define BTN_B 47 #define BTN_START 48 #define BTN_SELECT 45 // Button configuration #define BTN_ACTIVE_LEVEL 0 // Buttons pull to GND (active LOW) #define BTN_DEBOUNCE_MS 50 // Debounce time // ============================================ // POTENTIOMETER PINS (ADC) // ============================================ #define POTI_VOLUME_PIN 3 // ADC1_CH2 - Volume control #define POTI_BRIGHT_PIN 46 // ADC2_CH5 - Brightness control #define POTI_ADC_WIDTH ADC_WIDTH_BIT_12 // 12-bit (0-4095) #define POTI_ADC_ATTEN ADC_ATTEN_DB_11 // 0-3.3V range // ============================================ // LINK CABLE PINS (GPIO for 2-Player) // ============================================ #define LINK_GPIO_SCLK 17 // Serial Clock (bidirectional) #define LINK_GPIO_SOUT 18 // Serial Out (data to other GB) #define LINK_GPIO_SIN 38 // Serial In (data from other GB) // Link Cable Settings #define LINK_CLOCK_FREQ 8192 // Hz (GameBoy standard) #define LINK_BYTE_TIME_US 122 // Microseconds per byte #define LINK_BIT_TIME_US 15 // Microseconds per bit // ============================================ // STATUS LED (optional indicator) // ============================================ #define LED_STATUS_PIN 39 // Status LED (Link active, etc.) #define LED_ACTIVE_LEVEL 1 // Active HIGH // ============================================ // POWER MANAGEMENT (optional) // ============================================ #define BATTERY_ADC_PIN -1 // Not used yet #define POWER_ENABLE_PIN -1 // Not used yet // ============================================ // DEBUG/UART (Serial Console) // ============================================ #define UART_NUM UART_NUM_0 #define UART_TX_PIN 43 #define UART_RX_PIN 44 #define UART_BAUD_RATE 115200 // ============================================ // GPIO SUMMARY (for reference/debugging) // ============================================ /* WAVESHARE ESP32-S3-TOUCH-LCD-2 PIN ALLOCATION: GPIO | Function | Direction | Notes ------|-------------------|-----------|------------------ 1 | BTN_UP | Input | Pull-up 2 | BTN_DOWN | Input | Pull-up 3 | POTI_VOLUME | Input | ADC1_CH2 4 | SD_CS | Output | SPI 5 | TOUCH_SDA | I/O | I2C0 6 | TOUCH_SCL | Output | I2C0 7 | TOUCH_INT | Input | Interrupt 8 | LCD_DC | Output | SPI 9 | LCD_BCKL | Output | PWM 10 | LCD_CS | Output | SPI 11 | LCD_MOSI | Output | SPI 12 | LCD_SCLK | Output | SPI 13 | LCD_MISO | Input | SPI (not used) 14 | LCD_RST | Output | Reset 15 | NFC_SDA | I/O | I2C1 16 | NFC_SCL | Output | I2C1 17 | LINK_SCLK | I/O | Link Cable 18 | LINK_SOUT | Output | Link Cable 21 | BTN_A | Input | Pull-up 35 | I2S_BCLK | Output | Audio Bit Clock 36 | I2S_LRC | Output | Audio Word Select 37 | I2S_DIN | Output | Audio Data 38 | LINK_SIN | Input | Link Cable 39 | LED_STATUS | Output | Status indicator 41 | BTN_RIGHT | Input | Pull-up (conflict fixed!) 42 | BTN_LEFT | Input | Pull-up (conflict fixed!) 43 | UART_TX | Output | Debug 44 | UART_RX | Input | Debug 45 | BTN_SELECT | Input | Pull-up 46 | POTI_BRIGHT | Input | ADC2_CH5 47 | BTN_B | Input | Pull-up 48 | BTN_START | Input | Pull-up NOTES: - PIN CONFLICTS FIXED! I2S moved to GPIO 35/36/37 - Buttons GPIO 41/42 are now free from conflicts! - SPI bus is shared: Display + SD Card → Use separate CS pins! - I2C0: Touch controller - I2C1: NFC reader (separate bus!) - All buttons have internal pull-ups enabled */ // ============================================ // HARDWARE VALIDATION MACROS // ============================================ #define VALIDATE_PIN(pin) ((pin) >= 0 && (pin) <= 48) // Check for pin conflicts at compile time #ifdef __cplusplus } #endif